forked from bartvdbraak/blender
BGE: Fix T19241: draw debug shape with overlay/background scene.
It's for the function render.drawLine and physics debug.
This commit is contained in:
parent
ba146899c8
commit
76beb7b7d4
@ -1252,12 +1252,15 @@ void KX_KetsjiEngine::PostRenderScene(KX_Scene* scene)
|
|||||||
// We need to first make sure our viewport is correct (enabling multiple viewports can mess this up)
|
// We need to first make sure our viewport is correct (enabling multiple viewports can mess this up)
|
||||||
m_canvas->SetViewPort(0, 0, m_canvas->GetWidth(), m_canvas->GetHeight());
|
m_canvas->SetViewPort(0, 0, m_canvas->GetWidth(), m_canvas->GetHeight());
|
||||||
|
|
||||||
m_rasterizer->FlushDebugShapes();
|
m_rasterizer->FlushDebugShapes(scene);
|
||||||
scene->Render2DFilters(m_canvas);
|
scene->Render2DFilters(m_canvas);
|
||||||
|
|
||||||
#ifdef WITH_PYTHON
|
#ifdef WITH_PYTHON
|
||||||
PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment());
|
PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment());
|
||||||
scene->RunDrawingCallbacks(scene->GetPostDrawCB());
|
scene->RunDrawingCallbacks(scene->GetPostDrawCB());
|
||||||
|
|
||||||
|
// Python draw callback can also call debug draw functions, so we have to clear debug shapes.
|
||||||
|
m_rasterizer->FlushDebugShapes(scene);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,17 +186,17 @@ class KX_KetsjiEngine* KX_GetActiveEngine()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* why is this in python? */
|
/* why is this in python? */
|
||||||
void KX_RasterizerDrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color)
|
void KX_RasterizerDrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color)
|
||||||
{
|
{
|
||||||
if (gp_Rasterizer)
|
if (gp_Rasterizer)
|
||||||
gp_Rasterizer->DrawDebugLine(from,to,color);
|
gp_Rasterizer->DrawDebugLine(gp_KetsjiScene, from, to, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KX_RasterizerDrawDebugCircle(const MT_Vector3& center, const MT_Scalar radius, 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)
|
const MT_Vector3& normal, int nsector)
|
||||||
{
|
{
|
||||||
if (gp_Rasterizer)
|
if (gp_Rasterizer)
|
||||||
gp_Rasterizer->DrawDebugCircle(center, radius, color, normal, nsector);
|
gp_Rasterizer->DrawDebugCircle(gp_KetsjiScene, center, radius, color, normal, nsector);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef WITH_PYTHON
|
#ifdef WITH_PYTHON
|
||||||
@ -1265,7 +1265,7 @@ static PyObject *gPyDrawLine(PyObject *, PyObject *args)
|
|||||||
if (!PyVecTo(ob_color, color))
|
if (!PyVecTo(ob_color, color))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
gp_Rasterizer->DrawDebugLine(from,to,color);
|
gp_Rasterizer->DrawDebugLine(gp_KetsjiScene, from, to, color);
|
||||||
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,7 @@ class RAS_ICanvas;
|
|||||||
class RAS_IPolyMaterial;
|
class RAS_IPolyMaterial;
|
||||||
class RAS_MeshSlot;
|
class RAS_MeshSlot;
|
||||||
class RAS_ILightObject;
|
class RAS_ILightObject;
|
||||||
|
class SCA_IScene;
|
||||||
|
|
||||||
typedef vector<unsigned short> KX_IndexArray;
|
typedef vector<unsigned short> KX_IndexArray;
|
||||||
typedef vector<RAS_TexVert> KX_VertexArray;
|
typedef vector<RAS_TexVert> KX_VertexArray;
|
||||||
@ -384,10 +385,10 @@ public:
|
|||||||
*/
|
*/
|
||||||
virtual void SetPolygonOffset(float mult, float add) = 0;
|
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 DrawDebugLine(SCA_IScene *scene, const MT_Vector3 &from, const MT_Vector3 &to, const MT_Vector3& color) = 0;
|
||||||
virtual void DrawDebugCircle(const MT_Vector3 ¢er, const MT_Scalar radius, const MT_Vector3 &color,
|
virtual void DrawDebugCircle(SCA_IScene *scene, const MT_Vector3 ¢er, const MT_Scalar radius,
|
||||||
const MT_Vector3 &normal, int nsector) = 0;
|
const MT_Vector3 &color, const MT_Vector3 &normal, int nsector) = 0;
|
||||||
virtual void FlushDebugShapes() = 0;
|
virtual void FlushDebugShapes(SCA_IScene *scene) = 0;
|
||||||
|
|
||||||
virtual void SetTexCoordNum(int num) = 0;
|
virtual void SetTexCoordNum(int num) = 0;
|
||||||
virtual void SetAttribNum(int num) = 0;
|
virtual void SetAttribNum(int num) = 0;
|
||||||
|
@ -356,9 +356,10 @@ void RAS_OpenGLRasterizer::ClearCachingInfo(void)
|
|||||||
m_materialCachingInfo = 0;
|
m_materialCachingInfo = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RAS_OpenGLRasterizer::FlushDebugShapes()
|
void RAS_OpenGLRasterizer::FlushDebugShapes(SCA_IScene *scene)
|
||||||
{
|
{
|
||||||
if (m_debugShapes.empty())
|
std::vector<OglDebugShape> &debugShapes = m_debugShapes[scene];
|
||||||
|
if (debugShapes.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// DrawDebugLines
|
// DrawDebugLines
|
||||||
@ -372,28 +373,26 @@ void RAS_OpenGLRasterizer::FlushDebugShapes()
|
|||||||
|
|
||||||
//draw lines
|
//draw lines
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
for (unsigned int i=0;i<m_debugShapes.size();i++)
|
for (unsigned int i = 0; i < debugShapes.size(); i++) {
|
||||||
{
|
if (debugShapes[i].m_type != OglDebugShape::LINE)
|
||||||
if (m_debugShapes[i].m_type != OglDebugShape::LINE)
|
|
||||||
continue;
|
continue;
|
||||||
glColor4f(m_debugShapes[i].m_color[0],m_debugShapes[i].m_color[1],m_debugShapes[i].m_color[2],1.f);
|
glColor4f(debugShapes[i].m_color[0], debugShapes[i].m_color[1], debugShapes[i].m_color[2], 1.0f);
|
||||||
const MT_Scalar* fromPtr = &m_debugShapes[i].m_pos.x();
|
const MT_Scalar *fromPtr = &debugShapes[i].m_pos.x();
|
||||||
const MT_Scalar* toPtr= &m_debugShapes[i].m_param.x();
|
const MT_Scalar *toPtr= &debugShapes[i].m_param.x();
|
||||||
glVertex3dv(fromPtr);
|
glVertex3dv(fromPtr);
|
||||||
glVertex3dv(toPtr);
|
glVertex3dv(toPtr);
|
||||||
}
|
}
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
//draw circles
|
//draw circles
|
||||||
for (unsigned int i=0;i<m_debugShapes.size();i++)
|
for (unsigned int i = 0; i < debugShapes.size(); i++) {
|
||||||
{
|
if (debugShapes[i].m_type != OglDebugShape::CIRCLE)
|
||||||
if (m_debugShapes[i].m_type != OglDebugShape::CIRCLE)
|
|
||||||
continue;
|
continue;
|
||||||
glBegin(GL_LINE_LOOP);
|
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);
|
glColor4f(debugShapes[i].m_color[0], debugShapes[i].m_color[1], debugShapes[i].m_color[2], 1.0f);
|
||||||
|
|
||||||
static const MT_Vector3 worldUp(0.0, 0.0, 1.0);
|
static const MT_Vector3 worldUp(0.0, 0.0, 1.0);
|
||||||
MT_Vector3 norm = m_debugShapes[i].m_param;
|
MT_Vector3 norm = debugShapes[i].m_param;
|
||||||
MT_Matrix3x3 tr;
|
MT_Matrix3x3 tr;
|
||||||
if (norm.fuzzyZero() || norm == worldUp)
|
if (norm.fuzzyZero() || norm == worldUp)
|
||||||
{
|
{
|
||||||
@ -408,14 +407,14 @@ void RAS_OpenGLRasterizer::FlushDebugShapes()
|
|||||||
yaxis.x(), yaxis.y(), yaxis.z(),
|
yaxis.x(), yaxis.y(), yaxis.z(),
|
||||||
norm.x(), norm.y(), norm.z());
|
norm.x(), norm.y(), norm.z());
|
||||||
}
|
}
|
||||||
MT_Scalar rad = m_debugShapes[i].m_param2.x();
|
MT_Scalar rad = debugShapes[i].m_param2.x();
|
||||||
int n = (int) m_debugShapes[i].m_param2.y();
|
int n = (int)debugShapes[i].m_param2.y();
|
||||||
for (int j = 0; j<n; j++)
|
for (int j = 0; j<n; j++)
|
||||||
{
|
{
|
||||||
MT_Scalar theta = j*M_PI*2/n;
|
MT_Scalar theta = j*M_PI*2/n;
|
||||||
MT_Vector3 pos(cos(theta) * rad, sin(theta) * rad, 0.0);
|
MT_Vector3 pos(cos(theta) * rad, sin(theta) * rad, 0.0);
|
||||||
pos = pos*tr;
|
pos = pos*tr;
|
||||||
pos += m_debugShapes[i].m_pos;
|
pos += debugShapes[i].m_pos;
|
||||||
const MT_Scalar* posPtr = &pos.x();
|
const MT_Scalar* posPtr = &pos.x();
|
||||||
glVertex3dv(posPtr);
|
glVertex3dv(posPtr);
|
||||||
}
|
}
|
||||||
@ -425,13 +424,11 @@ void RAS_OpenGLRasterizer::FlushDebugShapes()
|
|||||||
if (light) glEnable(GL_LIGHTING);
|
if (light) glEnable(GL_LIGHTING);
|
||||||
if (tex) glEnable(GL_TEXTURE_2D);
|
if (tex) glEnable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
m_debugShapes.clear();
|
debugShapes.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RAS_OpenGLRasterizer::EndFrame()
|
void RAS_OpenGLRasterizer::EndFrame()
|
||||||
{
|
{
|
||||||
FlushDebugShapes();
|
|
||||||
|
|
||||||
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
||||||
|
|
||||||
glDisable(GL_MULTISAMPLE_ARB);
|
glDisable(GL_MULTISAMPLE_ARB);
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
#include "MT_CmMatrix4x4.h"
|
#include "MT_CmMatrix4x4.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#include "RAS_IRasterizer.h"
|
#include "RAS_IRasterizer.h"
|
||||||
@ -223,20 +224,20 @@ public:
|
|||||||
|
|
||||||
virtual void SetPolygonOffset(float mult, float add);
|
virtual void SetPolygonOffset(float mult, float add);
|
||||||
|
|
||||||
virtual void FlushDebugShapes();
|
virtual void FlushDebugShapes(SCA_IScene *scene);
|
||||||
|
|
||||||
virtual void DrawDebugLine(const MT_Vector3 &from,const MT_Vector3 &to, const MT_Vector3 &color)
|
virtual void DrawDebugLine(SCA_IScene *scene, const MT_Vector3 &from,const MT_Vector3 &to, const MT_Vector3 &color)
|
||||||
{
|
{
|
||||||
OglDebugShape line;
|
OglDebugShape line;
|
||||||
line.m_type = OglDebugShape::LINE;
|
line.m_type = OglDebugShape::LINE;
|
||||||
line.m_pos= from;
|
line.m_pos= from;
|
||||||
line.m_param = to;
|
line.m_param = to;
|
||||||
line.m_color = color;
|
line.m_color = color;
|
||||||
m_debugShapes.push_back(line);
|
m_debugShapes[scene].push_back(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void DrawDebugCircle(const MT_Vector3 ¢er, const MT_Scalar radius, const MT_Vector3 &color,
|
virtual void DrawDebugCircle(SCA_IScene *scene, const MT_Vector3 ¢er, const MT_Scalar radius,
|
||||||
const MT_Vector3 &normal, int nsector)
|
const MT_Vector3 &color, const MT_Vector3 &normal, int nsector)
|
||||||
{
|
{
|
||||||
OglDebugShape line;
|
OglDebugShape line;
|
||||||
line.m_type = OglDebugShape::CIRCLE;
|
line.m_type = OglDebugShape::CIRCLE;
|
||||||
@ -245,10 +246,11 @@ public:
|
|||||||
line.m_color = color;
|
line.m_color = color;
|
||||||
line.m_param2.x() = radius;
|
line.m_param2.x() = radius;
|
||||||
line.m_param2.y() = (float) nsector;
|
line.m_param2.y() = (float) nsector;
|
||||||
m_debugShapes.push_back(line);
|
m_debugShapes[scene].push_back(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector <OglDebugShape> m_debugShapes;
|
// We store each debug shape by scene.
|
||||||
|
std::map<SCA_IScene *, std::vector<OglDebugShape> > m_debugShapes;
|
||||||
|
|
||||||
virtual void SetTexCoordNum(int num);
|
virtual void SetTexCoordNum(int num);
|
||||||
virtual void SetAttribNum(int num);
|
virtual void SetAttribNum(int num);
|
||||||
|
Loading…
Reference in New Issue
Block a user