Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


#ActualN01

Posted 05 September 2013 - 07:12 AM

oh, i just used PxRigidDynamic::setMass(...);

i replaced it with PxRigidBodyExt::setMassAndUpdateInertia after createShape(), using the same masses(~25 for medium object and 1-5 for small objects). and now, if i set scene scale factor to 1.0f, objects don't fall through stuff, but everything is still in slow-mo. so maybe i've missed some other parameter?

 

here's how i initialize convex hull actors(beware of temporary\experimental grabage-code):

 


mDynamicMaterial = mPhysics->createMaterial(0.5f, 0.5f, 0.3f);
mStaticMaterial = mPhysics->createMaterial(1.0f, 1.0f, 0.5f);

...

convexEntities[convexEntityId].objectId = f;
convexEntities[convexEntityId].isStatic = Objects[f].isImmovable;

tempVertices.resize(Objects[f].convexHull.size()/3); //convert to PxVec3, eliminate this part in future
for(unsigned v = 0, p = 0; v < Objects[f].convexHull.size() - 1; v += 3, p++) {
    tempVertices[p] = PxVec3(Objects[f].convexHull[v], Objects[f].convexHull[v + 1], Objects[f].convexHull[v + 2]);
}

convexDesc.points.count     = tempVertices.size();
convexDesc.points.stride    = sizeof(PxVec3);
convexDesc.points.data      = &tempVertices[0];
convexDesc.flags            = PxConvexFlag::eCOMPUTE_CONVEX | PxConvexFlag::eINFLATE_CONVEX;//just in case, so it never exceeds 256. mesh reduction algorithms i found, screw up convex hulls for some reason, so i decided to rely on PhysX.

PxToolkit::MemoryOutputStream buf;
if(!mCooking->cookConvexMesh(convexDesc, buf)) {
    LOG << " #Failed to cook convex hull for " << modelStorage[Objects[f].modelId].modelName << endl;
    break;
}

PxToolkit::MemoryInputData input(buf.getData(), buf.getSize());
PxConvexMesh* convexMesh = mPhysics->createConvexMesh(input);

tempMatrix = glm::translate(glm::mat4(), Objects[f].position.toVec3());
tempMatrix = glm::rotate(tempMatrix, Objects[f].rotation.x, 1.0f, 0.0f, 0.0f);
tempMatrix = glm::rotate(tempMatrix, Objects[f].rotation.y, 0.0f, 1.0f, 0.0f);
tempMatrix = glm::rotate(tempMatrix, Objects[f].rotation.z, 0.0f, 0.0f, 1.0f);

pxTempMatrix = PxMat44(glm::value_ptr(tempMatrix));
if(Objects[f].isImmovable == false) {
    convexEntities[convexEntityId].mDynamicActor = mPhysics->createRigidDynamic(PxTransform(PxVec3(0.0)));
    convexEntities[convexEntityId].mDynamicActor->setGlobalPose(PxTransform(pxTempMatrix));
    convexEntities[convexEntityId].mDynamicActor->setLinearDamping(PxReal(0.05f));
    convexEntities[convexEntityId].mDynamicActor->setAngularDamping(PxReal(0.05f));

    convexEntities[convexEntityId].mDynamicActor->setCMassLocalPose(PxTransform(PxVec3(Objects[f].localCenter.x, Objects[f].localCenter.y, Objects[f].localCenter.z)));

    PxMeshScale scale(PxVec3(Objects[f].scale.x,Objects[f].scale.y,Objects[f].scale.z), PxQuat::createIdentity()); //because it's more convenient in my case
    PxShape* aConvexShape = convexEntities[convexEntityId].mDynamicActor->createShape(PxConvexMeshGeometry(convexMesh, scale), *mDynamicMaterial);
    PxRigidBodyExt::setMassAndUpdateInertia(*convexEntities[convexEntityId].mDynamicActor, Objects[f].weight);

    mScene->addActor(*convexEntities[convexEntityId].mDynamicActor);
} else {
    convexEntities[convexEntityId].mStaticActor = mPhysics->createRigidStatic(PxTransform(PxVec3(0.0)));
    convexEntities[convexEntityId].mStaticActor->setGlobalPose(PxTransform(pxTempMatrix));

    PxMeshScale scale(PxVec3(Objects[f].scale.x,Objects[f].scale.y,Objects[f].scale.z), PxQuat::createIdentity());
    PxShape* aConvexShape = convexEntities[convexEntityId].mStaticActor->createShape(PxConvexMeshGeometry(convexMesh, scale), *mStaticMaterial);

    mScene->addActor(*convexEntities[convexEntityId].mStaticActor);
}

P.S. i use PxDefaultSimulationFilterShader.


#1N01

Posted 05 September 2013 - 07:06 AM

oh, i just used PxRigidDynamic::setMass(...);

i replaced it with PxRigidBodyExt::setMassAndUpdateInertia after createShape(), using the same masses(~25 for medium object and 1-5 for small objects). and now, if i set scene scale factor to 1.0f, objects don't fall through stuff, but everything is still in slow-mo. so maybe i've missed some other parameter?

 

here's how i initialize convex hull actors(beware of temporary\experimental grabage-code):

 


mDynamicMaterial = mPhysics->createMaterial(0.5f, 0.5f, 0.3f);
mStaticMaterial = mPhysics->createMaterial(1.0f, 1.0f, 0.5f);

...

convexEntities[convexEntityId].objectId = f;
convexEntities[convexEntityId].isStatic = Objects[f].isImmovable;

tempVertices.resize(Objects[f].convexHull.size()/3); //convert to PxVec3, eliminate this part in future
for(unsigned v = 0, p = 0; v < Objects[f].convexHull.size() - 1; v += 3, p++) {
    tempVertices[p] = PxVec3(Objects[f].convexHull[v], Objects[f].convexHull[v + 1], Objects[f].convexHull[v + 2]);
}

convexDesc.points.count     = tempVertices.size();
convexDesc.points.stride    = sizeof(PxVec3);
convexDesc.points.data      = &tempVertices[0];
convexDesc.flags            = PxConvexFlag::eCOMPUTE_CONVEX | PxConvexFlag::eINFLATE_CONVEX;//just in case, so it never exceeds 256. mesh reduction algorithms i found, screw up convex hulls for some reason, so i decided to rely on PhysX.

PxToolkit::MemoryOutputStream buf;
if(!mCooking->cookConvexMesh(convexDesc, buf)) {
    LOG << " #Failed to cook convex hull for " << modelStorage[Objects[f].modelId].modelName << endl;
    break;
}

PxToolkit::MemoryInputData input(buf.getData(), buf.getSize());
PxConvexMesh* convexMesh = mPhysics->createConvexMesh(input);

tempMatrix = glm::translate(glm::mat4(), Objects[f].position.toVec3() * reScale);
tempMatrix = glm::rotate(tempMatrix, Objects[f].rotation.x, 1.0f, 0.0f, 0.0f);
tempMatrix = glm::rotate(tempMatrix, Objects[f].rotation.y, 0.0f, 1.0f, 0.0f);
tempMatrix = glm::rotate(tempMatrix, Objects[f].rotation.z, 0.0f, 0.0f, 1.0f);

pxTempMatrix = PxMat44(glm::value_ptr(tempMatrix));
if(Objects[f].isImmovable == false) {
    convexEntities[convexEntityId].mDynamicActor = mPhysics->createRigidDynamic(PxTransform(PxVec3(0.0)));
    convexEntities[convexEntityId].mDynamicActor->setGlobalPose(PxTransform(pxTempMatrix));
    convexEntities[convexEntityId].mDynamicActor->setLinearDamping(PxReal(0.05f));
    convexEntities[convexEntityId].mDynamicActor->setAngularDamping(PxReal(0.05f));

    convexEntities[convexEntityId].mDynamicActor->setCMassLocalPose(PxTransform(PxVec3(Objects[f].localCenter.x, Objects[f].localCenter.y, Objects[f].localCenter.z)));

    PxMeshScale scale(PxVec3(Objects[f].scale.x,Objects[f].scale.y,Objects[f].scale.z), PxQuat::createIdentity()); //because it's more convenient in my case
    PxShape* aConvexShape = convexEntities[convexEntityId].mDynamicActor->createShape(PxConvexMeshGeometry(convexMesh, scale), *mDynamicMaterial);
    PxRigidBodyExt::setMassAndUpdateInertia(*convexEntities[convexEntityId].mDynamicActor, Objects[f].weight);

    mScene->addActor(*convexEntities[convexEntityId].mDynamicActor);
} else {
    convexEntities[convexEntityId].mStaticActor = mPhysics->createRigidStatic(PxTransform(PxVec3(0.0)));
    convexEntities[convexEntityId].mStaticActor->setGlobalPose(PxTransform(pxTempMatrix));

    PxMeshScale scale(PxVec3(Objects[f].scale.x,Objects[f].scale.y,Objects[f].scale.z), PxQuat::createIdentity());
    PxShape* aConvexShape = convexEntities[convexEntityId].mStaticActor->createShape(PxConvexMeshGeometry(convexMesh, scale), *mStaticMaterial);

    mScene->addActor(*convexEntities[convexEntityId].mStaticActor);
}

P.S. i use PxDefaultSimulationFilterShader.


PARTNERS