Jump to content
  • Advertisement

Archived

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

BrokenNails

Camera Rotation aka "Beating head against wall"

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

RTS style here. Trying to rotate the camera about the vertical axis (Z in my case) while staying focussed on a single point (ie the camera and it''s direct line of sight to a point on the terrain would carve out a lovely cone shape when doing a full rotation). Camera implemented using the standard 3 vectors (eye, lookAt, and up). Anyway, I thought the following pseudo code (I''m at work so pseudo''s all I''ve got) was what I was after, but it only works when the lookAt vector is at the origin. If it''s not then things tend to rotate in an odd fashion: (a, b, and c are matrices) a = Translate(new Vector3(0,0,0) - lookat_vector) //translate back to the origin b = RotateZ(angle) // Rotate about vertical (z) axis c = Translate(lookat_vector) //translate back to original position eye_vector.transform(a * b * c) up_vector.transform(a * b * c) Is there something blindingly obvious I''m doing wrong here? I think I''m beyond the point where I am thinking rationally... :-)

Share this post


Link to post
Share on other sites
Advertisement
I might be wrong here, especially if I am misunderstanding you but to recap.

You are standing at Point xyz
You are looking at point(in the distance) xyz
You want to do a 360 turn around that point correct?

If so then I beleive what you want to do is rotate the camera around that point as its origin(not the real origin).

So translate to that point rotateaxis(y) in this case, and then translate back to your the distance you were from the "look at point", but not on the exact same spot. I think you could do that by subtracting the vectors to get the distance, then translating the camera to the point of "look" rotate it around the y, then take that "point" and translate back the distance you were before.

or maybe I got that backwards on what you want to rotate. Maybe all you want to do is rotate the "world" around that point, instead of its original origin.

Grr hope I haven't confused you more :-(
Trying to help, maybe my ramblings did if not :-( i'll try again

[edited by - 3dxd on June 3, 2004 4:17:08 PM]

Share this post


Link to post
Share on other sites
Wouldn't it be easier to just position the camera and use a standard lookat function to set its orientation? Something like:
    eye.x = r * cos( a );
eye.y = r * sin( a );
eye.z = h;
camera.lookat( eye, lookat, up );



John Bolton
Page 44 Studios
Current project: NHL Faceoff 2005 PS2


[edited by - JohnBolton on June 3, 2004 4:19:55 PM]

Share this post


Link to post
Share on other sites
Errr, maybe?

Yes, I have the camera at point x,y,z (my eye_vector).
The camera looks at point x,y,z (the lookAt_vector).

And yes, I want to rotate the camera around that (lookAt) point.

Maybe my explanantion of what I was doing wasn''t particularly clear. I was under the impression that the API call RotateZ (or Y depending on what your vertical axis is) did a rotation about that axis at the origin. But since I want my camera to rotate about the lookAt point rather than the origin I figured that translating the camera by the lookAt vector would effectively move the lookAt point to the true origin so I could rotate correctly.

Hmmm, not sure if that''s made things clearer or not??? Reading your post again I *think* we''re talking about the same thing....

Share this post


Link to post
Share on other sites
John:
Yeah, I think that''s what I''m *trying* to do. It''s the "position camera" bit that''s tripping me up.

Your equations look fairly painless. Maybe I''ll give that a go rather than messing with the matrices...

Share this post


Link to post
Share on other sites
I actually meant rotateAxis which is one function different then rotatey/z/x etc.

It allows for an arbitrary axis, but Johns suggestion works great, unless you want the camera to move to other areas of the map and then, based on a certain "keystroke" pan around.

of course you can just move things around the camera(positioned) and then use that special key to pan.

Share this post


Link to post
Share on other sites
what you want to do is this.

Starting from the origin, translate the camera to the distance that it will be away from the object. Then rotate it along the same plane, then rotate it on the perpindicular plane. Then translate it out to the objects actual position.

That should give you the proper camera angle.



-Dazz

Share this post


Link to post
Share on other sites
Right. Well reading all these replies (which I *do* appreciate) I feel like I'm not too far off the mark. Let me just explain using an example to see if I'm understanding this correctly. Bear with me... :-)

Assuming left hand coords and y axis is vertical/height.

Say the camera is at (1,1,1) and the point it is looking at is (1,0,0). I want to move the camera 90 degrees to the left (rotating about the lookAt point).

Now just using my brain it seems to me that the camera will end up at (2,1,0) yes? If not then I'll just move to 2D as I clearly have no place meddling in 3D matters...

Now how to do this in code:
I would have thought to translate the camera pos so that the rotation axis passed through the origin. This would require a translation of (-1,0,0) ie the reversed lookAt vector.

The camera is now at (0,1,1). We do a simple rotation about the y/vertical axis using, say, RotationY(pi/2) (positive or negative - can't remember).

This leaves the camera at (1,1,0). We then reverse the earlier translation ie now (1,0,0), which takes the camera to (2,1,0) which is where my hand-waving, brain visualisation would have placed it.

This is the theory upon which I was basing my code that was so badly described in the initial post.

Am I way off base here?

Again, appreciate all the assistance.

[edited by - BrokenNails on June 3, 2004 7:50:44 PM]

Share this post


Link to post
Share on other sites
Just occured to me:

Perhaps performing the translation..rotation..translation transform on the up_vector isn''t such a smart idea. Rotation yes, translation no...

Gotta try this when I get home.

Share this post


Link to post
Share on other sites
I think what you want are polar/spherical coordinates.

Try this:

http://mathworld.wolfram.com/PolarCoordinates.html

http://mathworld.wolfram.com/SphericalCoordinates.html


Hope those help. They change from x,y,z into two angles. You could then use those to do your rotations.

Translate by the negative position vector. Rotate by up axis, then by x axis.

Hope this helps, its been a while since i did this.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!