Stellarium 0.12.4
TrailGroup.hpp
1 /*
2  * Stellarium
3  * Copyright (C) 2010 Fabien Chereau
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  */
19 
20 #ifndef TRAILGROUP_HPP
21 #define TRAILGROUP_HPP
22 
23 #include "VecMath.hpp"
24 #include "StelCore.hpp"
25 #include "StelObjectType.hpp"
26 
27 
29 {
30 public:
31  TrailGroup(float atimeExtent);
32 
33  ~TrailGroup();
34 
35  void draw(StelCore* core, class StelRenderer* renderer);
36 
37  // Add 1 point to all the curves at current time and suppress too old points
38  void update();
39 
40  // Set the matrix to use to post process J2000 positions before storing in the trail
41  void setJ2000ToTrailNative(const Mat4d& m);
42 
43  void addObject(const StelObjectP&, const Vec3f* col=NULL);
44 
45  void setOpacity(float op)
46  {
47  opacity = op;
48  }
49 
51  void reset();
52 
53 private:
55  struct ColoredVertex
56  {
57  Vec3f position;
58  Vec4f color;
59 
60  ColoredVertex(){}
61 
62  VERTEX_ATTRIBUTES(Vec3f Position, Vec4f Color);
63  };
64 
65  struct Trail
66  {
67  Trail(const StelObjectP& obj, const Vec3f& col)
68  : stelObject(obj), color(col), vertexBuffer(NULL)
69  {
70  }
71 
72  StelObjectP stelObject;
73 
74  // Using QVector instead of QList.
75  // QList is an array of pointers to elements, which are 8 byte on 64-bit,
76  // while Vec3f is 12 byte, so not much space saved (or time, at popFront).
77  // At the same time, it has a bad cache performance that slows down drawing.
78 
79  // All previous positions
80  QVector<Vec3f> posHistory;
81  Vec3f color;
82  StelVertexBuffer<ColoredVertex>* vertexBuffer;
83  };
84 
85  QList<Trail> allTrails;
86 
87  // Maximum time extent in days
88  float timeExtent;
89 
90  QList<float> times;
91 
92  Mat4d j2000ToTrailNative;
93  Mat4d j2000ToTrailNativeInverted;
94 
95  float opacity;
96 
100  double lastTimeInHistory;
101 };
102 
103 #endif // TRAILMGR_HPP