Esempio n. 1
0
// Draw a torus (doughnut), using the current 1D texture for light shading
void DrawTorus(M3DMatrix44f mTransform)
    {
    GLfloat majorRadius = 0.35f;
    GLfloat minorRadius = 0.15f;
    GLint   numMajor = 40;
    GLint   numMinor = 20;
    M3DVector3f objectVertex;         // Vertex in object/eye space
    M3DVector3f transformedVertex;    // New Transformed vertex   
    double majorStep = 2.0f*M3D_PI / numMajor;
    double minorStep = 2.0f*M3D_PI / numMinor;
    int i, j;
    
    for (i=0; i<numMajor; ++i) 
        {
        double a0 = i * majorStep;
        double a1 = a0 + majorStep;
        GLfloat x0 = (GLfloat) cos(a0);
        GLfloat y0 = (GLfloat) sin(a0);
        GLfloat x1 = (GLfloat) cos(a1);
        GLfloat y1 = (GLfloat) sin(a1);

        glBegin(GL_TRIANGLE_STRIP);
        for (j=0; j<=numMinor; ++j) 
            {
            double b = j * minorStep;
            GLfloat c = (GLfloat) cos(b);
            GLfloat r = minorRadius * c + majorRadius;
            GLfloat z = minorRadius * (GLfloat) sin(b);

            // First point
            objectVertex[0] = x0*r;
            objectVertex[1] = y0*r;
            objectVertex[2] = z;
            m3dTransformVector3(transformedVertex, objectVertex, mTransform);
            glVertex3fv(transformedVertex);

            // Second point
            objectVertex[0] = x1*r;
            objectVertex[1] = y1*r;
            objectVertex[2] = z;
            m3dTransformVector3(transformedVertex, objectVertex, mTransform);
            glVertex3fv(transformedVertex);
            }
        glEnd();
        }
    }
Esempio n. 2
0
// Called to draw scene objects
void DrawModels(void)
{
    M3DVector3f lightPosEye;
    M3DMatrix44f mv;

    // Transform light position to eye space
    glPushMatrix();
    glRotatef(lightRotation, 0.0, 1.0, 0.0);
    glGetFloatv(GL_MODELVIEW_MATRIX, mv);
    m3dTransformVector3(lightPosEye, lightPos, mv);
    glPopMatrix();

    GLint uniformLoc = glGetUniformLocation(progObj[whichShader], "lightPos");
    if (uniformLoc != -1)
    {
        glUniform3fv(uniformLoc, 1, lightPosEye);
    }

    // Draw sphere
    glutSolidSphere(50.0f, tess, tess);
}
Esempio n. 3
0
void PassGouraudDataToShader()
{
	glUniformMatrix4fv(mvpMatrixLocation, 1, GL_FALSE, transformPipeline.GetModelViewProjectionMatrix());
	glUniformMatrix4fv(mvMatrixLocation, 1, GL_FALSE, transformPipeline.GetModelViewMatrix());
	glUniformMatrix3fv(normalMatrixLocation, 1, GL_FALSE, transformPipeline.GetNormalMatrix());

	M3DMatrix44f viewMatrix;
	cameraFrame.GetCameraMatrix(viewMatrix);
	M3DVector3f lightPositionInEyeSpace;
	m3dTransformVector3(lightPositionInEyeSpace, lightPosition, viewMatrix);

	glUniform3fv(shaderLightPositionLocation, 1, lightPositionInEyeSpace);
	glUniform3fv(shaderLightColorLocation, 1, lightColor);
	glUniform1f(shaderLightAngleLocation, lightAngle);
	glUniform1f(shaderLightAttenuation0Location, lightAttenuation0);
	glUniform1f(shaderLightAttenuation1Location, lightAttenuation1);
	glUniform1f(shaderLightAttenuation2Location, lightAttenuation2);

	glUniform3fv(materialAmbientColorLocation, 1, materialAmbientColor);
	glUniform3fv(materialDiffuseColorLocation, 1, materialDiffuseColor);
	glUniform3fv(materialSpecularColorLocation, 1, materialSpecularColor);
	glUniform1f(materialSpecularExponentLocation, materialSpecularExponent);
}
Esempio n. 4
0
// Called to draw scene objects
void DrawModels(void)
{
    M3DVector3f lightPosEye0, lightPosEye1, lightPosEye2;
    M3DMatrix44f mv;

    // Transform light position to eye space
    glPushMatrix();
    glRotatef(lightRotation, 0.0, 1.0, 0.0);
    glGetFloatv(GL_MODELVIEW_MATRIX, mv);
    m3dTransformVector3(lightPosEye0, lightPos0, mv);
    if (whichShader == THREELIGHTS)
    {
        m3dTransformVector3(lightPosEye1, lightPos1, mv);
        m3dTransformVector3(lightPosEye2, lightPos2, mv);
    }
    glPopMatrix();

    GLint uniformLoc = glGetUniformLocation(progObj[whichShader], "lightPos[0]");
    if (uniformLoc != -1)
    {
        glUniform3fv(uniformLoc, 1, lightPosEye0);
    }
    uniformLoc = glGetUniformLocation(progObj[whichShader], "lightPos[1]");
    if (uniformLoc != -1)
    {
        glUniform3fv(uniformLoc, 1, lightPosEye1);
    }
    uniformLoc = glGetUniformLocation(progObj[whichShader], "lightPos[2]");
    if (uniformLoc != -1)
    {
        glUniform3fv(uniformLoc, 1, lightPosEye2);
    }
    uniformLoc = glGetUniformLocation(progObj[whichShader], "squashStretch");
    if (uniformLoc != -1)
    {
        glUniform3fv(uniformLoc, 1, squashStretch);
    }
    uniformLoc = glGetUniformLocation(progObj[whichShader], "density");
    if (uniformLoc != -1)
    {
        glUniform1f(uniformLoc, density);
    }

    // Draw plane that the objects rest on
    glColor3f(0.0f, 0.0f, 0.90f); // Blue
    glNormal3f(0.0f, 1.0f, 0.0f);
    glBegin(GL_QUADS);
        glVertex3f(-100.0f, -25.0f, -100.0f);
        glVertex3f(-100.0f, -25.0f, 100.0f);		
        glVertex3f(100.0f,  -25.0f, 100.0f);
        glVertex3f(100.0f,  -25.0f, -100.0f);
    glEnd();

    // Draw red cube
    glColor3f(1.0f, 0.0f, 0.0f);
    glutSolidCube(48.0f);

    // Draw green sphere
    glColor3f(0.0f, 1.0f, 0.0f);
    glPushMatrix();
    glTranslatef(-60.0f, 0.0f, 0.0f);
    glutSolidSphere(25.0f, 50, 50);
    glPopMatrix();

    // Draw magenta torus
    glColor3f(1.0f, 0.0f, 1.0f);
    glPushMatrix();
    glTranslatef(0.0f, 0.0f, 60.0f);
    glutSolidTorus(8.0f, 16.0f, 50, 50);
    glPopMatrix();

    if (whichShader == STRETCH)
    {
        // Cone and teapot are rotated such that their
        // Y and Z squash scales must be switched
        GLfloat rotatedSquashStretch[4];

        rotatedSquashStretch[0] = squashStretch[0];
        rotatedSquashStretch[1] = squashStretch[2];
        rotatedSquashStretch[2] = squashStretch[1];
        rotatedSquashStretch[3] = squashStretch[3];

        GLint uniformLoc = glGetUniformLocation(progObj[whichShader], "squashStretch");
        if (uniformLoc != -1)
        {
            glUniform3fv(uniformLoc, 1, rotatedSquashStretch);
        }
    }

    // Draw yellow cone
    glColor3f(1.0f, 1.0f, 0.0f);
    glPushMatrix();
    glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
    glTranslatef(60.0f, 0.0f, -24.0f);
    glutSolidCone(25.0f, 50.0f, 50, 50);
    glPopMatrix();

    // Draw cyan teapot
    glColor3f(0.0f, 1.0f, 1.0f);
    glPushMatrix();
    glTranslatef(0.0f, 0.0f, -60.0f);
    glutSolidTeapot(25.0f);
    glPopMatrix();
}
Esempio n. 5
0
// Called to draw scene objects
void DrawModels(void)
{
    M3DVector3f lightPosEye;
    M3DMatrix44f mv, mv2;
    M3DMatrix44f mv2IT_4x4;
    GLfloat mv2IT_3x3[9];
    GLint i;

    // Transform light position to eye space
    glGetFloatv(GL_MODELVIEW_MATRIX, mv);
    m3dTransformVector3(lightPosEye, lightPos, mv);

    glUniform3fv(lightPosLoc, 1, lightPosEye);

    // Setup modelview matrices for upper arm
    glPushMatrix();
    glRotatef(elbowBend, 0.0f, 0.0f, 1.0f);
    glTranslatef(-50.0f, 0.0f, 0.0f);
    glGetFloatv(GL_MODELVIEW_MATRIX, mv2);
    glPopMatrix();
    glTranslatef(-50.0f, 0.0f, 0.0f);

    glUniformMatrix4fv(mv2Loc, 1, GL_FALSE, mv2);

    m3dInvertMatrix44(mv2IT_4x4, mv2);

    // Take upper left 3x3 for 2nd normal matrix
    for (i = 0; i < 9; i++)
    {
        mv2IT_3x3[i] = mv2IT_4x4[((i/3)*4)+(i%3)];
    }
    glUniformMatrix3fv(mv2ITLoc, 1, GL_TRUE, mv2IT_3x3);

    // Draw upper arm cylinder
    glColor3f(0.0f, 0.0f, 0.90f);      // Blue
    // 50 long, 10 shoulder, 9 elbow, with weights applied to second half
    DrawCylinder(50.0f, 15.0f, 9.0f, 1.0f, 0.5f);

    // Setup modelview matrices for forearm
    glTranslatef(50.0f, 0.0f, 0.0f);
    glPushMatrix();
    glGetFloatv(GL_MODELVIEW_MATRIX, mv2);
    glPopMatrix();
    glRotatef(elbowBend, 0.0f, 0.0f, 1.0f);

    glUniformMatrix4fv(mv2Loc, 1, GL_FALSE, mv2);

    m3dInvertMatrix44(mv2IT_4x4, mv2);

    // Take upper left 3x3 for 2nd normal matrix
    for (i = 0; i < 9; i++)
    {
        mv2IT_3x3[i] = mv2IT_4x4[((i/3)*4)+(i%3)];
    }
    glUniformMatrix3fv(mv2ITLoc, 1, GL_TRUE, mv2IT_3x3);

    // Draw forearm cylinder
    glColor3f(0.9f, 0.0f, 0.0f);       // Red
    // 40 long, 9 elbow, 5 wrist, with weights applied to first half
    DrawCylinder(40.0f, 9.0f, 5.0f, 0.5f, 1.0f);
}