I am trying to make 3D drawing software. I wanted to have the drag feature so I am using object picking using the OBB algorithm. I am facing problems in understanding the algorithm, and my implementation thus is having bugs.

How do I implement object picking, using OBB in OpenGL? As I am new to OpenGL (free-glut library), a step by step explanation would be helpful.

  • \$\begingroup\$ Given that this question self admits no relation to video game development (3D drawing software is an entirely differant ballpark), this question would probably be better directed towards the Computer Graphics Stack Exchange. \$\endgroup\$
    – Gnemlock
    Mar 25 '17 at 9:18

First you have to implement AABB picking with AABB-ray intersection test. Picking an OBB is then achieved by transforming the ray inside the OBB's local space and doing an intersection test with an unit AABB - local ray. Transforming the ray into the OBB local space is done by transforming the ray origin and ray direction by the inverse of the OBB's transformation matrix.

To get a picking ray, you have to unproject your pick position (mouse position) to the camera near and far planes by transforming it by the inverse view projection matrix. Something like this:

vector3 near = vector3(mouse.xy,0,1) * matInverseVP;
vector3 far = vector3(mouse.xy,1,1) * matInverseVP;
vector3 rayOrigin = near;
vector3 rayDirection = normalize(far - near);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .