worldFragment & movable distances

nyxojaele

18-02-2006 20:49:34

I'm trying to create a simple way to detect whether there's some terrain between my camera and my character entity-- I'm trying this thru a RaySceneQuery (I'm assuming this is the best awy...), but when I use it and check what sorts of results it gives me, it does, indeed, return both my character, and my terrain. It returns a worldFragment for the terrain, and a movable for both the terrain and the character. Looking at the movables, it says the distance to the terrain is significantly less than that of the character! I'm assuming this is because it's detecting hitting the bounding box of the page of terrain, or some such..

Is there a way to restrict hit detection to a triangle level, or am I just looking at this in entirely the wrong way?

Falagard

18-02-2006 22:17:37

My code is out of date but I used to go:


raySceneQuery->setQueryMask(RSQ_FirstTerrain);
Vector3 terrainPos;
RaySceneQueryResult& queryResult = raySceneQuery->execute();
RaySceneQueryResult::iterator it = queryResult.begin();
if (it != queryResult.end() && it->worldFragment)
{
terrainPos = it->worldFragment->singleIntersection;
}


I'm SURE there's an example of it somewhere in the PLM2 demo or samples.

nyxojaele

19-02-2006 01:12:29

Hmm...

it->worldFragment->singleIntersection

What transform space is that in? World?

Also, exactly what is the .y value read from in that? Is it 1 of the verticies that composes the triangle the ray intersected with? Because I've noticed that when I set an entity to the height returned, and the entity is above a slope, it's either hovering slightly above the ground, or the bottom little bit of it is buried in the terrain.

I'm also having some issues with my code that keeps the camera above the terrain-- it doesn't appear to be returning the proper values for terrain height? I dunno-- I'm still debugging that, so not asking for help on that yet.

tuan kuranes

20-02-2006 08:03:24

What transform space is that in? World?
Yes.
Also, exactly what is the .y value read from in that ?
height of the terrain at this point.
SingleIntersection being the point where intersection bewteen ray and terrain mesh occurs. May be interpolated if inside a triangle.

I'm also having some issues with my code that keeps the camera above the terrain
RSQ_FirstTerrain is for any direction ray against Terrain. Some imprecision may results from ray "step" advance difference. I tried to reduce a much as possible.

If getting height at a point, use RSQ_Height as it gives better results.

I'm SURE there's an example of it somewhere in the PLM2 demo or samples.
during demo, fire 'm' key once, then using 3 mouse button you can try different types of ray. (look under camera to see RSQ_Height result.) If middle of sphere isn't at exact intersection (without moving camera afterwards)...
then there is a problem, and please report it, along with reproducable steps (using demo maps.).

nyxojaele

22-02-2006 05:28:00

Hmm, perhaps I'm doing something wrong here...

When I use RSQ_Height, everything's great (thanks for pointing that out for me!), but obviously that's only good for testing height straight up and down.

Now I want to test an arbitrary Ray, so I can't use RSQ_Height. If I don't set any setQueryMask settings, it seems to do an RSQ_Height test anyways(correct me if I'm wrong.. but it always gives the same x & z values as the origin of the ray, on my program, even tho the ray is OBVIOUSLY aimed at a different angle...)

If I use RSQ_FirstTerrain, I always get a worldFragment singleIntersection equal to Vector3(-1, -1, -1) (wtf?), and if I use RSQ_AllTerrain, I get nothing returned at all!

Falagard

22-02-2006 07:27:47

As far as I know RSQ_Height ignores the ray itself and only uses the origin of the ray. It's not really a ray query - it's more like "get me the height at this x,z location"

The RSQ_FirstTerrain - I wonder how you're creating your ray?

tuan kuranes

22-02-2006 08:10:36

If I don't set any setQueryMask settings, it seems to do an RSQ_Height test anyways
It shouldn't. only if Ray direction is +- Vector::UNIT_Y.

If I use RSQ_FirstTerrain, I always get a worldFragment singleIntersection equal to Vector3(-1, -1, -1) (wtf?), and if I use RSQ_AllTerrain, I get nothing returned at all!
Ray casting seems wrong if you get those results.
As Falagard, You'll have to provide how you use ray ...
(Be sure to check PLSM2 Demo about how it uses ray casting.)