Skip to content

Commit

Permalink
adding Quest controller interaction to physics simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
stemkoski committed Mar 14, 2022
1 parent a15ec90 commit c28757b
Showing 1 changed file with 251 additions and 0 deletions.
251 changes: 251 additions & 0 deletions quest-physics.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
<!DOCTYPE html>
<html>

<head>
<title>A-Frame: Quest movement and interaction with physics</title>
<script src="https://aframe.io/releases/1.3.0/aframe.min.js"></script>
<script src="js/aframe-environment-component.js"></script>
<script src="js/controller-listener.js"></script>
<script src="js/player-move.js"></script>
<script src="js/raycaster-extras.js"></script>
<script src="js/physx.release.js"></script>
<script src="js/physics.js"></script>
</head>

<body>

<script>
// if raycaster is pointing at this object, press trigger to change color
AFRAME.registerComponent("physics-grab", {
init: function ()
{
let self = this;

this.el.addEventListener("raycaster-grabbed", function() {
self.el.addState("grabbed");
});

this.el.addEventListener("raycaster-released", function() {
self.el.removeState("grabbed");
});
},

tick: function()
{

}
});


</script>

<a-scene environment="preset: default;"
physx="autoLoad: true; delay: 1000; wasmUrl: js/physx.release.wasm; useDefaultScene: false;">

<a-assets>
<img id="gradient" src="images/gradient-fade.png" />
<img id="crate" src="images/crate.jpg" />
<img id="pixels" src="images/pixels.png" />
<img id="ball" src="images/basketball-gray.png" />
<img id="hexagons" src="images/hexagons.png"/>
</a-assets>

<a-sky
color = "#000337">
</a-sky>

<a-entity
id="player"
position="0 0 0"
player-move="controllerListenerId: #controller-data;
navigationMeshClass: environmentGround;">

<a-camera></a-camera>

<a-entity
id="controller-data"
controller-listener="leftControllerId: #left-controller;
rightControllerId: #right-controller;">
</a-entity>

<a-entity
id="left-controller"
oculus-touch-controls="hand: left">
</a-entity>

<a-entity
id="right-controller"
oculus-touch-controls="hand: right"
raycaster="objects: .raycaster-target, .environmentGround;"
raycaster-extras="controllerListenerId: #controller-data;
beamImageSrc: #gradient; beamLength: 0.5;">
</a-entity>

</a-entity>

<!-- Floor -->
<a-box physx-body="type: static;"
class="environmentGround"
position="0 0.02 0"
width="20" depth="20" height="0.1"
material="src: #crate; repeat: 10 10;">
</a-box>

<!-- Walls -->
<a-box physx-body="type: static;"
position="0 0.51 -10"
width="20" depth="0.1" height="1"
material="src: #crate; repeat: 5 1;">
</a-box>

<a-box physx-body="type: static;"
position="0 0.51 10"
width="20" depth="0.1" height="1"
material="src: #crate; repeat: 5 1;">
</a-box>

<a-box physx-body="type: static;"
position="10 0.51 0"
width="0.1" depth="20" height="1"
material="src: #crate; repeat: 5 1;">
</a-box>

<a-box physx-body="type: static;"
position="-10 0.51 0"
width="0.1" depth="20" height="1"
material="src: #crate; repeat: 5 1;">
</a-box>

<!-- Dynamic objects -->

<a-box physx-body="type: dynamic; highPrecision: true;"
raycaster-target="canGrab: true;"
physics-grab
position="-5 3 -5" rotation="10 20 30"
material="color: red;">
</a-box>

<a-box physx-body="type: dynamic;"
raycaster-target="canGrab: true;"
physics-grab
position="-6.5 3 -5" rotation="10 20 30"
material="color: yellow;">
</a-box>

<a-box physx-body="type: dynamic;"
raycaster-target="canGrab: true;"
physics-grab
position="-6 3 -5" rotation="10 20 30"
material="color: green;">
</a-box>

<a-cylinder physx-body="type: dynamic;"
raycaster-target="canGrab: true;"
physics-grab
position="-3 3 -5" rotation="5 10 15"
radius="0.5" height="1.5"
material="color: orange;">
</a-cylinder>

<a-entity physx-body="type: dynamic;"
raycaster-target="canGrab: true;"
physics-grab
geometry="primitive: icosahedron; radius: 0.5;"
position="-1 3 -5" rotation="53 37 42"
material="color: blue;">
</a-entity>

<a-entity physx-body="type: dynamic;"
raycaster-target="canGrab: true;"
physics-grab
geometry="primitive: dodecahedron; radius: 0.5;"
position="-1 3 -6" rotation="53 37 42"
material="color: violet;">
</a-entity>

<a-sphere physx-body="type: dynamic;" physx-material="restitution: 0.8;"
raycaster-target="canGrab: true;"
physics-grab
position="1 6 -5"
radius="0.5"
material="src:#ball; color:red;">
</a-sphere>

<a-sphere physx-body="type: dynamic;" physx-material="restitution: 0.8;"
raycaster-target="canGrab: true;"
physics-grab
position="2.5 6 -5.1"
radius="0.5"
material="src:#ball; color:orange;">
</a-sphere>

<a-sphere physx-body="type: dynamic;" physx-material="restitution: 0.8;"
raycaster-target="canGrab: true;"
physics-grab
position="3 4 -5"
radius="0.5"
material="src:#ball; color:yellow;">
</a-sphere>

<a-sphere physx-body="type: dynamic;" physx-material="restitution: 0.8;"
raycaster-target="canGrab: true;"
physics-grab
position="3.5 8 -4.8"
radius="0.5"
material="src:#ball; color:green;">
</a-sphere>

<a-sphere physx-body="type: dynamic;" physx-material="restitution: 0.8;"
raycaster-target="canGrab: true;"
physics-grab
position="5 2 -5"
radius="0.5"
material="src:#ball; color:blue;">
</a-sphere>

<a-sphere physx-body="type: dynamic;" physx-material="restitution: 0.8;"
raycaster-target="canGrab: true;"
physics-grab
position="5 2 5"
radius="0.5"
material="src:#ball; color:violet;">
</a-sphere>

<!-- kinematic boxes -->

<a-box
physx-body="type: kinematic;"
width="0.1" depth="1" height="4"
position = "-1 1 -2"
color = "#BBBBBB"
raycaster-target="canGrab: true;">
</a-box>

<a-box
physx-body="type: kinematic;"
width="0.1" depth="1" height="4"
position = "1 1 -2"
color = "#BBBBBB"
raycaster-target="canGrab: true;">
</a-box>

<a-box
physx-body="type: kinematic;"
width="0.1" depth="1" height="4"
position = "-3 1 -2"
color = "#BBBBBB"
raycaster-target="canGrab: true;">
</a-box>

<a-box
physx-body="type: kinematic;"
width="0.1" depth="1" height="4"
position = "3 1 -2"
color = "#BBBBBB"
raycaster-target="canGrab: true;">
</a-box>

</a-scene>

</body>
</html>

0 comments on commit c28757b

Please sign in to comment.