[Help]Any idea how to do this

tomneo2000

25-09-2009 14:25:07

Ok i know "UserData" is not suppose to touch if useing NxOgre (will crash program), so is there any way that i can assign my class instance to an Actor?
I use Git version

for example:

class myclass
{
public:
int count;
myclass()
{
count=0;
}
};

If i can i assign this class's instance to an actor then i can retrieve the this class's instance from that actor to do some modify like change count to any number i want.


An other question is that can i cast rigid body to Actor?

betajaen

25-09-2009 15:02:33

PLEASE STOP MAKING POST AFTER POST. JUST REPLY TO YOUR OLD POSTS.

No, you can't attach anything from Actor/Body, unless you inherit from those classes, then when you need something specific to your class, you cast it.

class MyBody : public OGRE3DBody
{
MyBody(int mydata, OGRE3DRigidBodyPrototype* prototype, OGRE3DRenderSystem* rendersystem)
: OGRE3DBody(prototype, rendersystem), myData(mydata)
{
/// my code here.
};
~MyBody()
{
}

int myData;
};


You will need to new/delete MyBody yourself and store copies of the pointer in a vector or map. NxOgre will treat MyBody as an Actor internally (as MyClass inherits from Body, which inherits from Actor, which inherits from RigidBody).

Actors are RigidBodies so yes.

tomneo2000

26-09-2009 06:02:53

PLEASE STOP MAKING POST AFTER POST. JUST REPLY TO YOUR OLD POSTS.

No, you can't attach anything from Actor/Body, unless you inherit from those classes, then when you need something specific to your class, you cast it.

class MyBody : public OGRE3DBody
{
MyBody(int mydata, OGRE3DRigidBodyPrototype* prototype, OGRE3DRenderSystem* rendersystem)
: OGRE3DBody(prototype, rendersystem), myData(mydata)
{
/// my code here.
};
~MyBody()
{
}

int myData;
};


You will need to new/delete MyBody yourself and store copies of the pointer in a vector or map. NxOgre will treat MyBody as an Actor internally (as MyClass inherits from Body, which inherits from Actor, which inherits from RigidBody).

Actors are RigidBodies so yes.


ok do you mean like this:

//first i declare a MyBodyList
std::list<MyBody*> MyBodyList;

//so now i can create many bodies i want
MyBodyList.push_back(new MyBody(int mydata, OGRE3DRigidBodyPrototype* prototype, OGRE3DRenderSystem* rendersystem));


But if there is a collision happen

void onContact(const NxOgre::ContactPair& pair)
{
}

the pair.mFirst and pair.mSecond are still type of rigid body, can i retrieve myData?

betajaen

26-09-2009 09:27:11

Cast it into your MyBody.

tomneo2000

27-09-2009 05:08:07

"OGRE3DRigidBodyPrototype* prototype"
If i make a instance of prototype, for example, "new OGRE3DRigidBodyPrototype();". What attributes should i give value? For instance, prototype->mName="ABC";
I read "createBody()" method in OGRE3DRenderSystem.cpp, seems it need to setup by myself.

I have made my own class and inherit from OGRE3DBody and here is my code:

In header file

#include <NxOgre.h>
#include <NxOgreOGRE3D.h>

class MyBody:public OGRE3DBody
{
public:

MyBody(OGRE3DRigidBodyPrototype* prototype, OGRE3DRenderSystem* renderSystem, void* userData=0);
~MyBody();
protected:

OGRE3DRigidBodyPrototype* mPrototype;
OGRE3DRenderSystem* mRenderSystem;
NxOgre::RigidBodyDescription mDescription;

public:

void* mUserData;
};


In cpp file

#include "MyBody.h"

MyBody::MyBody(OGRE3DRigidBodyPrototype* prototype, OGRE3DRenderSystem* renderSystem, void* userData)
:OGRE3DBody(prototype, renderSystem)
{
MyBody::mPrototype=prototype;
MyBody::mRenderSystem=renderSystem;
MyBody::mUserData=userData;
}

MyBody::~MyBody()
{

}


In the beginning, i run the program i got this error(Sometime it occur).
Here is the information from CallStack: msvcr80d.dll!_CrtIsValidHeapPointer(const void * pUserData=0x0520f028) Line 2072 C++



Every time i press ESC to exit from program i got this error(Always occur)
Here is the information from CallStack: msvcr80d.dll!_output_l(_iobuf * stream=0x00681d60, const char * format=0x007a40c0, localeinfo_struct * plocinfo=0x00000000, char * argptr=0x0012f99c) Line 1648 + 0x1f bytesC++



Actually. i have no idea how to debug with this situation.

tomneo2000

28-09-2009 02:42:01

Any one have same problem?

tomneo2000

28-09-2009 06:11:56

I have a problem about raycast. I am not sure i am doing the correct way or wrong way, but my raycast is really strange.

Here is my code:

First, i create a ray and i give it a distance which is 70 unit on Y axis

NxOgre::Ray myray(NxOgre::Vec3(0,30,0), NxOgre::Vec3(0,1,0));
myray.mDirection.distance(NxOgre::Vec3(0, 70, 0));
myray.mDirection.normalise();
mScene->raycastAllBounds(myray, mycb, NxOgre::Enums::ShapesType_Dynamic);


Second, in my callback class i implement function "onHitEvent"

class mycallback: public NxOgre::Callback
{
public:
std::list<OGRE3DBody*>* robotlist;
std::list<OGRE3DBody*>* barrellist;
OGRE3DRenderSystem* mRS;
NxOgre::Mesh* robotmesh;
NxOgre::Scene* mScene;
Ogre::SceneManager* mSceneMgr;
bool created;

mycallback(std::list<OGRE3DBody*>* rl, std::list<OGRE3DBody*>* bl, OGRE3DRenderSystem* rs, NxOgre::Mesh* rbmesh, NxOgre::Scene* sn, Ogre::SceneManager* osm)
{
robotlist=rl;
barrellist=bl;
mRS=rs;
robotmesh=rbmesh;
mScene=sn;
mSceneMgr=osm;
created=false;
}

bool onHitEvent(const NxOgre::RaycastHit& rh)
{
Ogre::ManualObject* mo=mSceneMgr->createManualObject("manualobject");
mo->begin("raycastmaterial", RenderOperation::OT_LINE_LIST);
mo->estimateVertexCount(2);

mo->position(0, 30, 0);
mo->position(rh.mWorldImpact.x, rh.mWorldImpact.y, rh.mWorldImpact.z);

mo->end();
mSceneMgr->getRootSceneNode()->createChildSceneNode("ray")->attachObject(mo);
return true;
}
}


The problem is that when i do this rh.mRigidBody i got error because mRigidBody pointer is 0XCCCCCC, i don't know why, but i am sure my ray hit a body. I thought if my ray hit a body then i am suppose to retrieve a rigid body from a body, desn't it?
Another problem is my ray is too long like a infinite line, but i did limit it's distance, didn't i?

In the picture you can see a white line and it is very very long even longer than 70 units, but i did limit it. How come my raycast don't change length ?