-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDynamicObject.h
227 lines (169 loc) · 6.57 KB
/
DynamicObject.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
//-----------------------------------------------------------------------------
// Copyright (c) 2012 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
#ifndef _DynamicObject_H_
#define _DynamicObject_H_
#ifndef _SCENEOBJECT_H_
#include "scene/sceneObject.h"
#endif
#ifndef _CONVEX_H_
#include "collision/convex.h"
#endif
#ifndef __RESOURCE_H__
#include "core/resource.h"
#endif
#ifndef _NETSTRINGTABLE_H_
#include "sim/netStringTable.h"
#endif
#ifndef _TSSHAPE_H_
#include "ts/tsShape.h"
#endif
class TSShapeInstance;
class TSThread;
class DynamicObject;
class PhysicsBody;
struct ObjectRenderInst;
class DynamicObjectPolysoupConvex : public Convex
{
typedef Convex Parent;
friend class TSMesh;
public:
DynamicObjectPolysoupConvex();
~DynamicObjectPolysoupConvex() {};
public:
Box3F box;
Point3F verts[4];
PlaneF normal;
S32 idx;
TSMesh *mesh;
static SceneObject* smCurObject;
public:
// Returns the bounding box in world coordinates
Box3F getBoundingBox() const;
Box3F getBoundingBox(const MatrixF& mat, const Point3F& scale) const;
void getFeatures(const MatrixF& mat,const VectorF& n, ConvexFeature* cf);
// This returns a list of convex faces to collide against
void getPolyList(AbstractPolyList* list);
// This returns the furthest point from the input vector
Point3F support(const VectorF& v) const;
};
/// A simple mesh shape with optional ambient animation.
class DynamicObject : public SceneObject
{
typedef SceneObject Parent;
static U32 smUniqueIdentifier;
enum MaskBits
{
TransformMask = Parent::NextFreeMask << 0,
AdvancedStaticOptionsMask = Parent::NextFreeMask << 1,
UpdateCollisionMask = Parent::NextFreeMask << 2,
SkinMask = Parent::NextFreeFlag << 3,
NextFreeMask = Parent::NextFreeMask << 4
};
public:
/// The different types of mesh data types
enum MeshType
{
None = 0, ///< No mesh
Bounds = 1, ///< Bounding box of the shape
CollisionMesh = 2, ///< Specifically designated collision meshes
VisibleMesh = 3 ///< Rendered mesh polygons
};
protected:
bool onAdd();
void onRemove();
// Collision
void prepCollision();
bool castRay(const Point3F &start, const Point3F &end, RayInfo* info);
bool castRayRendered(const Point3F &start, const Point3F &end, RayInfo* info);
bool buildPolyList(PolyListContext context, AbstractPolyList* polyList, const Box3F &box, const SphereF& sphere);
void buildConvex(const Box3F& box, Convex* convex);
bool _createShape();
void _updatePhysics();
void _renderNormals( ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat );
void _onResourceChanged( const Torque::Path &path );
// ProcessObject
virtual void processTick( const Move *move );
virtual void interpolateTick( F32 delta );
virtual void advanceTime( F32 dt );
/// Start or stop processing ticks depending on our state.
void _updateShouldTick();
protected:
Convex *mConvexList;
StringTableEntry mShapeName;
U32 mShapeHash;
Resource<TSShape> mShape;
Vector<S32> mCollisionDetails;
Vector<S32> mLOSDetails;
TSShapeInstance *mShapeInstance;
NetStringHandle mSkinNameHandle;
String mAppliedSkinName;
bool mPlayAmbient;
TSThread* mAmbientThread;
/// The type of mesh data to return for collision queries.
MeshType mCollisionType;
/// The type of mesh data to return for decal polylist queries.
MeshType mDecalType;
bool mAllowPlayerStep;
/// If true each submesh within the TSShape is culled
/// against the object space frustum.
bool mMeshCulling;
/// If true the shape is sorted by the origin of the
/// model instead of the nearest point of the bounds.
bool mUseOriginSort;
PhysicsBody *mPhysicsRep;
// Debug stuff
F32 mRenderNormalScalar;
S32 mForceDetail;
public:
DynamicObject();
~DynamicObject();
DECLARE_CONOBJECT(DynamicObject);
static void initPersistFields();
static bool _setFieldSkin( void *object, const char* index, const char* data );
static const char *_getFieldSkin( void *object, const char *data );
// Skinning
void setSkinName( const char *name );
void reSkin();
// NetObject
U32 packUpdate( NetConnection *conn, U32 mask, BitStream *stream );
void unpackUpdate( NetConnection *conn, BitStream *stream );
// SceneObject
void setTransform( const MatrixF &mat );
void onScaleChanged();
void prepRenderImage( SceneRenderState *state );
void inspectPostApply();
/// The type of mesh data use for collision queries.
MeshType getCollisionType() const { return mCollisionType; }
bool allowPlayerStep() const { return mAllowPlayerStep; }
Resource<TSShape> getShape() const { return mShape; }
StringTableEntry getShapeFileName() { return mShapeName; }
TSShapeInstance* getShapeInstance() const { return mShapeInstance; }
const Vector<S32>& getCollisionDetails() const { return mCollisionDetails; }
const Vector<S32>& getLOSDetails() const { return mLOSDetails; }
void getNodeTransform(const char* nodeName, MatrixF* mat);
Vector<String> getNodeTransforms();
};
//typedef DynamicObject::MeshType DOMeshType;
//DefineEnumType( DOMeshType );
typedef DynamicObject::MeshType DOMeshType;
DefineEnumType( DOMeshType );
#endif // _H_DynamicObject