Skip to content

Commit

Permalink
update physics docs
Browse files Browse the repository at this point in the history
  • Loading branch information
hannojg committed Jul 15, 2024
1 parent 9cc2c7b commit 4020552
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 9 deletions.
55 changes: 46 additions & 9 deletions docs_old/physics.md → docs/docs/guides/PHYSICS.mdx
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
---
id: physics
title: Physics
sidebar_label: Physics
slug: /guides/physics
---

# Physics API

> [!TIP]
> As physics engine Bullet is used. We simply provide a JS/JSI wrapper around it.
> So it can help to familiarize with their documentation first:
> - [Bullet_User_Manual.pdf](https://github.com/bulletphysics/bullet3/blob/master/docs/Bullet_User_Manual.pdf)
:::warning
The API for physics is still work in progress and might change in the future.
:::

Imperative API:
:::tip
As physics engine [**bullet3**](https://github.com/bulletphysics/bullet3) is used. We simply provide a JS/JSI wrapper around it.
So it can help to familiarize with their documentation first:
- [Bullet_User_Manual.pdf](https://github.com/bulletphysics/bullet3/blob/master/docs/Bullet_User_Manual.pdf)
:::

- [Bullet imperative API](../package/src/bullet/types/api.ts)

Hooks:

Expand Down Expand Up @@ -47,7 +56,7 @@ const center = boundingBox.center
**Get the transform an entity:**

```tsx
const transformManager = useTransformManager(engine)
const {transformManager} = useFilamentContext()
const transform = transformManager.getTransform(entity)

// Get the calculated world scale:
Expand All @@ -72,7 +81,35 @@ const rigidBody = useRigidBody({
mass: 1,
shape: boxShape,
transform: transform,
// Pass the world for the body tp be automatically added to the world:
// Pass the world for the body to be automatically added to the world:
world: world
})
```
```

**Update the physical world**

We need to simulate physics every frame:

```tsx
const renderCallback = useCallback(() => {
"worklet"

// This updates the world at 60Hz/60 FPS
world.stepSimulation(1 / 60, 1, 1 / 60)
}, [world])
```

**Update the transform of our physic entities**

Now that the physical world has been updated we need to update the transform of our entities.
The `transformManager` has a convenience method for that:

```tsx
const renderCallback = useCallback(() => {
"worklet"

world.stepSimulation(1 / 60, 1, 1 / 60)

// Update our entity:
transformManager.updateTransformByRigidBody(entity, rigidBody)
}, [world])
1 change: 1 addition & 0 deletions docs/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const sidebars: SidebarsConfig = {
"guides/asset-loading",
"guides/transformation",
"guides/skybox",
"guides/physics"
],
API: [
{
Expand Down

0 comments on commit 4020552

Please sign in to comment.