[Orxonox-commit 5379] r10042 - in code/branches/turretFS14: data/levels src/modules/objects src/modules/objects/controllers
muemart at orxonox.net
muemart at orxonox.net
Tue Apr 29 11:16:17 CEST 2014
Author: muemart
Date: 2014-04-29 11:16:16 +0200 (Tue, 29 Apr 2014)
New Revision: 10042
Modified:
code/branches/turretFS14/data/levels/turretTest.oxw
code/branches/turretFS14/src/modules/objects/Turret.cc
code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc
code/branches/turretFS14/src/modules/objects/controllers/TurretController.h
Log:
Fix rotation if parent is already rotated. Everything hopefully now works as expected. It's a giant mess right now, so still have to clean it up.
Modified: code/branches/turretFS14/data/levels/turretTest.oxw
===================================================================
--- code/branches/turretFS14/data/levels/turretTest.oxw 2014-04-22 15:32:37 UTC (rev 10041)
+++ code/branches/turretFS14/data/levels/turretTest.oxw 2014-04-29 09:16:16 UTC (rev 10042)
@@ -33,7 +33,7 @@
<SpawnPoint team=0 position="-200,0,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
-<SpaceShip position="-100,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" />
@@ -57,9 +57,17 @@
<Model mesh="sphere.mesh" position="0,0,30" scale=1/>
</attached>
-</SpaceShip>
+</SpaceShip> -->
+<StaticEntity position="100,0,0">
+ <attached>
+ <Model mesh="sphere.mesh" position="20,0,0" scale=1/>
-<SpaceShip position="100,0,0" yaw=0 pitch=0>
+ <Model mesh="sphere.mesh" position="0,25,0" scale=1.5/>
+
+ <Model mesh="sphere.mesh" position="0,0,30" scale=2/>
+ </attached>
+</StaticEntity>
+<SpaceShip position="100,0,0" yaw=0 pitch=90>
<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" />
@@ -72,16 +80,12 @@
<Template link=spaceshipturrettest />
</templates>
<controller>
- <TurretController team=9 />
+ <TurretController team=10 />
</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>
Modified: code/branches/turretFS14/src/modules/objects/Turret.cc
===================================================================
--- code/branches/turretFS14/src/modules/objects/Turret.cc 2014-04-22 15:32:37 UTC (rev 10041)
+++ code/branches/turretFS14/src/modules/objects/Turret.cc 2014-04-29 09:16:16 UTC (rev 10042)
@@ -112,10 +112,12 @@
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_);
- pitch(Degree(localAngularAcceleration_.x()/10000), WorldEntity::World);
- yaw(Degree(localAngularAcceleration_.y()/10000), WorldEntity::World);
- roll(Degree(localAngularAcceleration_.z()/10000), WorldEntity::World);
+ pitch(Degree(localAngularAcceleration_.x()*dt/1000), WorldEntity::World);
+ yaw(Degree(localAngularAcceleration_.y()*dt/1000), WorldEntity::World);
+ roll(Degree(localAngularAcceleration_.z()*dt/1000), WorldEntity::World);
this->localAngularAcceleration_.setValue(0, 0, 0);
}
Modified: code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc
===================================================================
--- code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc 2014-04-22 15:32:37 UTC (rev 10041)
+++ code/branches/turretFS14/src/modules/objects/controllers/TurretController.cc 2014-04-29 09:16:16 UTC (rev 10042)
@@ -46,7 +46,6 @@
this->maxPitch_ = 90;
this->maxYaw_ = 90;
this->gotOrient_ = false;
- orxout() << "Constructor " << this << endl;
}
TurretController::~TurretController()
@@ -94,14 +93,16 @@
}
}
- bool TurretController::isInRange(Vector3 position)
+ 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;
@@ -113,6 +114,7 @@
return false;
}
+ //Check yaw
dirProjected = dir;
dirProjected.y = 0;
startDirProjected = this->startDir_;
@@ -125,56 +127,78 @@
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);
+ }
+
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_);
- 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_;
+ this->gotOrient_ = true;
- //startDir should always be (0,0,-1)
- this->startDir_ = getTransformedVector(this->startOrient_ * WorldEntity::FRONT, this->localX_, this->localY_, this->localZ_);
+ }
- this->gotOrient_ = 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_;
+ }
- //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;
- 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->moveToTargetPosition();
- if(this->isLookingAtTarget(Degree(5).valueRadians()))
- {
- orxout() << 42 << endl;
- }
- }
+ 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;
+ }
+ }
}
}
\ 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-22 15:32:37 UTC (rev 10041)
+++ code/branches/turretFS14/src/modules/objects/controllers/TurretController.h 2014-04-29 09:16:16 UTC (rev 10042)
@@ -55,8 +55,12 @@
Vector3 localYStart_;
Vector3 localX_;
Vector3 localXStart_;
+
+ void aimAtPositionRot(const Vector3 &position);
+ void aimAtTargetRot();
void searchTarget();
- bool isInRange(Vector3 position);
+ bool isInRange(const Vector3 &position);
+ bool isLookingAtTargetNew(float angle) const;
};
}
More information about the Orxonox-commit
mailing list