mirror of https://github.com/bjornbytes/lovr.git
Merge pull request #763 from jmiskovic/fix/jolt-setmass
Fix setMass; correct terrain sampling
This commit is contained in:
commit
72e042f6ae
|
@ -114,8 +114,8 @@ Shape* luax_newterrainshape(lua_State* L, int index) {
|
||||||
uint32_t n = luax_optu32(L, index + 1, 100);
|
uint32_t n = luax_optu32(L, index + 1, 100);
|
||||||
float* vertices = lovrMalloc(sizeof(float) * n * n);
|
float* vertices = lovrMalloc(sizeof(float) * n * n);
|
||||||
for (uint32_t i = 0; i < n * n; i++) {
|
for (uint32_t i = 0; i < n * n; i++) {
|
||||||
float x = scaleXZ * (-.5f + ((float) (i % n)) / n);
|
float x = scaleXZ * (-.5f + ((float) (i % n)) / (n - 1));
|
||||||
float z = scaleXZ * (-.5f + ((float) (i / n)) / n);
|
float z = scaleXZ * (-.5f + ((float) (i / n)) / (n - 1));
|
||||||
lua_pushvalue(L, index);
|
lua_pushvalue(L, index);
|
||||||
lua_pushnumber(L, x);
|
lua_pushnumber(L, x);
|
||||||
lua_pushnumber(L, z);
|
lua_pushnumber(L, z);
|
||||||
|
|
|
@ -623,10 +623,10 @@ float lovrColliderGetMass(Collider* collider) {
|
||||||
void lovrColliderSetMass(Collider* collider, float mass) {
|
void lovrColliderSetMass(Collider* collider, float mass) {
|
||||||
JPH_MotionProperties* motionProperties = JPH_Body_GetMotionProperties(collider->body);
|
JPH_MotionProperties* motionProperties = JPH_Body_GetMotionProperties(collider->body);
|
||||||
Shape* shape = collider->shape;
|
Shape* shape = collider->shape;
|
||||||
JPH_MassProperties* massProperties;
|
JPH_MassProperties massProperties;
|
||||||
JPH_Shape_GetMassProperties(shape->shape, massProperties);
|
JPH_Shape_GetMassProperties(shape->shape, &massProperties);
|
||||||
JPH_MassProperties_ScaleToMass(massProperties, mass);
|
JPH_MassProperties_ScaleToMass(&massProperties, mass);
|
||||||
JPH_MotionProperties_SetMassProperties(motionProperties, JPH_AllowedDOFs_All, massProperties);
|
JPH_MotionProperties_SetMassProperties(motionProperties, JPH_AllowedDOFs_All, &massProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lovrColliderGetMassData(Collider* collider, float centerOfMass[3], float* mass, float inertia[6]) {
|
void lovrColliderGetMassData(Collider* collider, float centerOfMass[3], float* mass, float inertia[6]) {
|
||||||
|
@ -964,9 +964,9 @@ TerrainShape* lovrTerrainShapeCreate(float* vertices, uint32_t n, float scaleXZ,
|
||||||
.z = -.5f * scaleXZ
|
.z = -.5f * scaleXZ
|
||||||
};
|
};
|
||||||
const JPH_Vec3 scale = {
|
const JPH_Vec3 scale = {
|
||||||
.x = scaleXZ / n,
|
.x = scaleXZ / (n - 1),
|
||||||
.y = scaleY,
|
.y = scaleY,
|
||||||
.z = scaleXZ / n
|
.z = scaleXZ / (n - 1)
|
||||||
};
|
};
|
||||||
|
|
||||||
JPH_HeightFieldShapeSettings* shape_settings = JPH_HeightFieldShapeSettings_Create(vertices, &offset, &scale, n);
|
JPH_HeightFieldShapeSettings* shape_settings = JPH_HeightFieldShapeSettings_Create(vertices, &offset, &scale, n);
|
||||||
|
|
Loading…
Reference in New Issue