Jimcpp 2.1.0
Jimcpp is a high-performance c++ graphics engine.
Loading...
Searching...
No Matches
S3DVertex.hpp
1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in jimcpp/jimcpp.hpp
4
5#ifndef S_3D_VERTEX_HPP_INCLUDED
6#define S_3D_VERTEX_HPP_INCLUDED
7
8#include <jimcpp/core/engine/vector3d.hpp>
9#include <jimcpp/core/engine/vector2d.hpp>
10#include <jimcpp/core/engine/SColor.hpp>
11
12namespace jpp
13{
14namespace video
15{
16
33
35const char* const sBuiltInVertexTypeNames[] =
36{
37 "standard",
38 "2tcoords",
39 "tangents",
40 0
41};
42
45{
46public:
48 S3DVertex() : Color(0xffffffff) {}
49
51 S3DVertex(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv)
52 : Pos(x,y,z), Normal(nx,ny,nz), Color(c), TCoords(tu,tv) {}
53
55 S3DVertex(const core::vector3df& pos, const core::vector3df& normal,
56 SColor color, const core::vector2d<f32>& tcoords)
57 : Pos(pos), Normal(normal), Color(color), TCoords(tcoords) {}
58
59public:
62
65
68
71
72public:
73 bool operator==(const S3DVertex& other) const
74 {
75 return ((Pos == other.Pos) && (Normal == other.Normal) &&
76 (Color == other.Color) && (TCoords == other.TCoords));
77 }
78
79 bool operator!=(const S3DVertex& other) const
80 {
81 return ((Pos != other.Pos) || (Normal != other.Normal) ||
82 (Color != other.Color) || (TCoords != other.TCoords));
83 }
84
85 bool operator<(const S3DVertex& other) const
86 {
87 return ((Pos < other.Pos) ||
88 ((Pos == other.Pos) && (Normal < other.Normal)) ||
89 ((Pos == other.Pos) && (Normal == other.Normal) && (Color < other.Color)) ||
90 ((Pos == other.Pos) && (Normal == other.Normal) && (Color == other.Color) && (TCoords < other.TCoords)));
91 }
92
95 {
96 return EVT_STANDARD;
97 }
98
99 //\param d d=0 returns other, d=1 returns this, values between interpolate.
100 S3DVertex getInterpolated(const S3DVertex& other, f32 d)
101 {
102 d = core::clamp(d, 0.0f, 1.0f);
103 return S3DVertex(Pos.getInterpolated(other.Pos, d),
104 Normal.getInterpolated(other.Normal, d),
105 Color.getInterpolated(other.Color, d),
107 }
108};
109
110
112
116{
117public:
120
122 S3DVertex2TCoords(f32 x, f32 y, f32 z, SColor c, f32 tu, f32 tv, f32 tu2, f32 tv2)
123 : S3DVertex(x,y,z, 0.0f, 0.0f, 0.0f, c, tu,tv), TCoords2(tu2,tv2) {}
124
127 const core::vector2d<f32>& tcoords, const core::vector2d<f32>& tcoords2)
128 : S3DVertex(pos, core::vector3df(), color, tcoords), TCoords2(tcoords2) {}
129
131 S3DVertex2TCoords(const core::vector3df& pos, const core::vector3df& normal, const SColor& color,
132 const core::vector2d<f32>& tcoords, const core::vector2d<f32>& tcoords2)
133 : S3DVertex(pos, normal, color, tcoords), TCoords2(tcoords2) {}
134
136 S3DVertex2TCoords(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv, f32 tu2, f32 tv2)
137 : S3DVertex(x,y,z, nx,ny,nz, c, tu,tv), TCoords2(tu2,tv2) {}
138
140 S3DVertex2TCoords(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv)
141 : S3DVertex(x,y,z, nx,ny,nz, c, tu,tv), TCoords2(tu,tv) {}
142
145 SColor color, const core::vector2d<f32>& tcoords)
146 : S3DVertex(pos, normal, color, tcoords), TCoords2(tcoords) {}
147
150
151public:
154
155public:
157 bool operator==(const S3DVertex2TCoords& other) const
158 {
159 return ((static_cast<S3DVertex>(*this)==static_cast<const S3DVertex&>(other)) &&
160 (TCoords2 == other.TCoords2));
161 }
162
164 bool operator!=(const S3DVertex2TCoords& other) const
165 {
166 return ((static_cast<S3DVertex>(*this)!=static_cast<const S3DVertex&>(other)) ||
167 (TCoords2 != other.TCoords2));
168 }
169
170 bool operator<(const S3DVertex2TCoords& other) const
171 {
172 return ((static_cast<S3DVertex>(*this) < other) ||
173 ((static_cast<S3DVertex>(*this) == static_cast<const S3DVertex&>(other)) && (TCoords2 < other.TCoords2)));
174 }
175
176 static E_VERTEX_TYPE getType()
177 {
178 return EVT_2TCOORDS;
179 }
180
181 //\param d d=0 returns other, d=1 returns this, values between interpolate.
182 S3DVertex2TCoords getInterpolated(const S3DVertex2TCoords& other, f32 d)
183 {
184 d = core::clamp(d, 0.0f, 1.0f);
185 return S3DVertex2TCoords(Pos.getInterpolated(other.Pos, d),
186 Normal.getInterpolated(other.Normal, d),
187 Color.getInterpolated(other.Color, d),
188 TCoords.getInterpolated(other.TCoords, d),
189 TCoords2.getInterpolated(other.TCoords2, d));
190 }
191};
192
193
195
199{
200public:
203
205 S3DVertexTangents(f32 x, f32 y, f32 z, f32 nx=0.0f, f32 ny=0.0f, f32 nz=0.0f,
206 SColor c = 0xFFFFFFFF, f32 tu=0.0f, f32 tv=0.0f,
207 f32 tanx=0.0f, f32 tany=0.0f, f32 tanz=0.0f,
208 f32 bx=0.0f, f32 by=0.0f, f32 bz=0.0f)
209 : S3DVertex(x,y,z, nx,ny,nz, c, tu,tv), Tangent(tanx,tany,tanz), Binormal(bx,by,bz) { }
210
213 const core::vector2df& tcoords)
214 : S3DVertex(pos, core::vector3df(), c, tcoords) { }
215
218 const core::vector3df& normal, SColor c,
219 const core::vector2df& tcoords,
220 const core::vector3df& tangent=core::vector3df(),
221 const core::vector3df& binormal=core::vector3df())
222 : S3DVertex(pos, normal, c, tcoords), Tangent(tangent), Binormal(binormal) { }
223
226
227public:
230
233
234public:
235 bool operator==(const S3DVertexTangents& other) const
236 {
237 return ((static_cast<S3DVertex>(*this)==static_cast<const S3DVertex&>(other)) &&
238 (Tangent == other.Tangent) &&
239 (Binormal == other.Binormal));
240 }
241
242 bool operator!=(const S3DVertexTangents& other) const
243 {
244 return ((static_cast<S3DVertex>(*this)!=static_cast<const S3DVertex&>(other)) ||
245 (Tangent != other.Tangent) ||
246 (Binormal != other.Binormal));
247 }
248
249 bool operator<(const S3DVertexTangents& other) const
250 {
251 return ((static_cast<S3DVertex>(*this) < other) ||
252 ((static_cast<S3DVertex>(*this) == static_cast<const S3DVertex&>(other)) && (Tangent < other.Tangent)) ||
253 ((static_cast<S3DVertex>(*this) == static_cast<const S3DVertex&>(other)) && (Tangent == other.Tangent) && (Binormal < other.Binormal)));
254 }
255
256 static E_VERTEX_TYPE getType()
257 {
258 return EVT_TANGENTS;
259 }
260
261 S3DVertexTangents getInterpolated(const S3DVertexTangents& other, f32 d)
262 {
263 d = core::clamp(d, 0.0f, 1.0f);
264 return S3DVertexTangents(Pos.getInterpolated(other.Pos, d),
265 Normal.getInterpolated(other.Normal, d),
266 Color.getInterpolated(other.Color, d),
267 TCoords.getInterpolated(other.TCoords, d),
268 Tangent.getInterpolated(other.Tangent, d),
269 Binormal.getInterpolated(other.Binormal, d));
270 }
271};
272
273
274
275inline u32 getVertexPitchFromType(E_VERTEX_TYPE vertexType)
276{
277 switch (vertexType)
278 {
280 return sizeof(video::S3DVertex2TCoords);
282 return sizeof(video::S3DVertexTangents);
283 default:
284 return sizeof(video::S3DVertex);
285 }
286}
287
288} // end namespace video
289} // end namespace jpp
290
291#endif
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.hpp:22
vector2d< T > getInterpolated(const vector2d< T > &other, f64 d) const
Creates an interpolated vector between this vector and another vector.
Definition vector2d.hpp:312
vector3d< T > getInterpolated(const vector3d< T > &other, f64 d) const
Creates an interpolated vector between this vector and another vector.
Definition vector3d.hpp:287
Vertex with two texture coordinates.
Definition S3DVertex.hpp:116
S3DVertex2TCoords(f32 x, f32 y, f32 z, SColor c, f32 tu, f32 tv, f32 tu2, f32 tv2)
constructor with two different texture coords, but no normal
Definition S3DVertex.hpp:122
S3DVertex2TCoords(const core::vector3df &pos, const core::vector3df &normal, SColor color, const core::vector2d< f32 > &tcoords)
constructor with the same texture coords and normal
Definition S3DVertex.hpp:144
bool operator!=(const S3DVertex2TCoords &other) const
Inequality operator.
Definition S3DVertex.hpp:164
S3DVertex2TCoords(const core::vector3df &pos, const core::vector3df &normal, const SColor &color, const core::vector2d< f32 > &tcoords, const core::vector2d< f32 > &tcoords2)
constructor with all values
Definition S3DVertex.hpp:131
S3DVertex2TCoords(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv, f32 tu2, f32 tv2)
constructor with all values
Definition S3DVertex.hpp:136
S3DVertex2TCoords(const S3DVertex &o)
constructor from S3DVertex
Definition S3DVertex.hpp:149
core::vector2d< f32 > TCoords2
Second set of texture coordinates.
Definition S3DVertex.hpp:153
S3DVertex2TCoords()
default constructor
Definition S3DVertex.hpp:119
bool operator==(const S3DVertex2TCoords &other) const
Equality operator.
Definition S3DVertex.hpp:157
S3DVertex2TCoords(const core::vector3df &pos, SColor color, const core::vector2d< f32 > &tcoords, const core::vector2d< f32 > &tcoords2)
constructor with two different texture coords, but no normal
Definition S3DVertex.hpp:126
S3DVertex2TCoords(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv)
constructor with the same texture coords and normal
Definition S3DVertex.hpp:140
Vertex with a tangent and binormal vector.
Definition S3DVertex.hpp:199
S3DVertexTangents(f32 x, f32 y, f32 z, f32 nx=0.0f, f32 ny=0.0f, f32 nz=0.0f, SColor c=0xFFFFFFFF, f32 tu=0.0f, f32 tv=0.0f, f32 tanx=0.0f, f32 tany=0.0f, f32 tanz=0.0f, f32 bx=0.0f, f32 by=0.0f, f32 bz=0.0f)
constructor
Definition S3DVertex.hpp:205
S3DVertexTangents(const core::vector3df &pos, const core::vector3df &normal, SColor c, const core::vector2df &tcoords, const core::vector3df &tangent=core::vector3df(), const core::vector3df &binormal=core::vector3df())
constructor
Definition S3DVertex.hpp:217
S3DVertexTangents()
default constructor
Definition S3DVertex.hpp:202
S3DVertexTangents(const S3DVertex &o)
constructor from S3DVertex
Definition S3DVertex.hpp:225
core::vector3df Tangent
Tangent vector along the x-axis of the texture.
Definition S3DVertex.hpp:229
S3DVertexTangents(const core::vector3df &pos, SColor c, const core::vector2df &tcoords)
constructor
Definition S3DVertex.hpp:212
core::vector3df Binormal
Binormal vector (tangent x normal)
Definition S3DVertex.hpp:232
standard vertex used by the Jimcpp engine.
Definition S3DVertex.hpp:45
core::vector3df Normal
Normal vector.
Definition S3DVertex.hpp:64
SColor Color
Color.
Definition S3DVertex.hpp:67
core::vector3df Pos
Position.
Definition S3DVertex.hpp:61
S3DVertex(const core::vector3df &pos, const core::vector3df &normal, SColor color, const core::vector2d< f32 > &tcoords)
constructor
Definition S3DVertex.hpp:55
static E_VERTEX_TYPE getType()
Get type of the class.
Definition S3DVertex.hpp:94
core::vector2d< f32 > TCoords
Texture coordinates.
Definition S3DVertex.hpp:70
S3DVertex()
default constructor
Definition S3DVertex.hpp:48
S3DVertex(f32 x, f32 y, f32 z, f32 nx, f32 ny, f32 nz, SColor c, f32 tu, f32 tv)
constructor
Definition S3DVertex.hpp:51
Class representing a 32 bit ARGB color.
Definition SColor.hpp:317
SColor getInterpolated(const SColor &other, f32 d) const
Interpolates the color with a f32 value to another color.
Definition SColor.hpp:455
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
Definition irrMath.hpp:164
const char *const sBuiltInVertexTypeNames[]
Array holding the built in vertex type names.
Definition S3DVertex.hpp:35
E_VERTEX_TYPE
Enumeration for all vertex types there are.
Definition S3DVertex.hpp:19
@ EVT_STANDARD
Standard vertex type used by the Jimcpp engine, video::S3DVertex.
Definition S3DVertex.hpp:21
@ EVT_2TCOORDS
Vertex with two texture coordinates, video::S3DVertex2TCoords.
Definition S3DVertex.hpp:25
@ EVT_TANGENTS
Vertex with a tangent and binormal vector, video::S3DVertexTangents.
Definition S3DVertex.hpp:31
As of Jimcpp 1.6, position2d is a synonym for vector2d.
Definition vector3d.hpp:11
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.hpp:64
float f32
32 bit floating point variable.
Definition irrTypes.hpp:110

Jimcpp    @cppfx.xyz

K