Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2499 was 2469, checked in by rgrieder, 16 years ago

Resolved the issue with the collision shape synchronisation.

  • Property svn:eol-style set to native
File size: 4.2 KB
Line 
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:
23 *      Reto Grieder
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
39#include "CompoundCollisionShape.h"
40#include "objects/worldentities/WorldEntity.h"
41
42namespace orxonox
43{
44    CreateFactory(CollisionShape);
45
46    CollisionShape::CollisionShape(BaseObject* creator)
47        : BaseObject(creator)
48        , Synchronisable(creator)
49    {
50        RegisterObject(CollisionShape);
51
52        this->parent_ = 0;
53        this->parentID_ = OBJECTID_UNKNOWN;
54        this->collisionShape_ = 0;
55        this->position_ = Vector3::ZERO;
56        this->orientation_ = Quaternion::IDENTITY;
57        this->scale_ = Vector3::UNIT_SCALE;
58
59        this->registerVariables();
60    }
61
62    CollisionShape::~CollisionShape()
63    {
64    }
65
66    void CollisionShape::XMLPort(Element& xmlelement, XMLPort::Mode mode)
67    {
68        SUPER(CollisionShape, XMLPort, xmlelement, mode);
69
70        XMLPortParamTemplate(CollisionShape, "position", setPosition, getPosition, xmlelement, mode, const Vector3&);
71        XMLPortParamTemplate(CollisionShape, "orientation", setOrientation, getOrientation, xmlelement, mode, const Quaternion&);
72        XMLPortParamTemplate(CollisionShape, "scale3D", setScale3D, getScale3D, xmlelement, mode, const Vector3&);
73        XMLPortParamLoadOnly(CollisionShape, "scale", setScale, xmlelement, mode);
74        XMLPortParamLoadOnly(CollisionShape, "yaw",   yaw,   xmlelement, mode);
75        XMLPortParamLoadOnly(CollisionShape, "pitch", pitch, xmlelement, mode);
76        XMLPortParamLoadOnly(CollisionShape, "roll",  roll,  xmlelement, mode);
77    }
78
79    void CollisionShape::registerVariables()
80    {
81        registerVariable(this->parentID_, variableDirection::toclient, new NetworkCallback<CollisionShape>(this, &CollisionShape::parentChanged));
82    }
83
84    void CollisionShape::parentChanged()
85    {
86        Synchronisable* synchronisable = Synchronisable::getSynchronisable(this->parentID_);
87        CompoundCollisionShape* CCSparent = dynamic_cast<CompoundCollisionShape*>(synchronisable);
88        if (CCSparent)
89            CCSparent->addChildShape(this);
90        else
91        {
92            WorldEntity* WEparent = dynamic_cast<WorldEntity*>(synchronisable);
93            if (WEparent)
94                WEparent->attachCollisionShape(this);
95        }
96    }
97
98    void CollisionShape::updateParent()
99    {
100        if (this->parent_)
101            this->parent_->updateChildShape(this);
102    }
103
104    bool CollisionShape::hasTransform() const
105    {
106        return (!this->position_.positionEquals(Vector3(0, 0, 0), 0.001) ||
107                !this->orientation_.equals(Quaternion(1,0,0,0), Degree(0.1)));
108    }
109
110    void CollisionShape::setScale3D(const Vector3& scale)
111    {
112        CCOUT(2) << "Warning: Cannot set the scale of a collision shape: Not yet implemented." << std::endl;
113    }
114
115    void CollisionShape::setScale(float scale)
116    {
117        CCOUT(2) << "Warning: Cannot set the scale of a collision shape: Not yet implemented." << std::endl;
118    }
119
120    void CollisionShape::calculateLocalInertia(btScalar mass, btVector3& inertia) const
121    {
122        if (this->collisionShape_)
123            this->collisionShape_->calculateLocalInertia(mass, inertia);
124        else
125            inertia.setValue(0, 0, 0);
126    }
127}
Note: See TracBrowser for help on using the repository browser.