Skip to content

Commit 43d2393

Browse files
Add rigidBody.velocityAtPoint (#305)
* Add rigidBody.velocityAtPoint * Add changelog entry * fix: free wasm vector in RigidBody.velocityAtPoint. --------- Co-authored-by: Sébastien Crozet <[email protected]>
1 parent 083a866 commit 43d2393

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030

3131

3232

33+
#### Added
34+
35+
- Added `RigidBody.velocityAtPoint` function to retrieve the velocity of a given world-space point on a rigid-body.
36+
3337
### 0.14.0 (20 July 2024)
3438

3539
#### Modified

src.ts/dynamics/rigid_body.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,18 @@ export class RigidBody {
507507
return VectorOps.fromRaw(this.rawSet.rbLinvel(this.handle));
508508
}
509509

510+
/**
511+
* The velocity of the given world-space point on this rigid-body.
512+
*/
513+
public velocityAtPoint(point: Vector): Vector {
514+
const rawPoint = VectorOps.intoRaw(point);
515+
let result = VectorOps.fromRaw(
516+
this.rawSet.rbVelocityAtPoint(this.handle, rawPoint),
517+
);
518+
rawPoint.free();
519+
return result;
520+
}
521+
510522
// #if DIM3
511523
/**
512524
* The angular velocity of this rigid-body.

src/dynamics/rigid_body.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::geometry::RawColliderSet;
44
use crate::math::RawSdpMatrix3;
55
use crate::math::{RawRotation, RawVector};
66
use crate::utils::{self, FlatHandle};
7+
use na::Point;
78
use rapier::dynamics::MassProperties;
89
use wasm_bindgen::prelude::*;
910

@@ -297,6 +298,13 @@ impl RawRigidBodySet {
297298
self.map(handle, |rb| RawVector(*rb.angvel()))
298299
}
299300

301+
/// The velocity of the given world-space point on this rigid-body.
302+
pub fn rbVelocityAtPoint(&self, handle: FlatHandle, point: &RawVector) -> RawVector {
303+
self.map(handle, |rb| {
304+
rb.velocity_at_point(&Point::from(point.0)).into()
305+
})
306+
}
307+
300308
pub fn rbLockTranslations(&mut self, handle: FlatHandle, locked: bool, wake_up: bool) {
301309
self.map_mut(handle, |rb| rb.lock_translations(locked, wake_up))
302310
}

0 commit comments

Comments
 (0)