[Orxonox-commit 7717] r12310 - in code/branches/OrxoBlox_FS19: data/levels src/modules/OrxoBlox src/modules/weapons/projectiles

pomselj at orxonox.net pomselj at orxonox.net
Thu Apr 18 16:04:34 CEST 2019


Author: pomselj
Date: 2019-04-18 16:04:33 +0200 (Thu, 18 Apr 2019)
New Revision: 12310

Modified:
   code/branches/OrxoBlox_FS19/data/levels/orxoblox.oxw
   code/branches/OrxoBlox_FS19/data/levels/towerDefense.oxw
   code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBlox.cc
   code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.cc
   code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.h
   code/branches/OrxoBlox_FS19/src/modules/weapons/projectiles/BallProjectile.cc
   code/branches/OrxoBlox_FS19/src/modules/weapons/projectiles/BallProjectile.h
Log:
oxw file cleaned up

Modified: code/branches/OrxoBlox_FS19/data/levels/orxoblox.oxw
===================================================================
--- code/branches/OrxoBlox_FS19/data/levels/orxoblox.oxw	2019-04-18 14:02:06 UTC (rev 12309)
+++ code/branches/OrxoBlox_FS19/data/levels/orxoblox.oxw	2019-04-18 14:04:33 UTC (rev 12310)
@@ -23,15 +23,6 @@
   </OrxoBloxBat>
 </Template>
 
-<Template name=OrxoBloxbat>
-  <OrxoBloxBat camerapositiontemplate=OrxoBloxbatcameras>
-    <attached>
-      <Model position="60,0,-50" mesh="cube.mesh" scale3D="2,2,14" />
-      <!--Model roll=180 mesh="OrxoBloxbat.mesh" scale=0.045 /-->
-    </attached>
-  </OrxoBloxBat>
-</Template>
-
 <Template name=OrxoBloxball>
   <OrxoBloxBall 
    defScoreSound = "sounds/PlayerWinScore_cut.ogg"
@@ -52,40 +43,7 @@
 
 
 
-<Template name=OrxoBloxStonescameras defaults=0>
-  <OrxoBloxStones>
-    <camerapositions>
-      <CameraPosition position="55,75,200" absolute=true />
-    </camerapositions>
-  </OrxoBloxStones>
-</Template>
 
-<Template name=OrxoBloxstone>
-  <OrxoBloxStones camerapositiontemplate=OrxoBloxStonescameras >
-    <attached>
-      <Model position="0,0,0" mesh="CuboidBody.mesh" scale=4.5 />
-      <Model position="0,0,0" mesh="cube_orange.mesh" scale=4.3 />
-    </attached>
-  </OrxoBloxStones>
-</Template>
-
-<Template name=OrxoBloxWallcameras defaults=0>
-  <OrxoBloxWall>
-    <camerapositions>
-      <CameraPosition position="55,75,200" absolute=true />
-      <!--CameraPosition position="0,50,160" drag=true mouselook=true />
-      <CameraPosition position="0,50,0" pitch=-90 drag=true mouselook=true /-->
-    </camerapositions>
-  </OrxoBloxWall>
-</Template>
-
-<Template name=OrxoBloxwall>
-  <OrxoBloxWall camerapositiontemplate=OrxoBloxWallcameras>
-  </OrxoBloxWall>
-</Template>
-
-
-
 <Level
   plugins = "OrxoBlox"
  gametype = "OrxoBlox"
@@ -103,177 +61,25 @@
    ambientlight = "0.5, 0.5, 0.5"
    skybox       = "Orxonox/skyBoxBasic"
   >
-    <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
+    <!-- <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0"/> -->
+    <Light type=directional position="-100, 10000, -700" lookat="0.2, -1, 0" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
+    <SpawnPoint team=0 position="0,0,0" lookat="0,0,0" spawnclass= Asteroids2DShip />
 
-    <SpawnPoint position="991.729, -110.11, 435.404" orientation="0.534038, 0.563456, 0.212168, 0.593553" />
+    <!--<Model mesh="axes.mesh" scale=10 position="0,0,0" /> -->
 
+
     <MovableEntity rotationrate=5 rotationaxis="0,0,1">
       <attached>
-        <OrxoBloxCenterpoint name=OrxoBloxcenter dimension="120,100" balltemplate=OrxoBloxball battemplate=OrxoBloxbat ballspeed=200 ballaccfactor=1.0 batspeed=130 batlength=0.25 StoneTemplate=OrxoBloxstone WallTemplate=OrxoBloxwall>
+        <OrxoBloxCenterpoint name=OrxoBloxcenter dimension="120,100" balltemplate=OrxoBloxball ballspeed=200 ballaccfactor=1.0>
           <attached>
             <!-- Balken die das Spielfeld begrenzen. -->
             <Model position="0,0,-50" mesh="cube.mesh" scale3D="60,1,1" />
             <Model position="60,0,0" mesh="cube.mesh" scale3D="1,1,50"/>
             <Model position="-60,0,0" mesh="cube.mesh" scale3D="1,1,50"/>
-
-            <ParticleSpawner name=scoreeffect_right position="120,0, 45" source="Orxonox/sparks2" lifetime=0.1 autostart=0 />
-            <ParticleSpawner name=scoreeffect_right position="120,0, 30" source="Orxonox/BigExplosion1part2" lifetime=3.0 autostart=0 />
-            <ParticleSpawner name=scoreeffect_right position="120,0, 15" source="Orxonox/sparks2" lifetime=0.1 autostart=0 />
-            <ParticleSpawner name=scoreeffect_right position="120,0,  0" source="Orxonox/BigExplosion1part2" lifetime=0.1 autostart=0 />
-            <ParticleSpawner name=scoreeffect_right position="120,0,-15" source="Orxonox/sparks2" lifetime=0.1 autostart=0 />
-            <ParticleSpawner name=scoreeffect_right position="120,0,-30" source="Orxonox/BigExplosion1part2" lifetime=3.0 autostart=0 />
-            <ParticleSpawner name=scoreeffect_right position="120,0,-45" source="Orxonox/sparks2" lifetime=0.1 autostart=0 />
-
-            <ParticleSpawner name=scoreeffect_left position="-120,0, 45" source="Orxonox/sparks2" lifetime=0.1 autostart=0 />
-            <ParticleSpawner name=scoreeffect_left position="-120,0, 30" source="Orxonox/BigExplosion1part2" lifetime=3.0 autostart=0 />
-            <ParticleSpawner name=scoreeffect_left position="-120,0, 15" source="Orxonox/sparks2" lifetime=0.1 autostart=0 />
-            <ParticleSpawner name=scoreeffect_left position="-120,0,  0" source="Orxonox/BigExplosion1part2" lifetime=0.1 autostart=0 />
-            <ParticleSpawner name=scoreeffect_left position="-120,0,-15" source="Orxonox/sparks2" lifetime=0.1 autostart=0 />
-            <ParticleSpawner name=scoreeffect_left position="-120,0,-30" source="Orxonox/BigExplosion1part2" lifetime=3.0 autostart=0 />
-            <ParticleSpawner name=scoreeffect_left position="-120,0,-45" source="Orxonox/sparks2" lifetime=0.1 autostart=0 />
-
-<!-- TODO: Create a OrxoBlox Score Sound and include it here.
-This WorldSound works, but doesn't make sense, since it is played together with ambient/moodDependedDirectory/Ganymede.ogg -->
-            <!--WorldSound name="scoreSound" position="0,0,0" source="sounds/OrxoBloxScore_cut.ogg" >
-              <events>
-                <play>
-                  <EventListener event=OrxoBloxcenter />
-                </play>
-              </events>
-            </WorldSound-->
-
-            <?lua
-              for i = 1, 15, 1 do
-            ?>
-              <ParticleSpawner name=scoreeffect_center position="<?lua print(math.random() * 200 - 100) ?>,0,<?lua print(math.random() * 120 - 60) ?>" source="Orxonox/sparks2" lifetime=0.02 autostart=0 startdelay=<?lua print(math.random() * 0.7) ?> />
-            <?lua end ?>
-
           </attached>
         </OrxoBloxCenterpoint>
       </attached>
-    </MovableEntity>
-
-    <EventDispatcher>
-      <targets>
-        <EventTarget target=scoreeffect_right />
-        <EventTarget target=scoreeffect_center />
-      </targets>
-      <events>
-        <spawn>
-          <EventFilter>
-            <names>
-              <EventName name=right />
-            </names>
-            <EventListener event=OrxoBloxcenter />
-          </EventFilter>
-        </spawn>
-      </events>
-    </EventDispatcher>
-    <EventDispatcher>
-      <targets>
-        <EventTarget target=scoreeffect_left />
-        <EventTarget target=scoreeffect_center />
-      </targets>
-      <events>
-        <spawn>
-          <EventFilter>
-            <names>
-              <EventName name=left />
-            </names>
-            <EventListener event=OrxoBloxcenter />
-          </EventFilter>
-        </spawn>
-      </events>
-    </EventDispatcher>
-
-    <?lua
-      dofile("includes/CuboidSpaceStation.lua")
-    ?>
-
-    <StaticEntity pitch=15>
-      <attached>
-        <MovableEntity rotationrate="-4.15786" rotationaxis="0,0,1">
-          <attached>
-            <StaticEntity position="-2500,0,0" yaw=90 pitch=90>
-              <attached>
-                <?lua
-                  createSpaceStationPar(0,2,1,2,1,4,1,50)
-                ?>
-              </attached>
-            </StaticEntity>
-          </attached>
-        </MovableEntity>
-      </attached>
-    </StaticEntity>
-
-    <StaticEntity position="0,1200,-200" yaw=50 pitch=60 roll=45>
-      <attached>
-        <Model scale=10 mesh="Carrier.mesh" />
-        <Model position="0,30,20" scale=10 mesh="pirate.mesh" roll="180" />
-        <Model position="-80,-30,20" scale=10 mesh="pirate.mesh" roll="180" />
-      </attached>
-    </StaticEntity>
-
-    <StaticEntity pitch=70>
-      <attached>
-        <MovableEntity rotationaxis="0,0,1" rotationrate=8.5974>
-          <attached>
-            <StaticEntity yaw=-90 pitch=0 roll=90 position="800,0,0">
-              <attached>
-                <Model position="0,0,0" scale=10 mesh="satellite.mesh" />
-                <MovableEntity position="-4,0,20" velocity="0,0,0" rotationaxis="0,0,1" rotationrate=50>
-                  <attached>
-                    <Model position="0,0,0" scale=10 mesh="satellitedish.mesh"/>
-                  </attached>
-                </MovableEntity>
-                <ParticleEmitter pitch=-135 roll=30 position="-14, 3.5,-2.5" source="Orxonox/thruster3" lifetime=2.0 loop=1 startdelay=3.0 />
-                <ParticleEmitter pitch=135 roll=30 position="-14, 3.5,-9" source="Orxonox/thruster3" lifetime=2.0 loop=1 startdelay=3.0 />
-                <ParticleEmitter pitch=-45 roll=30 position="-14,-3.5,-2.5" source="Orxonox/thruster3" lifetime=2.0 loop=1 startdelay=3.0 />
-                <ParticleEmitter pitch=45 roll=30 position="-14,-3.5,-9" source="Orxonox/thruster3" lifetime=2.0 loop=1 startdelay=3.0 />
-              </attached>
-            </StaticEntity>
-          </attached>
-        </MovableEntity>
-      </attached>
-    </StaticEntity>
-
-    <?lua
-      for i = 1, 10, 1 do
-    ?>
-      <MovableEntity position="<?lua print(math.random() * 600 - 300)?>, <?lua print(math.random() * 600 - 300) ?>, <?lua print(math.random() * 100 + 300) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
-        <attached>
-          <Model scale="<?lua print(math.random() * 10 + 5) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
-        </attached>
-      </MovableEntity>
-      <MovableEntity position="<?lua print(math.random() * 600 - 300)?>, <?lua print(math.random() * 600 - 300) ?>, <?lua print(math.random() * -100 - 300) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
-        <attached>
-          <Model scale="<?lua print(math.random() * 10 + 5) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
-        </attached>
-      </MovableEntity>
-
-      <MovableEntity position="<?lua print(math.random() * 600 - 300)?>, <?lua print(math.random() * 100 + 300) ?>, <?lua print(math.random() * 600 - 300) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
-        <attached>
-          <Model scale="<?lua print(math.random() * 10 + 5) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
-        </attached>
-      </MovableEntity>
-      <MovableEntity position="<?lua print(math.random() * 600 - 300)?>, <?lua print(math.random() * -100 - 300) ?>, <?lua print(math.random() * 600 - 300) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
-        <attached>
-          <Model scale="<?lua print(math.random() * 10 + 5) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
-        </attached>
-      </MovableEntity>
-
-      <MovableEntity position="<?lua print(math.random() * 100 + 300)?>, <?lua print(math.random() * 600 - 300) ?>, <?lua print(math.random() * 600 - 300) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
-        <attached>
-          <Model scale="<?lua print(math.random() * 10 + 5) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
-        </attached>
-      </MovableEntity>
-      <MovableEntity position="<?lua print(math.random() * -100 - 300)?>, <?lua print(math.random() * 600 - 300) ?>, <?lua print(math.random() * 600 - 300) ?>" rotationaxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationrate="<?lua print(math.random() * 30 + 5) ?>">
-        <attached>
-          <Model scale="<?lua print(math.random() * 10 + 5) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" shadow=false />
-        </attached>
-      </MovableEntity>
-    <?lua end ?>
-    
+    </MovableEntity>   
   </Scene>
 </Level>
 

Modified: code/branches/OrxoBlox_FS19/data/levels/towerDefense.oxw
===================================================================
--- code/branches/OrxoBlox_FS19/data/levels/towerDefense.oxw	2019-04-18 14:02:06 UTC (rev 12309)
+++ code/branches/OrxoBlox_FS19/data/levels/towerDefense.oxw	2019-04-18 14:04:33 UTC (rev 12310)
@@ -105,7 +105,7 @@
           <DefaultWeaponmodeLink firemode=0 weaponmode=0 />
         </links>
         <Weapon>          
-          <BallGun mode=0 munitionpershot=0 muzzleoffset="0,0,0" damage=200 shielddamage=4 />
+          <BallGun mode=0 munitionpershot=0 muzzleoffset="0,0,0" damage=0 shielddamage=4 />
         </Weapon>
       </WeaponPack>
     </weaponpacks>

Modified: code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBlox.cc
===================================================================
--- code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBlox.cc	2019-04-18 14:02:06 UTC (rev 12309)
+++ code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBlox.cc	2019-04-18 14:04:33 UTC (rev 12310)
@@ -48,7 +48,6 @@
 
 #include "OrxoBloxCenterpoint.h"
 #include "OrxoBloxBall.h"
-// #include "OrxoBloxBat.h"//Remove??
 #include "OrxoBloxBot.h"//Remove??
 #include "OrxoBloxStones.h"
 #include "OrxoBloxWall.h"

Modified: code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.cc
===================================================================
--- code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.cc	2019-04-18 14:02:06 UTC (rev 12309)
+++ code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.cc	2019-04-18 14:04:33 UTC (rev 12310)
@@ -32,6 +32,7 @@
 */
 
 #include "OrxoBloxBall.h"
+#include <bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h>
 
 #include "core/CoreIncludes.h"
 #include "core/GameMode.h"
@@ -259,4 +260,57 @@
             assert(0);
         return BLANKSTRING;
     }
+
+
+    void OrxoBloxBall::Bounce(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) {
+
+        Vector3 velocity = this->getVelocity();
+        Vector3 myPosition = otherObject->getPosition();
+        btVector3 positionOtherObject = contactPoint.getPositionWorldOnA();
+        orxout() << "About to Bounce >D" << endl;
+        //if (positionOtherObject.y < 0) {
+            //this.destroy()
+        //}S
+        //else {
+        
+            int distance_X = positionOtherObject.getX() - myPosition.x;
+            int distance_Z = positionOtherObject.getZ() - myPosition.z;
+
+            if (distance_X < 0)
+                distance_X = -distance_X;
+    
+
+            if (distance_Z < 0)
+                distance_Z = -distance_Z;
+
+            orxout() << distance_X << endl;
+            orxout() << distance_Z << endl;
+
+            if (distance_X < distance_Z) {
+                velocity.z = -velocity.z;
+                orxout() << "z" << endl;
+            }
+            if (distance_Z < distance_X) {
+                velocity.x = -velocity.x;
+                orxout() << "x" << endl;
+            }
+            else {
+                velocity.x = -velocity.x;
+                velocity.z = -velocity.z;
+                orxout() << "both" << endl;
+            }
+            this->setVelocity(velocity);
+        //}
+    }
+
+
+    bool OrxoBloxBall::collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint)
+    {
+        orxout() << "About to Bounce >D" << endl;
+        bool result = MovableEntity::collidesAgainst(otherObject, ownCollisionShape, contactPoint);
+        Bounce(otherObject, ownCollisionShape, contactPoint);
+        return result;
+    }
+
+
 }

Modified: code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.h
===================================================================
--- code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.h	2019-04-18 14:02:06 UTC (rev 12309)
+++ code/branches/OrxoBlox_FS19/src/modules/OrxoBlox/OrxoBloxBall.h	2019-04-18 14:04:33 UTC (rev 12310)
@@ -40,6 +40,7 @@
 #include "util/Math.h"
 
 #include "worldentities/MovableEntity.h"
+#include <bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h>
 
 
 namespace orxonox
@@ -131,6 +132,8 @@
             const std::string& getDefBatSound();
             void setDefBoundarySound(const std::string& engineSound);
             const std::string& getDefBoundarySound();
+            void Bounce(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint);
+            virtual bool collidesAgainst(WorldEntity* otherObject, const btCollisionShape* ownCollisionShape, btManifoldPoint& contactPoint) override;
 
         private:
             void registerVariables();

Modified: code/branches/OrxoBlox_FS19/src/modules/weapons/projectiles/BallProjectile.cc
===================================================================
--- code/branches/OrxoBlox_FS19/src/modules/weapons/projectiles/BallProjectile.cc	2019-04-18 14:02:06 UTC (rev 12309)
+++ code/branches/OrxoBlox_FS19/src/modules/weapons/projectiles/BallProjectile.cc	2019-04-18 14:04:33 UTC (rev 12310)
@@ -39,6 +39,8 @@
 #include "Scene.h"
 #include "core/command/Executor.h"
 #include "util/Convert.h"
+#include <bullet/BulletCollision/NarrowPhaseCollision/btManifoldPoint.h>
+#include <bullet/LinearMath/btVector3.h>
 
 namespace orxonox
 {
@@ -57,7 +59,10 @@
 
     void BallProjectile::registerVariables()
     {
+        registerVariable( this->fieldWidth_ );
+        registerVariable( this->fieldHeight_ );
         registerVariable(this->materialBase_);
+        registerVariable( this->speed_ );
     }
 
     /**
@@ -86,11 +91,13 @@
         this->setMaterial(this->materialBase_);
     }
 
+
+
     void BallProjectile::Bounce(WorldEntity* otherObject, btManifoldPoint& contactPoint, const btCollisionShape* cs) {
 
         Vector3 velocity = this->getVelocity();
-        Vector3 positionOtherObject = otherObject->getPosition();
-        Vector3 contactPosition = this->getPosition();
+        Vector3 myPosition = otherObject->getPosition();
+        btVector3 positionOtherObject = contactPoint.getPositionWorldOnA();
         orxout() << "About to Bounce >D" << endl;
         //if (positionOtherObject.y < 0) {
             //this.destroy()
@@ -97,42 +104,39 @@
         //}S
         //else {
         
-            int distance_X = positionOtherObject.x - contactPosition.x;
-            int distance_Y = positionOtherObject.y - contactPosition.y;
+            int distance_X = positionOtherObject.getX() - myPosition.x;
+            int distance_Z = positionOtherObject.getZ() - myPosition.z;
 
             if (distance_X < 0)
-                distance_Y = -distance_Y;
+                distance_X = -distance_X;
     
 
-            if (distance_Y < 0)
-                distance_X = -distance_X;
+            if (distance_Z < 0)
+                distance_Z = -distance_Z;
 
-            if (distance_X < distance_Y)
-                velocity.y = -velocity.y;
-            if (distance_Y < distance_X)
+            orxout() << distance_X << endl;
+            orxout() << distance_Z << endl;
+
+            if (distance_X < distance_Z) {
+                velocity.z = -velocity.z;
+                orxout() << "z" << endl;
+            }
+            if (distance_Z < distance_X) {
                 velocity.x = -velocity.x;
+                orxout() << "x" << endl;
+            }
             else {
                 velocity.x = -velocity.x;
-                velocity.y = -velocity.y;
+                velocity.z = -velocity.z;
+                orxout() << "both" << endl;
             }
+            this->setVelocity(velocity);
         //}
     }
 
-/**
-    @brief
-        The function called when a projectile hits another thing.
-        Calls the hit-function, starts the shield recharge countdown, displays visual hit effects defined in Pawn.
-        Needs to be called in the collidesAgainst() function by every Class directly inheriting from BasicProjectile.
-    @param otherObject
-        A pointer to the object the Projectile has collided against.
-    @param contactPoint
-        A btManifoldPoint indicating the point of contact/impact.
-    @param cs
-        The btCollisionShape of the other object
-    @return
-        Returns true if the collision resulted in a successful hit.
-    @see Pawn.h
-    */
+
+
+
     
     bool BallProjectile::processCollision(WorldEntity* otherObject, btManifoldPoint& contactPoint, const btCollisionShape* cs)
     {
@@ -144,4 +148,88 @@
 
         return result;
     }
+
+
+
+
+
+
+    void BallProjectile::tick(float dt)
+    {
+        SUPER(BallProjectile, tick, dt);
+
+        // Get the current position, velocity and acceleration of the ball.
+        Vector3 position = this->getPosition();
+        Vector3 velocity = this->getVelocity();
+        Vector3 acceleration = this->getAcceleration();
+
+        // If the ball has gone over the top or bottom boundary of the playing field (i.e. the ball has hit the top or bottom delimiters).
+        if (position.z > this->fieldHeight_ / 2 || position.z < -this->fieldHeight_ / 2)
+        {
+            // Its velocity in z-direction is inverted (i.e. it bounces off).
+            velocity.z = -velocity.z;
+            // And its position is set as to not overstep the boundary it has just crossed.
+            if (position.z > this->fieldHeight_ / 2)
+                position.z = this->fieldHeight_ / 2;
+            if (position.z < -this->fieldHeight_ / 2)
+                position.z = -this->fieldHeight_ / 2;
+
+            this->fireEvent();
+        }
+        
+        //Ball hits the right or left wall and should bounce back.
+        // If the ball has crossed the left or right boundary of the playing field.
+        if (position.x > this->fieldWidth_ / 2 || position.x < -this->fieldWidth_ / 2)
+        {
+            //Ball hits the right Wall
+            if (position.x > this->fieldWidth_ / 2)
+                {
+                    // Set the ball to be exactly at the boundary.
+                    position.x = this->fieldWidth_ / 2;
+                    // Invert its velocity in x-direction (i.e. it bounces off).
+                    velocity.x = -velocity.x;
+                    this->fireEvent();
+                    }
+
+            //Ball hits the left wall
+            else if (position.x < -this->fieldWidth_ / 2)
+                {
+                        // Set the ball to be exactly at the boundary.
+                        position.x = -this->fieldWidth_ / 2;
+                        // Invert its velocity in x-direction (i.e. it bounces off).
+                        velocity.x = -velocity.x;
+                        this->fireEvent();
+                    }
+        }
+
+        // Set the position, velocity and acceleration of the ball, if they have changed.
+        if (acceleration != this->getAcceleration())
+            this->setAcceleration(acceleration);
+        if (velocity != this->getVelocity())
+            this->setVelocity(velocity);
+        if (position != this->getPosition())
+            this->setPosition(position);
+    }
+
+
+
+
+    void BallProjectile::setSpeed(float speed)
+    {
+        if (speed != this->speed_) // If the speed changes
+        {
+            this->speed_ = speed;
+
+            // Set the speed in the direction of the balls current velocity.
+            Vector3 velocity = this->getVelocity();
+            if (velocity.x != 0)
+                velocity.x = sgn(velocity.x) * this->speed_;
+            else // If the balls current velocity is zero, the speed is set in a random direction.
+                velocity.x = this->speed_ * sgn(rnd(-1,1));
+
+            this->setVelocity(velocity);
+        }
+    }
+
+
 }

Modified: code/branches/OrxoBlox_FS19/src/modules/weapons/projectiles/BallProjectile.h
===================================================================
--- code/branches/OrxoBlox_FS19/src/modules/weapons/projectiles/BallProjectile.h	2019-04-18 14:02:06 UTC (rev 12309)
+++ code/branches/OrxoBlox_FS19/src/modules/weapons/projectiles/BallProjectile.h	2019-04-18 14:04:33 UTC (rev 12310)
@@ -53,7 +53,10 @@
             BallProjectile(Context* context);
             void Bounce(WorldEntity* otherObject, btManifoldPoint& contactPoint, const btCollisionShape* cs);
             virtual void setMaterial(const std::string& material) override;
+            virtual void tick(float dt) override;
+            void setSpeed(float speed);
 
+
         protected:
             bool processCollision(WorldEntity* otherObject, btManifoldPoint& contactPoint, const btCollisionShape* cs) override;
 
@@ -62,6 +65,9 @@
             void registerVariables();
             void changeTexture();
             
+            float speed_; //!< The speed (in x-direction) of the ball.
+            float fieldWidth_; //!< The width of the playing field.
+            float fieldHeight_; //!< The height of the playing field.
             unsigned int textureIndex_; //!< The current index of the texture. (i.e. the index of the currently displayed texture)
             unsigned int maxTextureIndex_; //!< The maximal index.
             std::string materialBase_; //!< The base name of the material.



More information about the Orxonox-commit mailing list