[Orxonox-commit 474] r3049 - in trunk/src: orxonox orxonox/objects/controllers orxonox/objects/gametypes orxonox/objects/worldentities util
landauf at orxonox.net
landauf at orxonox.net
Mon May 25 03:26:43 CEST 2009
Author: landauf
Date: 2009-05-25 03:26:43 +0200 (Mon, 25 May 2009)
New Revision: 3049
Added:
trunk/src/orxonox/objects/controllers/WaypointController.cc
trunk/src/orxonox/objects/controllers/WaypointController.h
trunk/src/orxonox/objects/controllers/WaypointPatrolController.cc
trunk/src/orxonox/objects/controllers/WaypointPatrolController.h
Modified:
trunk/src/orxonox/OrxonoxPrereqs.h
trunk/src/orxonox/objects/controllers/AIController.cc
trunk/src/orxonox/objects/controllers/ArtificialController.cc
trunk/src/orxonox/objects/controllers/ArtificialController.h
trunk/src/orxonox/objects/controllers/CMakeLists.txt
trunk/src/orxonox/objects/gametypes/TeamDeathmatch.cc
trunk/src/orxonox/objects/gametypes/TeamDeathmatch.h
trunk/src/orxonox/objects/worldentities/ControllableEntity.cc
trunk/src/orxonox/objects/worldentities/ControllableEntity.h
trunk/src/util/Math.cc
Log:
- Added option to add a Controller to a ControllableEntity in the XML file
- Added two new classes: WaypointController (follows waypoints) and WaypointPatrolController (follows waypoints and kills enemies within a given radius)
- Radarpoints in TeamDeathmatch are now coloured
Modified: trunk/src/orxonox/OrxonoxPrereqs.h
===================================================================
--- trunk/src/orxonox/OrxonoxPrereqs.h 2009-05-24 23:12:52 UTC (rev 3048)
+++ trunk/src/orxonox/OrxonoxPrereqs.h 2009-05-25 01:26:43 UTC (rev 3049)
@@ -195,6 +195,8 @@
class ArtificialController;
class AIController;
class ScriptController;
+ class WaypointController;
+ class WaypointPatrolController;
class PongAI;
class Info;
Modified: trunk/src/orxonox/objects/controllers/AIController.cc
===================================================================
--- trunk/src/orxonox/objects/controllers/AIController.cc 2009-05-24 23:12:52 UTC (rev 3048)
+++ trunk/src/orxonox/objects/controllers/AIController.cc 2009-05-25 01:26:43 UTC (rev 3049)
@@ -107,9 +107,9 @@
this->aimAtTarget();
if (this->bHasTargetPosition_)
- this->moveToTargetPosition(dt);
+ this->moveToTargetPosition();
- if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(500) && this->isLookingAtTarget(Ogre::Math::PI / 20.0))
+ if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0))
this->getControllableEntity()->fire(WeaponMode::fire);
SUPER(AIController, tick, dt);
Modified: trunk/src/orxonox/objects/controllers/ArtificialController.cc
===================================================================
--- trunk/src/orxonox/objects/controllers/ArtificialController.cc 2009-05-24 23:12:52 UTC (rev 3048)
+++ trunk/src/orxonox/objects/controllers/ArtificialController.cc 2009-05-25 01:26:43 UTC (rev 3049)
@@ -33,6 +33,9 @@
#include "objects/worldentities/ControllableEntity.h"
#include "objects/worldentities/pawns/Pawn.h"
+#include "objects/gametypes/TeamDeathmatch.h"
+#include "objects/controllers/WaypointPatrolController.h"
+
namespace orxonox
{
ArtificialController::ArtificialController(BaseObject* creator) : Controller(creator)
@@ -49,13 +52,13 @@
{
}
- void ArtificialController::moveToTargetPosition(float dt)
+ void ArtificialController::moveToPosition(const Vector3& target)
{
if (!this->getControllableEntity())
return;
- Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, this->targetPosition_);
- float distance = (this->targetPosition_ - this->getControllableEntity()->getPosition()).length();
+ Vector2 coord = get2DViewdirection(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
+ float distance = (target - this->getControllableEntity()->getPosition()).length();
if (this->target_ || distance > 10)
{
@@ -70,12 +73,31 @@
this->getControllableEntity()->moveFrontBack(0.8);
}
+ void ArtificialController::moveToTargetPosition()
+ {
+ this->moveToPosition(this->targetPosition_);
+ }
+
+ void ArtificialController::setTargetPosition(const Vector3& target)
+ {
+ this->targetPosition_ = target;
+ this->bHasTargetPosition_ = true;
+ }
+
void ArtificialController::searchRandomTargetPosition()
{
this->targetPosition_ = Vector3(rnd(-2000,2000), rnd(-2000,2000), rnd(-2000,2000));
this->bHasTargetPosition_ = true;
}
+ void ArtificialController::setTarget(Pawn* target)
+ {
+ this->target_ = target;
+
+ if (target)
+ this->targetPosition_ = target->getPosition();
+ }
+
void ArtificialController::searchNewTarget()
{
if (!this->getControllableEntity())
@@ -86,7 +108,9 @@
for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it; ++it)
{
-// if (it->getTeamNr() != this->getTeamNr())
+ if (ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))
+ continue;
+
if (static_cast<ControllableEntity*>(*it) != this->getControllableEntity())
{
float speed = this->getControllableEntity()->getVelocity().length();
@@ -146,4 +170,38 @@
this->searchRandomTargetPosition();
}
}
+
+ bool ArtificialController::sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype)
+ {
+ if (entity1 == entity2)
+ return true;
+
+ int team1 = -1;
+ int team2 = -1;
+
+ if (entity1->getXMLController())
+ {
+ WaypointPatrolController* wpc = dynamic_cast<WaypointPatrolController*>(entity1->getXMLController());
+ if (wpc)
+ team1 = wpc->getTeam();
+ }
+ if (entity2->getXMLController())
+ {
+ WaypointPatrolController* wpc = dynamic_cast<WaypointPatrolController*>(entity2->getXMLController());
+ if (wpc)
+ team2 = wpc->getTeam();
+ }
+
+ TeamDeathmatch* tdm = dynamic_cast<TeamDeathmatch*>(gametype);
+ if (tdm)
+ {
+ if (entity1->getPlayer())
+ team1 = tdm->getTeam(entity1->getPlayer());
+
+ if (entity2->getPlayer())
+ team2 = tdm->getTeam(entity2->getPlayer());
+ }
+
+ return (team1 == team2 && team1 != -1);
+ }
}
Modified: trunk/src/orxonox/objects/controllers/ArtificialController.h
===================================================================
--- trunk/src/orxonox/objects/controllers/ArtificialController.h 2009-05-24 23:12:52 UTC (rev 3048)
+++ trunk/src/orxonox/objects/controllers/ArtificialController.h 2009-05-25 01:26:43 UTC (rev 3049)
@@ -46,8 +46,13 @@
virtual void destroyedPawn(Pawn* pawn);
protected:
- void moveToTargetPosition(float dt);
+ void moveToPosition(const Vector3& target);
+ void moveToTargetPosition();
+
+ void setTargetPosition(const Vector3& target);
void searchRandomTargetPosition();
+
+ void setTarget(Pawn* target);
void searchNewTarget();
void forgetTarget();
void aimAtTarget();
@@ -55,6 +60,8 @@
bool isCloseAtTarget(float distance) const;
bool isLookingAtTarget(float angle) const;
+ static bool sameTeam(ControllableEntity* entity1, ControllableEntity* entity2, Gametype* gametype); // hack
+
bool bHasTargetPosition_;
Vector3 targetPosition_;
Pawn* target_;
Modified: trunk/src/orxonox/objects/controllers/CMakeLists.txt
===================================================================
--- trunk/src/orxonox/objects/controllers/CMakeLists.txt 2009-05-24 23:12:52 UTC (rev 3048)
+++ trunk/src/orxonox/objects/controllers/CMakeLists.txt 2009-05-25 01:26:43 UTC (rev 3049)
@@ -4,5 +4,7 @@
ArtificialController.cc
AIController.cc
ScriptController.cc
+ WaypointController.cc
+ WaypointPatrolController.cc
PongAI.cc
)
Added: trunk/src/orxonox/objects/controllers/WaypointController.cc
===================================================================
--- trunk/src/orxonox/objects/controllers/WaypointController.cc (rev 0)
+++ trunk/src/orxonox/objects/controllers/WaypointController.cc 2009-05-25 01:26:43 UTC (rev 3049)
@@ -0,0 +1,90 @@
+/*
+ * 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
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "WaypointController.h"
+
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+
+namespace orxonox
+{
+ CreateFactory(WaypointController);
+
+ WaypointController::WaypointController(BaseObject* creator) : ArtificialController(creator)
+ {
+ RegisterObject(WaypointController);
+
+ this->currentWaypoint_ = 0;
+ this->setAccuracy(100);
+ }
+
+ WaypointController::~WaypointController()
+ {
+ if (this->isInitialized())
+ {
+ for (size_t i = 0; i < this->waypoints_.size(); ++i)
+ delete this->waypoints_[i];
+ }
+ }
+
+ void WaypointController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+ {
+ SUPER(WaypointController, XMLPort, xmlelement, mode);
+
+ XMLPortParam(WaypointController, "accuracy", setAccuracy, getAccuracy, xmlelement, mode).defaultValues(100.0f);
+ XMLPortObject(WaypointController, WorldEntity, "waypoints", addWaypoint, getWaypoint, xmlelement, mode);
+ }
+
+ void WaypointController::tick(float dt)
+ {
+ if (!this->isActive())
+ return;
+
+ if (this->waypoints_.size() == 0 || !this->getControllableEntity())
+ return;
+
+ if (this->waypoints_[this->currentWaypoint_]->getWorldPosition().squaredDistance(this->getControllableEntity()->getPosition()) <= this->squaredaccuracy_)
+ this->currentWaypoint_ = (this->currentWaypoint_ + 1) % this->waypoints_.size();
+
+ this->moveToPosition(this->waypoints_[this->currentWaypoint_]->getWorldPosition());
+ }
+
+ void WaypointController::addWaypoint(WorldEntity* waypoint)
+ {
+ this->waypoints_.push_back(waypoint);
+ }
+
+ WorldEntity* WaypointController::getWaypoint(unsigned int index) const
+ {
+ if (index < this->waypoints_.size())
+ return this->waypoints_[index];
+ else
+ return 0;
+ }
+}
Added: trunk/src/orxonox/objects/controllers/WaypointController.h
===================================================================
--- trunk/src/orxonox/objects/controllers/WaypointController.h (rev 0)
+++ trunk/src/orxonox/objects/controllers/WaypointController.h 2009-05-25 01:26:43 UTC (rev 3049)
@@ -0,0 +1,65 @@
+/*
+ * 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
+ * Co-authors:
+ * ...
+ *
+ */
+
+#ifndef _WaypointController_H__
+#define _WaypointController_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include <vector>
+
+#include "ArtificialController.h"
+#include "objects/Tickable.h"
+
+namespace orxonox
+{
+ class _OrxonoxExport WaypointController : public ArtificialController, public Tickable
+ {
+ public:
+ WaypointController(BaseObject* creator);
+ virtual ~WaypointController();
+
+ virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+ virtual void tick(float dt);
+
+ void addWaypoint(WorldEntity* waypoint);
+ WorldEntity* getWaypoint(unsigned int index) const;
+
+ inline void setAccuracy(float accuracy)
+ { this->squaredaccuracy_ = accuracy*accuracy; }
+ inline float getAccuracy() const
+ { return sqrt(this->squaredaccuracy_); }
+
+ protected:
+ std::vector<WorldEntity*> waypoints_;
+ size_t currentWaypoint_;
+ float squaredaccuracy_;
+ };
+}
+
+#endif /* _WaypointController_H__ */
Added: trunk/src/orxonox/objects/controllers/WaypointPatrolController.cc
===================================================================
--- trunk/src/orxonox/objects/controllers/WaypointPatrolController.cc (rev 0)
+++ trunk/src/orxonox/objects/controllers/WaypointPatrolController.cc 2009-05-25 01:26:43 UTC (rev 3049)
@@ -0,0 +1,104 @@
+/*
+ * 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
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "WaypointPatrolController.h"
+
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+
+namespace orxonox
+{
+ CreateFactory(WaypointPatrolController);
+
+ WaypointPatrolController::WaypointPatrolController(BaseObject* creator) : WaypointController(creator)
+ {
+ RegisterObject(WaypointPatrolController);
+
+ this->team_ = 0;
+ this->alertnessradius_ = 500;
+
+ this->patrolTimer_.setTimer(rnd(), true, this, createExecutor(createFunctor(&WaypointPatrolController::searchEnemy)));
+ }
+
+ void WaypointPatrolController::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+ {
+ SUPER(WaypointPatrolController, XMLPort, xmlelement, mode);
+
+ XMLPortParam(WaypointPatrolController, "alertnessradius", setAlertnessRadius, getAlertnessRadius, xmlelement, mode).defaultValues(500.0f);
+ XMLPortParam(WaypointPatrolController, "team", setTeam, getTeam, xmlelement, mode).defaultValues(0);
+ }
+
+ void WaypointPatrolController::tick(float dt)
+ {
+ if (!this->isActive())
+ return;
+
+ if (this->target_)
+ {
+ this->aimAtTarget();
+
+ if (this->bHasTargetPosition_)
+ this->moveToTargetPosition();
+
+ if (this->getControllableEntity() && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0))
+ this->getControllableEntity()->fire(WeaponMode::fire);
+ }
+ else
+ {
+ SUPER(WaypointPatrolController, tick, dt);
+ }
+ }
+
+ void WaypointPatrolController::searchEnemy()
+ {
+ this->patrolTimer_.setInterval(rnd());
+
+ if (!this->getControllableEntity())
+ return;
+
+ Vector3 myposition = this->getControllableEntity()->getPosition();
+ float shortestsqdistance = (unsigned int)-1;
+
+ for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)
+ {
+ if (ArtificialController::sameTeam(this->getControllableEntity(), static_cast<ControllableEntity*>(*it), this->getGametype()))
+ continue;
+
+ float sqdistance = it->getPosition().squaredDistance(myposition);
+ if (sqdistance < shortestsqdistance)
+ {
+ shortestsqdistance = sqdistance;
+ this->target_ = (*it);
+ }
+ }
+
+ if (shortestsqdistance > (this->alertnessradius_ * this->alertnessradius_))
+ this->target_ = 0;
+ }
+}
Added: trunk/src/orxonox/objects/controllers/WaypointPatrolController.h
===================================================================
--- trunk/src/orxonox/objects/controllers/WaypointPatrolController.h (rev 0)
+++ trunk/src/orxonox/objects/controllers/WaypointPatrolController.h 2009-05-25 01:26:43 UTC (rev 3049)
@@ -0,0 +1,67 @@
+/*
+ * 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
+ * Co-authors:
+ * ...
+ *
+ */
+
+#ifndef _WaypointPatrolController_H__
+#define _WaypointPatrolController_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "WaypointController.h"
+#include "tools/Timer.h"
+
+namespace orxonox
+{
+ class _OrxonoxExport WaypointPatrolController : public WaypointController
+ {
+ public:
+ WaypointPatrolController(BaseObject* creator);
+ virtual ~WaypointPatrolController() {}
+
+ virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+ virtual void tick(float dt);
+
+ inline void setTeam(int team)
+ { this->team_ = team; }
+ inline int getTeam() const
+ { return this->team_; }
+
+ inline void setAlertnessRadius(float radius)
+ { this->alertnessradius_ = radius; }
+ inline float getAlertnessRadius() const
+ { return this->alertnessradius_; }
+
+ protected:
+ void searchEnemy();
+
+ int team_;
+ float alertnessradius_;
+ Timer<WaypointPatrolController> patrolTimer_;
+ };
+}
+
+#endif /* _WaypointPatrolController_H__ */
Modified: trunk/src/orxonox/objects/gametypes/TeamDeathmatch.cc
===================================================================
--- trunk/src/orxonox/objects/gametypes/TeamDeathmatch.cc 2009-05-24 23:12:52 UTC (rev 3048)
+++ trunk/src/orxonox/objects/gametypes/TeamDeathmatch.cc 2009-05-25 01:26:43 UTC (rev 3049)
@@ -163,6 +163,8 @@
{
if (pawn)
{
+ pawn->setRadarObjectColour(this->teamcolours_[it_player->second]);
+
std::set<WorldEntity*> pawnAttachments = pawn->getAttachedObjects();
for (std::set<WorldEntity*>::iterator it = pawnAttachments.begin(); it != pawnAttachments.end(); ++it)
{
Modified: trunk/src/orxonox/objects/gametypes/TeamDeathmatch.h
===================================================================
--- trunk/src/orxonox/objects/gametypes/TeamDeathmatch.h 2009-05-24 23:12:52 UTC (rev 3048)
+++ trunk/src/orxonox/objects/gametypes/TeamDeathmatch.h 2009-05-25 01:26:43 UTC (rev 3049)
@@ -54,13 +54,14 @@
virtual void playerStartsControllingPawn(PlayerInfo* player, Pawn* pawn);
+ int getTeam(PlayerInfo* player);
+
inline const ColourValue& getTeamColour(int teamnr) const
{ return this->teamcolours_[teamnr]; }
protected:
virtual SpawnPoint* getBestSpawnPoint(PlayerInfo* player) const;
bool pawnsAreInTheSameTeam(Pawn* pawn1, Pawn* pawn2);
- int getTeam(PlayerInfo* player);
std::map<PlayerInfo*, int> teamnumbers_;
std::vector<ColourValue> teamcolours_;
Modified: trunk/src/orxonox/objects/worldentities/ControllableEntity.cc
===================================================================
--- trunk/src/orxonox/objects/worldentities/ControllableEntity.cc 2009-05-24 23:12:52 UTC (rev 3048)
+++ trunk/src/orxonox/objects/worldentities/ControllableEntity.cc 2009-05-25 01:26:43 UTC (rev 3049)
@@ -39,6 +39,7 @@
#include "objects/Scene.h"
#include "objects/infos/PlayerInfo.h"
+#include "objects/controllers/Controller.h"
#include "objects/worldentities/Camera.h"
#include "objects/worldentities/CameraPosition.h"
#include "overlays/OverlayGroup.h"
@@ -60,6 +61,7 @@
this->playerID_ = OBJECTID_UNKNOWN;
this->hud_ = 0;
this->camera_ = 0;
+ this->xmlcontroller_ = 0;
this->bDestroyWhenPlayerLeft_ = false;
this->cameraPositionRootNode_ = this->node_->createChildSceneNode();
this->bMouseLook_ = false;
@@ -92,6 +94,9 @@
if (this->getPlayer() && this->getPlayer()->getControllableEntity() == this)
this->getPlayer()->stopControl();
+ if (this->xmlcontroller_)
+ delete this->xmlcontroller_;
+
if (this->hud_)
delete this->hud_;
@@ -114,6 +119,7 @@
XMLPortParam(ControllableEntity, "camerapositiontemplate", setCameraPositionTemplate, getCameraPositionTemkplate, xmlelement, mode);
XMLPortObject(ControllableEntity, CameraPosition, "camerapositions", addCameraPosition, getCameraPosition, xmlelement, mode);
+ XMLPortObject(ControllableEntity, Controller, "controller", setXMLController, getXMLController, xmlelement, mode);
}
void ControllableEntity::setConfigValues()
@@ -303,6 +309,18 @@
}
}
+ void ControllableEntity::setXMLController(Controller* controller)
+ {
+ if (!this->xmlcontroller_)
+ {
+ this->xmlcontroller_ = controller;
+ this->bHasLocalController_ = true;
+ this->xmlcontroller_->setControllableEntity(this);
+ }
+ else
+ COUT(2) << "Warning: ControllableEntity \"" << this->getName() << "\" already has a Controller." << std::endl;
+ }
+
void ControllableEntity::parentChanged()
{
WorldEntity::parentChanged();
Modified: trunk/src/orxonox/objects/worldentities/ControllableEntity.h
===================================================================
--- trunk/src/orxonox/objects/worldentities/ControllableEntity.h 2009-05-24 23:12:52 UTC (rev 3048)
+++ trunk/src/orxonox/objects/worldentities/ControllableEntity.h 2009-05-25 01:26:43 UTC (rev 3049)
@@ -129,6 +129,9 @@
inline float getMouseLookSpeed() const
{ return this->mouseLookSpeed_; }
+ inline Controller* getXMLController() const
+ { return this->xmlcontroller_; }
+
protected:
virtual void setPlayer(PlayerInfo* player); // don't call this directly, use friend class PlayerInfo instead
virtual void removePlayer(); // don't call this directly, use friend class PlayerInfo instead
@@ -141,6 +144,8 @@
{ this->hudtemplate_ = name; }
private:
+ void setXMLController(Controller* controller);
+
void overwrite();
void processOverwrite();
@@ -187,6 +192,7 @@
Ogre::SceneNode* cameraPositionRootNode_;
std::list<CameraPosition*> cameraPositions_;
std::string cameraPositionTemplate_;
+ Controller* xmlcontroller_;
};
}
Modified: trunk/src/util/Math.cc
===================================================================
--- trunk/src/util/Math.cc 2009-05-24 23:12:52 UTC (rev 3048)
+++ trunk/src/util/Math.cc 2009-05-25 01:26:43 UTC (rev 3049)
@@ -128,7 +128,14 @@
orxonox::Vector3 projection = Ogre::Plane(mydirection, myposition).projectVector(distance);
float projectionlength = projection.length();
- if (projectionlength == 0) return orxonox::Vector2(0, 0);
+ if (projectionlength == 0)
+ {
+ if (myposition.dotProduct(otherposition) >= 0)
+ return orxonox::Vector2(0, 0);
+ else
+ return orxonox::Vector2(0, 1);
+ }
+
float angle = acos(clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1));
if ((mydirection.crossProduct(myorthonormal)).dotProduct(distance) > 0)
@@ -160,7 +167,13 @@
orxonox::Vector3 projection = Ogre::Plane(mydirection, myposition).projectVector(distance);
float projectionlength = projection.length();
- if (projectionlength == 0) return orxonox::Vector2(0, 0);
+ if (projectionlength == 0)
+ {
+ if (myposition.dotProduct(otherposition) >= 0)
+ return orxonox::Vector2(0, 0);
+ else
+ return orxonox::Vector2(0, 1);
+ }
float angle = acos(clamp<float>(myorthonormal.dotProduct(projection) / projectionlength, -1, 1));
float distancelength = distance.length();
More information about the Orxonox-commit
mailing list