gugus
26-05-2008 21:45:20
It the first time i try to use raycast and i am quiet confuse with raycast ,raycasthit,etc.
I don't know what i must do to get the Actors the raycast hit,i tried several things(including the search button),but i don't get it.What procedure should I follow(no need to give code,what I need is the generale idea)?
And when is the raycast calculated?During the scene update?
Thanks.
betajaen
26-05-2008 22:28:54
It's done straight away.
Basically, you can use the Scene helper function, or do your own:
Actors actors = mScene->getActorsFromRaycast(position, normalised_normal, range);
RayCaster* mRay = new RayCaster(mCamera->getPosition(), Vector3(0,0,0), 100, RayCaster::RCT_CLOSEST, mScene);
if (mRay->castShape(RayCaster::AF_NONE)) {
Vector3 hitpos = mRay->getClosestRaycastHit().mWorldImpact;
Actor* actor = mRay->getClosestActor();
}
There are many different combinations and setup on how you use the RayCaster. Just play with it, and read the class documentation.
But beware; When '22 comes out. I've rewrote the Raycaster class, it's a lot easier and simple to work with.
Caphalor
27-05-2008 09:57:25
But beware; When '22 comes out. I've rewrote the Raycaster class, it's a lot easier and simple to work with.
Nooo my small wrapper class will be complete useless.
I think 3 types of raycaster contructors would be useful:
1. Raycasting from a point using a direction vector: already implemented
2. Raycasting from a point to another point:
Ogre::Vector3 dir = target - origin;
Ogre::Real dist = dir.normalise();
3. Raycasting from a point using an Orientation:
Ogre::Vector3 Direction = Orientation * -Ogre::Vector3::UNIT_Z;
I know that it's off topic, but will 22' contain the new character System?
betajaen
27-05-2008 11:49:14
Not useless, you just have to change it. The new raycaster works a little bit like the new ManualMesh style of programming, it also reminds me of SQL for some reason.
Raycaster* mRay = mScene->createRaycaster();
mRay->origin(NxVec3(0,0,0));
mRay->normal(NxVec3(1,0,0));
mRay->distance(100);
mRay->type(Raycaster::RCT_All);
mRay->accuracy(Raycaster::AC_Accurate);
mRay->cast();
ActorRaycastHits::SharedListIterator ah = mRay->getActors().getIterator();
for (ActorRaycastHit* ar = ait.Begin(); ar = ait.Next();) {
std::cout << "'" << ar->mActor->getName() << "' @ " << ar->mDistance << "m" << std::endl;
}
No. They won't be in for '22. But I've been working on the NxCharacter code for another project, and I want to start the new Character system, I've been planning in '23. I've been playing GTAIV a little bit, and I like how it's implemented and want to duplicate some of it.
nargil
07-10-2008 19:42:31
what exactly is "ait" in the sample code above ? Shouldn't it be ah ?
betajaen
07-10-2008 19:43:53
It should be "ah", or "ah" should be "ait" depending on your preference.
nargil
07-10-2008 19:58:33
ok, and I guess mRay->getActors().getIterator(); should be just mRay->Actors();
at least in .T2
Could you now help migrate this 1.0'21 code to 1.0'22.T2 ?
NxOgre::RayCastHit cRaycaster::getRaycastHit()
{
NxOgre::RayCastHit rch = this->nxRay->getClosestRaycastHit();
NxOgre::RayCastReport::Iterator it = this->nxRay->mReport.mItems.begin();
while(it != this->nxRay->mReport.mItems.end())
{
std::cout << (*it).first << std::endl;
if((*it).first.compare("strzalkaX.mesh")==0
|| (*it).first.compare("strzalkaY.mesh")==0
|| (*it).first.compare("strzalkaZ.mesh")==0
|| (*it).first.compare("kwadratXYactor")==0
|| (*it).first.compare("kwadratXZactor")==0
|| (*it).first.compare("kwadratZYactor")==0
) rch = (*it).second.t;
it++;
}
return rch; //;
}
the errors:
1>d:\programowanie\gra\wxwed2\wxwed\raycaster.cpp(57) : error C2027: use of undefined type 'NxOgre::RayCastHit'
1> d:\programowanie\nx\1.0.22.t2\include\nxogreprerequisites.h(132) : see declaration of 'NxOgre::RayCastHit'
1>d:\programowanie\gra\wxwed2\wxwed\raycaster.cpp(57) : error C2079: 'cRaycaster::getRaycastHit' uses undefined struct 'NxOgre::RayCastHit'
1>d:\programowanie\gra\wxwed2\wxwed\raycaster.cpp(58) : error C2079: 'rch' uses undefined struct 'NxOgre::RayCastHit'
1>d:\programowanie\gra\wxwed2\wxwed\raycaster.cpp(58) : error C2039: 'getClosestRaycastHit' : is not a member of 'NxOgre::Raycaster'
1> d:\programowanie\nx\1.0.22.t2\include\nxogreraycaster.h(122) : see declaration of 'NxOgre::Raycaster'
1>d:\programowanie\gra\wxwed2\wxwed\raycaster.cpp(59) : error C2039: 'mReport' : is not a member of 'NxOgre::Raycaster'
1> d:\programowanie\nx\1.0.22.t2\include\nxogreraycaster.h(122) : see declaration of 'NxOgre::Raycaster'
1>d:\programowanie\gra\wxwed2\wxwed\raycaster.cpp(59) : error C2228: left of '.mItems' must have class/struct/union
1>d:\programowanie\gra\wxwed2\wxwed\raycaster.cpp(59) : error C2228: left of '.begin' must have class/struct/union
1>d:\programowanie\gra\wxwed2\wxwed\raycaster.cpp(60) : error C2039: 'mReport' : is not a member of 'NxOgre::Raycaster'
1> d:\programowanie\nx\1.0.22.t2\include\nxogreraycaster.h(122) : see declaration of 'NxOgre::Raycaster'
1>d:\programowanie\gra\wxwed2\wxwed\raycaster.cpp(60) : error C2228: left of '.mItems' must have class/struct/union
1>d:\programowanie\gra\wxwed2\wxwed\raycaster.cpp(60) : error C2228: left of '.end' must have class/struct/union
1>d:\programowanie\gra\wxwed2\wxwed\raycaster.cpp(60) : fatal error C1903: unable to recover from previous error(s); stopping compilation
What really bothers me is "error C2027: use of undefined type 'NxOgre::RayCastHit'". The other errors i could fix myself.
betajaen
07-10-2008 20:24:47
Try this:
mRay = mScene->createRaycaster();
mRay->origin(NxVec3(0,0,0));
mRay->normal(NxVec3(1,0,0));
mRay->distance(100);
mRay->type(Raycaster::RCT_Closest);
if (mRay->cast()) {
for (ActorRaycastHit* ar = ait.Begin(); ar = ait.Next();) {
std::cout << "'" << ar->mActor->getName() << "' @ " << ar->mDistance << "m" << std::endl;
}
}
mScene->destroyRaycaster(mRay);