[Orxonox-commit 5376] r10039 - in code/branches/turretFS14: data/levels data/levels/templates src/libraries/core/input src/modules/objects src/modules/objects/controllers src/orxonox/controllers src/orxonox/worldentities
muemart at orxonox.net
muemart at orxonox.net
Thu Apr 17 16:05:06 CEST 2014
Author: muemart
Date: 2014-04-17 16:05:06 +0200 (Thu, 17 Apr 2014)
New Revision: 10039
Modified:
code/branches/turretFS14/data/levels/templates/spaceshipAssff.oxt
code/branches/turretFS14/data/levels/turretTest.oxw
code/branches/turretFS14/src/libraries/core/input/InputManager.cc
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/controllers/ArtificialController.cc
code/branches/turretFS14/src/orxonox/controllers/FormationController.cc
code/branches/turretFS14/src/orxonox/worldentities/WorldEntity.cc
Log:
Move logic into controller, don't use bullet for rotations, and use WorldPosition in FormationController+ (good idea?)
Modified: code/branches/turretFS14/data/levels/templates/spaceshipAssff.oxt
===================================================================
--- code/branches/turretFS14/data/levels/templates/spaceshipAssff.oxt 2014-04-17 14:04:50 UTC (rev 10038)
+++ code/branches/turretFS14/data/levels/templates/spaceshipAssff.oxt 2014-04-17 14:05:06 UTC (rev 10039)
@@ -48,14 +48,14 @@
<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>
+ <!-- <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> -->
</attached>
<collisionShapes>
Modified: code/branches/turretFS14/data/levels/turretTest.oxw
===================================================================
--- code/branches/turretFS14/data/levels/turretTest.oxw 2014-04-17 14:04:50 UTC (rev 10038)
+++ code/branches/turretFS14/data/levels/turretTest.oxw 2014-04-17 14:05:06 UTC (rev 10039)
@@ -33,7 +33,7 @@
<SpawnPoint team=0 position="-200,0,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
-<MovableEntity position="0,0,0" yaw=0 pitch=0>
+<SpaceShip position="-100,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,14 +41,14 @@
<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=90 maxYaw=90 attackRadius=2000>
+ <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="20,0,0" scale=1/>
@@ -57,11 +57,35 @@
<Model mesh="sphere.mesh" position="0,0,30" scale=1/>
</attached>
-</MovableEntity>
+</SpaceShip>
+<SpaceShip position="100,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" />
+ <Model position="0,0,0" mesh="turretSocketTop.mesh" scale3D="10,10,10" />
+ <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=90 maxYaw=90 attackRadius=2000>
+ <templates>
+ <Template link=spaceshipturrettest />
+ </templates>
+ <controller>
+ <TurretController team=9 />
+ </controller>
+ </Turret>
+ <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,0,30" scale=1/>
+
+ </attached>
+</SpaceShip>
+
+
</Scene>
</Level>
Modified: code/branches/turretFS14/src/libraries/core/input/InputManager.cc
===================================================================
--- code/branches/turretFS14/src/libraries/core/input/InputManager.cc 2014-04-17 14:04:50 UTC (rev 10038)
+++ code/branches/turretFS14/src/libraries/core/input/InputManager.cc 2014-04-17 14:05:06 UTC (rev 10039)
@@ -174,13 +174,13 @@
paramList.insert(StringPair("XAutoRepeatOn", "true"));
if (exclusiveMouse_ || GraphicsManager::getInstance().isFullScreen())
- {
+ { // HACK MARTIN for debugging, changed values here to true
if (CommandLineParser::getValue("keyboard_no_grab").get<bool>())
paramList.insert(StringPair("x11_keyboard_grab", "false"));
else
- paramList.insert(StringPair("x11_keyboard_grab", "true"));
- paramList.insert(StringPair("x11_mouse_grab", "true"));
- paramList.insert(StringPair("x11_mouse_hide", "true"));
+ paramList.insert(StringPair("x11_keyboard_grab", "false"));
+ paramList.insert(StringPair("x11_mouse_grab", "false"));
+ paramList.insert(StringPair("x11_mouse_hide", "false"));
}
else
{
Modified: code/branches/turretFS14/src/modules/objects/Turret.cc
===================================================================
--- code/branches/turretFS14/src/modules/objects/Turret.cc 2014-04-17 14:04:50 UTC (rev 10038)
+++ code/branches/turretFS14/src/modules/objects/Turret.cc 2014-04-17 14:05:06 UTC (rev 10039)
@@ -43,15 +43,6 @@
Turret::Turret(Context* context) : Pawn(context)
{
RegisterObject(Turret);
- 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;
this->localAngularAcceleration_.setValue(0, 0, 0);
@@ -109,42 +100,8 @@
this->localAngularAcceleration_.setZ(this->localAngularAcceleration_.z() + value.x*0.8f);
}
- bool Turret::isInRange(Vector3 position)
- {
- Vector3 distance = position - this->getPosition();
- if(distance.squaredLength() > (this->attackRadius_ * this->attackRadius_))
- {
- return false;
- }
-
- 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;
- }
-
- 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::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);
}
@@ -152,25 +109,14 @@
{
SUPER(Turret, tick, dt);
- if(!gotOrient_)
- {
- 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();
+ this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
+ this->localAngularAcceleration_ = physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_;
- //startDir should always be (0,0,-1)
- this->startDir_ = getTransformedVector(this->startOrient_ * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);
- this->gotOrient_ = true;
- }
+ pitch(Degree(localAngularAcceleration_.x()/10000), WorldEntity::World);
+ yaw(Degree(localAngularAcceleration_.y()/10000), WorldEntity::World);
+ roll(Degree(localAngularAcceleration_.z()/10000), WorldEntity::World);
- this->localAngularAcceleration_ *= this->getLocalInertia() * this->rotationThrust_;
- this->physicalBody_->applyTorque(physicalBody_->getWorldTransform().getBasis() * this->localAngularAcceleration_);
this->localAngularAcceleration_.setValue(0, 0, 0);
}
-
-}
+}
\ 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-17 14:04:50 UTC (rev 10038)
+++ code/branches/turretFS14/src/modules/objects/Turret.h 2014-04-17 14:05:06 UTC (rev 10039)
@@ -53,37 +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;}
-
- inline Ogre::Real getMaxPitch()
- {return this->maxPitch_;}
-
- inline void setMaxYaw(Ogre::Real yaw)
- {this->maxYaw_ = yaw;}
-
- 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_;
- float attackRadius_;
- Quaternion startOrient_;
- Vector3 startDir_;
- Vector3 localZ_;
- Vector3 localY_;
- Vector3 localX_;
float rotationThrust_;
btVector3 localAngularAcceleration_;
@@ -91,4 +62,3 @@
}
#endif
-
Modified: code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc
===================================================================
--- code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc 2014-04-17 14:04:50 UTC (rev 10038)
+++ code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc 2014-04-17 14:05:06 UTC (rev 10039)
@@ -37,6 +37,16 @@
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;
+ orxout() << "Constructor " << this << endl;
}
TurretController::~TurretController()
@@ -47,7 +57,7 @@
void TurretController::searchTarget()
{
Turret* turret = orxonox_cast<Turret*>(this->getControllableEntity());
- if(target_ && turret->isInRange(target_->getPosition()))
+ if(target_ && this->isInRange(target_->getWorldPosition()))
{
return;
}
@@ -61,7 +71,7 @@
if(parent)
{
Pawn* parenttarget = orxonox_cast<Pawn*>(parent->getTarget());
- if(parenttarget && turret->isInRange(parenttarget->getPosition()))
+ if(parenttarget && this->isInRange(parenttarget->getWorldPosition()))
{
this->setTarget(parenttarget);
turret->setTarget(parenttarget);
@@ -75,7 +85,7 @@
if (ArtificialController::sameTeam(this->getControllableEntity(), entity, this->getGametype()))
continue;
- if(turret->isInRange(entity->getPosition()))
+ if(this->isInRange(entity->getWorldPosition()))
{
this->setTarget(entity);
turret->setTarget(entity);
@@ -84,21 +94,87 @@
}
}
+ bool TurretController::isInRange(Vector3 position)
+ {
+ Vector3 distance = position - this->getControllableEntity()->getWorldPosition();
+ if(distance.squaredLength() > (this->attackRadius_ * this->attackRadius_))
+ {
+ return false;
+ }
+
+ 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;
+ }
+
+ 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::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_;
+
+ //startDir should always be (0,0,-1)
+ this->startDir_ = getTransformedVector(this->startOrient_ * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);
+
+ this->gotOrient_ = true;
+ }
+
+ //orxout() << "Controller " << this;
+ //orxout() << "\tControllable Entity " << this->getControllableEntity() << endl;
+ 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_;
+ }
+
+ orxout() << this->getControllableEntity()->getWorldPosition() << endl;
+
+
if (!this->isActive() || !this->getControllableEntity())
return;
this->searchTarget();
- this->getControllableEntity()->rotatePitch(0.2);
- /*if(target_)
+ if(target_)
{
this->aimAtTarget();
+ //this->getControllableEntity()->lookAt(this->targetPosition_);
//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-17 14:04:50 UTC (rev 10038)
+++ code/branches/turretFS14/src/modules/objects/controllers/TurretController.h 2014-04-17 14:05:06 UTC (rev 10039)
@@ -43,7 +43,20 @@
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 searchTarget();
+ bool isInRange(Vector3 position);
};
}
Modified: code/branches/turretFS14/src/orxonox/controllers/ArtificialController.cc
===================================================================
--- code/branches/turretFS14/src/orxonox/controllers/ArtificialController.cc 2014-04-17 14:04:50 UTC (rev 10038)
+++ code/branches/turretFS14/src/orxonox/controllers/ArtificialController.cc 2014-04-17 14:05:06 UTC (rev 10039)
@@ -93,7 +93,7 @@
static const float hardcoded_projectile_speed = 1250;
- this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getPosition(), hardcoded_projectile_speed, this->target_->getPosition(), this->target_->getVelocity());
+ this->targetPosition_ = getPredictedPosition(this->getControllableEntity()->getWorldPosition(), hardcoded_projectile_speed, this->target_->getWorldPosition(), this->target_->getVelocity());
this->bHasTargetPosition_ = (this->targetPosition_ != Vector3::ZERO);
Pawn* pawn = orxonox_cast<Pawn*>(this->getControllableEntity());
Modified: code/branches/turretFS14/src/orxonox/controllers/FormationController.cc
===================================================================
--- code/branches/turretFS14/src/orxonox/controllers/FormationController.cc 2014-04-17 14:04:50 UTC (rev 10038)
+++ code/branches/turretFS14/src/orxonox/controllers/FormationController.cc 2014-04-17 14:05:06 UTC (rev 10039)
@@ -276,8 +276,8 @@
// return;
}
- Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
- float distance = (target - this->getControllableEntity()->getPosition()).length();
+ Vector2 coord = get2DViewcoordinates(this->getControllableEntity()->getWorldPosition(), this->getControllableEntity()->getOrientation() * WorldEntity::FRONT, this->getControllableEntity()->getOrientation() * WorldEntity::UP, target);
+ float distance = (target - this->getControllableEntity()->getWorldPosition()).length();
float rotateX = clamp(coord.x * 10, -1.0f, 1.0f);
float rotateY = clamp(coord.y * 10, -1.0f, 1.0f);
Modified: code/branches/turretFS14/src/orxonox/worldentities/WorldEntity.cc
===================================================================
--- code/branches/turretFS14/src/orxonox/worldentities/WorldEntity.cc 2014-04-17 14:04:50 UTC (rev 10038)
+++ code/branches/turretFS14/src/orxonox/worldentities/WorldEntity.cc 2014-04-17 14:05:06 UTC (rev 10039)
@@ -413,6 +413,7 @@
}
else if (this->isDynamic())
{
+ //hacky hack, really shouldn't do that
//orxout(internal_warning) << "Cannot attach a dynamic object to a WorldEntity." << endl;
//return false;
}
More information about the Orxonox-commit
mailing list