Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1608


Ignore:
Timestamp:
Jun 17, 2008, 3:33:03 PM (16 years ago)
Author:
landauf
Message:
  • added a backlight to all SpaceShips, leaving a trail behind (configurable)
  • changed some lines in SpaceShipAI, AI seems to be more fair now…
  • fixed a bug in Math.cc algorithms to calculate radar positions and AI movement (division by zero and acos of 1.000001)
  • added destroy() and destroydelay to ParticleSpawner, so the smoketrail of a destroyed enemy stays visible for some seconds
  • added 2 lines to Orxonox.cc to make the length of the backlight-trail independend of the gamespeed

########################
# !!! MEDIA UPDATE !!! #
########################

Location:
code/trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/bin/levels/sample.oxw

    r1602 r1608  
    99  </audio-->
    1010
    11 <Ambient colourvalue="0.1, 0.1, 0.1" />
     11<Ambient colourvalue="0.5, 0.5, 0.5" />
    1212<Skybox src="Orxonox/Starbox" />
    1313<SpaceShip camera="true" position="0,0,0" scale="10" yawpitchroll="0,0,0" mesh="assff.mesh" maxSpeed="500" maxSideAndBackSpeed="50" maxRotation="1.0" transAcc="200" rotAcc="3.0" transDamp="75" rotDamp="1.0" />
  • code/trunk/src/core/BaseObject.h

    r1558 r1608  
    6666
    6767            /** @brief Sets the state of the objects activity. @param bActive True = active */
    68             inline void setActivity(bool bActive) { this->bActive_ = bActive; this->changedActivity(); }
     68            inline void setActive(bool bActive) { this->bActive_ = bActive; this->changedActivity(); }
    6969            /** @brief Returns the state of the objects activity. @return The state of the activity */
    7070            inline bool isActive() const { return this->bActive_; }
     
    7373
    7474            /** @brief Sets the state of the objects visibility. @param bVisible True = visible */
    75             inline void setVisibility(bool bVisible) { this->bVisible_ = bVisible; this->changedVisibility(); }
     75            inline void setVisible(bool bVisible) { this->bVisible_ = bVisible; this->changedVisibility(); }
    7676            /** @brief Returns the state of the objects visibility. @return The state of the visibility */
    7777            inline bool isVisible() const { return this->bVisible_; }
  • code/trunk/src/orxonox/CMakeLists.txt

    r1555 r1608  
    2020
    2121  objects/Ambient.cc
     22  objects/Backlight.cc
    2223  objects/Camera.cc
    2324  objects/CameraHandler.cc
  • code/trunk/src/orxonox/Orxonox.cc

    r1577 r1608  
    7272#include "console/InGameConsole.h"
    7373#include "objects/Tickable.h"
     74#include "objects/Backlight.h"
    7475#include "tools/ParticleInterface.h"
    7576
     
    169170    float change = factor / Orxonox::getSingleton()->getTimeFactor();
    170171    Orxonox::getSingleton()->timefactor_ = factor;
    171 
    172172    for (Iterator<ParticleInterface> it = ObjectList<ParticleInterface>::begin(); it; ++it)
    173173        it->setSpeedFactor(it->getSpeedFactor() * change);
     174
     175    for (Iterator<Backlight> it = ObjectList<Backlight>::begin(); it; ++it)
     176        it->setTimeFactor(Orxonox::getSingleton()->getTimeFactor());
    174177  }
    175178
  • code/trunk/src/orxonox/objects/ParticleSpawner.cc

    r1602 r1608  
    3333#include "core/Executor.h"
    3434#include "tools/ParticleInterface.h"
     35#include "GraphicsEngine.h"
    3536
    3637namespace orxonox
     
    4445    }
    4546
    46     ParticleSpawner::ParticleSpawner(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime, float delay, const Vector3& direction)
     47    ParticleSpawner::ParticleSpawner(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime, float startdelay, float destroydelay, const Vector3& direction)
    4748    {
    4849        RegisterObject(ParticleSpawner);
    49         this->setParticle(templateName, detaillevel, lifetime, delay, direction);
     50        this->setParticle(templateName, detaillevel, lifetime, startdelay, destroydelay, direction);
    5051    }
    5152
    52     void ParticleSpawner::setParticle(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime, float delay, const Vector3& direction)
     53    void ParticleSpawner::setParticle(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime, float startdelay, float destroydelay, const Vector3& direction)
    5354    {
    5455        ExecutorMember<ParticleSpawner>* executor = createExecutor(createFunctor(&ParticleSpawner::createParticleSpawner));
     56        this->destroydelay_ = destroydelay;
    5557        executor->setDefaultValues(lifetime);
    56         this->timer_.setTimer(delay, false, this, executor);
     58        this->timer_.setTimer(startdelay, false, this, executor);
    5759        this->particle_ = new ParticleInterface(templateName, detaillevel);
    5860        this->particle_->addToSceneNode(this->getNode());
     
    7274        }
    7375    };
     76
     77    void ParticleSpawner::destroy()
     78    {
     79        this->setPosition(this->getNode()->getParent()->getPosition());
     80        this->getNode()->getParent()->removeChild(this->getNode());
     81        GraphicsEngine::getSingleton().getSceneManager()->getRootSceneNode()->addChild(this->getNode());
     82        if (this->particle_)
     83            this->particle_->setEnabled(false);
     84        if (!this->timer_.isActive() || this->timer_.getRemainingTime() > this->destroydelay_)
     85            this->timer_.setTimer(this->destroydelay_, false, this, createExecutor(createFunctor(&ParticleSpawner::destroyParticleSpawner)));
     86    }
    7487
    7588    void ParticleSpawner::createParticleSpawner(float lifetime)
  • code/trunk/src/orxonox/objects/ParticleSpawner.h

    r1602 r1608  
    4141        public:
    4242            ParticleSpawner();
    43             ParticleSpawner(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime = 0, float delay = 0, const Vector3& direction = Vector3::ZERO);
     43            ParticleSpawner(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime = 0, float startdelay = 0, float destroydelay = 0, const Vector3& direction = Vector3::ZERO);
    4444            virtual ~ParticleSpawner();
     45            void destroy();
    4546
    46             void setParticle(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime = 0, float delay = 0, const Vector3& direction = Vector3::ZERO);
     47            void setParticle(const std::string& templateName, LODParticle::LOD detaillevel, float lifetime = 0, float startdelay = 0, float destroydelay = 0, const Vector3& direction = Vector3::ZERO);
    4748            inline ParticleInterface* getParticleInterface() const
    4849                { return this->particle_; }
     
    5657            Timer<ParticleSpawner> timer_;
    5758            ParticleInterface* particle_;
     59            float destroydelay_;
    5860    };
    5961}
  • code/trunk/src/orxonox/objects/SpaceShip.cc

    r1602 r1608  
    3535#include <OgreSceneNode.h>
    3636
    37 #include "CameraHandler.h"
    3837#include "util/Convert.h"
    3938#include "util/Math.h"
     39
    4040#include "core/CoreIncludes.h"
    4141#include "core/ConfigValueIncludes.h"
    4242#include "core/Debug.h"
     43#include "core/XMLPort.h"
     44#include "core/ConsoleCommand.h"
     45#include "core/input/InputManager.h"
     46
     47#include "network/Client.h"
     48
     49#include "hud/HUD.h"
     50#include "tools/ParticleInterface.h"
     51
    4352#include "GraphicsEngine.h"
    44 #include "core/input/InputManager.h"
    45 #include "tools/ParticleInterface.h"
    4653#include "RotatingProjectile.h"
    4754#include "ParticleProjectile.h"
    48 #include "core/XMLPort.h"
    49 #include "core/ConsoleCommand.h"
    50 #include "network/Client.h"
    51 #include "hud/HUD.h"
     55#include "ParticleSpawner.h"
     56#include "Backlight.h"
     57#include "CameraHandler.h"
    5258
    5359namespace orxonox
     
    101107        this->tt1_ = 0;
    102108        this->tt2_ = 0;
     109        this->smoke_ = 0;
     110        this->fire_ = 0;
     111
     112        this->backlight_ = 0;
    103113
    104114        this->redNode_ = 0;
     
    143153                delete this->tt2_;
    144154
    145             if (setMouseEventCallback_)
     155            if (this->smoke_)
     156                this->smoke_->destroy();
     157            if (this->fire_)
     158                this->fire_->destroy();
     159
     160            if (this->backlight_)
     161                delete this->backlight_;
     162
     163            if (this->setMouseEventCallback_)
    146164                InputManager::removeMouseHandler("SpaceShip");
    147165
     
    184202    void SpaceShip::init()
    185203    {
    186         // START CREATING THRUSTER
     204        // START CREATING THRUSTERS
    187205        this->tt1_ = new ParticleInterface("Orxonox/thruster1", LODParticle::low);
    188206        this->tt1_->createNewEmitter();
     
    216234        node2c->attachObject(this->leftThrusterFlare_.getBillboardSet());
    217235        node2c->attachObject(this->rightThrusterFlare_.getBillboardSet());
    218         // END CREATING THRUSTER
     236        // END CREATING THRUSTERS
    219237
    220238        // START CREATING BLINKING LIGHTS
     
    234252        // END CREATING BLINKING LIGHTS
    235253
    236         this->smoke_.setParticle("Orxonox/smoke5", LODParticle::normal);
    237         this->fire_.setParticle("Orxonox/fire3", LODParticle::normal);
     254        // START CREATING ADDITIONAL EFFECTS
     255        this->backlight_ = new Backlight(this->maxSpeed_, 0.8);
     256        this->attachObject(this->backlight_);
     257        this->backlight_->setPosition(-2.35, 0, 0.2);
     258        this->backlight_->setColour(this->getProjectileColour());
     259
     260        this->smoke_ = new ParticleSpawner();
     261        this->smoke_->setParticle("Orxonox/smoke5", LODParticle::normal, 0, 0, 3);
    238262        this->attachObject(this->smoke_);
     263
     264        this->fire_ = new ParticleSpawner();
     265        this->fire_->setParticle("Orxonox/fire3", LODParticle::normal, 0, 0, 1);
    239266        this->attachObject(this->fire_);
     267        // END CREATING ADDITIONAL EFFECTS
    240268
    241269        if (this->isExactlyA(Class(SpaceShip)))
     
    255283            this->chFarNode_->attachObject(this->crosshairFar_.getBillboardSet());
    256284            this->chFarNode_->setScale(0.4, 0.4, 0.4);
     285            // END of testing crosshair
    257286        }
    258287
    259288        createCamera();
    260         // END of testing crosshair
    261289    }
    262290
     
    280308        this->rightThrusterFlare_.setVisible(this->isVisible());
    281309        this->leftThrusterFlare_.setVisible(this->isVisible());
    282         this->smoke_.setVisible(this->isVisible());
    283         this->fire_.setVisible(this->isVisible());
     310        this->smoke_->setVisible(this->isVisible());
     311        this->fire_->setVisible(this->isVisible());
     312        this->backlight_->setVisible(this->isVisible());
    284313    }
    285314
     
    336365        CameraHandler::getInstance()->requestFocus(cam_);
    337366      }
    338 
    339367    }
    340368
     
    378406    }
    379407
    380     int sgn(float x)
    381     {
    382         if (x >= 0)
    383             return 1;
    384         else
    385             return -1;
    386     }
    387 
    388408    std::string SpaceShip::whereAmI() {
    389         return getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().x)
    390         + "  " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().y)
    391         + "  " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().z);
     409        return getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().x)
     410        + "  " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().y)
     411        + "  " + getConvertedValue<float, std::string>(SpaceShip::getLocalShip()->getPosition().z);
    392412    }
    393413
     
    403423            this->cam_->tick(dt);
    404424
    405         this->smoke_.setVisible(this->isVisible() && this->health_ < 40);
    406         this->fire_.setVisible(this->isVisible() && this->health_ < 20);
     425        if (this->smoke_)
     426            this->smoke_->setVisible(this->isVisible() && this->health_ < 40);
     427        if (this->fire_)
     428            this->fire_->setVisible(this->isVisible() && this->health_ < 20);
     429
     430        if (this->backlight_)
     431        {   // (there's already fire ||                 we're to slow                 ||                  we're moving backwards                  )
     432            if (this->health_ < 20   || this->getVelocity().squaredLength() < 150*150 || this->getVelocity().dotProduct(this->getInitialDir()) < 0)
     433                this->backlight_->setActive(false);
     434            else
     435                this->backlight_->setActive(true);
     436        }
    407437
    408438        if (this->redNode_ && this->greenNode_)
     
    521551        }
    522552
    523         if( myShip_ )
    524         {
    525           COUT(5) << "steering our ship: " << objectID << std::endl;
    526           this->acceleration_.x = 0;
    527           this->acceleration_.y = 0;
    528           this->momentum_ = 0;
    529           this->mouseXRotation_ = Radian(0);
    530           this->mouseYRotation_ = Radian(0);
    531         }/*else
    532           COUT(4) << "not steering ship: " << objectID << " our ship: " << network::Client::getSingleton()->getShipID() << std::endl;*/
    533 
    534           this->bLMousePressed_ = false;
     553        COUT(5) << "steering our ship: " << objectID << std::endl;
     554        this->acceleration_.x = 0;
     555        this->acceleration_.y = 0;
     556        this->momentum_ = 0;
     557        this->mouseXRotation_ = Radian(0);
     558        this->mouseYRotation_ = Radian(0);
     559        this->bLMousePressed_ = false;
    535560    }
    536561
  • code/trunk/src/orxonox/objects/SpaceShip.h

    r1602 r1608  
    3737#include "Model.h"
    3838#include "tools/BillboardSet.h"
    39 #include "ParticleSpawner.h"
    4039
    4140namespace orxonox
     
    145144            BillboardSet rightThrusterFlare_;
    146145
     146            Backlight* backlight_;
     147
    147148            BillboardSet redBillboard_;
    148149            BillboardSet greenBillboard_;
     
    151152            float blinkTime_;
    152153
    153             ParticleSpawner smoke_;
    154             ParticleSpawner fire_;
     154            ParticleSpawner* smoke_;
     155            ParticleSpawner* fire_;
    155156
    156157            BillboardSet crosshairNear_;
  • code/trunk/src/orxonox/objects/SpaceShipAI.cc

    r1566 r1608  
    102102            newenemy->XMLPort(xmlelement, XMLPort::LoadObject);
    103103
    104             ParticleSpawner* spawneffect = new ParticleSpawner("Orxonox/fairytwirl", LODParticle::normal, 2.0, 0.0, newenemy->getOrth());
     104            ParticleSpawner* spawneffect = new ParticleSpawner("Orxonox/fairytwirl", LODParticle::normal, 2.0, 0, 0, newenemy->getOrth());
    105105            spawneffect->setPosition(newenemy->getPosition() - newenemy->getOrth() * 50);
    106106            spawneffect->create();
     
    131131        // search enemy
    132132        random = rnd(maxrand);
    133         if (random < 20 && (!this->target_))
     133        if (random < 15 && (!this->target_))
    134134            this->searchNewTarget();
    135135
     
    146146        // fly somewhere
    147147        random = rnd(maxrand);
    148         if (random < 40 && (!this->bHasTargetPosition_ && !this->target_))
     148        if (random < 50 && (!this->bHasTargetPosition_ && !this->target_))
    149149            this->searchNewTargetPosition();
    150150
     
    201201        Vector3 ringdirection = Vector3(rnd(), rnd(), rnd());
    202202        ringdirection.normalise();
    203         explosion = new ParticleSpawner("Orxonox/BigExplosion1part3", LODParticle::normal, 3.0, 0.5, ringdirection);
    204         explosion->setPosition(this->getPosition());
    205         explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true);
    206         explosion->setScale(4);
    207         explosion->create();
    208         explosion = new ParticleSpawner("Orxonox/BigExplosion1part3", LODParticle::high, 3.0, 0.5, ringdirection);
     203        explosion = new ParticleSpawner("Orxonox/BigExplosion1part3", LODParticle::normal, 3.0, 0.5, 0, ringdirection);
     204        explosion->setPosition(this->getPosition());
     205        explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true);
     206        explosion->setScale(4);
     207        explosion->create();
     208        explosion = new ParticleSpawner("Orxonox/BigExplosion1part3", LODParticle::high, 3.0, 0.5, 0, ringdirection);
    209209        explosion->setPosition(this->getPosition());
    210210        explosion->getParticleInterface()->setKeepParticlesInLocalSpace(true);
     
    235235    {
    236236        Vector2 coord = get2DViewdirection(this->getPosition(), this->getDir(), this->getOrth(), this->targetPosition_);
    237         this->setMoveYaw(0.8 * sgn(coord.x));
    238         this->setMovePitch(0.8 * sgn(coord.y));
    239 
    240         if ((this->targetPosition_ - this->getPosition()).length() > 500)
     237
     238        float distance = (this->targetPosition_ - this->getPosition()).length();
     239        if (this->target_ || distance > 50)
     240        {
     241            // Multiply with 0.8 to make them a bit slower
     242            this->setMoveYaw(0.8 * sgn(coord.x) * coord.x*coord.x);
     243            this->setMovePitch(0.8 * sgn(coord.y) * coord.y*coord.y);
     244        }
     245
     246        if (this->target_ && distance < 1000 && this->getVelocity().squaredLength() > this->target_->getVelocity().squaredLength())
     247            this->setMoveLongitudinal(-0.5); // They don't brake with full power to give the player a chance
     248        else if (!this->target_ && distance <= this->getVelocity().length() / (2 * this->getTransAcc()))
     249            this->setMoveLongitudinal(-1.0);
     250        else
    241251            this->setMoveLongitudinal(0.8);
    242 
    243         if (this->isCloseAtTarget(300) && this->target_)
    244         {
    245             if (this->getVelocity().length() > this->target_->getVelocity().length())
    246                 this->setMoveLongitudinal(-0.5);
    247         }
    248252    }
    249253
     
    306310    void SpaceShipAI::shipDied(SpaceShipAI* ship)
    307311    {
    308         this->forgetTarget();
    309         this->searchNewTargetPosition();
     312        if (ship == this->target_)
     313        {
     314            this->forgetTarget();
     315            this->searchNewTargetPosition();
     316        }
    310317    }
    311318}
  • code/trunk/src/orxonox/tools/Timer.h

    r1552 r1608  
    9595            inline bool isActive() const
    9696                { return this->bActive_; }
     97            /** @brief Returns the remaining time until the Timer calls the function. @return The remaining time */
     98            inline float getRemainingTime() const
     99                { return this->time_; }
    97100            /** @brief Gives the Timer some extra time. @param time The amount of extra time in seconds */
    98101            inline void addTime(float time)
  • code/trunk/src/util/Math.cc

    r1566 r1608  
    7575{
    7676    orxonox::Vector3 distance = otherposition - myposition;
    77     return acos(mydirection.dotProduct(distance) / distance.length());
     77    float distancelength = distance.length();
     78    if (distancelength == 0)
     79        return 0;
     80    else
     81        return acos(clamp<float>(mydirection.dotProduct(distance) / distancelength, -1, 1));
    7882}
    7983
     
    8488    // project difference vector on our plane
    8589    orxonox::Vector3 projection = Ogre::Plane(mydirection, myposition).projectVector(distance);
    86     float angle = acos(myorthonormal.dotProduct(projection) / projection.length());
     90
     91    float projectionlength = projection.length();
     92    if (projectionlength == 0) return orxonox::Vector2(0, 0);
     93    float angle = acos(clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1));
    8794
    8895    if ((mydirection.crossProduct(myorthonormal)).dotProduct(distance) > 0)
     
    98105    // project difference vector on our plane
    99106    orxonox::Vector3 projection = Ogre::Plane(mydirection, myposition).projectVector(distance);
    100     float angle = acos(myorthonormal.dotProduct(projection) / projection.length());
    101     float radius = acos(mydirection.dotProduct(distance) / distance.length()) / Ogre::Math::PI;
     107
     108    float projectionlength = projection.length();
     109    if (projectionlength == 0) return orxonox::Vector2(0, 0);
     110    float angle = acos(clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1));
     111
     112    float distancelength = distance.length();
     113    if (distancelength == 0) return orxonox::Vector2(0, 0);
     114    float radius = acos(clamp<float>(mydirection.dotProduct(distance) / distancelength, -1, 1)) / Ogre::Math::PI;
    102115
    103116    if ((mydirection.crossProduct(myorthonormal)).dotProduct(distance) > 0)
Note: See TracChangeset for help on using the changeset viewer.