Jump to content
  • Advertisement
Sign in to follow this  
D3DXVEC5

Camera Translation+Turn problem

This topic is 4082 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello i have a'v read many post of ur forum and finally make my simple camera, but it seems something wrong about her, it seems she rotates wrong(above some uknown point) I just want to create a simple qaternion camera that have PITCH YAW ROLL and can change order like yaw pitch roll. Can somebody look at my code and help me
void NxQuatToD3DXQ(NxQuat *q,D3DXQUATERNION *q_r)
{
	q_r->w=q->w;
	q_r->x=q->x;
	q_r->y=q->y;
	q_r->z=q->z;
}

NxVec3 QMultiplyVEC(NxQuat q,NxVec3 v)
{


	NxVec3 vn(v);
	vn.normalize();

	NxQuat vq, rq,cq;
	vq.x = vn.x;
	vq.y = vn.y;
	vq.z = vn.z;
	vq.w = 0.0f;

	q.conjugate();

	rq = vq * q;
	rq = q * rq;

	return (NxVec3(rq.x, rq.y, rq.z));

}

class TestCam
{
	D3DXMATRIX CamProj;
	D3DXMATRIX CamView;
	NxVec3 CamPos;
	NxQuat CamRot;
public:
	TestCam()
	{
		D3DXMatrixIdentity(&CamProj);
		D3DXMatrixIdentity(&CamView);
		CamPos=NxVec3(0,0,0);
		CamRot.id();
	}
	void Turn(float Pitch,float Yaw,float Roll)
	{
		NxQuat qYaw, qPitch,qRoll;
		qPitch.fromAngleAxis(Pitch,NxVec3(1,0,0));
		qYaw.fromAngleAxis(Yaw,NxVec3(0,1,0));
		qRoll.fromAngleAxis(Roll,NxVec3(0,1,0));


		CamRot = qYaw*qPitch*qRoll* CamRot;
	}
	void Move(float dx,float dy,float dz)
	{
		NxQuat resq;
		resq.id();
		NxVec3 resv=QMultiplyVEC(CamRot,NxVec3(dx,dy,dz));
		CamPos += resv * 0.1f;
	}
	void BuildView()
	{
		D3DXQUATERNION p;
		D3DXMATRIX trans;
		NxQuatToD3DXQ(&CamRot,&p);
		D3DXMatrixRotationQuaternion(&CamView,&p);
		D3DXMatrixTranslation(&trans,-CamPos.x,-CamPos.y,-CamPos.z);
		CamView*=trans;
        device->SetTransform(D3DTS_VIEW,&CamView);
	}
	void BuildProjection()
	{		
		D3DXMatrixPerspectiveFovLH( &CamProj, 
			D3DXToRadian( 70 ),
			(float)(d3dpp.BackBufferWidth / d3dpp.BackBufferHeight), 1,1000 );

		device->SetTransform(D3DTS_PROJECTION, &CamProj);
	}
};

and can somebody tell's me please, how to set this code into normal tags? [Edited by - D3DXVEC5 on March 23, 2007 9:03:24 AM]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
CamView*=trans;
I think that should be:
CamView = trans * CamView;
I see some other potential problems with your code as well - I'll try to post back later and provide a little more detail.

Also, the source tags are [ source ][ /source ] (no spaces).

Share this post


Link to post
Share on other sites
well, exe did't help me by the reason my videocard have very bad relationship with opengl, can u give me some code from ur camera(turn,move,builing view matrix) please

Share this post


Link to post
Share on other sites
tx, but still i need yaw*pitch*roll camera represented by quaternions, ur code confused me and it seems u do not using quaternions in them, so it did't help :(

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!