void Material::create(MaterialPrototype* prototype) { if (mScene == 0) { NxOgre_ThrowError("Tried to create a Material without a valid Scene"); return; } NxMaterialDesc description; Functions::PrototypeFunctions::MaterialPrototypeToNxMaterialDesc(prototype, description); if (description.isValid() == false) { SharedStringStream message(SharedStringStream::_LARGE); message << "An error occured whilst creating a Material.\nThe reason(s) and cause(s) could be:\n\n"; if (mScene == 0) message << " - Scene is not created.\n"; message << Reason::whyAsStream(description).get(); NxOgre_ThrowError(message.get()); return; } mMaterial = mScene->getScene()->createMaterial(description); }
void RigidBody::create(const Matrix44& pose, SimpleShape* shape, Real mass, Scene* scene) { if (mActor != 0) { NxOgre_ThrowError("RigidBody tried to create an actor that was already created."); return; } if (shape == 0) { NxOgre_ThrowError("RigidBody tried to create an actor that has no shape."); return; } if (scene == 0) { NxOgre_ThrowError("RigidBody tried to create an actor that has no scene."); return; } NxActorDesc actor_description; NxBodyDesc body_description; actor_description.globalPose.setRowMajor44(pose.ptr()); Functions::SimpleShapeToActorDescription(actor_description, shape); if (mass) { body_description.mass = mass; actor_description.body = &body_description; } mActor = scene->getScene()->createActor(actor_description); if (mActor == 0) { NxOgre_ThrowError("RigidBody actor was not created."); return; } for (unsigned int i=0; i < actor_description.shapes.size(); i++) { NxShapeDesc* desc = actor_description.shapes[i]; delete desc; } mActor->userData = (void*) NxOgre_New(PhysXPointer)(this, getClassType()); }
SphericalJoint::SphericalJoint(RigidBody* first, RigidBody* second, const SphericalJointDescription& desc) : Joint(first, second), mSphericalJoint(0) { NxSphericalJointDesc description; mRigidBodies[0] = first; mRigidBodies[1] = second; description.actor[0] = mRigidBodies[0]->getNxActor(); if (mRigidBodies[1]) description.actor[1] = mRigidBodies[1]->getNxActor(); else description.actor[1] = 0; Functions::PrototypeFunctions::SphericalJointDescriptionToNxSphericalJointDescription(desc, description); if (description.isValid() == false) { SharedStringStream message(SharedStringStream::_LARGE); message << "An error occured whilst creating a SphericalJoint.\nThe reason(s) and cause(s) could be:\n\n"; message << Reason::whyAsStream(description).get(); NxOgre_ThrowError(message.get()); return; } mJoint = first->getScene()->getScene()->createJoint(description); mSphericalJoint = mJoint->isSphericalJoint(); }
Archive* ResourceSystem::openArchive(const String& name, const UniformResourceIdentifier& uri) { ResourceProtocol* requestedProtocol = 0; ArrayIterator<ResourceProtocol*> iterator = mProtocols.getIterator(); for (ResourceProtocol* protocol = iterator.begin(); protocol = iterator.next();) { if (protocol->getProtocolHash() == uri.getProtocolHash()) { requestedProtocol = protocol; break; } } if (requestedProtocol == 0) { SharedStringStream ss(200); ss << "Could not open archive '" << uri.getLocation() << ":" << uri.getLocation() << "\n" << "Reason: Protocol could not be found."; NxOgre_ThrowError(ss.get()); return 0; } Archive* archive = requestedProtocol->openArchive(name, uri); if (archive == 0) { SharedStringStream ss(200); ss << "Could not open archive '" << uri.getLocation() << ":" << uri.getLocation() << "\n" << "Reason: Protocol could not open archive."; NxOgre_ThrowError(ss.get()); return 0; } mArchives.insert(archive); return archive; }
Resource* ResourceSystem::open(const ArchiveResourceIdentifier& ari, Enums::ResourceAccess access) { Archive* archive = 0; for (unsigned int i=0;i < mArchives.size(); i++) { if (mArchives[i]->getNameHash() == ari.getArchiveHash()) { archive = mArchives[i]; break; } } if (archive == 0) { SharedStringStream ss(200); ss << "Could not open resource '" << ari.getArchive() << ":" << ari.getResourceName() << "\n" << "Reason: Archive could not be found."; NxOgre_ThrowError(ss.get()); return 0; } return archive->open(ari, access); }
void RigidBody::create(RigidBodyPrototype* prototype, Scene* scene, Shapes* final_shapes) { if (mActor != 0) { NxOgre_ThrowError("RigidBody tried to create an actor that was already created."); return; } if (prototype == 0) { NxOgre_ThrowError("RigidBody tried to create an actor that has no prototype."); return; } if (scene == 0) { NxOgre_ThrowError("RigidBody tried to create an actor that has no scene."); return; } if (prototype->mShapes.size() == 0) { NxOgre_ThrowError("RigidBody has no shapes."); return; } mScene = scene; NxActorDesc actor_description; NxBodyDesc body_description; // Copy over the prototype into the Actor and possible Body descriptions. Functions::PrototypeFunctions::RigidBodyPrototypeToNxActorAndNxBodyDesc(prototype, actor_description, body_description); // Create the shapes, and bind them to the shape that represents them - or not. for (unsigned int i=0;i < prototype->mShapes.size(); i++) { Shape* shape = prototype->mShapes[i]; NxShapeDesc* description = shape->create(); //OUAN HACK MAYBE HERE IS WHY SHAPES DIDNT GET ITS NAME description->name=prototype->mName.c_str(); if (description) { if (final_shapes) description->userData = (void*) NxOgre_New(PhysXPointer)(shape, shape->getClassType(), this); actor_description.shapes.push_back(description); } } mActor = mScene->getScene()->createActor(actor_description); if (mActor == 0) { SharedStringStream ss; ss << "RigidBody actor was not created! \n" << "Reason(s) are: \n" << Reason::whyAsStream(actor_description); NxOgre_ThrowError(ss.get()); return; } mActor->userData = (void*) NxOgre_New(PhysXPointer)(this, getClassType()); for (unsigned int i=0; i < actor_description.shapes.size(); i++) { NxShapeDesc* desc = actor_description.shapes[i]; delete desc; } if (final_shapes) { NxShape* const* shapes = mActor->getShapes(); NxU32 nbShapes = mActor->getNbShapes(); while (nbShapes--) { NxShape* physx_shape = shapes[nbShapes]; PhysXShapeBinder::BindShape(physx_shape); final_shapes->insert(pointer_representive_cast<Shape>(physx_shape->userData)); } } }