[Orxonox-commit 7753] r12346 - code/branches/OrxoBlox_FS19/src/modules/OrxoBlox

pomselj at orxonox.net pomselj at orxonox.net
Thu May 9 11:36:28 CEST 2019


Author: pomselj
Date: 2019-05-09 11:36:28 +0200 (Thu, 09 May 2019)
New Revision: 12346

Modified:
   code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBlox.cc
   code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBlox.h
   code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.cc
   code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.h
   code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxWall.cc
   code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxWall.h
Log:
Worked on Collision, doesn't work yet, compiles tho

Modified: code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBlox.cc
===================================================================
--- code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBlox.cc	2019-05-09 09:18:16 UTC (rev 12345)
+++ code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBlox.cc	2019-05-09 09:36:28 UTC (rev 12346)
@@ -146,7 +146,7 @@
             level_=1;
 
             // Create the first Wall.
-            this->LevelUp();
+            this->createWall();
 
             //Create Ship
             //this->ship_ = new OrxoBloxShip(this->center_->getContext());
@@ -212,11 +212,12 @@
         level_++;
         this->createWall();
         this->activeWalls_.push_back(this->futureWall_);
+        for (int i = 0; i < this->futureWall_->getNumberOfStones(); i++)
+            this->stones_.push_back(this->futureWall_->getStone(i));
         //new location of ship
         //new amount of balls
         //create balls
         //insert new wall
-
     }
 
     void OrxoBlox::createWall(void){
@@ -242,6 +243,23 @@
             this->ball_->setSpeed(this->center_->getBallSpeed());
     }
 
+    OrxoBloxStones* OrxoBlox::CheckForCollision(OrxoBloxBall* Ball) {
+
+        orxout() << "Checking for Collision" << endl;
+        Vector3 BallPosition = Ball->getPosition();
+        for(OrxoBloxStones* someStone : this->stones_)
+        {
+            orxout() << "Checking a stone" << endl;
+            const Vector3& StonePosition = someStone->getPosition(); //!< Saves the position of the currentStone
+            int size = someStone->getSize();
+            if((BallPosition.x >= StonePosition.x - size && BallPosition.x <= StonePosition.x + size) || 
+                (BallPosition.z >= StonePosition.z - size && BallPosition.z <= StonePosition.z + size)) {
+                orxout() << "FOUND ONE" << endl;
+                return someStone;
+            }
+        }
+        orxout() << "Found nothing...." << endl;
+        return nullptr;
+    }
     
-    
 }

Modified: code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBlox.h
===================================================================
--- code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBlox.h	2019-05-09 09:18:16 UTC (rev 12345)
+++ code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBlox.h	2019-05-09 09:36:28 UTC (rev 12346)
@@ -86,6 +86,7 @@
 
             OrxoBloxCenterpoint* getCenterpoint(void)
                 { return this->center_; }
+            OrxoBloxStones* CheckForCollision(OrxoBloxBall* Ball);
 
         protected:
         private:

Modified: code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.cc
===================================================================
--- code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.cc	2019-05-09 09:18:16 UTC (rev 12345)
+++ code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.cc	2019-05-09 09:36:28 UTC (rev 12346)
@@ -54,7 +54,7 @@
         Constructor. Registers and initializes the object.
     */
     OrxoBloxBall::OrxoBloxBall(Context* context)
-        : MovableEntity(context)
+        : Pawn(context)
     {
         RegisterObject(OrxoBloxBall);
 
@@ -62,6 +62,7 @@
         this->accelerationFactor_ = 1.0f;
         this->bDeleteBats_ = false;
         this->relMercyOffset_ = 0.05f;
+        this->orxoblox_ = this->getOrxoBlox();
 
         this->registerVariables();
 
@@ -205,6 +206,9 @@
             this->setVelocity(velocity);
         if (position != this->getPosition())
             this->setPosition(position);
+        this->Collides((this->orxoblox_->CheckForCollision(this)));
+
+ 
     }
 
     /**
@@ -286,11 +290,11 @@
     }
 
 
-    void OrxoBloxBall::Bounce(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) {
+    void OrxoBloxBall::Bounce(OrxoBloxStones* otherObject) {
 
         Vector3 velocity = this->getVelocity();
-        Vector3 myPosition = otherObject->getPosition();
-        btVector3 positionOtherObject = contactPoint.getPositionWorldOnA();
+        Vector3 positionOtherObject = otherObject->getPosition();
+        Vector3 myPosition = this->getPosition();
         orxout() << "About to Bounce >D" << endl;
         //if (positionOtherObject.y < 0) {
             //this.destroy()
@@ -297,8 +301,8 @@
         //}S
         //else {
         
-            int distance_X = positionOtherObject.getX() - myPosition.x;
-            int distance_Z = positionOtherObject.getZ() - myPosition.z;
+            int distance_X = myPosition.x - positionOtherObject.x;
+            int distance_Z = myPosition.z - positionOtherObject.z;
 
             if (distance_X < 0)
                 distance_X = -distance_X;
@@ -324,17 +328,29 @@
                 orxout() << "both" << endl;
             }
             this->setVelocity(velocity);
-        //}
     }
 
 
-    bool OrxoBloxBall::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
+    void OrxoBloxBall::Collides(OrxoBloxStones* otherObject)
     {
+
+        if(otherObject == nullptr)
+            return;
+
         orxout() << "About to Bounce >D" << endl;
-        bool result = MovableEntity::collidesAgainst(otherObject, ownCollisionShape, contactPoint);
-        Bounce(otherObject, ownCollisionShape, contactPoint);
-        return result;
+        Bounce(otherObject);
     }
 
+    OrxoBlox* OrxoBloxBall::getOrxoBlox()
+    {
+        if (this->getGametype() != nullptr && this->getGametype()->isA(Class(OrxoBlox)))
+        {
+            OrxoBlox* orxobloxGametype = orxonox_cast<OrxoBlox*>(this->getGametype());
+            return orxobloxGametype;
+        }
+        else orxout()<<"There is no Gametype for OrxoBlox! ask Anna"<< endl;
+        return nullptr;
+    }
 
+
 }

Modified: code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.h
===================================================================
--- code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.h	2019-05-09 09:18:16 UTC (rev 12345)
+++ code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.h	2019-05-09 09:36:28 UTC (rev 12346)
@@ -39,7 +39,7 @@
 
 #include "util/Math.h"
 
-#include "worldentities/MovableEntity.h"
+#include "worldentities/pawns/Pawn.h"
 #include <bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h>
 
 
@@ -57,7 +57,7 @@
 
     @ingroup OrxoBlox
     */
-    class _OrxoBloxExport OrxoBloxBall : public MovableEntity
+    class _OrxoBloxExport OrxoBloxBall : public Pawn
     {
         public:
             OrxoBloxBall(Context* context);
@@ -122,9 +122,8 @@
                 { return this->batlength_; }
 
 
-            void Bounce(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint);
-            
-            virtual bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) override;
+            void Bounce(OrxoBloxStones* otherObject);
+            void Collides(OrxoBloxStones* otherObject);
 
             static const float MAX_REL_Z_VELOCITY;
 
@@ -138,6 +137,7 @@
         private:
             void registerVariables();
 
+            OrxoBlox* getOrxoBlox();
             float fieldWidth_; //!< The width of the playing field.
             float fieldHeight_; //!< The height of the playing field.
             float speed_; //!< The speed (in x-direction) of the ball.
@@ -149,6 +149,7 @@
             WorldSound* defScoreSound_;
             WorldSound* defBatSound_;
             WorldSound* defBoundarySound_;
+            OrxoBlox* orxoblox_;
     };
 }
 

Modified: code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxWall.cc
===================================================================
--- code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxWall.cc	2019-05-09 09:18:16 UTC (rev 12345)
+++ code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxWall.cc	2019-05-09 09:36:28 UTC (rev 12346)
@@ -88,4 +88,8 @@
         else orxout()<<"There is no Gametype for OrxoBlox! ask Anna"<< endl;
         return nullptr;
     }
+
+    int OrxoBloxWall::getNumberOfStones() {
+        return num_Stones_;
+    }
 }
\ No newline at end of file

Modified: code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxWall.h
===================================================================
--- code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxWall.h	2019-05-09 09:18:16 UTC (rev 12345)
+++ code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxWall.h	2019-05-09 09:36:28 UTC (rev 12346)
@@ -41,6 +41,7 @@
 
             void setGame(OrxoBlox* orxoblox)
                 { assert(orxoblox); orxoblox_ = orxoblox; }
+            int getNumberOfStones();
         private:
             void createWall(void);
             OrxoBlox* getOrxoBlox();



More information about the Orxonox-commit mailing list