ScummVM API documentation
MeshEntity.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22/*
23 * Copyright (C) 2006-2010 - Frictional Games
24 *
25 * This file is part of HPL1 Engine.
26 */
27
28#ifndef HPL_MESH_ENTITY_H
29#define HPL_MESH_ENTITY_H
30
31#include "hpl1/engine/graphics/GraphicsTypes.h"
32#include "hpl1/engine/graphics/Renderable.h"
33#include "hpl1/engine/math/MathTypes.h"
34#include "hpl1/engine/math/MeshTypes.h"
35#include "hpl1/engine/scene/Entity3D.h"
36#include "hpl1/engine/system/SystemTypes.h"
37
38#include "hpl1/engine/scene/SubMeshEntity.h"
39
40#include "common/array.h"
41#include "hpl1/engine/scene/AnimationState.h"
42#include "common/stablemap.h"
43
44namespace hpl {
45
46class cMaterialManager;
47class cMeshManager;
48class cAnimationManager;
49class cMesh;
50class cSubMesh;
51class cMeshEntity;
52class cAnimation;
53class cAnimationState;
54class cNodeState;
55class cBone;
56class cNode3D;
57class iCollideShape;
58class iPhysicsBody;
59class iPhysicsWorld;
60class cWorld3D;
61
62//-----------------------------------------------------------------------
63
65public:
66 void OnTransformUpdate(iEntity3D *apEntity);
67};
68
69//------------------------------------------
70
72public:
73 virtual ~cMeshEntityCallback() = default;
74 virtual void AfterAnimationUpdate(cMeshEntity *apMeshEntity, float afTimeStep) = 0;
75};
76
77//------------------------------------------
78
79kSaveData_ChildClass(iRenderable, cMeshEntity) {
80 kSaveData_ClassInit(cMeshEntity) public : tString msMeshName;
81
82 bool mbCastShadows;
83
84 int mlBodyId;
85
87
89
90 virtual iSaveObject *CreateSaveObject(cSaveObjectHandler * apSaveObjectHandler, cGame * apGame);
91 virtual int GetSaveCreatePrio();
92};
93
94//------------------------------------------
95
96class cMeshEntity : public iRenderable {
97 typedef iRenderable super;
98 friend class cSubMeshEntity;
99 friend class cMeshEntityRootNodeUpdate;
100 friend class cMesh;
101
102public:
103 cMeshEntity(const tString asName, cMesh *apMesh, cMaterialManager *apMaterialManager,
104 cMeshManager *apMeshManager, cAnimationManager *apAnimationManager);
105 ~cMeshEntity();
106
107 void SetWorld(cWorld3D *apWorld) { mpWorld = apWorld; }
108 cWorld3D *GetWorld() { return mpWorld; }
109
110 void SetCastsShadows(bool abX);
111
112 cNode3D *GetRootNode() { return mpRootNode; }
113
114 void SetCallback(cMeshEntityCallback *apCallback) { mpCallback = apCallback; }
115
116 // Sub mesh entities
117 cSubMeshEntity *GetSubMeshEntity(unsigned int alIdx);
118 cSubMeshEntity *GetSubMeshEntityName(const tString &asName);
119 int GetSubMeshEntityNum();
120
121 // Animation states
122 cAnimationState *AddAnimation(cAnimation *apAnimation, const tString &asName, float afBaseSpeed);
123 void ClearAnimations();
124
125 cAnimationState *GetAnimationState(int alIndex);
126 int GetAnimationStateIndex(const tString &asName);
127 cAnimationState *GetAnimationStateFromName(const tString &asName);
128 int GetAnimationStateNum();
129
130 // Animation controller
131 void Play(int alIndex, bool abLoop, bool bStopPrev);
132 void PlayName(const tString &asName, bool abLoop, bool bStopPrev);
133 void Stop();
134
135 // Bone states
136 cBoneState *GetBoneState(int alIndex);
137 int GetBoneStateIndex(const tString &asName);
138 cBoneState *GetBoneStateFromName(const tString &asName);
139 int GetBoneStateNum();
140
141 void SetSkeletonPhysicsActive(bool abX);
142 bool GetSkeletonPhysicsActive();
143
144 void SetSkeletonPhysicsCanSleep(bool abX) { mbSkeletonPhysicsCanSleep = abX; }
145 bool GetSkeletonPhysicsCanSleep() { return mbSkeletonPhysicsCanSleep; }
146
147 float GetSkeletonPhysicsWeight();
148 void SetSkeletonPhysicsWeight(float afX);
149
150 void FadeSkeletonPhysicsWeight(float afTime);
151
152 void SetSkeletonCollidersActive(bool abX);
153 bool GetSkeletonCollidersActive();
154
155 void AlignBodiesToSkeleton(bool abCalculateSpeed);
156
157 cMesh *GetMesh() { return mpMesh; }
158
166
176 iCollideShape *apShape, const cMatrixf &a_mtxShape,
177 tVector3fList *apPosList, tIntList *apNumList);
178
179 void ResetGraphicsUpdated();
180
181 // Node states
182 cNode3D *GetNodeState(int alIndex);
183 int GetNodeStateIndex(const tString &asName);
184 cNode3D *GetNodeStateFromName(const tString &asName);
185 int GetNodeStateNum();
186 bool HasNodes() { return mbHasNodes; }
187
188 bool AttachEntityToParent(iEntity3D *apEntity, const tString &asParent);
189
190 // Entity implementation
191 tString GetEntityType() { return "Mesh"; }
192 bool IsVisible() { return IsRendered(); }
193 void SetVisible(bool abVisible) { SetRendered(abVisible); }
194
195 void UpdateLogic(float afTimeStep);
196
197 // Renderable implementation.
198 void UpdateGraphics(cCamera3D *apCamera, float afFrameTime, cRenderList *apRenderList);
199 void SetRendered(bool abX);
200 iMaterial *GetMaterial();
201 iVertexBuffer *GetVertexBuffer();
202 bool IsShadowCaster();
203 cBoundingVolume *GetBoundingVolume();
204 cMatrixf *GetModelMatrix(cCamera3D *apCamera);
206 eRenderableType GetRenderType();
207
208 void SetBody(iPhysicsBody *apBody) { mpBody = apBody; }
209 iPhysicsBody *GetBody() { return mpBody; }
210
211 // SaveObject implementation
213 virtual void SaveToSaveData(iSaveData *apSaveData);
214 virtual void LoadFromSaveData(iSaveData *apSaveData);
215 virtual void SaveDataSetup(cSaveObjectHandler *apSaveObjectHandler, cGame *apGame);
216
217private:
218 void UpdateNodeMatrixRec(const cMatrixf &a_mtxParentWorld, cNode3D *apNode);
219
220 void HandleAnimationEvent(cAnimationEvent *apEvent);
221
222 void SetBoneMatrixFromBodyRec(const cMatrixf &a_mtxParentWorld, cBoneState *apBoneState);
223
224 void UpdateBVFromSubs();
225
226 void BuildBoneStatesRec(cBone *apBone, cNode3D *apParent);
227
228 cMaterialManager *mpMaterialManager;
229 cMeshManager *mpMeshManager;
230 cAnimationManager *mpAnimationManager;
231
232 cWorld3D *mpWorld;
233
234 tSubMeshEntityVec mvSubMeshes;
235 tSubMeshEntityMap m_mapSubMeshes;
236
237 tAnimationStateVec mvAnimationStates;
238 tAnimationStateIndexMap m_mapAnimationStateIndices;
239
240 tNodeStateVec mvBoneStates;
241 tNodeStateIndexMap m_mapBoneStateIndices;
242 tNodeStateVec mvTempBoneStates;
243
244 Common::Array<cMatrixf> mvBoneMatrices;
245
246 bool mbSkeletonPhysics;
247 bool mbSkeletonPhysicsFading;
248 float mfSkeletonPhysicsFadeSpeed;
249 float mfSkeletonPhysicsWeight;
250
251 bool mbSkeletonPhysicsSleeping;
252 bool mbSkeletonPhysicsCanSleep;
253
254 bool mbSkeletonColliders;
255
256 bool mbUpdatedBones;
257
258 bool mbHasNodes;
259 tNodeStateVec mvNodeStates;
260 tNodeStateIndexMap m_mapNodeStateIndices;
261
262 int mlStartSleepCount;
263 int mlUpdateCount;
264 float mfTimeStepAccum;
265
266 cMesh *mpMesh;
267
268 cNode3D *mpRootNode;
269 cMeshEntityRootNodeUpdate *mpRootCallback;
270
271 cMeshEntityCallback *mpCallback;
272
273 tEntity3DList mlstAttachedEntities;
274
275 cMatrixf mtxTemp;
276
277 iPhysicsBody *mpBody;
278
279 // Properies:
280 bool mbCastShadows;
281};
282
283//-----------------------------------------------------------------------
284
285} // namespace hpl
286
287#endif // HPL_MESH_ENTITY_H
Definition: str.h:59
Definition: AnimationState.h:71
Definition: Animation.h:44
Definition: AnimationManager.h:39
Definition: AnimationState.h:80
Definition: Bone.h:47
Definition: BoneState.h:37
Definition: Container.h:121
Definition: Game.h:91
Definition: MaterialManager.h:41
Definition: MeshEntity.h:71
Definition: MeshEntity.h:96
virtual void SaveToSaveData(iSaveData *apSaveData)
virtual iSaveData * CreateSaveData()
virtual void LoadFromSaveData(iSaveData *apSaveData)
virtual void SaveDataSetup(cSaveObjectHandler *apSaveObjectHandler, cGame *apGame)
cMatrixf CalculateTransformFromSkeleton(cVector3f *apPostion, cVector3f *apAngles)
bool CheckColliderShapeCollision(iPhysicsWorld *apWorld, iCollideShape *apShape, const cMatrixf &a_mtxShape, tVector3fList *apPosList, tIntList *apNumList)
int GetMatrixUpdateCount()
Definition: MeshEntity.h:64
Definition: Mesh.h:215
Definition: MeshManager.h:39
Definition: Node3D.h:52
Definition: SaveGame.h:183
Definition: SubMeshEntity.h:95
Definition: World3D.h:179
Definition: CollideShape.h:50
Definition: Entity3D.h:81
Definition: Entity3D.h:44
Definition: PhysicsBody.h:117
Definition: PhysicsWorld.h:115
Definition: Renderable.h:70
Definition: SaveGame.h:111
Definition: SaveGame.h:130