Sign in to follow this  
jjens

OpenGL Help with OpenGL model coordinates

Recommended Posts

Preface: I'm extremely new to OpenGL so please bear with me. I just signed on for some contract work on an open source project. The majority of my work is C++, which I know, but some of it revolves around OpenGL rendering, which I don't (using GLUT and GLUI). The program allows the user to take a 3d model and rotate, zoom, etc. It allows the user to click on the model and create a point, then click again and get the distance between the two points in 3D space. Right now this works by using the buffer to find the closest triangle to the click, then placing a dot in the exact center of that triangle. The problem with this is that although it's a very close approximation, it's not exact. It also doesn't allow someone to have two dots in the same triangle. So, I need a way to translate a click in one coordinate system (0,0 to x, x) to the model coordinate system (the standard +/- X, +/- Y, +/- Z system). This is similar to a thread currently on the front page about drawing a line "straight back". I'll still be finding the closest triangle, but using the x, y of the mouse click to draw straight back to the model and place a dot at the point of intersection on that nearest triangle. I guess my first question is whether this is easy or complicated? It's tough not knowing what you don't know. :P Any help or points in the right direction is appreciated.

Share this post


Link to post
Share on other sites
Quote:
Right now this works by using the buffer to find the closest triangle to the click, then placing a dot in the exact center of that triangle.
To what buffer are you referring?
Quote:
The problem with this is that although it's a very close approximation, it's not exact. It also doesn't allow someone to have two dots in the same triangle.
It sounds like you need to intersect a ray with the model in order to find an exact point of intersection. This will eliminate any inaccuracy, and will allow you to select points arbitrarily (e.g. two points on the same triangle).

It's not exactly trivial, but it's quite doable. You could probably also make use of an existing collision detection library to do some of the work for you.

How complex are these models? How many triangles on average?

Share this post


Link to post
Share on other sites
Quote:
Original post by jyk
Quote:
Right now this works by using the buffer to find the closest triangle to the click, then placing a dot in the exact center of that triangle.
To what buffer are you referring?


The code clears some memory and then executes this statement:

GLuint *ptr = selection_buffer;

And then uses ptr to cycle through until it finds the nearest triangle. I'm still working that one out, but I think it's fine right now to treat it as a black box as the triangle-finding part works fine.

Quote:
Quote:
The problem with this is that although it's a very close approximation, it's not exact. It also doesn't allow someone to have two dots in the same triangle.
It sounds like you need to intersect a ray with the model in order to find an exact point of intersection. This will eliminate any inaccuracy, and will allow you to select points arbitrarily (e.g. two points on the same triangle).

It's not exactly trivial, but it's quite doable. You could probably also make use of an existing collision detection library to do some of the work for you.

How complex are these models? How many triangles on average?


Intersecting a ray with the model sounds exactly like what I'd want to do. As far as libraries, I'd really prefer to not use another library since it's open source and not my project. The models are fairly complex, somewhere in the thousands of triangles.

I'm looking into the ray thing now - thanks for your help so far.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this