WorldToLocal and LocalToWorld relations

If I have this:
[lua]
p1, a1 = LocalToWorld(p2, a2, p3, a3)
[/lua]

I know p1, a1, p2 and a2. How do I calculate p3 and a3? I think it’s some combination of the functions mentioned, but I can’t figure out which one.

EDIT:

Found that
[lua]
p2, a2 == WorldToLocal(p1, a1, p3, a3)
[/lua]

Still doesn’t answer my question though:sigh:

Can you explain what p and a are?

position and angle

Position and angle?

Edit:

Uhh… what do I say here?

The question is totally ambiguous. Please explain what you’re trying to do.

p3 and a3 are your world positions/angles. Basically,


p1 = p2 + p3
a1 = a2 + a3

Correct me if I’m wrong.

Well, at one point in code I have access to the vectors p2 and p3 and the angles a2 and a3.
I use these in the function LocalToWorld() (as shown in OP) to get vector p1 and angle a1 which I store.

Then at another point in code I only have access to vector p1 and p2 and angle a1 and a2.
Though I need a way to calculate vector p3 and angle a3, using those 4 values. Do I need to explain more?

…Doing a little algebra, assuming my above post is correct we can deduce that:


p3 = p1 - p2
a3 = a1 - a2

Sorry to say it ain’t:frown:

Origin + local vector = world vector

What’s wrong with that?

You’re not taking the angles into account.

Origin + local angle = world angle

Plus angles don’t affect where the vectors are?

They do. The positions are local to the direction of the angle.

Ex: say the offset angle’s yaw is 0 and the offset vector’s x is 10, then the point will be ten units infront of the origin point, right? So far so good, BUT. If the offsets angle’s yaw would be let’s say 90, then the point would 10 units to the right of the origin point.
So yes, it does affect where the vectors are.

Can’t you help him masters of lua? :frowning: I see we won’t get GS2 this year…

Vectors are a direction and a magnitude bro. I’m failing Higher (A level) Physics, but I remember that. That means the vector will not the same as it should if you don’t take angles into account too.

I know vectors have direction, but I thought it was relative to the origin, and then angles simply add on to the direction without changing the position or vector direction.

World vectors are magnitudes and angles from the world origin (0,0,0)
Local vectors are magnitudes and angles from the origin of the parent (an entity)
Normal vectors are vectors that only show angles from the world origin

This function uses worldPosition and worldAngle to create the transform matrix. It then uses the inverse of that matrix to transform the first two arguments to local coordinate space.

This does the exact same thing. It creates a matrix from worldPosition and worldAngle. It then transforms the local position and angle to obtain the same points in world space.

The last two arguments are akin to the entity when you call Entity:WorldToLocal() or Entity:LocalToWorld(). You don’t calculate the last two arguments. You should know them. They have no relation to the first set of arguments you pass to the function, besides that they are used to build the transformation matrix.

Jinto is master, yay. I wonder this will help Ralle.

I feared this was the case:frown: Oh well, atleast I know for sure now, thanks!