1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| makeCylinder: function (radius, height, latitudeBands, longitudeBands) { this.points = []; this.colors = []; this.texCoords = [];
for (var latNumber = 0; latNumber <= latitudeBands; latNumber++) { var y = height * (latNumber / latitudeBands - 0.5); for (var longNumber = 0; longNumber <= longitudeBands; longNumber++) { var theta = longNumber * 2 * Math.PI / longitudeBands; var x = radius * Math.cos(theta); var z = radius * Math.sin(theta); var u = longNumber / longitudeBands; var v = latNumber / latitudeBands;
this.points.push(x, y, z); this.texCoords.push(u, v); this.colors.push(1.0, 1.0, 1.0, 1.0); } }
for (var latNumber = 0; latNumber < latitudeBands; latNumber++) { for (var longNumber = 0; longNumber < longitudeBands; longNumber++) { var first = (latNumber * (longitudeBands + 1)) + longNumber; var second = first + longitudeBands + 1;
this.points.push(this.points[first * 3], this.points[first * 3 + 1], this.points[first * 3 + 2]); this.points.push(this.points[second * 3], this.points[second * 3 + 1], this.points[second * 3 + 2]); this.points.push(this.points[(first + 1) * 3], this.points[(first + 1) * 3 + 1], this.points[(first + 1) * 3 + 2]);
this.points.push(this.points[second * 3], this.points[second * 3 + 1], this.points[second * 3 + 2]); this.points.push(this.points[(second + 1) * 3], this.points[(second + 1) * 3 + 1], this.points[(second + 1) * 3 + 2]); this.points.push(this.points[(first + 1) * 3], this.points[(first + 1) * 3 + 1], this.points[(first + 1) * 3 + 2]);
this.texCoords.push(this.texCoords[first * 2], this.texCoords[first * 2 + 1]); this.texCoords.push(this.texCoords[second * 2], this.texCoords[second * 2 + 1]); this.texCoords.push(this.texCoords[(first + 1) * 2], this.texCoords[(first + 1) * 2 + 1]);
this.texCoords.push(this.texCoords[second * 2], this.texCoords[second * 2 + 1]); this.texCoords.push(this.texCoords[(second + 1) * 2], this.texCoords[(second + 1) * 2 + 1]); this.texCoords.push(this.texCoords[(first + 1) * 2], this.texCoords[(first + 1) * 2 + 1]);
var colorIndex = Math.floor(latNumber / (latitudeBands / 6)); for (var i = 0; i < 6; i++) { this.colors.push(this.vertexColors[colorIndex][0], this.vertexColors[colorIndex][1], this.vertexColors[colorIndex][2], this.vertexColors[colorIndex][3]); } } }
var baseCenterIndex = this.points.length / 3; this.points.push(0.0, -height / 2, 0.0); this.texCoords.push(0.5, 0.5); this.colors.push(1.0, 1.0, 1.0, 1.0);
for (var longNumber = 0; longNumber <= longitudeBands; longNumber++) { var theta = longNumber * 2 * Math.PI / longitudeBands; var x = radius * Math.cos(theta); var z = radius * Math.sin(theta); var u = 0.5 + 0.5 * Math.cos(theta); var v = 0.5 + 0.5 * Math.sin(theta);
this.points.push(x, -height / 2, z); this.texCoords.push(u, v); this.colors.push(1.0, 1.0, 1.0, 1.0);
if (longNumber > 0) { this.points.push(0.0, -height / 2, 0.0); this.points.push(this.points[(baseCenterIndex + longNumber) * 3], this.points[(baseCenterIndex + longNumber) * 3 + 1], this.points[(baseCenterIndex + longNumber) * 3 + 2]); this.points.push(this.points[(baseCenterIndex + longNumber + 1) * 3], this.points[(baseCenterIndex + longNumber + 1) * 3 + 1], this.points[(baseCenterIndex + longNumber + 1) * 3 + 2]);
this.texCoords.push(0.5, 0.5); this.texCoords.push(this.texCoords[(baseCenterIndex + longNumber) * 2], this.texCoords[(baseCenterIndex + longNumber) * 2 + 1]); this.texCoords.push(this.texCoords[(baseCenterIndex + longNumber + 1) * 2], this.texCoords[(baseCenterIndex + longNumber + 1) * 2 + 1]);
for (var i = 0; i < 3; i++) { this.colors.push(1.0, 1.0, 1.0, 1.0); } } }
var topCenterIndex = this.points.length / 3; this.points.push(0.0, height / 2, 0.0); this.texCoords.push(0.5, 0.5); this.colors.push(1.0, 1.0, 1.0, 1.0);
for (var longNumber = 0; longNumber <= longitudeBands; longNumber++) { var theta = longNumber * 2 * Math.PI / longitudeBands; var x = radius * Math.cos(theta); var z = radius * Math.sin(theta); var u = 0.5 + 0.5 * Math.cos(theta); var v = 0.5 + 0.5 * Math.sin(theta);
this.points.push(x, height / 2, z); this.texCoords.push(u, v); this.colors.push(1.0, 1.0, 1.0, 1.0);
if (longNumber > 0) { this.points.push(0.0, height / 2, 0.0); this.points.push(this.points[(topCenterIndex + longNumber) * 3], this.points[(topCenterIndex + longNumber) * 3 + 1], this.points[(topCenterIndex + longNumber) * 3 + 2]); this.points.push(this.points[(topCenterIndex + longNumber + 1) * 3], this.points[(topCenterIndex + longNumber + 1) * 3 + 1], this.points[(topCenterIndex + longNumber + 1) * 3 + 2]);
this.texCoords.push(0.5, 0.5); this.texCoords.push(this.texCoords[(topCenterIndex + longNumber) * 2], this.texCoords[(topCenterIndex + longNumber) * 2 + 1]); this.texCoords.push(this.texCoords[(topCenterIndex + longNumber + 1) * 2], this.texCoords[(topCenterIndex + longNumber + 1) * 2 + 1]);
for (var i = 0; i < 3; i++) { this.colors.push(1.0, 1.0, 1.0, 1.0); } } } }
|