Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use <a href="http://www.opengl.org/sdk/docs/man2/xhtml/gluUnProject.xml" rel="nofollow">gluUnproject</a> to map your cursor position from screen space into world space. By tracking the delta of the 3D world coordinates when the mouse button was first clicked to the current position (after dragging) this gives you the x,y&amp;z values you should use to translate your object.</p> <p>Also, it should be 'glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);'</p> <p>This is kind of off the top of my head and is psuedocodish. This doesn't take into account any selection or any of that. So, clicking down and moving the mouse would move the object even if the object wasn't under the mouse cursor when you clicked. You'll obviously need to add mouse handlers.</p> <pre><code>glm::dvec3 original_position;//position of object when we start moving glm::dvec3 world_anchor;//world space coordinates of where we left clicked glm::ivec2 screen_anchor;//screen space coordinates of where we left clicked Object object; OnLButtonDown(int x, int y)//x,y = where we clicked { original_position = object.GetPosition(); screen_anchor = ivec2(x,y);//screen coords where we clicked gluUnproject(x,y,0,modelview_matrix,projection_matrix,viewport,&amp;world_anchor.x, &amp;world_anchor.y,&amp;world_anchor.z); } OnMouseMove(int x, int y) //x,y = current mouse cursor position { if(left_button_down) MoveObject(screen_anchor.x-x,screen_anchor.y-y); } } MoveObject(int dx, int dy)//dx,dy = distance from current mouse position to screen_anchor { glm::dvec3 world_position;//current mouse position in world coordinates gluUnProject(dx,dy,0,modelview_matrix,projection_matrix,viewport,&amp;world_position.x, &amp;world_position.y,&amp;world_position.z); glm::dev3 world_delta = world_anchor-world_position; object.SetPosition(original_position+world_delta); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload