What is DOTS equivalent of UnityEngine TransformPoint, TransformDirection and TransformVector?

I am looking for DOTS based equivalent of
UnityEngine.Tansform

InverseTransformDirection(direction)

and

TransformDirection(direction)

Or custom functions of these two.
Any thoughts?

I haven’t used them myself yet but it looks like TransformAspect.TransformDirectionWorldToLocal() and TransformAspect.TransformDirectionLocalToWorld() respectively should do what you want

1 Like

There’s math.transform() for TransformPoint equivalent, as for the TransformDirection, I think its more like this:
https://discussions.unity.com/t/737484/10

Overall, its a matrix manipulation, so if you want, you can just take matrix and perform math.mul on it.
And if something is inverse, you’d just take inverse of that matrix and perform the same operation.

2 Likes

I will need to check these later and compare with UnityEngine transform. Thx.

That what I suspects so. But unsure, if I got right matrix manipulation. I was able to find many equations for UnityEngine. Vector3 for example, but it is much harder to find for Unity Engine.Transform functions.

I am converting some old OOP code.

1 Like

I’ve done this in a few places, looking through here’s an example of both ways.

//Get airflow localised values, clamp z value. This avoids physics-breaking spins when tailsliding.
float3 localAirflow = matrix4x4.inverse.MultiplyVector(relativeAirflow);

localAirflow.z = math.clamp(localAirflow.z, s.maxPositiveVelocity_ms, s.maxNegativeVelocity_ms); //TODO Make Variable

//Transform airflow back to world values
relativeAirflow = matrix4x4.MultiplyVector(localAirflow);

I got the matrix4x4 via:

//Get localToWorld matrix
Matrix4x4 matrix4x4 = Matrix4x4.identity;
matrix4x4 = localToWorld.Value;
1 Like

@Karearea , this is interesting. Seems getting results. Yet it operates on the Unity Engine math libraries using Matrix4x4, instead float4x4.

Did you hit any burst limitations to that?

Well as luck would have it, I think my technique is now broken in Entities 1.0 builds due to burst (ok in the editor). So I’d be interested to know of a solution too. Will try the solution from xVergilx’s link when I get a chance.

From the other thread, these all work well:

LocalPosition = math.transform(math.inverse(localToWorld.Value), WorldPostion)
WorldPostion = math.transform(localToWorld.Value, LocalPosition)

LocalVector = math.rotate(math.inverse(localToWorld.Value), WorldVector)
WorldVector = math.rotate(localToWorld.Value, LocalVector)

3 Likes

Hey again.
I would like say hips of thx for the answers.

And actually I would like to confirm @Karearea solutions, as I validated them on my side.

// UnityEngine.Transform InverseTransformPoint
localPosition = math.transform(math.inverse(localToWorld.Value), worldPostion)
// UnityEngine.Transform TransformPoint
worldPostion = math.transform(localToWorld.Value, localPosition)
// UnityEngine.Transform InverseTransformDirection
localVector = math.rotate(math.inverse(localToWorld.Value), worldDirection)
// UnityEngine.Transform TransformDirection
worldVector = math.rotate(localToWorld.Value, localDirection)

My one more question on the matter of transforms, for this to be complementary, what is the DOTS equivalent for
TransformVector and InverseTransformVector?

I am testing following and seems getting correct results.

// UnityEngine.Transform InverseTransformVector
float3 vDiff = targetPosition - refWorldPosition;
float3 worldVector = math.normalize(vDiff);
float3 localVector = math.rotate(math.inverse(refWorldRotation), worldVector);
// UnityEngine.Transform tnsformVector
float3 vDiff = targetPosition - refLocalPosition;
float3 localVector= math.normalize(vDiff);
float3 worldVector= math.rotate(refLocalRotation, localVector);
7 Likes