PROTO::KLUDGE  0.1
Quick prototyping library for games using SDL and OpenGL.
GLTransformable.hpp
Go to the documentation of this file.
1 #ifndef GLTRANSFORMABLE_HPP
2 #define GLTRANSFORMABLE_HPP
3 
4 #include "GL/glew.h"
5 #include "glm/glm.hpp"
6 #include "core/GLStates.hpp"
7 
8 namespace pk
9 {
15  struct GLRect
16  {
17  GLfloat d_top;
18  GLfloat d_left;
19  GLfloat d_width;
20  GLfloat d_height;
21  };
22 
32  {
33  GLuint d_VAO;
34  GLuint d_VBO;
35  GLuint d_IBO;
36  GLsizei d_indexCount;
37  glm::mat4 d_model;
39  glm::vec2 d_origin;
40  glm::vec2 d_position;
41  GLfloat d_angle;
42  glm::vec2 d_scale;
44  };
45 
52  {
53  public:
54 
60 
61  virtual ~GLTransformable();
62 
71  void setRect(GLRect r){ m_data.d_rect = r; };
72 
80  GLRect &getRect(){ return m_data.d_rect; };
81 
88  void setWidth(GLfloat w){ m_data.d_rect.d_width = w; };
89 
96  GLfloat &getWidth(){ return m_data.d_rect.d_width; };
97 
105  void setHeight(GLfloat h){ m_data.d_rect.d_height = h; };
106 
113  GLfloat &getHeight(){ return m_data.d_rect.d_height; };
114 
121  // specifying the origin to set.
123  void setOrigin(glm::vec2 origin){ m_data.d_origin = origin; };
124 
133  glm::vec2 &getOrigin(){ return m_data.d_origin; };
134 
141  // specifying the position to set.
143  void setPosition(glm::vec2 position){ m_data.d_position = position; };
144 
153  const glm::vec2 &getPosition(){ return m_data.d_position; };
154 
163  void move(glm::vec2 offset){ setPosition(m_data.d_position + offset); };
164 
172  void setAngle(float angle){ m_data.d_angle = angle; };
173 
180  float getAngle(){ return m_data.d_angle; };
181 
190  void rotate(float degrees){ setAngle(m_data.d_angle + degrees); };
191 
198  void setScale(glm::vec2 scale){ m_data.d_scale = scale; };
199 
205  glm::vec2 getScale(){ return m_data.d_scale; };
206 
214  void scale(glm::vec2 scale){ setScale(m_data.d_scale + scale); };
215 
221  void clear();
222 
223  public:
225  };
226 }
227 
228 #endif // GLTRANSFORMABLE_HPP
GLfloat & getHeight()
Get the height of the GLTransformable.
Definition: GLTransformable.hpp:113
void clear()
Clear the buffers and reset the GLTransformable to an uninitialized state.
Definition: GLTransformable.hpp:214
void setRect(GLRect r)
Set the bounding rectangle for the GLTransformable object. Useful for calculating origin and size def...
Definition: GLTransformable.hpp:71
GLuint d_VBO
A GLuint specifying an OpenGL vertex buffer object to bind.
Definition: GLTransformable.hpp:34
Definition: Game.hpp:7
GLfloat d_width
Definition: GLTransformable.hpp:19
Decorator class for creating easing OpenGL transformations for game objects.
Definition: GLTransformable.hpp:51
glm::vec2 d_origin
A vector of floats representing the origin of the GLTransformable.
Definition: GLTransformable.hpp:39
GLfloat d_left
Definition: GLTransformable.hpp:18
void setWidth(GLfloat w)
Convenient function for setting the width of the GLTransformable.
Definition: GLTransformable.hpp:88
GLsizei d_indexCount
The number of indices in the OpenGL index buffer object.
Definition: GLTransformable.hpp:36
glm::mat4 d_model
An OpenGL Model matrix.
Definition: GLTransformable.hpp:37
void scale(glm::vec2 scale)
Scale the GLTransformable by a constant factor specified as a glm::vec2 of floats.
Definition: GLTransformable.hpp:214
GLRect & getRect()
Get the current bounding rectangle of the GLTransformable object.
Definition: GLTransformable.hpp:80
GLRect d_rect
A struct containing information necessary for calculating size and origin of an object.
Definition: GLTransformable.hpp:43
GLTransformData m_data
Internal transform data for GLTransformable inherited classes.
Definition: GLTransformable.hpp:224
glm::vec2 d_scale
A vector of floats representing the scale of the GLTransformable.
Definition: GLTransformable.hpp:42
GLuint d_VAO
A GLuint specifying an OpenGL vertex array object to bind.
Definition: GLTransformable.hpp:33
void setHeight(GLfloat h)
Definition: GLTransformable.hpp:105
const glm::vec2 & getPosition()
Get the position of the GLTransformable in screen coordinates (NOT normalized coordinates such as cli...
Definition: GLTransformable.hpp:153
Transform data for GLTransformable objects. Used by the GLTransformable class internally, but usable in isolation as well.
Definition: GLTransformable.hpp:31
GLfloat & getWidth()
Get the width of the GLTransformable.
Definition: GLTransformable.hpp:96
GLfloat d_angle
The angle of rotation for the GLTransformable specified in degrees (NOT radians). ...
Definition: GLTransformable.hpp:41
GLStates d_glStates
The available OpenGL state used for rendering.
Definition: GLTransformable.hpp:38
glm::vec2 d_position
A vector of floats representing the position of the GLTransformable.
Definition: GLTransformable.hpp:40
Stores the states used to draw OpenGL objects.
Definition: GLStates.hpp:16
Useful for defining size and origin of an OpenGL object.
Definition: GLTransformable.hpp:15
glm::vec2 & getOrigin()
Get the origin of the GLTransformable in screen coordinates (NOT normalized coordinates such as clip ...
Definition: GLTransformable.hpp:133
GLuint d_IBO
A GLuint specifying an OpenGL index buffer object to bind.
Definition: GLTransformable.hpp:35
void setScale(glm::vec2 scale)
Set the scale of the GLTransformable.
Definition: GLTransformable.hpp:198
float getAngle()
Get the angle of the GLTransformable (in degrees, NOT radians).
Definition: GLTransformable.hpp:180
void setPosition(glm::vec2 position)
Set the position of the GLTransformable in screen coordinates (NOT normalized coordinates such as cli...
Definition: GLTransformable.hpp:143
void setOrigin(glm::vec2 origin)
Set the origin of the GLTransformable in screen coordinates (NOT normalized coordinates such as clip ...
Definition: GLTransformable.hpp:123
glm::vec2 getScale()
Get the scale of the GLTransformable.
Definition: GLTransformable.hpp:205
void rotate(float degrees)
Rotate the GLTransformable by a constant value (in degrees, NOT radians). (in degrees, NOT radians).
Definition: GLTransformable.hpp:190
void setAngle(float angle)
Set the angle of the GLTransformable (in degrees, NOT radians).
Definition: GLTransformable.hpp:172
virtual ~GLTransformable()
GLfloat d_top
Definition: GLTransformable.hpp:17
GLfloat d_height
Definition: GLTransformable.hpp:20
void move(glm::vec2 offset)
Move the GLTransformable by a constant offset value in screen coordinates (NOT normalized coordinates...
Definition: GLTransformable.hpp:163
GLTransformable()
Default constructor.