commit 8b2d8ad14bfba6d49b6401c22d62f016e1bf8883
parent 7a17f5e2c194996a7529b932b15e264ea43bd063
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date: Fri, 9 Dec 2011 23:46:09 +0100
Quelques modifs pas encore commit.
Diffstat:
5 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/main.cpp b/main.cpp
@@ -21,7 +21,7 @@ int main() {
Vertex ne(size, size, 0);
Vertex se(size, 0, 0);
Vertex sw(0, 0, 0);
- Vertex nw(0, size*2, 0);
+ Vertex nw(0, size*1.3, 0);
Chose* c = new QuadRoutes(ne,se,sw,nw);
// c->subdivide();
recursiveSubdivide(c);
diff --git a/rules/quadroutes.cpp b/rules/quadroutes.cpp
@@ -1,5 +1,8 @@
#include "all_includes.hh"
+const float QuadRoutes::cosMin = std::cos((90+maxAngleDelta)/180.f*3.14159);
+const float QuadRoutes::cosMax = std::cos((90-maxAngleDelta)/180.f*3.14159);
+
QuadRoutes::QuadRoutes(Vertex ne, Vertex se, Vertex sw, Vertex nw) : Chose(), ne(ne), se(se), sw(sw), nw(nw) {
addEntropy(ne, se, sw, nw);
triangulation();
@@ -38,6 +41,8 @@ bool QuadRoutes::subdivide() {
Vertex split = intersection(s,n,w,e);
+ std::cout << "n-split-e=" << cosAngle(n,split,e) << " minmax=" << cosMax << std::endl;
+
// Créer 4 quad (qne, qse, qsw, qnw), puis :
Quad q[4] = {
Quad(ne, e, split, n),
diff --git a/rules/quadroutes.hh b/rules/quadroutes.hh
@@ -14,6 +14,9 @@ public:
static const int hrw = 250; // half road width : 2,50m.
static const int minchildsize = 1000;
static const int minQuadSize = 2500;
+ static const int maxAngleDelta = 20; // 90±20°
+ static const float cosMin;
+ static const float cosMax;
public:
QuadRoutes(Vertex ne, Vertex se, Vertex sw, Vertex nw);
int width();
diff --git a/vertex.cpp b/vertex.cpp
@@ -25,8 +25,8 @@ Vertex intersection(Vertex a, Vertex b, Vertex c, Vertex d) {
Vertex Vertex::projectOn(Vertex v) {
// http://www.developpez.net/forums/d202580/applications/developpement-2d-3d-jeux/contribuez/faq-mat-quat-ajout-calculs-vectoriels/
- int64 scalaire = this->x*v.x + this->y*v.y;
- int64 normecarre = v.norm();
+ int64 scalaire = ((int64)this->x)*((int64)v.x) + ((int64)this->y)*((int64)v.y);
+ int normecarre = v.norm();
normecarre *= normecarre;
return Vertex(((int64)v.x) * scalaire / normecarre, ((int64)v.y) * scalaire / normecarre, 0);
}
@@ -40,6 +40,15 @@ Vertex Vertex::perpendicular() {
return Vertex(-y, x, 0);
}
+float Vertex::cosAngle(Vertex v) {
+ // http://www.developpez.net/forums/d202580/applications/developpement-2d-3d-jeux/contribuez/faq-mat-quat-ajout-calculs-vectoriels/
+ return ((double)(this->x*v.x + this->y*v.y)) / (((double)norm())*((double)v.norm()));
+}
+
+float cosAngle(Vertex u, Vertex v, Vertex w) {
+ return (u-v).cosAngle(w-v);
+}
+
Vertex::operator Vertexf() { return Vertexf(x,y,z); }
std::ostream& operator<<(std::ostream& os, const Vertex& v) {
diff --git a/vertex.hh b/vertex.hh
@@ -17,6 +17,8 @@ class Vertex {
Vertex projectOn(Vertex v);
Vertex setNorm(int n);
Vertex perpendicular(); // Perpendiculaire 2D dans le sens contraire des aiguilles d'une montre.
+ float cosAngle(Vertex v); // cosinus de l'angle entre this et v.
+ friend float cosAngle(Vertex u, Vertex v, Vertex w);
static Vertex fromSpherical(float r, float xAngle, float yAngle);
friend Vertex intersection(Vertex a, Vertex b, Vertex c, Vertex d); // Intersection entre (a,b) et (c,d).