Jump to content
  • Advertisement

Archived

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

Bacardi34

Very Frustrated...

This topic is 5668 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

I am trying to get a first person style camera system up and running, i have a camera working that moves around and a model for the arm and what its holding. But i cant seem to get the arm to move with the camera. It rotates fine, because no matter where i move the camera and turn it to face the arm object, its always facing away from the camera, but it will not move with the camera, make sense? I tried just moving the arm object to make sure it can, and that works fine. The way i am trying to move the arm/camera, is get the position matrix, use the keys to get forward/back/rotation, store forward back in vTrans, and rotation in vRot which is radians. here is the code
    
D3DXVECTOR3		vTrans( 0.0, 0.0, 0.0 );				// Tracks camera point movement

	D3DXVECTOR3		vRot( 0.0, 0.0, 0.0 );				// Tracks camera rotation

	D3DXMATRIX		matView;									// Will be the View Matrix

	float			time	= g_Timer.GetTimeSinceLastFrame();
	D3DXMatrixIdentity( &matView );

// if the up key is pressed, then move the camera forward.

	if( KEYDOWN( g_keyboardBuffer, DIK_UP ))
	{
		vTrans.z += MOVESPEED * time;		
	}
	// if down is pressed, move the camera back

	if( KEYDOWN( g_keyboardBuffer, DIK_DOWN ))
	{
		vTrans.z -= MOVESPEED * time;		
	}
	// right is pressed, rotate the camera right

	if( KEYDOWN( g_keyboardBuffer, DIK_RIGHT ))
	{
		vRot.x += ROTATIONSPEED * time;
	}
	// left is pressed, rotate left

	if( KEYDOWN( g_keyboardBuffer, DIK_LEFT ))
	{
		vRot.x -= ROTATIONSPEED * time;
	}

	// Now translate the camera

	D3DXMATRIX matTrans, matRot, matPosition;
	D3DXQUATERNION qRot;

	// First translate the position of the camera

	matPosition = g_Camera.GetPositionMatrix();
	D3DXMatrixTranslation( &matTrans, vTrans.x, vTrans.y, vTrans.z );
	D3DXMatrixMultiply( &matPosition, &matTrans, &matPosition );
	// Next handle the rotation of the camera

	D3DXQuaternionRotationYawPitchRoll( &qRot, vRot.x, vRot.y, vRot.z );
	D3DXMatrixRotationQuaternion( &matRot, &qRot );
	D3DXMatrixMultiply( &matPosition, &matRot, &matPosition );
	D3DXMatrixInverse( &matView, NULL, &matPosition );
	// Reset the camera view and position matrices

	g_Camera.SetPositionMat( matPosition );
	g_Camera.SetViewMat( matView );

	g_pd3dDevice->SetTransform( D3DTS_VIEW, &matView );
	g_pd3dDevice->SetTransform( D3DTS_PROJECTION, &g_Camera.GetProjMatrix() );

// Now translate the sword position

	// First translate the position 

	matPosition = g_Sword.GetWorldMatrix();
	D3DXMatrixMultiply( &matPosition, &matTrans, &matPosition );
	// Next handle the rotation 


	D3DXMatrixMultiply( &matPosition, &matRot, &matPosition );

	// Reset the position matrices

	g_Sword.SetWorldMatrix( matPosition );
	g_Sword.SetMatrix( &matPosition );
    
so for some reason, like i said, the rotation works fine, but the sword/arm object does not move, it stays where it was created. i cant for the life of me figure out why, and i am about to throw the computer out the window Any ideas or Tutorials/articles on FPS stlye games/cameras? Thanks much in advance. [edited by - Bacardi34 on February 8, 2003 6:40:03 PM]

Share this post


Link to post
Share on other sites
Advertisement
quote:

...i cant for the life of me figure out why, and i am about to throw the computer out the window


Throw it off No, wait, I think I found your problem, I can''t see your
g_pd3dDevice->SetTransform( D3DTS_WORLD , &matWorld );
transformation taking place in your posted code...
I hope that''s your problem, otherwise you can still throw your
computer out the window




KaMiKaZe

Share this post


Link to post
Share on other sites
In the Render function i call the set transform like so:

  
g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET,
D3DCOLOR_XRGB( 28,205,236 ), 1.0f, 0 );

// Set the world matrix

D3DXMatrixIdentity( &g_WorldMat );
g_pd3dDevice->SetTransform( D3DTS_WORLD, &g_WorldMat );

g_pd3dDevice->SetRenderState( D3DRS_LIGHTING, FALSE );

// Begin the scene

g_pd3dDevice->BeginScene();

g_pd3dDevice->SetTransform( D3DTS_WORLD, g_Ground.GetMatrix() );
if( FAILED( g_Ground.Render( g_pd3dDevice, &g_WorldMat )))
MessageBox( NULL, "GR RENDER FAIL", "GR RENDER FAIL", NULL);

g_pd3dDevice->SetTransform( D3DTS_WORLD, &g_Sword.GetWorldMatrix() );
if( FAILED( g_Sword.Render( g_pd3dDevice, &g_WorldMat )))
MessageBox( NULL, "SWORD REND", "SWORD REND", NULL );

g_pd3dDevice->SetTransform( D3DTS_WORLD, &g_WorldMat );
g_Sky.Render( g_pd3dDevice, &g_WorldMat );

g_pd3dDevice->EndScene();
g_pd3dDevice->Present( NULL, NULL, NULL, NULL );


Share this post


Link to post
Share on other sites
I think the problem is that you are using –vTrans in the view matrix and translating your hand by +vTrans. So effectively, you’re doing nothing (vTrans and -vTrans cancel out each other when the 2 matrices are multiplied).

When the cursor keys are used to navigate the world, the objects stay where they are. They’re not translated (when you stand up and walk in the room, the objects stay where they are, the chair/computer/wall doesn’t move with you. The objects’ world matrices remain unchanged, only YOUR matrix (the view matrix) is the one changed).

Remove these:

    
// First translate the position

matPosition = g_Sword.GetWorldMatrix();
D3DXMatrixMultiply( &matPosition, &matTrans, &matPosition );
// Next handle the rotation

D3DXMatrixMultiply( &matPosition, &matRot, &matPosition );
// Reset the position matrices

g_Sword.SetWorldMatrix( matPosition );
g_Sword.SetMatrix( &matPosition );


By the way, IMHO this isn’t a good way to handle cameras. From your code, it seems that pressing up moves the camera in the +ve direction of the world’s z axis, not the camera’s z axis (which is different).

(If you turn to the right 90 degrees and move forward, you’re actually moving in the direction of the x axis, not the z axis)

Note: The up, right and forward vectors can be extracted from the view matrix.


[edited by - Coder on February 9, 2003 5:20:02 AM]

Share this post


Link to post
Share on other sites
quote:
Any ideas or Tutorials/articles on FPS stlye games/cameras?


I have around 5 on my PC:

"Rotating the camera": This one is by mr game maker I think. So you should search for "gamemaker camera" or something similar.

"Camera tutorial": By Ian kerr (search terms)
"Camera tutorial": By Toby Murray
"Camera orientation in 3DS": Ask midnight column, on flipcode

"Viewing systems for 3D engines": Not a camera tutorial actually, but it''s good. It''s on GDNet somewhere in the articles section.

If you fail to find them, mail me and I''ll mail them to you.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!