Skip to content

Performance convert Matrix4x4 into float4x4 #223

Open
@YomYomNuts

Description

@YomYomNuts

I spot a little improve to convert Matrix4x4 into float4x4
In the current version:
public static implicit operator float4x4(Matrix4x4 m) { return new float4x4(m.GetColumn(0), m.GetColumn(1), m.GetColumn(2), m.GetColumn(3)); }
My suggestion:
public static implicit operator float4x4(Matrix4x4 m) { return new float4x4(m.m00, m.m01, m.m02, m.m03, m.m10, m.m11, m.m12, m.m13, m.m20, m.m21, m.m22, m.m23, m.m30, m.m31, m.m32, m.m33); }

In the current version, you call the column to give you an Vector4 that you convert by an implicit cast into a float4. For the construction, that's not very efficient, i think it's because you want to use a "mirror" function with the cast float4x4 into Matrix4x4

Guillaume

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions