Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 17, 2014, 4:05:06 PM (10 years ago)
Author:
muemart
Message:

Move logic into controller, don't use bullet for rotations, and use WorldPosition in FormationController+ (good idea?)

Location:
code/branches/turretFS14/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/turretFS14/src/libraries/core/input/InputManager.cc

    r9667 r10039  
    175175
    176176        if (exclusiveMouse_ || GraphicsManager::getInstance().isFullScreen())
    177         {
     177        {   // HACK MARTIN for debugging, changed values here to true
    178178            if (CommandLineParser::getValue("keyboard_no_grab").get<bool>())
    179179                paramList.insert(StringPair("x11_keyboard_grab", "false"));
    180180            else
    181                 paramList.insert(StringPair("x11_keyboard_grab", "true"));
    182             paramList.insert(StringPair("x11_mouse_grab",  "true"));
    183             paramList.insert(StringPair("x11_mouse_hide", "true"));
     181                paramList.insert(StringPair("x11_keyboard_grab", "false"));
     182            paramList.insert(StringPair("x11_mouse_grab",  "false"));
     183            paramList.insert(StringPair("x11_mouse_hide", "false"));
    184184        }
    185185        else
  • code/branches/turretFS14/src/modules/objects/Turret.cc

    r10031 r10039  
    4444    {
    4545        RegisterObject(Turret);
    46         this->startOrient_ = Quaternion::IDENTITY;
    47         this->startDir_ = Vector3::ZERO;
    48         this->localZ_ = Vector3::UNIT_Z;
    49         this->localY_ = Vector3::UNIT_Y;
    50         this->localX_ = Vector3::UNIT_X;
    51         this->maxPitch_ = 0;
    52         this->maxYaw_ = 0;
    53         this->attackRadius_ = 200;
    54         this->gotOrient_ = false;
    5546        this->rotationThrust_ = 50;
    5647
     
    110101    }
    111102
    112     bool Turret::isInRange(Vector3 position)
    113     {
    114         Vector3 distance = position - this->getPosition();
    115         if(distance.squaredLength() > (this->attackRadius_ * this->attackRadius_))
    116         {
    117             return false;
    118         }
    119 
    120         Vector3 dir = getTransformedVector(distance, this->localX_, this->localY_, this->localZ_);
    121         Vector3 dirProjected = dir;
    122         dirProjected.x = 0;
    123         Vector3 startDirProjected = this->startDir_;
    124         startDirProjected.x = 0;
    125         Ogre::Real angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
    126         if(angle > this->maxPitch_)
    127         {
    128             return false;
    129         }
    130 
    131         dirProjected = dir;
    132         dirProjected.y = 0;
    133         startDirProjected = this->startDir_;
    134         startDirProjected.y = 0;
    135         angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
    136         if(angle > this->maxYaw_)
    137         {
    138             return false;
    139         }
    140         return true;
    141     }
    142 
    143103    void Turret::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    144104    {
    145         XMLPortParam(Turret, "maxPitch", setMaxPitch, getMaxPitch, xmlelement, mode);
    146         XMLPortParam(Turret, "maxYaw", setMaxYaw, getMaxYaw, xmlelement, mode);
    147         XMLPortParam(Turret, "attackRadius", setAttackRadius, getAttackRadius, xmlelement, mode);
    148105        SUPER(Turret, XMLPort, xmlelement, mode);
    149106    }
     
    153110        SUPER(Turret, tick, dt);
    154111
    155         if(!gotOrient_)
    156         {
    157             this->startOrient_ = this->getOrientation();
    158             this->localX_ = this->startOrient_ * this->localX_;
    159             this->localX_.normalise();
    160             this->localY_ = this->startOrient_ * this->localY_;
    161             this->localY_.normalise();
    162             this->localZ_ = this->startOrient_ * this->localZ_;
    163             this->localZ_.normalise();
     112        this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
     113        this->localAngularAcceleration_ = physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_;
    164114
    165             //startDir should always be (0,0,-1)
    166             this->startDir_ = getTransformedVector(this->startOrient_ * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);
    167115
    168             this->gotOrient_ = true;
    169         }
     116        pitch(Degree(localAngularAcceleration_.x()/10000), WorldEntity::World);
     117        yaw(Degree(localAngularAcceleration_.y()/10000), WorldEntity::World);
     118        roll(Degree(localAngularAcceleration_.z()/10000), WorldEntity::World);
    170119
    171         this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
    172         this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
    173120        this->localAngularAcceleration_.setValue(0, 0, 0);
    174121    }
    175 
    176122}
  • code/branches/turretFS14/src/modules/objects/Turret.h

    r10031 r10039  
    5454            virtual void tick(float dt);
    5555
    56             virtual bool isInRange(Vector3 position);
    57 
    58             inline void setMaxPitch(Ogre::Real pitch)
    59                 {this->maxPitch_ = pitch;}
    60 
    61             inline Ogre::Real getMaxPitch()
    62                 {return this->maxPitch_;}
    63 
    64             inline void setMaxYaw(Ogre::Real yaw)
    65                 {this->maxYaw_ = yaw;}
    66 
    67             inline Ogre::Real getMaxYaw()
    68                 {return this->maxYaw_;}
    69 
    70             inline void setAttackRadius(float radius)
    71                 {this->attackRadius_ = radius;}
    72 
    73             inline float getAttackRadius()
    74                 {return this->attackRadius_;}
    75 
    7656
    7757        private:
    78             bool gotOrient_;
    79             Ogre::Real maxPitch_;
    80             Ogre::Real maxYaw_;
    81             float attackRadius_;
    82             Quaternion startOrient_;
    83             Vector3 startDir_;
    84             Vector3 localZ_;
    85             Vector3 localY_;
    86             Vector3 localX_;
    8758            float rotationThrust_;
    8859
     
    9263
    9364#endif
    94 
  • code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc

    r10031 r10039  
    3838        {
    3939                RegisterObject(TurretController);
     40                this->startOrient_ = Quaternion::IDENTITY;
     41        this->startDir_ = Vector3::ZERO;
     42        this->localZ_ = Vector3::UNIT_Z;
     43        this->localY_ = Vector3::UNIT_Y;
     44        this->localX_ = Vector3::UNIT_X;
     45        this->attackRadius_ = 200;
     46        this->maxPitch_ = 90;
     47        this->maxYaw_ = 90;
     48        this->gotOrient_ = false;
     49        orxout() << "Constructor " << this << endl;
    4050        }
    4151
     
    4858        {
    4959        Turret* turret = orxonox_cast<Turret*>(this->getControllableEntity());
    50         if(target_ && turret->isInRange(target_->getPosition()))
     60        if(target_ && this->isInRange(target_->getWorldPosition()))
    5161        {
    5262                return;
     
    6272        {
    6373                Pawn* parenttarget = orxonox_cast<Pawn*>(parent->getTarget());
    64                 if(parenttarget && turret->isInRange(parenttarget->getPosition()))
     74                if(parenttarget && this->isInRange(parenttarget->getWorldPosition()))
    6575                {
    6676                        this->setTarget(parenttarget);
     
    7686                continue;
    7787
    78             if(turret->isInRange(entity->getPosition()))
     88            if(this->isInRange(entity->getWorldPosition()))
    7989            {
    8090                this->setTarget(entity);
     
    8595        }
    8696
     97        bool TurretController::isInRange(Vector3 position)
     98    {
     99        Vector3 distance = position - this->getControllableEntity()->getWorldPosition();
     100        if(distance.squaredLength() > (this->attackRadius_ * this->attackRadius_))
     101        {
     102            return false;
     103        }
     104
     105        Vector3 dir = getTransformedVector(distance, this->localX_, this->localY_, this->localZ_);
     106        Vector3 dirProjected = dir;
     107        dirProjected.x = 0;
     108        Vector3 startDirProjected = this->startDir_;
     109        startDirProjected.x = 0;
     110        Ogre::Real angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
     111        if(angle > this->maxPitch_)
     112        {
     113            return false;
     114        }
     115
     116        dirProjected = dir;
     117        dirProjected.y = 0;
     118        startDirProjected = this->startDir_;
     119        startDirProjected.y = 0;
     120        angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
     121        if(angle > this->maxYaw_)
     122        {
     123            return false;
     124        }
     125        return true;
     126    }
     127
    87128        void TurretController::tick(float dt)
    88129        {
     130
     131
     132        if(!gotOrient_)
     133        {
     134            this->startOrient_ = this->getControllableEntity()->getOrientation();
     135            this->localXStart_ = this->startOrient_ * this->localX_;
     136            this->localXStart_.normalise();
     137            this->localX_ = this->localXStart_;
     138            this->localYStart_ = this->startOrient_ * this->localY_;
     139            this->localYStart_.normalise();
     140            this->localY_ = this->localYStart_;
     141            this->localZStart_ = this->startOrient_ * this->localZ_;
     142            this->localZStart_.normalise();
     143            this->localZ_ = this->localZStart_;
     144
     145            //startDir should always be (0,0,-1)
     146            this->startDir_ = getTransformedVector(this->startOrient_ * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);
     147
     148            this->gotOrient_ = true;
     149        }
     150
     151        //orxout() << "Controller " << this;
     152        //orxout() << "\tControllable Entity " << this->getControllableEntity() << endl;
     153        WorldEntity* parent = this->getControllableEntity()->getParent();
     154        if(parent)
     155        {
     156            Quaternion parentrot = parent->getOrientation();
     157            this->localX_ = parentrot * this->localXStart_;
     158            this->localY_ = parentrot * this->localYStart_;
     159            this->localZ_ = parentrot * this->localZStart_;
     160        }
     161
     162        orxout() << this->getControllableEntity()->getWorldPosition() << endl;
     163
     164
    89165        if (!this->isActive() || !this->getControllableEntity())
    90166            return;
    91167                this->searchTarget();
    92                 this->getControllableEntity()->rotatePitch(0.2);
    93                 /*if(target_)
     168                if(target_)
    94169                {
    95170                        this->aimAtTarget();
     171                        //this->getControllableEntity()->lookAt(this->targetPosition_);
    96172                        //It says move, but really it only turns
    97173                        this->moveToTargetPosition();
     
    100176                                orxout() << 42 << endl;
    101177                        }
    102                 }*/
     178                }
    103179        }
    104180 }
  • code/branches/turretFS14/src/modules/objects/controllers/TurretController.h

    r10031 r10039  
    4444
    4545                private:
     46            bool gotOrient_;
     47            float attackRadius_;
     48            Ogre::Real maxPitch_;
     49            Ogre::Real maxYaw_;
     50            Quaternion startOrient_;
     51            Vector3 startDir_;
     52            Vector3 localZ_;
     53            Vector3 localZStart_;
     54            Vector3 localY_;
     55            Vector3 localYStart_;
     56            Vector3 localX_;
     57            Vector3 localXStart_;
    4658                        void searchTarget();
     59                        bool isInRange(Vector3 position);
    4760        };
    4861 }
  • code/branches/turretFS14/src/orxonox/controllers/ArtificialController.cc

    r9667 r10039  
    9494        static const float hardcoded_projectile_speed = 1250;
    9595
    96         this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getPosition(), hardcoded_projectile_speed, this->target_->getPosition(), this->target_->getVelocity());
     96        this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getWorldPosition(), hardcoded_projectile_speed, this->target_->getWorldPosition(), this->target_->getVelocity());
    9797        this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO);
    9898
  • code/branches/turretFS14/src/orxonox/controllers/FormationController.cc

    r9800 r10039  
    277277        }
    278278
    279         Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
    280         float distance = (target - this->getControllableEntity()->getPosition()).length();
     279        Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getWorldPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
     280        float distance = (target - this->getControllableEntity()->getWorldPosition()).length();
    281281        float rotateX = clamp(coord.x * 10, -1.0f, 1.0f);
    282282        float rotateY = clamp(coord.y * 10, -1.0f, 1.0f);
  • code/branches/turretFS14/src/orxonox/worldentities/WorldEntity.cc

    r10031 r10039  
    414414            else if (this->isDynamic())
    415415            {
     416                //hacky hack, really shouldn't do that
    416417                //orxout(internal_warning) << "Cannot attach a dynamic object to a WorldEntity." << endl;
    417418                //return false;
Note: See TracChangeset for help on using the changeset viewer.