Basic Vector math question..
I have an orientation and a location. When pointing in a certain direction I can move forward by adding unit vectors of my current orientation.
My question is.. How do I strafe?
I''m betting that I need to find out a vector that is 90deg to the ''left'' of my current relative position.
Many thanks for any suggestions.
Chris
Chris Brodie
In that oreintation, do you have two vectors? You at least need to keep track of a facing & a up vector (or use a Q like am). Cross product of the facing & up vector gives you the left or right vector depending on the 'handedness' of your system.
Succint helped me with a similar question a week or so ago.
Anyway, here's my results (detailed enough answer? )
Magmai Kai Holmlor
- The disgruntled & disillusioned
Edited by - Magmai Kai Holmlor on February 1, 2001 9:33:56 PM
Edited by - Magmai Kai Holmlor on February 1, 2001 9:36:45 PM
Succint helped me with a similar question a week or so ago.
Anyway, here's my results (detailed enough answer? )
void CGameEngine::MoveMyCharacter(DWORD dwNow_ms, float dt_sec, D3DXVECTOR3* pos, D3DXQUATERNION* fac) { float t_sec = float(dwNow_ms/1000.0f); D3DXVECTOR3 x; D3DXQUATERNION dr; D3DXVECTOR3 v3Looking_At, v3Up, v3Left; D3DXMATRIX matRot; m_MyCharacter->Extrapolate(t_sec, pos, fac); HRESULT hr; BYTE* KbState; static char state ='x'; if(dt_sec>0.333) dt_sec=0.333f; //float TurnRate = 0.65f*dt_sec; //float MoveRate = 1.3f*dt_sec; //float TurnRate = 0.05f; //float MoveRate = 0.1f; float MoveRate = m_MyCharacter->MovementRate_mps() * dt_sec; float TurnRate = m_MyCharacter->TurnRate_rps() * dt_sec; BOOL bMoved=false, bTurned=false; if(!FAILED(hr=CInputEngine::KeyState(&KbState))) { if(KbState[DIK_X] & 0x80) state = 'x'; if(KbState[DIK_Y] & 0x80) state = 'y'; if(KbState[DIK_Z] & 0x80) state = 'z'; if(KbState[DIK_NUMPAD5] & 0x80) { } if(KbState[DIK_LEFT] & 0x80) { if((KbState[DIK_LALT]&0x80)||(KbState[DIK_RALT]&0x80)) { //Strafe matRot = D3DI3D_QuaternionToOrthoV3(v3Left, v3Up, v3Looking_At, *fac); *pos += MoveRate * v3Left; bMoved=true; } else { //Turn if(state=='x') D3DMath_QuaternionFromAngles(dr.x, dr.y, dr.z, dr.w, 0.0f, TurnRate, 0.0f); else if(state=='y') D3DMath_QuaternionFromAngles(dr.x, dr.y, dr.z, dr.w, 0.0f, 0.0f, TurnRate); else if(state=='z') D3DMath_QuaternionFromAngles(dr.x, dr.y, dr.z, dr.w, TurnRate, 0.0f, 0.0f); *fac = dr * *fac; //D3DXMatrixRotationQuaternion(&matRot, &dr); bTurned=true; } } if(KbState[DIK_RIGHT] & 0x80) { if((KbState[DIK_LALT]&0x80)||(KbState[DIK_RALT]&0x80)) { //Strafe matRot = D3DI3D_QuaternionToOrthoV3(v3Left, v3Up, v3Looking_At, *fac); *pos += MoveRate * -v3Left; bMoved=true; } else { if(state=='x') D3DMath_QuaternionFromAngles(dr.x, dr.y, dr.z, dr.w, 0.0f, -TurnRate, 0.0f); else if(state=='y') D3DMath_QuaternionFromAngles(dr.x, dr.y, dr.z, dr.w, 0.0f, 0.0f, -TurnRate); else if(state=='z') D3DMath_QuaternionFromAngles(dr.x, dr.y, dr.z, dr.w, -TurnRate, 0.0f, 0.0f); *fac = dr * *fac; //D3DXMatrixRotationQuaternion(&matRot, &dr); bTurned=true; } } //if(bTurned) matRot = D3DI3D_QuaternionToOrthoV3(v3Left, v3Up, v3Looking_At, *fac); /* if(m_stFacing) { char stemp[256]; //fac->x, fac->y, fac->z, fac->w sprintf(stemp, "Looking At: %.3f, %.3f, %.3f", v3Looking_At.x, v3Looking_At.y, v3Looking_At.z); CString strLooking(stemp); strLooking+=CString("\n"); sprintf(stemp, "Quaternion: %.3f, %.3f, %.3f, %.3f", fac->x, fac->y, fac->z, fac->w); strLooking += stemp + CString("\n"); int i=0; sprintf(stemp, "Matrix(0,i): %.3f, %.3f, %.3f", matRot(i,1), matRot(i,2), matRot(i,3)); i++;strLooking += stemp + CString("\n"); sprintf(stemp, "Matrix(0,i): %.3f, %.3f, %.3f", matRot(i,1), matRot(i,2), matRot(i,3)); i++;strLooking += stemp + CString("\n"); sprintf(stemp, "Matrix(0,i): %.3f, %.3f, %.3f", matRot(i,1), matRot(i,2), matRot(i,3)); strLooking += stemp + CString("\n"); m_stFacing->SetWindowText(strLooking); } */ if(KbState[DIK_UP] & 0x80) { matRot = D3DI3D_QuaternionToOrthoV3(v3Left, v3Up, v3Looking_At, *fac); *pos += MoveRate * -v3Looking_At; bMoved=true; } if(KbState[DIK_DOWN] & 0x80) { matRot = D3DI3D_QuaternionToOrthoV3(v3Left, v3Up, v3Looking_At, *fac); *pos += -MoveRate * -v3Looking_At; bMoved=true; } if(bMoved||bTurned) m_MyCharacter->Update(t_sec,*pos,*fac); if(bMoved) hViewport->MoveCamera(pos->x, pos->y, pos->z); if(bTurned) { //matRot = D3DI3D_QuaternionToOrthoV3(v3Left, v3Up, v3Looking_At, dr); D3DXMatrixRotationQuaternion(&matRot, &dr); hViewport->RotateCamera(matRot); } } }//Extracts the Orthogonal projection vectors from a Rotation Quaternion D3DXMATRIX D3DI3D_QuaternionToOrthoV3(D3DXVECTOR3 &v3Left, D3DXVECTOR3 &v3Up, D3DXVECTOR3 &v3Dir, const D3DXQUATERNION& qRot) { D3DXMATRIX matRot; D3DXMatrixRotationQuaternion(&matRot, &qRot); v3Left = D3DXVECTOR3(matRot(0,0), matRot(1,0), matRot(2,0)); v3Up = D3DXVECTOR3(matRot(0,1), matRot(1,1), matRot(2,1)); v3Dir = D3DXVECTOR3(matRot(0,2), matRot(1,2), matRot(2,2)); return(matRot); }
Magmai Kai Holmlor
- The disgruntled & disillusioned
Edited by - Magmai Kai Holmlor on February 1, 2001 9:33:56 PM
Edited by - Magmai Kai Holmlor on February 1, 2001 9:36:45 PM
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement