www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 90a6202619c332044f94ee4f1e0bd1589001e4ea
parent 7943a11f8419d8741259854e41ac07ff1dd6bd64
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date:   Tue, 10 Jan 2012 19:00:53 +0100

Modification de Quad::inset pour qu'il fonctionne en 3D.

Diffstat:
Mgeometry/quad.cpp | 6+++++-
Mgeometry/quad.hh | 1+
Mgeometry/vertex.cpp | 73-------------------------------------------------------------------------
Mgeometry/vertex.hh | 1-
Mrules/batiment/batimentquadmur.cpp | 4++--
5 files changed, 8 insertions(+), 77 deletions(-)

diff --git a/geometry/quad.cpp b/geometry/quad.cpp @@ -11,7 +11,7 @@ Quad::Quad(Vertex ne, Vertex se, Vertex sw, Vertex nw) { Quad Quad::inset(Cardinal side, float offset) const { Quad q = (*this) << int(side); - Vertex offsetDirection = (q[NW]-q[NE]).perpendicularCw(); + Vertex offsetDirection = Triangle(q[NE], q[NW], q[NW] + q.normal()).normal(); float distE = offset / offsetDirection.cosAngle(q[SE] - q[NE]); float distW = offset / offsetDirection.cosAngle(q[SW] - q[NW]); q[NE] = q[NE] + (q[SE] - q[NE]).setNorm(distE); @@ -132,3 +132,7 @@ float Quad::surface() const { Quad Quad::offsetNormal(float offset) const { return ((*this) + Triangle(c[NE], c[SE], c[SW]).normal().setNorm(offset)); } + +Vertex Quad::normal() const { + return Triangle(c[NE], c[SE], c[SW]).normal(); +} diff --git a/geometry/quad.hh b/geometry/quad.hh @@ -42,6 +42,7 @@ class Quad { //void cutCornerCorner(Coin from) const; Quad makeParallelogram() const; Quad offsetNormal(float offset) const; + Vertex normal() const; }; diff --git a/geometry/vertex.cpp b/geometry/vertex.cpp @@ -19,7 +19,6 @@ Vertex intersection(Vertex a, Vertex b, Vertex c, Vertex d) { ); } -// TODO : n'est qu'en 2D ! Vertex Vertex::projectOn(Vertex v) const { // http://www.developpez.net/forums/d202580/applications/developpement-2d-3d-jeux/contribuez/faq-mat-quat-ajout-calculs-vectoriels/ float scalaire = (this->x)*(v.x) + (this->y)*(v.y) + (this->z)*(v.z); @@ -31,13 +30,8 @@ Vertex Vertex::setNorm(float n) const { return (*this * n / norm()); } -Vertex Vertex::perpendicularCw() const { - return Vertex(-y, x, 0); -} - float Vertex::cosAngle(Vertex v) const { // http://www.developpez.net/forums/d202580/applications/developpement-2d-3d-jeux/contribuez/faq-mat-quat-ajout-calculs-vectoriels/ - //std::cout << "cosAngle " << *this << " " << v << " " << ((this->x*v.x + this->y*v.y) / (norm()*v.norm())) << " " << (norm()*v.norm()) << std::endl; return ((this->x*v.x + this->y*v.y) / (norm()*v.norm())); } @@ -86,70 +80,3 @@ Vertex Vertex::fromSpherical(float r, float xAngle, float yAngle) { r * std::cos(xAngle / 180.f * Angle::Pi) ); } - - - - -/* - -Vertex::Vertex() {} - -Vertex::Vertex(float x, float y, float z): x(x), y(y), z(z) {} - -float Vertex::norm() { return std::sqrt(x*x + y*y + z*z); } - -Vertex::operator Vertex() { return Vertex(x,y,z); } - -std::ostream& operator<<(std::ostream& os, const Vertex& v) { - return os << "(" << v.x << "," << v.y << "," << v.z << ")"; -} - -Vertex operator+(const Vertex& u, const Vertex& v) { - return Vertex(u.x + v.x, u.y + v.y, u.z + v.z); -} - -Vertex operator-(const Vertex& u, const Vertex& v) { - return Vertex(u.x - v.x, u.y - v.y, u.z - v.z); -} - -Vertex operator+(const Vertex& u, const Vertex& v) { - return Vertex(u.x + v.x, u.y + v.y, u.z + v.z); -} - -Vertex operator-(const Vertex& u, const Vertex& v) { - return Vertex(u.x - v.x, u.y - v.y, u.z - v.z); -} - -Vertex operator-(const Vertex& v) { - return Vertex(-v.x, -v.y, -v.z); -} - -Vertex operator*(const Vertex& v, const int n) { - return Vertex(v.x * n, v.y * n, v.z * n); -} - -Vertex operator*(const Vertex& u, const Vertex& v) { - return Vertex( - (u.y * v.z) - (u.z * v.y), - (u.z * v.x) - (u.x * v.z), - (u.x * v.y) - (u.y * v.x) - ); -} - -Vertex operator/(const Vertex& v, const int n) { - return Vertex(v.x / n, v.y / n, v.z / n); -} - -Vertex operator/(const Vertex& v, const float f) { - return Vertex(v.x / f, v.y / f, v.z / f); -} - -Vertex Vertex::fromSpherical(float r, float xAngle, float yAngle) { - // http://electron9.phys.utk.edu/vectors/3dcoordinates.htm - return Vertex( - r * std::sin(xAngle / 180 * 3.14159) * std::cos(yAngle / 180 * 3.14159), - r * std::sin(xAngle / 180 * 3.14159) * std::sin(yAngle / 180 * 3.14159), - r * std::cos(xAngle / 180 * 3.14159) - ); -} -*/ diff --git a/geometry/vertex.hh b/geometry/vertex.hh @@ -15,7 +15,6 @@ class Vertex { float norm() const; Vertex projectOn(Vertex v) const; Vertex setNorm(float n) const; - Vertex perpendicularCw() const; // Perpendiculaire 2D dans le sens contraire des aiguilles d'une montre (ClockWise). float cosAngle(Vertex v) const; // cosinus de l'angle entre this et v. float angle(Vertex v) const; // Angle entre this et v. static Vertex fromSpherical(float r, float xAngle, float yAngle); diff --git a/rules/batiment/batimentquadmur.cpp b/rules/batiment/batimentquadmur.cpp @@ -38,8 +38,8 @@ bool BatimentQuadMur::split() { Quad bottom = c; - //addChild(new BatimentQuadMur(c,windowPos)); - //addChild(new BatimentQuadMur(windowPos,ch)); + addChild(new BatimentQuadMur(c,windowPos)); + addChild(new BatimentQuadMur(windowPosh,ch)); return true; }