Ejemplo n.º 1
0
Scene::Scene(ScenePrototype* prototype, NxPhysicsSDK* sdk)
    : mScene(0),
      mSDK(sdk),
      mActors(Classes::_Actor),
      mSceneGeometries(Classes::_SceneGeometry),
      mPhysXCallback(0),
      mSceneTimer(0)
{

    mPhysXCallback = NxOgre_New(PhysXCallback)(this);

    mName = prototype->mName;

    NxSceneDesc scene_description;
    Functions::PrototypeFunctions::ScenePrototypeToNxSceneDesc(prototype, scene_description);
    mProcessingPriority = prototype->mProcessingPriority;
    mFetchingPriority = prototype->mFetchingPriority;
    mProcessing = false;

    scene_description.userTriggerReport = mPhysXCallback;
    scene_description.userContactReport = mPhysXCallback;

    scene_description.timeStepMethod = NX_TIMESTEP_FIXED; // temp.
    scene_description.maxTimestep = 1.0f/60.0f;

    mScene = mSDK->createScene(scene_description);

    if (mScene == 0)
    {
        SharedStringStream message(SharedStringStream::_LARGE);

        if (mName.length())
            message << "An error occured whilst creating the Scene named '" << mName << "'\nThe reason(s) and cause(s) could be:\n\n";
        else
            message << "An error occured whilst creating a Scene.\nThe reason(s) and cause(s) could be:\n\n";

        if (mSDK == 0)
            message << " - NxPhysicsSDK is not created.\n";

        message << Reason::whyAsStream(scene_description).get();

        // Hey there! Got an assertion that points to here?
        // Check your SceneDescription/SceneProtoype properties to see if they are valid or not.
        NxOgre_ThrowAssertion(0, message.get());
        return;
    }

    Material* material = NxOgre_New(Material)(mScene->getMaterialFromIndex(0), this);
    mMaterials.insert(material);

    TimeController::getSingleton()->mListeners[mProcessingPriority].insert(this);
    TimeController::getSingleton()->mListeners[mFetchingPriority].insert(this);


    mSceneTimer = new FixedSceneTimer(this); // temp.

    mMachineIterator = mMachines.getIterator();

}
Ejemplo n.º 2
0
SceneGeometry* Scene::createSceneGeometry(Shape* shape, const Matrix44& pose, const RigidBodyDescription& description)
{
    RigidBodyPrototype* prototype = NxOgre_New(RigidBodyPrototype)();
    Functions::PrototypeFunctions::RigidBodyDescriptionToRigidBodyPrototype(description, prototype);
    prototype->mShapes.insert(shape);
    prototype->mType = Enums::RigidBodyType_Geometry;
    prototype->mGlobalPose = pose;
    SceneGeometry* scene_geometry = NxOgre_New(SceneGeometry)(prototype, this);
    NxOgre_Delete(prototype);
    mSceneGeometries.insert(scene_geometry);
    return scene_geometry;
}
Ejemplo n.º 3
0
Volume* Scene::createVolume(Shapes shapes, const Matrix44& pose, Callback* callback, Enums::VolumeCollisionType vct)
{
    RigidBodyPrototype* prototype = NxOgre_New(RigidBodyPrototype)();
    prototype->mShapes = shapes;
    prototype->mGlobalPose = pose;
    prototype->mType = Enums::RigidBodyType_Volume;
    prototype->mVolumeCollisionType = vct;
    Volume* volume = NxOgre_New(Volume)(prototype, this, callback);
    NxOgre_Delete(prototype);
    mVolumes.insert(volume);
    return volume;
}
Ejemplo n.º 4
0
KinematicActor* Scene::createKinematicActor(Shapes shapes, const Matrix44& pose, const RigidBodyDescription& description)
{
    RigidBodyPrototype* prototype = NxOgre_New(RigidBodyPrototype)();
    Functions::PrototypeFunctions::RigidBodyDescriptionToRigidBodyPrototype(description, prototype);
    prototype->mShapes = shapes;
    prototype->mGlobalPose = pose;
    prototype->mType = Enums::RigidBodyType_Kinematic;
    KinematicActor* kactor = NxOgre_New(KinematicActor)(prototype, this);
    NxOgre_Delete(prototype);
    mKinematicActors.insert(kactor);
    return kactor;
}
Ejemplo n.º 5
0
Actor* Scene::createActor(Shape* shape, const Matrix44& pose, const RigidBodyDescription& description)
{
    RigidBodyPrototype* prototype = NxOgre_New(RigidBodyPrototype)();
    Functions::PrototypeFunctions::RigidBodyDescriptionToRigidBodyPrototype(description, prototype);
    prototype->mShapes.insert(shape);
    prototype->mType = Enums::RigidBodyType_Dynamic;
    prototype->mGlobalPose = pose;
    Actor* actor = NxOgre_New(Actor)(prototype, this);
    NxOgre_Delete(prototype);
    mActors.insert(actor);
    return actor;
}
void UniformResourceIdentifier::set(const char* str)
{

 if (mReferences == 0)
 {
  mURI = NxOgre_New(URIHash)();
  mReferences = (unsigned short*) NxOgre_Allocate(sizeof(unsigned short), Classes::_BufferReferenceCounter);
  (*mReferences) = 1;
 }
 
 // Split up protocol and location here.
 unsigned int str_length    = Functions::getCStringLength(str);
 unsigned int colonPosition = -1;

 for (unsigned int i=0;i < str_length;i++)
 {
  if (str[i] == ':')
  {
   colonPosition = i;
   break;
  }
 }

 if (colonPosition == -1)
  return;

 setProtocol(str, 0, colonPosition);

 if (colonPosition + 1 != str_length)
  setLocation(str, colonPosition + 1, str_length - colonPosition - 1);

}
Ejemplo n.º 7
0
Material* Scene::createMaterial(const MaterialDescription& description)
{
    NxOgre::MaterialPrototype* prototype = NxOgre_New(MaterialPrototype)();
    Functions::PrototypeFunctions::MaterialDescriptionToMaterialPrototype(description, prototype);
    Material* material = createMaterial(prototype);
    NxOgre_Delete(prototype);
    return material;
}
Ejemplo n.º 8
0
OGRE3DBody* OGRE3DRenderSystem::createBody(NxOgre::Shape* shape, NxOgre::Vec3 position, const Ogre::String& meshName,  const NxOgre::RigidBodyDescription& description)
{
 // Create a OGRE3DPrototype using the NxOgre_New macro, all NxOgre classes and classes that
 // use PointerClass should use NxOgre_New and NxOgre_Delete.
 OGRE3DRigidBodyPrototype* prototype = NxOgre_New(OGRE3DRigidBodyPrototype)();
 
 if (prototype->mSceneManager == 0)
  prototype->mSceneManager = mSceneManager;
 
 // Send the physics stuff from the description into the prototype. This is quite important.
 NxOgre::Functions::PrototypeFunctions::RigidBodyDescriptionToRigidBodyPrototype(description, prototype);
 
 // We want a dynamic rigid body, that jumps around in the fjords with other dynamic rigid bodies.
 prototype->mType = NxOgre::Enums::RigidBodyType_Dynamic;

 // Copy the position over to the prototype.
 prototype->mGlobalPose.identity();
 prototype->mGlobalPose.set(position);

 // Add the shape to the list of shapes in the prototype.
 prototype->mShapes.insert(shape);

 // And our bits.
 prototype->mMeshName = meshName;

 // Create the body using again the NxOgre_New macro. Passing on the prototype we just created and a copy
 // of the scene pointer. we are using.
 OGRE3DBody* body = NxOgre_New(OGRE3DBody)(prototype, this);

 // Since the OGRE3DBody and NxOgre no longer needs the prototype, and we don't either. It's time to clean up.
 NxOgre_Delete(prototype);

 // Make a local copy.
 mBodies.insert(body);

 // And we are done.
 return body;
}
Ejemplo n.º 9
0
OGRE3DKinematicBody* OGRE3DRenderSystem::createKinematicBody(NxOgre::Shape* shape, NxOgre::Vec3 position, Ogre::SceneNode* node, const NxOgre::RigidBodyDescription& description)
{
	// Create a OGRE3DPrototype using the NxOgre_New macro, all NxOgre classes and classes that
	// use PointerClass should use NxOgre_New and NxOgre_Delete.
	OGRE3DRigidBodyPrototype* prototype = NxOgre_New(OGRE3DRigidBodyPrototype)();

	if (prototype->mSceneManager == 0)
		prototype->mSceneManager = mSceneManager;

	// Send the physics stuff from the description into the prototype. This is quite important.
	NxOgre::Functions::PrototypeFunctions::RigidBodyDescriptionToRigidBodyPrototype(description, prototype);

	// We want a kinematic rigid body, so it can laugh at the other bodies as it defies gravity and ignores conventional forces.
	prototype->mType = NxOgre::Enums::RigidBodyType_Kinematic;

	// Copy the position over to the prototype.
	prototype->mGlobalPose.identity();
	prototype->mGlobalPose.set(position);

	// Add the shape to the list of shapes in the prototype.
	prototype->mShapes.insert(shape);

	// And our bits.
	prototype->mNode=node;

	// Create the body using again the NxOgre_New macro. Passing on the prototype we just created and a copy
	// of the scene pointer. we are using.
	OGRE3DKinematicBody* kinematicBody = NxOgre_New(OGRE3DKinematicBody)(prototype, this);

	// Since the OGRE3DBody and NxOgre no longer needs the prototype, and we don't either. It's time to clean up.
	NxOgre_Delete(prototype);

	// Make a local copy.
	mKinematicBodies.insert(kinematicBody);

	// And we are done.
	return kinematicBody;
}
Ejemplo n.º 10
0
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()); 
}
Ejemplo n.º 11
0
VisualDebugger::VisualDebugger(World* world)
: mWorld(world), mRenderable(0), mMeshData(0)
{
 mMeshData = NxOgre_New(VisualDebuggerMeshData)();
}
Ejemplo n.º 12
0
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));
  }
 }

 
}
Ejemplo n.º 13
0
SoftBody* Scene::createSoftBody(const SoftBodyDescription& description, Renderable* renderable, Enums::Priority rp)
{
    SoftBody* cloth = NxOgre_New(SoftBody)(description, renderable, rp, this);
    mSoftBodies.insert(cloth);
    return cloth;
}
Ejemplo n.º 14
0
Cloth* Scene::createCloth(const ClothDescription& description, Renderable* renderable, Enums::Priority rp)
{
    Cloth* cloth = NxOgre_New(Cloth)(description, renderable, rp, this);
    mCloths.insert(cloth);
    return cloth;
}
Ejemplo n.º 15
0
KinematicController* Scene::createKinematicController(const Vec3& size, const Vec3& globalPosition)
{
    KinematicController* controller = NxOgre_New(KinematicController)(size, globalPosition, this);
    mKinematicControllers.insert(controller);
    return controller;
}
Ejemplo n.º 16
0
Material* Scene::createMaterial(MaterialPrototype* prototype)
{
    Material* material = NxOgre_New(Material)(prototype, this);
    mMaterials.insert(material);
    return material;
}