TriangleMesh* DebugGeometryBuilder::createArrow( float size, const Vector& start, const Vector& end )
{
   Vector dir;
   dir.setSub( end, start );
   dir.normalize();

   Vector perpVec1, perpVec2;
   VectorUtil::calculatePerpendicularVector( dir, perpVec1 );
   perpVec1.normalize();
   perpVec2.setCross( dir, perpVec1 );

   FastFloat simdSize; simdSize.setFromFloat( size );
   perpVec1.mul( simdSize );
   perpVec2.mul( simdSize );


   // the line
   std::vector<LitVertex> vertices;
   std::vector<Face> faces;
   addCuboid( simdSize, start, end, vertices, faces );

   // the cone tip
   FastFloat tipSize; tipSize.setFromFloat( 1.3f * size );
   Vector tipEnd;
   tipEnd.setMulAdd( dir, tipSize, end );
   addCone( tipSize, end, tipEnd, vertices, faces );
   TriangleMesh* mesh = new TriangleMesh( FilePath(), vertices, faces );
   return mesh;
}
Example #2
0
void convexHull3 (Points &points, vector<int> &hull)
{
	if (points.size() < 4) {
		return;
	}

	Arrangement arr;

	// add vertices
	for (int i = 0; i < points.size(); ++i) {
		Vertex *v = arr.addVertex(points[i]);
		v->id = vertex_id++;
	}

	init(arr);

	// Compute a random permutation p5, p6, . . . , pn of the remaining points.
	int n = points.size() - 4;
	int *p = new int [n];
	randomPermutation (n, p);

	for (int i = 4; i < arr.vertices.size(); ++i) {
		int r = p[i - 4] + 4;

		// Fconflict(Pr) is empty (that is, Pr lies inside C), nothing changes.
		if (arr.vertices[r]->visibleFaces.size() == 0) continue;

		// Compute the horizon
		Edges horizon;
		findHorizon(arr, arr.vertices[r], horizon);

		// list up all the vertices that have to be tested for the conflict graph
		Vertices vertices;
		listUpdateVertices(arr, arr.vertices[r], horizon, vertices);

		// delete all the visible faces and edges except the horizon
		deleteVisibleCone(arr, arr.vertices[r]);

		// add all the outgoing edges from Pr, and all the new faces
		addCone(arr, arr.vertices[r], horizon, vertices);
	}

	// build the return values
	buildHull(arr, hull);

	// debug
	std::ofstream ofs("test.vtk");
	outputVTK(points, hull, ofs);
}
Example #3
0
void NGLScene::keyPressEvent(QKeyEvent *_event)
{
  // this method is called every time the main window recives a key event.
  // we then switch on the key value and set the camera in the NGLScene
  switch (_event->key())
  {
  // escape key to quite
  case Qt::Key_Escape : QGuiApplication::exit(EXIT_SUCCESS); break;
  // turn on wirframe rendering
  case Qt::Key_W : glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); break;
  // turn off wire frame
  case Qt::Key_S : glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); break;
  // show full screen
  case Qt::Key_F : showFullScreen(); break;
  // show windowed
  case Qt::Key_N : showNormal(); break;
  case Qt::Key_Space : m_car->reset(); break;
  case Qt::Key_X : stepAnimation(); break;
  case Qt::Key_1 : addCube(); break;
  case Qt::Key_2 : addSphere(); break;
  case Qt::Key_3 : addCapsule(); break;
  case Qt::Key_4 : addCylinder(); break;
  case Qt::Key_5 : addCone(); break;
  case Qt::Key_6 : addMesh(TEAPOT); break;
  case Qt::Key_7 : addMesh(APPLE); break;
/*  case Qt::Key_Left : m_physics->addImpulse(ngl::Vec3(-5,0.0f,0.0f)); break;
  case Qt::Key_Right : m_physics->addImpulse(ngl::Vec3(5.0f,0.0f,0.0f)); break;
  case Qt::Key_Up : m_physics->addImpulse(ngl::Vec3(0.0f,5.0f,0.0f)); break;
  case Qt::Key_Down : m_physics->addImpulse(ngl::Vec3(0.0f,-5.0f,0.0f)); break;
*/
  case Qt::Key_Left : m_car->left(); break;
  case Qt::Key_Right : m_car->right(); break;
  case Qt::Key_Up : m_car->accelerate(); break;
  case Qt::Key_Down : m_car->stop(); break;


  case Qt::Key_B : toggleBBox(); break;
  case Qt::Key_R : toggleRandomPlace(); break;
  case Qt::Key_0 : resetSim();  break;

  default : break;
  }
  // finally update the GLWindow and re-draw
  //if (isExposed())
    renderNow();
}
Example #4
0
/**
 * Delaunay triangulation using the same algorithm as convexHull3.
 */
void triangulate (Points2D &points2D, vector<int> &triangles)
{
	if (points2D.size() < 4) {
		triangles.push_back(0);
		triangles.push_back(1);
		triangles.push_back(2);
		return;
	}

	Arrangement arr;

	// arrange the 3D points
	Points points;
	for (int i = 0; i < points2D.size(); ++i) {
		double x = points2D[i]->getP().getX().mid();
		double y = points2D[i]->getP().getY().mid();
		double z = x * x + y * y;
		points.push_back(new InputPoint(x * 2, y * 2, z));
	}

	// add vertices
	for (int i = 0; i < points.size(); ++i) {
		Vertex *v = arr.addVertex(points[i]);
		v->id = vertex_id++;
	}

	init(arr);

	// Compute a random permutation p5, p6, . . . , pn of the remaining points.
	int n = points.size() - 4;
	int *p = new int [n];
	randomPermutation (n, p);

	for (int i = 4; i < arr.vertices.size(); ++i) {
		int r = p[i - 4] + 4;

		// Fconflict(Pr) is empty (that is, Pr lies inside C), nothing changes.
		if (arr.vertices[r]->visibleFaces.size() == 0) continue;

		// compute the horizon
		Edges horizon;
		findHorizon(arr, arr.vertices[r], horizon);

		// list up all the vertices that have to be tested for the conflict graph
		Vertices vertices;
		listUpdateVertices(arr, arr.vertices[r], horizon, vertices);

		// delete all the visible faces and edges except the horizon
		deleteVisibleCone(arr, arr.vertices[r]);

		// add all the outgoing edges from Pr, and all the new faces
		addCone(arr, arr.vertices[r], horizon, vertices);
	}

	// list up all the faces that are visible from (0, 0, -oo)
	for (Faces::iterator f = arr.faces.begin(); f != arr.faces.end(); ++f) {
		Vertex *v0 = (*f)->edge->tail;
		Vertex *v1 = (*f)->edge->twin->next->tail;
		Vertex *v2 = (*f)->edge->twin->next->twin->next->tail;

		// if it is not visible, then skip it.
		PV3 u = v1->p->getP() - v0->p->getP();
		PV3 v = v2->p->getP() - v0->p->getP();
		PV3 w(0, 0, -1);
		if (w.tripleProduct(u, v).sign() <= 0) continue;

		// if it is visible, then copy the indices to the result.
		// Note that since the triangle is in counter-clockwise order viewed from the bottom, 
		// we have to reverse the order to get the counter-clockwise order viewed from the top.
		triangles.push_back(v0->id);
		triangles.push_back(v2->id);
		triangles.push_back(v1->id);
	}
}