Moderators: Sascha Willems, walaber
NewtonSetSolverModel(mpNewtonWorld,0);
NewtonSetFrictionModel(mpNewtonWorld,0);
are these three very small cylnders wit teh same orientaion? it look they are almost in the same position
//test Yeside compound shape shape
// - Rotation="1.5708 -0 0" Translation="0 0 0.024399" Size="0.021 0.096" Pos="0 0 0.115947"
// - Rotation="1.5708 -0 0" Translation="0 0 0.056366" Size="0.195 0.024" Pos="0 0 0.147914"
// - Rotation="1.5708 -0 0" Translation="0 0 -0.056366" Size="0.0065 0.07 Pos="0 0 0.035182"
NewtonCompoundCollisionBeginAddRemove(compound);
dMatrix offsetMatrix (dPitchMatrix(1.5708f));
offsetMatrix.m_posit.m_z = 0.115947f;
NewtonCollision* collision = NewtonCreateCylinder (world, 0.021f, 0.096f, 0, &offsetMatrix[0][0]) ;
NewtonCompoundCollisionAddSubCollision (compound, collision);
NewtonDestroyCollision(collision);
offsetMatrix.m_posit.m_z = 0.147914f;
collision = NewtonCreateCylinder (world, 0.195f, 0.024f, 0, &offsetMatrix[0][0]) ;
NewtonCompoundCollisionAddSubCollision (compound, collision);
NewtonDestroyCollision(collision);
offsetMatrix.m_posit.m_z = 0.035182f;
collision = NewtonCreateCylinder (world, 0.0065f, 0.07f, 0, &offsetMatrix[0][0]) ;
NewtonCompoundCollisionAddSubCollision (compound, collision);
NewtonDestroyCollision(collision);
NewtonCompoundCollisionEndAddRemove(compound);
void DemoEntityManager::SerializeFile (void* const serializeHandle, const void* const buffer, int size)
{
// check that each chunk is a multiple of 4 bytes, this is useful for easy little to big Indian conversion
_ASSERTE ((size & 0x03) == 0);
fwrite (buffer, size, 1, (FILE*) serializeHandle);
}
void DemoEntityManager::DeserializeFile (void* const serializeHandle, void* const buffer, int size)
{
// check that each chunk is a multiple of 4 bytes, this is useful for easy little to big Indian conversion
_ASSERTE ((size & 0x03) == 0);
fread (buffer, size, 1, (FILE*) serializeHandle);
}
void DemoEntityManager::BodySerialization (NewtonBody* const body, NewtonSerializeCallback serializeCallback, void* const serializeHandle)
{
// here the use can save information of this body, ex:
// a string naming the body,
// serialize the visual mesh, or save a link to the visual mesh
// save labels for looking up the body call backs
// for the demos I will simple write three stream to identify what body it is, the application can do anything
const char* const bodyIndentification = "gravityBody\0\0\0\0";
int size = (strlen (bodyIndentification) + 3) & -4;
serializeCallback (serializeHandle, &size, sizeof (size));
serializeCallback (serializeHandle, bodyIndentification, size);
}
void DemoEntityManager::BodyDeserialization (NewtonBody* const body, NewtonDeserializeCallback serializecallback, void* const serializeHandle)
{
int size;
char bodyIndentification[256];
serializecallback (serializeHandle, &size, sizeof (size));
serializecallback (serializeHandle, bodyIndentification, size);
// get the world and the scene form the world user data
NewtonWorld* const world = NewtonBodyGetWorld(body);
DemoEntityManager* const scene = (DemoEntityManager*)NewtonWorldGetUserData(world);
// here we attach a visual object to the entity,
dMatrix matrix;
NewtonBodyGetMatrix(body, &matrix[0][0]);
DemoEntity* const entity = new DemoEntity(matrix, NULL);
scene->Append (entity);
NewtonBodySetUserData (body, entity);
NewtonBodySetTransformCallback(body, DemoEntity::TransformCallback);
NewtonBodySetForceAndTorqueCallback(body, PhysicsApplyGravityForce);
//for visual mesh we will collision mesh and convert it to a visual mesh using NewtonMesh
NewtonCollision* const collision = NewtonBodyGetCollision(body);
int collisionID = NewtonCollisionGetType(collision) ;
DemoMesh* mesh = NULL;
switch (collisionID)
{
case SERIALIZE_ID_HEIGHTFIELD:
{
NewtonCollisionInfoRecord info;
NewtonCollisionGetInfo(collision, &info);
const NewtonHeightFieldCollisionParam& heighfield = info.m_heightField;
mesh = new DemoMesh ("terrain", heighfield.m_elevation, heighfield.m_width, heighfield.m_horizonalScale, 1.0f/16.0f, 128);
break;
}
default:
mesh = new DemoMesh("cylinder_1", collision, NULL, NULL, NULL);
break;
}
entity->SetMesh(mesh);
mesh->Release();
}
}
void DemoEntityManager::DeserializedPhysicScene (const char* const name)
{
// add the sky
CreateSkyBox();
FILE* const file = fopen (name, "rb");
// read the application data use to initialize the engine and other application related stuff.
// reading the camera orientation
dMatrix camMatrix;
DeserializeFile (file, &camMatrix, sizeof (camMatrix));
SetCameraMatrix(dQuaternion (camMatrix), camMatrix.m_posit);
NewtonDeserialize (m_world, BodyDeserialization, DeserializeFile, file);
fclose (file);
}
void DemoEntityManager::InterpolateMatrices ()
{
// calculate the fraction of the time step for interpolations
unsigned64 timeStep = dGetTimeInMicrosenconds () - m_microsecunds;
dFloat step = (dFloat (timeStep) * MAX_PHYSICS_FPS) / 1.0e6f;
_ASSERTE (step >= 0.0f);
if (step > 1.0f) {
step = 1.0f;
}
// interpolate the Camera matrix;
m_camera->InterpolateMatrix (*this, step);
// interpolate the location of all entities in the world
for (NewtonBody* body = NewtonWorldGetFirstBody(m_world); body; body = NewtonWorldGetNextBody(m_world, body)) {
DemoEntity* const entity = (DemoEntity*)NewtonBodyGetUserData(body);
if (entity) {
entity->InterpolateMatrix (*this, step);
}
}
}
Users browsing this forum: No registered users and 0 guests