Skip to main content
gamedev.net
🔒 Locked

Making objects look at camera

Started by lost_wolf Apr 26, 2006 at 12:29 PM 2 replies 600+ views
Original Post
lost_wolf
lost_wolf
I would like to make a set of objects look at and follow the cameras motion inside of the 3d world. I'm using gluLookAt() to define where my camera is and thus have the location and where the camera is looking stored. I know how to do this using Trig, but before i go through all that i was wondering if there is a faster way to do it? xxx Trig calcs whenever the camera moves isn't that appealing to me...
It is not god who created us. But us who created god, for we are the ones with the power to create and destroy entire universes, we are the ones with the power to imagine and forget.
Zakwayda
Zakwayda
Quote:
Original post by lost_wolf
I would like to make a set of objects look at and follow the cameras motion inside of the 3d world. I'm using gluLookAt() to define where my camera is and thus have the location and where the camera is looking stored. I know how to do this using Trig, but before i go through all that i was wondering if there is a faster way to do it? xxx Trig calcs whenever the camera moves isn't that appealing to me...
Don't worry about the trig functions; they're unlikely to be a bottleneck. There are other ways to do it though that don't involve trig. What method to use basically depends on what sort of behavior you want, such as:

1. Should the objects follow the target exactly, or 'lag' behind if the target moves quickly
2. Does the world have a fixed up vector for reference, or is it a no-fixed-up environment such as a space sim

If you need more specific suggestions, perhaps you could describe what the objects are, exactly what sort of behavior you want them to have, and so on.
lost_wolf
lost_wolf
I'm going to have a fixed up vector, I don't see the need for a non-fixed right now in my current project (even though with the way i was working out the trig calcs, this has no purpose in having objects look at the camera...). Right now i'm playing around with 2 triangular prisms counting as eyes and i want the eyes to constantly look at the camera without lagging. There are some other similar things I want to do, but they will all follow the same behavior.

I don't want them to look where the camera is looking or anything like that, i want them to look directly at the camera, i have a box being drawn to represent all of my cameras in the scene.
It is not god who created us. But us who created god, for we are the ones with the power to create and destroy entire universes, we are the ones with the power to imagine and forget.
Zakwayda
Zakwayda
I would just do a simple aim-at matrix. To see how to compute the basis vectors, you can look here. For reasons I won't go into, everything but the translation part of the DX example is already what you want for your OpenGL matrix. The only difference is that the position of the object should go in the right-most column (elements 12, 13 and 14), and the bottom row should be [ 0 0 0 1 ].

I skipped over a few details, so ask if you need more info.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.