mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 18:23:54 +02:00
add ShapeInfo::computeVolume()
This commit is contained in:
parent
dd2421ffcd
commit
8236837dd0
2 changed files with 36 additions and 0 deletions
|
@ -24,18 +24,21 @@ void ShapeInfo::clear() {
|
|||
void ShapeInfo::setBox(const glm::vec3& halfExtents) {
|
||||
_type = BOX_SHAPE;
|
||||
_data.clear();
|
||||
// _data[0] = < halfX, halfY, halfZ >
|
||||
_data.push_back(halfExtents);
|
||||
}
|
||||
|
||||
void ShapeInfo::setSphere(float radius) {
|
||||
_type = SPHERE_SHAPE;
|
||||
_data.clear();
|
||||
// _data[0] = < radius, radius, radius >
|
||||
_data.push_back(glm::vec3(radius));
|
||||
}
|
||||
|
||||
void ShapeInfo::setCylinder(float radius, float halfHeight) {
|
||||
_type = CYLINDER_SHAPE;
|
||||
_data.clear();
|
||||
// _data[0] = < radius, halfHeight, radius >
|
||||
// NOTE: default cylinder has (UpAxis = 1) axis along yAxis and radius stored in X
|
||||
_data.push_back(glm::vec3(radius, halfHeight, radius));
|
||||
}
|
||||
|
@ -43,6 +46,7 @@ void ShapeInfo::setCylinder(float radius, float halfHeight) {
|
|||
void ShapeInfo::setCapsule(float radius, float halfHeight) {
|
||||
_type = CAPSULE_SHAPE;
|
||||
_data.clear();
|
||||
// _data[0] = < radius, halfHeight, radius >
|
||||
_data.push_back(glm::vec3(radius, halfHeight, radius));
|
||||
}
|
||||
|
||||
|
@ -58,3 +62,34 @@ glm::vec3 ShapeInfo::getBoundingBoxDiagonal() const {
|
|||
}
|
||||
return glm::vec3(0.0f);
|
||||
}
|
||||
|
||||
float ShapeInfo::computeVolume() const {
|
||||
const float DEFAULT_VOLUME = 1.0f;
|
||||
float volume = DEFAULT_VOLUME;
|
||||
switch(_type) {
|
||||
case BOX_SHAPE: {
|
||||
// factor of 8.0 because the components of _data[0] are all halfExtents
|
||||
volume = 8.0f * _data[0].x * _data[0].y * _data[0].z;
|
||||
break;
|
||||
}
|
||||
case SPHERE_SHAPE: {
|
||||
float radius = _data[0].x;
|
||||
volume = 4.0f * PI * radius * radius * radius / 3.0f;
|
||||
break;
|
||||
}
|
||||
case CYLINDER_SHAPE: {
|
||||
float radius = _data[0].x;
|
||||
volume = PI * radius * radius * 2.0f * _data[0].y;
|
||||
break;
|
||||
}
|
||||
case CAPSULE_SHAPE: {
|
||||
float radius = _data[0].x;
|
||||
volume = PI * radius * radius * (2.0f * _data[0].y + 4.0f * radius / 3.0f);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
assert(volume > 0.0f);
|
||||
return volume;
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ public:
|
|||
const QVector<glm::vec3>& getData() const { return _data; }
|
||||
|
||||
glm::vec3 getBoundingBoxDiagonal() const;
|
||||
float computeVolume() const;
|
||||
|
||||
protected:
|
||||
int _type;
|
||||
|
|
Loading…
Reference in a new issue