20 #ifndef __STELVERTEXARRAY_HPP__ 21 #define __STELVERTEXARRAY_HPP__ 23 #include "VecMath.hpp" 31 enum StelPrimitiveType
38 TriangleStrip = 0x0005,
42 StelVertexArray(StelPrimitiveType pType=StelVertexArray::Triangles) : primitiveType(pType) {;}
43 StelVertexArray(
const QVector<Vec3d>& v, StelPrimitiveType pType=StelVertexArray::Triangles,
const QVector<Vec2f>& t=QVector<Vec2f>(),
const QVector<unsigned short> i=QVector<unsigned short>()) :
58 StelPrimitiveType primitiveType;
60 bool isIndexed()
const {
return !indices.isEmpty();}
62 bool isTextured()
const {
return !texCoords.isEmpty();}
64 bool isColored()
const {
return !colors.isEmpty();}
83 const Vec3d* specVertexAt(
int i)
const {
84 return &vertex.at(specIndiceAt<I>(i));
87 template <
bool T,
bool I>
88 const Vec2f* specTexCoordAt(
int i)
const {
89 return T ? &texCoords.at(specIndiceAt<I>(i)) : Q_NULLPTR;
92 template <
bool C,
bool I>
93 const Vec3f* specColorAt(
int i)
const {
94 return C ? &colors.at(specIndiceAt<I>(i)) : Q_NULLPTR;
98 unsigned int specIndiceAt(
unsigned int i)
const {
99 return I ? indices.at(i) : i;
102 template<
bool T,
bool I,
bool C,
class Func>
103 inline Func specForeachTriangle(Func func)
const;
115 bool textured = isTextured();
116 bool colored = isColored();
117 bool useIndice = isIndexed();
124 return specForeachTriangle<true, true, true, Func>(func);
126 return specForeachTriangle<true, true, false, Func>(func);
131 return specForeachTriangle<true, false, true, Func>(func);
133 return specForeachTriangle<true, false, false, Func>(func);
141 return specForeachTriangle<false, true, true, Func>(func);
143 return specForeachTriangle<false, true, false, Func>(func);
148 return specForeachTriangle<false, false, true, Func>(func);
150 return specForeachTriangle<false, false, false, Func>(func);
155 template<
bool T,
bool I,
bool C,
class Func>
156 Func StelVertexArray::specForeachTriangle(Func func)
const 158 switch (primitiveType)
160 case StelVertexArray::Triangles:
161 Q_ASSERT(
vertex.size() % 3 == 0);
162 for (
int i = 0; i <
vertex.size(); i += 3)
164 func(specVertexAt<I>(i), specVertexAt<I>(i+1), specVertexAt<I>(i+2),
165 specTexCoordAt<T, I>(i), specTexCoordAt<T, I>(i+1), specTexCoordAt<T, I>(i+2),
166 specColorAt<C, I>(i), specColorAt<C, I>(i+1), specColorAt<C, I>(i+2),
167 specIndiceAt<I>(i), specIndiceAt<I>(i+1), specIndiceAt<I>(i+2));
170 case StelVertexArray::TriangleFan:
172 const Vec3d* v0 = specVertexAt<I>(0);
173 const Vec2f* t0 = specTexCoordAt<T, I>(0);
174 const Vec3f* c0 = specColorAt<C, I>(0);
175 unsigned int i0 = specIndiceAt<I>(0);
176 for (
int i = 1; i <
vertex.size() - 1; ++i)
178 func(v0, specVertexAt<I>(i), specVertexAt<I>(i+1),
179 t0, specTexCoordAt<T, I>(i), specTexCoordAt<T, I>(i+1),
180 c0, specColorAt<C, I>(i), specColorAt<C, I>(i+1),
181 i0, specIndiceAt<I>(i), specIndiceAt<I>(i+1));
185 case StelVertexArray::TriangleStrip:
187 for (
int i = 2; i <
vertex.size(); ++i)
190 func(specVertexAt<I>(i-2), specVertexAt<I>(i-1), specVertexAt<I>(i),
191 specTexCoordAt<T, I>(i-2), specTexCoordAt<T, I>(i-1), specTexCoordAt<T, I>(i),
192 specColorAt<C, I>(i-2), specColorAt<C, I>(i-1), specColorAt<C, I>(i),
193 specIndiceAt<I>(i-2), specIndiceAt<I>(i-1), specIndiceAt<I>(i));
195 func(specVertexAt<I>(i-1), specVertexAt<I>(i-2), specVertexAt<I>(i),
196 specTexCoordAt<T, I>(i-1), specTexCoordAt<T, I>(i-2), specTexCoordAt<T, I>(i),
197 specColorAt<C, I>(i-1), specColorAt<C, I>(i-2), specColorAt<C, I>(i),
198 specIndiceAt<I>(i-1), specIndiceAt<I>(i-2), specIndiceAt<I>(i));
203 Q_ASSERT_X(0, Q_FUNC_INFO,
"unsupported primitive type");
209 #endif // __STELVERTEXARRAY_HPP__ QVector< Vec2f > texCoords
OpenGL compatible array of edge flags to be displayed using vertex arrays.
Func foreachTriangle(Func func) const
call a function for each triangle of the array.
QVector< Vec3f > colors
OpenGL compatible array of vertex colors to be displayed using arrays.
A templatized 2d vector compatible with openGL.
QDataStream & operator<<(QDataStream &out, const SphericalRegionP ®ion)
Serialize the passed SphericalRegionP into a binary blob.
Provide the main interface to all operations of projecting coordinates from sky to screen...
QVector< Vec3d > vertex
OpenGL compatible array of 3D vertex to be displayed using vertex arrays.
QDataStream & operator>>(QDataStream &in, SphericalRegionP ®ion)
Load the SphericalRegionP from a binary blob.
StelVertexArray removeDiscontinuousTriangles(const class StelProjector *prj) const
Create a copy of the array with all the triangles intersecting the projector discontinuity removed...
QVector< unsigned short > indices
OpenGL compatible array of indices for the vertex and the textures.