Game Development Reference
In-Depth Information
Excerpt from include/cyclone/contacts.h
#include <cyclone/contacts.h>
void ContactResolver::prepareContacts(Contact* contacts,
unsigned numContacts,
real duration)
// Generate contact velocity and axis information.
Contact* lastContact = contacts + numContacts;
for(Contact* contact=contacts; contact < lastContact; contact++)
// Calculate the internal contact data (inertia, basis, etc).
In the calculateInternals method of the contact we need to calculate each of the
three bits of data: the contact basis, the relative position, and the relative velocity:
Excerpt from src/contacts.cpp
void Contact::calculateInternals(real duration)
// Check if the first object is NULL, and swap if it is.
if (!body[0]) swapBodies();
// Calculate a set of axes at the contact point.
// Store the relative position of the contact relative to each body.
relativeContactPosition[0] = contactPoint - body[0]->getPosition();
if (body[1]) {
relativeContactPosition[1] =
contactPoint - body[1]->getPosition();
// Find the relative velocity of the bodies at the contact point.
contactVelocity = calculateLocalVelocity(0, duration);
if (body[1]) {
contactVelocity -= calculateLocalVelocity(1, duration);
// Calculate the desired change in velocity for resolution.
Search Nedrilad ::

Custom Search