1 // OGLVIEW_WCL.CPP
2
3 // Copyright (C) 2005 Tommi Hassinen.
4
5 // This package is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9
10 // This package is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14
15 // You should have received a copy of the GNU General Public License
16 // along with this package; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 /*################################################################################################*/
20
21 #include "oglview_wcl.h"
22
23 #include <oglappth/oglv3d.h>
24 #include <oglappth/base_app.h>
25
26 #include "appdefine.h"
27 #include "custom_app.h"
28
29 /*################################################################################################*/
30
31 #define SB_SIZE 1024 // the selection buffer size.
32
33 bool oglview_wcl::quick_update = false;
34 bool oglview_wcl::draw_info = true;
35
oglview_wcl(custom_camera * cc)36 oglview_wcl::oglview_wcl(custom_camera * cc) :
37 pangofont_wcl(cc)
38 {
39 ccam = cc;
40 my_wnd_number = (ccam->wcl_counter++) + 1;
41
42 render = RENDER_BALL_AND_STICK;
43
44 label = LABEL_NOTHING;
45
46 colormode = ccam->prj->GetDefaultColorMode();
47
48 enable_fog = false;
49 accumulate = false;
50
51 select_buffer = new iGLu[SB_SIZE];
52 }
53
~oglview_wcl(void)54 oglview_wcl::~oglview_wcl(void)
55 {
56 delete[] select_buffer;
57 }
58
GetCCam(void)59 custom_camera * oglview_wcl::GetCCam(void)
60 {
61 return ccam; // this is the same as casting base_wcl::GetCam().
62 }
63
GetCRD(i32s * p1,fGL * p2)64 void oglview_wcl::GetCRD(i32s * p1, fGL * p2)
65 {
66 base_wnd * w = GetWnd();
67
68 if (w == NULL) // just return zeros if not linked to any window...
69 {
70 p2[0] = p2[1] = p2[2] = 0.0;
71 return;
72 }
73
74 oglv3d<GLfloat> xdir = (ccam->GetSafeLD()->ydir).vpr(ccam->GetSafeLD()->zdir); xdir = xdir / xdir.len();
75 oglv3d<GLfloat> tmpv = oglv3d<GLfloat>(ccam->GetSafeLD()->crd); tmpv = tmpv + (ccam->GetSafeLD()->zdir * ccam->focus);
76 tmpv = tmpv + xdir * (2.0 * vdim[0] * (fGL) (w->GetWidth() / 2 - p1[0]) / (fGL) w->GetWidth());
77 tmpv = tmpv + ccam->GetSafeLD()->ydir * (2.0 * vdim[1] * (fGL) (w->GetHeight() / 2 - p1[1]) / (fGL) w->GetHeight());
78 for (i32s n1 = 0;n1 < 3;n1++) p2[n1] = tmpv[n1];
79 }
80
81 static ogl_transformer tool_transformer;
82 static const ogl_obj_loc_data * tdata = NULL;
83 static const ogl_camera * rdata = NULL;
84
ButtonEvent(int x,int y)85 void oglview_wcl::ButtonEvent(int x, int y)
86 {
87 if (GetWnd()->IsTimerON())
88 {
89 bool allow_anim = false;
90 if (custom_app::GetCurrentMouseTool() == custom_app::mtZoom) allow_anim = true;
91 if (custom_app::GetCurrentMouseTool() == custom_app::mtClipping) allow_anim = true;
92
93 if (!allow_anim) GetWnd()->SetTimerOFF();
94 }
95
96 custom_transformer_client * ctc = custom_app::GetAppC()->GetPrj();
97
98 static i32s stored_render;
99 static bool stored_accumulate;
100
101 ///////////////////////////////////////////////////////////////////////////
102
103 if (custom_app::GetCurrentMouseTool() == custom_app::mtDraw)
104 {
105 mouseinfo::latest_x = x;
106 mouseinfo::latest_y = y;
107
108 MyUpdateWnd(pDraw, x, y);
109 }
110
111 ///////////////////////////////////////////////////////////////////////////
112
113 if (custom_app::GetCurrentMouseTool() == custom_app::mtErase)
114 {
115 mouseinfo::latest_x = x;
116 mouseinfo::latest_y = y;
117
118 MyUpdateWnd(pErase, x, y);
119 }
120
121 ///////////////////////////////////////////////////////////////////////////
122
123 if (custom_app::GetCurrentMouseTool() == custom_app::mtSelect)
124 {
125 if (mouseinfo::state != mouseinfo::sDown) return;
126
127 MyUpdateWnd(pSelect, x, y);
128 }
129
130 ///////////////////////////////////////////////////////////////////////////
131
132 if (custom_app::GetCurrentMouseTool() == custom_app::mtZoom)
133 {
134 if (quick_update)
135 {
136 if (mouseinfo::state == mouseinfo::sDown)
137 {
138 stored_render = render;
139 stored_accumulate = accumulate;
140
141 render = RENDER_WIREFRAME;
142 accumulate = false;
143 }
144 else
145 {
146 render = stored_render;
147 accumulate = stored_accumulate;
148
149 ccam->prj->UpdateGraphicsViews(ccam);
150 }
151 }
152
153 mouseinfo::latest_x = x;
154 mouseinfo::latest_y = y;
155 }
156
157 ///////////////////////////////////////////////////////////////////////////
158
159 if (custom_app::GetCurrentMouseTool() == custom_app::mtClipping)
160 {
161 if (quick_update)
162 {
163 if (mouseinfo::state == mouseinfo::sDown)
164 {
165 stored_render = render;
166 stored_accumulate = accumulate;
167
168 render = RENDER_WIREFRAME;
169 accumulate = false;
170 }
171 else
172 {
173 render = stored_render;
174 accumulate = stored_accumulate;
175
176 ccam->prj->UpdateGraphicsViews(ccam);
177 }
178 }
179
180 mouseinfo::latest_x = x;
181 mouseinfo::latest_y = y;
182 }
183
184 ///////////////////////////////////////////////////////////////////////////
185
186 if (custom_app::GetCurrentMouseTool() == custom_app::mtTranslateXY)
187 {
188 if (mouseinfo::state == mouseinfo::sDown)
189 {
190 if (quick_update) // if quick, change the rendering params...
191 {
192 stored_render = render;
193 stored_accumulate = accumulate;
194
195 render = RENDER_WIREFRAME;
196 accumulate = false;
197 }
198
199 if (!mouseinfo::shift_down)
200 {
201 ctc->tc_object_ref = ccam;
202 ctc->tc_local_object = true;
203 }
204 else
205 {
206 ctc->tc_object_ref = ccam->prj->selected_object;
207
208 i32s index = base_app::GetAppB()->IsLight(ctc->tc_object_ref);
209 ctc->tc_local_object = (index != NOT_DEFINED && dynamic_cast<ogl_light *>(ctc->tc_object_ref)->owner == ccam);
210
211 if (!ctc->tc_object_ref && mouseinfo::shift_down)
212 {
213 tool_transformer.Init(custom_app::GetPrj());
214 ctc->tc_object_ref = (& tool_transformer);
215 }
216
217 if (ctc->tc_object_ref) ctc->tc_object_ref->BeginTransformation();
218 }
219
220 // if CTRL is down, use object's own direction, not that of camera's !!!!!!!!!
221 // if CTRL is down, use object's own direction, not that of camera's !!!!!!!!!
222 // if CTRL is down, use object's own direction, not that of camera's !!!!!!!!!
223
224 if (mouseinfo::ctrl_down) tdata = ctc->tc_object_ref->GetSafeLD();
225 else tdata = ccam->GetSafeLD();
226 }
227 else
228 {
229 if (ctc->tc_object_ref) ctc->tc_object_ref->EndTransformation();
230
231 if (quick_update) // if quick, put back original params and update...
232 {
233 render = stored_render;
234 accumulate = stored_accumulate;
235
236 if (ctc->tc_local_object) ccam->prj->UpdateGraphicsViews(ccam);
237 else ccam->prj->UpdateAllGraphicsViews();
238 }
239 }
240
241 mouseinfo::latest_x = x;
242 mouseinfo::latest_y = y;
243 }
244
245 ///////////////////////////////////////////////////////////////////////////
246
247 if (custom_app::GetCurrentMouseTool() == custom_app::mtTranslateZ)
248 {
249 if (mouseinfo::state == mouseinfo::sDown)
250 {
251 if (quick_update) // if quick, change the rendering params...
252 {
253 stored_render = render;
254 stored_accumulate = accumulate;
255
256 render = RENDER_WIREFRAME;
257 accumulate = false;
258 }
259
260 if (!mouseinfo::shift_down)
261 {
262 ctc->tc_object_ref = ccam;
263 ctc->tc_local_object = true;
264 }
265 else
266 {
267 ctc->tc_object_ref = ccam->prj->selected_object;
268
269 i32s index = base_app::GetAppB()->IsLight(ctc->tc_object_ref);
270 ctc->tc_local_object = (index != NOT_DEFINED && dynamic_cast<ogl_light *>(ctc->tc_object_ref)->owner == ccam);
271
272 if (!ctc->tc_object_ref && mouseinfo::shift_down)
273 {
274 tool_transformer.Init(ccam->prj);
275 ctc->tc_object_ref = (& tool_transformer);
276 }
277
278 if (ctc->tc_object_ref) ctc->tc_object_ref->BeginTransformation();
279 }
280
281 // if CTRL is down, use object's own direction, not that of camera's !!!!!!!!!
282 // if CTRL is down, use object's own direction, not that of camera's !!!!!!!!!
283 // if CTRL is down, use object's own direction, not that of camera's !!!!!!!!!
284
285 if (mouseinfo::ctrl_down) tdata = ctc->tc_object_ref->GetSafeLD();
286 else tdata = ccam->GetSafeLD();
287 }
288 else
289 {
290 if (ctc->tc_object_ref) ctc->tc_object_ref->EndTransformation();
291
292 if (quick_update) // if quick, put back original params and update...
293 {
294 render = stored_render;
295 accumulate = stored_accumulate;
296
297 if (ctc->tc_local_object) ccam->prj->UpdateGraphicsViews(ccam);
298 else ccam->prj->UpdateAllGraphicsViews();
299 }
300 }
301
302 mouseinfo::latest_x = x;
303 mouseinfo::latest_y = y;
304 }
305
306 ///////////////////////////////////////////////////////////////////////////
307
308 if (custom_app::GetCurrentMouseTool() == custom_app::mtOrbitXY)
309 {
310 if (mouseinfo::state == mouseinfo::sDown)
311 {
312 if (quick_update) // if quick, change the rendering params...
313 {
314 stored_render = render;
315 stored_accumulate = accumulate;
316
317 render = RENDER_WIREFRAME;
318 accumulate = false;
319 }
320
321 if (!mouseinfo::shift_down)
322 {
323 ctc->tc_object_ref = ccam;
324 ctc->tc_local_object = true;
325 }
326 else
327 {
328 ctc->tc_object_ref = ccam->prj->selected_object;
329
330 i32s index = base_app::GetAppB()->IsLight(ctc->tc_object_ref);
331 ctc->tc_local_object = (index != NOT_DEFINED && dynamic_cast<ogl_light *>(ctc->tc_object_ref)->owner == ccam);
332
333 if (!ctc->tc_object_ref && mouseinfo::shift_down)
334 {
335 tool_transformer.Init(ccam->prj);
336 ctc->tc_object_ref = (& tool_transformer);
337 }
338
339 if (ctc->tc_object_ref) ctc->tc_object_ref->BeginTransformation();
340 }
341
342 rdata = ccam;
343 }
344 else
345 {
346 if (ctc->tc_object_ref) ctc->tc_object_ref->EndTransformation();
347
348 if (quick_update) // if quick, put back original params and update...
349 {
350 render = stored_render;
351 accumulate = stored_accumulate;
352
353 if (ctc->tc_local_object) ccam->prj->UpdateGraphicsViews(ccam);
354 else ccam->prj->UpdateAllGraphicsViews();
355 }
356
357 // the animation switch is here...
358
359 if (animX * animX + animY * animY > 7.5)
360 {
361 animX *= 0.25; animY *= 0.25;
362 GetWnd()->SetTimerON(10);
363 }
364 }
365
366 mouseinfo::latest_x = x;
367 mouseinfo::latest_y = y;
368 }
369
370 ///////////////////////////////////////////////////////////////////////////
371
372 if (custom_app::GetCurrentMouseTool() == custom_app::mtOrbitZ)
373 {
374 if (mouseinfo::state == mouseinfo::sDown)
375 {
376 if (quick_update) // if quick, change the rendering params...
377 {
378 stored_render = render;
379 stored_accumulate = accumulate;
380
381 render = RENDER_WIREFRAME;
382 accumulate = false;
383 }
384
385 if (!mouseinfo::shift_down)
386 {
387 ctc->tc_object_ref = ccam;
388 ctc->tc_local_object = true;
389 }
390 else
391 {
392 ctc->tc_object_ref = ccam->prj->selected_object;
393
394 i32s index = base_app::GetAppB()->IsLight(ctc->tc_object_ref);
395 ctc->tc_local_object = (index != NOT_DEFINED && dynamic_cast<ogl_light *>(ctc->tc_object_ref)->owner == ccam);
396
397 if (!ctc->tc_object_ref && mouseinfo::shift_down)
398 {
399 tool_transformer.Init(ccam->prj);
400 ctc->tc_object_ref = (& tool_transformer);
401 }
402
403 if (ctc->tc_object_ref) ctc->tc_object_ref->BeginTransformation();
404 }
405
406 rdata = ccam;
407 }
408 else
409 {
410 if (ctc->tc_object_ref) ctc->tc_object_ref->EndTransformation();
411
412 if (quick_update) // if quick, put back original params and update...
413 {
414 render = stored_render;
415 accumulate = stored_accumulate;
416
417 if (ctc->tc_local_object) ccam->prj->UpdateGraphicsViews(ccam);
418 else ccam->prj->UpdateAllGraphicsViews();
419 }
420 }
421
422 mouseinfo::latest_x = x;
423 mouseinfo::latest_y = y;
424 }
425
426 ///////////////////////////////////////////////////////////////////////////
427
428 if (custom_app::GetCurrentMouseTool() == custom_app::mtRotateXY)
429 {
430 if (mouseinfo::state == mouseinfo::sDown)
431 {
432 if (quick_update) // if quick, change the rendering params...
433 {
434 stored_render = render;
435 stored_accumulate = accumulate;
436
437 render = RENDER_WIREFRAME;
438 accumulate = false;
439 }
440
441 if (!mouseinfo::shift_down)
442 {
443 ctc->tc_object_ref = ccam;
444 ctc->tc_local_object = true;
445 }
446 else
447 {
448 ctc->tc_object_ref = ccam->prj->selected_object;
449
450 i32s index = base_app::GetAppB()->IsLight(ctc->tc_object_ref);
451 ctc->tc_local_object = (index != NOT_DEFINED && dynamic_cast<ogl_light *>(ctc->tc_object_ref)->owner == ccam);
452
453 if (!ctc->tc_object_ref && mouseinfo::shift_down)
454 {
455 tool_transformer.Init(ccam->prj);
456 ctc->tc_object_ref = (& tool_transformer);
457 }
458
459 if (ctc->tc_object_ref) ctc->tc_object_ref->BeginTransformation();
460 }
461
462 rdata = ccam;
463 }
464 else
465 {
466 if (ctc->tc_object_ref) ctc->tc_object_ref->EndTransformation();
467
468 if (quick_update) // if quick, put back original params and update...
469 {
470 render = stored_render;
471 accumulate = stored_accumulate;
472
473 if (ctc->tc_local_object) ccam->prj->UpdateGraphicsViews(ccam);
474 else ccam->prj->UpdateAllGraphicsViews();
475 }
476 }
477
478 mouseinfo::latest_x = x;
479 mouseinfo::latest_y = y;
480 }
481
482 ///////////////////////////////////////////////////////////////////////////
483
484 if (custom_app::GetCurrentMouseTool() == custom_app::mtRotateZ)
485 {
486 if (mouseinfo::state == mouseinfo::sDown)
487 {
488 if (quick_update) // if quick, change the rendering params...
489 {
490 stored_render = render;
491 stored_accumulate = accumulate;
492
493 render = RENDER_WIREFRAME;
494 accumulate = false;
495 }
496
497 if (!mouseinfo::shift_down)
498 {
499 ctc->tc_object_ref = ccam;
500 ctc->tc_local_object = true;
501 }
502 else
503 {
504 ctc->tc_object_ref = ccam->prj->selected_object;
505
506 i32s index = base_app::GetAppB()->IsLight(ctc->tc_object_ref);
507 ctc->tc_local_object = (index != NOT_DEFINED && dynamic_cast<ogl_light *>(ctc->tc_object_ref)->owner == ccam);
508
509 if (!ctc->tc_object_ref && mouseinfo::shift_down)
510 {
511 tool_transformer.Init(ccam->prj);
512 ctc->tc_object_ref = (& tool_transformer);
513 }
514
515 if (ctc->tc_object_ref) ctc->tc_object_ref->BeginTransformation();
516 }
517
518 rdata = ccam;
519 }
520 else
521 {
522 if (ctc->tc_object_ref) ctc->tc_object_ref->EndTransformation();
523
524 if (quick_update) // if quick, put back original params and update...
525 {
526 render = stored_render;
527 accumulate = stored_accumulate;
528
529 if (ctc->tc_local_object) ccam->prj->UpdateGraphicsViews(ccam);
530 else ccam->prj->UpdateAllGraphicsViews();
531 }
532 }
533
534 mouseinfo::latest_x = x;
535 mouseinfo::latest_y = y;
536 }
537
538 ///////////////////////////////////////////////////////////////////////////
539
540 if (custom_app::GetCurrentMouseTool() == custom_app::mtMeasure)
541 {
542 if (mouseinfo::state != mouseinfo::sDown) return;
543
544 MyUpdateWnd(pMeasure, x, y);
545 }
546 }
547
MotionEvent(int x,int y)548 void oglview_wcl::MotionEvent(int x, int y)
549 {
550 custom_transformer_client * ctc = custom_app::GetAppC()->GetPrj();
551
552 ///////////////////////////////////////////////////////////////////////////
553
554 if (custom_app::GetCurrentMouseTool() == custom_app::mtDraw)
555 {
556 }
557
558 ///////////////////////////////////////////////////////////////////////////
559
560 if (custom_app::GetCurrentMouseTool() == custom_app::mtErase)
561 {
562 }
563
564 ///////////////////////////////////////////////////////////////////////////
565
566 if (custom_app::GetCurrentMouseTool() == custom_app::mtSelect)
567 {
568 }
569
570 ///////////////////////////////////////////////////////////////////////////
571
572 if (custom_app::GetCurrentMouseTool() == custom_app::mtZoom)
573 {
574 fGL dist[3] = { 0.0, 0.0, 0.0 };
575 dist[2] = mouseinfo::dist_sensitivity * vdim[1] * (fGL) (mouseinfo::latest_y - y) / (fGL) GetWnd()->GetHeight();
576 //cout << "AA : " << ccam->GetSafeLD()->crd[0] << " " << ccam->GetSafeLD()->crd[1] << " " << ccam->GetSafeLD()->crd[2] << endl;
577 ccam->TranslateObject(dist, ccam->GetSafeLD());
578 //cout << "BB : " << ccam->GetSafeLD()->crd[0] << " " << ccam->GetSafeLD()->crd[1] << " " << ccam->GetSafeLD()->crd[2] << endl;
579 ccam->focus += dist[2];
580
581 if (quick_update) ccam->prj->UpdateGraphicsView(this);
582 else ccam->prj->UpdateGraphicsViews(ccam);
583
584 mouseinfo::latest_x = x;
585 mouseinfo::latest_y = y;
586 }
587
588 ///////////////////////////////////////////////////////////////////////////
589
590 if (custom_app::GetCurrentMouseTool() == custom_app::mtClipping)
591 {
592 ccam->clipping += (fGL) (mouseinfo::latest_y - y) / (fGL) GetWnd()->GetHeight();
593 if (ccam->clipping < 0.01) ccam->clipping = 0.01;
594 if (ccam->clipping > 0.99) ccam->clipping = 0.99;
595
596 cout << "clipping = " << ccam->clipping << " = ";
597 cout << (ccam->clipping * (2.0 * ccam->focus)) << " nm." << endl;
598
599 if (quick_update) ccam->prj->UpdateGraphicsView(this);
600 else ccam->prj->UpdateGraphicsViews(ccam);
601
602 mouseinfo::latest_x = x;
603 mouseinfo::latest_y = y;
604 }
605
606 ///////////////////////////////////////////////////////////////////////////
607
608 if (custom_app::GetCurrentMouseTool() == custom_app::mtTranslateXY)
609 {
610 fGL dist[3] = { 0.0, 0.0, 0.0 };
611 if (ctc->tc_object_ref != NULL && tdata != NULL)
612 {
613 dist[0] = mouseinfo::dist_sensitivity * vdim[0] * (fGL) (mouseinfo::latest_x - x) / (fGL) GetWnd()->GetWidth();
614 dist[1] = mouseinfo::dist_sensitivity * vdim[1] * (fGL) (mouseinfo::latest_y - y) / (fGL) GetWnd()->GetHeight();
615 ctc->tc_object_ref->TranslateObject(dist, tdata);
616
617 if (quick_update) ccam->prj->UpdateGraphicsView(this);
618 else
619 {
620 if (ctc->tc_local_object) ccam->prj->UpdateGraphicsViews(ccam);
621 else ccam->prj->UpdateAllGraphicsViews();
622 }
623 }
624
625 mouseinfo::latest_x = x;
626 mouseinfo::latest_y = y;
627 }
628
629 ///////////////////////////////////////////////////////////////////////////
630
631 if (custom_app::GetCurrentMouseTool() == custom_app::mtTranslateZ)
632 {
633 fGL dist[3] = { 0.0, 0.0, 0.0 };
634 if (ctc->tc_object_ref != NULL && tdata != NULL)
635 {
636 dist[2] = mouseinfo::dist_sensitivity * vdim[1] * (fGL) (mouseinfo::latest_y - y) / (fGL) GetWnd()->GetHeight();
637 ctc->tc_object_ref->TranslateObject(dist, tdata);
638
639 if (quick_update) ccam->prj->UpdateGraphicsView(this);
640 else
641 {
642 if (ctc->tc_local_object) ccam->prj->UpdateGraphicsViews(ccam);
643 else ccam->prj->UpdateAllGraphicsViews();
644 }
645 }
646
647 mouseinfo::latest_x = x;
648 mouseinfo::latest_y = y;
649 }
650
651 ///////////////////////////////////////////////////////////////////////////
652
653 if (custom_app::GetCurrentMouseTool() == custom_app::mtOrbitXY)
654 {
655 fGL ang[3] = { 0.0, 0.0, 0.0 };
656 if (ctc->tc_object_ref != NULL)
657 {
658 ang[0] = mouseinfo::ang_sensitivity * (fGL) (mouseinfo::latest_y - y) / (fGL) GetWnd()->GetHeight();
659 ang[1] = mouseinfo::ang_sensitivity * (fGL) (x - mouseinfo::latest_x) / (fGL) GetWnd()->GetWidth();
660 ctc->tc_object_ref->OrbitObject(ang, * rdata);
661
662 animX = ang[0]; animY = ang[1];
663
664 if (quick_update) ccam->prj->UpdateGraphicsView(this);
665 else
666 {
667 if (ctc->tc_local_object) ccam->prj->UpdateGraphicsViews(ccam);
668 else ccam->prj->UpdateAllGraphicsViews();
669 }
670 }
671
672 mouseinfo::latest_x = x;
673 mouseinfo::latest_y = y;
674 }
675
676 ///////////////////////////////////////////////////////////////////////////
677
678 if (custom_app::GetCurrentMouseTool() == custom_app::mtOrbitZ)
679 {
680 fGL ang[3] = { 0.0, 0.0, 0.0 };
681 if (ctc->tc_object_ref != NULL)
682 {
683 ang[2] = mouseinfo::ang_sensitivity * (fGL) (x - mouseinfo::latest_x) / (fGL) GetWnd()->GetWidth();
684 ctc->tc_object_ref->OrbitObject(ang, * rdata);
685
686 if (quick_update) ccam->prj->UpdateGraphicsView(this);
687 else
688 {
689 if (ctc->tc_local_object) ccam->prj->UpdateGraphicsViews(ccam);
690 else ccam->prj->UpdateAllGraphicsViews();
691 }
692 }
693
694 mouseinfo::latest_x = x;
695 mouseinfo::latest_y = y;
696 }
697
698 ///////////////////////////////////////////////////////////////////////////
699
700 if (custom_app::GetCurrentMouseTool() == custom_app::mtRotateXY)
701 {
702 fGL ang[3] = { 0.0, 0.0, 0.0 };
703 if (ctc->tc_object_ref != NULL)
704 {
705 ang[0] = mouseinfo::ang_sensitivity * (fGL) (mouseinfo::latest_y - y) / (fGL) GetWnd()->GetHeight();
706 ang[1] = mouseinfo::ang_sensitivity * (fGL) (x - mouseinfo::latest_x) / (fGL) GetWnd()->GetWidth();
707 ctc->tc_object_ref->RotateObject(ang, * rdata);
708
709 if (quick_update) ccam->prj->UpdateGraphicsView(this);
710 else
711 {
712 if (ctc->tc_local_object) ccam->prj->UpdateGraphicsViews(ccam);
713 else ccam->prj->UpdateAllGraphicsViews();
714 }
715 }
716
717 mouseinfo::latest_x = x;
718 mouseinfo::latest_y = y;
719 }
720
721 ///////////////////////////////////////////////////////////////////////////
722
723 if (custom_app::GetCurrentMouseTool() == custom_app::mtRotateZ)
724 {
725 fGL ang[3] = { 0.0, 0.0, 0.0 };
726 if (ctc->tc_object_ref != NULL)
727 {
728 ang[2] = mouseinfo::ang_sensitivity * (fGL) (x - mouseinfo::latest_x) / (fGL) GetWnd()->GetWidth();
729 ctc->tc_object_ref->RotateObject(ang, * rdata);
730
731 if (quick_update) ccam->prj->UpdateGraphicsView(this);
732 else
733 {
734 if (ctc->tc_local_object) ccam->prj->UpdateGraphicsViews(ccam);
735 else ccam->prj->UpdateAllGraphicsViews();
736 }
737 }
738
739 mouseinfo::latest_x = x;
740 mouseinfo::latest_y = y;
741 }
742
743 ///////////////////////////////////////////////////////////////////////////
744
745 if (custom_app::GetCurrentMouseTool() == custom_app::mtMeasure)
746 {
747 }
748 }
749
UpdateWnd(void)750 void oglview_wcl::UpdateWnd(void)
751 {
752 base_wnd * w = GetWnd();
753 if (w != NULL && ccam != NULL)
754 {
755 w->SetCurrent();
756 MyUpdateWnd();
757 }
758 else cout << "DEBUG : oglview_wcl::UpdateWnd() : skipped!" << endl;
759 }
760
MyUpdateWnd(pmode pm,int x,int y)761 void oglview_wcl::MyUpdateWnd(pmode pm, int x, int y)
762 {
763 if (GetWnd() == NULL) return; // skip rendering if an invalid wnd!!!
764 if (GetWnd()->GetWidth() < 0) return; // skip rendering if an invalid wnd!!!
765
766 // A SIMPLE FRAMES-PER-SECOND COUNTER FOR GRAPHICS OPTIMIZATION
767 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
768 /* const int numframes = 30;
769 static int framecounter = 0;
770 static double timecounter = 0.0;
771 static long prevtime = 0;
772 timeval tv; gettimeofday(& tv, NULL);
773 long currtime = tv.tv_usec; // according to manpages, this should be in microseconds???
774 long difftime = currtime - prevtime; // the CLOCKS_PER_SEC factor works a lot better than 1.0e-06
775 prevtime = currtime;
776 if (difftime > 0) // skip the frame in timer overflow situation!!!
777 {
778 double t_secs = (double) difftime / (double) CLOCKS_PER_SEC; // time unit???
779 framecounter++; timecounter += t_secs;
780 if (framecounter >= numframes)
781 {
782 cout << "frame rate = " << ((double) framecounter / timecounter) << " FPS (";
783 cout << framecounter << " frames in " << timecounter << " seconds)." << endl;
784 framecounter = 0; timecounter = 0.0;
785 }
786 } */
787 // A SIMPLE FRAMES-PER-SECOND COUNTER FOR GRAPHICS OPTIMIZATION
788 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
789
790 bool pick = (pm != DoNotPick);
791 cam->RenderScene(GetWnd(), accumulate, pick, x, y);
792
793 // if this was a selection operation, read the information from the selection buffer.
794
795 if (pick)
796 {
797 i32s tmp1 = glRenderMode(GL_RENDER); // number of records in s-buffer.
798 i32s tmp2 = NOT_DEFINED; // index to the beginning of the selected record.
799
800 iGLu tmp3 = 0xffffffff; // original, lowest z-value...
801 // iGLu tmp3 = 0x00000000; // alternative, highest z-value...
802
803 /////////////////////////////////////////////////////////////////////////
804 // here we examine the selection buffer and select the hit with lowest
805 // z-value (since we assume that this object was visible to the user).
806 /////////////////////////////////////////////////////////////////////////
807
808 i32s tmp4[2] = { 0, 0 };
809 while (tmp4[0] < tmp1)
810 {
811 if (select_buffer[tmp4[1] + 1] < tmp3) // original, lowest z-value...
812 // if (select_buffer[tmp4[1] + 2] > tmp3) // alternative, highest z-value...
813 {
814 tmp2 = tmp4[1];
815 tmp3 = select_buffer[tmp4[1] + 1]; // original, lowest z-value...
816 // tmp3 = select_buffer[tmp4[1] + 2]; // alternative, highest z-value...
817 }
818
819 tmp4[0]++;
820 tmp4[1] += select_buffer[tmp4[1]] + 3;
821 }
822
823 // now we copy all name records of the selected hit...
824
825 vector<iGLu> name_vector;
826 if (tmp2 != NOT_DEFINED)
827 {
828 for (i32u i1 = 0;i1 < select_buffer[tmp2];i1++)
829 {
830 name_vector.push_back(select_buffer[tmp2 + i1 + 3]);
831 }
832 }
833
834 // "draw"- and "erase"-events are always forwarded to prj.
835
836 if (pm == pDraw) ccam->prj->DrawEvent(this, name_vector);
837 if (pm == pErase) ccam->prj->EraseEvent(this, name_vector);
838
839 // "select"- and "measure"-events are forwarded only if
840 // MODEL_DEPENDENT flag is set (an atom selection event).
841
842 if (pm == pSelect && name_vector.size() > 1)
843 {
844 bool test = (name_vector[0] & GLNAME_MODEL_DEPENDENT);
845 if (test)
846 {
847 ccam->prj->selected_object = NULL;
848 ccam->prj->SelectEvent(this, name_vector);
849 }
850 else
851 {
852 // we are doing a light/object selection...
853 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
854
855 base_app * app = base_app::GetAppB();
856 custom_app * myapp = custom_app::GetAppC();
857
858 const ogl_dummy_object * ref = NULL;
859 switch (name_vector[0])
860 {
861 case GLNAME_LIGHT:
862 ref = (const ogl_dummy_object *) app->FindPtrByGLName(name_vector[1]);
863 myapp->SelectLight(ref);
864 break;
865
866 case GLNAME_OBJECT:
867 ref = (const ogl_dummy_object *) app->FindPtrByGLName(name_vector[1]);
868 myapp->GetPrj()->SelectObject(ref);
869 break;
870 }
871 }
872 }
873
874 if (pm == pMeasure && name_vector.size() > 1)
875 {
876 bool test = (name_vector[0] & GLNAME_MODEL_DEPENDENT);
877 if (test)
878 {
879 // todo : make measurement different from
880 // selection (do not use a selection flag but
881 // make a separate way to show it) -> no need
882 // to mess with selected_object here anymore...
883
884 ccam->prj->selected_object = NULL; // FixMe!!!
885
886 ccam->prj->MeasureEvent(this, name_vector);
887 }
888 }
889 }
890 }
891
InitGL(void)892 void oglview_wcl::InitGL(void)
893 {
894 const fGL background[4] = { 0.0, 0.0, 0.0, 1.0};
895 glClearColor(background[0], background[1], background[2], background[3]);
896
897 glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST);
898 glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 64);
899
900 const fGL specular_reflectance[4] = { 0.9, 0.9, 0.9, 1.0 };
901 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular_reflectance);
902
903 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
904 glEnable(GL_COLOR_MATERIAL);
905
906 const fGL ambient_intensity[4] = { 0.2, 0.2, 0.2, 1.0 };
907 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient_intensity);
908
909 glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, true);
910
911 glFogi(GL_FOG_MODE, GL_EXP);
912 glFogf(GL_FOG_DENSITY, 0.15);
913
914 const fGL fog_color[4] = { 0.0, 0.0, 0.0, 0.0 };
915 glFogfv(GL_FOG_COLOR, fog_color);
916
917 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
918
919 glSelectBuffer(SB_SIZE, select_buffer);
920
921 // also setup the lights, just to make sure it always happens...
922 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
923
924 base_app::GetAppB()->SetupLights(ccam);
925
926 // all classes that inherit pangofont_wcl must call ogl_InitPangoFont()!!!
927 // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
928
929 ogl_InitPangoFont("courier 12");
930 }
931
RenderGL(rmode rm)932 void oglview_wcl::RenderGL(rmode rm)
933 {
934 custom_app::GetAppC()->GetPrj()->Render(this, rm);
935 }
936
937 /*################################################################################################*/
938
939 // eof
940