Results 1 to 2 of 2

Thread: ray intersection point

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2011
    Posts
    3

    ray intersection point

    hi, i did something like this:

    i have some objects vertices stored in arrays verts[100][100][4] with verts[#][#][0] = x, verts[#][#][1] = y, verts[#][#][2] = z i also have normals but im not sure if i'll need though

    i have a mouse function that shoots a ray when i click the screen and im sure that is working right. i used gluunproject to figure that out. then, i made functions for my sphere and cylinder objects that use the quadratic equation to see if a ray hits it. this is working. if i have some sphere at (5, 0, 0) and cylinder at (0,5, 0) it is tested and returns a hit with the ray.

    now my problem is to find the point of intersection. i have run the ray direction vector, and origin vector into inverse transformation of the object so it is in "object coordinates" and i think my code is right for that. now i have to find the nearest point on my object that the ray intersects with.

    i do not understand how to use my vertices and these ray vectors in object coordinates to find the nearest point ,or any point for that matter.

    i assume i use some for loops to loop through my vertices but i dont understand what i compare it too.

    im a noob at this stuff but have slowly gotten my way this far only to get stuck here for the past day.

    can someone please explain what i should do now or even give some pseudocode. i'd really appreciate it


    also i have the 't' value that returned from the quadratic equation. do i use that to get the point somehow?

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    Re: ray intersection point

    Hi sa0sin,
    Since you are doing intersection with a couple of objects, you should use the minimum t value. So in pseudo code it is something along these lines.
    Code :
    #include <limits> //for numeric limits::infinity
    float tmin = numeric_limits<float>::infinity();
    float t = tmin;
    for each object o
       if(intersects(o, ray, &amp;t))
          if(t<tmin) {
             tmin = t;
          }
    end for
    This gives you the nearest point t value. Now the point of intersection is simply
    Code :
    vec3 hit_point = ray.origin + tmin*ray.direction;
    Regards,
    Mobeen

Similar Threads

  1. AABB-Triangle intersection point
    By overTaker in forum OpenGL: General
    Replies: 5
    Last Post: 04-17-2014, 09:41 AM
  2. Point of intersection inside 3D triangle?
    By stargazer in forum OpenGL: General
    Replies: 1
    Last Post: 07-28-2005, 08:55 PM
  3. How to get an intersection point
    By wir33658 in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 04-01-2003, 11:55 PM
  4. Ray-point intersection
    By vitaliy in forum OpenGL: Advanced Coding
    Replies: 6
    Last Post: 07-11-2002, 06:31 AM
  5. point intersection?
    By screwtape in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 04-16-2001, 11:46 PM

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