Xanas
09-19-2005, 02:46 PM
I'm pretty sure this is the function I want, basically what I'm doing is I'm using the selection rendermode to select the object that I want, and then using gluUnproject to grab opengl world coordinates so I can move the object there. The problem is I'm in perspective viewmode gluPerspective(45.0, width/height, 0.1, 100.0); and so I basically need to figure out how to calculate values along the line (vector? ) that goes from 0.0, 0.0, 0.0 (presuming that's camera position in world coordinates anyway, but this may be something else i need to know.. it could be 0.1..).
Anyway, as you can see I don't know very much. I've just been doing opengl tutorials lately and some redbook/bluebook stuff as well trying to pickup how to use it. I'm progressing ok, but I've been out of school for awhile so I've forgotten a lot of the maths and it's really not that easy to get back into it without examples :) I was pretty good at math back then I should be able to relearn but it's been long enough that just hearing it outright sounds confusing.
So if someone is willing i could use some help in understanding exactly how I would calculate a specific point on the line. I'm sure it's easy to those still doing math constantly but a bit confusing to someone who hasn't done it in a few years.
If you are interested in the relavent code I have so far it'd be
void PositionGLObject(int mousex, mousey){
GLfloat x, y, z; // allocate memory for the x, y, z position
GLint viewport[4]; //stores viewport information
GLdouble modmatrix[16], projmatrix[16];
glGetIntegerv(GL_VIEWPORT, viewport); //transfers viewport info into viewport array.
glGetDoublev(GL_PROJECTION_MATRIX, projmatrix);
glGetDoublev(GL_MODELVIEW_MATRIX, modmatrix);
// invert mousey so that down lowers value
mousey = viewport[3] - mousey;
gluUnProject((GLdouble) mousex, (GLdouble) mousey, 1.0, projmatrix, modmatrix, &x, &y, &z);
cout<<"X: "<<x<<"Y: "<<y<<"Z: "<<z<<endl; //print out values
}
Feel free to correct me if I'm doing anything wrong there! Basically I'm just going to set a global variable during the function that will move the object around. I'm doing a simple program on my own to teach myself, tutorials only get me so far so I do my own thing to truly understand what I'm actually doing.
In this scenario the object I'm selecting is translated in glTranslate(0.0, 0.0, -4.0); like that, but obviously the math should work for any distance upon the line so it shouldn't really matter.
Anyway, as you can see I don't know very much. I've just been doing opengl tutorials lately and some redbook/bluebook stuff as well trying to pickup how to use it. I'm progressing ok, but I've been out of school for awhile so I've forgotten a lot of the maths and it's really not that easy to get back into it without examples :) I was pretty good at math back then I should be able to relearn but it's been long enough that just hearing it outright sounds confusing.
So if someone is willing i could use some help in understanding exactly how I would calculate a specific point on the line. I'm sure it's easy to those still doing math constantly but a bit confusing to someone who hasn't done it in a few years.
If you are interested in the relavent code I have so far it'd be
void PositionGLObject(int mousex, mousey){
GLfloat x, y, z; // allocate memory for the x, y, z position
GLint viewport[4]; //stores viewport information
GLdouble modmatrix[16], projmatrix[16];
glGetIntegerv(GL_VIEWPORT, viewport); //transfers viewport info into viewport array.
glGetDoublev(GL_PROJECTION_MATRIX, projmatrix);
glGetDoublev(GL_MODELVIEW_MATRIX, modmatrix);
// invert mousey so that down lowers value
mousey = viewport[3] - mousey;
gluUnProject((GLdouble) mousex, (GLdouble) mousey, 1.0, projmatrix, modmatrix, &x, &y, &z);
cout<<"X: "<<x<<"Y: "<<y<<"Z: "<<z<<endl; //print out values
}
Feel free to correct me if I'm doing anything wrong there! Basically I'm just going to set a global variable during the function that will move the object around. I'm doing a simple program on my own to teach myself, tutorials only get me so far so I do my own thing to truly understand what I'm actually doing.
In this scenario the object I'm selecting is translated in glTranslate(0.0, 0.0, -4.0); like that, but obviously the math should work for any distance upon the line so it shouldn't really matter.