# Replacement for Transform.Transformpoint in Dots

Discussion in 'Data Oriented Technology Stack' started by calabi, Feb 14, 2020 at 11:10 PM.

1. ### calabi

Joined:
Oct 29, 2009
Posts:
118
I'm trying to convert some code from one of Catlike codes tutorials. I'm wondering what the equivalent to Transform.Transformpoint would be in Dots. I'm no good at maths and havent a clue about transform matrices so I have no hope of figuring it out on my own any help would be appreciated.

This is the code I'm trying to convert into a job.

Code (CSharp):
1.   public Vector3 GetVelocity (float t) {
2.               return transform.TransformPoint(Bezier.GetFirstDerivative(points, points, points, t)) - transform.position;
3.            }
Bezier.GetFirstDerivative() is converted to this.

Code (CSharp):
1. float oneMinusT = 1f - placeonSpline;
2. float3  wtfevenisthis = 3f * oneMinusT * oneMinusT * (Bezpoint1 - Bezpoint0) + 6f * oneMinusT * placeonSpline * (Bezpoint2 - Bezpoint1) + 3f * placeonSpline * placeonSpline * (Bezpoint3 - Bezpoint2);
So I need to do something like this in the job Transform.TransformPoint(wtfevenisthis - translation) except clearly not using Transformpoint.

2. ### snacktime

Joined:
Apr 15, 2013
Posts:
2,555
You just need to know the basics. float4x4.TRS will give you a transformation matrix. Here are a couple of extension methods illustrating conversion.

Code (csharp):
1.
2. public static float3 WorldToLocal(this float4x4 transform, float3 point)
3.         {
4.             return math.transform(math.inverse(transform), point);
5.         }
6.
7.         public static float3 LocalToWorld(this float4x4 transform, float3 point)
8.         {
9.             return math.transform(transform, point);
10.         }
11.
12.

florianhanke likes this.
3. ### calabi

Joined:
Oct 29, 2009
Posts:
118
I think I see, I think I understand now. Transformpoint, is already taking the transform of the object, so I'm transforming that with the other point. Thanks a lot.

4. ### calabi

Joined:
Oct 29, 2009
Posts:
118
Really sorry to be a pain but I'm not sure I really do get it. The whole point is to get the direction of the Bezier. So that when objects are moving along that Bezier they point in that direction. I've got the below code with some help from the Discord. I presume the 1 value would be the scale so I would also need to get the scale of the entity.

var yourTRS = float4x4.TRS(thispos.Value, enitityrotate.Value, 1);
float4 resultPoint = math.mul(yourTRS, wtfevenisthis);

The resultPoint equation math.mul() doesn't work I presume because the second variable is a float3. But then how do I even get a float3 from these because that's what I need a float3 to get the direction.

5. ### 5argon

Joined:
Jun 10, 2013
Posts:
1,482
Here are steps to understand this :

- First you should look up matrix multiplication. Then you will learn that a side matters in matrix multiplication, and a 4x4 matrix * 4x1 matrix = 4x1 matrix. And it is not possible to multiply 2 matrices where col of the left one doesn't match row of the right one.
- Then search about first derivative and slope. Then you will learn that it can represent a direction at a given point on the function.
- Then look up about CG and transformation matrix, why a 4x4 matrix could move and rotate your point. You should make up a point and try multiplying by hand and see where it goes.
- Then search about homogenous coordinate why you need a 4x4 matrix in the first place. This will answer your mismatched size required for matrix multiplication.

Then use DOTS Mathematics function (in below comment from @Opeth001) to solve what you need : You need a point transformed to look in direction according to slope, and also translate to that position you got the slope from, so it stick to the curve.

tertle likes this.

Joined:
Jan 28, 2017
Posts:
537
7. ### calabi

Joined:
Oct 29, 2009
Posts:
118
Ok, thanks everyone, I will be back (if), when I've solved this. unityunity