• Advertisement
Sign in to follow this  

Calculating a position specific to the camera

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

The camera has free 3d movement. It holds a view vector and a position vector like so CVector3 pos; CVector3 view; so the position may be x = 10.0f, y = 10.0f, z = 50.0f and view may be x = 10.0f, y = 15.0f, z = 40.0f Doesn't really matter what the positions are, when you press forward, the camera moves towards the view vector. Pretty basic camera class. 1.0f is equal to 1 meter in my project. Now, I need to find out the position that is 4 meters to left of the camera, and 1.5 meters to the front of the camera. I think there is an easy way to find this, but I am missing it. Any help is appreciated.

Share this post


Link to post
Share on other sites
Advertisement
it's a bit complicated as you thought.
To move sideways(strafe) you need to know your side vector.
to know the side vector when you only have the front vector you need the up vector and then do a crossproduct to get the side vector.

alternatively you store the view vector as angles(degrees) and then convert it into front side and up vectors later when you need them using cos and sin.

Share this post


Link to post
Share on other sites
//left
{
xpos -= (float)sin((heading+90)*piover180) * (0.05f*speed);
zpos -= (float)cos((heading+90)*piover180) * (0.05f*speed);
}

//right
{
xpos += (float)sin((heading+90)*piover180) * (0.05f*speed);
zpos += (float)cos((heading+90)*piover180) * (0.05f*speed);
}

My modification for strafing based on NEHE lesson 10 (I think).


The (0.05f*speed) is just a speed variable. I have a key that increases/decreases speed (default speed = 1).

-LW

Share this post


Link to post
Share on other sites
Quote:
Original post by leggyguy
The camera has free 3d movement.

It holds a view vector and a position vector like so

CVector3 pos;
CVector3 view;

so the position may be x = 10.0f, y = 10.0f, z = 50.0f

and view may be x = 10.0f, y = 15.0f, z = 40.0f

Doesn't really matter what the positions are, when you press forward, the camera moves towards the view vector. Pretty basic camera class.

1.0f is equal to 1 meter in my project.

Now, I need to find out the position that is 4 meters to left of the camera, and 1.5 meters to the front of the camera.

I think there is an easy way to find this, but I am missing it.

Any help is appreciated.


The easiest way to do this is to build a complete camera frame, and use the basis vectors to calculate what you want. You have the view vector, all you need now are the up and side vectors.

To calculate the side vector, use some arbitary up vector ( [0,1,0] for instance ), and use side = up x front. Once the side vector has been calculated, you can find the true up vector, though it's not important in this application.

Now you need to normalise the front and side vectors. Once done, you can calculate the vector from the camera position, to the position that you want, by doing: 4 * side + 1.5 * front.

To get the absolute position ( i.e, not in the cameras frame ), then also add the camera's position vector.

Share this post


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

  • Advertisement