1 //
2 //  SuperTuxKart - a fun racing game with go-kart
3 //  Copyright (C) 2010-2015 Joerg Henrichs
4 //
5 //  This program is free software; you can redistribute it and/or
6 //  modify it under the terms of the GNU General Public License
7 //  as published by the Free Software Foundation; either version 3
8 //  of the License, or (at your option) any later version.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU General Public License for more details.
14 //
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program; if not, write to the Free Software
17 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 
19 #include "physics/irr_debug_drawer.hpp"
20 
21 #include "graphics/irr_driver.hpp"
22 #include "karts/abstract_kart.hpp"
23 #include "modes/world.hpp"
24 
25 #include <ISceneManager.h>
26 #include <ISceneNode.h>
27 #include <ICameraSceneNode.h>
28 
IrrDebugDrawer()29 IrrDebugDrawer::IrrDebugDrawer()
30 {
31     m_debug_mode = DM_NONE;
32 }   // IrrDebugDrawer
33 
34 // -----------------------------------------------------------------------------
35 /** Activates the next debug mode, or switches the mode off again.
36  */
nextDebugMode()37 void IrrDebugDrawer::nextDebugMode()
38 {
39     // Go to next debug mode. Note that debug mode 3 (
40     setDebugMode((DebugModeType) ((m_debug_mode+1) % 3));
41 }
42 // -----------------------------------------------------------------------------
43 
setDebugMode(DebugModeType mode)44 void IrrDebugDrawer::setDebugMode(DebugModeType mode)
45 {
46     m_debug_mode = mode;
47     World *world = World::getWorld();
48     unsigned int num_karts = world->getNumKarts();
49     for(unsigned int i=0; i<num_karts; i++)
50     {
51         AbstractKart *kart = world->getKart(i);
52         if(kart->isEliminated()) continue;
53         kart->getNode()->setVisible(!(m_debug_mode & DM_NO_KARTS_GRAPHICS));
54     }
55 }   // nextDebugMode
56 
57 // -----------------------------------------------------------------------------
drawLine(const btVector3 & from,const btVector3 & to,const btVector3 & color)58 void IrrDebugDrawer::drawLine(const btVector3& from, const btVector3& to,
59                               const btVector3& color)
60 {
61     video::SColor c(255, (int)(color.getX()*255), (int)(color.getY()*255),
62                          (int)(color.getZ()*255)                          );
63 
64     //World::getWorld()->getCa
65 
66     if (from.distance2(m_camera_pos) > 10000) return;
67 
68     std::vector<float>& v = m_lines[c];
69     v.push_back(from.getX());
70     v.push_back(from.getY());
71     v.push_back(from.getZ());
72     v.push_back(to.getX());
73     v.push_back(to.getY());
74     v.push_back(to.getZ());
75     //draw3DLine((const core::vector3df&)from, (const core::vector3df&)to, c);
76 }
77 
78 // -----------------------------------------------------------------------------
79 
beginNextFrame()80 void IrrDebugDrawer::beginNextFrame()
81 {
82     for (std::map<video::SColor, std::vector<float> >::iterator it = m_lines.begin(); it != m_lines.end(); it++)
83     {
84         it->second.clear();
85     }
86 
87     scene::ICameraSceneNode* camera = irr_driver->getSceneManager()->getActiveCamera();
88     m_camera_pos = camera->getPosition();
89 }
90 
91 /* EOF */
92 
93