Vec3
Since 0.6
[x, y, z] in metres, Y up, right-handed, forward is -Z.
Signature
export type Vec3 = [number, number, number]
Import: import type { Vec3 } from "@argus/api"
Example
The tested fixture fixtures/host/hover.ts.
import type { Behavior, Ctx, Vec3 } from "@argus/api"
// docs/API.md, "Forces, torques and impulses": a body that hovers (thrust = m·g), and the same lift
// as four rotors in the airframe's own frame plus a yaw torque. Typechecked by packages/api's tests.
const HUBS: Vec3[] = [[0.3, 0, 0.3], [-0.3, 0, 0.3], [0.3, 0, -0.3], [-0.3, 0, -0.3]]
function hover(ctx: Ctx) {
const body = ctx.body
if (!body) return
if (ctx.props["rotors"] !== true) {
body.addForce([0, body.mass * 9.81, 0])
return
}
for (const h of HUBS) body.addForceAtPoint([0, (body.mass * 9.81) / 4, 0], h, "local")
body.addTorque([0, (ctx.props["yaw"] as number | undefined) ?? 0, 0], "local")
}
export default {
// The first physics step runs before the first update; this is its thrust.
init(ctx) { hover(ctx) },
update(ctx) { hover(ctx) },
} satisfies Behavior