-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathGeometry.cpp
134 lines (109 loc) · 2.96 KB
/
Geometry.cpp
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
//
// Geometry.cpp
// Mood Globe
//
// Created by Spencer Salazar on 6/26/12.
// Copyright (c) 2012 Stanford University. All rights reserved.
//
#include "Geometry.h"
#include <stdio.h>
const GLcolor4f GLcolor4f::white(1, 1, 1, 1);
const GLcolor4f GLcolor4f::red(1, 0, 0, 1);
const GLcolor4f GLcolor4f::green(0, 1, 0, 1);
const GLcolor4f GLcolor4f::blue(0, 0, 1, 1);
const GLcolor4f GLcolor4f::black(0, 0, 0, 1);
GLvertex3f::GLvertex3f(const GLvertex2f &v)
{
x = v.x;
y = v.y;
z = 0;
}
GLvertex2f GLvertex3f::toLatLong() const
{
GLvertex2f ll;
ll.x = (atan2f(y,x) / M_PI + 1.0f) * 0.5f;
ll.y = asinf(z) / M_PI + 0.5f;
return ll;
}
GLvertex2f GLvertex3f::xy() const
{
return GLvertex2f(x, y);
}
GLvertex3f operator+(const GLvertex3f &v1, const GLvertex3f &v2)
{
GLvertex3f v3 = GLvertex3f(v1.x+v2.x, v1.y+v2.y, v1.z+v2.z);
return v3;
}
GLvertex3f operator-(const GLvertex3f &v1, const GLvertex3f &v2)
{
GLvertex3f v3 = GLvertex3f(v1.x-v2.x, v1.y-v2.y, v1.z-v2.z);
return v3;
}
GLvertex3f operator*(const GLvertex3f &v, const GLfloat s)
{
GLvertex3f v2 = GLvertex3f(v.x*s, v.y*s, v.z*s);
return v2;
}
GLvertex3f operator/(const GLvertex3f &v, const GLfloat s)
{
GLvertex3f v2 = GLvertex3f(v.x/s, v.y/s, v.z/s);
return v2;
}
bool operator==(const GLvertex3f &v, const GLvertex3f &v2)
{
return v.x == v2.x && v.y == v2.y && v.z == v2.z;
}
bool operator!=(const GLvertex3f &v, const GLvertex3f &v2)
{
return v.x != v2.x || v.y != v2.y || v.z != v2.z;
}
GLvertex3f lerp(float d, const GLvertex3f &a, const GLvertex3f &b)
{
return GLvertex3f(a.x*(1-d)+b.x*d, a.y*(1-d)+b.y*d, a.z*(1-d)+b.z*d);
}
GLcolor4f lerp(float d, const GLcolor4f &a, const GLcolor4f &b)
{
return GLcolor4f(a.r*(1-d)+b.r*d, a.g*(1-d)+b.g*d, a.b*(1-d)+b.b*d, a.a*(1-d)+b.a*d);
}
GLvertex2f operator+(const GLvertex2f &v1, const GLvertex2f &v2)
{
GLvertex2f v3 = GLvertex2f(v1.x+v2.x, v1.y+v2.y);
return v3;
}
GLvertex2f operator-(const GLvertex2f &v1, const GLvertex2f &v2)
{
GLvertex2f v3 = GLvertex2f(v1.x-v2.x, v1.y-v2.y);
return v3;
}
GLvertex2f operator*(const GLvertex2f &v, const GLfloat &s)
{
GLvertex2f v2 = GLvertex2f(v.x*s, v.y*s);
return v2;
}
GLvertex2f operator/(const GLvertex2f &v, const GLfloat &s)
{
GLvertex2f v2 = GLvertex2f(v.x/s, v.y/s);
return v2;
}
bool operator==(const GLvertex2f &v, const GLvertex2f &v2)
{
return v.x == v2.x && v.y == v2.y;
}
bool operator!=(const GLvertex2f &v, const GLvertex2f &v2)
{
return v.x != v2.x || v.y != v2.y;
}
GLvertex2f rotateZ(const GLvertex2f &v, GLfloat rads)
{
return GLvertex2f(v.x*cosf(rads)-v.y*sinf(rads), v.x*sinf(rads)+v.y*cosf(rads));
}
GLvertex3f rotateZ(const GLvertex3f &v, GLfloat rads)
{
return GLvertex3f(v.x*cosf(rads)-v.y*sinf(rads), v.x*sinf(rads)+v.y*cosf(rads), v.z);
}
bool GLvrectf::contains(const GLvertex3f &p)
{
if(p.x >= bl.x && p.y >= bl.y && p.x <= ur.x && p.y <= ur.y)
return true;
return false;
}