Simple Mouse Click Raycast

bertheimer

09-06-2010 17:52:29

Hi all
1) i have a big problem, ok ...for me but hopefully not for you guys. I'm new to the NxOgre stuff and I have been walking around the Internet to find out how to create a simple Raycast by clicking into the Scene, selecting 1 Actor and change the Position of it. But i didnt succeed. I work with CEGUI and this was my last try:



CEGUI::Point mousePos = CEGUI::MouseCursor::getSingleton().getPosition();
NxOgre::Ray mouseRay2=mCamera->getCameraToViewportRay(mousePos.d_x/float(arg.state.width), mousePos.d_y/float(arg.state.height));
NxOgre::RaycastHit HitResult = mRenderSystem->getScene()->raycastClosestShape(mouseRay2,NxOgre::Enums::ShapesType_Dynamic);
if(HitResult.mRigidBody)
{
if(HitResult.mRigidBody->getClassType() == ::_OGRE3DBody)
{
//changePosition
}
}


Unfortunatly he is throwing me some errors. One is that "mCamera" has the Namespace of Ogre. But i didnt find out how to convert it into NxOgre.
Perhaps you have a better solution.

2) One further concern... I was just wondering if there is any physic editor with which i can create complex physic models by placing physic models manually unlike with Four. And afterwards i can export the model into nxs files.

Thank you
greetings from Germany :D

bertheimer

10-06-2010 10:07:52

Finally i ve solved my problem after one additional workaround. So for those who are facing the same newbe problem:



Real x = (CEGUI::MouseCursor::getSingleton().getPosition().d_x / mWindow->getWidth());
Real y = (CEGUI::MouseCursor::getSingleton().getPosition().d_y / mWindow->getHeight());
Ray mouseRay = mCamera->getCameraToViewportRay(x, y);
NxOgre::Ray test(mouseRay.getOrigin(),mouseRay.getDirection());
NxOgre::RaycastHit HitResult = mRenderSystem->getScene()->raycastClosestShape(test,NxOgre::Enums::ShapesType_Dynamic);

if(HitResult.mRigidBody)
{
NxOgre::Actor* a = static_cast<NxOgre::Actor*>(HitResult.mRigidBody);
a->setGlobalPosition(NxOgre::Vec3(100,0,0));
}

betajaen

10-06-2010 10:50:03

Yep, that's the correct way of doing it.