3

I am building an augmented reality application and I have the yaw, pitch, and roll for the camera. I want to start placing objects in the 3D environment. I want to make it so that when the user clicks, a 3D point pops up right where the camera is pointed (center of the 2D screen) and when the user moves, the point moves accordingly in 3D space. The camera does not change position, only orientation. Is there a proper way to recover the 3D location of this point? We can assume that all points are equidistant from the camera location.

I am able to accomplish this independently for two axes (OpenGL default orientation). This works for changes in the vertical axis:

x = -sin(pitch)
y = cos(pitch)
z = 0

This also works for changes in the horizontal axis:

x = 0
y = -sin(yaw)
z = cos(yaw)

I was thinking that I should just make combine into:

x = -sin(pitch)
y = sin(yaw) * cos(pitch) 
z = cos(yaw)

and that seems to be close, but not exactly correct. Any suggestions would be greatly appreciated!

Radford Parker
  • 731
  • 4
  • 14

1 Answers1

1

It sounds like you just want to convert from a rotation vector (pitch,yaw,roll) to a rotation matrix. The conversion can bee seen on the Wikipedia article on rotation matrices. The idea is that once you have constructed your matrix, to transform any point simply.

final_pos = rot_mat*initial_pose

where final and initial pose are 3x1 vectors and rot_mat is a 3x3 matrix.

Hammer
  • 10,109
  • 1
  • 36
  • 52
  • Thanks for the response. I understand what you are saying and I am actually doing this for some objects in my AR application, but these are being assigned a constant, arbitrary 3D location at compile time. The problem with your solution is that I don't know the initial position of where the points will go, which is what I am asking. I can get two out of three of the components of the initial position, but one axis is off a little bit. I want the user to be able to click anywhere on the 2D screen and project that point into the 3D environment by finding the proper initial position. – Radford Parker Sep 18 '12 at 21:54
  • 1
    ok, I seem to have misunderstood your question. If your problem is finding the 3d coordinates of an object corresponding to its 2d screen coordinates then what are the 3 equations you listed for? sin and cos only ever go from -1 to 1. Is that the domain of your world coordinates? Also, when you say all points can be assumed to be equidistant from the camera location do you mean along one axis or all axis? put another way, does the equidistant surface form a flat plane or a sphere surrounding the camera? – Hammer Sep 18 '12 at 22:24
  • I apologize for not making things more clear. I end up normalizing and multiplying all three values by 1000 to make sure every point's 3D location is spherically equidistant away from the camera. – Radford Parker Sep 19 '12 at 14:14
  • 1
    could you define your coordinate system? Is the camera pointing in the -z direction? Maybe I am still misunderstanding your question but it still sounds like you want a rotation matrix. Start with a point a distance of 1 from the camera along whatever axis you have defined pitch,yaw,roll to be 0, then transform it by the rotation matrix and multiply by 1000. That should give you a vector defined by the camera and the point, pointing in the direction defined by the rotation matrix and a magnitude of 1000 – Hammer Sep 19 '12 at 15:21
  • Yes, the look vector is -z and the up vector is +y. This is starting to make sense. Define the default point as (0, 0, -1) and then multiply that by the rotation matrix. I'll try that implementation as soon as I can. Thanks so much Hammer. – Radford Parker Sep 19 '12 at 19:10
  • Parker, I accomplished something similar. Remember to inverse your camera view matrix and then multiply it by (0,0,-1) to get a new position vector in world space. – flankechen Feb 11 '15 at 02:59