//------------------------------------------------------------------------------
void
DebugDraw::DrawSolidCircle( const b2Vec2 & center, float32 radius,
                            const b2Vec2 & axis, const b2Color & color ) 
{
    b2Vec2 vertices[16];
    _getCircleVertices( vertices, center, radius );
    DrawSolidPolygon( vertices, 16, color );
}
Exemple #2
0
	void Render::DrawShape(b2Fixture* fixture, const b2Transform& xf, const b2Color& color) {
		switch (fixture->GetType()) {
			case b2Shape::e_circle: {
				b2CircleShape* circle = (b2CircleShape*) fixture->GetShape();

				b2Vec2 center = b2Mul(xf, circle->m_p);
				float32 radius = circle->m_radius;
				b2Vec2 axis = b2Mul(xf.q, b2Vec2(1.0f, 0.0f));

				DrawSolidCircle(center, radius, axis, color);
			}
				break;

			case b2Shape::e_edge: {
				b2EdgeShape* edge = (b2EdgeShape*) fixture->GetShape();
				b2Vec2 v1 = b2Mul(xf, edge->m_vertex1);
				b2Vec2 v2 = b2Mul(xf, edge->m_vertex2);
				DrawSegment(v1, v2, color);
			}
				break;

			case b2Shape::e_chain: {
				b2ChainShape* chain = (b2ChainShape*) fixture->GetShape();
				int32 count = chain->m_count;
				const b2Vec2* vertices = chain->m_vertices;

				b2Vec2 v1 = b2Mul(xf, vertices[0]);
				for (int32 i = 1; i < count; ++i) {
					b2Vec2 v2 = b2Mul(xf, vertices[i]);
					DrawSegment(v1, v2, color);
					DrawCircle(v1, 0.05f, color);
					v1 = v2;
				}
			}
				break;

			case b2Shape::e_polygon: {
				b2PolygonShape* poly = (b2PolygonShape*) fixture->GetShape();
				int32 vertexCount = poly->m_vertexCount;
				b2Assert(vertexCount <= b2_maxPolygonVertices);
				b2Vec2 vertices[b2_maxPolygonVertices];

				for (int32 i = 0; i < vertexCount; ++i) {
					vertices[i] = b2Mul(xf, poly->m_vertices[i]);
				}

				DrawSolidPolygon(vertices, vertexCount, color);
			}
				break;

			default:
				break;
		}
	}
Exemple #3
0
void Drawer::DrawShape(b2Transform& transf, b2Fixture *fix, b2Color& col)
{
	// The shape contains the vertices/points of the primitive structure
	// The coordinates of the vertices are in local coordinates and need to be transformed
	// Transformation is done via translation and rotation with the b2Transform of the body the shape is living in
	b2Shape *shape = fix->GetShape();

	switch (shape->GetType()) {

	case b2Shape::e_polygon:
		{
			b2PolygonShape *pShape = dynamic_cast<b2PolygonShape *>(shape);
			int vertexCount = pShape->GetVertexCount();
	
			b2Vec2 poly[b2_maxPolygonVertices];

			for (int i = 0; i < vertexCount; i++) {
				poly[i] = b2Mul(transf, pShape->m_vertices[i]);

			}
			DrawSolidPolygon(poly, vertexCount, col);
		}
		break;

	case b2Shape::e_circle:
		{
			b2CircleShape *cShape = dynamic_cast<b2CircleShape *>(shape);
			b2Vec2 cent = b2Mul(transf, cShape->m_p);
			DrawSolidCircle(cent, cShape->m_radius, col);
		}
		break;

	case b2Shape::e_edge:
		{
			b2EdgeShape *eShape = dynamic_cast<b2EdgeShape *>(shape);
			b2Vec2 p1 = b2Mul(transf, eShape->m_vertex1);
			b2Vec2 p2 = b2Mul(transf, eShape->m_vertex2);
			DrawSegment(p1, p2, col);
		}
		break;

	default:
		break;
	}
}
//if usezbuffer = false. we use 1/z buffer
void CRenderObjectsManager:: Render(bool bLighting,bool bbackfaceremove,bool usezbuffer)
{
	//convert to world coordinate system
	Model2World();
	

	int i = 0;
	int j = 0;
	////back face removal
	{
		for( i = 0; i < m_RenderList.size();++i)
		{
			CRenderObject *pObj = m_RenderList[i];
			POLYGONLIST &polygonlist = pObj->m_PolyGonList;
			int polygonsize = polygonlist.size();
			for( j = 0; j < polygonsize;++j)
			{
				POLYGON &polygon = polygonlist[j];
				if(bbackfaceremove)
				{
					VERTICESLIST &pointlist = pObj->m_translateverticesList;
					Vector4D p0p1(pointlist[polygon.v[1]].vertex-pointlist[polygon.v[0]].vertex);
					Vector4D p0p2(pointlist[polygon.v[2]].vertex-pointlist[polygon.v[0]].vertex);
					Vector4D normal = p0p1.CrossProduct(p0p2);
					Vector4D viewvec(m_pCam->m_pos-pointlist[polygon.v[0]].vertex);
					float dp = viewvec.DotProduct(normal);
					if(dp <0)
					{
						polygon.state |= POLYGON_BACKFACEREMOVE;
					}
				}
				else
				{
					polygon.state &= ~POLYGON_BACKFACEREMOVE;
				}
				
			}
		}

	}
	
	
	//Lighting handle
	for( i = 0; i < m_RenderList.size();++i)
	{
			CRenderObject *pObj = m_RenderList[i];
			POLYGONLIST &polygonlist = pObj->m_PolyGonList;
			int polygonsize = polygonlist.size();
			for( j = 0; j < polygonsize;++j)
			{
				POLYGON &polygon = polygonlist[j];
				if(polygon.state & POLYGON_BACKFACEREMOVE) continue;
				if(bLighting)
				 polygon.state |= POLYGON_LIGHTING_PROCESSED;
				else
				{
					polygon.state &= ~POLYGON_LIGHTING_PROCESSED;
					continue;
				}
				VERTICESLIST &pointlist = pObj->m_translateverticesList;
				ProcessLighting(pObj,polygon);
			}
	}
	//convert them to the view,screen
	Matrix mat = m_pCam->GetWorldToCameraMatrix();
	mat *= m_pCam->GetCameraToProjectionMatrix();
	mat *=m_pCam->GetProjectionToScreenMatrix();
	//4d   coordinate .need to convert it to 3d
	
	for( i = 0; i < m_RenderList.size();++i)
	{
		CRenderObject *pObj = m_RenderList[i];
		VERTICESLIST & Translatedvertices = pObj->m_translateverticesList;
		for( j = 0; j < Translatedvertices.size();++j)
		{
			float z  = Translatedvertices[j].vertex.z;
			Translatedvertices[j].vertex *= mat;
			Translatedvertices[j].vertex *= 1/Translatedvertices[j].vertex.w ;
			Translatedvertices[j].vertex.z =z;
		}
	}
	//sort them


	for( i = 0; i < m_RenderList.size();++i)
	{
		CRenderObject *pObj = m_RenderList[i];
		POLYGONLIST &polygonlist = pObj->m_PolyGonList;
		int polygonsize = polygonlist.size();
		for( j = 0; j < polygonsize;++j)
		{
			POLYGON &polygon = polygonlist[j];
			if(polygon.state & POLYGON_BACKFACEREMOVE) continue;
			VERTICESLIST &pointlist = pObj->m_translateverticesList;
			




			/************************************************************************/
			/* Draw wireframe polygon                                                                    */
			/************************************************************************/ 
			/*line(pointlist[polygon.v[0]].x,pointlist[polygon.v[0]].y,
				pointlist[polygon.v[1]].x,pointlist[polygon.v[1]].y,
				RGB(0,255,0));
			line(pointlist[polygon.v[1]].x,pointlist[polygon.v[1]].y,
				pointlist[polygon.v[2]].x,pointlist[polygon.v[2]].y,
				RGB(0,255,0));
			line(pointlist[polygon.v[2]].x,pointlist[polygon.v[2]].y,
				pointlist[polygon.v[0]].x,pointlist[polygon.v[0]].y,
				RGB(0,255,0));*/
			//or
			//DrawWireFramePolygon(pointlist[polygon.v[0]],pointlist[polygon.v[1]],
		    //                pointlist[polygon.v[2]],RGB(0,0,0));
			/************************************************************************/
			/* End wireframe polygon                                                                    */
			/************************************************************************/


			/************************************************************************/
			/* Solid polygon                                                                    */
			/************************************************************************/
			//DrawSolidPolygon(pointlist[polygon.v[0]],pointlist[polygon.v[1]],
			       //       pointlist[polygon.v[2]],RGB(0,255,0));
			/************************************************************************/
			/* End Solid Polygon                                                                    */
			/************************************************************************/

			/************************************************************************/
			/* Lighting processing                                                                    */
			/************************************************************************/
			   if((polygon.state & SHADE_MODEL_CONSTANT) && !(polygon.state & OBJECT_HAS_TEXTURE))
				DrawSolidPolygon(pointlist[polygon.v[0]].vertex,
				                 pointlist[polygon.v[1]].vertex,
					             pointlist[polygon.v[2]].vertex,
						         polygon.state & POLYGON_LIGHTING_PROCESSED ?
								 polygon.ret_color.rgba:polygon.color.rgba);
			   else if( polygon.state & OBJECT_HAS_TEXTURE)
			   {
				   if(usezbuffer)
				     RenderTextureTriangle(pObj,polygon);
				   else
					 DrawTextureTriangle_invz(polygon,pObj);
			   }
			   else
			   {
				   DrawWireFramePolygon(pointlist[polygon.v[0]].vertex,pointlist[polygon.v[1]].vertex,
					   pointlist[polygon.v[2]].vertex,polygon.color.rgba);
			   }
		}
	}


}