Rotate FreeCamera
by Dave DAmico · in Torque X 2D · 01/06/2009 (11:58 am) · 7 replies
I'm having trouble setting the rotation of a FreeCameraComponent. I can set the value but for some reason on the next iteration of the draw loop it is back at zero. I've created two properties to setting position and rotation. Position works fine, rotation does not:
public Vector3 TransitionPosition
{
get
{
if (Owner != null)
{
T3DSceneComponent scene = Owner.Components.FindComponent<T3DSceneComponent>();
if (scene != null)
{
return scene.Position;
}
else return Vector3.Zero;
}
else
return Vector3.Zero;
}
set
{
if (Owner != null)
{
T3DSceneComponent scene = Owner.Components.FindComponent<T3DSceneComponent>();
if (scene != null)
{
scene.Position = value;
}
}
}
}
public Vector3 TransitionRotation
{
get
{
if (Owner != null)
{
T3DSceneComponent scene = Owner.Components.FindComponent<T3DSceneComponent>();
if (scene != null)
{
return Helper.YawPitchRollFromQuaternion(scene.Rotation);
}
else return Vector3.Zero;
}
else
return Vector3.Zero;
}
set
{
if (Owner != null)
{
T3DSceneComponent scene = Owner.Components.FindComponent<T3DSceneComponent>();
if (scene != null)
{
scene.Rotation = Quaternion.CreateFromYawPitchRoll(value.Y, value.X, value.Z);
}
}
}
}About the author
#2
01/12/2009 (7:46 am)
What if I don't have the Pro version? :)
#3
1. Create your own 3D component using the new 3D Component - call it "MyCameraComponent"
2. Change its class declaration to: public class MyCameraComponent : FreeCameraComponent
3. Add the public SetTransform() method exactly as listed above
4. Change your code (or levelData.txscene) to use MyCameraComponent instead of FreeCameraComponent
And off you go... That should do the trick, even if you do not have the pro version.
John K.
01/12/2009 (11:29 pm)
Hmmm. What about sub-classing it and exposing it anyway? Afterall C# is an object-oriented language...1. Create your own 3D component using the new 3D Component - call it "MyCameraComponent"
2. Change its class declaration to: public class MyCameraComponent : FreeCameraComponent
3. Add the public SetTransform() method exactly as listed above
4. Change your code (or levelData.txscene) to use MyCameraComponent instead of FreeCameraComponent
And off you go... That should do the trick, even if you do not have the pro version.
John K.
#4
01/13/2009 (8:17 am)
Thanks for the reply John. However, i'm still having the same problem, my rotation setter looks like this now:set
{
if (Owner != null)
{
T3DSceneComponent scene = Owner.Components.FindComponent<T3DSceneComponent>();
if (scene != null)
{
Matrix m = Matrix.CreateFromYawPitchRoll(value.Y, value.X, value.Z);
SetTransform(m, false);
}
}
}
#5
John K.
www.envygames.com
01/18/2009 (9:51 pm)
Hmmm... That should do it. You've set a break point and confirmed this code is reached? Is there something else fighting for control over the camera? For example, if you have a movement component attached to an object, it may be resetting the camera position.John K.
www.envygames.com
#6
01/19/2009 (7:10 am)
Yes it is definitly hitting the code. I was thinking the same thing about another component is fighting over rotation. I'll have to do some more testing... thanks John.
#7
01/20/2009 (12:14 pm)
I created a new project that just has the FreeCameraComponent. I changed the FreeCameraComponent to the camera component that I created that has the properties listed above. The results are the same... only the position is updated even if I use the set transform method in the rotation setter.
Associate John Kanalakis
EnvyGames
public void SetTransform(Matrix NewTransform, bool UpdateTransform) { _transform = NewTransform; if (UpdateTransform) _UpdateTransform(); }John K.