redhand::game_object class

The game_object is a complex object which can be displayed in a world.

It is the first abstraction layer and is a very low level openGL object. You can create a game_object by specifying all the points, and which points form a triangel. If nothing else is specified, the default shader is used to render this object. Please use a shader which is added to the same world as the game_object in order to prevent errors.

The Points specified are all local coordinates. This means they are in the first sector of a 2 dimensional coordinate system. If there is any point outside of this range the creation of the object will fail. For each point you must also specify the color of that point.

Each game_object has a name which is "game_object" by default.

In addition to that the object also holds its position, rotation and scale in world coordinates.

Constructors, destructors, conversion operators

game_object() protected
Construct an empty game_object, no buffers are initilized and not configuration set.
game_object(game_object_properties properties)
Construct a new game object object form a given set of properties.
~game_object() virtual
Destroy the game object.

Public functions

auto getShader() -> std::shared_ptr<redhand::shader>
This function returns a pointer to the attached shader.
void draw(redhand::drawing_event evt) virtual
This function draws the object on the screen.
void onLoop(game_loop_event evt) virtual
The loop function of the object.
auto hasErrord() -> bool
false if no error has happened
auto getPosition() -> glm::vec2 virtual
Get the Position of the object.
void setPosition(glm::vec2 pos) virtual
Set the Position of the object.
void move(glm::vec2 delta_pos) virtual
moves the object by the specified amount
auto getRotation() -> float virtual
gets the rotation in degrees
void setRotation(float rot) virtual
sets the objects rotation by the specified amount in degrees counterclockwise
void rotate(float delta_rot) virtual
Rotates the object by the specified amount in degrees counterclockwise.
void setColorAlpha(float alpha) virtual
set the alpha value of the color
void setScreenSize(int width, int height) virtual
Sets the screen size to let the object scale the texture correctly.
void setName(std::string name) virtual
This function sets the name of the game_object to the given string.
auto getName() -> std::string_view
This funtion returns the name of the object.
auto getScale() -> glm::vec2
get the scal of the object
auto getHitbox() -> std::vector<glm::vec2> virtual
Get the Hitbox of the game_object.

Protected functions

void updateWorldTransformation() virtual
this function updates the world_transformation matrix using the game_object_properties.
void updateBuffers()
this function refreshed the gpu buffers

Protected variables

unsigned int VAO
The identifier of the Video Array Object.
unsigned int VBO
The identifier of the Video Buffer Object.
unsigned int EBO
The identifier of the Element Buffer Object.
std::vector<float> data
This array stores the data of all the vertecies.
std::shared_mutex mutex_data
lock the point_data of the object
unsigned int texture_mode
The texture mode of the object.
std::shared_mutex mutex_texture_mode
lock the texture_mode of the object
bool has_errored
false if no error happened
std::shared_mutex mutex_has_errored
lock the has_errored of the object
redhand::game_object_properties object_properties
The properties of this object.
std::shared_mutex mutex_object_properties
lock the properties of the object
glm::vec2 texture_scale
The scaling factor of the attached texture along the x and y axis.
std::shared_mutex mutex_texture_scale
lock the texture_scale of the object
std::shared_mutex mutex_game_object
The lock for the object.
glm::mat4 world_transformation
The matrix for the world transformation (rotation,scaling and moving)
std::shared_mutex mutex_world_transformation
lock the world_transformation of the object

Function documentation

redhand::game_object::game_object(game_object_properties properties)

Construct a new game object object form a given set of properties.

Parameters
properties The properties that should be used.

glm::vec2 redhand::game_object::getPosition() virtual

Get the Position of the object.

Returns std::array<float,2>

void redhand::game_object::setPosition(glm::vec2 pos) virtual

Set the Position of the object.

Parameters
pos a vector with the in x and y direction in world scale

void redhand::game_object::move(glm::vec2 delta_pos) virtual

moves the object by the specified amount

Parameters
delta_pos a vector with the difference in x and y direction in world scale

void redhand::game_object::setRotation(float rot) virtual

sets the objects rotation by the specified amount in degrees counterclockwise

Parameters
rot the new rotation in degrees

void redhand::game_object::setColorAlpha(float alpha) virtual

set the alpha value of the color

Parameters
alpha The new alpha value of the color

void redhand::game_object::setScreenSize(int width, int height) virtual

Sets the screen size to let the object scale the texture correctly.

Parameters
width the width of the screen
height the height of he screen

glm::vec2 redhand::game_object::getScale()

get the scal of the object

Returns std::array<float,2> [0] = x scale and [1] is y scale

std::vector<glm::vec2> redhand::game_object::getHitbox() virtual

Get the Hitbox of the game_object.

Returns std::vector<glm::vec2> the hitbox of the game_object.

void redhand::game_object::updateBuffers() protected

this function refreshed the gpu buffers

Create arrays and buffers