OpenGothic
Open source reimplementation of Gothic I and II
Loading...
Searching...
No Matches
physicmesh.cpp
Go to the documentation of this file.
1#include "physicmesh.h"
2
7
8PhysicMesh::PhysicMesh(const ProtoMesh& proto, DynamicWorld& owner, bool movable)
9 :ani(&proto) {
10 Tempest::Matrix4x4 pos;
11 pos.identity();
12
13 for(auto& i:proto.attach) {
14 DynamicWorld::Item physic;
15 if(movable)
16 physic = owner.movableObj(i.shape.get(),pos); else
17 physic = owner.staticObj (i.shape.get(),pos);
18 sub.emplace_back(std::move(physic));
19 }
20 }
21
22bool PhysicMesh::isEmpty() const {
23 return sub.empty();
24 }
25
26void PhysicMesh::setObjMatrix(const Tempest::Matrix4x4& obj) {
27 implSetObjMatrix(obj,skeleton==nullptr ? nullptr : skeleton->tr.data());
28 }
29
31 skeleton = sk;
32 if(ani!=nullptr && skeleton!=nullptr)
33 binder=Resources::bindMesh(*ani,*skeleton);
34 }
35
36void PhysicMesh::setPose(const Pose& p) {
37 implSetObjMatrix(Tempest::Matrix4x4::mkIdentity(),p.transform());
38 }
39
40void PhysicMesh::implSetObjMatrix(const Tempest::Matrix4x4 &mt, const Tempest::Matrix4x4* tr) {
41 const size_t binds = (binder==nullptr ? 0 : binder->bind.size());
42 for(size_t i=0; i<binds; ++i) {
43 if(ani->submeshId[i].subId!=0)
44 continue;
45 auto id = binder->bind[i];
46 auto mat = mt;
47 if(id<skeleton->tr.size())
48 mat = tr[id];
49 sub[ani->submeshId[i].id].setObjMatrix(mat);
50 }
51 for(size_t i=binds; i<sub.size(); ++i)
52 sub[i].setObjMatrix(mt);
53 }
54
56 for(auto& i:sub)
57 i.setInteractive(it);
58 }
std::vector< size_t > bind
Item movableObj(const PhysicMeshShape *src, const Tempest::Matrix4x4 &m)
Item staticObj(const PhysicMeshShape *src, const Tempest::Matrix4x4 &m)
void setInteractive(Interactive *it)
PhysicMesh()=default
void setPose(const Pose &p)
void setObjMatrix(const Tempest::Matrix4x4 &m)
void setSkeleton(const Skeleton *sk)
bool isEmpty() const
Definition pose.h:16
const Tempest::Matrix4x4 * transform() const
Definition pose.cpp:889
std::vector< Attach > attach
Definition protomesh.h:82
std::vector< SubMeshId > submeshId
Definition protomesh.h:84
static const AttachBinder * bindMesh(const ProtoMesh &anim, const Skeleton &s)
std::vector< Tempest::Matrix4x4 > tr
Definition skeleton.h:24