Example #1
0
static void drawScene(void)
{
    const GLfloat model_diffuse[4]  = {1.0f, 0.8f, 0.8f, 1.0f};
    const GLfloat model_specular[4] = {0.6f, 0.6f, 0.6f, 1.0f};
    const GLfloat model_shininess   = 20.0f;

    glPushMatrix();

    // Rotate the object
    glRotatef((GLfloat) rot_x * 0.5f, 1.0f, 0.0f, 0.0f);
    glRotatef((GLfloat) rot_y * 0.5f, 0.0f, 1.0f, 0.0f);
    glRotatef((GLfloat) rot_z * 0.5f, 0.0f, 0.0f, 1.0f);

    // Set model color (used for orthogonal views, lighting disabled)
    glColor4fv(model_diffuse);

    // Set model material (used for perspective view, lighting enabled)
    glMaterialfv(GL_FRONT, GL_DIFFUSE, model_diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, model_specular);
    glMaterialf(GL_FRONT, GL_SHININESS, model_shininess);

    // Draw torus
    drawTorus();

    glPopMatrix();
}
Example #2
0
void
doRedraw(void)
{
    static GLfloat x, y, z;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glPushMatrix();
    glRotatef(x, 1.0F, 0.0F, 0.0F);
    glRotatef(y, 0.0F, 1.0F, 0.0F);
    glRotatef(z, 0.0F, 0.0F, 1.0F);

    drawTorus();

    glPopMatrix();

    SwapBuffers(hDC);

    x += 5.0F;
    if (x > 360.0F) x -= 360.0F;
    y += 7.0F;
    if (y > 360.0F) y -= 360.0F;
    z += 9.0F;
    if (z > 360.0F) z -= 360.0F;
}
Example #3
0
void init()
{
    g_theTorus = glGenLists(1);
    glNewList(g_theTorus, GL_COMPILE);
    drawTorus(20, 50);
    glEndList();
    glShadeModel(GL_FLAT);
    glClearColor(0.0, 0.0, 0.0, 0.0);
}
Example #4
0
/*******************************************************************************
 The main routine for displaying the scene.  Gets the latest snapshot of state
 from the haptic thread and uses it for displaying a 3D cursor.  Draws the
 anchor visual if the anchor is presently active.
*******************************************************************************/
void drawSceneGraphics()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);        
    
    drawCursor();

    drawSphere();
    drawTorus();
    drawTeapot();
}
Example #5
0
void WireCoilPic::draw(const dblArray3_t& dummy)
{
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	dblArray3_t xyz = { 0.0, 0.0, -1.0 };
	dblArray3_t c = cross3dVectorsAndMultByConst(xyz, axis_m);
	glTranslated(cent_m[0], cent_m[1], cent_m[2]);
	glRotated(90, c[0], c[1], c[2]);
	drawTorus(5, 30, radius_m, thickness_m);
	glPopMatrix();
}
Example #6
0
void SampleModel::drawEyeBandana() {
	setDiffuseColor(COLOR_RED);
	glPushMatrix();
	glTranslated(0, UPPER_TORSO_RADIUS + HEAD_RADIUS + 0.3, 0);
	drawTorus(0.3, 0.5);
	glPopMatrix();
	if (VAL(NINJATURTLE))
		setDiffuseColor(COLOR_GREEN);
	else
		setDiffuseColor(.940f, .816f, .811f);
}
void Cheerio::draw()
{
    if( !_isActive ) {
        return; // ignore inactive Cheerio
    }

    glPushMatrix();
    GameObject::draw();

    glColor3f( components3(CheerioColors::cheerio) );
    drawTorus( _innerRadius, _outerRadius, 10, 10 );

    glPopMatrix();
}
Example #8
0
/*******************************************************************************
 The main routine for haptically rendering the scene.
*******************************************************************************/
void drawSceneHaptics()
{
    hlBeginFrame();
    
    hlBeginShape(HL_SHAPE_FEEDBACK_BUFFER, gSphereShapeId);
    hlTouchableFace(HL_FRONT);
    drawSphere();
    hlEndShape();

    hlBeginShape(HL_SHAPE_FEEDBACK_BUFFER, gTorusShapeId);
    hlTouchableFace(HL_FRONT);
    drawTorus();
    hlEndShape();

    hlBeginShape(HL_SHAPE_FEEDBACK_BUFFER, gTeapotShapeId);
    hlTouchableFace(HL_BACK);
    drawTeapot();
    hlEndShape();

    hlEndFrame();

    // Call any event callbacks that have been triggered.
    hlCheckEvents();
}
Example #9
0
void Ariou() {
	Mat4f temp = getModelViewMatrix();
	ModelerApplication::Instance()->Swing(LEFT_UPPER_ARM_ROTATE_X, 3.1);
	//ModelerApplication::Instance()->Swing(LEFT_UPPER_ARM_ROTATE_Y, 2.5);

	ModelerApplication::Instance()->Swing(HEAD_ROTATE, 1);

	ModelerApplication::Instance()->Swing(RIGHT_UPPER_ARM_ROTATE_X, 1.1);
	ModelerApplication::Instance()->Swing(RIGHT_UPPER_ARM_ROTATE_Y, 4.5);

	ModelerApplication::Instance()->Swing(LEFT_LEG_ROTATE_X, 6.1);
	ModelerApplication::Instance()->Swing(RIGHT_LEG_ROTATE_X, 6.1);
	glPushMatrix();
		glTranslated(VAL(XPOS), VAL(YPOS), VAL(ZPOS));
		glScaled(VAL(XSCALE), VAL(YSCALE), VAL(ZSCALE));
		glRotated(VAL(ROTATE), 0, 1, 0);
		setDiffuseColor(COLOR_YELLOW);

		// Torus
		if (VAL(DETAIL_LEVEL) > 1) {
			glPushMatrix();
				glTranslated(.0f, 6, .0f);
				drawTorus(VAL(TORUS_R), VAL(TORUS_r));
			glPopMatrix();
		}
		
		//head
		glPushMatrix();
			glTranslated(0, VAL(LEG_LENGTH) + 0.05 + VAL(HEIGHT) + 0.05 + VAL(HEAD_SIZE), 0);
			glRotated(VAL(HEAD_ROTATE), 0.0, 1.0, 0.0);
			drawSphere(VAL(HEAD_SIZE));
			if (VAL(DETAIL_LEVEL) > 2) {

				// Nose
				drawRoundCylinder(VAL(HEAD_SIZE) * 1.1, 0.2, 0.2);

				// Ear
				glPushMatrix();
				glTranslated(0.9 / sqrt(0.9*0.9 + 1.1*1.1) * VAL(HEAD_SIZE), 1.1 / sqrt(0.9*0.9 + 1.1*1.1) * VAL(HEAD_SIZE), 0);
				glRotated(-20, 0, 0, 1);
				SpawnParticles(temp);
				drawPyramid(VAL(EAR_SIZE));
				glPopMatrix();

				glPushMatrix();
				glTranslated(-0.9 / sqrt(0.9*0.9 + 1.1*1.1) * VAL(HEAD_SIZE), 1.1 / sqrt(0.9*0.9 + 1.1*1.1) * VAL(HEAD_SIZE), 0);
				glRotated(20, 0, 0, 1);
				SpawnParticles(temp);
				drawPyramid(VAL(EAR_SIZE));
				glPopMatrix();
				
				// Eyes
				glPushMatrix();
				setDiffuseColor(COLOR_RED);
				glTranslated(-0.5 / sqrt(0.5*0.5 * 2) * VAL(HEAD_SIZE) * 0.5, 0.5 / sqrt(0.5*0.5 * 2) * VAL(HEAD_SIZE) * 0.5, VAL(HEAD_SIZE) - 0.9);
					drawRoundCylinder( 0.9, 0.2, 0.2);
				glPopMatrix();
				glPushMatrix();
				setDiffuseColor(COLOR_RED);
				glTranslated( 0.5 / sqrt(0.5*0.5 * 2) * VAL(HEAD_SIZE) * 0.5, 0.5 / sqrt(0.5*0.5 * 2) * VAL(HEAD_SIZE) * 0.5, VAL(HEAD_SIZE) - 0.9);
					drawRoundCylinder( 0.9, 0.2, 0.2);
				glPopMatrix();
			}
		glPopMatrix();

		if (VAL(DETAIL_LEVEL) > 1) {
			//body
			// a.k.a. torso/trunk
			glPushMatrix();
			setDiffuseColor(COLOR_YELLOW);
			glTranslated(0, 0.05 + VAL(LEG_LENGTH), 0);
			glRotated(-90, 1.0, 0.0, 0.0);
			drawRoundCylinder(VAL(HEIGHT), 0.7, 0.6);
			glPushMatrix();
			glTranslated(-0.8, 0, VAL(HEIGHT) - 0.4);
			glRotated(90, 0, 1, 0);
			// the shoulder
			if (VAL(DETAIL_LEVEL) > 2) {
				drawRoundCylinder(1.6, 0.2, 0.2);
			}
			glPopMatrix();

			// the waist
			if (VAL(DETAIL_LEVEL) > 3) {
				glPushMatrix();
				glTranslated(0, 0, 0.5);
				glRotated(90, 1, 0, 0);
				drawTorus(0.7, 0.08);
				glPopMatrix();
			}

			glPopMatrix();

			if (VAL(DETAIL_LEVEL) > 2) {
				//right arm
				glPushMatrix();
				glTranslated(-0.7 - 0.20, VAL(LEG_LENGTH) + 0.05 + VAL(HEIGHT) * 0.9f, 0);
				glTranslated(0.15, 0, 0);
				glRotated(VAL(RIGHT_UPPER_ARM_ROTATE_X), 1.0, 0.0, 0.0);
				glRotated(VAL(RIGHT_UPPER_ARM_ROTATE_Y), 0.0, 1.0, 0.0);
				glTranslated(-0.15, 0, 0);
				drawRoundCylinder(VAL(UPPER_ARM_LENGTH), 0.22, 0.15);

				// lower arm
				glTranslated(0, 0, VAL(UPPER_ARM_LENGTH) - 0.1);
				glRotated(VAL(RIGHT_LOWER_ARM_ROTATE) - 180, 1, 0, 0);
				drawRoundCylinder(VAL(LOWER_ARM_LENGTH), 0.15, 0.20);

				// hand
				glPushMatrix();
				glTranslated(-0.03, -0.15, VAL(LOWER_ARM_LENGTH) - 0.1);
				glRotated(VAL(RIGHT_HAND_ANGLE), 0, 1, 0);
				drawCylinder(0.8, 0.15, 0.0001);
				glPopMatrix();

				glPushMatrix();
				glTranslated(0.03, -0.15, VAL(LOWER_ARM_LENGTH) - 0.1);
				glRotated(-VAL(RIGHT_HAND_ANGLE), 0, 1, 0);
				drawCylinder(0.8, 0.15, 0.0001);
				glPopMatrix();

				glPopMatrix();

				//left arm
				glPushMatrix();
				glTranslated(0.7 + 0.20, VAL(LEG_LENGTH) + 0.05 + VAL(HEIGHT) * 0.9f, 0);
				glTranslated(-0.15, 0, 0);
				glRotated(VAL(LEFT_UPPER_ARM_ROTATE_X), 1.0, 0.0, 0.0);
				glRotated(VAL(LEFT_UPPER_ARM_ROTATE_Y), 0.0, 1.0, 0.0);
				glTranslated(0.15, 0, 0);
				drawRoundCylinder(VAL(UPPER_ARM_LENGTH), 0.22, 0.15);

				glTranslated(0, 0, VAL(UPPER_ARM_LENGTH) - 0.1);
				glRotated(VAL(LEFT_LOWER_ARM_ROTATE) - 180, 1, 0, 0);
				drawRoundCylinder(VAL(LOWER_ARM_LENGTH), 0.15, 0.20);

				// hand
				glPushMatrix();
				glTranslated(-0.03, 0, VAL(LOWER_ARM_LENGTH) - 0.1);
				glRotated(VAL(LEFT_HAND_ANGLE), 0, 1, 0);
				drawBox(0.03, 0.25, 0.5);
				glPopMatrix();

				glPushMatrix();
				glTranslated(0.03, 0, VAL(LOWER_ARM_LENGTH) - 0.1);
				glRotated(-VAL(LEFT_HAND_ANGLE), 0, 1, 0);
				drawBox(0.03, 0.25, 0.5);
				if (VAL(DETAIL_LEVEL) > 3) {
					glRotated(90, 0, 0, 1);
					drawCylinder(5, 0.02, 0.02);
					if (VAL(DETAIL_LEVEL) > 4) {
						glTranslated(0, 0, 4);

						glPushMatrix();
						setDiffuseColor(COLOR_GREEN);
						glTranslated(0, -0.5, 1);
						//SpawnParticles(temp);
						glPushMatrix();
						glRotated(90, 1.0, 0.0, 0.0);
						glPopMatrix();
						glPopMatrix();
					}
				}
				glPopMatrix();

				glPopMatrix();
			}

			//right leg
			glPushMatrix();
			setDiffuseColor(COLOR_YELLOW);
			glTranslated(-0.5, VAL(LEG_LENGTH), 0);
			glRotated(VAL(RIGHT_LEG_ROTATE_X), 1.0, 0.0, 0.0);
			glRotated(VAL(RIGHT_LEG_ROTATE_Y), 0.0, 1.0, 0.0);
			drawRoundCylinder(VAL(LEG_LENGTH) - 0.15, 0.3, 0.4);
			glTranslated(0, 0, VAL(LEG_LENGTH) * 0.85f);
			glRotated(70, 1, 0, 0);
			drawTorus(VAL(FEET_SIZE), VAL(FEET_SIZE) / 4);

			glPopMatrix();

			//left leg
			glPushMatrix();
			glTranslated(0.5, VAL(LEG_LENGTH), 0);
			glRotated(VAL(LEFT_LEG_ROTATE_X), 1.0, 0.0, 0.0);
			glRotated(VAL(LEFT_LEG_ROTATE_Y), 0.0, 1.0, 0.0);
			drawRoundCylinder(VAL(LEG_LENGTH) - 0.15, 0.3, 0.4);
			glTranslated(0, 0, VAL(LEG_LENGTH) * 0.85f);
			glRotated(70, 1, 0, 0);
			drawTorus(VAL(FEET_SIZE), VAL(FEET_SIZE) / 4);

			glPopMatrix();
		}
	glPopMatrix();
}
Example #10
0
int main(int argc, char* argv[])
{
    SetupCallbacks();

    // generate geometry

    genTorus( TORUS_ROWS, TORUS_SLICES, TORUS_RADIUS, TORUS_THICKNESS, torus_vertices, torus_indices );

    // flush cache so that no stray data remains

    sceKernelDcacheWritebackAll();

    // setup Edram buffers

    void* frameBuffer = (void*)0;
    const void* doubleBuffer = (void*)0x44000;
    const void* renderTarget = (void*)0x88000;
    const void* depthBuffer = (void*)0x110000;

    // setup GU

    sceGuInit();

    sceGuStart(GU_DIRECT,list);
    sceGuDrawBuffer(GU_PSM_4444,frameBuffer,BUF_WIDTH);
    sceGuDispBuffer(SCR_WIDTH,SCR_HEIGHT,(void*)doubleBuffer,BUF_WIDTH);
    sceGuDepthBuffer((void*)depthBuffer,BUF_WIDTH);
    sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
    sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);
    sceGuDepthRange(0xc350,0x2710);
    sceGuScissor(0,0,SCR_WIDTH,SCR_HEIGHT);
    sceGuEnable(GU_SCISSOR_TEST);
    sceGuDepthFunc(GU_GEQUAL);
    sceGuEnable(GU_DEPTH_TEST);
    sceGuFrontFace(GU_CW);
    sceGuShadeModel(GU_SMOOTH);
    sceGuEnable(GU_CULL_FACE);
    sceGuEnable(GU_TEXTURE_2D);
    sceGuFinish();
    sceGuSync(0,0);

    sceDisplayWaitVblankStart();
    sceGuDisplay(GU_TRUE);

    // run sample
    int val = 0;
    Texture offscreenTexture = {
        GU_PSM_4444,
        0, 128, 128, 128,
        sceGeEdramGetAddr() + (int)renderTarget
    };

    for(;;)
    {
        sceGuStart(GU_DIRECT,list);

        {
            sceGuDrawBufferList(GU_PSM_4444,(void*)renderTarget,offscreenTexture.stride);

            // setup viewport

            sceGuOffset(2048 - (offscreenTexture.width/2),2048 - (offscreenTexture.height/2));
            sceGuViewport(2048,2048,offscreenTexture.width,offscreenTexture.height);

            // clear screen

            sceGuClearColor(0xffffffff);
            sceGuClearDepth(0);
            sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

            // draw torus to offscreen texture

            drawTorus( val );
        }

        {
            // set frame buffer

            sceGuDrawBufferList(GU_PSM_4444,(void*)frameBuffer,BUF_WIDTH);

            // setup viewport

            sceGuOffset(2048 - (SCR_WIDTH/2),2048 - (SCR_HEIGHT/2));
            sceGuViewport(2048,2048,SCR_WIDTH,SCR_HEIGHT);

            // clear screen

            sceGuClearColor(0xff554433);
            sceGuClearDepth(0);
            sceGuClear(GU_COLOR_BUFFER_BIT|GU_DEPTH_BUFFER_BIT);

            // draw cube using offscreen texture

            drawCube( &offscreenTexture, val );

        }

        sceGuFinish();
        sceGuSync(0,0);

        sceDisplayWaitVblankStart();
        frameBuffer = sceGuSwapBuffers();

        val++;
    }

    sceGuTerm();

    sceKernelExitGame();
    return 0;
}
Example #11
0
void
redraw(void)
{
  glClearColor(0.1, 0.1, 0.1, 1.0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glBegin(GL_QUADS);
  glColor3f(0.9, 0.0, 1.0);
  glVertex3f(-2.0, -2.0, -1.0);
  glColor3f(0.9, 0.0, 1.0);
  glVertex3f(2.0, -2.0, -1.0);
  glColor3f(0.0, 0.1, 0.1);
  glVertex3f(2.0, 2.0, -1.0);
  glColor3f(0.0, 0.1, 0.1);
  glVertex3f(-2.0, 2.0, -1.0);
  glEnd();

  glEnable(GL_DEPTH_TEST);

  if (useLighting) {
    glEnable(GL_LIGHTING);
    glPushMatrix();
    glRotatef(lightRotY, 0, 1, 0);
    glRotatef(lightRotX, 1, 0, 0);
    setLight();
    glPopMatrix();
  } else {
    glColor3f(0.2, 0.2, 0.2);
  }
  if (useTexture || useSpecularTexture) {
    glEnable(GL_TEXTURE_2D);
  }
  if (useTexture) {
    setCheckTexture();
  } else {
    setNullTexture();
  }
  if (useSpecularTexture) {
    /* pass one */
    glEnable(GL_BLEND);
    glBlendFunc(GL_ONE, GL_ZERO);
    setMaterial(MAT_NO_SPECULAR);
  } else {
    setMaterial(MAT_ALL);
  }
  glPushMatrix();
  glRotatef(objectRotY, 0, 1, 0);
  glRotatef(objectRotX, 1, 0, 0);
  if (useHighRes) {
    switch (drawObj) {
    case 0:
      drawSphere(64, 64, 0.8);
      break;
    case 1:
      drawCylinder(32, 64, 1.0, 0.4);
      break;
    case 2:
      drawTorus(64, 64, 0.6, 0.2);
      break;
    default:
      break;
    }
  } else {
    switch (drawObj) {
    case 0:
      drawSphere(16, 32, 0.8);
      break;
    case 1:
      drawCylinder(6, 16, 1.0, 0.4);
      break;
    case 2:
      drawTorus(32, 16, 0.6, 0.2);
      break;
    default:
      break;
    }
  }
  glPopMatrix();

  if (useSpecularTexture) {
    /* pass two */
    if (!useLighting) {
      glColor3f(1.0, 1.0, 1.0);
    }
    glBlendFunc(GL_ONE, GL_ONE);
    glEnable(GL_TEXTURE_GEN_S);
    glEnable(GL_TEXTURE_GEN_T);
    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);

    setMaterial(MAT_SPECULAR_TEXTURE_ONLY);
    glPushMatrix();
    glRotatef(objectRotY, 0, 1, 0);
    glRotatef(objectRotX, 1, 0, 0);
    if (useHighRes) {
      switch (drawObj) {
      case 0:
        drawSphere(64, 64, 0.8);
        break;
      case 1:
        drawCylinder(32, 64, 1.0, 0.4);
        break;
      case 2:
        drawTorus(64, 64, 0.6, 0.2);
        break;
      default:
        break;
      }
    } else {
      switch (drawObj) {
      case 0:
        drawSphere(16, 32, 0.8);
        break;
      case 1:
        drawCylinder(6, 16, 1.0, 0.4);
        break;
      case 2:
        drawTorus(32, 16, 0.6, 0.2);
        break;
      default:
        break;
      }
    }
    glPopMatrix();
  }
  glDisable(GL_DEPTH_TEST);
  glDisable(GL_LIGHTING);
  glDisable(GL_TEXTURE_2D);
  glDisable(GL_BLEND);
  glDisable(GL_TEXTURE_GEN_S);
  glDisable(GL_TEXTURE_GEN_T);
}
Example #12
0
void Ariou::draw() {
	ModelerView::draw();

	ModelerApplication::Instance()->Swing(LEFT_UPPER_ARM_ROTATE_X, 3.1);
	//ModelerApplication::Instance()->Swing(LEFT_UPPER_ARM_ROTATE_Y, 2.5);

	ModelerApplication::Instance()->Swing(HEAD_ROTATE, 1);

	ModelerApplication::Instance()->Swing(RIGHT_UPPER_ARM_ROTATE_X, 1.1);
	ModelerApplication::Instance()->Swing(RIGHT_UPPER_ARM_ROTATE_Y, 4.5);

	ModelerApplication::Instance()->Swing(LEFT_LEG_ROTATE_X, 6.1);
	ModelerApplication::Instance()->Swing(RIGHT_LEG_ROTATE_X, 6.1);

	ModelerApplication::Instance()->Swing(LS_DEPTH, 0.02);
	ModelerApplication::Instance()->Swing(LS_ANGLE, 0.15);

	setAmbientColor(.1f, .1f, .1f);
	setDiffuseColor(COLOR_RED);
	glPushMatrix();
	glScaled(VAL(FLOOR_SIZE), VAL(FLOOR_SIZE), VAL(FLOOR_SIZE));
	drawSierpinskiTriangle(0, 0, 1,
		0.86602540378443864676372317075293618347140262690519, 0, -0.5,
		-0.86602540378443864676372317075293618347140262690519, 0, -0.5,
		VAL(FLOOR_DEPTH));

	glTranslated(0, -0.05, 0);
	setDiffuseColor(COLOR_WHITE);
	drawPolygon(16, 2);
	glPopMatrix();


	glPushMatrix();
		/*
		GLfloat maambient[] = { 0.79225f, 0.79225f, 0.79225f, 1.0f };
		GLfloat madiffuse[] = { 0.50754f, 0.50754f, 0.50754f, 1.0f };
		GLfloat maspecular[] = { 0.508273f, 0.508273f, 0.508273f, 0.508273f };
		GLfloat shininess = 51.2f;
		GLfloat maemi[] = { 0.0f, 0.0f, 0.0f, 1.0f };

		glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, maambient);
		glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, madiffuse);
		glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, maspecular);
		glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, shininess);
		glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, maemi);
		*/

		glTranslated(VAL(XPOS), VAL(YPOS), VAL(ZPOS));
		glScaled(VAL(XSCALE), VAL(YSCALE), VAL(ZSCALE));
		glRotated(VAL(ROTATE), 0, 1, 0);
		setDiffuseColor(COLOR_YELLOW);

		// Torus
		if (VAL(DETAIL_LEVEL) > 1) {
			glPushMatrix();
				glTranslated(.0f, 6, .0f);
				drawTorus(VAL(TORUS_R), VAL(TORUS_r));
			glPopMatrix();
		}
		
		//head
		glPushMatrix();
			glTranslated(0, VAL(LEG_LENGTH) + 0.05 + VAL(HEIGHT) + 0.05 + VAL(HEAD_SIZE), 0);
			glRotated(VAL(HEAD_ROTATE), 0.0, 1.0, 0.0);
			drawSphere(VAL(HEAD_SIZE));
			if (VAL(DETAIL_LEVEL) > 2) {

				// Nose
				drawRoundCylinder(VAL(HEAD_SIZE) * 1.1, 0.2, 0.2);

				// Ear
				glPushMatrix();
				glTranslated(0.9 / sqrt(0.9*0.9 + 1.1*1.1) * VAL(HEAD_SIZE), 1.1 / sqrt(0.9*0.9 + 1.1*1.1) * VAL(HEAD_SIZE), 0);
				glRotated(-20, 0, 0, 1);
				drawPyramid(VAL(EAR_SIZE));
				glPopMatrix();

				glPushMatrix();
				glTranslated(-0.9 / sqrt(0.9*0.9 + 1.1*1.1) * VAL(HEAD_SIZE), 1.1 / sqrt(0.9*0.9 + 1.1*1.1) * VAL(HEAD_SIZE), 0);
				glRotated(20, 0, 0, 1);
				drawPyramid(VAL(EAR_SIZE));
				glPopMatrix();
				
				// Eyes
				glPushMatrix();
				setDiffuseColor(COLOR_RED);
				glTranslated(-0.5 / sqrt(0.5*0.5 * 2) * VAL(HEAD_SIZE) * 0.5, 0.5 / sqrt(0.5*0.5 * 2) * VAL(HEAD_SIZE) * 0.5, VAL(HEAD_SIZE) - 0.9);
					drawRoundCylinder( 0.9, 0.2, 0.2);
				glPopMatrix();
				glPushMatrix();
				setDiffuseColor(COLOR_RED);
				glTranslated( 0.5 / sqrt(0.5*0.5 * 2) * VAL(HEAD_SIZE) * 0.5, 0.5 / sqrt(0.5*0.5 * 2) * VAL(HEAD_SIZE) * 0.5, VAL(HEAD_SIZE) - 0.9);
					drawRoundCylinder( 0.9, 0.2, 0.2);
				glPopMatrix();
			}
		glPopMatrix();

		if (VAL(DETAIL_LEVEL) > 1) {
			//body
			// a.k.a. torso/trunk
			glPushMatrix();
			setDiffuseColor(COLOR_YELLOW);
			glTranslated(0, 0.05 + VAL(LEG_LENGTH), 0);
			glRotated(-90, 1.0, 0.0, 0.0);
			drawRoundCylinder(VAL(HEIGHT), 0.7, 0.6);
			glPushMatrix();
			glTranslated(-0.8, 0, VAL(HEIGHT) - 0.4);
			glRotated(90, 0, 1, 0);
			// the shoulder
			if (VAL(DETAIL_LEVEL) > 2) {
				drawRoundCylinder(1.6, 0.2, 0.2);
			}
			glPopMatrix();

			// the waist
			if (VAL(DETAIL_LEVEL) > 3) {
				glPushMatrix();
				glTranslated(0, 0, 0.5);
				glRotated(90, 1, 0, 0);
				drawTorus(0.7, 0.08);
				glPopMatrix();
			}

			glPopMatrix();

			if (VAL(DETAIL_LEVEL) > 2) {
				//right arm
				glPushMatrix();
				glTranslated(-0.7 - 0.20, VAL(LEG_LENGTH) + 0.05 + VAL(HEIGHT) * 0.9f, 0);
				glTranslated(0.15, 0, 0);
				glRotated(VAL(RIGHT_UPPER_ARM_ROTATE_X), 1.0, 0.0, 0.0);
				glRotated(VAL(RIGHT_UPPER_ARM_ROTATE_Y), 0.0, 1.0, 0.0);
				glTranslated(-0.15, 0, 0);
				drawRoundCylinder(VAL(UPPER_ARM_LENGTH), 0.22, 0.15);

				// lower arm
				glTranslated(0, 0, VAL(UPPER_ARM_LENGTH) - 0.1);
				glRotated(VAL(RIGHT_LOWER_ARM_ROTATE) - 180, 1, 0, 0);
				drawRoundCylinder(VAL(LOWER_ARM_LENGTH), 0.15, 0.20);

				// hand
				glPushMatrix();
				glTranslated(-0.03, -0.15, VAL(LOWER_ARM_LENGTH) - 0.1);
				glRotated(VAL(RIGHT_HAND_ANGLE), 0, 1, 0);
				drawCylinder(0.8, 0.15, 0.0001);
				glPopMatrix();

				glPushMatrix();
				glTranslated(0.03, -0.15, VAL(LOWER_ARM_LENGTH) - 0.1);
				glRotated(-VAL(RIGHT_HAND_ANGLE), 0, 1, 0);
				drawCylinder(0.8, 0.15, 0.0001);
				glPopMatrix();

				glPopMatrix();

				//left arm
				glPushMatrix();
				glTranslated(0.7 + 0.20, VAL(LEG_LENGTH) + 0.05 + VAL(HEIGHT) * 0.9f, 0);
				glTranslated(-0.15, 0, 0);
				glRotated(VAL(LEFT_UPPER_ARM_ROTATE_X), 1.0, 0.0, 0.0);
				glRotated(VAL(LEFT_UPPER_ARM_ROTATE_Y), 0.0, 1.0, 0.0);
				glTranslated(0.15, 0, 0);
				drawRoundCylinder(VAL(UPPER_ARM_LENGTH), 0.22, 0.15);

				glTranslated(0, 0, VAL(UPPER_ARM_LENGTH) - 0.1);
				glRotated(VAL(LEFT_LOWER_ARM_ROTATE) - 180, 1, 0, 0);
				drawRoundCylinder(VAL(LOWER_ARM_LENGTH), 0.15, 0.20);

				// hand
				glPushMatrix();
				glTranslated(-0.03, 0, VAL(LOWER_ARM_LENGTH) - 0.1);
				glRotated(VAL(LEFT_HAND_ANGLE), 0, 1, 0);
				drawBox(0.03, 0.25, 0.5);
				glPopMatrix();

				glPushMatrix();
				glTranslated(0.03, 0, VAL(LOWER_ARM_LENGTH) - 0.1);
				glRotated(-VAL(LEFT_HAND_ANGLE), 0, 1, 0);
				drawBox(0.03, 0.25, 0.5);
				if (VAL(DETAIL_LEVEL) > 3) {
					glRotated(90, 0, 0, 1);
					drawCylinder(5, 0.02, 0.02);
					if (VAL(DETAIL_LEVEL) > 4) {
						glTranslated(0, 0, 4);
						LS ls("X", VAL(LS_DEPTH), VAL(LS_ANGLE));
						ls.expand(0);

						glPushMatrix();
						setDiffuseColor(COLOR_GREEN);
						glTranslated(0, -0.5, 1);
						glPushMatrix();
						glRotated(90, 1.0, 0.0, 0.0);
						ls.drawLS();
						glPopMatrix();
						glPopMatrix();
					}
				}
				glPopMatrix();

				glPopMatrix();
			}

			//right leg
			glPushMatrix();
			setDiffuseColor(COLOR_YELLOW);
			glTranslated(-0.5, VAL(LEG_LENGTH), 0);
			glRotated(VAL(RIGHT_LEG_ROTATE_X), 1.0, 0.0, 0.0);
			glRotated(VAL(RIGHT_LEG_ROTATE_Y), 0.0, 1.0, 0.0);
			drawRoundCylinder(VAL(LEG_LENGTH) - 0.15, 0.3, 0.4);
			glTranslated(0, 0, VAL(LEG_LENGTH) * 0.85f);
			glRotated(70, 1, 0, 0);
			drawTorus(VAL(FEET_SIZE), VAL(FEET_SIZE) / 4);

			glPopMatrix();

			//left leg
			glPushMatrix();
			glTranslated(0.5, VAL(LEG_LENGTH), 0);
			glRotated(VAL(LEFT_LEG_ROTATE_X), 1.0, 0.0, 0.0);
			glRotated(VAL(LEFT_LEG_ROTATE_Y), 0.0, 1.0, 0.0);
			drawRoundCylinder(VAL(LEG_LENGTH) - 0.15, 0.3, 0.4);
			glTranslated(0, 0, VAL(LEG_LENGTH) * 0.85f);
			glRotated(70, 1, 0, 0);
			drawTorus(VAL(FEET_SIZE), VAL(FEET_SIZE) / 4);

			glPopMatrix();
		}
	glPopMatrix();
}
Example #13
0
void Display()
{
    static CStopWatch timer;
    GLfloat yRot = timer.GetElapsedSeconds() * 60.0;

    M3DVector3f vCameraPosition;
    M3DVector3f vCameraForward;
    M3DVector3f vMirrorPosition;
    M3DVector3f vMirrorForward;
    void movingCylinder();

    cameraFrame.GetOrigin(vCameraPosition);
    cameraFrame.GetForwardVector(vCameraForward);

    vMirrorPosition[0] = 0.0f;
    vMirrorPosition[1] = 0.1f;
    vMirrorPosition[2] = -20.0f;
    mirrorFrame.SetOrigin(vMirrorPosition);

    vMirrorForward[0] = vCameraPosition[0];
    vMirrorForward[1] = vCameraPosition[1];
    vMirrorForward[2] = (vCameraPosition[2] + 20);
    m3dNormalizeVector3(vMirrorForward);
    mirrorFrame.SetForwardVector(vMirrorForward);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glBindFramebuffer(GL_DRAW_FRAMEBUFFER,fboName);
    glDrawBuffers(1,fboBuffers);
    glViewport(0,0,mirrorWidth,mirrorHeight);

    modelViewMatrix.PushMatrix();
    M3DMatrix44f mMirrorView;
    mirrorFrame.GetCameraMatrix(mMirrorView);
    modelViewMatrix.MultMatrix(mMirrorView);
    modelViewMatrix.Scale(-1.0f,1.0f,1.0f);
    glBindTexture(GL_TEXTURE_2D,textures[0]);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE,
                                 transformPipeline.GetModelViewProjectionMatrix(),
                                 vWhite,0);
    floorBatch.Draw();

    drawSun();
    drawTorus(yRot);
    modelViewMatrix.PopMatrix();

    glBindFramebuffer(GL_DRAW_FRAMEBUFFER,0);
    glDrawBuffers(1,windowBuffer);
    glViewport(0,0,mirrorWidth,mirrorHeight);

    modelViewMatrix.PushMatrix();
    M3DMatrix44f mCamera;
    cameraFrame.GetCameraMatrix(mCamera);
    modelViewMatrix.MultMatrix(mCamera);

    modelViewMatrix.PushMatrix();
    glBindTexture(GL_TEXTURE_2D,mirrorTexture);
    shaderManager.UseStockShader(GLT_SHADER_TEXTURE_REPLACE,
                                 transformPipeline.GetModelViewProjectionMatrix(),0);
    mirrorFrontBatch.Draw();
    modelViewMatrix.PopMatrix();
    modelViewMatrix.PushMatrix();
    glBindTexture(GL_TEXTURE_2D,textures[0]);
    shaderManager.UseStockShader(GLT_SHADER_TEXTURE_MODULATE,
                                 transformPipeline.GetModelViewProjectionMatrix(),
                                 vWhite,0);
    floorBatch.Draw();

    drawSun();
    drawTorus(yRot);
    modelViewMatrix.PopMatrix();
    modelViewMatrix.PopMatrix();


    //control to moving cylinder
    movingCylinder();

    glutSwapBuffers();
    glutPostRedisplay();
}