aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Rahm <rahm@google.com>2025-12-23 12:59:23 -0700
committerJosh Rahm <rahm@google.com>2025-12-23 12:59:23 -0700
commit46efbf05fcade8199035f956e20a63ca91fc88fd (patch)
tree9e3f3e297ea66e442e1a11b5ad16ad8ed6fc7fb7
parent306bb687414f54177eb37ab7cd744e491c397c31 (diff)
downloadSonsOfSol-46efbf05fcade8199035f956e20a63ca91fc88fd.tar.gz
SonsOfSol-46efbf05fcade8199035f956e20a63ca91fc88fd.tar.bz2
SonsOfSol-46efbf05fcade8199035f956e20a63ca91fc88fd.zip
Run clang-format and add .clang-format
-rw-r--r--.clang-format83
-rw-r--r--.gitignore2
-rw-r--r--Main.cpp22
-rw-r--r--Makefile58
-rw-r--r--glox/compat/glox/GloxLightSource.hpp135
-rw-r--r--glox/compat/glox/GloxLightSourceManager.hpp28
-rw-r--r--glox/compat/glox/objects/GloxCube.hpp55
-rw-r--r--glox/compat/glox/objects/GloxSphere.hpp6
-rw-r--r--glox/compat/glox/objects/GloxTexturedCube.hpp185
-rw-r--r--glox/compat/glox/objects/GloxTexturedSphere.hpp42
-rw-r--r--glox/compat/glox/objects/examples/GloxCylinder.hpp77
-rw-r--r--glox/glox/GloxColor.hpp165
-rw-r--r--glox/glox/GloxCommon.hpp89
-rw-r--r--glox/glox/GloxDebug.hpp84
-rw-r--r--glox/glox/GloxFirstPersonPerspective.hpp73
-rw-r--r--glox/glox/GloxLookAtPerspective.hpp75
-rw-r--r--glox/glox/GloxNormal.hpp135
-rw-r--r--glox/glox/GloxObject.hpp8
-rw-r--r--glox/glox/GloxPerspective.hpp35
-rw-r--r--glox/glox/GloxPlottable.hpp8
-rw-r--r--glox/glox/GloxPoint.hpp298
-rw-r--r--glox/glox/GloxPointCollection.hpp111
-rw-r--r--glox/glox/GloxPointNormal.hpp77
-rw-r--r--glox/glox/GloxPointNormalTexture.hpp51
-rw-r--r--glox/glox/GloxProgram.hpp96
-rw-r--r--glox/glox/GloxQuadStrip.hpp49
-rw-r--r--glox/glox/GloxRenderable.hpp6
-rw-r--r--glox/glox/GloxRotation.hpp43
-rw-r--r--glox/glox/GloxScopedAttributes.hpp16
-rw-r--r--glox/glox/GloxScopedBegin.hpp12
-rw-r--r--glox/glox/GloxScopedRotation.hpp28
-rw-r--r--glox/glox/GloxScopedTranslation.hpp16
-rw-r--r--glox/glox/GloxShader.hpp40
-rw-r--r--glox/glox/GloxStandardProjection.hpp77
-rw-r--r--glox/glox/GloxState.hpp64
-rw-r--r--glox/glox/GloxTexture.hpp18
-rw-r--r--glox/glox/GloxTextureFactory.hpp28
-rw-r--r--glox/glox/GloxTextureRepeat.hpp61
-rw-r--r--glox/glox/GloxVector3.hpp126
-rw-r--r--glox/glox/GloxVector4.hpp86
-rw-r--r--glox/glox/GloxVectorizable.hpp18
-rw-r--r--glox/glox/GloxViewport.hpp45
-rw-r--r--glox/glox/src/GloxCube.cpp128
-rw-r--r--glox/glox/src/GloxCylinder.cpp74
-rw-r--r--glox/glox/src/GloxFirstPersonPerspective.cpp38
-rw-r--r--glox/glox/src/GloxLightSource.cpp81
-rw-r--r--glox/glox/src/GloxLightSourceManager.cpp49
-rw-r--r--glox/glox/src/GloxProgram.cpp110
-rw-r--r--glox/glox/src/GloxShader.cpp89
-rw-r--r--glox/glox/src/GloxTextureFactory.cpp238
-rw-r--r--glox/glox/src/GloxTexturedCube.cpp248
-rw-r--r--glox/glox/src/GloxTexturedSphere.cpp72
-rw-r--r--slox/slox/SloxApplication.hpp42
-rw-r--r--slox/slox/SloxRawEventHandler.hpp58
-rw-r--r--slox/slox/SloxTextureFactory.hpp36
-rw-r--r--slox/slox/events/SloxFunctionQuitListener.hpp22
-rw-r--r--slox/slox/events/SloxKeyListener.hpp12
-rw-r--r--slox/slox/events/SloxMouseMotionListener.hpp16
-rw-r--r--slox/slox/events/SloxQuitListener.hpp8
-rw-r--r--slox/slox/events/SloxResizeListener.hpp6
-rw-r--r--slox/slox/loader/SloxModelObject.hpp20
-rw-r--r--slox/slox/loader/SloxObjectLoader.hpp97
-rw-r--r--slox/slox/loader/SloxObjectMaterial.hpp121
-rw-r--r--slox/slox/loader/private_db/SloxObjectLoader.cpp452
-rw-r--r--slox/slox/private_db/SloxApplication.cpp43
-rw-r--r--slox/slox/private_db/SloxRawEventHandler.cpp66
-rw-r--r--slox/slox/private_db/SloxTextureFactory.cpp314
-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
82 files changed, 3694 insertions, 3796 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..df2202e
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,83 @@
+# Google C/C++ Code Style settings
+# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
+# Author: Kehan Xue, kehan.xue (at) gmail.com
+
+Language: Cpp
+BasedOnStyle: Google
+AccessModifierOffset: -1
+AlignAfterOpenBracket: Align
+AlignConsecutiveAssignments: None
+AlignOperands: Align
+AllowAllArgumentsOnNextLine: true
+AllowAllConstructorInitializersOnNextLine: true
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortBlocksOnASingleLine: Empty
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: Inline
+AllowShortIfStatementsOnASingleLine: Never # To avoid conflict, set this "Never" and each "if statement" should include brace when coding
+AllowShortLambdasOnASingleLine: Inline
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterReturnType: None
+AlwaysBreakTemplateDeclarations: Yes
+BinPackArguments: true
+BreakBeforeBraces: Custom
+BraceWrapping:
+ AfterCaseLabel: false
+ AfterClass: false
+ AfterStruct: false
+ AfterControlStatement: Never
+ AfterEnum: false
+ AfterFunction: false
+ AfterNamespace: false
+ AfterUnion: false
+ AfterExternBlock: false
+ BeforeCatch: false
+ BeforeElse: false
+ BeforeLambdaBody: false
+ IndentBraces: false
+ SplitEmptyFunction: false
+ SplitEmptyRecord: false
+ SplitEmptyNamespace: false
+BreakBeforeBinaryOperators: None
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializers: BeforeColon
+BreakInheritanceList: BeforeColon
+ColumnLimit: 80
+CompactNamespaces: false
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: true
+DerivePointerAlignment: false # Make sure the * or & align on the left
+EmptyLineBeforeAccessModifier: LogicalBlock
+FixNamespaceComments: true
+IncludeBlocks: Preserve
+IndentCaseLabels: true
+IndentPPDirectives: None
+IndentWidth: 2
+KeepEmptyLinesAtTheStartOfBlocks: true
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCSpaceAfterProperty: false
+ObjCSpaceBeforeProtocolList: true
+PointerAlignment: Left
+ReflowComments: false
+# SeparateDefinitionBlocks: Always # Only support since clang-format 14
+SpaceAfterCStyleCast: false
+SpaceAfterLogicalNot: false
+SpaceAfterTemplateKeyword: true
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCpp11BracedList: false
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: ControlStatements
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceBeforeSquareBrackets: false
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 2
+SpacesInAngles: false
+SpacesInCStyleCastParentheses: false
+SpacesInContainerLiterals: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+Standard: c++11
+TabWidth: 4
+UseTab: Never
diff --git a/.gitignore b/.gitignore
index d772925..d7f1e84 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
*~
*.swp
*.swo
+
+Makefile
diff --git a/Main.cpp b/Main.cpp
index 869ac06..d6ee2fb 100644
--- a/Main.cpp
+++ b/Main.cpp
@@ -4,15 +4,15 @@
* will be the base class for this */
#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 "glox/GloxViewport.hpp"
-#include "glox/GloxFirstPersonPerspective.hpp"
-#include "glox/objects/GloxTexturedCube.hpp"
#include "glox/GloxColor.hpp"
+#include "glox/GloxFirstPersonPerspective.hpp"
#include "glox/GloxLookAtPerspective.hpp"
+#include "glox/GloxViewport.hpp"
+#include "glox/objects/GloxTexturedCube.hpp"
#include "sons_of_sol/SonsOfSolApplication.hpp"
@@ -20,13 +20,13 @@ using namespace slox;
using namespace glox;
using namespace std;
-void exit( const SDL_QuitEvent& evt ) {
- (void) evt;
- exit( 0 );
+void exit(const SDL_QuitEvent& evt) {
+ (void)evt;
+ exit(0);
}
-int main ( int argc, char ** argv ) {
- SonsOfSolApplication game;
- game.run( argc, argv );
- return 0;
+int main(int argc, char** argv) {
+ SonsOfSolApplication game;
+ game.run(argc, argv);
+ return 0;
}
diff --git a/Makefile b/Makefile
deleted file mode 100644
index ebc57b9..0000000
--- a/Makefile
+++ /dev/null
@@ -1,58 +0,0 @@
-CPPC?=g++
-AR?=ar
-OPTFLAGS?=-g3 -ggdb
-CFLAGS= -Wall -Wextra -I. $(OPTFLAGS) -D DEBUG_LEVEL_TRACE -Islox -Iglox
-LDFLAGS= -Lslox -Lglox -lslox -lglox -lGL -lGLU -lSDL -lm -ljpeg -lSDL_image -lGLEW
-OBJECTS=obs/Main.o obs/AIShip.o obs/ControlMultiplexer.o obs/PlayerShip.o obs/ApplicationInit.o obs/SonsOfSolApplication.o obs/Projectile.o obs/ApplicationDisplay.o
-BINARY=SonsOfSol
-all: submodules setup $(OBJECTS)
- $(CPPC) -o $(BINARY) $(OBJECTS) $(LDFLAGS)
-
-genmake:
- find . -name genmake.sh -exec {} \;
-
-setup:
- mkdir -p obs/
-
-submodules:
- for i in $$(find */ -name Makefile) ; do \
- cd $$(dirname $$i) && make && cd ..; \
- done
-
-clean:
- - rm -rf obs $(BINARY)
- for i in $$(find */ -name Makefile) ; do \
- cd $$(dirname $$i) && make clean && cd ..; \
- done
-obs/Main.o: Main.cpp \
- sons_of_sol/SonsOfSolApplication.hpp
- $(CPPC) $(CFLAGS) -o $@ -c $<
-
-obs/AIShip.o: sons_of_sol/private_db/AIShip.cpp \
- sons_of_sol/AIShip.hpp
- $(CPPC) $(CFLAGS) -o $@ -c $<
-
-obs/ControlMultiplexer.o: sons_of_sol/private_db/ControlMultiplexer.cpp \
- sons_of_sol/ControlMultiplexer.hpp
- $(CPPC) $(CFLAGS) -o $@ -c $<
-
-obs/PlayerShip.o: sons_of_sol/private_db/PlayerShip.cpp \
- sons_of_sol/PlayerShip.hpp
- $(CPPC) $(CFLAGS) -o $@ -c $<
-
-obs/ApplicationInit.o: sons_of_sol/private_db/ApplicationInit.cpp \
- sons_of_sol/SonsOfSolApplication.hpp
- $(CPPC) $(CFLAGS) -o $@ -c $<
-
-obs/SonsOfSolApplication.o: sons_of_sol/private_db/SonsOfSolApplication.cpp \
- sons_of_sol/SonsOfSolApplication.hpp
- $(CPPC) $(CFLAGS) -o $@ -c $<
-
-obs/Projectile.o: sons_of_sol/private_db/Projectile.cpp \
- sons_of_sol/Projectile.hpp
- $(CPPC) $(CFLAGS) -o $@ -c $<
-
-obs/ApplicationDisplay.o: sons_of_sol/private_db/ApplicationDisplay.cpp \
- sons_of_sol/SonsOfSolApplication.hpp
- $(CPPC) $(CFLAGS) -o $@ -c $<
-
diff --git a/glox/compat/glox/GloxLightSource.hpp b/glox/compat/glox/GloxLightSource.hpp
index 59331f9..ad159c8 100644
--- a/glox/compat/glox/GloxLightSource.hpp
+++ b/glox/compat/glox/GloxLightSource.hpp
@@ -7,8 +7,8 @@
* GloxLight.hpp: <description>
*/
-#include "glox/GloxPoint.hpp"
#include "glox/GloxColor.hpp"
+#include "glox/GloxPoint.hpp"
#include "glox/GloxRenderable.hpp"
#include <map>
@@ -16,80 +16,71 @@
namespace glox {
class GloxLightSource {
-public:
- /* Create a new light source using the light_id
+ public:
+ /* Create a new light source using the light_id
* that is to be used in OpenGl */
- inline GloxLightSource( GLenum light_id ) :
- m_light( light_id ) {}
-
- /* Sets the color of this light
- * source */;
- void setColor( const GloxColor& color );
-
- /* Sets the position of a point */
- void setPosition( const GloxPoint<>& position, bool directional=false ) {
- m_pos = position;
- this->directional = directional;
- }
-
- inline const GloxPointf& getPosition() { return m_pos ; }
-
- /* Sets whether this light is
+ inline GloxLightSource(GLenum light_id)
+ : m_light(light_id) {}
+
+ /* Sets the color of this light
+ * source */
+ ;
+ void setColor(const GloxColor& color);
+
+ /* Sets the position of a point */
+ void setPosition(const GloxPoint<>& position, bool directional = false) {
+ m_pos = position;
+ this->directional = directional;
+ }
+
+ inline const GloxPointf& getPosition() { return m_pos; }
+
+ /* Sets whether this light is
* enabled or not */
- inline void setEnabled( bool enabled ) {
- this->enabled = enabled;
- }
-
- /* True if this light is enabled */
- inline bool isEnabled() const {
- return this->enabled;
- }
-
- inline void setAmbient( const GloxColor& color ) {
- this->ambient = color;
- }
-
- inline void setDiffuse( const GloxColor& color ) {
- this->diffuse = color;
- }
-
- inline void setSpecular( const GloxColor& color ) {
- this->specular = color;
- }
-
- inline void setLightModelAttribute( GLenum attr, float value ) {
- lightModelsAttrs[attr] = value;
- }
-
- inline void setLightModelAttribute( GLenum attr, const GloxColor& color ) {
- lightModelsAttrs_vectors[attr] = color;
- }
-
- /* Reder this light source */
- void render() const ;
-
-private:
- typedef std::map<GLenum,float> M_lm_map_t;
- typedef std::map< GLenum,GloxColor > M_lm_map_vec_t;
-
- GLenum m_light;
-
- GloxPoint<> m_pos;
- bool directional;
-
- /* The index of this light source */
- int index;
- bool enabled;
-
- /* Colors for different attributes */
- GloxColor ambient;
- GloxColor diffuse;
- GloxColor specular;
-
- M_lm_map_t lightModelsAttrs;
- M_lm_map_vec_t lightModelsAttrs_vectors;
+ inline void setEnabled(bool enabled) { this->enabled = enabled; }
+
+ /* True if this light is enabled */
+ inline bool isEnabled() const { return this->enabled; }
+
+ inline void setAmbient(const GloxColor& color) { this->ambient = color; }
+
+ inline void setDiffuse(const GloxColor& color) { this->diffuse = color; }
+
+ inline void setSpecular(const GloxColor& color) { this->specular = color; }
+
+ inline void setLightModelAttribute(GLenum attr, float value) {
+ lightModelsAttrs[attr] = value;
+ }
+
+ inline void setLightModelAttribute(GLenum attr, const GloxColor& color) {
+ lightModelsAttrs_vectors[attr] = color;
+ }
+
+ /* Reder this light source */
+ void render() const;
+
+ private:
+ typedef std::map<GLenum, float> M_lm_map_t;
+ typedef std::map<GLenum, GloxColor> M_lm_map_vec_t;
+
+ GLenum m_light;
+
+ GloxPoint<> m_pos;
+ bool directional;
+
+ /* The index of this light source */
+ int index;
+ bool enabled;
+
+ /* Colors for different attributes */
+ GloxColor ambient;
+ GloxColor diffuse;
+ GloxColor specular;
+
+ M_lm_map_t lightModelsAttrs;
+ M_lm_map_vec_t lightModelsAttrs_vectors;
};
-}
+} // namespace glox
#endif /* GLOXLIGHT_HPP_ */
diff --git a/glox/compat/glox/GloxLightSourceManager.hpp b/glox/compat/glox/GloxLightSourceManager.hpp
index 27037c5..e084907 100644
--- a/glox/compat/glox/GloxLightSourceManager.hpp
+++ b/glox/compat/glox/GloxLightSourceManager.hpp
@@ -20,31 +20,31 @@ namespace glox {
* and allocated through this GloxLightSourceManager
*/
class GloxLightSourceManager : public GloxRenderable {
-public:
- inline GloxLightSourceManager() {
- /* Initialize the arry of LightSources to
+ public:
+ inline GloxLightSourceManager() {
+ /* Initialize the arry of LightSources to
* NULL */
- for( size_t i = 0; i < GLOX_MAX_NUM_LIGHTS; ++ i ) {
- m_sources[i] = NULL;
- }
+ for (size_t i = 0; i < GLOX_MAX_NUM_LIGHTS; ++i) {
+ m_sources[i] = NULL;
}
+ }
- /* Renders the lighting for this GloxLightSourceManager.
+ /* Renders the lighting for this GloxLightSourceManager.
* This will render the scene with the lights in this
* manager and only the lights in this manager */
- void render() const ;
+ void render() const;
- /* Returns the light source with
+ /* Returns the light source with
* the ID `id'. Valid ID's are
* 0-7. An invalid id will return
* NULL. */
- GloxLightSource* getLightSource( int id ) ;
+ GloxLightSource* getLightSource(int id);
-private:
- /* The sources of light */
- GloxLightSource* m_sources[ GLOX_MAX_NUM_LIGHTS ];
+ private:
+ /* The sources of light */
+ GloxLightSource* m_sources[GLOX_MAX_NUM_LIGHTS];
};
-}
+} // namespace glox
#endif /* GLOXLIGHTSOURCEMANAGER_HPP_ */
diff --git a/glox/compat/glox/objects/GloxCube.hpp b/glox/compat/glox/objects/GloxCube.hpp
index f0e8f51..764f993 100644
--- a/glox/compat/glox/objects/GloxCube.hpp
+++ b/glox/compat/glox/objects/GloxCube.hpp
@@ -9,48 +9,43 @@
* GloxTexturedCube in GloxTexturedCube.hpp
*/
+#include "glox/GloxColor.hpp"
#include "glox/GloxCommon.hpp"
#include "glox/GloxNormal.hpp"
-#include "glox/GloxPoint.hpp"
#include "glox/GloxObject.hpp"
-#include "glox/GloxColor.hpp"
+#include "glox/GloxPoint.hpp"
#include "glox/GloxPointCollection.hpp"
#include "glox/GloxScopedAttributes.hpp"
namespace glox {
class GloxCube : public GloxObject {
-public:
- /* Creates a new cube with the size
+ public:
+ /* Creates a new cube with the size
* `size`. The size is the length of
* each side of the cube */
- GloxCube( float x, float y, float z, const GloxColor& color );
-
- inline GloxCube( const GloxCube& other ) {
- m_disp_list = other.m_disp_list ;
- m_color = other.m_color;
- }
-
- /* Draw this cube */
- void draw() const ;
-
- /* Sets the color of this cube */
- inline void setColor( const GloxColor& color ) {
- m_color = color;
- }
-
- /* Returns the color of this cube */
- inline const GloxColor& getColor() const {
- return m_color;
- }
-
-private:
- int m_disp_list ;
- /* The color of this cube */
- GloxColor m_color;
+ GloxCube(float x, float y, float z, const GloxColor& color);
+
+ inline GloxCube(const GloxCube& other) {
+ m_disp_list = other.m_disp_list;
+ m_color = other.m_color;
+ }
+
+ /* Draw this cube */
+ void draw() const;
+
+ /* Sets the color of this cube */
+ inline void setColor(const GloxColor& color) { m_color = color; }
+
+ /* Returns the color of this cube */
+ inline const GloxColor& getColor() const { return m_color; }
+
+ private:
+ int m_disp_list;
+ /* The color of this cube */
+ GloxColor m_color;
};
-}
+} // namespace glox
#endif /* GLOXCUBE_HPP_ */
-
diff --git a/glox/compat/glox/objects/GloxSphere.hpp b/glox/compat/glox/objects/GloxSphere.hpp
index cd1a97a..720fef0 100644
--- a/glox/compat/glox/objects/GloxSphere.hpp
+++ b/glox/compat/glox/objects/GloxSphere.hpp
@@ -11,10 +11,10 @@
#include "glox/GloxObject"
class GloxSphere : public GloxObject {
-public:
- GloxSphere( float radius, float res=2 );
+ public:
+ GloxSphere(float radius, float res = 2);
- void setTexture( const GloxTexture* texture );
+ void setTexture(const GloxTexture* texture);
}
#endif /* GLOXSPHERE_HPP_ */
diff --git a/glox/compat/glox/objects/GloxTexturedCube.hpp b/glox/compat/glox/objects/GloxTexturedCube.hpp
index c162fde..759dfa2 100644
--- a/glox/compat/glox/objects/GloxTexturedCube.hpp
+++ b/glox/compat/glox/objects/GloxTexturedCube.hpp
@@ -9,117 +9,112 @@
* GloxTexturedCube in GloxTexturedCube.hpp
*/
+#include "glox/GloxColor.hpp"
#include "glox/GloxCommon.hpp"
+#include "glox/GloxDebug.hpp"
#include "glox/GloxNormal.hpp"
-#include "glox/GloxPoint.hpp"
#include "glox/GloxObject.hpp"
-#include "glox/GloxColor.hpp"
+#include "glox/GloxPoint.hpp"
#include "glox/GloxPointCollection.hpp"
+#include "glox/GloxPointNormalTexture.hpp"
#include "glox/GloxScopedAttributes.hpp"
#include "glox/GloxTextureRepeat.hpp"
-#include "glox/GloxPointNormalTexture.hpp"
-#include "glox/GloxDebug.hpp"
namespace glox {
class GloxTexturedCube : public GloxObject {
-public:
- /* Creates a new cube with the size
+ public:
+ /* Creates a new cube with the size
* `size`. The size is the length of
* each side of the cube */
- GloxTexturedCube( float size, const GloxColor& color,
- const GloxTextureRepeat& topTex = GloxTextureRepeat(NULL),
- const GloxTextureRepeat& botTex = GloxTextureRepeat(NULL),
- const GloxTextureRepeat& frontTex = GloxTextureRepeat(NULL),
- const GloxTextureRepeat& backTex = GloxTextureRepeat(NULL),
- const GloxTextureRepeat& leftTex = GloxTextureRepeat(NULL),
- const GloxTextureRepeat& rightTex = GloxTextureRepeat(NULL) );
-
- /* Draw this cube */
- void draw() const ;
-
- /* Sets the color of this cube */
- inline void setColor( const GloxColor& color ) {
- m_color = color;
- }
-
- /* Returns the color of this cube */
- inline const GloxColor& getColor() const {
- return m_color;
- }
-
- inline void setTopTexture( const GloxTextureRepeat& top_tex ) {
- m_top_tex = top_tex;
- update_top();
- }
-
- inline void setBottomTexture( const GloxTextureRepeat& tex ) {
- m_bottom_tex = tex;
- update_bottom();
- }
-
- inline void setFrontTexture( const GloxTextureRepeat& tex ) {
- m_front_tex = tex;
- update_front();
- }
-
- inline void setBackTexture( const GloxTextureRepeat& tex ) {
- m_back_tex = tex;
- update_back();
- }
-
- inline void setRightTexture( const GloxTextureRepeat& tex ) {
- m_right_tex = tex;
- update_right();
- }
-
- inline void setLeftTexture( const GloxTextureRepeat& tex ) {
- m_left_tex = tex;
- update_left();
- }
-
-private:
- void update_top();
- void update_bottom();
- void update_front();
- void update_back();
- void update_right();
- void update_left();
-
- /* A typedef to make my life easier */
- typedef GloxPointCollection< GloxPointNormalTexture > _M_Square;
-
- inline void plot_with( const _M_Square& face, const GloxTextureRepeat& tex ) const;
-
- /* +/- y axis */
- _M_Square m_top;
- _M_Square m_bottom;
-
- /* -/+ z axis */
- _M_Square m_front;
- _M_Square m_back;
-
- /* -/+ x axis */
- _M_Square m_left;
- _M_Square m_right;
-
- /* The textures for the various faces of
+ GloxTexturedCube(float size, const GloxColor& color,
+ const GloxTextureRepeat& topTex = GloxTextureRepeat(NULL),
+ const GloxTextureRepeat& botTex = GloxTextureRepeat(NULL),
+ const GloxTextureRepeat& frontTex = GloxTextureRepeat(NULL),
+ const GloxTextureRepeat& backTex = GloxTextureRepeat(NULL),
+ const GloxTextureRepeat& leftTex = GloxTextureRepeat(NULL),
+ const GloxTextureRepeat& rightTex = GloxTextureRepeat(NULL));
+
+ /* Draw this cube */
+ void draw() const;
+
+ /* Sets the color of this cube */
+ inline void setColor(const GloxColor& color) { m_color = color; }
+
+ /* Returns the color of this cube */
+ inline const GloxColor& getColor() const { return m_color; }
+
+ inline void setTopTexture(const GloxTextureRepeat& top_tex) {
+ m_top_tex = top_tex;
+ update_top();
+ }
+
+ inline void setBottomTexture(const GloxTextureRepeat& tex) {
+ m_bottom_tex = tex;
+ update_bottom();
+ }
+
+ inline void setFrontTexture(const GloxTextureRepeat& tex) {
+ m_front_tex = tex;
+ update_front();
+ }
+
+ inline void setBackTexture(const GloxTextureRepeat& tex) {
+ m_back_tex = tex;
+ update_back();
+ }
+
+ inline void setRightTexture(const GloxTextureRepeat& tex) {
+ m_right_tex = tex;
+ update_right();
+ }
+
+ inline void setLeftTexture(const GloxTextureRepeat& tex) {
+ m_left_tex = tex;
+ update_left();
+ }
+
+ private:
+ void update_top();
+ void update_bottom();
+ void update_front();
+ void update_back();
+ void update_right();
+ void update_left();
+
+ /* A typedef to make my life easier */
+ typedef GloxPointCollection<GloxPointNormalTexture> _M_Square;
+
+ inline void plot_with(const _M_Square& face,
+ const GloxTextureRepeat& tex) const;
+
+ /* +/- y axis */
+ _M_Square m_top;
+ _M_Square m_bottom;
+
+ /* -/+ z axis */
+ _M_Square m_front;
+ _M_Square m_back;
+
+ /* -/+ x axis */
+ _M_Square m_left;
+ _M_Square m_right;
+
+ /* The textures for the various faces of
* the cube */
- GloxTextureRepeat m_top_tex;
- GloxTextureRepeat m_bottom_tex;
- GloxTextureRepeat m_front_tex;
- GloxTextureRepeat m_back_tex;
- GloxTextureRepeat m_left_tex;
- GloxTextureRepeat m_right_tex;
+ GloxTextureRepeat m_top_tex;
+ GloxTextureRepeat m_bottom_tex;
+ GloxTextureRepeat m_front_tex;
+ GloxTextureRepeat m_back_tex;
+ GloxTextureRepeat m_left_tex;
+ GloxTextureRepeat m_right_tex;
- /* The color of this cube */
- GloxColor m_color;
+ /* The color of this cube */
+ GloxColor m_color;
-
- float m_half;
+ float m_half;
};
-}
+} // namespace glox
#endif /* GLOXTEXTUREDCUBE_HPP_ */
-
diff --git a/glox/compat/glox/objects/GloxTexturedSphere.hpp b/glox/compat/glox/objects/GloxTexturedSphere.hpp
index d7a17e8..593c370 100644
--- a/glox/compat/glox/objects/GloxTexturedSphere.hpp
+++ b/glox/compat/glox/objects/GloxTexturedSphere.hpp
@@ -7,8 +7,8 @@
* GloxTexturedSphere.hpp: <description>
*/
-#include "glox/GloxTexture.hpp"
#include "glox/GloxObject.hpp"
+#include "glox/GloxTexture.hpp"
namespace glox {
@@ -16,37 +16,37 @@ namespace glox {
* The texture is mapped using a mercader projection
*/
class GloxTexturedSphere : public GloxObject {
-public:
- /* Create a new GloxTexturedSphere
+ public:
+ /* Create a new GloxTexturedSphere
* radius: the radius of the sphere
* res: the resolution of the sphere. Should
* be a factor of 360
* */
- GloxTexturedSphere( float radius, float res, const GloxTexture& texture );
+ GloxTexturedSphere(float radius, float res, const GloxTexture& texture);
+
+ /* Draw this sphere */
+ void draw() const;
- /* Draw this sphere */
- void draw() const;
+ /* Returns teh radius of the sphere */
+ inline float getRadius() const { return m_radius; }
- /* Returns teh radius of the sphere */
- inline float getRadius() const { return m_radius; }
+ /* Set the radius of this sphere */
+ inline void setRadius(float radius) { m_radius = radius; }
- /* Set the radius of this sphere */
- inline void setRadius( float radius ) { m_radius = radius; }
+ /* Returns the texture */
+ inline const GloxTexture& getTexture() const { return m_texture; }
- /* Returns the texture */
- inline const GloxTexture& getTexture() const { return m_texture; }
+ private:
+ /* The texture of the sphere */
+ GloxTexture m_texture;
-private:
- /* The texture of the sphere */
- GloxTexture m_texture;
+ /* The radius */
+ float m_radius;
- /* The radius */
- float m_radius;
-
- /* The display list of this sphere */
- int m_disp_list;
+ /* The display list of this sphere */
+ int m_disp_list;
};
-}
+} // namespace glox
#endif /* GLOXTEXTUREDSPHERE_HPP_ */
diff --git a/glox/compat/glox/objects/examples/GloxCylinder.hpp b/glox/compat/glox/objects/examples/GloxCylinder.hpp
index 7436f8e..e7e0f32 100644
--- a/glox/compat/glox/objects/examples/GloxCylinder.hpp
+++ b/glox/compat/glox/objects/examples/GloxCylinder.hpp
@@ -10,11 +10,11 @@
#include "glox/GloxObject.hpp"
#include "glox/GloxPointNormalTexture.hpp"
-#include "glox/GloxTexture.hpp"
#include "glox/GloxQuadStrip.hpp"
+#include "glox/GloxTexture.hpp"
-#include "glox/GloxScopedTranslation.hpp"
#include "glox/GloxColor.hpp"
+#include "glox/GloxScopedTranslation.hpp"
#include "glox/GloxPoint.hpp"
@@ -28,56 +28,55 @@ namespace glox {
* a cylinder. This object supports lighting
* and texturing */
class GloxCylinder : public GloxObject {
-public:
- /* Creates a cylinder with the radius r and the height
+ public:
+ /* Creates a cylinder with the radius r and the height
* h. th_res specifies the radial resolution of this
* cylinder */
- GloxCylinder( const GloxPoint<float>& pos, float r, float h,
- float th_res=6, const GloxTexture* texture=NULL, bool normals=true, float rep=1, float repy=1 );
+ GloxCylinder(const GloxPoint<float>& pos, float r, float h, float th_res = 6,
+ const GloxTexture* texture = NULL, bool normals = true,
+ float rep = 1, float repy = 1);
- /* Get the position of this
+ /* Get the position of this
* Cylinder */
- inline const GloxPoint<float>& getPosition() const {
- return m_position;
- }
-
- /* Sets the position of this Cylinder */
- inline void setPosition( const GloxPoint<float>& new_pos ) {
- m_position = new_pos;
+ inline const GloxPoint<float>& getPosition() const { return m_position; }
+
+ /* Sets the position of this Cylinder */
+ inline void setPosition(const GloxPoint<float>& new_pos) {
+ m_position = new_pos;
+ }
+
+ inline void draw() const {
+ if (m_texture) {
+ glEnable(GL_TEXTURE_2D);
+ m_texture->bind();
+ } else {
+ glDisable(GL_TEXTURE_2D);
}
-
- inline void draw() const {
- if( m_texture ) {
- glEnable(GL_TEXTURE_2D);
- m_texture->bind();
- } else {
- glDisable(GL_TEXTURE_2D);
- }
- /* Color of the tree without a texture */
- static const GloxColor brown( 139, 69, 19 );
- /* Translate to the position of
+ /* Color of the tree without a texture */
+ static const GloxColor brown(139, 69, 19);
+ /* Translate to the position of
* this object */
- GloxScopedTranslation trans( m_position );
+ GloxScopedTranslation trans(m_position);
- /* Set the OpenGL state machine to
+ /* Set the OpenGL state machine to
* use brown as the color */
- m_body.plot();
- glDisable(GL_TEXTURE_2D);
- }
+ m_body.plot();
+ glDisable(GL_TEXTURE_2D);
+ }
-private:
- /* The position of this cylinder */
- GloxPoint<float> m_position;
-
- /* the cylinder is basically just a quad
+ private:
+ /* The position of this cylinder */
+ GloxPoint<float> m_position;
+
+ /* the cylinder is basically just a quad
* strip. This object supports lighting,
* so the components are PointNormals */
- GloxQuadStrip< GloxPointNormalTexture > m_body;
+ GloxQuadStrip<GloxPointNormalTexture> m_body;
- /* the texture used for ths cylinder */
- const GloxTexture* m_texture;
+ /* the texture used for ths cylinder */
+ const GloxTexture* m_texture;
};
-};
+}; // namespace glox
#endif /* GLOXCYLINDER_HPP_ */
diff --git a/glox/glox/GloxColor.hpp b/glox/glox/GloxColor.hpp
index 11775d8..9ca7d62 100644
--- a/glox/glox/GloxColor.hpp
+++ b/glox/glox/GloxColor.hpp
@@ -11,102 +11,105 @@
#include "glox/GloxRenderable.hpp"
#include "glox/GloxVectorizable.hpp"
-#include <string>
#include <sstream>
+#include <string>
namespace glox {
/* This is a color class, it is for
* convinience */
-class GloxColor : public GloxRenderable,GloxVectorizable<uint8_t>,GloxVectorizable<float> {
-public:
- /* Creates a new color that is defined
+class GloxColor : public GloxRenderable,
+ GloxVectorizable<uint8_t>,
+ GloxVectorizable<float> {
+ public:
+ /* Creates a new color that is defined
* from the float values for r, g, b. The
* default value is an opaque black color */
- inline GloxColor( uint8_t r=0, uint8_t g=0, uint8_t b=0, uint8_t a=255 ) :
- r( r ), g( g ), b( b ), a( a ) {}
+ inline GloxColor(uint8_t r = 0, uint8_t g = 0, uint8_t b = 0, uint8_t a = 255)
+ : r(r), g(g), b(b), a(a) {}
- inline GloxColor( const GloxColor& color ) :
- r( color.r ), g( color.g ), b( color.b ), a( color.a ) {}
+ inline GloxColor(const GloxColor& color)
+ : r(color.r), g(color.g), b(color.b), a(color.a) {}
-
-
- /* Get the components of this
+ /* Get the components of this
* color */
- inline uint8_t getR() const { return r; }
- inline uint8_t getG() const { return g; }
- inline uint8_t getB() const { return b; }
- inline uint8_t getA() const { return a; }
-
- inline void render() const {
- if( a < 255 ) {
- glColor4ub( r, g, b, a );
- } else {
- glColor3ub( r, g, b );
- }
+ inline uint8_t getR() const { return r; }
+ inline uint8_t getG() const { return g; }
+ inline uint8_t getB() const { return b; }
+ inline uint8_t getA() const { return a; }
+
+ inline void render() const {
+ if (a < 255) {
+ glColor4ub(r, g, b, a);
+ } else {
+ glColor3ub(r, g, b);
}
-
-
- inline void scale( float f ) { scale2( f ); }
- inline void scale( uint8_t f ) { scale2( f ); }
-
- virtual int toVector( float* arr, size_t len ) const {
- if( len < 3 ) return -1;
- arr[0] = r / 255.0;
- arr[1] = g / 255.0;
- arr[2] = b / 255.0;
- if( len > 3 ) {
- arr[3] = a / 255.0;
- return 4;
- }
- return 3;
+ }
+
+ inline void scale(float f) { scale2(f); }
+ inline void scale(uint8_t f) { scale2(f); }
+
+ virtual int toVector(float* arr, size_t len) const {
+ if (len < 3)
+ return -1;
+ arr[0] = r / 255.0;
+ arr[1] = g / 255.0;
+ arr[2] = b / 255.0;
+ if (len > 3) {
+ arr[3] = a / 255.0;
+ return 4;
}
-
- virtual int toVector( uint8_t* arr, size_t len ) const {
- if( len < 3 ) return -1;
- arr[0] = r;
- arr[1] = g;
- arr[2] = b;
- if( len > 3 ) {
- arr[3] = a;
- return 4;
- }
- return 3;
+ return 3;
+ }
+
+ virtual int toVector(uint8_t* arr, size_t len) const {
+ if (len < 3)
+ return -1;
+ arr[0] = r;
+ arr[1] = g;
+ arr[2] = b;
+ if (len > 3) {
+ arr[3] = a;
+ return 4;
}
-
- inline GloxColor operator*( float value ) const {
- GloxColor ret( * this );
- ret.scale2( value );
- return ret;
- }
-
- inline std::string toString( ) const {
- char buf[ 32 ];
- snprintf( buf, 32, "( %d, %d, %d, %d )\n", r, g, b, a );
- return std::string( buf );
- }
-
- inline GloxColor operator*( int value ) const { return (*this) * ((float)value); }
-
-private:
- template <class NumT>
- inline void scale2( NumT f ) {
- int r1 = (int)(f * r);
- int g1 = (int)(f * r);
- int b1 = (int)(f * r);
- int a1 = (int)(f * r);
- r = r1 & 0xFF;
- g = g1 & 0xFF;
- b = b1 & 0xFF;
- a = a1 & 0xFF;
- }
-
- uint8_t r;
- uint8_t g;
- uint8_t b;
- uint8_t a;
+ return 3;
+ }
+
+ inline GloxColor operator*(float value) const {
+ GloxColor ret(*this);
+ ret.scale2(value);
+ return ret;
+ }
+
+ inline std::string toString() const {
+ char buf[32];
+ snprintf(buf, 32, "( %d, %d, %d, %d )\n", r, g, b, a);
+ return std::string(buf);
+ }
+
+ inline GloxColor operator*(int value) const {
+ return (*this) * ((float)value);
+ }
+
+ private:
+ template <class NumT>
+ inline void scale2(NumT f) {
+ int r1 = (int)(f * r);
+ int g1 = (int)(f * r);
+ int b1 = (int)(f * r);
+ int a1 = (int)(f * r);
+ r = r1 & 0xFF;
+ g = g1 & 0xFF;
+ b = b1 & 0xFF;
+ a = a1 & 0xFF;
+ }
+
+ uint8_t r;
+ uint8_t g;
+ uint8_t b;
+ uint8_t a;
};
-}
+} // namespace glox
#endif /* GLOXCOLOR_HPP_ */
diff --git a/glox/glox/GloxCommon.hpp b/glox/glox/GloxCommon.hpp
index 77b1e82..edbfc7e 100644
--- a/glox/glox/GloxCommon.hpp
+++ b/glox/glox/GloxCommon.hpp
@@ -2,9 +2,9 @@
#define GLOXCOMMON_HPP_
#include <inttypes.h>
-#include <cstdio>
#include <math.h>
#include <algorithm>
+#include <cstdio>
#include <cstdlib>
/* Include the OpenGL stuff */
@@ -22,52 +22,61 @@
*/
namespace glox {
- #define GloxWith( en, code ) \
- { glBegin( en ) ; \
- code ;\
- glEnd(); }
+#define GloxWith(en, code) \
+ { \
+ glBegin(en); \
+ code; \
+ glEnd(); \
+ }
- #define GloxEnableFor( en, code ) \
- { glEnable( en ) ; code ; glDisable( en ); }
+#define GloxEnableFor(en, code) \
+ { \
+ glEnable(en); \
+ code; \
+ glDisable(en); \
+ }
- #define GloxDisableFor( en, code ) \
- { glDisable( en ) ; code ; glEnable( en ) ; }
+#define GloxDisableFor(en, code) \
+ { \
+ glDisable(en); \
+ code; \
+ glEnable(en); \
+ }
- #define GloxWithTranslation( point, code ) \
- { \
- glox::GloxState::pushMatrix(); \
- glox::GloxState::translate( (point) ); \
- code; \
- glox::GloxState::popMatrix(); \
- }
- #define GloxScale( amt, code ) \
- { \
- glox::GloxState::pushMatrix(); \
- glScalef( amt,amt,amt ); \
- code; \
- glox::GloxState::popMatrix(); \
- }
+#define GloxWithTranslation(point, code) \
+ { \
+ glox::GloxState::pushMatrix(); \
+ glox::GloxState::translate((point)); \
+ code; \
+ glox::GloxState::popMatrix(); \
+ }
+#define GloxScale(amt, code) \
+ { \
+ glox::GloxState::pushMatrix(); \
+ glScalef(amt, amt, amt); \
+ code; \
+ glox::GloxState::popMatrix(); \
+ }
- typedef long long Glox64;
- typedef unsigned long long Glox64u;
- typedef int Glox32;
- typedef unsigned int Glox32u;
- typedef unsigned char Glox8u;
- typedef signed char Glox8;
- typedef unsigned short Glox16u;
- typedef signed short Glox16;
+typedef long long Glox64;
+typedef unsigned long long Glox64u;
+typedef int Glox32;
+typedef unsigned int Glox32u;
+typedef unsigned char Glox8u;
+typedef signed char Glox8;
+typedef unsigned short Glox16u;
+typedef signed short Glox16;
- inline double GloxCos( double th ) {
- return cos(3.1415927/180*(th));
- }
+inline double GloxCos(double th) {
+ return cos(3.1415927 / 180 * (th));
+}
- inline double GloxSin( double th ) {
- return sin(3.1415927/180*(th));
- }
+inline double GloxSin(double th) {
+ return sin(3.1415927 / 180 * (th));
+}
- #define GloxToDegrees( th ) \
- ((180 * (th)) / 3.14159927)
+#define GloxToDegrees(th) ((180 * (th)) / 3.14159927)
-};
+}; // namespace glox
#endif /* GLOXCOMMON_HPP_ */
diff --git a/glox/glox/GloxDebug.hpp b/glox/glox/GloxDebug.hpp
index 8b3f964..1601f0b 100644
--- a/glox/glox/GloxDebug.hpp
+++ b/glox/glox/GloxDebug.hpp
@@ -36,39 +36,57 @@ extern FILE* log_file;
#endif
#if DEBUG_LEVEL > 5
-#define GloxTrace( category, fmt, ... ) if(1){ printf("[TRACE] (%s) - " fmt, category, ##__VA_ARGS__ ); }
-#else
-#define GloxTrace( category, fmt, ... )
-#endif
-
-#if DEBUG_LEVEL > 4
-#define GloxDebug( category, fmt, ... ) if(1){ printf("[DEBUG] (%s) - " fmt, category, ##__VA_ARGS__ ); }
-#else
-#define GloxDebug( category, fmt, ... )
-#endif
-
-#if DEBUG_LEVEL > 3
-#define GloxInfo( category, fmt, ... ) if(1){ printf("[INFO] (%s) - " fmt, category, ##__VA_ARGS__ ); }
-#else
-#define GloxInfo ( category, fmt, ... )
-#endif
-
-#if DEBUG_LEVEL > 2
-#define GloxWarn( category, fmt, ... ) if(1){ printf("[WARN] (%s) - " fmt, category, ##__VA_ARGS__ ); }
-#else
-#define GloxWarn( category, fmt, ... )
-#endif
-
-#if DEBUG_LEVEL > 1
-#define GloxError( category, fmt, ... ) if(1){ printf("[ERROR] (%s) - " fmt, category, ##__VA_ARGS__ ); }
-#else
-#define GloxError( category, fmt, ... )
-#endif
-
-#if DEBUG_LEVEL > 0
-#define GloxFatal( category, fmt, ... ) if(1){ printf("[FATAL] (%s) - " fmt, category, ##__VA_ARGS__ ); }
-#else
-#define GloxFatal( category, fmt, ... )
+#define GloxTrace(category, fmt, ...) \
+ if (1) { \
+ printf("[TRACE] (%s) - " fmt, category, ##__VA_ARGS__); \
+ }
+#else
+#define GloxTrace(category, fmt, ...)
+#endif
+
+#if DEBUG_LEVEL > 4
+#define GloxDebug(category, fmt, ...) \
+ if (1) { \
+ printf("[DEBUG] (%s) - " fmt, category, ##__VA_ARGS__); \
+ }
+#else
+#define GloxDebug(category, fmt, ...)
+#endif
+
+#if DEBUG_LEVEL > 3
+#define GloxInfo(category, fmt, ...) \
+ if (1) { \
+ printf("[INFO] (%s) - " fmt, category, ##__VA_ARGS__); \
+ }
+#else
+#define GloxInfo (category, fmt, ...)
+#endif
+
+#if DEBUG_LEVEL > 2
+#define GloxWarn(category, fmt, ...) \
+ if (1) { \
+ printf("[WARN] (%s) - " fmt, category, ##__VA_ARGS__); \
+ }
+#else
+#define GloxWarn(category, fmt, ...)
+#endif
+
+#if DEBUG_LEVEL > 1
+#define GloxError(category, fmt, ...) \
+ if (1) { \
+ printf("[ERROR] (%s) - " fmt, category, ##__VA_ARGS__); \
+ }
+#else
+#define GloxError(category, fmt, ...)
+#endif
+
+#if DEBUG_LEVEL > 0
+#define GloxFatal(category, fmt, ...) \
+ if (1) { \
+ printf("[FATAL] (%s) - " fmt, category, ##__VA_ARGS__); \
+ }
+#else
+#define GloxFatal(category, fmt, ...)
#endif
#endif /* GLOXDEBUG_HPP_ */
diff --git a/glox/glox/GloxFirstPersonPerspective.hpp b/glox/glox/GloxFirstPersonPerspective.hpp
index 6effa3a..10e7248 100644
--- a/glox/glox/GloxFirstPersonPerspective.hpp
+++ b/glox/glox/GloxFirstPersonPerspective.hpp
@@ -15,50 +15,49 @@
namespace glox {
class GloxFirstPersonPerspective : public GloxStandardProjection {
-public:
- inline GloxFirstPersonPerspective(
- const GloxPoint<>& pos=GloxPoint<>(),
- float roll=0, float pitch=0, float yaw=0,
- float fov=50.0, float asp=1.8, float znear=0.1, float zfar=500.0 ) :
- GloxStandardProjection( pos, fov, asp, znear, zfar ),
- m_yaw( yaw ), m_pitch( pitch ), m_roll( roll ) {}
+ public:
+ inline GloxFirstPersonPerspective(const GloxPoint<>& pos = GloxPoint<>(),
+ float roll = 0, float pitch = 0,
+ float yaw = 0, float fov = 50.0,
+ float asp = 1.8, float znear = 0.1,
+ float zfar = 500.0)
+ : GloxStandardProjection(pos, fov, asp, znear, zfar),
+ m_yaw(yaw),
+ m_pitch(pitch),
+ m_roll(roll) {}
- inline void setYaw( float yaw ) {
- m_yaw = yaw;
- }
+ inline void setYaw(float yaw) { m_yaw = yaw; }
- inline void setPitch( float pitch ) {
- m_pitch = pitch;
- }
+ inline void setPitch(float pitch) { m_pitch = pitch; }
- inline void setRoll( float roll ) {
- m_roll = roll;
- }
+ inline void setRoll(float roll) { m_roll = roll; }
- inline float getYaw() const { return m_yaw; }
- inline float getPitch() const { return m_pitch; }
- inline float getRoll() const { return m_roll; }
+ inline float getYaw() const { return m_yaw; }
+ inline float getPitch() const { return m_pitch; }
+ inline float getRoll() const { return m_roll; }
- /* adds a vector of rotations, expressed in
+ /* adds a vector of rotations, expressed in
* terms or roll, pitch and yaw */
- inline void addRotationVector( const GloxVector3<float>& vec ) {
- m_roll += vec.get0();
- m_pitch += GloxCos( m_roll )*vec.get1() + GloxSin( m_roll )*vec.get2();
- m_yaw += GloxSin( m_roll )*vec.get1() + GloxCos( m_roll ) * vec.get2();
- }
-
- virtual void render() const;
-
- inline GloxPoint<> forward( float rad ) {
- return GloxPoint<>::fromSpherical( rad, m_yaw, m_pitch ) + this->getPosition();
- }
-private:
- /* Rotations */
- float m_yaw; /* Horizontal rotation */
- float m_pitch; /* Up or down */
- float m_roll;
+ inline void addRotationVector(const GloxVector3<float>& vec) {
+ m_roll += vec.get0();
+ m_pitch += GloxCos(m_roll) * vec.get1() + GloxSin(m_roll) * vec.get2();
+ m_yaw += GloxSin(m_roll) * vec.get1() + GloxCos(m_roll) * vec.get2();
+ }
+
+ virtual void render() const;
+
+ inline GloxPoint<> forward(float rad) {
+ return GloxPoint<>::fromSpherical(rad, m_yaw, m_pitch) +
+ this->getPosition();
+ }
+
+ private:
+ /* Rotations */
+ float m_yaw; /* Horizontal rotation */
+ float m_pitch; /* Up or down */
+ float m_roll;
};
-}
+} // namespace glox
#endif /* GLOXFIRSTPERSONPERSPECTIVE_HPP_ */
diff --git a/glox/glox/GloxLookAtPerspective.hpp b/glox/glox/GloxLookAtPerspective.hpp
index 67d197b..dee5bd4 100644
--- a/glox/glox/GloxLookAtPerspective.hpp
+++ b/glox/glox/GloxLookAtPerspective.hpp
@@ -9,54 +9,51 @@
#include <GL/glu.h>
+#include "glox/GloxDebug.hpp"
#include "glox/GloxPerspective.hpp"
-#include "glox/GloxState.hpp"
#include "glox/GloxStandardProjection.hpp"
-#include "glox/GloxDebug.hpp"
+#include "glox/GloxState.hpp"
namespace glox {
/* This is a projection which is a thin
* layer around gluLookAt */
class GloxLookAtPerspective : public GloxStandardProjection {
-public:
- inline GloxLookAtPerspective( const GloxPoint<>& pos=GloxPoint<>(),
- const GloxPoint<>& lookAt=GloxPoint<>(), const GloxPoint<>& upVec=GloxPoint<>( 0.0f, 1.0f, 0.0f ),
- float fov=50.0, float asp=1.8, float zn=0.1, float zfar=500.0) :
- GloxStandardProjection( pos, fov, asp, zn, zfar ),
- m_LookAtPoint( lookAt ), m_UpVector( upVec ) {}
-
- inline virtual void render() const {
-// GloxTrace( "GloxLookAtPerspective", "gluLookAt: %s %s %s\n",
-// getPosition().toString().c_str(), m_LookAtPoint.toString().c_str(),
-// m_UpVector.toString().c_str() );
-
- gluLookAt( getPosition().getX(), getPosition().getY(), getPosition().getZ(),
- m_LookAtPoint.getX(), m_LookAtPoint.getY(), m_LookAtPoint.getZ(),
- m_UpVector.getX() , m_UpVector.getY() , m_UpVector.getZ() );
- }
-
- inline void setLookAtPoint( const GloxPoint<>& point ) {
- m_LookAtPoint = point;
- }
-
- inline const GloxPoint<>& getLookAtPoint() {
- return m_LookAtPoint;
- }
-
- inline void setUpVector( const GloxPoint<>& point ) {
- m_UpVector = point;
- }
-
- inline const GloxPoint<>& getUpVector() {
- return m_UpVector;
- }
-
-private:
- GloxPoint<> m_LookAtPoint;
- GloxPoint<> m_UpVector;
+ public:
+ inline GloxLookAtPerspective(
+ const GloxPoint<>& pos = GloxPoint<>(),
+ const GloxPoint<>& lookAt = GloxPoint<>(),
+ const GloxPoint<>& upVec = GloxPoint<>(0.0f, 1.0f, 0.0f),
+ float fov = 50.0, float asp = 1.8, float zn = 0.1, float zfar = 500.0)
+ : GloxStandardProjection(pos, fov, asp, zn, zfar),
+ m_LookAtPoint(lookAt),
+ m_UpVector(upVec) {}
+
+ inline virtual void render() const {
+ // GloxTrace( "GloxLookAtPerspective", "gluLookAt: %s %s %s\n",
+ // getPosition().toString().c_str(), m_LookAtPoint.toString().c_str(),
+ // m_UpVector.toString().c_str() );
+
+ gluLookAt(getPosition().getX(), getPosition().getY(), getPosition().getZ(),
+ m_LookAtPoint.getX(), m_LookAtPoint.getY(), m_LookAtPoint.getZ(),
+ m_UpVector.getX(), m_UpVector.getY(), m_UpVector.getZ());
+ }
+
+ inline void setLookAtPoint(const GloxPoint<>& point) {
+ m_LookAtPoint = point;
+ }
+
+ inline const GloxPoint<>& getLookAtPoint() { return m_LookAtPoint; }
+
+ inline void setUpVector(const GloxPoint<>& point) { m_UpVector = point; }
+
+ inline const GloxPoint<>& getUpVector() { return m_UpVector; }
+
+ private:
+ GloxPoint<> m_LookAtPoint;
+ GloxPoint<> m_UpVector;
};
-}
+} // namespace glox
#endif /* GLOXLOOKATPERSPECTIVE_HPP_ */
diff --git a/glox/glox/GloxNormal.hpp b/glox/glox/GloxNormal.hpp
index 18fb709..fc70181 100644
--- a/glox/glox/GloxNormal.hpp
+++ b/glox/glox/GloxNormal.hpp
@@ -9,130 +9,119 @@
#include "glox/GloxPlottable.hpp"
-#include <string>
#include <sstream>
+#include <string>
namespace glox {
/* Type that the GloxNormal holds,
* defaults to an integer */
-template <class NumT=float>
+template <class NumT = float>
/* A normal in 3D space. This class
* implements Plottable which provides
* the `plot` function which calles
* glVertex on the components */
class GloxNormal : public GloxPlottable {
-public:
- /* Creates a new GloxNormal from the components
+ public:
+ /* Creates a new GloxNormal from the components
* specified */
- inline GloxNormal( const NumT& x=0, const NumT& y=0, const NumT& z=0 ):
- x(x), y(y), z(z) {}
+ inline GloxNormal(const NumT& x = 0, const NumT& y = 0, const NumT& z = 0)
+ : x(x), y(y), z(z) {}
- /* Copies the glox normal other */
- inline GloxNormal( const GloxNormal<NumT>& other ) :
- x(other.x), y(other.y), z(other.z) {}
+ /* Copies the glox normal other */
+ inline GloxNormal(const GloxNormal<NumT>& other)
+ : x(other.x), y(other.y), z(other.z) {}
- /* Returns the X componet of this
+ /* Returns the X componet of this
* normal */
- inline const NumT& getX() const {
- return x;
- }
+ inline const NumT& getX() const { return x; }
- /* Returns the Y component of this
+ /* Returns the Y component of this
* normal */
- inline const NumT& getY() const {
- return y;
- }
+ inline const NumT& getY() const { return y; }
- /* Returns the Z component of this
+ /* Returns the Z component of this
* normal */
- inline const NumT& getZ() const {
- return z;
- }
+ inline const NumT& getZ() const { return z; }
- /* Sets the X component of this
+ /* Sets the X component of this
* normal */
- inline void setX( const NumT& x ) {
- this->x = x;
- }
+ inline void setX(const NumT& x) { this->x = x; }
- /* Sets the Y component of this normal */
- inline void setY( const NumT& y ) {
- this->y = y;
- }
+ /* Sets the Y component of this normal */
+ inline void setY(const NumT& y) { this->y = y; }
- /* Sets the Z component of this
+ /* Sets the Z component of this
* normal */
- inline void setZ( const NumT& z ) {
- this->z = z;
- }
+ inline void setZ(const NumT& z) { this->z = z; }
- /* Copy the normal `normal` into this
+ /* Copy the normal `normal` into this
* normal */
- inline const GloxNormal<NumT>& operator=( const GloxNormal<NumT>& normal ) {
- this->x = normal.x;
- this->y = normal.y;
- this->z = normal.z;
+ inline const GloxNormal<NumT>& operator=(const GloxNormal<NumT>& normal) {
+ this->x = normal.x;
+ this->y = normal.y;
+ this->z = normal.z;
- return * this;
- }
+ return *this;
+ }
- /* Add the components of `normal` to this */
- inline GloxNormal<NumT>& operator+=( const GloxNormal<NumT>& normal ) {
- this->x += normal.x;
- this->y += normal.y;
- this->z += normal.z;
+ /* Add the components of `normal` to this */
+ inline GloxNormal<NumT>& operator+=(const GloxNormal<NumT>& normal) {
+ this->x += normal.x;
+ this->y += normal.y;
+ this->z += normal.z;
- return * this;
- }
+ return *this;
+ }
- /* Returns a new GloxNormal that is the sum
+ /* Returns a new GloxNormal that is the sum
* of this and `normal` */
- inline GloxNormal<NumT> operator+( const GloxNormal<NumT>& normal ) const {
- GloxNormal<NumT> ret;
- ret += normal;
- return ret;
- }
-
- inline std::string toString() const {
- std::stringstream stream;
- stream << "( " << x << ", " << y << ", " << z << " )";
- return stream.str();
- }
-
- /* Plot this normal. This function depends on the
+ inline GloxNormal<NumT> operator+(const GloxNormal<NumT>& normal) const {
+ GloxNormal<NumT> ret;
+ ret += normal;
+ return ret;
+ }
+
+ inline std::string toString() const {
+ std::stringstream stream;
+ stream << "( " << x << ", " << y << ", " << z << " )";
+ return stream.str();
+ }
+
+ /* Plot this normal. This function depends on the
* number provided */
- inline void plot( ) const;
+ inline void plot() const;
- /* Does exactly the same thing that plot does, but
+ /* Does exactly the same thing that plot does, but
* sometimes it is better to be more explicit about
* what plot is actually doing */
- inline void glNormal() const { plot() ; }
-private:
- NumT x;
- NumT y;
- NumT z;
+ inline void glNormal() const { plot(); }
+
+ private:
+ NumT x;
+ NumT y;
+ NumT z;
};
/* Implementations of the plot functions for
* different template arguments */
template <>
inline void GloxNormal<int>::plot() const {
- glNormal3i( this->getX(), this->getY(), this->getZ() );
+ glNormal3i(this->getX(), this->getY(), this->getZ());
}
template <>
inline void GloxNormal<float>::plot() const {
- glNormal3f( this->getX(), this->getY(), this->getZ() );
+ glNormal3f(this->getX(), this->getY(), this->getZ());
}
template <>
inline void GloxNormal<short>::plot() const {
- glNormal3s( this->getX(), this->getY(), this->getZ() );
+ glNormal3s(this->getX(), this->getY(), this->getZ());
}
template <class T>
inline void GloxNormal<T>::plot() const {
- glNormal3d( this->getX(), this->getY(), this->getZ() );
+ glNormal3d(this->getX(), this->getY(), this->getZ());
}
-}
+} // namespace glox
#endif /* GLOXNORMAL_HPP_ */
diff --git a/glox/glox/GloxObject.hpp b/glox/glox/GloxObject.hpp
index 3a9ef6e..f67731f 100644
--- a/glox/glox/GloxObject.hpp
+++ b/glox/glox/GloxObject.hpp
@@ -19,11 +19,11 @@ namespace glox {
* transformations of the OpenGL state machine
*/
class GloxObject {
-public:
- /* Draws this object */
- virtual void draw() const = 0;
+ public:
+ /* Draws this object */
+ virtual void draw() const = 0;
};
-}
+} // namespace glox
#endif /* GLOXOBJECT_HPP_ */
diff --git a/glox/glox/GloxPerspective.hpp b/glox/glox/GloxPerspective.hpp
index c22631e..c96a274 100644
--- a/glox/glox/GloxPerspective.hpp
+++ b/glox/glox/GloxPerspective.hpp
@@ -7,8 +7,8 @@
* GloxPerspective.hpp: <description>
*/
-#include "glox/GloxRenderable.hpp"
#include "glox/GloxPoint.hpp"
+#include "glox/GloxRenderable.hpp"
namespace glox {
@@ -17,35 +17,30 @@ namespace glox {
* render() function will render the world
* from this perspective */
class GloxPerspective : public GloxRenderable {
-public:
- /* Create a new Perspective at the location
+ public:
+ /* Create a new Perspective at the location
* 'pos' */
- inline GloxPerspective( const GloxPoint<>& pos ) :
- m_position( pos ) {}
+ inline GloxPerspective(const GloxPoint<>& pos) : m_position(pos) {}
- /* set the position of the perspective */
- inline void setPosition( const GloxPoint<>& pos ) {
- m_position = pos;
- }
+ /* set the position of the perspective */
+ inline void setPosition(const GloxPoint<>& pos) { m_position = pos; }
- /* Returns the position of the Perspective */
- inline const GloxPoint<>& getPosition() const {
- return m_position;
- }
+ /* Returns the position of the Perspective */
+ inline const GloxPoint<>& getPosition() const { return m_position; }
- /* This is called everytime the display
+ /* This is called everytime the display
* function is called */
- virtual void render() const = 0;
+ virtual void render() const = 0;
- /* This renders a projection. This
+ /* This renders a projection. This
* should be called if parameters
* change */
- virtual void project() const = 0;
+ virtual void project() const = 0;
-private:
- GloxPoint<> m_position;
+ private:
+ GloxPoint<> m_position;
};
-}
+} // namespace glox
#endif /* GLOXPERSPECTIVE_HPP_ */
diff --git a/glox/glox/GloxPlottable.hpp b/glox/glox/GloxPlottable.hpp
index 15d5560..4416c52 100644
--- a/glox/glox/GloxPlottable.hpp
+++ b/glox/glox/GloxPlottable.hpp
@@ -12,12 +12,12 @@ namespace glox {
/* A plottable object is an object which
* can plot itself */
class GloxPlottable {
-public:
- /* Plot this object on the
+ public:
+ /* Plot this object on the
* space */
- virtual void plot() const = 0;
+ virtual void plot() const = 0;
};
-}
+} // namespace glox
#endif /* PLOTTABLE_HPP_ */
diff --git a/glox/glox/GloxPoint.hpp b/glox/glox/GloxPoint.hpp
index 866d6ab..391db6f 100644
--- a/glox/glox/GloxPoint.hpp
+++ b/glox/glox/GloxPoint.hpp
@@ -9,12 +9,12 @@
#include "glox/GloxCommon.hpp"
#include "glox/GloxPlottable.hpp"
-#include "glox/GloxVectorizable.hpp"
#include "glox/GloxVector4.hpp"
+#include "glox/GloxVectorizable.hpp"
#include <iostream>
-#include <string>
#include <sstream>
+#include <string>
#include <cmath>
@@ -22,187 +22,171 @@ namespace glox {
/* Type that the GloxPoint holds,
* defaults to an integer */
-template <class NumT=float>
+template <class NumT = float>
/* A point in 3D space. This class
* implements Plottable which provides
* the `plot` function which calles
* glVertex on the components */
-class GloxPoint : public GloxPlottable,GloxVectorizable<NumT> {
-public:
- inline static GloxPoint<> fromSpherical( NumT r, NumT th, NumT ph ) {
- // double Ex = -2*dim*Sin(th)*Cos(ph);
- // double Ey = +2*dim *Sin(ph);
- // double Ez = +2*dim*Cos(th)*Cos(ph);
- return GloxPoint<>( -r * GloxSin( th ) * GloxCos( ph ),
- r * GloxSin( ph ),
- r * GloxCos( th ) * GloxCos( ph ) ) ;
- }
-
- inline static GloxPoint<> fromSpherical( const GloxVector4<NumT>& vec ) {
- return fromSpherical( vec.getX(), vec.getY(), vec.getZ() );
- }
-
- /* Creates a new GloxPoint from the components
+class GloxPoint : public GloxPlottable, GloxVectorizable<NumT> {
+ public:
+ inline static GloxPoint<> fromSpherical(NumT r, NumT th, NumT ph) {
+ // double Ex = -2*dim*Sin(th)*Cos(ph);
+ // double Ey = +2*dim *Sin(ph);
+ // double Ez = +2*dim*Cos(th)*Cos(ph);
+ return GloxPoint<>(-r * GloxSin(th) * GloxCos(ph), r * GloxSin(ph),
+ r * GloxCos(th) * GloxCos(ph));
+ }
+
+ inline static GloxPoint<> fromSpherical(const GloxVector4<NumT>& vec) {
+ return fromSpherical(vec.getX(), vec.getY(), vec.getZ());
+ }
+
+ /* Creates a new GloxPoint from the components
* specified */
- inline GloxPoint( const NumT& x=0, const NumT& y=0, const NumT& z=0 ):
- x(x), y(y), z(z) {}
+ inline GloxPoint(const NumT& x = 0, const NumT& y = 0, const NumT& z = 0)
+ : x(x), y(y), z(z) {}
- /* Copies the glox point other */
- inline GloxPoint( const GloxPoint<NumT>& other ) :
- x(other.x), y(other.y), z(other.z) {}
+ /* Copies the glox point other */
+ inline GloxPoint(const GloxPoint<NumT>& other)
+ : x(other.x), y(other.y), z(other.z) {}
- /* Returns the X componet of this
+ /* Returns the X componet of this
* point */
- inline const NumT& getX() const {
- return x;
- }
+ inline const NumT& getX() const { return x; }
- /* Returns the Y component of this
+ /* Returns the Y component of this
* point */
- inline const NumT& getY() const {
- return y;
- }
+ inline const NumT& getY() const { return y; }
- /* Returns the Z component of this
+ /* Returns the Z component of this
* point */
- inline const NumT& getZ() const {
- return z;
- }
+ inline const NumT& getZ() const { return z; }
- /* Sets the X component of this
+ /* Sets the X component of this
* point */
- inline void setX( const NumT& x ) {
- this->x = x;
- }
+ inline void setX(const NumT& x) { this->x = x; }
- /* Sets the Y component of this point */
- inline void setY( const NumT& y ) {
- this->y = y;
- }
+ /* Sets the Y component of this point */
+ inline void setY(const NumT& y) { this->y = y; }
- /* Sets the Z component of this
+ /* Sets the Z component of this
* point */
- inline void setZ( const NumT& z ) {
- this->z = z;
- }
+ inline void setZ(const NumT& z) { this->z = z; }
- inline float getMagnitude() const {
- return sqrt( x * x + y * y + z * z ) ;
- }
+ inline float getMagnitude() const { return sqrt(x * x + y * y + z * z); }
- /* Copy the point `point` into this
+ /* Copy the point `point` into this
* point */
- inline const GloxPoint<NumT>& operator=( const GloxPoint<NumT>& point ) {
- this->x = point.x;
- this->y = point.y;
- this->z = point.z;
+ inline const GloxPoint<NumT>& operator=(const GloxPoint<NumT>& point) {
+ this->x = point.x;
+ this->y = point.y;
+ this->z = point.z;
- return * this;
- }
+ return *this;
+ }
- /* Add the components of `point` to this */
- inline GloxPoint<NumT>& operator+=( const GloxPoint<NumT>& point ) {
- this->x += point.x;
- this->y += point.y;
- this->z += point.z;
+ /* Add the components of `point` to this */
+ inline GloxPoint<NumT>& operator+=(const GloxPoint<NumT>& point) {
+ this->x += point.x;
+ this->y += point.y;
+ this->z += point.z;
- return * this;
- }
+ return *this;
+ }
- /* Add the components of `point` to this */
- inline GloxPoint<NumT>& operator-=( const GloxPoint<NumT>& point ) {
- this->x -= point.x;
- this->y -= point.y;
- this->z -= point.z;
+ /* Add the components of `point` to this */
+ inline GloxPoint<NumT>& operator-=(const GloxPoint<NumT>& point) {
+ this->x -= point.x;
+ this->y -= point.y;
+ this->z -= point.z;
- return * this;
- }
+ return *this;
+ }
- /* Returns a new GloxPoint that is the sum
+ /* Returns a new GloxPoint that is the sum
* of this and `point` */
- inline GloxPoint<NumT> operator+( const GloxPoint<NumT>& point ) const {
- GloxPoint<NumT> ret = *this;
- ret += point;
- return ret;
- }
+ inline GloxPoint<NumT> operator+(const GloxPoint<NumT>& point) const {
+ GloxPoint<NumT> ret = *this;
+ ret += point;
+ return ret;
+ }
- /* Returns a new GloxPoint that is the sum
+ /* Returns a new GloxPoint that is the sum
* of this and `point` */
- inline GloxPoint<NumT> operator-( const GloxPoint<NumT>& point ) const {
- GloxPoint<NumT> ret = *this;
- ret -= point;
- return ret;
- }
-
- inline GloxPoint<NumT>& operator*=( NumT scalar ) {
- x *= scalar;
- y *= scalar;
- z *= scalar;
- return * this;
- }
-
- inline GloxPoint<NumT> operator*(NumT scalar) const {
- GloxPoint<NumT> ret = * this;
- ret *= scalar;
- return ret;
- }
-
- inline NumT dot( const GloxPoint<NumT>& other ) {
- GloxPoint<> tmp1 = *this;
- GloxPoint<> tmp2 = other;
-
- // std::cout << "Orig: " << this->toString() << ", " << other.toString() << std::endl;
- tmp1.normalize();
- tmp2.normalize();
-
- // std::cout << "Norm: " << this->toString() << ", " << other.toString() << std::endl;;
- return tmp1.x * tmp2.x +
- tmp1.y * tmp2.y +
- tmp1.z * tmp2.z ;
- }
-
- inline GloxPoint<NumT> cross( const GloxPoint<NumT>& other ) {
- return GloxPoint(
- y * other.z - z * other.y
- , z * other.x - x * other.z
- , x * other.y - y * other.x
- );
- }
-
- inline void normalize() {
- float mag = getMagnitude();
-
- x = x / mag;
- y = y / mag;
- z = z / mag;
- }
-
- inline std::string toString() const {
- std::stringstream stream;
- stream << "( " << x << ", " << y << ", " << z << " )";
- return stream.str();
- }
-
- virtual inline void scale( NumT amt ) {
- x *= amt; y *= amt; z *= amt;
- }
-
- int toVector( NumT* arr, size_t len ) const {
- if( len < 3 ) return -1;
- arr[0] = x;
- arr[1] = y;
- arr[2] = z;
- return 3;
- }
-
- /* Plot this point. This function depends on the
+ inline GloxPoint<NumT> operator-(const GloxPoint<NumT>& point) const {
+ GloxPoint<NumT> ret = *this;
+ ret -= point;
+ return ret;
+ }
+
+ inline GloxPoint<NumT>& operator*=(NumT scalar) {
+ x *= scalar;
+ y *= scalar;
+ z *= scalar;
+ return *this;
+ }
+
+ inline GloxPoint<NumT> operator*(NumT scalar) const {
+ GloxPoint<NumT> ret = *this;
+ ret *= scalar;
+ return ret;
+ }
+
+ inline NumT dot(const GloxPoint<NumT>& other) {
+ GloxPoint<> tmp1 = *this;
+ GloxPoint<> tmp2 = other;
+
+ // std::cout << "Orig: " << this->toString() << ", " << other.toString() << std::endl;
+ tmp1.normalize();
+ tmp2.normalize();
+
+ // std::cout << "Norm: " << this->toString() << ", " << other.toString() << std::endl;;
+ return tmp1.x * tmp2.x + tmp1.y * tmp2.y + tmp1.z * tmp2.z;
+ }
+
+ inline GloxPoint<NumT> cross(const GloxPoint<NumT>& other) {
+ return GloxPoint(y * other.z - z * other.y, z * other.x - x * other.z,
+ x * other.y - y * other.x);
+ }
+
+ inline void normalize() {
+ float mag = getMagnitude();
+
+ x = x / mag;
+ y = y / mag;
+ z = z / mag;
+ }
+
+ inline std::string toString() const {
+ std::stringstream stream;
+ stream << "( " << x << ", " << y << ", " << z << " )";
+ return stream.str();
+ }
+
+ virtual inline void scale(NumT amt) {
+ x *= amt;
+ y *= amt;
+ z *= amt;
+ }
+
+ int toVector(NumT* arr, size_t len) const {
+ if (len < 3)
+ return -1;
+ arr[0] = x;
+ arr[1] = y;
+ arr[2] = z;
+ return 3;
+ }
+
+ /* Plot this point. This function depends on the
* number provided */
- inline void plot( ) const;
-private:
- NumT x;
- NumT y;
- NumT z;
+ inline void plot() const;
+
+ private:
+ NumT x;
+ NumT y;
+ NumT z;
};
typedef GloxPoint<> GloxPointf;
@@ -211,21 +195,21 @@ typedef GloxPoint<> GloxPointf;
* different template arguments */
template <>
inline void GloxPoint<int>::plot() const {
- glVertex3i( this->getX(), this->getY(), this->getZ() );
+ glVertex3i(this->getX(), this->getY(), this->getZ());
}
template <>
inline void GloxPoint<float>::plot() const {
- glVertex3f( this->getX(), this->getY(), this->getZ() );
+ glVertex3f(this->getX(), this->getY(), this->getZ());
}
template <>
inline void GloxPoint<short>::plot() const {
- glVertex3s( this->getX(), this->getY(), this->getZ() );
+ glVertex3s(this->getX(), this->getY(), this->getZ());
}
template <class T>
inline void GloxPoint<T>::plot() const {
- glVertex3d( this->getX(), this->getY(), this->getZ() );
+ glVertex3d(this->getX(), this->getY(), this->getZ());
}
-}
+} // namespace glox
#endif /* GLOXPOINT_HPP_ */
diff --git a/glox/glox/GloxPointCollection.hpp b/glox/glox/GloxPointCollection.hpp
index f6a209a..934abec 100644
--- a/glox/glox/GloxPointCollection.hpp
+++ b/glox/glox/GloxPointCollection.hpp
@@ -7,97 +7,82 @@
* GloxPointCollection.hpp: <description>
*/
+#include "glox/GloxDebug.hpp"
#include "glox/GloxPlottable.hpp"
#include "glox/GloxPoint.hpp"
-#include "glox/GloxDebug.hpp"
-#include <vector>
-#include <string>
#include <sstream>
+#include <string>
+#include <vector>
namespace glox {
-template < class PlottableT=GloxPoint<float> >
+template <class PlottableT = GloxPoint<float>>
/* GloxPointCollection: a collection of Plottable that
* may be plotted in bulk */
class GloxPointCollection : public GloxPlottable {
-public:
- /* Shorter vector term */
- typedef std::vector< PlottableT > m_Vec_t;
- typedef typename m_Vec_t::iterator iterator;
- typedef typename m_Vec_t::const_iterator const_iterator;
+ public:
+ /* Shorter vector term */
+ typedef std::vector<PlottableT> m_Vec_t;
+ typedef typename m_Vec_t::iterator iterator;
+ typedef typename m_Vec_t::const_iterator const_iterator;
- /* Constructs a new GloxPointCollection with
+ /* Constructs a new GloxPointCollection with
* no Points */
- inline GloxPointCollection( ) {
- // Nothing here for now
- }
+ inline GloxPointCollection() {
+ // Nothing here for now
+ }
- /* Creates a new GloxPointCollection with the
+ /* Creates a new GloxPointCollection with the
* initial starting points `points`
*/
- inline GloxPointCollection( const m_Vec_t& points ) {
- this->points = points;
- }
-
- /* Iterate through the vector of Plottable
+ inline GloxPointCollection(const m_Vec_t& points) { this->points = points; }
+
+ /* Iterate through the vector of Plottable
* and call their plot functions */
- virtual void plot() const {
- // GloxTrace( "GloxPointCollection", "plot(): this = %s\n", this->toString().c_str() );
+ virtual void plot() const {
+ // GloxTrace( "GloxPointCollection", "plot(): this = %s\n", this->toString().c_str() );
- for( const_iterator itr = this->begin(); itr != this->end(); ++ itr ) {
- (*itr).plot();
- }
- }
+ for (const_iterator itr = this->begin(); itr != this->end(); ++itr) {
+ (*itr).plot();
+ }
+ }
- /* Appends a point to this collection */
- virtual void add( const PlottableT& point ) {
- this->points.push_back( point );
- }
+ /* Appends a point to this collection */
+ virtual void add(const PlottableT& point) { this->points.push_back(point); }
- /* Returns an iterator for this
+ /* Returns an iterator for this
* GloxPointCollection */
- inline iterator begin() {
- return points.begin();
- }
+ inline iterator begin() { return points.begin(); }
- /* Returns then end of the iterator */
- inline iterator end() {
- return points.end();
- }
+ /* Returns then end of the iterator */
+ inline iterator end() { return points.end(); }
- inline void clear() {
- points.clear();
- }
+ inline void clear() { points.clear(); }
- /* Returns an iterator for this
+ /* Returns an iterator for this
* GloxPointCollection */
- inline const_iterator begin() const {
- return points.begin();
- }
-
- /* Returns then end of the const_iterator */
- inline const_iterator end() const {
- return points.end();
- }
-
- inline std::string toString() const {
- std::stringstream stream;
- stream << "[ ";
- for( const_iterator itr = this->begin(); itr != this->end(); ++ itr ) {
- stream << (*itr).toString() << ", ";
- }
- stream << "]";
- return stream.str();
- }
+ inline const_iterator begin() const { return points.begin(); }
-private:
+ /* Returns then end of the const_iterator */
+ inline const_iterator end() const { return points.end(); }
- /* The points to plot */
- m_Vec_t points;
-};
+ inline std::string toString() const {
+ std::stringstream stream;
+ stream << "[ ";
+ for (const_iterator itr = this->begin(); itr != this->end(); ++itr) {
+ stream << (*itr).toString() << ", ";
+ }
+ stream << "]";
+ return stream.str();
+ }
+ private:
+ /* The points to plot */
+ m_Vec_t points;
};
+}; // namespace glox
+
#endif /* GLOXPOINTCOLLECTION_HPP_ */
diff --git a/glox/glox/GloxPointNormal.hpp b/glox/glox/GloxPointNormal.hpp
index 256db75..63671d9 100644
--- a/glox/glox/GloxPointNormal.hpp
+++ b/glox/glox/GloxPointNormal.hpp
@@ -7,67 +7,60 @@
* GloxPointNormal.hpp: <description>
*/
+#include "glox/GloxNormal.hpp"
#include "glox/GloxPlottable.hpp"
#include "glox/GloxPoint.hpp"
-#include "glox/GloxNormal.hpp"
-#include <string>
#include <sstream>
+#include <string>
namespace glox {
/* The number type used by both
* the point and the normal to use */
-template <class NumT=float>
+template <class NumT = float>
/* A class that couples a point with a normal. This
* is a useful wrapper over both a glVertex and glNormal
* functions */
-class GloxPointNormal : public GloxPlottable{
-public:
- /* Creates a new point at the
+class GloxPointNormal : public GloxPlottable {
+ public:
+ /* Creates a new point at the
* origin with no normal */
- GloxPointNormal( ) :
- m_point(), m_normal() {}
+ GloxPointNormal() : m_point(), m_normal() {}
- /* Creates a new GloxPointNormal at the point `point`
+ /* Creates a new GloxPointNormal at the point `point`
* and with the normal `normal` */
- GloxPointNormal( const GloxPoint<NumT>& point, const GloxNormal<NumT>& normal ) :
- m_point( point ), m_normal( normal ) {}
+ GloxPointNormal(const GloxPoint<NumT>& point, const GloxNormal<NumT>& normal)
+ : m_point(point), m_normal(normal) {}
- /* Plots a point and sets the
+ /* Plots a point and sets the
* normal for that point */
- inline void plot( ) const {
- m_normal.plot();
- m_point.plot();
- }
-
- inline void setPoint( const GloxPoint<NumT>& point ) {
- m_point = point;
- }
-
- inline void setNormal( const GloxNormal<NumT>& normal ) {
- m_normal = normal;
- }
-
- inline const GloxPoint<NumT>& getPoint () {
- return m_point;
- }
-
- inline const GloxNormal<NumT>& getNormal() {
- return m_normal;
- }
-
- inline const std::string toString() const {
- std::stringstream ret;
- ret << "GloxPointNormal{ " << m_point.toString() << ", " << m_normal.toString() << " }" ;
- return ret.str();
- }
-private:
- GloxPoint<NumT> m_point;
- GloxNormal<NumT> m_normal;
+ inline void plot() const {
+ m_normal.plot();
+ m_point.plot();
+ }
+
+ inline void setPoint(const GloxPoint<NumT>& point) { m_point = point; }
+
+ inline void setNormal(const GloxNormal<NumT>& normal) { m_normal = normal; }
+
+ inline const GloxPoint<NumT>& getPoint() { return m_point; }
+
+ inline const GloxNormal<NumT>& getNormal() { return m_normal; }
+
+ inline const std::string toString() const {
+ std::stringstream ret;
+ ret << "GloxPointNormal{ " << m_point.toString() << ", "
+ << m_normal.toString() << " }";
+ return ret.str();
+ }
+
+ private:
+ GloxPoint<NumT> m_point;
+ GloxNormal<NumT> m_normal;
};
-}
+} // namespace glox
#endif /* GLOXPOINTNORMAL_HPP_ */
diff --git a/glox/glox/GloxPointNormalTexture.hpp b/glox/glox/GloxPointNormalTexture.hpp
index 6bed16f..0636fca 100644
--- a/glox/glox/GloxPointNormalTexture.hpp
+++ b/glox/glox/GloxPointNormalTexture.hpp
@@ -8,9 +8,9 @@
*/
#include "glox/GloxPlottable.hpp"
+#include "glox/GloxPoint.hpp"
#include "glox/GloxPointNormal.hpp"
#include "glox/GloxTexture.hpp"
-#include "glox/GloxPoint.hpp"
namespace glox {
@@ -22,29 +22,34 @@ namespace glox {
* that point
*/
class GloxPointNormalTexture : public GloxPlottable {
-public:
- inline GloxPointNormalTexture( const GloxPointNormal<>& pointNormal, const GloxPoint<>& texPoint ) :
- m_PointNormal( pointNormal ), m_TextureMap( texPoint ) {
- }
-
- inline GloxPointNormalTexture( const GloxPoint<>& point, const GloxNormal<>& normal, const GloxPoint<>& texPoint ) :
- m_PointNormal( point, normal ), m_TextureMap( texPoint ) {}
-
- inline void plot() const {
- glTexCoord2f( m_TextureMap.getX(), m_TextureMap.getY() );
- m_PointNormal.plot();
- }
-
- inline const GloxPointNormal<>& getPointNormal() const { return m_PointNormal; }
- inline const GloxPoint<>& getTexturePoint() const { return m_TextureMap; }
-
- inline GloxPointNormal<>& getPointNormal() { return m_PointNormal; }
- inline GloxPoint<>& getTexturePoint() { return m_TextureMap; }
-private:
- GloxPointNormal<> m_PointNormal;
- GloxPoint<> m_TextureMap;
+ public:
+ inline GloxPointNormalTexture(const GloxPointNormal<>& pointNormal,
+ const GloxPoint<>& texPoint)
+ : m_PointNormal(pointNormal), m_TextureMap(texPoint) {}
+
+ inline GloxPointNormalTexture(const GloxPoint<>& point,
+ const GloxNormal<>& normal,
+ const GloxPoint<>& texPoint)
+ : m_PointNormal(point, normal), m_TextureMap(texPoint) {}
+
+ inline void plot() const {
+ glTexCoord2f(m_TextureMap.getX(), m_TextureMap.getY());
+ m_PointNormal.plot();
+ }
+
+ inline const GloxPointNormal<>& getPointNormal() const {
+ return m_PointNormal;
+ }
+ inline const GloxPoint<>& getTexturePoint() const { return m_TextureMap; }
+
+ inline GloxPointNormal<>& getPointNormal() { return m_PointNormal; }
+ inline GloxPoint<>& getTexturePoint() { return m_TextureMap; }
+
+ private:
+ GloxPointNormal<> m_PointNormal;
+ GloxPoint<> m_TextureMap;
};
-}
+} // namespace glox
#endif /* GLOXPOINTNORMALTEXTURE_HPP_ */
diff --git a/glox/glox/GloxProgram.hpp b/glox/glox/GloxProgram.hpp
index e10f7ca..2bab9e2 100644
--- a/glox/glox/GloxProgram.hpp
+++ b/glox/glox/GloxProgram.hpp
@@ -8,79 +8,79 @@
*/
#include "glox/GloxCommon.hpp"
+#include "glox/GloxPoint.hpp"
#include "glox/GloxShader.hpp"
#include "glox/GloxVector3.hpp"
#include "glox/GloxVector4.hpp"
-#include "glox/GloxPoint.hpp"
#include <vector>
namespace glox {
class GloxProgram {
-public:
- GloxProgram( ) ;
+ public:
+ GloxProgram();
- unsigned int getId() {
- return id ;
- }
+ unsigned int getId() { return id; }
- int attachShader( const GloxShader& shader ) ;
-
- int attachShaderFromFile( const char* filename, GLenum type ) ;
+ int attachShader(const GloxShader& shader);
- int getUniformLocation( const char* uniform ) ;
+ int attachShaderFromFile(const char* filename, GLenum type);
- inline void setUniformFloat( int uniform, float fl ) {
- glUniform1f( uniform, fl ) ;
- }
+ int getUniformLocation(const char* uniform);
- inline void setUniformInteger( int uniform, float i ) {
- glUniform1f( uniform, i ) ;
- }
+ inline void setUniformFloat(int uniform, float fl) {
+ glUniform1f(uniform, fl);
+ }
- template <class Vectorizable3>
- inline void setUniformVector3( int uniform, const Vectorizable3& point ) {
- glUniform3f( uniform, point.getX(), point.getY(), point.getZ() ) ;
- }
+ inline void setUniformInteger(int uniform, float i) {
+ glUniform1f(uniform, i);
+ }
- template <class Vectorizable4>
- inline void setUniformVector4( int uniform, const Vectorizable4& point ) {
- float arr[4] ;
- point.toVector( arr, 4 ) ;
- glUniform4fv( uniform, 1, arr ) ;
- }
+ template <class Vectorizable3>
+ inline void setUniformVector3(int uniform, const Vectorizable3& point) {
+ glUniform3f(uniform, point.getX(), point.getY(), point.getZ());
+ }
+
+ template <class Vectorizable4>
+ inline void setUniformVector4(int uniform, const Vectorizable4& point) {
+ float arr[4];
+ point.toVector(arr, 4);
+ glUniform4fv(uniform, 1, arr);
+ }
- template <class Vectorizable3>
- inline void setUniformVector3FromList( int uniform, const std::vector<Vectorizable3>& vecs ) {
- int len = vecs.size() * 3 ;
- float* arr = new float[len] ;
+ template <class Vectorizable3>
+ inline void setUniformVector3FromList(
+ int uniform, const std::vector<Vectorizable3>& vecs) {
+ int len = vecs.size() * 3;
+ float* arr = new float[len];
- for ( size_t i = 0; i < vecs.size() ; ++ i ) {
- vecs[i].toVector( arr + (i * 3), 3 ) ;
- }
+ for (size_t i = 0; i < vecs.size(); ++i) {
+ vecs[i].toVector(arr + (i * 3), 3);
}
+ }
- template <class Vectorizable4>
- inline void setUniformVector4FromList( int uniform, const std::vector<Vectorizable4>& vecs ) {
- int len = vecs.size() * 4 ;
- float* arr = new float[len] ;
+ template <class Vectorizable4>
+ inline void setUniformVector4FromList(
+ int uniform, const std::vector<Vectorizable4>& vecs) {
+ int len = vecs.size() * 4;
+ float* arr = new float[len];
+
+ for (size_t i = 0; i < vecs.size(); ++i) {
+ vecs[i].toVector(arr + (i * 3), 3);
+ }
+ };
- for ( size_t i = 0; i < vecs.size() ; ++ i ) {
- vecs[i].toVector( arr + (i * 3), 3 ) ;
- }
- };
-
- void render() const ;
+ void render() const;
- int link();
+ int link();
- static void unloadPrograms() ;
-private:
+ static void unloadPrograms();
- unsigned int id ;
+ private:
+ unsigned int id;
};
-}
+} // namespace glox
#endif /* GLOXPROGRAM_HPP_ */
diff --git a/glox/glox/GloxQuadStrip.hpp b/glox/glox/GloxQuadStrip.hpp
index 6eb283e..bc14e02 100644
--- a/glox/glox/GloxQuadStrip.hpp
+++ b/glox/glox/GloxQuadStrip.hpp
@@ -14,7 +14,7 @@
namespace glox {
-template <class PlottableT /* extends Plottable */ = GloxPoint<float> >
+template <class PlottableT /* extends Plottable */ = GloxPoint<float>>
/* This class represents a quad strip
* for OpenGL. This will draw a collection
@@ -25,37 +25,34 @@ template <class PlottableT /* extends Plottable */ = GloxPoint<float> >
* that it IS dependent on state
* of the OpenGL machine */
class GloxQuadStrip : public GloxPlottable {
-public:
- inline GloxQuadStrip() :
- points() {}
- /* Creates a new GloxQuadStrip with the points
+ public:
+ inline GloxQuadStrip() : points() {}
+ /* Creates a new GloxQuadStrip with the points
* given as a vector as it's initial points */
- inline GloxQuadStrip( const std::vector< PlottableT >& points ) :
- points( points ) {}
+ inline GloxQuadStrip(const std::vector<PlottableT>& points)
+ : points(points) {}
- /* Creates a new GloxQuadStrip with the points
+ /* Creates a new GloxQuadStrip with the points
* given as a collection of points */
- inline GloxQuadStrip( const GloxPointCollection<PlottableT>& collection ) :
- points( collection ) {}
-
- /* Plots the points as a GL_QUAD_STRIP */
- inline virtual void plot() const {
- glBegin( GL_QUAD_STRIP );
- points.plot();
- glEnd();
- }
-
- /* Appends a point to the collection
+ inline GloxQuadStrip(const GloxPointCollection<PlottableT>& collection)
+ : points(collection) {}
+
+ /* Plots the points as a GL_QUAD_STRIP */
+ inline virtual void plot() const {
+ glBegin(GL_QUAD_STRIP);
+ points.plot();
+ glEnd();
+ }
+
+ /* Appends a point to the collection
* of points to plot */
- inline void addPoint( const PlottableT& point ) {
- points.add( point );
- }
+ inline void addPoint(const PlottableT& point) { points.add(point); }
-private:
- /* The points that make up this
+ private:
+ /* The points that make up this
* quad strip */
- GloxPointCollection<PlottableT> points;
+ GloxPointCollection<PlottableT> points;
};
-}
+} // namespace glox
#endif /* QUADSTRIP_HPP_ */
diff --git a/glox/glox/GloxRenderable.hpp b/glox/glox/GloxRenderable.hpp
index cf1265b..3ea8a20 100644
--- a/glox/glox/GloxRenderable.hpp
+++ b/glox/glox/GloxRenderable.hpp
@@ -10,10 +10,10 @@
namespace glox {
class GloxRenderable {
-public:
- virtual void render() const = 0;
+ public:
+ virtual void render() const = 0;
};
-}
+} // namespace glox
#endif /* GLOXRENDERABLE_HPP_ */
diff --git a/glox/glox/GloxRotation.hpp b/glox/glox/GloxRotation.hpp
index 3dd9966..1b9810d 100644
--- a/glox/glox/GloxRotation.hpp
+++ b/glox/glox/GloxRotation.hpp
@@ -12,28 +12,29 @@
namespace glox {
class GloxRotation {
-public:
- inline GloxRotation( double ang, double x, double y, double z ) :
- m_ang( ang ), m_x( x ), m_y( y ), m_z( z ) {}
-
- inline void render() const { glRotatef( m_ang, m_x, m_y, m_z ); }
-
- inline double getAngle() const { return m_ang; }
- inline double getX() const { return m_x; }
- inline double getY() const { return m_y; }
- inline double getZ() const { return m_z; }
-
- inline void setAngle( double ang ) { m_ang = ang ; }
- inline void setX( double x ) { m_x = x; }
- inline void setY( double y ) { m_y = y; }
- inline void setZ( double z ) { m_z = z; }
-private:
- double m_ang;
- double m_x;
- double m_y;
- double m_z;
+ public:
+ inline GloxRotation(double ang, double x, double y, double z)
+ : m_ang(ang), m_x(x), m_y(y), m_z(z) {}
+
+ inline void render() const { glRotatef(m_ang, m_x, m_y, m_z); }
+
+ inline double getAngle() const { return m_ang; }
+ inline double getX() const { return m_x; }
+ inline double getY() const { return m_y; }
+ inline double getZ() const { return m_z; }
+
+ inline void setAngle(double ang) { m_ang = ang; }
+ inline void setX(double x) { m_x = x; }
+ inline void setY(double y) { m_y = y; }
+ inline void setZ(double z) { m_z = z; }
+
+ private:
+ double m_ang;
+ double m_x;
+ double m_y;
+ double m_z;
};
-}
+} // namespace glox
#endif /* GLOXROTATION_HPP_ */
diff --git a/glox/glox/GloxScopedAttributes.hpp b/glox/glox/GloxScopedAttributes.hpp
index 7491ad8..06f5caf 100644
--- a/glox/glox/GloxScopedAttributes.hpp
+++ b/glox/glox/GloxScopedAttributes.hpp
@@ -21,18 +21,14 @@ namespace glox {
* attributes from the GL stack.
*/
class GloxScopedAttributes {
-public:
- /* Push the attributes on the GL stack */
- inline GloxScopedAttributes( GLbitfield fields ) {
- glPushAttrib( fields );
- }
+ public:
+ /* Push the attributes on the GL stack */
+ inline GloxScopedAttributes(GLbitfield fields) { glPushAttrib(fields); }
- /* Restore the attributes */
- inline ~GloxScopedAttributes( ) {
- glPopAttrib() ;
- }
+ /* Restore the attributes */
+ inline ~GloxScopedAttributes() { glPopAttrib(); }
};
-}
+} // namespace glox
#endif /* GLOXSCOPEDATTRIBUTES_HPP_ */
diff --git a/glox/glox/GloxScopedBegin.hpp b/glox/glox/GloxScopedBegin.hpp
index 15459be..910d87d 100644
--- a/glox/glox/GloxScopedBegin.hpp
+++ b/glox/glox/GloxScopedBegin.hpp
@@ -15,16 +15,12 @@ namespace glox {
* this class scopes a begin so GlEnd is
* automatically called when leaving scope */
class GloxScopedBegin {
-public:
- inline GloxScopedBegin( GLenum to_begin ) {
- glBegin( to_begin );
- }
+ public:
+ inline GloxScopedBegin(GLenum to_begin) { glBegin(to_begin); }
- inline ~GloxScopedBegin( ) {
- glEnd();
- }
+ inline ~GloxScopedBegin() { glEnd(); }
};
-}
+} // namespace glox
#endif /* GLOXSCOPEDBEGIN_HPP_ */
diff --git a/glox/glox/GloxScopedRotation.hpp b/glox/glox/GloxScopedRotation.hpp
index 4c95c27..373aeb6 100644
--- a/glox/glox/GloxScopedRotation.hpp
+++ b/glox/glox/GloxScopedRotation.hpp
@@ -4,29 +4,27 @@
* GloxScopedTranslation.hpp: <description>
*/
-#include "glox/GloxState.hpp"
#include "glox/GloxRotation.hpp"
+#include "glox/GloxState.hpp"
namespace glox {
/* A translation that endures for
* the current scope */
class GloxScopedRotation {
-public:
- inline GloxScopedRotation( double angle, double x, double y, double z ) {
- GloxState::pushMatrix();
- GloxState::rotate( angle, x, y, z );
- }
+ public:
+ inline GloxScopedRotation(double angle, double x, double y, double z) {
+ GloxState::pushMatrix();
+ GloxState::rotate(angle, x, y, z);
+ }
- inline GloxScopedRotation( const GloxRotation& rotation ) {
- GloxState::pushMatrix();
- GloxState::rotate( rotation.getAngle(), rotation.getX(),
- rotation.getY(), rotation.getZ() );
- }
+ inline GloxScopedRotation(const GloxRotation& rotation) {
+ GloxState::pushMatrix();
+ GloxState::rotate(rotation.getAngle(), rotation.getX(), rotation.getY(),
+ rotation.getZ());
+ }
- inline ~GloxScopedRotation( ) {
- GloxState::popMatrix();
- }
+ inline ~GloxScopedRotation() { GloxState::popMatrix(); }
};
-}
+} // namespace glox
diff --git a/glox/glox/GloxScopedTranslation.hpp b/glox/glox/GloxScopedTranslation.hpp
index 4dc14c2..7b2d0c4 100644
--- a/glox/glox/GloxScopedTranslation.hpp
+++ b/glox/glox/GloxScopedTranslation.hpp
@@ -15,17 +15,15 @@ namespace glox {
/* A translation that endures for
* the current scope */
class GloxScopedTranslation {
-public:
- inline GloxScopedTranslation( const GloxPoint<>& point ) {
- GloxState::pushMatrix();
- GloxState::translate( point );
- }
+ public:
+ inline GloxScopedTranslation(const GloxPoint<>& point) {
+ GloxState::pushMatrix();
+ GloxState::translate(point);
+ }
- inline ~GloxScopedTranslation( ) {
- GloxState::popMatrix();
- }
+ inline ~GloxScopedTranslation() { GloxState::popMatrix(); }
};
-}
+} // namespace glox
#endif /* GLOXSCOPEDTRANSLATION_HPP_ */
diff --git a/glox/glox/GloxShader.hpp b/glox/glox/GloxShader.hpp
index 98e42a0..b10e783 100644
--- a/glox/glox/GloxShader.hpp
+++ b/glox/glox/GloxShader.hpp
@@ -7,41 +7,33 @@
* GloxShader.hpp: <description>
*/
-
-#include "glox/GloxCommon.hpp"
#include <string>
+#include "glox/GloxCommon.hpp"
namespace glox {
class GloxShader {
-public:
- inline GloxShader( GLenum type ) {
- this->type = type ;
- }
+ public:
+ inline GloxShader(GLenum type) { this->type = type; }
+
+ static inline const std::string& getMessage() { return message; }
- static inline const std::string& getMessage() {
- return message ;
- }
+ inline GLenum getType() const { return type; }
- inline GLenum getType() const {
- return type ;
- }
+ inline unsigned int getId() const { return m_shader; }
- inline unsigned int getId() const {
- return m_shader ;
- }
+ int load(const char* filename);
- int load( const char* filename ) ;
+ ~GloxShader();
- ~GloxShader() ;
-private:
- unsigned int m_shader ;
- GLenum type ;
+ private:
+ unsigned int m_shader;
+ GLenum type;
- static int readFile( const char* filename, std::string& into ) ;
- static std::string message ;
-} ;
+ static int readFile(const char* filename, std::string& into);
+ static std::string message;
+};
-}
+} // namespace glox
#endif /* GLOXSHADER_HPP_ */
diff --git a/glox/glox/GloxStandardProjection.hpp b/glox/glox/GloxStandardProjection.hpp
index 1ca0416..55d99e8 100644
--- a/glox/glox/GloxStandardProjection.hpp
+++ b/glox/glox/GloxStandardProjection.hpp
@@ -15,46 +15,49 @@
namespace glox {
class GloxStandardProjection : public GloxPerspective {
-public:
-
-inline GloxStandardProjection( const GloxPoint<>& pos, float fov=50.0, float asp=1.8, float znear=0.1, float zfar=500.0 ) :
- GloxPerspective( pos ),
- m_FieldOfView( fov ), m_AspectRatio( asp ), m_ZNear( znear ), m_ZFar( zfar ) {
-}
-
-/* Set up the projection */
-inline virtual void project() const {
- GloxState::matrixMode(GL_PROJECTION);
- GloxState::loadIdentity();
-
- gluPerspective( m_FieldOfView, m_AspectRatio, m_ZNear, m_ZFar );
-
- GloxState::matrixMode(GL_MODELVIEW);
- GloxState::loadIdentity();
-}
-
-/* This class only helps with
+ public:
+ inline GloxStandardProjection(const GloxPoint<>& pos, float fov = 50.0,
+ float asp = 1.8, float znear = 0.1,
+ float zfar = 500.0)
+ : GloxPerspective(pos),
+ m_FieldOfView(fov),
+ m_AspectRatio(asp),
+ m_ZNear(znear),
+ m_ZFar(zfar) {}
+
+ /* Set up the projection */
+ inline virtual void project() const {
+ GloxState::matrixMode(GL_PROJECTION);
+ GloxState::loadIdentity();
+
+ gluPerspective(m_FieldOfView, m_AspectRatio, m_ZNear, m_ZFar);
+
+ GloxState::matrixMode(GL_MODELVIEW);
+ GloxState::loadIdentity();
+ }
+
+ /* This class only helps with
* projections, it still needs to
* have render implemented */
-virtual void render() const = 0;
-
-float getFieldOfView() const { return m_FieldOfView; }
-float getAspectRatio() const { return m_AspectRatio; }
-float getZNear() const { return m_ZNear; }
-float getZFar() const { return m_ZFar; }
-
-void setFieldOfView( float fieldOfView) { m_FieldOfView = fieldOfView; }
-void setAspectRatio( float aspectRatio) { m_AspectRatio = aspectRatio; }
-void setZNear( float zNear) { m_ZNear = zNear; }
-void setZFar ( float zFar) { m_ZFar = zFar; }
-
-private:
- float m_FieldOfView;
- float m_AspectRatio;
- float m_ZNear;
- float m_ZFar;
+ virtual void render() const = 0;
+
+ float getFieldOfView() const { return m_FieldOfView; }
+ float getAspectRatio() const { return m_AspectRatio; }
+ float getZNear() const { return m_ZNear; }
+ float getZFar() const { return m_ZFar; }
+
+ void setFieldOfView(float fieldOfView) { m_FieldOfView = fieldOfView; }
+ void setAspectRatio(float aspectRatio) { m_AspectRatio = aspectRatio; }
+ void setZNear(float zNear) { m_ZNear = zNear; }
+ void setZFar(float zFar) { m_ZFar = zFar; }
+
+ private:
+ float m_FieldOfView;
+ float m_AspectRatio;
+ float m_ZNear;
+ float m_ZFar;
};
-}
+} // namespace glox
#endif /* GLOXSTANDARDPROJECTION_HPP_ */
diff --git a/glox/glox/GloxState.hpp b/glox/glox/GloxState.hpp
index 3725bbc..1213de0 100644
--- a/glox/glox/GloxState.hpp
+++ b/glox/glox/GloxState.hpp
@@ -13,63 +13,55 @@
namespace glox {
class GloxState {
-public:
- inline static void pushMatrix() { glPushMatrix(); }
- inline static void popMatrix() { glPopMatrix(); }
+ public:
+ inline static void pushMatrix() { glPushMatrix(); }
+ inline static void popMatrix() { glPopMatrix(); }
- template <class T>
- inline static void translate( const GloxPoint<T>& point ) ;
+ template <class T>
+ inline static void translate(const GloxPoint<T>& point);
- inline static void matrixMode( GLenum val ) { glMatrixMode( val ) ; }
- inline static void loadIdentity() { glLoadIdentity(); }
+ inline static void matrixMode(GLenum val) { glMatrixMode(val); }
+ inline static void loadIdentity() { glLoadIdentity(); }
- inline static void rotate( float amt, const GloxPoint<>& vector ) {
- glRotatef( amt, vector.getX(), vector.getY(), vector.getZ() );
- }
+ inline static void rotate(float amt, const GloxPoint<>& vector) {
+ glRotatef(amt, vector.getX(), vector.getY(), vector.getZ());
+ }
- inline static void clear( GLbitfield val ) {
- glClear(val);
- }
+ inline static void clear(GLbitfield val) { glClear(val); }
- inline static void enable( GLenum e ) {
- glEnable( e );
- }
+ inline static void enable(GLenum e) { glEnable(e); }
- inline static void disable( GLenum e ) {
- glDisable( e );
- }
+ inline static void disable(GLenum e) { glDisable(e); }
- inline static void flush() {
- glFlush();
- }
+ inline static void flush() { glFlush(); }
- inline static void lightModel( GLenum key, int val ) {
- glLightModeli( key, val );
- }
+ inline static void lightModel(GLenum key, int val) {
+ glLightModeli(key, val);
+ }
- inline static void colorMaterial( GLenum key, GLenum val ) {
- glColorMaterial(key,val);
- }
+ inline static void colorMaterial(GLenum key, GLenum val) {
+ glColorMaterial(key, val);
+ }
- inline static void rotate( double ang, double x, double y, double z ) {
- glRotated( ang, x, y, z );
- }
+ inline static void rotate(double ang, double x, double y, double z) {
+ glRotated(ang, x, y, z);
+ }
};
template <>
/* Floats are a special case, so translate to
* them like normal */
-inline void GloxState::translate( const GloxPoint<float>& point ) {
- glTranslatef( point.getX(), point.getY(), point.getZ() );
+inline void GloxState::translate(const GloxPoint<float>& point) {
+ glTranslatef(point.getX(), point.getY(), point.getZ());
}
template <class T>
/* Everything else should be implicity cast
* to a double and send to glTranslated */
-inline void GloxState::translate( const GloxPoint<T>& point ) {
- glTranslated( point.getX(), point.getY(), point.getZ() );
+inline void GloxState::translate(const GloxPoint<T>& point) {
+ glTranslated(point.getX(), point.getY(), point.getZ());
}
-}
+} // namespace glox
#endif /* GLOXSTATE_HPP_ */
diff --git a/glox/glox/GloxTexture.hpp b/glox/glox/GloxTexture.hpp
index 1427c6a..335d063 100644
--- a/glox/glox/GloxTexture.hpp
+++ b/glox/glox/GloxTexture.hpp
@@ -12,18 +12,18 @@
namespace glox {
class GloxTexture {
-public:
- GloxTexture( unsigned int id=0 ) :
- m_id( id ) {}
+ public:
+ GloxTexture(unsigned int id = 0) : m_id(id) {}
- unsigned int getId() const { return m_id ; }
- void bind() const { glBindTexture( GL_TEXTURE_2D, m_id ) ; }
+ unsigned int getId() const { return m_id; }
+ void bind() const { glBindTexture(GL_TEXTURE_2D, m_id); }
- void setId( unsigned int id ) { m_id = id; }
-private:
- unsigned int m_id;
+ void setId(unsigned int id) { m_id = id; }
+
+ private:
+ unsigned int m_id;
};
-}
+} // namespace glox
#endif /* GLOXTEXTURE_HPP_ */
diff --git a/glox/glox/GloxTextureFactory.hpp b/glox/glox/GloxTextureFactory.hpp
index 32ddb1c..cf8a919 100644
--- a/glox/glox/GloxTextureFactory.hpp
+++ b/glox/glox/GloxTextureFactory.hpp
@@ -9,8 +9,8 @@
#include "glox/GloxTexture.hpp"
-#include <iostream>
#include <fstream>
+#include <iostream>
#include <string>
namespace glox {
@@ -19,30 +19,32 @@ namespace glox {
* texture objects. The textures can then
* be pinned onto objects */
class GloxTextureFactory {
-public:
- /* Creates a new texture from a bitmap
+ public:
+ /* Creates a new texture from a bitmap
* image. If there is an error, NULL is
* returned */
- static GloxTexture* textureFromBitmap( std::istream& stream );
- static inline GloxTexture* textureFromBitmapFile( const char* filename ) {
- std::ifstream ifs;
- ifs.open( filename, std::ifstream::binary );
+ static GloxTexture* textureFromBitmap(std::istream& stream);
+ static inline GloxTexture* textureFromBitmapFile(const char* filename) {
+ std::ifstream ifs;
+ ifs.open(filename, std::ifstream::binary);
- if( ! ifs.is_open() ) { return NULL; }
- return textureFromBitmap( ifs );
+ if (!ifs.is_open()) {
+ return NULL;
}
+ return textureFromBitmap(ifs);
+ }
#ifndef NO_JPG_SUPPORT
- static GloxTexture* buildTextureFromJpg( std::istream& stream );
+ static GloxTexture* buildTextureFromJpg(std::istream& stream);
#endif
#ifndef NO_PNG_SUPPORT
- static GloxTexture* buildTextureFromPng( std::istream& stream );
+ static GloxTexture* buildTextureFromPng(std::istream& stream);
#endif
- static const std::string& getErrorMessage();
+ static const std::string& getErrorMessage();
};
-}
+} // namespace glox
#endif /* GLOXTEXTUREFACTORY_HPP_ */
diff --git a/glox/glox/GloxTextureRepeat.hpp b/glox/glox/GloxTextureRepeat.hpp
index e9bd526..1cebdfe 100644
--- a/glox/glox/GloxTextureRepeat.hpp
+++ b/glox/glox/GloxTextureRepeat.hpp
@@ -15,45 +15,34 @@
namespace glox {
class GloxTextureRepeat {
-public:
- inline GloxTextureRepeat( const GloxTexture* texture, float xreps=1.0f, float yreps=1.0 ):
- m_texture( texture ), m_xreps( xreps ), m_yreps( yreps ) {}
-
- inline const GloxTexture* getTexture() const {
- return m_texture ;
- }
-
- inline bool isNull() const {
- return m_texture == NULL;
- }
-
- inline float getXReps() const {
- return m_xreps;
- }
-
- inline float getYReps() const {
- return m_yreps;
- }
-
- inline void setYReps( float yreps) {
- m_yreps = yreps;
- }
-
- inline void setXReps( float xreps ) {
- m_xreps = xreps;
- }
-private:
- /* The texture this class
+ public:
+ inline GloxTextureRepeat(const GloxTexture* texture, float xreps = 1.0f,
+ float yreps = 1.0)
+ : m_texture(texture), m_xreps(xreps), m_yreps(yreps) {}
+
+ inline const GloxTexture* getTexture() const { return m_texture; }
+
+ inline bool isNull() const { return m_texture == NULL; }
+
+ inline float getXReps() const { return m_xreps; }
+
+ inline float getYReps() const { return m_yreps; }
+
+ inline void setYReps(float yreps) { m_yreps = yreps; }
+
+ inline void setXReps(float xreps) { m_xreps = xreps; }
+
+ private:
+ /* The texture this class
* is repeating */
- const GloxTexture* m_texture;
-
- /* The number of times to repeat
+ const GloxTexture* m_texture;
+
+ /* The number of times to repeat
* this texture */
- float m_xreps;
- float m_yreps;
+ float m_xreps;
+ float m_yreps;
};
-}
-
+} // namespace glox
#endif /* GLOXTEXTUREREPEAT_HPP_ */
diff --git a/glox/glox/GloxVector3.hpp b/glox/glox/GloxVector3.hpp
index 390a820..796c62d 100644
--- a/glox/glox/GloxVector3.hpp
+++ b/glox/glox/GloxVector3.hpp
@@ -9,78 +9,74 @@
#include "glox/GloxPoint.hpp"
-#include <string>
#include <sstream>
+#include <string>
#include <cmath>
namespace glox {
-template <class NumT=float>
+template <class NumT = float>
class GloxVector3 {
-public:
- inline GloxVector3( const NumT& x=0, const NumT& y=0, const NumT& z=0 ) :
- x( x ), y( y ), z( z ) {}
-
- inline const NumT& get0() const { return x; }
- inline const NumT& get1() const { return y; }
- inline const NumT& get2() const { return z; }
-
- inline void set0( const NumT& x ) { this->x = x; }
- inline void set1( const NumT& y ) { this->y = y; }
- inline void set2( const NumT& z ) { this->z = z; }
-
- inline bool isZero() {
- return x == 0 && y == 0 && z == 0 ;
- }
-
- inline void operator+=(const GloxVector3& other ) {
- x += other.x;
- y += other.y;
- z += other.z;
- }
-
- inline void operator*=( NumT scalar ) {
- x *= scalar;
- y *= scalar;
- z *= scalar;
- }
-
- inline GloxVector3<NumT> operator*( NumT scalar ) {
- GloxVector3 tmp = *this;
- tmp *= scalar;
- return tmp;
- }
-
- inline GloxVector3<NumT> cross( const GloxVector3<NumT>& v ) {
- return GloxVector3<NumT>(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
- }
-
- inline double getMagnitude() const {
- return sqrt( x*x + y*y + z*z );
- }
-
- void normalize() {
- double mag = getMagnitude();
- x = x / mag;
- y = y / mag;
- z = z / mag;
- }
-
- inline GloxPoint<NumT> toPoint() {
- return GloxPoint<NumT>( x, y, z );
- }
-
- inline std::string toString() const {
- std::stringstream stream;
- stream << "( " << x << ", " << y << ", " << z << " )";
- return stream.str();
- }
-private:
- NumT x;
- NumT y;
- NumT z;
+ public:
+ inline GloxVector3(const NumT& x = 0, const NumT& y = 0, const NumT& z = 0)
+ : x(x), y(y), z(z) {}
+
+ inline const NumT& get0() const { return x; }
+ inline const NumT& get1() const { return y; }
+ inline const NumT& get2() const { return z; }
+
+ inline void set0(const NumT& x) { this->x = x; }
+ inline void set1(const NumT& y) { this->y = y; }
+ inline void set2(const NumT& z) { this->z = z; }
+
+ inline bool isZero() { return x == 0 && y == 0 && z == 0; }
+
+ inline void operator+=(const GloxVector3& other) {
+ x += other.x;
+ y += other.y;
+ z += other.z;
+ }
+
+ inline void operator*=(NumT scalar) {
+ x *= scalar;
+ y *= scalar;
+ z *= scalar;
+ }
+
+ inline GloxVector3<NumT> operator*(NumT scalar) {
+ GloxVector3 tmp = *this;
+ tmp *= scalar;
+ return tmp;
+ }
+
+ inline GloxVector3<NumT> cross(const GloxVector3<NumT>& v) {
+ return GloxVector3<NumT>(y * v.z - z * v.y, z * v.x - x * v.z,
+ x * v.y - y * v.x);
+ }
+
+ inline double getMagnitude() const { return sqrt(x * x + y * y + z * z); }
+
+ void normalize() {
+ double mag = getMagnitude();
+ x = x / mag;
+ y = y / mag;
+ z = z / mag;
+ }
+
+ inline GloxPoint<NumT> toPoint() { return GloxPoint<NumT>(x, y, z); }
+
+ inline std::string toString() const {
+ std::stringstream stream;
+ stream << "( " << x << ", " << y << ", " << z << " )";
+ return stream.str();
+ }
+
+ private:
+ NumT x;
+ NumT y;
+ NumT z;
};
-}
+} // namespace glox
#endif /* GLOXVECTOR3_HPP_ */
diff --git a/glox/glox/GloxVector4.hpp b/glox/glox/GloxVector4.hpp
index 6aeecfc..d906d2a 100644
--- a/glox/glox/GloxVector4.hpp
+++ b/glox/glox/GloxVector4.hpp
@@ -7,54 +7,54 @@
* GloxVector4.hpp: <description>
*/
-#include <string>
#include <sstream>
+#include <string>
namespace glox {
-template <class NumT=float>
+template <class NumT = float>
class GloxVector4 {
-public:
- inline GloxVector4( const NumT& x=0, const NumT& y=0, const NumT& z=0, const NumT& w=0 ) :
- x( x ), y( y ), z( z ), w( w ) {}
-
- inline const NumT& getX() const { return x; }
- inline const NumT& getY() const { return y; }
- inline const NumT& getZ() const { return z; }
- inline const NumT& getW() const { return w; }
-
- inline const NumT& get0() const { return x; }
- inline const NumT& get1() const { return y; }
- inline const NumT& get2() const { return z; }
- inline const NumT& get3() const { return w; }
-
- inline void setX( const NumT& x ) { this->x = x; }
- inline void setY( const NumT& y ) { this->y = y; }
- inline void setZ( const NumT& z ) { this->z = z; }
- inline void setW( const NumT& w ) { this->w = w; }
-
- inline bool isZero() {
- return x == 0 && y == 0 && z == 0 && w == 0 ;
- }
-
- inline void operator+=(const GloxVector4& other ) {
- x += other.x;
- y += other.y;
- z += other.z;
- w += other.w;
- }
-
- inline std::string toString() const {
- std::stringstream stream;
- stream << "( " << x << ", " << y << ", " << z << ", " << w << " )";
- return stream.str();
- }
-private:
- NumT x;
- NumT y;
- NumT z;
- NumT w;
+ public:
+ inline GloxVector4(const NumT& x = 0, const NumT& y = 0, const NumT& z = 0,
+ const NumT& w = 0)
+ : x(x), y(y), z(z), w(w) {}
+
+ inline const NumT& getX() const { return x; }
+ inline const NumT& getY() const { return y; }
+ inline const NumT& getZ() const { return z; }
+ inline const NumT& getW() const { return w; }
+
+ inline const NumT& get0() const { return x; }
+ inline const NumT& get1() const { return y; }
+ inline const NumT& get2() const { return z; }
+ inline const NumT& get3() const { return w; }
+
+ inline void setX(const NumT& x) { this->x = x; }
+ inline void setY(const NumT& y) { this->y = y; }
+ inline void setZ(const NumT& z) { this->z = z; }
+ inline void setW(const NumT& w) { this->w = w; }
+
+ inline bool isZero() { return x == 0 && y == 0 && z == 0 && w == 0; }
+
+ inline void operator+=(const GloxVector4& other) {
+ x += other.x;
+ y += other.y;
+ z += other.z;
+ w += other.w;
+ }
+
+ inline std::string toString() const {
+ std::stringstream stream;
+ stream << "( " << x << ", " << y << ", " << z << ", " << w << " )";
+ return stream.str();
+ }
+
+ private:
+ NumT x;
+ NumT y;
+ NumT z;
+ NumT w;
};
-}
+} // namespace glox
#endif /* GLOXVECTOR4_HPP_ */
diff --git a/glox/glox/GloxVectorizable.hpp b/glox/glox/GloxVectorizable.hpp
index 5f84cd0..bdb4690 100644
--- a/glox/glox/GloxVectorizable.hpp
+++ b/glox/glox/GloxVectorizable.hpp
@@ -13,21 +13,19 @@
namespace glox {
-template <class NumT=float>
+template <class NumT = float>
class GloxVectorizable {
-public:
- /* All vectors must be able to be multiplied
+ public:
+ /* All vectors must be able to be multiplied
* by a scalar */
- virtual void scale( NumT amt ) = 0;
- inline GloxVectorizable<NumT>& operator*=( NumT amt ) { scale( amt ); };
+ virtual void scale(NumT amt) = 0;
+ inline GloxVectorizable<NumT>& operator*=(NumT amt) { scale(amt); };
- /* Creates a primitive vector and returns
+ /* Creates a primitive vector and returns
* the number of elements stored */
- virtual int toVector( NumT* arr, size_t len ) const = 0;
+ virtual int toVector(NumT* arr, size_t len) const = 0;
};
-}
-
-
+} // namespace glox
#endif /* GLOXVECTORIZABLE_HPP_ */
diff --git a/glox/glox/GloxViewport.hpp b/glox/glox/GloxViewport.hpp
index 785e315..877a817 100644
--- a/glox/glox/GloxViewport.hpp
+++ b/glox/glox/GloxViewport.hpp
@@ -10,28 +10,27 @@
#include "glox/GloxRenderable.hpp"
namespace glox {
- class GloxViewport : public GloxRenderable {
- public:
- inline GloxViewport( int x=0, int y=0, int width=0, int height=0 ) :
- m_x( x ), m_y( y ), m_width( width ), m_height( height ) {}
-
- inline void render() const {
- glViewport( m_x, m_y, m_width, m_height );
- }
-
- inline void setX( int x ) { m_x = x ; }
- inline void setY( int y ) { m_y = y ; }
-
- inline void setWidth( int width ) { m_width = width; }
- inline void setHeight( int height ) { m_height = height; }
-
- inline double getAspectRatio() { return (double)m_width / (double)m_height ; }
- private:
- int m_x;
- int m_y;
- int m_width;
- int m_height;
- };
-}
+class GloxViewport : public GloxRenderable {
+ public:
+ inline GloxViewport(int x = 0, int y = 0, int width = 0, int height = 0)
+ : m_x(x), m_y(y), m_width(width), m_height(height) {}
+
+ inline void render() const { glViewport(m_x, m_y, m_width, m_height); }
+
+ inline void setX(int x) { m_x = x; }
+ inline void setY(int y) { m_y = y; }
+
+ inline void setWidth(int width) { m_width = width; }
+ inline void setHeight(int height) { m_height = height; }
+
+ inline double getAspectRatio() { return (double)m_width / (double)m_height; }
+
+ private:
+ int m_x;
+ int m_y;
+ int m_width;
+ int m_height;
+};
+} // namespace glox
#endif /* GLOXVIEWPORT_HPP_ */
diff --git a/glox/glox/src/GloxCube.cpp b/glox/glox/src/GloxCube.cpp
index 91204ef..eb7a72e 100644
--- a/glox/glox/src/GloxCube.cpp
+++ b/glox/glox/src/GloxCube.cpp
@@ -3,80 +3,80 @@
namespace glox {
-GloxCube::GloxCube( float x, float y, float z, const GloxColor& color ) :
- m_color( color ) {
- float halfx = x / 2;
- float halfy = y / 2;
- float halfz = z / 2;
+GloxCube::GloxCube(float x, float y, float z, const GloxColor& color)
+ : m_color(color) {
+ float halfx = x / 2;
+ float halfy = y / 2;
+ float halfz = z / 2;
- m_disp_list = glGenLists( 1 );
- GloxNormal<> normal(0,0,0);
- glNewList( m_disp_list, GL_COMPILE );
- /* The points for the top */
- normal.setY( 1 );
- normal.plot();
- GloxPoint<> ( -halfx, halfy, halfz ).plot();
- GloxPoint<> ( halfx, halfy, halfz ).plot();
- GloxPoint<> ( halfx, halfy,-halfz ).plot();
- GloxPoint<> ( -halfx, halfy,-halfz ).plot();
+ m_disp_list = glGenLists(1);
+ GloxNormal<> normal(0, 0, 0);
+ glNewList(m_disp_list, GL_COMPILE);
+ /* The points for the top */
+ normal.setY(1);
+ normal.plot();
+ GloxPoint<>(-halfx, halfy, halfz).plot();
+ GloxPoint<>(halfx, halfy, halfz).plot();
+ GloxPoint<>(halfx, halfy, -halfz).plot();
+ GloxPoint<>(-halfx, halfy, -halfz).plot();
- /* The points for the bottom */
- normal.setY( -1 );
- normal.plot();
- GloxPoint<> ( -halfx,-halfy, halfz ).plot();
- GloxPoint<> ( halfx,-halfy, halfz ).plot();
- GloxPoint<> ( halfx,-halfy,-halfz ).plot();
- GloxPoint<> ( -halfx,-halfy,-halfz ).plot();
- normal.setY( 0 ) ;
-
- /* The points for the front */
- normal.setZ( 1 );
- normal.plot();
- GloxPoint<> ( -halfx, halfy, halfz ).plot();
- GloxPoint<> ( halfx, halfy, halfz ).plot();
- GloxPoint<> ( halfx,-halfy, halfz ).plot();
- GloxPoint<> ( -halfx,-halfy, halfz ).plot();
+ /* The points for the bottom */
+ normal.setY(-1);
+ normal.plot();
+ GloxPoint<>(-halfx, -halfy, halfz).plot();
+ GloxPoint<>(halfx, -halfy, halfz).plot();
+ GloxPoint<>(halfx, -halfy, -halfz).plot();
+ GloxPoint<>(-halfx, -halfy, -halfz).plot();
+ normal.setY(0);
- /* The points for the back */
- normal.setZ( -1 );
- normal.plot();
- GloxPoint<> ( -halfx, halfy,-halfz ).plot();
- GloxPoint<> ( halfx, halfy,-halfz ).plot();
- GloxPoint<> ( halfx,-halfy,-halfz ).plot();
- GloxPoint<> ( -halfx,-halfy,-halfz ).plot();
- normal.setZ( 0 );
-
- /* The points for the right */
- normal.setX( 1 );
- normal.plot();
- GloxPoint<> ( halfx, -halfy, halfz ).plot();
- GloxPoint<> ( halfx, halfy, halfz ).plot();
- GloxPoint<> ( halfx, halfy,-halfz ).plot();
- GloxPoint<> ( halfx, -halfy,-halfz ).plot();
+ /* The points for the front */
+ normal.setZ(1);
+ normal.plot();
+ GloxPoint<>(-halfx, halfy, halfz).plot();
+ GloxPoint<>(halfx, halfy, halfz).plot();
+ GloxPoint<>(halfx, -halfy, halfz).plot();
+ GloxPoint<>(-halfx, -halfy, halfz).plot();
- /* The points for the right */
- normal.setX( -1 );
- normal.plot();
- GloxPoint<> ( -halfx, -halfy, halfz ).plot();
- GloxPoint<> ( -halfx, halfy, halfz ).plot();
- GloxPoint<> ( -halfx, halfy,-halfz ).plot();
- GloxPoint<> ( -halfx, -halfy,-halfz ).plot();
+ /* The points for the back */
+ normal.setZ(-1);
+ normal.plot();
+ GloxPoint<>(-halfx, halfy, -halfz).plot();
+ GloxPoint<>(halfx, halfy, -halfz).plot();
+ GloxPoint<>(halfx, -halfy, -halfz).plot();
+ GloxPoint<>(-halfx, -halfy, -halfz).plot();
+ normal.setZ(0);
- glEndList();
+ /* The points for the right */
+ normal.setX(1);
+ normal.plot();
+ GloxPoint<>(halfx, -halfy, halfz).plot();
+ GloxPoint<>(halfx, halfy, halfz).plot();
+ GloxPoint<>(halfx, halfy, -halfz).plot();
+ GloxPoint<>(halfx, -halfy, -halfz).plot();
+
+ /* The points for the right */
+ normal.setX(-1);
+ normal.plot();
+ GloxPoint<>(-halfx, -halfy, halfz).plot();
+ GloxPoint<>(-halfx, halfy, halfz).plot();
+ GloxPoint<>(-halfx, halfy, -halfz).plot();
+ GloxPoint<>(-halfx, -halfy, -halfz).plot();
+
+ glEndList();
}
void GloxCube::draw() const {
- /* Save current attributes for this scope */
- GloxScopedAttributes __sca( GL_CURRENT_BIT );
- GloxScopedBegin __sbgn( GL_QUADS );
+ /* Save current attributes for this scope */
+ GloxScopedAttributes __sca(GL_CURRENT_BIT);
+ GloxScopedBegin __sbgn(GL_QUADS);
- /* The normal to use for plotting */
- GloxNormal<> normal(0,0,0);
+ /* The normal to use for plotting */
+ GloxNormal<> normal(0, 0, 0);
- /* Render this color */
- m_color.render();
+ /* Render this color */
+ m_color.render();
- glCallList( m_disp_list );
+ glCallList(m_disp_list);
}
-}
+} // namespace glox
diff --git a/glox/glox/src/GloxCylinder.cpp b/glox/glox/src/GloxCylinder.cpp
index 3eb9840..9e72b45 100644
--- a/glox/glox/src/GloxCylinder.cpp
+++ b/glox/glox/src/GloxCylinder.cpp
@@ -4,53 +4,55 @@
namespace glox {
-GloxCylinder::GloxCylinder( const GloxPoint<float>& pos, float r, float h, float th_res, const GloxTexture* texture, bool normals, float rep, float repy ) :
- m_position( pos ) {
- float th = 0;
- m_texture = texture;
+GloxCylinder::GloxCylinder(const GloxPoint<float>& pos, float r, float h,
+ float th_res, const GloxTexture* texture,
+ bool normals, float rep, float repy)
+ : m_position(pos) {
+ float th = 0;
+ m_texture = texture;
- GloxPoint<> point;
- GloxNormal<> normal;
- GloxPoint<> texPoint;
+ GloxPoint<> point;
+ GloxNormal<> normal;
+ GloxPoint<> texPoint;
- float texStep;
+ float texStep;
- /* The position in the texture */
- float texPos = 0;
+ /* The position in the texture */
+ float texPos = 0;
- if( m_texture ) {
- /* We want the texture to map exactly
+ if (m_texture) {
+ /* We want the texture to map exactly
* to the sphere */
- texStep = th_res / 360 * rep;
+ texStep = th_res / 360 * rep;
+ }
+
+ for (; th <= 360; th += th_res, texPos += texStep) {
+ point.setX(r * GloxCos(th));
+ point.setZ(r * GloxSin(th));
+ point.setY(0);
+
+ if (normals) {
+ normal.setX(point.getX());
+ normal.setY(0);
+ normal.setZ(point.getZ());
}
- for( ; th <= 360; th += th_res, texPos += texStep ) {
- point.setX( r * GloxCos( th ) );
- point.setZ( r * GloxSin( th ) );
- point.setY( 0 );
+ texPoint.setX(texPos);
+ texPoint.setY(repy);
+ texPoint.setZ(0);
- if( normals ) {
- normal.setX( point.getX() );
- normal.setY( 0 );
- normal.setZ( point.getZ() );
- }
-
- texPoint.setX( texPos );
- texPoint.setY( repy );
- texPoint.setZ( 0 );
-
- /* Add the new PointNormal to the
+ /* Add the new PointNormal to the
* body */
- m_body.addPoint( GloxPointNormalTexture( point, normal, texPoint ) );
+ m_body.addPoint(GloxPointNormalTexture(point, normal, texPoint));
- /* The upper portion of the
+ /* The upper portion of the
* cylinder */
- point.setY( h );
- texPoint.setY( 0 );
+ point.setY(h);
+ texPoint.setY(0);
- // The normal remains the same
- m_body.addPoint( GloxPointNormalTexture( point, normal, texPoint ) );
- }
+ // The normal remains the same
+ m_body.addPoint(GloxPointNormalTexture(point, normal, texPoint));
+ }
}
-}
+} // namespace glox
diff --git a/glox/glox/src/GloxFirstPersonPerspective.cpp b/glox/glox/src/GloxFirstPersonPerspective.cpp
index 6459286..cad8e5d 100644
--- a/glox/glox/src/GloxFirstPersonPerspective.cpp
+++ b/glox/glox/src/GloxFirstPersonPerspective.cpp
@@ -1,31 +1,33 @@
-#include "glox/GloxCommon.hpp"
#include "glox/GloxFirstPersonPerspective.hpp"
-#include "glox/GloxState.hpp"
+#include "glox/GloxCommon.hpp"
#include "glox/GloxDebug.hpp"
+#include "glox/GloxState.hpp"
#include <GL/glu.h>
namespace glox {
void GloxFirstPersonPerspective::render() const {
- /* The point we are going to look at in first
+ /* The point we are going to look at in first
* person mode */
- GloxPoint<> lookat = GloxPoint<>::fromSpherical( 1.0f, m_yaw, m_pitch );
+ GloxPoint<> lookat = GloxPoint<>::fromSpherical(1.0f, m_yaw, m_pitch);
- /* translate the lookat to this
+ /* translate the lookat to this
* position */
- const GloxPoint<>& pos = this->getPosition();
- GloxPoint<> upvec = GloxPoint<>::fromSpherical( 1.0f, GloxSin(m_roll) * m_yaw, GloxCos(m_roll) * m_pitch + 90 );
- lookat += pos;
-
- GloxTrace( "GloxFirstPersonPerspective", "gluLookAt %s %s %s\n", pos.toString().c_str(), lookat.toString().c_str(), upvec.toString().c_str() );
- GloxTrace( "GloxFirstPersonPerspective", "(%f, %f, %f)\n", m_roll, m_pitch, m_yaw );
- /* Deal with roll */
-
- gluLookAt( pos.getX(), pos.getY(), pos.getZ(),
- lookat.getX(), lookat.getY(), lookat.getZ(),
- 0, 1, 0 );
-
+ const GloxPoint<>& pos = this->getPosition();
+ GloxPoint<> upvec = GloxPoint<>::fromSpherical(
+ 1.0f, GloxSin(m_roll) * m_yaw, GloxCos(m_roll) * m_pitch + 90);
+ lookat += pos;
+
+ GloxTrace("GloxFirstPersonPerspective", "gluLookAt %s %s %s\n",
+ pos.toString().c_str(), lookat.toString().c_str(),
+ upvec.toString().c_str());
+ GloxTrace("GloxFirstPersonPerspective", "(%f, %f, %f)\n", m_roll, m_pitch,
+ m_yaw);
+ /* Deal with roll */
+
+ gluLookAt(pos.getX(), pos.getY(), pos.getZ(), lookat.getX(), lookat.getY(),
+ lookat.getZ(), 0, 1, 0);
}
-}
+} // namespace glox
diff --git a/glox/glox/src/GloxLightSource.cpp b/glox/glox/src/GloxLightSource.cpp
index 9917d71..8c4a516 100644
--- a/glox/glox/src/GloxLightSource.cpp
+++ b/glox/glox/src/GloxLightSource.cpp
@@ -3,46 +3,45 @@
namespace glox {
void GloxLightSource::render() const {
- if( ! this->isEnabled() ) {
- GloxTrace( "GloxLightSource", "Light %d Disabled\n", index );
- return ;
- }
-
- for( M_lm_map_t::const_iterator itr = lightModelsAttrs.begin();
- /* Set all of the attributes in the map */
- itr != lightModelsAttrs.end() ; ++ itr ) {
- glLightModelf( (*itr).first, (*itr).second );
- }
-
- float vec[4];
- for( M_lm_map_vec_t::const_iterator itr = lightModelsAttrs_vectors.begin();
- /* Set all of the attributes in the map */
- itr != lightModelsAttrs_vectors.end() ; ++ itr ) {
- (*itr).second.toVector( vec, 4 );
- glLightModelfv( (*itr).first, vec );
- }
-
- glEnable( m_light );
-
- this->ambient.toVector( vec, 4 );
- //GloxTrace( "GloxLightSource", "ambient: {%f, %f, %f, %f}\n", vec[0], vec[1], vec[2], vec[3] );
- glLightfv(m_light,GL_AMBIENT, vec);
-
- this->diffuse.toVector( vec, 4 );
- //GloxTrace( "GloxLightSource", "diffuse: %s\n", this->diffuse.toString().c_str() );
- //GloxTrace( "GloxLightSource", "diffuse: {%f, %f, %f, %f}\n", vec[0], vec[1], vec[2], vec[3] );
- glLightfv(m_light,GL_DIFFUSE ,vec);
-
- this->specular.toVector( vec, 4 );
- //GloxTrace( "GloxLightSource", "specular: {%f, %f, %f, %f}\n", vec[0], vec[1], vec[2], vec[3] );
- glLightfv(m_light,GL_SPECULAR,vec);
-
-
- /* enable this light */
- glEnable( this->m_light );
- this->m_pos.toVector( vec, 4 );
-
- glLightfv(m_light,GL_POSITION,vec);
+ if (!this->isEnabled()) {
+ GloxTrace("GloxLightSource", "Light %d Disabled\n", index);
+ return;
+ }
+
+ for (M_lm_map_t::const_iterator itr = lightModelsAttrs.begin();
+ /* Set all of the attributes in the map */
+ itr != lightModelsAttrs.end(); ++itr) {
+ glLightModelf((*itr).first, (*itr).second);
+ }
+
+ float vec[4];
+ for (M_lm_map_vec_t::const_iterator itr = lightModelsAttrs_vectors.begin();
+ /* Set all of the attributes in the map */
+ itr != lightModelsAttrs_vectors.end(); ++itr) {
+ (*itr).second.toVector(vec, 4);
+ glLightModelfv((*itr).first, vec);
+ }
+
+ glEnable(m_light);
+
+ this->ambient.toVector(vec, 4);
+ //GloxTrace( "GloxLightSource", "ambient: {%f, %f, %f, %f}\n", vec[0], vec[1], vec[2], vec[3] );
+ glLightfv(m_light, GL_AMBIENT, vec);
+
+ this->diffuse.toVector(vec, 4);
+ //GloxTrace( "GloxLightSource", "diffuse: %s\n", this->diffuse.toString().c_str() );
+ //GloxTrace( "GloxLightSource", "diffuse: {%f, %f, %f, %f}\n", vec[0], vec[1], vec[2], vec[3] );
+ glLightfv(m_light, GL_DIFFUSE, vec);
+
+ this->specular.toVector(vec, 4);
+ //GloxTrace( "GloxLightSource", "specular: {%f, %f, %f, %f}\n", vec[0], vec[1], vec[2], vec[3] );
+ glLightfv(m_light, GL_SPECULAR, vec);
+
+ /* enable this light */
+ glEnable(this->m_light);
+ this->m_pos.toVector(vec, 4);
+
+ glLightfv(m_light, GL_POSITION, vec);
}
-}
+} // namespace glox
diff --git a/glox/glox/src/GloxLightSourceManager.cpp b/glox/glox/src/GloxLightSourceManager.cpp
index 5ce2c0d..d2bcc79 100644
--- a/glox/glox/src/GloxLightSourceManager.cpp
+++ b/glox/glox/src/GloxLightSourceManager.cpp
@@ -1,44 +1,37 @@
#include "glox/GloxLightSourceManager.hpp"
-#include "glox/GloxState.hpp"
#include <iostream>
+#include "glox/GloxState.hpp"
using namespace std;
namespace glox {
int light_source_gl[] = {
- GL_LIGHT0,
- GL_LIGHT1,
- GL_LIGHT2,
- GL_LIGHT2,
- GL_LIGHT3,
- GL_LIGHT4,
- GL_LIGHT5,
- GL_LIGHT6,
- GL_LIGHT7,
+ GL_LIGHT0, GL_LIGHT1, GL_LIGHT2, GL_LIGHT2, GL_LIGHT3,
+ GL_LIGHT4, GL_LIGHT5, GL_LIGHT6, GL_LIGHT7,
};
void GloxLightSourceManager::render() const {
- GloxState::enable( GL_NORMALIZE );
- GloxState::enable( GL_LIGHTING );
- GloxState::colorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE);
- GloxState::enable(GL_COLOR_MATERIAL);
-
- for ( size_t i = 0 ; i < GLOX_MAX_NUM_LIGHTS; ++ i ) {
- if( m_sources[i] && m_sources[i]->isEnabled() ) {
- m_sources[i]->render();
- }
- }
+ GloxState::enable(GL_NORMALIZE);
+ GloxState::enable(GL_LIGHTING);
+ GloxState::colorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
+ GloxState::enable(GL_COLOR_MATERIAL);
+
+ for (size_t i = 0; i < GLOX_MAX_NUM_LIGHTS; ++i) {
+ if (m_sources[i] && m_sources[i]->isEnabled()) {
+ m_sources[i]->render();
+ }
+ }
}
-GloxLightSource* GloxLightSourceManager::getLightSource( int id ) {
- if( m_sources[id] ) {
- return m_sources[id];
- }
+GloxLightSource* GloxLightSourceManager::getLightSource(int id) {
+ if (m_sources[id]) {
+ return m_sources[id];
+ }
- GloxLightSource* lightSource = new GloxLightSource( light_source_gl[id] );
- m_sources[id] = lightSource;
+ GloxLightSource* lightSource = new GloxLightSource(light_source_gl[id]);
+ m_sources[id] = lightSource;
- return lightSource;
+ return lightSource;
}
-}
+} // namespace glox
diff --git a/glox/glox/src/GloxProgram.cpp b/glox/glox/src/GloxProgram.cpp
index df79bf0..7f2ab2b 100644
--- a/glox/glox/src/GloxProgram.cpp
+++ b/glox/glox/src/GloxProgram.cpp
@@ -2,88 +2,88 @@
#include <iostream>
-using namespace glox ;
-using namespace std ;
+using namespace glox;
+using namespace std;
-GloxProgram::GloxProgram( ) {
- // cout << "Creating program2" << endl;
- this->id = glCreateProgram() ;
- // cout << "Done making program" << endl ;
+GloxProgram::GloxProgram() {
+ // cout << "Creating program2" << endl;
+ this->id = glCreateProgram();
+ // cout << "Done making program" << endl ;
}
-int GloxProgram::attachShader( const GloxShader& shader ) {
- int shader_id = shader.getId() ;
- glAttachShader( this->id, shader_id ) ;
- return 0 ;
+int GloxProgram::attachShader(const GloxShader& shader) {
+ int shader_id = shader.getId();
+ glAttachShader(this->id, shader_id);
+ return 0;
}
-int GloxProgram::attachShaderFromFile( const char* filename, GLenum type ) {
- GloxShader shader( type ) ;
- int ret = shader.load( filename ) ;
- if( ! ret ) {
- return this->attachShader( shader );
- }
- return ret ;
+int GloxProgram::attachShaderFromFile(const char* filename, GLenum type) {
+ GloxShader shader(type);
+ int ret = shader.load(filename);
+ if (!ret) {
+ return this->attachShader(shader);
+ }
+ return ret;
}
-int GloxProgram::getUniformLocation( const char* uniform ) {
- return glGetUniformLocation(this->id, uniform);
+int GloxProgram::getUniformLocation(const char* uniform) {
+ return glGetUniformLocation(this->id, uniform);
}
void GloxProgram::render() const {
- glUseProgram( this->id );
+ glUseProgram(this->id);
}
-void setUniformVector3( int uniform, const std::vector< GloxVector3<> >& vec ) {
- int len = vec.size() * 3 ;
- float* arr = new float[len] ;
+void setUniformVector3(int uniform, const std::vector<GloxVector3<>>& vec) {
+ int len = vec.size() * 3;
+ float* arr = new float[len];
- for( size_t i = 0 ; i < vec.size() ; ++ i ) {
- arr[i * 3 + 0] = vec[i].get0();
- arr[i * 3 + 1] = vec[i].get1();
- arr[i * 3 + 2] = vec[i].get2();
- }
+ for (size_t i = 0; i < vec.size(); ++i) {
+ arr[i * 3 + 0] = vec[i].get0();
+ arr[i * 3 + 1] = vec[i].get1();
+ arr[i * 3 + 2] = vec[i].get2();
+ }
- glUniform3fv(uniform, vec.size(), arr);
+ glUniform3fv(uniform, vec.size(), arr);
}
-void setUniformVector3( int uniform, const std::vector< GloxVector4<> >& vec ) {
- int len = vec.size() * 4 ;
- float* arr = new float[len] ;
+void setUniformVector3(int uniform, const std::vector<GloxVector4<>>& vec) {
+ int len = vec.size() * 4;
+ float* arr = new float[len];
- for( size_t i = 0 ; i < vec.size() ; ++ i ) {
- arr[i * 4 + 0] = vec[i].get0();
- arr[i * 4 + 1] = vec[i].get1();
- arr[i * 4 + 2] = vec[i].get2();
- }
+ for (size_t i = 0; i < vec.size(); ++i) {
+ arr[i * 4 + 0] = vec[i].get0();
+ arr[i * 4 + 1] = vec[i].get1();
+ arr[i * 4 + 2] = vec[i].get2();
+ }
- glUniform4fv(uniform, vec.size(), arr);
+ glUniform4fv(uniform, vec.size(), arr);
}
void GloxProgram::unloadPrograms() {
- glUseProgram( 0 ) ;
+ glUseProgram(0);
}
int GloxProgram::link() {
- int result ;
- glLinkProgram( id );
- glGetProgramiv( id , GL_LINK_STATUS, &result);
+ int result;
+ glLinkProgram(id);
+ glGetProgramiv(id, GL_LINK_STATUS, &result);
- if(result == GL_FALSE) {
- GLint length;
- char *log;
+ if (result == GL_FALSE) {
+ GLint length;
+ char* log;
- /* get the program info log */
- glGetProgramiv( id , GL_INFO_LOG_LENGTH, &length);
- log = new char[length];
- glGetProgramInfoLog( id , length, &result, log);
+ /* get the program info log */
+ glGetProgramiv(id, GL_INFO_LOG_LENGTH, &length);
+ log = new char[length];
+ glGetProgramInfoLog(id, length, &result, log);
- /* print an error message and the info log */
- fprintf(stderr, "Program linking failed: %s\n", log);
- free(log);
+ /* print an error message and the info log */
+ fprintf(stderr, "Program linking failed: %s\n", log);
+ free(log);
- return -1 ;
- }
+ return -1;
+ }
- return 0 ;
+ return 0;
}
diff --git a/glox/glox/src/GloxShader.cpp b/glox/glox/src/GloxShader.cpp
index 3516189..265b9db 100644
--- a/glox/glox/src/GloxShader.cpp
+++ b/glox/glox/src/GloxShader.cpp
@@ -1,71 +1,72 @@
#include "glox/GloxShader.hpp"
-#include <iostream>
#include <fstream>
+#include <iostream>
#include <sstream>
-using namespace glox ;
-using namespace std ;
+using namespace glox;
+using namespace std;
-string GloxShader::message ;
+string GloxShader::message;
-int GloxShader::readFile( const char* filename, string& into ) {
- ifstream stream ;
- stream.open( filename ) ;
- stringstream sstream ;
+int GloxShader::readFile(const char* filename, string& into) {
+ ifstream stream;
+ stream.open(filename);
+ stringstream sstream;
- std::string line ;
+ std::string line;
- if( ! stream ) {
- message = string( "Unable to open file ") + filename + " for read" ;
- return -1 ;
- }
+ if (!stream) {
+ message = string("Unable to open file ") + filename + " for read";
+ return -1;
+ }
- while ( ! stream.eof() ) {
- getline( stream, line ) ;
- sstream << line << "\n" ;
- }
+ while (!stream.eof()) {
+ getline(stream, line);
+ sstream << line << "\n";
+ }
- into = sstream.str();
+ into = sstream.str();
- return 0 ;
+ return 0;
}
-int GloxShader::load( const char* filename) {
- std::string contents ;
+int GloxShader::load(const char* filename) {
+ std::string contents;
- if( readFile( filename, contents ) < 0 ) {
- return -1 ;
- }
+ if (readFile(filename, contents) < 0) {
+ return -1;
+ }
- m_shader = glCreateShader( this->type ) ;
- const char* source = contents.c_str();
- int len = contents.length();
- glShaderSource( m_shader, 1, & source, &len ) ;
- glCompileShader( m_shader ) ;
+ m_shader = glCreateShader(this->type);
+ const char* source = contents.c_str();
+ int len = contents.length();
+ glShaderSource(m_shader, 1, &source, &len);
+ glCompileShader(m_shader);
- int result, length ;
- glGetShaderiv(m_shader, GL_COMPILE_STATUS, &result);
- if( result == GL_FALSE ) {
- char *log;
+ int result, length;
+ glGetShaderiv(m_shader, GL_COMPILE_STATUS, &result);
+ if (result == GL_FALSE) {
+ char* log;
- glGetShaderiv(m_shader, GL_INFO_LOG_LENGTH, &length);
- log = new char[length];
- glGetShaderInfoLog(m_shader, length, &result, log);
+ glGetShaderiv(m_shader, GL_INFO_LOG_LENGTH, &length);
+ log = new char[length];
+ glGetShaderInfoLog(m_shader, length, &result, log);
- fprintf(stderr, "shaderCompileFromFile(): Unable to compile %s: %s\n", filename, log);
- free(log);
+ fprintf(stderr, "shaderCompileFromFile(): Unable to compile %s: %s\n",
+ filename, log);
+ free(log);
- glDeleteShader(m_shader);
+ glDeleteShader(m_shader);
- cerr << "Returning with error code -1" << endl ;
- return -1 ;
- }
+ cerr << "Returning with error code -1" << endl;
+ return -1;
+ }
- return 0 ;
+ return 0;
}
GloxShader::~GloxShader() {
- glDeleteShader( m_shader ) ;
+ glDeleteShader(m_shader);
}
diff --git a/glox/glox/src/GloxTextureFactory.cpp b/glox/glox/src/GloxTextureFactory.cpp
index 4cb5904..8b0037a 100644
--- a/glox/glox/src/GloxTextureFactory.cpp
+++ b/glox/glox/src/GloxTextureFactory.cpp
@@ -1,11 +1,11 @@
#include "glox/GloxTextureFactory.hpp"
-#include "glox/GloxTexture.hpp"
#include "glox/GloxCommon.hpp"
+#include "glox/GloxTexture.hpp"
#include "glox/GloxDebug.hpp"
-#include <sstream>
#include <GL/glu.h>
+#include <sstream>
#define BMP_MAGIC_LE 0x4D42
#define BMP_MAGIC_BE 0x424D
@@ -14,129 +14,129 @@ using namespace std;
namespace glox {
-static void revendian(void* x,const int n) {
- int k;
- char* ch = (char*)x;
- for (k=0;k<n/2;k++)
- {
- char tmp = ch[k];
- ch[k] = ch[n-1-k];
- ch[n-1-k] = tmp;
- }
+static void revendian(void* x, const int n) {
+ int k;
+ char* ch = (char*)x;
+ for (k = 0; k < n / 2; k++) {
+ char tmp = ch[k];
+ ch[k] = ch[n - 1 - k];
+ ch[n - 1 - k] = tmp;
+ }
}
std::string error_str;
const std::string& GloxTextureFactory::getErrorMessage() {
- return error_str;
+ return error_str;
}
-GloxTexture* GloxTextureFactory::textureFromBitmap( std::istream& stream ) {
- unsigned int texture;
- unsigned short magic;
- unsigned int dx,dy,size;
- unsigned short nbp,bpp;
- unsigned char* image;
- unsigned int k;
- int max;
-
- stream.read( (char*)&magic, 2 );
-
- if( magic != BMP_MAGIC_LE && magic != BMP_MAGIC_BE ) {
- error_str = "Bad magic number for bitmap\n";
- return NULL;
- }
-
- stream.seekg( 16, stream.cur );
- stream.read( (char*)&dx, 4 );
- stream.read( (char*)&dy, 4 );
- stream.read( (char*)&nbp, 2 );
- stream.read( (char*)&bpp, 2 );
- stream.read( (char*)&k, 4 );
-
- GloxTrace( "GloxTextureFactory", "dx = %d, dy = %d, nbp = %d, bpp = %d, k = %d\n",
- dx, dy, nbp, bpp, k );
-
- if( magic == BMP_MAGIC_BE ) {
- revendian( &dx, sizeof( dx ) );
- revendian( &dy, sizeof( dy ) );
- revendian( &nbp, sizeof( nbp ) );
- revendian( &bpp, sizeof( bpp ) );
- revendian( &k, sizeof( k ) );
- }
-
- glGetIntegerv( GL_MAX_TEXTURE_SIZE, &max );
-
- stringstream error;
-
- if ( dx < 1 || dx > (unsigned int)max) {
- error << "Image width " << dx << " out of range 1-" << max << "\n";
- error_str = error.str();
- return NULL;
- }
- if ( dy < 1 || dy > (unsigned int)max) {
- error << "Image height " << dy << " out of range 1-" << max << "\n";
- error_str = error.str();
- return NULL;
- }
- if ( nbp != 1) {
- error << "Bit planes is not 1: " << nbp << "\n";
- error_str = error.str();
- return NULL;
- }
- if ( bpp != 24) {
- error << "Bits per pixel is not 24: " << bpp << "\n";
- error_str = error.str();
- return NULL;
- }
- if ( k != 0) {
- error_str = "Compressed files not supported\n";
- return NULL;
- }
-
- size = 3 * dx * dy;
- image = new uint8_t[size];
-
- if( ! image ) {
- error_str = "Not enough memory for image\n";
- return NULL;
- }
-
- stream.seekg( 20, stream.cur );
- stream.read( (char*)image, size );
- for( k = 0; k < size; k += 3 ) {
- uint8_t temp = image[k];
- image[k] = image[k+2];
- image[k+2] = temp;
- }
-
- int err = glGetError();
- if (err){
- error_str = std::string((char*)gluErrorString(err));
- delete[] image;
- return NULL;
- }
-
- glGenTextures( 1, &texture );
- glBindTexture( GL_TEXTURE_2D, texture );
- glTexImage2D( GL_TEXTURE_2D, 0, 3, dx, dy, 0, GL_RGB, GL_UNSIGNED_BYTE, image );
-
- err = glGetError();
- if( err ) {
- error_str = std::string((char*)gluErrorString(err));
- delete[] image;
- return NULL;
- }
-
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
-
- GloxDebug( "GloxTextureFactory", "Loaded Texture. First pixel: (%d, %d, %d)\n",
- image[0], image[1], image[2] );
-
- delete[] image;
-
- return new GloxTexture( texture );
+GloxTexture* GloxTextureFactory::textureFromBitmap(std::istream& stream) {
+ unsigned int texture;
+ unsigned short magic;
+ unsigned int dx, dy, size;
+ unsigned short nbp, bpp;
+ unsigned char* image;
+ unsigned int k;
+ int max;
+
+ stream.read((char*)&magic, 2);
+
+ if (magic != BMP_MAGIC_LE && magic != BMP_MAGIC_BE) {
+ error_str = "Bad magic number for bitmap\n";
+ return NULL;
+ }
+
+ stream.seekg(16, stream.cur);
+ stream.read((char*)&dx, 4);
+ stream.read((char*)&dy, 4);
+ stream.read((char*)&nbp, 2);
+ stream.read((char*)&bpp, 2);
+ stream.read((char*)&k, 4);
+
+ GloxTrace("GloxTextureFactory",
+ "dx = %d, dy = %d, nbp = %d, bpp = %d, k = %d\n", dx, dy, nbp, bpp,
+ k);
+
+ if (magic == BMP_MAGIC_BE) {
+ revendian(&dx, sizeof(dx));
+ revendian(&dy, sizeof(dy));
+ revendian(&nbp, sizeof(nbp));
+ revendian(&bpp, sizeof(bpp));
+ revendian(&k, sizeof(k));
+ }
+
+ glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max);
+
+ stringstream error;
+
+ if (dx < 1 || dx > (unsigned int)max) {
+ error << "Image width " << dx << " out of range 1-" << max << "\n";
+ error_str = error.str();
+ return NULL;
+ }
+ if (dy < 1 || dy > (unsigned int)max) {
+ error << "Image height " << dy << " out of range 1-" << max << "\n";
+ error_str = error.str();
+ return NULL;
+ }
+ if (nbp != 1) {
+ error << "Bit planes is not 1: " << nbp << "\n";
+ error_str = error.str();
+ return NULL;
+ }
+ if (bpp != 24) {
+ error << "Bits per pixel is not 24: " << bpp << "\n";
+ error_str = error.str();
+ return NULL;
+ }
+ if (k != 0) {
+ error_str = "Compressed files not supported\n";
+ return NULL;
+ }
+
+ size = 3 * dx * dy;
+ image = new uint8_t[size];
+
+ if (!image) {
+ error_str = "Not enough memory for image\n";
+ return NULL;
+ }
+
+ stream.seekg(20, stream.cur);
+ stream.read((char*)image, size);
+ for (k = 0; k < size; k += 3) {
+ uint8_t temp = image[k];
+ image[k] = image[k + 2];
+ image[k + 2] = temp;
+ }
+
+ int err = glGetError();
+ if (err) {
+ error_str = std::string((char*)gluErrorString(err));
+ delete[] image;
+ return NULL;
+ }
+
+ glGenTextures(1, &texture);
+ glBindTexture(GL_TEXTURE_2D, texture);
+ glTexImage2D(GL_TEXTURE_2D, 0, 3, dx, dy, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
+
+ err = glGetError();
+ if (err) {
+ error_str = std::string((char*)gluErrorString(err));
+ delete[] image;
+ return NULL;
+ }
+
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+
+ GloxDebug("GloxTextureFactory", "Loaded Texture. First pixel: (%d, %d, %d)\n",
+ image[0], image[1], image[2]);
+
+ delete[] image;
+
+ return new GloxTexture(texture);
}
-};
+}; // namespace glox
diff --git a/glox/glox/src/GloxTexturedCube.cpp b/glox/glox/src/GloxTexturedCube.cpp
index f56e146..a89e8ee 100644
--- a/glox/glox/src/GloxTexturedCube.cpp
+++ b/glox/glox/src/GloxTexturedCube.cpp
@@ -4,172 +4,194 @@
namespace glox {
void GloxTexturedCube::update_top() {
- m_top.clear();
+ m_top.clear();
- GloxNormal<> normal( 0, 1, 0 );
+ GloxNormal<> normal(0, 1, 0);
- /* The points for the top */
- m_top.add( GloxPointNormalTexture( GloxPoint<>(-m_half, m_half,-m_half),
- normal, GloxPoint<>(0,0)) );
+ /* The points for the top */
+ m_top.add(GloxPointNormalTexture(GloxPoint<>(-m_half, m_half, -m_half),
+ normal, GloxPoint<>(0, 0)));
- m_top.add( GloxPointNormalTexture( GloxPoint<>( m_half, m_half,-m_half),
- normal, GloxPoint<>(m_top_tex.getXReps(),0)) );
+ m_top.add(GloxPointNormalTexture(GloxPoint<>(m_half, m_half, -m_half), normal,
+ GloxPoint<>(m_top_tex.getXReps(), 0)));
- m_top.add( GloxPointNormalTexture( GloxPoint<>( m_half, m_half, m_half),
- normal, GloxPoint<>(m_top_tex.getXReps(),m_top_tex.getYReps())) );
+ m_top.add(GloxPointNormalTexture(
+ GloxPoint<>(m_half, m_half, m_half), normal,
+ GloxPoint<>(m_top_tex.getXReps(), m_top_tex.getYReps())));
- m_top.add( GloxPointNormalTexture( GloxPoint<>(-m_half, m_half, m_half),
- normal, GloxPoint<>(0,m_top_tex.getYReps())) );
+ m_top.add(GloxPointNormalTexture(GloxPoint<>(-m_half, m_half, m_half), normal,
+ GloxPoint<>(0, m_top_tex.getYReps())));
}
void GloxTexturedCube::update_bottom() {
- m_bottom.clear();
+ m_bottom.clear();
- GloxNormal<> normal( 0, -1, 0 );
+ GloxNormal<> normal(0, -1, 0);
- /* The points for the top */
- m_bottom.add( GloxPointNormalTexture( GloxPoint<>(-m_half,-m_half, m_half),
- normal, GloxPoint<>(0,0)) );
+ /* The points for the top */
+ m_bottom.add(GloxPointNormalTexture(GloxPoint<>(-m_half, -m_half, m_half),
+ normal, GloxPoint<>(0, 0)));
- m_bottom.add( GloxPointNormalTexture( GloxPoint<>( m_half,-m_half, m_half),
- normal, GloxPoint<>(m_bottom_tex.getXReps(),0)) );
+ m_bottom.add(GloxPointNormalTexture(GloxPoint<>(m_half, -m_half, m_half),
+ normal,
+ GloxPoint<>(m_bottom_tex.getXReps(), 0)));
- m_bottom.add( GloxPointNormalTexture( GloxPoint<>( m_half,-m_half,-m_half),
- normal, GloxPoint<>(m_bottom_tex.getXReps(),m_bottom_tex.getYReps())) );
+ m_bottom.add(GloxPointNormalTexture(
+ GloxPoint<>(m_half, -m_half, -m_half), normal,
+ GloxPoint<>(m_bottom_tex.getXReps(), m_bottom_tex.getYReps())));
- m_bottom.add( GloxPointNormalTexture( GloxPoint<>(-m_half,-m_half,-m_half),
- normal, GloxPoint<>(0,m_bottom_tex.getYReps())) );
+ m_bottom.add(GloxPointNormalTexture(GloxPoint<>(-m_half, -m_half, -m_half),
+ normal,
+ GloxPoint<>(0, m_bottom_tex.getYReps())));
}
void GloxTexturedCube::update_front() {
- m_front.clear();
+ m_front.clear();
- GloxNormal<> normal( 0, 0, 1 );
+ GloxNormal<> normal(0, 0, 1);
- /* The points for the top */
- m_front.add( GloxPointNormalTexture( GloxPoint<>(-m_half, m_half, m_half),
- normal, GloxPoint<>(0,0)) );
+ /* The points for the top */
+ m_front.add(GloxPointNormalTexture(GloxPoint<>(-m_half, m_half, m_half),
+ normal, GloxPoint<>(0, 0)));
- m_front.add( GloxPointNormalTexture( GloxPoint<>( m_half, m_half, m_half),
- normal, GloxPoint<>(m_front_tex.getXReps(),0)) );
+ m_front.add(GloxPointNormalTexture(GloxPoint<>(m_half, m_half, m_half),
+ normal,
+ GloxPoint<>(m_front_tex.getXReps(), 0)));
- m_front.add( GloxPointNormalTexture( GloxPoint<>( m_half,-m_half, m_half),
- normal, GloxPoint<>(m_front_tex.getXReps(),m_front_tex.getYReps())) );
+ m_front.add(GloxPointNormalTexture(
+ GloxPoint<>(m_half, -m_half, m_half), normal,
+ GloxPoint<>(m_front_tex.getXReps(), m_front_tex.getYReps())));
- m_front.add( GloxPointNormalTexture( GloxPoint<>(-m_half,-m_half, m_half),
- normal, GloxPoint<>(0,m_front_tex.getYReps())) );
+ m_front.add(GloxPointNormalTexture(GloxPoint<>(-m_half, -m_half, m_half),
+ normal,
+ GloxPoint<>(0, m_front_tex.getYReps())));
}
void GloxTexturedCube::update_back() {
- m_back.clear();
+ m_back.clear();
- GloxNormal<> normal( 0, 0, -1 );
+ GloxNormal<> normal(0, 0, -1);
- /* The points for the back */
- m_back.add( GloxPointNormalTexture( GloxPoint<>(-m_half, m_half,-m_half),
- normal, GloxPoint<>(0,0)) );
+ /* The points for the back */
+ m_back.add(GloxPointNormalTexture(GloxPoint<>(-m_half, m_half, -m_half),
+ normal, GloxPoint<>(0, 0)));
- m_back.add( GloxPointNormalTexture( GloxPoint<>( m_half, m_half,-m_half),
- normal, GloxPoint<>(m_back_tex.getXReps(),0)) );
+ m_back.add(GloxPointNormalTexture(GloxPoint<>(m_half, m_half, -m_half),
+ normal,
+ GloxPoint<>(m_back_tex.getXReps(), 0)));
- m_back.add( GloxPointNormalTexture( GloxPoint<>( m_half,-m_half,-m_half),
- normal, GloxPoint<>(m_back_tex.getXReps(),m_front_tex.getYReps())) );
+ m_back.add(GloxPointNormalTexture(
+ GloxPoint<>(m_half, -m_half, -m_half), normal,
+ GloxPoint<>(m_back_tex.getXReps(), m_front_tex.getYReps())));
- m_back.add( GloxPointNormalTexture( GloxPoint<>(-m_half,-m_half,-m_half),
- normal, GloxPoint<>(0,m_back_tex.getYReps())) );
+ m_back.add(GloxPointNormalTexture(GloxPoint<>(-m_half, -m_half, -m_half),
+ normal,
+ GloxPoint<>(0, m_back_tex.getYReps())));
}
void GloxTexturedCube::update_right() {
- m_right.clear();
+ m_right.clear();
- GloxNormal<> normal( 1, 0, 0 );
+ GloxNormal<> normal(1, 0, 0);
- /* The points for the right */
- m_right.add( GloxPointNormalTexture( GloxPoint<>( m_half,-m_half, m_half),
- normal, GloxPoint<>(0,0)) );
+ /* The points for the right */
+ m_right.add(GloxPointNormalTexture(GloxPoint<>(m_half, -m_half, m_half),
+ normal, GloxPoint<>(0, 0)));
- m_right.add( GloxPointNormalTexture( GloxPoint<>( m_half, m_half, m_half),
- normal, GloxPoint<>(m_right_tex.getXReps(),0)) );
+ m_right.add(GloxPointNormalTexture(GloxPoint<>(m_half, m_half, m_half),
+ normal,
+ GloxPoint<>(m_right_tex.getXReps(), 0)));
- m_right.add( GloxPointNormalTexture( GloxPoint<>( m_half, m_half,-m_half),
- normal, GloxPoint<>(m_right_tex.getXReps(),m_front_tex.getYReps())) );
+ m_right.add(GloxPointNormalTexture(
+ GloxPoint<>(m_half, m_half, -m_half), normal,
+ GloxPoint<>(m_right_tex.getXReps(), m_front_tex.getYReps())));
- m_right.add( GloxPointNormalTexture( GloxPoint<>( m_half,-m_half,-m_half),
- normal, GloxPoint<>(0,m_right_tex.getYReps())) );
+ m_right.add(GloxPointNormalTexture(GloxPoint<>(m_half, -m_half, -m_half),
+ normal,
+ GloxPoint<>(0, m_right_tex.getYReps())));
}
void GloxTexturedCube::update_left() {
- m_left.clear();
+ m_left.clear();
- GloxNormal<> normal( -1, 0, 0 );
+ GloxNormal<> normal(-1, 0, 0);
- /* The points for the left */
- m_left.add( GloxPointNormalTexture( GloxPoint<>(-m_half,-m_half, m_half),
- normal, GloxPoint<>(0,0)) );
+ /* The points for the left */
+ m_left.add(GloxPointNormalTexture(GloxPoint<>(-m_half, -m_half, m_half),
+ normal, GloxPoint<>(0, 0)));
- m_left.add( GloxPointNormalTexture( GloxPoint<>(-m_half, m_half, m_half),
- normal, GloxPoint<>(m_left_tex.getXReps(),0)) );
+ m_left.add(GloxPointNormalTexture(GloxPoint<>(-m_half, m_half, m_half),
+ normal,
+ GloxPoint<>(m_left_tex.getXReps(), 0)));
- m_left.add( GloxPointNormalTexture( GloxPoint<>(-m_half, m_half,-m_half),
- normal, GloxPoint<>(m_left_tex.getXReps(),m_front_tex.getYReps())) );
+ m_left.add(GloxPointNormalTexture(
+ GloxPoint<>(-m_half, m_half, -m_half), normal,
+ GloxPoint<>(m_left_tex.getXReps(), m_front_tex.getYReps())));
- m_left.add( GloxPointNormalTexture( GloxPoint<>(-m_half,-m_half,-m_half),
- normal, GloxPoint<>(0,m_left_tex.getYReps())) );
+ m_left.add(GloxPointNormalTexture(GloxPoint<>(-m_half, -m_half, -m_half),
+ normal,
+ GloxPoint<>(0, m_left_tex.getYReps())));
}
-GloxTexturedCube::GloxTexturedCube( float size, const GloxColor& color,
- const GloxTextureRepeat& topTex ,
- const GloxTextureRepeat& botTex ,
- const GloxTextureRepeat& frontTex ,
- const GloxTextureRepeat& backTex ,
- const GloxTextureRepeat& leftTex ,
- const GloxTextureRepeat& rightTex ) :
-
- m_top_tex( topTex ) , m_bottom_tex( botTex ), m_front_tex( frontTex ),
- m_back_tex( backTex ), m_left_tex( leftTex ), m_right_tex( rightTex ),
- m_color( color ) {
- m_half = size / 2;
-
- update_top();
- update_bottom();
- update_front();
- update_back();
- update_left();
- update_right();
+GloxTexturedCube::GloxTexturedCube(float size, const GloxColor& color,
+ const GloxTextureRepeat& topTex,
+ const GloxTextureRepeat& botTex,
+ const GloxTextureRepeat& frontTex,
+ const GloxTextureRepeat& backTex,
+ const GloxTextureRepeat& leftTex,
+ const GloxTextureRepeat& rightTex)
+ :
+
+ m_top_tex(topTex),
+ m_bottom_tex(botTex),
+ m_front_tex(frontTex),
+ m_back_tex(backTex),
+ m_left_tex(leftTex),
+ m_right_tex(rightTex),
+ m_color(color) {
+ m_half = size / 2;
+
+ update_top();
+ update_bottom();
+ update_front();
+ update_back();
+ update_left();
+ update_right();
}
-inline void GloxTexturedCube::plot_with( const _M_Square& face, const GloxTextureRepeat& tex ) const {
- if( tex.isNull() ) {
- glDisable( GL_TEXTURE_2D );
- } else {
- tex.getTexture()->bind();
- glEnable( GL_TEXTURE_2D );
- }
+inline void GloxTexturedCube::plot_with(const _M_Square& face,
+ const GloxTextureRepeat& tex) const {
+ if (tex.isNull()) {
+ glDisable(GL_TEXTURE_2D);
+ } else {
+ tex.getTexture()->bind();
+ glEnable(GL_TEXTURE_2D);
+ }
- glBegin( GL_QUADS );
- face.plot();
- glEnd();
+ glBegin(GL_QUADS);
+ face.plot();
+ glEnd();
- glDisable( GL_TEXTURE_2D );
+ glDisable(GL_TEXTURE_2D);
}
void GloxTexturedCube::draw() const {
- /* Save current attributes for this scope */
- GloxScopedAttributes __sca( GL_CURRENT_BIT );
- //GloxScopedBegin __sbgn( GL_QUADS );
-
- /* The normal to use for plotting */
- GloxNormal<> normal(0,0,0);
-
- /* Render this color */
- m_color.render();
-
- plot_with(m_right, m_right_tex);
- plot_with(m_left, m_left_tex);
- plot_with(m_top, m_top_tex);
- plot_with(m_bottom, m_bottom_tex);
- plot_with(m_front, m_front_tex);
- plot_with(m_back, m_back_tex);
+ /* Save current attributes for this scope */
+ GloxScopedAttributes __sca(GL_CURRENT_BIT);
+ //GloxScopedBegin __sbgn( GL_QUADS );
+
+ /* The normal to use for plotting */
+ GloxNormal<> normal(0, 0, 0);
+
+ /* Render this color */
+ m_color.render();
+
+ plot_with(m_right, m_right_tex);
+ plot_with(m_left, m_left_tex);
+ plot_with(m_top, m_top_tex);
+ plot_with(m_bottom, m_bottom_tex);
+ plot_with(m_front, m_front_tex);
+ plot_with(m_back, m_back_tex);
}
-}
+} // namespace glox
diff --git a/glox/glox/src/GloxTexturedSphere.cpp b/glox/glox/src/GloxTexturedSphere.cpp
index f718497..0a8d452 100644
--- a/glox/glox/src/GloxTexturedSphere.cpp
+++ b/glox/glox/src/GloxTexturedSphere.cpp
@@ -1,52 +1,50 @@
#include "glox/objects/GloxTexturedSphere.hpp"
#include "glox/GloxCommon.hpp"
-#include "glox/GloxPoint.hpp"
#include "glox/GloxNormal.hpp"
+#include "glox/GloxPoint.hpp"
#include "glox/GloxPointNormalTexture.hpp"
#include "glox/GloxScopedAttributes.hpp"
namespace glox {
-static void m_vertex( float th, float ph ) {
- GloxPoint<> point = GloxPoint<>::fromSpherical( 1, th, ph );
- GloxNormal<> normal( point.getX(), point.getY(), point.getZ() );
- GloxPoint<> texPoint( th/360.0, ph/180.0 + 0.5 );
-
- GloxPointNormalTexture( point, normal, texPoint ).plot();
+static void m_vertex(float th, float ph) {
+ GloxPoint<> point = GloxPoint<>::fromSpherical(1, th, ph);
+ GloxNormal<> normal(point.getX(), point.getY(), point.getZ());
+ GloxPoint<> texPoint(th / 360.0, ph / 180.0 + 0.5);
+
+ GloxPointNormalTexture(point, normal, texPoint).plot();
}
-GloxTexturedSphere::GloxTexturedSphere( float radius, float res, const GloxTexture& texture ) {
- m_radius = radius;
- m_texture = texture;
-
- /* Generate the display list */
- m_disp_list = glGenLists( 1 );
- glNewList( m_disp_list, GL_COMPILE );
-
- float ph, th;
- for ( ph = -90 ; ph < 90 ; ph += res ) {
- GloxWith( GL_QUAD_STRIP,
- for ( th = 0 ; th <= 360 ; th += res ) {
- m_vertex(th,ph);
- m_vertex(th,ph+res);
- }
- );
- }
-
- glEndList();
+GloxTexturedSphere::GloxTexturedSphere(float radius, float res,
+ const GloxTexture& texture) {
+ m_radius = radius;
+ m_texture = texture;
+
+ /* Generate the display list */
+ m_disp_list = glGenLists(1);
+ glNewList(m_disp_list, GL_COMPILE);
+
+ float ph, th;
+ for (ph = -90; ph < 90; ph += res) {
+ GloxWith(
+ GL_QUAD_STRIP, for (th = 0; th <= 360; th += res) {
+ m_vertex(th, ph);
+ m_vertex(th, ph + res);
+ });
+ }
+
+ glEndList();
}
void GloxTexturedSphere::draw() const {
- glPushMatrix();
- GloxEnableFor( GL_TEXTURE_2D,
- glScalef( m_radius, m_radius, m_radius );
- /* Bind the texture */
- m_texture.bind();
-
- /* Call the display list */
- glCallList( m_disp_list );
- );
- glPopMatrix();
+ glPushMatrix();
+ GloxEnableFor(GL_TEXTURE_2D, glScalef(m_radius, m_radius, m_radius);
+ /* Bind the texture */
+ m_texture.bind();
+
+ /* Call the display list */
+ glCallList(m_disp_list););
+ glPopMatrix();
}
-}
+} // namespace glox
diff --git a/slox/slox/SloxApplication.hpp b/slox/slox/SloxApplication.hpp
index ea2b8d8..127d8b1 100644
--- a/slox/slox/SloxApplication.hpp
+++ b/slox/slox/SloxApplication.hpp
@@ -16,45 +16,41 @@ namespace slox {
/* This is the base class for all applications
* using the Slox framework */
class SloxApplication {
-public:
- /* initializes the application. This function
+ public:
+ /* initializes the application. This function
* is responsible for almost all of the initialization
* of the application */
- virtual bool initialize(int argc, char** argv) = 0;
-
- /* This is called whenever there
+ virtual bool initialize(int argc, char** argv) = 0;
+
+ /* This is called whenever there
* is an event that is raised */
- virtual void onEvent( const SDL_Event& event ) = 0;
+ virtual void onEvent(const SDL_Event& event) = 0;
- /* This is called for every iteration
+ /* This is called for every iteration
* in the event loop. Returns
* true if the application is to
* continue running */
- virtual bool loop( uint32_t ticks ) = 0;
+ virtual bool loop(uint32_t ticks) = 0;
- /* Runs this application. This
+ /* Runs this application. This
* is the only implemented method
* in this class */
- virtual void run( int argc=0, char** argv=NULL ) ;
+ virtual void run(int argc = 0, char** argv = NULL);
- /* Clean up the application */
- virtual inline ~SloxApplication() {}
+ /* Clean up the application */
+ virtual inline ~SloxApplication() {}
- /* Sets a useful error message for the
+ /* Sets a useful error message for the
* user to make it easier to debug problems */
- virtual inline void setError( const std::string& error ) {
- m_error = error;
- }
+ virtual inline void setError(const std::string& error) { m_error = error; }
- /* Returns the error message */
- virtual inline const std::string& getError() const {
- return m_error;
- }
+ /* Returns the error message */
+ virtual inline const std::string& getError() const { return m_error; }
-private:
- std::string m_error;
+ private:
+ std::string m_error;
};
-}
+} // namespace slox
#endif /* SLOXAPPLICATION_HPP_ */
diff --git a/slox/slox/SloxRawEventHandler.hpp b/slox/slox/SloxRawEventHandler.hpp
index 39c4677..797b12d 100644
--- a/slox/slox/SloxRawEventHandler.hpp
+++ b/slox/slox/SloxRawEventHandler.hpp
@@ -16,42 +16,42 @@
#include "slox/SloxCommon.hpp"
#include "slox/events/SloxKeyListener.hpp"
+#include "slox/events/SloxMouseMotionListener.hpp"
#include "slox/events/SloxQuitListener.hpp"
#include "slox/events/SloxResizeListener.hpp"
-#include "slox/events/SloxMouseMotionListener.hpp"
namespace slox {
class SloxRawEventHandler {
-public:
- void onEvent( const SDL_Event& event );
-
- /* Add a key listener to this event handler */
- inline void addKeyListener( SloxKeyListener* listener ) {
- keyListeners.push_back( listener );
- }
-
- inline void addQuitListener( SloxQuitListener* listener ) {
- quitListeners.push_back( listener );
- }
-
- inline void addResizeListener( SloxResizeListener* listener ) {
- resizeListeners.push_back( listener );
- }
-
- inline void addMouseMotionListener( SloxMouseMotionListener* listener ) {
- mouseMotionListeners.push_back( listener );
- }
-
-private:
- std::vector<SloxKeyListener*> keyListeners;
- std::vector<SloxQuitListener*> quitListeners;
- std::vector<SloxResizeListener*> resizeListeners;
- std::vector<SloxMouseMotionListener*> mouseMotionListeners;
-
- // TODO: more to add
+ public:
+ void onEvent(const SDL_Event& event);
+
+ /* Add a key listener to this event handler */
+ inline void addKeyListener(SloxKeyListener* listener) {
+ keyListeners.push_back(listener);
+ }
+
+ inline void addQuitListener(SloxQuitListener* listener) {
+ quitListeners.push_back(listener);
+ }
+
+ inline void addResizeListener(SloxResizeListener* listener) {
+ resizeListeners.push_back(listener);
+ }
+
+ inline void addMouseMotionListener(SloxMouseMotionListener* listener) {
+ mouseMotionListeners.push_back(listener);
+ }
+
+ private:
+ std::vector<SloxKeyListener*> keyListeners;
+ std::vector<SloxQuitListener*> quitListeners;
+ std::vector<SloxResizeListener*> resizeListeners;
+ std::vector<SloxMouseMotionListener*> mouseMotionListeners;
+
+ // TODO: more to add
};
-}
+} // namespace slox
#endif /* SLOXRAWEVENTLISTENTER_HPP_ */
diff --git a/slox/slox/SloxTextureFactory.hpp b/slox/slox/SloxTextureFactory.hpp
index 883e956..2326bf2 100644
--- a/slox/slox/SloxTextureFactory.hpp
+++ b/slox/slox/SloxTextureFactory.hpp
@@ -9,10 +9,10 @@
#ifndef NO_OPENGL
-#include <string>
#include <GL/gl.h>
-#include "slox/SloxCommon.hpp"
+#include <string>
#include <vector>
+#include "slox/SloxCommon.hpp"
#include <SDL/SDL_image.h>
@@ -20,32 +20,30 @@ namespace slox {
/* has dependencies on OpenGL */
class SloxTextureFactory {
-public:
- inline SloxTextureFactory( ) {
- m_path.push_back( "." );
- m_path.push_back( "" );
- }
+ public:
+ inline SloxTextureFactory() {
+ m_path.push_back(".");
+ m_path.push_back("");
+ }
- /* returns 0 if ok, 1 if warning, -1 if error */
- int readBitmapFile( const char* filename, unsigned int* texture ) ;
+ /* returns 0 if ok, 1 if warning, -1 if error */
+ int readBitmapFile(const char* filename, unsigned int* texture);
- int readImageFile( const char* filename, unsigned int* texture ) ;
+ int readImageFile(const char* filename, unsigned int* texture);
- const std::string& getMessage() ;
+ const std::string& getMessage();
- inline void addToPath( const char* path ) {
- m_path.push_back( path );
- }
+ inline void addToPath(const char* path) { m_path.push_back(path); }
-private:
- int getFileFromPath( const char* basename, std::string& into );
+ private:
+ int getFileFromPath(const char* basename, std::string& into);
- std::vector<std::string> m_path;
+ std::vector<std::string> m_path;
- std::string m_message;
+ std::string m_message;
};
-}
+} // namespace slox
#else
#warn "SloxTextureFactory is not available when compiling with -D NO_OPENGL"
diff --git a/slox/slox/events/SloxFunctionQuitListener.hpp b/slox/slox/events/SloxFunctionQuitListener.hpp
index 9df189d..11ec5be 100644
--- a/slox/slox/events/SloxFunctionQuitListener.hpp
+++ b/slox/slox/events/SloxFunctionQuitListener.hpp
@@ -15,21 +15,19 @@
namespace slox {
class SloxFunctionQuitListener : public SloxQuitListener {
-public:
- inline SloxFunctionQuitListener( void (*func)( const SDL_QuitEvent& evt ) ) {
- m_function_ptr = func;
- }
+ public:
+ inline SloxFunctionQuitListener(void (*func)(const SDL_QuitEvent& evt)) {
+ m_function_ptr = func;
+ }
- virtual inline void onQuit( const SDL_QuitEvent& event ) {
- m_function_ptr( event );
- }
+ virtual inline void onQuit(const SDL_QuitEvent& event) {
+ m_function_ptr(event);
+ }
-private:
- void (*m_function_ptr)( const SDL_QuitEvent& evt );
+ private:
+ void (*m_function_ptr)(const SDL_QuitEvent& evt);
};
-}
-
-
+} // namespace slox
#endif /* SLOXFUNCTIONQUITLISTENER_CPP_ */
diff --git a/slox/slox/events/SloxKeyListener.hpp b/slox/slox/events/SloxKeyListener.hpp
index 422c1bf..efae560 100644
--- a/slox/slox/events/SloxKeyListener.hpp
+++ b/slox/slox/events/SloxKeyListener.hpp
@@ -15,15 +15,15 @@
namespace slox {
class SloxKeyListener {
-public:
- /* Called when a key was pressed or
+ public:
+ /* Called when a key was pressed or
* repeated */
- virtual inline void onKeyDown( const SDL_KeyboardEvent& event ) { (void) event; }
+ virtual inline void onKeyDown(const SDL_KeyboardEvent& event) { (void)event; }
- /* Called when a key was released */
- virtual inline void onKeyUp ( const SDL_KeyboardEvent& event ) { (void) event; }
+ /* Called when a key was released */
+ virtual inline void onKeyUp(const SDL_KeyboardEvent& event) { (void)event; }
};
-}
+} // namespace slox
#endif /* SLOXKEYLISTENER_HPP_ */
diff --git a/slox/slox/events/SloxMouseMotionListener.hpp b/slox/slox/events/SloxMouseMotionListener.hpp
index 1994886..0f8ff18 100644
--- a/slox/slox/events/SloxMouseMotionListener.hpp
+++ b/slox/slox/events/SloxMouseMotionListener.hpp
@@ -10,16 +10,16 @@
#include "slox/SloxCommon.hpp"
namespace slox {
-
+
/* A class that listens for mouse motion */
class SloxMouseMotionListener {
-public:
- /* Called when the mouse is moved */
- virtual inline void onMouseMoved( const SDL_MouseMotionEvent& event ) {
- (void) event;
- };
+ public:
+ /* Called when the mouse is moved */
+ virtual inline void onMouseMoved(const SDL_MouseMotionEvent& event) {
+ (void)event;
+ };
};
-
-}
+
+} // namespace slox
#endif /* SLOXMOUSEMOTIONLISTENER_HPP_ */
diff --git a/slox/slox/events/SloxQuitListener.hpp b/slox/slox/events/SloxQuitListener.hpp
index fe5e368..431aac6 100644
--- a/slox/slox/events/SloxQuitListener.hpp
+++ b/slox/slox/events/SloxQuitListener.hpp
@@ -15,11 +15,11 @@
namespace slox {
class SloxQuitListener {
-public:
- /* Called when there was a quit event */
- virtual inline void onQuit( const SDL_QuitEvent& event ) { (void) event; };
+ public:
+ /* Called when there was a quit event */
+ virtual inline void onQuit(const SDL_QuitEvent& event) { (void)event; };
};
-}
+} // namespace slox
#endif /* SLOXQUITLISTENER_HPP_ */
diff --git a/slox/slox/events/SloxResizeListener.hpp b/slox/slox/events/SloxResizeListener.hpp
index e24aa51..35dd992 100644
--- a/slox/slox/events/SloxResizeListener.hpp
+++ b/slox/slox/events/SloxResizeListener.hpp
@@ -12,10 +12,10 @@
namespace slox {
class SloxResizeListener {
-public:
- inline virtual void onResize( const SDL_ResizeEvent& event ) { (void)event; }
+ public:
+ inline virtual void onResize(const SDL_ResizeEvent& event) { (void)event; }
};
-}
+} // namespace slox
#endif /* SLOXRESIZELISTENER_HPP_ */
diff --git a/slox/slox/loader/SloxModelObject.hpp b/slox/slox/loader/SloxModelObject.hpp
index 5171589..536869f 100644
--- a/slox/slox/loader/SloxModelObject.hpp
+++ b/slox/slox/loader/SloxModelObject.hpp
@@ -16,19 +16,19 @@ namespace slox {
class SloxModelObject : public glox::GloxObject {
-public:
- inline SloxModelObject( int disp ) : m_display_list( disp ) {}
-
- inline int getDisplayList() const { return m_display_list; }
+ public:
+ inline SloxModelObject(int disp) : m_display_list(disp) {}
- inline virtual void draw() const { glCallList( m_display_list ); }
+ inline int getDisplayList() const { return m_display_list; }
- inline virtual ~SloxModelObject() {
- }
-private:
- int m_display_list;
+ inline virtual void draw() const { glCallList(m_display_list); }
+
+ inline virtual ~SloxModelObject() {}
+
+ private:
+ int m_display_list;
};
-}
+} // namespace slox
#endif /* GLOXMODELOBJECT_HPP_ */
diff --git a/slox/slox/loader/SloxObjectLoader.hpp b/slox/slox/loader/SloxObjectLoader.hpp
index e662f4e..224943b 100644
--- a/slox/slox/loader/SloxObjectLoader.hpp
+++ b/slox/slox/loader/SloxObjectLoader.hpp
@@ -7,13 +7,13 @@
* SloxObjectLoader.hpp: <description>
*/
-#include "slox/loader/SloxModelObject.hpp"
#include "slox/SloxTextureFactory.hpp"
+#include "slox/loader/SloxModelObject.hpp"
-#include <vector>
+#include <cerrno>
#include <fstream>
#include <iostream>
-#include <cerrno>
+#include <vector>
namespace slox {
@@ -22,85 +22,84 @@ namespace slox {
* as the object depicted by the obj file
* loaded */
class SloxObjectLoader {
-public:
- inline SloxObjectLoader( SloxTextureFactory* textureFactory = NULL ) {
- m_path.push_back( "." );
- m_path.push_back( "" );
- m_texture_factory = textureFactory;
- }
-
- inline void setTextureFactory( SloxTextureFactory* factory ) {
- m_texture_factory = factory;
- }
-
- /* loads an object from an input stream.
+ public:
+ inline SloxObjectLoader(SloxTextureFactory* textureFactory = NULL) {
+ m_path.push_back(".");
+ m_path.push_back("");
+ m_texture_factory = textureFactory;
+ }
+
+ inline void setTextureFactory(SloxTextureFactory* factory) {
+ m_texture_factory = factory;
+ }
+
+ /* loads an object from an input stream.
* The stream should have the contents of an
* obj file */
- SloxModelObject* loadObjectFromStream( std::istream& input );
+ SloxModelObject* loadObjectFromStream(std::istream& input);
- /* Loads an object from a file, this
+ /* Loads an object from a file, this
* is a humble wrapper around the loadOBjectFromStream
* declared above that opens the file with a
* standard istream */
- inline SloxModelObject* loadObjectFromFile( const std::string& filename ) {
- std::ifstream stream;
- SloxModelObject* ret = NULL;
+ inline SloxModelObject* loadObjectFromFile(const std::string& filename) {
+ std::ifstream stream;
+ SloxModelObject* ret = NULL;
- /* Try to open the stream, load the object
+ /* Try to open the stream, load the object
* from that stream and close the
* stream */
- if( openFileFromPath( filename.c_str(), stream ) ) {
- object_loader_reason = filename + ": not found on path";
- return NULL;
- }
-
- ret = loadObjectFromStream( stream );
- stream.close();
- return ret;
+ if (openFileFromPath(filename.c_str(), stream)) {
+ object_loader_reason = filename + ": not found on path";
+ return NULL;
}
- /* If the object loading fails and returns
+ ret = loadObjectFromStream(stream);
+ stream.close();
+ return ret;
+ }
+
+ /* If the object loading fails and returns
* NULL, calling this function will return
* a string describing the reason */
- const char* getReason() const ;
+ const char* getReason() const;
- /* Add a path to the path variable so
+ /* Add a path to the path variable so
* the factory will look in this folder
* for a texture */
- inline void addToPath( const char* path ) {
- m_path.push_back( path );
- }
-private:
- void loadMaterial( const char* file );
+ inline void addToPath(const char* path) { m_path.push_back(path); }
- /* Returns the file from the path */
- int openFileFromPath( const char* basename, std::ifstream& into );
+ private:
+ void loadMaterial(const char* file);
- /* This is a string that describes the current
+ /* Returns the file from the path */
+ int openFileFromPath(const char* basename, std::ifstream& into);
+
+ /* This is a string that describes the current
* filename that is being parsed.
*
* This name will take the name of *.obj or *.mtl
*/
- const char* object_loader_filename;
-
- /*
+ const char* object_loader_filename;
+
+ /*
* This is a string that depicts the reason
* for failure. This should not be accessed
* directly, use SloxObjectLoader::getReason()
* instead, I'm just being lazy */
- std::string object_loader_reason;
+ std::string object_loader_reason;
- /*
+ /*
* The places on the filesystem where this object
* loader will look for objects to load
*/
- std::vector< std::string > m_path;
+ std::vector<std::string> m_path;
- /* The texture factory used to load
+ /* The texture factory used to load
* the textures into the program */
- SloxTextureFactory* m_texture_factory;
+ SloxTextureFactory* m_texture_factory;
};
-}
+} // namespace slox
#endif /* GLOXOBJECTLOADER_HPP_ */
diff --git a/slox/slox/loader/SloxObjectMaterial.hpp b/slox/slox/loader/SloxObjectMaterial.hpp
index e1e6eb8..8419c02 100644
--- a/slox/slox/loader/SloxObjectMaterial.hpp
+++ b/slox/slox/loader/SloxObjectMaterial.hpp
@@ -7,8 +7,8 @@
* glox::GloxObjectMaterial.hpp: <description>
*/
-#include <string>
#include <algorithm>
+#include <string>
#include "glox/GloxColor.hpp"
#include "glox/GloxTexture.hpp"
@@ -16,80 +16,53 @@
namespace slox {
class SloxObjectMaterial {
-public:
- SloxObjectMaterial( const std::string name = ""
- , const glox::GloxColor& ka = glox::GloxColor()
- , const glox::GloxColor& kd = glox::GloxColor()
- , const glox::GloxColor& ks = glox::GloxColor()
- , float ns = 0
- , const glox::GloxTexture& tex = glox::GloxTexture() ) :
- m_name( name ), m_Ka( ka ), m_Kd( kd ),
- m_Ks( ks ), m_Ns( ns ), m_tex( tex ) {}
-
- inline void setNs( float ns ) {
- m_Ns = ns;
- }
-
- inline void setTransparency( float trans ) {
- m_trans = trans;
- }
-
- inline void setKa( const glox::GloxColor& ka ) {
- m_Ka = ka;
- }
-
- inline void setKd( const glox::GloxColor& kd ) {
- m_Kd = kd;
- }
-
- inline void setKs( const glox::GloxColor& ks ) {
- m_Ks = ks;
- }
-
- inline void setName( const std::string name ) {
- m_name = name;
- }
-
- inline const std::string getName() const {
- return m_name ;
- }
-
- inline const glox::GloxColor& getKa() const {
- return m_Ka;
- }
-
- inline const glox::GloxColor& getKd() const {
- return m_Kd;
- }
-
- inline const glox::GloxColor& getKs() const {
- return m_Ks;
- }
-
- inline const glox::GloxTexture& getTexture() const {
- return m_tex;
- }
-
- inline float getNs() const {
- return m_Ns;
- }
-
- inline void setTexture( const glox::GloxTexture& tex ) {
- m_tex = tex;
- }
-
-private:
- std::string m_name;
- glox::GloxColor m_Ka;
- glox::GloxColor m_Kd;
- glox::GloxColor m_Ks;
-
- float m_Ns;
- float m_trans;
-
- glox::GloxTexture m_tex;
+ public:
+ SloxObjectMaterial(const std::string name = "",
+ const glox::GloxColor& ka = glox::GloxColor(),
+ const glox::GloxColor& kd = glox::GloxColor(),
+ const glox::GloxColor& ks = glox::GloxColor(),
+ float ns = 0,
+ const glox::GloxTexture& tex = glox::GloxTexture())
+ : m_name(name), m_Ka(ka), m_Kd(kd), m_Ks(ks), m_Ns(ns), m_tex(tex) {}
+
+ inline void setNs(float ns) { m_Ns = ns; }
+
+ inline void setTransparency(float trans) { m_trans = trans; }
+
+ inline void setKa(const glox::GloxColor& ka) { m_Ka = ka; }
+
+ inline void setKd(const glox::GloxColor& kd) { m_Kd = kd; }
+
+ inline void setKs(const glox::GloxColor& ks) { m_Ks = ks; }
+
+ inline void setName(const std::string name) { m_name = name; }
+
+ inline const std::string getName() const { return m_name; }
+
+ inline const glox::GloxColor& getKa() const { return m_Ka; }
+
+ inline const glox::GloxColor& getKd() const { return m_Kd; }
+
+ inline const glox::GloxColor& getKs() const { return m_Ks; }
+
+ inline const glox::GloxTexture& getTexture() const { return m_tex; }
+
+ inline float getNs() const { return m_Ns; }
+
+ inline void setTexture(const glox::GloxTexture& tex) { m_tex = tex; }
+
+ private:
+ std::string m_name;
+ glox::GloxColor m_Ka;
+ glox::GloxColor m_Kd;
+ glox::GloxColor m_Ks;
+
+ float m_Ns;
+ float m_trans;
+
+ glox::GloxTexture m_tex;
};
-}
+} // namespace slox
#endif /* GLOXOBJECTMATERIAL_HPP_ */
diff --git a/slox/slox/loader/private_db/SloxObjectLoader.cpp b/slox/slox/loader/private_db/SloxObjectLoader.cpp
index 3ad5f45..94ae134 100644
--- a/slox/slox/loader/private_db/SloxObjectLoader.cpp
+++ b/slox/slox/loader/private_db/SloxObjectLoader.cpp
@@ -1,38 +1,40 @@
-#include <vector>
-#include <map>
-#include <sstream>
#include <cstdio>
#include <fstream>
+#include <map>
+#include <sstream>
+#include <vector>
#include "slox/loader/SloxObjectLoader.hpp"
+#include <sys/stat.h>
+#include "glox/GloxCommon.hpp"
+#include "glox/GloxNormal.hpp"
+#include "glox/GloxPoint.hpp"
#include "glox/GloxScopedAttributes.hpp"
#include "glox/GloxScopedBegin.hpp"
-#include "glox/GloxPoint.hpp"
-#include "glox/GloxNormal.hpp"
-#include "glox/GloxCommon.hpp"
#include "glox/GloxTextureFactory.hpp"
-#include <sys/stat.h>
using namespace std;
using namespace glox;
namespace slox {
-int SloxObjectLoader::openFileFromPath( const char* basename, std::ifstream& into ) {
- struct stat st;
- char buf[4096];
- into.clear();
- for( vector<string>::iterator itr = m_path.begin(); itr < m_path.end(); ++ itr ) {
- snprintf( buf, 4096, "%s/%s", (*itr).c_str(), basename );
- if( ! stat( buf, & st ) ) {
- into.open( buf, ios::in );
- return 0;
- }
- }
-
- /* Nothing was found */
- return 1;
+int SloxObjectLoader::openFileFromPath(const char* basename,
+ std::ifstream& into) {
+ struct stat st;
+ char buf[4096];
+ into.clear();
+ for (vector<string>::iterator itr = m_path.begin(); itr < m_path.end();
+ ++itr) {
+ snprintf(buf, 4096, "%s/%s", (*itr).c_str(), basename);
+ if (!stat(buf, &st)) {
+ into.open(buf, ios::in);
+ return 0;
+ }
+ }
+
+ /* Nothing was found */
+ return 1;
}
/* The reason the loading failed
@@ -41,7 +43,7 @@ std::string object_loader_reason;
/* The map of material names to their
* respective materials */
-static map< string, SloxObjectMaterial > materials;
+static map<string, SloxObjectMaterial> materials;
/* The current line number of the stream */
int linenum = 0;
@@ -51,250 +53,264 @@ const char* object_loader_filename = NULL;
/* Helper function that trims the whitespace from
* a string */
-static inline std::string &trim(std::string &s) {
- s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
- s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
- return s;
+static inline std::string& trim(std::string& s) {
+ s.erase(s.begin(),
+ std::find_if(s.begin(), s.end(),
+ std::not1(std::ptr_fun<int, int>(std::isspace))));
+ s.erase(std::find_if(s.rbegin(), s.rend(),
+ std::not1(std::ptr_fun<int, int>(std::isspace)))
+ .base(),
+ s.end());
+ return s;
};
/* Simple function that returns the reason
* why the loader failed */
const char* SloxObjectLoader::getReason() const {
- return object_loader_reason.c_str();
+ return object_loader_reason.c_str();
}
/* Typedef a texture point to a pair
* of floats */
-typedef pair<float,float> TexPointT;
+typedef pair<float, float> TexPointT;
/* Read n number of floats into a float
* array */
-void p_read_n_floats__( const char* line, float* floats, size_t n ) {
- stringstream linestream( line );
-
- for( size_t i = 0; i < n; ++ i ) {
- if( linestream.eof() ) throw "Premature EOF while reading floats!";
- linestream >> floats[i];
- }
+void p_read_n_floats__(const char* line, float* floats, size_t n) {
+ stringstream linestream(line);
+
+ for (size_t i = 0; i < n; ++i) {
+ if (linestream.eof())
+ throw "Premature EOF while reading floats!";
+ linestream >> floats[i];
+ }
}
/* read a point in the for "%f %f %f" from a
* line */
-inline GloxPointf p_read_point__( const char* line ) {
- float xyz[3];
- p_read_n_floats__( line, xyz, 3 );
- return GloxPointf( xyz[0], xyz[1], xyz[2] );
+inline GloxPointf p_read_point__(const char* line) {
+ float xyz[3];
+ p_read_n_floats__(line, xyz, 3);
+ return GloxPointf(xyz[0], xyz[1], xyz[2]);
}
/* Read a color in the save format as mentioned above */
-inline GloxColor p_read_color__( const char* line ) {
- float xyz[3];
- p_read_n_floats__( line, xyz, 3 );
- return GloxColor( xyz[0], xyz[1], xyz[2] );
+inline GloxColor p_read_color__(const char* line) {
+ float xyz[3];
+ p_read_n_floats__(line, xyz, 3);
+ return GloxColor(xyz[0], xyz[1], xyz[2]);
}
/* read a normal in the same format as mentioned
* above */
-inline GloxNormal<> p_read_normal__( const char* line ) {
- float xyz[3];
- p_read_n_floats__( line, xyz, 3 );
- return GloxNormal<>( xyz[0], xyz[1], xyz[2] );
+inline GloxNormal<> p_read_normal__(const char* line) {
+ float xyz[3];
+ p_read_n_floats__(line, xyz, 3);
+ return GloxNormal<>(xyz[0], xyz[1], xyz[2]);
}
/* Read a texture point in the form
* "%f %f" as above */
-inline TexPointT p_read_tex_point__( const char* line ) {
- float xy[2];
- p_read_n_floats__( line, xy, 2 );
- return TexPointT( xy[0], xy[1] );
+inline TexPointT p_read_tex_point__(const char* line) {
+ float xy[2];
+ p_read_n_floats__(line, xy, 2);
+ return TexPointT(xy[0], xy[1]);
}
/* Have OpenGL set the material to the
* material as referenced by 'name'
*/
-void setMaterial( const char* name ) {
- if( materials.find( name ) == materials.end() ) {
- cerr << "Unable to set the material " << name << "; The material was never loaded\n" << endl;
- throw "Unable to set material; never loaded";
- }
-
- const SloxObjectMaterial& material = materials[ name ];
- float fvec[4];
- material.getKa().toVector( fvec, 4 );
- // cout << "Material KA: " << material.getKa().toString() << endl;
- glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT ,fvec);
- material.getKd().toVector( fvec, 4 );
- glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE ,fvec);
- material.getKs().toVector( fvec, 4 );
- glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR ,fvec);
- fvec[0] = material.getNs();
- glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS, &fvec[0]);
-
- // cout << "Reading Texture with id of: " << material.getTexture().getId() << endl;
- if( material.getTexture().getId() > 0 ) {
- glEnable( GL_TEXTURE_2D );
- material.getTexture().bind();
- } else {
- glDisable( GL_TEXTURE_2D );
- }
+void setMaterial(const char* name) {
+ if (materials.find(name) == materials.end()) {
+ cerr << "Unable to set the material " << name
+ << "; The material was never loaded\n"
+ << endl;
+ throw "Unable to set material; never loaded";
+ }
+
+ const SloxObjectMaterial& material = materials[name];
+ float fvec[4];
+ material.getKa().toVector(fvec, 4);
+ // cout << "Material KA: " << material.getKa().toString() << endl;
+ glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, fvec);
+ material.getKd().toVector(fvec, 4);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, fvec);
+ material.getKs().toVector(fvec, 4);
+ glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, fvec);
+ fvec[0] = material.getNs();
+ glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &fvec[0]);
+
+ // cout << "Reading Texture with id of: " << material.getTexture().getId() << endl;
+ if (material.getTexture().getId() > 0) {
+ glEnable(GL_TEXTURE_2D);
+ material.getTexture().bind();
+ } else {
+ glDisable(GL_TEXTURE_2D);
+ }
}
/* Load a material from the file 'file' */
-void SloxObjectLoader::loadMaterial( const char* file ) {
- ifstream instream;
- const char* oldobject_loader_filename = object_loader_filename;
- object_loader_filename = file;
+void SloxObjectLoader::loadMaterial(const char* file) {
+ ifstream instream;
+ const char* oldobject_loader_filename = object_loader_filename;
+ object_loader_filename = file;
+
+ string line;
+ string word;
+
+ SloxObjectMaterial* material = NULL;
+
+ if (openFileFromPath(file, instream)) {
+ throw "Unable to open material file!";
+ }
+
+ linenum = 0;
+ while (!instream.eof()) {
+ getline(instream, line);
+ ++linenum;
+ stringstream linestream(line);
+ linestream >> word;
+ if (word == "newmtl") {
+ linestream >> word;
+ material = &materials[word];
+ material->setName(word);
+ } else if (material == NULL) {
+ /* Do Nothing */
+ } else if (!line.compare(0, 2, "Ka")) {
+ material->setKa(p_read_color__(line.c_str() + 2));
+ } else if (!line.compare(0, 2, "Kd")) {
+ material->setKd(p_read_color__(line.c_str() + 2));
+ } else if (!line.compare(0, 2, "Ks")) {
+ material->setKs(p_read_color__(line.c_str() + 2));
+ } else if (!line.compare(0, 2, "Ns")) {
+ float tmp;
+ linestream >> tmp;
+ material->setNs(tmp);
+ } else if (word == "map_Kd") {
+ linestream >> word;
+ unsigned int tex;
+ int ret;
+
+ if (word[0] == '/') {
+ cerr << "Warning: absolute path being used for texture!" << endl;
+ exit(1);
+ }
+
+ ret = m_texture_factory->readImageFile(word.c_str(), &tex);
+ if (ret < 0) {
+ cerr << "Can't read texture: " << m_texture_factory->getMessage()
+ << endl;
+ throw "Unable to open texture file!";
+ }
+ GloxTexture tmp(tex);
+ // cout << "Crated texture with id of: " << tmp.getId() << endl;
+ material->setTexture(tmp);
+ }
+ }
- string line;
- string word;
+ instream.close();
+ object_loader_filename = oldobject_loader_filename;
+}
- SloxObjectMaterial* material = NULL;
+SloxModelObject* SloxObjectLoader::loadObjectFromStream(istream& input) {
+ int display_list = glGenLists(1);
+ vector<GloxPointf> verts;
+ vector<GloxNormal<>> norms;
+ vector<TexPointT> tex_points;
+
+ string line;
+
+ glNewList(display_list, GL_COMPILE);
+ GloxScopedAttributes p_gsa__(GL_TEXTURE_BIT);
+
+ try {
+ while (!input.eof()) {
+ getline(input, line);
+ if (input.fail()) {
+ /* If we fail to read, break */
+ break;
+ }
+ trim(line);
+
+ /* handle the case for points/normals/texture points */
+ if (!line.compare(0, 2, "v ")) {
+ verts.push_back(p_read_point__(line.c_str() + 2));
+ } else if (!line.compare(0, 2, "vn")) {
+ norms.push_back(p_read_normal__(line.c_str() + 2));
+ } else if (!line.compare(0, 2, "vt")) {
+ tex_points.push_back(p_read_tex_point__(line.c_str() + 2));
+ }
+
+ /* build the face */
+ else if (line[0] == 'f') {
+ const char* lineptr = line.c_str() + 1;
+ {
+ GloxScopedBegin p_gsb__(GL_POLYGON);
+ stringstream linestream(lineptr);
+ std::string word;
+ while (!linestream.eof()) {
+ unsigned int Kv = 0;
+ unsigned int Kt = 0;
+ unsigned int Kn = 0;
- if( openFileFromPath( file, instream ) ) {
- throw "Unable to open material file!";
- }
-
- linenum = 0;
- while( ! instream.eof() ) {
- getline( instream, line ) ;
- ++ linenum;
- stringstream linestream( line );
- linestream >> word;
- if( word == "newmtl" ) {
linestream >> word;
- material = & materials[ word ];
- material->setName( word );
- } else if ( material == NULL ) {
- /* Do Nothing */
- } else if ( ! line.compare( 0, 2, "Ka" ) ) {
- material->setKa( p_read_color__( line.c_str() + 2 ) );
- } else if ( ! line.compare( 0, 2, "Kd" ) ) {
- material->setKd( p_read_color__( line.c_str() + 2 ) );
- } else if ( ! line.compare( 0, 2, "Ks" ) ) {
- material->setKs( p_read_color__( line.c_str() + 2 ) );
- } else if ( ! line.compare( 0, 2, "Ns" ) ) {
- float tmp;
- linestream >> tmp;
- material->setNs( tmp );
- } else if( word == "map_Kd" ) {
- linestream >> word;
- unsigned int tex;
- int ret;
- if ( word[0] == '/' ) {
- cerr << "Warning: absolute path being used for texture!" << endl ;
- exit( 1 );
+ if (!(sscanf(word.c_str(), "%u/%u/%u", &Kv, &Kt, &Kn) == 3 ||
+ sscanf(word.c_str(), "%u//%u", &Kv, &Kn) == 2 ||
+ sscanf(word.c_str(), "%u", &Kv) == 1)) {
+ throw "Invalid facet!";
}
- ret = m_texture_factory->readImageFile( word.c_str(), &tex );
- if( ret < 0 ) {
- cerr << "Can't read texture: " << m_texture_factory->getMessage() << endl;
- throw "Unable to open texture file!";
+ if (Kv > verts.size())
+ throw "Vertex out of range!";
+ if (Kn > norms.size())
+ throw "Normal out of range!";
+ if (Kt > tex_points.size())
+ throw "Texture out of range!";
+
+ float arr[4];
+ // cout << "face (" << Kv << ", " << Kt << ", " << Kn << ")" << endl;
+ if (Kt) {
+ arr[0] = tex_points[Kt - 1].first;
+ arr[1] = tex_points[Kt - 1].second;
+ glTexCoord2fv(arr);
}
- GloxTexture tmp( tex );
- // cout << "Crated texture with id of: " << tmp.getId() << endl;
- material->setTexture( tmp );
- }
- }
-
- instream.close();
- object_loader_filename = oldobject_loader_filename;
-}
-
-SloxModelObject* SloxObjectLoader::loadObjectFromStream( istream& input ) {
- int display_list = glGenLists( 1 );
- vector< GloxPointf > verts;
- vector< GloxNormal<> > norms;
- vector< TexPointT > tex_points;
-
- string line;
-
- glNewList( display_list, GL_COMPILE );
- GloxScopedAttributes p_gsa__( GL_TEXTURE_BIT );
-
- try {
- while( ! input.eof() ) {
- getline( input, line );
- if( input.fail() ) {
- /* If we fail to read, break */
- break ;
- }
- trim( line );
-
- /* handle the case for points/normals/texture points */
- if( ! line.compare( 0, 2, "v " ) ) {
- verts.push_back( p_read_point__( line.c_str() + 2 ) );
- } else if ( ! line.compare( 0, 2, "vn" ) ) {
- norms.push_back( p_read_normal__( line.c_str() + 2 ) );
- } else if ( ! line.compare( 0, 2, "vt" ) ) {
- tex_points.push_back( p_read_tex_point__( line.c_str() + 2 ) );
+ if (Kn) {
+ norms[Kn - 1].plot();
}
-
- /* build the face */
- else if( line[0] == 'f' ) {
- const char* lineptr = line.c_str() + 1;
- { GloxScopedBegin p_gsb__( GL_POLYGON );
- stringstream linestream( lineptr );
- std::string word;
- while( ! linestream.eof() ) {
- unsigned int Kv = 0;
- unsigned int Kt = 0;
- unsigned int Kn = 0;
-
- linestream >> word;
-
- if( ! (sscanf( word.c_str(), "%u/%u/%u", &Kv, &Kt, &Kn ) == 3 ||
- sscanf( word.c_str(), "%u//%u", &Kv, &Kn ) == 2 ||
- sscanf( word.c_str(), "%u", &Kv ) == 1 ) ){
- throw "Invalid facet!";
- }
-
- if ( Kv > verts.size() ) throw "Vertex out of range!";
- if ( Kn > norms.size() ) throw "Normal out of range!";
- if ( Kt > tex_points.size() ) throw "Texture out of range!";
-
- float arr[4];
- // cout << "face (" << Kv << ", " << Kt << ", " << Kn << ")" << endl;
- if ( Kt ) {
- arr[0] = tex_points[Kt-1].first;
- arr[1] = tex_points[Kt-1].second;
- glTexCoord2fv( arr );
- }
- if( Kn ) {
- norms[Kn - 1].plot();
- } if( Kv ) {
- verts[Kv - 1].plot();
- }
-
- }} /* End GloxScopedBegin */
-
- } else {
- stringstream linestream( line );
- string word;
- linestream >> word;
-
- if( word == "usemtl" ) {
- /* use the material in the next word */
- linestream >> word;
- setMaterial( word.c_str() );
- } else if ( word == "mtllib" ) {
- linestream >> word;
- loadMaterial( word.c_str() );
- }
+ if (Kv) {
+ verts[Kv - 1].plot();
}
+ }
+ } /* End GloxScopedBegin */
+ } else {
+ stringstream linestream(line);
+ string word;
+ linestream >> word;
+
+ if (word == "usemtl") {
+ /* use the material in the next word */
+ linestream >> word;
+ setMaterial(word.c_str());
+ } else if (word == "mtllib") {
+ linestream >> word;
+ loadMaterial(word.c_str());
}
- } catch( const char * reason ) {
- glEndList();
- char buf[512];
- snprintf( buf, 512, "%s file: %s line: %d", reason, object_loader_filename, linenum );
- object_loader_reason = buf;
- object_loader_filename = NULL;
- return NULL;
+ }
}
-
+ } catch (const char* reason) {
glEndList();
- return new SloxModelObject( display_list );
+ char buf[512];
+ snprintf(buf, 512, "%s file: %s line: %d", reason, object_loader_filename,
+ linenum);
+ object_loader_reason = buf;
+ object_loader_filename = NULL;
+ return NULL;
+ }
+
+ glEndList();
+ return new SloxModelObject(display_list);
}
-}
+} // namespace slox
diff --git a/slox/slox/private_db/SloxApplication.cpp b/slox/slox/private_db/SloxApplication.cpp
index 1ab905a..8b7c667 100644
--- a/slox/slox/private_db/SloxApplication.cpp
+++ b/slox/slox/private_db/SloxApplication.cpp
@@ -5,34 +5,35 @@
namespace slox {
-void SloxApplication::run( int argc, char** argv ) {
- SDL_Event event;
- memset( & event, 0, sizeof( event ) );
- bool run = true;
-
- /* Initialize the application */
- if( !this->initialize( argc, argv ) ) {
- fprintf( stderr, "Error initializing SloxApplication: %s\n", this->getError().c_str() );
- return ;
- }
+void SloxApplication::run(int argc, char** argv) {
+ SDL_Event event;
+ memset(&event, 0, sizeof(event));
+ bool run = true;
+
+ /* Initialize the application */
+ if (!this->initialize(argc, argv)) {
+ fprintf(stderr, "Error initializing SloxApplication: %s\n",
+ this->getError().c_str());
+ return;
+ }
- while( run ) {
- /* While we are continuing to
+ while (run) {
+ /* While we are continuing to
* run */
- while( SDL_PollEvent( & event ) ) {
- /* Iterate through the events
+ while (SDL_PollEvent(&event)) {
+ /* Iterate through the events
* and call the applications
* raw evetn handler */
- this->onEvent( event );
- }
+ this->onEvent(event);
+ }
- /* Call the main meat of this
+ /* Call the main meat of this
* loop */
- run = this->loop( SDL_GetTicks() );
- }
+ run = this->loop(SDL_GetTicks());
+ }
- /* The cleanup should be handled by
+ /* The cleanup should be handled by
* the destructor */
}
-}
+} // namespace slox
diff --git a/slox/slox/private_db/SloxRawEventHandler.cpp b/slox/slox/private_db/SloxRawEventHandler.cpp
index 825d1d9..813755e 100644
--- a/slox/slox/private_db/SloxRawEventHandler.cpp
+++ b/slox/slox/private_db/SloxRawEventHandler.cpp
@@ -4,40 +4,40 @@ using namespace std;
namespace slox {
-void SloxRawEventHandler::onEvent( const SDL_Event& event ) {
- switch( event.type ) {
- case SDL_VIDEORESIZE:
- for( vector<SloxResizeListener*>::iterator itr = resizeListeners.begin();
- itr != resizeListeners.end(); ++ itr ) {
- (*itr)->onResize( event.resize );
- }
- break;
- case SDL_KEYDOWN:
- for( vector<SloxKeyListener*>::iterator itr = keyListeners.begin();
- itr != keyListeners.end(); ++ itr ) {
- (*itr)->onKeyDown( event.key );
- }
- break;
+void SloxRawEventHandler::onEvent(const SDL_Event& event) {
+ switch (event.type) {
+ case SDL_VIDEORESIZE:
+ for (vector<SloxResizeListener*>::iterator itr = resizeListeners.begin();
+ itr != resizeListeners.end(); ++itr) {
+ (*itr)->onResize(event.resize);
+ }
+ break;
+ case SDL_KEYDOWN:
+ for (vector<SloxKeyListener*>::iterator itr = keyListeners.begin();
+ itr != keyListeners.end(); ++itr) {
+ (*itr)->onKeyDown(event.key);
+ }
+ break;
- case SDL_KEYUP:
- for( vector<SloxKeyListener*>::iterator itr = keyListeners.begin();
- itr != keyListeners.end(); ++ itr ) {
- (*itr)->onKeyUp( event.key );
- }
- break;
+ case SDL_KEYUP:
+ for (vector<SloxKeyListener*>::iterator itr = keyListeners.begin();
+ itr != keyListeners.end(); ++itr) {
+ (*itr)->onKeyUp(event.key);
+ }
+ break;
- case SDL_QUIT:
- for( vector<SloxQuitListener*>::iterator itr = quitListeners.begin();
- itr != quitListeners.end(); ++ itr ) {
- (*itr)->onQuit( event.quit );
- }
- case SDL_MOUSEMOTION:
- for( vector<SloxMouseMotionListener*>::iterator itr = mouseMotionListeners.begin();
- itr != mouseMotionListeners.end(); ++ itr ) {
- (*itr)->onMouseMoved( event.motion );
- }
-
- }
+ case SDL_QUIT:
+ for (vector<SloxQuitListener*>::iterator itr = quitListeners.begin();
+ itr != quitListeners.end(); ++itr) {
+ (*itr)->onQuit(event.quit);
+ }
+ case SDL_MOUSEMOTION:
+ for (vector<SloxMouseMotionListener*>::iterator itr =
+ mouseMotionListeners.begin();
+ itr != mouseMotionListeners.end(); ++itr) {
+ (*itr)->onMouseMoved(event.motion);
+ }
+ }
}
-}
+} // namespace slox
diff --git a/slox/slox/private_db/SloxTextureFactory.cpp b/slox/slox/private_db/SloxTextureFactory.cpp
index 58bda0e..538c57f 100644
--- a/slox/slox/private_db/SloxTextureFactory.cpp
+++ b/slox/slox/private_db/SloxTextureFactory.cpp
@@ -6,173 +6,175 @@ using namespace std;
namespace slox {
const std::string& SloxTextureFactory::getMessage() {
- return m_message;
+ return m_message;
}
-int SloxTextureFactory::getFileFromPath( const char* basename, std::string& into ) {
- struct stat st;
- char buf[4096];
- into.clear();
- for( vector<string>::iterator itr = m_path.begin(); itr < m_path.end(); ++ itr ) {
- snprintf( buf, 4096, "%s/%s", (*itr).c_str(), basename );
- if( ! stat( buf, & st ) ) {
- /* We found a file on the path */
- into = buf;
- return 0;
- }
- }
-
- /* Nothing was found */
- return 1;
+int SloxTextureFactory::getFileFromPath(const char* basename,
+ std::string& into) {
+ struct stat st;
+ char buf[4096];
+ into.clear();
+ for (vector<string>::iterator itr = m_path.begin(); itr < m_path.end();
+ ++itr) {
+ snprintf(buf, 4096, "%s/%s", (*itr).c_str(), basename);
+ if (!stat(buf, &st)) {
+ /* We found a file on the path */
+ into = buf;
+ return 0;
+ }
+ }
+
+ /* Nothing was found */
+ return 1;
}
-int SloxTextureFactory::readImageFile( const char* filename, unsigned int* texture_r ) {
- int ret = 0 ;
- unsigned int texture ;
- SDL_Surface* surface ;
- int nOfColors ;
- GLenum texture_format ;
- std::string realpath ;
-
- *texture_r = 0;
- if( getFileFromPath( filename, realpath ) ) {
- m_message = string( "File ") + filename + " does not exist on the path!" ;
- return -1 ;
+int SloxTextureFactory::readImageFile(const char* filename,
+ unsigned int* texture_r) {
+ int ret = 0;
+ unsigned int texture;
+ SDL_Surface* surface;
+ int nOfColors;
+ GLenum texture_format;
+ std::string realpath;
+
+ *texture_r = 0;
+ if (getFileFromPath(filename, realpath)) {
+ m_message = string("File ") + filename + " does not exist on the path!";
+ return -1;
+ }
+
+ if ((surface = IMG_Load(realpath.c_str()))) {
+ if (surface->w & (surface->w - 1)) {
+ m_message = "Warning: width not power of 2";
+ ret = 1;
}
- if( (surface = IMG_Load( realpath.c_str() ) ) ) {
- if ( surface->w & (surface->w - 1) ) {
- m_message = "Warning: width not power of 2" ;
- ret = 1 ;
- }
-
- if ( surface->h & (surface->h - 1) ) {
- m_message = "Warning: height not power of 2" ;
- ret = 1 ;
- }
-
- nOfColors = surface->format->BytesPerPixel ;
- if (nOfColors == 4) // contains an alpha channel
- {
- if (surface->format->Rmask == 0x000000ff)
- texture_format = GL_RGBA;
- else
- texture_format = GL_BGRA;
- } else if (nOfColors == 3) // no alpha channel
- {
- if (surface->format->Rmask == 0x000000ff)
- texture_format = GL_RGB;
- else
- texture_format = GL_BGR;
- } else {
- m_message = "warning: image not truecolor\n";
- ret = 1;
- }
-
- // Have OpenGL generate a texture object handle for us
- glGenTextures( 1, &texture );
-
- // Bind the texture object
- glBindTexture( GL_TEXTURE_2D, texture );
-
- // Set the texture's stretching properties
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
-
- // Edit the texture object's image data using the information SDL_Surface gives us
- glTexImage2D( GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0,
- texture_format, GL_UNSIGNED_BYTE, surface->pixels );
- }
- else {
- char error[ 256 ];
- snprintf( error, 256, "Error: could not load image: %s\n", SDL_GetError() );
- m_message = error;
- return -1;
- }
-
- // Free the SDL_Surface only if it was successfully created
- if ( surface ) {
- SDL_FreeSurface( surface );
+ if (surface->h & (surface->h - 1)) {
+ m_message = "Warning: height not power of 2";
+ ret = 1;
}
- *texture_r = texture;
- return ret ;
+ nOfColors = surface->format->BytesPerPixel;
+ if (nOfColors == 4) // contains an alpha channel
+ {
+ if (surface->format->Rmask == 0x000000ff)
+ texture_format = GL_RGBA;
+ else
+ texture_format = GL_BGRA;
+ } else if (nOfColors == 3) // no alpha channel
+ {
+ if (surface->format->Rmask == 0x000000ff)
+ texture_format = GL_RGB;
+ else
+ texture_format = GL_BGR;
+ } else {
+ m_message = "warning: image not truecolor\n";
+ ret = 1;
+ }
+
+ // Have OpenGL generate a texture object handle for us
+ glGenTextures(1, &texture);
+
+ // Bind the texture object
+ glBindTexture(GL_TEXTURE_2D, texture);
+
+ // Set the texture's stretching properties
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ // Edit the texture object's image data using the information SDL_Surface gives us
+ glTexImage2D(GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0,
+ texture_format, GL_UNSIGNED_BYTE, surface->pixels);
+ } else {
+ char error[256];
+ snprintf(error, 256, "Error: could not load image: %s\n", SDL_GetError());
+ m_message = error;
+ return -1;
+ }
+
+ // Free the SDL_Surface only if it was successfully created
+ if (surface) {
+ SDL_FreeSurface(surface);
+ }
+
+ *texture_r = texture;
+ return ret;
}
-int SloxTextureFactory::readBitmapFile( const char* filename, unsigned int* texture_r ) {
- int ret = 0;
- unsigned int texture;
- SDL_Surface* surface;
- int nOfColors;
- GLenum texture_format;
- std::string realpath;
-
- if( getFileFromPath( filename, realpath ) ) {
- m_message = string("File ") + filename + " does not exist on the path!";
- return -1;
- }
-
- if ( (surface = SDL_LoadBMP( realpath.c_str() )) ) {
-
- // Check that the image's width is a power of 2
- if ( (surface->w & (surface->w - 1)) != 0 ) {
- m_message = "Warning: width not power of 2" ;
- ret = 1;
- }
-
- // Also check if the height is a power of 2
- if ( (surface->h & (surface->h - 1)) != 0 ) {
- m_message = "Warning: height not power of 2";
- ret = 1;
- }
-
- // get the number of channels in the SDL surface
- nOfColors = surface->format->BytesPerPixel;
- if (nOfColors == 4) // contains an alpha channel
- {
- if (surface->format->Rmask == 0x000000ff)
- texture_format = GL_RGBA;
- else
- texture_format = GL_BGRA;
- } else if (nOfColors == 3) // no alpha channel
- {
- if (surface->format->Rmask == 0x000000ff)
- texture_format = GL_RGB;
- else
- texture_format = GL_BGR;
- } else {
- m_message = "warning: image not truecolor\n";
- // this error should not go unhandled
- }
-
- // Have OpenGL generate a texture object handle for us
- glGenTextures( 1, &texture );
-
- // Bind the texture object
- glBindTexture( GL_TEXTURE_2D, texture );
-
- // Set the texture's stretching properties
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
- glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
-
- // Edit the texture object's image data using the information SDL_Surface gives us
- glTexImage2D( GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0,
- texture_format, GL_UNSIGNED_BYTE, surface->pixels );
- }
- else {
- char error[ 256 ];
- snprintf( error, 256, "Error: could not load image: %s\n", SDL_GetError() );
- m_message = error;
- return -1;
- }
-
- // Free the SDL_Surface only if it was successfully created
- if ( surface ) {
- SDL_FreeSurface( surface );
+int SloxTextureFactory::readBitmapFile(const char* filename,
+ unsigned int* texture_r) {
+ int ret = 0;
+ unsigned int texture;
+ SDL_Surface* surface;
+ int nOfColors;
+ GLenum texture_format;
+ std::string realpath;
+
+ if (getFileFromPath(filename, realpath)) {
+ m_message = string("File ") + filename + " does not exist on the path!";
+ return -1;
+ }
+
+ if ((surface = SDL_LoadBMP(realpath.c_str()))) {
+
+ // Check that the image's width is a power of 2
+ if ((surface->w & (surface->w - 1)) != 0) {
+ m_message = "Warning: width not power of 2";
+ ret = 1;
}
- *texture_r = texture;
- return ret;
-}
+ // Also check if the height is a power of 2
+ if ((surface->h & (surface->h - 1)) != 0) {
+ m_message = "Warning: height not power of 2";
+ ret = 1;
+ }
+
+ // get the number of channels in the SDL surface
+ nOfColors = surface->format->BytesPerPixel;
+ if (nOfColors == 4) // contains an alpha channel
+ {
+ if (surface->format->Rmask == 0x000000ff)
+ texture_format = GL_RGBA;
+ else
+ texture_format = GL_BGRA;
+ } else if (nOfColors == 3) // no alpha channel
+ {
+ if (surface->format->Rmask == 0x000000ff)
+ texture_format = GL_RGB;
+ else
+ texture_format = GL_BGR;
+ } else {
+ m_message = "warning: image not truecolor\n";
+ // this error should not go unhandled
+ }
+ // Have OpenGL generate a texture object handle for us
+ glGenTextures(1, &texture);
+
+ // Bind the texture object
+ glBindTexture(GL_TEXTURE_2D, texture);
+
+ // Set the texture's stretching properties
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ // Edit the texture object's image data using the information SDL_Surface gives us
+ glTexImage2D(GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0,
+ texture_format, GL_UNSIGNED_BYTE, surface->pixels);
+ } else {
+ char error[256];
+ snprintf(error, 256, "Error: could not load image: %s\n", SDL_GetError());
+ m_message = error;
+ return -1;
+ }
+
+ // Free the SDL_Surface only if it was successfully created
+ if (surface) {
+ SDL_FreeSurface(surface);
+ }
+
+ *texture_r = texture;
+ return ret;
}
+
+} // namespace slox
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();
}