Hi,
After digging back into math, I think I've got my movement in my 3d engine working fine, mathematically. Although, my free mouselook looks a bit "shocking", it's not really smooth.
Is there someone willing to take a look at my "movement"-code, and/or maybe check this little demo: http://www.sierracosworth.nl/engine-tst2.zip
(mouselook, W/S/A/D, T/G, F1=fullscreen, F2 and more = effects on/off)
All suggestions and help is welcome.
Here's the source-code (parts related to movement/mouselook).
"main" input checking:
if(input->buffer[DIK_W] || input->buffer[DIK_UP] & 0x80) {
scene->cam->pos.x += (float)sin(scene->cam->rot.y*piover180) * moveSpeed;
scene->cam->pos.z -= (float)cos(scene->cam->rot.y*piover180) * moveSpeed;
}
if(input->buffer[DIK_S] || input->buffer[DIK_DOWN] & 0x80) {
scene->cam->pos.x -= (float)sin(scene->cam->rot.y*piover180) * moveSpeed;
scene->cam->pos.z += (float)cos(scene->cam->rot.y*piover180) * moveSpeed;
}
if(input->buffer[DIK_A] || input->buffer[DIK_LEFT] & 0x80) {
scene->cam->pos.x -= (float)sin((scene->cam->rot.y+90.0f)*piover180) * moveSpeed;
scene->cam->pos.z += (float)cos((scene->cam->rot.y+90.0f)*piover180) * moveSpeed;
}
if(input->buffer[DIK_D] || input->buffer[DIK_RIGHT] & 0x80) {
scene->cam->pos.x -= (float)sin((scene->cam->rot.y-90.0f)*piover180) * moveSpeed;
scene->cam->pos.z += (float)cos((scene->cam->rot.y-90.0f)*piover180) * moveSpeed;
}
input->CheckMouseState(turnAngle, &scene->cam->rot.x, &scene->cam->rot.y);
Specific mouselook function:
void GLdinput::CheckMouseState(float angle, float *camXrot, float *camYrot)
{
GetCursorPos(&mpos);
*camYrot -= ((float)((screenWidth/2 - mpos.x)) * angle); // / (screenwidth / 5.2);
*camXrot += (float)(mpos.y - screenHeight/2) * angle;
// if(mpos.x < (float)screenWidth/2) *camYrot-=angle;
// else if(mpos.x > (float)screenWidth/2) *camYrot+=angle;
// if(mpos.y < (float)screenHeight/2) *camXrot-=angle;
// else if(mpos.y > (float)screenHeight/2) *camXrot+=angle;
// if(*camXrot > 360) *camXrot = 0;
// if(*camXrot < 0) *camXrot = 360;
// if(*camYrot > 360) *camYrot = 0;
// if(*camYrot < 0) *camYrot = 360;
SetCursorPos(screenWidth/2, screenHeight/2);
}
Rendering the 3d scene:
int GLscene::Render(int width, int height)
{
static int mc, oc;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(cam->rot.x, 1, 0, 0);
glRotatef(cam->rot.y, 0, 1, 0);
glTranslatef(-cam->pos.x, -cam->pos.y, -cam->pos.z);
frustum.CalculateFrustum();
...position lightsources
...draw all objects if they're in the frustum