|
@@ -5,21 +5,31 @@ class Cylinder extends Quads {
|
|
|
|
|
|
var segs : Int;
|
|
var segs : Int;
|
|
|
|
|
|
- public function new( segs : Int, ray = 1.0, height = 1.0 ) {
|
|
|
|
|
|
+ public function new( segs : Int, ray = 1.0, height = 1.0, centered = false ) {
|
|
var pts = new Array();
|
|
var pts = new Array();
|
|
|
|
+ var normals = new Array();
|
|
var ds = Math.PI * 2 / segs;
|
|
var ds = Math.PI * 2 / segs;
|
|
this.segs = segs;
|
|
this.segs = segs;
|
|
|
|
+ var z0 = centered ? -height * 0.5 : 0;
|
|
|
|
+ var z1 = centered ? -z0 : height;
|
|
for( s in 0...segs ) {
|
|
for( s in 0...segs ) {
|
|
var a = s * ds;
|
|
var a = s * ds;
|
|
var a2 = (s + 1) * ds;
|
|
var a2 = (s + 1) * ds;
|
|
var x = Math.cos(a) * ray, y = Math.sin(a) * ray;
|
|
var x = Math.cos(a) * ray, y = Math.sin(a) * ray;
|
|
var x2 = Math.cos(a2) * ray, y2 = Math.sin(a2) * ray;
|
|
var x2 = Math.cos(a2) * ray, y2 = Math.sin(a2) * ray;
|
|
- pts.push(new Point(x, y, 0));
|
|
|
|
- pts.push(new Point(x2, y2, 0));
|
|
|
|
- pts.push(new Point(x, y, height));
|
|
|
|
- pts.push(new Point(x2, y2, height));
|
|
|
|
|
|
+ pts.push(new Point(x, y, z0));
|
|
|
|
+ pts.push(new Point(x2, y2, z0));
|
|
|
|
+ pts.push(new Point(x, y, z1));
|
|
|
|
+ pts.push(new Point(x2, y2, z1));
|
|
|
|
+
|
|
|
|
+ var n0 = new Point(Math.cos(a), Math.sin(a), 0);
|
|
|
|
+ var n1 = new Point(Math.cos(a2), Math.sin(a2), 0);
|
|
|
|
+ normals.push(n0);
|
|
|
|
+ normals.push(n1);
|
|
|
|
+ normals.push(n0);
|
|
|
|
+ normals.push(n1);
|
|
}
|
|
}
|
|
- super(pts);
|
|
|
|
|
|
+ super(pts,normals);
|
|
}
|
|
}
|
|
|
|
|
|
override function addUVs() {
|
|
override function addUVs() {
|
|
@@ -34,30 +44,4 @@ class Cylinder extends Quads {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- override public function addNormals() {
|
|
|
|
- normals = new Array();
|
|
|
|
- var ds = Math.PI * 2 / segs;
|
|
|
|
- for( s in 0...segs ) {
|
|
|
|
- //var ac = (s + 0.5) * ds;
|
|
|
|
-
|
|
|
|
- var ac0 = (s - 0.5) * ds;
|
|
|
|
- var ac1 = (s+ 0.5) * ds;
|
|
|
|
-
|
|
|
|
- //var n = new Point(Math.cos(ac), Math.sin(ac), 0);
|
|
|
|
- var n0 = new Point(Math.cos(ac0), Math.sin(ac0), 0);
|
|
|
|
- var n1 = new Point(Math.cos(ac1), Math.sin(ac1), 0);
|
|
|
|
- /*
|
|
|
|
- normals.push(n);
|
|
|
|
- normals.push(n);
|
|
|
|
- normals.push(n);
|
|
|
|
- normals.push(n);
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
- normals.push(n0);
|
|
|
|
- normals.push(n1);
|
|
|
|
- normals.push(n0);
|
|
|
|
- normals.push(n1);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
}
|
|
}
|