TDME2  1.9.200
TransparentRenderFacesPool.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <vector>
5 
6 #include <tdme/tdme.h>
15 #include <tdme/math/fwd-tdme.h>
16 #include <tdme/math/Matrix4x4.h>
17 #include <tdme/math/Vector3.h>
19 #include <tdme/utilities/Console.h>
20 #include <tdme/utilities/Pool.h>
21 
22 using std::string;
23 using std::vector;
24 
37 
38 /**
39  * Transparent render faces pool
40  * @author andreas.drewke
41  */
43 {
44  friend class EntityRenderer;
45  friend class tdme::engine::Engine;
46 
47 private:
48  static constexpr int32_t FACES_MAX { 16384 };
49  vector<TransparentRenderFace*> transparentRenderFaces;
51 
52 public:
53  // forbid class copy
55 
56  /**
57  * Public constructor
58  */
60 
61  /**
62  * Creates an array of transparent render faces from
63  * @param modelViewMatrix model view matrix
64  * @param objectNode object node
65  * @param facesEntityIdx faces entity index
66  * @param faceIdx face index
67  */
68  inline void createTransparentRenderFaces(Matrix4x4& modelViewMatrix, ObjectNode* objectNode, int32_t facesEntityIdx, int32_t faceIdx) {
69  // retrieve objects we need
70  const auto& facesEntities = objectNode->node->getFacesEntities();
71  const auto& facesEntity = facesEntities[facesEntityIdx];
72  const auto& faces = facesEntity.getFaces();
73  const auto& nodeTransformedVertices = objectNode->mesh->vertices;
74  // objects we will use for calculations
75  float distanceFromCamera;
76  Vector3 faceCenter;
77  // create transparent render faces
78  for (auto i = 0; i < faces.size(); i++) {
79  // check for pool overflow
81  Console::println(string("TransparentRenderFacesPool::createTransparentRenderFaces(): Too many transparent render faces"));
82  break;
83  }
84  // set up face
85  auto faceVertexIndices = faces[i].getVertexIndices();
86  faceCenter.set(0.0f, 0.0f, 0.0f);
87  faceCenter.add((*nodeTransformedVertices)[faceVertexIndices[0]]);
88  faceCenter.add((*nodeTransformedVertices)[faceVertexIndices[1]]);
89  faceCenter.add((*nodeTransformedVertices)[faceVertexIndices[2]]);
90  faceCenter.scale(1.0f / 3.0f);
91  faceCenter = modelViewMatrix.multiply(faceCenter);
92  distanceFromCamera = -faceCenter.getZ();
93  // create transparent render face
94  auto transparentRenderFace = transparentRenderFacesPool.allocate();
95  transparentRenderFace->objectNode = objectNode;
96  transparentRenderFace->facesEntityIdx = facesEntityIdx;
97  transparentRenderFace->faceIdx = faceIdx;
98  transparentRenderFace->distanceFromCamera = distanceFromCamera;
99  transparentRenderFaces.push_back(transparentRenderFace);
100  faceIdx++;
101  }
102  }
103 
104  /**
105  * Merges given transparent render faces pool into this pool
106  * @param srcTransparentRenderFacesPool transparent render faces pool
107  */
108  inline void merge(TransparentRenderFacesPool* srcTransparentRenderFacesPool) {
109  for (auto srcTransparentRenderFace: srcTransparentRenderFacesPool->transparentRenderFaces) {
110  auto transparentRenderFace = transparentRenderFacesPool.allocate();
111  *transparentRenderFace = *srcTransparentRenderFace;
112  transparentRenderFaces.push_back(transparentRenderFace);
113  }
114  }
115 
116  /**
117  * Reset
118  */
119  inline void reset() {
121  transparentRenderFaces.clear();
122  }
123 
124  /**
125  * @return transparent render faces vector
126  */
127  inline vector<TransparentRenderFace*>& getTransparentRenderFaces() {
128  return transparentRenderFaces;
129  }
130 
131  /**
132  * @return allocated faces
133  */
134  inline int32_t size() {
136  }
137 
138 };
Engine main class.
Definition: Engine.h:131
Represents a model face, consisting of vertex, normal, tangent and bitangent vectors,...
Definition: Face.h:18
Node faces entity A node can have multiple entities containing faces and a applied material.
Definition: FacesEntity.h:23
Model node.
Definition: Node.h:32
const vector< FacesEntity > & getFacesEntities() const
Definition: Node.h:260
Object node mesh specifically for rendering.
Object node specifically for rendering.
Definition: ObjectNode.h:41
TransparentRenderFacesPool_TransparentRenderFacesPool transparentRenderFacesPool
void createTransparentRenderFaces(Matrix4x4 &modelViewMatrix, ObjectNode *objectNode, int32_t facesEntityIdx, int32_t faceIdx)
Creates an array of transparent render faces from.
void merge(TransparentRenderFacesPool *srcTransparentRenderFacesPool)
Merges given transparent render faces pool into this pool.
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
Definition: Matrix4x4.h:23
Vector3 multiply(const Vector3 &vector3) const
Multiplies this matrix with vector3.
Definition: Matrix4x4.h:225
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20
float getZ() const
Definition: Vector3.h:134
Vector3 & add(float scalar)
Adds a scalar.
Definition: Vector3.h:153
Vector3 & scale(float scalar)
Scales by scalar.
Definition: Vector3.h:201
Vector3 & set(float x, float y, float z)
Sets this vector3 by its components.
Definition: Vector3.h:70
Console class.
Definition: Console.h:29
Pool template class.
Definition: Pool.h:20
T * allocate()
Allocate a new element from pool.
Definition: Pool.h:55
int32_t size()
Definition: Pool.h:91
void reset()
Reset this pool.
Definition: Pool.h:98
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6