Skip to content
Browse files

IMPROVEMENT: used normal of the wave to control rotation of the boat

  • Loading branch information...
1 parent c6b15f9 commit 218c234cecd9a8a3df6be96ea4677176f2a7e965 @gnuvince committed
Showing with 8 additions and 12 deletions.
  1. +8 −12 Application/Sources/Scene/Boat.cpp
View
20 Application/Sources/Scene/Boat.cpp
@@ -173,22 +173,18 @@ namespace Application
for (int i = 0; i < 5; ++i)
y_average += getDeltaYAtPoint(waterSurface, points[i]);
y_average /= 5;
- Transformation<real> t = GetLocalTransformation();
- t.Translate(Vector3<real>(0, y_average + BOAT_THICKNESS/4, 0));
- SetLocalTransformation(t);
-
+ Transformation<real> t = mHull.GetLocalTransformation();
+ t.SetTranslation(Vector3<real>(0, y_average + BOAT_THICKNESS/4, 0));
// Rotations du bateau
- real delta_y_on_x = getWaterHeightAt(waterSurface, points[2]) - getWaterHeightAt(waterSurface, points[4]);
- real delta_y_on_z = getWaterHeightAt(waterSurface, points[1]) - getWaterHeightAt(waterSurface, points[2]);
- real angle_on_x = atan(delta_y_on_x / BOAT_WIDTH);
- real angle_on_z = atan(delta_y_on_z / BOAT_LENGTH);
- t = mHull.GetLocalTransformation();
- t.RotateX(dt * angle_on_x);
- t.RotateZ(dt * angle_on_z);
- t.RotateY(0);
+ Vector3<real> global_position = GetLocalToGlobal() * points[0];
+ Vector3<real> water_orientation = waterSurface.GetGlobalNormal(global_position);
+ t.SetRotationX(atan(water_orientation.Z() / water_orientation.X()));
+ t.SetRotationZ(atan(water_orientation.Z() / water_orientation.Y()));
+
mHull.SetLocalTransformation(t);
+
if (MainWindow::Get()->IsKeyPressed('w')) {
Transformation<real> t = GetLocalTransformation();
t.Translate(Vector3<real>(cos(angle - PI/2)*-20*dt, 0, -sin(angle - PI/2)*-20*dt));

0 comments on commit 218c234

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