[Orxonox-commit 7070] r11687 - code/branches/Waypoints_HS17/src/orxonox/controllers
jostoffe at orxonox.net
jostoffe at orxonox.net
Sun Dec 17 17:28:37 CET 2017
Author: jostoffe
Date: 2017-12-17 17:28:37 +0100 (Sun, 17 Dec 2017)
New Revision: 11687
Added:
code/branches/Waypoints_HS17/src/orxonox/controllers/ArrowController.cc
code/branches/Waypoints_HS17/src/orxonox/controllers/ArrowController.h
Log:
Added: code/branches/Waypoints_HS17/src/orxonox/controllers/ArrowController.cc
===================================================================
--- code/branches/Waypoints_HS17/src/orxonox/controllers/ArrowController.cc (rev 0)
+++ code/branches/Waypoints_HS17/src/orxonox/controllers/ArrowController.cc 2017-12-17 16:28:37 UTC (rev 11687)
@@ -0,0 +1,156 @@
+/*
+ * 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:
+ * Oli Scheuss
+ * Co-authors:
+ * Damian 'Mozork' Frick
+ *
+ */
+
+#include "ArrowController.h"
+#include "HumanController.h"
+#include "worldentities/WorldEntity.h"
+
+#include "worldentities/Arrow.h"
+#include "util/Math.h"
+
+namespace orxonox
+{
+
+ RegisterClass(ArrowController);
+
+
+
+ /**
+ @brief
+ Constructor.
+ */
+ ArrowController::ArrowController(Context* context) : Controller(context)
+ {
+
+ RegisterObject(ArrowController);
+
+ this->currentGPSPoint_ = 0;
+ this->accuracy_ = 1000.0f;
+
+ arrow = nullptr;
+
+ for(Arrow* a: ObjectList<Arrow>())
+ arrow = a;
+
+ assert(arrow != nullptr);
+ this->setControllableEntity(arrow);
+
+ orxout() << "constructor aufgerufen" << endl;
+ }
+
+ //Set the distance you need to reach before the next waypoint will be selected
+ void ArrowController::setAccuracy(float accuracy){
+ this->accuracy_ = accuracy;
+ }
+
+ float ArrowController::getAccuracy(){
+ return this->accuracy_;
+ };
+
+ void ArrowController::addGPSPoint(WorldEntity* gpspoint)
+ {
+ this->gpspoints_.push_back(gpspoint);
+ }
+
+ WorldEntity* ArrowController::getGPSPoint(unsigned int index) const
+ {
+ if (index < this->gpspoints_.size())
+ return this->gpspoints_[index];
+ else
+ return nullptr;
+ }
+ /**
+ @brief
+ Destructor.
+ */
+
+ ArrowController::~ArrowController()
+ {
+ for (WorldEntity* gpspoint : this->gpspoints_)
+ {
+ if(gpspoint)
+ gpspoint->destroy();
+ }
+
+ }
+
+
+ void ArrowController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+ {
+ SUPER(ArrowController, XMLPort, xmlelement, mode);
+
+ XMLPortObject(ArrowController, WorldEntity, "gpspoints", addGPSPoint, getGPSPoint, xmlelement, mode);
+ XMLPortParam(ArrowController, "accuracy", setAccuracy, getAccuracy, xmlelement, mode);
+ }
+
+ void ArrowController::tick(float dt)
+ {
+ if (!this->isActive())
+ return;
+
+ if (this->gpspoints_.size() == 0 || !this->getControllableEntity())
+ return;
+ //Set all waypoint to invisible at the beginning
+ if (this->currentGPSPoint_ == 0){
+ for(unsigned int i = 0; i < this->gpspoints_.size(); i++ )
+ this->gpspoints_[i]->setVisible(false);
+ }
+ //Make the arrow inivisible as soon as you reached the last Waypoint, otherwise make the next waypoint visible
+ if(currentGPSPoint_ >= gpspoints_.size()){
+ this->getControllableEntity()->setVisible(false);
+ return;
+ }
+ else this->gpspoints_[this->currentGPSPoint_]->setVisible(true);
+
+ //Set the next waypoint as target as soon as you reached the previous one
+ if (this->gpspoints_[this->currentGPSPoint_]->getWorldPosition().squaredDistance(this->getControllableEntity()->getPosition()) <= this->accuracy_){
+ this->gpspoints_[this->currentGPSPoint_]->setVisible(false);
+ this->currentGPSPoint_ = (this->currentGPSPoint_ + 1);
+ return;
+ }
+
+ Vector3 target = gpspoints_[currentGPSPoint_]->getWorldPosition();
+ WorldEntity::TransformSpace trans = WorldEntity::TransformSpace::World;
+
+ //Get the position and orientation of the Spaceship
+ Vector3 spaceShipPosition = HumanController::getLocalControllerSingleton()->getControllableEntity()->getWorldPosition();
+ Quaternion spaceShipOrientation = HumanController::getLocalControllerSingleton()->getControllableEntity()->getOrientation();
+
+ //Calculate the new arrow position
+ Vector3 ss_y = spaceShipOrientation.yAxis();
+ spaceShipPosition.x += 20 * ss_y.x;
+ spaceShipPosition.y += 20 * ss_y.y;
+ spaceShipPosition.z += 20 * ss_y.z;
+
+ //Update Arrow position and orientation
+ this->getControllableEntity()->setPosition(spaceShipPosition);
+ this->getControllableEntity()->lookAt(target, trans, Vector3(0,0,1));
+
+
+ }
+}
Added: code/branches/Waypoints_HS17/src/orxonox/controllers/ArrowController.h
===================================================================
--- code/branches/Waypoints_HS17/src/orxonox/controllers/ArrowController.h (rev 0)
+++ code/branches/Waypoints_HS17/src/orxonox/controllers/ArrowController.h 2017-12-17 16:28:37 UTC (rev 11687)
@@ -0,0 +1,73 @@
+/*
+ * 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:
+ * Oli Scheuss
+ * Co-authors:
+ * Damian 'Mozork' Frick
+ *
+ */
+
+#ifndef _ArrowController_H__
+#define _ArrowController_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "Controller.h"
+#include "tools/interfaces/Tickable.h"
+#include "worldentities/Arrow.h"
+
+namespace orxonox
+{
+ /**
+ @brief
+ Controller for the Arrow of the PPS tutorial.
+ @author
+ Oli Scheuss
+ */
+ class _OrxonoxExport ArrowController : public Controller, public Tickable
+ {
+ public:
+ ArrowController(Context* context);
+ virtual ~ArrowController();
+
+ virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
+
+ void addGPSPoint(WorldEntity* gpspoint);
+ WorldEntity* getGPSPoint(unsigned int index) const;
+ void setAccuracy(float accuracy);
+ float getAccuracy();
+
+ virtual void tick(float dt); //!< The controlling happens here. This method defines what the controller has to do each tick.
+
+ protected:
+
+ std::vector<WeakPtr<WorldEntity>> gpspoints_;
+ size_t currentGPSPoint_;
+ float accuracy_;
+ WorldEntity* defaultGPSpoint_;
+
+ private:
+ Arrow *arrow;
+ };
+}
+
+#endif /* _ArrowController_H__ */
More information about the Orxonox-commit
mailing list