From 1e3543752f47a6a98ddd8cf1f69e605888e823c7 Mon Sep 17 00:00:00 2001 From: "chappuis.daniel" Date: Thu, 30 Jun 2011 20:12:37 +0000 Subject: [PATCH] Add ConeShape git-svn-id: https://reactphysics3d.googlecode.com/svn/trunk@427 92aac97c-a6ce-11dd-a772-7fcde58d38e6 --- src/body/ConeShape.cpp | 1 + src/body/ConeShape.h | 107 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 src/body/ConeShape.cpp create mode 100644 src/body/ConeShape.h diff --git a/src/body/ConeShape.cpp b/src/body/ConeShape.cpp new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/src/body/ConeShape.cpp @@ -0,0 +1 @@ + diff --git a/src/body/ConeShape.h b/src/body/ConeShape.h new file mode 100644 index 00000000..de2a09e5 --- /dev/null +++ b/src/body/ConeShape.h @@ -0,0 +1,107 @@ +/******************************************************************************** +* ReactPhysics3D physics library, http://code.google.com/p/reactphysics3d/ * +* Copyright (c) 2011 Daniel Chappuis * +********************************************************************************* +* * +* Permission is hereby granted, free of charge, to any person obtaining a copy * +* of this software and associated documentation files (the "Software"), to deal * +* in the Software without restriction, including without limitation the rights * +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * +* copies of the Software, and to permit persons to whom the Software is * +* furnished to do so, subject to the following conditions: * +* * +* The above copyright notice and this permission notice shall be included in * +* all copies or substantial portions of the Software. * +* * +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * +* THE SOFTWARE. * +********************************************************************************/ + +#ifndef BOUNDING_CONE_H +#define BOUNDING_CONE_H + +// Libraries +#include "NarrowBoundingVolume.h" +#include "../mathematics/mathematics.h" + +// ReactPhysics3D namespace +namespace reactphysics3d { + +/* ------------------------------------------------------------------- + Class ConeShape : + This class represents a cone bounding volume. + ------------------------------------------------------------------- +*/ +class ConeShape : public NarrowBoundingVolume { + protected : + Vector3D center; // Center point of the sphere + double radius; // Radius of the sphere + + public : + ConeShape(const Vector3D& center, double radius); // Constructor + virtual ~ConeShape(); // Destructor + + Vector3D getCenter() const; // Return the center point of the sphere + void setCenter(const Vector3D& center); // Set the center point of the sphere + double getRadius() const; // Return the radius of the sphere + void setRadius(double radius); // Set the radius of the sphere + virtual void update(const Vector3D& newCenter, + const Quaternion& rotationQuaternion); // Update the sphere orientation according to a new orientation of the rigid body + virtual AABB* computeAABB() const; // Return the corresponding AABB + virtual Vector3D getSupportPoint(const Vector3D& direction, double margin=0.0) const; // Return a support point in a given direction + +#ifdef VISUAL_DEBUG + virtual void draw() const; // Draw the sphere (only for testing purpose) +#endif +}; + +// Return the center point of the sphere +inline Vector3D BoundingSphere::getCenter() const { + return center; +} + +// Set the center point of the sphere +inline void BoundingSphere::setCenter(const Vector3D& center) { + this->center = center; +} + +// Get the radius of the sphere +inline double BoundingSphere::getRadius() const { + return radius; +} + +// Set the radius of the sphere +inline void BoundingSphere::setRadius(double radius) { + this->radius = radius; +} + +// Update the orientation of the shere according to the orientation of the rigid body +inline void BoundingSphere::update(const Vector3D& newCenter, const Quaternion& rotationQuaternion) { + // Update the center of the sphere + center = newCenter; +} + +// Return a support point in a given direction +inline Vector3D BoundingSphere::getSupportPoint(const Vector3D& direction, double margin) const { + assert(margin >= 0.0); + double length = direction.length(); + + // If the direction vector is not the zero vector + if (length > EPSILON) { + // Return the support point of the sphere in the given direction + return center + (radius + margin) * direction.getUnit(); + } + + // If the direction vector is the zero vector we return a point on the + // boundary of the sphere + return center + Vector3D(radius + margin, 0.0, 0.0); +} + +}; // End of the ReactPhysics3D namespace + +#endif \ No newline at end of file