|
@@ -1057,9 +1057,21 @@ PhysicsCollisionShape* PhysicsController::createHeightfield(Node* node, Image* i
|
|
|
{
|
|
{
|
|
|
for (unsigned int y = 0, h = image->getHeight(); y < h; ++y)
|
|
for (unsigned int y = 0, h = image->getHeight(); y < h; ++y)
|
|
|
{
|
|
{
|
|
|
- heights[x + y * w] = ((((float)data[(x + y * h) * pixelSize + 0]) +
|
|
|
|
|
- ((float)data[(x + y * h) * pixelSize + 1]) +
|
|
|
|
|
- ((float)data[(x + y * h) * pixelSize + 2])) / 768.0f) * (maxHeight - minHeight) + minHeight;
|
|
|
|
|
|
|
+ //
|
|
|
|
|
+ // Orignially in GamePlay this was normalizedHeightGrayscale which generally yielded
|
|
|
|
|
+ // only 8-bit precision. This has been replaced by normalizedHeightPacked (with a
|
|
|
|
|
+ // corresponding change in gameplay-encoder).
|
|
|
|
|
+ //
|
|
|
|
|
+ // BACKWARD COMPATIBILITY
|
|
|
|
|
+ // In grayscale images where r=g=b this will maintain some degree of compatibility,
|
|
|
|
|
+ // to within 0.4%. This can be seen by setting r=g=b=x and comparing the grayscale
|
|
|
|
|
+ // height expression to the packed height expression: the error is 2^-8 + 2^-16
|
|
|
|
|
+ // which is just under 0.4%.
|
|
|
|
|
+ //
|
|
|
|
|
+ heights[x + y * w] = normalizedHeightPacked(
|
|
|
|
|
+ data[(x + y * h) * pixelSize + 0],
|
|
|
|
|
+ data[(x + y * h) * pixelSize + 1],
|
|
|
|
|
+ data[(x + y * h) * pixelSize + 2]) * (maxHeight - minHeight) + minHeight;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1382,6 +1394,16 @@ float PhysicsController::calculateHeight(float* data, unsigned int width, unsign
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+float PhysicsController::normalizedHeightGrayscale(float r, float g, float b)
|
|
|
|
|
+{
|
|
|
|
|
+ return (r + g + b) / 768.0f;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+float PhysicsController::normalizedHeightPacked(float r, float g, float b)
|
|
|
|
|
+{
|
|
|
|
|
+ return (256.0f*r + g + 0.00390625f*b) / 65536.0f;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
void PhysicsController::addConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b, PhysicsConstraint* constraint)
|
|
void PhysicsController::addConstraint(PhysicsRigidBody* a, PhysicsRigidBody* b, PhysicsConstraint* constraint)
|
|
|
{
|
|
{
|
|
|
GP_ASSERT(a);
|
|
GP_ASSERT(a);
|