[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" |
---|
[2469] | 40 | #include "objects/worldentities/WorldEntity.h" |
---|
[2374] | 41 | |
---|
[2303] | 42 | namespace orxonox |
---|
| 43 | { |
---|
| 44 | CreateFactory(CollisionShape); |
---|
| 45 | |
---|
[2374] | 46 | CollisionShape::CollisionShape(BaseObject* creator) |
---|
| 47 | : BaseObject(creator) |
---|
[2442] | 48 | , Synchronisable(creator) |
---|
[2303] | 49 | { |
---|
| 50 | RegisterObject(CollisionShape); |
---|
| 51 | |
---|
[2374] | 52 | this->parent_ = 0; |
---|
[2445] | 53 | this->parentID_ = OBJECTID_UNKNOWN; |
---|
[2374] | 54 | this->collisionShape_ = 0; |
---|
[2403] | 55 | this->position_ = Vector3::ZERO; |
---|
| 56 | this->orientation_ = Quaternion::IDENTITY; |
---|
| 57 | this->scale_ = Vector3::UNIT_SCALE; |
---|
[2469] | 58 | |
---|
| 59 | this->registerVariables(); |
---|
[2303] | 60 | } |
---|
| 61 | |
---|
| 62 | CollisionShape::~CollisionShape() |
---|
| 63 | { |
---|
| 64 | } |
---|
| 65 | |
---|
| 66 | void CollisionShape::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
---|
| 67 | { |
---|
| 68 | SUPER(CollisionShape, XMLPort, xmlelement, mode); |
---|
[2374] | 69 | |
---|
| 70 | XMLPortParamTemplate(CollisionShape, "position", setPosition, getPosition, xmlelement, mode, const Vector3&); |
---|
| 71 | XMLPortParamTemplate(CollisionShape, "orientation", setOrientation, getOrientation, xmlelement, mode, const Quaternion&); |
---|
[2429] | 72 | XMLPortParamTemplate(CollisionShape, "scale3D", setScale3D, getScale3D, xmlelement, mode, const Vector3&); |
---|
| 73 | XMLPortParamLoadOnly(CollisionShape, "scale", setScale, xmlelement, mode); |
---|
[2374] | 74 | XMLPortParamLoadOnly(CollisionShape, "yaw", yaw, xmlelement, mode); |
---|
| 75 | XMLPortParamLoadOnly(CollisionShape, "pitch", pitch, xmlelement, mode); |
---|
| 76 | XMLPortParamLoadOnly(CollisionShape, "roll", roll, xmlelement, mode); |
---|
[2303] | 77 | } |
---|
| 78 | |
---|
[2374] | 79 | void CollisionShape::registerVariables() |
---|
[2303] | 80 | { |
---|
[2442] | 81 | registerVariable(this->parentID_, variableDirection::toclient, new NetworkCallback<CollisionShape>(this, &CollisionShape::parentChanged)); |
---|
[2303] | 82 | } |
---|
| 83 | |
---|
[2423] | 84 | void CollisionShape::parentChanged() |
---|
[2303] | 85 | { |
---|
[2469] | 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 | } |
---|
[2303] | 96 | } |
---|
| 97 | |
---|
[2423] | 98 | void CollisionShape::updateParent() |
---|
| 99 | { |
---|
| 100 | if (this->parent_) |
---|
| 101 | this->parent_->updateChildShape(this); |
---|
| 102 | } |
---|
| 103 | |
---|
[2374] | 104 | bool CollisionShape::hasTransform() const |
---|
[2303] | 105 | { |
---|
[2374] | 106 | return (!this->position_.positionEquals(Vector3(0, 0, 0), 0.001) || |
---|
| 107 | !this->orientation_.equals(Quaternion(1,0,0,0), Degree(0.1))); |
---|
[2303] | 108 | } |
---|
[2306] | 109 | |
---|
| 110 | void CollisionShape::setScale3D(const Vector3& scale) |
---|
| 111 | { |
---|
[2433] | 112 | CCOUT(2) << "Warning: Cannot set the scale of a collision shape: Not yet implemented." << std::endl; |
---|
[2306] | 113 | } |
---|
| 114 | |
---|
[2374] | 115 | void CollisionShape::setScale(float scale) |
---|
[2306] | 116 | { |
---|
[2433] | 117 | CCOUT(2) << "Warning: Cannot set the scale of a collision shape: Not yet implemented." << std::endl; |
---|
[2306] | 118 | } |
---|
[2423] | 119 | |
---|
[2452] | 120 | void CollisionShape::calculateLocalInertia(btScalar mass, btVector3& inertia) const |
---|
[2423] | 121 | { |
---|
| 122 | if (this->collisionShape_) |
---|
| 123 | this->collisionShape_->calculateLocalInertia(mass, inertia); |
---|
[2452] | 124 | else |
---|
| 125 | inertia.setValue(0, 0, 0); |
---|
[2423] | 126 | } |
---|
[2303] | 127 | } |
---|