lxq100
March 1, 2024, 8:08am
1
code
If not provided, the physics engine will compute an appropriate value.
I want to know how this value is calculated. I need codes
Cedric
March 1, 2024, 10:41am
2
Mass properties are computed here :
break;
case PhysicsActivationControl.ALWAYS_INACTIVE:
this._hknp.HP_Body_SetActivationControl(body._pluginData.hpBodyId, this._hknp.ActivationControl.ALWAYS_INACTIVE);
break;
case PhysicsActivationControl.SIMULATION_CONTROLLED:
this._hknp.HP_Body_SetActivationControl(body._pluginData.hpBodyId, this._hknp.ActivationControl.SIMULATION_CONTROLLED);
break;
}
}
private _internalComputeMassProperties(pluginData: BodyPluginData): any[] {
const shapeRes = this._hknp.HP_Body_GetShape(pluginData.hpBodyId);
if (shapeRes[0] == this._hknp.Result.RESULT_OK) {
const shapeMass = this._hknp.HP_Shape_BuildMassProperties(shapeRes[1]);
if (shapeMass[0] == this._hknp.Result.RESULT_OK) {
return shapeMass[1];
}
}
// Failed; return a unit inertia
return [[0, 0, 0], 1, [1, 1, 1], [0, 0, 0, 1]];
You can change default density of a shape with
restitutionCombine: this._nativeToMaterialCombine(hkMaterial[4]),
};
}
/**
* Sets the density of a physics shape.
* @param shape - The physics shape to set the density of.
* @param density - The density to set.
*
*/
public setDensity(shape: PhysicsShape, density: number): void {
this._hknp.HP_Shape_SetDensity(shape._pluginData, density);
}
/**
* Calculates the density of a given physics shape.
*
* @param shape - The physics shape to calculate the density of.
* @returns The density of the given physics shape.
*
*/
lxq100
March 2, 2024, 7:44am
3
If I set mass=20、 centerOfMass==[0,-0.5, 0] and inertia=[1,0,1].
Will inertia be affected by mass centerOfMass and then be recalculated?
After the physical body is created, is the value of inertia calculated based on the mass center of mass or set by the user [1,0,1]?
Cedric
March 4, 2024, 11:00am
4
Defaults values are computed and are then overriden by what user provides :