Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- physx::PxRigidDynamic *Game::CreatePhysXActor(physx::PxGeometry &geometry,physx::PxMaterial &material,physx::PxTransform &transform)
- {
- physx::PxPhysics *physics = m_stateNetwork->GetPhysics();
- if(physics == NULL)
- return NULL;
- physx::PxRigidDynamic *actor = physics->createRigidDynamic(transform);
- actor->createShape(geometry,material);
- m_pxScene->addActor(*actor);
- actor->putToSleep();
- return actor;
- }
- physx::PxRigidDynamic *Game::CreatePhysXActor(physx::PxGeometry &geometry,physx::PxMaterial &material,glm::vec3 &pos) {return CreatePhysXActor(geometry,material,physx::PxTransform(physx::PxVec3(pos.x,pos.y,pos.z)));}
- PhysObj *BaseEntity::InitializeModelPhysics()
- {
- Model *mdl = GetModel();
- if(mdl == NULL)
- return NULL;
- std::vector<CollisionMesh*> *collisionMeshes;
- mdl->GetCollisionMeshes(&collisionMeshes);
- if(collisionMeshes->empty())
- return NULL;
- Skeleton *skeleton = mdl->GetSkeleton();
- physx::PxPhysics *physics = engine->GetPhysics();
- physx::PxCooking *cooking = engine->GetCookingLibrary();
- NetworkState *state = GetNetworkState();
- Game *game = state->GetGameState();
- physx::PxMaterial *material = physics->createMaterial(0.5f,0.5f,0.1f);
- physx::PxConvexMeshDesc meshDesc;
- meshDesc.points.stride = sizeof(glm::vec3);
- meshDesc.flags = physx::PxConvexFlag::eCOMPUTE_CONVEX;
- meshDesc.vertexLimit = 256;
- std::vector<physx::PxRigidActor*> actors;
- std::map<int,unsigned int> boneActorIDs;
- bool bPhys = false;
- for(unsigned int i=0;i<collisionMeshes->size();i++)
- {
- CollisionMesh *mesh = (*collisionMeshes)[i];
- std::vector<glm::vec3> &verts = mesh->vertices;
- if(!verts.empty())
- {
- meshDesc.points.count = verts.size();
- meshDesc.points.data = &verts[0];
- physx::MemoryOutputStream buf;
- if(cooking->cookConvexMesh(meshDesc,buf))
- {
- physx::MemoryInputData input(buf.getData(),buf.getSize());
- physx::PxConvexMesh *convexMesh = physics->createConvexMesh(input);
- int boneID = mesh->GetBoneParent();
- std::map<int,unsigned int>::iterator it = boneActorIDs.find(boneID);
- if(it == boneActorIDs.end())
- {
- physx::PxRigidDynamic *actor = game->CreatePhysXActor(physx::PxConvexMeshGeometry(convexMesh),*material,*GetPosition());
- actor->setRigidBodyFlag(physx::PxRigidBodyFlag::Enum::eENABLE_CCD,true);
- actor->setRigidBodyFlag(physx::PxRigidBodyFlag::Enum::eENABLE_CCD_FRICTION,true);
- float mass = 50.f;
- physx::PxRigidBodyExt::setMassAndUpdateInertia(*actor,mass);
- if(bPhys == false)
- {
- bPhys = true;
- if(m_physObject != NULL)
- DestroyPhysicsObject();
- m_physObject = new DynamicPhysObj(this,actor,boneID);
- }
- else
- static_cast<DynamicPhysObj*>(m_physObject)->AddActor(actor,boneID);
- actors.push_back(actor);
- boneActorIDs.insert(std::map<int,unsigned int>::value_type(boneID,actors.size() -1));
- }
- else
- actors[it->second]->createShape(physx::PxConvexMeshGeometry(convexMesh),*material);
- }
- }
- }
- if(bPhys == false)
- return NULL;
- return m_physObject;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement