Skip to content
Browse files

Buoy-Buoy collision; side collisions

  • Loading branch information...
1 parent aa9b972 commit 5a9a12a79c06e7b0834c453e9df866c928631432 @Gabriano Gabriano committed Feb 2, 2012
Showing with 23 additions and 3 deletions.
  1. +4 −3 Application/Sources/Scene/Boat.cpp
  2. +19 −0 Application/Sources/Scene/CollisionHandler.cpp
View
7 Application/Sources/Scene/Boat.cpp
@@ -5,6 +5,7 @@
#define BOAT_WIDTH 3.2
#define BOAT_THICKNESS 0.8
#define BOAT_LENGTH 4.8
+#define WHEEL_THICKNESS 0.8
using namespace CoreLib;
@@ -45,8 +46,8 @@ namespace Application
mHull.SetSizes(BOAT_WIDTH, BOAT_THICKNESS, BOAT_LENGTH);
mMast.SetSizes(6, .1, 10);
mFlag.SetSizes(1, .2, 10);
- mLeftWheel.SetSizes(.8, 2.4, 10);
- mRightWheel.SetSizes(.8, 2.4, 10);
+ mLeftWheel.SetSizes(WHEEL_THICKNESS, 2.4, 10);
+ mRightWheel.SetSizes(WHEEL_THICKNESS, 2.4, 10);
for (int i = 0; i < 5; ++i) {
mRightPaddles[i].SetSizes(5.7, .2, .6);
@@ -264,7 +265,7 @@ namespace Application
{
// Vous pouvez remplacer cette valeur au besoin.
//Elle doit correspondre à la taille de la coque du bateau
- return BOAT_WIDTH;
+ return BOAT_WIDTH + 2*WHEEL_THICKNESS;
}
real Boat::GetAngle() const {
View
19 Application/Sources/Scene/CollisionHandler.cpp
@@ -137,6 +137,25 @@ void CollisionHandler::ResolveCollision( Buoy& buoy1, Buoy& buoy2 )
// La méthode OnCollide de la classe
// Buoy doit être appelée lorsqu'il y a collision.
///////////////////////////////////////
+
+ real r1 = buoy1.GetRadius();
+ real r2 = buoy2.GetRadius();
+
+ Vector3<real> b2_center = buoy1.GetGlobalToLocal() * (buoy2.GetLocalToGlobal() *
+ Vector3<real>(0, 0, 0));
+
+ real D = sqrt(b2_center.X()*b2_center.X() + b2_center.Z()*b2_center.Z());
+
+ if (D < (r1 + r2)) { // Collision
+ real d = r1 - ( D - r2);
+ Vector3<real> v = b2_center.Normalized() * (d/2);
+
+ buoy1.GetLocalTransformation().Translate(-v);
+ buoy2.GetLocalTransformation().Translate((buoy2.GetGlobalToLocal() * (buoy1.GetLocalToGlobal() * (b2_center + v))));
+
+ buoy1.OnCollide();
+ buoy2.OnCollide();
+ }
}
}

0 comments on commit 5a9a12a

Please sign in to comment.
Something went wrong with that request. Please try again.