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')
-rw-r--r--src/client/camera.cc61
-rw-r--r--src/client/main.cc12
-rw-r--r--src/client/video.cc7
-rw-r--r--src/client/view.cc41
4 files changed, 63 insertions, 58 deletions
diff --git a/src/client/camera.cc b/src/client/camera.cc
index 1b4255f..42d686a 100644
--- a/src/client/camera.cc
+++ b/src/client/camera.cc
@@ -1,11 +1,9 @@
-/* camera.cc
+/* client/camera.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
*/
#include "common/functions.h"
-#include "common/osirion.h"
-
#include "game/game.h"
#include "gl/osiriongl.h"
@@ -14,51 +12,40 @@ namespace camera
enum Mode {Free, Track};
Mode mode = Track;
-const float track_pitch = 15.0f; // default tracking pitch
+const float track_pitch = -15.0f; // default tracking pitch
const float offset_inc = 5.0f; // default offset increment
-float yaw = 90; // current yaw, angle in XZ plane
-float yaw_offset = 0; // target offset, relative to target yaw
+float yaw = 0; // current yaw, angle in XZ plane, positive is looking left
+float yaw_target = 0; // target yaw
-float pitch = -90; // current pitch, angle in XY
-float pitch_offset = track_pitch; // target offset, relative to target pitch
+float pitch = -45.0f; // current pitch, angle in XY, positive is looking up
+float pitch_target = track_pitch; // target pitch
-float distance = 2.0f; // distance from the eye to the target
+float distance = 0.4f; // distance from the eye to the target
void draw(float elapsed)
{
- float yaw_target;
if (mode == Track) {
- // track the target
- yaw_target = game::ship.yaw - yaw_offset;
- } else {
- yaw_target = - yaw_offset;
+ yaw_target = game::ship.yaw;
}
// adjust yaw
float d = degreesf(yaw - yaw_target);
yaw = degreesf( yaw - d * elapsed) ;
-
+
// adjust pitch target
- float pitch_target = 0.0f - pitch_offset;
d = degreesf(pitch - pitch_target);
pitch = degreesf( pitch - d *elapsed);
- /*
- gl::translate(distance, 0.0, 0.0);
- gl::rotate(-pitch,0, 0, 1.0 );
- gl::rotate(-yaw, 0, 1.0f, 0);
- */
switch (mode) {
case Free:
- gl::translate(1+distance * GAMESCALE, 0.0f, 0.0f);
+ gl::translate(1.0f+distance, -distance, 0.0f);
gl::rotate(-pitch, 0, 0, 1.0f);
gl::rotate(-yaw, 0, 1.0f, 0);
break;
case Track:
- //gl::translate(1+distance* GAMESCALE, -0.5f* GAMESCALE, 0.0f);
- gl::translate(1+ 2* GAMESCALE, -0.5f* GAMESCALE, 0.0f);
+ gl::translate(1.0f+distance, -distance , 0.0f);
gl::rotate(-pitch, 0, 0, 1.0f);
gl::rotate(-yaw, 0, 1.0f, 0);
break;
@@ -70,44 +57,50 @@ void draw(float elapsed)
void rotate_right()
{
if (mode == Free ) {
- yaw_offset = degreesf( yaw_offset - offset_inc);
+ yaw_target = degreesf( yaw_target + offset_inc);
}
}
void rotate_left()
{
if (mode == Free ) {
- yaw_offset = degreesf( yaw_offset + offset_inc);
+ yaw_target = degreesf( yaw_target - offset_inc);
}
}
void rotate_up()
{
if (mode == Free ) {
- pitch_offset = pitch_offset + offset_inc;
- if (pitch_offset > 90.0f) pitch_offset = 90.0f;
+ pitch_target = pitch_target + offset_inc;
+ if (pitch_target > 90.0f) pitch_target = 90.0f;
}
}
void rotate_down()
{
if (mode == Free ) {
- pitch_offset = pitch_offset - offset_inc;
- if (pitch_offset < -90.0f) pitch_offset = -90.0f;
+ pitch_target = pitch_target - offset_inc;
+ if (pitch_target < -90.0f) pitch_target = -90.0f;
}
}
void nextmode() {
switch(mode) {
case Free:
+ // switch camera to Track mode
mode = Track;
- yaw_offset = 0;
- yaw = game::ship.yaw;
- pitch_offset = track_pitch;
+ yaw_target = game::ship.yaw;
+ yaw = yaw_target;
+ pitch_target = track_pitch;
+ pitch = pitch_target;
break;
case Track:
+ // switch camera to Free mode
mode = Free;
- yaw_offset = 0;
+ yaw_target = game::ship.yaw;
+ yaw = yaw_target;
+ pitch_target = track_pitch;
+ pitch = pitch_target;
break;
default:
break;
diff --git a/src/client/main.cc b/src/client/main.cc
index 66e0fa3..696c02f 100644
--- a/src/client/main.cc
+++ b/src/client/main.cc
@@ -1,4 +1,4 @@
-/* main.cc
+/* client/main.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
*/
@@ -10,21 +10,21 @@
#include <iostream>
// project headers
-#include "common/osirion.h"
+#include "osirion.h"
#include "game/game.h"
#include "input.h"
#include "video.h"
-void quit(int exit_code)
+void quit(int status)
{
SDL_Quit();
- exit(exit_code);
+ exit(status);
}
int main( int argc, char *argv[] )
{
- std::cout << "The Osirion project " << OSIRION_VERSION << std::endl;
+ std::cout << "Project::OSiRiON " << OSIRION_VERSION << std::endl;
// Initialize the video subsystem
video::init();
@@ -39,7 +39,7 @@ int main( int argc, char *argv[] )
game::init();
Uint32 startup = SDL_GetTicks();
- while(game::initialized) {
+ while(game::initialized) {
Uint32 chrono = SDL_GetTicks();
// overflow protection ~49 days
diff --git a/src/client/video.cc b/src/client/video.cc
index eb4297e..2697585 100644
--- a/src/client/video.cc
+++ b/src/client/video.cc
@@ -33,9 +33,13 @@ void reset()
gl::frontface(GL_CCW );
gl::enable( GL_CULL_FACE );
- gl::depthmask(GL_TRUE); // Depth buffer writing
+ // Depth buffer writing
+ gl::depthmask(GL_TRUE);
gl::enable(GL_DEPTH_TEST);
+ // Alpha blending
+ gl::blendfunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+
// Set the clear color
gl::clearcolor( 0, 0, 0, 0 );
@@ -73,6 +77,7 @@ void init()
SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );
SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );
+ SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 2);
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
flags = SDL_OPENGL | SDL_FULLSCREEN;
diff --git a/src/client/view.cc b/src/client/view.cc
index 3641261..d9b5f42 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -10,15 +10,14 @@
#include <SDL/SDL.h>
// project headers
+#include "osirion.h"
#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"
@@ -55,7 +54,7 @@ void reset() {
//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);
+ gl::frustum( -frustumsize * video::ratio, frustumsize * video::ratio, -frustumsize, frustumsize, 1.0f, 1024.0f);
/*
map world coordinates to GL coordinates
@@ -69,17 +68,21 @@ void reset() {
void draw_background()
{
using namespace gl;
+
+// // // enable Alpha blending
+ gl::enable(GL_BLEND);
+ // galactic axis
begin(Lines);
color(0.9f, 0.5f, 0.0f);
- vertex(-2,1,0);
+ vertex(-2,0,0);
color(1.0f, 1.0f, 0.0f);
- vertex(2,1,0);
+ vertex(2,0,0);
- vertex(0,1,-0.5);
- vertex(0,1,0.5);
+ vertex(0,0,-0.5);
+ vertex(0,0,0.5);
- vertex(0,2.0f,0);
+ vertex(0,1.0f,0);
vertex(0,-1, 0);
end();
@@ -93,22 +96,24 @@ void draw_background()
color(0,0, 1.0f);
begin(Lines);
for (int i=-gridsize; i <= gridsize; i++) {
- color(0,0, 0);
+ color(0,0, 0, 0);
vertex(i-dx, y, -gridsize-dz);
- color(0,0, (gridsize-abs(i))*s);
+ color(0,0, (gridsize-abs(i))*s, (gridsize-abs(i))*s);
vertex(i-dx, y, -dz);
vertex(i-dx, y, -dz);
- color(0,0, 0);
+ color(0,0, 0, 0);
vertex(i-dx, y, gridsize-dz);
vertex(-gridsize-dx, y, i-dz);
- color(0,0, (gridsize-abs(i))*s);
+ color(0,0, (gridsize-abs(i))*s, (gridsize-abs(i))*s);
vertex(-dx, y, i-dz);
vertex(-dx, y, i-dz);
- color(0,0, 0);
+ color(0,0, 0, 0);
vertex(gridsize-dx, y, i-dz);
}
end();
+
+ gl::disable(GL_BLEND);
}
void draw_world(float elapsed)
@@ -118,13 +123,15 @@ void draw_world(float elapsed)
//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);
+ gl::scale(0.2f, 0.2f, 0.2f);
shipdrawer->draw(elapsed);
gl::pop();
//std::cerr << "star at " << game::star.location << " translate " << game::star.location - game::ship.location << std::endl;
+ gl::push();
gl::translate(game::star.location - target->location);
stardrawer->draw(elapsed);
+ gl::pop();
}
@@ -140,11 +147,11 @@ void draw(float elapsed)
// Camera transformation
camera::draw(elapsed);
- // draw the semi-static background
- draw_background();
-
// draw the world
draw_world(elapsed);
+
+ // draw the semi-static background
+ draw_background();
SDL_GL_SwapBuffers( );
}