[Orxonox-commit 5368] r10031 - in code/branches/turretFS14: data/levels data/levels/templates src/modules/objects src/modules/objects/controllers src/orxonox/worldentities
muemart at orxonox.net
muemart at orxonox.net
Thu Apr 10 16:06:03 CEST 2014
Author: muemart
Date: 2014-04-10 16:06:03 +0200 (Thu, 10 Apr 2014)
New Revision: 10031
Modified:
code/branches/turretFS14/data/levels/templates/spaceshipAssff.oxt
code/branches/turretFS14/data/levels/templates/spaceshipTurretTest.oxt
code/branches/turretFS14/data/levels/turretTest.oxw
code/branches/turretFS14/src/modules/objects/Turret.cc
code/branches/turretFS14/src/modules/objects/Turret.h
code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc
code/branches/turretFS14/src/modules/objects/controllers/TurretController.h
code/branches/turretFS14/src/orxonox/worldentities/WorldEntity.cc
Log:
Limit turret's rotation (another method...), work a bit on the controller, and make a (ugly?) hack to allow attaching dynamic objects
Modified: code/branches/turretFS14/data/levels/templates/spaceshipAssff.oxt
===================================================================
--- code/branches/turretFS14/data/levels/templates/spaceshipAssff.oxt 2014-04-10 13:57:29 UTC (rev 10030)
+++ code/branches/turretFS14/data/levels/templates/spaceshipAssff.oxt 2014-04-10 14:06:03 UTC (rev 10031)
@@ -47,6 +47,16 @@
<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 />
+
+ <Turret position="0,10,0" pitch="90" yaw="0" roll="0" maxPitch=90 maxYaw=90 attackRadius=2000>
+ <templates>
+ <Template link=spaceshipturrettest />
+ </templates>
+ <controller>
+ <TurretController team=10 />
+ </controller>
+ </Turret>
+
</attached>
<collisionShapes>
<BoxCollisionShape position="0,0,0" halfExtents="10, 3, 5" />
Modified: code/branches/turretFS14/data/levels/templates/spaceshipTurretTest.oxt
===================================================================
--- code/branches/turretFS14/data/levels/templates/spaceshipTurretTest.oxt 2014-04-10 13:57:29 UTC (rev 10030)
+++ code/branches/turretFS14/data/levels/templates/spaceshipTurretTest.oxt 2014-04-10 14:06:03 UTC (rev 10031)
@@ -1,7 +1,7 @@
<Template name=spaceshipturrettest>
<Turret position="0,0,0" collisionType="dynamic" angularDamping=0.999999 mass=100>
<attached>
- <Model position="0,0,0" pitch="90" roll="0" mesh="turretHead.mesh" scale3D="10,10,10"/>
+ <Model position="0,0,0" pitch="-90" roll="0" mesh="turretHead.mesh" scale3D="10,10,10"/>
</attached>
<collisionShapes>
<SphereCollisionShape radius="10" position = "0,0,0"/>
@@ -20,4 +20,4 @@
<CameraPosition position="0,30,120" drag=true mouselook=true />
</camerapositions>
</SpaceShip>
-</Template>
+</Template>
\ No newline at end of file
Modified: code/branches/turretFS14/data/levels/turretTest.oxw
===================================================================
--- code/branches/turretFS14/data/levels/turretTest.oxw 2014-04-10 13:57:29 UTC (rev 10030)
+++ code/branches/turretFS14/data/levels/turretTest.oxw 2014-04-10 14:06:03 UTC (rev 10031)
@@ -33,7 +33,7 @@
<SpawnPoint team=0 position="-200,0,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
-<StaticEntity position="0,0,0" yaw=0 pitch=0>
+<MovableEntity position="0,0,0" yaw=0 pitch=0>
<attached>
<Model position="0,0,0" mesh="turretSocketFront.mesh" scale3D="10,10,10" />
<Model position="0,0,0" mesh="turretSocketIn.mesh" scale3D="10,10,10" />
@@ -41,23 +41,23 @@
<Model position="0,0,0" mesh="turretSocketLeft.mesh" scale3D="10,10,10" />
<Model position="0,0,0" mesh="turretSocketRight.mesh" scale3D="10,10,10" />
- <Turret position="0,10,0" pitch="-90" yaw="0" roll="0" maxPitch=30 maxYaw=30>
+ <!-- <Turret position="0,10,0" pitch="90" yaw="0" roll="0" maxPitch=90 maxYaw=90 attackRadius=2000>
<templates>
<Template link=spaceshipturrettest />
</templates>
<controller>
<TurretController team=10 />
</controller>
- </Turret>
+ </Turret> -->
- <Model mesh="sphere.mesh" position="25,0,0" scale=1 />
+ <Model mesh="sphere.mesh" position="20,0,0" scale=1/>
- <Model mesh="sphere.mesh" position="0,25,0" scale=1 />
+ <Model mesh="sphere.mesh" position="0,25,0" scale=1/>
- <Model mesh="sphere.mesh" position="0,0,25" scale=1 />
+ <Model mesh="sphere.mesh" position="0,0,30" scale=1/>
</attached>
-</StaticEntity>
+</MovableEntity>
Modified: code/branches/turretFS14/src/modules/objects/Turret.cc
===================================================================
--- code/branches/turretFS14/src/modules/objects/Turret.cc 2014-04-10 13:57:29 UTC (rev 10030)
+++ code/branches/turretFS14/src/modules/objects/Turret.cc 2014-04-10 14:06:03 UTC (rev 10031)
@@ -43,9 +43,14 @@
Turret::Turret(Context* context) : Pawn(context)
{
RegisterObject(Turret);
- this->startOrientInv_ = Quaternion::IDENTITY;
+ this->startOrient_ = Quaternion::IDENTITY;
+ this->startDir_ = Vector3::ZERO;
+ this->localZ_ = Vector3::UNIT_Z;
+ this->localY_ = Vector3::UNIT_Y;
+ this->localX_ = Vector3::UNIT_X;
this->maxPitch_ = 0;
this->maxYaw_ = 0;
+ this->attackRadius_ = 200;
this->gotOrient_ = false;
this->rotationThrust_ = 50;
@@ -62,88 +67,84 @@
void Turret::rotatePitch(const Vector2& value)
- {
- if (this->maxPitch_ == 0)
+ {
+ //This is a failed attempt at limiting the turret's rotation. It's handled in the controller (for now?)
+ /*
+ Vector3 currentDir = getTransformedVector(this->getOrientation() * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);
+ Vector3 currentDirProjected = currentDir;
+ currentDirProjected.x = 0;
+ Vector3 startDirProjected = this->startDir_;
+ startDirProjected.x = 0;
+ Ogre::Real angle = startDirProjected.angleBetween(currentDirProjected).valueDegrees();
+ //orxout() << "Pitch: " << angle << endl;
+ //if(angle < this->maxPitch_ || (currentDirProjected.y <= 0 && value.x > 0) || (currentDirProjected.y > 0 && value.x < 0) )
{
- return;
- }
- if (this->maxPitch_ >= 180) //no need to check, if the limit too big
- {
this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x*0.8f);
- return;
}
-
- Quaternion drot = startOrientInv_ * this->getOrientation();
-
- Ogre::Real val = boundBetween(drot.getPitch(false).valueDegrees(), -180, 180);
- Ogre::Real offset = boundBetween(Degree(value.x).valueDegrees(), -180, 180);
- Ogre::Real lowerBound = offset - this->maxPitch_;
- Ogre::Real upperBound = offset + this->maxPitch_;
- if (lowerBound < -180) //Avoid wrapping around of the boundaries
- {
- lowerBound += this->maxPitch_;
- upperBound += this->maxPitch_;
- val = boundBetween(val + this->maxPitch_, -180, 180); //val might wrap around here
- }
- else if (upperBound >= 180) //Avoid wrapping around of the boundaries (the other side)
- {
- lowerBound -= this->maxPitch_;
- upperBound -= this->maxPitch_;
- val = boundBetween(val-this->maxPitch_, -180, 180); //val might wrap around here
- }
- if ((val >= lowerBound || value.x > 0) && (val <= upperBound || value.x < 0))
- {
- this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x*0.8f);
- }
- return;
+ */
+ this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x*0.8f);
}
void Turret::rotateYaw(const Vector2& value)
{
- if (this->maxPitch_ == 0)
+ //This is a failed attempt at limiting the turret's rotation. It's handled in the controller (for now?)
+ /*
+ Vector3 currentDir = getTransformedVector(this->getOrientation() * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);
+ Vector3 currentDirProjected = currentDir;
+ currentDirProjected.y = 0;
+ Vector3 startDirProjected = this->startDir_;
+ startDirProjected.y = 0;
+ Ogre::Real angle = startDirProjected.angleBetween(currentDirProjected).valueDegrees();
+ orxout() << "Yaw: " << angle << endl;
+ if(angle < this->maxYaw_ || (currentDirProjected.x <= 0 && value.x < 0) || (currentDirProjected.x > 0 && value.x > 0))
{
- return;
- }
- if (this->maxPitch_ >= 180) //no need to check, if the limit too big
- {
this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x*0.8f);
- return;
}
+ */
+ this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x*0.8f);
+ }
- Quaternion drot = startOrientInv_ * this->getOrientation();
+ void Turret::rotateRoll(const Vector2& value)
+ {
+ this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x*0.8f);
+ }
- Ogre::Real val = boundBetween(drot.getYaw(false).valueDegrees(), -180, 180);
- Ogre::Real offset = boundBetween(Degree(value.x).valueDegrees(), -180, 180);
- Ogre::Real lowerBound = offset - this->maxPitch_;
- Ogre::Real upperBound = offset + this->maxPitch_;
- if (lowerBound < -180) //Avoid wrapping around of the boundaries
+ bool Turret::isInRange(Vector3 position)
+ {
+ Vector3 distance = position - this->getPosition();
+ if(distance.squaredLength() > (this->attackRadius_ * this->attackRadius_))
{
- lowerBound += this->maxPitch_;
- upperBound += this->maxPitch_;
- val = boundBetween(val + this->maxPitch_, -180, 180); //val might wrap around here
+ return false;
}
- else if (upperBound >= 180) //Avoid wrapping around of the boundaries (the other side)
+
+ Vector3 dir = getTransformedVector(distance, this->localX_, this->localY_, this->localZ_);
+ Vector3 dirProjected = dir;
+ dirProjected.x = 0;
+ Vector3 startDirProjected = this->startDir_;
+ startDirProjected.x = 0;
+ Ogre::Real angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
+ if(angle > this->maxPitch_)
{
- lowerBound -= this->maxPitch_;
- upperBound -= this->maxPitch_;
- val = boundBetween(val-this->maxPitch_, -180, 180); //val might wrap around here
+ return false;
}
- if ((val >= lowerBound || value.x > 0) && (val <= upperBound || value.x < 0))
+
+ dirProjected = dir;
+ dirProjected.y = 0;
+ startDirProjected = this->startDir_;
+ startDirProjected.y = 0;
+ angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
+ if(angle > this->maxYaw_)
{
- this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x*0.8f);
+ return false;
}
- return;
+ return true;
}
- void Turret::rotateRoll(const Vector2& value)
- {
- return; //Standard turrets don't roll
- }
-
void Turret::XMLPort(Element& xmlelement, XMLPort::Mode mode)
{
XMLPortParam(Turret, "maxPitch", setMaxPitch, getMaxPitch, xmlelement, mode);
XMLPortParam(Turret, "maxYaw", setMaxYaw, getMaxYaw, xmlelement, mode);
+ XMLPortParam(Turret, "attackRadius", setAttackRadius, getAttackRadius, xmlelement, mode);
SUPER(Turret, XMLPort, xmlelement, mode);
}
@@ -153,25 +154,23 @@
if(!gotOrient_)
{
- startOrientInv_ = this->getOrientation().Inverse();
- gotOrient_ = true;
+ this->startOrient_ = this->getOrientation();
+ this->localX_ = this->startOrient_ * this->localX_;
+ this->localX_.normalise();
+ this->localY_ = this->startOrient_ * this->localY_;
+ this->localY_.normalise();
+ this->localZ_ = this->startOrient_ * this->localZ_;
+ this->localZ_.normalise();
+
+ //startDir should always be (0,0,-1)
+ this->startDir_ = getTransformedVector(this->startOrient_ * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);
+
+ this->gotOrient_ = true;
}
- Quaternion drot = startOrientInv_ * this->getOrientation();
- orxout() << "Pitch: " << drot.getPitch(false).valueDegrees() << "\tYaw: " << drot.getYaw(false).valueDegrees() << "\tRoll: " << drot.getRoll(false).valueDegrees() << endl;
-
+
this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
this->localAngularAcceleration_.setValue(0, 0, 0);
}
-
- Ogre::Real Turret::boundBetween(Ogre::Real val, Ogre::Real lowerBound, Ogre::Real upperBound)
- {
- if (lowerBound > upperBound){ std::swap(lowerBound, upperBound); }
- val -= lowerBound; //adjust to 0
- Ogre::Real rangeSize = upperBound - lowerBound;
- if (rangeSize == 0){ return upperBound; } //avoid dividing by 0
- return val - (rangeSize * std::floor(val / rangeSize)) + lowerBound;
- }
-
}
Modified: code/branches/turretFS14/src/modules/objects/Turret.h
===================================================================
--- code/branches/turretFS14/src/modules/objects/Turret.h 2014-04-10 13:57:29 UTC (rev 10030)
+++ code/branches/turretFS14/src/modules/objects/Turret.h 2014-04-10 14:06:03 UTC (rev 10031)
@@ -36,10 +36,8 @@
#define _Turret_H__
#include "objects/ObjectsPrereqs.h"
-#include "OgreQuaternion.h"
+#include "worldentities/pawns/Pawn.h"
-#include "worldentities/pawns/SpaceShip.h"
-
namespace orxonox
{
class _ObjectsExport Turret : public Pawn
@@ -55,6 +53,8 @@
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
virtual void tick(float dt);
+ virtual bool isInRange(Vector3 position);
+
inline void setMaxPitch(Ogre::Real pitch)
{this->maxPitch_ = pitch;}
@@ -67,16 +67,26 @@
inline Ogre::Real getMaxYaw()
{return this->maxYaw_;}
+ inline void setAttackRadius(float radius)
+ {this->attackRadius_ = radius;}
+
+ inline float getAttackRadius()
+ {return this->attackRadius_;}
+
+
private:
bool gotOrient_;
Ogre::Real maxPitch_;
Ogre::Real maxYaw_;
- Quaternion startOrientInv_;
+ float attackRadius_;
+ Quaternion startOrient_;
+ Vector3 startDir_;
+ Vector3 localZ_;
+ Vector3 localY_;
+ Vector3 localX_;
float rotationThrust_;
btVector3 localAngularAcceleration_;
-
- Ogre::Real boundBetween(float val, float lowerBound, float upperBound);
};
}
Modified: code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc
===================================================================
--- code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc 2014-04-10 13:57:29 UTC (rev 10030)
+++ code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc 2014-04-10 14:06:03 UTC (rev 10031)
@@ -26,7 +26,9 @@
*
*/
- #include "TurretController.h"
+#include "TurretController.h"
+#include "worldentities/pawns/Pawn.h"
+#include "Turret.h"
namespace orxonox
{
@@ -35,8 +37,6 @@
TurretController::TurretController(Context* context) : ArtificialController(context)
{
RegisterObject(TurretController);
- counter = 0;
- flag = false;
}
TurretController::~TurretController()
@@ -44,24 +44,61 @@
}
+ void TurretController::searchTarget()
+ {
+ Turret* turret = orxonox_cast<Turret*>(this->getControllableEntity());
+ if(target_ && turret->isInRange(target_->getPosition()))
+ {
+ return;
+ }
+ else
+ {
+ this->forgetTarget();
+ }
+
+
+ ControllableEntity* parent = orxonox_cast<ControllableEntity*>(turret->getParent());
+ if(parent)
+ {
+ Pawn* parenttarget = orxonox_cast<Pawn*>(parent->getTarget());
+ if(parenttarget && turret->isInRange(parenttarget->getPosition()))
+ {
+ this->setTarget(parenttarget);
+ turret->setTarget(parenttarget);
+ return;
+ }
+ }
+
+ for (ObjectList<Pawn>::iterator it = ObjectList<Pawn>::begin(); it != ObjectList<Pawn>::end(); ++it)
+ {
+ Pawn* entity = orxonox_cast<Pawn*>(*it);
+ if (ArtificialController::sameTeam(this->getControllableEntity(), entity, this->getGametype()))
+ continue;
+
+ if(turret->isInRange(entity->getPosition()))
+ {
+ this->setTarget(entity);
+ turret->setTarget(entity);
+ break;
+ }
+ }
+ }
+
void TurretController::tick(float dt)
{
- counter += dt;
- if(counter >= 10)
+ if (!this->isActive() || !this->getControllableEntity())
+ return;
+ this->searchTarget();
+ this->getControllableEntity()->rotatePitch(0.2);
+ /*if(target_)
{
- counter = 0;
- flag = !flag;
- orxout() << "Direction change" << endl;
- }
- if(flag)
- {
- this->getControllableEntity()->rotatePitch(10*dt);
- //this->getControllableEntity()->rotateYaw(10*dt);
- }
- else
- {
- this->getControllableEntity()->rotatePitch(-10*dt);
- //this->getControllableEntity()->rotateYaw(-10*dt);
- }
+ this->aimAtTarget();
+ //It says move, but really it only turns
+ this->moveToTargetPosition();
+ if(this->isLookingAtTarget(Degree(5).valueRadians()))
+ {
+ orxout() << 42 << endl;
+ }
+ }*/
}
}
\ No newline at end of file
Modified: code/branches/turretFS14/src/modules/objects/controllers/TurretController.h
===================================================================
--- code/branches/turretFS14/src/modules/objects/controllers/TurretController.h 2014-04-10 13:57:29 UTC (rev 10030)
+++ code/branches/turretFS14/src/modules/objects/controllers/TurretController.h 2014-04-10 14:06:03 UTC (rev 10031)
@@ -43,8 +43,7 @@
virtual void tick(float dt);
private:
- float counter;
- bool flag;
+ void searchTarget();
};
}
Modified: code/branches/turretFS14/src/orxonox/worldentities/WorldEntity.cc
===================================================================
--- code/branches/turretFS14/src/orxonox/worldentities/WorldEntity.cc 2014-04-10 13:57:29 UTC (rev 10030)
+++ code/branches/turretFS14/src/orxonox/worldentities/WorldEntity.cc 2014-04-10 14:06:03 UTC (rev 10031)
@@ -413,8 +413,8 @@
}
else if (this->isDynamic())
{
- orxout(internal_warning) << "Cannot attach a dynamic object to a WorldEntity." << endl;
- return false;
+ //orxout(internal_warning) << "Cannot attach a dynamic object to a WorldEntity." << endl;
+ //return false;
}
else if (this->isKinematic() && newParent->isDynamic())
{
More information about the Orxonox-commit
mailing list