mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
Asserts, and reformat code
This commit is contained in:
parent
6bd15649f9
commit
a5d774a1c3
@ -37,6 +37,7 @@ OdeJoint::
|
|||||||
|
|
||||||
void OdeJoint::
|
void OdeJoint::
|
||||||
destroy() {
|
destroy() {
|
||||||
|
nassertv(_id);
|
||||||
dJointDestroy(_id);
|
dJointDestroy(_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,6 +51,7 @@ destroy() {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void OdeJoint::
|
void OdeJoint::
|
||||||
attach_bodies(const OdeBody &body1, const OdeBody &body2) {
|
attach_bodies(const OdeBody &body1, const OdeBody &body2) {
|
||||||
|
nassertv(_id);
|
||||||
nassertv(body1.get_id() != 0 && body2.get_id() != 0);
|
nassertv(body1.get_id() != 0 && body2.get_id() != 0);
|
||||||
dJointAttach(_id, body1.get_id(), body2.get_id());
|
dJointAttach(_id, body1.get_id(), body2.get_id());
|
||||||
}
|
}
|
||||||
@ -65,6 +67,7 @@ attach_bodies(const OdeBody &body1, const OdeBody &body2) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void OdeJoint::
|
void OdeJoint::
|
||||||
attach_body(const OdeBody &body, int index) {
|
attach_body(const OdeBody &body, int index) {
|
||||||
|
nassertv(_id);
|
||||||
nassertv(body.get_id() != 0);
|
nassertv(body.get_id() != 0);
|
||||||
nassertv(index == 0 || index == 1);
|
nassertv(index == 0 || index == 1);
|
||||||
if (index == 0) {
|
if (index == 0) {
|
||||||
@ -76,6 +79,7 @@ attach_body(const OdeBody &body, int index) {
|
|||||||
|
|
||||||
void OdeJoint::
|
void OdeJoint::
|
||||||
detach() {
|
detach() {
|
||||||
|
nassertv(_id);
|
||||||
dJointAttach(_id, 0, 0);
|
dJointAttach(_id, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,46 +50,55 @@ OdeSpace::
|
|||||||
|
|
||||||
void OdeSpace::
|
void OdeSpace::
|
||||||
destroy() {
|
destroy() {
|
||||||
|
nassertv(_id);
|
||||||
dSpaceDestroy(_id);
|
dSpaceDestroy(_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
int OdeSpace::
|
int OdeSpace::
|
||||||
query(const OdeGeom& geom) const {
|
query(const OdeGeom& geom) const {
|
||||||
|
nassertr(_id, 0);
|
||||||
return dSpaceQuery(_id, geom.get_id());
|
return dSpaceQuery(_id, geom.get_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
int OdeSpace::
|
int OdeSpace::
|
||||||
query(const OdeSpace& space) const {
|
query(const OdeSpace& space) const {
|
||||||
|
nassertr(_id, 0);
|
||||||
return dSpaceQuery(_id, (dGeomID)space.get_id());
|
return dSpaceQuery(_id, (dGeomID)space.get_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
void OdeSpace::
|
void OdeSpace::
|
||||||
add(OdeSpace& space) {
|
add(OdeSpace& space) {
|
||||||
|
nassertv(_id);
|
||||||
dSpaceAdd(_id, (dGeomID)space.get_id());
|
dSpaceAdd(_id, (dGeomID)space.get_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
void OdeSpace::
|
void OdeSpace::
|
||||||
remove(OdeSpace& space) {
|
remove(OdeSpace& space) {
|
||||||
|
nassertv(_id);
|
||||||
dSpaceRemove(_id, (dGeomID)space.get_id());
|
dSpaceRemove(_id, (dGeomID)space.get_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
void OdeSpace::
|
void OdeSpace::
|
||||||
add(OdeGeom& geom) {
|
add(OdeGeom& geom) {
|
||||||
|
nassertv(_id);
|
||||||
dSpaceAdd(_id, geom.get_id());
|
dSpaceAdd(_id, geom.get_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
void OdeSpace::
|
void OdeSpace::
|
||||||
remove(OdeGeom& geom) {
|
remove(OdeGeom& geom) {
|
||||||
|
nassertv(_id);
|
||||||
dSpaceRemove(_id, geom.get_id());
|
dSpaceRemove(_id, geom.get_id());
|
||||||
}
|
}
|
||||||
|
|
||||||
void OdeSpace::
|
void OdeSpace::
|
||||||
clean() {
|
clean() {
|
||||||
|
nassertv(_id);
|
||||||
dSpaceClean(_id);
|
dSpaceClean(_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
OdeGeom OdeSpace::
|
OdeGeom OdeSpace::
|
||||||
get_geom(int i) {
|
get_geom(int i) {
|
||||||
|
nassertr(_id, OdeGeom(0));
|
||||||
return OdeGeom(dSpaceGetGeom(_id, i));
|
return OdeGeom(dSpaceGetGeom(_id, i));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,170 +116,160 @@ operator bool () const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OdeSpace::
|
void OdeSpace::
|
||||||
set_auto_collide_world(OdeWorld &world)
|
set_auto_collide_world(OdeWorld &world) {
|
||||||
{
|
my_world = &world;
|
||||||
my_world = &world;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OdeSpace::
|
void OdeSpace::
|
||||||
set_auto_collide_joint_group(OdeJointGroup &joint_group)
|
set_auto_collide_joint_group(OdeJointGroup &joint_group) {
|
||||||
{
|
_collide_joint_group = joint_group.get_id();
|
||||||
_collide_joint_group = joint_group.get_id();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int OdeSpace::
|
int OdeSpace::
|
||||||
auto_collide()
|
auto_collide() {
|
||||||
{
|
if (my_world == NULL) {
|
||||||
if (my_world == NULL) {
|
odespace_cat.error() << "No collide world has been set!\n";
|
||||||
odespace_cat.error() << "No collide world has been set!\n";
|
return 0;
|
||||||
return 0;
|
} else {
|
||||||
} else {
|
nassertr(_id, 0);
|
||||||
OdeSpace::contactCount = 0;
|
OdeSpace::contactCount = 0;
|
||||||
_collide_space = this;
|
_collide_space = this;
|
||||||
_collide_world = my_world;
|
_collide_world = my_world;
|
||||||
dSpaceCollide(_id, this, &auto_callback);
|
dSpaceCollide(_id, this, &auto_callback);
|
||||||
return OdeSpace::contactCount;
|
return OdeSpace::contactCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
double OdeSpace::
|
double OdeSpace::
|
||||||
get_contact_data(int data_index)
|
get_contact_data(int data_index) {
|
||||||
// get the contact data it looks like so [x1,y1,z1,x2,y2,z2... x64,y64,z64]
|
// get the contact data it looks like so [x1,y1,z1,x2,y2,z2... x64,y64,z64]
|
||||||
// use the return in from autoCollide to determine how much of the data is
|
// use the return in from autoCollide to determine how much of the data is
|
||||||
// valid. The data would be more straight forward but the callbacks have to be
|
// valid. The data would be more straight forward but the callbacks have to be
|
||||||
// static.
|
// static.
|
||||||
{
|
return OdeSpace::contact_data[data_index];
|
||||||
return OdeSpace::contact_data[data_index];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int OdeSpace::
|
int OdeSpace::
|
||||||
get_contact_id(int data_index, int first)
|
get_contact_id(int data_index, int first) {
|
||||||
// get the contact data it looks like so [x1,y1,z1,x2,y2,z2... x64,y64,z64]
|
// get the contact data it looks like so [x1,y1,z1,x2,y2,z2... x64,y64,z64]
|
||||||
// use the return in from autoCollide to determine how much of the data is
|
// use the return in from autoCollide to determine how much of the data is
|
||||||
// valid. The data would be more straight forward but the callbacks have to be
|
// valid. The data would be more straight forward but the callbacks have to be
|
||||||
// static.
|
// static.
|
||||||
{
|
if (first == 0) {
|
||||||
if (first == 0)
|
return OdeSpace::contact_ids[(data_index * 2) + 0];
|
||||||
{
|
} else {
|
||||||
return OdeSpace::contact_ids[(data_index * 2) + 0];
|
return OdeSpace::contact_ids[(data_index * 2) + 1];
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return OdeSpace::contact_ids[(data_index * 2) + 1];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OdeSpace::
|
void OdeSpace::
|
||||||
auto_callback(void *data, dGeomID o1, dGeomID o2)
|
auto_callback(void *data, dGeomID o1, dGeomID o2) {
|
||||||
// uses data stored on the world to resolve collisions so you don't have to use near_callbacks in python
|
// uses data stored on the world to resolve collisions so you don't have to use near_callbacks in python
|
||||||
{
|
int i;
|
||||||
int i;
|
static int autoCallbackCounter = 0;
|
||||||
static int autoCallbackCounter = 0;
|
dBodyID b1 = dGeomGetBody(o1);
|
||||||
dBodyID b1 = dGeomGetBody(o1);
|
dBodyID b2 = dGeomGetBody(o2);
|
||||||
dBodyID b2 = dGeomGetBody(o2);
|
|
||||||
|
|
||||||
dContact contact[OdeSpace::MAX_CONTACTS];
|
dContact contact[OdeSpace::MAX_CONTACTS];
|
||||||
|
|
||||||
int surface1 = _collide_space->get_surface_type(o1);
|
int surface1 = _collide_space->get_surface_type(o1);
|
||||||
int surface2 = _collide_space->get_surface_type(o2);
|
int surface2 = _collide_space->get_surface_type(o2);
|
||||||
|
|
||||||
nassertv(_collide_world != NULL);
|
nassertv(_collide_world != NULL);
|
||||||
sSurfaceParams collide_params;
|
sSurfaceParams collide_params;
|
||||||
collide_params = _collide_world->get_surface(surface1, surface2);
|
collide_params = _collide_world->get_surface(surface1, surface2);
|
||||||
|
|
||||||
for (i=0; i < OdeSpace::MAX_CONTACTS; i++)
|
for (i=0; i < OdeSpace::MAX_CONTACTS; i++) {
|
||||||
{
|
contact[i].surface.mode = collide_params.colparams.mode;
|
||||||
contact[i].surface.mode = collide_params.colparams.mode;
|
contact[i].surface.mu = collide_params.colparams.mu;
|
||||||
contact[i].surface.mu = collide_params.colparams.mu;
|
contact[i].surface.mu2 = collide_params.colparams.mu2;
|
||||||
contact[i].surface.mu2 = collide_params.colparams.mu2;
|
contact[i].surface.bounce = collide_params.colparams.bounce;
|
||||||
contact[i].surface.bounce = collide_params.colparams.bounce;
|
contact[i].surface.bounce_vel = collide_params.colparams.bounce_vel;
|
||||||
contact[i].surface.bounce_vel = collide_params.colparams.bounce_vel;
|
contact[i].surface.soft_cfm = collide_params.colparams.soft_cfm;
|
||||||
contact[i].surface.soft_cfm = collide_params.colparams.soft_cfm;
|
}
|
||||||
|
|
||||||
|
static int numc = 0;
|
||||||
|
numc = dCollide(o1, o2, OdeSpace::MAX_CONTACTS, &contact[0].geom, sizeof(dContact));
|
||||||
|
|
||||||
|
if (numc) {
|
||||||
|
if (odespace_cat.is_debug() && (autoCallbackCounter%30 == 0)) {
|
||||||
|
odespace_cat.debug() << autoCallbackCounter <<" collision between geoms " << o1 << " and " << o2 << "\n";
|
||||||
|
odespace_cat.debug() << "collision between body " << b1 << " and " << b2 << "\n";
|
||||||
|
odespace_cat.debug() << "surface1= "<< surface1 << " surface2=" << surface2 << "\n";
|
||||||
|
}
|
||||||
|
autoCallbackCounter += 1;
|
||||||
|
|
||||||
|
PT(OdeCollisionEntry) entry;
|
||||||
|
if (!_collide_space->_collision_event.empty()) {
|
||||||
|
entry = new OdeCollisionEntry;
|
||||||
|
entry->_geom1 = o1;
|
||||||
|
entry->_geom2 = o2;
|
||||||
|
entry->_body1 = b1;
|
||||||
|
entry->_body2 = b2;
|
||||||
|
entry->_num_points = numc;
|
||||||
|
entry->_points = new LPoint3f[numc];
|
||||||
}
|
}
|
||||||
|
|
||||||
static int numc = 0;
|
for(i=0; i < numc; i++) {
|
||||||
numc = dCollide(o1, o2, OdeSpace::MAX_CONTACTS, &contact[0].geom, sizeof(dContact));
|
dJointID c = dJointCreateContact(_collide_world->get_id(), _collide_joint_group, contact + i);
|
||||||
|
if ((_collide_space->get_collide_id(o1) >= 0) && (_collide_space->get_collide_id(o2) >= 0)) {
|
||||||
if (numc)
|
dJointAttach(c, b1, b2);
|
||||||
{
|
}
|
||||||
if (odespace_cat.is_debug() && (autoCallbackCounter%30 == 0)) {
|
if (!_collide_space->_collision_event.empty()) {
|
||||||
odespace_cat.debug() << autoCallbackCounter <<" collision between geoms " << o1 << " and " << o2 << "\n";
|
entry->_points[i][0] = contact[i].geom.pos[0];
|
||||||
odespace_cat.debug() << "collision between body " << b1 << " and " << b2 << "\n";
|
entry->_points[i][1] = contact[i].geom.pos[1];
|
||||||
odespace_cat.debug() << "surface1= "<< surface1 << " surface2=" << surface2 << "\n";
|
entry->_points[i][2] = contact[i].geom.pos[2];
|
||||||
}
|
}
|
||||||
autoCallbackCounter += 1;
|
// this creates contact position data for python. It is useful for debugging only 64 points are stored
|
||||||
|
if(contactCount < 64) {
|
||||||
PT(OdeCollisionEntry) entry;
|
OdeSpace::contact_data[0 + (OdeSpace::contactCount * 3)] = contact[i].geom.pos[0];
|
||||||
if (!_collide_space->_collision_event.empty()) {
|
OdeSpace::contact_data[1 + (OdeSpace::contactCount * 3)] = contact[i].geom.pos[1];
|
||||||
entry = new OdeCollisionEntry;
|
OdeSpace::contact_data[2 + (OdeSpace::contactCount * 3)] = contact[i].geom.pos[2];
|
||||||
entry->_geom1 = o1;
|
OdeSpace::contact_ids[0 + (OdeSpace::contactCount * 2)] = _collide_space->get_collide_id(o1);
|
||||||
entry->_geom2 = o2;
|
OdeSpace::contact_ids[1 + (OdeSpace::contactCount * 2)] = _collide_space->get_collide_id(o2);
|
||||||
entry->_body1 = b1;
|
OdeSpace::contactCount += 1;
|
||||||
entry->_body2 = b2;
|
}
|
||||||
entry->_num_points = numc;
|
|
||||||
entry->_points = new LPoint3f[numc];
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i=0; i < numc; i++)
|
|
||||||
{
|
|
||||||
dJointID c = dJointCreateContact(_collide_world->get_id(), _collide_joint_group, contact + i);
|
|
||||||
if ((_collide_space->get_collide_id(o1) >= 0) && (_collide_space->get_collide_id(o2) >= 0))
|
|
||||||
{
|
|
||||||
dJointAttach(c, b1, b2);
|
|
||||||
}
|
|
||||||
if (!_collide_space->_collision_event.empty()) {
|
|
||||||
entry->_points[i][0] = contact[i].geom.pos[0];
|
|
||||||
entry->_points[i][1] = contact[i].geom.pos[1];
|
|
||||||
entry->_points[i][2] = contact[i].geom.pos[2];
|
|
||||||
}
|
|
||||||
// this creates contact position data for python. It is useful for debugging only 64 points are stored
|
|
||||||
if(contactCount < 64)
|
|
||||||
{
|
|
||||||
OdeSpace::contact_data[0 + (OdeSpace::contactCount * 3)] = contact[i].geom.pos[0];
|
|
||||||
OdeSpace::contact_data[1 + (OdeSpace::contactCount * 3)] = contact[i].geom.pos[1];
|
|
||||||
OdeSpace::contact_data[2 + (OdeSpace::contactCount * 3)] = contact[i].geom.pos[2];
|
|
||||||
OdeSpace::contact_ids[0 + (OdeSpace::contactCount * 2)] = _collide_space->get_collide_id(o1);
|
|
||||||
OdeSpace::contact_ids[1 + (OdeSpace::contactCount * 2)] = _collide_space->get_collide_id(o2);
|
|
||||||
OdeSpace::contactCount += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_collide_world->set_dampen_on_bodies(b1, b2, collide_params.dampen);
|
|
||||||
|
|
||||||
if (!_collide_space->_collision_event.empty()) {
|
|
||||||
throw_event(_collide_space->_collision_event, EventParameter(entry));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
_collide_world->set_dampen_on_bodies(b1, b2, collide_params.dampen);
|
||||||
|
|
||||||
|
if (!_collide_space->_collision_event.empty()) {
|
||||||
|
throw_event(_collide_space->_collision_event, EventParameter(entry));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_PYTHON
|
#ifdef HAVE_PYTHON
|
||||||
int OdeSpace::
|
int OdeSpace::
|
||||||
collide(PyObject* arg, PyObject* callback) {
|
collide(PyObject* arg, PyObject* callback) {
|
||||||
nassertr(callback != NULL, -1);
|
nassertr(callback != NULL, -1);
|
||||||
if (!PyCallable_Check(callback)) {
|
if (!PyCallable_Check(callback)) {
|
||||||
PyErr_Format(PyExc_TypeError, "'%s' object is not callable", callback->ob_type->tp_name);
|
PyErr_Format(PyExc_TypeError, "'%s' object is not callable", callback->ob_type->tp_name);
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else if (_id == NULL) {
|
||||||
OdeSpace::_python_callback = (PyObject*) callback;
|
// Well, while we're in the mood of python exceptions, let's make this one too.
|
||||||
Py_XINCREF(OdeSpace::_python_callback);
|
PyErr_Format(PyExc_TypeError, "OdeSpace is not valid!");
|
||||||
dSpaceCollide(_id, (void*) arg, &near_callback);
|
return -1;
|
||||||
Py_XDECREF(OdeSpace::_python_callback);
|
} else {
|
||||||
return 0;
|
OdeSpace::_python_callback = (PyObject*) callback;
|
||||||
}
|
Py_XINCREF(OdeSpace::_python_callback);
|
||||||
|
dSpaceCollide(_id, (void*) arg, &near_callback);
|
||||||
|
Py_XDECREF(OdeSpace::_python_callback);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OdeSpace::
|
void OdeSpace::
|
||||||
near_callback(void *data, dGeomID o1, dGeomID o2) {
|
near_callback(void *data, dGeomID o1, dGeomID o2) {
|
||||||
odespace_cat.spam() << "near_callback called, data: " << data << ", dGeomID1: " << o1 << ", dGeomID2: " << o2 << "\n";
|
odespace_cat.spam() << "near_callback called, data: " << data << ", dGeomID1: " << o1 << ", dGeomID2: " << o2 << "\n";
|
||||||
OdeGeom g1 (o1);
|
OdeGeom g1 (o1);
|
||||||
OdeGeom g2 (o2);
|
OdeGeom g2 (o2);
|
||||||
PyObject* p1 = DTool_CreatePyInstanceTyped(&g1, Dtool_OdeGeom, true, false, g1.get_type_index());
|
PyObject* p1 = DTool_CreatePyInstanceTyped(&g1, Dtool_OdeGeom, true, false, g1.get_type_index());
|
||||||
PyObject* p2 = DTool_CreatePyInstanceTyped(&g2, Dtool_OdeGeom, true, false, g2.get_type_index());
|
PyObject* p2 = DTool_CreatePyInstanceTyped(&g2, Dtool_OdeGeom, true, false, g2.get_type_index());
|
||||||
PyObject* result = PyEval_CallFunction(_python_callback, "OOO", (PyObject*) data, p1, p2);
|
PyObject* result = PyEval_CallFunction(_python_callback, "OOO", (PyObject*) data, p1, p2);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
odespace_cat.error() << "An error occurred while calling python function!\n";
|
odespace_cat.error() << "An error occurred while calling python function!\n";
|
||||||
PyErr_Print();
|
PyErr_Print();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -308,8 +307,7 @@ set_surface_type(OdeGeom& geom, int surfaceType){
|
|||||||
}
|
}
|
||||||
|
|
||||||
int OdeSpace::
|
int OdeSpace::
|
||||||
get_surface_type(dGeomID id)
|
get_surface_type(dGeomID id) {
|
||||||
{
|
|
||||||
GeomSurfaceMap::iterator iter = _geom_surface_map.find(id);
|
GeomSurfaceMap::iterator iter = _geom_surface_map.find(id);
|
||||||
if (iter != _geom_surface_map.end()) {
|
if (iter != _geom_surface_map.end()) {
|
||||||
// odespace_cat.debug() << "get_default_surface_type the geomId =" << id <<" surfaceType=" << iter->second << "\n";
|
// odespace_cat.debug() << "get_default_surface_type the geomId =" << id <<" surfaceType=" << iter->second << "\n";
|
||||||
@ -320,14 +318,14 @@ get_surface_type(dGeomID id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int OdeSpace::
|
int OdeSpace::
|
||||||
get_surface_type(OdeGeom& geom){
|
get_surface_type(OdeGeom& geom) {
|
||||||
dGeomID id = geom.get_id();
|
dGeomID id = geom.get_id();
|
||||||
return get_surface_type(id);
|
return get_surface_type(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int OdeSpace::
|
int OdeSpace::
|
||||||
set_collide_id( int collide_id, dGeomID id){
|
set_collide_id( int collide_id, dGeomID id) {
|
||||||
_geom_collide_id_map[id]= collide_id;
|
_geom_collide_id_map[id]= collide_id;
|
||||||
|
|
||||||
//odespace_cat.debug() << "set_collide_id " << id << " " << _geom_collide_id_map[id] <<"\n";
|
//odespace_cat.debug() << "set_collide_id " << id << " " << _geom_collide_id_map[id] <<"\n";
|
||||||
@ -345,24 +343,20 @@ set_collide_id( int collide_id, dGeomID id){
|
|||||||
}
|
}
|
||||||
|
|
||||||
int OdeSpace::
|
int OdeSpace::
|
||||||
set_collide_id( OdeGeom& geom, int collide_id)
|
set_collide_id( OdeGeom& geom, int collide_id) {
|
||||||
{
|
dGeomID id = geom.get_id();
|
||||||
dGeomID id = geom.get_id();
|
return set_collide_id(collide_id, id);
|
||||||
return set_collide_id(collide_id, id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int OdeSpace::
|
int OdeSpace::
|
||||||
get_collide_id(OdeGeom& geom)
|
get_collide_id(OdeGeom& geom) {
|
||||||
{
|
dGeomID id = geom.get_id();
|
||||||
dGeomID id = geom.get_id();
|
return get_collide_id(id);
|
||||||
return get_collide_id(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int OdeSpace::
|
int OdeSpace::
|
||||||
get_collide_id(dGeomID id)
|
get_collide_id(dGeomID id) {
|
||||||
{
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
GeomCollideIdMap::iterator iter2 = _geom_collide_id_map.begin();
|
GeomCollideIdMap::iterator iter2 = _geom_collide_id_map.begin();
|
||||||
while (iter2 != _geom_collide_id_map.end()) {
|
while (iter2 != _geom_collide_id_map.end()) {
|
||||||
|
@ -39,162 +39,139 @@ OdeWorld::
|
|||||||
|
|
||||||
void OdeWorld::
|
void OdeWorld::
|
||||||
destroy() {
|
destroy() {
|
||||||
if(_num_surfaces > 0)
|
if(_num_surfaces > 0) {
|
||||||
{
|
delete _surface_table;
|
||||||
delete _surface_table;
|
|
||||||
}
|
}
|
||||||
|
nassertv(_id);
|
||||||
dWorldDestroy(_id);
|
dWorldDestroy(_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
void OdeWorld::
|
void OdeWorld::
|
||||||
assign_surface_body(OdeBody& body, int surface)
|
assign_surface_body(OdeBody& body, int surface) {
|
||||||
{
|
// odeworld_cat.debug() << "assign_surface_body body.Id =" << body.get_id() << " surface=" << surface << "\n";
|
||||||
// odeworld_cat.debug() << "assign_surface_body body.Id =" << body.get_id() << " surface=" << surface << "\n";
|
_body_dampen_map[body.get_id()].surfaceType = surface;
|
||||||
_body_dampen_map[body.get_id()].surfaceType = surface;
|
_body_dampen_map[body.get_id()].dampen = 0.0f;
|
||||||
_body_dampen_map[body.get_id()].dampen = 0.0f;
|
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void OdeWorld::
|
void OdeWorld::
|
||||||
add_body_dampening(OdeBody& body, int surface)
|
add_body_dampening(OdeBody& body, int surface) {
|
||||||
{
|
_body_dampen_map[body.get_id()].dampen = 0.0f;
|
||||||
_body_dampen_map[body.get_id()].dampen = 0.0f;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OdeWorld::
|
void OdeWorld::
|
||||||
init_surface_table(PN_uint8 num_surfaces)
|
init_surface_table(PN_uint8 num_surfaces) {
|
||||||
{
|
_surface_table = new sSurfaceParams[num_surfaces * num_surfaces];
|
||||||
_surface_table = new sSurfaceParams[num_surfaces * num_surfaces];
|
//_dampen_table = new sSurfaceParams[num_surfaces * num_surfaces];
|
||||||
//_dampen_table = new sSurfaceParams[num_surfaces * num_surfaces];
|
_num_surfaces = num_surfaces;
|
||||||
_num_surfaces = num_surfaces;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OdeWorld::
|
void OdeWorld::
|
||||||
set_surface(int pos1, int pos2, sSurfaceParams& entry)
|
set_surface(int pos1, int pos2, sSurfaceParams& entry) {
|
||||||
{
|
odeworld_cat.debug() << " pos1 " << pos1 << " pos2 " << pos2 << " num surfaces " << (int)_num_surfaces << " endline\n";
|
||||||
odeworld_cat.debug() << " pos1 " << pos1 << " pos2 " << pos2 << " num surfaces " << (int)_num_surfaces << " endline\n";
|
if((_num_surfaces <= pos1) || (_num_surfaces <= pos2)) {
|
||||||
if((_num_surfaces <= pos1) || (_num_surfaces <= pos2))
|
odeworld_cat.error() << "surface position exceeds size of surface table, set num_surface in initSurfaceTable higher." << "\n";
|
||||||
{
|
return;
|
||||||
odeworld_cat.error() << "surface position exceeds size of surface table, set num_surface in initSurfaceTable higher." << "\n";
|
}
|
||||||
return;
|
int true_pos = (pos1 * _num_surfaces) + pos2;
|
||||||
}
|
_surface_table[true_pos].colparams.mode = entry.colparams.mode;
|
||||||
int true_pos = (pos1 * _num_surfaces) + pos2;
|
_surface_table[true_pos].colparams.mu = entry.colparams.mu;
|
||||||
_surface_table[true_pos].colparams.mode = entry.colparams.mode;
|
_surface_table[true_pos].colparams.mu2 = entry.colparams.mu2;
|
||||||
_surface_table[true_pos].colparams.mu = entry.colparams.mu;
|
_surface_table[true_pos].colparams.bounce = entry.colparams.bounce;
|
||||||
_surface_table[true_pos].colparams.mu2 = entry.colparams.mu2;
|
_surface_table[true_pos].colparams.bounce_vel = entry.colparams.bounce_vel;
|
||||||
_surface_table[true_pos].colparams.bounce = entry.colparams.bounce;
|
_surface_table[true_pos].colparams.soft_cfm = entry.colparams.soft_cfm;
|
||||||
_surface_table[true_pos].colparams.bounce_vel = entry.colparams.bounce_vel;
|
_surface_table[true_pos].colparams.motion1 = entry.colparams.motion1;
|
||||||
_surface_table[true_pos].colparams.soft_cfm = entry.colparams.soft_cfm;
|
_surface_table[true_pos].colparams.motion2 = entry.colparams.motion2;
|
||||||
_surface_table[true_pos].colparams.motion1 = entry.colparams.motion1;
|
_surface_table[true_pos].colparams.slip1 = entry.colparams.slip1;
|
||||||
_surface_table[true_pos].colparams.motion2 = entry.colparams.motion2;
|
_surface_table[true_pos].colparams.slip2 = entry.colparams.slip2;
|
||||||
_surface_table[true_pos].colparams.slip1 = entry.colparams.slip1;
|
_surface_table[true_pos].dampen = entry.dampen;
|
||||||
_surface_table[true_pos].colparams.slip2 = entry.colparams.slip2;
|
|
||||||
_surface_table[true_pos].dampen = entry.dampen;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sSurfaceParams& OdeWorld::
|
sSurfaceParams& OdeWorld::
|
||||||
get_surface(PN_uint8 surface1, PN_uint8 surface2)
|
get_surface(PN_uint8 surface1, PN_uint8 surface2) {
|
||||||
{
|
int true_pos = 0;
|
||||||
int true_pos = 0;
|
if(surface1 >= surface2) {
|
||||||
if(surface1 >= surface2)
|
true_pos = (surface1 * _num_surfaces) + surface2;
|
||||||
{
|
} else {
|
||||||
true_pos = (surface1 * _num_surfaces) + surface2;
|
true_pos = (surface2 * _num_surfaces) + surface1;
|
||||||
}
|
}
|
||||||
else
|
if((_num_surfaces <= surface1) || (_num_surfaces <= surface2)) {
|
||||||
{
|
odeworld_cat.error() << "surface position exceeds size of surface table, set num_surface in initSurfaceTable higher." << "\n";
|
||||||
true_pos = (surface2 * _num_surfaces) + surface1;
|
//nassertr_always((_num_surfaces > surface1 && _num_surfaces > surface2), _surface_table[true_pos]);
|
||||||
}
|
}
|
||||||
if((_num_surfaces <= surface1) || (_num_surfaces <= surface2))
|
return _surface_table[true_pos];
|
||||||
{
|
|
||||||
odeworld_cat.error() << "surface position exceeds size of surface table, set num_surface in initSurfaceTable higher." << "\n";
|
|
||||||
//nassertr_always((_num_surfaces > surface1 && _num_surfaces > surface2), _surface_table[true_pos]);
|
|
||||||
}
|
|
||||||
return _surface_table[true_pos];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void OdeWorld::
|
void OdeWorld::
|
||||||
set_surface_entry( PN_uint8 pos1, PN_uint8 pos2,
|
set_surface_entry(PN_uint8 pos1, PN_uint8 pos2,
|
||||||
dReal mu,
|
dReal mu,
|
||||||
dReal bounce,
|
dReal bounce,
|
||||||
dReal bounce_vel,
|
dReal bounce_vel,
|
||||||
dReal soft_erp,
|
dReal soft_erp,
|
||||||
dReal soft_cfm,
|
dReal soft_cfm,
|
||||||
dReal slip,
|
dReal slip,
|
||||||
dReal dampen)
|
dReal dampen) {
|
||||||
{
|
//todo: add mode
|
||||||
//todo: add mode
|
sSurfaceParams new_params;
|
||||||
sSurfaceParams new_params;
|
int someMode = 0;
|
||||||
int someMode = 0;
|
if (bounce > 0.0001) {
|
||||||
if (bounce > 0.0001)
|
someMode |= dContactBounce;
|
||||||
{
|
}
|
||||||
someMode |= dContactBounce;
|
if (soft_erp > 0.0001) {
|
||||||
}
|
someMode |= dContactSoftERP;
|
||||||
if (soft_erp > 0.0001)
|
}
|
||||||
{
|
if (soft_cfm > 0.0001) {
|
||||||
someMode |= dContactSoftERP;
|
someMode |= dContactSoftCFM;
|
||||||
}
|
}
|
||||||
if (soft_cfm > 0.0001)
|
if (slip > 0.0001) {
|
||||||
{
|
someMode = someMode | dContactSlip1 | dContactSlip2;
|
||||||
someMode |= dContactSoftCFM;
|
}
|
||||||
}
|
new_params.colparams.mode = dContactBounce | dContactSoftCFM | dContactApprox1;// | dContactSoftERP;
|
||||||
if (slip > 0.0001)
|
new_params.colparams.mu = mu;
|
||||||
{
|
new_params.colparams.mu2 = mu;
|
||||||
someMode = someMode | dContactSlip1 | dContactSlip2;
|
new_params.colparams.bounce = bounce;
|
||||||
}
|
new_params.colparams.bounce_vel = bounce_vel;
|
||||||
new_params.colparams.mode = dContactBounce | dContactSoftCFM | dContactApprox1;// | dContactSoftERP;
|
new_params.colparams.soft_erp = soft_erp;
|
||||||
new_params.colparams.mu = mu;
|
new_params.colparams.soft_cfm = soft_cfm;
|
||||||
new_params.colparams.mu2 = mu;
|
new_params.colparams.slip1 = slip;
|
||||||
new_params.colparams.bounce = bounce;
|
new_params.colparams.slip2 = slip;
|
||||||
new_params.colparams.bounce_vel = bounce_vel;
|
new_params.colparams.motion1 = 0.0;
|
||||||
new_params.colparams.soft_erp = soft_erp;
|
new_params.colparams.motion2 = 0.0;
|
||||||
new_params.colparams.soft_cfm = soft_cfm;
|
new_params.dampen = dampen;
|
||||||
new_params.colparams.slip1 = slip;
|
//todo: a bit of wasted space here
|
||||||
new_params.colparams.slip2 = slip;
|
set_surface(pos1, pos2, new_params);
|
||||||
new_params.colparams.motion1 = 0.0;
|
|
||||||
new_params.colparams.motion2 = 0.0;
|
if(pos1 >= pos2) {
|
||||||
new_params.dampen = dampen;
|
|
||||||
//todo: a bit of wasted space here
|
|
||||||
set_surface(pos1, pos2, new_params);
|
set_surface(pos1, pos2, new_params);
|
||||||
|
} else {
|
||||||
if(pos1 >= pos2)
|
set_surface(pos2, pos1, new_params);
|
||||||
{
|
}
|
||||||
set_surface(pos1, pos2, new_params);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
set_surface(pos2, pos1, new_params);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void OdeWorld::
|
void OdeWorld::
|
||||||
set_dampen_on_bodies(dBodyID id1, dBodyID id2,dReal damp)
|
set_dampen_on_bodies(dBodyID id1, dBodyID id2,dReal damp) {
|
||||||
{
|
if(_body_dampen_map[id1].dampen < damp) {
|
||||||
if(_body_dampen_map[id1].dampen < damp)
|
_body_dampen_map[id1].dampen = damp;
|
||||||
{
|
}
|
||||||
_body_dampen_map[id1].dampen = damp;
|
if(_body_dampen_map[id2].dampen < damp) {
|
||||||
}
|
_body_dampen_map[id2].dampen = damp;
|
||||||
if(_body_dampen_map[id2].dampen < damp)
|
}
|
||||||
{
|
|
||||||
_body_dampen_map[id2].dampen = damp;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float OdeWorld::
|
float OdeWorld::
|
||||||
apply_dampening(float dt, OdeBody& body)
|
apply_dampening(float dt, OdeBody& body) {
|
||||||
{
|
dBodyID bodyId = body.get_id();
|
||||||
dBodyID bodyId = body.get_id();
|
dReal damp = _body_dampen_map[bodyId].dampen;
|
||||||
dReal damp = _body_dampen_map[bodyId].dampen;
|
float dampening = 1.00 - (damp * dt);
|
||||||
float dampening = 1.00 - (damp * dt);
|
body.set_angular_vel(body.get_angular_vel() * dampening);
|
||||||
body.set_angular_vel(body.get_angular_vel() * dampening);
|
body.set_linear_vel(body.get_linear_vel() * dampening);
|
||||||
body.set_linear_vel(body.get_linear_vel() * dampening);
|
_body_dampen_map[bodyId].dampen = 0.0;
|
||||||
_body_dampen_map[bodyId].dampen = 0.0;
|
return dampening;
|
||||||
return dampening;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
OdeWorld::
|
OdeWorld::
|
||||||
|
Loading…
x
Reference in New Issue
Block a user