[Orxonox-commit 2345] r7060 - in code/branches/presentation3: data/levels/templates src/orxonox/controllers src/orxonox/worldentities
gasserlu at orxonox.net
gasserlu at orxonox.net
Mon May 31 16:44:02 CEST 2010
Author: gasserlu
Date: 2010-05-31 16:44:02 +0200 (Mon, 31 May 2010)
New Revision: 7060
Modified:
code/branches/presentation3/data/levels/templates/pickup_representation_templates.oxt
code/branches/presentation3/src/orxonox/controllers/DroneController.cc
code/branches/presentation3/src/orxonox/worldentities/Drone.cc
code/branches/presentation3/src/orxonox/worldentities/Drone.h
Log:
drone shootingRange implemented
Modified: code/branches/presentation3/data/levels/templates/pickup_representation_templates.oxt
===================================================================
--- code/branches/presentation3/data/levels/templates/pickup_representation_templates.oxt 2010-05-31 14:25:04 UTC (rev 7059)
+++ code/branches/presentation3/data/levels/templates/pickup_representation_templates.oxt 2010-05-31 14:44:02 UTC (rev 7060)
@@ -428,7 +428,7 @@
<!-- Drone Pickup -->
<Template name=droneTemplate>
- <Drone name="meineDrohne" mass= "50" linearDamping = "0.7" angularDamping = "0.99999" maxDistanceToOwner_=150 minDistanceToOwner_=50 primaryThrust_=250 auxilaryThrust_=250 rotationThrust_=50>
+ <Drone name="meineDrohne" mass= "50" linearDamping = "0.7" angularDamping = "0.99999" maxDistanceToOwner_=150 minDistanceToOwner_=75 maxShootingRange_=1000 primaryThrust_=250 auxilaryThrust_=250 rotationThrust_=50>
<attached>
<Model scale="1" mesh="drone.mesh"/>
</attached>
Modified: code/branches/presentation3/src/orxonox/controllers/DroneController.cc
===================================================================
--- code/branches/presentation3/src/orxonox/controllers/DroneController.cc 2010-05-31 14:25:04 UTC (rev 7059)
+++ code/branches/presentation3/src/orxonox/controllers/DroneController.cc 2010-05-31 14:44:02 UTC (rev 7060)
@@ -74,17 +74,18 @@
{
float random;
float maxrand = 100.0f / ACTION_INTERVAL;
+ float distanceToTargetSquared;
- // const Vector3& ownerPosition = getOwner()->getWorldPosition();
- // const Vector3& dronePosition = getDrone()->getWorldPosition();
-
- // const Vector3& locOwnerDir = getDrone()->getOrientation().UnitInverse()*(ownerPosition-dronePosition); //Vector from Drone To Owner out of drones local coordinate system
-
+ if (target_) {
+ const Vector3& locTargetDir = getDrone()->getOrientation().UnitInverse()*((getDrone()->getWorldPosition())-(target_->getWorldPosition())); //Vector from Drone To target out of drones local coordinate system
+ distanceToTargetSquared = locTargetDir.squaredLength();
+ }
+
random = rnd(maxrand);
- if ( random < 30 && (!this->target_))
+ if ( random < 30 || (!this->target_) || distanceToTargetSquared > (this->getDrone()->getMaxShootingRange()*this->getDrone()->getMaxShootingRange()))
this->searchNewTarget();
- if (random < 50 && this->target_)
+ if (random < 50 && this->target_ && distanceToTargetSquared < (this->getDrone()->getMaxShootingRange()*this->getDrone()->getMaxShootingRange()))
{
this->isShooting_ = true;
this->aimAtTarget();
@@ -104,14 +105,13 @@
*/
void DroneController::tick(float dt)
{
- // Drone *myDrone = static_cast<Drone*>(this->getControllableEntity());
float maxDistanceSquared = this->getDrone()->getMaxDistanceToOwner()*this->getDrone()->getMaxDistanceToOwner();
float minDistanceSquared = this->getDrone()->getMinDistanceToOwner()*this->getDrone()->getMinDistanceToOwner();
if ((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() > maxDistanceSquared) {
- this->moveToPosition(this->getOwner()->getWorldPosition());
+ this->moveToPosition(this->getOwner()->getWorldPosition()); //fly towards owner
}
else if((this->getDrone()->getWorldPosition() - this->getOwner()->getWorldPosition()).squaredLength() < minDistanceSquared) {
- this->moveToPosition(-this->getOwner()->getWorldPosition());
+ this->moveToPosition(-this->getOwner()->getWorldPosition()); //fly away from owner
}
else if(!isShooting_) {
float random = rnd(2.0f);
@@ -130,6 +130,10 @@
void DroneController::ownerDied()
{
+// if (this->target_) { //Drone has some kind of Stockholm-Syndrom --> gets attached to Owners Killer
+// this->setOwner(target_);
+// this->searchNewTarget();
+// }
if (this->drone_)
this->drone_->destroy();
else
Modified: code/branches/presentation3/src/orxonox/worldentities/Drone.cc
===================================================================
--- code/branches/presentation3/src/orxonox/worldentities/Drone.cc 2010-05-31 14:25:04 UTC (rev 7059)
+++ code/branches/presentation3/src/orxonox/worldentities/Drone.cc 2010-05-31 14:44:02 UTC (rev 7060)
@@ -78,6 +78,7 @@
XMLPortParam(Drone, "rotationThrust_", setRotationThrust, getRotationThrust, xmlelement, mode);
XMLPortParam(Drone, "maxDistanceToOwner_", setMaxDistanceToOwner, getMaxDistanceToOwner, xmlelement, mode);
XMLPortParam(Drone, "minDistanceToOwner_", setMinDistanceToOwner, getMinDistanceToOwner, xmlelement, mode);
+ XMLPortParam(Drone, "maxShootingRange_", setMaxShootingRange, getMaxShootingRange, xmlelement, mode);
}
Modified: code/branches/presentation3/src/orxonox/worldentities/Drone.h
===================================================================
--- code/branches/presentation3/src/orxonox/worldentities/Drone.h 2010-05-31 14:25:04 UTC (rev 7059)
+++ code/branches/presentation3/src/orxonox/worldentities/Drone.h 2010-05-31 14:44:02 UTC (rev 7060)
@@ -113,6 +113,8 @@
{ this->maxDistanceToOwner_=distance; }
inline void setMinDistanceToOwner( float distance)
{ this->minDistanceToOwner_=distance; }
+ inline void setMaxShootingRange( float distance)
+ { this->maxShootingRange_=distance; }
/**
@@ -129,6 +131,8 @@
{ return this->maxDistanceToOwner_; }
inline float getMinDistanceToOwner()
{ return this->minDistanceToOwner_; }
+ inline float getMaxShootingRange()
+ { return this->maxShootingRange_; }
private:
DroneController *myController_; //!< The controller of the Drone.
@@ -140,6 +144,7 @@
float rotationThrust_; //!< The amount of rotation thrust. Used for rotations only.
float maxDistanceToOwner_; //Maximum Distance to owner
float minDistanceToOwner_; //Minimum Distance to owner
+ float maxShootingRange_;
};
}
More information about the Orxonox-commit
mailing list