Permalink
Browse files

Added boat components

  • Loading branch information...
1 parent f1bb1bb commit 4e222cb286f6b39f659a7d99fd41fde3566607a5 @gnuvince committed Jan 29, 2012
Showing with 128 additions and 21 deletions.
  1. +110 −12 Application/Sources/Scene/Boat.cpp
  2. +18 −9 Application/Sources/Scene/Boat.h
@@ -2,9 +2,9 @@
#include "MainWindow.h"
#include "CoreLib/Cube.h"
-#define BOAT_WIDTH 2
+#define BOAT_WIDTH 3.2
#define BOAT_THICKNESS 0.8
-#define BOAT_LENGTH 2
+#define BOAT_LENGTH 4.8
using namespace CoreLib;
@@ -22,10 +22,17 @@ namespace Application
// sous-objet à l'aide de la méthode this->AddChild(...)
///////////////////////////////////////
- mHull.SetSizes(BOAT_WIDTH, BOAT_THICKNESS, BOAT_LENGTH);
- mHull.SetMaterial(&mHullMaterial);
this->AddChild(&mHull);
+ mHull.AddChild(&mMast);
+ mMast.AddChild(&mFlag);
+ mHull.AddChild(&mLeftWheel);
+ mHull.AddChild(&mRightWheel);
+
+ for (int i = 0; i < 5; ++i) {
+ mLeftWheel.AddChild(&mLeftPaddles[i]);
+ mRightWheel.AddChild(&mRightPaddles[i]);
+ }
// Size definition
///////////////////////////////////////
@@ -35,6 +42,17 @@ namespace Application
// SetSizes(...)
///////////////////////////////////////
+ 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);
+
+ for (int i = 0; i < 5; ++i) {
+ mRightPaddles[i].SetSizes(5.7, .2, .6);
+ mLeftPaddles[i].SetSizes(5.7, .2, .6);
+ }
+
// Relative transformations
///////////////////////////////////////
// IFT3355
@@ -47,6 +65,29 @@ namespace Application
// de la classe Transformation
///////////////////////////////////////
+ mMast.GetLocalTransformation().SetTranslation(Vector3<real>(0, 3, 0));
+
+ mFlag.GetLocalTransformation().SetTranslation(Vector3<real>(-.5, 3, 0));
+ mFlag.GetLocalTransformation().SetRotationZ(PI / 2);
+
+ mLeftWheel.GetLocalTransformation().SetTranslation(Vector3<real>(-2, 0, 0));
+ mLeftWheel.GetLocalTransformation().SetRotationZ(PI/2);
+
+ mRightWheel.GetLocalTransformation().SetTranslation(Vector3<real>(2, 0, 0));
+ mRightWheel.GetLocalTransformation().SetRotationZ(PI/2);
+
+ for (int i = 0; i < 5; ++i) {
+ Transformation<real> t = mLeftPaddles[i].GetLocalTransformation();
+ t.RotateX(PI/2);
+ t.RotateY(i/5.0 * 2 * PI);
+ mLeftPaddles[i].SetLocalTransformation(t);
+
+ t = mRightPaddles[i].GetLocalTransformation();
+ t.RotateX(PI/2);
+ t.RotateY(i/5.0 * 2 * PI);
+ mRightPaddles[i].SetLocalTransformation(t);
+ }
+
// Material definition
///////////////////////////////////////
// IFT3355
@@ -57,6 +98,9 @@ namespace Application
mHullMaterial.SetSpecular( Color<real>( 0.01, 0.01, 0.01, 1.0 ) );
mHullMaterial.SetShininess( 128 );
+ mFlagMaterial.SetSurface(Color<real>(1, 0, 0, 1));
+ mFlagMaterial.SetShininess( 128 );
+
// Material application
///////////////////////////////////////
// IFT3355
@@ -67,6 +111,18 @@ namespace Application
// pouvez utiliser le même matériau pour plusieurs
// objets.
///////////////////////////////////////
+
+ mHull.SetMaterial(&mHullMaterial);
+ mMast.SetMaterial(&mHullMaterial);
+ mFlag.SetMaterial(&mFlagMaterial);
+ mLeftWheel.SetMaterial(&mHullMaterial);
+ mRightWheel.SetMaterial(&mHullMaterial);
+
+ for (int i = 0; i < 5; ++i) {
+ mLeftPaddles[i].SetMaterial(&mHullMaterial);
+ mRightPaddles[i].SetMaterial(&mHullMaterial);
+ }
+
}
@@ -106,18 +162,19 @@ namespace Application
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),
+ Vector3<real>(BOAT_WIDTH/2, 0, 0),
+ Vector3<real>(-BOAT_WIDTH/2, 0, 0),
+ Vector3<real>(0, 0, BOAT_LENGTH/2),
+ Vector3<real>(0, 0, -BOAT_LENGTH/2),
};
// Hauteur du bateau
real y_average = 0;
- for (int i = 0; i < 5; ++i) y_average += getDeltaYAtPoint(waterSurface, points[i]);
+ 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 / 2, 0));
+ t.Translate(Vector3<real>(0, y_average + BOAT_THICKNESS/4, 0));
SetLocalTransformation(t);
@@ -129,34 +186,75 @@ namespace Application
t = mHull.GetLocalTransformation();
t.RotateX(dt * angle_on_x);
t.RotateZ(dt * angle_on_z);
+ t.RotateY(0);
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));
SetLocalTransformation(t);
+
+ for (int i = 0; i < 5; ++i) {
+ Transformation<real> t = mLeftPaddles[i].GetLocalTransformation();
+ t.RotateY(dt*2);
+ mLeftPaddles[i].SetLocalTransformation(t);
+
+ t = mRightPaddles[i].GetLocalTransformation();
+ t.RotateY(dt*2);
+ mRightPaddles[i].SetLocalTransformation(t);
+ }
}
if (MainWindow::Get()->IsKeyPressed('s')) {
Transformation<real> t = GetLocalTransformation();
t.Translate(Vector3<real>(cos(angle - PI/2)*10*dt, 0, -sin(angle - PI/2)*10*dt));
SetLocalTransformation(t);
+
+ for (int i = 0; i < 5; ++i) {
+ Transformation<real> t = mLeftPaddles[i].GetLocalTransformation();
+ t.RotateY(-dt*2);
+ mLeftPaddles[i].SetLocalTransformation(t);
+
+ t = mRightPaddles[i].GetLocalTransformation();
+ t.RotateY(-dt*2);
+ mRightPaddles[i].SetLocalTransformation(t);
+ }
}
if (MainWindow::Get()->IsKeyPressed('a')) {
Transformation<real> t = GetLocalTransformation();
t.RotateY(dt);
SetLocalTransformation(t);
+
+ for (int i = 0; i < 5; ++i) {
+ Transformation<real> t = mLeftPaddles[i].GetLocalTransformation();
+ t.RotateY(dt);
+ mLeftPaddles[i].SetLocalTransformation(t);
+
+ t = mRightPaddles[i].GetLocalTransformation();
+ t.RotateY(-dt);
+ mRightPaddles[i].SetLocalTransformation(t);
+ }
+
angle += dt;
}
if (MainWindow::Get()->IsKeyPressed('d')) {
Transformation<real> t = GetLocalTransformation();
t.RotateY(-dt);
SetLocalTransformation(t);
+
+ for (int i = 0; i < 5; ++i) {
+ Transformation<real> t = mLeftPaddles[i].GetLocalTransformation();
+ t.RotateY(-dt);
+ mLeftPaddles[i].SetLocalTransformation(t);
+
+ t = mRightPaddles[i].GetLocalTransformation();
+ t.RotateY(dt);
+ mRightPaddles[i].SetLocalTransformation(t);
+ }
+
angle -= dt;
}
@@ -5,6 +5,7 @@
#include "WaterSurface.h"
#include "CoreLib/BlinnPhongMaterial.h"
#include "CoreLib/Camera.h"
+#include "CoreLib/Cone.h"
#include "CoreLib/Cube.h"
#include "CoreLib/Cylinder.h"
#include "CoreLib/Node.h"
@@ -16,21 +17,29 @@ namespace Application
class Boat : public CoreLib::Node<real>
{
public:
- Boat();
+Boat();
- void Animate( const WaterSurface& waterSurface, real time, real dt );
+void Animate( const WaterSurface& waterSurface, real time, real dt );
- real GetSizeZ() const;
- real GetSizeX() const;
+real GetSizeZ() const;
+real GetSizeX() const;
private:
- CoreLib::Cube<real> mHull;
+CoreLib::Cube<real> mHull;
- CoreLib::BlinnPhongMaterial<real> mHullMaterial;
- real angle;
+CoreLib::BlinnPhongMaterial<real> mHullMaterial;
+CoreLib::BlinnPhongMaterial<real> mFlagMaterial;
+real angle;
- real getWaterHeightAt(const WaterSurface&, CoreLib::Vector3<real>);
- real getDeltaYAtPoint(const WaterSurface&, CoreLib::Vector3<real>);
+real getWaterHeightAt(const WaterSurface&, CoreLib::Vector3<real>);
+real getDeltaYAtPoint(const WaterSurface&, CoreLib::Vector3<real>);
+
+CoreLib::Cylinder<real> mMast;
+CoreLib::Cone<real> mFlag;
+CoreLib::Cylinder<real> mLeftWheel;
+CoreLib::Cylinder<real> mRightWheel;
+CoreLib::Cube<real> mLeftPaddles[5];
+CoreLib::Cube<real> mRightPaddles[5];
};
}

0 comments on commit 4e222cb

Please sign in to comment.