Calculating a position specific to the camera
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.
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.
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.
www.flashbang.se | www.thegeekstate.com | nehe.gamedev.net | glAux fix for lesson 6 | [twitter]thegeekstate[/twitter]
if you are talking about cos and sin, then I give up. I am really bad at mathematics.
//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
{
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
-------------------LordsWarrior-------------------
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.
If at first you don't succeed, redefine success.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement