diff options
Diffstat (limited to 'sdl/glframe.c')
-rw-r--r-- | sdl/glframe.c | 51 |
1 files changed, 42 insertions, 9 deletions
diff --git a/sdl/glframe.c b/sdl/glframe.c index e9c31e3..b3dc33e 100644 --- a/sdl/glframe.c +++ b/sdl/glframe.c @@ -67,7 +67,9 @@ void glframe_apply_camera_transform(GLFrame *frame) int rot_only = 0; M3DMatrix44f m; - glframe_get_camera_orientation(frame, m); + glframe_get_camera_orientation(frame, m); + m3dPrintMatrix44f(m); + glMultMatrixf(m); /* if rotation only, then do not do the translation */ @@ -91,20 +93,51 @@ void glframe_move_forward(GLFrame *frame, float delta) frame->v_location[2] += frame->v_forward[2] * delta; } +/* rotate left or right */ void glframe_rotate_local_y(GLFrame *frame, float angle) { - M3DMatrix44f rotMat; + M3DMatrix44f rotmat; + M3DVector3f newvect; /* just rotate around the up vector */ - /* create a rotation matrix around my Up (Y) vector */ - m3dRotationMatrix44f(rotMat, angle, frame->v_up[0], frame->v_up[1], frame->v_up[2]); + /* create a rotation matrix around up vector */ + m3dRotationMatrix44f(rotmat, angle, frame->v_up[0], frame->v_up[1], frame->v_up[2]); + + /* rotate forward pointing vector (inlined 3x3 transform) */ + newvect[0] = rotmat[0] * frame->v_forward[0] + rotmat[4] * frame->v_forward[1] + rotmat[8] * frame->v_forward[2]; + newvect[1] = rotmat[1] * frame->v_forward[0] + rotmat[5] * frame->v_forward[1] + rotmat[9] * frame->v_forward[2]; + newvect[2] = rotmat[2] * frame->v_forward[0] + rotmat[6] * frame->v_forward[1] + rotmat[10] * frame->v_forward[2]; + m3dCopyVector3f(frame->v_forward, newvect); +} - M3DVector3f newVect; +/* rotate up or down */ +void glframe_rotate_local_x(GLFrame *frame, float angle) +{ + M3DMatrix44f rotmat; + M3DVector3f newfwdvec; + M3DVector3f newupvec; + M3DVector3f x, z; + + /* z vector is reversed */ + z[0] = -frame->v_forward[0]; + z[1] = -frame->v_forward[1]; + z[2] = -frame->v_forward[2]; + + /* x vector = y cross z */ + m3dCrossProductf(x, frame->v_up, z); + + /* create a rotation matrix around x axis */ + m3dRotationMatrix44f(rotmat, angle, x[0], x[1], x[2]); /* rotate forward pointing vector (inlined 3x3 transform) */ - newVect[0] = rotMat[0] * frame->v_forward[0] + rotMat[4] * frame->v_forward[1] + rotMat[8] * frame->v_forward[2]; - newVect[1] = rotMat[1] * frame->v_forward[0] + rotMat[5] * frame->v_forward[1] + rotMat[9] * frame->v_forward[2]; - newVect[2] = rotMat[2] * frame->v_forward[0] + rotMat[6] * frame->v_forward[1] + rotMat[10] * frame->v_forward[2]; - m3dCopyVector3f(frame->v_forward, newVect); + newfwdvec[0] = rotmat[0] * frame->v_forward[0] + rotmat[4] * frame->v_forward[1] + rotmat[8] * frame->v_forward[2]; + newfwdvec[1] = rotmat[1] * frame->v_forward[0] + rotmat[5] * frame->v_forward[1] + rotmat[9] * frame->v_forward[2]; + newfwdvec[2] = rotmat[2] * frame->v_forward[0] + rotmat[6] * frame->v_forward[1] + rotmat[10] * frame->v_forward[2]; + + /* calculate new up vector */ + m3dCrossProductf(newupvec, x, newfwdvec); + + m3dCopyVector3f(frame->v_forward, newfwdvec); + m3dCopyVector3f(frame->v_up, newupvec); } |