[Orxonox-commit 7220] r11834 - code/branches/3DPacman_FS18/src/modules/3DPacman
dreherm at orxonox.net
dreherm at orxonox.net
Thu Mar 29 12:15:21 CEST 2018
Author: dreherm
Date: 2018-03-29 12:15:19 +0200 (Thu, 29 Mar 2018)
New Revision: 11834
Modified:
code/branches/3DPacman_FS18/src/modules/3DPacman/PacmanGhost.cc
code/branches/3DPacman_FS18/src/modules/3DPacman/PacmanGhost.h
code/branches/3DPacman_FS18/src/modules/3DPacman/PacmanGhostController.cc
Log:
Update for ghost controller and ghost class
Modified: code/branches/3DPacman_FS18/src/modules/3DPacman/PacmanGhost.cc
===================================================================
--- code/branches/3DPacman_FS18/src/modules/3DPacman/PacmanGhost.cc 2018-03-26 11:09:34 UTC (rev 11833)
+++ code/branches/3DPacman_FS18/src/modules/3DPacman/PacmanGhost.cc 2018-03-29 10:15:19 UTC (rev 11834)
@@ -49,11 +49,11 @@
this->localLinearAcceleration_.setValue(0, 0, 0);
this->localAngularAcceleration_.setValue(0, 0, 0);
- this->primaryThrust_ = 100;
- this->auxiliaryThrust_ = 100;
- this->rotationThrust_ = 10;
this->setCollisionType(CollisionType::Dynamic);
+
+ Vector3 resetposition = new Vector3(0,0,0); //Set Default start position
+
}
/**
@@ -77,10 +77,9 @@
SUPER(PacmanGhost, XMLPort, xmlelement, mode);
XMLPortParam(PacmanGhost, "primaryThrust", setPrimaryThrust, getPrimaryThrust, xmlelement, mode);
- // Make sure you add the variables auxiliaryThrust_ and rotationThrust_ to XMLPort.
- // Variables can be added by the following command
- // XMLPortParam(Classname, "xml-attribute-name (i.e. variablename)", setFunctionName, getFunctionName, xmlelement, mode);
- // Also make sure that you also create the get- and set-functions in AutonomousDrone.h. As you can see, the get- and set-functions for the variable primaryThrust_ has already been specified there, so you can get your inspiration from there.
+ XMLPortParam(PacmanGhost, "auxilliaryThrust", setAuxillaryThrust, getAuxillaryThrust, xmlelement, mode);
+ XMLPortParam(PacmanGhost, "rotationThrust", setRotationThrust, getRotationThrust, xmlelement, mode);
+ XMLPortParam(PacmanGhost, "resetposition", setResetPosition, getResetPosition, xmlelement, mode);
}
/**
Modified: code/branches/3DPacman_FS18/src/modules/3DPacman/PacmanGhost.h
===================================================================
--- code/branches/3DPacman_FS18/src/modules/3DPacman/PacmanGhost.h 2018-03-26 11:09:34 UTC (rev 11833)
+++ code/branches/3DPacman_FS18/src/modules/3DPacman/PacmanGhost.h 2018-03-29 10:15:19 UTC (rev 11834)
@@ -54,7 +54,8 @@
virtual void rotateYaw(const Vector2& value);
virtual void rotatePitch(const Vector2& value);
virtual void rotateRoll(const Vector2& value);
-
+
+ virtual void resetGhost();
/**
@brief Moves the Drone in the Front/Back-direction by the specifed amount.
@param value The amount by which the drone is to be moved.
@@ -99,9 +100,14 @@
*/
inline void setPrimaryThrust( float thrust )
{ this->primaryThrust_ = thrust; }
- //TODO: Place your set-functions here.
- // Hint: auxiliary thrust, rotation thrust.
-
+ inline void setAuxillaryThrust( float thrust )
+ { this->auxillaryThrust_ = thrust; }
+ inline void setRotationThrust( float thrust )
+ { this->rotationThrust_ = thrust; }
+
+ inline void setResetPosition(Vector3 rpos)
+ { this->resetposition = rpos; }
+
/**
@brief Gets the primary thrust to the input amount.
@return The amount of thrust.
@@ -108,8 +114,16 @@
*/
inline float getPrimaryThrust()
{ return this->primaryThrust_; }
- //TODO: Place your get-functions here.
+ inline float getAuxillaryThrust()
+ { return this->auxillaryThrust_; }
+ inline float getRotationThrust()
+ { return this->rotationThrust_; }
+
+ inline Vector3 getResetPosition()
+ { return this->resetposition; }
+
+
private:
PacmanGhostController *myController_; //!< The controller of the AutonomousDrone.
@@ -118,6 +132,7 @@
float primaryThrust_; //!< The amount of primary thrust. This is just used, when moving forward.
float auxiliaryThrust_; //!< The amount of auxiliary thrust. Used for all other movements (except for rotations).
float rotationThrust_; //!< The amount of rotation thrust. Used for rotations only.s
+ Vector3 resetposition; //Start position for Ghost
};
Modified: code/branches/3DPacman_FS18/src/modules/3DPacman/PacmanGhostController.cc
===================================================================
--- code/branches/3DPacman_FS18/src/modules/3DPacman/PacmanGhostController.cc 2018-03-26 11:09:34 UTC (rev 11833)
+++ code/branches/3DPacman_FS18/src/modules/3DPacman/PacmanGhostController.cc 2018-03-29 10:15:19 UTC (rev 11834)
@@ -42,15 +42,22 @@
@param context
The context of this object.
*/
- PacmanGhostRed::PacmanGhostController(Context* context) : Controller(context)
+ PacmanGhostController::PacmanGhostController(Context* context) : Controller(context)
{
RegisterObject(PacmanGhostController);
+
+ PacmanGhost* myGhost = nullptr;
+ this->actuelposition = myGhost.getPosition();
+
bool ismoving = false;
- float reltarget_x;
- float reltarget_z;
- Vector3& actuelposition;
+ this->target_x = actuelposition.x;
+ this->target_z = actuelposition.z;
}
+ void PacmanGhostController::setGhost(PacmanGhost ghost){
+ this->myGhost = ghost;
+ }
+
/**
@brief
Destructor.
@@ -60,6 +67,8 @@
}
+
+ static Vector3[] possibleposition = [new Vector3(0,10,245), new Vector3(215,0,240)];
/**
@brief
The controlling happens here. This method defines what the controller has to do each tick.
@@ -76,51 +85,38 @@
ObjectList<PacmanGhost>::iterator it = objectList.begin();
PacmanGhost* myDrone = *it;
- if (myGhost != nullptr)
+ if (this->myGhost != nullptr)
{
- actuelposition = myGhost.getPosition();
+ this->actuelposition = this->myGhost.getPosition();
- if(actuelposition.x = reltarget_x && actuelposition.z = reltarget_z){
- ismoving = false;
+ if(((this->actuelposition.x - this->target_x)<0.1) && ((this->actuelposition.z - this->target_z)<0.1)){
+ this->ismoving = false;
}
-
-
- if(ismoving){
- moveRightLeft();
- moveFrontBack();
+ if(this->ismoving){
+ if(!((this->actuelposition.z-target_z)<0.1))
+ moveFrontBack(sgn(this->actuelposition.z-this->target_z)*dt*100);
+ if(!((this->actuelposition.x-target_x)<0.1))
+ moveRightLeft(sgn(this->actuelposition.x-this->target_x)*dt*100); //Assume dt is quite small
+ }
+
+ else{ //Check on which position ghost is
+ if(((this->actuelposition.x - possibleposition[0].x)<0.1) && ((this->actuelposition.z - possibleposition[1].z)<0.1)){
+ this->target_x = possibleposition[1].x;
+ this->target_z = possibleposition[1].z;
+ this->ismoving = true;
}
-
+ else if(((actuelposition.x - possibleposition[0].x)<0.1) && ((actuelposition.z - possibleposition[1].z)<0.1)){
+ this->target_x = 0
+ this->target_z =
+ this->ismoving = true;
+ }
else{
+ }
+ } //End of Position table
- //hashtable
-
- int random = rand();
-
- switch(actuelposition) {
- case 1: if(random % 4 == 0){
- reltarget_x = 250;
- reltarget_z = 0;
- }
- else if(random % 4 == 1){
- reltarget_x = 0;
- reltarget_z = 250;
- }
- else if(random % 4 == 2){
- reltarget_x = 0;
- reltarget_z = -250;
- }
- else if(random % 4 == 3){
- reltarget_x = -250;
- reltarget_z = 0;
- }
- moving = true;
- case 2:
- }
- }
-
-
}
}
+
}
More information about the Orxonox-commit
mailing list