Exemplo n.º 1
0
        /// <summary>
        /// Makes this <see cref="GameElement"/> look at the given <paramref name="targetPosition"/>.
        /// </summary>
        /// <param name="targetPosition">The target translation to look at.</param>
        public void LookAt(Point3f targetPosition)
        {
            Matrix4f lookAtMatrix   = Matrix4f.LookAt(Position, targetPosition, UpVector);
            Matrix4f transformation = Matrix4f.CreateTranslation(Translation);
            Matrix4f ret            = (lookAtMatrix * transformation);

            Vector3f direction = Point3f.CreateVector(targetPosition, Position);

            Vector3f rotation = ret.GetEulerAngles();

            if (direction.Z <= 0)
            {
                rotation.Y *= -1;
            }
            if (direction.Z == 0 && direction.Y == 0 && direction.X != 0)
            {
                rotation.Y = MathHelper.PiOver2 * (direction.X < 0 ? 1 : (direction.X > 0 ? -1 : 0));
            }
            if (direction.Z == 0 && direction.X == 0 && direction.Y != 0)
            {
                rotation.X = MathHelper.PiOver2 * (direction.Y < 0 ? 1 : (direction.Y > 0 ? -1 : 0));
            }

            Rotation = rotation;
            //LookAt(Point3f.CreateVector(targetPosition, Position));
        }
Exemplo n.º 2
0
        public override void Update()
        {
            if (_innerRigidBody != null && _shouldUpdate)
            {
                Collider  c = _geCollider;
                Transform t = gameElement.WorldTransform;
                // _innerRigidBody.MotionState.WorldTransform = (Matrix)t.GetTransformation();
                // .ActivationState == ActivationState.ActiveTag ? activeColor : passiveColor
                Matrix4f transform = _rbWorldTransfom;
                //gameElement.LocalTransform.Move(transform.GetTranslate());
                //gameElement.LocalTransform.Rotate(transform.GetEulerAngles());

                Vector3f
                    newT   = transform.GetTranslate(),
                    newR   = transform.GetEulerAngles(),
                    deltaT = newT - _lastTranslate,
                    deltaR = newR - _lastRotate;

                gameElement.LocalTransform.SetTranslation(newT);
                gameElement.LocalTransform.SetRotation(newR);

                _lastRotate    = newR;
                _lastTranslate = newT;

                _shouldUpdate = false;
            }
        }