Exemplo n.º 1
0
void Sphere::draw(GLuint tgLoc, GLuint tcoordsLoc) const
{
    drawHalfSphere(tgLoc, tcoordsLoc);

    glPushMatrix();
        glRotatef(180, 0, 0, 1);
        drawHalfSphere(tgLoc, tcoordsLoc);
    glPopMatrix();
}
Exemplo n.º 2
0
void ShapeToGeometryVisitor::apply(const osg::Capsule& capsule)
{
    gl.PushMatrix();

    gl.Translated(capsule.getCenter().x(),capsule.getCenter().y(),capsule.getCenter().z());

    if (!capsule.zeroRotation())
    {
        osg::Matrixd rotation(capsule.computeRotationMatrix());
        gl.MultMatrixd(rotation.ptr());
    }

    // evaluate hints
    bool createBody = (_hints ? _hints->getCreateBody() : true);
    bool createTop = (_hints ? _hints->getCreateTop() : true);
    bool createBottom = (_hints ? _hints->getCreateBottom() : true);

    unsigned int numSegments = 40;
    unsigned int numRows = 20;
    float ratio = (_hints ? _hints->getDetailRatio() : 1.0f);
    if (ratio > 0.0f && ratio != 1.0f) {
        numSegments = (unsigned int) (numSegments * ratio);
        if (numSegments < MIN_NUM_SEGMENTS)
            numSegments = MIN_NUM_SEGMENTS;
        numRows = (unsigned int) (numRows * ratio);
        if (numRows < MIN_NUM_ROWS)
            numRows = MIN_NUM_ROWS;
    }

    // if numRows is odd the top and bottom halves of sphere won't match, so bump up to the next event numRows
    if ((numRows%2)!=0) ++numRows;


    // capsule cylindrical body
    if (createBody)
        drawCylinderBody(numSegments, capsule.getRadius(), capsule.getHeight());

    // capsule top cap
    if (createTop)
        drawHalfSphere(numSegments, numRows, capsule.getRadius(), SphereTopHalf, capsule.getHeight()/2.0f);

    // capsule bottom cap
    if (createBottom)
        drawHalfSphere(numSegments, numRows, capsule.getRadius(), SphereBottomHalf, -capsule.getHeight()/2.0f);

    gl.PopMatrix();
}
Exemplo n.º 3
0
void drawHelicopter(){
	float colorA0[]={0,0,0,0};
	float colorA1[]={0,0,0,0};
	float colorA2[]={0,0,0,0};
	float colorD0[]={0.7529,0.6902,0.5686,1};
	float colorD1[]={0,0,0,1};
	float colorD2[]={0,0,0,0.2};
	float colorS0[]={0.7529,0.6902,0.5686,1};
	float colorS1[]={0.5,0.5,0.5,1};
	float colorS2[]={0,0,1,0.2};
	glPushMatrix();
	glTranslatef(heliPos.x,heliPos.y,heliPos.z);
	glRotatef(atan2(quaternionW.Length(),quaternionS)*180.0f/M_PI*2.0f,quaternionW.x,quaternionW.y,quaternionW.z);
	glMaterialfv(GL_FRONT,GL_AMBIENT,colorA0);
	glMaterialfv(GL_FRONT,GL_DIFFUSE,colorD0);
	glMaterialfv(GL_FRONT, GL_SPECULAR, colorS0);
	glMaterialf(GL_FRONT,GL_SHININESS,50);
	glPushMatrix();
	glTranslatef(0.0f,0.8f,0.0f);
	glRotatef(-90.0f,1.0f,0.0f,0.0f);
	drawCylinder(0.2,0.4,20,20);
	glPopMatrix();
	
	glPushMatrix();
	glTranslatef(0.0f,0.0f,1.4f);
	drawCylinder(0.2,2.0,20,20);
	glPopMatrix();
	
	glPushMatrix();
	glTranslatef(-1.0f,-1.0f,-2.5f);
	drawCylinder(0.1,4.0,20,20);
	glPopMatrix();
	
	glPushMatrix();
	glTranslatef(1.0f,-1.0f,-2.5f);
	drawCylinder(0.1,4.0,20,20);
	glPopMatrix();
	
	glPushMatrix();
	glTranslatef(0.0f,0.0f,0.5f);
	glRotatef(90.0f,1.0f,-1.0f,0.0f);
	glTranslatef(0.0f,0.0f,0.4f);
	drawCylinder(0.1,1.0,20,20);
	glPopMatrix();
	
	glPushMatrix();
	glTranslatef(0.0f,0.0f,-1.5f);
	glRotatef(90.0f,1.0f,-1.0f,0.0f);
	glTranslatef(0.0f,0.0f,0.4f);
	drawCylinder(0.1,1.0,20,20);
	glPopMatrix();
	
	glPushMatrix();
	glTranslatef(0.0f,0.0f,0.5f);
	glRotatef(-90.0f,-1.0f,-1.0f,0.0f);
	glTranslatef(0.0f,0.0f,0.4f);
	drawCylinder(0.1,1.0,20,20);
	glPopMatrix();
	
	glPushMatrix();
	glTranslatef(0.0f,0.0f,-1.5f);
	glRotatef(-90.0f,-1.0f,-1.0f,0.0f);
	glTranslatef(0.0f,0.0f,0.4f);
	drawCylinder(0.1,1.0,20,20);
	glPopMatrix();

	glPushMatrix();
	glTranslatef(0.0f,1.2f,0.0f);
	glMaterialfv(GL_FRONT,GL_AMBIENT,colorA1);
	glMaterialfv(GL_FRONT,GL_DIFFUSE,colorD1);
	glMaterialfv(GL_FRONT, GL_SPECULAR, colorS1);
	glMaterialf(GL_FRONT,GL_SHININESS,1);
	drawTopRotor(3.0f,rotorAngle);
	glPopMatrix();
	
	glPushMatrix();
	glTranslatef(0.2f,0.0f,3.3f);
	glRotatef(-90.0f,0.0f,0.0f,1.0f);
	drawBackRotor(1.0f,rotorAngle);
	glPopMatrix();
	
	glMaterialfv(GL_FRONT,GL_AMBIENT,colorA0);
	glMaterialfv(GL_FRONT,GL_DIFFUSE,colorD0);
	glMaterialfv(GL_FRONT, GL_SPECULAR, colorS0);
	glMaterialf(GL_FRONT,GL_SHININESS,50);
	glPushMatrix();
	glTranslatef(0.0f,0.0f,-0.5f);
	glScalef(1.0f,1.0f,2.0f);
	drawQuarterSphere(1.0, 20, 20);
	glPushMatrix();
	glRotatef(180.0f,0.0f,0.0f,1.0f);
	drawHalfSphere(1.0, 20, 20);
	glPopMatrix();
	glRotatef(180.0f,0.0f,1.0f,0.0f);
	glMaterialfv(GL_FRONT,GL_AMBIENT,colorA2);
	glMaterialfv(GL_FRONT,GL_DIFFUSE,colorD2);
	glMaterialfv(GL_FRONT, GL_SPECULAR, colorS2);
	glMaterialf(GL_FRONT,GL_SHININESS,50);
	drawQuarterSphere(1.0, 20, 20);
	glPopMatrix();
	
	glPopMatrix();
}
Exemplo n.º 4
0
void drawSphere(float radius,int slices,int stacks)
{
	drawHalfSphere(radius,slices,stacks,1.0);
	drawHalfSphere(radius,slices,stacks,-1.0);
	
}