PDA

View Full Version : check if an object is behind another



{MSX}
09-05-2005, 11:46 AM
Hi! i'd like to see if an object is behind another (from the camera point of view). I'd like, if the protagonist is hidden, to draw the hiding object as blend, to let the player see the character.

Thanks!

Paulius
09-05-2005, 01:08 PM
trace a few rays from eye position to some points on youre charaters bounding box. Objects which rays hit before the charater are hiding him.

JSoftware
09-05-2005, 01:30 PM
if you're doing opegl rendering then just use the hp_occlusion_test to test if the character is completely hidden. first draw the occluder. then disable color writes and draw the ocharacter. if the test tells he's hidden then enable color writes and draw the character then draw the occluder with some blending.

if i figured this out right then the character in front of the character should be blended with the character. if this should work then it probably could be done in a better way

happy coding :D

Paulius
09-05-2005, 02:03 PM
Yes, but not having to constantly synchronize CPU with GPU is always better

{MSX}
09-05-2005, 02:42 PM
Thanks!
Paulius, can you tell me something more about casting a ray? I've never done it :P
I use sphere as approximation, so i should have sphere-ray collisioni guess.
If you've some code it would be nice :P

Thanks!

Paulius
09-05-2005, 03:17 PM
My Ray sphere intersection test:

t1:= Infinity;
t2:= Infinity;
DistX:= RayOrigin[X] - Sphere[X];
DistY:= RayOrigin[Y] - Sphere[Y];
DistZ:= RayOrigin[Z] - Sphere[Z];
b:= RayDirection[X]*DistX + RayDirection[Y]*DistY + RayDirection[Z]*DistZ;
c:= DistX*DistX + DistY*DistY + DistZ*DistZ - Radius*Radius;
d:= b * b - c;
if d >= 0.0 then
begin
sq:= sqrt(d);
t1:= -b - sq;
t2:= -b + sq;
end;
t1 - distance to the 1st hit, t2 - the 2nd. Infinity is a no hit constant. RayDirection must be normalized.

{MSX}
09-05-2005, 04:50 PM
thanks, great piece of code!

now as ray i can take the vector from camera position to camera target, right ?
I'm tring it :P

Paulius
09-05-2005, 05:22 PM
You should direct a ray not to camera target but to the position of you?¢_Tre characters bounding sphere. And to take into account objects that partially obstruct the character but not its center, trace a few more rays with direction jittered around characters bounding sphere