Skip to content

Commit

Permalink
Merge pull request #30 from react-spring/feature/cylinder-orientation
Browse files Browse the repository at this point in the history
Fix cylinder axis orientation, update deps, bump version to 0.10.0
  • Loading branch information
codynova authored Jun 9, 2020
2 parents 41dcdb4 + 3767192 commit 6470829
Show file tree
Hide file tree
Showing 5 changed files with 1,159 additions and 1,124 deletions.
12 changes: 6 additions & 6 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), radiusBottom * sin(0), -height * 0.5));
vertices.push(new Vec3(radiusBottom * cos(0), -height * 0.5, -radiusBottom * sin(0)));
bottomface.push(0); // First top point

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

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

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

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

faces.push([2 * i + 2, 2 * i + 3, 2 * i + 1, 2 * i]);
Expand All @@ -8380,12 +8380,12 @@ var Cylinder = /*#__PURE__*/function (_ConvexPolyhedron) {


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

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

var temp = [];

Expand Down
12 changes: 6 additions & 6 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), radiusBottom * sin(0), -height * 0.5));
vertices.push(new Vec3(radiusBottom * cos(0), -height * 0.5, -radiusBottom * sin(0)));
bottomface.push(0); // First top point

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

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

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

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

faces.push([2 * i + 2, 2 * i + 3, 2 * i + 1, 2 * i]);
Expand All @@ -7789,12 +7789,12 @@ class Cylinder extends ConvexPolyhedron {


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

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

const temp = [];

Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cannon-es",
"version": "0.9.1",
"version": "0.10.0",
"description": "A lightweight 3D physics engine written in JavaScript.",
"homepage": "https://github.com/schteppe/cannon.js",
"author": "Stefan Hedman <[email protected]> (http://steffe.se)",
Expand Down Expand Up @@ -44,20 +44,20 @@
}
],
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"@babel/preset-typescript": "^7.9.0",
"@babel/core": "^7.10.2",
"@babel/preset-env": "^7.10.2",
"@babel/preset-typescript": "^7.10.1",
"gh-pages": "^2.2.0",
"husky": "^4.2.3",
"prettier": "^2.0.2",
"husky": "^4.2.5",
"prettier": "^2.0.5",
"pretty-quick": "^2.0.1",
"rimraf": "^3.0.2",
"rollup": "^2.2.0",
"rollup": "^2.15.0",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-size-snapshot": "^0.11.0",
"typescript": "^3.8.3"
"rollup-plugin-size-snapshot": "^0.12.0",
"typescript": "^3.9.5"
}
}
12 changes: 6 additions & 6 deletions src/shapes/Cylinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@ export class Cylinder extends ConvexPolyhedron {
const sin = Math.sin

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

// First top point
vertices.push(new Vec3(radiusTop * cos(0), radiusTop * sin(0), height * 0.5))
vertices.push(new Vec3(radiusTop * cos(0), height * 0.5, -radiusTop * sin(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), radiusBottom * sin(theta), -height * 0.5))
vertices.push(new Vec3(radiusBottom * cos(theta), -height * 0.5, -radiusBottom * sin(theta)))
bottomface.push(2 * i + 2)
// Top
vertices.push(new Vec3(radiusTop * cos(theta), radiusTop * sin(theta), height * 0.5))
vertices.push(new Vec3(radiusTop * cos(theta), height * 0.5, -radiusTop * sin(theta)))
topface.push(2 * i + 3)

// Face
Expand All @@ -49,11 +49,11 @@ export class Cylinder extends ConvexPolyhedron {

// 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), sin(thetaN), 0))
axes.push(new Vec3(cos(thetaN), 0, -sin(thetaN)))
}
}
faces.push(topface)
axes.push(new Vec3(0, 0, 1))
axes.push(new Vec3(0, 1, 0))

// Reorder bottom face
const temp = []
Expand Down
Loading

0 comments on commit 6470829

Please sign in to comment.