gosu 0.7.25-i386-mingw32 → 0.7.26-i386-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING.txt +1 -1
- data/Gosu/Async.hpp +48 -0
- data/Gosu/Audio.hpp +165 -0
- data/Gosu/AutoLink.hpp +16 -0
- data/Gosu/Bitmap.hpp +85 -0
- data/Gosu/ButtonsMac.hpp +140 -0
- data/Gosu/ButtonsWin.hpp +140 -0
- data/Gosu/ButtonsX.hpp +141 -0
- data/Gosu/Color.hpp +202 -0
- data/Gosu/Directories.hpp +36 -0
- data/Gosu/Font.hpp +74 -0
- data/Gosu/Fwd.hpp +30 -0
- data/Gosu/Gosu.hpp +33 -0
- data/Gosu/Graphics.hpp +118 -0
- data/Gosu/GraphicsBase.hpp +69 -0
- data/Gosu/IO.hpp +252 -0
- data/Gosu/Image.hpp +136 -0
- data/Gosu/ImageData.hpp +49 -0
- data/Gosu/Input.hpp +162 -0
- data/Gosu/Math.hpp +135 -0
- data/Gosu/Platform.hpp +73 -0
- data/Gosu/Sockets.hpp +139 -0
- data/Gosu/Text.hpp +71 -0
- data/Gosu/TextInput.hpp +70 -0
- data/Gosu/Timing.hpp +16 -0
- data/Gosu/Utility.hpp +25 -0
- data/Gosu/Version.hpp +9 -0
- data/Gosu/WinUtility.hpp +76 -0
- data/Gosu/Window.hpp +124 -0
- data/lib/gosu.for_1_8.so +0 -0
- data/lib/gosu.for_1_9.so +0 -0
- data/lib/gosu/patches.rb +13 -13
- metadata +32 -4
data/Gosu/Image.hpp
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
//! \file Image.hpp
|
2
|
+
//! Interface of the Image class and helper functions.
|
3
|
+
|
4
|
+
#ifndef GOSU_IMAGE_HPP
|
5
|
+
#define GOSU_IMAGE_HPP
|
6
|
+
|
7
|
+
#include <Gosu/Fwd.hpp>
|
8
|
+
#include <Gosu/Bitmap.hpp>
|
9
|
+
#include <boost/shared_ptr.hpp>
|
10
|
+
#include <memory>
|
11
|
+
|
12
|
+
namespace Gosu
|
13
|
+
{
|
14
|
+
//! Provides functionality for drawing rectangular images.
|
15
|
+
class Image
|
16
|
+
{
|
17
|
+
boost::shared_ptr<ImageData> data;
|
18
|
+
|
19
|
+
public:
|
20
|
+
//! Loads an image from a given filename that can be drawn onto
|
21
|
+
//! graphics.
|
22
|
+
//! This constructor can handle PNG and BMP images. A color key of #ff00ff is
|
23
|
+
//! automatically applied to BMP type images. For more flexibility, use the
|
24
|
+
//! corresponding constructor that uses a Bitmap object.
|
25
|
+
Image(Graphics& graphics, const std::wstring& filename,
|
26
|
+
bool tileable = false);
|
27
|
+
//! Loads a portion of the the image at the given filename that can be
|
28
|
+
//! drawn onto graphics.
|
29
|
+
//! This constructor can handle PNG and BMP images. A color key of #ff00ff is
|
30
|
+
//! automatically applied to BMP type images. For more flexibility, use the
|
31
|
+
//! corresponding constructor that uses a Bitmap object.
|
32
|
+
Image(Graphics& graphics, const std::wstring& filename, unsigned srcX,
|
33
|
+
unsigned srcY, unsigned srcWidth, unsigned srcHeight,
|
34
|
+
bool tileable = false);
|
35
|
+
|
36
|
+
//! Converts the given bitmap into an image that can be drawn onto
|
37
|
+
//! graphics.
|
38
|
+
Image(Graphics& graphics, const Bitmap& source,
|
39
|
+
bool tileable = false);
|
40
|
+
//! Converts a portion of the given bitmap into an image that can be
|
41
|
+
//! drawn onto graphics.
|
42
|
+
Image(Graphics& graphics, const Bitmap& source, unsigned srcX,
|
43
|
+
unsigned srcY, unsigned srcWidth, unsigned srcHeight,
|
44
|
+
bool tileable = false);
|
45
|
+
|
46
|
+
//! Creates an Image from a user-supplied instance of the ImageData interface.
|
47
|
+
explicit Image(std::auto_ptr<ImageData> data);
|
48
|
+
|
49
|
+
unsigned width() const;
|
50
|
+
unsigned height() const;
|
51
|
+
|
52
|
+
//! Draws the image so its upper left corner is at (x; y).
|
53
|
+
void draw(double x, double y, ZPos z,
|
54
|
+
double factorX = 1, double factorY = 1,
|
55
|
+
Color c = Color::WHITE,
|
56
|
+
AlphaMode mode = amDefault) const;
|
57
|
+
//! Like draw(), but allows to give modulation colors for all four
|
58
|
+
//! corners.
|
59
|
+
void drawMod(double x, double y, ZPos z,
|
60
|
+
double factorX, double factorY,
|
61
|
+
Color c1, Color c2, Color c3, Color c4,
|
62
|
+
AlphaMode mode = amDefault) const;
|
63
|
+
|
64
|
+
//! Draws the image rotated by the given angle so that its rotation
|
65
|
+
//! center is at (x; y). Note that this is different from how all the
|
66
|
+
//! other drawing functions work!
|
67
|
+
//! \param angle See Math.hpp for an explanation of how Gosu interprets
|
68
|
+
//! angles.
|
69
|
+
//! \param centerX Relative horizontal position of the rotation center
|
70
|
+
//! on the image. 0 is the left border, 1 is the right border, 0.5 is
|
71
|
+
//! the center (and default).
|
72
|
+
//! \param centerY See centerX.
|
73
|
+
void drawRot(double x, double y, ZPos z,
|
74
|
+
double angle, double centerX = 0.5, double centerY = 0.5,
|
75
|
+
double factorX = 1, double factorY = 1,
|
76
|
+
Color c = Color::WHITE,
|
77
|
+
AlphaMode mode = amDefault) const;
|
78
|
+
|
79
|
+
//! Provides access to the underlying image data object.
|
80
|
+
const ImageData& getData() const;
|
81
|
+
};
|
82
|
+
|
83
|
+
//! Convenience function that splits a BMP or PNG file into an array
|
84
|
+
//! of small rectangles and creates images from them.
|
85
|
+
//! \param tileWidth If positive, specifies the width of one tile in
|
86
|
+
//! pixels. If negative, the bitmap is divided into -tileWidth rows.
|
87
|
+
//! \param tileHeight See tileWidth.
|
88
|
+
//! \param appendTo STL container to which the images will be appended.
|
89
|
+
//! Must provide a push_back member function; std::vector<boost::shared_ptr<Image>>
|
90
|
+
//! or boost::ptr_vector<Image> are good choices.
|
91
|
+
template<typename Container>
|
92
|
+
void imagesFromTiledBitmap(Graphics& graphics, const std::wstring& filename,
|
93
|
+
int tileWidth, int tileHeight, bool tileable, Container& appendTo)
|
94
|
+
{
|
95
|
+
imagesFromTiledBitmap(graphics, quickLoadBitmap(filename), tileWidth, tileHeight, tileable, appendTo);
|
96
|
+
}
|
97
|
+
|
98
|
+
//! Convenience function that splits a bitmap into an area of array
|
99
|
+
//! rectangles and creates images from them.
|
100
|
+
//! \param tileWidth If positive, specifies the width of one tile in
|
101
|
+
//! pixels. If negative, the bitmap is divided into -tileWidth rows.
|
102
|
+
//! \param tileHeight See tileWidth.
|
103
|
+
//! \param appendTo STL container to which the images will be appended.
|
104
|
+
//! Must provide a push_back member function; std::vector<boost::shared_ptr<Image>>
|
105
|
+
//! or boost::ptr_vector<Image> are good choices.
|
106
|
+
template<typename Container>
|
107
|
+
void imagesFromTiledBitmap(Graphics& graphics, const Bitmap& bmp,
|
108
|
+
int tileWidth, int tileHeight, bool tileable, Container& appendTo)
|
109
|
+
{
|
110
|
+
int tilesX, tilesY;
|
111
|
+
|
112
|
+
if (tileWidth > 0)
|
113
|
+
tilesX = bmp.width() / tileWidth;
|
114
|
+
else
|
115
|
+
{
|
116
|
+
tilesX = -tileWidth;
|
117
|
+
tileWidth = bmp.width() / tilesX;
|
118
|
+
}
|
119
|
+
|
120
|
+
if (tileHeight > 0)
|
121
|
+
tilesY = bmp.height() / tileHeight;
|
122
|
+
else
|
123
|
+
{
|
124
|
+
tilesY = -tileHeight;
|
125
|
+
tileHeight = bmp.height() / tilesY;
|
126
|
+
}
|
127
|
+
|
128
|
+
for (int y = 0; y < tilesY; ++y)
|
129
|
+
for (int x = 0; x < tilesX; ++x)
|
130
|
+
appendTo.push_back(typename Container::value_type(new Image(graphics, bmp,
|
131
|
+
x * tileWidth, y * tileHeight, tileWidth, tileHeight,
|
132
|
+
tileable)));
|
133
|
+
}
|
134
|
+
}
|
135
|
+
|
136
|
+
#endif
|
data/Gosu/ImageData.hpp
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
//! \file ImageData.hpp
|
2
|
+
//! Interface of the ImageData class.
|
3
|
+
|
4
|
+
#ifndef GOSU_IMAGEDATA_HPP
|
5
|
+
#define GOSU_IMAGEDATA_HPP
|
6
|
+
|
7
|
+
#include <Gosu/Color.hpp>
|
8
|
+
#include <Gosu/GraphicsBase.hpp>
|
9
|
+
#include <boost/optional.hpp>
|
10
|
+
#include <boost/utility.hpp>
|
11
|
+
|
12
|
+
namespace Gosu
|
13
|
+
{
|
14
|
+
//! Contains information about the underlying OpenGL texture and the
|
15
|
+
//! u/v space used for image data. Can be retrieved from some images
|
16
|
+
//! to use them in OpenGL operations.
|
17
|
+
struct GLTexInfo
|
18
|
+
{
|
19
|
+
int texName;
|
20
|
+
float left, right, top, bottom;
|
21
|
+
};
|
22
|
+
|
23
|
+
//! The ImageData class is an abstract base class for drawable images.
|
24
|
+
//! Instances of classes derived by ImageData are usually returned by
|
25
|
+
//! Graphics::createImage and usually only used to implement drawing
|
26
|
+
//! primitives like Image, which then provide a more specialized and
|
27
|
+
//! intuitive drawing interface.
|
28
|
+
class ImageData : boost::noncopyable
|
29
|
+
{
|
30
|
+
public:
|
31
|
+
virtual ~ImageData()
|
32
|
+
{
|
33
|
+
}
|
34
|
+
|
35
|
+
virtual unsigned width() const = 0;
|
36
|
+
virtual unsigned height() const = 0;
|
37
|
+
|
38
|
+
virtual void draw(double x1, double y1, Color c1,
|
39
|
+
double x2, double y2, Color c2,
|
40
|
+
double x3, double y3, Color c3,
|
41
|
+
double x4, double y4, Color c4,
|
42
|
+
ZPos z, AlphaMode mode) const = 0;
|
43
|
+
|
44
|
+
virtual boost::optional<GLTexInfo> glTexInfo() const = 0;
|
45
|
+
virtual Bitmap toBitmap() const = 0;
|
46
|
+
};
|
47
|
+
}
|
48
|
+
|
49
|
+
#endif
|
data/Gosu/Input.hpp
ADDED
@@ -0,0 +1,162 @@
|
|
1
|
+
//! \file Input.hpp
|
2
|
+
//! Interface of the Input class.
|
3
|
+
|
4
|
+
#ifndef GOSU_INPUT_HPP
|
5
|
+
#define GOSU_INPUT_HPP
|
6
|
+
|
7
|
+
#include <Gosu/Fwd.hpp>
|
8
|
+
#include <Gosu/Platform.hpp>
|
9
|
+
|
10
|
+
#ifdef GOSU_IS_WIN
|
11
|
+
#include <Gosu/ButtonsWin.hpp>
|
12
|
+
#ifndef NOMINMAX
|
13
|
+
#define NOMINMAX
|
14
|
+
#endif
|
15
|
+
#include <windows.h>
|
16
|
+
#endif
|
17
|
+
|
18
|
+
#ifdef GOSU_IS_MAC
|
19
|
+
#include <Gosu/ButtonsMac.hpp>
|
20
|
+
#endif
|
21
|
+
|
22
|
+
#ifdef GOSU_IS_X
|
23
|
+
#include <X11/Xlib.h>
|
24
|
+
#include <X11/Xutil.h>
|
25
|
+
#include <X11/keysym.h>
|
26
|
+
#include <Gosu/ButtonsX.hpp>
|
27
|
+
#endif
|
28
|
+
|
29
|
+
#include <Gosu/Platform.hpp>
|
30
|
+
#include <Gosu/Fwd.hpp>
|
31
|
+
#include <boost/function.hpp>
|
32
|
+
#include <boost/scoped_ptr.hpp>
|
33
|
+
#include <vector>
|
34
|
+
|
35
|
+
namespace Gosu
|
36
|
+
{
|
37
|
+
//! Very lightweight class that identifies a button (keyboard, mouse or other device).
|
38
|
+
class Button
|
39
|
+
{
|
40
|
+
unsigned id_;
|
41
|
+
|
42
|
+
public:
|
43
|
+
//! For internal use.
|
44
|
+
explicit Button(unsigned id) : id_(id) {}
|
45
|
+
//! For internal use.
|
46
|
+
unsigned id() const { return id_; }
|
47
|
+
|
48
|
+
//! Default constructor; == noButton.
|
49
|
+
Button() : id_(noButton) {}
|
50
|
+
|
51
|
+
//! Conversion from ButtonName constants.
|
52
|
+
Button(ButtonName name) : id_(name) {}
|
53
|
+
};
|
54
|
+
|
55
|
+
//! Tests whether two Buttons identify the same physical button.
|
56
|
+
inline bool operator==(Button lhs, Button rhs)
|
57
|
+
{
|
58
|
+
return lhs.id() == rhs.id();
|
59
|
+
}
|
60
|
+
inline bool operator!=(Button lhs, Button rhs)
|
61
|
+
{
|
62
|
+
return !(lhs == rhs);
|
63
|
+
}
|
64
|
+
inline bool operator<(Button lhs, Button rhs)
|
65
|
+
{
|
66
|
+
return lhs.id() < rhs.id();
|
67
|
+
}
|
68
|
+
|
69
|
+
//! Struct that saves information about a touch on the surface of a multi-
|
70
|
+
//! touch device.
|
71
|
+
//! Available even on non-iPhone platforms to make it easier to compile the
|
72
|
+
//! same source for multiple platforms.
|
73
|
+
struct Touch
|
74
|
+
{
|
75
|
+
//! Allows for identification of a touch across calls.
|
76
|
+
void* id;
|
77
|
+
//! Position of a touch on the touch screen.
|
78
|
+
float x, y;
|
79
|
+
};
|
80
|
+
typedef std::vector<Touch> Touches;
|
81
|
+
|
82
|
+
//! Manages initialization and shutdown of the input system. Only one Input
|
83
|
+
//! instance can exist per application.
|
84
|
+
class Input
|
85
|
+
{
|
86
|
+
struct Impl;
|
87
|
+
boost::scoped_ptr<Impl> pimpl;
|
88
|
+
|
89
|
+
public:
|
90
|
+
#ifdef GOSU_IS_WIN
|
91
|
+
Input(HWND window);
|
92
|
+
#endif
|
93
|
+
|
94
|
+
#ifdef GOSU_IS_MAC
|
95
|
+
#ifdef GOSU_IS_IPHONE
|
96
|
+
Input(void* view, float updateInterval);
|
97
|
+
void feedTouchEvent(int type, void* touches);
|
98
|
+
#else
|
99
|
+
Input(void* window);
|
100
|
+
bool feedNSEvent(void* event);
|
101
|
+
#endif
|
102
|
+
#endif
|
103
|
+
|
104
|
+
#ifdef GOSU_IS_X
|
105
|
+
Input(::Display* display, ::Window window);
|
106
|
+
bool feedXEvent(::XEvent& event);
|
107
|
+
#endif
|
108
|
+
|
109
|
+
~Input();
|
110
|
+
|
111
|
+
//! Returns the character a button usually produces, or 0.
|
112
|
+
static wchar_t idToChar(Button btn);
|
113
|
+
//! Returns the button that has to be pressed to produce the
|
114
|
+
//! given character, or noButton.
|
115
|
+
static Button charToId(wchar_t ch);
|
116
|
+
|
117
|
+
//! Returns true if a button is currently pressed.
|
118
|
+
//! Updated every tick.
|
119
|
+
bool down(Button btn) const;
|
120
|
+
|
121
|
+
//! Returns the horizontal position of the mouse relative to the top
|
122
|
+
//! left corner of the window given to Input's constructor.
|
123
|
+
double mouseX() const;
|
124
|
+
//! See mouseX.
|
125
|
+
double mouseY() const;
|
126
|
+
|
127
|
+
//! Immediately moves the mouse as far towards the desired position
|
128
|
+
//! as possible. x and y are relativ to the window just as in the mouse
|
129
|
+
//! position accessors.
|
130
|
+
void setMousePosition(double x, double y);
|
131
|
+
|
132
|
+
// Undocumented for the moment. Also applies to currentTouches().
|
133
|
+
void setMouseFactors(double factorX, double factorY);
|
134
|
+
|
135
|
+
//! Currently known touches.
|
136
|
+
const Touches& currentTouches() const;
|
137
|
+
|
138
|
+
//! Accelerometer positions in all three dimensions (smoothened).
|
139
|
+
double accelerometerX() const;
|
140
|
+
double accelerometerY() const;
|
141
|
+
double accelerometerZ() const;
|
142
|
+
|
143
|
+
//! Collects new information about which buttons are pressed, where the
|
144
|
+
//! mouse is and calls onButtonUp/onButtonDown, if assigned.
|
145
|
+
void update();
|
146
|
+
|
147
|
+
//! Assignable events that are called by update. You can bind these to your own functions.
|
148
|
+
//! If you use the Window class, it will assign forward these to its own methods.
|
149
|
+
boost::function<void (Button)> onButtonDown, onButtonUp;
|
150
|
+
|
151
|
+
//! Assignable events that are called by update. You can bind these to your own functions.
|
152
|
+
//! If you use the Window class, it will assign forward these to its own methods.
|
153
|
+
boost::function<void (Touch)> onTouchBegan, onTouchMoved, onTouchEnded;
|
154
|
+
|
155
|
+
//! Returns the currently active TextInput instance, or 0.
|
156
|
+
TextInput* textInput() const;
|
157
|
+
//! Sets the currently active TextInput, or clears it (input = 0).
|
158
|
+
void setTextInput(TextInput* input);
|
159
|
+
};
|
160
|
+
}
|
161
|
+
|
162
|
+
#endif
|
data/Gosu/Math.hpp
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
//! \file Math.hpp
|
2
|
+
//! Contains simple math functionality.
|
3
|
+
|
4
|
+
#ifndef GOSU_MATH_HPP
|
5
|
+
#define GOSU_MATH_HPP
|
6
|
+
|
7
|
+
namespace Gosu
|
8
|
+
{
|
9
|
+
//! Pi.
|
10
|
+
const double pi = 3.1415926536;
|
11
|
+
|
12
|
+
//! Truncates the fractional part of a real value. Equivalent to
|
13
|
+
//! static_cast<long>.
|
14
|
+
inline long trunc(double value)
|
15
|
+
{
|
16
|
+
return static_cast<long>(value);
|
17
|
+
}
|
18
|
+
|
19
|
+
//! Rounds a real value towards the next integer.
|
20
|
+
inline long round(double value)
|
21
|
+
{
|
22
|
+
if (value >= 0)
|
23
|
+
return static_cast<long>(value + 0.5);
|
24
|
+
else
|
25
|
+
return static_cast<long>(value - 0.5);
|
26
|
+
}
|
27
|
+
|
28
|
+
//! Returns a real value between min (inclusive) and max (exclusive).
|
29
|
+
//! Uses std::rand, so you should call std::srand before using it.
|
30
|
+
double random(double min, double max);
|
31
|
+
|
32
|
+
//! Translates between Gosu's angle system (where 0� is at the top)
|
33
|
+
//! and radians (where 0 is at the right).
|
34
|
+
inline double gosuToRadians(double angle)
|
35
|
+
{
|
36
|
+
return (angle - 90) * pi / 180;
|
37
|
+
}
|
38
|
+
//! Translates between Gosu's angle system (where 0� is at the top)
|
39
|
+
//! and radians (where 0 is at the right).
|
40
|
+
inline double radiansToGosu(double angle)
|
41
|
+
{
|
42
|
+
return angle * 180 / pi + 90;
|
43
|
+
}
|
44
|
+
|
45
|
+
//! Translates between degrees (used by Gosu) and radians, i.e. it
|
46
|
+
//! does not change the 'origin' of the angle system.
|
47
|
+
inline double degreesToRadians(double angle)
|
48
|
+
{
|
49
|
+
return angle * pi / 180;
|
50
|
+
}
|
51
|
+
//! Translates between degrees (used by Gosu) and radians, i.e. it
|
52
|
+
//! does not change the 'origin' of the angle system.
|
53
|
+
inline double radiansToDegrees(double angle)
|
54
|
+
{
|
55
|
+
return angle * 180 / pi;
|
56
|
+
}
|
57
|
+
|
58
|
+
//! Returns the horizontal distance between the origin and the point to
|
59
|
+
//! which you would get if you moved radius pixels in the direction
|
60
|
+
//! specified by angle.
|
61
|
+
//! \param angle Angle in degrees where 0.0 means upwards.
|
62
|
+
double offsetX(double angle, double radius);
|
63
|
+
//! Returns the vertical distance between the origin and the point to
|
64
|
+
//! which you would get if you moved radius pixels in the direction
|
65
|
+
//! specified by angle.
|
66
|
+
//! \param angle Angle in degrees where 0.0 means upwards.
|
67
|
+
double offsetY(double angle, double radius);
|
68
|
+
//! Returns the angle from point 1 to point 2 in degrees, where 0.0 means
|
69
|
+
//! upwards. Returns def if both points are equal.
|
70
|
+
double angle(double fromX, double fromY, double toX, double toY,
|
71
|
+
double def = 0);
|
72
|
+
//! Returns the smallest angle that can be added to angle1 to get to
|
73
|
+
//! angle2 (can be negative if counter-clockwise movement is shorter).
|
74
|
+
double angleDiff(double angle1, double angle2);
|
75
|
+
//! Normalizes an angle to fit into the range [0; 360[.
|
76
|
+
double normalizeAngle(double angle);
|
77
|
+
|
78
|
+
//! Returns value * value.
|
79
|
+
template<typename T>
|
80
|
+
T square(T value)
|
81
|
+
{
|
82
|
+
return value * value;
|
83
|
+
}
|
84
|
+
|
85
|
+
//! Returns min if value is smaller than min, max if value is larger than
|
86
|
+
//! max and value otherwise.
|
87
|
+
template<typename T>
|
88
|
+
T clamp(T value, T min, T max)
|
89
|
+
{
|
90
|
+
if (value < min)
|
91
|
+
return min;
|
92
|
+
if (value > max)
|
93
|
+
return max;
|
94
|
+
return value;
|
95
|
+
}
|
96
|
+
|
97
|
+
// Backward compatibility with 0.7.x
|
98
|
+
template<typename T>
|
99
|
+
T boundBy(T value, T min, T max)
|
100
|
+
{
|
101
|
+
return clamp(value, min, max);
|
102
|
+
}
|
103
|
+
|
104
|
+
//! Returns (value-min) % (max-min) + min, where % always has a positive
|
105
|
+
//! result for max > min. The results are undefined for max <= min.
|
106
|
+
//! Note: This means that max is exclusive.
|
107
|
+
int wrap(int value, int min, int max);
|
108
|
+
//! Returns (value-min) % (max-min) + min, where % always has a positive
|
109
|
+
//! result for max > min. The results are undefined for max <= min.
|
110
|
+
//! Note: This means that max is exclusive.
|
111
|
+
float wrap(float value, float min, float max);
|
112
|
+
//! Returns (value-min) % (max-min) + min, where % always has a positive
|
113
|
+
//! result for max > min. The results are undefined for max <= min.
|
114
|
+
//! Note: This means that max is exclusive.
|
115
|
+
double wrap(double value, double min, double max);
|
116
|
+
|
117
|
+
//! Returns the square of the distance between two points.
|
118
|
+
inline double distanceSqr(double x1, double y1, double x2, double y2)
|
119
|
+
{
|
120
|
+
return square(x1 - x2) + square(y1 - y2);
|
121
|
+
}
|
122
|
+
|
123
|
+
//! Returns the distance between two points.
|
124
|
+
double distance(double x1, double y1, double x2, double y2);
|
125
|
+
|
126
|
+
//! Interpolates a value between a and b, weight being the bias towards the second value.
|
127
|
+
//! Examples: interpolate(0, 10, 0.5) == 5, interpolate(-10, 10, 0.25) == 5, interpolate(0, 10, -0.5) == -5.
|
128
|
+
template<typename T>
|
129
|
+
T interpolate(T a, T b, double weight = 0.5)
|
130
|
+
{
|
131
|
+
return a * (1.0 - weight) + b * weight;
|
132
|
+
}
|
133
|
+
}
|
134
|
+
|
135
|
+
#endif
|