diff options
Diffstat (limited to 'src/render')
-rw-r--r-- | src/render/Makefile.am | 45 | ||||
-rw-r--r-- | src/render/debugdrawer.cc | 127 | ||||
-rw-r--r-- | src/render/debugdrawer.h | 54 | ||||
-rw-r--r-- | src/render/draw.cc | 37 | ||||
-rw-r--r-- | src/render/render.cc | 10 | ||||
-rw-r--r-- | src/render/render.h | 4 |
6 files changed, 253 insertions, 24 deletions
diff --git a/src/render/Makefile.am b/src/render/Makefile.am index 4636250..4389805 100644 --- a/src/render/Makefile.am +++ b/src/render/Makefile.am @@ -8,10 +8,43 @@ noinst_LTLIBRARIES = librender.la endif librender_la_LDFLAGS = -avoid-version -no-undefined @GL_LIBS@ + librender_la_LIBADD = $(top_builddir)/src/math/libmath.la -librender_la_SOURCES = camera.cc draw.cc dust.cc gl.cc image.cc jpgfile.cc \ - particles.cc pngfile.cc render.cc renderext.cc screenshot.cc sky.cc \ - state.cc text.cc textures.cc tgafile.cc -noinst_HEADERS = camera.h draw.h dust.h gl.h image.h jpgfile.h \ - particles.h pngfile.h render.h renderext.h screenshot.h sky.h \ - state.h text.h textures.h tgafile.h + +librender_la_SOURCES = \ + camera.cc \ + debugdrawer.cc \ + draw.cc \ + dust.cc \ + gl.cc \ + image.cc \ + jpgfile.cc \ + particles.cc \ + pngfile.cc \ + render.cc \ + renderext.cc \ + screenshot.cc \ + sky.cc \ + state.cc \ + text.cc \ + textures.cc \ + tgafile.cc + +noinst_HEADERS = \ + camera.h \ + debugdrawer.h \ + draw.h \ + dust.h \ + gl.h \ + image.h \ + jpgfile.h \ + particles.h \ + pngfile.h \ + render.h \ + renderext.h \ + screenshot.h \ + sky.h \ + state.h \ + text.h \ + textures.h \ + tgafile.h diff --git a/src/render/debugdrawer.cc b/src/render/debugdrawer.cc new file mode 100644 index 0000000..03d5746 --- /dev/null +++ b/src/render/debugdrawer.cc @@ -0,0 +1,127 @@ +/* + render/debugdrawer.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#include "render/debugdrawer.h" +#include "render/gl.h" +#include "sys/sys.h" + +namespace render { + +DebugDrawer bullet_debugdrawer; + +DebugDrawer::DebugDrawer() +{ + debugdrawer_debugmode = btIDebugDraw::DBG_DrawWireframe + btIDebugDraw::DBG_DrawConstraints; +} + +DebugDrawer::~DebugDrawer() +{ +} + +void DebugDrawer::drawLine(const btVector3& from, const btVector3& to,const btVector3& color) +{ + gl::vertex(from[0], from[1], from[2]); + gl::vertex(to[0], to[1], to[2]); +} + +void DebugDrawer::drawLine(const btVector3& from, const btVector3 & to, const btVector3 & fromColor, const btVector3 & toColor) +{ + gl::vertex(from[0], from[1], from[2]); + gl::vertex(to[0], to[1], to[2]); +} + +void DebugDrawer::drawContactPoint(const btVector3 & point, const btVector3 & normal, btScalar distance , int lifetime, const btVector3 & color) +{ + +} + +void DebugDrawer::drawSphere(btScalar radius, const btTransform & transform, const btVector3 & color) +{ + btVector3 start = transform.getOrigin(); + + const btVector3 xoffs = transform.getBasis() * btVector3(radius,0,0); + const btVector3 yoffs = transform.getBasis() * btVector3(0,radius,0); + const btVector3 zoffs = transform.getBasis() * btVector3(0,0,radius); + + // XY + drawLine(start-xoffs, start+yoffs, color); + drawLine(start+yoffs, start+xoffs, color); + drawLine(start+xoffs, start-yoffs, color); + drawLine(start-yoffs, start-xoffs, color); + + // XZ + drawLine(start-xoffs, start+zoffs, color); + drawLine(start+zoffs, start+xoffs, color); + drawLine(start+xoffs, start-zoffs, color); + drawLine(start-zoffs, start-xoffs, color); + + // YZ + drawLine(start-yoffs, start+zoffs, color); + drawLine(start+zoffs, start+yoffs, color); + drawLine(start+yoffs, start-zoffs, color); + drawLine(start-zoffs, start-yoffs, color); +} + +void DebugDrawer::drawSphere(const btVector3 & p, btScalar radius, const btVector3 & color) +{ + btTransform tr; + tr.setIdentity(); + tr.setOrigin(p); + drawSphere(radius,tr,color); +} + +void DebugDrawer::drawBox(const btVector3 & bbMin, const btVector3 & bbMax, const btVector3 & color) +{ + drawLine(btVector3(bbMin[0], bbMin[1], bbMin[2]), btVector3(bbMax[0], bbMin[1], bbMin[2]), color); + drawLine(btVector3(bbMax[0], bbMin[1], bbMin[2]), btVector3(bbMax[0], bbMax[1], bbMin[2]), color); + drawLine(btVector3(bbMax[0], bbMax[1], bbMin[2]), btVector3(bbMin[0], bbMax[1], bbMin[2]), color); + drawLine(btVector3(bbMin[0], bbMax[1], bbMin[2]), btVector3(bbMin[0], bbMin[1], bbMin[2]), color); + drawLine(btVector3(bbMin[0], bbMin[1], bbMin[2]), btVector3(bbMin[0], bbMin[1], bbMax[2]), color); + drawLine(btVector3(bbMax[0], bbMin[1], bbMin[2]), btVector3(bbMax[0], bbMin[1], bbMax[2]), color); + drawLine(btVector3(bbMax[0], bbMax[1], bbMin[2]), btVector3(bbMax[0], bbMax[1], bbMax[2]), color); + drawLine(btVector3(bbMin[0], bbMax[1], bbMin[2]), btVector3(bbMin[0], bbMax[1], bbMax[2]), color); + drawLine(btVector3(bbMin[0], bbMin[1], bbMax[2]), btVector3(bbMax[0], bbMin[1], bbMax[2]), color); + drawLine(btVector3(bbMax[0], bbMin[1], bbMax[2]), btVector3(bbMax[0], bbMax[1], bbMax[2]), color); + drawLine(btVector3(bbMax[0], bbMax[1], bbMax[2]), btVector3(bbMin[0], bbMax[1], bbMax[2]), color); + drawLine(btVector3(bbMin[0], bbMax[1], bbMax[2]), btVector3(bbMin[0], bbMin[1], bbMax[2]), color); +} + +void DebugDrawer::drawBox(const btVector3 & bbMin, const btVector3 & bbMax, const btTransform & trans, const btVector3 & color) +{ + drawLine(trans * btVector3(bbMin[0], bbMin[1], bbMin[2]), trans * btVector3(bbMax[0], bbMin[1], bbMin[2]), color); + drawLine(trans * btVector3(bbMax[0], bbMin[1], bbMin[2]), trans * btVector3(bbMax[0], bbMax[1], bbMin[2]), color); + drawLine(trans * btVector3(bbMax[0], bbMax[1], bbMin[2]), trans * btVector3(bbMin[0], bbMax[1], bbMin[2]), color); + drawLine(trans * btVector3(bbMin[0], bbMax[1], bbMin[2]), trans * btVector3(bbMin[0], bbMin[1], bbMin[2]), color); + drawLine(trans * btVector3(bbMin[0], bbMin[1], bbMin[2]), trans * btVector3(bbMin[0], bbMin[1], bbMax[2]), color); + drawLine(trans * btVector3(bbMax[0], bbMin[1], bbMin[2]), trans * btVector3(bbMax[0], bbMin[1], bbMax[2]), color); + drawLine(trans * btVector3(bbMax[0], bbMax[1], bbMin[2]), trans * btVector3(bbMax[0], bbMax[1], bbMax[2]), color); + drawLine(trans * btVector3(bbMin[0], bbMax[1], bbMin[2]), trans * btVector3(bbMin[0], bbMax[1], bbMax[2]), color); + drawLine(trans * btVector3(bbMin[0], bbMin[1], bbMax[2]), trans * btVector3(bbMax[0], bbMin[1], bbMax[2]), color); + drawLine(trans * btVector3(bbMax[0], bbMin[1], bbMax[2]), trans * btVector3(bbMax[0], bbMax[1], bbMax[2]), color); + drawLine(trans * btVector3(bbMax[0], bbMax[1], bbMax[2]), trans * btVector3(bbMin[0], bbMax[1], bbMax[2]), color); + drawLine(trans * btVector3(bbMin[0], bbMax[1], bbMax[2]), trans * btVector3(bbMin[0], bbMin[1], bbMax[2]), color); +} +void DebugDrawer::reportErrorWarning(const char *warningString) +{ + con_warn << warningString << std::endl; +} + +void DebugDrawer::draw3dText(const btVector3 &location, const char *textString) +{ +} + +void DebugDrawer::setDebugMode(int debugMode) +{ + debugdrawer_debugmode = debugMode; +} + +int DebugDrawer::getDebugMode() const +{ + return debugdrawer_debugmode; +} + + +} // namespace render
\ No newline at end of file diff --git a/src/render/debugdrawer.h b/src/render/debugdrawer.h new file mode 100644 index 0000000..a23cecc --- /dev/null +++ b/src/render/debugdrawer.h @@ -0,0 +1,54 @@ +/* + render/debugdrawer.h + This file is part of the Osirion project and is distributed under + the terms of the GNU General Public License version 2 +*/ + +#ifndef __INCLUDED_RENDER_DEBUGDRAWER_H__ +#define __INCLUDED_RENDER_DEBUGDRAWER_H__ + +#include "LinearMath/btIDebugDraw.h" + +namespace render { + +/** + * @brief implementation for the bullet debug draw interface + * This class implements the bullet btIDebugDraw interface to + * render the world as seen by the bullet physics library + */ +class DebugDrawer: public btIDebugDraw +{ +public: + DebugDrawer(); + virtual ~DebugDrawer(); + + virtual void drawLine(const btVector3 & from, const btVector3 & to, const btVector3 & color); + + virtual void drawLine(const btVector3& from, const btVector3 & to, const btVector3 & fromColor, const btVector3 & toColor); + + virtual void drawContactPoint(const btVector3 & point, const btVector3 & normal, btScalar distance, int lifetime, const btVector3 & color); + + virtual void drawSphere(btScalar radius, const btTransform & transform, const btVector3 & color); + + virtual void drawSphere(const btVector3 & p, btScalar radius, const btVector3 & color); + + virtual void drawBox(const btVector3 & bbMin, const btVector3 & bbMax, const btVector3 & color); + + virtual void drawBox(const btVector3 & bbMin, const btVector3 & bbMax, const btTransform & trans, const btVector3 & color); + + virtual void reportErrorWarning(const char *warningString); + + virtual void draw3dText(const btVector3 &location, const char *textString); + + virtual void setDebugMode(int debugMode); + + virtual int getDebugMode() const; + +private: + int debugdrawer_debugmode; +}; + +extern DebugDrawer bullet_debugdrawer; +} // namespace render + +#endif // __INCLUDED_RENDER_DEBUGDRAWER_H__ diff --git a/src/render/draw.cc b/src/render/draw.cc index d54387a..656653b 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -15,6 +15,7 @@ #include "model/model.h" #include "render/render.h" #include "render/textures.h" +#include "render/debugdrawer.h" #include "render/draw.h" #include "render/dust.h" #include "render/gl.h" @@ -1206,12 +1207,17 @@ void draw(float seconds) glPolygonMode(GL_FRONT, GL_FILL); draw_pass_sky(); // draw the skybox + + gl::depthmask(GL_TRUE); // enable writing to the depth buffer + gl::enable(GL_DEPTH_TEST); + gl::enable(GL_CULL_FACE); // enable culling + gl::enable(GL_COLOR_MATERIAL); // enable color tracking // enable wireframe mode if requested if (r_wireframe && r_wireframe->value()) { glPolygonMode(GL_FRONT, GL_LINE); } - + // set vertex array pointers glInterleavedArrays(GL_T2F_N3F_V3F, 0, core::game()->vertexarray()->ptr()); @@ -1220,12 +1226,6 @@ void draw(float seconds) glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_VERTEX_ARRAY); - gl::depthmask(GL_TRUE); // enable writing to the depth buffer - gl::enable(GL_DEPTH_TEST); - - gl::enable(GL_CULL_FACE); // enable culling - gl::enable(GL_COLOR_MATERIAL); // enable color tracking - if (r_normalize && r_normalize->value()) { // enable full normalization gl::enable(GL_NORMALIZE); @@ -1248,7 +1248,7 @@ void draw(float seconds) // disable full normalization gl::disable(GL_NORMALIZE); } else { - // disable resaling of normals + // disable rescaling of normals gl::disable(GL_RESCALE_NORMAL); } @@ -1294,12 +1294,27 @@ void draw(float seconds) glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); - + gl::depthmask(GL_TRUE); // enable depth buffer writing + gl::disable(GL_DEPTH_TEST); // disable depth buffer testing + + // draw physics + if (r_physics && r_physics->value()) { + if (zone->physics()) { + if (!zone->physics()->getDebugDrawer()) + zone->physics()->setDebugDrawer(&bullet_debugdrawer); + + // draw physics bodies in red + gl::color(1.0f, 0.0f, 0.0f, 1.0f); + gl::begin(gl::Lines); + zone->physics()->debugDrawWorld(); + gl::end(); + } + } + gl::disable(GL_COLOR_MATERIAL); // disable color tracking gl::disable(GL_CULL_FACE); // disable culling - gl::depthmask(GL_TRUE); // enable depth buffer writing - gl::disable(GL_DEPTH_TEST); // disable depth buffer testing + // GL_BLEND must be enabled for the GUI } diff --git a/src/render/render.cc b/src/render/render.cc index acc9c86..398cb6b 100644 --- a/src/render/render.cc +++ b/src/render/render.cc @@ -36,7 +36,7 @@ core::Cvar *r_radius = 0; core::Cvar *r_sky = 0; core::Cvar *r_wireframe = 0; core::Cvar *r_mipmap = 0; -core::Cvar *r_collision = 0; +core::Cvar *r_physics = 0; core::Cvar *r_normals = 0; core::Cvar *r_normalize = 0; @@ -106,10 +106,10 @@ void init(int width, int height) r_specular = core::Cvar::get("r_specular", "0.2", core::Cvar::Archive); r_specular->set_info("[float] specular light intensity"); - /* - r_collision = core::Cvar::get("r_collision", "1", core::Cvar::Archive); - r_collision->set_info("[bool] render collision (server side only)"); - */ + + r_physics = core::Cvar::get("r_physics", "0", core::Cvar::Archive); + r_physics->set_info("[bool] render physics (local game only)"); + Screenshot::screenshotformat = core::Cvar::get("screenshotformat", "jpg", core::Cvar::Archive); Screenshot::screenshotformat->set_info("[string] screenshot format: jpg png tga"); diff --git a/src/render/render.h b/src/render/render.h index 190cdb5..5e5f3d1 100644 --- a/src/render/render.h +++ b/src/render/render.h @@ -56,8 +56,8 @@ extern core::Cvar *r_sky; extern core::Cvar *r_wireframe; /// render vertex normals extern core::Cvar *r_normals; -/// render collision -extern core::Cvar *r_collision; +/// render physics +extern core::Cvar *r_physics; /// use hardware generated mipmaps (requires OpenGL 1.4, does not work on all cards) extern core::Cvar *r_mipmap; /// use GL_NORMALIZE instead of GL_RESCALE_NORMAL |