AGL  0
3D graphics library
Entity Class Reference

The Entity; basically all visible objects in AGL. More...

Inheritance diagram for Entity:
Collaboration diagram for Entity:

Public Member Functions

 Entity (const glm::vec3 &pos=glm::vec3(0))
 Create an entity centered at pos. More...
 
 Entity (const Entity &other)
 Create an entity from data copied from other. More...
 
 ~Entity ()
 
void translate (const glm::vec3 &d=glm::vec3(0))
 Translate (move,shift) the entity. More...
 
void translate (float dx=0, float dy=0, float dz=0)
 Translate (move, shift) the entity. More...
 
void rotate (float rad=0, glm::vec3 axis=glm::vec3(0))
 Rotate the entity. More...
 
void scale (const glm::vec3 &s=glm::vec3(1))
 Scale the entity. More...
 
void scale (float sx=1, float sy=std::nanf(""), float sz=std::nanf(""))
 Scale the entity. More...
 
void transform (const glm::mat4 &m)
 Transform the entity. More...
 
void applyTransform ()
 Transform the vertices permanently. More...
 
void add (BaseEntity &e)
 Add an Entity or Light as a child of the entity. More...
 
virtual void mergeData ()
 Merge the vertices, normals and uvs into a single merged array. More...
 
virtual void createBuffers ()
 Create all the buffers for rendering. More...
 
glm::mat4 getMatM ()
 Get the model matrix. More...
 
- Public Member Functions inherited from BaseEntity
virtual ~BaseEntity ()
 

Public Attributes

GLuint VAO = 0
 Vertex array. More...
 
GLuint VBO = 0
 Vertex buffer. More...
 
GLuint EBO = 0
 Index buffer. More...
 
bool dynamic = false
 If true, the material is dynamic, ie. vertices might change during runtime. More...
 
std::vector< GLfloat > vertices
 Vertices. More...
 
std::vector< GLfloat > normals
 Normals. More...
 
std::vector< GLfloat > uvs
 Texture coordinates. More...
 
std::vector< GLfloat > merged
 The final combination of vertices, normals, and uvs. More...
 
std::vector< GLuint > indices
 Indices. More...
 
glm::vec3 position
 Position of the entity, the entity is centered here. More...
 
glm::mat4 model
 The model matrix for the entity. This is the M part of the MVP matrix. This is responsible for all the transformations of this entity. More...
 
Material material
 Material for shading this entity. More...
 
std::vector< BaseEntity * > children
 Children of this entity. More...
 
- Public Attributes inherited from BaseEntity
Entityparent = nullptr
 Parent of the entity, whose child this is. All transformations of the parent is also applied to the child. More...
 

Detailed Description

The Entity; basically all visible objects in AGL.

Entity consists of anything that is visible on the scene. The entities consists of

  • vertices: Each vertex is a point on the 3D coordinate. A shape consists of multiple vertices connected by edges. Three such adjacent edges (ie. three vertices) combines to form a triangular face of the entity.
  • normals: Each of the vertices can consist of a normal, a 3D vector pointing perpendicularly away from the surface that defines the surface and possibly it's orientation. Normals are generally used for lighting calculations.
  • uvs (texture coordinates): Each of the vertices can also contain a 2D texture coordinate. This is used to map a texture on the surface of the entity.
  • indices: Indices are a set of triplets of index, each defining a face of the entity. Since an entity can only have triangular faces with three vertices, each triplet of indices defines a single face. The index is formed with the 0-indexed position of the vertices. For example, a triplet of (0, 1, 2) defines the face formed by the vertices at the first, second and third position in the vertices array.

Constructor & Destructor Documentation

◆ Entity() [1/2]

Entity ( const glm::vec3 &  pos = glm::vec3(0))

Create an entity centered at pos.

Parameters
posPosition of the entity.

◆ Entity() [2/2]

Entity ( const Entity other)

Create an entity from data copied from other.

Parameters
otherAnother entity for the copy constructor.

◆ ~Entity()

~Entity ( )

Member Function Documentation

◆ add()

void add ( BaseEntity e)

Add an Entity or Light as a child of the entity.

Parameters
eEntity or Light to add.

◆ applyTransform()

void applyTransform ( )

Transform the vertices permanently.

After this operation, all the transformations will be applied to all the vertices and normals. The model matrix will reset to an identity matrix.

◆ createBuffers()

void createBuffers ( )
virtual

Create all the buffers for rendering.

Reimplemented in SharedEntity.

◆ getMatM()

glm::mat4 getMatM ( )

Get the model matrix.

Returns
The model matrix after accounting for the shift due to position and parent transformations.

◆ mergeData()

void mergeData ( )
virtual

Merge the vertices, normals and uvs into a single merged array.

Reimplemented in SharedEntity.

◆ rotate()

void rotate ( float  rad = 0,
glm::vec3  axis = glm::vec3(0) 
)

Rotate the entity.

Parameters
radAngle to rotate by, in radians.
axisAxis of rotation.

◆ scale() [1/2]

void scale ( const glm::vec3 &  s = glm::vec3(1))

Scale the entity.

Parameters
sVector to scale by.

◆ scale() [2/2]

void scale ( float  sx = 1,
float  sy = std::nanf(""),
float  sz = std::nanf("") 
)

Scale the entity.

Parameters
sxAmount to scale along the x-axis.
syAmount to scale along the y-axis.
szAmount to scale along the z-axis.

If sy and sz is unspecified, they default to sx. If only sz is unspecified, it defaults to 1.

◆ transform()

void transform ( const glm::mat4 &  m)

Transform the entity.

Parameters
mMatrix to transform by.

◆ translate() [1/2]

void translate ( const glm::vec3 &  d = glm::vec3(0))

Translate (move,shift) the entity.

Parameters
dVector to translate by.

◆ translate() [2/2]

void translate ( float  dx = 0,
float  dy = 0,
float  dz = 0 
)

Translate (move, shift) the entity.

Parameters
dxAmount to translate along the x-axis.
dyAmount to translate along the y-axis.
dzAmount to translate along the z-axis.

Member Data Documentation

◆ children

std::vector<BaseEntity*> children

Children of this entity.

◆ dynamic

bool dynamic = false

If true, the material is dynamic, ie. vertices might change during runtime.

◆ EBO

GLuint EBO = 0

Index buffer.

◆ indices

std::vector<GLuint> indices

Indices.

◆ material

Material material

Material for shading this entity.

◆ merged

std::vector<GLfloat> merged

The final combination of vertices, normals, and uvs.

◆ model

glm::mat4 model

The model matrix for the entity. This is the M part of the MVP matrix. This is responsible for all the transformations of this entity.

◆ normals

std::vector<GLfloat> normals

Normals.

◆ position

glm::vec3 position

Position of the entity, the entity is centered here.

◆ uvs

std::vector<GLfloat> uvs

Texture coordinates.

◆ VAO

GLuint VAO = 0

Vertex array.

◆ VBO

GLuint VBO = 0

Vertex buffer.

◆ vertices

std::vector<GLfloat> vertices

Vertices.


The documentation for this class was generated from the following files: