-
Notifications
You must be signed in to change notification settings - Fork 8
/
Geo2D_Draw.cpp
113 lines (109 loc) · 2.57 KB
/
Geo2D_Draw.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
#include "Geo2D_Draw.h"
#include "UTIL_openGL.h"
//================================================================================================//
/**********************************************
** functions that draw the geometrix objects **
**********************************************/
//================================================================================================//
namespace GeoDraw2D
{
void DrawLine(Line l)
{
glBegin(GL_LINES);
glVertex2fv(l.s.v);
glVertex2fv(l.e.v);
//normal
glColor3f(1,0,0);
glVertex2fv((l.s + l.r*(l.d*0.5f)).v);
glColor3f(1,1,0);
glVertex2fv((l.s + l.r*(l.d*0.5f) + l.n*5).v);
glEnd();
glBegin(GL_POINTS);
glColor3f(0,1,0);
glVertex2fv(l.s.v);
glColor3f(0,0,1);
glVertex2fv(l.e.v);
glEnd();
}
void DrawLine(Vec2 s, Vec2 e)
{
glBegin(GL_LINES);
glVertex2fv(s.v);
glVertex2fv(e.v);
glEnd();
/* glPointSize(5);
glBegin(GL_POINTS);
glColor3f(0,1,0);
glVertex2fv(s.v);
glColor3f(0,0,1);
glVertex2fv(e.v);
glEnd();
*/ }
void DrawBox(Box b)
{
glBegin(GL_LINE_LOOP);
glVertex2f(b.mins.x, b.mins.y);
glVertex2f(b.maxs.x, b.mins.y);
glVertex2f(b.maxs.x, b.maxs.y);
glVertex2f(b.mins.x, b.maxs.y);
glEnd();
glBegin(GL_POINTS);
glVertex2fv(b.p.v);
glEnd();
}
void DrawSphere(Sphere s, int numPoints)
{
float degree = (float)(360/numPoints);
float d=0;
glBegin(GL_LINE_LOOP);
for(int n=0; n<numPoints; n++)
{
glVertex2f(s.p.x + sin(d*PI/180) * s.r, s.p.y + cos(d*PI/180) * s.r);
d+=degree;
}
glEnd();
glBegin(GL_POINTS);
glVertex2fv(s.p.v);
glEnd();
}
void DrawIntersection(Vec2 entry, Vec2 exit)
{
glBegin(GL_POINTS);
glColor3f(1,1,0);
glVertex2fv(entry.v);
glColor3f(0,1,1);
glVertex2fv(exit.v);
glEnd();
}
void DrawCapsule(Capsule c, int numPoints)
{
Vec2 r1, r2, r3, r4;
r1 = Vec2(c.l.s + c.l.n * c.r) - c.l.s;
r2 = Vec2(c.l.s + Vec2(0,-c.r)) - c.l.s;
r3 = Vec2(c.l.e + c.l.n * c.r) - c.l.e;
r4 = Vec2(c.l.e + Vec2(0,-c.r)) - c.l.e;
glBegin(GL_LINES);
glVertex2fv((c.l.s + c.l.n * c.r).v);
glVertex2fv((c.l.e + c.l.n * c.r).v);
glVertex2fv((c.l.s - c.l.n * c.r).v);
glVertex2fv((c.l.e - c.l.n * c.r).v);
glEnd();
float degree = (float)(360/(numPoints-2));
float d=0;
glBegin(GL_LINE_STRIP);
for(int n=0; n<numPoints; n++)
{
glVertex2f(c.l.e.x + sin(d*PI/180) * c.r, c.l.e.y + cos(d*PI/180) * c.r);
d+=degree;
}
glEnd();
d=0;
glBegin(GL_LINE_STRIP);
for(int n=0; n<numPoints; n++)
{
glVertex2f(c.l.s.x + sin(d*PI/180) * c.r, c.l.s.y + cos(d*PI/180) * c.r);
d-=degree;
}
glEnd();
}
}