RogueCannon.ts 955 B

1234567891011121314151617181920212223242526272829303132
  1. import * as CANNON from 'cannon-es';
  2. import * as THREE from 'three';
  3. export type CollisionEvent = {body: CANNON.Body, target: CANNON.Body, contact: CANNON.ContactEquation};
  4. let RogueCannon: {world: CANNON.World} = {world: new CANNON.World()};
  5. export function getWorld() {
  6. return RogueCannon.world;
  7. }
  8. export function setWorld(newWorld: CANNON.World) {
  9. RogueCannon.world = newWorld;
  10. }
  11. export function copyThreeV3(vector3: THREE.Vector3, target: CANNON.Vec3) {
  12. target.set(vector3.x, vector3.y, vector3.z);
  13. }
  14. export function copyThreeQuaternion(quaternion: THREE.Quaternion, target: CANNON.Quaternion) {
  15. const q = quaternion;
  16. target.set(q.x, q.y, q.z, q.w);
  17. }
  18. export function copyCannonV3(vector3: CANNON.Vec3, target: THREE.Vector3) {
  19. target.set(vector3.x, vector3.y, vector3.z);
  20. }
  21. export function copyCannonQuaternion(quaternion: CANNON.Quaternion, target: THREE.Quaternion) {
  22. const q = quaternion;
  23. target.set(q.x, q.y, q.z, q.w);
  24. }