[Orxonox-commit 5334] r9997 - in code/branches/modularships: data/levels src/orxonox/collisionshapes src/orxonox/worldentities src/orxonox/worldentities/pawns

noep at orxonox.net noep at orxonox.net
Wed Mar 12 18:39:47 CET 2014


Author: noep
Date: 2014-03-12 18:39:46 +0100 (Wed, 12 Mar 2014)
New Revision: 9997

Modified:
   code/branches/modularships/data/levels/emptyLevel.oxw
   code/branches/modularships/src/orxonox/collisionshapes/CollisionShape.h
   code/branches/modularships/src/orxonox/collisionshapes/CompoundCollisionShape.cc
   code/branches/modularships/src/orxonox/collisionshapes/CompoundCollisionShape.h
   code/branches/modularships/src/orxonox/worldentities/WorldEntity.h
   code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.cc
   code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.h
Log:
Added functions to print the collisionshape-structure of a Pawn which gets hit. Doesn't quite work yet.

Modified: code/branches/modularships/data/levels/emptyLevel.oxw
===================================================================
--- code/branches/modularships/data/levels/emptyLevel.oxw	2014-03-09 21:34:08 UTC (rev 9996)
+++ code/branches/modularships/data/levels/emptyLevel.oxw	2014-03-12 17:39:46 UTC (rev 9997)
@@ -48,13 +48,24 @@
     </collisionShapes> 
     </MovableEntity>
     
-    <Pawn health=30 position="0,-100,0" direction="0,0,0" collisionType=dynamic mass=1000 name=box radarname = "Box 4" >
+    <Pawn health=1000 initialhealth=1000 maxhealth=1000 position="0,-100,0" direction="0,0,0" collisionType=dynamic mass=1000 name=box radarname = "Box 4" >
         <attached>
             <Model position="0,0,0" mesh="crate.mesh" scale3D="3,3,3" />
+            <Model position="0,-30,0" mesh="cube.mesh" scale3D="15,15,15" />
+            <StaticEntity position="0,-60,0" direction="0,0,0" collisionType=static mass=100 friction=0.01 >
+                <attached> 
+                    <Model position="0,0,0" mesh="cube.mesh" scale3D="15,15,15" />
+                    <Model position="0,0,30" mesh="cube.mesh" scale3D="15,15,15" /> 
+                </attached> 
+                <collisionShapes> 
+                    <BoxCollisionShape position="0,0,0" halfExtents="15,15,15" /> 
+                    <BoxCollisionShape position="0,0,30" halfExtents="15,15,15" /> 
+                </collisionShapes> 
+            </StaticEntity>
         </attached>
         <collisionShapes>
             <BoxCollisionShape position="0,0,0" halfExtents="15,15,15" />
-            <BoxCollisionShape position="0,-15,0" halfExtents="15,15,15" />
+            <BoxCollisionShape position="0,-30,0" halfExtents="15,15,15" />
         </collisionShapes>
     </Pawn>
     

Modified: code/branches/modularships/src/orxonox/collisionshapes/CollisionShape.h
===================================================================
--- code/branches/modularships/src/orxonox/collisionshapes/CollisionShape.h	2014-03-09 21:34:08 UTC (rev 9996)
+++ code/branches/modularships/src/orxonox/collisionshapes/CollisionShape.h	2014-03-12 17:39:46 UTC (rev 9997)
@@ -169,6 +169,9 @@
             bool notifyBeingAttached(CompoundCollisionShape* newParent); // Notifies the CollisionShape of being attached to a CompoundCollisionShape.
             void notifyDetached(); // Notifies the CollisionShape of being detached from a CompoundCollisionShape.
 
+            inline unsigned int getparentID()
+                { return this->parentID_; }
+
         protected:
             virtual void updateParent(); // Updates the CompoundCollisionShape the CollisionShape belongs to, after the CollisionShape has changed.
             virtual void parentChanged(); // Is called when the parentID of the CollisionShape has changed.

Modified: code/branches/modularships/src/orxonox/collisionshapes/CompoundCollisionShape.cc
===================================================================
--- code/branches/modularships/src/orxonox/collisionshapes/CompoundCollisionShape.cc	2014-03-09 21:34:08 UTC (rev 9996)
+++ code/branches/modularships/src/orxonox/collisionshapes/CompoundCollisionShape.cc	2014-03-12 17:39:46 UTC (rev 9997)
@@ -296,4 +296,9 @@
 
         this->updatePublicShape();*/
     }
+
+    int CompoundCollisionShape::getNumChildShapes()
+    {
+        return this->compoundShape_->getNumChildShapes();
+    }
 }

Modified: code/branches/modularships/src/orxonox/collisionshapes/CompoundCollisionShape.h
===================================================================
--- code/branches/modularships/src/orxonox/collisionshapes/CompoundCollisionShape.h	2014-03-09 21:34:08 UTC (rev 9996)
+++ code/branches/modularships/src/orxonox/collisionshapes/CompoundCollisionShape.h	2014-03-12 17:39:46 UTC (rev 9997)
@@ -70,6 +70,7 @@
             void updateAttachedShape(CollisionShape* shape);
 
             virtual void changedScale();
+            int getNumChildShapes();
 
         private:
             void updatePublicShape();

Modified: code/branches/modularships/src/orxonox/worldentities/WorldEntity.h
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/WorldEntity.h	2014-03-09 21:34:08 UTC (rev 9996)
+++ code/branches/modularships/src/orxonox/worldentities/WorldEntity.h	2014-03-12 17:39:46 UTC (rev 9997)
@@ -408,6 +408,9 @@
             */
             virtual bool isCollisionTypeLegal(CollisionType type) const = 0;
 
+            inline virtual WorldEntityCollisionShape* getWorldEntityCollisionShape()
+                { return this->collisionShape_; }
+
             btRigidBody*  physicalBody_; //!< Bullet rigid body. Everything physical is applied to this instance.
 
         private:

Modified: code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.cc
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.cc	2014-03-09 21:34:08 UTC (rev 9996)
+++ code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.cc	2014-03-12 17:39:46 UTC (rev 9997)
@@ -49,6 +49,8 @@
 
 #include "controllers/FormationController.h"
 
+#include "collisionshapes/WorldEntityCollisionShape.h"
+
 namespace orxonox
 {
     RegisterClass(Pawn);
@@ -275,6 +277,9 @@
 
     void Pawn::customDamage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs)
     {
+        int collisionShapeIndex = this->isMyCollisionShape(cs);
+        orxout() << collisionShapeIndex << endl;
+
         // Applies multiplier given by the DamageBoost Pickup.
         if (originator)
             damage *= originator->getDamageMultiplier();
@@ -610,5 +615,56 @@
         return BLANKSTRING;
     }
 
+    // WIP function that (once I get it working) determines to which attached entity a collisionshape belongs.
+    // Shame that this doesn't seem to work as intended. It behaves differently (different number of childshapes) every reload. D:
+    int Pawn::isMyCollisionShape(const btCollisionShape* cs)
+    {
+        // This entities WECS
+        WorldEntityCollisionShape* ownWECS = this->getWorldEntityCollisionShape();
 
+        // e.g. "Box 4: Searching for CS 0x1ad49200"
+        orxout() << this->getRadarName() << ": Searching for CS " << cs << endl;
+        // e.g. "Box 4 is WorldEntityCollisionShape 0x126dd060"
+        orxout() << "  " << this->getRadarName() << " is WorldEntityCollisionShape " << ownWECS << endl;
+        // e.g. "Box 4 is objectID 943"
+        orxout() << "  " << this->getRadarName() << " is objectID " << this->getObjectID() << endl;
+
+        // print child shapes of this WECS
+        printChildShapes(ownWECS, 2, 0);
+
+        // end
+        orxout() << "  " << this->getRadarName() << ": no matching CS found." << endl;
+        return -1;
+    }
+
+    void Pawn::printChildShapes(CompoundCollisionShape* cs, int indent, int subshape)
+    {
+        // e.g. "  Childshape 1 (WECS 0x126dc8c0) has 2 childshapes:"
+        printSpaces(indent);  orxout() << "Childshape " << subshape << " (WECS " << cs << ") has " << cs->getNumChildShapes() << " childshapes:" << endl;
+
+        for (int i=0; i < cs->getNumChildShapes(); i++)
+        {
+            // For each childshape, print:
+            // pointer to the btCollisionShape
+            printSpaces(indent+2);  orxout() << "Bt-Childshape " << i << ": " << cs->getAttachedShape(i)->getCollisionShape() << endl;
+
+            // pointer to the CollisionShape
+            printSpaces(indent+2);  orxout() << "Orx-Childshape " << i << ": " << cs->getAttachedShape(i) << endl;
+
+            // parentID of the CollisionShape
+            printSpaces(indent+2);  orxout() << "ParentID of CS " << i << ": " << cs->getAttachedShape(i)->getparentID() << endl;
+
+            // if the childshape is a CompoundCollisionShape, print its children.
+            if (orxonox_cast<CompoundCollisionShape*>(cs->getAttachedShape(i)))
+            {
+                printChildShapes((CompoundCollisionShape*)(cs->getAttachedShape(i)), indent+2, i);
+            }
+        }
+    }
+
+    void Pawn::printSpaces(int number)
+    {
+        for(int i=0; i<number; i++)
+            orxout() << " ";
+    }
 }

Modified: code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.h
===================================================================
--- code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.h	2014-03-09 21:34:08 UTC (rev 9996)
+++ code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.h	2014-03-12 17:39:46 UTC (rev 9997)
@@ -231,6 +231,10 @@
             float spawnparticleduration_;
             unsigned int numexplosionchunks_;
 
+            virtual int isMyCollisionShape(const btCollisionShape* cs);
+            void printChildShapes(CompoundCollisionShape* cs, int indent, int subshape);
+            void printSpaces(int num);
+
         private:
             void registerVariables();
             inline void setWeaponSystem(WeaponSystem* weaponsystem)




More information about the Orxonox-commit mailing list