[Orxonox-commit 2975] r7673 - in code/trunk: data/levels src/modules/objects src/orxonox/infos
dafrick at orxonox.net
dafrick at orxonox.net
Thu Nov 25 23:24:50 CET 2010
Author: dafrick
Date: 2010-11-25 23:24:50 +0100 (Thu, 25 Nov 2010)
New Revision: 7673
Modified:
code/trunk/data/levels/The Time Machine.oxw
code/trunk/src/modules/objects/ForceField.cc
code/trunk/src/modules/objects/ForceField.h
code/trunk/src/orxonox/infos/Bot.cc
Log:
Documenting and extending ForceField.
A little cleaning up in The Time Machine level.
Adding a Bond villain...
Modified: code/trunk/data/levels/The Time Machine.oxw
===================================================================
--- code/trunk/data/levels/The Time Machine.oxw 2010-11-24 22:12:30 UTC (rev 7672)
+++ code/trunk/data/levels/The Time Machine.oxw 2010-11-25 22:24:50 UTC (rev 7673)
@@ -1,7 +1,7 @@
<LevelInfo
name = "The Time Machine"
description = "A simple level. The only goal is to defeat as much enemies as you can."
- tags = ""
+ tags = "singleplayer"
/>
<?lua
@@ -42,7 +42,7 @@
<Model position="0,0,0" yaw=90 pitch=-90 roll=0 scale=4 mesh="assff.mesh" />
<BlinkingBillboard position="17,-1.5,0" material="Examples/Flare" colour="1.0, 0.5, 0.3" amplitude=0.1 frequency=0.5 quadratic=1 />
<BlinkingBillboard position="-17,-1.5,0" material="Examples/Flare" colour="0.5, 1.0, 0.3" amplitude=0.1 frequency=0.5 phase=180 quadratic=1 />
- <DistanceTriggerBeacon name="PlayerDistanceTrigger" /> <!--added DistanceTrigger-->
+ <DistanceTriggerBeacon name="PlayerDistanceTrigger" /> <!--added DistanceTriggerBeacon-->
</attached>
<collisionShapes>
<BoxCollisionShape position="0,0,0" halfExtents="10, 3, 5" />
@@ -60,18 +60,14 @@
<!--*****************************************************************************************************************************************************************************************-->
-
-
-
-<!--CREATING SPAWNPOINTS______________________________________________________________________________________________________________________________________________________________OK-->
<Level
name="The Time Machine"
description="A simple level. The only goal is to defeat as much enemies as you can."
gametype=TeamDeathmatch
>
- <templates>
- <Template link=lodtemplate_default />
- </templates>
+ <templates>
+ <Template link=lodtemplate_default />
+ </templates>
<Scene
ambientlight="0.8,0.8,0.8"
skybox="Orxonox/skypanoramagen2"
@@ -79,8 +75,9 @@
<Light type=directional position="0,0,0" direction="0, 0, 0" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 1.0, 0.9" />
+<!--CREATING SPAWNPOINTS_____________________________________________________________________________________________________________________________________________________________________-->
<?lua for i=0,4,1 do
-x=500
+ x=500
?>
<TeamSpawnPoint team=0 position="-4000,0,<?lua print(i*x-1000) ?>" direction="5000,0,<?lua print(i*x-1000) ?>" spawnclass=SpaceShip pawndesign=spaceshipassffplayer />
@@ -88,13 +85,13 @@
<!-- TeamSpawnPoint team=0 position="-4000,0,<?lua print(i*x-1000) ?>" lookat="5000,0,<?lua print(i*x-1000) ?>" spawnclass=SpaceShip pawndesign=spaceshipassff /-->
<!--enemy spaceship spawnpoint-->
- <!-- TeamSpawnPoint team=1 position="4000,0,<?lua print(i*x-1000) ?>" lookat="-5000,0,<?lua print(i*x-1000) ?>" spawnclass=SpaceShip pawndesign=spaceshippirate /-->
+ <!--TeamSpawnPoint team=1 position="4000,0,<?lua print(i*x-1000) ?>" lookat="-5000,0,<?lua print(i*x-1000) ?>" spawnclass=SpaceShip pawndesign=spaceshippirate /-->
<?lua end ?>
<!--CREATING SPAWNPOINTS END______________________________________________________________________________________________________________________________________________________________-->
-<!--Triggers (used for the Time Machine effect)_________________________________________________________________________________________________________________________partially working-->
+<!--Triggers (used for the Time Machine effect)___________________________________________________________________________________________________________________________________________-->
<!--TRIGGERS IF THE PLAYERS REACHES THE "TIME MACHINE"-->
<DistanceTrigger name="EnterTimeMachine" position="0,0,0" distance="100" target="DistanceTriggerBeacon" targetname="PlayerDistanceTrigger" >
@@ -143,7 +140,7 @@
</EventTrigger>
</Trigger>
- <!-- This Trigger is true iff the player is in the TimeMachine and has shot another player -->
+ <!-- This Trigger is true if the player is in the TimeMachine and has shot another player -->
<EventTrigger name=trigger2 switch=true >
<events>
<trigger>
@@ -174,15 +171,15 @@
<!--Triggers (used for the Time Machine effect)_____________________________________________________________________________________________________________________________________________-->
-<!--Creating Spaceships___________________________________________________________________________________________________________________________________________________________________OK-->
+<!--Creating Spaceships_____________________________________________________________________________________________________________________________________________________________________-->
<?lua for i=0,5,1 do
-y=math.random(-500,500)
-z=math.random(-1000,1000)
-y2=math.random(-500,500)
-z2=math.random(-1000,1000)
-health=230
-addh=100
+ y=math.random(-500,500)
+ z=math.random(-1000,1000)
+ y2=math.random(-500,500)
+ z2=math.random(-1000,1000)
+ health=230
+ addh=100
?>
<EventTrigger name="BotDied" >
@@ -264,7 +261,7 @@
</EventTrigger>
<?lua end ?>
-<!--Creating Spaceships_____END___________________________________________________________________________________________________________________________________________________________OK-->
+<!--Creating Spaceships_____END_____________________________________________________________________________________________________________________________________________________________-->
<!--BILLBOARD IN THE MIDDLE OF THE BATTLEFIELD-->
<Billboard position="0,0,0" colour="1.0,1.0,1.0" material="Flares/backlightflare" scale=1 />
@@ -319,6 +316,7 @@
<attached>
<MovableEntity position="<?lua print(1500-3000*i) ?>,0,0">
<attached>
+ <ForceField position="0,0,0" mode="sphere" diameter=500 velocity=100000 />
<Billboard position="0,0,0" material="Examples/Flare" colour="1.0,1.0,1.0" scale=0.3/>
<MovableEntity position="0,0,0" rotationaxis="1,1,0" rotationrate=-255 >
<attached>
@@ -366,6 +364,7 @@
<attached>
<MovableEntity position="0,<?lua print(1500-3000*i) ?>,0">
<attached>
+ <ForceField position="0,0,0" mode="sphere" diameter=500 velocity=100000 />
<Billboard position="0,0,0" material="Examples/Flare" colour="1.0,1.0,1.0" scale=0.3/>
<MovableEntity position="0,0,0" rotationaxis="1,1,0" rotationrate=-255 >
<attached>
@@ -413,6 +412,7 @@
<attached>
<MovableEntity position="<?lua print(1000-2000*i) ?>,<?lua print(-1000+2000*i) ?>,0">
<attached>
+ <ForceField position="0,0,0" mode="sphere" diameter=500 velocity=100000 />
<Billboard position="0,0,0" material="Examples/Flare" colour="1.0,1.0,1.0" scale=0.3/>
<MovableEntity position="0,0,0" rotationaxis="1,1,0" rotationrate=-255 >
<attached>
@@ -460,6 +460,7 @@
<attached>
<MovableEntity position="<?lua print(1000-2000*i) ?>,<?lua print(-1000+2000*i) ?>,0">
<attached>
+ <ForceField position="0,0,0" mode="sphere" diameter=500 velocity=100000 />
<Billboard position="0,0,0" material="Examples/Flare" colour="1.0,1.0,1.0" scale=0.3/>
<MovableEntity position="0,0,0" rotationaxis="1,1,0" rotationrate=-255 >
<attached>
@@ -507,6 +508,7 @@
<attached>
<MovableEntity position="<?lua print(1000-2000*i) ?>,0,<?lua print(-1000+2000*i) ?>">
<attached>
+ <ForceField position="0,0,0" mode="sphere" diameter=500 velocity=100000 />
<Billboard position="0,0,0" material="Examples/Flare" colour="1.0,1.0,1.0" scale=0.3/>
<MovableEntity position="0,0,0" rotationaxis="1,1,0" rotationrate=-255 >
<attached>
Modified: code/trunk/src/modules/objects/ForceField.cc
===================================================================
--- code/trunk/src/modules/objects/ForceField.cc 2010-11-24 22:12:30 UTC (rev 7672)
+++ code/trunk/src/modules/objects/ForceField.cc 2010-11-25 22:24:50 UTC (rev 7673)
@@ -26,6 +26,11 @@
*
*/
+/**
+ at file ForceField.cc
+ at brief Implementation of the ForceField class.
+*/
+
#include "ForceField.h"
#include "core/CoreIncludes.h"
@@ -35,6 +40,9 @@
namespace orxonox
{
CreateFactory(ForceField);
+
+ /*static*/ const std::string modeStringNormal_s = "tube";
+ /*static*/ const std::string modeStringSphere_s = "sphere";
ForceField::ForceField(BaseObject* creator) : StaticEntity(creator)
{
@@ -42,12 +50,15 @@
//Standard Values
this->setDirection(Vector3::ZERO);
- velocity_ = 100;
- diameter_ = 500;
- length_ = 5000;
+ this->velocity_ = 100;
+ this->diameter_ = 500;
+ this->length_ = 5000;
+ this->mode_ = ForceFieldMode::tube;
}
- ForceField::~ForceField() {}
+ ForceField::~ForceField()
+ {
+ }
void ForceField::XMLPort(Element& xmlelement, XMLPort::Mode mode)
{
@@ -57,28 +68,77 @@
XMLPortParam(ForceField, "velocity", setVelocity, getVelocity, xmlelement, mode).defaultValues(100);
XMLPortParam(ForceField, "diameter", setDiameter, getDiameter, xmlelement, mode).defaultValues(500);
XMLPortParam(ForceField, "length" , setLength , getLength , xmlelement, mode).defaultValues(2000);
+ XMLPortParam(ForceField, "mode", setMode, getMode, xmlelement, mode);
}
void ForceField::tick(float dt)
{
+ // Iterate over all objects that could possibly be affected by the ForceField.
for (ObjectList<MobileEntity>::iterator it = ObjectList<MobileEntity>::begin(); it != ObjectList<MobileEntity>::end(); ++it)
{
- //calculate from
- Vector3 directionVec = this->getOrientation() * WorldEntity::FRONT;
- directionVec.normalise();
+ if(this->mode_ == ForceFieldMode::tube)
+ {
+ // The direction of the orientation of the force field.
+ Vector3 direction = this->getOrientation() * WorldEntity::FRONT;
+ direction.normalise();
- Vector3 distanceVec = it->getWorldPosition() - (this->getWorldPosition() + (this->length_ / 2 * directionVec));
+ // Vector from the center of the force field to the object its acting on.
+ // TODO: This could probably be simplified.
+ Vector3 distanceVector = it->getWorldPosition() - (this->getWorldPosition() + (this->halfLength_ * direction));
+
+ // The object is outside of the length of the ForceField.
+ if(distanceVector.length() > this->halfLength_)
+ return;
- //distance from centervector of the field (
- float distFromCenterVec = ((it->getWorldPosition() - this->getWorldPosition()).crossProduct(directionVec)).length();
+ // The distance of the object form the orientation vector. (Or rather the smallest distance from the orientation vector)
+ float distanceFromDirectionVector = ((it->getWorldPosition() - this->getWorldPosition()).crossProduct(direction)).length();
+
+ // If the object in a tube of radius diameter/2 around the direction of orientation.
+ if(distanceFromDirectionVector >= this->radius_)
+ return;
- if (distanceVec.length() < this->length_ / 2 && distFromCenterVec < diameter_ / 2)
+ // Apply a force to the object in the direction of the orientation.
+ // The force is highest when the object is directly on the direction vector, with a linear decrease, finally reaching zero, when distanceFromDirectionVector = radius.
+ it->applyCentralForce(((this->radius_ - distanceFromDirectionVector)/(this->radius_)) * this->velocity_ * direction);
+ }
+ else if(this->mode_ == ForceFieldMode::sphere)
{
- //normalize distance from center
- it->applyCentralForce(((diameter_ / 2 - distFromCenterVec) / (diameter_ / 2)) * directionVec * velocity_);
+ Vector3 distanceVector = it->getWorldPosition() - this->getWorldPosition();
+ float distance = distanceVector.length();
+ if (distance < this->radius_)
+ {
+ distanceVector.normalise();
+ it->applyCentralForce((this->radius_ - distance)/this->radius_ * this->velocity_ * distanceVector);
+ }
}
}
}
+
+ void ForceField::setMode(const std::string& mode)
+ {
+ if(mode == ForceField::modeStringTube_s)
+ this->mode_ = ForceFieldMode::tube;
+ else if(mode == ForceField::modeStringSphere_s)
+ this->mode_ = ForceFieldMode::sphere;
+ else
+ {
+ COUT(2) << "Wrong mode '" << mode << "' in ForceField. Setting to 'tube'." << std::endl;
+ this->mode_ = ForceFieldMode::tube;
+ }
+ }
+
+ inline const std::string& ForceField::getMode(void)
+ {
+ switch(this->mode_)
+ {
+ case ForceFieldMode::tube:
+ return ForceField::modeStringTube_s;
+ case ForceFieldMode::sphere:
+ return ForceField::modeStringSphere_s;
+ default:
+ return ForceField::modeStringTube_s;
+ }
+ }
}
Modified: code/trunk/src/modules/objects/ForceField.h
===================================================================
--- code/trunk/src/modules/objects/ForceField.h 2010-11-24 22:12:30 UTC (rev 7672)
+++ code/trunk/src/modules/objects/ForceField.h 2010-11-25 22:24:50 UTC (rev 7673)
@@ -22,7 +22,7 @@
* Author:
* Aurelian Jaggi
* Co-authors:
- * ...
+ * Damian 'Mozork' Frick
*
*/
@@ -32,6 +32,12 @@
@ingroup Objects
*/
+/**
+ at file ForceField.h
+ at brief Definition of the ForceField class.
+ at inGroup Objects
+*/
+
#ifndef _ForceField_H__
#define _ForceField_H__
@@ -42,36 +48,82 @@
namespace orxonox
{
+
+ /**
+ @brief
+ The mode of the ForceField.
+
+ @inGroup Objects
+ */
+ namespace ForceFieldMode
+ {
+ enum Value {
+ tube, //!< The ForceField has a tube shape.
+ sphere //!< The ForceField has a spherical shape.
+
+ };
+ }
+
+ /**
+ @brief
+ Implements a force field, that applies a force to any @ref orxonox::MoblieEnity "MobileEntity" that enters its range.
+
+ The following parameters can be set to specify the behavior of the ForceField.
+ - @b velocity The amount of force the ForceField excerts.
+ - @b diameter The diameter of the ForceField.
+ - @b length The length of the ForceField.
+ - @b mode The mode the ForceField is in. For mode:
+ -- <em>tube</em> A ForceField which exerts force only in the direction it is oriented. The force is only exerted on objects that are in a tube of length <em>length</em> and diameter <em>diameter</em>. The magintude of the force is proportional to the <em><velocity/em>, being highest when an object is in the middle of the tube (radius-wise), linearly decreasing with greater radii and finally reaching zero, when the object is <code>diameter/2</code> away from the orientation vector.
+ -- <em>sphere</em> A Force Field which exerts force radially away from itself, with the greatest magnitude (proportional to <em>velocity</em>) being in the origin of the ForceField, linearly decreasing with respect to the distance to the origin and finally reaching zero at distance <code>diameter/2</code>.
+
+ @author
+ Aurelian Jaggi
+
+ @author
+ Damian 'Mozork' Frick
+
+ @inGroup Objects
+ */
class _ObjectsExport ForceField : public StaticEntity, public Tickable
{
- public:
- ForceField(BaseObject* creator);
- virtual ~ForceField();
- virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
- virtual void tick(float dt);
+ public:
+ ForceField(BaseObject* creator);
+ virtual ~ForceField();
+ virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
+ virtual void tick(float dt);
- inline void setVelocity(float vel)
- { this->velocity_ = vel; }
+ inline void setVelocity(float vel)
+ { this->velocity_ = vel; }
- inline float getVelocity()
- { return velocity_; }
+ inline float getVelocity()
+ { return this->velocity_; }
- inline void setDiameter(float diam)
- { this->diameter_ = diam; }
+ inline void setDiameter(float diam)
+ { this->diameter_ = diam; this->radius_ = diam/2; }
- inline float getDiameter()
- { return diameter_; }
+ inline float getDiameter()
+ { return this->diameter_; }
- inline void setLength(float l)
- { this->length_ = l; }
+ inline void setLength(float l)
+ { this->length_ = l; this->halfLength_ = l/2; }
- inline float getLength()
- { return length_; }
+ inline float getLength()
+ { return this->length_; }
+
+ void setMode(const std::string& mode);
+
+ inline const std::string& getMode(void);
- private:
- float velocity_;
- float diameter_;
- float length_;
+ private:
+ static const std::string modeStringTube_s;
+ static const std::string modeStringSphere_s;
+
+ float velocity_;
+ float diameter_;
+ float radius_;
+ float length_;
+ float halfLength_;
+ ForceFieldMode::Value mode_;
};
}
Modified: code/trunk/src/orxonox/infos/Bot.cc
===================================================================
--- code/trunk/src/orxonox/infos/Bot.cc 2010-11-24 22:12:30 UTC (rev 7672)
+++ code/trunk/src/orxonox/infos/Bot.cc 2010-11-25 22:24:50 UTC (rev 7673)
@@ -81,10 +81,11 @@
"General Orlov",
"Max Zorin",
"Brad Whitaker",
- "General Koskov",
+ "General Georgi Koskov",
"Franz Sanchez",
"Alec Trevelyan",
"Elliot Carver",
+ "Elektra King"
"Viktor Zokas",
"Gustav Graves",
"Le Chiffre",
More information about the Orxonox-commit
mailing list