-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathvectors.h
115 lines (92 loc) · 3.05 KB
/
vectors.h
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
/*
Copyright (c) 2009 Andrew Caudwell ([email protected])
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. The name of the author may not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef VECTORS_H
#define VECTORS_H
#define GLM_FORCE_RADIANS
// the following are required for compatibility with GLM 0.9.9
#define GLM_FORCE_CTOR_INIT
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/matrix_access.hpp>
#include <glm/gtx/norm.hpp>
using glm::vec2;
using glm::vec3;
using glm::vec4;
using glm::mat3;
using glm::mat4;
vec2 rotate_vec2(const vec2& v, float s, float c);
vec2 normalise(const vec2& v);
vec3 normalise(const vec3& v);
vec4 normalise(const vec4& v);
class lerp2 : public glm::vec2 {
public:
vec2 p;
vec2 l;
lerp2() : vec2(), p(), l() {
}
const lerp2& snap() {
p = *this;
return *this;
}
static vec2 lerp(const vec2& a, const vec2& b, float n) {
return a + (b - a) * n;
}
const vec2& lerp(float n) {
l = p + (*this - p) * n;
return l;
}
const lerp2& operator= (const vec2& vec) {
this->x = vec.x;
this->y = vec.y;
return *this;
}
};
class lerp3 : public vec3 {
public:
vec3 p;
vec3 l;
lerp3() : vec3(), p(), l() {
}
const lerp3& snap() {
p = *this;
return *this;
}
static vec3 lerp(const vec3& a, const vec3& b, float n) {
return a + (b - a) * n;
}
const vec3& lerp(float n) {
l = p + (*this - p) * n;
return l;
}
const lerp3& operator= (const vec3& vec) {
this->x = vec.x;
this->y = vec.y;
this->z = vec.z;
return *this;
}
};
#endif