OGRE3DBody Mask

VileMK3

11-11-2009 18:35:20

Hey everyone,

I have encountered a small problem. In the game me and my team are developping for school we have two kinds of items that need to be manipulated in game, those added and dropped from yoru inventory and those directly used (levers or small objects that are knocked away).
Our game is physics heavy so I decided to try the following approach to see if an item is an item to be "manipulated" or to be "picked up":


NxOgre::ResourceSystem::getSingleton()->openArchive("Nxs", "file:C:/Data/DAE/Misc/Ogre_Projects/Fascinated/Fascinated/res/Nxs");
NxOgre::Mesh* convexMesh = NxOgre::MeshManager::getSingleton()->load("Nxs:EluminusCol.nxs");
NxOgre::Convex* convex = new NxOgre::Convex(convexMesh);
OGRE3DBody* convexBody = m_RenderSystem->createBody(convex, NxOgre::Vec3(200, 450, 100), "Eluminus.mesh");
convexBody->setGlobalOrientation(NxOgre::Matrix33(NxOgre::Real4(0, 45, 0, 45)));

ManipItem* item = static_cast<ManipItem*>(convexBody);
item->SetItemType("ManipItem");

item = static_cast<ManipItem*>(convexBody);
Ogre::String type = item->GetItemType();


This is basically a test code, so I just make an OGRE3DBody object as normal, naturally I get an access violation when trying to set the itemtype after casting it. (Item inherits from OGRE3DBody)
This is probably not the best way to try and do this so my question is:
How do I fix the problem with my code and is there some way to include masks into Ogre3DBody (or does it already have them) or is there some other way to get some information from an OGRE3DBody?
(Like userData in DirectX)

Thanks in advance ^^

betajaen

11-11-2009 18:55:11

You really can't cast like that in C++. Although ManipItem is a OGRE3DBody, convexBody is not - it's a OGRE3DBody.

What you should do is create the ManipItem directly via a nice createManiItem function. Something like this;

ManipItem* mySceneClass::createManipItem(NxOgre::Shape* shape, const NxOgre::Matrix44& pose, OGRE3DRigidBodyDescription& description, const std::string& meshName)
{

description.mNode = mSceneManager->getRootSceneNode()->createChildSceneNode(NxOgre::Vec3(pose).as<Ogre::Vector3>(), NxOgre::Quat(pose).as<Ogre::Quaternion>());
if (meshName.length())
description.mNode->attachObject(mSceneManager->createEntity(getUniqueName("entity"), meshName));

ManipItem* item = new ManipItem(shape, global_pose, description, m_RenderSystem);
m_Items.push_back(item);
return item;
}


Then your constructor for ManipItem may look a bit like this (with your bits added - of course).

ManipItem::ManipItem(NxOgre::Shape* shape, const NxOgre::Matrix44& global_pose, OGRE3DRigidBodyDescription& description, OGRE3DRenderSystem* renderSystem)
: OGRE3DBody(shape, global_pose, description, renderSystem)
{
// Your bits here.
}


Then with the code you posted above and the new functions;

NxOgre::ResourceSystem::getSingleton()->openArchive("Nxs", "file:C:/Data/DAE/Misc/Ogre_Projects/Fascinated/Fascinated/res/Nxs");
NxOgre::Mesh* convexMesh = NxOgre::MeshManager::getSingleton()->load("Nxs:EluminusCol.nxs");
NxOgre::Convex* convex = new NxOgre::Convex(convexMesh);
createManipItem* item = createManipItem(convex, NxOgre(Matrix44::NxOgre::Vec3(200, 450, 100), NxOgre::Quat(1, 0, 0, 0)) , "Eluminus.mesh");

item->SetItemType("ManipItem");
Ogre::String type = item->GetItemType();



Hope that helps. :)

p.s. Your quaternion is very wrong.

VileMK3

11-11-2009 19:05:13

Ah I see, this is what createBody does basically?
I was a little confused since I thought you HAD to create the OGRE3DBody via the rendersystem to "add" it to the scene.

Thanks for the help, this should do nicely ^^

betajaen

11-11-2009 22:16:14

Basically, yeah.

NxOgre doesn't know about Ogre; it doesn't import headers or libraries, so including a reference to Ogre it wouldn't work. It wouldn't be fair on OpenGL, or any other 3D/2D library that can be used with NxOgre because I would be favouring them over Ogre, which is why it's placed in the OGRE3DRenderSystem. I suppose a better name would be OGRE3DRenderScene, but it doesn't do all the jobs a scene does, unlike a OGRE3DBody and an Actor. Oh well.

VileMK3

11-11-2009 23:54:46

*nods * I see, either way, nice work on NxOgre, it works like a charm (if only the people who use it were as clever *points at self* lol)

I've got one small issue now though, I can't seem to find OGRE3DRigidBodyDescription anywhere so I tried using OGRE3DRigidBodyPrototype, using this makes the code work and the mesh is rendered but it's no longer updated with the TimeController each tick and my raycast doesn't add it to it's results anymore so I'm guessing using prototype isn't advisable. I've looked through NxOgre, etc but can't seem to find the RigidBodyDescription... (I am using the latest NxOgre version where the visual debugger isn't supported anymore for example, if that's important?)

betajaen

11-11-2009 23:57:10

I was looking at the Detritus code when I wrote that.

You should upgrade to the Git version of NxOgre (the master branch), the Visual debugger works and everything is nice and fast. The OGRERigidBodyDescription should be in there, otherwise substitute for a pointered OGRE3DRigidBodyPrototype. Almost the same really.

VileMK3

12-11-2009 10:30:01

Okay I switched over to Git, thanks for the help :)

VileMK3

12-11-2009 10:41:08

Though we're going wildly off topic from the mask question now lol, I've just encounted an error I've never seen before:
Entry Point Not Found
The procedure entry point ?set@Matrix44@NxOgre@@QAEXABVVec3@2@@Z could not be located in the dynamic link library NxOgre_Debug.dll.

Any idea what could be causing this? Git compiled properly and I followed the steps in the README file it outputs and my program compiles correctly too.

betajaen

12-11-2009 13:52:32

Sounds like your program is using the old DLL.

Make sure your program has been recompiled with the new GIT code, just in case, and copy the NxOgre.dll/NxOgre_Debug.dll from the sdk directory into your applications.

VileMK3

12-11-2009 14:41:18

That did the trick, though I had to try it a couple of times strangely enough...

Though I still can't find OGRE3DRigidBodyDescription... I'll try to get prototype working than.
The only real problem I still have is: how do I get the info out of the result of a raycast? I thought perhaps checking the result of the raycast against all items in the itemvector to see if it is an item that can be used and I do this by comparing their NxActors. Is this a good approach?