예제 #1
0
GLint GLAPIENTRY
gluProject(GLdouble objx, GLdouble objy, GLdouble objz, 
	      const GLdouble modelMatrix[16], 
	      const GLdouble projMatrix[16],
              const GLint viewport[4],
	      GLdouble *winx, GLdouble *winy, GLdouble *winz)
{
    double in[4];
    double out[4];

    in[0]=objx;
    in[1]=objy;
    in[2]=objz;
    in[3]=1.0;
    __gluMultMatrixVecd(modelMatrix, in, out);
    __gluMultMatrixVecd(projMatrix, out, in);
    if (in[3] == 0.0) return(GL_FALSE);
    in[0] /= in[3];
    in[1] /= in[3];
    in[2] /= in[3];
    /* Map x, y and z to range 0-1 */
    in[0] = in[0] * 0.5 + 0.5;
    in[1] = in[1] * 0.5 + 0.5;
    in[2] = in[2] * 0.5 + 0.5;

    /* Map x,y to viewport */
    in[0] = in[0] * viewport[2] + viewport[0];
    in[1] = in[1] * viewport[3] + viewport[1];

    *winx=in[0];
    *winy=in[1];
    *winz=in[2];
    return(GL_TRUE);
}
예제 #2
0
파일: nerverot.c 프로젝트: koo5/lemon-2
static void threed_draw (struct nerverotstate *st, double alpha)
{
    int n;
    int m = 0;
    float fun=0.5;

    GLint viewport[4];// Space For Viewport xywh
    GLdouble winx, winy, winz;// Space For Returned Projected Coords
    GLdouble mvmatrix[16], projmatrix[16];// Space For Transform Matrix
    glGetIntegerv (GL_VIEWPORT, (GLint *)&viewport);// Get Actual Viewport
    glGetDoublev (GL_MODELVIEW_MATRIX, (GLdouble*)&mvmatrix);// Get Actual Model View Matrix
    glGetDoublev (GL_PROJECTION_MATRIX,  (GLdouble*)&projmatrix);// Get Actual Projection Matrix

    for (n = 0; n < st->blotCount; n++)
    {
	Blot *b = &st->blots[n];
	double in[4];

	in[0]=b->x2;
	in[1]=b->y2;
	in[2]=b->z2;
	in[3]=1.0;
	__gluMultMatrixVecd(mvmatrix, in, b->ip);
    }
    glPushMatrix();
    glLoadIdentity();
    for (n = 0; n < st->blotCount; n++)
    {
	Blot *b = &st->blots[n];
	fun=(float)st->segsToDraw[m].c/(float)st->colorCount;
	glBegin(GL_LINE_STRIP);
	glColor4f(0.1,fun/2,0,alpha);
        if (gluProject(b->x2, b->y2, b->z2, mvmatrix, projmatrix, viewport, &winx, &winy, &winz))
	{
	    int i;
	    for (i = 1; i < blotShapeCount; i++)
	    {
		FLOAT rx=(st->minRadius + (winz)*(st->maxRadius - st->minRadius))/st->windowWidth*2.0;
		FLOAT ry=(st->minRadius + (winz)*(st->maxRadius - st->minRadius))/st->windowHeight*2.0;

		glVertex3f(
		    b->ip[0]+(blotShape[i-1].x+ b->xoff[1+blotShape[i-1].x][1+blotShape[i-1].y]* st->maxNerveRadius) *rx,
		    b->ip[1]+(blotShape[i-1].y+ b->yoff[1+blotShape[i-1].x][1+blotShape[i-1].y]* st->maxNerveRadius) *ry,b->ip[2]);
		glVertex3f(
		    b->ip[0]+(blotShape[i].x+ b->xoff[1+blotShape[i].x][1+blotShape[i].y]* st->maxNerveRadius) *rx,
		    b->ip[1]+(blotShape[i].y+ b->yoff[1+blotShape[i].x][1+blotShape[i].y]* st->maxNerveRadius) *ry,b->ip[2]);
		m++;
	    }
	}
	glEnd();
    }
    glPopMatrix();
}
예제 #3
0
GLint GLAPIENTRY
gluUnProject4(GLdouble winx, GLdouble winy, GLdouble winz, GLdouble clipw,
	      const GLdouble modelMatrix[16], 
	      const GLdouble projMatrix[16],
	      const GLint viewport[4],
	      GLclampd nearVal, GLclampd farVal,		    
	      GLdouble *objx, GLdouble *objy, GLdouble *objz,
	      GLdouble *objw)
{
    double finalMatrix[16];
    double in[4];
    double out[4];

    __gluMultMatricesd(modelMatrix, projMatrix, finalMatrix);
    if (!__gluInvertMatrixd(finalMatrix, finalMatrix)) return(GL_FALSE);

    in[0]=winx;
    in[1]=winy;
    in[2]=winz;
    in[3]=clipw;

    /* Map x and y from window coordinates */
    in[0] = (in[0] - viewport[0]) / viewport[2];
    in[1] = (in[1] - viewport[1]) / viewport[3];
    in[2] = (in[2] - nearVal) / (farVal - nearVal);

    /* Map to range -1 to 1 */
    in[0] = in[0] * 2 - 1;
    in[1] = in[1] * 2 - 1;
    in[2] = in[2] * 2 - 1;

    __gluMultMatrixVecd(finalMatrix, in, out);
    if (out[3] == 0.0) return(GL_FALSE);
    *objx = out[0];
    *objy = out[1];
    *objz = out[2];
    *objw = out[3];
    return(GL_TRUE);
}
예제 #4
0
GLint GLAPIENTRY
gluUnProject(GLdouble winx, GLdouble winy, GLdouble winz,
		const GLdouble modelMatrix[16], 
		const GLdouble projMatrix[16],
                const GLint viewport[4],
	        GLdouble *objx, GLdouble *objy, GLdouble *objz)
{
    float finalMatrix[16];
    float in[4];
    float out[4];

    __gluMultMatricesd(modelMatrix, projMatrix, finalMatrix);
    if (!__gluInvertMatrixd(finalMatrix, finalMatrix)) return(GL_FALSE);

    in[0]=winx;
    in[1]=winy;
    in[2]=winz;
    in[3]=1.0;

    /* Map x and y from window coordinates */
    in[0] = (in[0] - viewport[0]) / viewport[2];
    in[1] = (in[1] - viewport[1]) / viewport[3];

    /* Map to range -1 to 1 */
    in[0] = in[0] * 2 - 1;
    in[1] = in[1] * 2 - 1;
    in[2] = in[2] * 2 - 1;

    __gluMultMatrixVecd(finalMatrix, in, out);
    if (out[3] == 0.0) return(GL_FALSE);
    out[0] /= out[3];
    out[1] /= out[3];
    out[2] /= out[3];
    *objx = out[0];
    *objy = out[1];
    *objz = out[2];
    return(GL_TRUE);
}