aboutsummaryrefslogtreecommitdiff
path: root/glox
diff options
context:
space:
mode:
Diffstat (limited to 'glox')
-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
48 files changed, 1812 insertions, 1881 deletions
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