aboutsummaryrefslogtreecommitdiff
path: root/sons_of_sol
diff options
context:
space:
mode:
Diffstat (limited to 'sons_of_sol')
-rw-r--r--sons_of_sol/AIShip.hpp67
-rw-r--r--sons_of_sol/ControlMotionEvent.hpp65
-rw-r--r--sons_of_sol/ControlMotionListener.hpp10
-rw-r--r--sons_of_sol/ControlMultiplexer.hpp108
-rw-r--r--sons_of_sol/PlayerShip.hpp177
-rw-r--r--sons_of_sol/Projectile.hpp41
-rw-r--r--sons_of_sol/SonsOfSolApplication.hpp272
-rw-r--r--sons_of_sol/Updaters.hpp52
-rw-r--r--sons_of_sol/private_db/AIShip.cpp196
-rw-r--r--sons_of_sol/private_db/ApplicationDisplay.cpp246
-rw-r--r--sons_of_sol/private_db/ApplicationInit.cpp449
-rw-r--r--sons_of_sol/private_db/ControlMultiplexer.cpp93
-rw-r--r--sons_of_sol/private_db/PlayerShip.cpp235
-rw-r--r--sons_of_sol/private_db/Projectile.cpp98
-rw-r--r--sons_of_sol/private_db/SonsOfSolApplication.cpp210
15 files changed, 1138 insertions, 1181 deletions
diff --git a/sons_of_sol/AIShip.hpp b/sons_of_sol/AIShip.hpp
index b508a4b..d54c2bf 100644
--- a/sons_of_sol/AIShip.hpp
+++ b/sons_of_sol/AIShip.hpp
@@ -7,59 +7,58 @@
* AIShip.hpp: <description>
*/
-#include "slox/loader/SloxModelObject.hpp"
#include "glox/GloxCommon.hpp"
#include "glox/GloxState.hpp"
#include "glox/objects/GloxCube.hpp"
+#include "slox/loader/SloxModelObject.hpp"
-#include "slox/SloxCommon.hpp"
#include "glox/GloxPoint.hpp"
+#include "slox/SloxCommon.hpp"
class AIShip {
-public:
- class Updater {
- public:
- virtual glox::GloxPoint<> update( uint32_t ) = 0;
- };
- inline AIShip( Updater* update = NULL ) :
- update_func( update ), m_roll( 0 ), m_roll_to( 0 ) {}
-
- void update() ;
-
- void draw( float dist ) ;
+ public:
+ class Updater {
+ public:
+ virtual glox::GloxPoint<> update(uint32_t) = 0;
+ };
+ inline AIShip(Updater* update = NULL)
+ : update_func(update), m_roll(0), m_roll_to(0) {}
- void setTimeOffset( uint32_t off ) ;
+ void update();
- inline void setUpdateFunction( Updater* updater ) ;
+ void draw(float dist);
- static void setModel( slox::SloxModelObject* high, slox::SloxModelObject* med, slox::SloxModelObject* low ) ;
+ void setTimeOffset(uint32_t off);
- inline const glox::GloxPoint<>& getPosition() { return m_position ; }
+ inline void setUpdateFunction(Updater* updater);
-private:
- Updater* update_func;
+ static void setModel(slox::SloxModelObject* high, slox::SloxModelObject* med,
+ slox::SloxModelObject* low);
- void calculate_roll_to();
+ inline const glox::GloxPoint<>& getPosition() { return m_position; }
- float m_ptich ;
- float m_yaw ;
- float m_roll ;
+ private:
+ Updater* update_func;
- float m_roll_to ;
- float m_weight ;
- uint32_t m_time_offset ;
+ void calculate_roll_to();
- glox::GloxPoint<> m_position ;
- glox::GloxPoint<> m_last_position ;
- glox::GloxPoint<> m_future_position ;
+ float m_ptich;
+ float m_yaw;
+ float m_roll;
- static slox::SloxModelObject* s_high_model ;
- static slox::SloxModelObject* s_med_model ;
- static slox::SloxModelObject* s_low_model ;
+ float m_roll_to;
+ float m_weight;
+ uint32_t m_time_offset;
- static glox::GloxCube* s_really_far_away_model;
-} ;
+ glox::GloxPoint<> m_position;
+ glox::GloxPoint<> m_last_position;
+ glox::GloxPoint<> m_future_position;
+ static slox::SloxModelObject* s_high_model;
+ static slox::SloxModelObject* s_med_model;
+ static slox::SloxModelObject* s_low_model;
+ static glox::GloxCube* s_really_far_away_model;
+};
#endif /* AISHIP_HPP_ */
diff --git a/sons_of_sol/ControlMotionEvent.hpp b/sons_of_sol/ControlMotionEvent.hpp
index 5a93a69..930539b 100644
--- a/sons_of_sol/ControlMotionEvent.hpp
+++ b/sons_of_sol/ControlMotionEvent.hpp
@@ -12,54 +12,39 @@
*
* These values have been normalized */
class ControlMotionEvent {
-public:
- enum MotionEventType {
- NONE
- , PITCH
- , ROLL
- , YAW
- , THROTTLE
- , STRAFE_SIDE
- , STRAFE_UP
- , FIRE_PRIMARY
- };
+ public:
+ enum MotionEventType {
+ NONE,
+ PITCH,
+ ROLL,
+ YAW,
+ THROTTLE,
+ STRAFE_SIDE,
+ STRAFE_UP,
+ FIRE_PRIMARY
+ };
- enum MotionOrigin {
- JOYSTICK,
- MOUSE,
- BUTTON
- };
+ enum MotionOrigin { JOYSTICK, MOUSE, BUTTON };
- ControlMotionEvent( MotionEventType type, double mag, MotionOrigin origin ) :
- mag( mag ), type( type ), origin( origin ) {}
+ ControlMotionEvent(MotionEventType type, double mag, MotionOrigin origin)
+ : mag(mag), type(type), origin(origin) {}
- inline double getMagnitude() const {
- return mag;
- }
+ inline double getMagnitude() const { return mag; }
- inline MotionEventType getType() const {
- return type;
- }
+ inline MotionEventType getType() const { return type; }
- inline MotionOrigin getOrigin() const {
- return origin;
- }
+ inline MotionOrigin getOrigin() const { return origin; }
- inline void setMagnitude( double mag ) {
- this->mag = mag;
- }
+ inline void setMagnitude(double mag) { this->mag = mag; }
- inline void setType( MotionEventType type ) {
- this->type = type;
- }
+ inline void setType(MotionEventType type) { this->type = type; }
- inline void setOrigin( MotionOrigin origin ) {
- this->origin = origin;
- }
-private:
- double mag;
- MotionEventType type;
- MotionOrigin origin;
+ inline void setOrigin(MotionOrigin origin) { this->origin = origin; }
+
+ private:
+ double mag;
+ MotionEventType type;
+ MotionOrigin origin;
};
#endif /* CONTROLMOTIONEVENT_HPP_ */
diff --git a/sons_of_sol/ControlMotionListener.hpp b/sons_of_sol/ControlMotionListener.hpp
index 8269ebe..9cf7e09 100644
--- a/sons_of_sol/ControlMotionListener.hpp
+++ b/sons_of_sol/ControlMotionListener.hpp
@@ -10,11 +10,11 @@
#include "sons_of_sol/ControlMotionEvent.hpp"
class ControlMotionListener {
-public:
- /* Called once there is a control motion */
- virtual inline void onControlMotion( const ControlMotionEvent& event ) {
- (void) event;
- }
+ public:
+ /* Called once there is a control motion */
+ virtual inline void onControlMotion(const ControlMotionEvent& event) {
+ (void)event;
+ }
};
#endif /* CONTROLMOTIONLISTENER_HPP_ */
diff --git a/sons_of_sol/ControlMultiplexer.hpp b/sons_of_sol/ControlMultiplexer.hpp
index 33ae28d..025fdd0 100644
--- a/sons_of_sol/ControlMultiplexer.hpp
+++ b/sons_of_sol/ControlMultiplexer.hpp
@@ -19,77 +19,77 @@
#include <map>
#include <vector>
-class ControlMultiplexer :
- public slox::SloxKeyListener,
- public slox::SloxMouseMotionListener {
-public:
- /* Construct a new control multiplexer */
- ControlMultiplexer();
-
- /* Adds a listener to this ControlMultiplexer */
- inline void addControlMotionListener( ControlMotionListener* listener ) {
- m_motion_listeners.push_back( listener );
- }
-
- /* Called when a key is released. This event will be converted
+class ControlMultiplexer : public slox::SloxKeyListener,
+ public slox::SloxMouseMotionListener {
+ public:
+ /* Construct a new control multiplexer */
+ ControlMultiplexer();
+
+ /* Adds a listener to this ControlMultiplexer */
+ inline void addControlMotionListener(ControlMotionListener* listener) {
+ m_motion_listeners.push_back(listener);
+ }
+
+ /* Called when a key is released. This event will be converted
* into ControlMotionEvent and sent */
- virtual void onKeyUp( const SDL_KeyboardEvent& evt ) ;
+ virtual void onKeyUp(const SDL_KeyboardEvent& evt);
- /* Called when there was a key press. This event may be converted
+ /* Called when there was a key press. This event may be converted
* into ControlMotionEvent which is then sent off to all
* the listeners. If there is no mapping then the motion
* event is not sent */
- virtual void onKeyDown( const SDL_KeyboardEvent& evt ) ;
+ virtual void onKeyDown(const SDL_KeyboardEvent& evt);
- /* Called when the mouse is moved. This
+ /* Called when the mouse is moved. This
* is interpreted as a joystick event */
- virtual void onMouseMoved( const SDL_MouseMotionEvent& evt );
+ virtual void onMouseMoved(const SDL_MouseMotionEvent& evt);
- /* Called when there is an event that is called */
- void fireControlEvent( const ControlMotionEvent& evt );
+ /* Called when there is an event that is called */
+ void fireControlEvent(const ControlMotionEvent& evt);
- /* Adds a mapping from a key to a MotionEventType. Keys are represented
+ /* Adds a mapping from a key to a MotionEventType. Keys are represented
* as a 1 for pressed and 0 for not pressed, so some normalization must
* be done with a joystick in order to received the desired results */
- inline void setKeyMapping( SDLKey key, ControlMotionEvent::MotionEventType to, float mult=1.0f ) {
- m_keysym_map[ key ] = M_MapVal( to, mult );;
- }
+ inline void setKeyMapping(SDLKey key, ControlMotionEvent::MotionEventType to,
+ float mult = 1.0f) {
+ m_keysym_map[key] = M_MapVal(to, mult);
+ ;
+ }
- /* Removes a mapping from this multiplexer, such that
+ /* Removes a mapping from this multiplexer, such that
* a key of this type pressed will no longer fire that
* event */
- inline void removeKeyMapping( SDLKey key ) {
- m_keysym_map.erase( key );
- }
+ inline void removeKeyMapping(SDLKey key) { m_keysym_map.erase(key); }
- /* Sets a joystick axis mapping. If the joystick_index = 255 then it
+ /* Sets a joystick axis mapping. If the joystick_index = 255 then it
* is interpreted as the mouse */
- inline void setJoyAxisMapping( uint8_t joystick_index, uint8_t axis_index,
- ControlMotionEvent::MotionEventType to, float mult=1.0f ) {
- m_joy_axis_map[ joystick_index << 8 | axis_index ] = M_MapVal( to, mult );
- }
-
- inline void removeJoyAxisMapping( uint8_t joystick_index, uint8_t axis_index ) {
- m_joy_axis_map.erase( joystick_index << axis_index );
- }
-
-private:
- struct M_MapVal {
- inline M_MapVal( ControlMotionEvent::MotionEventType typ, float mult ) :
- type( typ ), multiplier( mult ) {}
- inline M_MapVal( ) : type( ControlMotionEvent::NONE ), multiplier( 0.0f ) {}
- ControlMotionEvent::MotionEventType type;
- float multiplier;
- };
- /* The listeners on this multiplexer */
- std::vector< ControlMotionListener* > m_motion_listeners;
-
- /* The keysym map */
- std::map< SDLKey, M_MapVal > m_keysym_map;
-
- /* Mapping of a bit oring of joystick index and axis index to
+ inline void setJoyAxisMapping(uint8_t joystick_index, uint8_t axis_index,
+ ControlMotionEvent::MotionEventType to,
+ float mult = 1.0f) {
+ m_joy_axis_map[joystick_index << 8 | axis_index] = M_MapVal(to, mult);
+ }
+
+ inline void removeJoyAxisMapping(uint8_t joystick_index, uint8_t axis_index) {
+ m_joy_axis_map.erase(joystick_index << axis_index);
+ }
+
+ private:
+ struct M_MapVal {
+ inline M_MapVal(ControlMotionEvent::MotionEventType typ, float mult)
+ : type(typ), multiplier(mult) {}
+ inline M_MapVal() : type(ControlMotionEvent::NONE), multiplier(0.0f) {}
+ ControlMotionEvent::MotionEventType type;
+ float multiplier;
+ };
+ /* The listeners on this multiplexer */
+ std::vector<ControlMotionListener*> m_motion_listeners;
+
+ /* The keysym map */
+ std::map<SDLKey, M_MapVal> m_keysym_map;
+
+ /* Mapping of a bit oring of joystick index and axis index to
* an event type */
- std::map< uint16_t, M_MapVal > m_joy_axis_map;
+ std::map<uint16_t, M_MapVal> m_joy_axis_map;
};
#endif /* CONTROLMULTIPLEXER_HPP_ */
diff --git a/sons_of_sol/PlayerShip.hpp b/sons_of_sol/PlayerShip.hpp
index b87e731..03c7e71 100644
--- a/sons_of_sol/PlayerShip.hpp
+++ b/sons_of_sol/PlayerShip.hpp
@@ -7,17 +7,17 @@
* Ship.hpp: <description>
*/
+#include "glox/GloxLookAtPerspective.hpp"
#include "glox/GloxPoint.hpp"
#include "glox/GloxVector3.hpp"
-#include "glox/GloxLookAtPerspective.hpp"
#include "slox/events/SloxKeyListener.hpp"
#include "ControlMotionListener.hpp"
#include "sons_of_sol/Projectile.hpp"
-#include <vector>
#include <queue>
+#include <vector>
#define GUN_RATE 1
#define N_LIVING_PROJECTILES (TTL / GUN_RATE)
@@ -26,137 +26,114 @@
* for the first person
* ship */
class PlayerShip : public ControlMotionListener {
-public:
- inline PlayerShip() :
- m_forward( 0, 0, -1 ), m_up( 0, 1, 0 ), m_right( 1, 0, 0 ),
- m_dpitch( 0 ),
- m_dyaw( 0 ),
- m_droll( 0 ),
- m_droll_to( 0 ),
- m_dforward( 0 ),
- m_dforward_to( 0 ),
- m_dup( 0 ),
- m_dup_to( 0 ),
- m_dright( 0 ),
- m_dright_to( 0 ),
- m_jitter( 0 ),
- m_is_firing( false ){}
-
- /* Draw the heads-up-display of the
+ public:
+ inline PlayerShip()
+ : m_forward(0, 0, -1),
+ m_up(0, 1, 0),
+ m_right(1, 0, 0),
+ m_dpitch(0),
+ m_dyaw(0),
+ m_droll(0),
+ m_droll_to(0),
+ m_dforward(0),
+ m_dforward_to(0),
+ m_dup(0),
+ m_dup_to(0),
+ m_dright(0),
+ m_dright_to(0),
+ m_jitter(0),
+ m_is_firing(false) {}
+
+ /* Draw the heads-up-display of the
* ship */
- void drawHUD();
+ void drawHUD();
- /* Render the perspective of
+ /* Render the perspective of
* this ship */
- void renderPerspective();
+ void renderPerspective();
+
+ /* Move the ship up and down */
+ void pitch(float angle);
- /* Move the ship up and down */
- void pitch( float angle );
+ /* Roll the ship */
+ void roll(float angle);
- /* Roll the ship */
- void roll( float angle );
+ /* Rotate the ship side to side */
+ void yaw(float angle);
- /* Rotate the ship side to side */
- void yaw( float angle );
+ /* Update this object */
+ void update();
- /* Update this object */
- void update();
+ const glox::GloxStandardProjection& getPerspective() const {
+ return m_perspective;
+ }
- const glox::GloxStandardProjection& getPerspective( ) const {
- return m_perspective;
- }
+ glox::GloxStandardProjection& getPerspective() { return m_perspective; }
- glox::GloxStandardProjection& getPerspective( ) {
- return m_perspective;
- }
+ void setPerspective(const glox::GloxLookAtPerspective& perspective) {
+ m_perspective = perspective;
+ }
- void setPerspective( const glox::GloxLookAtPerspective& perspective ) {
- m_perspective = perspective;
- }
+ inline void setDPitch(float dpitch) { this->m_dpitch = dpitch; }
- inline void setDPitch( float dpitch ) {
- this->m_dpitch = dpitch;
- }
+ inline void setDRoll(float droll) { this->m_droll = droll; }
- inline void setDRoll( float droll ) {
- this->m_droll = droll;
- }
+ inline void setDYaw(float dyaw) { this->m_dyaw = dyaw; }
- inline void setDYaw( float dyaw ) {
- this->m_dyaw = dyaw;
- }
+ inline float getDPitch() const { return m_dpitch; }
- inline float getDPitch() const {
- return m_dpitch;
- }
+ inline float getDYaw() const { return m_dyaw; }
- inline float getDYaw() const {
- return m_dyaw;
- }
+ inline float getDRoll() const { return m_droll; }
- inline float getDRoll() const {
- return m_droll;
- }
+ inline void setDForwardTo(float dforward) { m_dforward_to = dforward; }
- inline void setDForwardTo( float dforward ) {
- m_dforward_to = dforward ;
- }
+ inline float getDForward() { return m_dforward; }
- inline float getDForward() {
- return m_dforward;
- }
+ virtual void onControlMotion(const ControlMotionEvent& evt);
- virtual void onControlMotion( const ControlMotionEvent& evt );
+ inline const glox::GloxPoint<> getPosition() const { return m_position; }
- inline const glox::GloxPoint<> getPosition() const {
- return m_position;
- }
+ inline void setPosition(const glox::GloxPoint<>& pos) { m_position = pos; }
- inline void setPosition( const glox::GloxPoint<>& pos ) {
- m_position = pos;
- }
+ inline void setJitter(float jitter) { m_jitter = jitter; }
- inline void setJitter( float jitter ) {
- m_jitter = jitter ;
- }
+ inline float getJitter() { return m_jitter; }
- inline float getJitter( ) {
- return m_jitter ;
- }
+ void drawProjectiles();
- void drawProjectiles() ;
-private:
- /* The position of the ship */
- glox::GloxPoint<> m_position;
+ private:
+ /* The position of the ship */
+ glox::GloxPoint<> m_position;
- /* The orientation of the ship */
- glox::GloxVector3<> m_forward;
- glox::GloxVector3<> m_up;
- glox::GloxVector3<> m_right;
+ /* The orientation of the ship */
+ glox::GloxVector3<> m_forward;
+ glox::GloxVector3<> m_up;
+ glox::GloxVector3<> m_right;
- /* The perspective of the ship */
- glox::GloxLookAtPerspective m_perspective;
+ /* The perspective of the ship */
+ glox::GloxLookAtPerspective m_perspective;
- float m_dpitch;
- float m_dyaw;
+ float m_dpitch;
+ float m_dyaw;
- float m_droll;
- float m_droll_to;
+ float m_droll;
+ float m_droll_to;
- float m_dforward;
- float m_dforward_to;
+ float m_dforward;
+ float m_dforward_to;
- float m_dup;
- float m_dup_to;
+ float m_dup;
+ float m_dup_to;
- float m_dright;
- float m_dright_to;
+ float m_dright;
+ float m_dright_to;
- float m_jitter ;
+ float m_jitter;
- bool m_is_firing ;
- std::vector<Projectile> m_living_projectiles ;
- std::queue<int> m_open_positions;
+ bool m_is_firing;
+ std::vector<Projectile> m_living_projectiles;
+ std::queue<int> m_open_positions;
};
#endif /* SHIP_HPP_ */
diff --git a/sons_of_sol/Projectile.hpp b/sons_of_sol/Projectile.hpp
index 0949314..5f298a7 100644
--- a/sons_of_sol/Projectile.hpp
+++ b/sons_of_sol/Projectile.hpp
@@ -7,39 +7,40 @@
* Projectile.hpp: <description>
*/
+#include "glox/GloxCommon.hpp"
#include "glox/GloxPoint.hpp"
-#include "glox/objects/GloxCube.hpp"
#include "glox/GloxState.hpp"
-#include "glox/GloxCommon.hpp"
+#include "glox/objects/GloxCube.hpp"
#include <iostream>
#define TTL 50
class Projectile {
-public:
- Projectile( const glox::GloxPoint<>& position, const glox::GloxPoint<>& vector ) ;
-
- inline void update() {
- if( m_ttl == 0 || -- m_ttl == 0 ) {
- return ;
- }
- m_position += m_dpos;
+ public:
+ Projectile(const glox::GloxPoint<>& position,
+ const glox::GloxPoint<>& vector);
+
+ inline void update() {
+ if (m_ttl == 0 || --m_ttl == 0) {
+ return;
}
+ m_position += m_dpos;
+ }
- inline bool isDead() { return m_ttl == 0; }
+ inline bool isDead() { return m_ttl == 0; }
- void draw() ;
+ void draw();
- static void loadModel() ;
-private:
- uint8_t m_ttl ;
- float m_roty;
- float m_rotz;
- glox::GloxPoint<> m_position;
- glox::GloxPoint<> m_dpos;
- static glox::GloxCube* m_model ;
+ static void loadModel();
+ private:
+ uint8_t m_ttl;
+ float m_roty;
+ float m_rotz;
+ glox::GloxPoint<> m_position;
+ glox::GloxPoint<> m_dpos;
+ static glox::GloxCube* m_model;
};
#endif /* PROJECTILE_HPP_ */
diff --git a/sons_of_sol/SonsOfSolApplication.hpp b/sons_of_sol/SonsOfSolApplication.hpp
index ea56614..8d03e61 100644
--- a/sons_of_sol/SonsOfSolApplication.hpp
+++ b/sons_of_sol/SonsOfSolApplication.hpp
@@ -9,175 +9,175 @@
#include "glox/GloxCommon.hpp"
#include "slox/SloxApplication.hpp"
-#include "slox/SloxTextureFactory.hpp"
#include "slox/SloxRawEventHandler.hpp"
+#include "slox/SloxTextureFactory.hpp"
#include "slox/events/SloxFunctionQuitListener.hpp"
#include "slox/loader/SloxModelObject.hpp"
#include "slox/loader/SloxObjectLoader.hpp"
-#include "glox/GloxViewport.hpp"
-#include "glox/GloxFirstPersonPerspective.hpp"
-#include "glox/objects/GloxTexturedCube.hpp"
-#include "glox/objects/GloxTexturedSphere.hpp"
#include "glox/GloxColor.hpp"
-#include "glox/GloxLookAtPerspective.hpp"
+#include "glox/GloxFirstPersonPerspective.hpp"
#include "glox/GloxLightSourceManager.hpp"
-#include "glox/objects/GloxCube.hpp"
+#include "glox/GloxLookAtPerspective.hpp"
#include "glox/GloxProgram.hpp"
+#include "glox/GloxViewport.hpp"
+#include "glox/objects/GloxCube.hpp"
+#include "glox/objects/GloxTexturedCube.hpp"
+#include "glox/objects/GloxTexturedSphere.hpp"
-#include "sons_of_sol/PlayerShip.hpp"
-#include "sons_of_sol/ControlMultiplexer.hpp"
#include "sons_of_sol/AIShip.hpp"
+#include "sons_of_sol/ControlMultiplexer.hpp"
+#include "sons_of_sol/PlayerShip.hpp"
#include "sons_of_sol/Updaters.hpp"
#define FAR_DISTANCE_START 1
-#define FAR_DISTANCE_END 1000000
+#define FAR_DISTANCE_END 1000000
#define MID_DISTANCE_START 10
-#define MID_DISTANCE_END 100000
-
-class SonsOfSolApplication : public
- slox::SloxApplication,
- slox::SloxRawEventHandler,
- slox::SloxResizeListener,
- slox::SloxKeyListener,
- slox::SloxQuitListener {
-public:
- /* Process an event */
- virtual inline void onEvent( const SDL_Event& event ) {
- SloxRawEventHandler::onEvent( event );
- }
-
- virtual inline void onKeyDown( const SDL_KeyboardEvent& evt ) {
- if( evt.keysym.sym == SDLK_ESCAPE ) exit( 0 );
- if( evt.keysym.sym == SDLK_f ) {
- setFullScreen();
- };
- if( evt.keysym.sym == SDLK_p ) {
- pause();
- };
- }
-
- /* Initializes this application;
+#define MID_DISTANCE_END 100000
+
+class SonsOfSolApplication : public slox::SloxApplication,
+ slox::SloxRawEventHandler,
+ slox::SloxResizeListener,
+ slox::SloxKeyListener,
+ slox::SloxQuitListener {
+ public:
+ /* Process an event */
+ virtual inline void onEvent(const SDL_Event& event) {
+ SloxRawEventHandler::onEvent(event);
+ }
+
+ virtual inline void onKeyDown(const SDL_KeyboardEvent& evt) {
+ if (evt.keysym.sym == SDLK_ESCAPE)
+ exit(0);
+ if (evt.keysym.sym == SDLK_f) {
+ setFullScreen();
+ };
+ if (evt.keysym.sym == SDLK_p) {
+ pause();
+ };
+ }
+
+ /* Initializes this application;
* returns true if initialization
* succeeded, false otherwise */
- virtual bool initialize( int argc, char** argv );
+ virtual bool initialize(int argc, char** argv);
- /* The main loop of the application */
- virtual bool loop( uint32_t ticks ) {
- /* Update things that we might
+ /* The main loop of the application */
+ virtual bool loop(uint32_t ticks) {
+ /* Update things that we might
* want to */
- update( ticks );
+ update(ticks);
- /* Some boilder OpenGL stuff */
- glox::GloxState::clear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- glox::GloxState::loadIdentity();
- glox::GloxState::enable( GL_DEPTH_TEST );
+ /* Some boilder OpenGL stuff */
+ glox::GloxState::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glox::GloxState::loadIdentity();
+ glox::GloxState::enable(GL_DEPTH_TEST);
- /* Display some stuff */
- display();
+ /* Display some stuff */
+ display();
- /* Flush the buffers and
+ /* Flush the buffers and
* do the appropriate delay */
- glFlush();
- SDL_GL_SwapBuffers();
- SDL_Delay( 5 );
+ glFlush();
+ SDL_GL_SwapBuffers();
+ SDL_Delay(5);
- return !m_quit;
- }
+ return !m_quit;
+ }
- /* What happens when a quit event is
+ /* What happens when a quit event is
* intercepted */
- virtual inline void onQuit( const SDL_QuitEvent& evt ) {
- (void) evt;
- m_quit = true;
- }
-
- inline virtual ~SonsOfSolApplication() {
-
- }
-
- /* Resizes the perspective for OpenGL */
- inline void onResize( const SDL_ResizeEvent& evt ) {
- m_screen = SDL_SetVideoMode(evt.w,evt.h,0,SDL_OPENGL|SDL_RESIZABLE|SDL_DOUBLEBUF);
- reshape( evt.w, evt.h );
- }
-
- void pause() ;
-private:
- /* Render the background. (This is the Earth and skybox) */
- void renderFar();
- /* Render whats in the middle */
- void renderMid();
-
- void setupControls() ;
- void reshape( int width, int height );
-
- /* Sets up the lights to be used */
- void enableLighting( );
- void update( uint32_t ticks );
- void display( ) ;
- bool loadTextures();
- void setFullScreen();
-
- /* perspective stuff */
- glox::GloxViewport m_viewport;
- glox::GloxLookAtPerspective m_perspective;
-
- /* The sky */
- glox::GloxTexturedCube* m_sky;
- glox::GloxTexturedCube* m_crate;
- glox::GloxTexturedSphere* m_earth;
- glox::GloxTexturedSphere* m_moon;
-
- /* Textures */
- glox::GloxTexture m_sky_tex;
- glox::GloxTexture m_leaf_tex;
- glox::GloxTexture m_crate_tex;
- glox::GloxTexture m_star_tex;
- glox::GloxTexture m_earth_tex;
- glox::GloxTexture m_moon_tex;
-
- /* The sun */
- glox::GloxPointCollection<glox::GloxPointNormalTexture> m_star;
-
- std::vector<AIShip> m_aiships ;
- std::vector<AIShip::Updater*> m_updaters;
-
- /* The little test object */
- slox::SloxModelObject* m_probe;
- slox::SloxModelObject* m_frigate_industrial;
- slox::SloxModelObject* m_other_ship;
- slox::SloxModelObject* m_test_cube;
- slox::SloxModelObject* m_deathstar;
- slox::SloxModelObject* m_acceleration_cannon ;
-
- slox::SloxTextureFactory m_texture_factory;
- slox::SloxObjectLoader m_object_loader;
- /* A boolean stating if it is time
+ virtual inline void onQuit(const SDL_QuitEvent& evt) {
+ (void)evt;
+ m_quit = true;
+ }
+
+ inline virtual ~SonsOfSolApplication() {}
+
+ /* Resizes the perspective for OpenGL */
+ inline void onResize(const SDL_ResizeEvent& evt) {
+ m_screen = SDL_SetVideoMode(evt.w, evt.h, 0,
+ SDL_OPENGL | SDL_RESIZABLE | SDL_DOUBLEBUF);
+ reshape(evt.w, evt.h);
+ }
+
+ void pause();
+
+ private:
+ /* Render the background. (This is the Earth and skybox) */
+ void renderFar();
+ /* Render whats in the middle */
+ void renderMid();
+
+ void setupControls();
+ void reshape(int width, int height);
+
+ /* Sets up the lights to be used */
+ void enableLighting();
+ void update(uint32_t ticks);
+ void display();
+ bool loadTextures();
+ void setFullScreen();
+
+ /* perspective stuff */
+ glox::GloxViewport m_viewport;
+ glox::GloxLookAtPerspective m_perspective;
+
+ /* The sky */
+ glox::GloxTexturedCube* m_sky;
+ glox::GloxTexturedCube* m_crate;
+ glox::GloxTexturedSphere* m_earth;
+ glox::GloxTexturedSphere* m_moon;
+
+ /* Textures */
+ glox::GloxTexture m_sky_tex;
+ glox::GloxTexture m_leaf_tex;
+ glox::GloxTexture m_crate_tex;
+ glox::GloxTexture m_star_tex;
+ glox::GloxTexture m_earth_tex;
+ glox::GloxTexture m_moon_tex;
+
+ /* The sun */
+ glox::GloxPointCollection<glox::GloxPointNormalTexture> m_star;
+
+ std::vector<AIShip> m_aiships;
+ std::vector<AIShip::Updater*> m_updaters;
+
+ /* The little test object */
+ slox::SloxModelObject* m_probe;
+ slox::SloxModelObject* m_frigate_industrial;
+ slox::SloxModelObject* m_other_ship;
+ slox::SloxModelObject* m_test_cube;
+ slox::SloxModelObject* m_deathstar;
+ slox::SloxModelObject* m_acceleration_cannon;
+
+ slox::SloxTextureFactory m_texture_factory;
+ slox::SloxObjectLoader m_object_loader;
+ /* A boolean stating if it is time
* to quit */
- bool m_quit;
+ bool m_quit;
- glox::GloxLightSourceManager m_light_manager;
- PlayerShip m_ship;
+ glox::GloxLightSourceManager m_light_manager;
+ PlayerShip m_ship;
- SDL_Surface* m_screen;
- ControlMultiplexer m_event_multiplexer;
+ SDL_Surface* m_screen;
+ ControlMultiplexer m_event_multiplexer;
- int m_screen_width;
- int m_screen_height;
+ int m_screen_width;
+ int m_screen_height;
- int m_script_ttl ;
+ int m_script_ttl;
- bool m_is_paused;
+ bool m_is_paused;
- glox::GloxProgram* m_earth_prog ;
- glox::GloxProgram* m_moon_prog ;
- int m_earth_shader_light_pos ;
- int m_earth_shader_camera_pos ;
- int m_earth_shader_time ;
- int m_moon_shader_light_pos ;
- int m_moon_shader_camera_pos ;
+ glox::GloxProgram* m_earth_prog;
+ glox::GloxProgram* m_moon_prog;
+ int m_earth_shader_light_pos;
+ int m_earth_shader_camera_pos;
+ int m_earth_shader_time;
+ int m_moon_shader_light_pos;
+ int m_moon_shader_camera_pos;
};
#endif /* SONSOFSOLAPPLICATION_HPP_ */
diff --git a/sons_of_sol/Updaters.hpp b/sons_of_sol/Updaters.hpp
index 1f81112..e2e8b2d 100644
--- a/sons_of_sol/Updaters.hpp
+++ b/sons_of_sol/Updaters.hpp
@@ -7,37 +7,37 @@
* Updaters.hpp: <description>
*/
-#include "sons_of_sol/AIShip.hpp"
-#include "glox/GloxPoint.hpp"
#include "glox/GloxCommon.hpp"
+#include "glox/GloxPoint.hpp"
+#include "sons_of_sol/AIShip.hpp"
class EllipseUpdater : public AIShip::Updater {
-public:
- inline EllipseUpdater( const glox::GloxPoint<>& center,
- const glox::GloxPoint<>& major, const glox::GloxPoint<>& minor,
- float speed_factor ) :
- m_center( center ),
- m_major( major ),
- m_minor( minor ),
- m_speed( speed_factor ) {
- m_a = major.getMagnitude();
- m_b = minor.getMagnitude();
- }
+ public:
+ inline EllipseUpdater(const glox::GloxPoint<>& center,
+ const glox::GloxPoint<>& major,
+ const glox::GloxPoint<>& minor, float speed_factor)
+ : m_center(center),
+ m_major(major),
+ m_minor(minor),
+ m_speed(speed_factor) {
+ m_a = major.getMagnitude();
+ m_b = minor.getMagnitude();
+ }
+
+ inline glox::GloxPoint<> update(uint32_t time) {
+ float t = m_speed * time;
+ return m_center + (m_major * m_a * glox::GloxCos(t) +
+ m_minor * m_b * glox::GloxSin(t));
+ }
- inline glox::GloxPoint<> update( uint32_t time ) {
- float t = m_speed * time ;
- return m_center + ( m_major * m_a * glox::GloxCos( t ) +
- m_minor * m_b * glox::GloxSin( t ) );
- }
-
-private:
- glox::GloxPoint<> m_center;
- glox::GloxPoint<> m_major;
- glox::GloxPoint<> m_minor;
+ private:
+ glox::GloxPoint<> m_center;
+ glox::GloxPoint<> m_major;
+ glox::GloxPoint<> m_minor;
- float m_a;
- float m_b;
- float m_speed ;
+ float m_a;
+ float m_b;
+ float m_speed;
};
#endif /* UPDATERS_HPP_ */
diff --git a/sons_of_sol/private_db/AIShip.cpp b/sons_of_sol/private_db/AIShip.cpp
index 5940e42..b487d3c 100644
--- a/sons_of_sol/private_db/AIShip.cpp
+++ b/sons_of_sol/private_db/AIShip.cpp
@@ -3,124 +3,120 @@
#include <cmath>
#include <iostream>
+#include "glox/GloxColor.hpp"
#include "glox/GloxScopedRotation.hpp"
#include "glox/GloxScopedTranslation.hpp"
-#include "glox/GloxColor.hpp"
using namespace slox;
using namespace glox;
using namespace std;
-
-SloxModelObject* AIShip::s_high_model ;
-SloxModelObject* AIShip::s_med_model ;
-SloxModelObject* AIShip::s_low_model ;
-GloxCube* AIShip::s_really_far_away_model ;
-
-void AIShip::setModel( slox::SloxModelObject* high, slox::SloxModelObject* med, slox::SloxModelObject* low ) {
- s_high_model = high;
- s_med_model = med;
- s_low_model = low;
- s_really_far_away_model = new glox::GloxCube( 4, 0.5, 8, GloxColor(245,245,220) );
+SloxModelObject* AIShip::s_high_model;
+SloxModelObject* AIShip::s_med_model;
+SloxModelObject* AIShip::s_low_model;
+GloxCube* AIShip::s_really_far_away_model;
+
+void AIShip::setModel(slox::SloxModelObject* high, slox::SloxModelObject* med,
+ slox::SloxModelObject* low) {
+ s_high_model = high;
+ s_med_model = med;
+ s_low_model = low;
+ s_really_far_away_model =
+ new glox::GloxCube(4, 0.5, 8, GloxColor(245, 245, 220));
}
-void AIShip::setUpdateFunction( Updater* updater ){
- update_func = updater;
+void AIShip::setUpdateFunction(Updater* updater) {
+ update_func = updater;
- /* Update 3 times so we have a full set
+ /* Update 3 times so we have a full set
* of points to start with */
- update();
- update();
- update();
+ update();
+ update();
+ update();
}
void AIShip::calculate_roll_to() {
- GloxPoint<> total_change = m_future_position - m_last_position ;
- GloxPoint<> current_change = m_position - m_last_position ;
-
- float scalar_projection = ( current_change.dot( total_change ) / total_change.dot(total_change) ) ;
- total_change *= scalar_projection ;
- GloxPoint<> to_vector = current_change - total_change ;
- to_vector.normalize();
-
- float ang = to_vector.dot( GloxPointf(0,1,0) ) ;
- float tmp = GloxToDegrees( acos( ang ) );
-
- if( tmp == tmp ) {
- /* Cut out NANs */
- m_roll_to = tmp;
- }
-// cout << "m_roll_to " << m_roll_to << endl;
+ GloxPoint<> total_change = m_future_position - m_last_position;
+ GloxPoint<> current_change = m_position - m_last_position;
+
+ float scalar_projection =
+ (current_change.dot(total_change) / total_change.dot(total_change));
+ total_change *= scalar_projection;
+ GloxPoint<> to_vector = current_change - total_change;
+ to_vector.normalize();
+
+ float ang = to_vector.dot(GloxPointf(0, 1, 0));
+ float tmp = GloxToDegrees(acos(ang));
+
+ if (tmp == tmp) {
+ /* Cut out NANs */
+ m_roll_to = tmp;
+ }
+ // cout << "m_roll_to " << m_roll_to << endl;
}
-void AIShip::setTimeOffset( uint32_t off ) {
- m_time_offset = off ;
+void AIShip::setTimeOffset(uint32_t off) {
+ m_time_offset = off;
}
-void AIShip::update( ) {
- m_last_position = m_position;
- m_position = m_future_position ;
- m_future_position = update_func->update( SDL_GetTicks() + m_time_offset ) ;
+void AIShip::update() {
+ m_last_position = m_position;
+ m_position = m_future_position;
+ m_future_position = update_func->update(SDL_GetTicks() + m_time_offset);
}
-void AIShip::draw( float dist ) {
- GloxScopedTranslation __gstr1( m_position );
- /* The the change in the vector, this is where
+void AIShip::draw(float dist) {
+ GloxScopedTranslation __gstr1(m_position);
+ /* The the change in the vector, this is where
* the front of the ship goes */
- GloxPoint<> dpos = m_position - m_last_position ;
-
- /* Project the point onto the x,y plane */
- GloxPoint<> first( dpos.getX(), dpos.getY(), 0 );
- /* A point that represents the x axis */
- GloxPoint<> xaxis( 1, 0, 0 );
-
- /* Rotation around the z axis */
- float dot = first.dot( xaxis ) ;
- float rot = GloxToDegrees(acos( dot )) ;
-
- if( first.getY() < 0 ) {
- rot = - rot;
- }
- rot = rot + 180 ;
- // if( rot != rot ) {
- // cout << "Non existant Z rotation!" << endl ;
- // }
- GloxScopedRotation __gscr1( rot, 0, 0, 1 );
- /* x axis now follows *first* vector */
- /* Rotate around y axis to get x to follow *dpos* vector */
- dot = first.dot( dpos );
-
- rot = acos( dot );
- rot = GloxToDegrees( rot );
-
- if( dpos.getZ() < 0 ) {
- rot = - rot;
- }
-
- // if( rot != rot ) {
- // cout << "Non existant Y rotation!" << endl ;
- // }
- GloxScopedRotation __glcr2( rot, 0, 1, 0 );
-
- calculate_roll_to();
- if( m_roll != m_roll ) {
- m_roll = 0.0f;
- }
- m_roll = ( m_roll_to + (5 - 1) * m_roll) / 5.0f;
-
- float roll = m_roll;
- // if( dpos.getX() < 0 ) {
- // roll += 180 ;
- // }
-
- GloxScopedRotation __glco3( roll, 1, 0, 0 );
- GloxScale( 2,
- if( dist < 20 )
- s_high_model->draw();
- else if ( dist < 50 )
- s_med_model->draw();
- else if ( dist < 1000 )
- s_low_model->draw();
- else
- s_really_far_away_model->draw();
- );
+ GloxPoint<> dpos = m_position - m_last_position;
+
+ /* Project the point onto the x,y plane */
+ GloxPoint<> first(dpos.getX(), dpos.getY(), 0);
+ /* A point that represents the x axis */
+ GloxPoint<> xaxis(1, 0, 0);
+
+ /* Rotation around the z axis */
+ float dot = first.dot(xaxis);
+ float rot = GloxToDegrees(acos(dot));
+
+ if (first.getY() < 0) {
+ rot = -rot;
+ }
+ rot = rot + 180;
+ // if( rot != rot ) {
+ // cout << "Non existant Z rotation!" << endl ;
+ // }
+ GloxScopedRotation __gscr1(rot, 0, 0, 1);
+ /* x axis now follows *first* vector */
+ /* Rotate around y axis to get x to follow *dpos* vector */
+ dot = first.dot(dpos);
+
+ rot = acos(dot);
+ rot = GloxToDegrees(rot);
+
+ if (dpos.getZ() < 0) {
+ rot = -rot;
+ }
+
+ // if( rot != rot ) {
+ // cout << "Non existant Y rotation!" << endl ;
+ // }
+ GloxScopedRotation __glcr2(rot, 0, 1, 0);
+
+ calculate_roll_to();
+ if (m_roll != m_roll) {
+ m_roll = 0.0f;
+ }
+ m_roll = (m_roll_to + (5 - 1) * m_roll) / 5.0f;
+
+ float roll = m_roll;
+ // if( dpos.getX() < 0 ) {
+ // roll += 180 ;
+ // }
+
+ GloxScopedRotation __glco3(roll, 1, 0, 0);
+ GloxScale(2, if (dist < 20) s_high_model->draw();
+ else if (dist < 50) s_med_model->draw();
+ else if (dist < 1000) s_low_model->draw();
+ else s_really_far_away_model->draw(););
}
diff --git a/sons_of_sol/private_db/ApplicationDisplay.cpp b/sons_of_sol/private_db/ApplicationDisplay.cpp
index c9e773e..bf94b33 100644
--- a/sons_of_sol/private_db/ApplicationDisplay.cpp
+++ b/sons_of_sol/private_db/ApplicationDisplay.cpp
@@ -11,146 +11,128 @@ using namespace slox;
using namespace std;
float randJitter() {
- return ((rand() & 0xFF) - 128.0) / (256.0 * 10) ;
+ return ((rand() & 0xFF) - 128.0) / (256.0 * 10);
}
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 ;
+ 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));
}
- /* Translate to the this perspective */
- m_ship.drawHUD();
+ 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;
+ }
- m_ship.getPerspective().setZNear( FAR_DISTANCE_START );
- m_ship.getPerspective().setZFar( FAR_DISTANCE_END );
- m_ship.getPerspective().render();
+ /* Translate to the this perspective */
+ m_ship.drawHUD();
- /* We don't want lighting for the skybox */
- GloxDisableFor( GL_LIGHTING,
- /* Draw some stuff relative to the
+ 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
+ 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() ) ;
- m_earth_prog->setUniformFloat( m_earth_shader_time, SDL_GetTicks() / 300000.0 ) ;
-
- //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();
+ m_earth_prog->render();
+ m_earth_prog->setUniformVector3(
+ m_earth_shader_light_pos,
+ m_light_manager.getLightSource(0)->getPosition());
+ m_earth_prog->setUniformFloat(m_earth_shader_time,
+ SDL_GetTicks() / 300000.0);
+
+ //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();
}
diff --git a/sons_of_sol/private_db/ApplicationInit.cpp b/sons_of_sol/private_db/ApplicationInit.cpp
index 7729d12..dccc99a 100644
--- a/sons_of_sol/private_db/ApplicationInit.cpp
+++ b/sons_of_sol/private_db/ApplicationInit.cpp
@@ -10,221 +10,242 @@ using namespace slox;
using namespace glox;
using namespace std;
-bool SonsOfSolApplication::initialize( int argc, char** argv ) {
- (void) argc;
- (void) argv;
- /* Use our texture factory to load textures */
- m_object_loader.setTextureFactory( &m_texture_factory );
- m_is_paused = false ;
-
- setupControls();
-
- SDL_Init( SDL_INIT_VIDEO );
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
- const SDL_VideoInfo* info = SDL_GetVideoInfo(); //<-- calls SDL_GetVideoInfo();
- m_screen_width = info->current_w;
- m_screen_height = info->current_h;
- m_screen = SDL_SetVideoMode( 600, 600, 0, SDL_OPENGL|SDL_RESIZABLE|SDL_DOUBLEBUF );
-
- m_perspective.setPosition( GloxPoint<>( 0, 0, 10 ) );
- m_perspective.setZFar ( FAR_DISTANCE_END );
- m_perspective.setZNear( FAR_DISTANCE_START );
- m_ship.setPerspective( m_perspective );
- m_ship.setPosition( GloxPointf( 0, 10, -3 ) );
-
-
- if( argv[1] == NULL || strcmp(argv[1],"nograb") ) {
- SDL_ShowCursor( 0 );
- SDL_WM_GrabInput(SDL_GRAB_ON);
- }
-
- if( glewInit() != GLEW_OK ) {
- cerr << "Unable to initialize GLEW" << endl ;
- exit( 122 ) ;
- }
-
- /* Add some listeners */
- this->addQuitListener( this );
- this->addKeyListener( this );
-
- this->addResizeListener( this );
-
- m_event_multiplexer.addControlMotionListener( & m_ship );
-
- if( ! m_screen ) {
- /* If the screen could not be initialized, print
+bool SonsOfSolApplication::initialize(int argc, char** argv) {
+ (void)argc;
+ (void)argv;
+ /* Use our texture factory to load textures */
+ m_object_loader.setTextureFactory(&m_texture_factory);
+ m_is_paused = false;
+
+ setupControls();
+
+ SDL_Init(SDL_INIT_VIDEO);
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+ const SDL_VideoInfo* info =
+ SDL_GetVideoInfo(); //<-- calls SDL_GetVideoInfo();
+ m_screen_width = info->current_w;
+ m_screen_height = info->current_h;
+ m_screen =
+ SDL_SetVideoMode(600, 600, 0, SDL_OPENGL | SDL_RESIZABLE | SDL_DOUBLEBUF);
+
+ m_perspective.setPosition(GloxPoint<>(0, 0, 10));
+ m_perspective.setZFar(FAR_DISTANCE_END);
+ m_perspective.setZNear(FAR_DISTANCE_START);
+ m_ship.setPerspective(m_perspective);
+ m_ship.setPosition(GloxPointf(0, 10, -3));
+
+ if (argv[1] == NULL || strcmp(argv[1], "nograb")) {
+ SDL_ShowCursor(0);
+ SDL_WM_GrabInput(SDL_GRAB_ON);
+ }
+
+ if (glewInit() != GLEW_OK) {
+ cerr << "Unable to initialize GLEW" << endl;
+ exit(122);
+ }
+
+ /* Add some listeners */
+ this->addQuitListener(this);
+ this->addKeyListener(this);
+
+ this->addResizeListener(this);
+
+ m_event_multiplexer.addControlMotionListener(&m_ship);
+
+ if (!m_screen) {
+ /* If the screen could not be initialized, print
* a useful video message */
- this->setError( "Cannot set SDL video mode\n" );
- return false;
- }
-
- SDL_WM_SetCaption( "Sons Of Sol", "" );
- reshape( m_screen->w, m_screen->h );
-
- /* Load the textures into memory */
- if( ! loadTextures() ) return false;
-
- GloxTextureRepeat texrep( &m_sky_tex, 1.8, 1.8 );
- m_sky = new GloxTexturedCube( FAR_DISTANCE_END - 100, GloxColor( 255, 255, 255 ),
- texrep, texrep, texrep, texrep, texrep, texrep );
-
- texrep = GloxTextureRepeat( &m_crate_tex, 1, 1 );
- m_crate = new GloxTexturedCube( 5.0f, GloxColor( 255, 255, 255 ),
- texrep, texrep, texrep, texrep, texrep, texrep );
-
- m_object_loader.addToPath( "objects" );
- m_object_loader.addToPath( "objects/material" );
- m_earth = new GloxTexturedSphere( FAR_DISTANCE_END / 4.0, 5.0f, m_earth_tex );
- m_moon = new GloxTexturedSphere( FAR_DISTANCE_END / 24.0, 5.0f, m_moon_tex );
- m_probe = m_object_loader.loadObjectFromFile( "probe.obj" );
-
- m_script_ttl = 130 ;
- if( ! m_probe ) {
- cerr << "Unable to load probe: " << m_object_loader.getReason() << endl;
- exit( 123 );
- }
-
- m_frigate_industrial = m_object_loader.loadObjectFromFile( "frigate_industrial.obj" );
- if( ! m_frigate_industrial ) {
- cerr << "Unable to load frigate_industrial\n" << m_object_loader.getReason() << endl;
- exit( 123 );
+ this->setError("Cannot set SDL video mode\n");
+ return false;
+ }
+
+ SDL_WM_SetCaption("Sons Of Sol", "");
+ reshape(m_screen->w, m_screen->h);
+
+ /* Load the textures into memory */
+ if (!loadTextures())
+ return false;
+
+ GloxTextureRepeat texrep(&m_sky_tex, 1.8, 1.8);
+ m_sky = new GloxTexturedCube(FAR_DISTANCE_END - 100, GloxColor(255, 255, 255),
+ texrep, texrep, texrep, texrep, texrep, texrep);
+
+ texrep = GloxTextureRepeat(&m_crate_tex, 1, 1);
+ m_crate = new GloxTexturedCube(5.0f, GloxColor(255, 255, 255), texrep, texrep,
+ texrep, texrep, texrep, texrep);
+
+ m_object_loader.addToPath("objects");
+ m_object_loader.addToPath("objects/material");
+ m_earth = new GloxTexturedSphere(FAR_DISTANCE_END / 4.0, 5.0f, m_earth_tex);
+ m_moon = new GloxTexturedSphere(FAR_DISTANCE_END / 24.0, 5.0f, m_moon_tex);
+ m_probe = m_object_loader.loadObjectFromFile("probe.obj");
+
+ m_script_ttl = 130;
+ if (!m_probe) {
+ cerr << "Unable to load probe: " << m_object_loader.getReason() << endl;
+ exit(123);
+ }
+
+ m_frigate_industrial =
+ m_object_loader.loadObjectFromFile("frigate_industrial.obj");
+ if (!m_frigate_industrial) {
+ cerr << "Unable to load frigate_industrial\n"
+ << m_object_loader.getReason() << endl;
+ exit(123);
+ }
+
+ m_other_ship = m_object_loader.loadObjectFromFile("ship.obj");
+ SloxModelObject* ship_med =
+ m_object_loader.loadObjectFromFile("ship_med.obj");
+ SloxModelObject* ship_low =
+ m_object_loader.loadObjectFromFile("ship_low.obj");
+ if (!(m_other_ship && ship_med && ship_low)) {
+ cerr << "Unable to load other ship\n"
+ << m_object_loader.getReason() << endl;
+ exit(123);
+ }
+
+ m_test_cube = m_object_loader.loadObjectFromFile("cube.obj");
+ if (!m_test_cube) {
+ cerr << "Unable to load test cube\n" << m_object_loader.getReason() << endl;
+ exit(123);
+ }
+
+ m_deathstar = m_object_loader.loadObjectFromFile("deathstar.obj");
+ if (!m_deathstar) {
+ cerr << "Unable to load deathstar\n" << m_object_loader.getReason() << endl;
+ exit(123);
+ }
+
+ m_acceleration_cannon =
+ m_object_loader.loadObjectFromFile("acceleration_cannon.obj");
+ if (!m_acceleration_cannon) {
+ cerr << "Unable to load acceleration cannon\n"
+ << m_object_loader.getReason() << endl;
+ exit(123);
+ }
+
+ AIShip::setModel(m_other_ship, ship_med, ship_low);
+
+ float xstart = 0.5 * (-FAR_DISTANCE_END / 5.0f);
+ float xend = 0.5 * (-xstart);
+ float ystart = 0.3 * (FAR_DISTANCE_END / 3.0f - FAR_DISTANCE_END / 2);
+ float yend = 0.3 * (ystart + 2 * (FAR_DISTANCE_END / 5.0f));
+ /* Add the points for the sun */
+ m_star.add(GloxPointNormalTexture(
+ GloxPoint<>(xstart, ystart, -(FAR_DISTANCE_END) / 3),
+ GloxNormal<>(0, 0, 0), GloxPoint<>(0, 0)));
+ m_star.add(
+ GloxPointNormalTexture(GloxPoint<>(xend, ystart, -(FAR_DISTANCE_END) / 3),
+ GloxNormal<>(0, 0, 0), GloxPoint<>(1, 0)));
+ m_star.add(
+ GloxPointNormalTexture(GloxPoint<>(xend, yend, -(FAR_DISTANCE_END) / 3),
+ GloxNormal<>(0, 0, 0), GloxPoint<>(1, 1)));
+ m_star.add(
+ GloxPointNormalTexture(GloxPoint<>(xstart, yend, -(FAR_DISTANCE_END) / 3),
+ GloxNormal<>(0, 0, 0), GloxPoint<>(0, 1)));
+
+ /* Move the light souce to the sun */
+ GloxLightSource* source = m_light_manager.getLightSource(0);
+ source->setPosition(GloxPointf(0, 200, -695));
+
+ m_quit = false;
+
+ /* Starting ships */
+ for (int i = 0; i < 5; ++i) {
+ AIShip::Updater* updater =
+ new EllipseUpdater(GloxPointf(0, -10, 0), GloxPointf(0, 10, 10),
+ GloxPointf(10, i * 5, 0), 0.01);
+ m_updaters.push_back(updater);
+ AIShip tmp(updater);
+ tmp.setTimeOffset(1000 * i);
+ m_aiships.push_back(tmp);
+ }
+
+ /* Frigate ships */
+ for (int j = 0; j < 360; j += 72) {
+ for (int i = 0; i < 10; ++i) {
+ float pos = 10000 + 100 * i;
+ GloxPointf center(pos, pos, pos);
+ float cos = GloxCos(j);
+ float sin = GloxSin(j);
+ AIShip::Updater* updater =
+ new EllipseUpdater(center, GloxPointf(60 * cos, -100 * sin, 2),
+ GloxPointf(50 * cos, 10 * sin, 50) * 2, 0.002);
+ m_updaters.push_back(updater);
+ AIShip tmp(updater);
+ tmp.setTimeOffset(100000 * i);
+ m_aiships.push_back(tmp);
}
-
- m_other_ship = m_object_loader.loadObjectFromFile( "ship.obj" );
- SloxModelObject* ship_med = m_object_loader.loadObjectFromFile( "ship_med.obj" ) ;
- SloxModelObject* ship_low = m_object_loader.loadObjectFromFile( "ship_low.obj" ) ;
- if( ! (m_other_ship && ship_med && ship_low) ) {
- cerr << "Unable to load other ship\n" << m_object_loader.getReason() << endl;
- exit( 123 );
- }
-
- m_test_cube = m_object_loader.loadObjectFromFile( "cube.obj" );
- if( ! m_test_cube ) {
- cerr << "Unable to load test cube\n" << m_object_loader.getReason() << endl;
- exit( 123 );
+ }
+
+ /* Deathstar ships */
+ for (int j = 0; j < 360; j += 72) {
+ for (int i = 0; i < 10; ++i) {
+ float pos = 100 * i;
+ GloxPointf center(5000 + pos, -1000 + pos, -20000 + pos);
+ float cos = GloxCos(j);
+ float sin = GloxSin(j);
+ AIShip::Updater* updater =
+ new EllipseUpdater(center, GloxPointf(60 * cos, -70 * sin, 2),
+ GloxPointf(50 * cos, 10 * sin, 40) * 2, 0.002);
+ m_updaters.push_back(updater);
+ AIShip tmp(updater);
+ tmp.setTimeOffset(10000 * i);
+ m_aiships.push_back(tmp);
}
-
- m_deathstar = m_object_loader.loadObjectFromFile( "deathstar.obj" ) ;
- if( ! m_deathstar ) {
- cerr << "Unable to load deathstar\n" << m_object_loader.getReason() << endl;
- exit( 123 );
- }
-
- m_acceleration_cannon = m_object_loader.loadObjectFromFile( "acceleration_cannon.obj" ) ;
- if( ! m_acceleration_cannon ) {
- cerr << "Unable to load acceleration cannon\n" << m_object_loader.getReason() << endl;
- exit( 123 );
- }
-
- AIShip::setModel( m_other_ship, ship_med, ship_low ) ;
-
- float xstart = 0.5*(- FAR_DISTANCE_END / 5.0f);
- float xend = 0.5*(- xstart);
- float ystart = 0.3*(FAR_DISTANCE_END / 3.0f - FAR_DISTANCE_END / 2);
- float yend = 0.3*(ystart + 2*(FAR_DISTANCE_END / 5.0f));
- /* Add the points for the sun */
- m_star.add( GloxPointNormalTexture(
- GloxPoint<>( xstart, ystart, -(FAR_DISTANCE_END) / 3 ), GloxNormal<>(0,0,0), GloxPoint<>( 0,0 ) ) );
- m_star.add( GloxPointNormalTexture(
- GloxPoint<>( xend, ystart, -(FAR_DISTANCE_END) / 3 ), GloxNormal<>(0,0,0), GloxPoint<>( 1,0 ) ) );
- m_star.add( GloxPointNormalTexture(
- GloxPoint<>( xend, yend, -(FAR_DISTANCE_END) / 3 ), GloxNormal<>(0,0,0), GloxPoint<>( 1,1 ) ) );
- m_star.add( GloxPointNormalTexture(
- GloxPoint<>( xstart, yend, -(FAR_DISTANCE_END) / 3 ), GloxNormal<>(0,0,0), GloxPoint<>( 0,1 ) ) );
-
- /* Move the light souce to the sun */
- GloxLightSource* source = m_light_manager.getLightSource( 0 );
- source->setPosition( GloxPointf( 0, 200, -695 ) );
-
- m_quit = false;
-
- /* Starting ships */
- for( int i = 0; i < 5; ++ i ) {
- AIShip::Updater* updater = new EllipseUpdater( GloxPointf(0,-10,0), GloxPointf(0,10,10), GloxPointf(10,i*5,0), 0.01 );
- m_updaters.push_back( updater );
- AIShip tmp( updater );
- tmp.setTimeOffset( 1000 * i ) ;
- m_aiships.push_back( tmp ) ;
- }
-
- /* Frigate ships */
- for ( int j = 0; j < 360; j += 72 ) {
- for( int i = 0; i < 10; ++ i ) {
- float pos = 10000 + 100 * i;
- GloxPointf center( pos, pos, pos );
- float cos = GloxCos(j) ;
- float sin = GloxSin(j) ;
- AIShip::Updater* updater =
- new EllipseUpdater( center, GloxPointf(60*cos,-100*sin,2) , GloxPointf(50*cos,10*sin,50) * 2, 0.002 );
- m_updaters.push_back( updater );
- AIShip tmp( updater );
- tmp.setTimeOffset( 100000 * i ) ;
- m_aiships.push_back( tmp ) ;
- }
- }
-
- /* Deathstar ships */
- for ( int j = 0; j < 360; j += 72 ) {
- for( int i = 0; i < 10; ++ i ) {
- float pos = 100 * i;
- GloxPointf center( 5000 + pos, -1000+pos, -20000+pos );
- float cos = GloxCos(j) ;
- float sin = GloxSin(j) ;
- AIShip::Updater* updater =
- new EllipseUpdater( center, GloxPointf(60*cos,-70*sin,2) , GloxPointf(50*cos,10*sin,40) * 2, 0.002 );
- m_updaters.push_back( updater );
- AIShip tmp( updater );
- tmp.setTimeOffset( 10000 * i ) ;
- m_aiships.push_back( tmp ) ;
- }
- }
-
- m_earth_prog = new GloxProgram() ;
-
-
- printf( "Using GLSL version %s\n", glGetString( GL_SHADING_LANGUAGE_VERSION ) );
-
- const char* earth_frag_shader = "shaders/earth.fp";
- float version = atof( (const char*) glGetString( GL_SHADING_LANGUAGE_VERSION ) );
- if( version < 1.29 ) {
- fprintf( stderr, "Using version %02f, unfortunately, I must use the fallback shader\n", version );
- earth_frag_shader = "shaders/earth_fallback.fp";
- }
-
- if( m_earth_prog->attachShaderFromFile( "shaders/earth.vp", GL_VERTEX_SHADER ) ||
- m_earth_prog->attachShaderFromFile( earth_frag_shader, GL_FRAGMENT_SHADER ) ||
- m_earth_prog->link() ) {
- cerr << "Warning Unable to load shaders: " <<
- GloxShader::getMessage() << endl;
- }
- m_earth_shader_light_pos = m_earth_prog->getUniformLocation( "lightPos" );
- m_earth_shader_camera_pos = m_earth_prog->getUniformLocation( "cameraPos" );
- m_earth_shader_time = m_earth_prog->getUniformLocation( "time" ) ;
-
- // cout << "Earth light " << m_earth_shader_light_pos << endl;
- // cout << "Earth camera " << m_earth_shader_camera_pos << endl;
-
- m_moon_prog = new GloxProgram() ;
- if( m_moon_prog->attachShaderFromFile( "shaders/moon.vp", GL_VERTEX_SHADER ) ||
- m_moon_prog->attachShaderFromFile( "shaders/moon.fp", GL_FRAGMENT_SHADER ) ||
- m_moon_prog->link() ) {
- cerr << "Warning Unable to load shaders: " <<
- GloxShader::getMessage() << endl;
- }
- m_moon_shader_light_pos = m_moon_prog->getUniformLocation( "lightPos" );
- m_moon_shader_camera_pos = m_moon_prog->getUniformLocation( "cameraPos" );
-
-
- // start the starting light
- GloxLightSource* start = m_light_manager.getLightSource( 0 );
- start->setLightModelAttribute( GL_LIGHT_MODEL_AMBIENT, GloxColor(50,50,50) );
- start->setAmbient ( GloxColor(30,30,30) );
- start->setDiffuse ( GloxColor(255,0,0) );
- start->setPosition( GloxPoint<>( 0,0,0 ) );
-
- start->setEnabled( false );
-
- glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.5);
-
- return true;
+ }
+
+ m_earth_prog = new GloxProgram();
+
+ printf("Using GLSL version %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
+
+ const char* earth_frag_shader = "shaders/earth.fp";
+ float version = atof((const char*)glGetString(GL_SHADING_LANGUAGE_VERSION));
+ if (version < 1.29) {
+ fprintf(
+ stderr,
+ "Using version %02f, unfortunately, I must use the fallback shader\n",
+ version);
+ earth_frag_shader = "shaders/earth_fallback.fp";
+ }
+
+ if (m_earth_prog->attachShaderFromFile("shaders/earth.vp",
+ GL_VERTEX_SHADER) ||
+ m_earth_prog->attachShaderFromFile(earth_frag_shader,
+ GL_FRAGMENT_SHADER) ||
+ m_earth_prog->link()) {
+ cerr << "Warning Unable to load shaders: " << GloxShader::getMessage()
+ << endl;
+ }
+ m_earth_shader_light_pos = m_earth_prog->getUniformLocation("lightPos");
+ m_earth_shader_camera_pos = m_earth_prog->getUniformLocation("cameraPos");
+ m_earth_shader_time = m_earth_prog->getUniformLocation("time");
+
+ // cout << "Earth light " << m_earth_shader_light_pos << endl;
+ // cout << "Earth camera " << m_earth_shader_camera_pos << endl;
+
+ m_moon_prog = new GloxProgram();
+ if (m_moon_prog->attachShaderFromFile("shaders/moon.vp", GL_VERTEX_SHADER) ||
+ m_moon_prog->attachShaderFromFile("shaders/moon.fp",
+ GL_FRAGMENT_SHADER) ||
+ m_moon_prog->link()) {
+ cerr << "Warning Unable to load shaders: " << GloxShader::getMessage()
+ << endl;
+ }
+ m_moon_shader_light_pos = m_moon_prog->getUniformLocation("lightPos");
+ m_moon_shader_camera_pos = m_moon_prog->getUniformLocation("cameraPos");
+
+ // start the starting light
+ GloxLightSource* start = m_light_manager.getLightSource(0);
+ start->setLightModelAttribute(GL_LIGHT_MODEL_AMBIENT, GloxColor(50, 50, 50));
+ start->setAmbient(GloxColor(30, 30, 30));
+ start->setDiffuse(GloxColor(255, 0, 0));
+ start->setPosition(GloxPoint<>(0, 0, 0));
+
+ start->setEnabled(false);
+
+ glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.5);
+
+ return true;
}
diff --git a/sons_of_sol/private_db/ControlMultiplexer.cpp b/sons_of_sol/private_db/ControlMultiplexer.cpp
index 97ae2f4..aee9672 100644
--- a/sons_of_sol/private_db/ControlMultiplexer.cpp
+++ b/sons_of_sol/private_db/ControlMultiplexer.cpp
@@ -1,58 +1,61 @@
#include "sons_of_sol/ControlMultiplexer.hpp"
-ControlMultiplexer::ControlMultiplexer() {
-
-}
+ControlMultiplexer::ControlMultiplexer() {}
-void ControlMultiplexer::onKeyUp( const SDL_KeyboardEvent& evt ) {
- std::map< SDLKey, M_MapVal >::iterator itr;
- itr = m_keysym_map.find( evt.keysym.sym );
+void ControlMultiplexer::onKeyUp(const SDL_KeyboardEvent& evt) {
+ std::map<SDLKey, M_MapVal>::iterator itr;
+ itr = m_keysym_map.find(evt.keysym.sym);
- if( itr != m_keysym_map.end() ) {
- ControlMotionEvent event( (*itr).second.type, 0, ControlMotionEvent::BUTTON );
- fireControlEvent( event );
- }
+ if (itr != m_keysym_map.end()) {
+ ControlMotionEvent event((*itr).second.type, 0, ControlMotionEvent::BUTTON);
+ fireControlEvent(event);
+ }
}
-void ControlMultiplexer::onKeyDown( const SDL_KeyboardEvent& evt ) {
- std::map< SDLKey, M_MapVal >::iterator itr;
- itr = m_keysym_map.find( evt.keysym.sym );
+void ControlMultiplexer::onKeyDown(const SDL_KeyboardEvent& evt) {
+ std::map<SDLKey, M_MapVal>::iterator itr;
+ itr = m_keysym_map.find(evt.keysym.sym);
- if( itr != m_keysym_map.end() ) {
- ControlMotionEvent event( (*itr).second.type, 1 * (*itr).second.multiplier, ControlMotionEvent::BUTTON );
- fireControlEvent( event );
- }
+ if (itr != m_keysym_map.end()) {
+ ControlMotionEvent event((*itr).second.type, 1 * (*itr).second.multiplier,
+ ControlMotionEvent::BUTTON);
+ fireControlEvent(event);
+ }
}
-void ControlMultiplexer::onMouseMoved( const SDL_MouseMotionEvent& evt ) {
- std::map< uint16_t, M_MapVal >::iterator itr;
- /* x direction on mousepad */
- itr = m_joy_axis_map.find( 0xFF00 );
- const SDL_VideoInfo* info = SDL_GetVideoInfo(); //<-- calls SDL_GetVideoInfo();
- int screen_width = info->current_w;
- int screen_height = info->current_h;
-
- float x_norm = (evt.x - screen_width / 2) / ((float) screen_width / 2.0);
- if( itr != m_joy_axis_map.end() ) {
- ControlMotionEvent event( itr->second.type, x_norm * (*itr).second.multiplier,
- ControlMotionEvent::MOUSE );
- fireControlEvent( event );
- }
-
- /* y direction */
- float y_norm = (evt.y - screen_height / 2) / ((float) screen_height / 2.0);
- itr = m_joy_axis_map.find( 0xFF01 );
- if( itr != m_joy_axis_map.end() ) {
- ControlMotionEvent event( itr->second.type, y_norm * (*itr).second.multiplier,
- ControlMotionEvent::MOUSE );
- fireControlEvent( event );
- }
+void ControlMultiplexer::onMouseMoved(const SDL_MouseMotionEvent& evt) {
+ std::map<uint16_t, M_MapVal>::iterator itr;
+ /* x direction on mousepad */
+ itr = m_joy_axis_map.find(0xFF00);
+ const SDL_VideoInfo* info =
+ SDL_GetVideoInfo(); //<-- calls SDL_GetVideoInfo();
+ int screen_width = info->current_w;
+ int screen_height = info->current_h;
+
+ float x_norm = (evt.x - screen_width / 2) / ((float)screen_width / 2.0);
+ if (itr != m_joy_axis_map.end()) {
+ ControlMotionEvent event(itr->second.type,
+ x_norm * (*itr).second.multiplier,
+ ControlMotionEvent::MOUSE);
+ fireControlEvent(event);
+ }
+
+ /* y direction */
+ float y_norm = (evt.y - screen_height / 2) / ((float)screen_height / 2.0);
+ itr = m_joy_axis_map.find(0xFF01);
+ if (itr != m_joy_axis_map.end()) {
+ ControlMotionEvent event(itr->second.type,
+ y_norm * (*itr).second.multiplier,
+ ControlMotionEvent::MOUSE);
+ fireControlEvent(event);
+ }
}
-void ControlMultiplexer::fireControlEvent( const ControlMotionEvent& evt ) {
- std::vector< ControlMotionListener* >::iterator itr;
+void ControlMultiplexer::fireControlEvent(const ControlMotionEvent& evt) {
+ std::vector<ControlMotionListener*>::iterator itr;
- for( itr = m_motion_listeners.begin(); itr != m_motion_listeners.end() ; ++ itr ) {
- (*itr)->onControlMotion( evt );
- }
+ for (itr = m_motion_listeners.begin(); itr != m_motion_listeners.end();
+ ++itr) {
+ (*itr)->onControlMotion(evt);
+ }
}
diff --git a/sons_of_sol/private_db/PlayerShip.cpp b/sons_of_sol/private_db/PlayerShip.cpp
index 14eff74..6e2fb23 100644
--- a/sons_of_sol/private_db/PlayerShip.cpp
+++ b/sons_of_sol/private_db/PlayerShip.cpp
@@ -1,161 +1,160 @@
#include "sons_of_sol/PlayerShip.hpp"
-#include "glox/GloxCommon.hpp"
#include "glox/GloxColor.hpp"
+#include "glox/GloxCommon.hpp"
using namespace glox;
using namespace std;
-
-float randomJitter( float jitter ) {
- return (( rand() % 2000 - 1000 ) / 1000.0) * jitter ;
+float randomJitter(float jitter) {
+ return ((rand() % 2000 - 1000) / 1000.0) * jitter;
}
-void PlayerShip::pitch( float angle ) {
- /* Update the forward vector */
- m_forward *= (float)GloxCos( angle );
- m_forward += ( m_up * (float)GloxSin( angle ) );
- m_forward.normalize();
+void PlayerShip::pitch(float angle) {
+ /* Update the forward vector */
+ m_forward *= (float)GloxCos(angle);
+ m_forward += (m_up * (float)GloxSin(angle));
+ m_forward.normalize();
- m_up = m_right.cross( m_forward );
+ m_up = m_right.cross(m_forward);
}
-void PlayerShip::roll( float angle ) {
- m_right *= (float)GloxCos( angle );
- m_right += m_up * GloxSin( angle );
- m_right.normalize();
+void PlayerShip::roll(float angle) {
+ m_right *= (float)GloxCos(angle);
+ m_right += m_up * GloxSin(angle);
+ m_right.normalize();
- m_up = m_right.cross( m_forward );
+ m_up = m_right.cross(m_forward);
}
-void PlayerShip::yaw( float angle ) {
- m_right *= (float)GloxCos( angle );
- m_right += m_forward * GloxSin( angle );
- m_right.normalize();
+void PlayerShip::yaw(float angle) {
+ m_right *= (float)GloxCos(angle);
+ m_right += m_forward * GloxSin(angle);
+ m_right.normalize();
- m_forward = m_up.cross( m_right );
+ m_forward = m_up.cross(m_right);
}
-void PlayerShip::renderPerspective( ) {
+void PlayerShip::renderPerspective() {
- GloxPoint<> noise( randomJitter( m_jitter ), randomJitter( m_jitter ), randomJitter( m_jitter ) ) ;
- if( m_is_firing ) {
- noise += GloxPointf( randomJitter(0.01),randomJitter(0.01),randomJitter(0.01) );
- }
- m_perspective.setLookAtPoint( m_position + m_forward.toPoint() + noise );
- m_perspective.setPosition( m_position + (m_forward.toPoint() * 0.2f) );
- m_perspective.setUpVector( m_up.toPoint() );
-
- GloxColor( 255,255,255 ).render();
- GloxWith( GL_LINES,
- GloxPoint<>( 0,0,0 ).plot();
- m_position.plot() );
-}
-
-void PlayerShip::drawHUD() {
+ GloxPoint<> noise(randomJitter(m_jitter), randomJitter(m_jitter),
+ randomJitter(m_jitter));
+ if (m_is_firing) {
+ noise +=
+ GloxPointf(randomJitter(0.01), randomJitter(0.01), randomJitter(0.01));
+ }
+ m_perspective.setLookAtPoint(m_position + m_forward.toPoint() + noise);
+ m_perspective.setPosition(m_position + (m_forward.toPoint() * 0.2f));
+ m_perspective.setUpVector(m_up.toPoint());
+ GloxColor(255, 255, 255).render();
+ GloxWith(GL_LINES, GloxPoint<>(0, 0, 0).plot(); m_position.plot());
}
-static inline float update_val( float to, float x, int inertia ) {
- return ( to + (inertia - 1) * x ) / inertia;
+void PlayerShip::drawHUD() {}
+
+static inline float update_val(float to, float x, int inertia) {
+ return (to + (inertia - 1) * x) / inertia;
}
-void PlayerShip::onControlMotion( const ControlMotionEvent& evt ) {
- //printf( "Event Mag: %f\n", evt.getMagnitude() );
+void PlayerShip::onControlMotion(const ControlMotionEvent& evt) {
+ //printf( "Event Mag: %f\n", evt.getMagnitude() );
- if( evt.getType() == ControlMotionEvent::PITCH ) {
- m_dpitch = update_val( evt.getMagnitude(), m_dpitch, 10 );
- }
+ if (evt.getType() == ControlMotionEvent::PITCH) {
+ m_dpitch = update_val(evt.getMagnitude(), m_dpitch, 10);
+ }
- else if( evt.getType() == ControlMotionEvent::THROTTLE ) {
- m_dforward_to = evt.getMagnitude();
- }
+ else if (evt.getType() == ControlMotionEvent::THROTTLE) {
+ m_dforward_to = evt.getMagnitude();
+ }
- else if( evt.getType() == ControlMotionEvent::YAW ) {
- m_dyaw = update_val( evt.getMagnitude(), m_dyaw, 10 );
- }
+ else if (evt.getType() == ControlMotionEvent::YAW) {
+ m_dyaw = update_val(evt.getMagnitude(), m_dyaw, 10);
+ }
- else if( evt.getType() == ControlMotionEvent::ROLL ) {
- m_droll_to = evt.getMagnitude();
- }
+ else if (evt.getType() == ControlMotionEvent::ROLL) {
+ m_droll_to = evt.getMagnitude();
+ }
- else if( evt.getType() == ControlMotionEvent::STRAFE_SIDE ) {
- m_dright_to = evt.getMagnitude();
- }
+ else if (evt.getType() == ControlMotionEvent::STRAFE_SIDE) {
+ m_dright_to = evt.getMagnitude();
+ }
- else if( evt.getType() == ControlMotionEvent::STRAFE_UP ) {
- m_dup_to = evt.getMagnitude();
- }
+ else if (evt.getType() == ControlMotionEvent::STRAFE_UP) {
+ m_dup_to = evt.getMagnitude();
+ }
- else if( evt.getType() == ControlMotionEvent::FIRE_PRIMARY ) {
- m_is_firing = evt.getMagnitude() != 0 ;
- }
+ else if (evt.getType() == ControlMotionEvent::FIRE_PRIMARY) {
+ m_is_firing = evt.getMagnitude() != 0;
+ }
}
void PlayerShip::update() {
- static const float projectile_speed = 150;
- // printf( "dpitch: %f, droll: %f, dyaw: %f, dforward: %f, dright: %f, dup: %f\n",
- // m_dpitch, m_droll, m_dyaw, m_dforward, m_dright, m_dup );
-
- pitch( m_dpitch );
- roll( m_droll );
- yaw( m_dyaw );
-
- int i = 0;
- for( vector<Projectile>::iterator itr = m_living_projectiles.begin();
- itr != m_living_projectiles.end() ; ++ itr ) {
- if( ! (*itr).isDead() ) {
- (*itr).update();
- if( (*itr).isDead() ) {
- m_open_positions.push( i );
- }
- }
- ++ i;
+ static const float projectile_speed = 150;
+ // printf( "dpitch: %f, droll: %f, dyaw: %f, dforward: %f, dright: %f, dup: %f\n",
+ // m_dpitch, m_droll, m_dyaw, m_dforward, m_dright, m_dup );
+
+ pitch(m_dpitch);
+ roll(m_droll);
+ yaw(m_dyaw);
+
+ int i = 0;
+ for (vector<Projectile>::iterator itr = m_living_projectiles.begin();
+ itr != m_living_projectiles.end(); ++itr) {
+ if (!(*itr).isDead()) {
+ (*itr).update();
+ if ((*itr).isDead()) {
+ m_open_positions.push(i);
+ }
}
-
- m_position += (m_forward * m_dforward).toPoint();
- m_position += (m_right * m_dright).toPoint();
- m_position += (m_up * m_dup).toPoint();
-
- m_droll = update_val( m_droll_to, m_droll, 20 );
- m_dup = update_val( m_dup_to, m_dup, 20 );
- m_dright = update_val( m_dright_to, m_dright, 20 );
-
- float last_dforward = m_dforward ;
- m_dforward = update_val( m_dforward_to, m_dforward, 200 );
-
- float accel = m_dforward - last_dforward ;
- if( accel > 0 ) {
- m_jitter = accel / 40.0 ;
+ ++i;
+ }
+
+ m_position += (m_forward * m_dforward).toPoint();
+ m_position += (m_right * m_dright).toPoint();
+ m_position += (m_up * m_dup).toPoint();
+
+ m_droll = update_val(m_droll_to, m_droll, 20);
+ m_dup = update_val(m_dup_to, m_dup, 20);
+ m_dright = update_val(m_dright_to, m_dright, 20);
+
+ float last_dforward = m_dforward;
+ m_dforward = update_val(m_dforward_to, m_dforward, 200);
+
+ float accel = m_dforward - last_dforward;
+ if (accel > 0) {
+ m_jitter = accel / 40.0;
+ } else {
+ m_jitter = 0.0;
+ }
+
+ // This is only the case if we are using a mouse
+ m_dpitch = update_val(0, m_dpitch, 100);
+ m_dyaw = update_val(0, m_dyaw, 100);
+ // m_droll = (m_droll_to * ( 1 - exp( - m_droll_count ) ) + m_droll * ( 1 - exp( - m_droll_count ) ) )/ 2.0;
+ if (m_is_firing) {
+ GloxPointf spread(randomJitter(0.03), randomJitter(0.03),
+ randomJitter(0.03));
+ Projectile proj((m_position - m_up.toPoint() - m_right.toPoint()),
+ (m_forward.toPoint() + spread) * projectile_speed);
+
+ if (m_open_positions.empty()) {
+ m_living_projectiles.push_back(proj);
} else {
- m_jitter = 0.0 ;
- }
-
- // This is only the case if we are using a mouse
- m_dpitch = update_val( 0, m_dpitch, 100 );
- m_dyaw = update_val( 0, m_dyaw, 100 );
- // m_droll = (m_droll_to * ( 1 - exp( - m_droll_count ) ) + m_droll * ( 1 - exp( - m_droll_count ) ) )/ 2.0;
- if( m_is_firing ) {
- GloxPointf spread( randomJitter(0.03), randomJitter(0.03), randomJitter(0.03) );
- Projectile proj( (m_position - m_up.toPoint() - m_right.toPoint()), (m_forward.toPoint() + spread) * projectile_speed ) ;
-
- if( m_open_positions.empty() ) {
- m_living_projectiles.push_back( proj );
- } else {
- int idx = m_open_positions.front();
- m_open_positions.pop();
- m_living_projectiles[idx] = proj;
- }
+ int idx = m_open_positions.front();
+ m_open_positions.pop();
+ m_living_projectiles[idx] = proj;
}
+ }
- renderPerspective();
+ renderPerspective();
}
void PlayerShip::drawProjectiles() {
- for( vector<Projectile>::iterator itr = m_living_projectiles.begin();
- itr != m_living_projectiles.end() ; ++ itr ) {
- if( ! (*itr).isDead() ) {
- itr->draw();
- }
+ for (vector<Projectile>::iterator itr = m_living_projectiles.begin();
+ itr != m_living_projectiles.end(); ++itr) {
+ if (!(*itr).isDead()) {
+ itr->draw();
}
+ }
}
diff --git a/sons_of_sol/private_db/Projectile.cpp b/sons_of_sol/private_db/Projectile.cpp
index 7819a0c..339c1de 100644
--- a/sons_of_sol/private_db/Projectile.cpp
+++ b/sons_of_sol/private_db/Projectile.cpp
@@ -2,72 +2,70 @@
#include "glox/GloxColor.hpp"
#include "glox/GloxScopedRotation.hpp"
-using namespace glox ;
-using namespace std ;
+using namespace glox;
+using namespace std;
GloxCube* Projectile::m_model;
-void Projectile::loadModel( ) {
- if( ! m_model ) {
- m_model = new GloxCube( 10, 0.1, 0.1, GloxColor( 255, 255, 0 ) );
- }
+void Projectile::loadModel() {
+ if (!m_model) {
+ m_model = new GloxCube(10, 0.1, 0.1, GloxColor(255, 255, 0));
+ }
}
inline float jitter() {
- return (2 * rand() & 0xFF) / 256.0 ;
+ return (2 * rand() & 0xFF) / 256.0;
}
void Projectile::draw() {
- GloxPoint<> next = m_position + (m_dpos) * 0.2 + GloxPointf(jitter(),jitter(),jitter());
- GloxScopedAttributes __glsa( GL_CURRENT_BIT );
+ GloxPoint<> next =
+ m_position + (m_dpos) * 0.2 + GloxPointf(jitter(), jitter(), jitter());
+ GloxScopedAttributes __glsa(GL_CURRENT_BIT);
- GloxColor(
- (uint8_t)(255.0f / TTL * m_ttl ),
- (uint8_t)(250.0f / pow(TTL,2) * pow(m_ttl,2)),
- (uint8_t)(200.0f / pow(TTL,4) * pow(m_ttl,4)),
- (uint8_t)(100.0)
- ).render();
+ GloxColor((uint8_t)(255.0f / TTL * m_ttl),
+ (uint8_t)(250.0f / pow(TTL, 2) * pow(m_ttl, 2)),
+ (uint8_t)(200.0f / pow(TTL, 4) * pow(m_ttl, 4)), (uint8_t)(100.0))
+ .render();
- glLineWidth( m_ttl / 10.0f );
- GloxWith( GL_LINES,
- m_position.plot();
- GloxColor(
- (uint8_t)(255.0f / TTL * (m_ttl-1) ),
- (uint8_t)(200.0f / pow(TTL,2) * pow(m_ttl-1,2)),
- (uint8_t)(100.0f / pow(TTL,4) * pow(m_ttl-1,4))).render();
- next.plot();
- );
+ glLineWidth(m_ttl / 10.0f);
+ GloxWith(GL_LINES, m_position.plot();
+ GloxColor((uint8_t)(255.0f / TTL * (m_ttl - 1)),
+ (uint8_t)(200.0f / pow(TTL, 2) * pow(m_ttl - 1, 2)),
+ (uint8_t)(100.0f / pow(TTL, 4) * pow(m_ttl - 1, 4)))
+ .render();
+ next.plot(););
}
-Projectile::Projectile( const glox::GloxPoint<>& position, const glox::GloxPoint<>& vec ) {
- m_position = position;
- m_dpos = vec ;
- m_ttl = TTL;
+Projectile::Projectile(const glox::GloxPoint<>& position,
+ const glox::GloxPoint<>& vec) {
+ m_position = position;
+ m_dpos = vec;
+ m_ttl = TTL;
- loadModel();
+ loadModel();
- /* Project the point onto the x,y plane */
- GloxPoint<> first( m_dpos.getX(), m_dpos.getY(), 0 );
- /* A point that represents the x axis */
- GloxPoint<> xaxis( 1, 0, 0 );
+ /* Project the point onto the x,y plane */
+ GloxPoint<> first(m_dpos.getX(), m_dpos.getY(), 0);
+ /* A point that represents the x axis */
+ GloxPoint<> xaxis(1, 0, 0);
- /* Rotation around the z axis */
- float dot = first.dot( xaxis ) ;
- float rot = GloxToDegrees(acos( dot )) ;
+ /* Rotation around the z axis */
+ float dot = first.dot(xaxis);
+ float rot = GloxToDegrees(acos(dot));
- if( first.getY() < 0 ) {
- rot = - rot;
- }
- rot = rot + 180 ;
- m_roty = rot;
- /* x axis now follows *first* vector */
- /* Rotate around y axis to get x to follow *dpos* vector */
- dot = first.dot( m_dpos );
- rot = acos( dot );
- rot = GloxToDegrees( rot );
+ if (first.getY() < 0) {
+ rot = -rot;
+ }
+ rot = rot + 180;
+ m_roty = rot;
+ /* x axis now follows *first* vector */
+ /* Rotate around y axis to get x to follow *dpos* vector */
+ dot = first.dot(m_dpos);
+ rot = acos(dot);
+ rot = GloxToDegrees(rot);
- if( m_dpos.getZ() < 0 ) {
- rot = - rot;
- }
- m_rotz = rot;
+ if (m_dpos.getZ() < 0) {
+ rot = -rot;
+ }
+ m_rotz = rot;
}
diff --git a/sons_of_sol/private_db/SonsOfSolApplication.cpp b/sons_of_sol/private_db/SonsOfSolApplication.cpp
index 59f7e62..bd93015 100644
--- a/sons_of_sol/private_db/SonsOfSolApplication.cpp
+++ b/sons_of_sol/private_db/SonsOfSolApplication.cpp
@@ -11,136 +11,132 @@ using namespace glox;
using namespace std;
void SonsOfSolApplication::setupControls() {
- m_event_multiplexer.setKeyMapping( SDLK_w, ControlMotionEvent::THROTTLE, 30.0f );
- m_event_multiplexer.setKeyMapping( SDLK_s, ControlMotionEvent::THROTTLE, -20.0f );
- m_event_multiplexer.setKeyMapping( SDLK_d, ControlMotionEvent::STRAFE_SIDE );
- m_event_multiplexer.setKeyMapping( SDLK_a, ControlMotionEvent::STRAFE_SIDE, -1.0f );
- m_event_multiplexer.setKeyMapping( SDLK_z, ControlMotionEvent::STRAFE_UP, -1.0f );
- m_event_multiplexer.setKeyMapping( SDLK_x, ControlMotionEvent::STRAFE_UP, 0.3f );
-
- m_event_multiplexer.setKeyMapping( SDLK_q, ControlMotionEvent::ROLL, 5.0f );
- m_event_multiplexer.setKeyMapping( SDLK_e, ControlMotionEvent::ROLL, -5.0f );
- m_event_multiplexer.setKeyMapping( SDLK_k, ControlMotionEvent::PITCH );
- m_event_multiplexer.setKeyMapping( SDLK_j, ControlMotionEvent::PITCH, -1.0f );
- m_event_multiplexer.setKeyMapping( SDLK_l, ControlMotionEvent::YAW, -1.0f );
- m_event_multiplexer.setKeyMapping( SDLK_h, ControlMotionEvent::YAW );
-
- m_event_multiplexer.setKeyMapping( SDLK_SPACE, ControlMotionEvent::FIRE_PRIMARY );
- m_event_multiplexer.setKeyMapping( SDLK_LSHIFT, ControlMotionEvent::FIRE_PRIMARY );
-
- m_event_multiplexer.setJoyAxisMapping( 255, 0, ControlMotionEvent::YAW, -3.0f );
- m_event_multiplexer.setJoyAxisMapping( 255, 1, ControlMotionEvent::PITCH, -3.0f );
+ m_event_multiplexer.setKeyMapping(SDLK_w, ControlMotionEvent::THROTTLE,
+ 30.0f);
+ m_event_multiplexer.setKeyMapping(SDLK_s, ControlMotionEvent::THROTTLE,
+ -20.0f);
+ m_event_multiplexer.setKeyMapping(SDLK_d, ControlMotionEvent::STRAFE_SIDE);
+ m_event_multiplexer.setKeyMapping(SDLK_a, ControlMotionEvent::STRAFE_SIDE,
+ -1.0f);
+ m_event_multiplexer.setKeyMapping(SDLK_z, ControlMotionEvent::STRAFE_UP,
+ -1.0f);
+ m_event_multiplexer.setKeyMapping(SDLK_x, ControlMotionEvent::STRAFE_UP,
+ 0.3f);
+
+ m_event_multiplexer.setKeyMapping(SDLK_q, ControlMotionEvent::ROLL, 5.0f);
+ m_event_multiplexer.setKeyMapping(SDLK_e, ControlMotionEvent::ROLL, -5.0f);
+ m_event_multiplexer.setKeyMapping(SDLK_k, ControlMotionEvent::PITCH);
+ m_event_multiplexer.setKeyMapping(SDLK_j, ControlMotionEvent::PITCH, -1.0f);
+ m_event_multiplexer.setKeyMapping(SDLK_l, ControlMotionEvent::YAW, -1.0f);
+ m_event_multiplexer.setKeyMapping(SDLK_h, ControlMotionEvent::YAW);
+
+ m_event_multiplexer.setKeyMapping(SDLK_SPACE,
+ ControlMotionEvent::FIRE_PRIMARY);
+ m_event_multiplexer.setKeyMapping(SDLK_LSHIFT,
+ ControlMotionEvent::FIRE_PRIMARY);
+
+ m_event_multiplexer.setJoyAxisMapping(255, 0, ControlMotionEvent::YAW, -3.0f);
+ m_event_multiplexer.setJoyAxisMapping(255, 1, ControlMotionEvent::PITCH,
+ -3.0f);
}
void SonsOfSolApplication::setFullScreen() {
- m_screen = SDL_SetVideoMode(m_screen_width,m_screen_height,0,
- SDL_OPENGL|SDL_RESIZABLE|SDL_DOUBLEBUF|SDL_FULLSCREEN);
- reshape( m_screen_width, m_screen_height );
+ m_screen = SDL_SetVideoMode(
+ m_screen_width, m_screen_height, 0,
+ SDL_OPENGL | SDL_RESIZABLE | SDL_DOUBLEBUF | SDL_FULLSCREEN);
+ reshape(m_screen_width, m_screen_height);
}
void SonsOfSolApplication::pause() {
- if( m_is_paused ) {
- SDL_ShowCursor( 0 ) ;
- SDL_WM_GrabInput(SDL_GRAB_ON);
- } else {
- SDL_ShowCursor( 1 ) ;
- SDL_WM_GrabInput(SDL_GRAB_OFF);
- }
- m_is_paused = ! m_is_paused ;
+ if (m_is_paused) {
+ SDL_ShowCursor(0);
+ SDL_WM_GrabInput(SDL_GRAB_ON);
+ } else {
+ SDL_ShowCursor(1);
+ SDL_WM_GrabInput(SDL_GRAB_OFF);
+ }
+ m_is_paused = !m_is_paused;
}
-
#define NTEX 6
bool SonsOfSolApplication::loadTextures() {
- const char* files[NTEX] = {
- "stars.jpg",
- "leaf.jpg",
- "crate.jpg",
- "star.jpg",
- "earth.jpg",
- "moon.jpg"
- };
-
- GloxTexture* textures[NTEX] = {
- &m_sky_tex,
- &m_leaf_tex,
- &m_crate_tex,
- &m_star_tex,
- &m_earth_tex,
- &m_moon_tex
- };
-
- unsigned int tex = 0;
-
- m_texture_factory.addToPath( "objects/textures/" );
- m_texture_factory.addToPath( "objects/" );
- for ( int i = 0; i < NTEX; ++ i ) {
- if( m_texture_factory.readImageFile( files[i], &tex ) ) {
- /* Either there was a warning or an error, print out
+ const char* files[NTEX] = {"stars.jpg", "leaf.jpg", "crate.jpg",
+ "star.jpg", "earth.jpg", "moon.jpg"};
+
+ GloxTexture* textures[NTEX] = {&m_sky_tex, &m_leaf_tex, &m_crate_tex,
+ &m_star_tex, &m_earth_tex, &m_moon_tex};
+
+ unsigned int tex = 0;
+
+ m_texture_factory.addToPath("objects/textures/");
+ m_texture_factory.addToPath("objects/");
+ for (int i = 0; i < NTEX; ++i) {
+ if (m_texture_factory.readImageFile(files[i], &tex)) {
+ /* Either there was a warning or an error, print out
* either */
- fprintf( stderr, "Reading %s: %s\n", files[i], m_texture_factory.getMessage().c_str() );
-
- if( tex == 0 ) {
- /* If the texture hasn't changed, its an error, otherwise
+ fprintf(stderr, "Reading %s: %s\n", files[i],
+ m_texture_factory.getMessage().c_str());
+
+ if (tex == 0) {
+ /* If the texture hasn't changed, its an error, otherwise
* it's a warning, so continue */
- this->setError( "Aborting: unable to load texture" );
- return false;
- }
- }
- textures[i]->setId( tex );
- tex = 0;
- }
-
- return true;
+ this->setError("Aborting: unable to load texture");
+ return false;
+ }
+ }
+ textures[i]->setId(tex);
+ tex = 0;
+ }
+
+ return true;
}
void SonsOfSolApplication::enableLighting() {
- /* There is very little ambient light
+ /* There is very little ambient light
* in space */
- // int ambient_coef = 0.5;
- // int diffuse_coef = 100;
- int specular_coef = 0;
-
- GloxLightSource* sun = m_light_manager.getLightSource( 0 );
- GloxLightSource* earth = m_light_manager.getLightSource( 1 );
-
- GloxColor base(2,2,0);
- sun->setLightModelAttribute( GL_LIGHT_MODEL_AMBIENT, GloxColor(100,100,90) );
- sun->setAmbient ( GloxColor( 25, 25, 25 ) );
- sun->setDiffuse ( GloxColor( 255, 235, 200 ) );
- sun->setSpecular( base * specular_coef );
- sun->setLightModelAttribute( GL_LIGHT_MODEL_LOCAL_VIEWER, 1 );
- sun->setEnabled( true );
-
- earth->setLightModelAttribute( GL_LIGHT_MODEL_AMBIENT, GloxColor(0,0,0) );
- earth->setAmbient ( GloxColor(0,0,0) );
- earth->setDiffuse ( GloxColor(130,155,155) );
- earth->setSpecular( base * specular_coef );
- earth->setLightModelAttribute( GL_LIGHT_MODEL_LOCAL_VIEWER, 1 );
- earth->setPosition( GloxPoint<>( 700,-1000,0 ) );
+ // int ambient_coef = 0.5;
+ // int diffuse_coef = 100;
+ int specular_coef = 0;
+
+ GloxLightSource* sun = m_light_manager.getLightSource(0);
+ GloxLightSource* earth = m_light_manager.getLightSource(1);
+
+ GloxColor base(2, 2, 0);
+ sun->setLightModelAttribute(GL_LIGHT_MODEL_AMBIENT, GloxColor(100, 100, 90));
+ sun->setAmbient(GloxColor(25, 25, 25));
+ sun->setDiffuse(GloxColor(255, 235, 200));
+ sun->setSpecular(base * specular_coef);
+ sun->setLightModelAttribute(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
+ sun->setEnabled(true);
+
+ earth->setLightModelAttribute(GL_LIGHT_MODEL_AMBIENT, GloxColor(0, 0, 0));
+ earth->setAmbient(GloxColor(0, 0, 0));
+ earth->setDiffuse(GloxColor(130, 155, 155));
+ earth->setSpecular(base * specular_coef);
+ earth->setLightModelAttribute(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
+ earth->setPosition(GloxPoint<>(700, -1000, 0));
}
-void SonsOfSolApplication::update( uint32_t ticks ) {
- (void) ticks;
- m_ship.update();
+void SonsOfSolApplication::update(uint32_t ticks) {
+ (void)ticks;
+ m_ship.update();
- for( vector<AIShip>::iterator itr = m_aiships.begin() ;
- itr != m_aiships.end() ; ++ itr ) {
- itr->update();
- }
+ for (vector<AIShip>::iterator itr = m_aiships.begin(); itr != m_aiships.end();
+ ++itr) {
+ itr->update();
+ }
}
void SonsOfSolApplication::renderFar() {
- // m_ship.getPerspective().setZNear( FAR_DISTANCE_START );
- // m_ship.getPerspective().setZNear( FAR_DISTANCE_START );
+ // m_ship.getPerspective().setZNear( FAR_DISTANCE_START );
+ // m_ship.getPerspective().setZNear( FAR_DISTANCE_START );
}
+void SonsOfSolApplication::reshape(int width, int height) {
+ m_viewport.setWidth(width);
+ m_viewport.setHeight(height);
-void SonsOfSolApplication::reshape( int width, int height ) {
- m_viewport.setWidth( width );
- m_viewport.setHeight( height );
-
- m_viewport.render();
- m_ship.getPerspective().setAspectRatio( m_viewport.getAspectRatio() );
- m_ship.getPerspective().project();
+ m_viewport.render();
+ m_ship.getPerspective().setAspectRatio(m_viewport.getAspectRatio());
+ m_ship.getPerspective().project();
}