Ver código fonte

Added more basic collision shapes.

Lasse Öörni 13 anos atrás
pai
commit
3d273cc15e

+ 19 - 0
Engine/Engine/PhysicsAPI.cpp

@@ -24,10 +24,13 @@
 #include "Precompiled.h"
 #include "APITemplates.h"
 #include "BoxShape.h"
+#include "CapsuleShape.h"
+#include "CylinderShape.h"
 #include "Joint.h"
 #include "PhysicsWorld.h"
 #include "RigidBody.h"
 #include "Scene.h"
+#include "SphereShape.h"
 
 static PhysicsWorld* SceneGetPhysicsWorld(Scene* ptr)
 {
@@ -68,6 +71,22 @@ static void RegisterCollisionShapes(asIScriptEngine* engine)
     engine->RegisterObjectMethod("BoxShape", "void set_size(const Vector3&in)", asMETHOD(BoxShape, SetSize), asCALL_THISCALL);
     engine->RegisterObjectMethod("BoxShape", "const Vector3& get_size() const", asMETHOD(BoxShape, GetSize), asCALL_THISCALL);
     
+    RegisterCollisionShape<CapsuleShape>(engine, "CapsuleShape");
+    engine->RegisterObjectMethod("CapsuleShape", "void set_radius(float)", asMETHOD(CapsuleShape, SetRadius), asCALL_THISCALL);
+    engine->RegisterObjectMethod("CapsuleShape", "float get_radius() const", asMETHOD(CapsuleShape, GetRadius), asCALL_THISCALL);
+    engine->RegisterObjectMethod("CapsuleShape", "void set_height(float)", asMETHOD(CapsuleShape, SetHeight), asCALL_THISCALL);
+    engine->RegisterObjectMethod("CapsuleShape", "float get_height() const", asMETHOD(CapsuleShape, GetHeight), asCALL_THISCALL);
+    
+    RegisterCollisionShape<CylinderShape>(engine, "CylinderShape");
+    engine->RegisterObjectMethod("CylinderShape", "void set_radius(float)", asMETHOD(CylinderShape, SetRadius), asCALL_THISCALL);
+    engine->RegisterObjectMethod("CylinderShape", "float get_radius() const", asMETHOD(CylinderShape, GetRadius), asCALL_THISCALL);
+    engine->RegisterObjectMethod("CylinderShape", "void set_height(float)", asMETHOD(CylinderShape, SetHeight), asCALL_THISCALL);
+    engine->RegisterObjectMethod("CylinderShape", "float get_height() const", asMETHOD(CylinderShape, GetHeight), asCALL_THISCALL);
+    
+    RegisterCollisionShape<SphereShape>(engine, "SphereShape");
+    engine->RegisterObjectMethod("SphereShape", "void set_radius(float)", asMETHOD(SphereShape, SetRadius), asCALL_THISCALL);
+    engine->RegisterObjectMethod("SphereShape", "float get_radius() const", asMETHOD(SphereShape, GetRadius), asCALL_THISCALL);
+    
     // Register Variant GetPtr() for CollisionShape
     engine->RegisterObjectMethod("Variant", "CollisionShape@+ GetCollisionShape() const", asFUNCTION(GetVariantPtr<CollisionShape>), asCALL_CDECL_OBJLAST);
 }

+ 0 - 14
Engine/Physics/BoxShape.cpp

@@ -33,19 +33,10 @@ OBJECTTYPESTATIC(BoxShape);
 
 BoxShape::BoxShape(Context* context) :
     CollisionShape(context),
-    shape_(0),
     size_(Vector3::ONE)
 {
 }
 
-BoxShape::~BoxShape()
-{
-    delete shape_;
-    shape_ = 0;
-    
-    NotifyRigidBody();
-}
-
 void BoxShape::RegisterObject(Context* context)
 {
     context->RegisterFactory<BoxShape>();
@@ -55,11 +46,6 @@ void BoxShape::RegisterObject(Context* context)
     ATTRIBUTE(BoxShape, VAR_VECTOR3, "Size", size_, Vector3::ONE, AM_DEFAULT);
 }
 
-btCollisionShape* BoxShape::GetCollisionShape() const
-{
-    return shape_;
-}
-
 void BoxShape::SetSize(const Vector3& size)
 {
     if (size != size_)

+ 0 - 9
Engine/Physics/BoxShape.h

@@ -25,8 +25,6 @@
 
 #include "CollisionShape.h"
 
-class btBoxShape;
-
 /// Box collision shape component.
 class BoxShape : public CollisionShape
 {
@@ -35,14 +33,9 @@ class BoxShape : public CollisionShape
 public:
     /// Construct.
     BoxShape(Context* context);
-    /// Destruct.
-    ~BoxShape();
     /// Register object factory.
     static void RegisterObject(Context* context);
     
-    /// Return Bullet collision shape.
-    virtual btCollisionShape* GetCollisionShape() const;
-    
     /// %Set box size.
     void SetSize(const Vector3& size);
     /// Return box size.
@@ -53,8 +46,6 @@ protected:
     virtual void UpdateCollisionShape();
     
 private:
-    /// Box collision shape.
-    btBoxShape* shape_;
     /// Box size.
     Vector3 size_;
 };

+ 84 - 0
Engine/Physics/CapsuleShape.cpp

@@ -0,0 +1,84 @@
+//
+// Urho3D Engine
+// Copyright (c) 2008-2012 Lasse Öörni
+//
+// 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.
+//
+
+#include "Precompiled.h"
+#include "CapsuleShape.h"
+#include "Context.h"
+#include "Node.h"
+#include "PhysicsUtils.h"
+
+#include <BulletCollision/CollisionShapes/btCapsuleShape.h>
+
+OBJECTTYPESTATIC(CapsuleShape);
+
+static const float DEFAULT_RADIUS = 0.5f;
+static const float DEFAULT_HEIGHT = 1.0f;
+
+CapsuleShape::CapsuleShape(Context* context) :
+    CollisionShape(context),
+    radius_(DEFAULT_RADIUS),
+    height_(DEFAULT_HEIGHT)
+{
+}
+
+void CapsuleShape::RegisterObject(Context* context)
+{
+    context->RegisterFactory<CapsuleShape>();
+    
+    ATTRIBUTE(CapsuleShape, VAR_VECTOR3, "Offset Position", position_, Vector3::ZERO, AM_DEFAULT);
+    ATTRIBUTE(CapsuleShape, VAR_QUATERNION, "Offset Rotation", rotation_, Quaternion::IDENTITY, AM_DEFAULT);
+    ATTRIBUTE(CapsuleShape, VAR_FLOAT, "Radius", radius_, DEFAULT_RADIUS, AM_DEFAULT);
+    ATTRIBUTE(CapsuleShape, VAR_FLOAT, "Height", height_, DEFAULT_HEIGHT, AM_DEFAULT);
+}
+
+void CapsuleShape::SetRadius(float radius)
+{
+    if (radius != radius_)
+    {
+        radius_ = radius;
+        UpdateCollisionShape();
+        NotifyRigidBody();
+    }
+}
+
+void CapsuleShape::SetHeight(float height)
+{
+    if (height != height_)
+    {
+        height_ = height;
+        UpdateCollisionShape();
+        NotifyRigidBody();
+    }
+}
+
+void CapsuleShape::UpdateCollisionShape()
+{
+    if (node_)
+    {
+        delete shape_;
+        shape_ = 0;
+        
+        shape_ = new btCapsuleShape(radius_, Max(height_ - 2.0f * radius_, 0.0f));
+        shape_->setLocalScaling(ToBtVector3(node_->GetWorldScale()));
+    }
+}

+ 58 - 0
Engine/Physics/CapsuleShape.h

@@ -0,0 +1,58 @@
+//
+// Urho3D Engine
+// Copyright (c) 2008-2012 Lasse Öörni
+//
+// 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.
+//
+
+#pragma once
+
+#include "CollisionShape.h"
+
+/// Capsule collision shape component.
+class CapsuleShape : public CollisionShape
+{
+    OBJECT(CapsuleShape);
+    
+public:
+    /// Construct.
+    CapsuleShape(Context* context);
+    /// Register object factory.
+    static void RegisterObject(Context* context);
+    
+    /// %Set capsule radius.
+    void SetRadius(float radius);
+    /// %Set capsule height.
+    void SetHeight(float height);
+    
+    /// Return capsule radius.
+    float GetRadius() const { return radius_; }
+    /// Return capsule height.
+    float GetHeight() const { return height_; }
+    
+protected:
+    /// Update the collision shape.
+    virtual void UpdateCollisionShape();
+    
+private:
+    /// Capsule radius.
+    float radius_;
+    /// Capsule height.
+    float height_;
+};

+ 24 - 10
Engine/Physics/CollisionShape.cpp

@@ -256,6 +256,7 @@ OBJECTTYPESTATIC(CollisionShape);
 
 CollisionShape::CollisionShape(Context* context) :
     Component(context),
+    shape_(0),
     position_(Vector3::ZERO),
     rotation_(Quaternion::IDENTITY),
     cachedWorldScale_(Vector3::ONE),
@@ -265,6 +266,11 @@ CollisionShape::CollisionShape(Context* context) :
 
 CollisionShape::~CollisionShape()
 {
+    delete shape_;
+    shape_ = 0;
+    
+    NotifyRigidBody();
+    
     if (physicsWorld_)
         physicsWorld_->RemoveCollisionShape(this);
 }
@@ -286,21 +292,30 @@ void CollisionShape::ApplyAttributes()
 
 void CollisionShape::SetPosition(const Vector3& position)
 {
-    position_ = position;
-    NotifyRigidBody();
+    if (position != position_)
+    {
+        position_ = position;
+        NotifyRigidBody();
+    }
 }
 
 void CollisionShape::SetRotation(const Quaternion& rotation)
 {
-    rotation_ = rotation;
-    NotifyRigidBody();
+    if (rotation != rotation_)
+    {
+        rotation_ = rotation;
+        NotifyRigidBody();
+    }
 }
 
 void CollisionShape::SetTransform(const Vector3& position, const Quaternion& rotation)
 {
-    position_ = position;
-    rotation_ = rotation;
-    NotifyRigidBody();
+    if (position != position_ || rotation != rotation_)
+    {
+        position_ = position;
+        rotation_ = rotation;
+        NotifyRigidBody();
+    }
 }
 
 void CollisionShape::DrawDebugGeometry(DebugRenderer* debug, bool depthTest)
@@ -330,9 +345,8 @@ void CollisionShape::OnMarkedDirty(Node* node)
     Vector3 newWorldScale = node_->GetWorldScale();
     if (newWorldScale != cachedWorldScale_)
     {
-        btCollisionShape* shape = GetCollisionShape();
-        if (shape)
-            shape->setLocalScaling(ToBtVector3(newWorldScale));
+        if (shape_)
+            shape_->setLocalScaling(ToBtVector3(newWorldScale));
         NotifyRigidBody();
         
         cachedWorldScale_ = newWorldScale;

+ 6 - 4
Engine/Physics/CollisionShape.h

@@ -86,21 +86,21 @@ public:
     virtual void OnSetAttribute(const AttributeInfo& attr, const Variant& src);
     /// Apply attribute changes that can not be applied immediately. Called after scene load or a network update.
     virtual void ApplyAttributes();
-    /// Return Bullet collision shape.
-    virtual btCollisionShape* GetCollisionShape() const = 0;
     
     /// %Set offset position.
     void SetPosition(const Vector3& position);
-    /// %Set rotation.
+    /// %Set offset rotation.
     void SetRotation(const Quaternion& rotation);
     /// %Set offset transform.
     void SetTransform(const Vector3& position, const Quaternion& rotation);
     
+    /// Return Bullet collision shape
+    btCollisionShape* GetCollisionShape() const { return shape_; }
     /// Return physics world.
     PhysicsWorld* GetPhysicsWorld() const { return physicsWorld_; }
     /// Return offset position.
     const Vector3& GetPosition() const { return position_; }
-    /// Return rotation.
+    /// Return offset rotation.
     const Quaternion& GetRotation() const { return rotation_; }
     
     /// Add debug geometry to the debug renderer.
@@ -120,6 +120,8 @@ protected:
     WeakPtr<PhysicsWorld> physicsWorld_;
     /// Rigid body.
     WeakPtr<RigidBody> rigidBody_;
+    /// Bullet collision shape.
+    btCollisionShape* shape_;
     /// Offset position.
     Vector3 position_;
     /// Offset rotation.

+ 84 - 0
Engine/Physics/CylinderShape.cpp

@@ -0,0 +1,84 @@
+//
+// Urho3D Engine
+// Copyright (c) 2008-2012 Lasse Öörni
+//
+// 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.
+//
+
+#include "Precompiled.h"
+#include "CylinderShape.h"
+#include "Context.h"
+#include "Node.h"
+#include "PhysicsUtils.h"
+
+#include <BulletCollision/CollisionShapes/btCylinderShape.h>
+
+OBJECTTYPESTATIC(CylinderShape);
+
+static const float DEFAULT_RADIUS = 0.5f;
+static const float DEFAULT_HEIGHT = 1.0f;
+
+CylinderShape::CylinderShape(Context* context) :
+    CollisionShape(context),
+    radius_(DEFAULT_RADIUS),
+    height_(DEFAULT_HEIGHT)
+{
+}
+
+void CylinderShape::RegisterObject(Context* context)
+{
+    context->RegisterFactory<CylinderShape>();
+    
+    ATTRIBUTE(CylinderShape, VAR_VECTOR3, "Offset Position", position_, Vector3::ZERO, AM_DEFAULT);
+    ATTRIBUTE(CylinderShape, VAR_QUATERNION, "Offset Rotation", rotation_, Quaternion::IDENTITY, AM_DEFAULT);
+    ATTRIBUTE(CylinderShape, VAR_FLOAT, "Radius", radius_, DEFAULT_RADIUS, AM_DEFAULT);
+    ATTRIBUTE(CylinderShape, VAR_FLOAT, "Height", height_, DEFAULT_HEIGHT, AM_DEFAULT);
+}
+
+void CylinderShape::SetRadius(float radius)
+{
+    if (radius != radius_)
+    {
+        radius_ = radius;
+        UpdateCollisionShape();
+        NotifyRigidBody();
+    }
+}
+
+void CylinderShape::SetHeight(float height)
+{
+    if (height != height_)
+    {
+        height_ = height;
+        UpdateCollisionShape();
+        NotifyRigidBody();
+    }
+}
+
+void CylinderShape::UpdateCollisionShape()
+{
+    if (node_)
+    {
+        delete shape_;
+        shape_ = 0;
+        
+        shape_ = new btCylinderShape(btVector3(radius_, height_ * 0.5f, radius_));
+        shape_->setLocalScaling(ToBtVector3(node_->GetWorldScale()));
+    }
+}

+ 58 - 0
Engine/Physics/CylinderShape.h

@@ -0,0 +1,58 @@
+//
+// Urho3D Engine
+// Copyright (c) 2008-2012 Lasse Öörni
+//
+// 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.
+//
+
+#pragma once
+
+#include "CollisionShape.h"
+
+/// Cylinder collision shape component.
+class CylinderShape : public CollisionShape
+{
+    OBJECT(CylinderShape);
+    
+public:
+    /// Construct.
+    CylinderShape(Context* context);
+    /// Register object factory.
+    static void RegisterObject(Context* context);
+    
+    /// %Set cylinder radius.
+    void SetRadius(float radius);
+    /// %Set cylinder height.
+    void SetHeight(float height);
+    
+    /// Return cylinder radius.
+    float GetRadius() const { return radius_; }
+    /// Return cylinder height.
+    float GetHeight() const { return height_; }
+    
+protected:
+    /// Update the collision shape.
+    virtual void UpdateCollisionShape();
+    
+private:
+    /// Cylinder radius.
+    float radius_;
+    /// Cylinder height.
+    float height_;
+};

+ 6 - 0
Engine/Physics/PhysicsWorld.cpp

@@ -23,7 +23,9 @@
 
 #include "Precompiled.h"
 #include "BoxShape.h"
+#include "CapsuleShape.h"
 #include "Context.h"
+#include "CylinderShape.h"
 #include "DebugRenderer.h"
 #include "Joint.h"
 #include "Log.h"
@@ -37,6 +39,7 @@
 #include "Scene.h"
 #include "SceneEvents.h"
 #include "Sort.h"
+#include "SphereShape.h"
 
 #include <BulletCollision/BroadphaseCollision/btDbvtBroadphase.h>
 #include <BulletCollision/CollisionDispatch/btDefaultCollisionConfiguration.h>
@@ -317,5 +320,8 @@ void RegisterPhysicsLibrary(Context* context)
     Joint::RegisterObject(context);
     RigidBody::RegisterObject(context);
     BoxShape::RegisterObject(context);
+    CapsuleShape::RegisterObject(context);
+    CylinderShape::RegisterObject(context);
+    SphereShape::RegisterObject(context);
     PhysicsWorld::RegisterObject(context);
 }

+ 71 - 0
Engine/Physics/SphereShape.cpp

@@ -0,0 +1,71 @@
+//
+// Urho3D Engine
+// Copyright (c) 2008-2012 Lasse Öörni
+//
+// 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.
+//
+
+#include "Precompiled.h"
+#include "Context.h"
+#include "Node.h"
+#include "PhysicsUtils.h"
+#include "SphereShape.h"
+
+#include <BulletCollision/CollisionShapes/btSphereShape.h>
+
+OBJECTTYPESTATIC(SphereShape);
+
+static const float DEFAULT_RADIUS = 0.5f;
+
+SphereShape::SphereShape(Context* context) :
+    CollisionShape(context),
+    radius_(DEFAULT_RADIUS)
+{
+}
+
+void SphereShape::RegisterObject(Context* context)
+{
+    context->RegisterFactory<SphereShape>();
+    
+    ATTRIBUTE(SphereShape, VAR_VECTOR3, "Offset Position", position_, Vector3::ZERO, AM_DEFAULT);
+    ATTRIBUTE(SphereShape, VAR_QUATERNION, "Offset Rotation", rotation_, Quaternion::IDENTITY, AM_DEFAULT);
+    ATTRIBUTE(SphereShape, VAR_FLOAT, "Radius", radius_, DEFAULT_RADIUS, AM_DEFAULT);
+}
+
+void SphereShape::SetRadius(float radius)
+{
+    if (radius != radius_)
+    {
+        radius_ = radius;
+        UpdateCollisionShape();
+        NotifyRigidBody();
+    }
+}
+
+void SphereShape::UpdateCollisionShape()
+{
+    if (node_)
+    {
+        delete shape_;
+        shape_ = 0;
+        
+        shape_ = new btSphereShape(radius_);
+        shape_->setLocalScaling(ToBtVector3(node_->GetWorldScale()));
+    }
+}

+ 52 - 0
Engine/Physics/SphereShape.h

@@ -0,0 +1,52 @@
+//
+// Urho3D Engine
+// Copyright (c) 2008-2012 Lasse Öörni
+//
+// 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.
+//
+
+#pragma once
+
+#include "CollisionShape.h"
+
+/// Sphere collision shape component.
+class SphereShape : public CollisionShape
+{
+    OBJECT(SphereShape);
+    
+public:
+    /// Construct.
+    SphereShape(Context* context);
+    /// Register object factory.
+    static void RegisterObject(Context* context);
+    
+    /// %Set sphere radius.
+    void SetRadius(float radius);
+    
+    /// Return sphere radius.
+    float GetRadius() const { return radius_; }
+    
+protected:
+    /// Update the collision shape.
+    virtual void UpdateCollisionShape();
+    
+private:
+    /// Sphere radius.
+    float radius_;
+};