Jump to content
  • Advertisement
Sign in to follow this  
deathwearer

Rotation with a vector[NOT SOLVED]

This topic is 4330 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, in my game in my camera class i store the Eye point, where it look and the up vector. Each frame i calculate the new view matrice and use it. I have no trouble to strafe and go forward and backward. But I seem to not be able to do the math to rotate the LookAt vector. I was wondering if it's possible without using the view matrice. Because it bug everything else I'v done. Like I'd like to rotate my LookAt vector of 5 degree on the left. Thank [EDIT] If i have to use the Eye point and the up vector it's alright, aslong as i dont have to use the matrice directly. [Edited by - deathwearer on November 17, 2006 12:33:51 PM]

Share this post


Link to post
Share on other sites
Advertisement
You just need to rotate the vector by 5 degrees in the xz plane. If alpha = 5*(Pi/180),

new_vector.x = old_vector.x*cos(alpha) - old_vector.y*sin(alpha);
new_vector.y = old_vector.y;
new_vector.z = old_vector.x*sin(alpha) + old_vector.y*cos(alpha);

It's not clear to me whether LookAt is a vector (a direction in which you look) or a point (so the direction you look at is actually LookAt - Eye. In the latter case, substract Eye from LookAt, rotate, and add Eye back.

Share this post


Link to post
Share on other sites
Sure

to turn the camera to the left slightly:

Lookat=normalize(Lookat + -.001*Right)
Right=cross(Lookat,Up)

to turn the camera upwards slightly:

Lookat=normalize(Lookat + .001*Up)
Up=cross(Right,Lookat)


..and similar to go left and down..
Yes, in addition to Lookat(forward) and Up, you also need to keep track of the Right side of the camera.

If those end up being backwards, just flip the signs
Also, to get actual degrees of rotation you will need some trig.
Personally I do as above and ignore degree measures in favor of 'keep rotating till its good' since its easier...

Share this post


Link to post
Share on other sites
Quote:
Original post by alvaro
You just need to rotate the vector by 5 degrees in the xz plane. If alpha = 5*(Pi/180),

new_vector.x = old_vector.x*cos(alpha) - old_vector.y*sin(alpha);
new_vector.y = old_vector.y;
new_vector.z = old_vector.x*sin(alpha) + old_vector.y*cos(alpha);

It's not clear to me whether LookAt is a vector (a direction in which you look) or a point (so the direction you look at is actually LookAt - Eye. In the latter case, substract Eye from LookAt, rotate, and add Eye back.


I think he was asking for rotations in Camera Local Space, not world space...

Of course, depending on if he's making a Doom style game(walking) or a Descent style game(flying), that could work just as well.

Share this post


Link to post
Share on other sites
Thank guys for your help!

It gives something like that


void CCamera::RotateCamera(float YSpeed, float ZSpeed)
{
D3DXVECTOR3 vVector;
D3DXVec3Subtract(&vVector, &m_WorldPosition, &m_LookAt);

m_LookAt.z = (float)(m_WorldPosition.z + std::sin(YSpeed) * vVector.x + std::cos(YSpeed)*vVector.z);
m_LookAt.x = (float) (m_WorldPosition.x + std::cos(YSpeed) * vVector.x - std::sin(YSpeed) * vVector.z);

m_LookAt.y += ZSpeed * 2;
}

void CCamera::MoveCamera(float speed)
{
D3DXVECTOR3 vDirection;
D3DXVec3Normalize(&vDirection,
&(m_LookAt - m_WorldPosition));

m_WorldPosition += vDirection * speed;
m_LookAt += vDirection *speed;
}

void CCamera::StrafeCamera(float speed)
{
D3DXVECTOR3 vDirection;

D3DXVec3Normalize(&vDirection,
&(m_LookAt - m_WorldPosition));

D3DXVec3Cross(&vDirection,&vDirection,&m_Up);
D3DXVec3Normalize(&vDirection,&vDirection);


m_WorldPosition += vDirection * speed;
m_LookAt += vDirection * speed;
}



by the way what the difference between a local camera and world camera?

Share this post


Link to post
Share on other sites
Ok, it doens't work as well as i tought. When I'm in front of my tiger i can move the camera pretty well, When i go forward and go past of my tiger, hes right behind me, i move slightly my mouse and paf im looking straight to it. You said i should keep track of the right side of the camera but I don't really know how to do it and use it.

I created my right matrice (1.0f, 0.0f, 0.0f)

but like i said i don't know how to use it.

[EDIT] I'm making a FPS game.

[EDIT2] I'v just noticed a post earlier that talk about it, my bad. I'll try that. If that's what i think.

[EDIT3] My camera is set per default at :

D3DXVECTOR3 vEye(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 vLookAt(0.0f, 0.0f, 10.0f);
D3DXVECTOR3 vUp(0.0f, 1.0f, 0.0f);
D3DXVECTOR3 vRight(1.0f, 0.0f, 0.0f);

I don't know if my Right vector is alright. Because at the moment it when i move to left after 1/20 of rotation it goes right and stop at 1/20 rotation and repeat. I think It's because of my right vector but I'm having a serios headach with 3D math.

[Edited by - deathwearer on November 17, 2006 12:03:29 PM]

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.

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!