Can I still use Ogre::Root and Ogre::SceneManager objects.

jeremywilms

27-11-2009 04:22:22

Can I still use Ogre::Root and Ogre::SceneManager objects with NxOgre? I'd rather not rewrite a lot of what is written to use NxOgre::World and NxOgre::Scene. Are there any other ways of using the physics wrapper? I.e creating a world and adding existing Ogre::SceneManagers' and Ogre::SceneNodes' to it?

edit


Just looked at the FAQ
Q: Do I have to use the NxOgre Rendersystems with my application/game/library/pony?
A: No, at all. You can write your own. Treat the RenderSystem nearest to what as a guideline
when you implement you own.


Can someone direct me to some resources explaining how to use the Ogre3D RenderSystem with NxOgre? How would NxOgre notify me about translations and rotations of a given SceneNode when is has collided with an object, etc? Forgive my if these are poor questions, I'm having a hard time understanding how NxOgre works, I am still fairly new to Ogre, and during this week haven't had much time to look at NxOgre in-depth.

What I'm trying to do is create a singleton, cPhysicsManager, that handles all the physics in my game engine. All my game objects are created with the class cGameobject(or atleast have classes the inherit from this object), which inherits from cPhysicsObject, and in that classes constructor it notifies the cPhysicsManager about it's mass, weight, etc, and that it was created, providing any other information it may need. Then cPhysicsManager handles all the physics(collision, etc..) from there, where the cPhysicsObject doesn't have to worry about anything, just registering and unregistered(when destructed) with the cPhysicsManager singleton. I really don't want the rest of my project to be influenced by the Physics Engine. I wrote a nice wrapper around Ogre, and rewriting it, so it uses NxOgre's render system would be a pain and inconvenient to me, as I didn't plan to have the Rendering engine and the physics engine all in one.

Druha

27-11-2009 06:57:29

You are misunderstanding the way PhysX and NxOgre works. NxOgre handles only physics. The way you want to show such calculations is determined only by you fantasy. NxOgre Rendersystem is just an example how it can be done, not how it must be done.
In theory, for every physic object in your scene you need to create a Rigid Body, and then get it position/orientation every frame and place something (entity/particle system/billboard/whatever you like) there to show your object.
And of course you can still use all of Ogre related objects, cause Ogre and NxOgre are completely independent. (I am using NxOgre in standalone server app)

betajaen

27-11-2009 09:59:17

What Druha said.

The OGRE3DRenderSystem is merely an example on how it could be done with Ogre, people use OGRE3DRenderSystem because it's convenient. If you want to use your own system - that's fine.

jeremywilms

27-11-2009 15:04:33

What Druha said.

The OGRE3DRenderSystem is merely an example on how it could be done with Ogre, people use OGRE3DRenderSystem because it's convenient. If you want to use your own system - that's fine.


Ah, I understand. I had a feeling this was the case, I just wanted to make sure. Is there an API reference I can reffer to?

Thanks for your help.

betajaen

27-11-2009 16:06:56

For Cloth/SoftBodies/Fluids/VisualDebugger, Yes. There is a specific API you should follow, it's demonstrated quite well in the OGRE3DRenderSystem, see "Renderable". I have no problem people copying and pasting that code into their own - if it's too complicated for them to understand, but if you just want to use RigidBodies, then you don't need to implement it.

For RigidBodies, Actors/KinematicActors/StaticGeometries. Up to you. Basically it boils down to you choosing to inherit from these or making them a member variable and wrapping them, both styles have merits. To draw them you just update the position of the scenenode every frame from getPosition()/getOrientation() from the Actor/KinematicActor. The OGRE3DRenderSystem uses the inheriting role, which again demonstrated quite well.

jeremywilms

27-11-2009 22:59:28

Sorry if I'm being difficult to work with here.

What I mean is, can I still use Ogre3D, and not use the Nx RenderSystem, or create my own. Using just the Ogre libraries that came in the OgreSDK for rendering?

Not sure if you read it or not, but currently my design plan is(I describe it here). Can I still use this design with NxOgre.

What I'm trying to do is create a singleton, cPhysicsManager, that handles all the physics in my game engine. All my game objects are created with the class cGameobject(or atleast have classes the inherit from this object), which inherits from cPhysicsObject, and in that classes constructor it notifies the cPhysicsManager about it's mass, weight, etc, and that it was created, providing any other information it may need. Then cPhysicsManager handles all the physics(collision, etc..) from there, where the cPhysicsObject doesn't have to worry about anything, just registering and unregistered(when destructed) with the cPhysicsManager singleton. I really don't want the rest of my project to be influenced by the Physics Engine. I wrote a nice wrapper around Ogre, and rewriting it, so it uses NxOgre's render system would be a pain and inconvenient to me, as I didn't plan to have the Rendering engine and the physics engine all in one.

betajaen

27-11-2009 23:16:58

Yes, if you want to.

Like I said; The "OGRE3DRenderSystem" basically boils down to updating the SceneNode of the represented Actor every frame.(mNode->setPosition(getGlobalPosition().as<Ogre::Vector3>()). NxOgre doesn't play favourites. Despite the name, nothing of Ogre is actually referenced in the core code. If you want a really light wrapper that just handles node poses per frame - then okay. If you want a more complicated system that wraps around World/Scene as cPhysicsManager, and Actor's as a member variables of cPhysicsObject classes, you'll have to write the wrapping code yourself, but go for it.

jeremywilms

28-11-2009 16:43:47

Yes, if you want to.

Like I said; The "OGRE3DRenderSystem" basically boils down to updating the SceneNode of the represented Actor every frame.(mNode->setPosition(getGlobalPosition().as<Ogre::Vector3>()). NxOgre doesn't play favourites. Despite the name, nothing of Ogre is actually referenced in the core code. If you want a really light wrapper that just handles node poses per frame - then okay. If you want a more complicated system that wraps around World/Scene as cPhysicsManager, and Actor's as a member variables of cPhysicsObject classes, you'll have to write the wrapping code yourself, but go for it.

edit
Ah I understand now.

Thanks for your help.

betajaen

28-11-2009 18:01:46

That's okay.

If you need any further help with it, keep replying and I'll help you out. It'll also be useful for anyone who is in a similar situation.

jeremywilms

28-11-2009 22:41:37

That's okay.

If you need any further help with it, keep replying and I'll help you out. It'll also be useful for anyone who is in a similar situation.


I'm nearly done the wrapper, I've just run into bit of a linking error:

Here's where I create the actor(not sure if I'm doing it correctly)


cPhysicsActor::cPhysicsActor(NxOgre::Scene* pScene, PhysicsData* pPhysData)
{
m_pScene = pScene;

NxOgre::RigidBodyPrototype* pPrototype = new NxOgre::RigidBodyPrototype();


pPrototype->mShapes.insert(new NxOgre::Box(pPhysData->m_fWidth, pPhysData->m_fHeight, pPhysData->m_fDepth));
pPrototype->mGlobalPose = NxOgre::Vec3(0,0,0);
pPrototype->mMass = pPhysData->m_fMass;
pPrototype->mType = (pPhysData->m_bStatic ? NxOgre::Enums::RigidBodyType_Geometry : NxOgre::Enums::RigidBodyType_Dynamic);

m_pActor = pScene->createActor(pPrototype);
delete pPrototype;
}


However, I get linking errors(I'm linking with NxOgre_Debug.lib), but have left out NxOgreOGRE3D_Debug.lib.

cPhysicsActor.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class NxOgre::Actor * __thiscall NxOgre::Scene::createActor(class NxOgre::RigidBodyPrototype *)" (__imp_?createActor@Scene@NxOgre@@QAEPAVActor@2@PAVRigidBodyPrototype@2@@Z)


Also I'm curious to how I'm supposed to be destroying actors.

Thanks.

Edit


Okay, I looked at NxOgre's source and ended up with something like:

cPhysicsActor::cPhysicsActor(NxOgre::Scene* pScene, PhysicsData* pPhysData)
{
m_pScene = pScene;

NxOgre::Shapes shapesBuffer;
NxOgre::RigidBodyDescription desc = NxOgre::RigidBodyDescription();

shapesBuffer.insert(new NxOgre::Box(pPhysData->m_fWidth, pPhysData->m_fHeight, pPhysData->m_fDepth));

desc.mMass = pPhysData->m_fMass;

if(pPhysData->m_type == PhysObjType_Dynamic)
desc.mType = NxOgre::Enums::RigidBodyType_Dynamic;
else if(pPhysData->m_type == PhysObjType_Kinematic)
desc.mType = NxOgre::Enums::RigidBodyType_Kinematic;
else
cError::CriticalError("Invalid physics actor type.");

m_pActor = pScene->createActor(shapesBuffer, NxOgre::Vec3(0,0,0), desc);
}


I got the physics working(with gravity, and collision(although I'm not sure exactly how collision bounds work)), only I'm not sure how to position shapes in the Actor(and how to get it to cover the contents of a sceneNode.) Also, regardless to what I set RigidBodyDescription::mType to, the actor always acts the same(reacts to gravity)

PhysicsData::m_fWidth hold the width of the entity(along the x axis)
PhysicsData::m_fHeight holds the height(along y)
PhysicsData::m_fDepth hold the depth of the Box(along z)

So I have the members set to the according width, height and depth of the entity, how would I position the shape though so it covers the entity?

betajaen

29-11-2009 10:39:14

1. mType is not for you to change, it will always be changed by Scene.

If you want a different type of RigidBody, then you need to call the appropriate createActor, createStaticGeometry, createKinematicActor function.


2. The local pose in the ShapeBlueprint is to change the offset of the shape in relation to the center of the RigidBody.

jeremywilms

29-11-2009 18:09:43

There, completed the wrapper.

Thank your so much for your help betajaen. Your work is greatly appreciated.