Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 28, 2016, 3:45:32 PM (8 years ago)
Author:
fvultier
Message:

Added a debug console command that allows visualization of the weaponSlots.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/worldentities/pawns/Pawn.cc

    r11099 r11176  
    4949#include "weaponsystem/Munition.h"
    5050#include "sound/WorldSound.h"
     51#include "core/object/ObjectListIterator.h"
    5152
    5253#include "controllers/FormationController.h"
     
    5556{
    5657    RegisterClass(Pawn);
     58
     59    SetConsoleCommand("Pawn", "debugDrawWeapons", &Pawn::consoleCommand_debugDrawWeapons).addShortcut();
    5760
    5861    Pawn::Pawn(Context* context)
     
    168171    {
    169172        registerVariable(this->bAlive_,            VariableDirection::ToClient);
     173        registerVariable(this->bVulnerable_,       VariableDirection::ToClient);
    170174        registerVariable(this->health_,            VariableDirection::ToClient);
    171175        registerVariable(this->maxHealth_,         VariableDirection::ToClient);
     
    592596        return BLANKSTRING;
    593597    }
     598
     599    void Pawn::drawWeapons(bool bDraw)
     600    {
     601        if (bDraw)
     602        {
     603            std::vector<WeaponSlot*> weaponSlots = weaponSystem_->getAllWeaponSlots();
     604            int numWeaponSlots = weaponSlots.size();
     605            Vector3 slotPosition = Vector3::ZERO;
     606            Quaternion slotOrientation = Quaternion::IDENTITY;
     607            Model* slotModel = nullptr;
     608
     609            for (int i = 0; i < numWeaponSlots; ++i)
     610            {
     611                slotPosition = weaponSlots.at(i)->getPosition();
     612                slotOrientation = weaponSlots.at(i)->getOrientation();
     613                slotModel = new Model(this->getContext());
     614                slotModel->setMeshSource("Coordinates.mesh");
     615                slotModel->setScale(3.0f);
     616                slotModel->setOrientation(slotOrientation);
     617                slotModel->setPosition(slotPosition);
     618
     619                this->attach(slotModel);
     620                debugWeaponSlotModels_.push_back(slotModel);
     621            }
     622        }
     623        else
     624        {
     625            // delete all debug models
     626            for(Model* model : debugWeaponSlotModels_)
     627            {
     628                model->destroy();
     629            }
     630            debugWeaponSlotModels_.clear();
     631        }
     632    }
     633
     634    /*static*/ void Pawn::consoleCommand_debugDrawWeapons(bool bDraw)
     635    {
     636        if (bDraw)
     637        {
     638            orxout() << "WeaponSlot visualization enabled." << endl;
     639        }
     640        else
     641        {
     642            orxout() << "WeaponSlot visualization disabled." << endl;
     643        }
     644
     645        ObjectList<Pawn> pawnList;
     646        for (ObjectListIterator<Pawn> it = pawnList.begin(); it != pawnList.end(); ++it)
     647        {
     648            it->drawWeapons(bDraw);
     649        }
     650    }
    594651}
Note: See TracChangeset for help on using the changeset viewer.