~matttbe/ubuntu/quantal/rss-glx/lp1017780

« back to all changes in this revision

Viewing changes to src/PixelCity/glVector2.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2010-07-22 06:50:37 UTC
  • mfrom: (1.1.6 upstream) (2.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20100722065037-094eshi3ljwbtfa1
Tags: 0.9.1-3ubuntu1
* Merge from Debian unstable (LP: #604945). Remaining changes:
  - Added an apport package hook
  - Changed libgl1-mesa-swx11-dev to libgl1-mesa-dev in Build-Depends
* Dropped changes:
  - Drop dependency on openal. As the package is in universe now, it's not 
    mandatory anymore
  - src/skyrocket.{cpp,xml}: Disable sound by default. Same reason.
  - Add --disable-sound configure flag to debian/rules. Same reason.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-----------------------------------------------------------------------------
 
2
 
 
3
  Vector2.cpp
 
4
 
 
5
  2006 Shamus Young
 
6
 
 
7
-------------------------------------------------------------------------------
 
8
 
 
9
  Functions for dealing with 2d (usually texture mapping) values.
 
10
 
 
11
-----------------------------------------------------------------------------*/
 
12
 
 
13
#include <float.h>
 
14
#include <math.h>
 
15
#include <GL/gl.h>
 
16
 
 
17
#include "glTypes.h"
 
18
#include "Math.h"
 
19
#include "Macro.h"
 
20
 
 
21
/*-----------------------------------------------------------------------------
 
22
                           
 
23
-----------------------------------------------------------------------------*/
 
24
 
 
25
GLvector2 glVectorNormalize (GLvector2 v)
 
26
{
 
27
 
 
28
  float length;
 
29
 
 
30
  length = glVectorLength (v);
 
31
  if (length < 0.000001f)
 
32
    return v;
 
33
  return v * (1.0f / length);
 
34
 
 
35
}
 
36
 
 
37
/*-----------------------------------------------------------------------------
 
38
                           
 
39
-----------------------------------------------------------------------------*/
 
40
 
 
41
float glVectorLength (GLvector2 v)
 
42
{
 
43
 
 
44
  return (float)sqrt (v.x * v.x + v.y * v.y);
 
45
 
 
46
}
 
47
 
 
48
/*-----------------------------------------------------------------------------
 
49
 
 
50
-----------------------------------------------------------------------------*/
 
51
 
 
52
GLvector2 glVectorSinCos (float a)
 
53
{
 
54
 
 
55
  GLvector2      val;
 
56
 
 
57
  a *= DEGREES_TO_RADIANS;
 
58
  val.x = sinf (a);
 
59
  val.y = cosf (a);
 
60
  return val;
 
61
 
 
62
}
 
63
 
 
64
/*-----------------------------------------------------------------------------
 
65
 
 
66
-----------------------------------------------------------------------------*/
 
67
 
 
68
GLvector2 glVector (float x, float y)
 
69
{
 
70
 
 
71
  GLvector2      val;
 
72
 
 
73
  val.x = x;
 
74
  val.y = y;
 
75
  return val;
 
76
 
 
77
}
 
78
 
 
79
/*-----------------------------------------------------------------------------
 
80
 
 
81
-----------------------------------------------------------------------------*/
 
82
 
 
83
GLvector2 glVectorAdd (GLvector2 val1, GLvector2 val2)
 
84
{
 
85
 
 
86
  GLvector2      result;
 
87
 
 
88
  result.x = val1.x + val2.x;
 
89
  result.y = val1.y + val2.y;
 
90
  return result;
 
91
 
 
92
}
 
93
 
 
94
 
 
95
/*-----------------------------------------------------------------------------
 
96
                           
 
97
-----------------------------------------------------------------------------*/
 
98
 
 
99
GLvector2 glVectorInterpolate (GLvector2 v1, GLvector2 v2, float scalar)
 
100
{
 
101
 
 
102
  GLvector2 result;
 
103
 
 
104
  result.x = MathInterpolate (v1.x, v2.x, scalar);
 
105
  result.y = MathInterpolate (v1.y, v2.y, scalar);
 
106
  return result;
 
107
 
 
108
}  
 
109
 
 
110
/*-----------------------------------------------------------------------------
 
111
 
 
112
-----------------------------------------------------------------------------*/
 
113
 
 
114
GLvector2 glVectorSubtract (GLvector2 val1, GLvector2 val2)
 
115
{
 
116
 
 
117
  GLvector2      result;
 
118
 
 
119
  result.x = val1.x - val2.x;
 
120
  result.y = val1.y - val2.y;
 
121
  return result;
 
122
 
 
123
}
 
124
 
 
125
/*-----------------------------------------------------------------------------
 
126
+                           
 
127
-----------------------------------------------------------------------------*/
 
128
 
 
129
GLvector2 GLvector2::operator+ (const GLvector2& c)
 
130
{
 
131
  return glVector (x + c.x, y + c.y);
 
132
}
 
133
 
 
134
GLvector2 GLvector2::operator+ (const float& c)
 
135
{
 
136
  return glVector (x + c, y + c);
 
137
}
 
138
 
 
139
void GLvector2::operator+= (const GLvector2& c)
 
140
{
 
141
  x += c.x;
 
142
  y += c.y;
 
143
}
 
144
 
 
145
void GLvector2::operator+= (const float& c)
 
146
{
 
147
  x += c;
 
148
  y += c;
 
149
}
 
150
 
 
151
GLvector2 GLvector2::operator- (const GLvector2& c)
 
152
{
 
153
  return glVector (x - c.x, y - c.y);
 
154
}
 
155
 
 
156
GLvector2 GLvector2::operator- (const float& c)
 
157
{
 
158
  return glVector (x - c, y - c);
 
159
}
 
160
 
 
161
void GLvector2::operator-= (const GLvector2& c)
 
162
{
 
163
  x -= c.x;
 
164
  y -= c.y;
 
165
}
 
166
 
 
167
void GLvector2::operator-= (const float& c)
 
168
{
 
169
  x -= c;
 
170
  y -= c;
 
171
}
 
172
 
 
173
GLvector2 GLvector2::operator* (const GLvector2& c)
 
174
{
 
175
  return glVector (x * c.x, y * c.y);
 
176
}
 
177
 
 
178
GLvector2 GLvector2::operator* (const float& c)
 
179
{
 
180
  return glVector (x * c, y * c);
 
181
}
 
182
 
 
183
void GLvector2::operator*= (const GLvector2& c)
 
184
{
 
185
  x *= c.x;
 
186
  y *= c.y;
 
187
}
 
188
 
 
189
void GLvector2::operator*= (const float& c)
 
190
{
 
191
  x *= c;
 
192
  y *= c;
 
193
}
 
194
 
 
195
GLvector2 GLvector2::operator/ (const GLvector2& c)
 
196
{
 
197
  return glVector (x / c.x, y / c.y);
 
198
}
 
199
 
 
200
GLvector2 GLvector2::operator/ (const float& c)
 
201
{
 
202
  return glVector (x / c, y / c);
 
203
}
 
204
 
 
205
void GLvector2::operator/= (const GLvector2& c)
 
206
{
 
207
  x /= c.x;
 
208
  y /= c.y;
 
209
}
 
210
 
 
211
void GLvector2::operator/= (const float& c)
 
212
{
 
213
  x /= c;
 
214
  y /= c;
 
215
}
 
216
 
 
217
bool GLvector2::operator== (const GLvector2& c)
 
218
{
 
219
  if (x == c.x && y == c.y)
 
220
    return true;
 
221
  return false;
 
222
}