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)) : NULL;
93 template <
bool C,
bool I>
94 const Vec3f* specColorAt(
int i)
const {
95 return C ? &colors.at(specIndiceAt<I>(i)) : NULL;
99 unsigned int specIndiceAt(
unsigned int i)
const {
100 return I ? indices.at(i) : i;
103 template<
bool T,
bool I,
bool C,
class Func>
104 inline Func specForeachTriangle(Func func)
const;
116 bool textured = isTextured();
117 bool colored = isColored();
118 bool useIndice = isIndexed();
125 return specForeachTriangle<true, true, true, Func>(func);
127 return specForeachTriangle<true, true, false, Func>(func);
132 return specForeachTriangle<true, false, true, Func>(func);
134 return specForeachTriangle<true, false, false, Func>(func);
142 return specForeachTriangle<false, true, true, Func>(func);
144 return specForeachTriangle<false, true, false, Func>(func);
149 return specForeachTriangle<false, false, true, Func>(func);
151 return specForeachTriangle<false, false, false, Func>(func);
156 template<
bool T,
bool I,
bool C,
class Func>
157 Func StelVertexArray::specForeachTriangle(Func func)
const 159 switch (primitiveType)
161 case StelVertexArray::Triangles:
162 Q_ASSERT(
vertex.size() % 3 == 0);
163 for (
int i = 0; i <
vertex.size(); i += 3)
165 func(specVertexAt<I>(i), specVertexAt<I>(i+1), specVertexAt<I>(i+2),
166 specTexCoordAt<T, I>(i), specTexCoordAt<T, I>(i+1), specTexCoordAt<T, I>(i+2),
167 specColorAt<C, I>(i), specColorAt<C, I>(i+1), specColorAt<C, I>(i+2),
168 specIndiceAt<I>(i), specIndiceAt<I>(i+1), specIndiceAt<I>(i+2));
171 case StelVertexArray::TriangleFan:
173 const Vec3d* v0 = specVertexAt<I>(0);
174 const Vec2f* t0 = specTexCoordAt<T, I>(0);
175 const Vec3f* c0 = specColorAt<C, I>(0);
176 unsigned int i0 = specIndiceAt<I>(0);
177 for (
int i = 1; i <
vertex.size() - 1; ++i)
179 func(v0, specVertexAt<I>(i), specVertexAt<I>(i+1),
180 t0, specTexCoordAt<T, I>(i), specTexCoordAt<T, I>(i+1),
181 c0, specColorAt<C, I>(i), specColorAt<C, I>(i+1),
182 i0, specIndiceAt<I>(i), specIndiceAt<I>(i+1));
186 case StelVertexArray::TriangleStrip:
188 for (
int i = 2; i <
vertex.size(); ++i)
191 func(specVertexAt<I>(i-2), specVertexAt<I>(i-1), specVertexAt<I>(i),
192 specTexCoordAt<T, I>(i-2), specTexCoordAt<T, I>(i-1), specTexCoordAt<T, I>(i),
193 specColorAt<C, I>(i-2), specColorAt<C, I>(i-1), specColorAt<C, I>(i),
194 specIndiceAt<I>(i-2), specIndiceAt<I>(i-1), specIndiceAt<I>(i));
196 func(specVertexAt<I>(i-1), specVertexAt<I>(i-2), specVertexAt<I>(i),
197 specTexCoordAt<T, I>(i-1), specTexCoordAt<T, I>(i-2), specTexCoordAt<T, I>(i),
198 specColorAt<C, I>(i-1), specColorAt<C, I>(i-2), specColorAt<C, I>(i),
199 specIndiceAt<I>(i-1), specIndiceAt<I>(i-2), specIndiceAt<I>(i));
204 Q_ASSERT_X(0, Q_FUNC_INFO,
"unsupported primitive type");
210 #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.