Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 14, 2008, 4:16:52 PM (16 years ago)
Author:
rgrieder
Message:

Finally merged physics stuff. Target is physics_merge because I'll have to do some testing first.

Location:
code/branches/physics_merge
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/physics_merge

  • code/branches/physics_merge/src/orxonox/objects/worldentities/pawns/SpaceShip.cc

    r2371 r2442  
    3030#include "SpaceShip.h"
    3131
     32#include "BulletDynamics/Dynamics/btRigidBody.h"
     33
     34#include "util/Math.h"
     35#include "util/Exception.h"
    3236#include "core/CoreIncludes.h"
    3337#include "core/ConfigValueIncludes.h"
    3438#include "core/XMLPort.h"
    35 #include "util/Math.h"
    3639
    3740namespace orxonox
    3841{
     42    const float orientationGain = 100;
    3943    CreateFactory(SpaceShip);
    4044
     
    7882        XMLPortParam(SpaceShip, "rotacc",            setRotAcc,            getRotAcc,            xmlelement, mode);
    7983        XMLPortParam(SpaceShip, "transdamp",         setTransDamp,         getTransDamp,         xmlelement, mode);
     84
     85        if (this->physicalBody_)
     86        {
     87            this->physicalBody_->setDamping(0.7, 0.3);
     88        }
    8089    }
    8190
     
    97106    void SpaceShip::tick(float dt)
    98107    {
    99         if (this->isLocallyControlled())
    100         {
    101             // #####################################
    102             // ############# STEERING ##############
    103             // #####################################
    104 
    105             Vector3 velocity = this->getVelocity();
    106             if (velocity.x > this->maxSecondarySpeed_)
    107                 velocity.x = this->maxSecondarySpeed_;
    108             if (velocity.x < -this->maxSecondarySpeed_)
    109                 velocity.x = -this->maxSecondarySpeed_;
    110             if (velocity.y > this->maxSecondarySpeed_)
    111                 velocity.y = this->maxSecondarySpeed_;
    112             if (velocity.y < -this->maxSecondarySpeed_)
    113                 velocity.y = -this->maxSecondarySpeed_;
    114             if (velocity.z > this->maxSecondarySpeed_)
    115                 velocity.z = this->maxSecondarySpeed_;
    116             if (velocity.z < -this->maxSpeed_)
    117                 velocity.z = -this->maxSpeed_;
    118 
    119             // normalize velocity and acceleration
    120             for (size_t dimension = 0; dimension < 3; ++dimension)
    121             {
    122                 if (this->acceleration_[dimension] == 0)
    123                 {
    124                     if (velocity[dimension] > 0)
    125                     {
    126                         velocity[dimension] -= (this->translationDamping_ * dt);
    127                         if (velocity[dimension] < 0)
    128                             velocity[dimension] = 0;
    129                     }
    130                     else if (velocity[dimension] < 0)
    131                     {
    132                         velocity[dimension] += (this->translationDamping_ * dt);
    133                         if (velocity[dimension] > 0)
    134                             velocity[dimension] = 0;
    135                     }
    136                 }
    137             }
    138 
    139             this->setVelocity(velocity);
    140         }
    141 
    142 
    143108        SUPER(SpaceShip, tick, dt);
    144 
    145 
    146         if (this->isLocallyControlled())
    147         {
    148             this->yaw(this->yawRotation_ * dt);
    149             if (this->bInvertYAxis_)
    150                 this->pitch(Degree(-this->pitchRotation_ * dt));
    151             else
    152                 this->pitch(Degree( this->pitchRotation_ * dt));
    153             this->roll(this->rollRotation_ * dt);
    154 
    155             this->acceleration_.x = 0;
    156             this->acceleration_.y = 0;
    157             this->acceleration_.z = 0;
    158 
    159             this->yawRotation_   = this->zeroDegree_;
    160             this->pitchRotation_ = this->zeroDegree_;
    161             this->rollRotation_  = this->zeroDegree_;
    162         }
    163109    }
    164110
    165111    void SpaceShip::moveFrontBack(const Vector2& value)
    166112    {
    167         this->acceleration_.z = -this->translationAcceleration_ * value.x;
     113        assert(this->physicalBody_);
     114        this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 0.0f, -getMass() * value.x * 100));
    168115    }
    169116
    170117    void SpaceShip::moveRightLeft(const Vector2& value)
    171118    {
    172         this->acceleration_.x = this->translationAcceleration_ * value.x;
     119        this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(getMass() * value.x * 100, 0.0f, 0.0f));
    173120    }
    174121
    175122    void SpaceShip::moveUpDown(const Vector2& value)
    176123    {
    177         this->acceleration_.y = this->translationAcceleration_ * value.x;
     124        this->physicalBody_->applyCentralForce(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, getMass() * value.x * 100, 0.0f));
    178125    }
    179126
    180127    void SpaceShip::rotateYaw(const Vector2& value)
    181128    {
    182         Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_;
    183         if (temp > this->maxRotation_)
    184             temp = this->maxRotation_;
    185         if (temp < -this->maxRotation_)
    186             temp = -this->maxRotation_;
    187         this->yawRotation_ = Degree(temp);
     129        this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 1 / this->physicalBody_->getInvInertiaDiagLocal().y() * value.y * orientationGain, 0.0f));
    188130    }
    189131
    190132    void SpaceShip::rotatePitch(const Vector2& value)
    191133    {
    192         Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_;
    193         if (temp > this->maxRotation_)
    194             temp = this->maxRotation_;
    195         if (temp < -this->maxRotation_)
    196             temp = -this->maxRotation_;
    197         this->pitchRotation_ = Degree(temp);
     134        this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(1 / this->physicalBody_->getInvInertiaDiagLocal().x() * value.y * orientationGain, 0.0f, 0.0f));
    198135    }
    199136
    200137    void SpaceShip::rotateRoll(const Vector2& value)
    201138    {
    202         Degree temp = value.x * value.x * sgn(value.x) * this->rotationAcceleration_;
    203         if (temp > this->maxRotation_)
    204             temp = this->maxRotation_;
    205         if (temp < -this->maxRotation_)
    206             temp = -this->maxRotation_;
    207         this->rollRotation_ = Degree(temp);
     139        this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * btVector3(0.0f, 0.0f, -1 / this->physicalBody_->getInvInertiaDiagLocal().z() * value.y * orientationGain));
    208140    }
    209141
  • code/branches/physics_merge/src/orxonox/objects/worldentities/pawns/Spectator.cc

    r2371 r2442  
    2929#include "OrxonoxStableHeaders.h"
    3030#include "Spectator.h"
     31
     32#include <OgreBillboardSet.h>
    3133
    3234#include "core/CoreIncludes.h"
     
    6365        this->greetingFlare_->setBillboardSet(this->getScene()->getSceneManager(), "Examples/Flare", ColourValue(1.0, 1.0, 0.8), Vector3(0, 20, 0), 1);
    6466        if (this->greetingFlare_->getBillboardSet())
    65             this->getNode()->attachObject(this->greetingFlare_->getBillboardSet());
     67            this->attachOgreObject(this->greetingFlare_->getBillboardSet());
    6668        this->greetingFlare_->setVisible(false);
    6769        this->bGreetingFlareVisible_ = false;
     
    7880            {
    7981                if (this->greetingFlare_->getBillboardSet())
    80                     this->getNode()->detachObject(this->greetingFlare_->getBillboardSet());
     82                    this->detachOgreObject(this->greetingFlare_->getBillboardSet());
    8183                delete this->greetingFlare_;
    8284            }
     
    110112            Vector3 velocity = this->getVelocity();
    111113            velocity.normalise();
    112             this->setVelocity(velocity * this->speed_);
     114            this->setVelocity(this->getOrientation() * velocity * this->speed_);
    113115
    114116            this->yaw(Radian(this->yaw_ * this->rotationSpeed_));
Note: See TracChangeset for help on using the changeset viewer.