TDME2 1.9.121
Object3DBase_TransformedFacesIterator.cpp
Go to the documentation of this file.
2
3#include <tdme/tdme.h>
10#include <tdme/math/Matrix4x4.h>
11#include <tdme/math/Vector3.h>
12
22
23Object3DBase_TransformedFacesIterator::Object3DBase_TransformedFacesIterator(Object3DBase* object3DBase)
24{
25 this->object3DBase = object3DBase;
26 reset();
27}
28
30{
31 faceCount = 0;
32 for (auto object3DNode : object3DBase->object3dNodes) {
33 for (auto& facesEntity : object3DNode->node->getFacesEntities()) {
34 faceCount += facesEntity.getFaces().size();
35 }
36 }
37 faceIdx = 0;
38 faceIdxTotal = 0;
41 auto object3DNode = object3DBase->object3dNodes[object3DNodeIdx];
42 if (object3DNode->mesh->skinning == true) {
44 } else {
45 matrix.set(*object3DNode->nodeTransformationsMatrix);
46 }
48 node = object3DNode->node;
49}
50
52 reset();
53 return this;
54}
55
57{
58 auto object3DNode = object3DBase->object3dNodes[object3DNodeIdx];
59 auto& facesEntities = object3DNode->node->getFacesEntities();
60 auto& facesEntity = facesEntities[facesEntityIdx];
61 auto& faces = facesEntity.getFaces();
62 auto& face = faces[faceIdx];
63 // compute vertices
64 auto& faceVertexIndices = face.getVertexIndices();
65 auto nodeVerticesTransformed = object3DNode->mesh->vertices;
66 vertices[0] = matrix.multiply((*nodeVerticesTransformed)[faceVertexIndices[0]]);
67 vertices[1] = matrix.multiply((*nodeVerticesTransformed)[faceVertexIndices[1]]);
68 vertices[2] = matrix.multiply((*nodeVerticesTransformed)[faceVertexIndices[2]]);
69 // set up current node
70 node = object3DNode->node;
71 // increment to next face
73 faceIdx++;
74 // check if idxes over flow, if not yet finished
75 if (faceIdxTotal < faceCount) {
76 if (faceIdx == faces.size()) {
77 faceIdx = 0;
79 if (facesEntityIdx == facesEntities.size()) {
83 if (object3DNode->mesh->skinning == true) {
85 } else {
86 matrix.set(*object3DNode->nodeTransformationsMatrix);
87 }
89 }
90 }
91 }
92 //
93 return vertices;
94}
95
Represents a model face, consisting of vertex, normal, tangent and bitangent vectors,...
Definition: Face.h:19
Node faces entity A node can have multiple entities containing faces and a applied material.
Definition: FacesEntity.h:28
Model node.
Definition: Node.h:31
Object3DBase_TransformedFacesIterator * iterator()
Return iterator ready to iterate.
const Matrix4x4 & getTransformationsMatrix() const
Definition: Object3DBase.h:279
Object 3D node mesh specifically for rendering.
Object 3d node specifically for rendering.
Definition: Object3DNode.h:39
4x4 3D Matrix class
Definition: Matrix4x4.h:24
Matrix4x4 & identity()
Setup identity matrix.
Definition: Matrix4x4.h:326
Matrix4x4 & set(float r0c0, float r1c0, float r2c0, float r3c0, float r0c1, float r1c1, float r2c1, float r3c1, float r0c2, float r1c2, float r2c2, float r3c2, float r0c3, float r1c3, float r2c3, float r3c3)
Set up matrix by values.
Definition: Matrix4x4.h:95
Vector3 multiply(const Vector3 &v) const
Multiplies a vector3 with this matrix into destination vector.
Definition: Matrix4x4.h:351
3D vector 3 class
Definition: Vector3.h:22