Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

We got tanguage

  • Loading branch information...
commit f1bb1bbb571d0e8849c840254633d7516c66da63 1 parent 4a2db2e
Vincent Foley authored
55 Application/Sources/Scene/Boat.cpp
View
@@ -2,9 +2,9 @@
#include "MainWindow.h"
#include "CoreLib/Cube.h"
-#define BOAT_WIDTH 5
-#define BOAT_THICKNESS 0.3
-#define BOAT_LENGTH 5
+#define BOAT_WIDTH 2
+#define BOAT_THICKNESS 0.8
+#define BOAT_LENGTH 2
using namespace CoreLib;
@@ -21,14 +21,11 @@ namespace Application
// un Node<real> vous pouvez attacher ses
// sous-objet à l'aide de la méthode this->AddChild(...)
///////////////////////////////////////
- Cube<real> *platform = new Cube<real>(BOAT_WIDTH, BOAT_THICKNESS, BOAT_LENGTH);
- BlinnPhongMaterial<real> *bpm = new BlinnPhongMaterial<real>;
- Color<real> *red = new Color<real>(1, 0.5, 0, 1);
- bpm->SetSurface(*red);
- platform->SetMaterial(bpm);
+ mHull.SetSizes(BOAT_WIDTH, BOAT_THICKNESS, BOAT_LENGTH);
+ mHull.SetMaterial(&mHullMaterial);
- this->AddChild(platform);
+ this->AddChild(&mHull);
// Size definition
///////////////////////////////////////
@@ -73,10 +70,15 @@ namespace Application
}
+
+ real Boat::getWaterHeightAt(const WaterSurface& waterSurface, Vector3<real> pt) {
+ Vector3<real> water_position = waterSurface.GetGlobalWithHeight(pt);
+ return water_position.Y();
+ }
+
real Boat::getDeltaYAtPoint(const WaterSurface& waterSurface, Vector3<real> pt) {
Vector3<real> global_position = GetLocalToGlobal() * pt;
- Vector3<real> water_position = waterSurface.GetGlobalWithHeight(global_position);
- real y_delta = water_position.Y() - global_position.Y();
+ real y_delta = getWaterHeightAt(waterSurface, global_position) - global_position.Y();
return y_delta;
}
@@ -101,16 +103,35 @@ namespace Application
///////////////////////////////////////
- real y_average = (getDeltaYAtPoint(waterSurface, Vector3<real>(0, 0, 0))
- + getDeltaYAtPoint(waterSurface, Vector3<real>(BOAT_WIDTH/2, 0, BOAT_LENGTH/2))
- + getDeltaYAtPoint(waterSurface, Vector3<real>(BOAT_WIDTH/2, 0, -BOAT_LENGTH/2))
- + getDeltaYAtPoint(waterSurface, Vector3<real>(-BOAT_WIDTH/2, 0, BOAT_LENGTH/2))
- + getDeltaYAtPoint(waterSurface, Vector3<real>(-BOAT_WIDTH/2, 0, -BOAT_LENGTH/2))) / 5;
+
+ Vector3<real> points[5] = {
+ Vector3<real>(0, 0, 0),
+ Vector3<real>(BOAT_WIDTH/2, 0, BOAT_LENGTH/2),
+ Vector3<real>(BOAT_WIDTH/2, 0, -BOAT_LENGTH/2),
+ Vector3<real>(-BOAT_WIDTH/2, 0, BOAT_LENGTH/2),
+ Vector3<real>(-BOAT_WIDTH/2, 0, -BOAT_LENGTH/2),
+ };
+
+ // Hauteur du bateau
+ real y_average = 0;
+ 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, 0));
+ t.Translate(Vector3<real>(0, y_average + BOAT_THICKNESS / 2, 0));
SetLocalTransformation(t);
+ // 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);
+ mHull.SetLocalTransformation(t);
+
+
if (MainWindow::Get()->IsKeyPressed('w')) {
1  Application/Sources/Scene/Boat.h
View
@@ -29,6 +29,7 @@ class Boat : public CoreLib::Node<real>
CoreLib::BlinnPhongMaterial<real> mHullMaterial;
real angle;
+ real getWaterHeightAt(const WaterSurface&, CoreLib::Vector3<real>);
real getDeltaYAtPoint(const WaterSurface&, CoreLib::Vector3<real>);
};
Please sign in to comment.
Something went wrong with that request. Please try again.