From e8724b02f307e8f265cd08dc79d6a2cd17813d43 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 6 Jun 2014 08:50:57 -0700 Subject: [PATCH] add CapsuleShape::setEndPoints() --- libraries/shared/src/CapsuleShape.cpp | 32 +++++++++++++++------------ libraries/shared/src/CapsuleShape.h | 1 + 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/libraries/shared/src/CapsuleShape.cpp b/libraries/shared/src/CapsuleShape.cpp index 11bd70f8d2..8e887107dc 100644 --- a/libraries/shared/src/CapsuleShape.cpp +++ b/libraries/shared/src/CapsuleShape.cpp @@ -33,20 +33,7 @@ CapsuleShape::CapsuleShape(float radius, float halfHeight, const glm::vec3& posi CapsuleShape::CapsuleShape(float radius, const glm::vec3& startPoint, const glm::vec3& endPoint) : Shape(Shape::CAPSULE_SHAPE), _radius(radius), _halfHeight(0.0f) { - glm::vec3 axis = endPoint - startPoint; - _position = 0.5f * (endPoint + startPoint); - float height = glm::length(axis); - if (height > EPSILON) { - _halfHeight = 0.5f * height; - axis /= height; - glm::vec3 yAxis(0.0f, 1.0f, 0.0f); - float angle = glm::angle(axis, yAxis); - if (angle > EPSILON) { - axis = glm::normalize(glm::cross(yAxis, axis)); - _rotation = glm::angleAxis(angle, axis); - } - } - updateBoundingRadius(); + setEndPoints(startPoint, endPoint); } /// \param[out] startPoint is the center of start cap @@ -80,3 +67,20 @@ void CapsuleShape::setRadiusAndHalfHeight(float radius, float halfHeight) { updateBoundingRadius(); } +void CapsuleShape::setEndPoints(const glm::vec3& startPoint, const glm::vec3& endPoint) { + glm::vec3 axis = endPoint - startPoint; + _position = 0.5f * (endPoint + startPoint); + float height = glm::length(axis); + if (height > EPSILON) { + _halfHeight = 0.5f * height; + axis /= height; + glm::vec3 yAxis(0.0f, 1.0f, 0.0f); + float angle = glm::angle(axis, yAxis); + if (angle > EPSILON) { + axis = glm::normalize(glm::cross(yAxis, axis)); + _rotation = glm::angleAxis(angle, axis); + } + } + updateBoundingRadius(); +} + diff --git a/libraries/shared/src/CapsuleShape.h b/libraries/shared/src/CapsuleShape.h index 0889f6b2f3..756ae18911 100644 --- a/libraries/shared/src/CapsuleShape.h +++ b/libraries/shared/src/CapsuleShape.h @@ -37,6 +37,7 @@ public: void setRadius(float radius); void setHalfHeight(float height); void setRadiusAndHalfHeight(float radius, float height); + void setEndPoints(const glm::vec3& startPoint, const glm::vec3& endPoint); protected: void updateBoundingRadius() { _boundingRadius = _radius + _halfHeight; }