CHAPTER 8: Putting It All Together (^265)
void gluGetScreenLocation(GLfloat xa,GLfloat ya,GLfloat za,GLfloat sx, GLfloat
sy,GLfloat sz)
{
GLfloat mvmatrix[16];
GLfloat projmatrix[16];
GLfloat x,y,z;
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT,viewport); //4
glGetFloatv(GL_MODELVIEW_MATRIX,mvmatrix);
glGetFloatv(GL_PROJECTION_MATRIX,projmatrix);
gluProject(xa,ya,za,mvmatrix,projmatrix,viewport,&x,&y,&z);
y=viewport[3]-y; //5
sx=x;
sy=y;
if(sz!=NULL)
sz=z;
float scale=[[UIScreen mainScreen] scale]; //6
sx/=scale;
sy/=scale;
}
void gluMultMatrixVector3f(const GLfloat matrix[16], const GLfloat in[4],GLfloat out[4])
{
int i;
for (i=0; i<4; i++)
{
out[i] =
in[0] matrix[04+i] +
in[1] matrix[14+i] +
in[2] matrix[24+i] +
in[3] matrix[34+i];
}
}
In gluProject() we supply the needed matrices along with the desired xyz coordinates
we’re investigating, and it returns the screen xyz (yes, z) of the point’s projected
location.
Lines 1ff map the object coordinates to an array that will then be
multiplied by the modelMatrix (supplied as one of the arguments).
singke
(singke)
#1