[Orxonox-commit 5381] r10044 - in code/branches/turretFS14: data/levels data/levels/includes data/levels/templates src/modules/objects src/modules/objects/controllers
muemart at orxonox.net
muemart at orxonox.net
Tue May 6 11:07:07 CEST 2014
Author: muemart
Date: 2014-05-06 11:07:07 +0200 (Tue, 06 May 2014)
New Revision: 10044
Modified:
code/branches/turretFS14/data/levels/includes/weaponSettingsTurretTest.oxi
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
Log:
Move everything back to the Turret class, set the correct team, and (re)arm the turret. Also, hide it from the radar.
Modified: code/branches/turretFS14/data/levels/includes/weaponSettingsTurretTest.oxi
===================================================================
--- code/branches/turretFS14/data/levels/includes/weaponSettingsTurretTest.oxi 2014-04-29 09:31:23 UTC (rev 10043)
+++ code/branches/turretFS14/data/levels/includes/weaponSettingsTurretTest.oxi 2014-05-06 09:07:07 UTC (rev 10044)
@@ -13,10 +13,10 @@
<attached>
<Model mesh="sphere.mesh" position="3,3,-2.2" scale=0.6 />
</attached>
- <HsW01 mode=0 munitionpershot=0 delay=0 damage=0 material="Flares/point_lensflare" muzzleoffset=" 3, 3,-2.2" />
- <HsW01 mode=0 munitionpershot=0 delay=0 damage=0 material="Flares/point_lensflare" muzzleoffset=" 3,-3,-2.2" />
- <HsW01 mode=0 munitionpershot=0 delay=0 damage=0 material="Flares/point_lensflare" muzzleoffset="-3, 3,-2.2" />
- <HsW01 mode=0 munitionpershot=0 delay=0 damage=0 material="Flares/point_lensflare" muzzleoffset="-3,-3,-2.2" />
+ <HsW01 mode=0 munitionpershot=0 delay=0 damage=0 material="Flares/point_lensflare" muzzleoffset=" 30, 3,-2.2" />
+ <HsW01 mode=0 munitionpershot=0 delay=0 damage=0 material="Flares/point_lensflare" muzzleoffset=" 30,-3,-2.2" />
+ <HsW01 mode=0 munitionpershot=0 delay=0 damage=0 material="Flares/point_lensflare" muzzleoffset="-30, 3,-2.2" />
+ <HsW01 mode=0 munitionpershot=0 delay=0 damage=0 material="Flares/point_lensflare" muzzleoffset="-30,-3,-2.2" />
</Weapon>
</WeaponPack>
</weapons>
Modified: code/branches/turretFS14/data/levels/templates/spaceshipAssff.oxt
===================================================================
--- code/branches/turretFS14/data/levels/templates/spaceshipAssff.oxt 2014-04-29 09:31:23 UTC (rev 10043)
+++ code/branches/turretFS14/data/levels/templates/spaceshipAssff.oxt 2014-05-06 09:07:07 UTC (rev 10044)
@@ -47,16 +47,6 @@
<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-29 09:31:23 UTC (rev 10043)
+++ code/branches/turretFS14/data/levels/templates/spaceshipTurretTest.oxt 2014-05-06 09:07:07 UTC (rev 10044)
@@ -6,10 +6,10 @@
<collisionShapes>
<SphereCollisionShape radius="10" position = "0,0,0"/>
</collisionShapes>
- </Turret>
<?lua
include("../includes/weaponSettingsTurretTest.oxi")
?>
+ </Turret>
</Template>
<Template name=spaceshipturretcameras defaults=0>
Modified: code/branches/turretFS14/data/levels/turretTest.oxw
===================================================================
--- code/branches/turretFS14/data/levels/turretTest.oxw 2014-04-29 09:31:23 UTC (rev 10043)
+++ code/branches/turretFS14/data/levels/turretTest.oxw 2014-05-06 09:07:07 UTC (rev 10044)
@@ -58,6 +58,8 @@
</attached>
</SpaceShip> -->
+
+
<StaticEntity position="100,0,0">
<attached>
<Model mesh="sphere.mesh" position="20,0,0" scale=1/>
@@ -66,6 +68,7 @@
<Model mesh="sphere.mesh" position="0,0,30" scale=2/>
</attached>
+
</StaticEntity>
<SpaceShip position="100,0,0" yaw=0 pitch=90>
<attached>
Modified: code/branches/turretFS14/src/modules/objects/Turret.cc
===================================================================
--- code/branches/turretFS14/src/modules/objects/Turret.cc 2014-04-29 09:31:23 UTC (rev 10043)
+++ code/branches/turretFS14/src/modules/objects/Turret.cc 2014-05-06 09:07:07 UTC (rev 10044)
@@ -20,7 +20,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Author:
- * Marian Runo
+ * Marian Runo, Martin Mueller
* Co-authors:
* ...
*
@@ -29,7 +29,6 @@
#include "Turret.h"
#include "core/CoreIncludes.h"
#include "core/XMLPort.h"
-#include "BulletDynamics/Dynamics/btRigidBody.h"
namespace orxonox
{
@@ -44,8 +43,17 @@
{
RegisterObject(Turret);
this->rotationThrust_ = 50;
+ this->startDir_ = Vector3::ZERO;
+ this->localZ_ = Vector3::UNIT_Z;
+ this->localY_ = Vector3::UNIT_Y;
+ this->localX_ = Vector3::UNIT_X;
+ this->attackRadius_ = 200;
+ this->maxPitch_ = 90;
+ this->maxYaw_ = 90;
+ this->once_ = false;
+ this->rotation_ = Quaternion::IDENTITY;
- this->localAngularAcceleration_.setValue(0, 0, 0);
+ this->setRadarVisibility(false);
}
/**
@@ -57,6 +65,49 @@
}
+ bool Turret::isInRange(const Vector3 &position)
+ {
+ //Check distance
+ Vector3 distance = position - this->getWorldPosition();
+ if(distance.squaredLength() > (this->attackRadius_ * this->attackRadius_))
+ {
+ return false;
+ }
+
+ //Check pitch
+ 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_)
+ {
+ return false;
+ }
+
+ //Check yaw
+ dirProjected = dir;
+ dirProjected.y = 0;
+ startDirProjected = this->startDir_;
+ startDirProjected.y = 0;
+ angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
+ if(angle > this->maxYaw_)
+ {
+ return false;
+ }
+ return true;
+ }
+
+ void Turret::aimAtPosition(const Vector3& position)
+ {
+ Vector3 currDir = this->getWorldOrientation() * WorldEntity::FRONT;
+ Vector3 targetDir = position - this->getWorldPosition();
+
+ this->rotation_ = currDir.getRotationTo(targetDir);
+
+ }
+
void Turret::rotatePitch(const Vector2& value)
{
//This is a failed attempt at limiting the turret's rotation. It's handled in the controller (for now?)
@@ -73,7 +124,6 @@
this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x*0.8f);
}
*/
- this->localAngularAcceleration_.setX(this->localAngularAcceleration_.x() + value.x*0.8f);
}
void Turret::rotateYaw(const Vector2& value)
@@ -92,33 +142,66 @@
this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x*0.8f);
}
*/
- this->localAngularAcceleration_.setY(this->localAngularAcceleration_.y() + value.x*0.8f);
}
void Turret::rotateRoll(const Vector2& value)
{
- this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x*0.8f);
}
void Turret::XMLPort(Element& xmlelement, XMLPort::Mode mode)
{
SUPER(Turret, XMLPort, xmlelement, mode);
+
+ XMLPortParamVariable(Turret, "rotationThrust", rotationThrust_, xmlelement, mode);
+ XMLPortParam(Turret, "attackRadius", setAttackRadius, getAttackRadius, xmlelement, mode);
+ XMLPortParam(Turret, "maxYaw", setMaxYaw, getMaxYaw, xmlelement, mode);
+ XMLPortParam(Turret, "maxPitch", setMaxPitch, getMaxPitch, xmlelement, mode);
}
void Turret::tick(float dt)
{
SUPER(Turret, tick, dt);
- this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
- this->localAngularAcceleration_ = physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_;
- //physics don't work when attached :(
- //this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
+ if(!this->once_)
+ {
- pitch(Degree(localAngularAcceleration_.x()*dt/1000), WorldEntity::World);
- yaw(Degree(localAngularAcceleration_.y()*dt/1000), WorldEntity::World);
- roll(Degree(localAngularAcceleration_.z()*dt/1000), WorldEntity::World);
+ Quaternion startOrient = this->getOrientation();
+ this->localXStart_ = startOrient * this->localX_;
+ this->localXStart_.normalise();
+ this->localX_ = this->localXStart_;
+ this->localYStart_ = startOrient * this->localY_;
+ this->localYStart_.normalise();
+ this->localY_ = this->localYStart_;
+ this->localZStart_ = startOrient * this->localZ_;
+ this->localZStart_.normalise();
+ this->localZ_ = this->localZStart_;
- this->localAngularAcceleration_.setValue(0, 0, 0);
+ //startDir should always be (0,0,-1)
+ this->startDir_ = getTransformedVector(startOrient * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);
+
+ this->once_ = true;
+
+ }
+
+ //Adjust local axes to parent's rotation
+ WorldEntity* parent = this->getParent();
+ if(parent)
+ {
+ Quaternion parentrot = parent->getWorldOrientation();
+ this->localX_ = parentrot * this->localXStart_;
+ this->localY_ = parentrot * this->localYStart_;
+ this->localZ_ = parentrot * this->localZStart_;
+ }
+
+ //rotate
+ if(this->rotation_ != Quaternion::IDENTITY)
+ {
+ //Don't make the rotation instantaneous
+ Quaternion drot = Quaternion::Slerp(dt*this->rotationThrust_/20.f, Quaternion::IDENTITY, this->rotation_);
+ this->rotate(drot, WorldEntity::World);
+ this->rotation_ = Quaternion::IDENTITY;
+ }
+
}
}
\ No newline at end of file
Modified: code/branches/turretFS14/src/modules/objects/Turret.h
===================================================================
--- code/branches/turretFS14/src/modules/objects/Turret.h 2014-04-29 09:31:23 UTC (rev 10043)
+++ code/branches/turretFS14/src/modules/objects/Turret.h 2014-05-06 09:07:07 UTC (rev 10044)
@@ -49,15 +49,48 @@
virtual void rotatePitch(const Vector2& value);
virtual void rotateYaw(const Vector2& value);
virtual void rotateRoll(const Vector2& value);
+ virtual bool isInRange(const Vector3 &position);
+ virtual void aimAtPosition(const Vector3 &position);
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
virtual void tick(float dt);
+ inline void setAttackRadius(float radius)
+ { this->attackRadius_ = radius; }
+ inline void setMaxPitch(float pitch)
+ { this->maxPitch_ = pitch; }
+
+ inline void setMaxYaw(float yaw)
+ { this->maxYaw_ = yaw; }
+
+ inline float getAttackRadius() const
+ { return this->attackRadius_; }
+
+ inline float getMaxPitch() const
+ { return this->maxPitch_; }
+
+ inline float getMaxYaw() const
+ { return this->maxYaw_; }
+
+ protected:
+ Vector3 startDir_;
+ Vector3 localZ_;
+ Vector3 localZStart_;
+ Vector3 localY_;
+ Vector3 localYStart_;
+ Vector3 localX_;
+ Vector3 localXStart_;
+
private:
+ bool once_;
+
+ float attackRadius_;
+ Ogre::Real maxPitch_;
+ Ogre::Real maxYaw_;
float rotationThrust_;
- btVector3 localAngularAcceleration_;
+ Quaternion rotation_;
};
}
Modified: code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc
===================================================================
--- code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc 2014-04-29 09:31:23 UTC (rev 10043)
+++ code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc 2014-05-06 09:07:07 UTC (rev 10044)
@@ -37,15 +37,9 @@
TurretController::TurretController(Context* context) : ArtificialController(context)
{
RegisterObject(TurretController);
- this->startOrient_ = Quaternion::IDENTITY;
- this->startDir_ = Vector3::ZERO;
- this->localZ_ = Vector3::UNIT_Z;
- this->localY_ = Vector3::UNIT_Y;
- this->localX_ = Vector3::UNIT_X;
- this->attackRadius_ = 200;
- this->maxPitch_ = 90;
- this->maxYaw_ = 90;
- this->gotOrient_ = false;
+
+ this->once_ = false;
+
}
TurretController::~TurretController()
@@ -56,13 +50,14 @@
void TurretController::searchTarget()
{
Turret* turret = orxonox_cast<Turret*>(this->getControllableEntity());
- if(target_ && this->isInRange(target_->getWorldPosition()))
+ if(target_ && turret->isInRange(target_->getWorldPosition()))
{
return;
}
else
{
this->forgetTarget();
+ turret->setTarget(0);
}
@@ -70,7 +65,7 @@
if(parent)
{
Pawn* parenttarget = orxonox_cast<Pawn*>(parent->getTarget());
- if(parenttarget && this->isInRange(parenttarget->getWorldPosition()))
+ if(parenttarget && turret->isInRange(parenttarget->getWorldPosition()))
{
this->setTarget(parenttarget);
turret->setTarget(parenttarget);
@@ -81,10 +76,10 @@
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()))
+ if (this->FormationController::sameTeam(this->getControllableEntity(), entity, this->getGametype()))
continue;
- if(this->isInRange(entity->getWorldPosition()))
+ if(turret->isInRange(entity->getWorldPosition()))
{
this->setTarget(entity);
turret->setTarget(entity);
@@ -93,60 +88,6 @@
}
}
- bool TurretController::isInRange(const Vector3 &position)
- {
- //Check distance
- Vector3 distance = position - this->getControllableEntity()->getWorldPosition();
- if(distance.squaredLength() > (this->attackRadius_ * this->attackRadius_))
- {
- return false;
- }
-
- //Check pitch
- 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_)
- {
- return false;
- }
-
- //Check yaw
- dirProjected = dir;
- dirProjected.y = 0;
- startDirProjected = this->startDir_;
- startDirProjected.y = 0;
- angle = startDirProjected.angleBetween(dirProjected).valueDegrees();
- if(angle > this->maxYaw_)
- {
- return false;
- }
- return true;
- }
-
- void TurretController::aimAtPositionRot(const Vector3 &position)
- {
-
- Vector3 currDir = this->getControllableEntity()->getWorldOrientation() * WorldEntity::FRONT;
- Vector3 targetDir = position - this->getControllableEntity()->getWorldPosition();
-
- Quaternion rot = currDir.getRotationTo(targetDir);
-
- //Don't make the rotation instantaneous
- rot = Quaternion::Slerp(0.1, Quaternion::IDENTITY, rot);
-
- this->getControllableEntity()->rotate(rot, WorldEntity::World);
- }
-
-
- void TurretController::aimAtTargetRot()
- {
- this->aimAtPositionRot(this->target_->getWorldPosition());
- }
-
bool TurretController::isLookingAtTargetNew(float angle) const
{
return (getAngle(this->getControllableEntity()->getWorldPosition(), this->getControllableEntity()->getWorldOrientation() * WorldEntity::FRONT, this->target_->getWorldPosition()) < angle);
@@ -154,51 +95,48 @@
void TurretController::tick(float dt)
{
- if(!gotOrient_)
- {
- this->startOrient_ = this->getControllableEntity()->getOrientation();
- this->localXStart_ = this->startOrient_ * this->localX_;
- this->localXStart_.normalise();
- this->localX_ = this->localXStart_;
- this->localYStart_ = this->startOrient_ * this->localY_;
- this->localYStart_.normalise();
- this->localY_ = this->localYStart_;
- this->localZStart_ = this->startOrient_ * this->localZ_;
- this->localZStart_.normalise();
- this->localZ_ = this->localZStart_;
+ if (!this->isActive() || !this->getControllableEntity())
+ return;
- //startDir should always be (0,0,-1)
- this->startDir_ = getTransformedVector(this->startOrient_ * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);
- this->gotOrient_ = true;
+ if(!this->once_)
+ {
+ if(this->getTeam() != -1)
+ {
+ orxout(internal_warning) << "Turret: Team already set, may result in undesired behaviour" << endl;
+ }
+ else
+ {
+ //Make sure the turret is in the same team as the parent
+ ControllableEntity* parent = orxonox_cast<ControllableEntity*> (this->getControllableEntity()->getParent());
+ if(parent)
+ {
+ Controller* parentcontroller = parent->getController();
+ if(parentcontroller)
+ {
+ this->setTeam(parentcontroller->getTeam());
+ }
+ else
+ {
+ this->setTeam(parent->getTeam());
+ }
+ this->getControllableEntity()->setTeam(parent->getTeam());
+ }
+ }
+ this->once_ = true;
+ }
- }
-
- WorldEntity* parent = this->getControllableEntity()->getParent();
- if(parent)
- {
- Quaternion parentrot = parent->getOrientation();
- this->localX_ = parentrot * this->localXStart_;
- this->localY_ = parentrot * this->localYStart_;
- this->localZ_ = parentrot * this->localZStart_;
- }
-
-
-
- if (!this->isActive() || !this->getControllableEntity())
- return;
-
- this->searchTarget();
- if(target_)
- {
- this->aimAtTarget();
- //this->getControllableEntity()->lookAt(this->targetPosition_);
- //It says move, but really it only turns
- this->aimAtTargetRot();
- if(this->isLookingAtTargetNew(Degree(5).valueRadians()))
- {
- orxout() << 42 << endl;
- }
- }
+ this->searchTarget();
+ if(target_)
+ {
+ Turret* turret = orxonox_cast<Turret*> (this->getControllableEntity());
+ this->aimAtTarget();
+ turret->aimAtPosition(target_->getWorldPosition());
+ if(this->isLookingAtTargetNew(Degree(5).valueRadians()))
+ {
+ this->getControllableEntity()->fire(0);
+ 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-29 09:31:23 UTC (rev 10043)
+++ code/branches/turretFS14/src/modules/objects/controllers/TurretController.h 2014-05-06 09:07:07 UTC (rev 10044)
@@ -43,24 +43,11 @@
virtual void tick(float dt);
private:
- bool gotOrient_;
- float attackRadius_;
- Ogre::Real maxPitch_;
- Ogre::Real maxYaw_;
- Quaternion startOrient_;
- Vector3 startDir_;
- Vector3 localZ_;
- Vector3 localZStart_;
- Vector3 localY_;
- Vector3 localYStart_;
- Vector3 localX_;
- Vector3 localXStart_;
- void aimAtPositionRot(const Vector3 &position);
- void aimAtTargetRot();
void searchTarget();
- bool isInRange(const Vector3 &position);
bool isLookingAtTargetNew(float angle) const;
+
+ bool once_;
};
}
More information about the Orxonox-commit
mailing list