Game Development Community

3D object Direction

by Will O-Reagan · in Torque X 2D · 05/07/2008 (5:18 pm) · 1 replies

Is there a way to set a direction, or get a direction, of my Camera? in a Vector 3?

About the author

I have a degree in dramatic art, and literature, from UC Santa Barbara. I've worked for a few studios, also at Animax Ent in 2008, and some smaller studios. Currently studying Computer Science at CSU Channel Islands.


#1
05/07/2008 (7:21 pm)
The view matrix is the camera's inverted transform, so I assume that the camera's transform would move the camera from 0,0,0 facing 0,1,0 and with up being 0,0,1.

So that would make the camera's facing direction:

Vector3 forward = new Vector3(0.0f, 1.0f, 0.0f) //because torque uses Y-forward, Z-up the Vector3.Up and Vector3.Forward are wrong

Vector3 camDir = Vector3.Transform(forward, camera.Transform);

If you want the camera to face an object and be a certain distance from it, just attach it to the object and give it a position offset (distance from object). Or you can calculate the camera's transform manually if you like. Take that object's transform, apply some translation to it (for example negative Y to move away from the object), then use that for the camera's transform.

Note that you would probably need to take the object's transform, save off and zero out the translation giving you rotationMatrix, then take the original transform and add Vector3.Transform(cameraOffset, rotationMatrix). That way instead of moving negative Y you will move backwards from the object, no matter which way it is rotated.