[Orxonox-commit 2477] r7184 - in code/trunk/src: libraries/util modules/designtools modules/overlays/hud orxonox/controllers orxonox/overlays orxonox/worldentities/pawns
rgrieder at orxonox.net
rgrieder at orxonox.net
Wed Aug 18 21:46:16 CEST 2010
Author: rgrieder
Date: 2010-08-18 21:46:16 +0200 (Wed, 18 Aug 2010)
New Revision: 7184
Modified:
code/trunk/src/libraries/util/ExprParser.cc
code/trunk/src/libraries/util/Math.cc
code/trunk/src/libraries/util/Math.h
code/trunk/src/modules/designtools/CreateStars.cc
code/trunk/src/modules/overlays/hud/HUDRadar.cc
code/trunk/src/orxonox/controllers/AIController.cc
code/trunk/src/orxonox/controllers/ArtificialController.cc
code/trunk/src/orxonox/controllers/NewHumanController.cc
code/trunk/src/orxonox/controllers/WaypointPatrolController.cc
code/trunk/src/orxonox/overlays/OrxonoxOverlay.cc
code/trunk/src/orxonox/worldentities/pawns/FpsPlayer.cc
Log:
Replaced mathematical constants with a common definition in Math.h.
Use math::pi, math::pi_d (double), math::e, etc. from now on.
Modified: code/trunk/src/libraries/util/ExprParser.cc
===================================================================
--- code/trunk/src/libraries/util/ExprParser.cc 2010-08-18 17:49:31 UTC (rev 7183)
+++ code/trunk/src/libraries/util/ExprParser.cc 2010-08-18 19:46:16 UTC (rev 7184)
@@ -32,9 +32,11 @@
*/
#include "ExprParser.h"
+
#include <cmath>
#include <cstring>
#include <cstdlib>
+#include "Math.h"
// macros for easier if, else statements
#define CASE_1(var) if (!strcmp(SWITCH,var))
@@ -49,8 +51,8 @@
ExprParser::ExprParser()
{
this->failed_ = false;
- this->variables_["pi"] = 3.1415926535897932;
- this->variables_["e"] = 2.7182818284590452;
+ this->variables_["pi"] = math::pi_d;
+ this->variables_["e"] = math::e_d;
}
void ExprParser::setVariable(const std::string& varname, double value)
@@ -327,9 +329,9 @@
CASE("sqrt")
value = sqrt(parse_last_argument());
CASE("degrees")
- value = parse_last_argument()*180/3.1415926535897932;
+ value = parse_last_argument()*180/math::pi_d;
CASE("radians")
- value = parse_last_argument()*3.1415926535897932/180;
+ value = parse_last_argument()*math::pi_d/180;
CASE("mod")
{
value = parse_argument();
Modified: code/trunk/src/libraries/util/Math.cc
===================================================================
--- code/trunk/src/libraries/util/Math.cc 2010-08-18 17:49:31 UTC (rev 7183)
+++ code/trunk/src/libraries/util/Math.cc 2010-08-18 19:46:16 UTC (rev 7184)
@@ -184,7 +184,7 @@
float distancelength = distance.length();
if (distancelength == 0) return orxonox::Vector2(0, 0);
- float radius = acos(clamp<float>(mydirection.dotProduct(distance) / distancelength, -1, 1)) / Ogre::Math::PI;
+ float radius = acos(clamp<float>(mydirection.dotProduct(distance) / distancelength, -1, 1)) / math::pi;
if ((mydirection.crossProduct(myorthonormal)).dotProduct(distance) > 0)
return orxonox::Vector2( sin_value * radius, cos_value * radius);
Modified: code/trunk/src/libraries/util/Math.h
===================================================================
--- code/trunk/src/libraries/util/Math.h 2010-08-18 17:49:31 UTC (rev 7183)
+++ code/trunk/src/libraries/util/Math.h 2010-08-18 19:46:16 UTC (rev 7184)
@@ -58,6 +58,24 @@
namespace orxonox
{
+ // C++ doesn't define any constants for pi, e, etc.
+ namespace math
+ {
+ const float pi = 3.14159265f;
+ const float pi_2 = 1.57079633f;
+ const float pi_4 = 7.85398163e-1f;
+ const float e = 2.71828183f;
+ const float sqrt2 = 1.41421356f;
+ const float sqrt2_2 = 7.07106781e-1f;
+
+ const double pi_d = 3.14159265358979324;
+ const double pi_2_d = 1.57079632679489662;
+ const double pi_4_d = 7.85398163397448310e-1;
+ const double e_d = 2.71828182845904524;
+ const double sqrt2_d = 1.41421356237309505;
+ const double sqrt2_2_d = 7.07106781186547524e-1;
+ }
+
#if OGRE_VERSION < 0x010603
_UtilExport std::ostream& operator<<(std::ostream& out, const orxonox::Radian& radian);
_UtilExport std::ostream& operator<<(std::ostream& out, const orxonox::Degree& degree);
Modified: code/trunk/src/modules/designtools/CreateStars.cc
===================================================================
--- code/trunk/src/modules/designtools/CreateStars.cc 2010-08-18 17:49:31 UTC (rev 7183)
+++ code/trunk/src/modules/designtools/CreateStars.cc 2010-08-18 19:46:16 UTC (rev 7184)
@@ -38,8 +38,6 @@
{
CreateFactory(CreateStars);
- static const float pi = 3.14159265359f;
-
CreateStars::CreateStars(BaseObject* creator) : BaseObject(creator)
{
RegisterObject(CreateStars);
@@ -89,8 +87,8 @@
while(1)
{
- phi = rnd(2*pi);
- teta = rnd(pi);
+ phi = rnd(2*math::pi);
+ teta = rnd(math::pi);
float random = rnd(1);
if(sin(teta)>random) break;
}
Modified: code/trunk/src/modules/overlays/hud/HUDRadar.cc
===================================================================
--- code/trunk/src/modules/overlays/hud/HUDRadar.cc 2010-08-18 17:49:31 UTC (rev 7183)
+++ code/trunk/src/modules/overlays/hud/HUDRadar.cc 2010-08-18 19:46:16 UTC (rev 7184)
@@ -173,7 +173,7 @@
// calc position on radar...
Vector2 coord = get2DViewcoordinates(this->owner_->getPosition(), this->owner_->getOrientation() * WorldEntity::FRONT, this->owner_->getOrientation() * WorldEntity::UP, wePointer->getWorldPosition());
- coord *= Ogre::Math::PI / 3.5f; // small adjustment to make it fit the texture
+ coord *= math::pi / 3.5f; // small adjustment to make it fit the texture
it->second->setPosition((1.0f + coord.x - size) * 0.5f, (1.0f - coord.y - size) * 0.5f);
it->second->show();
Modified: code/trunk/src/orxonox/controllers/AIController.cc
===================================================================
--- code/trunk/src/orxonox/controllers/AIController.cc 2010-08-18 17:49:31 UTC (rev 7183)
+++ code/trunk/src/orxonox/controllers/AIController.cc 2010-08-18 19:46:16 UTC (rev 7184)
@@ -219,7 +219,7 @@
if (this->bHasTargetPosition_)
this->moveToTargetPosition();
- if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
+ if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f))
this->getControllableEntity()->fire(0);
}
@@ -252,7 +252,7 @@
if (this->bHasTargetPosition_)
this->moveToTargetPosition();
- if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
+ if (this->getControllableEntity() && this->bShooting_ && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f))
this->getControllableEntity()->fire(0);
}
Modified: code/trunk/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/trunk/src/orxonox/controllers/ArtificialController.cc 2010-08-18 17:49:31 UTC (rev 7183)
+++ code/trunk/src/orxonox/controllers/ArtificialController.cc 2010-08-18 19:46:16 UTC (rev 7184)
@@ -846,8 +846,8 @@
float speed = this->getControllableEntity()->getVelocity().length();
Vector3 distanceCurrent = this->targetPosition_ - this->getControllableEntity()->getPosition();
Vector3 distanceNew = it->getPosition() - this->getControllableEntity()->getPosition();
- if (!this->target_ || it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) * (1.5f + acos((this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).dotProduct(distanceNew) / speed / distanceNew.length()) / (2 * Ogre::Math::PI))
- < this->targetPosition_.squaredDistance(this->getControllableEntity()->getPosition()) * (1.5f + acos((this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).dotProduct(distanceCurrent) / speed / distanceCurrent.length()) / (2 * Ogre::Math::PI)) + rnd(-250, 250))
+ if (!this->target_ || it->getPosition().squaredDistance(this->getControllableEntity()->getPosition()) * (1.5f + acos((this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).dotProduct(distanceNew) / speed / distanceNew.length()) / (2 * math::pi))
+ < this->targetPosition_.squaredDistance(this->getControllableEntity()->getPosition()) * (1.5f + acos((this->getControllableEntity()->getOrientation() * WorldEntity::FRONT).dotProduct(distanceCurrent) / speed / distanceCurrent.length()) / (2 * math::pi)) + rnd(-250, 250))
{
this->target_ = (*it);
this->targetPosition_ = it->getPosition();
Modified: code/trunk/src/orxonox/controllers/NewHumanController.cc
===================================================================
--- code/trunk/src/orxonox/controllers/NewHumanController.cc 2010-08-18 17:49:31 UTC (rev 7183)
+++ code/trunk/src/orxonox/controllers/NewHumanController.cc 2010-08-18 19:46:16 UTC (rev 7184)
@@ -533,22 +533,22 @@
if (distance > 0.04f && distance <= 0.59f * arrowsSize_ / 2.0f )
{
- this->arrowsOverlay1_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * Ogre::Math::PI) * 360.0f));
+ this->arrowsOverlay1_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * math::pi) * 360.0f));
this->arrowsOverlay1_->show();
}
else if (distance > 0.59f * arrowsSize_ / 2.0f && distance <= 0.77f * arrowsSize_ / 2.0f )
{
- this->arrowsOverlay2_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * Ogre::Math::PI) * 360.0f));
+ this->arrowsOverlay2_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * math::pi) * 360.0f));
this->arrowsOverlay2_->show();
}
else if (distance > 0.77f * arrowsSize_ / 2.0f && distance <= arrowsSize_ / 2.0f)
{
- this->arrowsOverlay3_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * Ogre::Math::PI) * 360.0f));
+ this->arrowsOverlay3_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * math::pi) * 360.0f));
this->arrowsOverlay3_->show();
}
else if (distance > arrowsSize_ / 2.0f)
{
- this->arrowsOverlay4_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * Ogre::Math::PI) * 360.0f));
+ this->arrowsOverlay4_->setRotation(Degree(-90 + -1.0f * atan2(static_cast<float>(this->currentPitch_)/2*-1, static_cast<float>(this->currentYaw_)/2*-1) / (2.0f * math::pi) * 360.0f));
this->arrowsOverlay4_->show();
}
}
Modified: code/trunk/src/orxonox/controllers/WaypointPatrolController.cc
===================================================================
--- code/trunk/src/orxonox/controllers/WaypointPatrolController.cc 2010-08-18 17:49:31 UTC (rev 7183)
+++ code/trunk/src/orxonox/controllers/WaypointPatrolController.cc 2010-08-18 19:46:16 UTC (rev 7184)
@@ -67,7 +67,7 @@
if (this->bHasTargetPosition_)
this->moveToTargetPosition();
- if (this->getControllableEntity() && this->isCloseAtTarget(1000) && this->isLookingAtTarget(Ogre::Math::PI / 20.0f))
+ if (this->getControllableEntity() && this->isCloseAtTarget(1000) && this->isLookingAtTarget(math::pi / 20.0f))
this->getControllableEntity()->fire(0);
}
else
Modified: code/trunk/src/orxonox/overlays/OrxonoxOverlay.cc
===================================================================
--- code/trunk/src/orxonox/overlays/OrxonoxOverlay.cc 2010-08-18 17:49:31 UTC (rev 7183)
+++ code/trunk/src/orxonox/overlays/OrxonoxOverlay.cc 2010-08-18 19:46:16 UTC (rev 7184)
@@ -281,9 +281,9 @@
float angle = this->angle_.valueRadians();
if (angle < 0.0)
angle = -angle;
- angle -= Ogre::Math::PI * static_cast<int>(angle / (Ogre::Math::PI));
- if (angle > Ogre::Math::PI * 0.5)
- angle = Ogre::Math::PI - angle;
+ angle -= math::pi * static_cast<int>(angle / (math::pi));
+ if (angle > math::pi * 0.5)
+ angle = math::pi - angle;
// do some mathematical fiddling for a bounding box
Vector2 actualSize = size_ * sizeCorrection_;
Modified: code/trunk/src/orxonox/worldentities/pawns/FpsPlayer.cc
===================================================================
--- code/trunk/src/orxonox/worldentities/pawns/FpsPlayer.cc 2010-08-18 17:49:31 UTC (rev 7183)
+++ code/trunk/src/orxonox/worldentities/pawns/FpsPlayer.cc 2010-08-18 19:46:16 UTC (rev 7184)
@@ -170,23 +170,23 @@
this->yaw(Radian(this->yaw_ * this->getMouseLookSpeed()), WorldEntity::Parent);
Radian pitch = this->cameraPositionRootNode_->getOrientation().getPitch();
- if (pitch < Radian(1.5707f) && pitch > Radian(-1.5707f))
+ if (pitch < Radian(math::pi_2) && pitch > Radian(-math::pi_2))
{
this->cameraPositionRootNode_->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
}
- else if (pitch < Radian(-1.5707f))
+ else if (pitch < Radian(-math::pi_2))
{
if (this->pitch_ > 0.0f)
this->cameraPositionRootNode_->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
- else if (pitch < Radian(-1.571f))
- this->cameraPositionRootNode_->pitch(-pitch + Radian(-1.570796f));
+ else if (pitch < Radian(-math::pi_2))
+ this->cameraPositionRootNode_->pitch(-pitch + Radian(-math::pi_2));
}
- else if (pitch > Radian(1.5707f))
+ else if (pitch > Radian(math::pi_2))
{
if (this->pitch_ < 0.0f)
this->cameraPositionRootNode_->pitch(Radian(this->pitch_ * this->getMouseLookSpeed()));
- else if (pitch > Radian(1.571f))
- this->cameraPositionRootNode_->pitch(-pitch + Radian(1.570796f));
+ else if (pitch > Radian(math::pi_2))
+ this->cameraPositionRootNode_->pitch(-pitch + Radian(math::pi_2));
}
this->weaponNode_->setOrientation(this->cameraPositionRootNode_->getOrientation());
}
More information about the Orxonox-commit
mailing list