Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/view.cc')
-rw-r--r--src/client/view.cc153
1 files changed, 153 insertions, 0 deletions
diff --git a/src/client/view.cc b/src/client/view.cc
new file mode 100644
index 0000000..3641261
--- /dev/null
+++ b/src/client/view.cc
@@ -0,0 +1,153 @@
+/* view.cc
+ This file is part of the Osirion project and is distributed under
+ the terms and conditions of the GNU General Public License version 2
+*/
+
+// C++ headers
+#include <iostream>
+
+// SDL headers
+#include <SDL/SDL.h>
+
+// project headers
+#include "common/functions.h"
+#include "common/osirion.h"
+
+#include "game/game.h"
+#include "gl/osiriongl.h"
+
+#include "video.h"
+#include "camera.h"
+
+#include "shipdrawer.h"
+#include "stardrawer.h"
+
+namespace view
+{
+
+ShipDrawer *shipdrawer = 0;
+StarDrawer *stardrawer = 0;
+
+Ship *target =0; // the view's target
+
+void init() {
+ // draw scene
+ if (!shipdrawer) {
+ stardrawer = new StarDrawer(&game::star);
+ shipdrawer = new ShipDrawer(&game::ship);
+ target = &game::ship;
+ }
+
+}
+
+void shutdown()
+{
+ delete stardrawer;
+ stardrawer = 0;
+ delete shipdrawer;
+ shipdrawer = 0;
+}
+
+void reset() {
+ // Change to the projection matrix and set our viewing volume.
+ gl::matrixmode( GL_PROJECTION );
+ gl::loadidentity();
+
+ //glu::perspective( 64.0, video::ratio, 1.0, 1024.0 );
+ const float frustumsize=0.5f;
+ gl::frustum( -frustumsize * video::ratio, frustumsize * video::ratio, -frustumsize, frustumsize, 1.0, 1024.0);
+ /*
+ map world coordinates to GL coordinates
+
+ The world coordinates are identical to GL coordinates,
+ but the default viewing pitch (0 degrees)
+ is the positive X-axis
+ */
+ gl::rotate(90.0f, 0, 1.0, 0);
+}
+
+void draw_background()
+{
+ using namespace gl;
+
+ begin(Lines);
+ color(0.9f, 0.5f, 0.0f);
+ vertex(-2,1,0);
+ color(1.0f, 1.0f, 0.0f);
+ vertex(2,1,0);
+
+ vertex(0,1,-0.5);
+ vertex(0,1,0.5);
+
+ vertex(0,2.0f,0);
+ vertex(0,-1, 0);
+ end();
+
+ int gridsize = 32;
+ float s = 1.0f / gridsize;
+ float y = -4.0f;
+
+ float dx = target->location.x - floorf(target->location.x);
+ float dz = target->location.z - floorf(target->location.z);
+
+ color(0,0, 1.0f);
+ begin(Lines);
+ for (int i=-gridsize; i <= gridsize; i++) {
+ color(0,0, 0);
+ vertex(i-dx, y, -gridsize-dz);
+ color(0,0, (gridsize-abs(i))*s);
+ vertex(i-dx, y, -dz);
+ vertex(i-dx, y, -dz);
+ color(0,0, 0);
+ vertex(i-dx, y, gridsize-dz);
+
+ vertex(-gridsize-dx, y, i-dz);
+ color(0,0, (gridsize-abs(i))*s);
+ vertex(-dx, y, i-dz);
+ vertex(-dx, y, i-dz);
+ color(0,0, 0);
+ vertex(gridsize-dx, y, i-dz);
+ }
+ end();
+}
+
+void draw_world(float elapsed)
+{
+ // draw the world
+ gl::push();
+
+ //std::cerr << "ship at " << game::ship.location << " translate " << game::ship.location - target->location << std::endl;
+ gl::translate(game::ship.location - target->location);
+ gl::scale(GAMESCALE, GAMESCALE, GAMESCALE);
+ shipdrawer->draw(elapsed);
+ gl::pop();
+
+ //std::cerr << "star at " << game::star.location << " translate " << game::star.location - game::ship.location << std::endl;
+ gl::translate(game::star.location - target->location);
+ stardrawer->draw(elapsed);
+
+}
+
+void draw(float elapsed)
+{
+ // Clear the color and depth buffers.
+ gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+
+ // We don't want to modify the projection matrix.
+ gl::matrixmode( GL_MODELVIEW );
+ gl::loadidentity();
+
+ // Camera transformation
+ camera::draw(elapsed);
+
+ // draw the semi-static background
+ draw_background();
+
+ // draw the world
+ draw_world(elapsed);
+
+ SDL_GL_SwapBuffers( );
+}
+
+} // namespace view
+