[SOLVED] NxOgre::Raycaster bloodymess ?

deshan

04-11-2009 07:17:36

Hi all
The NxOgre::Raycaster is no longer in bloodymess. So how we can get the NxOgre::Actor that hit the ray? We can get the mDistance using NxOgre::RaycastHit but how to get the actor without having NxOgre::Raycaster?

spacegaier

04-11-2009 10:57:49


NxOgre::RaycastHit hit = mScene->raycastClosestShape(m_pRay, NxOgre::Enums::ShapesType_Dynamic);
if(hit.mRigidBody)
{
if(hit.mRigidBody->getClassType() == NxOgre::Classes::_Actor || hit.mRigidBody->getClassType() == ::_OGRE3DBody)
{
NxOgre::Actor* a = static_cast<NxOgre::Actor*>(hit.mRigidBody);
}
}

deshan

04-11-2009 16:12:27

Thank You spacegaier,
That works fine!!!
Thanx again.

One more request. If you have some time please put this code in wiki. Really saying that people out their will get a huge benefit.

spacegaier

04-11-2009 21:30:29

Yes, I've already started the tutorial about Raycasting. But haven't finished yet. Perhaps, I should just put the running stab in the wiki as a first draft.

Currently in my exam phase, so not enough time to finish it in the next weeks :( .

ahtm80

13-03-2010 16:57:53

Thanks it is work.
But too change camera direction, not stable working. My Codes that:
NxOgre::Vec3 RayPosition = mCamera->getPosition();
NxOgre::Vec3 RayDirection = mCamera->getDirection();
NxOgre::Ray XRay(RayPosition,RayDirection);
NxOgre::RaycastHit HitResult = PScene->raycastClosestShape(XRay,NxOgre::Enums::ShapesType_Dynamic);
if(HitResult.mRigidBody)
{
if(HitResult.mRigidBody->getClassType() == ::_OGRE3DBody)
{
guiDbg->setCaption("Hit");
}
}

Help pls. I wait for our answers.

deshan

14-03-2010 15:52:54

Try
mCamera->_getDerivedOrientation() * Ogre::Vector3(0, 0, -1);

ahtm80

16-03-2010 18:17:54

:( Same. Dont change. dont stable working. Look pls. that code in framelistener. It true?
NxOgre::Vec3 RayPosition = mCamera->getPosition();
NxOgre::Vec3 RayDirection = mCamera->getDerivedOrientation() * Ogre::Vector3(0,0,-1);//mCamera->getDirection();
NxOgre::Ray XRay(RayPosition,RayDirection);
NxOgre::RaycastHit HitResult = PScene->raycastClosestShape(XRay,NxOgre::Enums::ShapesType_Dynamic);
if(HitResult.mRigidBody)
{
if(HitResult.mRigidBody->getClassType() == ::_OGRE3DBody)
{
OverlayElement* guiDbg = OverlayManager::getSingleton().getOverlayElement("Core/DebugText");
guiDbg->setCaption("Hit");
}
}

deshan

17-03-2010 11:34:29

It is mCamera->getparentsceneNode()->_getDerivedOrientation() not mCamera->getDerivedOrientation()
And I think you have to set the world position of camera in RayPosition (get the derived position of the scenenode)
camera->getparentsceneNode()->_getDerivedPosition()

ahtm80

29-03-2010 15:39:27

i still dont work :D
i testing many method. But dont stable working. My codes:
//***************************************************************************************************************************************************************************
#include "ExampleApplication.h"
#include <NxOgre.h>
#include <NxOgreOGRE3D.h>

SceneNode* CamNode;
NxOgre::Scene* PhysicsScene;
//***************************************************************************************************************************************************************************
class PhysicsListener : public ExampleFrameListener
{
protected:
NxOgre::TimeController* pTimeController;
public:
PhysicsListener(RenderWindow* Win,Camera* Cam) : ExampleFrameListener(Win,Cam)
{
pTimeController = NxOgre::TimeController::getSingleton();
}

bool frameStarted(const FrameEvent& evt)
{
pTimeController->advance(evt.timeSinceLastFrame);
return ExampleFrameListener::frameStarted(evt);
}
};
//***************************************************************************************************************************************************************************
class HitListener : public ExampleFrameListener
{
protected:
OGRE3DRenderSystem* frameRenderSystem;
OGRE3DBody* mCube;

public:
HitListener(RenderWindow* Win,Camera* Cam,OGRE3DRenderSystem* getRenderSys) : ExampleFrameListener(Win,Cam,false,false),frameRenderSystem(getRenderSys)
{
}

bool frameStarted(const FrameEvent &evt)
{
CamNode->setPosition(mCamera->getPosition());
CamNode->getParentSceneNode()->_getDerivedPosition();
NxOgre::Ray XRay(CamNode->getPosition(),mCamera->getDirection());
NxOgre::RaycastHit HitResult = PhysicsScene->raycastClosestShape(XRay,NxOgre::Enums::ShapesType_Dynamic);
if(HitResult.mRigidBody)
{
if(HitResult.mRigidBody->getClassType() == ::_OGRE3DBody)
{
OverlayElement* guiDbg = OverlayManager::getSingleton().getOverlayElement("Core/DebugText");
guiDbg->setCaption("HIT");
}
}



if(mKeyboard->isKeyDown(OIS::KC_SPACE) && mTimeUntilNextToggle <= 0)
{
// Create a new Cube and apply some force to it
mCube = frameRenderSystem->createBody(new NxOgre::Box(40), NxOgre::Vec3(mCamera->getPosition().x,
mCamera->getPosition().y, mCamera->getPosition().z), "Kutu.mesh");
mCube->addForce(NxOgre::Vec3(mCamera->getDirection().x * 100000, mCamera->getDirection().y * 100000,
mCamera->getDirection().z * 100000), NxOgre::Enums::ForceMode_Force, true);
mTimeUntilNextToggle = 0.2;
}

return ExampleFrameListener::frameStarted(evt);
}
};
//***************************************************************************************************************************************************************************
class myApp : public ExampleApplication
{
protected:
NxOgre::World* PhysicsWorld;

OGRE3DRenderSystem* PhysicsRenderSystem;
private:
inline void InitializePhysics(void)
{
PhysicsWorld = NxOgre::World::createWorld();
NxOgre::SceneDescription sceneDesc;
sceneDesc.mGravity = NxOgre::Vec3(0.0f,-9.8f,0.0f);
PhysicsScene = PhysicsWorld->createScene(sceneDesc);
PhysicsScene->getMaterial(0)->setStaticFriction(0.5);
PhysicsScene->getMaterial(0)->setDynamicFriction(0.5);
PhysicsScene->getMaterial(0)->setRestitution(0.1);
PhysicsRenderSystem = new OGRE3DRenderSystem(PhysicsScene);
}

void CreateLight(const Ogre::String LightName,Vector3 LightPosition)
{
Light* TopLight = mSceneMgr->createLight(LightName);
TopLight->setType(Light::LT_POINT);
TopLight->setPosition(LightPosition);
TopLight->setDiffuseColour(1.0f,1.0f,1.0f);
TopLight->setSpecularColour(1.0f,1.0f,1.0f);
}
public:
myApp()
{
}

~myApp()
{
}
protected:
void createScene(void)
{
InitializePhysics();
mSceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE);
mSceneMgr->setAmbientLight(ColourValue(0.3f,0.3f,0.3f));
CreateLight("Light01",Vector3(50,200,50));

CamNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("Cam01");
CamNode->attachObject(mCamera);

for(int CounterH = 1;CounterH < 5;CounterH++)
{
for(int CounterL = 0;CounterL < 5;CounterL++)
{
OGRE3DBody* mCube = PhysicsRenderSystem->createBody(new NxOgre::Box(40),NxOgre::Vec3(CounterL * 40,CounterH * 40,0),"Kutu.mesh");
}
}

PhysicsScene->createSceneGeometry(new NxOgre::PlaneGeometry(0,NxOgre::Vec3(0,1,0)),Matrix44_Identity);
Plane plane(Vector3::UNIT_Y,0);
MeshManager::getSingleton().createPlane("ground",ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,plane,1500,1500,20,20,true,1,5,5,Vector3::UNIT_Z);
Entity* GrountEnt = mSceneMgr->createEntity("GroundEntity", "ground");
mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(GrountEnt);
GrountEnt->setMaterialName("Examples/Rockwall");
GrountEnt->setCastShadows(false);

SceneNode* IndGeneralScreenNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("IndicatorScreenNode");
MaterialPtr IndMatTarget = MaterialManager::getSingleton().create("IndTarget","General");
InitializeMat(IndMatTarget,"Target.png");
Rectangle2D *GeneralBox = new Ogre::Rectangle2D(true);
GeneralBox->setCorners(-0.02f,0.03f,0.03f,-0.02f);
GeneralBox->setBoundingBox(AxisAlignedBox(-100000.0 * Vector3::UNIT_SCALE,100000.0 * Vector3::UNIT_SCALE));
GeneralBox->setMaterial("IndTarget");
IndGeneralScreenNode->attachObject(GeneralBox);
}

void InitializeMat(MaterialPtr IndicatorMaterial,const Ogre::String TextureName)
{
IndicatorMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(TextureName);
IndicatorMaterial->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
IndicatorMaterial->getTechnique(0)->getPass(0)->setLightingEnabled(false);
IndicatorMaterial->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SceneBlendType::SBT_TRANSPARENT_ALPHA);
}

void createCamera(void)
{
mCamera = mSceneMgr->createCamera("PlayerCam");
mCamera->setNearClipDistance(5);
mCamera->setPosition(Vector3(0,30,200));
}

void createFrameListener(void)
{
mFrameListener = new PhysicsListener(mWindow,mCamera);
mRoot->addFrameListener(mFrameListener);
mFrameListener = new HitListener(mWindow,mCamera,PhysicsRenderSystem);
mRoot->addFrameListener(mFrameListener);
mFrameListener->showDebugOverlay(true);
}
};
//***************************************************************************************************************************************************************************
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#define WIN32_LEAN_AND_MEAN
#include "windows.h"

INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main(int argc, char **argv)
#endif
{
myApp app;
try {
app.go();
} catch( Exception& e ) {
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
MessageBox( NULL, e.what(), "An exception has occurred!", MB_OK | MB_ICONERROR | MB_TASKMODAL);
#else
fprintf(stderr, "An exception has occurred: %s\n",e.what());
#endif
}
return 0;
}
//***************************************************************************************************************************************************************************


Please review my codes. Dont stable working. Look screenshot. i add. i look front box. it work. But look behind dont working. Pls help.
Sorry my bad english.

ahtm80

02-04-2010 20:25:40

will not help anyone? help me pls.

deshan

03-04-2010 09:21:44

Ogre::Vector3 castDirection = mCamera->getParentSceneNode()->_getDerivedOrientation() * Ogre::Vector3(0, 0, -1);
NxOgre::Vec3 castPosition(mCamera->getParentSceneNode()->_getDerivedPosition());

NxOgre::RaycastHit hit = mScene->raycastClosestShape(NxOgre::Ray(castPosition,castDirection) ,NxOgre::Enums::ShapesType_Dynamic);

if(hit.mRigidBody)
if(hit.mRigidBody->getClassType() == NxOgre::Classes::_Actor || hit.mRigidBody->getClassType() == ::_OGRE3DBody)
{
// your code goes here
}


should work as i know.
If the camera is attahced to a ogre3dbody make sure to adjust castPosition to avoid the hitting of your own body.
castPosition.z - some value

ahtm80

03-04-2010 17:19:41

deshan Did you try? i dont work. not work at all this codes. Please help. necessary for my homework. :cry:

deshan

03-04-2010 18:04:34

Of Couse I tried. What is your error.

ahtm80

04-04-2010 09:49:17

that error:
getParentSceneNode with use camera, never not to happen hit. Use the following codes working. But dont stable working. Just box's front face working. Other face dont hit. Camera create function problem? Pls help.
void createCamera(void)
{
mCamera = mSceneMgr->createCamera("PlayerCam");
mCamera->setNearClipDistance(5);
mCamera->setPosition(Vector3(0,30,200));

CamNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("Cam01");
CamNode->attachObject(mCamera);
}

NxOgre::Ray XRay(mCamera->getPosition(),mCamera->getDirection());
NxOgre::RaycastHit HitResult = PhysicsScene->raycastClosestShape(XRay,NxOgre::Enums::ShapesType_Dynamic);
if(HitResult.mRigidBody)
{
if(HitResult.mRigidBody->getClassType() == ::_OGRE3DBody)
{
OverlayElement* guiDbg = OverlayManager::getSingleton().getOverlayElement("Core/DebugText");
guiDbg->setCaption("HIT");
}
}

and thanks you deshan for be interested in.i wait for answer.

Illidanz

06-04-2010 15:39:26

There's no need to get the parent scene node, you can use these methods on the camera directly (without the "_")

So, try to change the first line of that code in:
NxOgre::Ray XRay(mCamera->getDerivedPosition(),mCamera->getDerivedDirection());
and let us know if that works

ahtm80

06-04-2010 20:04:55

:( didnt working again. front surface hit. but box's back surface dont hit ray. i go crazy. i use nxogre 1.6 and ogre 1.6.5. Please help me. İ upload working folder. mesh end textures. Look pls. I wait for our answers. :(

ahtm80

12-04-2010 11:00:54

I to try all methods. i suppose bug on raycaster. Please fix this bug.

anjanikumar

21-05-2010 09:25:19

pls help yaar anybody

My topic is making one application in nxogre ,
in this one target is on the plane and hit by mouse and if hit is on the target then one entity will attach that position
for identify where the mouse ray is hit.....................

ahtm80

27-05-2010 12:30:54

nothing effort.
Bug nxogre raycasting. Go use bullet or newton. Or other game engines.

deshan

27-05-2010 17:44:24

Almsot replied to anjanikumar's pm.
@ahtm80
What bug you found?
NxOgre raycast works fine for me and many other.