[Orxonox-commit 3958] r8632 - in code/branches/presentation/src: modules/objects orxonox/worldentities

dafrick at orxonox.net dafrick at orxonox.net
Fri May 27 23:35:05 CEST 2011


Author: dafrick
Date: 2011-05-27 23:35:05 +0200 (Fri, 27 May 2011)
New Revision: 8632

Added:
   code/branches/presentation/src/modules/objects/SpaceBoundaries.cc
   code/branches/presentation/src/modules/objects/SpaceBoundaries.h
Removed:
   code/branches/presentation/src/orxonox/worldentities/SpaceBoundaries.cc
   code/branches/presentation/src/orxonox/worldentities/SpaceBoundaries.h
Modified:
   code/branches/presentation/src/modules/objects/CMakeLists.txt
   code/branches/presentation/src/modules/objects/ObjectsPrereqs.h
   code/branches/presentation/src/orxonox/worldentities/CMakeLists.txt
Log:
Moving space bounaries into modules/objects


Modified: code/branches/presentation/src/modules/objects/CMakeLists.txt
===================================================================
--- code/branches/presentation/src/modules/objects/CMakeLists.txt	2011-05-27 21:09:00 UTC (rev 8631)
+++ code/branches/presentation/src/modules/objects/CMakeLists.txt	2011-05-27 21:35:05 UTC (rev 8632)
@@ -3,6 +3,7 @@
   ForceField.cc
   Planet.cc
   Script.cc
+  SpaceBoundaries.cc
 )
 
 ADD_SUBDIRECTORY(collisionshapes)

Modified: code/branches/presentation/src/modules/objects/ObjectsPrereqs.h
===================================================================
--- code/branches/presentation/src/modules/objects/ObjectsPrereqs.h	2011-05-27 21:09:00 UTC (rev 8631)
+++ code/branches/presentation/src/modules/objects/ObjectsPrereqs.h	2011-05-27 21:35:05 UTC (rev 8632)
@@ -71,6 +71,7 @@
     class ForceField;
     class Planet;
     class Script;
+    class SpaceBoundaries;
 
     // collisionshapes
     class BoxCollisionShape;

Copied: code/branches/presentation/src/modules/objects/SpaceBoundaries.cc (from rev 8628, code/branches/presentation/src/orxonox/worldentities/SpaceBoundaries.cc)
===================================================================
--- code/branches/presentation/src/modules/objects/SpaceBoundaries.cc	                        (rev 0)
+++ code/branches/presentation/src/modules/objects/SpaceBoundaries.cc	2011-05-27 21:35:05 UTC (rev 8632)
@@ -0,0 +1,322 @@
+/*
+ *   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:
+ *      Maurus Kaufmann
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#include "SpaceBoundaries.h"
+
+#include <OgreBillboardSet.h>
+
+#include "core/CoreIncludes.h"
+#include "core/ObjectListIterator.h"
+#include "core/XMLPort.h"
+
+#include "graphics/Billboard.h"
+#include "infos/PlayerInfo.h"
+#include "worldentities/WorldEntity.h"
+#include "worldentities/pawns/Pawn.h"
+
+namespace orxonox
+{
+    CreateFactory(SpaceBoundaries);
+
+    SpaceBoundaries::SpaceBoundaries(BaseObject* creator) : StaticEntity(creator)
+    {
+        RegisterObject(SpaceBoundaries);
+
+        this->setMaxDistance(3000);
+        this->setWarnDistance(this->getMaxDistance());
+        this->setShowDistance(this->getMaxDistance());
+        this->setReaction(0);
+    }
+    SpaceBoundaries::~SpaceBoundaries()
+    {
+        if (this->isInitialized())
+        {
+            this->pawnsIn_.clear();
+        
+            for( std::vector<billboardAdministration>::iterator current = this->billboards_.begin(); current != this->billboards_.end(); current++)
+            {
+                if( current->billy != NULL)
+                {
+                    delete current->billy;
+                }
+            }
+            this->billboards_.clear();
+        }
+    }
+    
+    void SpaceBoundaries::checkWhoIsIn()
+    {
+        pawnsIn_.clear();
+        for(ObjectListIterator<Pawn> current = ObjectList<Pawn>::begin(); current != ObjectList<Pawn>::end(); ++current)
+        {
+            Pawn* currentPawn = *current;
+            if( this->reaction_ == 0 )
+            {
+                float distance = this->computeDistance(currentPawn);
+                if(distance <= this->maxDistance_)
+                {
+                    pawnsIn_.push_back(currentPawn);
+                }
+            } else if (this->reaction_ == 2) {
+                float distance = this->computeDistance(currentPawn);
+                if(distance >= this->maxDistance_)
+                {
+                    pawnsIn_.push_back(currentPawn);
+                }
+            } else {
+                pawnsIn_.push_back(currentPawn);
+            }
+        }
+    }
+    
+    void SpaceBoundaries::positionBillboard(const Vector3 position)
+    {
+        std::vector<billboardAdministration>::iterator current;
+        for( current = this->billboards_.begin(); current != this->billboards_.end(); current++)
+        {
+            if(!current->usedYet)
+            {
+                break;
+            }
+        }
+        if( current == this->billboards_.end() )
+        {
+            Billboard *tmp = new Billboard(this);
+            tmp->setPosition(position);
+            this->setBillboardOptions( tmp );
+            Vector3 normalisedVec = (position - this->getPosition()).normalisedCopy(); /* Vektor von Kugelmitte nach aussen */
+            tmp->setCommonDirection ( -1.0 * normalisedVec );
+            tmp->setCommonUpVector( Vector3::UNIT_Z );
+            billboardAdministration tmp2 = { true, tmp };
+            this->billboards_.push_back( tmp2 );
+        } else {
+            current->billy->setPosition(position);
+            current->billy->setVisible(true);
+            current->usedYet = true;
+            Vector3 normalisedVec = (position - this->getPosition()).normalisedCopy(); /* Vektor von Kugelmitte nach aussen */
+            current->billy->setCommonDirection ( -1.0 * normalisedVec );
+            current->billy->setCommonUpVector( Vector3::UNIT_Z );
+        }
+    }
+    
+    void SpaceBoundaries::setBillboardOptions(Billboard *billy)
+    {
+        if(billy != NULL)
+        {
+            billy->setMaterial("Grid");
+            billy->setBillboardType(Ogre::BBT_PERPENDICULAR_COMMON);
+            billy->setDefaultDimensions(150, 150);
+            billy->setVisible(true);
+        }
+    }
+    
+    void SpaceBoundaries::removeAllBillboards()
+    {
+        for( std::vector<billboardAdministration>::iterator current = this->billboards_.begin(); current != this->billboards_.end(); current++ )
+        {
+            current->usedYet = false;
+            current->billy->setVisible(false);
+        }
+    }
+    
+    void SpaceBoundaries::setMaxDistance(float r)
+    {
+        this->maxDistance_ = r;
+    }
+    float SpaceBoundaries::getMaxDistance()
+    {
+        return this->maxDistance_;
+    }
+    
+    void SpaceBoundaries::setWarnDistance(float r)
+    {
+        this->warnDistance_ = r;
+    }
+    float SpaceBoundaries::getWarnDistance()
+    {
+        return this->warnDistance_;
+    }
+    
+    void SpaceBoundaries::setShowDistance(float r)
+    {
+        this->showDistance_ = r;
+    }
+    float SpaceBoundaries::getShowDistance()
+    {
+        return this->showDistance_;
+    }
+    
+    void SpaceBoundaries::setHealthDecrease(float amount)
+    {
+        this->healthDecrease_ = amount/1000;
+    }
+    float SpaceBoundaries::getHealthDecrease()
+    {
+        return this->healthDecrease_;
+    }
+    
+    void SpaceBoundaries::setReaction(int mode)
+    {
+        this->reaction_ = mode;
+    }
+    int SpaceBoundaries::getReaction()
+    {
+        return this->reaction_;
+    }
+
+    void SpaceBoundaries::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+    {
+        SUPER(SpaceBoundaries, XMLPort, xmlelement, mode);
+
+        XMLPortParam(SpaceBoundaries, "maxDistance", setMaxDistance, getMaxDistance, xmlelement, mode);
+        XMLPortParam(SpaceBoundaries, "warnDistance", setWarnDistance, getWarnDistance, xmlelement, mode);
+        XMLPortParam(SpaceBoundaries, "showDistance", setShowDistance, getShowDistance, xmlelement, mode);
+        XMLPortParam(SpaceBoundaries, "healthDecrease", setHealthDecrease, getHealthDecrease, xmlelement, mode);
+        XMLPortParam(SpaceBoundaries, "reactionMode", setReaction, getReaction, xmlelement, mode);
+    }
+    
+    void SpaceBoundaries::tick(float dt)
+    {
+        this->checkWhoIsIn();
+        this->removeAllBillboards();
+        
+        float distance;
+        bool humanItem;
+        for( std::list<WeakPtr<Pawn> >::iterator current = pawnsIn_.begin(); current != pawnsIn_.end(); current++ )
+        {
+            Pawn* currentPawn = current->get();
+            if( currentPawn && currentPawn->getNode() ) 
+            {
+                distance = this->computeDistance(currentPawn);
+                humanItem = this->isHumanPlayer(currentPawn);
+                COUT(5) << "Distance:" << distance << std::endl; // message for debugging
+                if(distance > this->warnDistance_ && distance < this->maxDistance_) // Display warning
+                {
+                    if(humanItem)
+                    {
+                        this->displayWarning("Attention! You are close to the boundary!");
+                    }
+                }
+                if(/* humanItem &&*/ abs(this->maxDistance_ - distance) < this->showDistance_ )
+                {
+                    this->displayBoundaries(currentPawn); // Show the boundary
+                }
+                if(distance > this->maxDistance_ && (this->reaction_ == 1) )
+                {
+                    if( humanItem )
+                    {
+                        COUT(5) << "Health should be decreasing!" << std::endl;
+                        this->displayWarning("You are out of the area now!");
+                    }
+                    currentPawn->removeHealth( (distance - this->maxDistance_) * this->healthDecrease_);
+                }
+                if( (this->reaction_ == 0) && (distance + 100 > this->maxDistance_)) // Exception: A Pawn can't move more than 100 units per tick.
+                {
+                    this->conditionalBounceBack(currentPawn, distance, dt);
+                }
+                if( this->reaction_ == 2 && (distance - 100 < this->maxDistance_) )
+                {
+                    this->conditionalBounceBack(currentPawn, distance, dt);
+                }
+            }
+        }
+    }
+    
+    float SpaceBoundaries::computeDistance(WorldEntity *item)
+    {
+        if(item != NULL)
+        {
+            Vector3 itemPosition = item->getPosition();
+            return (itemPosition.distance(this->getPosition()));
+        } else {
+            return -1;
+        }
+    }
+    
+    void SpaceBoundaries::displayWarning(const std::string warnText)
+    {   
+        // TODO
+    }
+    
+    void SpaceBoundaries::displayBoundaries(Pawn *item)
+    {
+        
+        Vector3 direction = item->getPosition() - this->getPosition();
+        direction.normalise();
+        
+        Vector3 boundaryPosition = this->getPosition() + direction * this->maxDistance_;
+        
+        this->positionBillboard(boundaryPosition);
+    }
+    
+    void SpaceBoundaries::conditionalBounceBack(Pawn *item, float currentDistance, float dt)
+    {
+        Vector3 normal = item->getPosition() - this->getPosition();
+        normal.normalise();
+        Vector3 velocity = item->getVelocity();
+        float normalSpeed = item->getVelocity().dotProduct(normal);
+        
+        /* Check, whether the Pawn would leave the boundary in the next tick, if so send it back. */
+        if( this->reaction_ == 0 && currentDistance + normalSpeed * dt > this->maxDistance_ - 10 ) // -10: "security measure"
+        {
+            bounceBack(item, &normal, &velocity);
+        } else if (this->reaction_ == 2 && currentDistance - normalSpeed * dt < this->maxDistance_ + 10 ) // 10: "security measure"
+        {
+            normal = normal * (-1);
+            bounceBack(item, &normal, &velocity);
+        }
+    }
+    
+    void SpaceBoundaries::bounceBack(Pawn *item, Vector3 *normal, Vector3 *velocity)
+    {
+        float dampingFactor = 0.5;
+        *velocity = velocity->reflect(*normal);
+        Vector3 acceleration = item->getAcceleration();
+        acceleration = acceleration.reflect(*normal);
+        
+        item->lookAt( *velocity + this->getPosition() );
+        
+        item->setAcceleration(acceleration * dampingFactor);
+        item->setVelocity(*velocity * dampingFactor);
+        
+        item->setPosition( item->getPosition() - *normal * 10 ); // Set the position of the Pawn to be well inside the boundary.
+    }
+    
+    bool SpaceBoundaries::isHumanPlayer(Pawn *item)
+    {
+        if(item != NULL)
+        {
+            if(item->getPlayer())
+            {
+                return item->getPlayer()->isHumanPlayer();
+            }
+        }
+        return false;
+    }
+    
+}

Copied: code/branches/presentation/src/modules/objects/SpaceBoundaries.h (from rev 8628, code/branches/presentation/src/orxonox/worldentities/SpaceBoundaries.h)
===================================================================
--- code/branches/presentation/src/modules/objects/SpaceBoundaries.h	                        (rev 0)
+++ code/branches/presentation/src/modules/objects/SpaceBoundaries.h	2011-05-27 21:35:05 UTC (rev 8632)
@@ -0,0 +1,138 @@
+/*
+ *   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:
+ *      Maurus Kaufmann
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _SpaceBoundaries_H__
+#define _SpaceBoundaries_H__
+
+#include "objects/ObjectsPrereqs.h"
+
+#include <string>
+#include <list>
+#include <vector>
+
+#include "core/CoreIncludes.h"
+#include "core/WeakPtr.h"
+
+#include "tools/interfaces/Tickable.h"
+#include "worldentities/StaticEntity.h"
+
+namespace orxonox
+{
+
+/**
+ at brief SpaceBoundaries gives level creators the possibility to bar Pawns from leaving a defined area (until now this area is a ball).
+
+       Some attributes can/should be defined in the XML-File:
+       - 'position' : absolute position of the object of SpaceBoundaries in the level (usually 0,0,0) 
+       - 'maxDistance' : defines the area, where a pawn is allowed to be (radius of a ball).
+       - 'warnDistance' : If the distance between the pawn of the human player and 'position' is bigger than 'warnDistance', a message is displayed to
+                          inform the player that he'll soon be leaving the allowed area. (not implemented yet!)
+       - 'showDistance' : If the distance between the pawn and the boundary of the allowed area is smaller than 'showDistance', the boundary is shown. 
+       - 'reactionMode' : Integer-Value. Defines what effect appears if a space ship has crossed the boundaries.
+                            0: Reflect the space ship (default).
+                            1: Decrease Health of the space ship after having left the allowed area.
+                            2: Inverted Version of 0. Prohibit to fly INTO a defined area.
+       - 'healthDecrease' : a measure to define how fast the health of a pawn should decrease after leaving the allowed area (unnecessary if 'reactionMode' == 0).
+                            Recommended values: 0.1 (slow health decrease) to 5 (very fast health decrease)
+
+Follow http://www.orxonox.net/wiki/SpaceBoundaries to get some further information.
+
+Examples:
+Two examples how one could include SpaceBoundaries in the XML-File. The first one uses reflection, the second one health decrease.
+ at code
+<SpaceBoundaries position="0,0,0" maxDistance="1000" warnDistance="800" showDistance="100" reactionMode="0" />
+ at endcode
+
+ at code
+<SpaceBoundaries position="0,0,0" maxDistance="1000" warnDistance="800" showDistance="100" reactionMode="1" healthDecrease="0.2" />
+ at endcode
+*/
+
+    class _ObjectsExport SpaceBoundaries : public StaticEntity, public Tickable
+    {
+        public:
+            SpaceBoundaries(BaseObject* creator);
+            ~SpaceBoundaries();
+            
+            void setMaxDistance(float r);
+            float getMaxDistance();
+            
+            void setWarnDistance(float r);
+            float getWarnDistance();
+            
+            void setShowDistance(float r);
+            float getShowDistance();
+            
+            void setHealthDecrease(float amount);
+            float getHealthDecrease();
+            
+            void setReaction(int mode);
+            int getReaction();
+
+            void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+            
+            void tick(float dt);
+
+        private:
+            struct billboardAdministration{ bool usedYet; Billboard* billy; };
+            
+            // Variabeln::
+            std::list<WeakPtr<Pawn> > pawnsIn_; //!< List of the pawns that this instance of SpaceBoundaries has to handle.
+            
+            std::vector<billboardAdministration> billboards_;
+        
+            int reaction_; //!< Values: 0, 1, 2.
+                           //!< 0: Reflection on boundary (Standard).
+                           //!< 1: Decrease-Health-Mode.
+                           //!< 2: Inverted Version of 0. Prohibit to fly INTO a defined area.
+            float maxDistance_; //!<  Maximum allowed distance.
+            float warnDistance_; //!< Distance in which a warning is displayed.
+            float showDistance_; //!< Distance at which the boundaries are displayed.
+            
+            float healthDecrease_; //!< Rate of health loss.
+            
+            //RadarViewable* centerRadar_; //!< Representation of the space boundary in the radar.
+        
+            // Funktionen::
+            float computeDistance(WorldEntity *item); //!< Compute distance to center point.
+            void displayWarning(const std::string warnText); //!< TODO: Implement.
+            void displayBoundaries(Pawn *item);
+            void conditionalBounceBack(Pawn *item, float currentDistance, float dt);
+            void bounceBack(Pawn *item, Vector3 *normal, Vector3 *velocity);
+            bool isHumanPlayer(Pawn *item);
+            
+            void checkWhoIsIn(); //!< Update the list 'pawnsIn_'.
+            
+            void positionBillboard(const Vector3 position); //!< Display a Billboard at the position 'position'.
+            void setBillboardOptions(Billboard *billy);
+            void removeAllBillboards(); //!< Hide all elements of '*billboard_' and set their attribute 'usedYet' to 0.
+            
+    };
+}
+
+#endif /* _SpaceBoundaries_H__ */

Modified: code/branches/presentation/src/orxonox/worldentities/CMakeLists.txt
===================================================================
--- code/branches/presentation/src/orxonox/worldentities/CMakeLists.txt	2011-05-27 21:09:00 UTC (rev 8631)
+++ code/branches/presentation/src/orxonox/worldentities/CMakeLists.txt	2011-05-27 21:35:05 UTC (rev 8632)
@@ -11,7 +11,6 @@
   CameraPosition.cc
   SpawnPoint.cc
   TeamSpawnPoint.cc
-  SpaceBoundaries.cc
 )
 
 ADD_SUBDIRECTORY(pawns)

Deleted: code/branches/presentation/src/orxonox/worldentities/SpaceBoundaries.cc
===================================================================
--- code/branches/presentation/src/orxonox/worldentities/SpaceBoundaries.cc	2011-05-27 21:09:00 UTC (rev 8631)
+++ code/branches/presentation/src/orxonox/worldentities/SpaceBoundaries.cc	2011-05-27 21:35:05 UTC (rev 8632)
@@ -1,322 +0,0 @@
-/*
- *   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:
- *      Maurus Kaufmann
- *   Co-authors:
- *      ...
- *
- */
-
-#include "SpaceBoundaries.h"
-
-#include "worldentities/MobileEntity.h"
-#include "worldentities/ControllableEntity.h"
-#include "core/ObjectListIterator.h"
-#include "core/XMLPort.h"
-#include "worldentities/pawns/Pawn.h"
-#include "infos/PlayerInfo.h"
-#include "interfaces/RadarViewable.h"
-#include "graphics/Billboard.h"
-#include <OgreBillboardSet.h>
-
-
-namespace orxonox
-{
-    CreateFactory(SpaceBoundaries);
-
-    SpaceBoundaries::SpaceBoundaries(BaseObject* creator) : StaticEntity(creator)
-    {
-        RegisterObject(SpaceBoundaries);
-
-        this->setMaxDistance(3000);
-        this->setWarnDistance(this->getMaxDistance());
-        this->setShowDistance(this->getMaxDistance());
-        this->setReaction(0);
-    }
-    SpaceBoundaries::~SpaceBoundaries()
-    {
-        if (this->isInitialized())
-        {
-            this->pawnsIn_.clear();
-        
-            for( std::vector<billboardAdministration>::iterator current = this->billboards_.begin(); current != this->billboards_.end(); current++)
-            {
-                if( current->billy != NULL)
-                {
-                    delete current->billy;
-                }
-            }
-            this->billboards_.clear();
-        }
-    }
-    
-    void SpaceBoundaries::checkWhoIsIn()
-    {
-        pawnsIn_.clear();
-        for(ObjectListIterator<Pawn> current = ObjectList<Pawn>::begin(); current != ObjectList<Pawn>::end(); ++current)
-        {
-            Pawn* currentPawn = *current;
-            if( this->reaction_ == 0 )
-            {
-                float distance = this->computeDistance(currentPawn);
-                if(distance <= this->maxDistance_)
-                {
-                    pawnsIn_.push_back(currentPawn);
-                }
-            } else if (this->reaction_ == 2) {
-                float distance = this->computeDistance(currentPawn);
-                if(distance >= this->maxDistance_)
-                {
-                    pawnsIn_.push_back(currentPawn);
-                }
-            } else {
-                pawnsIn_.push_back(currentPawn);
-            }
-        }
-    }
-    
-    void SpaceBoundaries::positionBillboard(const Vector3 position)
-    {
-        std::vector<billboardAdministration>::iterator current;
-        for( current = this->billboards_.begin(); current != this->billboards_.end(); current++)
-        {
-            if(!current->usedYet)
-            {
-                break;
-            }
-        }
-        if( current == this->billboards_.end() )
-        {
-            Billboard *tmp = new Billboard(this);
-            tmp->setPosition(position);
-            this->setBillboardOptions( tmp );
-            Vector3 normalisedVec = (position - this->getPosition()).normalisedCopy(); /* Vektor von Kugelmitte nach aussen */
-            tmp->setCommonDirection ( -1.0 * normalisedVec );
-            tmp->setCommonUpVector( Vector3::UNIT_Z );
-            billboardAdministration tmp2 = { true, tmp };
-            this->billboards_.push_back( tmp2 );
-        } else {
-            current->billy->setPosition(position);
-            current->billy->setVisible(true);
-            current->usedYet = true;
-            Vector3 normalisedVec = (position - this->getPosition()).normalisedCopy(); /* Vektor von Kugelmitte nach aussen */
-            current->billy->setCommonDirection ( -1.0 * normalisedVec );
-            current->billy->setCommonUpVector( Vector3::UNIT_Z );
-        }
-    }
-    
-    void SpaceBoundaries::setBillboardOptions(Billboard *billy)
-    {
-        if(billy != NULL)
-        {
-            billy->setMaterial("Grid");
-            billy->setBillboardType(Ogre::BBT_PERPENDICULAR_COMMON);
-            billy->setDefaultDimensions(150, 150);
-            billy->setVisible(true);
-        }
-    }
-    
-    void SpaceBoundaries::removeAllBillboards()
-    {
-        for( std::vector<billboardAdministration>::iterator current = this->billboards_.begin(); current != this->billboards_.end(); current++ )
-        {
-            current->usedYet = false;
-            current->billy->setVisible(false);
-        }
-    }
-    
-    void SpaceBoundaries::setMaxDistance(float r)
-    {
-        this->maxDistance_ = r;
-    }
-    float SpaceBoundaries::getMaxDistance()
-    {
-        return this->maxDistance_;
-    }
-    
-    void SpaceBoundaries::setWarnDistance(float r)
-    {
-        this->warnDistance_ = r;
-    }
-    float SpaceBoundaries::getWarnDistance()
-    {
-        return this->warnDistance_;
-    }
-    
-    void SpaceBoundaries::setShowDistance(float r)
-    {
-        this->showDistance_ = r;
-    }
-    float SpaceBoundaries::getShowDistance()
-    {
-        return this->showDistance_;
-    }
-    
-    void SpaceBoundaries::setHealthDecrease(float amount)
-    {
-        this->healthDecrease_ = amount/1000;
-    }
-    float SpaceBoundaries::getHealthDecrease()
-    {
-        return this->healthDecrease_;
-    }
-    
-    void SpaceBoundaries::setReaction(int mode)
-    {
-        this->reaction_ = mode;
-    }
-    int SpaceBoundaries::getReaction()
-    {
-        return this->reaction_;
-    }
-
-    void SpaceBoundaries::XMLPort(Element& xmlelement, XMLPort::Mode mode)
-    {
-        SUPER(SpaceBoundaries, XMLPort, xmlelement, mode);
-
-        XMLPortParam(SpaceBoundaries, "maxDistance", setMaxDistance, getMaxDistance, xmlelement, mode);
-        XMLPortParam(SpaceBoundaries, "warnDistance", setWarnDistance, getWarnDistance, xmlelement, mode);
-        XMLPortParam(SpaceBoundaries, "showDistance", setShowDistance, getShowDistance, xmlelement, mode);
-        XMLPortParam(SpaceBoundaries, "healthDecrease", setHealthDecrease, getHealthDecrease, xmlelement, mode);
-        XMLPortParam(SpaceBoundaries, "reactionMode", setReaction, getReaction, xmlelement, mode);
-    }
-    
-    void SpaceBoundaries::tick(float dt)
-    {
-        this->checkWhoIsIn();
-        this->removeAllBillboards();
-        
-        float distance;
-        bool humanItem;
-        for( std::list<WeakPtr<Pawn> >::iterator current = pawnsIn_.begin(); current != pawnsIn_.end(); current++ )
-        {
-            Pawn* currentPawn = current->get();
-            if( currentPawn && currentPawn->getNode() ) 
-            {
-                distance = this->computeDistance(currentPawn);
-                humanItem = this->isHumanPlayer(currentPawn);
-                COUT(5) << "Distance:" << distance << std::endl; // message for debugging
-                if(distance > this->warnDistance_ && distance < this->maxDistance_) // Display warning
-                {
-                    if(humanItem)
-                    {
-                        this->displayWarning("Attention! You are close to the boundary!");
-                    }
-                }
-                if(/* humanItem &&*/ abs(this->maxDistance_ - distance) < this->showDistance_ )
-                {
-                    this->displayBoundaries(currentPawn); // Show the boundary
-                }
-                if(distance > this->maxDistance_ && (this->reaction_ == 1) )
-                {
-                    if( humanItem )
-                    {
-                        COUT(5) << "Health should be decreasing!" << std::endl;
-                        this->displayWarning("You are out of the area now!");
-                    }
-                    currentPawn->removeHealth( (distance - this->maxDistance_) * this->healthDecrease_);
-                }
-                if( (this->reaction_ == 0) && (distance + 100 > this->maxDistance_)) // Exception: A Pawn can't move more than 100 units per tick.
-                {
-                    this->conditionalBounceBack(currentPawn, distance, dt);
-                }
-                if( this->reaction_ == 2 && (distance - 100 < this->maxDistance_) )
-                {
-                    this->conditionalBounceBack(currentPawn, distance, dt);
-                }
-            }
-        }
-    }
-    
-    float SpaceBoundaries::computeDistance(WorldEntity *item)
-    {
-        if(item != NULL)
-        {
-            Vector3 itemPosition = item->getPosition();
-            return (itemPosition.distance(this->getPosition()));
-        } else {
-            return -1;
-        }
-    }
-    
-    void SpaceBoundaries::displayWarning(const std::string warnText)
-    {   
-        // TODO
-    }
-    
-    void SpaceBoundaries::displayBoundaries(Pawn *item)
-    {
-        
-        Vector3 direction = item->getPosition() - this->getPosition();
-        direction.normalise();
-        
-        Vector3 boundaryPosition = this->getPosition() + direction * this->maxDistance_;
-        
-        this->positionBillboard(boundaryPosition);
-    }
-    
-    void SpaceBoundaries::conditionalBounceBack(Pawn *item, float currentDistance, float dt)
-    {
-        Vector3 normal = item->getPosition() - this->getPosition();
-        normal.normalise();
-        Vector3 velocity = item->getVelocity();
-        float normalSpeed = item->getVelocity().dotProduct(normal);
-        
-        /* Check, whether the Pawn would leave the boundary in the next tick, if so send it back. */
-        if( this->reaction_ == 0 && currentDistance + normalSpeed * dt > this->maxDistance_ - 10 ) // -10: "security measure"
-        {
-            bounceBack(item, &normal, &velocity);
-        } else if (this->reaction_ == 2 && currentDistance - normalSpeed * dt < this->maxDistance_ + 10 ) // 10: "security measure"
-        {
-            normal = normal * (-1);
-            bounceBack(item, &normal, &velocity);
-        }
-    }
-    
-    void SpaceBoundaries::bounceBack(Pawn *item, Vector3 *normal, Vector3 *velocity)
-    {
-        float dampingFactor = 0.5;
-        *velocity = velocity->reflect(*normal);
-        Vector3 acceleration = item->getAcceleration();
-        acceleration = acceleration.reflect(*normal);
-        
-        item->lookAt( *velocity + this->getPosition() );
-        
-        item->setAcceleration(acceleration * dampingFactor);
-        item->setVelocity(*velocity * dampingFactor);
-        
-        item->setPosition( item->getPosition() - *normal * 10 ); // Set the position of the Pawn to be well inside the boundary.
-    }
-    
-    bool SpaceBoundaries::isHumanPlayer(Pawn *item)
-    {
-        if(item != NULL)
-        {
-            if(item->getPlayer())
-            {
-                return item->getPlayer()->isHumanPlayer();
-            }
-        }
-        return false;
-    }
-    
-}

Deleted: code/branches/presentation/src/orxonox/worldentities/SpaceBoundaries.h
===================================================================
--- code/branches/presentation/src/orxonox/worldentities/SpaceBoundaries.h	2011-05-27 21:09:00 UTC (rev 8631)
+++ code/branches/presentation/src/orxonox/worldentities/SpaceBoundaries.h	2011-05-27 21:35:05 UTC (rev 8632)
@@ -1,138 +0,0 @@
-/*
- *   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:
- *      Maurus Kaufmann
- *   Co-authors:
- *      ...
- *
- */
-
-#ifndef _SpaceBoundaries_H__
-#define _SpaceBoundaries_H__
-
-
-#include "core/CoreIncludes.h"
-#include "core/WeakPtr.h"
-#include "tools/interfaces/Tickable.h"
-#include "interfaces/RadarViewable.h"
-#include "worldentities/StaticEntity.h"
-#include "worldentities/WorldEntity.h"
-
-#include <string>
-#include <list>
-#include <vector>
-
-namespace orxonox
-{
-
-/**
- at brief SpaceBoundaries gives level creators the possibility to bar Pawns from leaving a defined area (until now this area is a ball).
-
-       Some attributes can/should be defined in the XML-File:
-       - 'position' : absolute position of the object of SpaceBoundaries in the level (usually 0,0,0) 
-       - 'maxDistance' : defines the area, where a pawn is allowed to be (radius of a ball).
-       - 'warnDistance' : If the distance between the pawn of the human player and 'position' is bigger than 'warnDistance', a message is displayed to
-                          inform the player that he'll soon be leaving the allowed area. (not implemented yet!)
-       - 'showDistance' : If the distance between the pawn and the boundary of the allowed area is smaller than 'showDistance', the boundary is shown. 
-       - 'reactionMode' : Integer-Value. Defines what effect appears if a space ship has crossed the boundaries.
-                            0: Reflect the space ship (default).
-                            1: Decrease Health of the space ship after having left the allowed area.
-                            2: Inverted Version of 0. Prohibit to fly INTO a defined area.
-       - 'healthDecrease' : a measure to define how fast the health of a pawn should decrease after leaving the allowed area (unnecessary if 'reactionMode' == 0).
-                            Recommended values: 0.1 (slow health decrease) to 5 (very fast health decrease)
-
-Follow http://www.orxonox.net/wiki/SpaceBoundaries to get some further information.
-
-Examples:
-Two examples how one could include SpaceBoundaries in the XML-File. The first one uses reflection, the second one health decrease.
- at code
-<SpaceBoundaries position="0,0,0" maxDistance="1000" warnDistance="800" showDistance="100" reactionMode="0" />
- at endcode
-
- at code
-<SpaceBoundaries position="0,0,0" maxDistance="1000" warnDistance="800" showDistance="100" reactionMode="1" healthDecrease="0.2" />
- at endcode
-*/
-
-    class _OrxonoxExport SpaceBoundaries : public StaticEntity, public Tickable
-    {
-        public:
-            SpaceBoundaries(BaseObject* creator);
-            ~SpaceBoundaries();
-            
-            void setMaxDistance(float r);
-            float getMaxDistance();
-            
-            void setWarnDistance(float r);
-            float getWarnDistance();
-            
-            void setShowDistance(float r);
-            float getShowDistance();
-            
-            void setHealthDecrease(float amount);
-            float getHealthDecrease();
-            
-            void setReaction(int mode);
-            int getReaction();
-
-            void XMLPort(Element& xmlelement, XMLPort::Mode mode);
-            
-            void tick(float dt);
-
-        private:
-            struct billboardAdministration{ bool usedYet; Billboard* billy; };
-            
-            // Variabeln::
-            std::list<WeakPtr<Pawn> > pawnsIn_; //!< List of the pawns that this instance of SpaceBoundaries has to handle.
-            
-            std::vector<billboardAdministration> billboards_;
-        
-            int reaction_; //!< Values: 0, 1, 2.
-                           //!< 0: Reflection on boundary (Standard).
-                           //!< 1: Decrease-Health-Mode.
-                           //!< 2: Inverted Version of 0. Prohibit to fly INTO a defined area.
-            float maxDistance_; //!<  Maximum allowed distance.
-            float warnDistance_; //!< Distance in which a warning is displayed.
-            float showDistance_; //!< Distance at which the boundaries are displayed.
-            
-            float healthDecrease_; //!< Rate of health loss.
-            
-            //RadarViewable* centerRadar_; //!< Representation of the space boundary in the radar.
-        
-            // Funktionen::
-            float computeDistance(WorldEntity *item); //!< Compute distance to center point.
-            void displayWarning(const std::string warnText); //!< TODO: Implement.
-            void displayBoundaries(Pawn *item);
-            void conditionalBounceBack(Pawn *item, float currentDistance, float dt);
-            void bounceBack(Pawn *item, Vector3 *normal, Vector3 *velocity);
-            bool isHumanPlayer(Pawn *item);
-            
-            void checkWhoIsIn(); //!< Update the list 'pawnsIn_'.
-            
-            void positionBillboard(const Vector3 position); //!< Display a Billboard at the position 'position'.
-            void setBillboardOptions(Billboard *billy);
-            void removeAllBillboards(); //!< Hide all elements of '*billboard_' and set their attribute 'usedYet' to 0.
-            
-    };
-}
-
-#endif /* _SpaceBoundaries_H__ */




More information about the Orxonox-commit mailing list