-
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.
Improve API, code quality and documentation
- Loading branch information
1 parent
3bfecee
commit 86cb287
Showing
37 changed files
with
495 additions
and
647 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,68 +1,25 @@ | ||
import './style.css' | ||
import { FCube, FScene3d } from '@fibbojs/3d' | ||
import MyCube from './classes/MyCube' | ||
import MySphere from './classes/MySphere' | ||
import Duck from './classes/Duck' | ||
import GltfCube from './classes/GltfCube' | ||
import MyGameCamera from './cameras/MyGameCamera' | ||
import { FCube, FGameCamera, FScene3d } from '@fibbojs/3d' | ||
|
||
(async () => { | ||
const scene = new FScene3d({ debug: true }) | ||
scene.init() | ||
// Initialize the scene | ||
const scene = new FScene3d() | ||
await scene.init() | ||
await scene.initPhysics() | ||
|
||
// Create a ground | ||
const ground = new FCube(scene) | ||
ground.setScale(15, 0.1, 15) | ||
ground.setPosition(0, -0.1, 0) | ||
ground.initCollider() | ||
ground.setColor(0x1F1F1F) | ||
scene.addComponent(ground) | ||
|
||
const cube = new MyCube(scene) | ||
// Create a cube | ||
const cube = new FCube(scene) | ||
cube.initRigidBody() | ||
scene.addComponent(cube) | ||
|
||
const sphere = new MySphere(scene) | ||
scene.addComponent(sphere) | ||
|
||
const duck = new Duck(scene) | ||
scene.addComponent(duck) | ||
|
||
const gltfCube = new GltfCube(scene) | ||
scene.addComponent(gltfCube) | ||
|
||
// Create 8 cubes dynamically in circle from 0 to 2PI | ||
for (let i = 0; i < 8; i++) { | ||
const angle = i * Math.PI / 4 | ||
const x = Math.cos(angle) * 4 | ||
const z = Math.sin(angle) * 4 | ||
const cube = new FCube(scene) | ||
cube.setPosition(x, 1, z) | ||
cube.initRigidBody() | ||
scene.addComponent(cube) | ||
} | ||
|
||
scene.camera = new MyGameCamera(gltfCube, scene) | ||
|
||
// Detect inputs to move the cube | ||
document.addEventListener('keydown', (event) => { | ||
const impulse = { x: 0, y: 0, z: 0 } | ||
switch (event.key) { | ||
case 'ArrowUp': | ||
impulse.z = -1 | ||
break | ||
case 'ArrowDown': | ||
impulse.z = 1 | ||
break | ||
case 'ArrowLeft': | ||
impulse.x = -1 | ||
break | ||
case 'ArrowRight': | ||
impulse.x = 1 | ||
break | ||
case ' ': | ||
gltfCube.rigidBody?.applyImpulse({ x: 0, y: 5, z: 0 }, true) | ||
break | ||
} | ||
gltfCube.rigidBody?.applyImpulse(impulse, true) | ||
}) | ||
// Attach a camera to the cube | ||
scene.camera = new FGameCamera(cube, scene) | ||
})() |
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
Oops, something went wrong.