13 #include "displayOpenDE.h"
16 #define dsDrawBox dsDrawBoxD
17 #define dsDrawSphere dsDrawSphereD
18 #define dsDrawTriangle dsDrawTriangleD
19 #define dsDrawCylinder dsDrawCylinderD
20 #define dsDrawCapsule dsDrawCapsuleD
21 #define dsDrawLine dsDrawLineD
22 #define dsDrawConvex dsDrawConvexD
26 void DisplayOpenDESpaces::drawGeom(dGeomID g,
const dReal *pos,
const dReal *R,
int show_aabb)
33 if (dGeomIsSpace(g) != 0)
35 displaySpace((dSpaceID)g);
39 int type = dGeomGetClass(g);
40 if (type == dBoxClass)
43 pos = dGeomGetPosition(g);
45 R = dGeomGetRotation(g);
48 dGeomBoxGetLengths(g, sides);
49 dsDrawBox(pos, R, sides);
51 else if (type == dSphereClass)
54 pos = dGeomGetPosition(g);
56 R = dGeomGetRotation(g);
57 dsDrawSphere(pos, R, dGeomSphereGetRadius(g));
59 else if (type == dCapsuleClass)
62 pos = dGeomGetPosition(g);
64 R = dGeomGetRotation(g);
66 dGeomCapsuleGetParams(g, &radius, &length);
67 dsDrawCapsule(pos, R, length, radius);
69 else if (type == dCylinderClass)
72 pos = dGeomGetPosition(g);
74 R = dGeomGetRotation(g);
76 dGeomCylinderGetParams(g, &radius, &length);
77 dsDrawCylinder(pos, R, length, radius);
79 else if (type == dGeomTransformClass)
82 pos = dGeomGetPosition(g);
84 R = dGeomGetRotation(g);
86 dGeomID g2 = dGeomTransformGetGeom(g);
87 const dReal *pos2 = dGeomGetPosition(g2);
88 const dReal *R2 = dGeomGetRotation(g2);
91 dMULTIPLY0_331(actual_pos, R, pos2);
92 actual_pos[0] += pos[0];
93 actual_pos[1] += pos[1];
94 actual_pos[2] += pos[2];
95 dMULTIPLY0_333(actual_R, R, R2);
96 drawGeom(g2, actual_pos, actual_R, 0);
105 dGeomGetAABB(g, aabb);
107 for (i = 0; i < 3; i++)
108 bbpos[i] = 0.5 * (aabb[i * 2] + aabb[i * 2 + 1]);
110 for (i = 0; i < 3; i++)
111 bbsides[i] = aabb[i * 2 + 1] - aabb[i * 2];
114 dsSetColorAlpha(1, 0, 0, 0.5);
115 dsDrawBox(bbpos, RI, bbsides);
119 void DisplayOpenDESpaces::displaySpace(dSpaceID space)
121 int ngeoms = dSpaceGetNumGeoms(space);
122 for (
int i = 0; i < ngeoms; ++i)
124 dGeomID geom = dSpaceGetGeom(space, i);
125 std::map<dGeomID, Color>::const_iterator it = m_gcolors.find(geom);
126 if (it != m_gcolors.end())
127 dsSetColor(it->second.r, it->second.g, it->second.b);
129 dsSetColor(m_activeColor.r, m_activeColor.g, m_activeColor.b);
130 drawGeom(geom,
nullptr,
nullptr, 0);
134 void DisplayOpenDESpaces::displaySpaces()
136 for (
unsigned int i = 0; i < m_spaces.size(); ++i)
138 m_activeColor = m_colors[i];
139 displaySpace(m_spaces[i]);
143 void DisplayOpenDESpaces::addSpace(dSpaceID space,
float r,
float g,
float b)
146 m_colors.push_back(c);
147 m_spaces.push_back(space);
150 void DisplayOpenDESpaces::setGeomColor(dGeomID geom,
float r,
float g,
float b)
156 void DisplayOpenDESpaces::clear()