1 // 2 // SuperTuxKart - a fun racing game with go-kart 3 // Copyright (C) 2004-2015 Ingo Ruhnke <grumbel@gmx.de> 4 // Copyright (C) 2013-2015 Joerg Henrichs 5 // 6 // This program is free software; you can redistribute it and/or 7 // modify it under the terms of the GNU General Public License 8 // as published by the Free Software Foundation; either version 3 9 // of the License, or (at your option) any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with this program; if not, write to the Free Software 18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 20 #ifndef HEADER_SKID_MARK_HPP 21 #define HEADER_SKID_MARK_HPP 22 23 #include <aabbox3d.h> 24 #include <memory> 25 #include <SColor.h> 26 #include <vector> 27 28 using namespace irr; 29 30 class Material; 31 32 namespace SP 33 { 34 class SPDynamicDrawCall; 35 class SPShader; 36 } 37 38 #include "utils/no_copy.hpp" 39 #include "utils/vec3.hpp" 40 41 class AbstractKart; 42 43 /** \brief This class is responsible for drawing skid marks for a kart. 44 * \ingroup graphics 45 */ 46 class SkidMarks : public NoCopy 47 { 48 private: 49 /** Reference to the kart to which these skidmarks belong. */ 50 const AbstractKart &m_kart; 51 52 /** True if the kart was skidding in the previous frame. */ 53 bool m_skid_marking; 54 55 /** Reduce effect of Z-fighting. */ 56 float m_width; 57 58 /** Initial alpha value. */ 59 static const int m_start_alpha; 60 61 /** Initial grey value, same for the 3 channels. */ 62 static const int m_start_grey; 63 64 /** Material to use for the skid marks. */ 65 Material* m_material; 66 67 /** Shader(alphablend) to use for the skid marks. */ 68 std::shared_ptr<SP::SPShader> m_shader; 69 70 // ------------------------------------------------------------------------ 71 class SkidMarkQuads : public NoCopy 72 { 73 /** Used to move skid marks at the same location slightly on 74 * top of each other to avoid a 'wobbling' effect when sometines 75 * the first and sometimes the 2nd one is drawn on top. */ 76 float m_z_offset; 77 78 /** Fade out = alpha value. */ 79 float m_fade_out; 80 81 video::SColor m_start_color; 82 83 /** Vector marking the start of the skidmarks (located between left and right wheel) */ 84 Vec3 m_center_start; 85 86 std::shared_ptr<SP::SPDynamicDrawCall> m_dy_dc; 87 88 public: 89 SkidMarkQuads (const Vec3 &left, const Vec3 &right, 90 const Vec3 &normal, Material* material, 91 std::shared_ptr<SP::SPShader> shader, 92 float z_offset, video::SColor* custom_color = NULL); 93 ~SkidMarkQuads(); 94 void add (const Vec3 &left, 95 const Vec3 &right, 96 const Vec3 &normal, 97 float distance); 98 bool fade (float f); getCenterStart() const99 const Vec3& getCenterStart() const { return m_center_start; } 100 }; // SkidMarkQuads 101 102 // ------------------------------------------------------------------------ 103 /** Two skidmark objects for the left and right wheel. */ 104 std::vector<std::unique_ptr<SkidMarkQuads> > m_left, m_right; 105 106 /** Shared static so that consecutive skidmarks are at a slightly 107 * different height. */ 108 static float m_avoid_z_fighting; 109 110 public: 111 SkidMarks(const AbstractKart& kart, float width=0.32f); 112 ~SkidMarks(); 113 void update (float dt, bool force_skid_marks=false, 114 video::SColor* custom_color = NULL); 115 void reset(); 116 117 }; // SkidMarks 118 119 #endif 120 121 /* EOF */ 122