UltravioletFramework / ultraviolet

The Ultraviolet Framework is a .NET game development framework written in C#.
https://github.com/UltravioletFramework/ultraviolet/wiki
MIT License
542 stars 46 forks source link

Creating a matrix from a position, rotation and scale. #92

Closed stefnotch closed 6 years ago

stefnotch commented 6 years ago

Feature request:

A method to create a matrix from a position, rotation and scale. Creating everything individually is an option, however, the code is longer and it's far less efficient.

Example implementation:

public static Matrix Create(Vector3 Position, Quaternion Rotation, Vector3 Scale)
{
    float rotX2 = Rotation.X * 2;
    float rotY2 = Rotation.Y * 2;
    float rotZ2 = Rotation.Z * 2;

    float xx = Rotation.X * rotX2;
    float xy = Rotation.X * rotY2;
    float xz = Rotation.X * rotZ2;
    float yy = Rotation.Y * rotY2;
    float yz = Rotation.Y * rotZ2;
    float zz = Rotation.Z * rotZ2;
    float wx = Rotation.W * rotX2;
    float wy = Rotation.W * rotY2;
    float wz = Rotation.W * rotZ2;

    return new Matrix(
                (1 - (yy + zz)) * Scale.X,
                (xy + wz) * Scale.X,
                (xz - wy) * Scale.X,
                0,
                (xy - wz) * Scale.Y,
                (1 - (xx + zz)) * Scale.Y,
                (yz + wx) * Scale.Y,
                0,
                (xz + wy) * Scale.Z,
                (yz - wx) * Scale.Z,
                (1 - (xx + yy)) * Scale.Z,
                0,
                Position.X,
                Position.Y,
                Position.Z,
                1
            );
}
stefnotch commented 6 years ago

Matrix.CreateRotation(Quaternion q) would also be nice.

stefnotch commented 6 years ago

Actually, what I want is this: https://docs.flaxengine.com/api/FlaxEngine.Matrix.html

tlgkccampbell commented 6 years ago

Ultraviolet 2018.08 will include new CreateFromQuaternion(), CreateFromYawPitchRoll(), and CreateFromTranslationRotationScale() methods on the Matrix structure.