Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 9997


Ignore:
Timestamp:
Mar 12, 2014, 6:39:46 PM (11 years ago)
Author:
noep
Message:

Added functions to print the collisionshape-structure of a Pawn which gets hit. Doesn't quite work yet.

Location:
code/branches/modularships
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/modularships/data/levels/emptyLevel.oxw

    r9996 r9997  
    4949    </MovableEntity>
    5050   
    51     <Pawn health=30 position="0,-100,0" direction="0,0,0" collisionType=dynamic mass=1000 name=box radarname = "Box 4" >
     51    <Pawn health=1000 initialhealth=1000 maxhealth=1000 position="0,-100,0" direction="0,0,0" collisionType=dynamic mass=1000 name=box radarname = "Box 4" >
    5252        <attached>
    5353            <Model position="0,0,0" mesh="crate.mesh" scale3D="3,3,3" />
     54            <Model position="0,-30,0" mesh="cube.mesh" scale3D="15,15,15" />
     55            <StaticEntity position="0,-60,0" direction="0,0,0" collisionType=static mass=100 friction=0.01 >
     56                <attached>
     57                    <Model position="0,0,0" mesh="cube.mesh" scale3D="15,15,15" />
     58                    <Model position="0,0,30" mesh="cube.mesh" scale3D="15,15,15" />
     59                </attached>
     60                <collisionShapes>
     61                    <BoxCollisionShape position="0,0,0" halfExtents="15,15,15" />
     62                    <BoxCollisionShape position="0,0,30" halfExtents="15,15,15" />
     63                </collisionShapes>
     64            </StaticEntity>
    5465        </attached>
    5566        <collisionShapes>
    5667            <BoxCollisionShape position="0,0,0" halfExtents="15,15,15" />
    57             <BoxCollisionShape position="0,-15,0" halfExtents="15,15,15" />
     68            <BoxCollisionShape position="0,-30,0" halfExtents="15,15,15" />
    5869        </collisionShapes>
    5970    </Pawn>
  • code/branches/modularships/src/orxonox/collisionshapes/CollisionShape.h

    r9667 r9997  
    170170            void notifyDetached(); // Notifies the CollisionShape of being detached from a CompoundCollisionShape.
    171171
     172            inline unsigned int getparentID()
     173                { return this->parentID_; }
     174
    172175        protected:
    173176            virtual void updateParent(); // Updates the CompoundCollisionShape the CollisionShape belongs to, after the CollisionShape has changed.
  • code/branches/modularships/src/orxonox/collisionshapes/CompoundCollisionShape.cc

    r9667 r9997  
    297297        this->updatePublicShape();*/
    298298    }
     299
     300    int CompoundCollisionShape::getNumChildShapes()
     301    {
     302        return this->compoundShape_->getNumChildShapes();
     303    }
    299304}
  • code/branches/modularships/src/orxonox/collisionshapes/CompoundCollisionShape.h

    r9667 r9997  
    7171
    7272            virtual void changedScale();
     73            int getNumChildShapes();
    7374
    7475        private:
  • code/branches/modularships/src/orxonox/worldentities/WorldEntity.h

    r9995 r9997  
    408408            */
    409409            virtual bool isCollisionTypeLegal(CollisionType type) const = 0;
     410
     411            inline virtual WorldEntityCollisionShape* getWorldEntityCollisionShape()
     412                { return this->collisionShape_; }
    410413
    411414            btRigidBody*  physicalBody_; //!< Bullet rigid body. Everything physical is applied to this instance.
  • code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.cc

    r9996 r9997  
    5050#include "controllers/FormationController.h"
    5151
     52#include "collisionshapes/WorldEntityCollisionShape.h"
     53
    5254namespace orxonox
    5355{
     
    276278    void Pawn::customDamage(float damage, float healthdamage, float shielddamage, Pawn* originator, const btCollisionShape* cs)
    277279    {
     280        int collisionShapeIndex = this->isMyCollisionShape(cs);
     281        orxout() << collisionShapeIndex << endl;
     282
    278283        // Applies multiplier given by the DamageBoost Pickup.
    279284        if (originator)
     
    611616    }
    612617
    613 
     618    // WIP function that (once I get it working) determines to which attached entity a collisionshape belongs.
     619    // Shame that this doesn't seem to work as intended. It behaves differently (different number of childshapes) every reload. D:
     620    int Pawn::isMyCollisionShape(const btCollisionShape* cs)
     621    {
     622        // This entities WECS
     623        WorldEntityCollisionShape* ownWECS = this->getWorldEntityCollisionShape();
     624
     625        // e.g. "Box 4: Searching for CS 0x1ad49200"
     626        orxout() << this->getRadarName() << ": Searching for CS " << cs << endl;
     627        // e.g. "Box 4 is WorldEntityCollisionShape 0x126dd060"
     628        orxout() << "  " << this->getRadarName() << " is WorldEntityCollisionShape " << ownWECS << endl;
     629        // e.g. "Box 4 is objectID 943"
     630        orxout() << "  " << this->getRadarName() << " is objectID " << this->getObjectID() << endl;
     631
     632        // print child shapes of this WECS
     633        printChildShapes(ownWECS, 2, 0);
     634
     635        // end
     636        orxout() << "  " << this->getRadarName() << ": no matching CS found." << endl;
     637        return -1;
     638    }
     639
     640    void Pawn::printChildShapes(CompoundCollisionShape* cs, int indent, int subshape)
     641    {
     642        // e.g. "  Childshape 1 (WECS 0x126dc8c0) has 2 childshapes:"
     643        printSpaces(indent);  orxout() << "Childshape " << subshape << " (WECS " << cs << ") has " << cs->getNumChildShapes() << " childshapes:" << endl;
     644
     645        for (int i=0; i < cs->getNumChildShapes(); i++)
     646        {
     647            // For each childshape, print:
     648            // pointer to the btCollisionShape
     649            printSpaces(indent+2);  orxout() << "Bt-Childshape " << i << ": " << cs->getAttachedShape(i)->getCollisionShape() << endl;
     650
     651            // pointer to the CollisionShape
     652            printSpaces(indent+2);  orxout() << "Orx-Childshape " << i << ": " << cs->getAttachedShape(i) << endl;
     653
     654            // parentID of the CollisionShape
     655            printSpaces(indent+2);  orxout() << "ParentID of CS " << i << ": " << cs->getAttachedShape(i)->getparentID() << endl;
     656
     657            // if the childshape is a CompoundCollisionShape, print its children.
     658            if (orxonox_cast<CompoundCollisionShape*>(cs->getAttachedShape(i)))
     659            {
     660                printChildShapes((CompoundCollisionShape*)(cs->getAttachedShape(i)), indent+2, i);
     661            }
     662        }
     663    }
     664
     665    void Pawn::printSpaces(int number)
     666    {
     667        for(int i=0; i<number; i++)
     668            orxout() << " ";
     669    }
    614670}
  • code/branches/modularships/src/orxonox/worldentities/pawns/Pawn.h

    r9995 r9997  
    232232            unsigned int numexplosionchunks_;
    233233
     234            virtual int isMyCollisionShape(const btCollisionShape* cs);
     235            void printChildShapes(CompoundCollisionShape* cs, int indent, int subshape);
     236            void printSpaces(int num);
     237
    234238        private:
    235239            void registerVariables();
Note: See TracChangeset for help on using the changeset viewer.