aboutsummaryrefslogtreecommitdiff
path: root/sons_of_sol/private_db/ApplicationDisplay.cpp
blob: e4a2a78eb3a63842e5a8f177231c83204f6c3a9e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
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();
}