[Orxonox-commit 6590] r11230 - code/branches/QuestGuide_HS16/src/orxonox/worldentities
ooguz at orxonox.net
ooguz at orxonox.net
Mon Oct 10 16:06:23 CEST 2016
Author: ooguz
Date: 2016-10-10 16:06:23 +0200 (Mon, 10 Oct 2016)
New Revision: 11230
Added:
code/branches/QuestGuide_HS16/src/orxonox/worldentities/Waypoint.cc
code/branches/QuestGuide_HS16/src/orxonox/worldentities/Waypoint.h
Modified:
code/branches/QuestGuide_HS16/src/orxonox/worldentities/CMakeLists.txt
Log:
Waypoint Klasse und Header erstellt.
Modified: code/branches/QuestGuide_HS16/src/orxonox/worldentities/CMakeLists.txt
===================================================================
--- code/branches/QuestGuide_HS16/src/orxonox/worldentities/CMakeLists.txt 2016-10-10 14:02:29 UTC (rev 11229)
+++ code/branches/QuestGuide_HS16/src/orxonox/worldentities/CMakeLists.txt 2016-10-10 14:06:23 UTC (rev 11230)
@@ -12,6 +12,7 @@
TeamSpawnPoint.cc
ExplosionPart.cc
Actionpoint.cc
+ Waypoint.cc
)
ADD_SUBDIRECTORY(pawns)
Added: code/branches/QuestGuide_HS16/src/orxonox/worldentities/Waypoint.cc
===================================================================
--- code/branches/QuestGuide_HS16/src/orxonox/worldentities/Waypoint.cc (rev 0)
+++ code/branches/QuestGuide_HS16/src/orxonox/worldentities/Waypoint.cc 2016-10-10 14:06:23 UTC (rev 11230)
@@ -0,0 +1,118 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Reto Grieder (physics)
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include "Waypoint.h"
+
+#include <OgreSceneNode.h>
+#include <BulletDynamics/Dynamics/btRigidBody.h>
+#include "util/OrxAssert.h"
+#include "core/CoreIncludes.h"
+
+namespace orxonox
+{
+ RegisterClass(Waypoint);
+
+ Waypoint::Waypoint(Context* context) : StaticEntity(context)
+ {
+ RegisterObject(Waypoint);
+
+ this->setPriority(Priority::VeryLow);
+
+ this->registerVariables();
+ }
+
+ Waypoint::~Waypoint()
+ {
+ }
+
+ void Waypoint::registerVariables()
+ {
+ // Ugly const casts, but are valid because position and orientation are not actually const
+ registerVariable(const_cast<Vector3&>(this->getPosition()), VariableDirection::ToClient, new NetworkCallback<StaticEntity>(this, &StaticEntity::positionChanged));
+ registerVariable(const_cast<Quaternion&>(this->getOrientation()), VariableDirection::ToClient, new NetworkCallback<StaticEntity>(this, &StaticEntity::orientationChanged));
+ }
+
+
+ void Waypoint::setPosition(const Vector3& position)
+ {
+ if (this->addedToPhysicalWorld())
+ {
+ orxout(internal_warning) << "Attempting to change the position of a StaticEntity at physics run time. Ignoring change." << endl;
+ return;
+ }
+ if (this->isStatic())
+ {
+ btTransform transf = this->physicalBody_->getWorldTransform();
+ transf.setOrigin(btVector3(position.x, position.y, position.z));
+ this->physicalBody_->setWorldTransform(transf);
+ }
+
+ this->node_->setPosition(position);
+ }
+
+ void Waypoint::setOrientation(const Quaternion& orientation)
+ {
+ if (this->addedToPhysicalWorld())
+ {
+ orxout(internal_warning) << "Attempting to change the orientation of a StaticEntity at physics run time. Ignoring change." << endl;
+ return;
+ }
+ if (this->isStatic())
+ {
+ btTransform transf = this->physicalBody_->getWorldTransform();
+ transf.setRotation(btQuaternion(orientation.x, orientation.y, orientation.z, orientation.w));
+ this->physicalBody_->setWorldTransform(transf);
+ }
+
+ this->node_->setOrientation(orientation);
+ }
+/*
+ bool StaticEntity::isCollisionTypeLegal(WorldEntity::CollisionType type) const
+ {
+ if (type == WorldEntity::CollisionType::Kinematic || type == WorldEntity::CollisionType::Dynamic)
+ {
+ orxout(internal_warning) << "Cannot tell a StaticEntity to have kinematic or dynamic collision type! Ignoring." << endl;
+ assert(false); // Only in debug mode
+ return false;
+ }
+ else
+ return true;
+ }
+*/
+ void Waypoint::setWorldTransform(const btTransform& worldTrans)
+ {
+ OrxAssert(false, "Setting world transform of a StaticEntity, which is CF_STATIC!");
+ }
+
+ void Waypoint::getWorldTransform(btTransform& worldTrans) const
+ {
+ worldTrans.setOrigin(btVector3(node_->getPosition().x, node_->getPosition().y, node_->getPosition().z));
+ worldTrans.setRotation(btQuaternion(node_->getOrientation().x, node_->getOrientation().y, node_->getOrientation().z, node_->getOrientation().w));
+ }
+}
Added: code/branches/QuestGuide_HS16/src/orxonox/worldentities/Waypoint.h
===================================================================
--- code/branches/QuestGuide_HS16/src/orxonox/worldentities/Waypoint.h (rev 0)
+++ code/branches/QuestGuide_HS16/src/orxonox/worldentities/Waypoint.h 2016-10-10 14:06:23 UTC (rev 11230)
@@ -0,0 +1,78 @@
+/*
+ * ORXONOX - the hottest 3D action shooter ever to exist
+ * > www.orxonox.net <
+ *
+ *
+ * License notice:
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Author:
+ * Fabian 'x3n' Landau
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+#ifndef _Waypoint_H__
+#define _Waypoint_H__
+
+#include "OrxonoxPrereqs.h"
+#include "StaticEntity.h"
+
+namespace orxonox
+{
+ /**
+ @brief
+ The StaticEntity is the simplest derivative of the @ref orxonox::WorldEntity class. This means all StaticEntity instances also have
+ a position in space, a mass, a scale, a frication, ... because every StaticEntity is a WorldEntity. You can attach StaticEntities to eachother ike @ref orxonox::WorldEntity WorldEntities.
+
+ In contrast to the MobileEntity the StaticEntity cannot move with respect to the parent to which it is attached. That's why
+ it is called StaticEntity. It will keep the same position (always with respect to its parent) forever unless you call the
+ function @see setPosition to changee it.
+
+ A StaticEntity can only have the collisition type WorldEntity::None or WorldEntity::Static. The collsion types WorldEntity::Dynamic and WorldEntity::Kinematic are illegal.
+ */
+
+ class _OrxonoxExport Waypoint : public StaticEntity
+ {
+ public:
+ Waypoint(Context* context);
+ virtual ~Waypoint();
+
+ using StaticEntity::setPosition;
+ using StaticEntity::setOrientation;
+
+ virtual void setPosition(const Vector3& position) override;
+ virtual void setOrientation(const Quaternion& orientation) override;
+
+ private:
+ void registerVariables();
+ //virtual bool isCollisionTypeLegal(CollisionType type) const override;
+
+ // network callbacks
+ inline void positionChanged()
+ { this->setPosition(this->getPosition()); }
+ inline void orientationChanged()
+ { this->setOrientation(this->getOrientation()); }
+
+ // Bullet btMotionState related
+ virtual void setWorldTransform(const btTransform& worldTrans) override;
+ virtual void getWorldTransform(btTransform& worldTrans) const override;
+ };
+}
+
+#endif /* _StaticEntity_H__ */
More information about the Orxonox-commit
mailing list