Archived

This topic is now archived and is closed to further replies.

Cybrosys

z-axis cirkular rotation, with a fixed lookat spot

Recommended Posts

This is what controls the gamera system so far, It works fine... but now It''s time to add cirkular rotation around a z-axis, and this I don''t know how to do..... (this is the camera code so far) GLdouble eyex, eyey;//, eyez, centerx, centery, centerz, upx, upy, upz; GLdouble eyez = 5.0f;//-atimer; GLdouble centerx = 5.0f; GLdouble centery = 5.0f; GLdouble centerz = 0.0f; GLdouble upx = 0.0f; GLdouble upy = 0.0f; GLdouble upz = 1.0f; ........................ gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz); eyex = centerx; eyey = centery-5.0f; ........................ if (keys[VK_LEFT]) centerx-=0.05f; if (keys[VK_RIGHT]) centerx+=0.05f; if (keys[VK_UP]) centery+=0.05f; if (keys[VK_DOWN]) centery-=0.05f; if (keys[''A'']) eyez+=0.05f; if (keys[''Z'']) { if (eyez <= 0.1f) { eyez = 0.1f; } else { eyez-=0.05f; } } ........................ So now I need help with z-axis camera rotation, or course the camera will look at a designated coord all the time...

Share this post


Link to post
Share on other sites
I''m using Dx so you''ll have to translate yourself:

  
D3DXMATRIX D3DI3D_QuaternionToOrthoV3(D3DXVECTOR3 &v3Left, D3DXVECTOR3 &v3Up, D3DXVECTOR3 &v3Dir, const D3DXQUATERNION& qRot)
{
// Credit goes to Succinct of GameDev

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);
}

void CAvatar::MoveAhead(float fElapsed_sec)
{
float MoveRate = m_fMovementRate_mps * fElapsed_sec;
D3DXVECTOR3 v3Looking_At, v3Up, v3Left;
D3DXMATRIX matRot;

matRot = D3DI3D_QuaternionToOrthoV3(v3Left, v3Up, v3Looking_At, m_qFacing);
m_v3Position += MoveRate * v3Looking_At;
m_bMoved=TRUE;
}

void CAvatar::RotateLeft(float fElapsed_sec)
{
D3DXQUATERNION dr;

float TurnRate = m_fTurnRate_rps * fElapsed_sec;

D3DMath_QuaternionFromAngles(dr.x, dr.y, dr.z, dr.w, 0.0f, TurnRate, 0.0f);
m_qFacing = dr * m_qFacing;
m_bTurned = TRUE;
}

//Translate

if(m_pavMe->HasMoved())
{
D3DXVECTOR3 v3Pos = m_pavMe->m_v3Position;
m_GfxEngine->MoveCamera(v3Pos.x, v3Pos.y, v3Pos.z);
}

//Rotate

if(m_pavMe->HasTurned())
{
D3DXMATRIX matRot;
D3DXVECTOR3 v3Pos;
D3DXQUATERNION qFac;
qFac = m_pavMe->m_qFacing; D3DXMatrixRotationQuaternion(&matRot, &qFac);
m_GfxEngine->RotateCameraAbs(matRot);
}


I think that''s everything you need to do doom style movement.

Magmai Kai Holmlor
- The disgruntled & disillusioned

Share this post


Link to post
Share on other sites
I wasn''t aiming at doom style looking and moving, this camera is more like "Ground Controls" camera. The camera is focused on looking at for example, "x = 10, y = 25, z = 0". What I want when rotating is rotating around that x and y focus. I know about using:
..........
degre += 0.1f;
eyex = eyex + (float)sin(degre);
eyey = eyey + (float)cos(degre);
..........
But that will only move the camera in a circular movement pattern, but what I want is for this rotation center is to be the focus''s x and y coord.

Share this post


Link to post
Share on other sites