- Home /
Place object in front of me with given Translation Vector
Hi, I'm tracking a marker with OpenCV. I am given a Translation Vector of the markers position relative to the Camera. For example, Vec3<-0.2, 0.3, 3.0> means my marker is 0.2m to the left, 0.3m above and 3m in front of me. My Camera is the camera of a head mounted display, so it's basically where my head is. I want to place an object where the marker is located, so 3m in front of where I am currently looking (and the marker got detected), 0.2m to the left... and so on. I tried the following with x, y and z being the values of the TVector I get from the Markers position relative to my camera and obj being the transform I want to place at that position.
private void placeObjectAtPosition(Transform obj, float x, float y, float z)
{
Transform camT = Camera.main.transform;
obj.position = (camT.forward + new Vector3(0, 0, z)) + (camT.right + new Vector3(x, 0, 0) + (camT.up + new Vector3(0, y, 0)));
}
This does not work however, what am I doing wrong?
Your answer
Follow this Question
Related Questions
seperation of prefabs with two dimensional terrain generation 0 Answers
moving a transform by 10 but it goes exra... 1 Answer
Object with many children will not show up in the center although its coordinates are set to 0, 0, 0 1 Answer
How to make Camera position Independent of its Rotation? 1 Answer
Is there an elegant way of limiting camera's position? 1 Answer