synched with trunk at revision 36569
[blender.git] / source / gameengine / Rasterizer / RAS_OpenGLRasterizer / RAS_OpenGLRasterizer.cpp
index 23e0a50..59710b6 100644 (file)
 
 #include "BKE_DerivedMesh.h"
 
+#ifndef M_PI
+#define M_PI           3.14159265358979323846
+#endif
+
 /**
  *  32x32 bit masks for vinterlace stereo mode
  */
@@ -350,9 +354,9 @@ void RAS_OpenGLRasterizer::ClearCachingInfo(void)
        m_materialCachingInfo = 0;
 }
 
-void RAS_OpenGLRasterizer::FlushDebugLines()
+void RAS_OpenGLRasterizer::FlushDebugShapes()
 {
-       if(!m_debugLines.size())
+       if(!m_debugShapes.size())
                return;
 
        // DrawDebugLines
@@ -364,29 +368,67 @@ void RAS_OpenGLRasterizer::FlushDebugLines()
        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::EndFrame()
 {
-       
-
-       FlushDebugLines();
+       FlushDebugShapes();
 
        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);