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
        /// <summary>
        /// Returns the transformation matrix of this <see cref="GameElement"/>.
        /// </summary>
        public Matrix4f GetTransformation()
        {
            Matrix4f t = Matrix4f.CreateTranslation(_translation);
            Matrix4f r = Matrix4f.CreateRotation(_rotation);
            Matrix4f s = Matrix4f.CreateScale(_scale);

            return(s * r * t);
        }
Exemplo n.º 3
0
 private void _setViewMatrix()
 {
     _viewMatrix = Matrix4f.CreateTranslation(-gameElement.WorldTransform.Translation) * Matrix4f.LookAt(_forward, _up);
 }