Problems to align camera
by AIDan · in Torque X 3D · 05/14/2009 (4:15 pm) · 3 replies
I have a camera which derives from T3DCameraComponent.
I want my camera to look at the target _controlledObject.SceneGroup.Position.
SceneGroup.Rotation= Quaternion.CreateFromRotationMatrix( Matrix.CreateLookAt(SceneGroup.Position, _controlledObject.SceneGroup.Position, _controlledObject.SceneGroup.Transform.Up) );
When I try this I get really strange results and I wonder why it does not work. Any ideas?
I want my camera to look at the target _controlledObject.SceneGroup.Position.
SceneGroup.Rotation= Quaternion.CreateFromRotationMatrix( Matrix.CreateLookAt(SceneGroup.Position, _controlledObject.SceneGroup.Position, _controlledObject.SceneGroup.Transform.Up) );
When I try this I get really strange results and I wonder why it does not work. Any ideas?
About the author
#2
05/15/2009 (8:14 am)
It appears to me that the problem seems to be related to the different coordination system used by Torque. Does Torque has its own methods to create a rotation matrix?
#3
05/17/2009 (10:07 am)
I finally got the look at stuff right by using MatrixUtil.CreateAimedTransform. But now I still have to set the up vector so the camera is always correctly aligned. Does anyone know where on the camera I can set that?
Torque Owner AIDan
All the offsets are set to zero.
Strangely My camera focuses the object correctly at the beginning when I do the following:
SceneGroup.Rotation= Quaternion.CreateFromRotationMatrix( Matrix.CreateWorld(Vector3.Zero, Vector3.Cross(Vector3.Normalize(_controlledObject.SceneGroup.Position - SceneGroup.Position), Vector3.Right), Vector3.Up) );
I wonder why this Cross is required. Makes no sense to me but it works.
When I rotate the object my camera should keep looking at it which it still does not.