物理引擎系统-ode
目录
四、物理引擎系统-ode——removeObjectFromList
五、物理引擎系统-ode——removeJointReferencesFromAttachedBodies
一、物理引擎系统-ode——ifdef
#ifdef _MSC_VER
#pragma warning(disable:4291) // for VC++, no complaints about "no matching operator delete found"
#endif
// this source file is mostly concerned with the data structures, not the
// numerics.
#include "objects.h"
#include <ode/ode.h>
#include "joint.h"
#include <ode/odemath.h>
#include <ode/matrix.h>
#include "step.h"
#include <ode/memory.h>
#include <ode/error.h>
// misc defines
#define ALLOCA dALLOCA16
//****************************************************************************
// utility
二、物理引擎系统-ode——initObject
static inline void initObject (dObject *obj, dxWorld *w)
{
obj->world = w;
obj->next = 0;
obj->tome = 0;
obj->userdata = 0;
obj->tag = 0;
}
// add an object `obj' to the list who's head pointer is pointed to by `first'.
三、物理引擎系统-ode——addObjectToList
static inline void addObjectToList (dObject *obj, dObject **first)
{
obj->next = *first;
obj->tome = first;
if (*first) (*first)->tome = &obj->next;
(*first) = obj;
}
// remove the object from the linked list
四、物理引擎系统-ode——removeObjectFromList
static inline void removeObjectFromList (dObject *obj)
{
if (obj->next) obj->next->tome = obj->tome;
*(obj->tome) = obj->next;
// safeguard
obj->next = 0;
obj->tome = 0;
}
// remove the joint from neighbour lists of all connected bodies
五、物理引擎系统-ode——removeJointReferencesFromAttachedBodies
static void removeJointReferencesFromAttachedBodies (dxJoint *j)
{
for (int i=0; i<2; i++) {
dxBody *body = j->node[i].body;
if (body) {
dxJointNode *n = body->firstjoint;
dxJointNode *last = 0;
while (n) {
if (n->joint == j) {
if (last) last->next = n->next;
else body->firstjoint = n->next;
break;
}
last = n;
n = n->next;
}
}
}
j->node[0].body = 0;
j->node[0].next = 0;
j->node[1].body = 0;
j->node[1].next = 0;
}