-
Notifications
You must be signed in to change notification settings - Fork 0
/
Freeform.h
executable file
·70 lines (60 loc) · 1.27 KB
/
Freeform.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
#ifndef __ComputerGraphics__freeform__
#define __ComputerGraphics__freeform__
#include <vector>
#include "Curve.h"
#include "float2.h"
class Freeform : public Curve
{
public:
std::vector<float2> controlPoints;
float2 offset;
virtual void setColor()=0;
virtual void addControlPoint(float2 p)
{
controlPoints.push_back(p-offset);
}
virtual void reset()
{
controlPoints.erase(controlPoints.begin(),controlPoints.begin()+controlPoints.size());
}
virtual void drawFreeform(bool selected, bool filled)
{
glPushMatrix();
glTranslatef(offset.x, offset.y, 0);
if(selected){
glColor3ub( 0, 0, 255 ); // Blue
} else {
setColor();
}
glLineWidth(2*(1+selected));
if(filled){
glBegin(GL_TRIANGLE_FAN);
} else {
glBegin(GL_LINE_STRIP);
}
draw();
glEnd();
glPopMatrix();
}
void drawControlPoints(bool selected){
float width = 2.5;
float height = 2.5;
if(selected){
glColor3ub( 0, 0, 255 );
} else {
setColor();
}
glPushMatrix();
glTranslatef(offset.x, offset.y, 0);
for(float2 &v : controlPoints){
glBegin(GL_TRIANGLE_STRIP);
glVertex2d(v.x-width, v.y-height);
glVertex2d(v.x+width, v.y-height);
glVertex2d(v.x-width, v.y+height);
glVertex2d(v.x+width, v.y+height);
glEnd();
}
glPopMatrix();
}
};
#endif