SuperTuxKart
skid_marks.hpp
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 <memory>
24 #include <SColor.h>
25 #include <vector>
26 
27 using namespace irr;
28 
29 class Material;
30 
31 namespace SP
32 {
33  class SPDynamicDrawCall;
34  class SPShader;
35 }
36 
37 namespace irr
38 {
39  namespace scene
40  {
41  class IMeshSceneNode;
42  }
43 }
44 
45 #include "utils/no_copy.hpp"
46 #include "utils/vec3.hpp"
47 
48 class AbstractKart;
49 
53 class SkidMarks : public NoCopy
54 {
55 private:
58 
61 
63  float m_width;
64 
66  static const int m_start_alpha;
67 
69  static const int m_start_grey;
70 
73 
75  std::shared_ptr<SP::SPShader> m_shader;
76 
77  float m_dt;
78  // ------------------------------------------------------------------------
79  class SkidMarkQuads : public NoCopy
80  {
84  float m_z_offset;
85 
87  float m_fade_out;
88 
89  video::SColor m_start_color;
90 
93 
94  std::shared_ptr<SP::SPDynamicDrawCall> m_dy_dc;
95 
96  irr::scene::IMeshSceneNode* m_node;
97 
98  void addSP (const Vec3 &left,
99  const Vec3 &right,
100  const Vec3 &normal,
101  float distance);
102 
103  void addLegacy (const Vec3 &left,
104  const Vec3 &right,
105  const Vec3 &normal,
106  float distance);
107  public:
108  SkidMarkQuads (const Vec3 &left, const Vec3 &right,
109  const Vec3 &normal, Material* material,
110  std::shared_ptr<SP::SPShader> shader,
111  float z_offset, video::SColor* custom_color = NULL);
112  ~SkidMarkQuads();
113 
114  void add (const Vec3 &left,
115  const Vec3 &right,
116  const Vec3 &normal,
117  float distance);
118  bool fade (float f);
119  const Vec3& getCenterStart() const { return m_center_start; }
120  }; // SkidMarkQuads
121 
122  // ------------------------------------------------------------------------
124  std::vector<std::unique_ptr<SkidMarkQuads> > m_left, m_right;
125 
128  static float m_avoid_z_fighting;
129 
130 public:
131  SkidMarks(const AbstractKart& kart, float width=0.32f);
132  ~SkidMarks();
133  void update (float dt, bool force_skid_marks=false,
134  video::SColor* custom_color = NULL);
135  void reset();
136 
137 }; // SkidMarks
138 
139 #endif
140 
141 /* EOF */
An abstract interface for the actual karts.
Definition: abstract_kart.hpp:62
Definition: material.hpp:48
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26
Definition: skid_marks.hpp:80
float m_z_offset
Used to move skid marks at the same location slightly on top of each other to avoid a 'wobbling' effe...
Definition: skid_marks.hpp:84
float m_fade_out
Fade out = alpha value.
Definition: skid_marks.hpp:87
Vec3 m_center_start
Vector marking the start of the skidmarks (located between left and right wheel)
Definition: skid_marks.hpp:92
This class is responsible for drawing skid marks for a kart.
Definition: skid_marks.hpp:54
static float m_avoid_z_fighting
Shared static so that consecutive skidmarks are at a slightly different height.
Definition: skid_marks.hpp:128
Material * m_material
Material to use for the skid marks.
Definition: skid_marks.hpp:72
std::shared_ptr< SP::SPShader > m_shader
Shader(alphablend) to use for the skid marks.
Definition: skid_marks.hpp:75
bool m_skid_marking
True if the kart was skidding in the previous frame.
Definition: skid_marks.hpp:60
std::vector< std::unique_ptr< SkidMarkQuads > > m_left
Two skidmark objects for the left and right wheel.
Definition: skid_marks.hpp:124
float m_width
Reduce effect of Z-fighting.
Definition: skid_marks.hpp:63
static const int m_start_alpha
Initial alpha value.
Definition: skid_marks.hpp:66
static const int m_start_grey
Initial grey value, same for the 3 channels.
Definition: skid_marks.hpp:69
const AbstractKart & m_kart
Reference to the kart to which these skidmarks belong.
Definition: skid_marks.hpp:57
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:35