dynamic mesh functions

This commit is contained in:
h4570
2022-07-18 20:32:30 +02:00
parent c56c3d76db
commit f249936981
4 changed files with 30 additions and 43 deletions
@@ -24,30 +24,22 @@ class DynamicMesh : public Mesh {
explicit DynamicMesh(const DynamicMesh& mesh); explicit DynamicMesh(const DynamicMesh& mesh);
~DynamicMesh(); ~DynamicMesh();
const u8& isMother() const { return _isMother; }
/** Get position from translation matrix */
Vec4* getPosition() {
return reinterpret_cast<Vec4*>(&translation.data[3 * 4]);
}
void setPosition(const Vec4& v) {
TYRA_ASSERT(v.w == 1.0F, "Vec4 must be homogeneous");
reinterpret_cast<Vec4*>(&translation.data[3 * 4])->set(v);
}
/** Returns material, which is a mesh "subgroup". */ /** Returns material, which is a mesh "subgroup". */
DynamicMeshMaterial* getMaterial(const u32& i) const { return materials[i]; } DynamicMeshMaterial* getMaterial(const u32& i) const { return materials[i]; }
DynamicMeshMaterial** getMaterials() { return materials; }
const u32& getMaterialsCount() const { return materialsCount; } const u32& getMaterialsCount() const { return materialsCount; }
const DynamicMeshAnimState& getAnimState() const { return animState; } const DynamicMeshAnimState& getAnimState() const { return animState; }
/** Count of all vertices. */ /** Count of all vertices. */
u32 getVertexCount() { return frames[0]->getVertexCount(); } inline u32 getVertexCount() { return frames[0]->getVertexCount(); }
/** Returns single frame. */ /** Returns single frame. */
DynamicMeshFrame* getFrame(const u32& i) const { return frames[i]; } DynamicMeshFrame* getFrame(const u32& i) { return frames[i]; }
DynamicMeshFrame** getFrames() { return frames; }
/** Count of frames. Static object (not animated) will have only 1 frame. */ /** Count of frames. Static object (not animated) will have only 1 frame. */
const u32& getFramesCount() const { return framesCount; } const u32& getFramesCount() const { return framesCount; }
@@ -62,22 +54,11 @@ class DynamicMesh : public Mesh {
const u32& getStayAnimationFrame() const { return animState.stayFrame; } const u32& getStayAnimationFrame() const { return animState.stayFrame; }
M4x4 getModelMatrix() const;
// /**
// * Returns material, which is a mesh "subgroup".
// * NULL if not found.
// */
// DynamicMeshMaterial* getMaterialById(const u32& t_id) const;
/** @returns bounding box object of current frame. */ /** @returns bounding box object of current frame. */
const BBox& getCurrentBoundingBox() const { const BBox& getCurrentBoundingBox() const {
return frames[animState.currentFrame]->getBBox(); return frames[animState.currentFrame]->getBBox();
} }
/** Check if are there any frames */
u8 isDataLoaded() const { return framesCount > 0; }
/** Loop in one frame */ /** Loop in one frame */
void playAnimation(const u32& t_frame) { playAnimation(t_frame, t_frame); } void playAnimation(const u32& t_frame) { playAnimation(t_frame, t_frame); }
@@ -102,7 +83,6 @@ class DynamicMesh : public Mesh {
private: private:
void initMesh(); void initMesh();
DynamicMeshAnimState animState; DynamicMeshAnimState animState;
u8 _isMother;
u32 framesCount, materialsCount; u32 framesCount, materialsCount;
DynamicMeshFrame** frames; DynamicMeshFrame** frames;
DynamicMeshMaterial** materials; DynamicMeshMaterial** materials;
+15 -2
View File
@@ -17,7 +17,7 @@ namespace Tyra {
class Mesh { class Mesh {
public: public:
explicit Mesh(); Mesh(const u8& isMother);
~Mesh(); ~Mesh();
/** Translation matrix */ /** Translation matrix */
@@ -29,9 +29,22 @@ class Mesh {
/** Scale matrix */ /** Scale matrix */
M4x4 scale; M4x4 scale;
const u32& getId() const { return id; } inline const u32& getId() const { return id; }
inline const u8& isMother() const { return _isMother; }
M4x4 getModelMatrix() const;
/** Get position from translation matrix */
inline Vec4* getPosition() {
return reinterpret_cast<Vec4*>(&translation.data[3 * 4]);
}
inline void setPosition(const Vec4& v) {
TYRA_ASSERT(v.w == 1.0F, "Vec4 must be homogeneous");
reinterpret_cast<Vec4*>(&translation.data[3 * 4])->set(v);
}
protected: protected:
u8 _isMother;
u32 id; u32 id;
}; };
@@ -15,7 +15,7 @@
namespace Tyra { namespace Tyra {
DynamicMesh::DynamicMesh(const MeshBuilderData& data) { DynamicMesh::DynamicMesh(const MeshBuilderData& data) : Mesh(true) {
framesCount = data.framesCount; framesCount = data.framesCount;
TYRA_ASSERT(framesCount > 0, "Frames count must be greater than 0"); TYRA_ASSERT(framesCount > 0, "Frames count must be greater than 0");
@@ -32,14 +32,10 @@ DynamicMesh::DynamicMesh(const MeshBuilderData& data) {
materials[i] = new DynamicMeshMaterial(data, i); materials[i] = new DynamicMeshMaterial(data, i);
} }
translation.translate(Vec4(0.0F, 0.0F, 0.0F, 1.0F));
initMesh(); initMesh();
_isMother = true;
} }
DynamicMesh::DynamicMesh(const DynamicMesh& mesh) { DynamicMesh::DynamicMesh(const DynamicMesh& mesh) : Mesh(false) {
framesCount = mesh.framesCount; framesCount = mesh.framesCount;
materialsCount = mesh.materialsCount; materialsCount = mesh.materialsCount;
@@ -53,11 +49,7 @@ DynamicMesh::DynamicMesh(const DynamicMesh& mesh) {
materials[i] = new DynamicMeshMaterial(*mesh.materials[i]); materials[i] = new DynamicMeshMaterial(*mesh.materials[i]);
} }
translation.translate(Vec4(0.0F, 0.0F, 0.0F, 1.0F));
initMesh(); initMesh();
_isMother = false;
} }
DynamicMesh::~DynamicMesh() { DynamicMesh::~DynamicMesh() {
@@ -73,10 +65,6 @@ DynamicMesh::~DynamicMesh() {
} }
} }
M4x4 DynamicMesh::getModelMatrix() const {
return translation * rotation * scale;
}
void DynamicMesh::initMesh() { void DynamicMesh::initMesh() {
animState.startFrame = 0; animState.startFrame = 0;
animState.endFrame = 0; animState.endFrame = 0;
+7 -1
View File
@@ -13,7 +13,13 @@
namespace Tyra { namespace Tyra {
Mesh::Mesh() { id = rand() % 1000000; } Mesh::Mesh(const u8& isMother) {
id = rand() % 1000000;
_isMother = isMother;
translation.translate(Vec4(0.0F, 0.0F, 0.0F, 1.0F));
}
M4x4 Mesh::getModelMatrix() const { return translation * rotation * scale; }
Mesh::~Mesh() {} Mesh::~Mesh() {}