Raycasting and the character class.

jchmack

14-01-2007 19:45:20

i cant get a ray to hit a character model.


Ogre::Ray r = CurrentCamera->getCameraToViewportRay(
float(x / mWindow->getWidth()),
float(y / mWindow->getHeight())
);

mRayCaster->setOrigin(r.getOrigin());
mRayCaster->setDirection(r.getDirection());

if (!mRayCaster->cast())
{
return;
}

MouseTarget->setPosition(mRayCaster->mHitPos);


This code works with everything but the character class objects. The ray just never hits. The MouseTarget node should become the position where the raycaster hit. Any ideas? Im using RC2 and dagon. It's really annoying because my camera is inside my character right now and since the raycaster doesnt return hits on character objects it cant raytrace for my characters projectiles. As a temporary fix i've put my camera a bit forward, but with this fix players can see through walls if they are right by them. Sigh... Thx in advance guys =).

DaCracker

14-01-2007 20:12:37

Use the RayCaster in nxOgre RC3 instead, that should I
think :)

Edit: ops.. didn't notice that you already use the RayCaster,
but it's still recommended that you use RC3.

jchmack

14-01-2007 20:13:36

Use the RayCaster in nxOgre RC3 instead, that should I
think :)


Does RC3 have its own raycaster? or just the ogre raycaster works better with it? Because im waiting for eihort to switch to RC3 so i can port it all at once. Besides from what i understand its complicated to get RC3 with dagon.

betajaen

14-01-2007 20:57:31

Yes, NxOgre has had it's own raycasting system for over a year now.

NxOgre does work with Dagon just a slight code change, it's just the tutorials that won't work with it.

jchmack

14-01-2007 21:06:53

Yes, NxOgre has had it's own raycasting system for over a year now.

NxOgre does work with Dagon just a slight code change, it's just the tutorials that won't work with it.


Ah i see. yeah now that i look at it the raycasting tutorial uses rayCaster. I got the code from the mouseMoveOrGrab(from tutorialapplicationdagon.h) function. Any reason why there you prefer to use an Ogre::Ray instead?

edit: nevermind that function uses the rayCaster object as well. So why doesnt my code's rays collide with character objects? Shouldn't it just set MouseTarget to wherever the ray hit?

DaCracker

14-01-2007 21:23:32



Ah i see. yeah now that i look at it the raycasting tutorial uses rayCaster. I got the code from the mouseMoveOrGrab(from tutorialapplicationdagon.h) function. Any reason why there you prefer to use an Ogre::Ray instead?

edit: nevermind that function uses the rayCaster object as well. So why doesnt my code's rays collide with character objects? Shouldn't it just set MouseTarget to wherever the ray hit?


It might be because RayCaster check for nxOgre::body objects.
The nxOgre::character class inherits the nxOgre::controllable instead
and have no connection to the nxOgre::body class so
the nxOgre::RayCaster class can't "see" nxOgre::character objects.
The Ogre::Ray on the other hand check for Ogre::UserDefinedObject's
(I think) instead and will therefore be able to get the nxOgre::character's
model as a result.

That's my theory :)

jchmack

14-01-2007 21:26:44



Ah i see. yeah now that i look at it the raycasting tutorial uses rayCaster. I got the code from the mouseMoveOrGrab(from tutorialapplicationdagon.h) function. Any reason why there you prefer to use an Ogre::Ray instead?

edit: nevermind that function uses the rayCaster object as well. So why doesnt my code's rays collide with character objects? Shouldn't it just set MouseTarget to wherever the ray hit?


It might be because RayCaster check for nxOgre::body objects.
The nxOgre::character class inherits the nxOgre::controllable instead
and have no connection to the nxOgre::body class so
the nxOgre::RayCaster class can't "see" nxOgre::character objects.
The Ogre::Ray on the other hand check for Ogre::UserDefinedObject's
(I think) instead and will therefore be able to get the nxOgre::character's
model as a result.

That's my theory :)


Hmm sounds about right. But wouldn't the nxOgre Ray just cast past the controlable object then? Then return whatever was past the character? Whenever it hits the capsule (my character objects are shaped as capsules) it doesn't return a hit at all.

betajaen

14-01-2007 22:42:49

Well if it doesn't hit the characters, it'll pass through like it's not there. There are ways around it though.

Oh, PhysX raycasting are far more accurate than Ogre's (which correct me if I'm wrong, only goes down to the bounding box).

jchmack

15-01-2007 09:19:21

I don't think u guys are seeing what i mean. put mouse mode on pick and create a character and a sphere. Right click on the sphere to make it the active target. Now left click on the character and nothing...(for me at least). The force is never added because the raycaster fails to cast or something. It may be in the way i create my character though. But im pretty certain it pretty much follows tutorial606.


void gamecharacter::Create(scene *mScene , Viewport* mViewport)
{
name+=Ogre::StringConverter::toString(objectcount);
objectcount++;

blueprint<character> bp;
bp.setToDefault();
bp.setGravity(false);
bp.setSlopeLimit(45);
bp.setStep(0.3);
bp.setShapeAsCapsule(CharacterRadius,CharacterHeight);
bp.setMesh("");

mPlayer = bp.create(name,InitialPosition,mScene);

MeshNode = mPlayer->mNode->createChildSceneNode(name+" Mesh Node");
MeshEntity = mScene->mSceneMgr->createEntity(name+" Entity",mesh);
MeshNode->translate(Vector3(0,-((CharacterHeight/2)+CharacterRadius),0));
MeshNode->scale( Vector3(1,1,1)*NinjaMeshConverter*(CharacterHeight+2*(CharacterRadius)));
MeshNode->attachObject(MeshEntity);

CharacterCamera = mScene->mSceneMgr->createCamera(name+" Camera");
CharacterCamera->setNearClipDistance(0.1);
CharacterCamera->setAspectRatio(Real(mViewport->getActualWidth()) / Real(mViewport->getActualHeight()));
CharacterCamera->moveRelative(Vector3(0,.1,-CharacterRadius));

mPlayer->mNode->attachObject(CharacterCamera);

GunNode = mPlayer->mNode->createChildSceneNode(name+" Gun Node");
GunNode->translate(Vector3(0,0,-CharacterRadius));
}

betajaen

15-01-2007 11:08:16

No, we do know what you mean. The PhysX raycaster doesn't "see" the character.

But there are ways around it; raycasting in a FXScene, or even using the Ogre Raycaster for characters.