Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

3 Dimensional Chat / Calculate new position

Author
Message
GMan
18
Years of Service
User Offline
Joined: 16th Sep 2006
Location: TEXAS
Posted: 14th Jan 2007 04:52 Edited at: 14th Jan 2007 04:53
This is a problem I am having for an OpenGL project. However, I felt it would be OK to post in this board, because it isn't Code specific at all, it has to do solely with math.

I need to calculate a location in 3D space that the camera will "look at", based on given x and y angles. NOTE: the angles are in radians.

So far I am calculating it like this:

pointy=sin(anglex);
pointx=sin(angley);
pointz=cos(angley);


for simplicity we will just assume the camera is at 0, 0, 0 and the location (pointx, pointy, pointz) is where the camera will be pointed at. The problem is with "pointz".

To sort of illustrate what the problem imagine that the camera is looking straight up. You can see from that code that it will calculate 1.0 for 'pointy' and it will calculate 0.0 for 'pointx'. However, because the pointz is based on the Y angle it will calculate 1.0 for 'pointz'. So the final point will be (0.0, 1.0, 1.0) As you can see this is not pointing directly up, it will be pointing at 45 degrees forward and up.


So basically I just need to know the actual MATH involved in calculating an new position based on an x and y angle.

The right man in the wrong place can make all the difference in the world.
GMan
18
Years of Service
User Offline
Joined: 16th Sep 2006
Location: TEXAS
Posted: 14th Jan 2007 20:20
Ok, I figured it out. I need a new variable and it should be calculated like this:

[i] pointy=sin(anglex);
temp=cos(anglex);
pointx=sin(angley)*temp;
pointz=cos(angley)*temp;

The right man in the wrong place can make all the difference in the world.

Login to post a reply

Server time is: 2024-11-26 16:44:37
Your offset time is: 2024-11-26 16:44:37