Example #1
0
	void Gizmos::addCube(const glm::vec3& center, const glm::vec3& extents, const glm::vec3& color)
	{
		glm::vec3 p100(-extents.x, extents.y, extents.z);
		glm::vec3 p101(-extents.x, extents.y, -extents.z);
		glm::vec3 p110(-extents.x, -extents.y, extents.z);
		glm::vec3 p111(-extents.x, -extents.y, -extents.z);
		glm::vec3 p000(extents.x, extents.y, extents.z);
		glm::vec3 p001(extents.x, extents.y, -extents.z);
		glm::vec3 p010(extents.x, -extents.y, extents.z);
		glm::vec3 p011(extents.x, -extents.y, -extents.z);
		p100 += center;
		p101 += center;
		p110 += center;
		p111 += center;
		p000 += center;
		p001 += center;
		p010 += center;
		p011 += center;

		_addLine(p100, p101, color);
		_addLine(p110, p111, color);
		_addLine(p100, p110, color);
		_addLine(p101, p111, color);

		_addLine(p000, p001, color);
		_addLine(p010, p011, color);
		_addLine(p000, p010, color);
		_addLine(p001, p011, color);

		_addLine(p000, p100, color);
		_addLine(p010, p110, color);
		_addLine(p011, p111, color);
		_addLine(p001, p101, color);
	}
   void OSGDebugDrawInterface::AddAABB(const dtEntity::Vec3f& minCoords, 
      const dtEntity::Vec3f& maxCoords, const dtEntity::Vec4f& color,
      int lineWidth, float duration, bool depthTestEnabled)
   {
      if(!mEnabled)
         return;
      osg::Vec3 p000(minCoords);
      osg::Vec3 p111(maxCoords);
      osg::Vec3 p001(minCoords[0], minCoords[1], maxCoords[2]);
      osg::Vec3 p010(minCoords[0], maxCoords[1], minCoords[2]);
      osg::Vec3 p100(maxCoords[0], minCoords[1], minCoords[2]);
      osg::Vec3 p011(minCoords[0], maxCoords[1], maxCoords[2]);
      osg::Vec3 p101(maxCoords[0], minCoords[1], maxCoords[2]);
      osg::Vec3 p110(maxCoords[0], maxCoords[1], minCoords[2]);
      
      std::vector<osg::Vec3> lines(24);
      lines[0] = p000; lines[1] = p100;
      lines[2] = p100; lines[3] = p101;
      lines[4] = p101; lines[5] = p001;
      lines[6] = p001; lines[7] = p000;

      lines[8] = p001; lines[9] = p011;
      lines[10] = p101; lines[11] = p111;
      lines[12] = p100; lines[13] = p110;
      lines[14] = p000; lines[15] = p010;

      lines[16] = p011; lines[17] = p111;
      lines[18] = p010; lines[19] = p011;
      lines[20] = p111; lines[21] = p110;
      lines[22] = p010; lines[23] = p110;

      
      AddLines(lines, color, lineWidth, duration, depthTestEnabled);
   }      
Example #3
0
void createCube(cMesh *a_mesh, double a_halfSize)
{
    // define eight corners of edges [x,y,z]
    cVector3d p000(-a_halfSize, -a_halfSize, -a_halfSize);
    cVector3d p100( a_halfSize, -a_halfSize, -a_halfSize);
    cVector3d p110( a_halfSize,  a_halfSize, -a_halfSize);
    cVector3d p010(-a_halfSize,  a_halfSize, -a_halfSize);
    cVector3d p001(-a_halfSize, -a_halfSize,  a_halfSize);
    cVector3d p101( a_halfSize, -a_halfSize,  a_halfSize);
    cVector3d p111( a_halfSize,  a_halfSize,  a_halfSize);
    cVector3d p011(-a_halfSize,  a_halfSize,  a_halfSize);

    // create two triangles for each face:

    //face -x
    a_mesh->newTriangle(p000, p001, p011);
    a_mesh->newTriangle(p000, p011, p010);

    //face +x
    a_mesh->newTriangle(p100, p110, p111);
    a_mesh->newTriangle(p100, p111, p101);

    //face -y
    a_mesh->newTriangle(p000, p100, p101);
    a_mesh->newTriangle(p000, p101, p001);

    //face +y
    a_mesh->newTriangle(p010, p011, p111);
    a_mesh->newTriangle(p010, p111, p110);

    //face -z
    a_mesh->newTriangle(p000, p010, p100);
    a_mesh->newTriangle(p010, p110, p100);

    //face +z
    a_mesh->newTriangle(p001, p101, p011);
    a_mesh->newTriangle(p101, p111, p011);

    // compute normals
    a_mesh->computeAllNormals(true);

    // compute boudary box
    a_mesh->computeBoundaryBox(true);
}
Example #4
0
	void Gizmos::addCube(const glm::mat4& transform, const glm::vec3& color)
	{
		glm::vec3 extents(1,1,1);

		glm::vec3 p100(-extents.x, extents.y, extents.z);
		glm::vec3 p101(-extents.x, extents.y, -extents.z);
		glm::vec3 p110(-extents.x, -extents.y, extents.z);
		glm::vec3 p111(-extents.x, -extents.y, -extents.z);
		glm::vec3 p000(extents.x, extents.y, extents.z);
		glm::vec3 p001(extents.x, extents.y, -extents.z);
		glm::vec3 p010(extents.x, -extents.y, extents.z);
		glm::vec3 p011(extents.x, -extents.y, -extents.z);
		p100 = glm::vec3(transform * glm::vec4(p100, 0));
		p101 = glm::vec3(transform * glm::vec4(p101, 0));
		p110 = glm::vec3(transform * glm::vec4(p110, 0));
		p111 = glm::vec3(transform * glm::vec4(p111, 0));
		p000 = glm::vec3(transform * glm::vec4(p000, 0));
		p001 = glm::vec3(transform * glm::vec4(p001, 0));
		p010 = glm::vec3(transform * glm::vec4(p010, 0));
		p011 = glm::vec3(transform * glm::vec4(p011, 0));

		_addLine(p100, p101, color);
		_addLine(p110, p111, color);
		_addLine(p100, p110, color);
		_addLine(p101, p111, color);

		_addLine(p000, p001, color);
		_addLine(p010, p011, color);
		_addLine(p000, p010, color);
		_addLine(p001, p011, color);

		_addLine(p000, p100, color);
		_addLine(p010, p110, color);
		_addLine(p011, p111, color);
		_addLine(p001, p101, color);
	}
Example #5
0
void MeshObject::MakeBox(float x,float y,float z,Material *mtl) {
	// Allocate arrays
	NumVertexes=24;
	NumTriangles=12;
	Vertexes=new Vertex[NumVertexes];
	Triangles=new Triangle[NumTriangles];
	if(mtl==0) mtl=new LambertMaterial;

	x*=0.5f;
	y*=0.5f;
	z*=0.5f;

	// Corners
	Vector3 p000(-x,-y,-z);
	Vector3 p001(-x,-y,z);
	Vector3 p010(-x,y,-z);
	Vector3 p011(-x,y,z);
	Vector3 p100(x,-y,-z);
	Vector3 p101(x,-y,z);
	Vector3 p110(x,y,-z);
	Vector3 p111(x,y,z);

	// Tex coords
	Vector3 t00(0.0f,0.0f,0.0f);
	Vector3 t01(0.0f,1.0f,0.0f);
	Vector3 t10(1.0f,0.0f,0.0f);
	Vector3 t11(1.0f,1.0f,0.0f);

	// Right
	Vertexes[0].Set(p101,Vector3::XAXIS,t00);
	Vertexes[1].Set(p100,Vector3::XAXIS,t10);
	Vertexes[2].Set(p110,Vector3::XAXIS,t11);
	Vertexes[3].Set(p111,Vector3::XAXIS,t01);
	Triangles[0].Init(&Vertexes[0],&Vertexes[1],&Vertexes[2],mtl);
	Triangles[1].Init(&Vertexes[0],&Vertexes[2],&Vertexes[3],mtl);

	// Left
	Vertexes[4].Set(p000,-Vector3::XAXIS,t00);
	Vertexes[5].Set(p001,-Vector3::XAXIS,t10);
	Vertexes[6].Set(p011,-Vector3::XAXIS,t11);
	Vertexes[7].Set(p010,-Vector3::XAXIS,t01);
	Triangles[2].Init(&Vertexes[4],&Vertexes[5],&Vertexes[6],mtl);
	Triangles[3].Init(&Vertexes[4],&Vertexes[6],&Vertexes[7],mtl);

	// Top
	Vertexes[8].Set(p011,Vector3::YAXIS,t00);
	Vertexes[9].Set(p111,Vector3::YAXIS,t10);
	Vertexes[10].Set(p110,Vector3::YAXIS,t11);
	Vertexes[11].Set(p010,Vector3::YAXIS,t01);
	Triangles[4].Init(&Vertexes[8],&Vertexes[9],&Vertexes[10],mtl);
	Triangles[5].Init(&Vertexes[8],&Vertexes[10],&Vertexes[11],mtl);

	// Bottom
	Vertexes[12].Set(p000,-Vector3::YAXIS,t00);
	Vertexes[13].Set(p100,-Vector3::YAXIS,t10);
	Vertexes[14].Set(p101,-Vector3::YAXIS,t11);
	Vertexes[15].Set(p001,-Vector3::YAXIS,t01);
	Triangles[6].Init(&Vertexes[12],&Vertexes[13],&Vertexes[14],mtl);
	Triangles[7].Init(&Vertexes[12],&Vertexes[14],&Vertexes[15],mtl);

	// Front
	Vertexes[16].Set(p001,Vector3::ZAXIS,t00);
	Vertexes[17].Set(p101,Vector3::ZAXIS,t10);
	Vertexes[18].Set(p111,Vector3::ZAXIS,t11);
	Vertexes[19].Set(p011,Vector3::ZAXIS,t01);
	Triangles[8].Init(&Vertexes[16],&Vertexes[17],&Vertexes[18],mtl);
	Triangles[9].Init(&Vertexes[16],&Vertexes[18],&Vertexes[19],mtl);

	// Back
	Vertexes[20].Set(p100,-Vector3::ZAXIS,t00);
	Vertexes[21].Set(p000,-Vector3::ZAXIS,t10);
	Vertexes[22].Set(p010,-Vector3::ZAXIS,t11);
	Vertexes[23].Set(p110,-Vector3::ZAXIS,t01);
	Triangles[10].Init(&Vertexes[20],&Vertexes[21],&Vertexes[22],mtl);
	Triangles[11].Init(&Vertexes[20],&Vertexes[22],&Vertexes[23],mtl);
}