Tutorials, extensions, and source files for ActionScript, Flash, and other Adobe products.

 

senocular.com ActionScript Library

isVisible.as

1
2
3
4
5
6
7
8
9
// 2D-based backface culling for 3D objects using 3 points a, b, and c on a surface
// where a, b, and c are the 2D representations of the 3D points.
isVisible = function(a,b,c){
	var db = b.x - a.x;
	if (!db) return (a.y > b.y == c.x > a.x);
	var dc = c.x - a.x;
	if (!dc) return (a.y > c.y == b.x < a.x);
	return ((b.y-a.y)/db < (c.y-a.y)/dc) != (a.x < b.x == a.x > c.x);
}