add some mouse controls
This commit is contained in:
@@ -101,6 +101,7 @@ struct InternalDataRenderer : public GLInstanceRendererInternalData
|
|||||||
float m_mouseXpos;
|
float m_mouseXpos;
|
||||||
float m_mouseYpos;
|
float m_mouseYpos;
|
||||||
bool m_mouseInitialized;
|
bool m_mouseInitialized;
|
||||||
|
int m_mouseButton;
|
||||||
|
|
||||||
GLuint m_defaultTexturehandle;
|
GLuint m_defaultTexturehandle;
|
||||||
|
|
||||||
@@ -111,13 +112,16 @@ struct InternalDataRenderer : public GLInstanceRendererInternalData
|
|||||||
m_cameraUp(0,1,0),
|
m_cameraUp(0,1,0),
|
||||||
m_azi(100.f),//135.f),
|
m_azi(100.f),//135.f),
|
||||||
m_ele(25.f),
|
m_ele(25.f),
|
||||||
m_mouseInitialized(false)
|
m_mouseInitialized(false),
|
||||||
|
m_mouseButton(0)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wheelCallback( float deltax, float deltay)
|
void wheelCallback( float deltax, float deltay)
|
||||||
|
{
|
||||||
|
if (!m_mouseButton)
|
||||||
{
|
{
|
||||||
if (btFabs(deltax)>btFabs(deltay))
|
if (btFabs(deltax)>btFabs(deltay))
|
||||||
{
|
{
|
||||||
@@ -125,14 +129,42 @@ struct InternalDataRenderer : public GLInstanceRendererInternalData
|
|||||||
|
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
m_cameraDistance -= deltay*0.1;
|
//m_cameraDistance -= deltay*0.1;
|
||||||
|
btVector3 fwd = m_cameraTargetPosition-m_cameraPosition;
|
||||||
|
fwd.normalize();
|
||||||
|
m_cameraTargetPosition += fwd*deltay*0.1;
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
if (btFabs(deltax)>btFabs(deltay))
|
||||||
|
{
|
||||||
|
btVector3 fwd = m_cameraTargetPosition-m_cameraPosition;
|
||||||
|
btVector3 side = m_cameraUp.cross(fwd);
|
||||||
|
side.normalize();
|
||||||
|
m_cameraTargetPosition += side * deltax*0.1;
|
||||||
|
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
m_cameraTargetPosition -= m_cameraUp * deltay*0.1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouseMoveCallback(float x, float y)
|
void mouseMoveCallback(float x, float y)
|
||||||
{
|
{
|
||||||
|
if (m_mouseButton)
|
||||||
|
{
|
||||||
|
float xDelta = x-m_mouseXpos;
|
||||||
|
float yDelta = y-m_mouseYpos;
|
||||||
|
// if (btFabs(xDelta)>btFabs(yDelta))
|
||||||
|
// {
|
||||||
|
m_azi += xDelta*0.1;
|
||||||
|
// } else
|
||||||
|
// {
|
||||||
|
m_ele += yDelta*0.1;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
m_mouseXpos = x;
|
m_mouseXpos = x;
|
||||||
m_mouseYpos = y;
|
m_mouseYpos = y;
|
||||||
@@ -141,25 +173,14 @@ struct InternalDataRenderer : public GLInstanceRendererInternalData
|
|||||||
|
|
||||||
void mouseButtonCallback(int button, int state, float x, float y)
|
void mouseButtonCallback(int button, int state, float x, float y)
|
||||||
{
|
{
|
||||||
if (m_mouseInitialized)
|
m_mouseButton=state;
|
||||||
{
|
|
||||||
if (button)
|
|
||||||
{
|
|
||||||
float xDelta = x-m_mouseXpos;
|
|
||||||
float yDelta = y-m_mouseYpos;
|
|
||||||
|
|
||||||
m_azi += xDelta*0.1;
|
|
||||||
m_ele += yDelta*0.1;
|
|
||||||
//printf("m_azi=%f\n",m_azi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_mouseXpos = x;
|
m_mouseXpos = x;
|
||||||
m_mouseYpos = y;
|
m_mouseYpos = y;
|
||||||
m_mouseInitialized = true;
|
m_mouseInitialized = true;
|
||||||
}
|
}
|
||||||
void keyboardCallback(unsigned char key, int x, int y)
|
void keyboardCallback(unsigned char key, int x, int y)
|
||||||
{
|
{
|
||||||
// printf("world\n");
|
printf("world\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -187,7 +208,7 @@ void btDefaultMouseMoveCallback( float x, float y)
|
|||||||
|
|
||||||
void btDefaultKeyboardCallback(int key, int state)
|
void btDefaultKeyboardCallback(int key, int state)
|
||||||
{
|
{
|
||||||
//printf("world\n");
|
printf("world2\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -890,7 +890,7 @@ void MacOpenGLWindow::startRendering()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (!handledEvent)
|
if (!handledEvent)
|
||||||
[m_internalData->m_myApp sendEvent:event];
|
[m_internalData->m_myApp sendEvent:event];
|
||||||
|
|
||||||
[m_internalData->m_myApp updateWindows];
|
[m_internalData->m_myApp updateWindows];
|
||||||
|
|||||||
Reference in New Issue
Block a user