One sided collision testing

I’m using panda’s inbuilt collision detection system to test for visibility. What I want to do is make a sort of one-way mirror for collision testing, so the collision geometry only counts if the collision test is coming from one direction but not the other.

Is there a simple way to do this, or some way to manually check which way the polygon is facing so I can work out which direction it’s in?

You can use CollisionEntry.getSurfaceNormal(nodePath) to get the normal, but polygons are one sided anyway.
If you are using ray-polygon collisions then it should work fine, for sphere-polygon I think a collision will be detected when the sphere is on the other side (half way?) of a backfacing poly.

I’m using segment-polygon tests and they are definitely colliding on both sides of the polygon.

I found a much simpler solution that works for me by just counting it as visible if there’s only one collision. There’s no way a collision can pass through two one-way collisions so it works out fine in practice.

To know whether an object is coming from the inside or the outside, you have to know which way the object is moving. To know this, you have to subtract the object’s previous position from its current position, normalize this vector, and take a dot product with the surface normal of the collision. Depending on whether this is larger than 0 or smaller than 0, the object is either colliding from one way or the other.
(Keep in mind that the surface normal may change if the object moves from one collided polygon to the other while colliding.)

(If you have continuous collision testing enabled, you could extract the previous point from the nodes itself.)

Alternatively, depending on the specific test, you might use getInteriorPoint() and test whether the interior point is moving inward or outward using the above method.