コード例 #1
0
        private CameraManager()
        {
            // camera mounting
            camera = TorqueObjectDatabase.Instance.FindObject<T2DSceneCamera>();

            if (camera != null)
            {
                if (camera.IsMounted)
                    camera.Dismount();

                camera.CameraWorldLimitMin = new Vector2(-1000, -1000);
                camera.CameraWorldLimitMax = new Vector2(1000, 1000);
                leashRange = new Vector2(20.0f, 20.0f);

                ParallaxManager.Instance.ParallaxTarget = camera;
                ProcessList.Instance.AddTickCallback(camera, this);
            }

            mountToObj = false;
            speed = 0.0f;
        }
コード例 #2
0
 public CameraManager(T2DSceneCamera camera)
 {
     this.camera = camera;
 }
コード例 #3
0
        ///<summary>
        ///Called when the owner is registered
        ///</summary>
        protected override bool _OnRegister(TorqueObject owner)
        {
            if (!base._OnRegister(owner) || !(owner is T2DSceneObject))
                return false;

            //todo: perform initialization for the component

            //todo: look up interfaces exposed by other components
            //E.g.,
            //_theirInterface =
            //     Owner.Components.GetInterface<ValueInterface<float>>(
            //         "float", "their interface name");

            //activate animation callback for this component.
            ProcessList.Instance.AddAnimationCallback(Owner, this);

            if (!CheckCamera)
                _camera =
                    TorqueObjectDatabase.Instance.FindObject<T2DSceneCamera>("Camera");

            //The following two lines are commented out so we could add a
            //the camera later. If there is no camera, the bounds checker has no
            //effect. If you uncomment the next two lines, we will fail if there
            //is no camera.
            //if (null == _camera)
            //  return false;

            return true;
        }
コード例 #4
0
        ///<summary>
        ///Called every frame.
        ///</summary>
        ///<param name="elapsed">
        ///The amount of elapsed time since the last call, in seconds.
        ///</param>
        public void UpdateAnimation(float elapsed)
        {
            if (CheckCamera)
                _camera = TorqueObjectDatabase.Instance.FindObject<T2DSceneCamera>("Camera");
            if (null == _camera)
                return;

            float minX = (UseCameraBounds ? _camera.SceneMin.X : 0) - MinOffset.X;
            float minY = (UseCameraBounds ? _camera.SceneMin.Y : 0) - MinOffset.Y;
            float maxX = (UseCameraBounds ? _camera.SceneMax.X : 0) + MaxOffset.X;
            float maxY = (UseCameraBounds ? _camera.SceneMax.Y : 0) + MaxOffset.Y;

            if (null != OnOutOfBounds &&
               (SceneObject.Position.X < minX - SceneObject.Size.X / 2.0f ||
               SceneObject.Position.X > maxX + SceneObject.Size.X / 2.0f ||
               SceneObject.Position.Y < minY - SceneObject.Size.Y / 2.0f ||
               SceneObject.Position.Y > maxY + SceneObject.Size.Y / 2.0f))
            {
                OnOutOfBounds(Owner);
            }

            if (null != OnAtBounds &&
               (SceneObject.Position.X < minX + SceneObject.Size.X / 2.0f ||
               SceneObject.Position.X > maxX - SceneObject.Size.X / 2.0f ||
               SceneObject.Position.Y < minY + SceneObject.Size.Y / 2.0f ||
               SceneObject.Position.Y > maxY - SceneObject.Size.Y / 2.0f))
            {
                OnAtBounds(Owner);
            }
        }
コード例 #5
0
ファイル: MyGame.cs プロジェクト: funkjunky/Raven
        ///<summary>
        ///Called after the graphics device is created and before the game is
        ///about to start running.
        ///</summary>
        protected override void BeginRun()
        {
            base.BeginRun();

            //load our scene objects from XML.  Torque X is designed to load
            //game data from XML, but this is not strictly required; anything
            //in an XML file can also be created manually in C# code.  The
            //SceneLoader is provided by TorqueGame and can be used to load
            //and unload XML files.
            //SceneLoader.Load(@"data\levels\EmptyLevel.txscene");

            T2DSceneGraph sceneGraph = new T2DSceneGraph(true);
            sceneGraph.Name = "DefaultSceneGraph";

            T2DSceneCamera camera = new T2DSceneCamera();
            camera.Name = "Camera";
            camera.CenterPosition = new Vector2(384, 384);
            camera.Extent = new Vector2(768, 768);
            camera.SceneGraph = sceneGraph;

            GUISceneview sceneview = new GUISceneview();
            sceneview.Name = "DefaultSceneView";
            sceneview.Camera = camera;

            if (null != Engine.SFXDevice)
            {
                _waveBank =
                    new WaveBank(Engine.SFXDevice, @"data\sounds\Sounds.xwb");
                _soundBank =
                    new SoundBank(Engine.SFXDevice, @"data\sounds\Sounds.xsb");
            }

            //Press escape on the keyboard or back on gamepad to exit game
            InputUtil.BindBackEscQuickExit();

            GamePaused = true;

            InitializeLibraries();

            GUILayout.Instance.Setup();

            //new GameManager(@"data\maps\RavenMap");
            //new GameManager(@"data\maps\RavenMapWithDoors");
            //new GameManager(@"data\maps\RavenMapWithDoorsAndItems");
            //new GameManager(@"data\maps\RavenMapWithDoorsAndItems2");
            new GameManager.GameManager(@"data\maps\mindcrafters");
        }
コード例 #6
0
        /// <summary>
        /// Called when the owner is registered
        /// </summary>
        protected override bool _OnRegister(TorqueObject owner)
        {
            if (!base._OnRegister(owner) || !(owner is T2DSceneObject))
                return false;

            // todo: perform initialization for the component

            // todo: look up interfaces exposed by other components
            // E.g.,
            // _theirInterface =
            //      Owner.Components.GetInterface<ValueInterface<float>>(
            //          "float", "their interface name");

            // store a reference to the camera (we're assuming the camera doesn't change)
            _camera = TorqueObjectDatabase.Instance.FindObject<T2DSceneCamera>("Camera");
            if (null == _camera)
                return false;

            return true;
        }
コード例 #7
0
        public Matrix GetShapeProjectionMatrix(T2DSceneCamera camera)
        {
            if (_shapeInstance == null)
                return Matrix.Identity;

            // Get the shape radius.
            float shapeRadius = _shapeInstance.GetShape().Radius;

            // What is the maximum scale in any axis.
            float maxAxisScale = Math.Max(Math.Max(_shapeScale.X, _shapeScale.Y), _shapeScale.Z);

            // Calculate a good zrange to use for the projection
            //
            // TODO: Need to properly calculate radius including mounted shapes.
            float zRange = shapeRadius * maxAxisScale * 4;

            // Create the projection for 3d.  We use the radius to ensure that
            // our near and far planes have enough range and do not clip on rotation.
            Matrix projection = GFXDevice.Instance.SetOrtho(false,
                -0.5f * camera.Extent.X, 0.5f * camera.Extent.X,
                -0.5f * camera.Extent.Y, 0.5f * camera.Extent.Y,
                -zRange, zRange);

            return projection;
        }