Esempio n. 1
0
void display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	// clear the screen - any drawing before here will not display

	glLoadIdentity();
	// set up the camera here
    camera.setCamera();

	// camera is set up - any drawing before here will display incorrectly
    
    // Draw Skybox
    glPushMatrix();
        glTranslatef(camera.getPosition().x,
                     camera.getPosition().y,
                     camera.getPosition().z);
        glDepthMask(GL_FALSE);
        skybox.draw();
        glDepthMask(GL_TRUE);
    glPopMatrix();

    // Draw Saturn
    glPushMatrix();
        glTranslatef(saturnInfo.x, 0.f, saturnInfo.z);
        glScalef(saturnInfo.radius, saturnInfo.radius, saturnInfo.radius);
        saturn.draw();
    glPopMatrix();
    
    // Draw Moons
    for (int i = 0; i < 10; i++)
    {
        glPushMatrix();
            glTranslatef(moonInfo[i].x, 0.f, moonInfo[i].z);
            glScalef(moonInfo[i].radius, moonInfo[i].radius, moonInfo[i].radius);
            moons[i].draw();
        glPopMatrix();
    }
    
    // Draw rings
    glPushMatrix();
        glTranslatef(ringInfo.x, 0.f, ringInfo.z);
        glScalef(ringInfo.radius, ringInfo.radius, ringInfo.radius);
        ring.draw();
    glPopMatrix();
    
	// send the current image to the screen - any drawing after here will not display
	glutSwapBuffers();
}
Esempio n. 2
0
void Ship :: setupCamera () const
{
	CoordinateSystem camera = getCameraCoordinateSystem();
	const Vector3& camera_position = camera.getPosition();
	const Vector3& camera_up       = camera.getUp();

	Vector3 look_at = camera_position + camera.getForward();

	gluLookAt(camera_position.x, camera_position.y, camera_position.z,
	          look_at.x,         look_at.y,         look_at.z,
	          camera_up.x,       camera_up.y,       camera_up.z);
}
Esempio n. 3
0
void World::playerFireBullet()
{
	if (m_playerShip.isAlive() && m_playerShip.isBulletReady())
	{
		CoordinateSystem cs = m_playerShip.getCoordinate();
		m_bullets[m_nextBulletIndex].fire(cs.getPosition(), cs.getForward(), m_playerShip.getId());
		m_playerShip.reloadBullet();
		m_nextBulletIndex++;
		if (m_nextBulletIndex == Const::BULLET_COUNT){
			m_nextBulletIndex = 0;
		}
	}
}
Esempio n. 4
0
void keyboard(unsigned char key, int x, int y)
{
    Vector3 origin = Vector3::ZERO;
    Vector3 direction_to_origin;
	switch (key)
	{
        case 27: // on [ESC]
            exit(0); // normal exit
            break;
        case ' ':
            camera.moveForward(0.5);
            break;
        case 'w':
            camera.moveUp(0.5);
            break;
        case 'a':
            camera.moveLeft(0.5);
            break;
        case 's':
            camera.moveDown(0.5);
            break;
        case 'd':
            camera.moveRight(0.5);
            break;
        case 'h':
            direction_to_origin = origin - camera.getPosition();
            camera.rotateToVector(direction_to_origin, 0.1);
            break;
        case ',':
            camera.setRoll(0.1);
            break;
        case '.':
            camera.setRoll(-0.1);
            break;
        case '/':
            camera.moveBackward(0.5);
            break;
	}
}
Esempio n. 5
0
void RingSystem :: draw (const CoordinateSystem& camera_coordinates) const
{
	const Vector3& camera_position = camera_coordinates.getPosition();
	RingSectorIndex camera_index(camera_position);

	if(DEBUGGING_CHOOSING_SECTORS)
		cout << "Drawing around ring sector " << camera_index << endl;

	for(int dx = -RING_SECTOR_DRAW_FROM_CAMERA_COUNT; dx <= RING_SECTOR_DRAW_FROM_CAMERA_COUNT; dx++)
	{
		short x = camera_index.getX() + dx;
		for(int dy = -RING_SECTOR_DRAW_FROM_CAMERA_COUNT; dy <= RING_SECTOR_DRAW_FROM_CAMERA_COUNT; dy++)
		{
			short y = camera_index.getY() + dy;
			for(int dz = -RING_SECTOR_DRAW_FROM_CAMERA_COUNT; dz <= RING_SECTOR_DRAW_FROM_CAMERA_COUNT; dz++)
			{
				short z = camera_index.getZ() + dz;
				RingSectorIndex ring_sector_index(x, y, z);

				const RingSector& ring_sector = getRingSector(ring_sector_index);
				unsigned int particle_count = (unsigned int)ring_sector.mv_ring_particles.size();

				if(DEBUGGING_CHOOSING_SECTORS && dx == 0 && dy == 0 && dz == 0)
				{
					cout << "\tRing Sector " << ring_sector.m_index << "\t==> "     << ring_sector.m_index.getCenter() << endl;
					cout << "\t\t "          << particle_count      << " particles" << endl;
				}

				for(unsigned int i = 0; i < particle_count; i++)
				{
					ring_sector.mv_ring_particles[i].draw(camera_position);
					if(DEBUGGING_CHOOSING_SECTORS && dx == 0 && dy == 0 && dz == 0)
						cout << "\t\t#" << i << ":\t" << ring_sector.mv_ring_particles[i].getPosition() << endl;
					}
			}
		}
	}
}
Esempio n. 6
0
void World::update()
{
	handleKeyPress();

	m_playerShip.update(*this);
	int i = 0;
	// bullet
	for (; i < Const::BULLET_COUNT; i++)
	{ 
		m_bullets[i].update(*this);
	}
	int abc = 0;
	// enemy ships
	Vector3 playerPosition = m_playerShip.getPosition();
	for (i = 0; i < Const::ENEMY_SHIP_AMOUNT;i++){

		if (m_ships[i].isAlive()){
			double distance = m_ships[i].getPosition().getDistanceSquared(playerPosition);
			if (distance < Const::NEAR_TO_PLAYER){
				m_ships[i].runAi(*this);
				m_ships[i].update(*this);
				abc++;
			}
		}
	}

	CoordinateSystem cs = m_playerShip.getCoordinate();
	Vector3 position = cs.getPosition();
	Vector3 up = cs.getUp();
	m_camera.setUp(cs.getUp());
	Vector3 forward = cs.getForward();
	m_camera.setForward(forward);
	position += 20 * up;
	position -= 100 * forward;
	m_camera.setPosition(position);
	checkCollision();
}
Esempio n. 7
0
void update()
{
    if (key_pressed[' '])
    {
        camera.moveForward(MOVE_SPEED);
    }
    if (key_pressed['w'] || key_pressed['W'])
    {
        camera.moveUp(MOVE_SPEED);
    }
    if (key_pressed['a'] || key_pressed['A'])
    {
        camera.moveLeft(MOVE_SPEED);
    }
    if (key_pressed['s'] || key_pressed['S'])
    {
        camera.moveDown(MOVE_SPEED);
    }
    if (key_pressed['d'] || key_pressed['D'])
    {
        camera.moveRight(MOVE_SPEED);
    }
    if (key_pressed['h'])
    {
        Vector3 origin = Vector3::ZERO;
        Vector3 direction_to_origin;
        direction_to_origin = origin - camera.getPosition();
        camera.rotateToVector(direction_to_origin, THETA);
    }
    if (key_pressed[','] || key_pressed['<'])
    {
        camera.setRoll(THETA);
    }
    if (key_pressed['.'] || key_pressed['>'])
    {
        camera.setRoll(-THETA);
    }
    if (key_pressed['/'] || key_pressed['?'])
    {
        camera.moveBackward(MOVE_SPEED);
    }
    if (special_key_pressed[GLUT_KEY_RIGHT])
    {
        camera.setYaw(-THETA);
    }
    if (special_key_pressed[GLUT_KEY_LEFT])
    {
        camera.setYaw(THETA);
    }
    if (special_key_pressed[GLUT_KEY_UP])
    {
        camera.setPitch(THETA);
    }
    if (special_key_pressed[GLUT_KEY_DOWN])
    {
        camera.setPitch(-THETA);
    }
    
	sleep(1.0 / 60.0);
	glutPostRedisplay();
}