Skip to content

Commit

Permalink
Reverse order of vertex creation of Cylinder
Browse files Browse the repository at this point in the history
  • Loading branch information
marcofugaro committed Jun 16, 2020
1 parent 6470829 commit 5323344
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
22 changes: 11 additions & 11 deletions dist/cannon-es.cjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8355,10 +8355,10 @@ var Cylinder = /*#__PURE__*/function (_ConvexPolyhedron) {
var cos = Math.cos;
var sin = Math.sin; // First bottom point

vertices.push(new Vec3(radiusBottom * cos(0), -height * 0.5, -radiusBottom * sin(0)));
vertices.push(new Vec3(-radiusBottom * sin(0), -height * 0.5, radiusBottom * cos(0)));
bottomface.push(0); // First top point

vertices.push(new Vec3(radiusTop * cos(0), height * 0.5, -radiusTop * sin(0)));
vertices.push(new Vec3(-radiusTop * sin(0), height * 0.5, radiusTop * cos(0)));
topface.push(1);

for (var i = 0; i < N; i++) {
Expand All @@ -8367,30 +8367,30 @@ var Cylinder = /*#__PURE__*/function (_ConvexPolyhedron) {

if (i < N - 1) {
// Bottom
vertices.push(new Vec3(radiusBottom * cos(theta), -height * 0.5, -radiusBottom * sin(theta)));
vertices.push(new Vec3(-radiusBottom * sin(theta), -height * 0.5, radiusBottom * cos(theta)));
bottomface.push(2 * i + 2); // Top

vertices.push(new Vec3(radiusTop * cos(theta), height * 0.5, -radiusTop * sin(theta)));
vertices.push(new Vec3(-radiusTop * sin(theta), height * 0.5, radiusTop * cos(theta)));
topface.push(2 * i + 3); // Face

faces.push([2 * i + 2, 2 * i + 3, 2 * i + 1, 2 * i]);
faces.push([2 * i, 2 * i + 1, 2 * i + 3, 2 * i + 2]);
} else {
faces.push([0, 1, 2 * i + 1, 2 * i]); // Connect
faces.push([2 * i, 2 * i + 1, 1, 0]); // Connect
} // Axis: we can cut off half of them if we have even number of segments


if (N % 2 === 1 || i < N / 2) {
axes.push(new Vec3(cos(thetaN), 0, -sin(thetaN)));
axes.push(new Vec3(-sin(thetaN), 0, cos(thetaN)));
}
}

faces.push(topface);
axes.push(new Vec3(0, 1, 0)); // Reorder bottom face
faces.push(bottomface);
axes.push(new Vec3(0, 1, 0)); // Reorder top face

var temp = [];

for (var _i = 0; _i < bottomface.length; _i++) {
temp.push(bottomface[bottomface.length - _i - 1]);
for (var _i = 0; _i < topface.length; _i++) {
temp.push(topface[topface.length - _i - 1]);
}

faces.push(temp);
Expand Down
22 changes: 11 additions & 11 deletions dist/cannon-es.js
Original file line number Diff line number Diff line change
Expand Up @@ -7764,10 +7764,10 @@ class Cylinder extends ConvexPolyhedron {
const cos = Math.cos;
const sin = Math.sin; // First bottom point

vertices.push(new Vec3(radiusBottom * cos(0), -height * 0.5, -radiusBottom * sin(0)));
vertices.push(new Vec3(-radiusBottom * sin(0), -height * 0.5, radiusBottom * cos(0)));
bottomface.push(0); // First top point

vertices.push(new Vec3(radiusTop * cos(0), height * 0.5, -radiusTop * sin(0)));
vertices.push(new Vec3(-radiusTop * sin(0), height * 0.5, radiusTop * cos(0)));
topface.push(1);

for (let i = 0; i < N; i++) {
Expand All @@ -7776,30 +7776,30 @@ class Cylinder extends ConvexPolyhedron {

if (i < N - 1) {
// Bottom
vertices.push(new Vec3(radiusBottom * cos(theta), -height * 0.5, -radiusBottom * sin(theta)));
vertices.push(new Vec3(-radiusBottom * sin(theta), -height * 0.5, radiusBottom * cos(theta)));
bottomface.push(2 * i + 2); // Top

vertices.push(new Vec3(radiusTop * cos(theta), height * 0.5, -radiusTop * sin(theta)));
vertices.push(new Vec3(-radiusTop * sin(theta), height * 0.5, radiusTop * cos(theta)));
topface.push(2 * i + 3); // Face

faces.push([2 * i + 2, 2 * i + 3, 2 * i + 1, 2 * i]);
faces.push([2 * i, 2 * i + 1, 2 * i + 3, 2 * i + 2]);
} else {
faces.push([0, 1, 2 * i + 1, 2 * i]); // Connect
faces.push([2 * i, 2 * i + 1, 1, 0]); // Connect
} // Axis: we can cut off half of them if we have even number of segments


if (N % 2 === 1 || i < N / 2) {
axes.push(new Vec3(cos(thetaN), 0, -sin(thetaN)));
axes.push(new Vec3(-sin(thetaN), 0, cos(thetaN)));
}
}

faces.push(topface);
axes.push(new Vec3(0, 1, 0)); // Reorder bottom face
faces.push(bottomface);
axes.push(new Vec3(0, 1, 0)); // Reorder top face

const temp = [];

for (let i = 0; i < bottomface.length; i++) {
temp.push(bottomface[bottomface.length - i - 1]);
for (let i = 0; i < topface.length; i++) {
temp.push(topface[topface.length - i - 1]);
}

faces.push(temp);
Expand Down
22 changes: 11 additions & 11 deletions src/shapes/Cylinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,42 @@ export class Cylinder extends ConvexPolyhedron {
const sin = Math.sin

// First bottom point
vertices.push(new Vec3(radiusBottom * cos(0), -height * 0.5, -radiusBottom * sin(0)))
vertices.push(new Vec3(-radiusBottom * sin(0), -height * 0.5, radiusBottom * cos(0)))
bottomface.push(0)

// First top point
vertices.push(new Vec3(radiusTop * cos(0), height * 0.5, -radiusTop * sin(0)))
vertices.push(new Vec3(-radiusTop * sin(0), height * 0.5, radiusTop * cos(0)))
topface.push(1)

for (let i = 0; i < N; i++) {
const theta = ((2 * Math.PI) / N) * (i + 1)
const thetaN = ((2 * Math.PI) / N) * (i + 0.5)
if (i < N - 1) {
// Bottom
vertices.push(new Vec3(radiusBottom * cos(theta), -height * 0.5, -radiusBottom * sin(theta)))
vertices.push(new Vec3(-radiusBottom * sin(theta), -height * 0.5, radiusBottom * cos(theta)))
bottomface.push(2 * i + 2)
// Top
vertices.push(new Vec3(radiusTop * cos(theta), height * 0.5, -radiusTop * sin(theta)))
vertices.push(new Vec3(-radiusTop * sin(theta), height * 0.5, radiusTop * cos(theta)))
topface.push(2 * i + 3)

// Face
faces.push([2 * i + 2, 2 * i + 3, 2 * i + 1, 2 * i])
faces.push([2 * i, 2 * i + 1, 2 * i + 3, 2 * i + 2])
} else {
faces.push([0, 1, 2 * i + 1, 2 * i]) // Connect
faces.push([2 * i, 2 * i + 1, 1, 0]) // Connect
}

// Axis: we can cut off half of them if we have even number of segments
if (N % 2 === 1 || i < N / 2) {
axes.push(new Vec3(cos(thetaN), 0, -sin(thetaN)))
axes.push(new Vec3(-sin(thetaN), 0, cos(thetaN)))
}
}
faces.push(topface)
faces.push(bottomface)
axes.push(new Vec3(0, 1, 0))

// Reorder bottom face
// Reorder top face
const temp = []
for (let i = 0; i < bottomface.length; i++) {
temp.push(bottomface[bottomface.length - i - 1])
for (let i = 0; i < topface.length; i++) {
temp.push(topface[topface.length - i - 1])
}
faces.push(temp)

Expand Down

0 comments on commit 5323344

Please sign in to comment.