Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 12, 2008, 1:44:09 PM (16 years ago)
Author:
rgrieder
Message:

Reverted all changes of attempt to update physics branch.

Location:
code/branches/physics
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/physics

  • code/branches/physics/src/orxonox/objects/worldentities/WorldEntity.cc

    r2087 r2192  
    3232#include <cassert>
    3333#include <OgreSceneManager.h>
     34#include "BulletCollision/CollisionShapes/btSphereShape.h"
    3435
    3536#include "core/CoreIncludes.h"
     
    6364        this->node_->setOrientation(Quaternion::IDENTITY);
    6465
     66        // Default behaviour does not include physics
     67        this->bAddedToPhysicalWorld_ = false;
     68        this->physicalBody_ = 0;
     69
    6570        this->registerVariables();
    6671    }
     
    7378            if (this->getScene()->getSceneManager())
    7479                this->getScene()->getSceneManager()->destroySceneNode(this->node_->getName());
     80           
     81            // Physics is not guaranteed, so check first
     82            if (this->physicalBody_)
     83            {
     84                if (this->bAddedToPhysicalWorld_)
     85                    this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_);
     86                if (this->physicalBody_->getCollisionShape())
     87                    delete this->physicalBody_->getCollisionShape();
     88                delete this->physicalBody_;
     89            }
    7590        }
    7691    }
     
    89104        XMLPortParamTemplate(WorldEntity, "scale3D", setScale3D, getScale3D, xmlelement, mode, const Vector3&);
    90105        XMLPortParam(WorldEntity, "scale", setScale, getScale, xmlelement, mode);
     106        XMLPortParam(WorldEntity, "collisionRadius", setcollisionRadius, getcollisionRadius, xmlelement, mode);
    91107
    92108        XMLPortObject(WorldEntity, WorldEntity, "attached", attach, getAttachedObject, xmlelement, mode);
     
    127143        object->parent_ = this;
    128144        object->parentID_ = this->getObjectID();
     145
     146        // Do the physical connection if required
     147        this->attachPhysicalObject(object);
    129148    }
    130149
     
    150169        return 0;
    151170    }
     171
     172    void WorldEntity::createPhysicalBody()
     173    {
     174        // Note: The motion state will be configured in a derived class.
     175        btRigidBody::btRigidBodyConstructionInfo bodyConstructionInfo(0, this, 0, btVector3(0,0,0));
     176        this->physicalBody_ = new btRigidBody(bodyConstructionInfo);
     177        this->getScene()->getPhysicalWorld()->addRigidBody(this->physicalBody_);
     178        this->bAddedToPhysicalWorld_ = true;
     179    }
     180
     181    void WorldEntity::setcollisionRadius(float radius)
     182    {
     183        if (!this->physicalBody_)
     184            createPhysicalBody();
     185
     186        // destroy old onw first
     187        btCollisionShape* oldShape = this->physicalBody_->getCollisionShape();
     188        if (oldShape)
     189            delete oldShape;
     190
     191        this->physicalBody_->setCollisionShape(new btSphereShape(btScalar(radius)));
     192    }
     193
     194    float WorldEntity::getcollisionRadius()
     195    {
     196        if (this->physicalBody_)
     197        {
     198            btSphereShape* sphere = dynamic_cast<btSphereShape*>(this->physicalBody_->getCollisionShape());
     199            if (sphere)
     200                return (float)sphere->getRadius();
     201        }
     202        return 0.0f;
     203    }
    152204}
Note: See TracChangeset for help on using the changeset viewer.