[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [29378] branches/soc-2010-nicks/source/ gameengine: Added debug circle rendering ( extended OglDebugLine to OglDebugShape, created new function KX_RasterizerDrawDebugCircle)

Nick Samarin nicks1987 at bigmir.net
Thu Jun 10 02:25:06 CEST 2010


Revision: 29378
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=29378
Author:   nicks
Date:     2010-06-10 02:25:04 +0200 (Thu, 10 Jun 2010)

Log Message:
-----------
Added debug circle rendering (extended OglDebugLine to OglDebugShape, created new function KX_RasterizerDrawDebugCircle)

Modified Paths:
--------------
    branches/soc-2010-nicks/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
    branches/soc-2010-nicks/source/gameengine/Ketsji/KX_ObstacleSimulation.cpp
    branches/soc-2010-nicks/source/gameengine/Ketsji/KX_PythonInit.cpp
    branches/soc-2010-nicks/source/gameengine/Ketsji/KX_PythonInit.h
    branches/soc-2010-nicks/source/gameengine/Rasterizer/RAS_IRasterizer.h
    branches/soc-2010-nicks/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
    branches/soc-2010-nicks/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h

Modified: branches/soc-2010-nicks/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
===================================================================
--- branches/soc-2010-nicks/source/gameengine/Ketsji/KX_KetsjiEngine.cpp	2010-06-10 00:19:06 UTC (rev 29377)
+++ branches/soc-2010-nicks/source/gameengine/Ketsji/KX_KetsjiEngine.cpp	2010-06-10 00:25:04 UTC (rev 29378)
@@ -341,7 +341,7 @@
 			m_rendertools->MotionBlur(m_rasterizer);
 			scene->Render2DFilters(m_canvas);
 			// no RunDrawingCallBacks
-			// no FlushDebugLines
+			// no FlushDebugShapes
 		}
 		m_dome->BindImages(i);
 	}	
@@ -1336,7 +1336,7 @@
 #ifndef DISABLE_PYTHON
 	scene->RunDrawingCallbacks(scene->GetPostDrawCB());	
 #endif
-	m_rasterizer->FlushDebugLines();
+	m_rasterizer->FlushDebugShapes();
 }
 
 void KX_KetsjiEngine::StopEngine()

Modified: branches/soc-2010-nicks/source/gameengine/Ketsji/KX_ObstacleSimulation.cpp
===================================================================
--- branches/soc-2010-nicks/source/gameengine/Ketsji/KX_ObstacleSimulation.cpp	2010-06-10 00:19:06 UTC (rev 29377)
+++ branches/soc-2010-nicks/source/gameengine/Ketsji/KX_ObstacleSimulation.cpp	2010-06-10 00:25:04 UTC (rev 29378)
@@ -246,13 +246,11 @@
 		{
 			KX_RasterizerDrawDebugLine(m_obstacles[i]->m_pos, m_obstacles[i]->m_pos2, bluecolor);
 		}
-/*
 		else if (m_obstacles[i]->m_shape==KX_OBSTACLE_CIRCLE)
 		{
 			KX_RasterizerDrawDebugCircle(m_obstacles[i]->m_pos, m_obstacles[i]->m_rad, bluecolor,
 										normal.normalized(), SECTORS_NUM);
-		}*/
-
+		}
 	}	
 }
 

Modified: branches/soc-2010-nicks/source/gameengine/Ketsji/KX_PythonInit.cpp
===================================================================
--- branches/soc-2010-nicks/source/gameengine/Ketsji/KX_PythonInit.cpp	2010-06-10 00:19:06 UTC (rev 29377)
+++ branches/soc-2010-nicks/source/gameengine/Ketsji/KX_PythonInit.cpp	2010-06-10 00:25:04 UTC (rev 29378)
@@ -156,6 +156,13 @@
 		gp_Rasterizer->DrawDebugLine(from,to,color);
 }
 
+void	KX_RasterizerDrawDebugCircle(const MT_Vector3& center, const MT_Scalar radius, const MT_Vector3& color,
+								   const MT_Vector3& normal, int nsector)
+{
+	if (gp_Rasterizer)
+		gp_Rasterizer->DrawDebugCircle(center, radius, color, normal, nsector);
+}
+
 #ifndef DISABLE_PYTHON
 
 static PyObject *gp_OrigPythonSysPath= NULL;

Modified: branches/soc-2010-nicks/source/gameengine/Ketsji/KX_PythonInit.h
===================================================================
--- branches/soc-2010-nicks/source/gameengine/Ketsji/KX_PythonInit.h	2010-06-10 00:19:06 UTC (rev 29377)
+++ branches/soc-2010-nicks/source/gameengine/Ketsji/KX_PythonInit.h	2010-06-10 00:25:04 UTC (rev 29378)
@@ -71,6 +71,8 @@
 #include "MT_Vector3.h"
 
 void		KX_RasterizerDrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color);
+void		KX_RasterizerDrawDebugCircle(const MT_Vector3& center, const MT_Scalar radius, const MT_Vector3& color,
+									 const MT_Vector3& normal, int nsector);
 
 #endif //__KX_PYTHON_INIT
 

Modified: branches/soc-2010-nicks/source/gameengine/Rasterizer/RAS_IRasterizer.h
===================================================================
--- branches/soc-2010-nicks/source/gameengine/Rasterizer/RAS_IRasterizer.h	2010-06-10 00:19:06 UTC (rev 29377)
+++ branches/soc-2010-nicks/source/gameengine/Rasterizer/RAS_IRasterizer.h	2010-06-10 00:25:04 UTC (rev 29378)
@@ -386,7 +386,9 @@
 	virtual void	SetPolygonOffset(float mult, float add) = 0;
 	
 	virtual	void	DrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color)=0;
-	virtual	void	FlushDebugLines()=0;
+	virtual	void	DrawDebugCircle(const MT_Vector3& center, const MT_Scalar radius, const MT_Vector3& color,
+										const MT_Vector3& normal, int nsector)=0;
+	virtual	void	FlushDebugShapes()=0;
 	
 
 

Modified: branches/soc-2010-nicks/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
===================================================================
--- branches/soc-2010-nicks/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp	2010-06-10 00:19:06 UTC (rev 29377)
+++ branches/soc-2010-nicks/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp	2010-06-10 00:25:04 UTC (rev 29378)
@@ -50,6 +50,10 @@
 
 #include "BKE_DerivedMesh.h"
 
+#ifndef M_PI
+#define M_PI		3.14159265358979323846
+#endif
+
 /**
  *  32x32 bit masks for vinterlace stereo mode
  */
@@ -343,9 +347,9 @@
 	m_materialCachingInfo = 0;
 }
 
-void RAS_OpenGLRasterizer::FlushDebugLines()
+void RAS_OpenGLRasterizer::FlushDebugShapes()
 {
-	if(!m_debugLines.size())
+	if(!m_debugShapes.size())
 		return;
 
 	// DrawDebugLines
@@ -357,29 +361,93 @@
 	if(light) glDisable(GL_LIGHTING);
 	if(tex) glDisable(GL_TEXTURE_2D);
 
+	//draw lines
 	glBegin(GL_LINES);
-	for (unsigned int i=0;i<m_debugLines.size();i++)
+	for (unsigned int i=0;i<m_debugShapes.size();i++)
 	{
-		glColor4f(m_debugLines[i].m_color[0],m_debugLines[i].m_color[1],m_debugLines[i].m_color[2],1.f);
-		const MT_Scalar* fromPtr = &m_debugLines[i].m_from.x();
-		const MT_Scalar* toPtr= &m_debugLines[i].m_to.x();
-
+		if (m_debugShapes[i].m_type != OglDebugShape::LINE)
+			continue;
+		glColor4f(m_debugShapes[i].m_color[0],m_debugShapes[i].m_color[1],m_debugShapes[i].m_color[2],1.f);
+		const MT_Scalar* fromPtr = &m_debugShapes[i].m_pos.x();
+		const MT_Scalar* toPtr= &m_debugShapes[i].m_param.x();
 		glVertex3dv(fromPtr);
 		glVertex3dv(toPtr);
 	}
 	glEnd();
 
+	//draw circles
+	for (unsigned int i=0;i<m_debugShapes.size();i++)
+	{
+		if (m_debugShapes[i].m_type != OglDebugShape::CIRCLE)
+			continue;
+		glBegin(GL_LINE_LOOP);
+		glColor4f(m_debugShapes[i].m_color[0],m_debugShapes[i].m_color[1],m_debugShapes[i].m_color[2],1.f);
+		
+		static const MT_Vector3 worldUp(0.,0.,1.);
+		MT_Vector3 norm = m_debugShapes[i].m_param;
+		MT_Matrix3x3 tr;
+		if (norm.fuzzyZero() || norm == worldUp)
+		{
+			tr.setIdentity();
+		}
+		else
+		{
+			MT_Vector3 xaxis, yaxis;
+			xaxis = MT_cross(norm, worldUp);
+			yaxis = MT_cross(xaxis, norm);
+			tr.setValue(xaxis.x(), xaxis.y(), xaxis.z(),
+						yaxis.x(), yaxis.y(), yaxis.z(),
+						norm.x(), norm.y(), norm.z());
+		}
+		MT_Scalar rad = m_debugShapes[i].m_param2.x();
+		int n = (int) m_debugShapes[i].m_param2.y();
+		for (int j = 0; j<n; j++)
+		{
+			MT_Scalar theta = j*M_PI*2/n;
+			MT_Vector3 pos(cos(theta)*rad, sin(theta)*rad, 0.);
+			pos = pos*tr;
+			pos += m_debugShapes[i].m_pos;
+			const MT_Scalar* posPtr = &pos.x();
+			glVertex3dv(posPtr);
+		}
+		glEnd();
+	}
+
+
 	if(light) glEnable(GL_LIGHTING);
 	if(tex) glEnable(GL_TEXTURE_2D);
 
-	m_debugLines.clear();
+	m_debugShapes.clear();
 }
 
+void RAS_OpenGLRasterizer::DrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color)
+{
+	OglDebugShape line;
+	line.m_type = OglDebugShape::LINE;
+	line.m_pos= from;
+	line.m_param = to;
+	line.m_color = color;
+	m_debugShapes.push_back(line);
+}
+
+void RAS_OpenGLRasterizer::DrawDebugCircle(const MT_Vector3& center, const MT_Scalar radius, const MT_Vector3& color,
+											const MT_Vector3& normal, int nsector)
+{
+	OglDebugShape line;
+	line.m_type = OglDebugShape::CIRCLE;
+	line.m_pos= center;
+	line.m_param = normal;
+	line.m_color = color;	
+	line.m_param2.x() = radius;
+	line.m_param2.y() = (float) nsector;
+	m_debugShapes.push_back(line);
+}
+
 void RAS_OpenGLRasterizer::EndFrame()
 {
 	
 
-	FlushDebugLines();
+	FlushDebugShapes();
 
 	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
 	m_2DCanvas->EndFrame();

Modified: branches/soc-2010-nicks/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h
===================================================================
--- branches/soc-2010-nicks/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h	2010-06-10 00:19:06 UTC (rev 29377)
+++ branches/soc-2010-nicks/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h	2010-06-10 00:25:04 UTC (rev 29378)
@@ -44,10 +44,15 @@
 #define RAS_MAX_TEXCO	8	// match in BL_Material
 #define RAS_MAX_ATTRIB	16	// match in BL_BlenderShader
 
-struct	OglDebugLine
+struct	OglDebugShape
 {
-	MT_Vector3	m_from;
-	MT_Vector3	m_to;
+	enum SHAPE_TYPE{
+		LINE, CIRCLE
+	};
+	SHAPE_TYPE  m_type;
+	MT_Vector3	m_pos;
+	MT_Vector3	m_param;
+	MT_Vector3	m_param2;
 	MT_Vector3	m_color;
 };
 
@@ -249,18 +254,13 @@
 
 	virtual void	SetPolygonOffset(float mult, float add);
 
-	virtual	void	FlushDebugLines();
+	virtual	void	FlushDebugShapes();
+	virtual	void	DrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color);
+	virtual	void	DrawDebugCircle(const MT_Vector3& center, const MT_Scalar radius, const MT_Vector3& color,
+									const MT_Vector3& normal, int nsector);
 
-	virtual	void	DrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color)
-	{
-		OglDebugLine line;
-		line.m_from = from;
-		line.m_to = to;
-		line.m_color = color;
-		m_debugLines.push_back(line);
-	}
 
-	std::vector <OglDebugLine>	m_debugLines;
+	std::vector <OglDebugShape>	m_debugShapes;
 
 	virtual void SetTexCoordNum(int num);
 	virtual void SetAttribNum(int num);





More information about the Bf-blender-cvs mailing list