~ubuntu-branches/ubuntu/warty/xplanet/warty

« back to all changes in this revision

Viewing changes to src/libmultiple/addOrbits.cpp

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones
  • Date: 2004-08-24 07:14:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040824071400-2dr4qnjbjmm8z3ia
Tags: 1.0.6-1ubuntu1
Build-depend: libtiff4-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <cmath>
 
2
#include <map>
 
3
using namespace std;
 
4
 
 
5
#include "body.h"
 
6
#include "Options.h"
 
7
#include "PlanetProperties.h"
 
8
#include "View.h"
 
9
 
 
10
#include "libannotate/LineSegment.h"
 
11
#include "libmultiple/libmultiple.h"
 
12
#include "libplanet/Planet.h"
 
13
 
 
14
static void
 
15
addArc(const double startTime, const double stopTime, 
 
16
       const int numTimes, const unsigned char color[3],
 
17
       const View *view, 
 
18
       const int width, const int height, 
 
19
       const double Prx, const double Pry, const double Prz,
 
20
       Planet *p, multimap<double, Annotation *> &annotationMap)
 
21
{
 
22
    Options *options = Options::getInstance();
 
23
 
 
24
    const body b = p->Index();
 
25
    const bool isTarget = (b == options->getTarget());
 
26
 
 
27
    const double delTime = (stopTime - startTime) / numTimes;
 
28
    bool firstTime = true;
 
29
    double prevX = 0, prevY = 0, prevZ = 0;
 
30
    for (int i = 0; i <= numTimes; i++)
 
31
    {
 
32
        const double jd = startTime + i * delTime;
 
33
 
 
34
        double X, Y, Z;
 
35
        Planet planet(jd, b);
 
36
        planet.calcHeliocentricEquatorial(false);
 
37
        planet.getPosition(X, Y, Z);
 
38
            
 
39
        view->XYZToPixel(X + Prx, Y + Pry, Z + Prz,
 
40
                         X, Y, Z);
 
41
        X += options->getCenterX();
 
42
        Y += options->getCenterY();
 
43
 
 
44
        if (!firstTime)
 
45
        {
 
46
            double nearX, nearY, nearZ;
 
47
            double farX, farY, farZ;
 
48
 
 
49
            if (prevZ > Z)
 
50
            {
 
51
                nearX = X; 
 
52
                nearY = Y; 
 
53
                nearZ = Z;
 
54
                farX = prevX; 
 
55
                farY = prevY;
 
56
                farZ = prevZ;
 
57
            }
 
58
            else
 
59
            {
 
60
                nearX = prevX; 
 
61
                nearY = prevY;
 
62
                nearZ = prevZ;
 
63
                farX = X; 
 
64
                farY = Y; 
 
65
                farZ = Z;
 
66
            }
 
67
 
 
68
            const bool skip = ((prevX < 0 && X < 0)
 
69
                               || (prevY < 0 && Y < 0)
 
70
                               || (prevX >= width && X >= width)
 
71
                               || (prevY >= height && Y >= height)
 
72
                               || (fabs(X) > width*100)
 
73
                               || (fabs(Y) > height*100)
 
74
                               || (fabs(prevX) > width*100)
 
75
                               || (fabs(prevY) > height*100)
 
76
                               || (prevZ < 0 && Z < 0));
 
77
 
 
78
            if (!skip || (i == 1 && isTarget)) 
 
79
            {
 
80
                LineSegment *ls = new LineSegment(color, 
 
81
                                                  farX, farY,
 
82
                                                  nearX, nearY);
 
83
                annotationMap.insert(pair<const double, Annotation*>(farZ, ls));
 
84
            }
 
85
        }
 
86
 
 
87
        prevX = X;
 
88
        prevY = Y;
 
89
        prevZ = Z;
 
90
 
 
91
        firstTime = false;
 
92
    }
 
93
}
 
94
 
 
95
void
 
96
addOrbits(const double jd0, const View *view, 
 
97
          const int width, const int height, 
 
98
          Planet *p,  PlanetProperties *currentProperties, 
 
99
          multimap<double, Annotation *> &annotationMap)
 
100
{
 
101
    const double period = p->Period();
 
102
    if (period == 0) return;
 
103
 
 
104
    const double startOrbit = currentProperties->StartOrbit();
 
105
    const double stopOrbit = currentProperties->StopOrbit();
 
106
    const double delOrbit = currentProperties->DelOrbit();
 
107
    const unsigned char *color = currentProperties->OrbitColor();
 
108
 
 
109
    double Prx=0, Pry=0, Prz=0;
 
110
    if (p->Primary() != SUN)
 
111
    {
 
112
        Planet primary(jd0, p->Primary());
 
113
        primary.calcHeliocentricEquatorial();
 
114
        primary.getPosition(Prx, Pry, Prz);
 
115
    }
 
116
 
 
117
    const double startTime = jd0 + startOrbit * period;
 
118
    const double stopTime = jd0 + stopOrbit * period;
 
119
 
 
120
    const int numTimes = (int) (180/delOrbit + 0.5);
 
121
 
 
122
    addArc(startTime, jd0, numTimes, color, view, width, height, 
 
123
           Prx, Pry, Prz, p, annotationMap);
 
124
    addArc(jd0, stopTime, numTimes, color, view, width, height, 
 
125
           Prx, Pry, Prz, p, annotationMap);
 
126
}