Strange raycast bug found [1.0'21]

nargil

22-08-2008 00:45:17

I found a solution, but still this needs to be fixed ;)

First of all i know the raycasting was giving reverse order actors. I fixed it as stated in the forums


Actor* RayCaster::getClosestActor() {
if (mReport.count() == 0)
return 0;

RayCastReport::Iterator mIterator = mReport.mItems.end();
mIterator--;
return (*mIterator).second.t.mActor;

}


It seemed to work for a really simple scene. Now i created my editors movement arrows and can't get accurate raycasting on them.

This is how my scene does look like:





here is my raycasting code

Ogre::Ray mray = cam->getCameraToViewportRay(x, y);
NxOgre::RayCaster* mRay = new NxOgre::RayCaster(mray.getOrigin(), mray.getDirection(), 10000, NxOgre::RayCaster::RCT_ALL, mEngine->mScene);
if (mRay->castShape(NxOgre::RayCaster::AF_NONE))
{
Vector3 hitpos = mRay->getClosestRaycastHit().mWorldImpact;
NxOgre::Body* actor = (NxOgre::Body*)((mRay->getClosestRaycastHit().mActor));
mStrzalki->raycast(actor->getName());
}
delete mRay;



Now the problem is that some actors are still reversed. For example when i move the cursor over the square connecting red and green arrow in a point where it can be the only actor hit by the ray - everything is ok




Now i lower the cursor and the background square is being selected, although it shouldn't - it's behing the previously highlighted square.




Someone could say: "ok you got an reversed raycast order", but its not the point - this doesn't happen for the square connecting green and blue arrow




Now someone could say: "ok - there is something wrong with the square that connects the red and green arrow, but there is also a bug with the green-blue connecting square. Lets rotate the camera:



The squares in the background aren't being selected - its fine:






but the red arrow is... just look:






However changing the raycaster from NxOgre::RayCaster::RCT_ALL to NxOgre::RayCaster::RCT_CLOSEST fixes the problem - so i can go ahead with my work.

Good luck fixing it :>

xadh00m

22-08-2008 10:01:00

Are you sure this is a bug? Maybe the results are just unordered. Currently I don´t have the docs at hand to check this...

Btw: How do you manage to move your cursor/pivot? I´m facing a similar problem
and would like to hear how this should be done...

nargil

22-08-2008 11:04:44

I don't know what you are asking about. I'm no pro to give advices how something *should* be done. The cursor on the screens is just photoshoped, because the standard windows pointer doesn't show up on screenshots.

If you're asking how i determine in which directions to move my objects (based on which part of the arrows the cursor hits) - for now I just pass the rayhit actors name to my arrows class, which compares the name and returns an enumeration like ARROWS_NONE, ARROWS_X, ARROWS_XZ... Although I'm going to rewrite it so it just compares pointers

On the other hand if u mean how I handle the mouse cursor leaving a renderwindows - just like 3dsmax9 is doing it - if a button is down, and the mouse leaves the right side of the window, then the cursor is placed again on the left side of the renderwindow

I don't really know if its really a bug, but imagine a bullet piercing multiple targets, and they die in a random order :P (yes I know - sort it manually)

xadh00m

22-08-2008 14:25:48

I don't really know if its really a bug, but imagine a bullet piercing multiple targets, and they die in a random order :P (yes I know - sort it manually)

I think you just take the getClosestActor() in that case... and kill him. ;-)

My question was how do you know how far your pivot has to move e.g. along
the x-axis depending on the mouse movement. Do you make some kind of projection onto e.g. the xz-plane of the pivot?

nargil

22-08-2008 15:05:41

Oh I don't need the end position to be accurate with the end mouse position. I just move the object along the axes based on (mouse.Pos - mouse.prevPos) * cameraDistance * someSpeedFactor. The speed factor can be adjusted so its almost accurate with the mouse position.

As a matter of facts raycasting the end position would make it impossible to wrap the mouse pointer withing the renderwindow.

betajaen

22-08-2008 15:28:26

And if it helps. NxOgre '22 has a new rewritten raycast class. It's much better, has more features, and behaves a bit like SQL.