Exemplo n.º 1
0
void dSceneRender::DrawCylinder(int segments, dFloat radius, dFloat heigh)
{
	dVector q0 ( heigh / 2.0f, radius, 0.0f, 0.0f);
	dVector q1 (-heigh / 2.0f, radius, 0.0f, 0.0f);
	dMatrix rotation (dPitchMatrix(2.0f * 3.1614f/segments));
	dVector cap0[1024];
	dVector cap1[1024];
	dAssert (segments < sizeof (cap0)/sizeof (cap0[0]));
	cap0[segments] = q0;
	cap1[segments] = q1;
	for (int i = 0; i < segments; i ++) {
		cap0[i] = q0;
		cap1[i] = q1;
		q0 = rotation.RotateVector(q0);
		q1 = rotation.RotateVector(q1);
	}
	dVector normal0 ( 1.0f, 0.0f, 0.0f, 0.0f);
	dVector normal1 (-1.0f, 0.0f, 0.0f, 0.0f);

	BeginTriangle();	
	for (int i = 2; i < segments; i ++) {
		SubmitNormal(normal0);
		DrawTriangle(cap0[0], cap0[i-1], cap0[i]);

		SubmitNormal(normal1);
		DrawTriangle(cap1[0], cap1[i], cap1[i - 1]);
	}

	for (int i = 0; i < segments; i ++) {
		dVector p0 (cap0[i]);
		dVector p1 (cap0[i + 1]);
		dVector p2 (cap1[i + 1]);
		dVector p3 (cap1[i]);

		dVector normal ((p1 - p0) * (p2 - p0));
		normal = normal.Scale (1.0f / dSqrt(normal % normal));

		SubmitNormal(normal);
		DrawTriangle(p0, p2, p1);

		SubmitNormal(normal);
		DrawTriangle(p0, p3, p2);
	}
	End();	
}
bool dgCollisionConvexHull::CheckConvex (dgPolyhedra& polyhedra1, const dgBigVector* hullVertexArray) const
{
	dgPolyhedra polyhedra(polyhedra1);

	dgPolyhedra::Iterator iter (polyhedra);
	dgBigVector center (dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f), dgFloat32 (0.0f));

	dgInt32 count = 0;
	dgInt32 mark = polyhedra.IncLRU();
	for (iter.Begin(); iter; iter ++) {
		dgEdge* const edge = &(*iter);
		if (edge->m_mark < mark) {
			count ++;
			center += hullVertexArray[edge->m_incidentVertex];
			dgEdge* ptr = edge;
			do {
				ptr->m_mark = mark;
				ptr = ptr->m_twin->m_next;
			} while (ptr != edge);
		}
	}
	center = center.Scale3 (dgFloat64 (1.0f) / dgFloat64 (count));

	for (iter.Begin(); iter; iter ++) {
		dgEdge* const edge = &(*iter);
		dgBigVector normal0 (FaceNormal (edge, hullVertexArray));
		dgBigVector normal1 (FaceNormal (edge->m_twin, hullVertexArray));

		dgBigPlane plane0 (normal0, - (normal0 % hullVertexArray[edge->m_incidentVertex]));
		dgBigPlane plane1 (normal1, - (normal1 % hullVertexArray[edge->m_twin->m_incidentVertex]));
		dgFloat64 test0 = plane0.Evalue(center);
		if (test0 > dgFloat64 (1.0e-3f)) {
			return false;
		}
		dgFloat64 test1 = plane1.Evalue(center);
//		if (test1 > dgFloat64 (0.0f)) {
		if (test1 > dgFloat64 (1.0e-3f)) {
			return false;
		}
	}

	return true;
}
Exemplo n.º 3
0
void MainWindow::createActions()
{
	openAct = new QAction("&Open", this);
	connect(openAct, SIGNAL(triggered()), this, SLOT(openAndReadFile()));

	exitAct = new QAction("E&xit", this);
    connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));

    aboutAct = new QAction("&About", this);
    connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));

    statAct = new QAction("&Stat", this);
    connect(statAct, SIGNAL(triggered()), this, SLOT(showStat()));

    resetAct = new QAction("&Reset position", this);
    resetAct->setStatusTip("Reset the position");
    connect(resetAct, SIGNAL(triggered()), this, SLOT(reset()));

    reseteffectAct = new QAction("&Reset", this);
    reseteffectAct->setStatusTip("Reset all material");
    connect(reseteffectAct, SIGNAL(triggered()), this, SLOT(reseteffect()));

    //ANIMATION-----------------------------------------------------
    animationShownAct = new QAction("&Shown", this);
    animationShownAct->setStatusTip("Show animation");
    animationShownAct->setCheckable(true);
    connect(animationShownAct, SIGNAL(triggered()), this, SLOT(showAnimation()));

    animationHiddenAct = new QAction("&Hidden", this);
    animationHiddenAct->setStatusTip("Hide animation");
    animationHiddenAct->setCheckable(true);
    connect(animationHiddenAct, SIGNAL(triggered()), this, SLOT(hideAnimation()));

    animationGroup = new QActionGroup(this);
    animationGroup->addAction(animationShownAct);
    animationGroup->addAction(animationHiddenAct);
    animationHiddenAct->setChecked(true);

    //COLOR-----------------------------------------------------
    color0Act = new QAction("&No light",this);
    color0Act->setStatusTip("No light");
    color0Act->setCheckable(true);
    connect(color0Act, SIGNAL(triggered()), this, SLOT(color0()));

    color1Act = new QAction("&Red",this);
    color1Act->setStatusTip("Red");
    color1Act->setCheckable(true);
    connect(color1Act, SIGNAL(triggered()), this, SLOT(color1()));

    color2Act = new QAction("&Green",this);
    color2Act->setStatusTip("Green");
    color2Act->setCheckable(true);
    connect(color2Act, SIGNAL(triggered()), this, SLOT(color2()));

    color3Act = new QAction("&Blue",this);
    color3Act->setStatusTip("Blue");
    color3Act->setCheckable(true);
    connect(color3Act, SIGNAL(triggered()), this, SLOT(color3()));

    color10Act = new QAction("&White",this);
    color10Act->setStatusTip("White");
    color10Act->setCheckable(true);
    connect(color10Act, SIGNAL(triggered()), this, SLOT(color10()));

    colorGroup = new QActionGroup(this);
    colorGroup->addAction(color0Act);
    colorGroup->addAction(color1Act);
    colorGroup->addAction(color2Act);
    colorGroup->addAction(color3Act);
    colorGroup->addAction(color10Act);
    color10Act->setChecked(true);

    //EFFECT-----------------------------------------------------
    effect0Act = new QAction("&No effect",this);
    effect0Act->setStatusTip("No effect");
    effect0Act->setCheckable(true);
    connect(effect0Act, SIGNAL(triggered()), this, SLOT(effect0()));

    effect1Act = new QAction("&Ambient",this);
    effect1Act->setStatusTip("Ambient");
    effect1Act->setCheckable(true);
    connect(effect1Act, SIGNAL(triggered()), this, SLOT(effect1()));

    effect2Act = new QAction("&Diffuse",this);
    effect2Act->setStatusTip("Diffuse");
    effect2Act->setCheckable(true);
    connect(effect2Act, SIGNAL(triggered()), this, SLOT(effect2()));

    effect10Act = new QAction("&All",this);
    effect10Act->setStatusTip("All effect");
    effect10Act->setCheckable(true);
    connect(effect10Act, SIGNAL(triggered()), this, SLOT(effect10()));

    effectGroup = new QActionGroup(this);
    effectGroup->addAction(effect0Act);
    effectGroup->addAction(effect1Act);
    effectGroup->addAction(effect2Act);
    effectGroup->addAction(effect10Act);
    effect10Act->setChecked(true);

    //AMBIENT-----------------------------------------------------
    ambient0Act = new QAction("&No Ambient",this);
    ambient0Act->setStatusTip("No Ambient");
    ambient0Act->setCheckable(true);
    connect(ambient0Act, SIGNAL(triggered()), this, SLOT(ambient0()));

    ambient1Act = new QAction("&Ambient",this);
    ambient1Act->setStatusTip("Ambient");
    ambient1Act->setCheckable(true);
    connect(ambient1Act, SIGNAL(triggered()), this, SLOT(ambient1()));

    ambient2Act = new QAction("&Ambient Color",this);
    ambient2Act->setStatusTip("Ambient Color");
    ambient2Act->setCheckable(true);
    connect(ambient2Act, SIGNAL(triggered()), this, SLOT(ambient2()));

    ambientGroup = new QActionGroup(this);
    ambientGroup->addAction(ambient0Act);
    ambientGroup->addAction(ambient1Act);
    ambientGroup->addAction(ambient2Act);
    ambient0Act->setChecked(true);

    //DIFFUSE-----------------------------------------------------
    diffuse0Act = new QAction("&No Diffuse",this);
    diffuse0Act->setStatusTip("No Diffuse");
    diffuse0Act->setCheckable(true);
    connect(diffuse0Act, SIGNAL(triggered()), this, SLOT(diffuse0()));

    diffuse1Act = new QAction("&Diffuse",this);
    diffuse1Act->setStatusTip("Diffuse");
    diffuse1Act->setCheckable(true);
    connect(diffuse1Act, SIGNAL(triggered()), this, SLOT(diffuse1()));

    diffuseGroup = new QActionGroup(this);
    diffuseGroup->addAction(diffuse0Act);
    diffuseGroup->addAction(diffuse1Act);
    diffuse0Act->setChecked(true);

    //SPECULAR-----------------------------------------------------
    specular0Act = new QAction("&No Specular",this);
    specular0Act->setStatusTip("No Specular");
    specular0Act->setCheckable(true);
    connect(specular0Act, SIGNAL(triggered()), this, SLOT(specular0()));

    specular1Act = new QAction("&Specular",this);
    specular1Act->setStatusTip("Specular");
    specular1Act->setCheckable(true);
    connect(specular1Act, SIGNAL(triggered()), this, SLOT(specular1()));

    specularGroup = new QActionGroup(this);
    specularGroup->addAction(specular0Act);
    specularGroup->addAction(specular1Act);
    specular0Act->setChecked(true);

    //SPECULAR-----------------------------------------------------
    shininess0Act = new QAction("&No Shininess",this);
    shininess0Act->setStatusTip("No Shininess");
    shininess0Act->setCheckable(true);
    connect(shininess0Act, SIGNAL(triggered()), this, SLOT(shininess0()));

    shininess1Act = new QAction("&Low Shininess",this);
    shininess1Act->setStatusTip("Low Shininess");
    shininess1Act->setCheckable(true);
    connect(shininess1Act, SIGNAL(triggered()), this, SLOT(shininess1()));

    shininess2Act = new QAction("&High Shininess",this);
    shininess2Act->setStatusTip("High Shininess");
    shininess2Act->setCheckable(true);
    connect(shininess2Act, SIGNAL(triggered()), this, SLOT(shininess2()));

    shininessGroup = new QActionGroup(this);
    shininessGroup->addAction(shininess0Act);
    shininessGroup->addAction(shininess1Act);
    shininessGroup->addAction(shininess2Act);
    shininess0Act->setChecked(true);

    //EMISSION-----------------------------------------------------
    emission0Act = new QAction("&No Emission",this);
    emission0Act->setStatusTip("No Emission");
    emission0Act->setCheckable(true);
    connect(emission0Act, SIGNAL(triggered()), this, SLOT(emission0()));

    emission1Act = new QAction("&Emission",this);
    emission1Act->setStatusTip("eEmission");
    emission1Act->setCheckable(true);
    connect(emission1Act, SIGNAL(triggered()), this, SLOT(emission1()));

    emissionGroup = new QActionGroup(this);
    emissionGroup->addAction(emission0Act);
    emissionGroup->addAction(emission1Act);
    emission0Act->setChecked(true);

    //SHADING-------------------------------------------------
    shading0Act = new QAction("&No shading", this);
    shading0Act->setStatusTip("No shading");
    shading0Act->setCheckable(true);
    connect(shading0Act, SIGNAL(triggered()), this, SLOT(shading0()));

    shading1Act = new QAction("&Flat shading", this);
    shading1Act->setStatusTip("Flat shading");
    shading1Act->setCheckable(true);
    connect(shading1Act, SIGNAL(triggered()), this, SLOT(shading1()));

    shading2Act = new QAction("&Smooth shading", this);
    shading2Act->setStatusTip("Smooth shading");
    shading2Act->setCheckable(true);
    connect(shading2Act, SIGNAL(triggered()), this, SLOT(shading2()));

    shadingGroup = new QActionGroup(this);
    shadingGroup->addAction(shading0Act);
    shadingGroup->addAction(shading1Act);
    shadingGroup->addAction(shading2Act);
    shading0Act->setChecked(true);

    //NORMAL----------------------------------------------------
    normal0Act = new QAction("&No normal",this);
    normal0Act->setStatusTip("No normal");
    normal0Act->setCheckable(true);
    connect(normal0Act, SIGNAL(triggered()), this, SLOT(normal0()));

    normal1Act = new QAction("&normal",this);
    normal1Act->setStatusTip("Has normal");
    normal1Act->setCheckable(true);
    connect(normal1Act, SIGNAL(triggered()), this, SLOT(normal1()));

    normalGroup = new QActionGroup(this);
    normalGroup->addAction(normal0Act);
    normalGroup->addAction(normal1Act);
    normal0Act->setChecked(true);
}
bool dgCollisionConvexHull::RemoveCoplanarEdge (dgPolyhedra& polyhedra, const dgBigVector* const hullVertexArray) const
{
	bool removeEdge = false;
	// remove coplanar edges
	dgInt32 mark = polyhedra.IncLRU();
	dgPolyhedra::Iterator iter (polyhedra);
	for (iter.Begin(); iter; ) {
		dgEdge* edge0 = &(*iter);
		iter ++;

		if (edge0->m_incidentFace != -1) {

			if (edge0->m_mark < mark) {
				edge0->m_mark = mark;
				edge0->m_twin->m_mark = mark;
				dgBigVector normal0 (FaceNormal (edge0, &hullVertexArray[0]));
				dgBigVector normal1 (FaceNormal (edge0->m_twin, &hullVertexArray[0]));

				dgFloat64 test = normal0 % normal1;
				if (test > dgFloat64 (0.99995f)) {

					if ((edge0->m_twin->m_next->m_twin->m_next != edge0) && (edge0->m_next->m_twin->m_next != edge0->m_twin)) {
						#define DG_MAX_EDGE_ANGLE dgFloat32 (1.0e-3f)

						if (edge0->m_twin == &(*iter)) {
							if (iter) {
								iter ++;
							}
						}

						dgBigVector e1 (hullVertexArray[edge0->m_twin->m_next->m_next->m_incidentVertex] - hullVertexArray[edge0->m_incidentVertex]);
						dgBigVector e0 (hullVertexArray[edge0->m_incidentVertex] - hullVertexArray[edge0->m_prev->m_incidentVertex]);

						dgAssert ((e0 % e0) >= dgFloat64 (0.0f));
						dgAssert ((e1 % e1) >= dgFloat64 (0.0f));

						e0 = e0.Scale3 (dgFloat64 (1.0f) / sqrt (e0 % e0));
						e1 = e1.Scale3 (dgFloat64 (1.0f) / sqrt (e1 % e1));
						dgBigVector n1 (e0 * e1);

						dgFloat64 projection = n1 % normal0;
						if (projection >= DG_MAX_EDGE_ANGLE) {

							dgBigVector e1 (hullVertexArray[edge0->m_next->m_next->m_incidentVertex] - hullVertexArray[edge0->m_twin->m_incidentVertex]);
							dgBigVector e0 (hullVertexArray[edge0->m_twin->m_incidentVertex] - hullVertexArray[edge0->m_twin->m_prev->m_incidentVertex]);
							dgAssert ((e0 % e0) >= dgFloat64 (0.0f));
							dgAssert ((e1 % e1) >= dgFloat64 (0.0f));
							//e0 = e0.Scale3 (dgRsqrt (e0 % e0));
							//e1 = e1.Scale3 (dgRsqrt (e1 % e1));
							e0 = e0.Scale3 (dgFloat64 (1.0f) / sqrt (e0 % e0));
							e1 = e1.Scale3 (dgFloat64 (1.0f) / sqrt (e1 % e1));

							dgBigVector n1 (e0 * e1);
							projection = n1 % normal0;
							if (projection >= DG_MAX_EDGE_ANGLE) {
								dgAssert (&(*iter) != edge0);
								dgAssert (&(*iter) != edge0->m_twin);
								polyhedra.DeleteEdge(edge0);
								removeEdge = true;
							}
						}

					} else {
						dgEdge* next = edge0->m_next;
						dgEdge* prev = edge0->m_prev;
						polyhedra.DeleteEdge(edge0);
						for (edge0 = next; edge0->m_prev->m_twin == edge0; edge0 = next) {
							next = edge0->m_next;
							polyhedra.DeleteEdge(edge0);
						}

						for (edge0 = prev; edge0->m_next->m_twin == edge0; edge0 = prev) {
							prev = edge0->m_prev;
							polyhedra.DeleteEdge(edge0);
						}
						iter.Begin(); 
						removeEdge = true;
					}
				}
			}
		}
	}

	return removeEdge;
}
void ShapeParabolicRectangle::generatePrimitives(SoAction *action)
{
    SoPrimitiveVertex   pv;
    SoState  *state = action->getState();

    SbBool useTexFunc = ( SoTextureCoordinateElement::getType(state) ==
                          SoTextureCoordinateElement::FUNCTION );

    const SoTextureCoordinateElement* tce = 0;
    if ( useTexFunc ) tce = SoTextureCoordinateElement::getInstance(state);


    SbVec3f  point;
 	const int rows = 12; // Number of points per row
    const int columns = 12; // Number of points per column
    const int totalPoints = (rows)*(columns); // Total points in the grid

    float vertex[totalPoints][6];

    int h = 0;
    double ui = 0;
	double vj = 0;

    for (int i = 0; i < rows; ++i )
    {
    	ui =( 1.0 /(double)(rows-1) ) * i;

    	for ( int j = 0 ; j < columns ; ++j )
    	{
    		vj = ( 1.0 /(double)(columns-1) ) * j;

    		Point3D point = GetPoint3D(ui, vj);
    		NormalVector normal;
    		if( activeSide.getValue() == 0 )	normal = -GetNormal(ui, vj);
    		else	normal = GetNormal(ui, vj);

    		vertex[h][0] = point.x;
    		vertex[h][1] = point.y;
    		vertex[h][2] = point.z;
    		vertex[h][3] = normal.x;
    		vertex[h][4] = normal.y;
    		vertex[h][5] = normal.z;

    		pv.setPoint( vertex[h][0], vertex[h][1], vertex[h][2] );
    		h++; //Increase h to the next point.

    	}
    }

    float u = 1;
    float v = 1;
    beginShape(action, QUADS );
	for( int irow = 0; irow < (rows-1); ++irow )
	{
		for( int icolumn = 0; icolumn < (columns-1); ++icolumn )
		{
			int index0 = irow*columns + icolumn;
			SbVec3f  point0( vertex[index0][0], vertex[index0][1],  vertex[index0][2] );
			SbVec3f normal0(vertex[index0][3], vertex[index0][4], vertex[index0][5] );
			SbVec4f texCoord0 = useTexFunc ? tce->get(point0, normal0): SbVec4f( u,v, 0.0, 1.0 );
			pv.setPoint(point0);
			pv.setNormal(normal0);
			pv.setTextureCoords(texCoord0);
			shapeVertex(&pv);

			int index1 = index0 + 1;
			SbVec3f  point1( vertex[index1][0], vertex[index1][1],  vertex[index1][2] );
			SbVec3f normal1(vertex[index1][3], vertex[index1][4], vertex[index1][5] );
			SbVec4f texCoord1 = useTexFunc ? tce->get(point1, normal1): SbVec4f( u,v, 0.0, 1.0 );
			pv.setPoint(point1);
			pv.setNormal(normal1);
			pv.setTextureCoords(texCoord1);
			shapeVertex(&pv);

			int index3 = index0 + columns;
			int index2 = index3 + 1;

			SbVec3f  point2( vertex[index2][0], vertex[index2][1],  vertex[index2][2] );
			SbVec3f normal2(vertex[index2][3], vertex[index2][4], vertex[index2][5] );
			SbVec4f texCoord2 = useTexFunc ? tce->get(point2, normal2): SbVec4f( u,v, 0.0, 1.0 );
			pv.setPoint(point2);
			pv.setNormal(normal2);
			pv.setTextureCoords(texCoord2);
			shapeVertex(&pv);

			SbVec3f  point3( vertex[index3][0], vertex[index3][1],  vertex[index3][2] );
			SbVec3f normal3(vertex[index3][3], vertex[index3][4], vertex[index3][5] );
			SbVec4f texCoord3 = useTexFunc ? tce->get(point3, normal3): SbVec4f( u,v, 0.0, 1.0 );
			pv.setPoint(point3);
			pv.setNormal(normal3);
			pv.setTextureCoords(texCoord3);
			shapeVertex(&pv);

		}
	}

	endShape();

}