I have a FPS style 3D world with mouse look. Transforms are done with the following function, based on camera position, look, up and right vectors.
void updateViewMatrix( void )
{
matrix4x4f view;
view.identity();
g_vLook.normalize();
g_vRight = crossProduct(g_vLook, g_vUp);
g_vRight.normalize();
g_vUp = crossProduct(g_vRight, g_vLook);
g_vUp.normalize();
view.m[0] = g_vRight.x;
view.m[1] = g_vUp.x;
view.m[2] = -g_vLook.x;
view.m[3] = 0.0f;
view.m[4] = g_vRight.y;
view.m[5] = g_vUp.y;
view.m[6] = -g_vLook.y;
view.m[7] = 0.0f;
view.m[8] = g_vRight.z;
view.m[9] = g_vUp.z;
view.m[10] = -g_vLook.z;
view.m[11] = 0.0f;
view.m[12] = -dotProduct(g_vRight, g_vCameraPos);
view.m[13] = -dotProduct(g_vUp, g_vCameraPos);
view.m[14] = dotProduct(g_vLook, g_vCameraPos);
view.m[15] = 1.0f;
glMultMatrixf( view.m );
}
I'm trying to shoot a sphere. My first idea is to save the camera related vectors at the moment of shooting. That should be the starting point of the sphere. Then I can move it through the world using the same methods I use to move the camera.
My problem is figuring out the transforms needed in the rendering function given here:
void render( void )
{
<SNIP>COLLISION DETECTION STUFF</SNIP>
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
//SET UP 3D
glEnable(GL_DEPTH_TEST);
glMatrixMode( GL_PROJECTION );
glPopMatrix();
glMatrixMode( GL_MODELVIEW );
glPopMatrix();
glLoadIdentity();
updateViewMatrix();
<SNIP>DO THE 3D STUFF</SNIP>
// ****************************************
// DO THE SPHERE/PROJECTILE ???????????????
// ****************************************
//SET UP 2D
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0,screenx,0,screeny);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
<SNIP>DO THE 2D STUFF (CROSSHAIR)</SNIP>
glutSwapBuffers();
}
I kind of understand what needs to be done, but it requires special care to separate the world and sphere transforms because the player can move while the sphere is "in flight" and that shouldn't affect it.
I'm very much a noob, but common sense is telling me that this sort of thing must be done all the time, so I've put it here. I'm sorry if I've judged it wrong. Thank you in advance for any tips, code, links... anything that could help me do this ASAP, as time is an issue.