Fastest way

Blitz3D Forums/Blitz3D Beginners Area/Fastest way

RifRaf(Posted 2004) [#1]
if you have two entities moving at a given speed, and any given angle, and then they collide. What is the quickest way to determine if entity1 is in front of, or behind entity2?

I could use entitypick and see if entity2 is picked or not
or I could position a pivot at the entity1 position, match its rotation, then moveentity 0,0,1. Then see if the pivot is closer to the entity2 than entity1 is. if it is then entity2 is in front of entity1. However that seems very hacked, and the pick method seems slow. any other ideas?


Sledge(Posted 2004) [#2]
Measure the distance of each from the camera? Must be fairly standard equations for that waiting to be Googled.


puki(Posted 2004) [#3]
That won't work - entities may be different sizes - or may not be travelling directly in front/behind of camera.


Sledge(Posted 2004) [#4]

entities may be different sizes



Sure, but you know what size your entities are and therefore what radius to compensate for.


or may not be travelling directly in front/behind of camera


Well if "in front" is a universal standard then get the z position.


sswift(Posted 2004) [#5]
"That won't work - entities may be different sizes - or may not be travelling directly in front/behind of camera."

Your question makes no sense.

Your question as written boils down to this:

"Two entities collide. How do I dtermine which one is in front of the other?"

How do you define "in front of"?

Nearer to the camera? That's easy. And doesn't matter if you're in front of the camera or not.

Drawing on top of the other? Ie, sphere 2's center is closer, but it's smaller and inside of sphere 1 because sphere 1 is bigger and sphere 1 draws on top. In that case, you can:

A) Do a linepick...
B) Look at all the vertices and find the one nearest the camera.
C) Subtract the radius from the distance of the center of each, so Sphere1 comes out closer than sphere 2 even though sphere 2's center is nearer the camera.


Or is there some other measure which you are using to determine "in front"?


RifRaf(Posted 2004) [#6]
"in front of" is local to the entities colliding.. so if entity1 is facing entity2 then entity2 is in front of entity1.

currently i am using entitypick, but it seems a slow way of doing it when i have many checks


sswift(Posted 2004) [#7]
"so if entity1 is facing entity2 then entity2 is in front of entity1."


If that's all that you want to know, if if one entity is "in front of" the other in their local space, then that is simple to calculate.

TFormPoint EntityX#(Entity1), EntityY#(Entity1), EntityZ#(Entity1), 0, Entity2
Z# = TformedZ#()

If Z# > 0 then Entity1 is in front of Entity2.


What that does, is calculates where Entity1 is in the space of Entity2. It transforms the location fo Entity1 from global space (0) to Entity2's space.

Since positive Z in Entity2's space is "in front of it", you know if the entity is in front of it.

You can also determine if one entity is to the left or right of another entity, behind it, or above and below it. Just get TformedX#() after the TformPoint for left and right, and TFormedY#() for above and below.


RifRaf(Posted 2004) [#8]
Thanks sswift, very helpfull.