TX 2.0 3d Camera rotation
by David Everhart · in Torque X 2D · 07/26/2008 (10:07 pm) · 3 replies
Anyone know the method or way to get a camera to point downward at a 45 degree angle (like an isometric camera)? I have tried setting the RotationOffset and have also tried setting the Camera.SceneGroup.Rotation to no avail. Any help is appreciated.
#2
IsoCameraComponent camera = this.Components.FindComponent();
outside of ProcessTick(). You only need to get the camera once, so you can move this line to _OnRegister() instead of querying for the camera component every couple milliseconds. I've also added a new method to set the camera transform in the next Torque X release. That should help with the positioning.
John K.
07/30/2008 (9:30 am)
Looks like you're on the right track David. You should consider moving this....IsoCameraComponent camera = this.Components.FindComponent
outside of ProcessTick(). You only need to get the camera once, so you can move this line to _OnRegister() instead of querying for the camera component every couple milliseconds. I've also added a new method to set the camera transform in the next Torque X release. That should help with the positioning.
John K.
#3
Really looking forward to the 3d chapters in your upcoming book, so many things are still kind of confusing to me( like the groundtransformcomponenet which requires an _xmlstate?) . On the plus side, digging into the source is giving me a better idea of how everything interacts with everything else.
07/30/2008 (11:20 am)
Yah, I wondered about the performance hit of having it in there. Per your suggestion, I will probably move it to a private variable, and have it set in the on register peice. Having a method to set the camera transform would be very nice. Really looking forward to the 3d chapters in your upcoming book, so many things are still kind of confusing to me( like the groundtransformcomponenet which requires an _xmlstate?) . On the plus side, digging into the source is giving me a better idea of how everything interacts with everything else.
Torque Owner David Everhart
using System; using System.Collections.Generic; using System.Text; using GarageGames.Torque.T3D; using Microsoft.Xna.Framework; namespace StarterGame3D { /// <summary> /// An isometric camera /// </summary> public class IsoCameraComponent : T3DCameraComponent { public void Update() { this.RotatedPositionOffset = RotatedPositionOffset + Vector3.Zero; } protected override void _UpdateTransform() { base._UpdateTransform(); } } }After creating this class, I set it up in the xml:<TorqueObject type="GarageGames.Torque.Core.TorqueObject" name="IsoCamera"> <Components> <CameraComponent type="StarterGame3D.IsoCameraComponent" name="CameraComponent"> <FarDistance>3000</FarDistance> <FOV>1.57</FOV> </CameraComponent> <SceneComponent type="GarageGames.Torque.T3D.T3DSceneComponent"> <Position> <X>1024</X> <Y>1024</Y> <Z>300</Z> </Position> </SceneComponent> </Components> </TorqueObject>At this point, I have a camera, but none of the features are set yet. I am not too familiar with the playermanager and all its caveats, so I dont use it at the moment. Instead, I created a basic PlayerComponent:
using System; using System.Collections.Generic; using System.Text; using GarageGames.Torque.Core; using GarageGames.Torque.Sim; using GarageGames.Torque.T3D; using Microsoft.Xna.Framework; namespace StarterGame3D { public class PlayerComponent :TorqueObject,ITickObject { public void ProcessTick(Move move, float dt) { IsoCameraComponent camera = this.Components.FindComponent<IsoCameraComponent>(); camera.Update(); } public void InterpolateTick(float dt) { } } }Its just a basic class that handles a process tick. All it does is get the camera component that is attached to it, then calls its update. I read on a previous post, that the camera will not auto follow the component it is attached to. However, to work around it, you just have it call the update function of the camera component, and it will track.Now to attach the camera to the player component, I used the following:
public void CreatePlayer() { //create the Player object PlayerComponent objPlayer = new PlayerComponent(); objPlayer.Name = "CurrentPlayer"; IsoCameraComponent isoCamera = TorqueObjectDatabase.Instance.FindObject<IsoCameraComponent>("CameraComponent"); isoCamera.PositionOffset = new Vector3(0f, -20f, 35f); isoCamera.RotationOffset = new Vector3(-45f, 0f, 0f); isoCamera.RotatedPositionOffset = new Vector3(0, 0, 0); isoCamera.SceneGroupName = "CurrentPlayer"; //create the render component T3DTSRenderComponent componentRender = new T3DTSRenderComponent(); componentRender.ShapeName = @"data\Skeleton\test.dts"; componentRender.SceneGroupName = "CurrentPlayer"; //create the scene component T3DSceneComponent componentScene = new T3DSceneComponent(); componentScene.Position = new Vector3(1024, 1024, 260); componentScene.SceneGroup = "CurrentPlayer"; // Create the RigidManager RigidCollisionManager rigidManager = TorqueObjectDatabase.Instance.FindObject<RigidCollisionManager>("RigidManager"); //define a proper collision shape CollisionBoxShape collisionShape = new CollisionBoxShape(); collisionShape.Size = new Vector3(4.95f,1f,4.2f); collisionShape.Center = new Vector3(0,-.1f,2f); T3DRigidComponent componentPhysics = new T3DRigidComponent(); componentPhysics.SceneGroupName = "CurrentPlayer"; componentPhysics.GravityScale = 1f; componentPhysics.Mass = 30.0f; componentPhysics.RigidManager = rigidManager; componentPhysics.RotationScale = 0f; componentPhysics.CollisionBody.AddCollisionShape(collisionShape); componentPhysics.RenderCollisionBounds = true; //add both of the components objPlayer.Components.AddComponent(componentRender); objPlayer.Components.AddComponent(componentScene); objPlayer.Components.AddComponent(componentPhysics); objPlayer.Components.AddComponent(isoCamera); //register the object TorqueObjectDatabase.Instance.Register(objPlayer); collisionShape.OnLoaded(objPlayer); ProcessList.Instance.AddTickCallback(objPlayer); }This will position the camera in a isometric view (perhaps not a true isometric, but close enough for now for testing). Below is a test shot:
This is prototype to see if I could get it going. I plan on adding a freelook camera, and inputmaps that allow for toggling between the cameras.