firstPlugin.cpp 1.82 KB
Newer Older
Pierre Kraemer's avatar
Pierre Kraemer committed
1 2 3
#include "firstPlugin.h"
#include "Algo/Geometry/boundingbox.h"

4 5 6 7 8 9
void FirstPlugin::cb_initGL(Scene* scene)
{
	if(scene)
	{
		// we fit the first (possibly the only) view of the newly liked
		// scene to the content of our map
Pierre Kraemer's avatar
Pierre Kraemer committed
10

11 12
		// bounding box of scene
		Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
Pierre Kraemer's avatar
Pierre Kraemer committed
13

14
		scene->firstViewFitSphere(bb.center()[0], bb.center()[1], bb.center()[2], bb.maxSize());
Pierre Kraemer's avatar
Pierre Kraemer committed
15

16
		m_render_topo = new Algo::Render::GL2::TopoRender() ;
Pierre Kraemer's avatar
Pierre Kraemer committed
17

18 19 20
		// render the topo of the map without boundary darts
		SelectorDartNoBoundary<PFP::MAP> nb(myMap);
		m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.9f, nb);
Pierre Kraemer's avatar
Pierre Kraemer committed
21 22 23
	}
}

24 25
void FirstPlugin::cb_redraw(Scene* scene)
{
Pierre Kraemer's avatar
Pierre Kraemer committed
26 27 28
	m_render_topo->drawTopo();
}

29 30 31 32 33
bool FirstPlugin::activate()
{
	// creation of 2 new faces: 1 triangle and 1 square
	Dart d1 = myMap.newFace(3);
	Dart d2 = myMap.newFace(4);
Pierre Kraemer's avatar
Pierre Kraemer committed
34

35 36
	// sew these faces along one of their edge
	myMap.sewFaces(d1, d2);
Pierre Kraemer's avatar
Pierre Kraemer committed
37

38 39 40
	// creation of a new attribute on vertices of type 3D vector for position.
	// a handler to this attribute is returned
	position = myMap.addAttribute<VEC3, VERTEX>("position");
Pierre Kraemer's avatar
Pierre Kraemer committed
41

42 43 44 45 46 47
	// affect position by moving in the map
	position[d1] = VEC3(0, 0, 0);
	position[PHI1(d1)] = VEC3(2, 0, 0);
	position[PHI_1(d1)] = VEC3(1, 2, 0);
	position[PHI<11>(d2)] = VEC3(0, -2, 0);
	position[PHI_1(d2)] = VEC3(2, -2, 0);
Pierre Kraemer's avatar
Pierre Kraemer committed
48

49
	m_render_topo=NULL;
Pierre Kraemer's avatar
Pierre Kraemer committed
50

51 52
	return true;
}
Pierre Kraemer's avatar
Pierre Kraemer committed
53

54 55 56 57 58
void FirstPlugin::disable()
{
	if(m_render_topo)
	{
		delete m_render_topo;
Pierre Kraemer's avatar
Pierre Kraemer committed
59 60 61 62 63 64 65 66
	}
}

/**
 * If we want to compile this plugin in debug mode,
 * we also define a DEBUG macro at the compilation
 */
#ifndef DEBUG
67 68
	// essential Qt function:
	// arguments are
Pierre Kraemer's avatar
Pierre Kraemer committed
69 70 71 72 73 74
	//	- the complied name of the plugin
	//	- the main class of our plugin (that extends VisualPlugin)
	Q_EXPORT_PLUGIN2(FirstPlugin, FirstPlugin)
#else
	Q_EXPORT_PLUGIN2(FirstPluginD, FirstPlugin)
#endif