Jump to content
  • Advertisement
Sign in to follow this  
Brocketino

Camera

This topic is 4864 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 have posted something very much like this before:) I'm trying to create a 3d person camera builtup from a position, view and up vector. I can move forward/backward, strafe and rotate around my character, the problem is that I can't make the character rotate so that it's back always facing the view of the camera. Would be really glad if someone could explain ( show some code ) how to achive this. // Brocket

Share this post


Link to post
Share on other sites
Advertisement
I already know the target direction, that's not the problem. The thing is that I don't know how to calculate the angle that I should use to rotate my model.
I tried to calculate the angle between the position/look vector of the camera, perhaps I'm doing something wrong or in the incorrect order?

Share this post


Link to post
Share on other sites
If you know the up and the forward vec, you can get the right vector via up cross forward. Then just fill your transformation matrix in colum major order and transform your points by that matrix.

Here's an example:

http://fileanchor.com/1283
BTW, 1,2,3,4,5 changes camera modes.

Share this post


Link to post
Share on other sites
Quote:
Original post by Name_Unknown
The dotproduct between the view dir and character facing direction will give you cos(theta).

Hmm, I must do something very wrong:)
When rendering my scene I place the character at the cameras target vector, so
shouldn't the direction the character is facing always be the same direction that the camera is facing?

// Cameras position
CVector3f vPos;
// Cameras view
CVector3f vView;
// Cameras up
CVector3f vUp;
// Forward
CVector3f vForward = vDir - vPos;
// Dotproduct
float theta = Dot(vForward,vPos);

What's wrong?

Share this post


Link to post
Share on other sites
Quote:
2float theta = Dot(vForward,vPos);
What's wrong?

2 things in that line
A/ neither variable is normalized
B/ ones a vector and the other is a position

just use gluLookAt(..)
eg
gluLookAT( person.x - person_direction.x*camdist, person.y + 10, person.z - person_direction.z*camdist, person.x,person.y, person.z, 0,1,0)

Share this post


Link to post
Share on other sites
It could also be a problem that theta is not Dot(A,B).
Dot(A,B) = |a||b|cos(theta) is so you need to take arccos(Dot(A,B)) (also known as cos inverse)

Share this post


Link to post
Share on other sites
Quote:
Original post by Brocketino
Quote:
Original post by Name_Unknown
The dotproduct between the view dir and character facing direction will give you cos(theta).

Hmm, I must do something very wrong:)
When rendering my scene I place the character at the cameras target vector, so
shouldn't the direction the character is facing always be the same direction that the camera is facing?

// Cameras position
CVector3f vPos;
// Cameras view
CVector3f vView;
// Cameras up
CVector3f vUp;
// Forward
CVector3f vForward = vDir - vPos;
// Dotproduct
float theta = Dot(vForward,vPos);

What's wrong?


1. Your theta is not the angle(It's just the projection but it gives the quadrant the angle is lying). You have to divide the dot by he magnitudes of both vforward and vpos:
ie:
cos(theta) = dot(vforward,vpos)/(mag(vpos) * mag(vforward))
Then use acos to get the actual angle in radians.

2. You know the orientation the object is supposed to look at. You dont have to rotate your model to orient it, instead you could fill an object matrix and transform your model with that matrix. That's what I did with the demo.

[Edited by - relsoft on July 28, 2005 2:16:12 AM]

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!