[Orxonox-commit 5526] r10189 - in code/trunk: data/levels src/libraries/core src/modules/objects src/modules/objects/collisionshapes

landauf at orxonox.net landauf at orxonox.net
Sun Jan 11 15:40:42 CET 2015


Author: landauf
Date: 2015-01-11 15:40:41 +0100 (Sun, 11 Jan 2015)
New Revision: 10189

Added:
   code/trunk/data/levels/collisionShapes.oxw
   code/trunk/src/modules/objects/collisionshapes/AbstractRadiusHeightCollisionShape.cc
   code/trunk/src/modules/objects/collisionshapes/AbstractRadiusHeightCollisionShape.h
   code/trunk/src/modules/objects/collisionshapes/CylinderCollisionShape.cc
   code/trunk/src/modules/objects/collisionshapes/CylinderCollisionShape.h
Modified:
   code/trunk/src/libraries/core/CoreIncludes.h
   code/trunk/src/modules/objects/ObjectsPrereqs.h
   code/trunk/src/modules/objects/collisionshapes/CMakeLists.txt
   code/trunk/src/modules/objects/collisionshapes/ConeCollisionShape.cc
   code/trunk/src/modules/objects/collisionshapes/ConeCollisionShape.h
Log:
added new collision shape (cylinder)

Added: code/trunk/data/levels/collisionShapes.oxw
===================================================================
--- code/trunk/data/levels/collisionShapes.oxw	                        (rev 0)
+++ code/trunk/data/levels/collisionShapes.oxw	2015-01-11 14:40:41 UTC (rev 10189)
@@ -0,0 +1,46 @@
+<LevelInfo
+ name = "Collision shapes"
+ description = "A level with some collision shapes."
+ tags = "showcase"
+ screenshot = "emptylevel.png"
+/>
+
+<?lua
+  include("stats.oxo")
+  include("HUDTemplates3.oxo")
+  include("templates/lodInformation.oxt")
+?>
+
+<?lua
+  include("templates/spaceshipAssff2.oxt")
+  include("templates/spaceshipPirate.oxt")
+  include("templates/spaceshipEscort.oxt")
+?>
+
+<Level>
+  <templates>
+    <Template link=lodtemplate_default />
+  </templates>
+  <?lua include("includes/notifications.oxi") ?>
+
+  <Scene
+    ambientlight = "0.8, 0.8, 0.8"
+    skybox       = "Orxonox/Starbox"
+  >
+
+    <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/>
+    <SpawnPoint team=0 position="-200,0,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipescort />
+    
+	<StaticEntity position="1000,0,0" collisionType="static">
+		<collisionShapes>
+			<SphereCollisionShape   position="0,-600,0" radius="100" />
+			<CylinderCollisionShape position="0,-300,0" radius="50" height="150" />
+			<BoxCollisionShape      position="0,-100,0" halfExtents="30, 50, 80" />
+			<ConeCollisionShape     position="0,+100,0" radius="50" height="150" />
+			<PlaneCollisionShape    position="0,+300,0" normal="0, -1, 0" offset="30" />
+		</collisionShapes>
+	</StaticEntity>
+	
+  </Scene>
+</Level>
+

Modified: code/trunk/src/libraries/core/CoreIncludes.h
===================================================================
--- code/trunk/src/libraries/core/CoreIncludes.h	2015-01-10 15:39:15 UTC (rev 10188)
+++ code/trunk/src/libraries/core/CoreIncludes.h	2015-01-11 14:40:41 UTC (rev 10189)
@@ -113,7 +113,7 @@
     RegisterClassWithFactory(ClassName, new orxonox::ClassFactoryWithContext<ClassName>(), false)
 
 /**
-    @brief Registers an abstract class in the framework.
+    @brief Registers an abstract class in the framework. Should be used in combination with inheritsFrom(base-class-identifier).
     @param ClassName The name of the class
 */
 #define RegisterAbstractClass(ClassName) \

Modified: code/trunk/src/modules/objects/ObjectsPrereqs.h
===================================================================
--- code/trunk/src/modules/objects/ObjectsPrereqs.h	2015-01-10 15:39:15 UTC (rev 10188)
+++ code/trunk/src/modules/objects/ObjectsPrereqs.h	2015-01-11 14:40:41 UTC (rev 10189)
@@ -75,8 +75,10 @@
     class Turret;
 
     // collisionshapes
+    class AbstractRadiusHeightCollisionShape;
     class BoxCollisionShape;
     class ConeCollisionShape;
+    class CylinderCollisionShape;
     class PlaneCollisionShape;
     class SphereCollisionShape;
 

Copied: code/trunk/src/modules/objects/collisionshapes/AbstractRadiusHeightCollisionShape.cc (from rev 10184, code/trunk/src/modules/objects/collisionshapes/ConeCollisionShape.cc)
===================================================================
--- code/trunk/src/modules/objects/collisionshapes/AbstractRadiusHeightCollisionShape.cc	                        (rev 0)
+++ code/trunk/src/modules/objects/collisionshapes/AbstractRadiusHeightCollisionShape.cc	2015-01-11 14:40:41 UTC (rev 10189)
@@ -0,0 +1,93 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      Fabian 'x3n' Landau
+ *
+ */
+
+/**
+    @file AbstractRadiusHeightCollisionShape.cc
+    @brief Implementation of the AbstractRadiusHeightCollisionShape class.
+*/
+
+#include "AbstractRadiusHeightCollisionShape.h"
+
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+#include "tools/BulletConversions.h"
+
+namespace orxonox
+{
+    RegisterAbstractClass(AbstractRadiusHeightCollisionShape).inheritsFrom(Class(CollisionShape));
+
+    /**
+    @brief
+        Constructor. Registers and initializes the object.
+    */
+    AbstractRadiusHeightCollisionShape::AbstractRadiusHeightCollisionShape(Context* context) : CollisionShape(context)
+    {
+        RegisterObject(AbstractRadiusHeightCollisionShape);
+
+        this->radius_ = 1.0f;
+        this->height_ = 1.0f;
+
+        this->registerVariables();
+    }
+
+    void AbstractRadiusHeightCollisionShape::registerVariables()
+    {
+        registerVariable(this->radius_, VariableDirection::ToClient, new NetworkCallback<CollisionShape>(this, &CollisionShape::updateShape));
+        registerVariable(this->height_, VariableDirection::ToClient, new NetworkCallback<CollisionShape>(this, &CollisionShape::updateShape));
+    }
+
+    void AbstractRadiusHeightCollisionShape::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(AbstractRadiusHeightCollisionShape, XMLPort, xmlelement, mode);
+
+        XMLPortParam(AbstractRadiusHeightCollisionShape, "radius", setRadius, getRadius, xmlelement, mode);
+        XMLPortParam(AbstractRadiusHeightCollisionShape, "height", setHeight, getHeight, xmlelement, mode);
+    }
+
+    /**
+    @brief
+        Is called when the scale of the AbstractRadiusHeightCollisionShape has changed.
+    */
+    void AbstractRadiusHeightCollisionShape::changedScale()
+    {
+        CollisionShape::changedScale();
+
+        // Resize the internal collision shape
+        // TODO: Assuming setLocalScaling works.
+        //this->collisionShape_->setLocalScaling(multi_cast<btVector3>(this->getScale3D()));
+        if(!this->hasUniformScaling())
+        {
+            orxout(internal_error) << "AbstractRadiusHeightCollisionShape: Non-uniform scaling is not yet supported." << endl;
+            return;
+        }
+
+        this->radius_ *= this->getScale();
+        this->height_ *= this->getScale();
+        this->updateShape();
+    }
+}

Copied: code/trunk/src/modules/objects/collisionshapes/AbstractRadiusHeightCollisionShape.h (from rev 10184, code/trunk/src/modules/objects/collisionshapes/ConeCollisionShape.h)
===================================================================
--- code/trunk/src/modules/objects/collisionshapes/AbstractRadiusHeightCollisionShape.h	                        (rev 0)
+++ code/trunk/src/modules/objects/collisionshapes/AbstractRadiusHeightCollisionShape.h	2015-01-11 14:40:41 UTC (rev 10189)
@@ -0,0 +1,97 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      Fabian 'x3n' Landau
+ *
+ */
+
+/**
+    @file AbstractRadiusHeightCollisionShape.h
+    @brief Definition of the AbstractRadiusHeightCollisionShape class.
+    @ingroup Collisionshapes
+*/
+
+#ifndef _AbstractRadiusHeightCollisionShape_H__
+#define _AbstractRadiusHeightCollisionShape_H__
+
+#include "objects/ObjectsPrereqs.h"
+#include "collisionshapes/CollisionShape.h"
+
+namespace orxonox
+{
+
+    /**
+    @brief
+        Wrapper for the bullet collision shapes with radius and height.
+
+    @ingroup Collisionshapes
+    */
+    class _ObjectsExport AbstractRadiusHeightCollisionShape : public CollisionShape
+    {
+        public:
+            AbstractRadiusHeightCollisionShape(Context* context);
+
+            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+
+            /**
+            @brief Set the radius of the AbstractRadiusHeightCollisionShape.
+                   If the radius changes, this causes the internal collision shape to be recreated.
+            @param value The radius to be set.
+            @return Returns true if the radius has changed, false if not.
+            */
+            inline bool setRadius(float value)
+                { if(this->radius_ == value) return false; this->radius_ = value; updateShape(); return true; }
+            /**
+            @brief Get the radius of the AbstractRadiusHeightCollisionShape.
+            @return Returns the radius of the AbstractRadiusHeightCollisionShape.
+            */
+            inline float getRadius() const
+                { return radius_; }
+
+            /**
+            @brief Set the height of the AbstractRadiusHeightCollisionShape.
+                   If the height changes, this causes the internal collision shape to be recreated.
+            @param value The height to be set.
+            @return Returns true if the height has changed, false if not.
+            */
+            inline bool setHeight(float value)
+                { if(this->height_ == value) return false; this->height_ = value; updateShape(); return true; }
+            /**
+            @brief Get the height of the AbstractRadiusHeightCollisionShape.
+            @return Returns the height of the AbstractRadiusHeightCollisionShape.
+            */
+            inline float getHeight() const
+                { return this->height_; }
+
+            virtual void changedScale(); // Is called when the scale of the AbstractRadiusHeightCollisionShape has changed.
+
+        private:
+            void registerVariables();
+
+            float radius_; //!< The radius of the AbstractRadiusHeightCollisionShape.
+            float height_; //!< The height of the AbstractRadiusHeightCollisionShape.
+     };
+}
+
+#endif /* _AbstractRadiusHeightCollisionShape_H__ */

Modified: code/trunk/src/modules/objects/collisionshapes/CMakeLists.txt
===================================================================
--- code/trunk/src/modules/objects/collisionshapes/CMakeLists.txt	2015-01-10 15:39:15 UTC (rev 10188)
+++ code/trunk/src/modules/objects/collisionshapes/CMakeLists.txt	2015-01-11 14:40:41 UTC (rev 10189)
@@ -1,6 +1,8 @@
 ADD_SOURCE_FILES(OBJECTS_SRC_FILES
+  AbstractRadiusHeightCollisionShape.cc
   BoxCollisionShape.cc
   ConeCollisionShape.cc
+  CylinderCollisionShape.cc
   PlaneCollisionShape.cc
   SphereCollisionShape.cc
 )

Modified: code/trunk/src/modules/objects/collisionshapes/ConeCollisionShape.cc
===================================================================
--- code/trunk/src/modules/objects/collisionshapes/ConeCollisionShape.cc	2015-01-10 15:39:15 UTC (rev 10188)
+++ code/trunk/src/modules/objects/collisionshapes/ConeCollisionShape.cc	2015-01-11 14:40:41 UTC (rev 10189)
@@ -36,7 +36,6 @@
 #include <BulletCollision/CollisionShapes/btConeShape.h>
 
 #include "core/CoreIncludes.h"
-#include "core/XMLPort.h"
 #include "tools/BulletConversions.h"
 
 namespace orxonox
@@ -47,15 +46,11 @@
     @brief
         Constructor. Registers and initializes the object.
     */
-    ConeCollisionShape::ConeCollisionShape(Context* context) : CollisionShape(context)
+    ConeCollisionShape::ConeCollisionShape(Context* context) : AbstractRadiusHeightCollisionShape(context)
     {
         RegisterObject(ConeCollisionShape);
 
-        this->radius_ = 1.0f;
-        this->height_ = 1.0f;
         updateShape();
-
-        this->registerVariables();
     }
 
     ConeCollisionShape::~ConeCollisionShape()
@@ -64,50 +59,14 @@
             delete this->collisionShape_;
     }
 
-    void ConeCollisionShape::registerVariables()
-    {
-        registerVariable(this->radius_, VariableDirection::ToClient, new NetworkCallback<CollisionShape>(this, &CollisionShape::updateShape));
-        registerVariable(this->height_, VariableDirection::ToClient, new NetworkCallback<CollisionShape>(this, &CollisionShape::updateShape));
-    }
-
-    void ConeCollisionShape::XMLPort(Element& xmlelement, XMLPort::Mode mode)
-    {
-        SUPER(ConeCollisionShape, XMLPort, xmlelement, mode);
-
-        XMLPortParam(ConeCollisionShape, "radius", setRadius, getRadius, xmlelement, mode);
-        XMLPortParam(ConeCollisionShape, "height", setHeight, getHeight, xmlelement, mode);
-    }
-
     /**
     @brief
-        Is called when the scale of the ConeCollisionShape has changed.
-    */
-    void ConeCollisionShape::changedScale()
-    {
-        CollisionShape::changedScale();
-
-        // Resize the internal collision shape
-        // TODO: Assuming setLocalScaling works.
-        //this->collisionShape_->setLocalScaling(multi_cast<btVector3>(this->getScale3D()));
-        if(!this->hasUniformScaling())
-        {
-            orxout(internal_error) << "ConeCollisionShape: Non-uniform scaling is not yet supported." << endl;
-            return;
-        }
-
-        this->radius_ *= this->getScale();
-        this->height_ *= this->getScale();
-        this->updateShape();
-    }
-
-    /**
-    @brief
         Creates a new internal collision shape for the ConeCollisionShape.
     @return
         Returns a pointer to the newly created btConeShape.
     */
     btCollisionShape* ConeCollisionShape::createNewShape() const
     {
-        return new btConeShape(this->radius_, this->height_);
+        return new btConeShape(this->getRadius(), this->getHeight());
     }
 }

Modified: code/trunk/src/modules/objects/collisionshapes/ConeCollisionShape.h
===================================================================
--- code/trunk/src/modules/objects/collisionshapes/ConeCollisionShape.h	2015-01-10 15:39:15 UTC (rev 10188)
+++ code/trunk/src/modules/objects/collisionshapes/ConeCollisionShape.h	2015-01-11 14:40:41 UTC (rev 10189)
@@ -36,7 +36,7 @@
 #define _ConeCollisionShape_H__
 
 #include "objects/ObjectsPrereqs.h"
-#include "collisionshapes/CollisionShape.h"
+#include "AbstractRadiusHeightCollisionShape.h"
 
 namespace orxonox
 {
@@ -51,53 +51,14 @@
     @see btConeShape
     @ingroup Collisionshapes
     */
-    class _ObjectsExport ConeCollisionShape : public CollisionShape
+    class _ObjectsExport ConeCollisionShape : public AbstractRadiusHeightCollisionShape
     {
         public:
             ConeCollisionShape(Context* context);
             virtual ~ConeCollisionShape();
 
-            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
-
-            /**
-            @brief Set the radius of the ConeCollisionShape.
-                   If the radius changes, this causes the internal collision shape to be recreated.
-            @param value The radius to be set.
-            @return Returns true if the radius has changed, false if not.
-            */
-            inline bool setRadius(float value)
-                { if(this->radius_ == value) return false; this->radius_ = value; updateShape(); return true; }
-            /**
-            @brief Get the radius of the ConeCollisionShape.
-            @return Returns the radius of the ConeCollisionShape.
-            */
-            inline float getRadius() const
-                { return radius_; }
-
-            /**
-            @brief Set the height of the ConeCollisionShape.
-                   If the height changes, this causes the internal collision shape to be recreated.
-            @param value The height to be set.
-            @return Returns true if the height has changed, false if not.
-            */
-            inline bool setHeight(float value)
-                { if(this->height_ == value) return false; this->height_ = value; updateShape(); return true; }
-            /**
-            @brief Get the height of the ConeCollisionShape.
-            @return Returns the height of the ConeCollisionShape.
-            */
-            inline float getHeight() const
-                { return this->height_; }
-
-            virtual void changedScale(); // Is called when the scale of the ConeCollisionShape has changed.
-
         private:
-            void registerVariables();
-
             btCollisionShape* createNewShape() const; // Creates a new internal collision shape for the ConeCollisionShape.
-
-            float radius_; //!< The radius of the ConeCollisionShape.
-            float height_; //!< The height of the ConeCollisionShape.
      };
 }
 

Added: code/trunk/src/modules/objects/collisionshapes/CylinderCollisionShape.cc
===================================================================
--- code/trunk/src/modules/objects/collisionshapes/CylinderCollisionShape.cc	                        (rev 0)
+++ code/trunk/src/modules/objects/collisionshapes/CylinderCollisionShape.cc	2015-01-11 14:40:41 UTC (rev 10189)
@@ -0,0 +1,73 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file CylinderCollisionShape.cc
+    @brief Implementation of the CylinderCollisionShape class.
+*/
+
+#include "CylinderCollisionShape.h"
+
+#include <BulletCollision/CollisionShapes/btCylinderShape.h>
+
+#include "core/CoreIncludes.h"
+#include "tools/BulletConversions.h"
+
+namespace orxonox
+{
+    RegisterClass(CylinderCollisionShape);
+
+    /**
+    @brief
+        Constructor. Registers and initializes the object.
+    */
+    CylinderCollisionShape::CylinderCollisionShape(Context* context) : AbstractRadiusHeightCollisionShape(context)
+    {
+        RegisterObject(CylinderCollisionShape);
+
+        updateShape();
+    }
+
+    CylinderCollisionShape::~CylinderCollisionShape()
+    {
+        if (this->isInitialized())
+            delete this->collisionShape_;
+    }
+
+    /**
+    @brief
+        Creates a new internal collision shape for the CylinderCollisionShape.
+    @return
+        Returns a pointer to the newly created btCylinderShape.
+    */
+    btCollisionShape* CylinderCollisionShape::createNewShape() const
+    {
+        // divide height by 2 because bullet expects the half extents
+        return new btCylinderShape(btVector3(this->getRadius(), this->getHeight() / 2, 0));
+    }
+}

Added: code/trunk/src/modules/objects/collisionshapes/CylinderCollisionShape.h
===================================================================
--- code/trunk/src/modules/objects/collisionshapes/CylinderCollisionShape.h	                        (rev 0)
+++ code/trunk/src/modules/objects/collisionshapes/CylinderCollisionShape.h	2015-01-11 14:40:41 UTC (rev 10189)
@@ -0,0 +1,62 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Fabian 'x3n' Landau
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+/**
+    @file CylinderCollisionShape.h
+    @brief Definition of the CylinderCollisionShape class.
+    @ingroup Collisionshapes
+*/
+
+#ifndef _CylinderCollisionShape_H__
+#define _CylinderCollisionShape_H__
+
+#include "objects/ObjectsPrereqs.h"
+#include "AbstractRadiusHeightCollisionShape.h"
+
+namespace orxonox
+{
+
+    /**
+    @brief
+        Wrapper for the bullet Cylinder collision shape class btCylinderShape.
+
+    @see btCylinderShape
+    @ingroup Collisionshapes
+    */
+    class _ObjectsExport CylinderCollisionShape : public AbstractRadiusHeightCollisionShape
+    {
+        public:
+            CylinderCollisionShape(Context* context);
+            virtual ~CylinderCollisionShape();
+
+        private:
+            btCollisionShape* createNewShape() const; // Creates a new internal collision shape for the CylinderCollisionShape.
+     };
+}
+
+#endif /* _CylinderCollisionShape_H__ */




More information about the Orxonox-commit mailing list