Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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}
Note: See TracChangeset for help on using the changeset viewer.