Archived

This topic is now archived and is closed to further replies.

CProgrammer

Rotation

Recommended Posts

CProgrammer    303
Say i have a camera in 3d-space looking at the origin and i can rotate it around the x, y and z axis. How would i have to rotate it according to how the arrow keys are pressed to make it look good? -CProgrammer

Share this post


Link to post
Share on other sites
Trienco    2555
quote:
Original post by CProgrammer
Say i have a camera in 3d-space looking at the origin and i can rotate it around the x, y and z axis.



which axis? world or camera? which point? origin or cameras position?

quote:

How would i have to rotate it according to how the arrow keys are pressed to make it look good?


add some random rotation and marvel about the results. sorry, but "to look good" isnt exactly a description that helps to understand how and around what it should rotate and "good looking" means to you.

Share this post


Link to post
Share on other sites
iNsAn1tY    476
You're talking about a form of linear interpolation. You'll have the camera's current position, and the amount by which the camera moves around the axes every second if the button is held down (say it takes 5 seconds to move through 360 degrees: step = 360.0f / 5.0f = 72.0f). In your button down function for the y axis, for example, add the following code:
yAngle += step * time;  
Alternatively, you can do true linear interpolation. You'd have two angles per axis, the camera's current angle, and the new angle as input by the user using the keys. You can then interpolate like so:
currAngle[0] += (newAngle[0] - currAngle[0]) * time;
currAngle[1] += (newAngle[1] - currAngle[1]) * time;
currAngle[2] += (newAngle[2] - currAngle[2]) * time;
Figuring out the time for each frame isn't too hard, and this method ensures that all your movement is completely smooth and controllable, no matter what the frame rate. However, note that the newAngle variable must stay the same until currAngle equals newAngle. Then you process some more input, and start over again...



Coding Stuff ->  [ iNsAn1tY Games | DarkVertex | How To Do CSG | Direct3D Vs. OpenGL | Google ]
Fun Stuff    ->  [ Evil T-Shirts | Stick-Based Comedy | You're Already Here | The Best Film Reviews ]


[edited by - iNsAn1tY on September 1, 2003 11:14:55 AM]

Share this post


Link to post
Share on other sites
drekkar    122
this is on loading/moving through a 3d world
probably has what you're looking for

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=10


[edited by - drekkar on September 1, 2003 12:36:18 PM]

Share this post


Link to post
Share on other sites
CProgrammer    303
Thanks for all the answers.
However i i think i didn''t explain the problem in enough detail.

Ok here goes:
I have a model sitting in the origin and a camera at position [0,0,-100]. Now i want to use the arrowkeys to move the camera around the origin. Meaning that the camera will always look at the origin and it will always have the distance 100 of the camera.
The effect should pretty much be the same as rotating the object.
For the camera movement i have 3 functions which can rotate the position of the camera around the 3 axis.
The problem is that theres only two set of keys but three axis around which i can rotate. If i just roate around y-axis with right-left and x-axis with up-down than that wont work smoothly.

Hope i clarifyed the problem.

-CProgrammer

Share this post


Link to post
Share on other sites
CodeJunkie    144
Here's an article you might find useful.

Or you may have to use a Spherical coordinate system to move the camera. I don't know how difficult implementing it will be.

I hope you find a solution.

[edit] spelin

[edited by - CodeJunkie on September 2, 2003 8:33:14 AM]

Share this post


Link to post
Share on other sites