Added debug circle rendering (extended OglDebugLine to OglDebugShape, created new function KX_RasterizerDrawDebugCircle)

This commit is contained in:
Nick Samarin
2010-06-10 00:25:04 +00:00
parent 0183d55108
commit 12b33ca099
7 changed files with 105 additions and 28 deletions

View File

@@ -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 @@ 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
@@ -357,29 +361,93 @@ 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::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();

View File

@@ -44,10 +44,15 @@ using namespace std;
#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 @@ public:
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);