Beispiel #1
0
void displayCallback()
{
	akj::ResetCubeDrawCount();
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glClear(  GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	
	if(gUseFBO)
	{
		if(gWidth != gPostFXFrameBuffer->mWidth || gHeight != gPostFXFrameBuffer->mHeight)
		{
			gPostFXFrameBuffer->InitBuffers(gWidth, gHeight, GL_SRGB8_ALPHA8);
			//rebind to the normal back buffer
			glBindFramebuffer(GL_FRAMEBUFFER, 0);
		}
		glEnable(GL_BLEND);
		glBlendEquation(GL_FUNC_ADD);
		glBlendFuncSeparate (GL_ONE, GL_ZERO, GL_ONE, GL_ZERO);
		RenderBackground();
		glBlendFuncSeparate (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO);

		//flame effects need to know about the time 
		gCompositingShader->BindUniformToFloat("my_time", gTime);

		glPolygonMode(GL_FRONT, GL_FILL);
		gCompositingShader->Use();
		// clear the color buffer
		// set up camera: we want a quad matched up to the viewport
		glMatrixMode( GL_PROJECTION );
		glLoadIdentity();
		glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
		glMatrixMode( GL_MODELVIEW );
		glLoadIdentity();
		//drawcube gives a -0.5 - 0.5 range, so mult by 2
		glScalef(2.0, 2.0, 1.0);
		glTranslatef( 0.0, 0.0, -0.8);
		akj::glDrawRect2D();
		akj::glCheckAllErrors(__FILE__,__LINE__);
		glClear( GL_DEPTH_BUFFER_BIT );
	}
	else
	{
		RenderBackground();
	}
	glClear( GL_DEPTH_BUFFER_BIT );
	glDisable(GL_BLEND);
	SetupCamera();
	RenderRabbit();

	if(gUseFBO)
	{
		if(gClearFBO)
		{
			glClear(  GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
			gClearFBO = false;
		}
		glActiveTexture(GL_TEXTURE0 + gPostFXFrameBuffer->GetBoundTextureUnit());
		glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, gWidth, gHeight);

	}

	glutSwapBuffers();
	if (gDump) {               // save images to file
		dumpPPM();
	}
	//printf("number of cubes this frame = %d\n", akj::GetCubeDrawCount());
	
}
void displayCallback()
{
    // clear the color buffer
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    
    // set up camera
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective( 45, 1.0, 0.1, 200.0 );
    
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();
    glTranslatef( 0.0, 0.0, -10.0 );
    switch (camera) {
        case 'p':
            glRotatef( 180, 0.0, 1.0, 0.0 );
            break;
        case 'f':
            glRotatef( -90, 0.0, 1.0, 0.0 );
            break;
        case 'b':
            glRotatef( 90, 0.0, 1.0, 0.0 );
            break;
        case 'a':
            glRotatef( 90, 1.0, 0.0, 0.0 );
            break;
        case 'u':
            glRotatef( -90, 1.0, 0.0, 0.0 );
            break;
        case 'r':
            break;
            
    }
    
    
    drawAxis();
    
    // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    // Draw your rabbit here
    // @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    
    // Always start the hierarchy from the middle body block
    
    glPushMatrix(); // Save camera matrix
    glColor3f(1,1,1); // Make rabbit white
    
    // Draw middle body block
    glTranslatef(0,jumpHeight+1,0);
    glTranslatef(0,0.1,0);
    glRotatef(rearAngle,0,0,1);
    glTranslatef(0,-0.1,0);
    glutSolidCube(1.3);
    
    // Build front body block
    glPushMatrix();
    glTranslatef(0.8,-0.05,0);
    glRotatef(jumpAngle*0.7,0,0,1);
    glRotatef(-curlAngle*0.4,0,0,1);
    glScaled(0.4,1,1);
    glutSolidCube(1.3);
    glScaled(1/0.4,1,1);
    
    // Build front right leg
    glPushMatrix();
    glTranslatef(0.15,-0.35,0.25);
    glRotated(FRLegAngle+30,0,0,1);
    glTranslatef(-0.11,-0.35,0.25);
    glScalef(0.4,1,0.4);
    glutSolidCube(0.5);
    
    // Build front right paw
    glPushMatrix();
    glScalef(1/0.4,1,1/0.4);
    glTranslatef(0.05,-0.25,0);
    glRotated(-FRLegAngle*0.85-30,0,0,1);
    glScalef(0.6,0.2,0.5);
    glutSolidCube(0.5);
    glPopMatrix();
    glPopMatrix();
    
    // Build front left leg
    glPushMatrix();
    glTranslatef(0.15,-0.35,-0.25);
    glRotated(FLLegAngle+30,0,0,1);
    glTranslatef(-0.11,-0.35,-0.25);
    glScalef(0.4,1,0.4);
    glutSolidCube(0.5);
    
    // Build front left paw
    glPushMatrix();
    glScalef(1/0.4,1,1/0.4);
    glTranslatef(0.05,-0.25,0);
    glRotated(-FLLegAngle*0.85-30,0,0,1);
    glScalef(0.6,0.2,0.5);
    glutSolidCube(0.5);
    glPopMatrix();
    glPopMatrix();
    
    // Build neck
    glPushMatrix();
    glRotatef(-headAngle+15,0,0,1);
    glTranslatef(0.3,0.5,0);
    glScalef(1.5,0.5,0.5);
    glutSolidCube(1);
    glScalef(1/1.5,2,2);
    
    // Build Head
    glTranslatef(0.5,0,0);
    glRotatef(-headAngle*1.8,0,0,1);
    glRotatef(-rearAngle,0,0,1);
    glScalef(0.8,0.8,0.8);
    glutSolidCube(1);
    glScalef(1/0.8,1/0.8,1/0.8);
    
    // Build right eye
    glPushMatrix();
    glTranslatef(0.355,0.07,0.17);
    glScalef(0.1,0.1,0.1);
    glColor3f(1,0,0); // Make the rabbit evil!
    glutSolidCube(1);
    glPopMatrix();
    
    // Build left eye
    glPushMatrix();
    glTranslatef(0.355,0.07,-0.17);
    glScalef(0.1,0.1,0.1);
    glutSolidCube(1);
    glColor3f(1,1,1);
    glPopMatrix();
    
    // Build the right ear
    glPushMatrix();
    glTranslatef(0.2,0,0.42);
    glTranslatef(0,0.3,0);
    glRotatef(-155+REAngle,1,0,0);
    glTranslatef(0,-0.3,0);
    glScalef(0.2,0.7,0.07);
    glutSolidCube(1);
    glPopMatrix();
    
    // Build the left ear
    glPushMatrix();
    glTranslatef(0.2,0,-0.42);
    glTranslatef(0,0.3,0);
    glRotatef(155-LEAngle,1,0,0);
    glTranslatef(0,-0.3,0);
    glScalef(0.2,0.7,0.07);
    glutSolidCube(1);
    glPopMatrix();
    glPopMatrix();
    glPopMatrix();
    
    // Build back body block
    glTranslatef(-0.9,-0.1,0);
    glRotatef(-jumpAngle+22, 0, 0, 1);
    glTranslatef(0.5,0.5,0);
    glRotatef(curlAngle*0.8,0,0,1);
    glTranslatef(-0.5,-0.5,0);
    glScaled(0.95,1,1);
    glutSolidCube(1.2);
    glScaled(1/0.95,1,1);
    
    // Build the right back leg
    glPushMatrix();
    glTranslatef(-0.1,-0.25,0.75);
    glTranslatef(0,0.3,0);
    glRotatef(BRLegAngle*0.8,0,0,1);
    glTranslatef(0,-0.3,0);
    glScalef(0.8,1,0.2);
    glutSolidCube(1);
    glScalef(1/0.8,1,1/0.2);
    
    // Build right back paw
    glPushMatrix();
    glTranslatef(-0.2,-0.46,0);
    glTranslatef(-0.13,0,0);
    glRotatef(-22-BRLegAngle*0.7,0,0,1);
    glRotatef(-rearAngle,0,0,1);
    glTranslatef(0.18,0,0);
    glScalef(0.5,0.2,0.3);
    glutSolidCube(1);
    glPopMatrix();
    glPopMatrix();
    
    // Build the back left leg
    glPushMatrix();
    glTranslatef(-0.1,-0.25,-0.75);
    glTranslatef(0,0.3,0);
    glRotatef(BLLegAngle*0.8,0,0,1);
    glTranslatef(0,-0.3,0);
    glScalef(0.8,1,0.2);
    glutSolidCube(1);
    glScalef(1/0.8,1,1/0.2);
    
    // Build left back paw
    glPushMatrix();
    glTranslatef(-0.2,-0.46,0);
    glTranslatef(-0.13,0,0);
    glRotatef(-22-BLLegAngle*0.7,0,0,1);
    glRotatef(-rearAngle,0,0,1);
    glTranslatef(0.18,0,0);
    glScalef(0.5,0.2,0.3);
    glutSolidCube(1);
    glPopMatrix();
    glPopMatrix();
    
    // Build tail
    glTranslatef(-0.6,0.2,0);
    glScalef(0.5,0.5,0.5);
    glutSolidCube(1);
    glPopMatrix();
    
    
    //    cout << "jumpHeight " << jumpHeight << "\n";
    //    cout << "JumpAngle " << jumpAngle << "\n";
    //    cout << "headAngle " << headAngle << "\n";
    //    cout << "FLLegAngle " << FLLegAngle << "\n";
    //    cout << "FRLegAngle " << FRLegAngle << "\n";
    //    cout << "count:" << frames << "\n";
    //    cout << "REangle " << REAngle << isREdown << "  " << "\n";
    //    cout << "LEangle " << LEAngle << isLEdown << "  " << "\n";
    
    // draw after the opaque objects, since it is translucent
    drawFloor();
    
    // draw the buffer to the screen
    glutSwapBuffers();
    
    if (Dump) {               // save images to file
        dumpPPM(iCount);
        iCount++;
    }
    
    GLenum error = glGetError();
    if(error != GL_NO_ERROR)
        printf("ERROR: %s\n", gluErrorString(error));
    
}
Beispiel #3
0
void keyboardCallback(unsigned char c, int x, int y)
{
	const int num_axes = 6;
	static float rotation_axes[6][3] =
	{
		{0.0, 0.0, 1.0},
		{0.0, 1.0, 0.0},
		{1.0, 0.0, 0.0},
		{1.0, 1.0, 0.0},
		{1.0, 0.0, 1.0},
		{0.0, 1.0, 1.0}
	};
	switch (c)
	{
	case 'm':
		TriggerRabbitAnimation(akj::Rabbit::LIMB_RAISE_RIGHT_FORE);
		break;
	case 'l':
		TriggerRabbitAnimation(akj::Rabbit::LIMB_RAISE_LEFT_FORE);
		break;
	case 'o':
		TriggerRabbitAnimation(akj::Rabbit::LIMB_RAISE_RIGHT_HIND);
		break;
	case 'n':
		TriggerRabbitAnimation(akj::Rabbit::LIMB_RAISE_LEFT_HIND);
		break;
	case 'e':
		TriggerRabbitAnimation(akj::Rabbit::EAR_RAISE_RIGHT);
		break;
	case 'w':
		TriggerRabbitAnimation(akj::Rabbit::EAR_RAISE_LEFT);
		break;
	case 'c':
		TriggerRabbitAnimation(akj::Rabbit::BODY_CURL);
		break;
	case 't':
		TriggerRabbitAnimation(akj::Rabbit::REAR_UP);
		break;
	case 'j':
		TriggerRabbitAnimation(akj::Rabbit::JUMP);
		break;
	case 'h':
		TriggerRabbitAnimation(akj::Rabbit::HEAD_NOD);
		break;
	case '2':
		TriggerRabbitAnimation(akj::Rabbit::ELLIPSETRANS);
		break;
	case 'f':
		gFOV += 1.0f;
		break;
	case 'v':
		gFOV -= 1.0f;
		break;
	case 'g':
		gFarPlane += 1.0f;
		break;
	case 'b':
		gFarPlane -= 1.0f;
		break;
	case 'q':
		exit (0);
		break;
	case '1':
		gUseFBO = !gUseFBO;
		gClearFBO = gUseFBO;
		break;
	case 'r':
		gRotationPerSecond = cUnitQuat();
		gRabbit->SetRotation(cUnitQuat());
		gRabbit->SetTranslation(cCoord3(0.0f));
		break;
	case 's':
		gRotationPerSecond = cUnitQuat();
		break;
	case 'i':
		dumpPPM();
		break;
	case 'd':               // dump animation PPM frames
		gImageCount = 0;         // image file count
		gDump = !gDump;
		break;
	case '-':
		gRabbit->MultiplyScale(cCoord3(2.0f / 3.0f, 2.0f / 3.0f, 2.0f / 3.0f));
		break;
	case '=':
		gRabbit->MultiplyScale(cCoord3(1.5f, 1.5f, 1.5f));
		break;
	case '3':
		gDoHalfAnimations = ! gDoHalfAnimations;
		break;
	case ' ':
		gDoSmoothAnimation = ! gDoSmoothAnimation;
		break;
	case 'x':
		gRotationPerSecond = cUnitQuat(cAngleAxis(kRotationRate * 2.0f * AKJ_PIf, rotation_axes[axis_choice][0], rotation_axes[axis_choice][1], rotation_axes[axis_choice][2]));
		axis_choice = (axis_choice + 1) % num_axes;
		break;
	}

	glutPostRedisplay();
}
void keyboardCallback(unsigned char c, int x, int y) {
    frames = 0;
    switch (c) {
        case 'q':
            exit (0);
            break;
        case 'p':
            camera = 'p';
            break;
        case 'f':
            camera = 'f';
            break;
        case 'b':
            camera = 'b';
            break;
        case 'a':
            camera = 'a';
            break;
        case 'u':
            camera = 'u';
            break;
        case 'r':
            camera = 'r';
            break;
        case 'i':
            dumpPPM(iCount);
            iCount++;
            break;
        case 'd':               // dump animation PPM frames
            iCount = 0;         // image file count
            Dump = !Dump;
            break;
        case 'j':
            isJumpUp = !isJumpUp;
            if (!isJumpcutOn)
                glutIdleFunc(idle);
            else {
                jumpAngle = jumpcutValue(isJumpUp, jumpAngle, 40, 0);
                jumpHeight = jumpcutValue(isJumpUp, jumpHeight, 1, 0);
            }
            break;
        case 'm':
            isFRLegUp = !isFRLegUp;
            if (!isJumpcutOn)
                glutIdleFunc(idle);
            else
                FRLegAngle = jumpcutValue(isFRLegUp, FRLegAngle, 70, 0);
            break;
        case 'l':
            isFLLegUp = !isFLLegUp;
            if (!isJumpcutOn)
                glutIdleFunc(idle);
            else
                FLLegAngle = jumpcutValue(isFLLegUp, FLLegAngle, 70, 0);
            break;
        case 'h':
            isHeadDown = !isHeadDown;
            if (!isJumpcutOn)
                glutIdleFunc(idle);
            else
                headAngle = jumpcutValue(isHeadDown, headAngle, 12, 0);
            break;
        case 'e':
            isREdown = !isREdown;
            if (!isJumpcutOn)
                glutIdleFunc(idle);
            else
                REAngle = jumpcutValue(isREdown, REAngle, 140, 0);
            break;
        case 'w':
            isLEdown = !isLEdown;
            if (!isJumpcutOn)
                glutIdleFunc(idle);
            else
                LEAngle = jumpcutValue(isLEdown, LEAngle, 140, 0);
            break;
        case 'c':
            isCurled = !isCurled;
            if (!isJumpcutOn)
                glutIdleFunc(idle);
            else
                curlAngle = jumpcutValue(isCurled, curlAngle, 40, 0);
            break;
        case 'o':
            isBRLegUp = !isBRLegUp;
            if (!isJumpcutOn)
                glutIdleFunc(idle);
            else
                BRLegAngle = jumpcutValue(isBRLegUp, BRLegAngle, 70, 0);
            break;
        case 'n':
            isBLLegUp = !isBLLegUp;
            if (!isJumpcutOn)
                glutIdleFunc(idle);
            else
                BLLegAngle = jumpcutValue(isBLLegUp, BLLegAngle, 70, 0);
            break;
        case 't':
            isReared = !isReared;
            if (!isJumpcutOn)
                glutIdleFunc(idle);
            else
                rearAngle = jumpcutValue(isReared, rearAngle, 90, 0);
            break;
        case ' ':
            isJumpcutOn = !isJumpcutOn;
            break;
            
    }
    
    glutPostRedisplay();
    
}