Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation/src/orxonox/objects/collisionshapes/CollisionShape.cc @ 2468

Last change on this file since 2468 was 2459, checked in by rgrieder, 16 years ago

Merged physics_merge back to presentation branch.

  • Property svn:eol-style set to native
File size: 3.9 KB
RevLine 
[2303]1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
[2304]23 *      Reto Grieder
[2303]24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "OrxonoxStableHeaders.h"
30#include "CollisionShape.h"
31
32#include "BulletCollision/CollisionShapes/btCollisionShape.h"
33
34#include "util/Exception.h"
35#include "core/CoreIncludes.h"
36#include "core/XMLPort.h"
37#include "tools/BulletConversions.h"
38
[2374]39#include "CompoundCollisionShape.h"
40
[2303]41namespace orxonox
42{
43    CreateFactory(CollisionShape);
44
[2374]45    CollisionShape::CollisionShape(BaseObject* creator)
46        : BaseObject(creator)
[2442]47        , Synchronisable(creator)
[2303]48    {
49        RegisterObject(CollisionShape);
50
[2374]51        this->parent_ = 0;
[2445]52        this->parentID_ = OBJECTID_UNKNOWN;
[2374]53        this->collisionShape_ = 0;
[2403]54        this->position_ = Vector3::ZERO;
55        this->orientation_ = Quaternion::IDENTITY;
56        this->scale_ = Vector3::UNIT_SCALE;
[2303]57    }
58
59    CollisionShape::~CollisionShape()
60    {
61    }
62
63    void CollisionShape::XMLPort(Element& xmlelement, XMLPort::Mode mode)
64    {
65        SUPER(CollisionShape, XMLPort, xmlelement, mode);
[2374]66
67        XMLPortParamTemplate(CollisionShape, "position", setPosition, getPosition, xmlelement, mode, const Vector3&);
68        XMLPortParamTemplate(CollisionShape, "orientation", setOrientation, getOrientation, xmlelement, mode, const Quaternion&);
[2429]69        XMLPortParamTemplate(CollisionShape, "scale3D", setScale3D, getScale3D, xmlelement, mode, const Vector3&);
70        XMLPortParamLoadOnly(CollisionShape, "scale", setScale, xmlelement, mode);
[2374]71        XMLPortParamLoadOnly(CollisionShape, "yaw",   yaw,   xmlelement, mode);
72        XMLPortParamLoadOnly(CollisionShape, "pitch", pitch, xmlelement, mode);
73        XMLPortParamLoadOnly(CollisionShape, "roll",  roll,  xmlelement, mode);
[2303]74    }
75
[2374]76    void CollisionShape::registerVariables()
[2303]77    {
[2442]78        registerVariable(this->parentID_, variableDirection::toclient, new NetworkCallback<CollisionShape>(this, &CollisionShape::parentChanged));
[2303]79    }
80
[2423]81    void CollisionShape::parentChanged()
[2303]82    {
[2374]83        CompoundCollisionShape* parent = dynamic_cast<CompoundCollisionShape*>(Synchronisable::getSynchronisable(this->parentID_));
84        if (parent)
85            parent->addChildShape(this);
[2303]86    }
87
[2423]88    void CollisionShape::updateParent()
89    {
90        if (this->parent_)
91            this->parent_->updateChildShape(this);
92    }
93
[2374]94    bool CollisionShape::hasTransform() const
[2303]95    {
[2374]96        return (!this->position_.positionEquals(Vector3(0, 0, 0), 0.001) ||
97                !this->orientation_.equals(Quaternion(1,0,0,0), Degree(0.1)));
[2303]98    }
[2306]99
100    void CollisionShape::setScale3D(const Vector3& scale)
101    {
[2433]102        CCOUT(2) << "Warning: Cannot set the scale of a collision shape: Not yet implemented." << std::endl;
[2306]103    }
104
[2374]105    void CollisionShape::setScale(float scale)
[2306]106    {
[2433]107        CCOUT(2) << "Warning: Cannot set the scale of a collision shape: Not yet implemented." << std::endl;
[2306]108    }
[2423]109
[2452]110    void CollisionShape::calculateLocalInertia(btScalar mass, btVector3& inertia) const
[2423]111    {
112        if (this->collisionShape_)
113            this->collisionShape_->calculateLocalInertia(mass, inertia);
[2452]114        else
115            inertia.setValue(0, 0, 0);
[2423]116    }
[2303]117}
Note: See TracBrowser for help on using the repository browser.