Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 15, 2008, 12:53:05 AM (17 years ago)
Author:
rgrieder
Message:

Merged physics_merge back to presentation branch.

Location:
code/branches/presentation
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation

  • code/branches/presentation/src/orxonox/objects/worldentities/pawns/Spectator.cc

    r2371 r2459  
    2929#include "OrxonoxStableHeaders.h"
    3030#include "Spectator.h"
     31
     32#include <OgreBillboardSet.h>
    3133
    3234#include "core/CoreIncludes.h"
     
    5052
    5153        this->speed_ = 100;
    52         this->rotationSpeed_ = 3;
     54        this->rotationGain_ = 3;
    5355
    5456        this->yaw_ = 0;
    5557        this->pitch_ = 0;
    5658        this->roll_ = 0;
     59        this->localVelocity_ = Vector3::ZERO;
    5760        this->setHudTemplate("spectatorhud");
    5861        this->hudmode_ = 0;
     
    6366        this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 20, 0), 1);
    6467        if (this->greetingFlare_->getBillboardSet())
    65             this->getNode()->attachObject(this->greetingFlare_->getBillboardSet());
     68            this->attachOgreObject(this->greetingFlare_->getBillboardSet());
    6669        this->greetingFlare_->setVisible(false);
    6770        this->bGreetingFlareVisible_ = false;
     
    7881            {
    7982                if (this->greetingFlare_->getBillboardSet())
    80                     this->getNode()->detachObject(this->greetingFlare_->getBillboardSet());
     83                    this->detachOgreObject(this->greetingFlare_->getBillboardSet());
    8184                delete this->greetingFlare_;
    8285            }
     
    108111        if (this->isLocallyControlled())
    109112        {
    110             Vector3 velocity = this->getVelocity();
    111             velocity.normalise();
    112             this->setVelocity(velocity * this->speed_);
    113 
    114             this->yaw(Radian(this->yaw_ * this->rotationSpeed_));
    115             this->pitch(Radian(this->pitch_ * this->rotationSpeed_));
    116             this->roll(Radian(this->roll_ * this->rotationSpeed_));
     113            float localSpeedSquared = this->localVelocity_.squaredLength();
     114            float localSpeed;
     115            if (localSpeedSquared > 1.0)
     116                localSpeed = this->speed_ / sqrtf(localSpeedSquared);
     117            else
     118                localSpeed = this->speed_;
     119
     120            this->localVelocity_.x *= localSpeed;
     121            this->localVelocity_.y *= localSpeed;
     122            this->localVelocity_.z *= localSpeed;
     123            this->setVelocity(this->getOrientation() * this->localVelocity_);
     124            this->localVelocity_.x = 0;
     125            this->localVelocity_.y = 0;
     126            this->localVelocity_.z = 0;
     127
     128            this->yaw  (Radian(this->yaw_   * this->rotationGain_));
     129            this->pitch(Radian(this->pitch_ * this->rotationGain_));
     130            this->roll (Radian(this->roll_  * this->rotationGain_));
    117131
    118132            this->yaw_ = this->pitch_ = this->roll_ = 0;
     
    120134
    121135        SUPER(Spectator, tick, dt);
    122 
    123         if (this->isLocallyControlled())
    124         {
    125             this->setVelocity(Vector3::ZERO);
    126         }
    127136    }
    128137
     
    143152    void Spectator::moveFrontBack(const Vector2& value)
    144153    {
    145         this->setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::FRONT);
     154        this->localVelocity_.z -= value.x;
    146155    }
    147156
    148157    void Spectator::moveRightLeft(const Vector2& value)
    149158    {
    150         this->setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::RIGHT);
     159        this->localVelocity_.x += value.x;
    151160    }
    152161
    153162    void Spectator::moveUpDown(const Vector2& value)
    154163    {
    155         this->setVelocity(this->getVelocity() + value.y * this->speed_ * WorldEntity::UP);
     164        this->localVelocity_.y += value.x;
    156165    }
    157166
    158167    void Spectator::rotateYaw(const Vector2& value)
    159168    {
    160         this->yaw_ = value.y;
     169        this->yaw_ += value.y;
    161170    }
    162171
    163172    void Spectator::rotatePitch(const Vector2& value)
    164173    {
    165         this->pitch_ = value.y;
     174        this->pitch_ += value.y;
    166175    }
    167176
    168177    void Spectator::rotateRoll(const Vector2& value)
    169178    {
    170         this->roll_ = value.y;
     179        this->roll_ += value.y;
    171180    }
    172181
Note: See TracChangeset for help on using the changeset viewer.