Prior to using Bullet, I was using SceneKit's built-in physics engine for my iOS projects. SceneKit expresses a rigid body's angular velocity as a 4D vector, where the x,y,z components describe the axis the body is currently rotating around, and the fourth w component specifies the speed the body is rotating around this axis (in radians/s I believe, but that's irrelevant to my question).
From what I understand, Bullet expresses a rigid body's angular velocity as a 3D vector, where the x, y and z components represent a rotation around the body's local x, y and z axis (a yaw, pitch, roll rotation).
I've been building a bullet physics wrapper for Swift, with support for wiring the simulation up to SceneKit, and I would like to consolidate the bridge between these 2 values (I would like users to be able to specify a 4D vector as they are used to with SceneKit, and have that get converted to the 3D vector Bullet expects).
I'm having a hard time visualizing this, and can't find much online. Are there any existing solutions out there for working with 4D vectors for angular velocities in bullet?
Thanks,
- Adam
Convert vec3 AngularVelocity to vec4?
-
- Posts: 849
- Joined: Tue Sep 30, 2014 6:03 pm
- Location: San Francisco
Re: Convert vec3 AngularVelocity to vec4?
That is incorrect. Bullet stores angular velocity as a 3D vector which points along the axis of rotation (as per the right-hand rule) and whose length is equal to the angular speed (in radians per second). The benefit of this format is: adding two angular velocities is done via simple 3D vector math.From what I understand, Bullet expresses a rigid body's angular velocity as a 3D vector, where the x, y and z components represent a rotation around the body's local x, y and z axis (a yaw, pitch, roll rotation).
To convert angular velocity from Bullet to SceneKit you would compute the length and store that in w then divide Bullet's x, y, and z components by the the length (*) to get SceneKit's normalized axis.
(*) Please don't divide by zero.
-
- Posts: 6
- Joined: Tue Jun 16, 2020 6:11 pm
Re: Convert vec3 AngularVelocity to vec4?
Ah I see, this makes much more sense! Thank you for the quick response.