From 1b8e8d1f6a4046d1475e9a4d4cdc0233b3badf59 Mon Sep 17 00:00:00 2001 From: Quentin BAZIN Date: Mon, 25 Feb 2013 14:51:11 +0100 Subject: [PATCH] Cube selection: OK. --- source/scene.cpp | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/source/scene.cpp b/source/scene.cpp index 2aff4355..070c86a0 100644 --- a/source/scene.cpp +++ b/source/scene.cpp @@ -36,7 +36,7 @@ bool Scene::intersectionLinePlane(vect3D normal, vect3D planePoint, vect3D lineO float p2 = u.x * normal.x + u.y * normal.y + u.z * normal.z; // Second point to be tested - float k = p1 / p2; + float k = p2 / p1; vect3D i; // Intersection point @@ -50,9 +50,6 @@ bool Scene::intersectionLinePlane(vect3D normal, vect3D planePoint, vect3D lineO v.y = i.y - planePoint.y; v.z = i.z - planePoint.z; - //if(normal.z == 1) - // cout << "p1(" << p1 << ")" << " | u(" << u.x << ";" << u.y << ";" << u.z << ") | p2(" << p2 << ") | i(" << i.x << ";" << i.y << ";" << i.z << ") | v(" << v.x << ";" << v.y << ";" << v.z << ") | "; - float size = 0.5; if(v.x >= -size && v.x <= size && v.y >= -size && v.y <= size && v.z >= -size && v.z <= size) { @@ -163,29 +160,25 @@ void Scene::testCubes(std::vector cubes) { float distance = FAR; Cube *cube = cubes[0]; for(std::vector::iterator it = cubes.begin() ; it != cubes.end() ; it++) { - /*vect3D center; + vect3D center; center.x = (*it)->x() + sqrt(3) / 2; center.y = (*it)->y() + sqrt(3) / 2; - center.z = (*it)->z() + sqrt(3) / 2;*/ + center.z = (*it)->z() + sqrt(3) / 2; if(intersectionLineCube((*it)->x(), (*it)->y(), (*it)->z(), linePoint, directionVector)) { - /*float d = sqrt(pow(linePoint.x - center.x, 2) + pow(linePoint.y - center.y, 2) + pow(linePoint.z - center.z, 2)); + float d = sqrt(pow(linePoint.x - center.x, 2) + pow(linePoint.y - center.y, 2) + pow(linePoint.z - center.z, 2)); if(d < distance) { distance = d; cube = (*it); - }*/ - - (*it)->setSelected(true); - } else { - (*it)->setSelected(false); + } } - //(*it)->setSelected(false); + (*it)->setSelected(false); } - //cube->setSelected(true); + cube->setSelected(true); } Scene::Scene() {