Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Buoy-Buoy collision; side collisions

  • Loading branch information...
commit 5a9a12a79c06e7b0834c453e9df866c928631432 1 parent aa9b972
Gabriano Gabriano authored
7 Application/Sources/Scene/Boat.cpp
@@ -5,6 +5,7 @@
5 5 #define BOAT_WIDTH 3.2
6 6 #define BOAT_THICKNESS 0.8
7 7 #define BOAT_LENGTH 4.8
  8 +#define WHEEL_THICKNESS 0.8
8 9
9 10 using namespace CoreLib;
10 11
@@ -45,8 +46,8 @@ namespace Application
45 46 mHull.SetSizes(BOAT_WIDTH, BOAT_THICKNESS, BOAT_LENGTH);
46 47 mMast.SetSizes(6, .1, 10);
47 48 mFlag.SetSizes(1, .2, 10);
48   - mLeftWheel.SetSizes(.8, 2.4, 10);
49   - mRightWheel.SetSizes(.8, 2.4, 10);
  49 + mLeftWheel.SetSizes(WHEEL_THICKNESS, 2.4, 10);
  50 + mRightWheel.SetSizes(WHEEL_THICKNESS, 2.4, 10);
50 51
51 52 for (int i = 0; i < 5; ++i) {
52 53 mRightPaddles[i].SetSizes(5.7, .2, .6);
@@ -264,7 +265,7 @@ namespace Application
264 265 {
265 266 // Vous pouvez remplacer cette valeur au besoin.
266 267 //Elle doit correspondre à la taille de la coque du bateau
267   - return BOAT_WIDTH;
  268 + return BOAT_WIDTH + 2*WHEEL_THICKNESS;
268 269 }
269 270
270 271 real Boat::GetAngle() const {
19 Application/Sources/Scene/CollisionHandler.cpp
@@ -137,6 +137,25 @@ void CollisionHandler::ResolveCollision( Buoy& buoy1, Buoy& buoy2 )
137 137 // La méthode OnCollide de la classe
138 138 // Buoy doit être appelée lorsqu'il y a collision.
139 139 ///////////////////////////////////////
  140 +
  141 + real r1 = buoy1.GetRadius();
  142 + real r2 = buoy2.GetRadius();
  143 +
  144 + Vector3<real> b2_center = buoy1.GetGlobalToLocal() * (buoy2.GetLocalToGlobal() *
  145 + Vector3<real>(0, 0, 0));
  146 +
  147 + real D = sqrt(b2_center.X()*b2_center.X() + b2_center.Z()*b2_center.Z());
  148 +
  149 + if (D < (r1 + r2)) { // Collision
  150 + real d = r1 - ( D - r2);
  151 + Vector3<real> v = b2_center.Normalized() * (d/2);
  152 +
  153 + buoy1.GetLocalTransformation().Translate(-v);
  154 + buoy2.GetLocalTransformation().Translate((buoy2.GetGlobalToLocal() * (buoy1.GetLocalToGlobal() * (b2_center + v))));
  155 +
  156 + buoy1.OnCollide();
  157 + buoy2.OnCollide();
  158 + }
140 159 }
141 160
142 161 }

0 comments on commit 5a9a12a

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