示例#1
0
void ClippingShader::setClipPlaneParamsNormal(unsigned int id, Geom::Vec3f normal)
{
	// Check if the given id is valid
	if (errorRaiseWrongId(!isClipPlaneIdValid(id), "ClippingShader::setClipPlaneParamsFirstVec"))
		return;

	// Get the corresponding plane index
	int planeIndex = m_clipPlanesIds[id].index;

	// Normalize
	Geom::Vec3f normalNormalized = normal;
	normalNormalized.normalize();

	// Check if it is worth updating values !
	if (normalNormalized == m_clipPlanes[planeIndex].normal)
		return;

	// Copy the given clipping plane parameter
	m_clipPlanes[planeIndex].normal = normalNormalized;

	// Update the plane arrays
	updateClipPlaneUniformsArray(id);

	// Send again the whole planes equations array to shader
	sendClipPlanesEquationsUniform();
}
ClippingPresetAnimatedSpheresCubeCollision::ClippingPresetAnimatedSpheresCubeCollision(Geom::Vec3f center, float size, int spheresCount, float radius)
{
	// Store animation settings
	m_cubeCenter = center;
	m_cubeSize = size;
	int usedSpheresCount = spheresCount;
	if (usedSpheresCount < 1)
		usedSpheresCount = 1;

	// Add spheres to preset
	for (int i = 0; i < usedSpheresCount; i++)
		addClipSphere(m_cubeCenter, radius);

	// Store spheres random directions
	m_spheresDirections.resize(usedSpheresCount);
	srand(time(NULL));
	for (size_t i = 0; i < m_spheresDirections.size(); i++)
	{
		Geom::Vec3f dir ((rand() % 1000) - 500, (rand() % 1000) - 500, (rand() % 1000) - 500);
		dir.normalize();
		m_spheresDirections[i] = dir;
	}

	// Set clipping mode
	setClippingMode(ClippingShader::CLIPPING_MODE_AND);
}
示例#3
0
int main(int argc, char **argv)
{


	// interface:
	QApplication app(argc, argv);
	MyQT sqt;

	if (argc>1)
		sqt.NBP = atoi(argv[1]);


	sqt.setHelpMsg("Param :size of grid (number of objects)\nMpuse (with shift):\n"
			" -click on object: selection\n -left click on frame: constraint 3d Rotation/Translation/Scale\n"
			" -right click on frame :free 2D Rotation/Translation\nKeys:\n  x/y/z lock/unlock translation\n  a/b/c lock/unlock rotation\n   s/t/u lock/unlock scaling");

    //  bounding box
    Geom::Vec3f lPosObj = Geom::Vec3f(0.0f,0.0f,0.0f);
    float lWidthObj = sqt.NBP*4.0f;

    // envoit info BB a l'interface
	sqt.setParamObject(lWidthObj,lPosObj.data());

	// show final pour premier redraw
	sqt.show();

	// et on attend la fin.
	return app.exec();

	return 0;
}
示例#4
0
void MyQT::createMap()
{
//	Dart d1 = Algo::Modelisation::createTetrahedron<PFP>(myMap);

//	Dart d2 = d1;

	position = myMap.addAttribute<PFP::VEC3, VERTEX>("position");

	Algo::Modelisation::Polyhedron<PFP> prim1(myMap, position);
	prim1.cylinder_topo(256, 256, true, true); // topo of sphere is a closed cylinder
	prim1.embedSphere(2.0f);

//	Dart d2 = d1;
//	position[d2] = PFP::VEC3(1, 0, 0);
//	d2 = PHI1(d2);
//	position[d2] = PFP::VEC3(-1, 0, 0);
//	d2 = PHI1(d2);
//	position[d2] = PFP::VEC3(0, 2, 0);
//	d2 = PHI<211>(d2);
//	position[d2] = PFP::VEC3(0, 1, 2);

	Algo::Modelisation::Polyhedron<PFP> prim2(myMap, position);
	prim2.cylinder_topo(256, 256, true, true); // topo of sphere is a closed cylinder
	prim2.embedSphere(2.0f);

	Geom::Matrix44f trf;
	trf.identity();
	Geom::translate<float>(5.0f, 0.0, 0.0, trf);
	prim2.transform(trf);

	xd1 = prim2.getDart();

//	xd1 = Algo::Modelisation::Polyhedron<PFP>::createTetra(myMap);
//	Dart xd2 = xd1;
//
//	position[xd2] = PFP::VEC3(5, 0, 0);
//	xd2 = PHI1(xd2);
//	position[xd2] = PFP::VEC3(3, 0, 0);
//	xd2 = PHI1(xd2);
//	position[xd2] = PFP::VEC3(4, 2, 0);
//	xd2 = PHI<211>(xd2);
//	position[xd2] = PFP::VEC3(4, 1, 2);

    //  bounding box of scene
    Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
    float lWidthObj = std::max<PFP::REAL>(std::max<PFP::REAL>(bb.size(0), bb.size(1)), bb.size(2));
    Geom::Vec3f lPosObj = (bb.min() +  bb.max()) / PFP::REAL(2);

    // send BB info to interface for centering on GL screen
	setParamObject(lWidthObj, lPosObj.data());

	// first show for be sure that GL context is binded
	show();

	// 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);
}
示例#5
0
void Topo3PrimalRender<PFP>::toSVG(Utils::SVG::SVGOut& svg)
{
	// alpha2
	Utils::SVG::SvgGroup* svg2 = new Utils::SVG::SvgGroup("alpha2", svg.m_model, svg.m_proj);
	Geom::Vec3f* ptr = reinterpret_cast<Geom::Vec3f*>(m_vbo1->lockPtr());
	svg2->setWidth(m_topo_relation_width);
	svg2->beginLines();
	for (unsigned int i=0; i<m_nbRel2; ++i)
	{
		Geom::Vec3f P = ptr[2*i];
		Geom::Vec3f Q = ptr[2*i+1];
		svg2->addLine(P, Q, Geom::Vec3f(0.8f,0.0f,0.0f));
	}
	svg2->endLines();
	m_vbo1->releasePtr();
	svg.addGroup(svg2);

	const Geom::Vec3f* colorsPtr = reinterpret_cast<const Geom::Vec3f*>(m_vbo2->lockPtr());
	ptr= reinterpret_cast<Geom::Vec3f*>(m_vbo0->lockPtr());

	Utils::SVG::SvgGroup* svg4 = new Utils::SVG::SvgGroup("darts", svg.m_model, svg.m_proj);
	svg4->setWidth(m_topo_dart_width);

	svg4->beginLines();
	for (unsigned int i=0; i<m_nbDarts; ++i)
	{
		Geom::Vec3f col = colorsPtr[2*i];
		if (col.norm2()>2.9f)
			col = Geom::Vec3f(1.0f,1.0f,1.0f) - col;
		svg4->addLine(ptr[2*i], ptr[2*i+1], col);
	}
	svg4->endLines();

	svg.addGroup(svg4);

	Utils::SVG::SvgGroup* svg5 = new Utils::SVG::SvgGroup("dartEmb", svg.m_model, svg.m_proj);
	svg5->setWidth(m_topo_dart_width);
	svg5->beginPoints();
	for (unsigned int i=0; i<m_nbDarts; ++i)
	{
		Geom::Vec3f col = colorsPtr[2*i];
		if (col.norm2()>2.9f)
			col = Geom::Vec3f(1.0f,1.0f,1.0f) - col;
		svg5->addPoint(ptr[2*i], col);
	}
	svg5->endPoints();
	svg.addGroup(svg5);

	m_vbo0->releasePtr();
	m_vbo2->releasePtr();

}
void ShaderExplodeSmoothVolumes::setLightPosition(const Geom::Vec3f& lp)
{
	m_light_pos = lp;
	bind();
	glUniform3fv(*m_unif_lightPos,1,lp.data());
	unbind();
}
示例#7
0
void ShaderPhong::setLightPosition(const Geom::Vec3f& lightPos)
{
    bind();
    glUniform3fv(*m_unif_lightPos,1,lightPos.data());
    m_lightPos = lightPos;
    unbind();
}
示例#8
0
void ShaderPhong::setEyePosition(const Geom::Vec3f& eyePos)
{
    if (m_with_eyepos)
    {
        bind();
        glUniform3fv(*m_unif_eyePos,1,eyePos.data());
        m_eyePos = eyePos;
        unbind();
    }
}
示例#9
0
void Strings3D::predraw(const Geom::Vec3f& color)
{
    bind();
    glUniform1i(*m_uniform_texture, 0);
    glUniform3fv(*m_uniform_color, 1, color.data());

    glActiveTextureARB(GL_TEXTURE0_ARB);
    glBindTexture(GL_TEXTURE_2D, *m_idTexture);
    glEnable(GL_TEXTURE_2D);

    glDisable(GL_LIGHTING);

    enableVertexAttribs();
}
示例#10
0
文件: tuto1.cpp 项目: Peiffert/CGoGN
void MyQT::createMap()
{
	// 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, MAP>("position");

	// creation of 2 new faces: 1 triangle and 1 square
	Dart d1 = myMap.newFace(3);
	Dart d2 = myMap.newFace(4);

	// sew these faces along one of their edge
	myMap.sewFaces(d1, d2);

	// 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);

    //  bounding box of scene
    Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
    float lWidthObj = std::max<PFP::REAL>(std::max<PFP::REAL>(bb.size(0), bb.size(1)), bb.size(2));
    Geom::Vec3f lPosObj = (bb.min() +  bb.max()) / PFP::REAL(2);

	show();
    // send BB info to interface for centering on GL screen
	setParamObject(lWidthObj, lPosObj.data());

	// first show for be sure that GL context is binded
	show();

	// render the topo of the map without boundary darts
	m_render_topo->setInitialBoundaryDartsColor(0,1,0);
	m_render_topo->updateDataGMap<PFP>(myMap, position, 0.9f, 0.9f,true);
}
void ShaderExplodeSmoothVolumes::setParams(float explV, float explF, const Geom::Vec4f& ambiant, const Geom::Vec3f& lightPos, const Geom::Vec4f& plane)
{
	bind();
	m_explodeV = explV;
	glUniform1f(*m_unif_explodeV, explV);
	m_explodeF = explF;
	glUniform1f(*m_unif_explodeF, explF);
	m_ambiant = ambiant;
	glUniform4fv(*m_unif_ambiant, 1, ambiant.data());
	m_light_pos = lightPos;
	glUniform3fv(*m_unif_lightPos, 1, lightPos.data());

	m_plane = plane;
	glUniform4fv(*m_unif_plane,    1, m_plane.data());

	unbind();
}
示例#12
0
void Strings3D::draw(unsigned int idSt, const Geom::Vec3f& pos)
{
    glUniform3fv(*m_uniform_position, 1, pos.data());
    glDrawArrays(GL_QUADS, m_strpos[idSt].first , m_strpos[idSt].second );
}
示例#13
0
int main(int argc, char **argv)
{
	position = myMap.addAttribute<VEC3, VERTEX>("position");

	Dart d0 = myMap.newFace(12);
	position[d0] = PFP::VEC3(0, 20, 0);
	d0 = myMap.phi1(d0);
	position[d0] = PFP::VEC3(10, 20, 0);
	d0 = myMap.phi1(d0);
	position[d0] = PFP::VEC3(10, 30, 0);
	Dart dx = myMap.phi1(d0);
	d0 = myMap.phi<11>(dx);
	position[d0] = PFP::VEC3(8, 27, 0);
	d0 = myMap.phi1(d0);
	position[d0] = PFP::VEC3(8, 22, 0);
	d0 = myMap.phi1(d0);
	position[d0] = PFP::VEC3(2, 22, 0);
	d0 = myMap.phi1(d0);
	position[d0] = PFP::VEC3(2, 27, 0);
	d0 = myMap.phi1(d0);
	myMap.sewFaces(d0,dx);
	position[d0] = PFP::VEC3(5, 27, 0);
	d0 = myMap.phi1(d0);
	position[d0] = PFP::VEC3(5, 30, 0);
	d0 = myMap.phi1(d0);
	position[d0] = PFP::VEC3(0, 30, 0);

	d0 = myMap.newFace(4);
	position[d0] = PFP::VEC3(-5, 14, -5);
	d0 = myMap.phi1(d0);
	position[d0] = PFP::VEC3(0, 18, -5);
	d0 = myMap.phi1(d0);
	position[d0] = PFP::VEC3(5, 14, -5);
	d0 = myMap.phi1(d0);
	position[d0] = PFP::VEC3(0, 20, -5);
	d0 = myMap.phi1(d0);

	Dart d1 = myMap.newFace(10);

	position[d1] = PFP::VEC3(0, 0, 0);
	d1 = myMap.phi1(d1);

	position[d1] = PFP::VEC3(2, 4, 0);
	d1 = myMap.phi1(d1);
	position[d1] = PFP::VEC3(4, 0, 0);
	d1 = myMap.phi1(d1);

	position[d1] = PFP::VEC3(10, 0, 0);
	d1 = myMap.phi1(d1);

	position[d1] = PFP::VEC3(4, 2, 0);
	d1 = myMap.phi1(d1);
	position[d1] = PFP::VEC3(14, 6, 0);
	d1 = myMap.phi1(d1);
	position[d1] = PFP::VEC3(6, 16, 0);
	d1 = myMap.phi1(d1);

	position[d1] = PFP::VEC3(8, 8, 0);
	d1 = myMap.phi1(d1);
	position[d1] = PFP::VEC3(4, 4, 0);
	d1 = myMap.phi1(d1);
	position[d1] = PFP::VEC3(0, 8, 0);

	Dart d2 = myMap.newFace(12);

	position[d2] = PFP::VEC3(0, -20, 0);
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(4, -20, 0);
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(8, -20, 0);
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(12, -20, 0);
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(12, -16, 0);
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(12, -12, 0);
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(12, -8, 0);
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(8, -8, 0);
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(4, -8, 0);
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(0, -8, 0);
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(0, -12, 0);
	d2 = myMap.phi1(d2);
	position[d2] = PFP::VEC3(0, -16, 0);
	d2 = myMap.phi1(d2);

#define NB 32

	//SPIRAL

	Dart d3 = myMap.newFace(NB*2);

	for (int i = 0; i<NB; ++i)
	{
		float z = 3.0f*float(rand()-RAND_MAX/2)/float(RAND_MAX);
		float alpha = (4.0f*6.283f / NB)*i;
		float radius = 1.2f*(NB-i);
		position[d3] = PFP::VEC3(radius*cos(alpha) -  2*NB+8, radius*sin(alpha), z);
		d3 = myMap.phi1(d3);
	}

	for (int i = NB-1; i>=0; --i)
	{
		float z = 3.0f*float(rand()-RAND_MAX/2)/float(RAND_MAX);
		float alpha = (4.0f*6.283f / NB)*i;
		float radius = (NB-i);
		position[d3] = PFP::VEC3(radius*cos(alpha) -  2*NB+8, radius*sin(alpha), z);
		d3 = myMap.phi1(d3);
	}

	//CIRCLE

	Dart d6 = myMap.newFace(NB);
	for (int i = 0; i<NB; ++i)
	{
		float z = 3.0f*float(rand()-RAND_MAX/2)/float(RAND_MAX);
		float alpha = (6.283f / NB)*i;
		float radius = NB;
		position[d6] = PFP::VEC3(radius*cos(alpha) + 2*NB+8, radius*sin(alpha), z);
		d6 = myMap.phi1(d6);
	}

// pour comparer les 2 versions (oreille et basique)
//#define NBB 100
//	for (int j = 0; j<10000; ++j)
//	{
//		Dart d6 = myMap.newFace(NBB);
//		for (int i = 0; i<NBB; ++i)
//		{
//			float alpha = (6.283f / NB)*i;
//			float radius = NB;
//			position[d6] = PFP::VEC3(radius*cos(alpha) + 2*NB+8, radius*sin(alpha), 0.1f*j);
//			d6 = myMap.phi1(d6);
//		}
//	}

	Geom::Vec3f V1(3,3,3);
	V1.normalize();
	Geom::Vec3f V2 = V1 ^ Geom::Vec3f(0,0,-1);
	Geom::Vec3f V3 = V1 ^ V2;

	V1 *= 50.0f;
	V2 *= 50.0f;

	Dart d5 = myMap.newFace(74);
	for (int i=0; i<74;++i)
	{
		float a = float(rand()-RAND_MAX/2)/float(RAND_MAX) * 0.25f;
		position[d5] = PFP::VEC3(0.0,60.0,0.0f) + Ifont[2*i] * V1 + Ifont[2*i+1]*V2 + a*V3;
		d5 = myMap.phi1(d5);
	}
	Dart d9 = myMap.newFace(174);
	for (int i=0; i<174;++i)
	{
		float a = float(rand()-RAND_MAX/2)/float(RAND_MAX) * 0.25f;
		position[d9] = PFP::VEC3(60.0,60.0,0.0f) + Gfont[2*i] * V1 + Gfont[2*i+1]*V2 + a*V3;
		d9 = myMap.phi1(d9);
	}

	// interface:
	QApplication app(argc, argv);
	MyQT sqt;


	// message d'aide
	sqt.setHelpMsg("Concave face rendering (ears method):\n"
			"a show all trianglesfaces\n"
			"a show none trianglesfaces\n"
			"+ / - show trinagles order rendering (ears creation)");

    //  bounding box
    Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
    float lWidthObj = std::max<PFP::REAL>(std::max<PFP::REAL>(bb.size(0), bb.size(1)), bb.size(2));
    Geom::Vec3f lPosObj = (bb.min() +  bb.max()) / PFP::REAL(2);

    // envoit info BB a l'interface
	sqt.setParamObject(lWidthObj, lPosObj.data());

	// show 1 pour GL context
	sqt.show();

	// update du VBO position (context GL necessaire)
	sqt.m_positionVBO->updateData(position);

	// update des primitives du renderer
	sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::TRIANGLES, &position);
	sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::LINES, &position);
	sqt.m_render->initPrimitives<PFP>(myMap, allDarts, Algo::Render::GL2::POINTS, &position);

//	 show final pour premier redraw
	sqt.show();

	// et on attend la fin.
	return app.exec();
}
示例#14
0
void Topo3Render::toSVG(Utils::SVG::SVGOut& svg)
{

	// PHI3 / beta3
	Utils::SVG::SvgGroup* svg1 = new Utils::SVG::SvgGroup("phi3", svg.m_model, svg.m_proj);
	const Geom::Vec3f* ptr = reinterpret_cast<Geom::Vec3f*>(m_vbo3->lockPtr());
	svg1->setWidth(m_topo_relation_width);
	svg1->beginLines();
	for (unsigned int i=0; i<m_nbRel3; ++i)
	{
		Geom::Vec3f P = (ptr[4*i]+ ptr[4*i+3])/2.0f;
		Geom::Vec3f Q = (ptr[4*i+1]+ ptr[4*i+2])/2.0f;
		svg1->addLine(P, Q,Geom::Vec3f(0.8f,0.8f,0.0f));
	}
	svg1->endLines();
	m_vbo3->releasePtr();

	svg.addGroup(svg1);

	// PHI2 / beta2
	Utils::SVG::SvgGroup* svg2 = new Utils::SVG::SvgGroup("phi2", svg.m_model, svg.m_proj);
	ptr = reinterpret_cast<Geom::Vec3f*>(m_vbo2->lockPtr());
	svg2->setWidth(m_topo_relation_width);
	svg2->beginLines();
	for (unsigned int i=0; i<m_nbRel2; ++i)
	{
		Geom::Vec3f P = (ptr[4*i]+ ptr[4*i+3])/2.0f;
		Geom::Vec3f Q = (ptr[4*i+1]+ ptr[4*i+2])/2.0f;
		svg2->addLine(P, Q,Geom::Vec3f(0.8f,0.0f,0.0f));
	}
	svg2->endLines();
	m_vbo2->releasePtr();

	svg.addGroup(svg2);

	//PHI1 /beta1
	Utils::SVG::SvgGroup* svg3 = new Utils::SVG::SvgGroup("phi1", svg.m_model, svg.m_proj);
	ptr = reinterpret_cast<Geom::Vec3f*>(m_vbo1->lockPtr());
	svg3->setWidth(m_topo_relation_width);
	svg3->beginLines();
	for (unsigned int i=0; i<m_nbRel1; ++i)
		svg3->addLine(ptr[2*i], ptr[2*i+1],Geom::Vec3f(0.0f,0.7f,0.7f));
	svg3->endLines();
	m_vbo1->releasePtr();

	svg.addGroup(svg3);

	const Geom::Vec3f* colorsPtr = reinterpret_cast<const Geom::Vec3f*>(m_vbo4->lockPtr());
	ptr= reinterpret_cast<Geom::Vec3f*>(m_vbo0->lockPtr());

	Utils::SVG::SvgGroup* svg4 = new Utils::SVG::SvgGroup("darts", svg.m_model, svg.m_proj);
	svg4->setWidth(m_topo_dart_width);

	svg4->beginLines();
	for (unsigned int i=0; i<m_nbDarts; ++i)
	{
		Geom::Vec3f col = colorsPtr[2*i];
		if (col.norm2()>2.9f)
			col = Geom::Vec3f(1.0f,1.0f,1.0f) - col;
		svg4->addLine(ptr[2*i], ptr[2*i+1], col);
	}
	svg4->endLines();

	svg.addGroup(svg4);

	Utils::SVG::SvgGroup* svg5 = new Utils::SVG::SvgGroup("dartEmb", svg.m_model, svg.m_proj);
	svg5->setWidth(m_topo_dart_width);
	svg5->beginPoints();
	for (unsigned int i=0; i<m_nbDarts; ++i)
	{
		Geom::Vec3f col = colorsPtr[2*i];
		if (col.norm2()>2.9f)
			col = Geom::Vec3f(1.0f,1.0f,1.0f) - col;
		svg5->addPoint(ptr[2*i], col);
	}
	svg5->endPoints();

	svg.addGroup(svg5);

	m_vbo0->releasePtr();
	m_vbo4->releasePtr();
}