Question on axis rotation
Hello everyone
I have some mathematic problem I just can't solve, since I'm an absolute maths noob ;)
Within my Tilebased 3D Engine I implemented an option to scroll the map with holding down the middle mousebutton and moving the mouse around. The scrollingspeed is calculated through the difference between the "here I clicked middle mousebutton" and "this is where the cursor is now" x/y coordinates.
The scrolling itself is simply done by in-/decrementing the speed amount of two variables: MapRelx and MapRely - these are the beginning coordinates of my map, which looks like this:
Picture
(never mind the messy sprites, that's another problem I'm working on ;))
The red arrows show, how the map would move, if I used my middle mousebutton (MapRelx/y are also shown) - works just fine.
BUT - When I rotate the map around the z-axis, I just can't figure out how to properly modify MapRelx/y so that the map would move like the blue arrows below would show.
Cause at the moment, it would move like the red arrows show, which is kind of weird.
Another Picture
I guess it's some simple sin/cos/tan stuff, but since I really don't have a slightiest notion of maths at all, I would really appreciate any help.
Thanks in advance
As you are posting in NeHe, I suppose you are using OpenGL, then, putting a glRotatef(Angle, 0 0 1) then a glTranslatef(x, y, z) should work just fine...
But, if you want to calculate it by your own:
Increasing by 'k' the rotated X axis would increase (k * cos(Angle)) on X and (k * sin(Angle)) on Y
and increasing by 'k' the rotated Y axis would increase (-k * sin(Angle)) on X (notice the minus sign) and (k * cos(Angle)) on Y
Hope it works :)
But, if you want to calculate it by your own:
Increasing by 'k' the rotated X axis would increase (k * cos(Angle)) on X and (k * sin(Angle)) on Y
and increasing by 'k' the rotated Y axis would increase (-k * sin(Angle)) on X (notice the minus sign) and (k * cos(Angle)) on Y
Hope it works :)
error C2065: 'signature' : undeclared identifier
I would say, create a vector (I'll call it nextPosition) like this: {MapRelX, 0.0f, MapRelY}, then rotate that vector by the angle of the camera. Finally, add nextPosition to the camera's current position. I don't know much (scratch that, anything) about OpenGL, but this method should work with any 3D library. Good luck!
Thanks a lot - the sin/cos calculation works just fine :D
How would I rotate a Vector? I'd like to try out that solution too.
How would I rotate a Vector? I'd like to try out that solution too.
Rotating a vector can get a little more complicated... I think the easiest way would be using matrices
This might be a good start point
3D Matrix Math Demystified
Note: if you are planning to do something in 3d you will probably end up having to use matrices anyway as those sin/cos have many limitations
This might be a good start point
3D Matrix Math Demystified
Note: if you are planning to do something in 3d you will probably end up having to use matrices anyway as those sin/cos have many limitations
error C2065: 'signature' : undeclared identifier
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement