Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 15, 2014, 5:10:55 PM (11 years ago)
Author:
muemart
Message:

Fix team acquisition, edit test level and start to try to make a raytest

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/turretFS14/src/modules/objects/Turret.cc

    r10049 r10060  
    3030#include "core/CoreIncludes.h"
    3131#include "core/XMLPort.h"
     32#include "Scene.h"
     33#include <OgreSceneQuery.h>
     34
    3235
    3336namespace orxonox
     
    7376    /**
    7477        @brief
    75         Checks, if a (world)position is inside the turret's range.
     78        Checks, if a WorldEntity is inside the turret's range.
    7679
    7780        This function is safe to use on turrets that are attached, rotated, etc.
    78         The turret's range is determined with the maxPitch, maxYaw, and the two attackRadius'.
    79 
    80         @param position
    81         The position to check
    82     */
    83     bool Turret::isInRange(const Vector3 &position)
     81        The turret's range is determined with the maxPitch, maxYaw, and the two attackRadius.
     82
     83        @param target
     84        The WorldEntity to check
     85
     86        @return
     87        The squared distance to the position. -1, if it's ouside of range
     88    */
     89    float Turret::isInRange(const WorldEntity* target ) const
    8490    {
    8591        //Check distance
    86         Vector3 distance = position - this->getWorldPosition();
     92        Vector3 distance = target->getWorldPosition() - this->getWorldPosition();
    8793        float distanceVal = distance.squaredLength();
    8894        if(distanceVal > (this->maxAttackRadius_ * this->maxAttackRadius_) || distanceVal < (this->minAttackRadius_ * this->minAttackRadius_))
    8995        {
    90             return false;
     96            return -1.f;
    9197        }
    9298
     
    100106        if(angle > this->maxPitch_)
    101107        {
    102             return false;
     108            return -1.f;
    103109        }
    104110
     
    111117        if(angle > this->maxYaw_)
    112118        {
    113             return false;
    114         }
    115         return true;
     119            return -1.f;
     120        }
     121
     122        Ogre::SceneManager* scenemanager = this->getScene()->getSceneManager();
     123        Ogre::Ray ray = Ogre::Ray(this->getWorldPosition(), distance);
     124        Ogre::DefaultRaySceneQuery rayscenequery = Ogre::DefaultRaySceneQuery(scenemanager);
     125        rayscenequery.setRay(ray);
     126
     127        return distanceVal;
    116128    }
    117129
     
    215227
    216228        Every tick, the turret gets rotated if it should, and the local axes get updated with the parent's rotation.
     229   
     230        @param dt
     231        Duration of the tick
    217232    */
    218233    void Turret::tick(float dt)
     
    220235        SUPER(Turret, tick, dt);
    221236
    222 
     237        //Stuff isn't properly initialized in the c'tor, so we have to do it like this
    223238        if(!this->once_)
    224239        {
     
    256271        {
    257272            //Don't make the rotation instantaneous. Use an arbitrary interpolation, not that great...
     273            //TODO: make the rotation better (constant velocity etc.). At the moment, the turret rotates
     274            //      slower the closer it is to the destination
    258275            Quaternion drot = Quaternion::nlerp(dt*this->rotationThrust_/20.f, Quaternion::IDENTITY, this->rotation_);
    259276            this->rotate(drot, WorldEntity::World);
Note: See TracChangeset for help on using the changeset viewer.