コード例 #1
0
        /// <summary>
        ///     Updates the camera movement.
        /// </summary>
        /// <param name="gameTime">The elapsed game time.</param>
        protected override void Update(TimeSpan gameTime)
        {
            if (this.currentState == State.Play || this.currentState == State.PlayAndRepeat)
            {
                bool isNext = this.path.Evaluate((int)(gameTime.Milliseconds * this.speed));

                if (isNext)
                {
                    this.currentCameraPoint = this.path.CurrentPoint;

                    // Manual inline: camera.Position = currentPoint.Position;
                    this.Camera.Position.X = this.currentCameraPoint.Position.X;
                    this.Camera.Position.Y = this.currentCameraPoint.Position.Y;
                    this.Camera.Position.Z = this.currentCameraPoint.Position.Z;

                    // Manual inline: camera.LookAt = currentPoint.LookAt;
                    this.Camera.LookAt.X = this.currentCameraPoint.LookAt.X;
                    this.Camera.LookAt.Y = this.currentCameraPoint.LookAt.Y;
                    this.Camera.LookAt.Z = this.currentCameraPoint.LookAt.Z;

                    // Manual inline: camera.UpVector = currentPoint.Up;
                    this.Camera.UpVector.X = this.currentCameraPoint.Up.X;
                    this.Camera.UpVector.Y = this.currentCameraPoint.Up.Y;
                    this.Camera.UpVector.Z = this.currentCameraPoint.Up.Z;
                }
                else
                {
                    this.currentState = State.Stop;
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///     Constructs an interpolated path based on the Key Frames.
        ///     Options are Linear or Cubic interpolation
        /// </summary>
        private void BuildPath()
        {
            this.currentPathPoints.Clear();

            // a point on a cubic spline is affected by every other point
            // so we need to build the cubic equations for each control point
            // by looking at the entire curve. This is what calculateCubicSpline does
            var looks     = new Vector3[this.keyFrames.Count];
            var positions = new Vector3[this.keyFrames.Count];
            var ups       = new Vector3[this.keyFrames.Count];

            for (int i = 0; i < this.keyFrames.Count; i++)
            {
                looks[i]     = this.keyFrames[i].LookAt;
                positions[i] = this.keyFrames[i].Position;
                ups[i]       = this.keyFrames[i].Up;
            }

            int count = this.keyFrames.Count - 1;

            Spline[] posCubic;
            Spline.CalculateCubicSpline(ref count, ref positions, out posCubic);
            Spline[] lookCubic;
            Spline.CalculateCubicSpline(ref count, ref looks, out lookCubic);
            Spline[] upCubic;
            Spline.CalculateCubicSpline(ref count, ref ups, out upCubic);

            for (int i = 0; i < this.keyFrames.Count - 1; i++)
            {
                for (int j = 0; j < this.pathSteps; j++)
                {
                    float k = j / (float)(this.pathSteps - 1);

                    Vector3 center = posCubic[i].GetPointOnSpline(k);
                    Vector3 up     = upCubic[i].GetPointOnSpline(k);
                    Vector3 look   = lookCubic[i].GetPointOnSpline(k);

                    var cam = new CameraPoint(ref center, ref look, ref up);
                    this.currentPathPoints.Add(cam);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Get the next point of the path.
        /// </summary>
        /// <param name="milliseconds">
        /// The milliseconds to advance in the path.
        /// </param>
        /// <returns>
        /// The next camera point in the path.
        /// </returns>
        public bool Evaluate(int milliseconds)
        {
            bool result = true;

            if (this.LoopEnabled)
            {
                this.camIndex = (this.camIndex + milliseconds) % this.currentPathPoints.Count;
            }
            else
            {
                this.camIndex = this.camIndex + milliseconds;
            }

            if (this.camIndex >= this.currentPathPoints.Count)
            {
                result = false;
            }
            else
            {
                this.CurrentPoint = this.currentPathPoints[this.camIndex];
            }

            return(result);
        }
コード例 #4
0
        /// <summary>
        ///     Updates the camera movement.
        /// </summary>
        /// <param name="gameTime">The elapsed game time.</param>
        protected override void Update(TimeSpan gameTime)
        {
            if (this.currentState == State.Play || this.currentState == State.PlayAndRepeat)
            {
                bool isNext = this.path.Evaluate((int)(gameTime.Milliseconds * this.speed));

                if (isNext)
                {
                    this.currentCameraPoint = this.path.CurrentPoint;

                    this.Camera.Position = this.currentCameraPoint.Position;
                    this.Camera.LookAt = this.currentCameraPoint.LookAt;
                    this.Camera.UpVector = this.currentCameraPoint.Up;
                }
                else
                {
                    this.currentState = State.Stop;
                }
            }
        }
コード例 #5
0
ファイル: MyScene.cs プロジェクト: pilotdes/DiceRoll
        protected override void CreateScene()
        {
            Physic3DCollisionGroup DiceCollisionGroup = new Physic3DCollisionGroup();
            Physic3DCollisionGroup TableCollisionGroup = new Physic3DCollisionGroup();
            TableCollisionGroup.DefineCollisionWith(DiceCollisionGroup);
            DiceCollisionGroup.DefineCollisionWith(TableCollisionGroup);

            RenderManager.DebugLines = false;

            physicsArgs = new Physic3DCollisionEventArgs();

            RenderManager.BackgroundColor = Color.CornflowerBlue;
            CameraPoint point1 = new CameraPoint();
            CameraPoint point2 = new CameraPoint();
            CameraPoint point3 = new CameraPoint();
            CameraPoint point4 = new CameraPoint();

            Entity ground = this.CreateGround();
            this.Createwalls();
            ground.FindComponent<RigidBody3D>().CollisionGroup = TableCollisionGroup;

            //var AnimationCamera = new PathCamera("AnimationCamera", new Vector3(0, 50, 80), Vector3.Zero, );
            //var beh = new PathCameraBehavior(new List<point1,point2,point3,point4>());

            //EntityManager.Add(AnimationCamera);
            PhysicsManager.Gravity3D = new Vector3(0, -9.8f, 0);

            Entity Die1 = new Entity("Die1")
                .AddComponent(new Transform3D())
                .AddComponent(new RigidBody3D()
                {
                    Restitution = GenRand(0.4, 0.7),
                    AngularVelocity = new Vector3(2.5f, 0, 0)
                })
                .AddComponent(new MeshCollider())
                .AddComponent(new Model("Content/Dice_LowPoly_OBJ.wpk"))
                .AddComponent(
                    new MaterialsMap(new BasicMaterial("Content/Red_Diffuse.wpk")
                    {
                        ReferenceAlpha = 0.5f
                    }))
                //.AddComponent(new MaterialsMap(new BasicMaterial(Color.Black)))
                .AddComponent(new ModelRenderer());
            float scale = .005f;
            Die1.FindComponent<Transform3D>().Scale.X = scale;
            Die1.FindComponent<Transform3D>().Scale.Y = scale;
            Die1.FindComponent<Transform3D>().Scale.Z = scale;
            Die1.FindComponent<Transform3D>().Position.Y = 2f;
            Die1.FindComponent<Transform3D>().Position.X = 0f;
            Die1.FindComponent<RigidBody3D>().CollisionGroup = DiceCollisionGroup;
            //Die1.FindComponent<RigidBody3D>().EnableContinuousContact = true;
            Die1.FindComponent<RigidBody3D>().LinearVelocity = new Vector3(Getrandom(), 0f, -3f);
            Die1.FindComponent<MeshCollider>().IsActive = true;
            Console.WriteLine(Die1.FindComponent<RigidBody3D>().Restitution);
            EntityManager.Add(Die1);
            Thread.Sleep(new TimeSpan(1000));

            Entity Die2 = new Entity("Die2")
                .AddComponent(new Transform3D())
                .AddComponent(new RigidBody3D() {Restitution = GenRand(0.4, 0.7)})
                .AddComponent(new MeshCollider())
                .AddComponent(new Model("Content/Dice_LowPoly_OBJ.wpk"))
                .AddComponent(
                    new MaterialsMap(new BasicMaterial("Content/White_Diffuse.wpk")
                    {
                        ReferenceAlpha = 0.5f
                    }))
                //.AddComponent(new MaterialsMap(new BasicMaterial(Color.Black)))
                .AddComponent(new ModelRenderer());
            Die2.FindComponent<Transform3D>().Scale.X = scale;
            Die2.FindComponent<Transform3D>().Scale.Y = scale;
            Die2.FindComponent<Transform3D>().Scale.Z = scale;
            Die2.FindComponent<Transform3D>().Position.Y = 2f;
            Die2.FindComponent<Transform3D>().Position.X = 1f;
            Die2.FindComponent<RigidBody3D>().LinearVelocity = new Vector3(Getrandom(), 0f, -3f);
            Die2.FindComponent<RigidBody3D>().CollisionGroup = DiceCollisionGroup;
            //Die1.FindComponent<RigidBody3D>().EnableContinuousContact = true;
            Die2.FindComponent<MeshCollider>().IsActive = true;
            Console.WriteLine(Die2.FindComponent<RigidBody3D>().Restitution);
            EntityManager.Add(Die2);

            //var mainCamera = new ViewCamera("MainCamera", new Vector3(0, 3, 0),
            //    new Vector3(Die1.FindComponent<Transform3D>().Position.X,
            //        Die1.FindComponent<Transform3D>().Position.Y, Die1.FindComponent<Transform3D>().Position.Z)); //xyz
            //EntityManager.Add(mainCamera);
            //RenderManager.SetActiveCamera(mainCamera.Entity);

            var mainCamera = new FreeCamera("MainCamera", new Vector3(-10, 3, 0), Vector3.Zero);
            // new Vector3(Die1.FindComponent<Transform3D>().Position.X,
            //Die1.FindComponent<Transform3D>().Position.Y, Die1.FindComponent<Transform3D>().Position.Z));
            EntityManager.Add(mainCamera);
            RenderManager.SetActiveCamera(mainCamera.Entity);

            //mainCamera.Entity.AddComponent(new Cam(Die1));

            this.AddSceneBehavior(new sb(), sb.Order.PostUpdate);
        }
コード例 #6
0
ファイル: Path.cs プロジェクト: joanjosepeivissa/Components
        /// <summary>
        ///     Constructs an interpolated path based on the Key Frames.
        ///     Options are Linear or Cubic interpolation
        /// </summary>
        private void BuildPath()
        {
            this.currentPathPoints.Clear();

            // a point on a cubic spline is affected by every other point
            // so we need to build the cubic equations for each control point
            // by looking at the entire curve. This is what calculateCubicSpline does
            var looks = new Vector3[this.keyFrames.Count];
            var positions = new Vector3[this.keyFrames.Count];
            var ups = new Vector3[this.keyFrames.Count];

            for (int i = 0; i < this.keyFrames.Count; i++)
            {
                looks[i] = this.keyFrames[i].LookAt;
                positions[i] = this.keyFrames[i].Position;
                ups[i] = this.keyFrames[i].Up;
            }

            int count = this.keyFrames.Count - 1;
            Spline[] posCubic;
            Spline.CalculateCubicSpline(ref count, ref positions, out posCubic);
            Spline[] lookCubic;
            Spline.CalculateCubicSpline(ref count, ref looks, out lookCubic);
            Spline[] upCubic;
            Spline.CalculateCubicSpline(ref count, ref ups, out upCubic);

            for (int i = 0; i < this.keyFrames.Count - 1; i++)
            {
                for (int j = 0; j < this.pathSteps; j++)
                {
                    float k = j / (float)(this.pathSteps - 1);

                    Vector3 center = posCubic[i].GetPointOnSpline(k);
                    Vector3 up = upCubic[i].GetPointOnSpline(k);
                    Vector3 look = lookCubic[i].GetPointOnSpline(k);

                    var cam = new CameraPoint(ref center, ref look, ref up);
                    this.currentPathPoints.Add(cam);
                }
            }
        }
コード例 #7
0
ファイル: Path.cs プロジェクト: joanjosepeivissa/Components
        /// <summary>
        /// Get the next point of the path.
        /// </summary>
        /// <param name="milliseconds">
        /// The milliseconds to advance in the path.
        /// </param>
        /// <returns>
        /// The next camera point in the path.
        /// </returns>
        public bool Evaluate(int milliseconds)
        {
            bool result = true;

            if (this.LoopEnabled)
            {
                this.camIndex = (this.camIndex + milliseconds) % this.currentPathPoints.Count;
            }
            else
            {
                this.camIndex = this.camIndex + milliseconds;
            }

            if (this.camIndex >= this.currentPathPoints.Count)
            {
                result = false;
            }
            else
            {
                this.CurrentPoint = this.currentPathPoints[this.camIndex];
            }

            return result;
        }