-
Notifications
You must be signed in to change notification settings - Fork 5
/
canvas.cpp
191 lines (154 loc) · 3.38 KB
/
canvas.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include "canvas.h"
BEGIN_EVENT_TABLE(Canvas, wxGLCanvas)
EVT_PAINT(Canvas::Paint)
EVT_SIZE(Canvas::Resized)
EVT_MOTION(Canvas::OnMouseM)
EVT_RIGHT_DOWN(Canvas::OnMouse)
EVT_RIGHT_UP(Canvas::OnMouse)
EVT_LEFT_DOWN(Canvas::OnMouse)
EVT_LEFT_UP(Canvas::OnMouse)
EVT_CHAR(Canvas::OnKey)
END_EVENT_TABLE()
Canvas::Canvas(wxWindow* parent, const wxWindowID id, const wxPoint& pos, const wxSize& size,bool triD)
:wxGLCanvas(parent, id,NULL, pos, size,0)
{
m_context = new wxGLContext(this);
window=parent;
dimension=triD;
flag = false;
scene.SetViewPoint(20,0,10);
}
void Canvas::AddObject(GLObject * obj)
{
if(dimension) scene.addObject(obj);
}
void Canvas::ChangeBackGroundColour(wxColour colour)
{
if(dimension)
{
scene.BackgroundColor((float)colour.Red()/255.0f,(float)colour.Green()/255.0f,(float)colour.Blue()/255.0f);
Refresh();
}
else return;
}
void Canvas::InitGL()
{
SetCurrent();
if(dimension) scene.init();
}
void Canvas::GetViewPoint(double &dist_or_2Dx,double &rot_or_2Dy,double &elv_or_2Dfx,double s2Dfy)
{
if(dimension)
{
scene.GetViewPoint(dist_or_2Dx,rot_or_2Dy,elv_or_2Dfx);
}
}
void Canvas::SetViewPoint(double dist_or_2Dx,double rot_or_2Dy,double elv_or_2Dfx,double s2Dfy)
{
if(dimension) scene.SetViewPoint(dist_or_2Dx,rot_or_2Dy,elv_or_2Dfx);
}
void Canvas::ClearObjects()
{
if(dimension)
scene.clearObjects();
}
void Canvas::SetViewCenter(double x, double y, double z)
{
if(dimension)
scene.SetViewCenter(x,y,z);
}
void Canvas::Paint(wxPaintEvent& event)
{
wxPaintDC(this);
SetCurrent();
if(!flag)
{
InitGL();
flag = true;
}
if(dimension)
{
scene.setViewSize(0,0,GetSize().x,GetSize().y);
scene.Draw();
}
SwapBuffers();
}
void Canvas::UpdateWorld(World* w)
{
if(dimension)
{
this->scene.clearObjects();
this->scene.addObject(w);
}
Refresh(false);
}
void Canvas::UpdateMeshpart(MeshPart* m)
{
if(dimension)
{
this->scene.clearObjects();
this->scene.addObject(m);
}
Refresh(false);
}
void Canvas::Resized(wxSizeEvent& event)
{
Refresh(false);
event.Skip();
}
void Canvas::OnMouseM(wxMouseEvent& event)
{
wxPoint pt = event.GetPosition();//return the physical mouse position
if(event.RightIsDown()||event.LeftIsDown())
{
if(dimension)scene.MouseMove(pt.x,pt.y);
Refresh(false);
}
event.Skip();
}
void Canvas::OnMouse(wxMouseEvent& event)
{
pt = event.GetPosition();
if(dimension)
{
scene.MouseButton(pt.x,pt.y,2,event.RightIsDown(),event.ShiftDown(),event.ControlDown());
scene.MouseButton(pt.x,pt.y,0,event.LeftIsDown(),event.ShiftDown(),event.ControlDown());
}
SetFocus();
event.Skip();
}
void Canvas::OnKey(wxKeyEvent& event)
{
if(dimension)
{
scene.KeyDown(event.GetUnicodeKey());
scene.SpecialKeyDown(event.GetUnicodeKey());
}
/*else
{
scene2D.KeyDown(event.GetUnicodeKey());
if(event.GetUnicodeKey()=='+')
Scale2D();
if(event.GetUnicodeKey()=='-')
Scale2D();
}
*/
SetFocus();
Refresh();
}
void Canvas::SetShowFrame(bool show)
{
if(dimension)
scene.setShowFrame(show);
}
void Canvas::DrawGrid(bool draw)
{
if(dimension)
scene.setShowGrid(draw);
//else
//scene2D.setShowGrid(draw); /// implementar setShowGrid en MRCore en glscene2D
}
void Canvas::ViewAll()
{
scene.viewAll();
}