Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Dec 3, 2008, 1:17:12 AM (16 years ago)
Author:
rgrieder
Message:

Added body queue to Scene: Physical objects now request to be added to the physical world.

Location:
code/branches/physics/src/orxonox/objects/worldentities
Files:
2 edited

Legend:

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

    r2306 r2313  
    8989                this->getScene()->getSceneManager()->destroySceneNode(this->node_->getName());
    9090
    91             this->setCollisionType(None);
     91            if (this->physicalBody_)
     92            {
     93                if (this->physicalBody_->isInWorld())
     94                    this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_);
     95                delete this->physicalBody_;
     96            }
     97            // TODO: Delete collisionShapes
    9298        }
    9399    }
     
    147153            else if (object->isKinematic())
    148154                ThrowException(NotImplemented, "Cannot attach a kinematic object to a static or kinematic one: Not yet implemented.");
    149             else if (object->physicalBody_->isInWorld() || this->physicalBody_->isInWorld())
    150                 ThrowException(PhysicsViolation, "Cannot attach a physical object at runtime.");
    151155            else
    152156            {
     157                if (this->physicalBody_->isInWorld())
     158                    removeFromPhysicalWorld();
     159                if (object->physicalBody_->isInWorld())
     160                    this->getScene()->removeRigidBody(object->physicalBody_);
     161
    153162                // static to static/kinematic/dynamic --> merge shapes
    154163                this->childMass_ += object->getMass();
     
    157166                // That also implies that cannot add a physics WE to the child afterwards.
    158167                object->setCollisionType(None);
     168
     169                addToPhysicalWorld();
    159170            }
    160171        }
     
    209220            // recalculate inertia tensor
    210221            if (this->isDynamic())
    211             {
    212222                internalSetMassProps();
    213             }
    214223        }
    215224        else
     
    228237        {
    229238            if (this->physicalBody_->isInWorld())
    230                 COUT(2) << "Warning: Cannot attach a physical object at runtime.";
    231             else
    232                 this->physicalBody_->setCollisionShape(this->collisionShape_->getCollisionShape());
    233         }
     239            {
     240                COUT(2) << "Warning: Attaching collision shapes at run time causes its physical body to be removed and added again.";
     241                removeFromPhysicalWorld();
     242            }
     243            this->physicalBody_->setCollisionShape(this->collisionShape_->getCollisionShape());
     244        }
     245
     246        addToPhysicalWorld();
    234247    }
    235248
     
    257270    }
    258271
     272    void WorldEntity::addToPhysicalWorld() const
     273    {
     274        if (this->isActive() && this->hasPhysics() && !this->physicalBody_->isInWorld())
     275            this->getScene()->addRigidBody(this->physicalBody_);
     276    }
     277
     278    void WorldEntity::removeFromPhysicalWorld() const
     279    {
     280        if (this->hasPhysics())
     281            this->getScene()->removeRigidBody(this->physicalBody_);
     282    }
     283
    259284    void WorldEntity::setScale3D(const Vector3& scale)
    260285    {
     
    278303        if (!this->hasPhysics())
    279304            COUT(3) << "Warning: Setting the mass of a WorldEntity with no physics has no effect." << std::endl;
    280         else if (this->physicalBody_->isInWorld())
    281             COUT(2) << "Warning: Cannot set the physical mass at run time. Storing new mass." << std::endl;
    282         else
     305        else
     306        {
     307            if (this->physicalBody_->isInWorld())
     308            {
     309                COUT(2) << "Warning: Setting the mass of a WorldEntity at run time causes its physical body to be removed and added again." << std::endl;
     310                removeFromPhysicalWorld();
     311            }
    283312            internalSetMassProps();
     313        }
     314
     315        addToPhysicalWorld();
    284316    }
    285317
     
    340372        {
    341373            // Destroy rigid body
    342             if (this->physicalBody_->isInWorld())
    343                 this->getScene()->getPhysicalWorld()->removeRigidBody(this->physicalBody_);
     374            assert(this->physicalBody_);
     375            removeFromPhysicalWorld();
    344376            delete this->physicalBody_;
    345377            this->physicalBody_ = 0;
     
    370402        // update mass and inertia tensor
    371403        internalSetMassProps(); // type is not None! See case None: in switch
     404
     405        addToPhysicalWorld();
    372406    }
    373407
  • code/branches/physics/src/orxonox/objects/worldentities/WorldEntity.h

    r2306 r2313  
    217217            btVector3 getLocalInertia(btScalar mass) const;
    218218            bool checkPhysics() const;
     219            void addToPhysicalWorld() const;
     220            void removeFromPhysicalWorld() const;
    219221
    220222            CollisionType                collisionType_;
Note: See TracChangeset for help on using the changeset viewer.