Пример #1
0
void Torch::draw2Self()
{
	if( world()->landscape()->drawingReflection() || world()->landscape()->drawingRefraction() )
		return;

	const unsigned char samplingPoints = 16;
	unsigned char visiblePoints;

	glPushMatrix();
	glTranslate( mFlarePosition );
	glScale( 0.3f );
	visiblePoints = mOcclusionTest.randomPointsOnUnitSphereVisible( samplingPoints );
	glPopMatrix();
	if( !visiblePoints )
		return;

	glPushAttrib( GL_VIEWPORT_BIT | GL_DEPTH_BUFFER_BIT | GL_CURRENT_BIT );
	glDepthMask( GL_FALSE );
	glDisable( GL_CULL_FACE );
	glDisable( GL_DEPTH_TEST );

	glDisable( GL_LIGHTING );
	glEnable( GL_BLEND );
	glBlendFunc( GL_SRC_ALPHA, GL_ONE );
	mMaterial->bind();
	glColor( ((float)visiblePoints/(float)samplingPoints)*mColor );

	sQuadVertexBuffer.bind();
	glClientActiveTexture( GL_TEXTURE0 );
	glEnableClientState( GL_VERTEX_ARRAY );
	glEnableClientState( GL_TEXTURE_COORD_ARRAY );

	glVertexPointer( 3, GL_FLOAT, 5*sizeof(GLfloat), (void*)0 );
	glTexCoordPointer( 2, GL_FLOAT, 5*sizeof(GLfloat), (void*)(3*sizeof(GLfloat)) );

	QMatrix4x4 flareCenter = modelViewMatrix();
	flareCenter.translate( mFlarePosition );
	Bilboard::begin( flareCenter );
	glScale( mFlareSize );
	glRotate( mFlareRotation, QVector3D(0,0,1) );
	glDrawArrays( GL_QUADS, 0, 4 );
	glRotate( -mFlareRotation*2.7f, QVector3D(0,0,1) );
	glDrawArrays( GL_QUADS, 0, 4 );
	Bilboard::end();

	glDisableClientState( GL_TEXTURE_COORD_ARRAY );
	glDisableClientState( GL_VERTEX_ARRAY );
	sQuadVertexBuffer.release();

	mMaterial->release();
	glDisable( GL_BLEND );

	glPopAttrib();
}
Пример #2
0
METHODPREFIX
void
glMultMatrix(
	const Geometry::ScalingTransformation<ScalarParam,3>& t)
	{
	glScale(t.getScaling().getComponents());
	}
Пример #3
0
void MyCar::drawCar() {
    glPushMatrix();
    //glScalef(0.7, 0.7, 0.7);
    glTranslatef(-2.0, 1.3, 0);
   
    glMateriali(GL_FRONT, GL_SHININESS, 55);
    glPushMatrix();
    float d = mesh.bbox.Diag();
    glScale(3 / d);
    glRotatef(90, 0, 1, 0);
    glRotatef(-90, 1, 0, 0);
    

    vcg::Point4f spotpos = vcg::Point4f(-0.9, 0.3, -4, 1.0);
    vcg::Point4f spotpos2 = vcg::Point4f(0.9, 0.3, -4, 1.0);
    vcg::Point4f spotdir = vcg::Point4f(0.0, 0.0, -1.0, 0.0);
    glLightfv(GL_LIGHT1, GL_POSITION, &spotpos[0]);
    glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, &spotdir[0]);
    glLightfv(GL_LIGHT2, GL_POSITION, &spotpos2[0]);
    glLightfv(GL_LIGHT2, GL_SPOT_DIRECTION, &spotdir[0]);

    glTranslate(-(_car.m->bbox.Center()));
    glDisable(GL_TEXTURE_2D);
    glEnable(GL_COLOR_MATERIAL);
    _car.Draw<vcg::GLW::DMSmooth, vcg::GLW::CMPerFace, vcg::GLW::TMNone > ();
    glPopMatrix();
    glDisable(GL_COLOR_MATERIAL);
    glEnable(GL_TEXTURE_2D);
}
void glLoadMatrix(const Geometry::OrthogonalTransformation<ScalarParam,3>& t)
{
    glLoadIdentity();
    glTranslate(t.getTranslation());
    glRotate(t.getRotation());
    glScale(t.getScaling(),t.getScaling(),t.getScaling());
}
Пример #5
0
METHODPREFIX
void
glLoadMatrix(
	const Geometry::UniformScalingTransformation<ScalarParam,3>& t)
	{
	glLoadIdentity();
	glScale(t.getScaling());
	}
Пример #6
0
METHODPREFIX
void
glMultMatrix(
	const Geometry::OrthogonalTransformation<ScalarParam,3>& t)
	{
	glTranslate(t.getTranslation().getComponents());
	glRotate(Math::deg(t.getRotation().getAngle()),t.getRotation().getAxis().getComponents());
	glScale(t.getScaling());
	}
Пример #7
0
void SplatterSystem::draw( const QMatrix4x4 & modelView )
{
	mParticleMaterial->bind();
	mParticleSystem->draw( modelView );
	mParticleMaterial->release();

	mSplatterMaterial->bind();
	glEnable( GL_BLEND );
	glBlendFunc( GL_DST_COLOR, GL_ZERO );
	glMatrixMode( GL_TEXTURE );
	for( int i = 0; i < mSplatters.size(); ++i )
	{
		if( mSplatters[i].fade <= 0.0f )
			continue;

		QVector4D c = Interpolation::linear( QVector4D(1.0f,1.0f,1.0f,1.0f), mSplatterMaterial->constData()->emission(), sqrtf(mSplatters[i].fade) );
		mSplatterMaterial->overrideEmission( c );

		glPushMatrix();
		QRectF mapRect = mTerrain->toMapF( mSplatters[i].rect );

		// rotate around center of texture in 90 deg. steps
		glTranslate( 0.5f, 0.5f, 0.0f );
		glRotate( mSplatters[i].rotation*90.0f, 0.0f, 0.0f, 1.0f );
		glTranslate( -0.5f, -0.5f, 0.0f );

		// transform texture coordinates to terrain patch
		float sizeFactor = powf( mSplatters[i].fade, mSplatterDriftFactor );
		QSizeF border = ( sizeFactor * mapRect.size() ) / 2.0f;
		glScale( 1.0/(mapRect.size().width()*(1.0f-sizeFactor)), 1.0/(mapRect.size().height()*(1.0f-sizeFactor)), 1.0 );
		glTranslate( -mapRect.x()-border.width(), -mapRect.y()-border.height(), 0.0 );

		float fX( mapRect.x()-(int)mapRect.x() );
		float fY( mapRect.y()-(int)mapRect.y() );
		QRect drawRect
		(
			floorf(mapRect.x()), floorf(mapRect.y()),
			ceilf(mapRect.width()+fX), ceilf(mapRect.height()+fY)
		);
		mTerrain->drawPatchMap( drawRect );
		glPopMatrix();
	}
	glMatrixMode( GL_MODELVIEW);
	glDisable( GL_BLEND );
	mSplatterMaterial->release();
}
Пример #8
0
void GridEditor::EditTool::glRenderActionTransparent(GLContextData& contextData) const
	{
	glPushAttrib(GL_ENABLE_BIT|GL_LINE_BIT|GL_POLYGON_BIT);
	
	/* Retrieve context entry: */
	DataItem* dataItem=contextData.retrieveDataItem<DataItem>(application);
	
	/* Render the influence sphere: */
	glDisable(GL_LIGHTING);
	
	glPushMatrix();
	glMultMatrix(getButtonDeviceTransformation(0));
	glScale(influenceRadius);
	glCallList(dataItem->influenceSphereDisplayListId);
	glPopMatrix();
	
	glPopAttrib();
	}
Пример #9
0
void glfemPlotField(femMesh *theMesh, double *u)
{
    int i,j,*nodes;
    float  xLoc[4];
    float  yLoc[4];
    double uLoc[4];
    double uMax = femMax(u,theMesh->nNode);
    double uMin = femMin(u,theMesh->nNode);
    int nLocalNode = theMesh->nLocalNode;
    
    for (i = 0; i < theMesh->nElem; ++i) {
        nodes = &(theMesh->elem[i*nLocalNode]);
        for (j=0; j < nLocalNode; ++j) {
            xLoc[j] = theMesh->X[nodes[j]];
            yLoc[j] = theMesh->Y[nodes[j]];
            uLoc[j] = glScale(uMin,uMax,u[nodes[j]]); }              
        glfemDrawColorElement(xLoc,yLoc,uLoc,nLocalNode); }
    glColor3f(0.0, 0.0, 0.0);
    glfemPlotMesh(theMesh);
}
Пример #10
0
void
PlanetographicGrid::render(Renderer* renderer,
                           const Point3f& pos,
                           float discSizeInPixels,
                           double tdb) const
{
    Quatd q = Quatd::yrotation(PI) * body.getEclipticToBodyFixed(tdb);
    Quatf qf((float) q.w, (float) q.x, (float) q.y, (float) q.z);

    // The grid can't be rendered exactly on the planet sphere, or
    // there will be z-fighting problems. Render it at a height above the
    // planet that will place it about one pixel away from the planet.
    float scale = (discSizeInPixels + 1) / discSizeInPixels;
    scale = max(scale, 1.001f);
    float offset = scale - 1.0f;

    Vec3f semiAxes = body.getSemiAxes();

    Vec3d posd(pos.x, pos.y, pos.z);
    Vec3d viewRayOrigin = Vec3d(-pos.x, -pos.y, -pos.z)  * (~q).toMatrix3();
    
    // Calculate the view normal; this is used for placement of the long/lat
    // label text.
    Vec3f vn  = Vec3f(0.0f, 0.0f, -1.0f) * renderer->getCameraOrientation().toMatrix3();
    Vec3d viewNormal(vn.x, vn.y, vn.z);

    // Enable depth buffering
    glEnable(GL_DEPTH_TEST);
    glDepthMask(GL_TRUE);
    glDisable(GL_BLEND);

    glDisable(GL_TEXTURE_2D);

    glPushMatrix();
    glRotate(~qf);
    glScale(scale * semiAxes);

    glEnableClientState(GL_VERTEX_ARRAY);

    glVertexPointer(3, GL_FLOAT, 0, xzCircle);

    // Only show the coordinate labels if the body is sufficiently large on screen
    bool showCoordinateLabels = false;
    if (discSizeInPixels > 50)
        showCoordinateLabels = true;

    float latitudeStep = minLatitudeStep;
    float longitudeStep = minLongitudeStep;
    if (discSizeInPixels < 200)
    {
        latitudeStep = 30.0f;
        longitudeStep = 30.0f;
    }
    
    for (float latitude = -90.0f + latitudeStep; latitude < 90.0f; latitude += latitudeStep)
    {
        float phi = degToRad(latitude);
        float r = (float) cos(phi);

        if (latitude == 0.0f)
        {
            glColor(Renderer::PlanetEquatorColor);
            glLineWidth(2.0f);
        }
        else
        {
            glColor(Renderer::PlanetographicGridColor);
        }
        glPushMatrix();
        glTranslatef(0.0f, (float) sin(phi), 0.0f);
        glScalef(r, r, r);
        glDrawArrays(GL_LINE_LOOP, 0, circleSubdivisions);
        glPopMatrix();
        glLineWidth(1.0f);
        
        if (showCoordinateLabels)
        {
            if (latitude != 0.0f && abs(latitude) < 90.0f)
            {
                char buf[64];

                char ns;
                if (latitude < 0.0f)
                    ns = northDirection == NorthNormal ? 'S' : 'N';
                else
                    ns = northDirection == NorthNormal ? 'N' : 'S';
                sprintf(buf, "%d%c", (int) fabs((double) latitude), ns);
                longLatLabel(buf, 0.0, latitude, viewRayOrigin, viewNormal, posd, q, semiAxes, offset, renderer);
                longLatLabel(buf, 180.0, latitude, viewRayOrigin, viewNormal, posd, q, semiAxes, offset, renderer);
            }
        }
    }

    glVertexPointer(3, GL_FLOAT, 0, xyCircle);

    for (float longitude = 0.0f; longitude <= 180.0f; longitude += longitudeStep)
    {
        glColor(Renderer::PlanetographicGridColor);
        glPushMatrix();
        glRotatef(longitude, 0.0f, 1.0f, 0.0f);
        glDrawArrays(GL_LINE_LOOP, 0, circleSubdivisions);
        glPopMatrix();

        if (showCoordinateLabels)
        {
            int showLongitude = 0;
            char ew = 'E';

            switch (longitudeConvention)
            {
            case EastWest:
                ew = 'E';
                showLongitude = (int) longitude;
                break;
            case Eastward:
                if (longitude > 0.0f)
                    showLongitude = 360 - (int) longitude;
                ew = 'E';
                break;
            case Westward:
                if (longitude > 0.0f)
                    showLongitude = 360 - (int) longitude;
                ew = 'W';
                break;
            }

            char buf[64];
            sprintf(buf, "%d%c", (int) showLongitude, ew);
            longLatLabel(buf, longitude, 0.0, viewRayOrigin, viewNormal, posd, q, semiAxes, offset, renderer);
            if (longitude > 0.0f && longitude < 180.0f)
            {
                showLongitude = (int) longitude;
                switch (longitudeConvention)
                {
                case EastWest:
                    ew = 'W';
                    showLongitude = (int) longitude;
                    break;
                case Eastward:
                    showLongitude = (int) longitude;
                    ew = 'E';
                    break;
                case Westward:
                    showLongitude = (int) longitude;
                    ew = 'W';
                    break;
                }

                sprintf(buf, "%d%c", showLongitude, ew);       
                longLatLabel(buf, -longitude, 0.0, viewRayOrigin, viewNormal, posd, q, semiAxes, offset, renderer);
            }
        }
    }

    glDisableClientState(GL_VERTEX_ARRAY);

    glPopMatrix();

    glDisable(GL_LIGHTING);

    glDisable(GL_DEPTH_TEST);
    glDepthMask(GL_FALSE);
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
}
Пример #11
0
inline void glScale( const QVector3D & scale )	{ glScale( scale.x(), scale.y(), scale.z() ); }
void RamachandranPlot::draw(void)
{
    ProteinState *state = curProtein();
    if ( !state ) return;
	 
	 GLText text;
    if(!valid())
    {
        /* Set the viewport: */
        glViewport(0,0,w(),h());
        
        /* Set the projection and modelview matrices: */
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        float factor=1.0/Math::Constants<double>::pi;
        glScale(factor,factor,factor);
        glDisable(GL_DEPTH_TEST);
    }
    
    /* Clear window: */
    glClearColor(backgroundColor);
    glClear(GL_COLOR_BUFFER_BIT);
    
    /* Draw ramachandran texture background: */
    glEnable(GL_TEXTURE_2D);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_BASE_LEVEL,0);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAX_LEVEL,0);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
    glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
    glPixelStorei(GL_UNPACK_ALIGNMENT,1);
    glPixelStorei(GL_UNPACK_SKIP_PIXELS,0);
    glPixelStorei(GL_UNPACK_ROW_LENGTH,0);
    glPixelStorei(GL_UNPACK_SKIP_ROWS,0);
    glPixelStorei(GL_UNPACK_IMAGE_HEIGHT,0);
    glPixelStorei(GL_UNPACK_SKIP_IMAGES,0);
    glTexImage2D(GL_TEXTURE_2D,0,GL_RGB8,ramachandranTextureHeight,ramachandranTextureWidth,0,GL_RGB,GL_UNSIGNED_BYTE,ramachandranTexture);
    glColor3f(1.0f,0.0f,1.0f);
    glBegin(GL_QUADS);
    glTexCoord2f(0.0f,0.0f);
    glVertex2f(-Math::Constants<float>::pi,-Math::Constants<float>::pi);
    glTexCoord2f(1.0f,0.0f);
    glVertex2f(Math::Constants<float>::pi,-Math::Constants<float>::pi);
    glTexCoord2f(1.0f,1.0f);
    glVertex2f(Math::Constants<float>::pi,Math::Constants<float>::pi);
    glTexCoord2f(0.0f,1.0f);
    glVertex2f(-Math::Constants<float>::pi,Math::Constants<float>::pi);
    glEnd();
    glDisable(GL_TEXTURE_2D);
    
    /* Draw coordinate axes: */
    glColor3f(1.0f-backgroundColor[0],1.0f-backgroundColor[1],1.0f-backgroundColor[2]);
    glBegin(GL_LINES);
    glVertex2f(0.0f,-4.0f);
    glVertex2f(0.0f,4.0f);
    glVertex2f(-4.0f,0.0f);
    glVertex2f(4.0f,0.0f);
    glEnd();

	/* Draw axes data range */
	text.setFontColor(0.0, 0.0, 0.0);
	/* h, v */
	/*	+  */
	/*-   +*/
	/*	-  */	
	text.drawFreeString("pi",2.3f,-2.7f);
	text.drawFreeString("-pi",-2.8f,-2.7f);
	text.drawFreeString("pi",-3.0f,2.6f);
	text.drawFreeString("0",-3.0f,-0.3f);
	text.drawFreeString("0",-0.3f,-2.7f);
	text.drawFreeString("Phi",0.15f,2.5f);
	text.drawFreeString("Psi",2.5f,0.15f);

	/* Draw axes label */
	text.setFontScale(0.003, 0.003);
	text.setFontColor(0.0, 0.0, 1.0);
    
    if(structureValid)
    {
        /* Visualize dihedral angles inside a selected structure: */
        glPointSize(3.0f);
        glBegin(GL_POINTS);
        glColor(selectedStructureColor);
        for(int i=0;i<numStructureResidues;++i)
            glVertex(structurePhis[i],structurePsis[i]);
        glEnd();
    }
    
    /* Visualize dihedral angles inside all active coil regions: */
    if(activeCoilsValid)
    {
        /* Visualize dihedral angles inside all active coil regions: */
        glPointSize(3.0f);
        glBegin(GL_POINTS);
        glColor(activeCoilRegionColor);
        for(int i=0;i<numActiveCoilsResidues;++i)
            glVertex(activeCoilsPhis[i],activeCoilsPsis[i]);
        glEnd();
    }

	if ( state->selectedResidue != 0 )
	{
    	/* Highlight dihedral angles of selected residue: */
		glEnable(GL_BLEND);
		glEnable(GL_POINT_SMOOTH);
        glPointSize(6.0f);
		glBegin(GL_POINTS);
        
		if(boundary)
			glColor3f(0.0f, 0.0f, 5.0f);
		else
			glColor3f(1.0f, 1.0f, 1.0f);
			//printf("draw phi %f psi %f\n", oldPhiAngle,oldPsiAngle);
			glVertex2f(oldPhiAngle,oldPsiAngle);
        
		glEnd();
		}
}