Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 30, 2008, 12:36:46 PM (17 years ago)
Author:
rgrieder
Message:

Still getting physics and its implications straight:

  • Removed PositionableEntity —> StaticEntity is now the way to go. They cannot be translated in any way during physics simulation. The trick will be to remove them and add them again to Bullet. This however is not yet implemented.
  • Forgot a few consts in WorldEntity
  • Fixed a bug with infinite masses
  • WE throws exception if you try to apply physics when the SceneNode is not in the root space of the Scene.
  • Moved velocity_ to MovableEntity
  • Outside world reference of WE/ME are now always the non-physical values. getPosition() will always return node_→getPosition() and when setting it, both RigidBody and SceneNode are translated. This accounts for velocity, orientation and position.
File:
1 edited

Legend:

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

    r2298 r2300  
    4242        RegisterObject(MovableEntity);
    4343
     44        this->velocity_ = Vector3::ZERO;
     45
    4446        this->registerVariables();
    4547    }
     
    5254    {
    5355        SUPER(MovableEntity, XMLPort, xmlelement, mode);
     56
     57        XMLPortParamTemplate(MovableEntity, "velocity", setVelocity, getVelocity, xmlelement, mode, const Vector3&);
    5458    }
    5559
     
    165169            this->physicalBody_->setWorldTransform(transf);
    166170        }
    167         else
    168         {
    169             // no physics, we do it ourselves
    170             this->node_->setPosition(position);
    171         }
     171
     172        this->node_->setPosition(position);
     173        positionChanged();
    172174    }
    173175
     
    180182            this->physicalBody_->translate(btVector3(distance.x, distance.y, distance.z));
    181183        }
    182         else
    183         {
    184             // no physics, we do it ourselves
    185             this->node_->translate(distance, relativeTo);
    186         }
     184
     185        this->node_->translate(distance, relativeTo);
     186        positionChanged();
    187187    }
    188188
     
    195195            this->physicalBody_->setWorldTransform(transf);
    196196        }
    197         else
    198         {
    199             // no physics, we do it ourselves
    200             this->node_->setOrientation(orientation);
    201         }
     197
     198        this->node_->setOrientation(orientation);
     199        orientationChanged();
    202200    }
    203201
     
    211209            this->physicalBody_->setWorldTransform(transf * btTransform(btQuaternion(rotation.w, rotation.x, rotation.y, rotation.z)));
    212210        }
    213         else
    214         {
    215             // no physics, we do it ourselves
    216             this->node_->rotate(rotation, relativeTo);
    217         }
     211
     212        this->node_->rotate(rotation, relativeTo);
     213        orientationChanged();
    218214    }
    219215
     
    228224            this->physicalBody_->setWorldTransform(transf * rotation);
    229225        }
    230         else
    231         {
    232             // no physics, we do it ourselves
    233             this->node_->yaw(angle, relativeTo);
    234         }
     226
     227        this->node_->yaw(angle, relativeTo);
     228        orientationChanged();
    235229    }
    236230
     
    245239            this->physicalBody_->setWorldTransform(transf * rotation);
    246240        }
    247         else
    248         {
    249             // no physics, we do it ourselves
    250             this->node_->pitch(angle, relativeTo);
    251         }
     241
     242        this->node_->pitch(angle, relativeTo);
     243        orientationChanged();
    252244    }
    253245
     
    262254            this->physicalBody_->setWorldTransform(transf * rotation);
    263255        }
    264         else
    265         {
    266             // no physics, we do it ourselves
    267             this->node_->roll(angle, relativeTo);
    268         }
     256
     257        this->node_->roll(angle, relativeTo);
     258        orientationChanged();
    269259    }
    270260
     
    279269            //this->physicalBody_->setWorldTransform(transf);
    280270        }
    281         else
    282         {
    283             // no physics, we do it ourselves
    284             this->node_->lookAt(target, relativeTo, localDirectionVector);
    285         }
     271
     272        this->node_->lookAt(target, relativeTo, localDirectionVector);
     273        orientationChanged();
    286274    }
    287275
     
    290278        if (this->isDynamic())
    291279        {
    292             ThrowException(NotImplemented, "ControllableEntity::lookAt() is not yet supported for physical objects.");
     280            ThrowException(NotImplemented, "ControllableEntity::setDirection() is not yet supported for physical objects.");
    293281            OrxAssert(relativeTo == Ogre::Node::TS_LOCAL, "Cannot align physical object relative \
    294282                                                          to any other space than TS_LOCAL.");
     
    296284            //this->physicalBody_->setWorldTransform(transf);
    297285        }
    298         else
    299         {
    300             // no physics, we do it ourselves
    301             this->node_->setDirection(direction, relativeTo, localDirectionVector);
    302         }
    303     }
    304 
    305     bool MovableEntity::isCollisionTypeLegal(WorldEntity::CollisionType type)
     286
     287        this->node_->setDirection(direction, relativeTo, localDirectionVector);
     288        orientationChanged();
     289    }
     290
     291    void MovableEntity::setVelocity(const Vector3& velocity)
     292    {
     293        if (this->isDynamic())
     294        {
     295            this->physicalBody_->setLinearVelocity(btVector3(velocity.x, velocity.y, velocity.z));
     296        }
     297
     298        this->velocity_ = velocity;
     299        velocityChanged();
     300    }
     301
     302    bool MovableEntity::isCollisionTypeLegal(WorldEntity::CollisionType type) const
    306303    {
    307304        if (type == WorldEntity::Static)
     
    320317        this->node_->setOrientation(Quaternion(worldTrans.getRotation().w(), worldTrans.getRotation().x(), worldTrans.getRotation().y(), worldTrans.getRotation().z()));
    321318        const btVector3& velocity = this->physicalBody_->getLinearVelocity();
    322         internalSetVelocity(Vector3(velocity.x(), velocity.y(), velocity.z()));
     319        this->velocity_ = Vector3(velocity.x(), velocity.y(), velocity.z());
     320        velocityChanged();
    323321        positionChanged();
    324322        orientationChanged();
     
    330328        worldTrans.setOrigin(btVector3(node_->getPosition().x, node_->getPosition().y, node_->getPosition().z));
    331329        worldTrans.setRotation(btQuaternion(node_->getOrientation().w, node_->getOrientation().x, node_->getOrientation().y, node_->getOrientation().z));
     330        if (this->isDynamic())
     331        {
     332            // This function gets called only once for dynamic objects to set the initial conditions
     333            // We have to set the velocity too.
     334            this->physicalBody_->setLinearVelocity(btVector3(velocity_.x, velocity_.y, velocity_.z));
     335        }
    332336    }
    333337}
Note: See TracChangeset for help on using the changeset viewer.