Ejemplo n.º 1
0
        /// <summary>
        /// Computes current position and orientation in the curve
        /// </summary>
        /// <param name="gameTime">Game time</param>
        /// <param name="manipulator">Manipulator to update</param>
        public override void UpdateManipulator(GameTime gameTime, Manipulator3D manipulator)
        {
            if (this.HasPath)
            {
                var   target    = this.path.GetNextControlPoint(this.path.Length);
                var   position  = manipulator.Position;
                float dToTarget = (target - position).Length();

                if (dToTarget > this.ArrivingThreshold)
                {
                    float maxSpeed = this.MaximumSpeed * gameTime.ElapsedSeconds;

                    this.pathTime += maxSpeed;

                    var next = this.path.GetPosition(this.pathTime);
                    this.Velocity = next - position;

                    manipulator.SetPosition(next, true);
                    manipulator.LookAt(next + this.Velocity, false, 0, true);
                }
                else
                {
                    this.Clear();
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets a new manipulator to this instance
        /// </summary>
        /// <param name="manipulator">Manipulator</param>
        public void SetManipulator(Manipulator3D manipulator)
        {
            this.Manipulator.Updated -= ManipulatorUpdated;
            this.Manipulator          = null;

            this.Manipulator          = manipulator;
            this.Manipulator.Updated += ManipulatorUpdated;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="scene">Scene</param>
        /// <param name="description">Description</param>
        public Cubemap(Scene scene, CubemapDescription description)
            : base(scene, description)
        {
            this.Manipulator = new Manipulator3D();

            this.InitializeBuffers(description.Name, description.Geometry, description.ReverseFaces);
            this.InitializeTexture(description.ContentPath, description.Texture);
        }
        /// <summary>
        /// Updates the manipulator's view and position
        /// </summary>
        /// <param name="gameTime">Game time</param>
        /// <param name="manipulator">Manipulator</param>
        public override void UpdateManipulator(GameTime gameTime, Manipulator3D manipulator)
        {
            if (this.HasPath)
            {
                var   target    = this.path.GetNextControlPoint(this.path.Length);
                var   position  = manipulator.Position;
                float dToTarget = (target - position).Length();

                if (dToTarget > this.ArrivingThreshold)
                {
                    float maxSpeed = this.MaximumSpeed * gameTime.ElapsedSeconds;
                    float maxForce = this.MaximumForce * gameTime.ElapsedSeconds;

                    var next = this.path.GetNextControlPoint(this.pathTime + maxSpeed);

                    // A vector pointing from the location to the target
                    var   desired = (next - position);
                    float dToNext = desired.Length();
                    if (dToNext != 0)
                    {
                        if (dToTarget < this.ArrivingRadius)
                        {
                            var m = Map(dToTarget, 0, this.ArrivingRadius, 0, maxSpeed);
                            desired = Vector3.Normalize(desired) * m;
                        }
                        else
                        {
                            desired = Vector3.Normalize(desired) * maxSpeed;
                        }

                        // Steering = Desired minus Velocity
                        var steer = desired - this.Velocity;

                        // Limit to maximum steering force
                        steer = steer.Limit(maxForce);

                        // Update velocity
                        this.Velocity += steer;

                        // Limit speed
                        this.Velocity = this.Velocity.Limit(maxSpeed);

                        this.pathTime += this.Velocity.Length();
                        var newPosition = this.path.GetPosition(this.pathTime);
                        var newNormal   = this.path.GetNormal(this.pathTime);

                        manipulator.SetPosition(newPosition, true);
                        manipulator.LookAt(newPosition + (newPosition - position), newNormal, true, 0.1f);
                    }
                }
                else
                {
                    this.Clear();
                }
            }
        }
Ejemplo n.º 5
0
 public CameraFollower(Manipulator3D manipulator, Vector3 position, Vector3 view)
 {
     this.manipulator    = manipulator;
     this.positionOffset = position;
     this.viewOffset     = view;
 }
Ejemplo n.º 6
0
 public CameraFollower(Manipulator3D manipulator)
 {
     this.manipulator = manipulator;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="parent">Parent manipulator</param>
 public Manipulator3D(Manipulator3D parent) : this()
 {
     this.Parent = parent;
 }