From 46efbf05fcade8199035f956e20a63ca91fc88fd Mon Sep 17 00:00:00 2001 From: Josh Rahm Date: Tue, 23 Dec 2025 12:59:23 -0700 Subject: Run clang-format and add .clang-format --- glox/compat/glox/GloxLightSource.hpp | 135 +++++----- glox/compat/glox/GloxLightSourceManager.hpp | 28 +- glox/compat/glox/objects/GloxCube.hpp | 55 ++-- glox/compat/glox/objects/GloxSphere.hpp | 6 +- glox/compat/glox/objects/GloxTexturedCube.hpp | 185 +++++++------ glox/compat/glox/objects/GloxTexturedSphere.hpp | 42 +-- glox/compat/glox/objects/examples/GloxCylinder.hpp | 77 +++--- glox/glox/GloxColor.hpp | 165 ++++++------ glox/glox/GloxCommon.hpp | 89 +++--- glox/glox/GloxDebug.hpp | 84 +++--- glox/glox/GloxFirstPersonPerspective.hpp | 73 +++-- glox/glox/GloxLookAtPerspective.hpp | 75 +++--- glox/glox/GloxNormal.hpp | 135 +++++----- glox/glox/GloxObject.hpp | 8 +- glox/glox/GloxPerspective.hpp | 35 ++- glox/glox/GloxPlottable.hpp | 8 +- glox/glox/GloxPoint.hpp | 298 ++++++++++----------- glox/glox/GloxPointCollection.hpp | 111 ++++---- glox/glox/GloxPointNormal.hpp | 77 +++--- glox/glox/GloxPointNormalTexture.hpp | 51 ++-- glox/glox/GloxProgram.hpp | 96 +++---- glox/glox/GloxQuadStrip.hpp | 49 ++-- glox/glox/GloxRenderable.hpp | 6 +- glox/glox/GloxRotation.hpp | 43 +-- glox/glox/GloxScopedAttributes.hpp | 16 +- glox/glox/GloxScopedBegin.hpp | 12 +- glox/glox/GloxScopedRotation.hpp | 28 +- glox/glox/GloxScopedTranslation.hpp | 16 +- glox/glox/GloxShader.hpp | 40 ++- glox/glox/GloxStandardProjection.hpp | 77 +++--- glox/glox/GloxState.hpp | 64 ++--- glox/glox/GloxTexture.hpp | 18 +- glox/glox/GloxTextureFactory.hpp | 28 +- glox/glox/GloxTextureRepeat.hpp | 61 ++--- glox/glox/GloxVector3.hpp | 126 +++++---- glox/glox/GloxVector4.hpp | 86 +++--- glox/glox/GloxVectorizable.hpp | 18 +- glox/glox/GloxViewport.hpp | 45 ++-- glox/glox/src/GloxCube.cpp | 128 ++++----- glox/glox/src/GloxCylinder.cpp | 74 ++--- glox/glox/src/GloxFirstPersonPerspective.cpp | 38 +-- glox/glox/src/GloxLightSource.cpp | 81 +++--- glox/glox/src/GloxLightSourceManager.cpp | 49 ++-- glox/glox/src/GloxProgram.cpp | 110 ++++---- glox/glox/src/GloxShader.cpp | 89 +++--- glox/glox/src/GloxTextureFactory.cpp | 238 ++++++++-------- glox/glox/src/GloxTexturedCube.cpp | 248 +++++++++-------- glox/glox/src/GloxTexturedSphere.cpp | 72 +++-- 48 files changed, 1812 insertions(+), 1881 deletions(-) (limited to 'glox') 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: */ -#include "glox/GloxPoint.hpp" #include "glox/GloxColor.hpp" +#include "glox/GloxPoint.hpp" #include "glox/GloxRenderable.hpp" #include @@ -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 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 M_lm_map_t; + typedef std::map 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 _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: */ -#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& 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& 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& getPosition() const { - return m_position; - } - - /* Sets the position of this Cylinder */ - inline void setPosition( const GloxPoint& new_pos ) { - m_position = new_pos; + inline const GloxPoint& getPosition() const { return m_position; } + + /* Sets the position of this Cylinder */ + inline void setPosition(const GloxPoint& 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 m_position; - - /* the cylinder is basically just a quad + private: + /* The position of this cylinder */ + GloxPoint m_position; + + /* the cylinder is basically just a quad * strip. This object supports lighting, * so the components are PointNormals */ - GloxQuadStrip< GloxPointNormalTexture > m_body; + GloxQuadStrip 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 #include +#include namespace glox { /* This is a color class, it is for * convinience */ -class GloxColor : public GloxRenderable,GloxVectorizable,GloxVectorizable { -public: - /* Creates a new color that is defined +class GloxColor : public GloxRenderable, + GloxVectorizable, + GloxVectorizable { + 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 - 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 + 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 -#include #include #include +#include #include /* 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& 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& 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 +#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 #include +#include namespace glox { /* Type that the GloxNormal holds, * defaults to an integer */ -template +template /* 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& other ) : - x(other.x), y(other.y), z(other.z) {} + /* Copies the glox normal other */ + inline GloxNormal(const GloxNormal& 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& operator=( const GloxNormal& normal ) { - this->x = normal.x; - this->y = normal.y; - this->z = normal.z; + inline const GloxNormal& operator=(const GloxNormal& 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& operator+=( const GloxNormal& normal ) { - this->x += normal.x; - this->y += normal.y; - this->z += normal.z; + /* Add the components of `normal` to this */ + inline GloxNormal& operator+=(const GloxNormal& 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 operator+( const GloxNormal& normal ) const { - GloxNormal 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 operator+(const GloxNormal& normal) const { + GloxNormal 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::plot() const { - glNormal3i( this->getX(), this->getY(), this->getZ() ); + glNormal3i(this->getX(), this->getY(), this->getZ()); } template <> inline void GloxNormal::plot() const { - glNormal3f( this->getX(), this->getY(), this->getZ() ); + glNormal3f(this->getX(), this->getY(), this->getZ()); } template <> inline void GloxNormal::plot() const { - glNormal3s( this->getX(), this->getY(), this->getZ() ); + glNormal3s(this->getX(), this->getY(), this->getZ()); } template inline void GloxNormal::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: */ -#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 -#include #include +#include #include @@ -22,187 +22,171 @@ namespace glox { /* Type that the GloxPoint holds, * defaults to an integer */ -template +template /* 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 { -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& vec ) { - return fromSpherical( vec.getX(), vec.getY(), vec.getZ() ); - } - - /* Creates a new GloxPoint from the components +class GloxPoint : public GloxPlottable, GloxVectorizable { + 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& 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& other ) : - x(other.x), y(other.y), z(other.z) {} + /* Copies the glox point other */ + inline GloxPoint(const GloxPoint& 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& operator=( const GloxPoint& point ) { - this->x = point.x; - this->y = point.y; - this->z = point.z; + inline const GloxPoint& operator=(const GloxPoint& 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& operator+=( const GloxPoint& point ) { - this->x += point.x; - this->y += point.y; - this->z += point.z; + /* Add the components of `point` to this */ + inline GloxPoint& operator+=(const GloxPoint& 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& operator-=( const GloxPoint& point ) { - this->x -= point.x; - this->y -= point.y; - this->z -= point.z; + /* Add the components of `point` to this */ + inline GloxPoint& operator-=(const GloxPoint& 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 operator+( const GloxPoint& point ) const { - GloxPoint ret = *this; - ret += point; - return ret; - } + inline GloxPoint operator+(const GloxPoint& point) const { + GloxPoint 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 operator-( const GloxPoint& point ) const { - GloxPoint ret = *this; - ret -= point; - return ret; - } - - inline GloxPoint& operator*=( NumT scalar ) { - x *= scalar; - y *= scalar; - z *= scalar; - return * this; - } - - inline GloxPoint operator*(NumT scalar) const { - GloxPoint ret = * this; - ret *= scalar; - return ret; - } - - inline NumT dot( const GloxPoint& 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 cross( const GloxPoint& 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 operator-(const GloxPoint& point) const { + GloxPoint ret = *this; + ret -= point; + return ret; + } + + inline GloxPoint& operator*=(NumT scalar) { + x *= scalar; + y *= scalar; + z *= scalar; + return *this; + } + + inline GloxPoint operator*(NumT scalar) const { + GloxPoint ret = *this; + ret *= scalar; + return ret; + } + + inline NumT dot(const GloxPoint& 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 cross(const GloxPoint& 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::plot() const { - glVertex3i( this->getX(), this->getY(), this->getZ() ); + glVertex3i(this->getX(), this->getY(), this->getZ()); } template <> inline void GloxPoint::plot() const { - glVertex3f( this->getX(), this->getY(), this->getZ() ); + glVertex3f(this->getX(), this->getY(), this->getZ()); } template <> inline void GloxPoint::plot() const { - glVertex3s( this->getX(), this->getY(), this->getZ() ); + glVertex3s(this->getX(), this->getY(), this->getZ()); } template inline void GloxPoint::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: */ +#include "glox/GloxDebug.hpp" #include "glox/GloxPlottable.hpp" #include "glox/GloxPoint.hpp" -#include "glox/GloxDebug.hpp" -#include -#include #include +#include +#include namespace glox { -template < class PlottableT=GloxPoint > +template > /* 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 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: */ +#include "glox/GloxNormal.hpp" #include "glox/GloxPlottable.hpp" #include "glox/GloxPoint.hpp" -#include "glox/GloxNormal.hpp" -#include #include +#include namespace glox { /* The number type used by both * the point and the normal to use */ -template +template /* 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& point, const GloxNormal& normal ) : - m_point( point ), m_normal( normal ) {} + GloxPointNormal(const GloxPoint& point, const GloxNormal