Fixed compilation error with debug mode
This commit is contained in:
208
src/graphics/abstract_renderer.cpp
Normal file
208
src/graphics/abstract_renderer.cpp
Normal file
@@ -0,0 +1,208 @@
|
||||
// SuperTuxKart - a fun racing game with go-kart
|
||||
// Copyright (C) 2015 SuperTuxKart-Team
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License
|
||||
// as published by the Free Software Foundation; either version 3
|
||||
// of the License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
|
||||
#include "graphics/abstract_renderer.hpp"
|
||||
#include "graphics/irr_driver.hpp"
|
||||
#include "guiengine/engine.hpp"
|
||||
#include "guiengine/scalable_font.hpp"
|
||||
|
||||
using namespace irr;
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
void AbstractRenderer::drawDebugMeshes()
|
||||
{
|
||||
for (unsigned int n=0; n<m_debug_meshes.size(); n++)
|
||||
{
|
||||
scene::IMesh* mesh = m_debug_meshes[n]->getMesh();
|
||||
scene::ISkinnedMesh* smesh = static_cast<scene::ISkinnedMesh*>(mesh);
|
||||
const core::array< scene::ISkinnedMesh::SJoint * >& joints =
|
||||
smesh->getAllJoints();
|
||||
|
||||
for (unsigned int j=0; j<joints.size(); j++)
|
||||
{
|
||||
drawJoint( false, true, joints[j], smesh, j);
|
||||
}
|
||||
}
|
||||
|
||||
video::SColor color(255,255,255,255);
|
||||
video::SMaterial material;
|
||||
material.Thickness = 2;
|
||||
material.AmbientColor = color;
|
||||
material.DiffuseColor = color;
|
||||
material.EmissiveColor= color;
|
||||
material.BackfaceCulling = false;
|
||||
material.setFlag(video::EMF_LIGHTING, false);
|
||||
irr_driver->getVideoDriver()->setMaterial(material);
|
||||
irr_driver->getVideoDriver()->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
||||
|
||||
for (unsigned int n=0; n<m_debug_meshes.size(); n++)
|
||||
{
|
||||
scene::IMesh* mesh = m_debug_meshes[n]->getMesh();
|
||||
|
||||
|
||||
scene::ISkinnedMesh* smesh = static_cast<scene::ISkinnedMesh*>(mesh);
|
||||
const core::array< scene::ISkinnedMesh::SJoint * >& joints =
|
||||
smesh->getAllJoints();
|
||||
|
||||
for (unsigned int j=0; j<joints.size(); j++)
|
||||
{
|
||||
scene::IMesh* mesh = m_debug_meshes[n]->getMesh();
|
||||
scene::ISkinnedMesh* smesh = static_cast<scene::ISkinnedMesh*>(mesh);
|
||||
|
||||
drawJoint(true, false, joints[j], smesh, j);
|
||||
}
|
||||
}
|
||||
} // drawDebugMeshes
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
/** Draws a joing for debugging skeletons.
|
||||
* \param drawline If true draw a line to the parent.
|
||||
* \param drawname If true draw the name of the joint.
|
||||
* \param joint The joint to draw.
|
||||
* \param mesh The mesh whose skeleton is drawn (only used to get
|
||||
* all joints to find the parent).
|
||||
* \param id Index, which (%4) determines the color to use.
|
||||
*/
|
||||
void AbstractRenderer::drawJoint(bool drawline, bool drawname,
|
||||
scene::ISkinnedMesh::SJoint* joint,
|
||||
scene::ISkinnedMesh* mesh, int id)
|
||||
{
|
||||
scene::ISkinnedMesh::SJoint* parent = NULL;
|
||||
const core::array< scene::ISkinnedMesh::SJoint * >& joints
|
||||
= mesh->getAllJoints();
|
||||
for (unsigned int j=0; j<joints.size(); j++)
|
||||
{
|
||||
if (joints[j]->Children.linear_search(joint) != -1)
|
||||
{
|
||||
parent = joints[j];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
core::vector3df jointpos = joint->GlobalMatrix.getTranslation();
|
||||
|
||||
video::SColor color(255, 255,255,255);
|
||||
if (parent == NULL) color = video::SColor(255,0,255,0);
|
||||
|
||||
switch (id % 4)
|
||||
{
|
||||
case 0:
|
||||
color = video::SColor(255,255,0,255);
|
||||
break;
|
||||
case 1:
|
||||
color = video::SColor(255,255,0,0);
|
||||
break;
|
||||
case 2:
|
||||
color = video::SColor(255,0,0,255);
|
||||
break;
|
||||
case 3:
|
||||
color = video::SColor(255,0,255,255);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (parent)
|
||||
{
|
||||
core::vector3df parentpos = parent->GlobalMatrix.getTranslation();
|
||||
|
||||
jointpos = joint->GlobalMatrix.getTranslation();
|
||||
|
||||
if (drawline)
|
||||
{
|
||||
irr_driver->getVideoDriver()->draw3DLine(jointpos,
|
||||
parentpos,
|
||||
color);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/*
|
||||
if (drawline)
|
||||
{
|
||||
irr_driver->getVideoDriver()->draw3DLine(jointpos,
|
||||
core::vector3df(0,0,0),
|
||||
color);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
if (joint->Children.size() == 0)
|
||||
{
|
||||
switch ((id + 1) % 4)
|
||||
{
|
||||
case 0:
|
||||
color = video::SColor(255,255,0,255);
|
||||
break;
|
||||
case 1:
|
||||
color = video::SColor(255,255,0,0);
|
||||
break;
|
||||
case 2:
|
||||
color = video::SColor(255,0,0,255);
|
||||
break;
|
||||
case 3:
|
||||
color = video::SColor(255,0,255,255);
|
||||
break;
|
||||
}
|
||||
|
||||
// This code doesn't quite work. 0.25 is used so that the bone is not
|
||||
// way too long (not sure why I need to manually size it down)
|
||||
// and the rotation of the bone is often rather off
|
||||
core::vector3df v(0.0f, 0.25f, 0.0f);
|
||||
//joint->GlobalMatrix.rotateVect(v);
|
||||
joint->LocalMatrix.rotateVect(v);
|
||||
v *= joint->LocalMatrix.getScale();
|
||||
irr_driver->getVideoDriver()->draw3DLine(jointpos,
|
||||
jointpos + v,
|
||||
color);
|
||||
}
|
||||
|
||||
switch ((id + 1) % 4)
|
||||
{
|
||||
case 0:
|
||||
color = video::SColor(255,255,0,255);
|
||||
break;
|
||||
case 1:
|
||||
color = video::SColor(255,255,0,0);
|
||||
break;
|
||||
case 2:
|
||||
color = video::SColor(255,0,0,255);
|
||||
break;
|
||||
case 3:
|
||||
color = video::SColor(255,0,255,255);
|
||||
break;
|
||||
}
|
||||
|
||||
if (drawname)
|
||||
{
|
||||
irr_driver->getVideoDriver()->setTransform(video::ETS_WORLD,
|
||||
core::IdentityMatrix);
|
||||
|
||||
core::vector2di textpos =
|
||||
irr_driver->getSceneManager()->getSceneCollisionManager()
|
||||
->getScreenCoordinatesFrom3DPosition(jointpos);
|
||||
|
||||
GUIEngine::getSmallFont()->draw( core::stringw(joint->Name.c_str()),
|
||||
core::rect<s32>(textpos,
|
||||
core::dimension2d<s32>(500,50)),
|
||||
color, false, false );
|
||||
}
|
||||
} //drawJoint
|
||||
|
||||
|
||||
#endif //DEBUG
|
||||
@@ -18,8 +18,23 @@
|
||||
#ifndef HEADER_ABSTRACT_RENDERER_HPP
|
||||
#define HEADER_ABSTRACT_RENDERER_HPP
|
||||
|
||||
#include <irrlicht.h>
|
||||
#include <vector>
|
||||
|
||||
class AbstractRenderer
|
||||
{
|
||||
protected:
|
||||
|
||||
/** Used to visualise skeletons. */
|
||||
std::vector<irr::scene::IAnimatedMeshSceneNode*> m_debug_meshes;
|
||||
|
||||
#ifdef DEBUG
|
||||
void drawDebugMeshes();
|
||||
void drawJoint(bool drawline, bool drawname,
|
||||
irr::scene::ISkinnedMesh::SJoint* joint,
|
||||
irr::scene::ISkinnedMesh* mesh, int id);
|
||||
#endif
|
||||
|
||||
public:
|
||||
virtual ~AbstractRenderer(){}
|
||||
|
||||
|
||||
@@ -359,7 +359,7 @@ void ShaderBasedRenderer::render(float dt)
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
irr_driver->drawDebugMeshes();
|
||||
drawDebugMeshes();
|
||||
#endif
|
||||
|
||||
PROFILER_PUSH_CPU_MARKER("EndSccene", 0x45, 0x75, 0x45);
|
||||
@@ -368,3 +368,5 @@ void ShaderBasedRenderer::render(float dt)
|
||||
|
||||
irr_driver->getPostProcessing()->update(dt);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ private:
|
||||
void debugPhysics();
|
||||
void renderPostProcessing(Camera * const camera);
|
||||
|
||||
|
||||
public:
|
||||
ShaderBasedRenderer();
|
||||
void render(float dt);
|
||||
|
||||
Reference in New Issue
Block a user