Sign in to follow this  
fitfool

Rotating camera

Recommended Posts

Hello, ive been doing some work with my camera recently. ive been able to get it strafe left/right and move forwar/backwords. Now im trying to get it to rotate. how i have it set up: Im listening for a user to push the left arrow button (VK_LEFT) then i call my function SetRotateX(0.2f) which *should* rotate the camera .2 to the right. but its not working and i know why... first, please take a look at this code, it contains my class, input function and my render function http://rafb.net/p/kX1mnc64.html on line 71, im setting the cameras position, but i am never setting if the camera should rotate or not. So basicly, im asking, how should i do this? ive read tutorials on how to bind "properties" (translation, scaling, and rotation) but all i do when i do that the triangle (that im rendering) is not visible. Thanks alot, fitfool

Share this post


Link to post
Share on other sites
The link provided is just a blank page in your blog...

...A camera is essentially a view matrix and it sounds like you want to rotate the view direction (a vector in this matrix) around the Y-axis when a user hits a direction. You would also have to update the "right" vector which is an axis in your camera space by computing the cross product of the new direction vector and the up vector. This new view matrix should provide the desired effect.

Share this post


Link to post
Share on other sites
*////EDIT////*


i made like this!


//Globals

static float RotateX = 0.0f;



//iput detction

if(KEYDOWN(keystate, DIK_D))
{
RotateX+=0.1f;
}

//the camera position


D3DXMatrixLookAtLH(&matView,
&D3DXVECTOR3 (RotateX, 0.0f, Move), // the camera position
&D3DXVECTOR3 (0.0f, 0.0f, 0.0f), // the look-at position
&D3DXVECTOR3 (0.0f, 1.0f, 0.0f)); // the up direction






if you dont understand it i will give you beter explenations!
and i hope it will soulve your question!

[Edited by - snoddas14 on March 22, 2007 7:05:43 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by snoddas14
i made this!

*** Source Snippet Removed ***

if you dont understand it i will give you beter explenations!
and i hope it will soulve your question!


I think you're a bit confused as to what D3DXMatrixLookAtLH and it's lookat parameter in particular really does (or maybe I'm misunderstanding the point of it :-)). The lookat parameter is actually the point you want the camera to "focus" on. Take for example a ball floating in space, its center lying in (10,20,10). Then you would pass D3DXVECTOR3( 10.f, 20.f, 10.f) as the lookat parameter to "look at" the ball. If you want to make use of your Rotate* variables explicitely, you should use other means such as D3DXMatrixRotation*, and concatenate these onto your view transformation.

Share this post


Link to post
Share on other sites
ahah!
I see my problem.

I was manually trying to rotate the camera, ill do like snoddas said, and use the lookat function. I must have misunderstood what this function does...

Thanks a-lot, fit

[Edited by - fitfool on March 22, 2007 1:53:35 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this