7#include <CustomJoint.h>
11#include <OgreSceneNode.h>
12#include <OgreSceneManager.h>
13#include <OgreManualObject.h>
45 m_debugnode = smgr->getRootSceneNode()->createChildSceneNode(
"__OgreNewt__Debugger__Node__");
51 m_raycastsnode = smgr->getRootSceneNode()->createChildSceneNode(
"__OgreNewt__Raycasts_Debugger__Node__");
100 Ogre::ManualObject* mo = it->second.m_lines;
132 if (it->second.m_updated)
133 newbodymap.insert(*it);
136 Ogre::ManualObject* mo = it->second.m_lines;
165 void _CDECL Debugger::newtonprocessJoints(
const NewtonJoint* newtonJoint,
void* userData)
168 CustomJoint* customJoint = (CustomJoint*)NewtonJointGetUserData(newtonJoint);
169 if (customJoint->GetUserData())
183 object->begin(
"BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST);
191 object->colour(colour);
196 NewtonCollisionForEachPolygonDo(shape, &matrix[0], newtonPerPoly,
object);
197 object->setCastShadows(
false);
205 MaterialIdColorMap::iterator it =
m_materialcolors.find(NewtonBodyGetMaterialGroupID(newtonBody));
207 Ogre::Vector3 pos, vel, omega;
208 Ogre::Quaternion ori;
215 std::ostringstream oss_name;
216 oss_name <<
"__OgreNewt__Debugger__Body__" << bod <<
"__";
217 std::ostringstream oss_info;
218 oss_info.precision(2);
219 oss_info.setf(std::ios::fixed, std::ios::floatfield);
220 Ogre::Vector3 inertia;
224 oss_info <<
"[" << bod->
getOgreNode()->getName() <<
"]" << std::endl;
225 oss_info <<
"Mass: " << mass << std::endl;
226 oss_info <<
"Position: " << pos[0] <<
" x " << pos[1] <<
" x " << pos[2] << std::endl;
227 oss_info <<
"Velocity: " << vel[0] <<
" x " << vel[1] <<
" x " << vel[2] << std::endl;
228 oss_info <<
"Omega: " << omega[0] <<
" x " << omega[1] <<
" x " << omega[2] << std::endl;
229 oss_info <<
"Inertia: " << inertia[0] <<
" x " << inertia[1] <<
" x " << inertia[2] << std::endl;
239 data->
m_node->setPosition(pos);
240 data->
m_node->setOrientation(ori);
253 data->
m_node->detachAllObjects();
254 data->
m_node->setPosition(pos);
255 data->
m_node->setOrientation(ori);
266 std::ostringstream oss;
267 oss <<
"__OgreNewt__Debugger__Lines__" << bod <<
"__";
268 data->
m_lines =
new Ogre::ManualObject(oss.str());
286 data->
m_lines->setCastShadows(
false);
287 data->
m_text->setCastShadows(
false);
294 void _CDECL Debugger::newtonPerPoly(
void* userData,
int vertexCount,
const dFloat* faceVertec,
int id)
296 Ogre::ManualObject* lines = (Ogre::ManualObject*)userData;
297 Ogre::Vector3 p0, p1;
302 int i = vertexCount - 1;
303 p0 = Ogre::Vector3(faceVertec[(i * 3) + 0], faceVertec[(i * 3) + 1], faceVertec[(i * 3) + 2]);
306 for (i = 0; i < vertexCount; i++)
308 p1 = Ogre::Vector3(faceVertec[(i * 3) + 0], faceVertec[(i * 3) + 1], faceVertec[(i * 3) + 2]);
373 std::ostringstream oss;
374 oss <<
"__OgreNewt__Raycast_Debugger__Lines__Raycastline__" << i++ <<
"__";
375 Ogre::ManualObject *line =
new Ogre::ManualObject(oss.str());
377 line->begin(
"BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST);
379 line->position(startpt);
380 line->position(endpt);
381 line->setCastShadows(
false);
395 std::ostringstream oss;
396 oss <<
"__OgreNewt__Raycast_Debugger__Lines__Convexcastlines__" << i++ <<
"__";
397 Ogre::ManualObject *line =
new Ogre::ManualObject(oss.str());
399 line->begin(
"BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST);
431 NewtonCollisionForEachPolygonDo(col->
getNewtonCollision(), &matrix[0], newtonPerPoly, line);
433 if (endpt != startpt)
436 NewtonCollisionForEachPolygonDo(col->
getNewtonCollision(), &matrix[0], newtonPerPoly, line);
438 line->setCastShadows(
false);
454 Ogre::Quaternion ori;
456 std::ostringstream oss;
457 oss <<
"__OgreNewt__Raycast_Debugger__Lines__DiscardedBody__" << i++ <<
"__";
458 Ogre::ManualObject *line =
new Ogre::ManualObject(oss.str());
460 line->begin(
"BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST);
467 line->setCastShadows(
false);
482 Ogre::Quaternion ori;
484 std::ostringstream oss;
485 oss <<
"__OgreNewt__Raycast_Debugger__Lines__HitBody__" << i++ <<
"__";
486 Ogre::ManualObject *line =
new Ogre::ManualObject(oss.str());
488 line->begin(
"BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_LIST);
495 line->setCastShadows(
false);
main class for all Rigid Bodies in the system.
void getMassMatrix(Ogre::Real &mass, Ogre::Vector3 &inertia) const
get Ogre::Real(mass) and Ogre::Vector3(inertia) of the body.
const OgreNewt::CollisionPtr & getCollision() const
set the factors that cause a body to "freeze" when equilibrium reached.
Ogre::Vector3 getVelocity() const
get velocity of the body. in global coordinates.
Ogre::Vector3 getOmega() const
get omega of the body. in global space.
NewtonBody * getNewtonBody() const
get a pointer to the NewtonBody object
Ogre::AxisAlignedBox getAABB() const
get the axis-aligned bounding box for this body.
Ogre::Node * getOgreNode() const
get a pointer to the attached Node.
void getVisualPositionOrientation(Ogre::Vector3 &pos, Ogre::Quaternion &orient) const
get the node position and orientation in form of an Ogre::Vector(position) and Ogre::Quaternion(orien...
NewtonCollision *const getNewtonCollision() const
retrieve the Newton pointer
represents a collision shape that is explicitly convex.
For viewing the Newton rigid bodies visually.
virtual void nodeDestroyed(const Ogre::Node *)
called when one of the nodes used in this class are destroyed
bool isRaycastRecording()
returns true, if currently recording raycasts
void showDebugInformation()
show the newton world
void setRaycastRecordingColor(Ogre::ColourValue rayCol, Ogre::ColourValue convexCol, Ogre::ColourValue hitBodyCol, Ogre::ColourValue prefilterDiscardedBodyCol)
set the color of the raycast-debug-lines
Ogre::ColourValue m_raycol
MaterialIdColorMap m_materialcolors
void buildDebugObjectFromCollision(Ogre::ManualObject *object, Ogre::ColourValue colour, const NewtonCollision *shape) const
bool isRaycastRecordingHitBodies()
returns true, if hit bodies are currently recording
void setDefaultColor(Ogre::ColourValue col)
set default color
void addHitBody(const OgreNewt::Body *body)
this function is used internally
Ogre::SceneNode * m_debugnode
BodyDebugDataMap m_cachemap
Ogre::ColourValue m_defaultcolor
Ogre::SceneNode * m_raycastsnode
Ogre::ColourValue m_hitbodycol
void clearBodyDebugDataCache()
clear debug data cache for bodies (m_cachemap)
void init(Ogre::SceneManager *smgr)
init the debugger.
void clearRaycastsRecorded()
clears all raycasts, that are currently shown, should probably be done once per frame!
void processJoint(Joint *joint)
call the function to show debug information for this joint
void hideDebugInformation()
remove lines and text drawn
Ogre::ColourValue m_prefilterdiscardedcol
void setMaterialColor(const MaterialID *mat, Ogre::ColourValue col)
set Material color
const OgreNewt::World * m_world
ManualObjectList mRecordedRaycastObjects
std::map< OgreNewt::Body *, BodyDebugData > BodyDebugDataMap
void addDiscardedBody(const OgreNewt::Body *body)
this function is used internally
void deInit()
de-init the debugger (cleantup)
Ogre::ColourValue m_convexcol
void addConvexRay(const OgreNewt::ConvexCollisionPtr &col, const Ogre::Vector3 &startpt, const Ogre::Quaternion &colori, const Ogre::Vector3 &endpt)
this function is used internally
void stopRaycastRecording()
disables raycast-debugging
Ogre::SceneManager * m_sceneManager
void processBody(Body *body)
create debug information for one body
void startRaycastRecording(bool markhitbodies=false)
enable additional raycast-debugging (this also enables displaying of recorded raycasts!...
void addRay(const Ogre::Vector3 &startpt, const Ogre::Vector3 &endpt)
this function is used internally
base class for all joints.
virtual void showDebugData(Ogre::SceneNode *debugRootNode)
show joint visual debugging data
int getID() const
get Newton-assigned material ID.
void setCaption(const Ogre::String &caption)
void setLocalTranslation(Ogre::Vector3 trans)
void setTextAlignment(const HorizontalAlignment &horizontalAlignment, const VerticalAlignment &verticalAlignment)
represents a physics world.
NewtonWorld * getNewtonWorld() const
retrieves a pointer to the NewtonWorld
Body * getFirstBody() const
to iterate through all bodies call this function and then use body->getNext()
_OgreNewtExport void QuatPosToMatrix(const Ogre::Quaternion &quat, const Ogre::Vector3 &pos, dFloat *matrix)
Take a Quaternion and Position Matrix and create a Newton-happy float matrix!
Ogre::ManualObject * m_lines
OgreNewt::OgreAddons::MovableText * m_text