how to get an objects position in another object's coordinate system THREE.js - coordinates

I have created a THREE.Scene, and within the scene there is an THREE.Object3D() that is a new 'coordinate system'.
Inside this object there is a particle with a certain position.
I understand that getting a this particle's position from the object's 'coordinate System' into the Scene's 'coordinate systems' requires the following
//Gives particle position in scene coordinates
particle.position.applyMatrix4(Object.matrixWorld)
What would be the inverse transformation though?
(aka, the particle is in the Scene's 'coordinate system' and I want to find its position in the objects 'coordinate system')

The inverse transformation of the transform you referred to can be calculated like so:
var mInverse = new THREE.Matrix4().getInverse( object.matrixWorld );
particle.position.applyMatrix4( mInverse );
three.js r.55

Related

How to get the absolute position of a child entity in bevy?

I am using the Bevy game engine.
The ability to have transforms be propagated to children in Bevy is handy, but when I am performing collision checks in my game, I have been using the object's Translation to compute its location. Now that I have some parent-child hierarchies in my scene, the Translation of each child entity is relative to its parent.
Is there a way to get the position of an entity relative to the world origin as opposed to the entity's parent?
The "world" position is stored in the GlobalTransform component. Transforms internally are 4x4 matrices where the translation() function returns the position. You can access it like this:
fn system(global_transform: &GlobalTransform) {
let position = global_transform.translation();
}

Accessing the Mesh from the Hololens trough the Holotoolkit

I am currently developing a Unity project for the HoloLens. For this I am using the Spatial Mapping Observer and the Spatial Mapping Manager from the HoloToolkit. I need to access the spatial Mesh, in particular the vertices in the mesh. Now my questions are:
How does the HoloLens handle meshes? To get access to all vertices I need to loop first trough the mesh list and then trough every mesh to get them. Why does the Spatial Mapping Manager provide me with several meshes?
In what coordinate frame are those vertices? If I want the relative distance from one vertex to the camera can I just subtract the camera position in world frame from the vertex position? Is the vertex in world frame?
Thank you very much for your time!
The Spatial Mapping mesh will automatically be on layer 31, so with a simple layermask you can get it.
Why does the Spatial Mapping Manager provide me with several meshes?
Unity only handles meshes up to ~2^16 vertices/faces, so when it gets bigger than this it will be split up.
In what coordinate frame are those vertices?
As far as I know they are not in any special coordinate frame, just the normal unity-coordinates.
If I want the relative distance from one vertex to the camera can I just subtract the camera position in world frame from the vertex position?
Yes, I think a Vector3.Distance should work. You can get the position of your main camera with Camera.mainCamera.gameObject.transform.position.

Positions of objects in the scene

My hierarchy of game objects is as follow.
Display(Scene)
Model(-4.708, 1.55, 14.4277)
Pass(4.7080, -1.5, -14.42)
handle(-0.0236,0.65690,0.149)
shaft(5.34,-1.0225,-0.1489)
head(-7.0912,-9.62,-0.5231)​
ball(0,0,0)
We can see Model and its coordinate on the image. Ball has position (0,0,0), but why it is located at the base of the Model?
How can I locate ball just beside the head?
Sounds like the origin point of one or more of the models is at off.
You can adjust this in 3d modelling software, or by making an empty game object inside unity and making your object a child of that object, then using the empty game object as the new origin point, you can adjust the positions of the child objects you assign to it.

Does having Root Motion applied prevent moving a transform position relative to world coordinates?

I have "GameObject 0" (GO0) with an animation controller that used parameters to transform states and is used as a wrapper for "GameObject 1"(GO1). "GameObject 1" has an animation controller that has Root Motion applied. Within GO1 there are 3 game objects whos animation is in the same animation clip as GO1.
This allows me to place GO1 in world coordinates and animate GO1's children in local coordinates to maintain relative positioning.
However, I am wish to move one of the children of GO1 to a world coordinate that is not relative to GO1. I have used script and Vector3.Lerp / Vector3.MoveTowards functions, but they are not working as expected. Is the Root Motion interfering with the Lerps?
I have change the script to add a new parent to the child object and animating the new parent. This seems to work but the rotation of the new parent is causing a new issue.

How can find Center of circle to Unity?

I have circle, and I'm trying to find center and convert to Vector2.
For example:
circleLocation : new Rect( Screen.width/10, Screen.height/2.75, Screen.width/3,Screen.width/3);
centerofcirle:New Vector2(circleLocation.width/3, circleLocation.height/3);
But this example's not correct, the circle is not turn center. What is this formula? How can find correct center of cirle and how to convert Vector2?
Reading between the lines here, I wonder if issue has nothing to do with your code here, but with the rotation point of your steering wheel object, which isn't where you want it to be.
A common technique to change the rotation point of a game object is to make that object the child of another game object in the Unity Editor. Then set the position of the child object as you wish relative to the position of the parent object. Now, rotate the parent object. The child object will automatically rotate around the parent object's position, since it's transform (including position/rotation) is relative to it's parent's.
You seem to be defining your circle using a Rect so just use the Rect.center property:
circleLocation.center;