1 //#**************************************************************
2 //# filename: GLDrawWnd.cpp
3 //#
4 //# author: Gerstmayr, Vetyukov
5 //#
6 //# generated:
7 //# description:
8 //# comments:
9 //#
10 //# Copyright (c) 2003-2013 Johannes Gerstmayr, Linz Center of Mechatronics GmbH, Austrian
11 //# Center of Competence in Mechatronics GmbH, Institute of Technical Mechanics at the
12 //# Johannes Kepler Universitaet Linz, Austria. All rights reserved.
13 //#
14 //# This file is part of HotInt.
15 //# HotInt is free software: you can redistribute it and/or modify it under the terms of
16 //# the HOTINT license. See folder 'licenses' for more details.
17 //#
18 //# bug reports are welcome!!!
19 //# WWW: www.hotint.org
20 //# email: bug_reports@hotint.org or support@hotint.org
21 //#***************************************************************************************
22
23
24
25 #include "stdafx.h"
26
27 //#include <iostream.h>
28 //#include <stdlib.h>
29 //#include <stdio.h>
30 //#include <fstream.h>
31
32 #define my_new_stdiostream
33
34 #include <iostream>
35 #include <fstream>
36 #include <cstdlib>
37 #include <cstdio>
38
39
40 //#include <math.h>
41
42 #include "savewindowbitmap.h"
43 #include "GLDrawWnd.h"
44
45 #ifdef _DEBUG
46 #define new DEBUG_NEW
47 #undef THIS_FILE
48 static char THIS_FILE[] = __FILE__;
49 #endif
50
51 #include "resource.h"
52
53 #define ROTATION_TIMER_ID 1
54 #define ROTATION_TIMER_DELAY 20
55 #define SCALING_ANIMATE_TIMER_ID 2
56
57 const int MAX_SIZE = 10000000;
58 const float MAX_FOVY = 160.0f; // Maximal viewing angle
59
60 const int ToolBarButtons = 10;
61 const int ToolBarButtonSize = 24;
62
63 const int FrameNumberDigits = 6;
64
65
66 const float NoSavedModelviewMatrix = 1.8945e10f;
67
68
69
70 // glEnable(GL_POLYGON_STIPPLE);
71 // glPolygonStipple(stippleMask[0]); /* 0% opaqueness */
72 // glPolygonStipple(stippleMask[8]); /* 50% opaqueness */
73 // glPolygonStipple(stippleMask[16]); /* 100% opaqueness */
74
75 const GLubyte stippleMask[17][128] =
76 {
77 /* NOTE: 0% opaqueness is faster to set and probably faster to render with:
78 glDisable(GL_POLYGON_STIPPLE);
79 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); */
80 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
81 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
82 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
83 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
84 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
85 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
86 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
87 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
88
89 {0x88, 0x88, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
90 0x88, 0x88, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
91 0x88, 0x88, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
92 0x88, 0x88, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
93 0x88, 0x88, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
94 0x88, 0x88, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
95 0x88, 0x88, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
96 0x88, 0x88, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
97
98 {0x88, 0x88, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00,
99 0x88, 0x88, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00,
100 0x88, 0x88, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00,
101 0x88, 0x88, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00,
102 0x88, 0x88, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00,
103 0x88, 0x88, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00,
104 0x88, 0x88, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00,
105 0x88, 0x88, 0x88, 0x88, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00},
106
107 {0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00,
108 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00,
109 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00,
110 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00,
111 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00,
112 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00,
113 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00,
114 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00},
115
116 {0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
117 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
118 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
119 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
120 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
121 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
122 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
123 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00, 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00},
124
125 {0xaa, 0xaa, 0xaa, 0xaa, 0x44, 0x44, 0x44, 0x44, 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
126 0xaa, 0xaa, 0xaa, 0xaa, 0x44, 0x44, 0x44, 0x44, 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
127 0xaa, 0xaa, 0xaa, 0xaa, 0x44, 0x44, 0x44, 0x44, 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
128 0xaa, 0xaa, 0xaa, 0xaa, 0x44, 0x44, 0x44, 0x44, 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
129 0xaa, 0xaa, 0xaa, 0xaa, 0x44, 0x44, 0x44, 0x44, 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
130 0xaa, 0xaa, 0xaa, 0xaa, 0x44, 0x44, 0x44, 0x44, 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
131 0xaa, 0xaa, 0xaa, 0xaa, 0x44, 0x44, 0x44, 0x44, 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00,
132 0xaa, 0xaa, 0xaa, 0xaa, 0x44, 0x44, 0x44, 0x44, 0xaa, 0xaa, 0xaa, 0xaa, 0x00, 0x00, 0x00, 0x00},
133
134 {0xaa, 0xaa, 0xaa, 0xaa, 0x44, 0x44, 0x44, 0x44, 0xaa, 0xaa, 0xaa, 0xaa, 0x11, 0x11, 0x11, 0x11,
135 0xaa, 0xaa, 0xaa, 0xaa, 0x44, 0x44, 0x44, 0x44, 0xaa, 0xaa, 0xaa, 0xaa, 0x11, 0x11, 0x11, 0x11,
136 0xaa, 0xaa, 0xaa, 0xaa, 0x44, 0x44, 0x44, 0x44, 0xaa, 0xaa, 0xaa, 0xaa, 0x11, 0x11, 0x11, 0x11,
137 0xaa, 0xaa, 0xaa, 0xaa, 0x44, 0x44, 0x44, 0x44, 0xaa, 0xaa, 0xaa, 0xaa, 0x11, 0x11, 0x11, 0x11,
138 0xaa, 0xaa, 0xaa, 0xaa, 0x44, 0x44, 0x44, 0x44, 0xaa, 0xaa, 0xaa, 0xaa, 0x11, 0x11, 0x11, 0x11,
139 0xaa, 0xaa, 0xaa, 0xaa, 0x44, 0x44, 0x44, 0x44, 0xaa, 0xaa, 0xaa, 0xaa, 0x11, 0x11, 0x11, 0x11,
140 0xaa, 0xaa, 0xaa, 0xaa, 0x44, 0x44, 0x44, 0x44, 0xaa, 0xaa, 0xaa, 0xaa, 0x11, 0x11, 0x11, 0x11,
141 0xaa, 0xaa, 0xaa, 0xaa, 0x44, 0x44, 0x44, 0x44, 0xaa, 0xaa, 0xaa, 0xaa, 0x11, 0x11, 0x11, 0x11},
142
143 {0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x11, 0x11, 0x11, 0x11,
144 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x11, 0x11, 0x11, 0x11,
145 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x11, 0x11, 0x11, 0x11,
146 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x11, 0x11, 0x11, 0x11,
147 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x11, 0x11, 0x11, 0x11,
148 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x11, 0x11, 0x11, 0x11,
149 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x11, 0x11, 0x11, 0x11,
150 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x11, 0x11, 0x11, 0x11},
151
152 {0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
153 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
154 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
155 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
156 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
157 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
158 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
159 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55},
160
161 {0xee, 0xee, 0xee, 0xee, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
162 0xee, 0xee, 0xee, 0xee, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
163 0xee, 0xee, 0xee, 0xee, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
164 0xee, 0xee, 0xee, 0xee, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
165 0xee, 0xee, 0xee, 0xee, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
166 0xee, 0xee, 0xee, 0xee, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
167 0xee, 0xee, 0xee, 0xee, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
168 0xee, 0xee, 0xee, 0xee, 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55},
169
170 {0xee, 0xee, 0xee, 0xee, 0x55, 0x55, 0x55, 0x55, 0xbb, 0xbb, 0xbb, 0xbb, 0x55, 0x55, 0x55, 0x55,
171 0xee, 0xee, 0xee, 0xee, 0x55, 0x55, 0x55, 0x55, 0xbb, 0xbb, 0xbb, 0xbb, 0x55, 0x55, 0x55, 0x55,
172 0xee, 0xee, 0xee, 0xee, 0x55, 0x55, 0x55, 0x55, 0xbb, 0xbb, 0xbb, 0xbb, 0x55, 0x55, 0x55, 0x55,
173 0xee, 0xee, 0xee, 0xee, 0x55, 0x55, 0x55, 0x55, 0xbb, 0xbb, 0xbb, 0xbb, 0x55, 0x55, 0x55, 0x55,
174 0xee, 0xee, 0xee, 0xee, 0x55, 0x55, 0x55, 0x55, 0xbb, 0xbb, 0xbb, 0xbb, 0x55, 0x55, 0x55, 0x55,
175 0xee, 0xee, 0xee, 0xee, 0x55, 0x55, 0x55, 0x55, 0xbb, 0xbb, 0xbb, 0xbb, 0x55, 0x55, 0x55, 0x55,
176 0xee, 0xee, 0xee, 0xee, 0x55, 0x55, 0x55, 0x55, 0xbb, 0xbb, 0xbb, 0xbb, 0x55, 0x55, 0x55, 0x55,
177 0xee, 0xee, 0xee, 0xee, 0x55, 0x55, 0x55, 0x55, 0xbb, 0xbb, 0xbb, 0xbb, 0x55, 0x55, 0x55, 0x55},
178
179 {0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55, 0xbb, 0xbb, 0xbb, 0xbb, 0x55, 0x55, 0x55, 0x55,
180 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55, 0xbb, 0xbb, 0xbb, 0xbb, 0x55, 0x55, 0x55, 0x55,
181 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55, 0xbb, 0xbb, 0xbb, 0xbb, 0x55, 0x55, 0x55, 0x55,
182 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55, 0xbb, 0xbb, 0xbb, 0xbb, 0x55, 0x55, 0x55, 0x55,
183 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55, 0xbb, 0xbb, 0xbb, 0xbb, 0x55, 0x55, 0x55, 0x55,
184 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55, 0xbb, 0xbb, 0xbb, 0xbb, 0x55, 0x55, 0x55, 0x55,
185 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55, 0xbb, 0xbb, 0xbb, 0xbb, 0x55, 0x55, 0x55, 0x55,
186 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55, 0xbb, 0xbb, 0xbb, 0xbb, 0x55, 0x55, 0x55, 0x55},
187
188 {0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55, 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55,
189 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55, 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55,
190 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55, 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55,
191 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55, 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55,
192 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55, 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55,
193 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55, 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55,
194 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55, 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55,
195 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55, 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55},
196
197 {0xff, 0xff, 0xff, 0xff, 0xdd, 0xdd, 0xdd, 0xdd, 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55,
198 0xff, 0xff, 0xff, 0xff, 0xdd, 0xdd, 0xdd, 0xdd, 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55,
199 0xff, 0xff, 0xff, 0xff, 0xdd, 0xdd, 0xdd, 0xdd, 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55,
200 0xff, 0xff, 0xff, 0xff, 0xdd, 0xdd, 0xdd, 0xdd, 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55,
201 0xff, 0xff, 0xff, 0xff, 0xdd, 0xdd, 0xdd, 0xdd, 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55,
202 0xff, 0xff, 0xff, 0xff, 0xdd, 0xdd, 0xdd, 0xdd, 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55,
203 0xff, 0xff, 0xff, 0xff, 0xdd, 0xdd, 0xdd, 0xdd, 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55,
204 0xff, 0xff, 0xff, 0xff, 0xdd, 0xdd, 0xdd, 0xdd, 0xff, 0xff, 0xff, 0xff, 0x55, 0x55, 0x55, 0x55},
205
206 {0xff, 0xff, 0xff, 0xff, 0xdd, 0xdd, 0xdd, 0xdd, 0xff, 0xff, 0xff, 0xff, 0x77, 0x77, 0x77, 0x77,
207 0xff, 0xff, 0xff, 0xff, 0xdd, 0xdd, 0xdd, 0xdd, 0xff, 0xff, 0xff, 0xff, 0x77, 0x77, 0x77, 0x77,
208 0xff, 0xff, 0xff, 0xff, 0xdd, 0xdd, 0xdd, 0xdd, 0xff, 0xff, 0xff, 0xff, 0x77, 0x77, 0x77, 0x77,
209 0xff, 0xff, 0xff, 0xff, 0xdd, 0xdd, 0xdd, 0xdd, 0xff, 0xff, 0xff, 0xff, 0x77, 0x77, 0x77, 0x77,
210 0xff, 0xff, 0xff, 0xff, 0xdd, 0xdd, 0xdd, 0xdd, 0xff, 0xff, 0xff, 0xff, 0x77, 0x77, 0x77, 0x77,
211 0xff, 0xff, 0xff, 0xff, 0xdd, 0xdd, 0xdd, 0xdd, 0xff, 0xff, 0xff, 0xff, 0x77, 0x77, 0x77, 0x77,
212 0xff, 0xff, 0xff, 0xff, 0xdd, 0xdd, 0xdd, 0xdd, 0xff, 0xff, 0xff, 0xff, 0x77, 0x77, 0x77, 0x77,
213 0xff, 0xff, 0xff, 0xff, 0xdd, 0xdd, 0xdd, 0xdd, 0xff, 0xff, 0xff, 0xff, 0x77, 0x77, 0x77, 0x77},
214
215 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x77, 0x77, 0x77, 0x77,
216 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x77, 0x77, 0x77, 0x77,
217 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x77, 0x77, 0x77, 0x77,
218 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x77, 0x77, 0x77, 0x77,
219 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x77, 0x77, 0x77, 0x77,
220 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x77, 0x77, 0x77, 0x77,
221 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x77, 0x77, 0x77, 0x77,
222 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x77, 0x77, 0x77, 0x77},
223
224 /* NOTE: 100% opaqueness is faster to set and probably faster to render with:
225 glDisable(GL_POLYGON_STIPPLE); */
226 {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
227 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
228 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
229 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
230 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
231 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
232 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
233 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
234 };
235
236
237
238 /////////////////////////////////////////////////////////////////////////////
239 // CGLDrawWnd
240
241 CToolBar CGLDrawWnd::ToolBar;
242
243 //GLsizei CGLDrawWnd::SelBufSize = 20;
244 const int MAX_N_TEXTURES = 1; //one is needed to pass texture //for storing textures: max. tested value: 136000; //approx. 2^17
245 const int MAX_N_FE_COLOR_TEXTURES = 8;
246
247
CGLDrawWnd()248 CGLDrawWnd::CGLDrawWnd() :
249 m_pDC(NULL),
250 AxesPosition(0),
251 bFittingTheView(false),
252 bShowLegend(1),
253 bRotationTimerRunning(false)
254 {
255 //bLighting = TRUE;
256 prohibit_redraw = 0;
257 StartingPoint.x = -1000000000;
258 StartingPoint.y = -1000000000;
259 Action = ActionNone;
260
261 DetailLevel = 2.8f;
262 TranslationStepCoeff = .01f;
263 RotationStep = 0.5f;
264 DetailLevelStepCoeff = 0.005f; // 0.00025
265 PerspectiveStepCoeff = 0.01f;
266 AspectRatio = 1;
267 CenterPoint.x = CenterPoint.y = 0;
268 CenterOffset.x = CenterOffset.y = CenterOffset.z = 0;
269 SCENE_OFFSET_COEFF = 1.5f;
270
271 saved_modelview_matrix[0] = NoSavedModelviewMatrix;
272
273 char buf[2000];
274 GetCurrentDirectory(2000,buf);
275 ProgramDirectory = buf;
276
277 BackgroundR = 0;
278 BackgroundG = 0;
279 BackgroundB = 0.3f;
280
281 ScrTextR = 1.0f;
282 ScrTextG = 1.0f;
283 ScrTextB = 0.7f;
284
285 //textures:
286 gltexturecnt = 0; //counter for OpenGL textures
287 gltexturecnt_warned = 0;
288 nmaxtextures = MAX_N_TEXTURES;
289 glstoretextures = 0; //do not store textures
290 }
291
SetWCDI(WCDInterface * p_wcdi)292 void CGLDrawWnd::SetWCDI(WCDInterface * p_wcdi)
293 {
294 pWCDI = p_wcdi;
295 MaxSceneCoord = pWCDI->GetSceneMaxAbsCoordinate();
296 bNoRotationState = !pWCDI->AllowRotation();
297 DialogFramesRecording.SetWCDI(pWCDI);
298 }
299
~CGLDrawWnd()300 CGLDrawWnd::~CGLDrawWnd()
301 {
302 glDeleteTextures(MAX_N_TEXTURES, texNames);
303 delete[] texNames;
304
305 glDeleteTextures(MAX_N_FE_COLOR_TEXTURES, FEcolortexNames);
306 delete[] FEcolortexNames;
307
308 /* if(hEnhMetaFile)
309 DeleteEnhMetaFile(hEnhMetaFile);*/
310 }
311
312
BEGIN_MESSAGE_MAP(CGLDrawWnd,CWnd)313 BEGIN_MESSAGE_MAP(CGLDrawWnd, CWnd)
314 //{{AFX_MSG_MAP(CGLDrawWnd)
315 ON_WM_CREATE()
316 ON_WM_PAINT()
317 ON_WM_SIZE()
318 ON_WM_ERASEBKGND()
319 ON_WM_DESTROY()
320 ON_WM_LBUTTONDBLCLK()
321 ON_WM_LBUTTONDOWN()
322 ON_WM_LBUTTONUP()
323 ON_WM_MOUSEMOVE()
324 ON_WM_RBUTTONDOWN()
325 ON_WM_RBUTTONUP()
326 ON_COMMAND(ID_BUTTON_NO_ROTATION, OnButtonNoRotation)
327 ON_COMMAND(ID_BUTTON_STANDARD_VIEW_XY, OnButtonStandardViewXy)
328 ON_COMMAND(ID_BUTTON_STANDARD_VIEW_XYZ, OnButtonStandardViewXyz)
329 ON_COMMAND(ID_BUTTON_STANDARD_VIEW_XZ, OnButtonStandardViewXz)
330 ON_COMMAND(ID_BUTTON_STANDARD_VIEW_YZ, OnButtonStandardViewYz)
331 ON_COMMAND(ID_BUTTON_STANDARD_VIEW_ROTATE, OnButtonStandardViewRotate)
332 ON_COMMAND(ID_BUTTON_FIT, OnButtonFit)
333 ON_COMMAND(ID_BUTTON_MOVE_AXES, OnButtonMoveAxes)
334 ON_WM_TIMER()
335 ON_COMMAND(ID_BUTTON_SAVE_IMAGE, OnButtonSaveImage)
336 ON_COMMAND(ID_BUTTON_FRAMES_RECORDING, OnButtonFramesRecording)
337 //}}AFX_MSG_MAP
338 ON_MESSAGE(WM_REDRAW,OnRedraw)
339 ON_NOTIFY_EX( TTN_NEEDTEXT, 0, ToolBarToolTipsSupport )
340 // ON_WM_KEYUP()
341 ON_WM_MOUSEWHEEL()
342 END_MESSAGE_MAP()
343
344
345 /////////////////////////////////////////////////////////////////////////////
346 // CGLDrawWnd message handlers
347
348 int CGLDrawWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
349 {
350 if (CWnd::OnCreate(lpCreateStruct) == -1)
351 return -1;
352
353 m_pDC = new CClientDC(this);
354 ASSERT(m_pDC != NULL);
355
356 Init();
357
358 if (!ToolBar.CreateEx(GetParent(), TBSTYLE_FLAT | TBSTYLE_TOOLTIPS, WS_CHILD | WS_VISIBLE | CBRS_TOP
359 | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC )
360 ||
361 !ToolBar.LoadToolBar(IDR_TOOLBAR_GL))
362 {
363 ASSERT(FALSE);
364 }
365 ToolBar.SetOwner(this);
366 EnableToolTips(TRUE);
367
368
369 return 0;
370 }
371
ToolBarToolTipsSupport(UINT id,NMHDR * pTTTStruct,LRESULT * pResult)372 BOOL CGLDrawWnd::ToolBarToolTipsSupport( UINT id, NMHDR * pTTTStruct, LRESULT * pResult )
373 {
374 TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pTTTStruct;
375 UINT nID =pTTTStruct->idFrom;
376 if(nID)
377 {
378 pTTT->lpszText = MAKEINTRESOURCE(nID);
379 pTTT->hinst = AfxGetResourceHandle();
380 return(TRUE);
381 }
382 return(FALSE);
383
384 }
385
Init()386 void CGLDrawWnd::Init()
387 {
388 PIXELFORMATDESCRIPTOR pfd;
389 int n;
390
391 if (!SetupPixelFormat())
392 return;
393
394 n = ::GetPixelFormat(m_pDC->GetSafeHdc());
395 ::DescribePixelFormat(m_pDC->GetSafeHdc(), n, sizeof(pfd), &pfd);
396
397 hrc = wglCreateContext(m_pDC->GetSafeHdc());
398 wglMakeCurrent(m_pDC->GetSafeHdc(), hrc);
399
400 CRect r;
401 GetWindowRect(&r);
402 glViewport(0, 0, r.Width(), r.Height());
403 AspectRatio = (GLdouble)r.Width()/r.Height();
404
405 //setup open GL parameters
406 glClearDepth(1.0f);
407 glEnable(GL_DEPTH_TEST);
408 glEnable(GL_NORMALIZE);
409
410 SelectObject(m_pDC->GetSafeHdc(), GetStockObject (SYSTEM_FONT));
411 wglUseFontBitmaps (m_pDC->GetSafeHdc(), 0, 255, 0);
412
413 glMatrixMode(GL_PROJECTION);
414 glLoadIdentity();
415
416 glMatrixMode(GL_MODELVIEW);
417 if(saved_modelview_matrix[0] == NoSavedModelviewMatrix)
418 OnButtonStandardViewXyz();
419 else
420 {
421 glLoadIdentity();
422 glMultMatrixf(saved_modelview_matrix);
423 }
424
425 gltexturecnt = 0;
426 texNames = new unsigned int[MAX_N_TEXTURES];
427 glGenTextures(MAX_N_TEXTURES, texNames);
428
429 FEcolortexNames = new unsigned int[MAX_N_FE_COLOR_TEXTURES];
430 glGenTextures(MAX_N_FE_COLOR_TEXTURES, FEcolortexNames);
431
432 ResetOpenGLParam();
433
434 SetPerspective();
435
436 if(bNoRotationState)
437 OnButtonStandardViewXy();
438
439 GL_SCENE_LIST = glGenLists(1);
440
441 if(pWCDI->GetIOption(221)) //$!DR 2013-12-18 do not compute or draw anything if no hotint window is shown
442 {
443 this->MaxSceneCoord = pWCDI->GetSceneMaxAbsCoordinate(); // (AD) recompute bounding box on init
444 Redraw();
445
446 if(saved_modelview_matrix[0] == NoSavedModelviewMatrix)
447 OnButtonFit();
448 }
449
450 }
451
ContentsChanged(int forcefit)452 void CGLDrawWnd::ContentsChanged(int forcefit) //Redraw and recompute scene size
453 {
454 if(pWCDI->GetIOption(221)) //$!DR 2013-12-18 do not compute or draw anything if no hotint window is shown
455 {
456 float newmax = pWCDI->GetSceneMaxAbsCoordinate();
457
458 if (newmax > 1.1*MaxSceneCoord || newmax < 0.5*MaxSceneCoord || forcefit)
459 {
460 char str[100];
461 //sprintf_s(str, "old max=%g, new max=%g", MaxSceneCoord, newmax);
462 MaxSceneCoord = newmax;
463
464 ButtonFit();
465 //Redraw();
466 }
467 else
468 {
469 Redraw();
470 }
471 }
472 }
473
ResetOpenGLParam()474 void CGLDrawWnd::ResetOpenGLParam()
475 {
476 //+++++++++++++++++
477
478 glEnable(GL_LINE_SMOOTH);
479
480 //OpenGL 2.0 or higher: ??? does not work!, need to tile triangles!
481 //#define GL_PHONG_WIN 0x80EA
482 //#define GL_PHONG_HINT_WIN 0x80EB
483 //#define GL_SHADOW_AMBIENT_SGIX 0x80BF
484
485 if (pWCDI->GetIOption(207))
486 {
487 glShadeModel(GL_SMOOTH);
488 }
489 else
490 glShadeModel(GL_FLAT);
491
492 glDisable (GL_LIGHTING);
493
494 glEnable(GL_COLOR_MATERIAL);
495 glEnable(GL_BLEND);
496 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
497 //++++++++++++++++++++++++++
498
499
500
501 glLineWidth(1.0f);
502 glPointSize(4.0f);
503
504
505 GLfloat lightamb = (float)pWCDI->GetDOption(207);
506 GLfloat lightdiff = (float)pWCDI->GetDOption(208);
507 GLfloat lightspec = (float)pWCDI->GetDOption(209);
508 GLfloat lightamb2 = (float)pWCDI->GetDOption(210);
509 GLfloat lightdiff2 = (float)pWCDI->GetDOption(211);
510 GLfloat lightspec2 = (float)pWCDI->GetDOption(212);
511 GLfloat mat_shininess = (float)pWCDI->GetDOption(219);
512
513 GLfloat mat_spec_col[4]; // = { 1, 1, 1, 1 };
514 mat_spec_col[0] = (float)pWCDI->GetDOption(220);
515 mat_spec_col[1] = (float)pWCDI->GetDOption(220);
516 mat_spec_col[2] = (float)pWCDI->GetDOption(220);
517 mat_spec_col[3] = 1.f;
518
519 GLfloat light_position1[4]; // = { 1, 1, -3, 0 }; //position x,y,z and 0 for directional source or 1 for exact light source
520 light_position1[0] = (float)pWCDI->GetDOption(213);
521 light_position1[1] = (float)pWCDI->GetDOption(214);
522 light_position1[2] = (float)pWCDI->GetDOption(215);
523 light_position1[3] = (float)pWCDI->GetIOption(210);
524
525 GLfloat light_position2[4]; // = { 0, 3, 2, 0 };
526 light_position2[0] = (float)pWCDI->GetDOption(216);
527 light_position2[1] = (float)pWCDI->GetDOption(217);
528 light_position2[2] = (float)pWCDI->GetDOption(218);
529 light_position2[3] = (float)pWCDI->GetIOption(211);
530
531 GLfloat vals[3];
532 vals[0] = vals[1] = vals[2] = lightamb;
533 glLightfv(GL_LIGHT0, GL_AMBIENT, vals);
534 vals[0] = vals[1] = vals[2] = lightdiff;
535 glLightfv(GL_LIGHT0, GL_DIFFUSE, vals);
536 vals[0] = vals[1] = vals[2] = lightspec;
537 glLightfv(GL_LIGHT0, GL_SPECULAR, vals);
538
539 glLightfv(GL_LIGHT0, GL_POSITION, light_position1);
540
541 vals[0] = vals[1] = vals[2] = lightamb2;
542 glLightfv(GL_LIGHT1, GL_AMBIENT, vals);
543 vals[0] = vals[1] = vals[2] = lightdiff2;
544 glLightfv(GL_LIGHT1, GL_DIFFUSE, vals);
545 vals[0] = vals[1] = vals[2] = lightspec2;
546 glLightfv(GL_LIGHT1, GL_SPECULAR, vals);
547
548 glLightfv(GL_LIGHT1, GL_POSITION, light_position2);
549
550
551 glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
552 glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, mat_spec_col);
553 //glMaterialf (GL_FRONT, GL_SHININESS, mat_shininess);
554 //glMaterialfv (GL_FRONT, GL_SPECULAR, mat_spec_col);
555
556 glLightModeli (GL_LIGHT_MODEL_TWO_SIDE, 0);
557 GLint locviewer = 0;
558 glLightModeli (GL_LIGHT_MODEL_LOCAL_VIEWER, locviewer);
559
560 if (pWCDI->GetIOption(208)) glEnable (GL_LIGHT0);
561 else glDisable (GL_LIGHT0);
562 if (pWCDI->GetIOption(209)) glEnable (GL_LIGHT1);
563 else glDisable (GL_LIGHT1);
564
565
566 switch (pWCDI->GetIOption(213))
567 {
568 case 1:
569 glCullFace(GL_FRONT);
570 glEnable(GL_CULL_FACE);
571 break;
572 case 2:
573 glCullFace(GL_BACK);
574 glEnable(GL_CULL_FACE);
575 break;
576 case 3:
577 glCullFace(GL_FRONT_AND_BACK);
578 glEnable(GL_CULL_FACE);
579 break;
580 default:
581 glDisable(GL_CULL_FACE);
582 }
583
584 CreateFEColorTexture(1024, 0, 0); //color (iso/no iso)
585 //CreateFEColorTexture(256, 1, 1); //grey
586
587 }
588
CreateFEColorTexture(int ncols,int texnum,int grey)589 void CGLDrawWnd::CreateFEColorTexture (int ncols, int texnum, int grey)
590 {
591 int i;
592
593 if (ncols < 2) ncols = 2;
594
595 colortexture = new GLubyte[4*ncols+8];
596
597 const double colp[][3] = //color
598 {
599 //{ 1, 0, 0 }, //NETGEN
600 //{ 1, 1, 0 },
601 //{ 0, 1, 0 },
602 //{ 0, 1, 1 },
603 //{ 0, 0, 1 },
604 //{ 1, 0, 1 },
605 //{ 1, 0, 0 },
606 //{ 0.25, 0.25, 0.25 },
607 { 0.1, 0.1, 0.1 },
608 { 0.1, 0.1, 0.9 },
609 { 0.1, 0.9, 0.9 },
610 { 0.1, 0.9, 0.1 },
611 { 0.9, 0.9, 0.1 },
612 { 0.9, 0.1, 0.1 },
613 { 0.9, 0.9, 0.9 },
614 { 0.9, 0.9, 0.9 }
615 };
616
617 const double colpg[][3] = //grey
618 {
619 { 0.1, 0.1, 0.1 },
620 { 0.2, 0.2, 0.2 },
621 { 0.8, 0.8, 0.8 },
622 { 0.8, 0.8, 0.8 },
623 { 0.8, 0.8, 0.95}
624 };
625
626 double niso = pWCDI->GetIOption(103);
627
628 for (i = 0; i < ncols; i++)
629 {
630 double value = ((double)i)/ (ncols-1.);
631
632
633 if (niso != 33 && niso != 0)
634 {
635 value = ((int)((niso)*value+0*0.5)); //for isolines ...
636 int niso2 = (int)niso-1; if (niso2 == 0) niso2 = 1;
637 value = value/niso2+1e-12;
638 }
639
640 if (pWCDI->GetIOption(105))
641 value *= 1.;
642 else
643 value *= 4.;
644
645 int iv = int(value);
646 double r = value - iv;
647
648 iv += 1;
649 if (i == 0) { iv = 0; r=0;}
650 if (i == ncols-1) {iv = 5; r=1;}
651
652
653 GLdouble col[3];
654 int j;
655 for (j = 0; j < 3; j++)
656 {
657 if (!pWCDI->GetIOption(105))
658 col[j] = (1-r) * colp[iv][j] + r * colp[iv+1][j];
659 else
660 col[j] = (1-r) * colpg[iv][j] + r * colpg[iv+1][j];
661 }
662
663 //glColor3d(col[0], col[1], col[2]); //??????
664 //char str[256];
665 //sprintf_s(str, "R=%.3f, G=%.3f, B=%.3f\n", col[0], col[1],col[2]);
666 //pWCDI->GetUserInterface()->AddText(str);
667
668 colortexture[4*i] = GLubyte (255 * col[0]);
669 colortexture[4*i+1] = GLubyte (255 * col[1]);
670 colortexture[4*i+2] = GLubyte (255 * col[2]);
671 colortexture[4*i+3] = GLubyte(255);
672 }
673
674
675 glBindTexture (GL_TEXTURE_1D, FEcolortexNames[texnum]);
676
677 glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP);
678 glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
679 glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
680
681 glTexImage1D (GL_TEXTURE_1D, 0, GL_RGBA, ncols, 0, GL_RGBA, GL_UNSIGNED_BYTE, colortexture);
682 glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
683
684 delete [] colortexture;
685
686
687 //cout << "linear = " << linear << endl;
688 //glBindTexture (GL_TEXTURE_1D, coltexname);
689 //if (linear)
690 //{
691 //glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
692 //glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
693 //}
694 //else
695 //{
696 //glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
697 //glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
698 //}
699 }
700
701
702
SetupPixelFormat()703 BOOL CGLDrawWnd::SetupPixelFormat()
704 {
705 static PIXELFORMATDESCRIPTOR pfd =
706 {
707 sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
708 1, // version number
709 PFD_DRAW_TO_WINDOW | // support window
710 PFD_SUPPORT_OPENGL | // support OpenGL
711 PFD_DOUBLEBUFFER, // double buffered
712 PFD_TYPE_RGBA, // RGBA type
713 24, // 24-bit color depth
714 0, 0, 0, 0, 0, 0, // color bits ignored
715 0, // no alpha buffer
716 0, // shift bit ignored
717 0, // no accumulation buffer
718 0, 0, 0, 0, // accum bits ignored
719 32, // 32-bit z-buffer
720 0, // no stencil buffer
721 0, // no auxiliary buffer
722 PFD_MAIN_PLANE, // main layer
723 0, // reserved
724 0, 0, 0 // layer masks ignored
725 };
726 int pixelformat;
727
728 if ( (pixelformat = ChoosePixelFormat(m_pDC->GetSafeHdc(), &pfd)) == 0 )
729 {
730 MessageBox("ChoosePixelFormat failed");
731 return FALSE;
732 }
733
734 if (SetPixelFormat(m_pDC->GetSafeHdc(), pixelformat, &pfd) == FALSE)
735 {
736 MessageBox("SetPixelFormat failed");
737 return FALSE;
738 }
739
740 return TRUE;
741 }
742
StopOpenGL()743 void CGLDrawWnd::StopOpenGL()
744 {
745 wglMakeCurrent(NULL,NULL);
746 wglDeleteContext(hrc);
747 }
748
749 // the structured text vertical position on the screen
GetStructTextVertPos(int nLineNo)750 float CGLDrawWnd::GetStructTextVertPos(int nLineNo)
751 {
752 float height = (float)(m_pDC->GetTextExtent("a").cy);
753 CRect r;
754 GetWindowRect(&r);
755 return 1-2*height*(nLineNo+1)/r.Height();
756 }
757
758 // the structured text horizontal position on the screen
GetStructTextHorPos(int nXPos,const CString & text)759 float CGLDrawWnd::GetStructTextHorPos(int nXPos,const CString & text)
760 {
761 if(nXPos < 0)
762 return -1.0f; // left side
763 float width = (float)(m_pDC->GetTextExtent(text).cx);
764 CRect r;
765 GetWindowRect(&r);
766 if(nXPos > 0)
767 return 1.0f - 2*width/r.Width(); // right side
768 return -width/r.Width(); // right side
769 }
770
771 // here the texts with fixed positions are displayed inthe OpenGL scene
PrintTextsFixed()772 void CGLDrawWnd::PrintTextsFixed()
773 {
774 if(bFittingTheView)
775 return;
776
777 glMatrixMode(GL_MODELVIEW);
778 glPushMatrix();
779 glLoadIdentity();
780 glMatrixMode(GL_PROJECTION);
781 glPushMatrix();
782 glLoadIdentity();
783 ::glColor3f(ScrTextR, ScrTextG, ScrTextB);
784 glListBase(0);
785 //glTranslated(0.f,0.f,4.f);
786
787 POSITION pos = Texts.GetHeadPosition();
788 while(pos)
789 {
790 const TextPortion & tp = Texts.GetNext(pos);
791 switch(tp.type)
792 {
793 case TextPortion::Text3D:
794 continue;
795 case TextPortion::Text2D:
796 glRasterPos3f(tp.x, tp.y, -1.0f);
797 break;
798 case TextPortion::TextStruct:
799 glRasterPos3f(GetStructTextHorPos(tp.nXPos,tp.text),GetStructTextVertPos(tp.nLineNo),-1.0f);
800 break;
801 default: ASSERT(FALSE);
802 }
803 glCallLists(tp.text.GetLength(), GL_UNSIGNED_BYTE, tp.text);
804 }
805
806 if(bNoRotationState)
807 {
808 static const CString NoRotation = "No rotation";
809 glRasterPos3f(-1.f, -1.f, -1.f);
810 glCallLists(NoRotation.GetLength(), GL_UNSIGNED_BYTE, NoRotation);
811 }
812 if(bRotationTimerRunning)
813 {
814 static const CString AutoRotation = "Automatic rotation";
815 glRasterPos3f(GetStructTextHorPos(0,AutoRotation), -1.0f, 0.0f);
816 glCallLists(AutoRotation.GetLength(), GL_UNSIGNED_BYTE, AutoRotation);
817 }
818 if(DialogFramesRecording.m_bCheckRecordFrames && DialogFramesRecording.m_bShowFrameNumbers)
819 {
820 CString FramesRecording;
821 FramesRecording.Format("frame %d",DialogFramesRecording.m_nFrameCounter);
822 glRasterPos3f(GetStructTextHorPos(1,FramesRecording), -1.0f, 0.0f);
823 glCallLists(FramesRecording.GetLength(), GL_UNSIGNED_BYTE, FramesRecording);
824 }
825
826 glPopMatrix();
827 glMatrixMode(GL_MODELVIEW);
828 glPopMatrix();
829 }
830
OnPaint()831 void CGLDrawWnd::OnPaint()
832 {
833 SetPerspective();
834
835 CPaintDC dc(this); // device context for painting
836
837 glClearColor(BackgroundR, BackgroundG, BackgroundB, 1.0f);
838 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
839
840 // the text should not be affected by the lighting effects
841 glDisable(GL_LIGHTING);
842 PrintTextsFixed();
843
844 DrawScene();
845
846 glFinish();
847 SwapBuffers(wglGetCurrentDC());
848 }
849
850 // the main painting function
DrawScene()851 void CGLDrawWnd::DrawScene()
852 {
853 float m[16];
854
855 glMatrixMode(GL_MODELVIEW);
856 glPushMatrix();
857 glLoadIdentity();
858
859 ResetOpenGLParam();
860 glPopMatrix();
861
862
863 // first we draw the axes
864 glMatrixMode(GL_PROJECTION);
865 glPushMatrix();
866 glLoadIdentity();
867 gluPerspective((GLdouble)10,AspectRatio,6,10);
868 glMatrixMode(GL_MODELVIEW);
869 glPushMatrix();
870 glGetFloatv(GL_MODELVIEW_MATRIX,m);
871 glLoadIdentity();
872 float f1 = (1.27f*(float)AspectRatio-0.25f);
873 float f2 = 0.85f;
874 glTranslated(-0.5f*f1*f2+0.01f,-0.5f*f2-0.02f,-8.f+1.5f);
875 switch(AxesPosition)
876 {
877 case 1: glTranslated(1.f*f1*f2,0,0); break;
878 case 2: glTranslated(1.f*f1*f2,1.0f*f2,0); break;
879 case 3: glTranslated(0,1.0f*f2,0); break;
880 case 4: glTranslated(0.5f*f1*f2,0.5f*f2,0); break;
881 }
882 glMultMatrixf(m);
883 ChooseAxesColor();
884 if(AxesPosition != 5 && !bFittingTheView)
885 {
886 glBegin(GL_LINES);
887 glVertex3f(0,0,0);
888 glVertex3f(0.1f,0,0);
889 glVertex3f(0,0,0);
890 glVertex3f(0,0.1f,0);
891 glVertex3f(0,0,0);
892 glVertex3f(0,0,-0.1f);
893 ::glEnd();
894 // names of the axes
895 ::glColor3f(ScrTextR, ScrTextG, ScrTextB);
896 glListBase(0);
897 glRasterPos3f(0.13f, 0.0f, 0.0f);
898 glCallLists(1, GL_UNSIGNED_BYTE, "x");
899 glRasterPos3f(0.0f, 0.13f, 0.0f);
900 glCallLists(1, GL_UNSIGNED_BYTE, "y");
901 glRasterPos3f(0.0f, 0.0f, -0.13f);
902 glCallLists(1, GL_UNSIGNED_BYTE, "z");
903 }
904 glPopMatrix();
905 glMatrixMode(GL_PROJECTION);
906 glPopMatrix();
907 glMatrixMode(GL_MODELVIEW);
908
909
910 // getting prepared to paint the rest
911 glMatrixMode(GL_MODELVIEW);
912
913
914 glPushMatrix();
915 glGetFloatv(GL_MODELVIEW_MATRIX,m);
916 glLoadIdentity();
917 glTranslated(CenterPoint.x,CenterPoint.y,(-MaxSceneCoord)*(1+SCENE_OFFSET_COEFF));
918 //glTranslated(CenterPoint.x-CenterOffset.x,CenterPoint.y+CenterOffset.y,(-MaxSceneCoord+CenterOffset.z)*(1+SCENE_OFFSET_COEFF));
919
920 glMultMatrixf(m);
921 glTranslated(-CenterOffset.x,-CenterOffset.y,CenterOffset.z);
922
923 if(pWCDI->GetIOption(206))
924 glEnable(GL_LIGHTING);
925
926 glCallList(GL_SCENE_LIST);
927 glDisable(GL_LIGHTING);
928
929 if(pWCDI->GetIOption(157))
930 {
931 if(pWCDI->GetIOption(149)) //activate clipping plane 1
932 {
933 GLdouble eqn[4] = {
934 pWCDI->GetDOption(125), // x-component of normal
935 pWCDI->GetDOption(126), // y-component of normal
936 pWCDI->GetDOption(127), // z-component of normal
937 pWCDI->GetDOption(128) // distance from origin
938 };
939 glClipPlane(GL_CLIP_PLANE0, eqn);
940 glEnable(GL_CLIP_PLANE0);
941 }
942 else
943 {
944 glDisable(GL_CLIP_PLANE0);
945 }
946
947 if(pWCDI->GetIOption(156)) //activate clipping plane 2
948 {
949 GLdouble eqn[4] = {
950 pWCDI->GetDOption(129), // x-component of normal
951 pWCDI->GetDOption(130), // y-component of normal
952 pWCDI->GetDOption(131), // z-component of normal
953 pWCDI->GetDOption(132) // distance from origin
954 };
955 glClipPlane(GL_CLIP_PLANE1, eqn);
956 glEnable(GL_CLIP_PLANE1);
957 }
958 else
959 {
960 glDisable(GL_CLIP_PLANE1);
961 }
962 }
963
964 glPopMatrix();
965
966 // and now the text3D, draw in front of text:
967 glPushMatrix();
968 glGetFloatv(GL_MODELVIEW_MATRIX,m);
969 glLoadIdentity();
970 glTranslated(CenterPoint.x,CenterPoint.y,(-MaxSceneCoord)*(1+SCENE_OFFSET_COEFF));
971
972 if (pWCDI->GetIOption(122)) glTranslated(0.f,0.f,-1.f); //option: bring text to front
973
974 glMultMatrixf(m);
975 glTranslated(-CenterOffset.x,-CenterOffset.y,CenterOffset.z);
976
977 if(!bFittingTheView)
978 {
979 ::glColor3f(ScrTextR, ScrTextG, ScrTextB);
980 glListBase(0);
981 POSITION pos = Texts.GetHeadPosition();
982 while(pos)
983 {
984 const TextPortion & tp = Texts.GetNext(pos);
985 if(tp.type == TextPortion::Text3D)
986 {
987 glRasterPos3f(tp.x, tp.y, tp.z);
988 glCallLists(tp.text.GetLength(), GL_UNSIGNED_BYTE, tp.text);
989 }
990 }
991 }
992
993 glPopMatrix();
994
995 }
996
997 // creating the perspective matrix
SetPerspective()998 void CGLDrawWnd::SetPerspective()
999 {
1000 glMatrixMode(GL_PROJECTION);
1001 glLoadIdentity();
1002 //$!PG 2011-3-15:[
1003 //$ PG 2011-3-15: commented the following line, in order to avoid the scene to be rescaled during load/time iterations
1004 //MaxSceneCoord = pWCDI->GetSceneMaxAbsCoordinate();
1005 //$!PG 2011-3-15:]
1006 gluPerspective((GLdouble)(MAX_FOVY/DetailLevel), AspectRatio,
1007 MaxSceneCoord*SCENE_OFFSET_COEFF, MaxSceneCoord*(2+SCENE_OFFSET_COEFF));
1008 //orig:
1009 //gluPerspective((GLdouble)(MAX_FOVY/DetailLevel), AspectRatio,
1010 // MaxSceneCoord*SCENE_OFFSET_COEFF, MaxSceneCoord*(2+SCENE_OFFSET_COEFF));
1011
1012 glMatrixMode(GL_MODELVIEW);
1013
1014
1015 }
1016
OnRedraw(WPARAM,LPARAM)1017 LRESULT CGLDrawWnd::OnRedraw(WPARAM, LPARAM)
1018 {
1019 Redraw();
1020
1021 // Eat spurious WM_REDRAW messages
1022 MSG msg;
1023 while(::PeekMessage(&msg, m_hWnd, WM_REDRAW, WM_REDRAW, PM_REMOVE));
1024
1025 return 0;
1026 }
1027
1028 extern int vertexcnt;
1029 extern int gltrigcnt;
1030 extern int glquadcnt;
1031 extern int gllinecnt;
1032
1033 // rebuild the scene
Redraw()1034 void CGLDrawWnd::Redraw()
1035 {
1036 if (prohibit_redraw) return;
1037
1038 Texts.RemoveAll();
1039
1040 //gluLookAt(0,0,10,0,0,5,0,1,0);
1041
1042 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
1043
1044 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1045 //texture:
1046 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1047 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1048
1049 gltexturecnt = 0;
1050 texturemode = 1-glstoretextures;
1051 glNewList(GL_SCENE_LIST,GL_COMPILE); //COMPILE, only for textures
1052
1053 pWCDI->RenderScene(this);
1054
1055 glEndList();
1056
1057 /*
1058 if (gltexturecnt > 100 || !glstoretextures)
1059 {
1060 //COMPILE, only for textures
1061 //do not include textures in call-list ...
1062 glCallList(GL_SCENE_LIST);
1063 gltexturecnt = 0;
1064 texturemode = 0;
1065 glNewList(GL_SCENE_LIST,GL_COMPILE); //COMPILE remaining objects
1066 pWCDI->RenderScene(this);
1067 glEndList();
1068 }
1069 */
1070
1071 /*
1072 char str[100];
1073 sprintf_s(str, "vertexcnt=%d", vertexcnt);
1074 PrintText2D(-0.99,-0.05,str);
1075 sprintf_s(str, "linecnt=%d", gllinecnt);
1076 PrintText2D(-0.99,-0.10,str);
1077 sprintf_s(str, "trigcnt=%d", gltrigcnt);
1078 PrintText2D(-0.99,-0.15,str);
1079 sprintf_s(str, "quadcnt=%d", glquadcnt);
1080 PrintText2D(-0.99,-0.20,str);
1081 int textcnt = Texts.GetCount();
1082 sprintf_s(str, "textcnt=%d", textcnt);
1083 PrintText2D(-0.99,-0.25,str);
1084 */
1085
1086 vertexcnt = 0;
1087 gltrigcnt = 0;
1088 glquadcnt = 0;
1089 gllinecnt = 0;
1090
1091 SetPerspective();
1092
1093 RedrawWindow();
1094
1095 PerformVideoFramesRecord();
1096 }
1097
1098 // the size of the window has changed
OnSize(UINT nType,int cx,int cy)1099 void CGLDrawWnd::OnSize(UINT nType, int cx, int cy)
1100 {
1101 CWnd::OnSize(nType, cx, cy);
1102
1103 if(cy > 0)
1104 {
1105 glViewport(0, 0, cx, cy);
1106 AspectRatio = (GLdouble)cx/cy;
1107 Redraw();
1108 }
1109
1110 CRect r;
1111 GetParent()->GetWindowRect(&r);
1112
1113 //ToolBar.MoveWindow(r.Width()-ToolBarButtons*ToolBarButtonSize-5-2,-2,r.Width(),ToolBarButtonSize-2); //!AD: 2012-07-25 in Win7 the last button is clipped by window frame
1114 ToolBar.MoveWindow(r.Width()-ToolBarButtons*ToolBarButtonSize-5-12,-2,r.Width(),ToolBarButtonSize-2); //!AD: 2012-07-25 looks nicer for Win7
1115 }
1116
OnEraseBkgnd(CDC * pDC)1117 BOOL CGLDrawWnd::OnEraseBkgnd(CDC* pDC)
1118 {
1119 return 1; //Prevents flickering
1120
1121 //return CView::OnEraseBkgnd(pDC);
1122 }
1123
OnDestroy()1124 void CGLDrawWnd::OnDestroy()
1125 {
1126 StopOpenGL();
1127 CWnd::OnDestroy();
1128 ToolBar.ShowWindow(SW_HIDE);
1129 if(m_pDC)
1130 delete m_pDC;
1131 }
1132
1133 //1.5 is standard value, smaller for higher distorted perspective!
SetSceneOffsetCoeff(float x)1134 void CGLDrawWnd::SetSceneOffsetCoeff(float x) {SCENE_OFFSET_COEFF = x;}
1135
OnLButtonDblClk(UINT nFlags,CPoint point)1136 void CGLDrawWnd::OnLButtonDblClk(UINT nFlags, CPoint point)
1137 {
1138 // TODO: Add your message handler code here and/or call default
1139
1140 //$ AD 2013-5-10: [ new code to catch an Element object in the GL Window
1141
1142 // define structure of name buffer
1143 GLuint buffer[32];
1144 GLubyte* p;
1145
1146
1147 // switch to selection mode
1148 glRenderMode(GL_SELECT);
1149 glInitNames();
1150 glPushName(0);
1151
1152
1153 //$ AD 2013-5-10: end ]
1154
1155 RedrawWindow();
1156
1157
1158 CWnd::OnLButtonDblClk(nFlags, point);
1159 }
1160
1161 // begin action - BoxZoom
OnLButtonDown(UINT nFlags,CPoint point)1162 void CGLDrawWnd::OnLButtonDown(UINT nFlags, CPoint point)
1163 {
1164 Action = ActionMove; //if no button is pressed
1165 if(!(nFlags & MK_CONTROL) && (nFlags & MK_SHIFT))
1166 Action = ActionSelect;
1167
1168 CurrentPoint = StartingPoint = point;
1169 SetCapture();
1170
1171
1172 CWnd::OnLButtonDown(nFlags, point);
1173 }
1174
1175 // end action -- always zoom
OnLButtonUp(UINT nFlags,CPoint point)1176 void CGLDrawWnd::OnLButtonUp(UINT nFlags, CPoint point)
1177 {
1178 if (!prohibit_redraw && Action == ActionSelect/*(StartingPoint.x != -1000000000)*/) //catch, if file dialog in OnFileOpenMBS is double-clicked!!!
1179 {
1180 ReleaseCapture();
1181
1182 MakeZoom(StartingPoint,point);
1183 // else
1184 //SelectRegion(StartingPoint,point,(nFlags & MK_SHIFT) != 0,(nFlags & MK_CONTROL) != 0);
1185 RedrawWindow();
1186 }
1187 else
1188 {
1189 ReleaseCapture();
1190 }
1191 Action = ActionNone;
1192
1193 CWnd::OnLButtonUp(nFlags, point);
1194 }
1195
1196 // the current action must be processed
OnMouseMove(UINT nFlags,CPoint point)1197 void CGLDrawWnd::OnMouseMove(UINT nFlags, CPoint point)
1198 {
1199 if( (Action == ActionRotate) ||
1200 (Action == ActionZoom) ||
1201 (Action == ActionPerspective) ||
1202 (Action == ActionMove) )
1203 {
1204 float m[16];
1205 glGetFloatv(GL_MODELVIEW_MATRIX,m);
1206 glLoadIdentity();
1207 switch(Action)
1208 {
1209 case ActionMove:
1210 {
1211 CRect r;
1212 GetWindowRect(&r);
1213 float c2 = 290.f/(float)r.Height(); //depends on zoom and perspective!!!
1214 float coeff = TranslationStepCoeff*MaxSceneCoord * (SCENE_OFFSET_COEFF+1.f) *c2/DetailLevel;
1215 CenterPoint.x += (point.x-CurrentPoint.x)*coeff;
1216 CenterPoint.y += -(point.y-CurrentPoint.y)*coeff;
1217 }
1218 break;
1219 case ActionZoom:
1220 {
1221 //DetailLevel *= 1 - (point.y-CurrentPoint.y)*DetailLevelStepCoeff/* *MaxSceneCoord*/;
1222
1223 float fact = (float)(point.y-CurrentPoint.y);
1224 if (fact < 0)
1225 DetailLevel *= 1.f + fabsf(fact)*DetailLevelStepCoeff/* *MaxSceneCoord*/;
1226 else
1227 DetailLevel *= 1.f/(1.f + fabsf(fact)*DetailLevelStepCoeff)/* *MaxSceneCoord*/;
1228
1229 /*
1230 DetailLevel -= 1;
1231 DetailLevel *= 1 - (point.y-CurrentPoint.y)*DetailLevelStepCoeff*MaxSceneCoord;
1232 DetailLevel += 1;*/
1233 DetailLevel = max(DetailLevel,0.9f);
1234 SetPerspective();
1235 //Redraw(); // can be used to remove defects while zooming
1236 // if BeginLinesOnSolid() are used in the scene,
1237 // but leads to flickering
1238 break;
1239 }
1240 case ActionPerspective:
1241 SCENE_OFFSET_COEFF *= 1 - (CurrentPoint.y - point.y)*PerspectiveStepCoeff/* *MaxSceneCoord*/;
1242 SCENE_OFFSET_COEFF = max(SCENE_OFFSET_COEFF,0.001f);
1243 SCENE_OFFSET_COEFF = min(SCENE_OFFSET_COEFF,100.f);
1244 SetPerspective();
1245 break;
1246 case ActionRotate:
1247 glRotatef ( (point.x-CurrentPoint.x)*RotationStep,
1248 0.0f,
1249 1.0f,
1250 0.0f );
1251 glRotatef ( (point.y-CurrentPoint.y)*RotationStep,
1252 1.0f,
1253 0.0f,
1254 0.0f );
1255 break;
1256 }
1257 glMultMatrixf(m);
1258 RedrawWindow();
1259 PerformVideoFramesRecord();
1260 }
1261 if(Action == ActionSelect)
1262 {
1263 CRect r1(StartingPoint,point);
1264 CRect r2(StartingPoint,CurrentPoint);
1265 r1.NormalizeRect();
1266 r2.NormalizeRect();
1267 m_pDC->DrawDragRect(r1,CSize(1,1),r2,CSize(1,1));
1268 }
1269 CurrentPoint = point;
1270
1271
1272 CWnd::OnMouseMove(nFlags, point);
1273 }
1274
OnMouseWheelGLDW(UINT nFlags,short zDelta,CPoint pt)1275 void CGLDrawWnd::OnMouseWheelGLDW(UINT nFlags, short zDelta, CPoint pt)
1276 {
1277 //zDelta: Indicates distance rotated. The zDelta value is expressed in multiples or divisions of WHEEL_DELTA, which is 120.
1278 //A value less than zero indicates rotating back (toward the user) while a value greater than zero indicates rotating forward (away from the user). The user can reverse this response by changing the Wheel setting in the mouse software.
1279 //See the Remarks for more information about this parameter.
1280
1281 //float m[16];
1282 //glGetFloatv(GL_MODELVIEW_MATRIX,m);
1283 //glLoadIdentity();
1284
1285 double fact = (double)zDelta/4.; //one wheel step is equal to moving the mouse 30 pts
1286
1287 if (fact > 0)
1288 DetailLevel *= 1. + fabs(fact)*DetailLevelStepCoeff/* *MaxSceneCoord*/;
1289 else
1290 DetailLevel *= 1./(1. + fabs(fact)*DetailLevelStepCoeff)/* *MaxSceneCoord*/;
1291
1292 DetailLevel = max(DetailLevel,0.9f);
1293 //SetPerspective();
1294 Redraw(); // can be used to remove defects while zooming
1295
1296 //glMultMatrixf(m);
1297 //RedrawWindow();
1298 PerformVideoFramesRecord();
1299 }
1300
1301 // begin action depending on the buttons currently pressed
OnRButtonDown(UINT nFlags,CPoint point)1302 void CGLDrawWnd::OnRButtonDown(UINT nFlags, CPoint point)
1303 {
1304 SetCapture();
1305 CurrentPoint = StartingPoint = point;
1306 Action = ActionRotate;
1307 if( ((nFlags & MK_CONTROL) && !(nFlags & MK_SHIFT)) || bNoRotationState)
1308 Action = ActionMove;
1309 if(!(nFlags & MK_CONTROL) && (nFlags & MK_SHIFT))
1310 Action = ActionZoom;
1311 if((nFlags & MK_CONTROL) && (nFlags & MK_SHIFT))
1312 Action = ActionPerspective;
1313
1314
1315 CWnd::OnRButtonDown(nFlags, point);
1316 }
1317
1318 // end action
OnRButtonUp(UINT nFlags,CPoint point)1319 void CGLDrawWnd::OnRButtonUp(UINT nFlags, CPoint point)
1320 {
1321 ReleaseCapture();
1322 if(Action == ActionZoom)
1323 {
1324 Redraw();
1325 }
1326 /*
1327 else if(Action == ActionRotate)
1328 {
1329 double dist = sqrt((point.x-StartingPoint.x)*(point.x-StartingPoint.x)+(point.y-StartingPoint.y)*(point.y-StartingPoint.y));
1330 if (dist < 1)
1331 {
1332 DetailLevel *= 0.5;
1333 Redraw();
1334 }
1335 }*/
1336 Action = ActionNone;
1337
1338
1339 CWnd::OnRButtonUp(nFlags, point);
1340 }
1341
1342 /*void CGLDrawWnd::SelectRegion(const CPoint & p1, const CPoint & p2, bool bShift, bool bCtrl)
1343 {
1344 GLuint * buf;
1345 bool bSizeEnough;
1346
1347 do
1348 {
1349 bSizeEnough = true;
1350 buf = new GLuint[SelBufSize];
1351 Selection.RemoveAll();
1352
1353 glSelectBuffer( SelBufSize-1, buf );
1354 glRenderMode( GL_SELECT );
1355
1356 GLfloat mproj[16];
1357 glMatrixMode( GL_PROJECTION );
1358 glGetFloatv( GL_PROJECTION_MATRIX, mproj );
1359 glPushMatrix();
1360
1361 GLint vp[4];
1362 glGetIntegerv( GL_VIEWPORT, vp );
1363 glLoadIdentity();
1364
1365 int x = (p1.x+p2.x)/2;
1366 int y = (p1.y+p2.y)/2;
1367 int width = abs(p1.x-p2.x);
1368 int height = abs(p1.y-p2.y);
1369 if(width < 3)
1370 width = 3;
1371 if(height < 3)
1372 height = 3;
1373 gluPickMatrix( x, vp[3]-y, width, height, vp );
1374 glMultMatrixf( mproj );
1375 glMatrixMode( GL_MODELVIEW );
1376
1377 float m[16];
1378 glPushMatrix();
1379 glGetFloatv(GL_MODELVIEW_MATRIX,m);
1380 glLoadIdentity();
1381 glTranslated(CenterPoint.x,CenterPoint.y,-m_fViewDepth);
1382 glMultMatrixf(m);
1383 glCallList(GL_LIST);
1384 glFinish();
1385 glPopMatrix();
1386
1387 glMatrixMode( GL_PROJECTION );
1388 glPopMatrix();
1389 glMatrixMode( GL_MODELVIEW );
1390 GLint nRecords = glRenderMode( GL_RENDER );
1391
1392 if(nRecords == -1) // �� ������� ������
1393 {
1394 bSizeEnough = false;
1395 delete[] buf;
1396 SelBufSize = (3*SelBufSize)/2;
1397 }
1398 else
1399 {
1400 int i=0, pos = 0;
1401 for( i=0; i < nRecords; i++ )
1402 {
1403 for(unsigned int k = pos+3; k < pos+3+buf[pos]; k++)
1404 Selection.AddTail(buf[k]);
1405 pos += 3+buf[pos];
1406 }
1407 }
1408 } while(!bSizeEnough);
1409
1410 pGLDFB->Select(Selection,bShift,bCtrl);
1411
1412 delete[] buf;
1413 }*/
1414
1415
1416 // handling the toolbar buttons
1417
OnButtonNoRotation()1418 void CGLDrawWnd::OnButtonNoRotation()
1419 {
1420 bNoRotationState = !bNoRotationState;
1421 RedrawWindow();
1422 }
1423
OnButtonStandardViewXy()1424 void CGLDrawWnd::OnButtonStandardViewXy()
1425 {
1426 OnButtonStandardViewXz();
1427 glRotated(-90,1,0,0);
1428 RedrawWindow();
1429 }
1430
OnButtonStandardViewXyz()1431 void CGLDrawWnd::OnButtonStandardViewXyz()
1432 {
1433 OnButtonStandardViewYz();
1434 glRotated(-90,0,0,1);
1435 glRotated(-90,1,0,0);
1436 glRotated(180,0,1,0);
1437
1438 double rot[4];
1439 rot[1] = 0;
1440 rot[2] = 0;
1441 rot[3] = 0;
1442 rot[pWCDI->GetIOption(200)] = 1;
1443 glRotated(pWCDI->GetDOption(200),rot[1],rot[2],rot[3]);
1444 rot[pWCDI->GetIOption(200)] = 0;
1445 rot[pWCDI->GetIOption(201)] = 1;
1446 glRotated(pWCDI->GetDOption(201),rot[1],rot[2],rot[3]);
1447 rot[pWCDI->GetIOption(201)] = 0;
1448 rot[pWCDI->GetIOption(202)] = 1;
1449 glRotated(pWCDI->GetDOption(202),rot[1],rot[2],rot[3]);
1450 rot[pWCDI->GetIOption(202)] = 0;
1451
1452 RedrawWindow();
1453 }
1454
OnButtonStandardViewXz()1455 void CGLDrawWnd::OnButtonStandardViewXz()
1456 {
1457 OnButtonStandardViewYz();
1458 glRotated(90,0,0,1);
1459 RedrawWindow();
1460 }
1461
OnButtonStandardViewYz()1462 void CGLDrawWnd::OnButtonStandardViewYz()
1463 {
1464 glMatrixMode(GL_MODELVIEW);
1465 glLoadIdentity();
1466 float m[16];
1467 glGetFloatv(GL_MODELVIEW_MATRIX,m);
1468 m[0] = -1;
1469 glMultMatrixf(m);
1470 glRotated(90,1,0,0);
1471 glRotated(90,0,0,1);
1472 RedrawWindow();
1473 }
1474
SetAnimateScalingTimer(int flag)1475 void CGLDrawWnd::SetAnimateScalingTimer(int flag)
1476 {
1477 old_scaling_factor = pWCDI->GetDOption(105);
1478 if(flag)
1479 {
1480 old_scaling_factor = pWCDI->GetDOption(105);
1481 virtual_animate_time = 0;
1482 SetTimer(SCALING_ANIMATE_TIMER_ID,ROTATION_TIMER_DELAY,NULL);
1483 }
1484 else
1485 {
1486 KillTimer(SCALING_ANIMATE_TIMER_ID);
1487 RedrawWindow();
1488 pWCDI->GetDOption(105) = old_scaling_factor;
1489 }
1490 }
1491
1492
OnButtonStandardViewRotate()1493 void CGLDrawWnd::OnButtonStandardViewRotate()
1494 {
1495 bNoRotationState = false;
1496 if(!bRotationTimerRunning)
1497 {
1498 bRotationTimerRunning = true;
1499 SetTimer(ROTATION_TIMER_ID,ROTATION_TIMER_DELAY,NULL);
1500 }
1501 else
1502 {
1503 bRotationTimerRunning = false;
1504 KillTimer(ROTATION_TIMER_ID);
1505 RedrawWindow();
1506 }
1507 }
1508
MakeZoom(const CPoint & p1,const CPoint & p2)1509 void CGLDrawWnd::MakeZoom(const CPoint & p1, const CPoint & p2)
1510 {
1511 int MidX = (p1.x+p2.x)/2;
1512 int MidY = (p1.y+p2.y)/2;
1513 CRect r;
1514 GetWindowRect(r);
1515 CPoint CentPoint = r.CenterPoint();
1516 ScreenToClient(&CentPoint);
1517 int dx = CentPoint.x - MidX;
1518 int dy = CentPoint.y - MidY;
1519
1520 //char str[256];
1521 //sprintf_s(str, "centerx=%d, centery=%d, px=%d, py=%d\n", CentPoint.x, CentPoint.y, MidX, MidY);
1522 //pWCDI->GetUserInterface()->AddText(str);
1523
1524
1525 //old: float coeff = MaxSceneCoord/DetailLevel;
1526 float c2 = 0.01f*290.f/(float)r.Height(); //depends on zoom and perspective!!!
1527 float coeff = MaxSceneCoord * (SCENE_OFFSET_COEFF+1.f) *c2/DetailLevel;
1528
1529 // the following coefficients adjust the accuracy of zooming
1530 CenterPoint.x += dx*coeff; //old: /r.Width()*7.8f
1531 CenterPoint.y += -dy*coeff; //old: /r.Height()*6.5f
1532 int width = abs(p1.x-p2.x);
1533 int height = abs(p1.y-p2.y);
1534 float Magnification;
1535 if(width < 5 || height < 5)
1536 Magnification = 2;
1537 else
1538 Magnification = min(((float)r.Width())/width,((float)r.Height())/height);
1539 if (Magnification > 100) Magnification = 100;
1540 DetailLevel *= Magnification;
1541
1542 Redraw();
1543 }
1544
1545
OnButtonFit()1546 void CGLDrawWnd::OnButtonFit()
1547 {
1548 MaxSceneCoord = pWCDI->GetSceneMaxAbsCoordinate();
1549
1550 ButtonFit();
1551 }
1552
ButtonFit()1553 void CGLDrawWnd::ButtonFit()
1554 {
1555 //pWCDI->GetUserInterface()->AddText("button fit\n");
1556
1557 // the scene needs to fit the screen
1558 CenterPoint.x = CenterPoint.y = 0;
1559 DetailLevel = 20.*1.5f;//1.5f;
1560 SCENE_OFFSET_COEFF = 10.f; //1.5
1561
1562 SetPerspective();
1563 //RedrawWindow();
1564
1565 // now we paint the scene virtually and find the bounds
1566 // First we fill the FeedBackBuffer in
1567 GLfloat *buf;
1568 int size = 3000;
1569 GLint nValues;
1570 bFittingTheView = true;
1571 do
1572 {
1573 buf = new GLfloat[ size ];
1574 glFeedbackBuffer( size, GL_3D_COLOR, buf );
1575 glRenderMode( GL_FEEDBACK );
1576 DrawScene();
1577 nValues = glRenderMode( GL_RENDER );
1578 if( nValues < 0 )
1579 {
1580 delete [] buf;
1581 size *= 2;
1582 }
1583 } while( size <= MAX_SIZE && nValues < 0 );
1584 bFittingTheView = false;
1585 if( nValues < 0 )
1586 {
1587 AfxMessageBox( "The scene is too complicated for screen fit!", MB_ICONSTOP );
1588 return;
1589 }
1590 // And now we are finding the borders of the scene
1591 // For simplicity we take into account only the points
1592 int i=0;
1593 int dim = 3 + 4;
1594 bool bPointConsidered = false;
1595 CRect r;
1596 GetWindowRect(r);
1597 int WindowHeight = r.Height();
1598 while( i < nValues ) switch( ( GLuint )buf[i] )
1599 {
1600 case GL_POINT_TOKEN:
1601 {
1602 i++;
1603 int x = (int)buf[i], y = WindowHeight - (int)buf[i+1];
1604 if(bPointConsidered)
1605 {
1606 r.left = min(r.left,x);
1607 r.right = max(r.right,x);
1608 r.top = max(r.top,y);
1609 r.bottom = min(r.bottom,y);
1610 }
1611 else
1612 {
1613 r.SetRect(x-2,y+2,x+2,y-2);
1614 bPointConsidered = true;
1615 }
1616 i += dim;
1617 break;
1618 }
1619 case GL_LINE_TOKEN:
1620 case GL_LINE_RESET_TOKEN:
1621 {
1622 i++;
1623 int x = (int)buf[i], y = WindowHeight - (int)buf[i+1];
1624 if(bPointConsidered)
1625 {
1626 r.left = min(r.left,x);
1627 r.right = max(r.right,x);
1628 r.top = max(r.top,y);
1629 r.bottom = min(r.bottom,y);
1630 }
1631 else
1632 {
1633 r.SetRect(x-2,y+2,x+2,y-2);
1634 bPointConsidered = true;
1635 }
1636 i += 2*dim;
1637 break;
1638 }
1639 case GL_BITMAP_TOKEN: break;
1640 ASSERT( FALSE );
1641 case GL_DRAW_PIXEL_TOKEN:
1642 ASSERT( FALSE );
1643 case GL_COPY_PIXEL_TOKEN:
1644 ASSERT( FALSE );
1645 case GL_PASS_THROUGH_TOKEN:
1646 ASSERT( FALSE );
1647 case GL_POLYGON_TOKEN:
1648 {
1649 int nVertices = ( int )buf[ ++i ];
1650 i++;
1651 int x = (int)buf[i], y = WindowHeight - (int)buf[i+1];
1652 if(bPointConsidered)
1653 {
1654 r.left = min(r.left,x);
1655 r.right = max(r.right,x);
1656 r.top = max(r.top,y);
1657 r.bottom = min(r.bottom,y);
1658 }
1659 else
1660 {
1661 r.SetRect(x-2,y+2,x+2,y-2);
1662 bPointConsidered = true;
1663 }
1664 i += nVertices * dim;
1665 break;
1666 }
1667 default:
1668 ASSERT( FALSE );
1669 }
1670 delete [] buf;
1671
1672 r.NormalizeRect();
1673 r.InflateRect(10,10,10,10); //originally: r.InflateRect(50,50,50,50);
1674 // And finally we make a BoxZoom for the determined screen coordinates
1675
1676 //char str[256];
1677 //sprintf_s(str, "MakeZoom: left=%d, top=%d, right=%d, bottom=%d\n", r.left, r.top, r.right, r.bottom);
1678 //pWCDI->GetUserInterface()->AddText(str); MaxSceneCoord = 1;
1679
1680 MakeZoom(r.TopLeft(),r.BottomRight());
1681 // DEBUG
1682 /*CClientDC dc(this);
1683 dc.LineTo(r.left,r.top);
1684 dc.LineTo(r.left,r.bottom);
1685 dc.LineTo(r.right,r.bottom);
1686 dc.LineTo(r.right,r.top);
1687 dc.LineTo(r.left,r.top);*/
1688 }
1689
OnButtonMoveAxes()1690 void CGLDrawWnd::OnButtonMoveAxes()
1691 {
1692 AxesPosition = (AxesPosition + 1) % 6;
1693 RedrawWindow();
1694 }
1695
1696
PrintText2D(float x,float y,const char * text)1697 void CGLDrawWnd::PrintText2D(float x, float y, const char * text)
1698 {
1699 PrintText3D(x,y,0,text);
1700 Texts.GetTail().type = TextPortion::Text2D;
1701 }
1702
1703
PrintText3D(float x,float y,float z,const char * text)1704 void CGLDrawWnd::PrintText3D(float x, float y, float z, const char * text)
1705 {
1706 TextPortion tp;
1707 tp.text = text;
1708 tp.x = x;
1709 tp.y = y;
1710 tp.z = -z;
1711 tp.type = TextPortion::Text3D;
1712 Texts.AddTail(tp);
1713 }
1714
PrintTextStruct(int nLineNo,int nXPos,const char * text)1715 void CGLDrawWnd::PrintTextStruct(int nLineNo, int nXPos, const char * text)
1716 {
1717 TextPortion tp;
1718 tp.text = text;
1719 tp.nLineNo = nLineNo;
1720 tp.nXPos = nXPos;
1721 tp.type = TextPortion::TextStruct;
1722 Texts.AddTail(tp);
1723 }
1724
1725
1726 // the scene may be rotating automatically with the timer, or a funny image may be animated
1727
OnTimer(UINT_PTR nIDEvent)1728 void CGLDrawWnd::OnTimer(UINT_PTR nIDEvent)
1729 {
1730 if(nIDEvent == ROTATION_TIMER_ID)
1731 {
1732 float m[16];
1733 glMatrixMode(GL_MODELVIEW);
1734 glGetFloatv(GL_MODELVIEW_MATRIX,m);
1735 glLoadIdentity();
1736 glRotated(0.7,0,1,0.1);
1737 glMultMatrixf(m);
1738 RedrawWindow();
1739 PerformVideoFramesRecord();
1740 }
1741 if(nIDEvent == SCALING_ANIMATE_TIMER_ID)
1742 {
1743 double t = virtual_animate_time;
1744 virtual_animate_time += 0.02;
1745 pWCDI->GetDOption(105) = old_scaling_factor * cos(2.*3.1415926535897932*t);
1746
1747 //check if animation cycle is only once:
1748 if (pWCDI->GetIOption(153) && virtual_animate_time > 1.)
1749 {
1750 KillTimer(SCALING_ANIMATE_TIMER_ID);
1751
1752 }
1753 else
1754 {
1755 Redraw();
1756 PerformVideoFramesRecord();
1757 }
1758 }
1759 CWnd::OnTimer(nIDEvent);
1760 }
1761
OnButtonSaveImage()1762 void CGLDrawWnd::OnButtonSaveImage()
1763 {
1764 // save a single image (screenshot)
1765 mystr path = pWCDI->GetTOption(120);
1766 mystr file = pWCDI->GetTOption(121);
1767 CString FileName_noext = CString(path) + "\\" + file;
1768
1769 int radio_format = pWCDI->GetIOption(167);
1770 switch(radio_format)
1771 {
1772 case 0: SaveWindowBitmap(this, FileName_noext + ".jpg", Gdiplus::ImageFormatJPEG); break;
1773 case 1: SaveWindowBitmap(this, FileName_noext + ".png", Gdiplus::ImageFormatPNG); break;
1774 case 2: SaveWindowBitmap(this, FileName_noext + ".bmp", Gdiplus::ImageFormatBMP); break;
1775 default: SaveWindowBitmap(this, FileName_noext + ".jpg", Gdiplus::ImageFormatJPEG); break;
1776 }
1777 }
1778
OnButtonFramesRecording()1779 void CGLDrawWnd::OnButtonFramesRecording()
1780 {
1781 CRect r;
1782 GetWindowRect(&r);
1783 DialogFramesRecording.SetWindowDimensions(r);
1784 BOOL bOldStatusRecordFrames = DialogFramesRecording.m_bCheckRecordFrames;
1785 BOOL bOldStatusShowFrameNumber = DialogFramesRecording.m_bShowFrameNumbers;
1786 DialogFramesRecording.DoModal();
1787 if( bOldStatusRecordFrames != DialogFramesRecording.m_bCheckRecordFrames ||
1788 bOldStatusShowFrameNumber != DialogFramesRecording.m_bShowFrameNumbers)
1789 RedrawWindow();
1790 }
1791
1792 // here the logics is implemented to work with the automatically saved frames of the animation
PerformVideoFramesRecord()1793 void CGLDrawWnd::PerformVideoFramesRecord()
1794 {
1795 if(!DialogFramesRecording.m_bCheckRecordFrames)
1796 return;
1797
1798 static int counter = 0;
1799 if(++counter < DialogFramesRecording.m_nRecordEachFrameOf)
1800 return;
1801
1802 //!AD: 2013-02-08 fix: prevent repeated saving of the same frame
1803 static double lastdrawtime = 0.;
1804 double drawtime = pWCDI->GetActualDrawTime();
1805 if (abs(drawtime-lastdrawtime) < abs(drawtime/1e8) )
1806 {
1807 return; // no more repeated draw of the same time point but allow for decreasing time value...
1808 }
1809 lastdrawtime = drawtime;
1810
1811 counter = 0;
1812
1813 CString FrameNumber;
1814 FrameNumber.Format("%d",DialogFramesRecording.m_nFrameCounter);
1815 DialogFramesRecording.m_nFrameCounter++;
1816 while(FrameNumber.GetLength() < FrameNumberDigits)
1817 FrameNumber = CString('0') + FrameNumber;
1818
1819 // save a single image (screenshot)
1820 mystr path = pWCDI->GetTOption(122);
1821 mystr file = pWCDI->GetTOption(123);
1822 CString FileName_noext = CString(path) + "\\" + file + FrameNumber;
1823
1824 int radio_format = pWCDI->GetIOption(167);
1825 switch(radio_format)
1826 {
1827 case 0: SaveWindowBitmap(this, FileName_noext + ".jpg", Gdiplus::ImageFormatJPEG); break;
1828 case 1: SaveWindowBitmap(this, FileName_noext + ".png", Gdiplus::ImageFormatPNG); break;
1829 case 2: SaveWindowBitmap(this, FileName_noext + ".bmp", Gdiplus::ImageFormatBMP); break;
1830 default: SaveWindowBitmap(this, FileName_noext + ".jpg", Gdiplus::ImageFormatJPEG); break;
1831 }
1832
1833 return;
1834
1835 //AD 2012-11-09: new routine ends here...
1836 // ONLY OLD CODE BELOW
1837 // FileName.Format("%d",DialogFramesRecording.m_nFrameCounter++);
1838 // while(FileName.GetLength() < FrameNumberDigits)
1839 // FileName = CString('0') + FileName;
1840 // FileName = DialogFramesRecording.m_strPathToImageFiles + "image" + FileName;
1841 //
1842 // if(!SaveWindowBitmap(this,FileName + ".bmp",Gdiplus::ImageFormatJPEG))
1843 // {
1844 // AfxMessageBox("Errors happened while saving the image.\nMake sure the path for the image files exists.",
1845 // MB_OK | MB_ICONSTOP);
1846 // DialogFramesRecording.m_bCheckRecordFrames = FALSE;
1847 // RedrawWindow();
1848 // }
1849 // else
1850 // if(DialogFramesRecording.m_bProcessImage)
1851 // {
1852 // SetProgramDirectoryAsCurrent();
1853 //
1854 // const char* str_bat = "process_image.bat";
1855 // const char* str_txt = "process_image.txt";
1856 //
1857 //#ifdef my_new_stdiostream
1858 // int opt = ios::in;
1859 // ifstream* ifs = new ifstream(str_bat, opt);
1860 // int isgood = ifs->good() && !ifs->fail();
1861 // ifs->close();
1862 // delete ifs;
1863 //
1864 // ifstream* ifs2 = new ifstream(str_txt, opt);
1865 // int isgood2 = ifs2->good() && !ifs2->fail();
1866 // ifs2->close();
1867 // delete ifs2;
1868 //#else
1869 // int opt = ios::in|ios::nocreate;
1870 // ifstream* ifs = new ifstream(str_bat, opt, filebuf::sh_read);
1871 // int isgood = ifs->good() && !ifs->fail();
1872 // ifs->close();
1873 // delete ifs;
1874 //
1875 // ifstream* ifs2 = new ifstream(str_txt, opt, filebuf::sh_read);
1876 // int isgood2 = ifs2->good() && !ifs2->fail();
1877 // ifs2->close();
1878 // delete ifs2;
1879 //#endif
1880 //
1881 //
1882 // if (!isgood)
1883 // {
1884 // if (isgood2)
1885 // {
1886 // //copy file!
1887 // const int buflen = 4096;
1888 // char buf[buflen+1];
1889 // char ch;
1890 //
1891 //#ifdef my_new_stdiostream
1892 // ifstream* ifile = new ifstream(str_txt, opt);
1893 //#else
1894 // ifstream* ifile = new ifstream(str_txt, opt, filebuf::sh_read);
1895 //#endif
1896 //
1897 // int i=0;
1898 // while (!ifile->eof() && i < buflen)
1899 // {
1900 // ifile->get(ch);
1901 // if (!ifile->eof() && ch != (char)EOF)
1902 // {
1903 // buf[i] = ch;
1904 // i++;
1905 // }
1906 // }
1907 // buf[i] = (char)0;
1908 //
1909 // ifile->close();
1910 // delete ifile;
1911 //
1912 // if (i == buflen)
1913 // {
1914 // AfxMessageBox("The file for processing images 'process_image.txt'\nis too long (> 4096 kb)!\nThe file has been recreated!");
1915 // isgood2=0;
1916 // }
1917 // else
1918 // {
1919 // ofstream ofs(str_bat);
1920 // ofs << buf;
1921 // }
1922 // }
1923 // if (!isgood2)
1924 // {
1925 // //file does not exist --> generate new file!
1926 // int opt = ios::out;
1927 // ofstream* ofs = new ofstream();
1928 //#ifdef my_new_stdiostream
1929 // ofs->open(str_bat, opt);
1930 //#else
1931 // ofs->open(str_bat, opt, filebuf::sh_read);
1932 //#endif
1933 // (*ofs) << "@echo off\ndel %1.jpg\nC:\\Programme\\ImageMagick\\convert -quality 100 %1.bmp %1.jpg\ndel %1.bmp\n";
1934 // ofs->close();
1935 // delete ofs;
1936 // }
1937 // }
1938 //
1939 //
1940 // ShellExecute(
1941 // NULL,
1942 // "open",
1943 // str_bat,
1944 // FileName,
1945 // ".",
1946 // SW_HIDE
1947 // // SW_SHOWMINIMIZED
1948 // );
1949 // }
1950 }
1951
Configuration2EDC(ElementDataContainer & edc)1952 void CGLDrawWnd::Configuration2EDC(ElementDataContainer& edc)
1953 {
1954 const int model_view_mat_len = 16;
1955 float m[model_view_mat_len];
1956 double v[model_view_mat_len];
1957 glGetFloatv(GL_MODELVIEW_MATRIX,m);
1958 for(int i = 0; i < model_view_mat_len; i++)
1959 {
1960 v[i] = (double)m[i];
1961 }
1962
1963 edc.TreeSetVectorC("HOTINTConfiguration.OpenGL.model_view_matrix",v,model_view_mat_len,"OpenGL model view matrix");
1964
1965 edc.TreeSetDoubleC("HOTINTConfiguration.3DView.Center_point.xpos",(double)CenterPoint.x,"Centerpoint x-position");
1966 edc.TreeSetDoubleC("HOTINTConfiguration.3DView.Center_point.ypos",(double)CenterPoint.y,"Centerpoint y-position");
1967
1968 edc.TreeSetDoubleC("HOTINTConfiguration.3DView.Center_offset.xpos",(double)CenterOffset.x,"Centeroffset x-position");
1969 edc.TreeSetDoubleC("HOTINTConfiguration.3DView.Center_offset.ypos",(double)CenterOffset.y,"Centeroffset y-position");
1970 edc.TreeSetDoubleC("HOTINTConfiguration.3DView.Center_offset.zpos",(double)CenterOffset.z,"Centeroffset z-position");
1971
1972 edc.TreeSetIntC("HOTINTConfiguration.axes_position",AxesPosition,"position of axes: left, bottom, right, top, no axes");
1973 edc.TreeSetIntC("HOTINTConfiguration.lock_rotation",bNoRotationState,"lock rotation of model (for 2D models)");
1974
1975 edc.TreeSetDoubleC("HOTINTConfiguration.3DView.scene_offset",(double)SCENE_OFFSET_COEFF,"Scene offset");
1976
1977 edc.TreeSetDoubleC("HOTINTConfiguration.3DView.zoom_factor",(double)DetailLevel,"zoom factor of 3D view");
1978
1979 edc.TreeSetDoubleC("HOTINTConfiguration.3DView.zoom_factor_mouse_inc",(double)DetailLevelStepCoeff,"increment of zoom factor per mousemove of 3D view on mousemove");
1980 edc.TreeSetDoubleC("HOTINTConfiguration.3DView.translation_mouse_inc",(double)TranslationStepCoeff,"increment of translation per mousemove of 3D view on mousemove");
1981 edc.TreeSetDoubleC("HOTINTConfiguration.3DView.rotation_mouse_inc",(double)RotationStep,"increment of rotation per mousemove of 3D view on mousemove");
1982 edc.TreeSetDoubleC("HOTINTConfiguration.3DView.perspective_mouse_inc",(double)PerspectiveStepCoeff,"increment of perspective per mousemove of 3D view on mousemove");
1983
1984 edc.TreeSetDoubleC("HOTINTConfiguration.3DView.aspect_ratio",(double)AspectRatio,"current aspect ratio in OpenGL view");
1985 edc.TreeSetDoubleC("HOTINTConfiguration.3DView.maximum_scene_coordinates",(double)MaxSceneCoord,"stored maximum scene coordinates in OpenGL view");
1986
1987 //saved_modelview_matrix[0] = NoSavedModelviewMatrix;
1988 saved_modelview_matrix[0] = NoSavedModelviewMatrix; //for loading, restore
1989
1990 DialogFramesRecording.Configuration2EDC(edc);
1991 }
1992
EDC2Configuration(const ElementDataContainer & edc)1993 void CGLDrawWnd::EDC2Configuration(const ElementDataContainer& edc)
1994 {
1995 const int model_view_mat_len = 16;
1996
1997 double* vptr;
1998 int len;
1999 edc.TreeGetVector("HOTINTConfiguration.OpenGL.model_view_matrix",&vptr,len);
2000 if (len != model_view_mat_len)
2001 {
2002 AfxMessageBox("Warning: HOTINTConfiguration.OpenGL.model_view_matrix must have length 16! Loaded matrix is ignored!");
2003 }
2004 else
2005 {
2006 for(int i = 0; i < model_view_mat_len; i++)
2007 {
2008 saved_modelview_matrix[i] = (float)(vptr[i]);
2009 }
2010 }
2011
2012 CenterPoint.x = (float)edc.TreeGetDouble("HOTINTConfiguration.3DView.Center_point.xpos");
2013 CenterPoint.y = (float)edc.TreeGetDouble("HOTINTConfiguration.3DView.Center_point.ypos");
2014
2015 CenterOffset.x = (float)edc.TreeGetDouble("HOTINTConfiguration.3DView.Center_offset.xpos");
2016 CenterOffset.y = (float)edc.TreeGetDouble("HOTINTConfiguration.3DView.Center_offset.ypos");
2017 CenterOffset.z = (float)edc.TreeGetDouble("HOTINTConfiguration.3DView.Center_offset.zpos");
2018
2019 AxesPosition = edc.TreeGetInt("HOTINTConfiguration.axes_position");
2020 bNoRotationState = (bool)edc.TreeGetInt("HOTINTConfiguration.lock_rotation");
2021
2022 SCENE_OFFSET_COEFF = (float)edc.TreeGetDouble("HOTINTConfiguration.3DView.scene_offset");
2023 DetailLevel = (float)edc.TreeGetDouble("HOTINTConfiguration.3DView.zoom_factor");
2024
2025 DetailLevelStepCoeff = (float)edc.TreeGetDouble("HOTINTConfiguration.3DView.zoom_factor_mouse_inc");
2026 TranslationStepCoeff = (float)edc.TreeGetDouble("HOTINTConfiguration.3DView.translation_mouse_inc");
2027 RotationStep = (float)edc.TreeGetDouble("HOTINTConfiguration.3DView.rotation_mouse_inc");
2028 PerspectiveStepCoeff = (float)edc.TreeGetDouble("HOTINTConfiguration.3DView.perspective_mouse_inc");
2029
2030 AspectRatio = (float)edc.TreeGetDouble("HOTINTConfiguration.3DView.aspect_ratio");
2031 MaxSceneCoord = (float)edc.TreeGetDouble("HOTINTConfiguration.3DView.maximum_scene_coordinates");
2032
2033 DialogFramesRecording.EDC2Configuration(edc);
2034
2035 }
2036
2037 //will be erased:
SaveConfig(CArchive & ar)2038 void CGLDrawWnd::SaveConfig(CArchive & ar)
2039 {
2040 float m[16];
2041 glGetFloatv(GL_MODELVIEW_MATRIX,m);
2042 for(int i = 0; i < 16; i++)
2043 ar << m[i];
2044
2045 ar << CenterPoint.x << CenterPoint.y << DetailLevel;// << bLighting; //lighting moved to ioption124
2046 ar << SCENE_OFFSET_COEFF;
2047 ar << AxesPosition;
2048 ar << bNoRotationState;
2049
2050 ar << DetailLevel;
2051 ar << TranslationStepCoeff;
2052 ar << RotationStep;
2053 ar << DetailLevelStepCoeff;
2054 ar << PerspectiveStepCoeff;
2055 ar << AspectRatio;
2056 ar << CenterOffset.x;
2057 ar << CenterOffset.y;
2058 ar << CenterOffset.z;
2059 ar << MaxSceneCoord;
2060
2061 saved_modelview_matrix[0] = NoSavedModelviewMatrix;
2062
2063 DialogFramesRecording.Serialize(ar);
2064 }
2065
2066 //will be erased:
LoadConfig(CArchive & ar)2067 void CGLDrawWnd::LoadConfig(CArchive & ar)
2068 {
2069 for(int i = 0; i < 16; i++)
2070 ar >> saved_modelview_matrix[i];
2071
2072 ar >> CenterPoint.x >> CenterPoint.y >> DetailLevel;// >> bLighting;
2073
2074 ar >> SCENE_OFFSET_COEFF;
2075 ar >> AxesPosition;
2076 ar >> bNoRotationState;
2077
2078 ar >> DetailLevel;
2079 ar >> TranslationStepCoeff;
2080 ar >> RotationStep;
2081 ar >> DetailLevelStepCoeff;
2082 ar >> PerspectiveStepCoeff;
2083 ar >> AspectRatio;
2084 ar >> CenterOffset.x;
2085 ar >> CenterOffset.y;
2086 ar >> CenterOffset.z;
2087 ar >> MaxSceneCoord;
2088
2089
2090 DialogFramesRecording.Serialize(ar);
2091 }
2092
ChooseAxesColor()2093 void CGLDrawWnd::ChooseAxesColor()
2094 {
2095 if( (BackgroundR + BackgroundG + BackgroundB) / 3 < 0.5f )
2096 ::glColor3f(0.9f, 0.9f, 0.9f);
2097 else
2098 ::glColor3f(0.1f, 0.1f, 0.1f);
2099 }
2100
2101
BeginLinesOnSolid()2102 void CGLDrawWnd::BeginLinesOnSolid()
2103 {
2104 glMatrixMode( GL_PROJECTION );
2105 glPushMatrix();
2106 glLoadIdentity();
2107 float fact = 1.0001;
2108 gluPerspective((GLdouble)(MAX_FOVY/DetailLevel), AspectRatio,
2109 MaxSceneCoord*SCENE_OFFSET_COEFF, MaxSceneCoord*(fact*2.+SCENE_OFFSET_COEFF));
2110 //gluPerspective((GLdouble)(MAX_FOVY/DetailLevel), AspectRatio,
2111 // MaxSceneCoord*SCENE_OFFSET_COEFF, MaxSceneCoord*(2.0001+SCENE_OFFSET_COEFF));
2112 glMatrixMode(GL_MODELVIEW);
2113
2114 glDepthMask( FALSE );
2115 }
2116
EndLinesOnSolid()2117 void CGLDrawWnd::EndLinesOnSolid()
2118 {
2119 glMatrixMode( GL_PROJECTION );
2120 glPopMatrix();
2121 glMatrixMode( GL_MODELVIEW );
2122 glDepthMask( TRUE );
2123 }
2124
2125
2126
2127