[ODE] Space additions for dRay
David McClurg
dmcclurg at pandemicstudios.com.au
Tue Aug 20 23:08:02 2002
This is a multi-part message in MIME format.
------_=_NextPart_001_01C248CA.2E39C162
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Erwin-- did your space locking stuff ever get posted? I'd very much =
like to look at this.
Also, I have a patch for a Tri-list vs Ray collider if you want it. See =
the attached file and just look at the int =
dcTriListCollider::CollideRay() function.
Ta
-----Original Message-----
From: Erwin de Vries [mailto:erwin@vo.com]
Sent: Monday, 5 August 2002 5:33 AM
To: ode@q12.org
Subject: [ODE] Space additions for dRay
Hi,
Today i've added some new stuff to the space. (Hash & simple) The =
concept is
'locking' the space. A locked space is a space where no modifications to
itself and the geometries it contains are allowed. Internally the =
space_aabb
pointers are calculated once in a Lock()/Unlock() sequence. Nested
lock/unlock pairs are not allowed.
It can be used to do instant collision detection for (but not limited =
to)
rays with minimal overhead.
The implementation is as follows:
// Puts the space in locked mode.
void dSpaceLock (dSpaceID space);
// Collides a single geometry with the other geometries in the space
void dSpaceCollideGeom (dSpaceID space, dxGeom* g, void *data, =
dNearCallback
*callback);
// Puts the space back in normal mode.
void dSpaceUnlock (dSpaceID space);
// Tells whether the space is currently locked.
int dSpaceLocked(dSpaceID space);
Thats it. These functions do not interfere with current behavior, so it =
is
all backwards compatible.
A current problem is dBodySetPosition(), etc. Unlike =
dGeomSetPostition(),
etc, we cant assert these, because there is no telling which geometries
point to a body's data. I dont have a good solution to this problem. =
What
would be possible is to regenerate a list of AABB's in the =
dSpaceUnlock()
function, and compare it to the one generated in the previous =
dSpaceLock().
If they dont match, assert. Only in debugmode of course.
I'll post this soon. Would you like to add this to the core code, Russ? =
I
just created it, so i havent tested it much, but i will do so the next =
days
It passes the space test incuded with ODE. Internally i had to change =
some
things in the hashspace. It now uses buffered allocations (using dArray)
instead of stack allocations for the lists of objects, which of course =
might
be a little slower, and certainly uses more memory. But i've not yet =
tested
how much. Couldnt be -that- much.
Erwin
_______________________________________________
ODE mailing list
ODE@q12.org
http://q12.org/mailman/listinfo/ode
------_=_NextPart_001_01C248CA.2E39C162
Content-Type: application/octet-stream;
name="dcTriListCollider.cpp"
Content-Transfer-Encoding: base64
Content-Description: dcTriListCollider.cpp
Content-Disposition: attachment;
filename="dcTriListCollider.cpp"
Ly8gRG8gTk9UIGJ1aWxkIHRoaXMgZmlsZSBzZXBlcmF0ZWx5LiBJdCBpcyBpbmNsdWRlZCBpbiBk
VHJpTGlzdC5jcHAgYXV0b21hdGljYWxseS4NCiNpbmNsdWRlICJhcnJheS5oIg0KI2luY2x1ZGUg
ImR4VHJpTGlzdC5oIg0KI2luY2x1ZGUgImRjVHJpTGlzdENvbGxpZGVyLmgiDQoNCiNpbmNsdWRl
ICJvcGNvZGUvb3Bjb2RlLmgiDQovL3VzaW5nIG5hbWVzcGFjZSBPcGNvZGU7DQojaW5jbHVkZSAi
ZGNBQUJCQ29sbGlkZXIuaCINCiNpbmNsdWRlICJkY09CQkNvbGxpZGVyLmgiDQojaW5jbHVkZSAi
b2RlL2RSYXkuaCINCg0KLy8jZGVmaW5lIEdFTkVSQVRFQk9ESUVTDQoNCmRjVHJpTGlzdENvbGxp
ZGVyOjpkY1RyaUxpc3RDb2xsaWRlcihkeEdlb20qIEdlb21ldHJ5KSA6IEFBQkJDb2xsaWRlcihW
ZXJ0aWNlcywgSW5kaWNlcyksIE9CQkNvbGxpZGVyKFZlcnRpY2VzLCBJbmRpY2VzKXsNCgl0aGlz
LT5HZW9tZXRyeSA9IEdlb21ldHJ5Ow0KCUdlb21EYXRhID0gKGR4VHJpTGlzdCopZEdlb21HZXRD
bGFzc0RhdGEoR2VvbWV0cnkpOw0KDQoJbWVtc2V0KEJveENvbnRhY3RzLCAwLCBzaXplb2YoQm94
Q29udGFjdHMpKTsNCn0NCg0KZGNUcmlMaXN0Q29sbGlkZXI6On5kY1RyaUxpc3RDb2xsaWRlcigp
ew0KCS8vDQp9DQoNCnZvaWQgZGNUcmlMaXN0Q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GhpdHMgYnV0IG5vdCB3aXRoaW4gYm91bmRhcmllcw0KICAgICAgfQ0KDQogICAg
ICBjb25zdCBkY1ZlY3RvcjMgQ29udGFjdFBvcyA9IFJheU9yaWdpbiArIFJheURpcmVjdGlvbiAq
IENvbnRhY3REZXB0aDsNCg0KICAgICAgLy8gSW5zaWRlIHRyaWFuZ2xlPw0KICAgICAgaW50IElu
ZGV4Ow0KICAgICAgZm9yIChJbmRleCA9IDA7IEluZGV4IDwgMzsgSW5kZXgrKyl7DQogICAgICAg
IGNvbnN0IGRjVmVjdG9yMyYgdjAgPSBWZXJ0aWNlc1tJbmRpY2VzW1RyaUluZGV4ICogMyArIElu
ZGV4XV07DQogICAgICAgIGNvbnN0IGRjVmVjdG9yMyYgdjEgPSBWZXJ0aWNlc1tJbmRpY2VzW1Ry
aUluZGV4ICogMyArIChJbmRleCArIDEpICUgM11dOw0KICAgICAgICBkY1BsYW5lIFBsYW5lKHYw
LCB2MSwgdjEgLSBUcmlQbGFuZS5Ob3JtYWwpOw0KDQogICAgICAgIGlmICghUGxhbmUuQ29udGFp
bnMoQ29udGFjdFBvcykpew0KICAgICAgICAgIGJyZWFrOw0KICAgICAgICB9DQogICAgICB9DQog
ICAgICBpZiAoSW5kZXggPT0gMyl7DQogICAgICAgIGRDb250YWN0R2VvbSYgT3V0Q29udGFjdCA9
ICpDb250YWN0czsNCiAgICAgICAgaWYgKE91dFRyaUNvdW50ID09IDAgfHwgQ29udGFjdERlcHRo
IDwgT3V0Q29udGFjdC5kZXB0aCkgew0KICAgICAgICAgICgoZGNWZWN0b3IzJilPdXRDb250YWN0
LnBvcykgPSBDb250YWN0UG9zOw0KICAgICAgICAgICgoZGNWZWN0b3IzJilPdXRDb250YWN0Lm5v
cm1hbCkgPSBDb250YWN0Tm9ybWFsOw0KICAgICAgICAgIE91dENvbnRhY3QuZGVwdGggPSBDb250
YWN0RGVwdGg7DQogICAgICAgICAgT3V0VHJpQ291bnQgPSAxOw0KICAgICAgICB9DQogIC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