var Triangle = new Class({
	
	initialize: function(canvas, p1, p2, p3){
		this.canvas = canvas;
		this.p1 = p1;
		this.p2 = p2;
		this.p3 = p3;
	},
	
	getNormal: function(){
		var a = Vector.substract(this.p2, this.p1);
		var b = Vector.substract(this.p3, this.p1);
		return a.cross(b);
	},
	
	getCenter: function(){
		return new Vector(
			(this.p1.x + this.p2.x + this.p3.x) / 3,
			(this.p1.y + this.p2.y + this.p3.y) / 3,
			(this.p1.z + this.p2.z + this.p3.z) / 3);
	},
	
	draw: function(){
		var p1 = cam.transform(this.p1);
		var p2 = cam.transform(this.p2);
		var p3 = cam.transform(this.p3);
		var lightness = Math.abs(this.getNormal().normalize().scalarProduct(lightVector));
		this.canvas.triangle(p1, p2, p3, [Math.round(100 * lightness), Math.round(200 * lightness), Math.round(100 * lightness)]);
	}
	
});
