Results 1 to 2 of 2

Thread: Drawing on an object.

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2011

    Drawing on an object.

    I'm importing an object file, let's say it's a plane for example. I want to be able to draw on the plane and I just can't seem to figure out how it's done. It's fairly trivial to know the x and y coordinates of the mouse click but what about the z coordinate? I need to be able to do some sort of ray tracing that shoots out a ray and tells me as soon as it reaches the object. What I'm trying to know is the z coordinate of the click which is on the object. That there are no other objects in my space is a good assumption for now.

  2. #2
    Newbie Frequent Contributor
    Join Date
    Mar 2016

    Re: Drawing on an object.

    Transform the ray to object space coordinates for each object and test all triangles of the object for a intersection with the ray.
    There are many possibilities to make this more efficient, some are:
    - test the ray (in world coordinates) against the world space bounding volumes of the object
    - use a hierarchical data structure on top of the object's bounding volumes to discard whole groups of objects
    - if each object has a large number of triangles, use a hierarchical data structure for each object

    A different approach is to read the depth buffer at the mouse position and transform the value from there into whatever coordinate system you need (probably world coordinates?). If you have multiple objects you won't know which one was hit though. To get that information you can assign each object a unique color and render all objects in their assigned color (lighting off) into the back buffer (or an FBO). In addition to the depth buffer you also read back the color at the mouse position which then identifies the object as well.

Similar Threads

  1. Help with drawing a line that follows an object?
    By eratic-magician in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 04-07-2017, 03:43 PM
  2. Drawing object without VBO
    By MirzaSe in forum OpenGL ES
    Replies: 1
    Last Post: 09-27-2014, 10:30 PM
  3. Drawing behind another object
    By racumin in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-30-2009, 12:08 PM
  4. drawing 3D object
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-15-2004, 03:58 PM
  5. drawing an object on a dialog box
    By kausik in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 04-08-2000, 05:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean