Example #1
0
// This callback function gets called by the Glut
// system whenever it decides things need to be redrawn.
void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glEnable(GL_DEPTH_TEST);

    glLoadIdentity();
    double dt = GetDeltaTime();
    if (gFirstPerson)
    {
        double rad = gRat.getDegrees()/180.0 * M_PI;
        double dx = cos(rad) * MOVE_SPEED * dt;
        double dy = sin(rad) * MOVE_SPEED * dt;

        double hover = 2.0;
        double terrainHeight = gMaze.getZ(gRat.getX() + dx, gRat.getY() + dy);
        double waterHeight = gWaterHeight + .4;
        double H = fmax(terrainHeight, waterHeight) + hover;
        double currentTerrainHeight = fmax(waterHeight, gMaze.getZ(gRat.getX(), gRat.getY()));
        double tilt = (fmax(terrainHeight, waterHeight) - currentTerrainHeight);
        double lookZ = H + tilt;
        gluLookAt(gRat.getX(), gRat.getY(), H, gRat.getX() + dx, gRat.getY() + dy, lookZ, 0, 0, 1);
        // when doing rat, calculate at point but z will stay.
    }
    else
    {
        gluLookAt(M*.5, -N*.5, 15, M*.5, N*.5, 0, 0, 0, 1); // 3 eye, 3 at point, 3 z-axis up
    }

	gMaze.draw(gWaterHeight);
    gRat.draw(gFirstPerson);
    if (gLeft) gRat.spinLeft(dt);
    if (gRight) gRat.spinRight(dt);
    if (gMiddle) gRat.move(dt);

    if (gFirstPerson)
    {
        gluPerspective(.02, (double)screen_x/screen_y, .0001, .0001);
    }
    else
    {
        gluPerspective(40, (double)screen_x/screen_y, RES*.5, 3*(RES+RES));
    }

	glutSwapBuffers();
	glutPostRedisplay();
}
Example #2
0
void onDisplay(void) {
    // cams.projection(winW, winH);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    cams.look();
    lights.display(&pacman);

    //draw stuff
    maze.draw();
    if (!maze.getPacmanDeathTime()) { //pacman is alive
        pacman.draw();
    }
    else particles.draw();
    mazeFloor.draw();
    ghosts.draw();
    hud.draw(winW, winH, &maze);
    glFlush();
}
Example #3
0
// This callback function gets called by the Glut
// system whenever it decides things need to be redrawn.
void display(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glEnable(GL_DEPTH_TEST);

  glLoadIdentity();
  double dt = GetDeltaTime();
  if (gFirstPerson)
  {
    double rad = gRat.getDegrees()/180.0 * M_PI;
    double dx = cos(rad) * MOVE_SPEED * dt;
    double dy = sin(rad) * MOVE_SPEED * dt;
    gluLookAt(gRat.getX(), gRat.getY(), gRatHeight, gRat.getX() + dx, gRat.getY() + dy, gRatHeight, 0, 0, 1);
    // when doing rat, calculate at point but z will stay.
  }
  else
  {
    gluLookAt(M*.5, -N*.5, 15, M*.5, N*.5, 0, 0, 0, 1); // 3 eye, 3 at point, 3 z-axis up
  }

	gMaze.draw();
  gRat.draw(gFirstPerson);

  if (gLeft) gRat.spinLeft(dt);
  if (gRight) gRat.spinRight(dt);
  if (gMiddle) gRat.move(dt);

  if (gFirstPerson)
  {
    gluPerspective(.02, (double)screen_x/screen_y, .0001, .0001);
  }
  else
  {
    gluPerspective(40, (double)screen_x/screen_y, N*.5, 3*(M+N));
  }

	glutSwapBuffers();
	glutPostRedisplay();

}
Example #4
0
    MouseMovement nextMovement(unsigned x, unsigned y, const Maze &maze) {
        const bool frontWall = maze.wallInFront();
        const bool leftWall  = maze.wallOnLeft();

        // Pause at each cell if the user requests it.
        // It allows for better viewing on command line.
        if(pause) {
            std::cout << "Hit enter to continue..., (" << x << "," << y << "), M=" << getManDistance(x,y) << std::endl;
            std::cin.ignore(10000, '\n');
            std::cin.clear();
        }

        std::cout << maze.draw(5) << std::endl << std::endl;

        // If we somehow miraculously hit the center
        // of the maze, just terminate and celebrate!
        if(isAtCenter(x, y)) {
            std::cout << "Found center! Good enough for the demo, won't try to get back." << std::endl;
            return Finish;
        }

        // If we hit the start of the maze a second time, then
        // we couldn't find the center and never will...
        if(x == 0 && y == 0) {
            if(visitedStart) {
                std::cout << "Unable to find center, giving up." << std::endl;
                return Finish;
            } else {
                visitedStart = true;
            }
        }

        // If we have just turned left, we should take that path!
        if(!frontWall && shouldGoForward) {
            shouldGoForward = false;
            return MoveForward;
        }

        // As long as nothing is in front and we have
        // a wall to our left, keep going forward!
        if(!frontWall && leftWall) {
            shouldGoForward = false;
            return MoveForward;
        }

        // If our forward and left paths are blocked
        // we should try going to the right!
        if(frontWall && leftWall) {
            shouldGoForward = false;
            return TurnClockwise;
        }

        // Lastly, if there is no left wall we should take that path!
        if(!leftWall) {
            shouldGoForward = true;
            return TurnCounterClockwise;
        }

        // If we get stuck somehow, just terminate.
        std::cout << "Got stuck..." << std::endl;
        return Finish;
    }
Example #5
0
void ColoredCubeApp::drawScene()
{
	D3DApp::drawScene();

	// Restore default states, input layout and primitive topology 
	// because mFont->DrawText changes them.  Note that we can 
	// restore the default states by passing null.
	md3dDevice->OMSetDepthStencilState(0, 0);
	float blendFactors[] = {0.0f, 0.0f, 0.0f, 0.0f};
	md3dDevice->OMSetBlendState(0, blendFactors, 0xffffffff);
    md3dDevice->IASetInputLayout(mVertexLayout);

	mfxEyePosVar->SetRawValue(&player.getPosition(), 0, sizeof(D3DXVECTOR3));

	//set the number of lights to use
	mfxNumLights->SetInt(numLights);

	// set the light array
	lights[0] = flashLightObject.lightSource;
	//lights[2] = lightObject1.getLight();
	if(gamestate == level2)
	{
		for(int i = 0; i < ghosts.getNumEnemies(); i++)
		{
			lights[2+i] = ghosts.getEnemies()[i].getLight();
		}
	}
	for(int i = 0; i < numLightObjects; i++)
	{
		lights[2+ghosts.getNumEnemies()+i] = lamps[i].getLight();
	}
	lights[numLights-1] = endLight;

	mfxLightVar->SetRawValue(&lights[0], 0, numLights*sizeof(Light));
 
	// Don't transform texture coordinates, so just use identity transformation.
	D3DXMATRIX texMtx;
	D3DXMatrixIdentity(&texMtx);
	mfxTexMtxVar->SetMatrix((float*)&texMtx);

	// set the point to the shader technique
	D3D10_TECHNIQUE_DESC techDesc;
	mTech->GetDesc(&techDesc);

	//draw the maze
	maze.draw(mTech,mView,mProj);
	
	//draw the keys
	if(gamestate == level1)
	{
		for(int i = 0; i < totalKeys; i++)
		{
			keyObject[i].draw(mView,mProj,mTech);
		}
	}

	//draw the end cube
	endCube.draw(mView,mProj,mTech);

	//draw the origin
	origin.draw(mView, mProj, mTech);
	
	for(int i = 0; i < numLightObjects; i++)
	{
		lamps[i].draw(mView,mProj,mTech);
	}

	for(int i = 0; i < numBatteries; i++)
	{
		batteries[i].draw(mView,mProj,mTechColor2);
	}

	//flashLightObject.draw(mView,mProj,mTechColor2);
	//flashLightObject.hitBox.draw(mView,mProj,mTechColor2);
	
	//batteryObject.draw(mView,mProj,mTechColor2);
	//player.draw(mView,mProj,mTechColor2);
	ghosts.draw(mView,mProj,mTech);

	/*floor.draw(mView, mProj, mTech);
	wall1.draw(mView, mProj, mTech);
	wall2.draw(mView, mProj, mTech);
	wall3.draw(mView, mProj, mTech);
	wall4.draw(mView, mProj, mTech);*/
	//lightObject1.draw(mView,mProj,mTech);

	// We specify DT_NOCLIP, so we do not care about width/height of the rect.
	RECT R = {5, 5, 0, 0};
	mFont->DrawText(0, mTimer.c_str(), -1, &R, DT_NOCLIP, BLUE);
	mSwapChain->Present(0, 0);
}