-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ede12d1
Showing
18 changed files
with
3,416 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>JoltPhysics.js demo</title> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"> | ||
<link rel="stylesheet" type="text/css" href="style.css"> | ||
</head> | ||
<body> | ||
<div id="container">Loading...</div> | ||
<div id="info">JoltPhysics.js demo</div> | ||
|
||
<script src="js/three/three.min.js"></script> | ||
<script src="js/three/OrbitControls.js"></script> | ||
<script src="js/three/WebGL.js"></script> | ||
<script src="js/three/stats.min.js"></script> | ||
<script src="js/example.js"></script> | ||
|
||
<script type="module"> | ||
import initJolt from 'https://www.unpkg.com/jolt-physics/dist/jolt-physics.wasm-compat.js'; | ||
|
||
initJolt().then(function (Jolt) { | ||
// Initialize this example | ||
initExample(Jolt, null); | ||
|
||
// Create a basic floor | ||
createFloor(); | ||
|
||
createBox(new Jolt.Vec3(-12, 8, -5), Jolt.Quat.prototype.sRotation(new Jolt.Vec3(0, 0, 1), 0.2 * Math.PI), new Jolt.Vec3(0.1, 10, 1), Jolt.Static, Jolt.NON_MOVING); | ||
createBox(new Jolt.Vec3(12, 8, -5), Jolt.Quat.prototype.sRotation(new Jolt.Vec3(0, 0, 1), -0.2 * Math.PI), new Jolt.Vec3(0.1, 10, 1), Jolt.Static, Jolt.NON_MOVING); | ||
|
||
let shape = new Jolt.SphereShape(0.5, null); | ||
let creationSettings = new Jolt.BodyCreationSettings(shape, new Jolt.Vec3(0, 0, 0), Jolt.Quat.prototype.sIdentity(), Jolt.Dynamic, Jolt.MOVING); | ||
creationSettings.mAllowedDOFs = Jolt.Plane2D; | ||
|
||
for (let x = 0; x < 20; ++x) | ||
for (let y = 0; y < 10; ++y) { | ||
creationSettings.mPosition = new Jolt.Vec3(-10 + x, 10 + y, -5) | ||
let body = bodyInterface.CreateBody(creationSettings); | ||
addToScene(body, 0xff0000); | ||
} | ||
}); | ||
|
||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>JoltPhysics.js demo</title> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0"> | ||
<link rel="stylesheet" type="text/css" href="style.css"> | ||
</head> | ||
<body> | ||
<div id="container">Loading...</div> | ||
<div id="info">JoltPhysics.js demo</div> | ||
|
||
<script src="js/three/three.min.js"></script> | ||
<script src="js/three/OrbitControls.js"></script> | ||
<script src="js/three/WebGL.js"></script> | ||
<script src="js/three/stats.min.js"></script> | ||
<script src="js/example.js"></script> | ||
|
||
<script type="module"> | ||
import initJolt from 'https://www.unpkg.com/jolt-physics/dist/jolt-physics.wasm-compat.js'; | ||
|
||
initJolt().then(function (Jolt) { | ||
// Spawning variables | ||
var objectTimePeriod = 0.01; | ||
var timeNextSpawn = time + objectTimePeriod; | ||
|
||
// Initialize this example | ||
initExample(Jolt, onUpdate); | ||
|
||
// Create a basic floor | ||
createFloor(); | ||
|
||
function generateObject() { | ||
// Position and rotate body | ||
let pos = new Jolt.Vec3((Math.random() - 0.5) * 25, 15, (Math.random() - 0.5) * 25); | ||
let rot = getRandomQuat(); | ||
|
||
// Create physics body | ||
let shape = new Jolt.BoxShape(new Jolt.Vec3(0.5, 0.5, 0.5), 0.05, null); | ||
let creationSettings = new Jolt.BodyCreationSettings(shape, pos, rot, Jolt.Dynamic, Jolt.MOVING); | ||
creationSettings.mRestitution = 0.5; | ||
let body = bodyInterface.CreateBody(creationSettings); | ||
|
||
addToScene(body, 0xff0000); | ||
|
||
if (dynamicObjects.length > 200) | ||
removeFromScene(dynamicObjects[1]); // Leave the floor alone | ||
} | ||
|
||
function onUpdate(time, deltaTime) { | ||
// Check if its time to spawn a new object | ||
if (time > timeNextSpawn) { | ||
generateObject(); | ||
timeNextSpawn = time + objectTimePeriod; | ||
} | ||
} | ||
}); | ||
|
||
</script> | ||
</body> | ||
</html> |
Oops, something went wrong.