Added debug circle rendering (extended OglDebugLine to OglDebugShape, created new function KX_RasterizerDrawDebugCircle)
This commit is contained in:
@@ -341,7 +341,7 @@ void KX_KetsjiEngine::RenderDome()
|
||||
m_rendertools->MotionBlur(m_rasterizer);
|
||||
scene->Render2DFilters(m_canvas);
|
||||
// no RunDrawingCallBacks
|
||||
// no FlushDebugLines
|
||||
// no FlushDebugShapes
|
||||
}
|
||||
m_dome->BindImages(i);
|
||||
}
|
||||
@@ -1336,7 +1336,7 @@ void KX_KetsjiEngine::PostRenderScene(KX_Scene* scene)
|
||||
#ifndef DISABLE_PYTHON
|
||||
scene->RunDrawingCallbacks(scene->GetPostDrawCB());
|
||||
#endif
|
||||
m_rasterizer->FlushDebugLines();
|
||||
m_rasterizer->FlushDebugShapes();
|
||||
}
|
||||
|
||||
void KX_KetsjiEngine::StopEngine()
|
||||
|
@@ -246,13 +246,11 @@ void KX_ObstacleSimulation::DrawObstacles()
|
||||
{
|
||||
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);
|
||||
}*/
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -156,6 +156,13 @@ void KX_RasterizerDrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,cons
|
||||
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;
|
||||
|
@@ -71,6 +71,8 @@ class KX_KetsjiEngine* KX_GetActiveEngine();
|
||||
#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
|
||||
|
||||
|
@@ -386,7 +386,9 @@ public:
|
||||
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;
|
||||
|
||||
|
||||
|
||||
|
@@ -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();
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user