# Calculating a position specific to the camera

This topic is 5041 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
Anyone able to help? Or is this really more complicated than it seems?

##### Share on other sites
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 on other sites
if you are talking about cos and sin, then I give up. I am really bad at mathematics.

##### 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 on other sites
Quote:
 Original post by leggyguyThe camera has free 3d movement. It holds a view vector and a position vector like soCVector3 pos;CVector3 view;so the position may be x = 10.0f, y = 10.0f, z = 50.0fand view may be x = 10.0f, y = 15.0f, z = 40.0fDoesn'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.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 13
• 9
• 9
• 34
• 16
• ### Forum Statistics

• Total Topics
634124
• Total Posts
3015661
×