diff options
| author | Joshua Rahm <joshua.rahm@colorado.edu> | 2013-12-10 19:19:26 -0700 |
|---|---|---|
| committer | Joshua Rahm <joshua.rahm@colorado.edu> | 2013-12-10 19:19:26 -0700 |
| commit | 010f829485d570afb66c630026504fec63f93cdd (patch) | |
| tree | d5e42e333178794377c05a99b5bf0c034485bcb6 /sons_of_sol/private_db/ApplicationDisplay.cpp | |
| parent | 7be3bda2b664068bf47404278fa9ee1ce552ea0e (diff) | |
| download | SonsOfSol-010f829485d570afb66c630026504fec63f93cdd.tar.gz SonsOfSol-010f829485d570afb66c630026504fec63f93cdd.tar.bz2 SonsOfSol-010f829485d570afb66c630026504fec63f93cdd.zip | |
Almost finished working commit
Diffstat (limited to 'sons_of_sol/private_db/ApplicationDisplay.cpp')
| -rw-r--r-- | sons_of_sol/private_db/ApplicationDisplay.cpp | 217 |
1 files changed, 217 insertions, 0 deletions
diff --git a/sons_of_sol/private_db/ApplicationDisplay.cpp b/sons_of_sol/private_db/ApplicationDisplay.cpp new file mode 100644 index 0000000..e4a2a78 --- /dev/null +++ b/sons_of_sol/private_db/ApplicationDisplay.cpp @@ -0,0 +1,217 @@ +#include "sons_of_sol/SonsOfSolApplication.hpp" + +#include "glox/GloxLightSource.hpp" +#include "glox/GloxRotation.hpp" +#include "glox/GloxScopedRotation.hpp" + +#include <iostream> + +using namespace glox; +using namespace slox; +using namespace std; + +float randJitter() { + return ((rand() & 0xFF) - 128.0) / (256.0 * 10) ; +} +void Cockpit() +{ + // Screen edge +// float w = 1.8; + // Save transform attributes (Matrix Mode and Enabled Modes) + glPushAttrib(GL_TRANSFORM_BIT|GL_ENABLE_BIT); + // Save projection matrix and set unit transform + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(-1.8,+1.8,-1,1,-1,1); + // Save model view matrix and set to indentity + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + // Draw instrument panel with texture + // glColor3f(1,1,1); + // glEnable(GL_TEXTURE_2D); + // glBegin(GL_QUADS); + // glTexCoord2d(0,0);glVertex2f(-2,-1); + // glTexCoord2d(1,0);glVertex2f(+2,-1); + // glTexCoord2d(1,1);glVertex2f(+2, 0); + // glTexCoord2d(0,1);glVertex2f(-2, 0); + // glEnd(); + // glDisable(GL_TEXTURE_2D); + // Draw the inside of the cockpit in grey +// glColor3f(0.6,0.6,0.6); +// glBegin(GL_QUADS); +// // Port +// glVertex2f(-2,-1); +// glVertex2f(-2,+1); +// glVertex2f(-w,+1); +// glVertex2f(-w,-1); +// // Starboard +// glVertex2f(+2,-1); +// glVertex2f(+2,+1); +// glVertex2f(+w,+1); +// glVertex2f(+w,-1); +// // Port overhead +// glVertex2f(-2.00,+0.8); +// glVertex2f(-2.00,+1); +// glVertex2f(-0.03,+1); +// glVertex2f(-0.03,+0.9); +// // Starboard overhead +// glVertex2f(+2.00,+0.8); +// glVertex2f(+2.00,+1); +// glVertex2f(+0.03,+1); +// glVertex2f(+0.03,+0.9); +// // Windshield divide +// glVertex2f(-0.03,+1); +// glVertex2f(+0.03,+1); +// glVertex2f(+0.03,+0); +// glVertex2f(-0.03,+0); +// glEnd(); + // Reset model view matrix + glPopMatrix(); + // Reset projection matrix + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + // Pop transform attributes (Matrix Mode and Enabled Modes) + glPopAttrib(); +} + +void SonsOfSolApplication::display() { + if ( m_script_ttl >= 0 ) { + GloxLightSource* golight = m_light_manager.getLightSource( 0 ); + golight->setPosition( m_ship.getPosition() ); + + if( m_script_ttl > 90 ) { + m_ship.setPosition( m_ship.getPosition() - GloxPointf( randJitter(),0.25,randJitter() ) ); + } else if( m_script_ttl > 80 ) { + float coef = 11 - (m_script_ttl - 80); + m_ship.setPosition( GloxPointf( randJitter()/coef,randJitter()/coef,randJitter()/coef-3 ) ); + } else if( m_script_ttl == 80 ) { + m_ship.setPosition( GloxPointf( 0,0,-3 ) ); + } + + golight->setEnabled( true ); + if ( m_script_ttl == 70 ) { + m_ship.setDForwardTo( 30 ); + golight->setLightModelAttribute( GL_LIGHT_MODEL_AMBIENT, GloxColor(50,50,50) ); + golight->setAmbient ( GloxColor(50,50,50) ); + golight->setDiffuse ( GloxColor(0,255,0) ); + } + if ( m_script_ttl == 0 ) { + this->addKeyListener( & m_event_multiplexer ); + this->addMouseMotionListener( & m_event_multiplexer ); + m_ship.setDForwardTo( 20 ) ; + enableLighting(); + } + cout << m_script_ttl << endl ; + m_script_ttl -= 1 ; + } + + /* Translate to the this perspective */ + m_ship.drawHUD(); + + m_ship.getPerspective().setZNear( FAR_DISTANCE_START ); + m_ship.getPerspective().setZFar( FAR_DISTANCE_END ); + m_ship.getPerspective().render(); + + /* We don't want lighting for the skybox */ + GloxDisableFor( GL_LIGHTING, + /* Draw some stuff relative to the + * ship so the ship cannot break out + * of the skybox */ + GloxWithTranslation( m_ship.getPosition(), + /* Draw the background sky */ + m_sky->draw(); + /* Draw the star texture */ + GloxEnableFor( GL_TEXTURE_2D, + m_star_tex.bind(); + GloxWith( GL_QUADS, m_star.plot() ); + ); + ) + + + + /* Draw the earth with its + * shaders */ + m_earth_prog->render() ; + m_earth_prog->setUniformVector3( m_earth_shader_light_pos, + m_light_manager.getLightSource(0)->getPosition() ) ; + + //GloxPoint<> pos( GloxCos( ticks ) * FAR_DISTANCE_END/4.0, 0, GloxSin( ticks ) * FAR_DISTANCE_END/4.0 ); + GloxPoint<> pos( -250000, 0, 0 ); + m_earth_prog->setUniformVector3( m_earth_shader_camera_pos, + pos ); + // cout << "Pos : " << pos.toString() << " " << (pos.getZ() / pos.getX()) << endl; + // cout << "Ship Position: " << m_ship.getPosition().toString() << (m_ship.getPosition().getZ() / m_ship.getPosition().getX()) << endl ; + GloxWithTranslation( m_ship.getPosition() + GloxPoint<>( 700,-FAR_DISTANCE_END / 2,0 ), + GloxRotation( -90, 0, 0, 1 ).render(); + GloxEnableFor( GL_BLEND, + m_earth->draw(); + ) + ) + + /* Draw the moon with its shaders */ + m_moon_prog->render() ; + m_moon_prog->setUniformVector3( m_moon_shader_light_pos, + m_light_manager.getLightSource( 0 )->getPosition() ) ; + + m_moon_prog->setUniformVector3( m_moon_shader_camera_pos, + m_ship.getPosition() ) ; + + GloxWithTranslation( m_ship.getPosition() + GloxPoint<>( 700,FAR_DISTANCE_END / 3.0f, 0 ), + GloxRotation( -90, 0, 0, 1 ).render(); + m_moon->draw() + ) + + GloxProgram::unloadPrograms() ; + ); + + + + m_light_manager.getLightSource( 1 )->setEnabled( true ); + m_light_manager.render(); + + GloxScale( 6, + m_acceleration_cannon->draw() ) ; + + for( vector<AIShip>::iterator itr = m_aiships.begin() ; itr != m_aiships.end() ; ++ itr ) { + // cout << itr->getPosition().toString() << endl ; + itr->draw( (itr->getPosition() - m_ship.getPosition()).getMagnitude() ); + } + + glPushMatrix(); + + // m_crate->draw(); + GloxWithTranslation( GloxPoint<>( 0,10,0 ), + m_probe->draw() ); + GloxWithTranslation( GloxPoint<>( 0,-10,0 ), + m_test_cube->draw() ); + + GloxWithTranslation( GloxPoint<>( 10000,10000,10000 ), + GloxScale( 1000, + glPushMatrix(); + glRotatef( 90, 1.2, 1.3, 1.4 ); + m_frigate_industrial->draw(); + glPopMatrix(); + ); + ); + + GloxWithTranslation( GloxPoint<>( 5000,-1000,-20000 ), + GloxScale( 100, + glPushMatrix(); + glRotatef( 90, 0.3, 1, 0 ); + m_deathstar->draw(); + glPopMatrix(); + ); + ); + + GloxDisableFor( GL_LIGHTING, + GloxEnableFor(GL_BLEND, + glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + m_ship.drawProjectiles(); + ) + ) + + + glPopMatrix(); +} |