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
|
#ifndef WORLDOBJECT_H
#define WORLDOBJECT_H
#include <string>
#include <plib/ssg.h>
#ifndef dVALIDMAT3
#define dVALIDMAT3 dVALIDMAT
#endif
inline void MakeDisplayLists(ssgEntity *e)
{
static bool disabled = getenv("PLODE_NO_DISPLAY_LISTS");
if (!e || disabled) return;
if (e->isAKindOf(ssgTypeBranch()))
{
ssgBranch *branch = (ssgBranch*) e ;
for (int i=0; i<branch->getNumKids(); i++)
{
ssgEntity *kid = branch->getKid(i);
assert(kid) ;
MakeDisplayLists(kid);
}
}
if (e->isAKindOf (ssgTypeLeaf()))
{
ssgLeaf *leaf = (ssgLeaf*) e;
leaf->makeDList();
}
}
class WorldObject
{
public:
WorldObject(ssgEntity *model) :
name("unnamed worldobject"),
entity(0)
{
}
virtual ~WorldObject()
{
}
virtual void Collide(WorldObject *other) {}
ssgEntity *GetEntity(void)
{
return entity;
}
std::string name;
protected:
// Interfaces between ODE API and PLIB API by converting transformations.
void SetTransformFromBody(ssgTransform *trf, dBodyID body)
{
const dReal *p=dBodyGetPosition(body);
assert(p);
if (!dVALIDVEC3(p)) fprintf(stderr,"Position of %s body is invalid!\n", name.c_str());
sgVec3 pos;
sgSetVec3(pos,p[0],p[1],p[2]);
const dReal *m=dBodyGetRotation(body);
assert(m);
if (!dVALIDMAT3(p)) fprintf(stderr,"Orientation of %s body is invalid!\n", name.c_str());
sgMat4 mat;
sgMakeIdentMat4(mat);
mat[0][0]=m[0];
mat[0][1]=m[4];
mat[0][2]=m[8];
mat[1][0]=m[1];
mat[1][1]=m[5];
mat[1][2]=m[9];
mat[2][0]=m[2];
mat[2][1]=m[6];
mat[2][2]=m[10];
sgCopyVec3(mat[3],pos);
trf->setTransform(mat);
}
ssgEntity *entity;
};
#endif
|