OpenGL Project/UnProject

Kattmat
Unregistered
 
Post: #1
I'm currently working on a 3d modeler (or in the exploratory stage of it, at least), and I'm wondering how to do this.
I'm using both ortho and perspective cameras. Ortho for the front/back/left/right/top etc views, and perspective for the isometric view.
I need to be able to put out vertices with the mouse in both the perspective and orthographic views. I need to get 3d coordinates from a 2d click, so to speak.

I know this is done by unprojecting using gluUnProject, but believe me, I've tried everything human posible with this stuff and I just can't get it to work. With errors ranging from waaay out of position on either one or two or all axises, or with only minimal changes when I click (like from 0.00015 to 0.00030 ranging from left to right of the entire view, when the real change should be about 100.0 units).

Anyone have a solution (in code would be a thrill) to this problem?

Huge thanks in advance, guys!
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
in a 2d view on a 3d space, every 2d point represents a 3d line.

use gluUnProject with z = 0 to get the 3d coordinate of that line at the near plane
use gluUnProject with z = 1 to get the 3d coordinate of that line at the far plane

that gives you two points on the line, and therefore implicitly its equation.

From there, where on the line you decide to place the point is up to you Smile
Quote this message in a reply
Kattmat
Unregistered
 
Post: #3
so THAT'S why they get all wrong when I just change the Z-value. Rolleyes
Thanks a bunch, man. Smile
Quote this message in a reply
Kattmat
Unregistered
 
Post: #4
Hm. I just tried it out.
gluUnProject((GLdouble)point.x, (GLdouble)point.y, 0.0, modelview, projection, viewport, ...);
gluUnProject((GLdouble)point.x, (GLdouble)point.y, 1.0, modelview, projection, viewport, ...);

but the thing is, the two values returned from both of them are identical. Could that, perchance, have anything to do with me being in orthographic mode? Should I first switch to perspective view, check the positions and stuff, and then switch back?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
er, they return 3 values...
Quote this message in a reply
Kattmat
Unregistered
 
Post: #6
What I mean is that when I take (x1 - x2) * scale, i get zero. Same with the y axis. The x1 and x2 values are the same. How come?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #7
seems likely that you're looking straight down the z axis...
Quote this message in a reply
Kattmat
Unregistered
 
Post: #8
Then why is the x and y values wrong? (Not when I subtact and shit, but before that)
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL ES 2.0 Problems - Senior Project Thread Zammy 3 4,571 Mar 16, 2010 12:32 PM
Last Post: arekkusu
  Setting Up An OpenGL project JohnDoe555 2 2,879 Sep 30, 2005 10:39 PM
Last Post: JohnDoe555
  PB SDL OpenGL Project mars 6 3,773 Jun 29, 2003 08:51 PM
Last Post: mars