Exemple #1
0
void gxRenderingPoint::RenderAsScreenSphere(int nRadius)
{
	GLdouble modelMatrix[16];
	GLdouble projMatrix[16];
	GLint viewport[4];

	glGetDoublev(GL_PROJECTION_MATRIX, projMatrix);
	glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix);
	glGetIntegerv(GL_VIEWPORT, viewport);

	GLdouble winx;
	GLdouble winy;
	GLdouble winz;

	GLdouble objx = x;
	GLdouble objy = y;
	GLdouble objz = z;

	gluProject(objx, objy, objz, modelMatrix, projMatrix, viewport, &winx, &winy, &winz);

	winx += nRadius;

	gluUnProject(winx, winy, winz, modelMatrix, projMatrix, viewport, &objx, &objy, &objz);

	mlVector3D vSurfacePosition(objx, objy, objz);

	float fRadius = (vSurfacePosition - (*this)).Magnitude();

	RenderAsSphere(fRadius);
}
Exemple #2
0
void World::RenderMousePickSphere()
{
    // Convert screen radius to 3D radius

    mlVector3D vPoint = m_vMousePickPosition;
    mlVector3D vPointBase = m_trnCameraBase.TransformPointInverse(vPoint);
    bool bEq = (vPoint - vPointBase).Magnitude() < 1.0f;

    int nRadius = 15;

    {
    GLdouble winX, winY, winZ;
    GLdouble objX, objY, objZ;

    objX = vPoint.x;
    objY = vPoint.y;
    objZ = vPoint.z;

    gluProject(objX, objY, objZ, modelMatrix, projMatrix, viewport, &winX, &winY, &winZ);

    winX += nRadius;

    gluUnProject(winX, winY, winZ, modelMatrix, projMatrix, viewport, &objX, &objY, &objZ);

    mlVector3D vSurfacePosition(objX, objY, objZ);

    float fRadius = (vSurfacePosition - vPoint).Magnitude();

    // Now render

    glLineWidth(1.0f);

    glDisable(GL_TEXTURE_2D);

    glMatrixMode(GL_MODELVIEW);

    glPushMatrix();

    glTranslatef(vPoint.x, vPoint.y, vPoint.z);

    //glPushMatrix();

    mlTransform transform = m_trnCameraBase;
    transform.SetTranslation(mlVector3DZero);

    mlMatrix4x4 mat(transform.GetMatrix());

    mlFloat * pMat = reinterpret_cast<mlFloat*>(&mat);

    glMultMatrixf(pMat);

    glColor4ub(
        0,
        255,
        0,
        255);

    //GLfloat faceColor[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
    //glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, faceColor);

    glutWireSphere(fRadius, 15, 15);
    glPopMatrix();
    }

#if 0

    float fTextScale = 0.1f;
    float fAxisScale = 3.0f;

    glDisable(GL_DEPTH_TEST);

    glBegin(GL_LINES);

    glColor4ub(255,0,0, 255);
    glVertex3f(0,0,0);
    glVertex3f(fRadius * fAxisScale, 0,0);

    glColor4ub(0,0,255, 255);
    glVertex3f(0,0,0);
    glVertex3f(0, fRadius * fAxisScale, 0);

    glColor4ub(0,255,0, 255);
    glVertex3f(0,0,0);
    glVertex3f(0,0, fRadius * fAxisScale);

    glEnd();

    // Next step: change this to use the base coordinate system instead of this hardcoded one.

    {
        stringstream ss;
        if(bEq)
            ss << std::setprecision(2) << std::fixed << "x=" << vPoint.x;
        else
            ss << std::setprecision(2) << std::fixed << "x=" << vPointBase.x << std::endl << "  " << vPoint.x;
        glColor4ub(255,0,0, 255);
        glPushMatrix();
        glTranslatef(fRadius * fAxisScale + fRadius * fTextScale * 0.1f, 0, 0);
        glScalef(fRadius * fTextScale, fRadius * fTextScale, fRadius * fTextScale);
        DrawText3DStroked(mlVector3DZero, ss.str());
        glPopMatrix();
    }

    {
        stringstream ss;
        if(bEq)
            ss << std::setprecision(2) << std::fixed << "y=" << vPoint.y;
        else
            ss << std::setprecision(2) << std::fixed << "y=" << vPointBase.y << std::endl << "  " << vPoint.y;
        glColor4ub(0,0,255, 255);
        glPushMatrix();
        glTranslatef(fRadius * fTextScale * 0.1f, fRadius * fAxisScale, 0);
        glScalef(fRadius * fTextScale, fRadius * fTextScale, fRadius * fTextScale);
        DrawText3DStroked(mlVector3DZero, ss.str());
        glPopMatrix();
    }

    {
        stringstream ss;
        if(bEq)
            ss << std::setprecision(2) << std::fixed << "z=" << vPoint.z;
        else
            ss << std::setprecision(2) << std::fixed << "z=" << vPointBase.z << std::endl << "  " << vPoint.z;
        glColor4ub(0,255,0, 255);
        glPushMatrix();
        glTranslatef(fRadius * fTextScale * 2.0f, 0, fRadius * fAxisScale);
        glScalef(fRadius * fTextScale, fRadius * fTextScale, fRadius * fTextScale);
        DrawText3DStroked(mlVector3DZero, ss.str());
        glPopMatrix();
    }

    glPopMatrix();

    {
        glPushMatrix();

        // Use the camera transform moved to the pick position.

        mlTransform transform = m_trnCamera;
        transform.SetTranslation(vPoint);

        mlMatrix4x4 mat(transform.GetMatrix());

        mlFloat * pMat = reinterpret_cast<mlFloat*>(&mat);

        glMultMatrixf(pMat);

        // Rotations required because DrawText3DStroked draws text along the Z axis
        glRotatef(-90.0f, 1.0, 0.0f, 0.0f);

        // Move text beneath the pick sphere
        glTranslatef(0,0,fRadius * -2.0f);

        // Use fRadius to scale it so it remains a constant size
        glScalef(fRadius * fTextScale, fRadius * fTextScale, fRadius * fTextScale);

        glColor4ub(255,255,0, 255);

        stringstream ss;
        if(bEq)
            ss << std::setprecision(2) << std::fixed << "(" << vPoint.x << "," << vPoint.y << "," << vPoint.z << ")";
        else
            ss << std::setprecision(2) << std::fixed << "(" << vPointBase.x << "," << vPointBase.y << "," << vPointBase.z << ")" << std::endl
                                                     << "(" << vPoint.x     << "," << vPoint.y     << "," << vPoint.z     << ")";

        DrawText3DStroked(mlVector3DZero, ss.str());

        glPopMatrix();
    }

    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);

    glColor4ub(0,255,0, 255);

    //glPopMatrix();

    }