1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
|
//
// glgrav - OpenGL N-Body gravity simulator
//
// Copyright (C) 2003 Ian Cowburn (ianc@noddybox.demon.co.uk)
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// -------------------------------------------------------------------------
//
// Mass
//
// $Id$
//
#ifndef MASS_H
#define MASS_H
#include "global.h"
#include "vec3d.h"
class Mass
{
public:
enum DrawItem {eMass, eRing};
Mass();
Mass(const string& name, double mass, double scale,
double posx, double posy, double posz,
double dx, double dy, double dz,
GLfloat r, GLfloat g, GLfloat b,
double rot, int sheild=0);
virtual ~Mass();
// Define a ring
//
void setRing(double from, double to,
GLfloat r, GLfloat g, GLfloat b, GLfloat alpha,
double rot, double angle);
// Set up an Open GL texture ID to use. It is assumed that
// texturing is not used till this member is called.
//
// The get function returns true if a texture has been assigned.
//
void setTexture(GLuint id);
bool getTexture(GLuint& id) const;
void setRingTexture(GLuint id);
bool getRingTexture(GLuint& id) const;
// Get Mass information
//
string getName() const;
double getMass() const;
double getSize() const;
void getPosition(double& x, double& y, double& z) const;
void getPreviousPosition(double& x, double& y, double& z) const;
void getDelta(double& dx, double& dy, double& dz) const;
void getColour(GLfloat& r, GLfloat& g, GLfloat& b) const;
bool isMassless() const;
// All resetting of various controls for collisions
//
void reset(double mass, double dx, double dy, double dz);
void reset(double mass);
// Attract the object to the provided mass. Note that the supplied
// mass is left unaltered.
//
// Returns true if the two objects have collided
//
bool calcAttraction(Mass& m, double gr_const);
// Move the mass along it's delta
//
void move();
void draw(bool solid, bool texture, DrawItem item) const;
// Streaming
//
friend ostream& operator<<(ostream& os, const Mass& m);
private:
string m_name;
double m_size;
double m_mass;
double m_scale;
double m_x,m_y,m_z;
double m_prevx,m_prevy,m_prevz;
Vec3D m_delta;
GLfloat m_r,m_g,m_b;
bool m_massless;
double m_rot;
double m_ang;
int m_shield;
bool m_textured;
GLuint m_texture_id;
bool m_ring;
double m_ring_from,m_ring_to;
double m_ring_rot,m_ring_ang,m_ring_tilt;
GLfloat m_rr,m_rg,m_rb;
GLfloat m_ring_alpha;
bool m_ring_textured;
GLuint m_ring_id;
double calcDistance2(Mass& m, double& dx, double& dy, double& dz);
void calcSize();
};
// Routine to find masses from a vector of them
//
bool findMass(vector<Mass>& m, const string& name, Mass& ret);
bool findMass(vector<Mass>& m, const string& name,
vector<Mass>::size_type& index);
#endif
// END OF FILE //
|