I am trying to figure out a way to create a new node that converts a vector to a given object space coordinate.
In practice, Translate Object uses the vector i want the Vector Out to return, but i can’t figure out how to get this working.
The functionality of this node is: If you use Set Object Location using the converted coodinates, the location will be applied as the object is parented to the reference object, but it is not.
If someone have an idea of how to achieve this, i would be grateful. Maybe already there is a way to do this in nodes, but i don’t know.
I can achieve this by creating an input for Relative Object in Translate Object node. The problem is that this way is very limited (because can be used only for Translate Object).
In translate object, if you check the On Local Axis checkbox, the translate method will be applied related to the direction of the object, you just need to select another object (that is the reference object) and set the camera object (or its axis object) in this case, and the character will move relatively to the camera.
I only want to know the math behind this method, to convert a given vector to a object space and apply it where it is needed. I will take a deeper look as soon i can, but maybe someone already know how to achieve this.
How to convert a world space coordinate into an object space coordinate?
If you answer this question, then for this you need
Child World Coordinat = Parent + Child (because they are relative to the parent).
For example objects Parent (10, 15, 20) and Child (-2, 3, 4).
The coordinates of Child in the world will be (8, 18, 24) because we are adding them.
Would you like to set Child by world coordinates? Child = Value - Parent
For example, let’s set Child in world coordinates to point (3, 7, 9). As a result, we get the coordinates of Child (7, -8, -11).
All directions (look, up, right) are determined by the transformation matrices of the object.
The camera is defined as follows:
public inline function right(): Vec4 { return new Vec4(transform.local._00, transform.local._01, transform.local._02); }
public inline function up(): Vec4 { return new Vec4(transform.local._10, transform.local._11, transform.local._12); }
public inline function look(): Vec4 { return new Vec4(-transform.local._20, -transform.local._21, -transform.local._22); }
The matrices themselves (view, perspective) are calculated in the buildMatrix() function. Study classes CameraObject, Transform in folder [ArmorySDK_path]\iron\Sources\iron\object.
I think it is what i am looking for, but i am getting Unknown identifier : getLocalVecFromWorld. Did i miss something? (i am using a custom node to test, i don’t know if this change anything)
Can i achieve this trough the function you send? I think this is some math with the Look, Up and Right vectors but i can’t even approach the result. I have sure that i am doing it in the wrong way.
If you want to use it, you first need to import that class. But instead it makes much more sense to use it as a Static Extension which is an awesome feature of Haxe. At the beginning of your file (usually after the imports) you simply write:
using armory.object.TransformExtension;
and then you can use it directly on transform objects (the first parameter is automatically set from the object it is called on):
// the first parameter is automatically set, you just pass the second one
reference.transform.getLocalVecFromWorld(vecIn);
I’m not entirely sure what you want. If you don’t use the move() function, it won’t move. So just take the parameter.
Or do you want to have a vector that’s vec.y times into the look() direction for example? Then just multiply both together (scalar * vector = vector). look() gives you a new vector object so if you use mult() on it, it won’t change the look direction, only that vector object.