I’m a bit stuck on this one, I have an object sliding across a surface and I’m trying to figure out if the underlying surface normal is concave or convex.
I’m not really sure where to start with this one, could anyone point me in the right direction?
Every triangle is by mathematical definition flat.
It only derives its concavity or convexity from analysis other nearby faces.
It comes down to what criteria you want to use. The polygon you are specifically pointing at up there appears to be convex on the side the arrow is on. But a little while to the right of it, the polys start to curve concave.
You could take an approach of moving the raycast laterally in small increments and seeing when you touch something with a different normal, and if that normal faces away or towards your normal, use that to decide your concavity.
But you would have to choose how far and what direction, etc., and obviously your answers would need to operate reasonably in the environment you’re using. Doesn’t make sense to move 1 unit away if your polys are only 0.01 units across, and converse is true too: moving 0.01 away when the poly might be 100 units across would require a lot of raycasts.
Also, you can’t reliably compare Vector3s for equality, since they contain floats. You probably want to see if the difference between the normals is more than a certain epsilon value to decide if it really is changed enough.
Hey thanks @Kurt-Dekker !
I have got the normal vector from the previous frame, I was thinking of comparing that to the current one. Do you think that has a chance to work? Maybe If I use a vector from the direction of travel too…
@petey I feel like you’re very close, at least for some gameplay useful definition of concave.
If the angle between the skier’s direction of motion and some number of timesteps earlier normal vector is less than 90º, it’s concave!
Convex as a formal definition is, "sweep lines from anywhere inside the boundary lines of a polygon. If you cross more than 1 border, it’s concave. This sweeping can be thought of as the change in normal vector: if your normal moves “backwards,” it’s concave.
But based on the screenshot you’re showing, I think it will be better gameplay to just compare to some past “snapshot” of the terrain, it may be more intuitive to the player.
Yeah, that makes sense actually… if you are a skiier, and you are travelling down that ribbon, then as @doctorpangloss mentioned above, maybe just a linear series of normals taken each frame and stored for a few frames in a circular buffer, and then you can decide from studying the recent ontes if you’ve just gone concave or convex. And you could even look ahead a bit too.