• Advertisement
Sign in to follow this  

Camera Translation+Turn problem

This topic is 3986 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
Quote:
Original post by D3DXVEC5
nope, it totally disable rotation
Then you did something wrong.

If you still need help with the problem, post the code again along with any revisions you've made.

Share this post


Link to post
Share on other sites
ok

const float PI = 3.14159265358979323846f; // Pi

#define DEGTORAD(x) ( ((x) * PI) / 180.0 )
#define RADTODEG(x) ( ((x) * 180.0) / PI )

void FromEuler(NxQuat *q,float x,float y,float z)
{
double ex, ey, ez; // temp half euler angles
double cr, cp, cy, sr, sp, sy, cpcy, spsy; // temp vars in roll,pitch yaw

ex = DEGTORAD(x) / 2.0; // convert to rads and half them
ey = DEGTORAD(y) / 2.0;
ez = DEGTORAD(z) / 2.0;

cr = cos(ex);
cp = cos(ey);
cy = cos(ez);

sr = sin(ex);
sp = sin(ey);
sy = sin(ez);

cpcy = cp * cy;
spsy = sp * sy;

q->w = float(cr * cpcy + sr * spsy);

q->x = float(sr * cpcy - cr * spsy);
q->y = float(cr * sp * cy + sr * cp * sy);
q->z = float(cr * cp * sy - sr * sp * cy);
q->normalize();
}

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 temp;
temp.id();
FromEuler(&temp,Pitch,Yaw,Roll);
CamRot = CamRot*temp;
}
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=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);
}
};


Share this post


Link to post
Share on other sites
One more thing i find some another QCamera
can u watch on her and tell does it can solve my problem? http://www.gamedev.net/reference/articles/article1997.asp

Share this post


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

  • Advertisement