Waitrud Weber’s blog

things and reminders for memories

3d: : Print Symbols : Screen doesn't work half.

x1 and z2 shares p1.

the above is the reason why x1 was not displayed.

in windows programming,

1. Use malloc.

2 Keep the memories of 1.

 

f:id:Waitrud_Weber:20190521175947j:plain

390 ://
391 :// lines            :
392 :// lines_2D         :
393 :// lines_patches_2D :
394 :// lines_patches    :
395 ://
396 :int wmpaint_display_threeD_proc ( HWND hWnd, HDC hDC, PAINTSTRUCT* ps, UINT uMsg, WPARAM wParam, LPARAM lParam ) {
397 : float lx, ly;
398 : float fx[3], fy[3];
399 : POINT points[3];
400 : vCalculation l_calc;
401 :
402 : if ( display_3d == 0 ) return -1;
403 :
404 :// vLine* v3d_line = l_calc.Lines_from_Mesh( vertexes, patch_num, num_patches, base_num_patches );
405 : // Print Global Vertexesx
406 : Print_Global_Vertexes ( vertexes, patch_num, num_patches, base_num_patches );
407 :
408 : printf("atri.p1=");
409 : atri.p1.print();
410 : printf("atri.p2=");
411 : atri.p2.print();
412 : printf("atri.p3=");
413 : atri.p3.print();
414 :
415 : printf("screen C=");
416 : screen->C.print();
417 :
418 : get_cooordinate_on_screen ( atri.p1, &fx[0], &fy[0] );
419 : lines_patches_2D[0]->p1->x = fx[0];
420 : lines_patches_2D[0]->p1->y = fy[0];
421 : lines_patches_2D[2]->p2->x = fx[0];
422 : lines_patches_2D[2]->p2->y = fy[0];
423 :
424 : get_cooordinate_on_screen ( atri.p2, &fx[1], &fy[1] );
425 : lines_patches_2D[0]->p2->x = fx[1];
426 : lines_patches_2D[0]->p2->y = fy[1];
427 : lines_patches_2D[1]->p1->x = fx[1];
428 : lines_patches_2D[1]->p1->y = fy[1];
429 :
430 : get_cooordinate_on_screen ( atri.p3, &fx[2], &fy[2] );
431 : lines_patches_2D[1]->p2->x = fx[2];
432 : lines_patches_2D[1]->p2->y = fy[2];
433 : lines_patches_2D[2]->p1->x = fx[2];
434 : lines_patches_2D[2]->p1->y = fy[2];
435 :
436 : GamePaint_011( hDC, lines_patches_2D[0] );
437 : GamePaint_011( hDC, lines_patches_2D[1] );
438 : GamePaint_011( hDC, lines_patches_2D[2] );
439 :
440 : // vLine** v3d_line = l_calc.Lines_from_Mesh( vertexes, patch_num, num_patches, base_num_patches );
441 : // vLine* v2d_line = (vLine*) to_screen( v3d_line,  num_patches*base_num_patches );
442 : // GamePaint_009( hDC, v2d_line );
443 :
444 : return 0;
445 :}

 

 

 86 ://
 87 ://
 88 ://
 89 ://
 90 ://
 91 :int display_threeD_initialize () {
 92 : vPoint eye;
 93 : char *p_cc;
 94 :
 95 : if ( call_once_display_threeD_initialize == 0 ) {
 96 :  call_once_display_threeD_initialize = 1;
 97 : } else {
 98 :  exit(-1);
 99 : }
100 :
101 : printf("display_threeD_initialize\r\n");
102 :
103 : eye.setPoint( 500.0f, 500.0f, -500.0f);
104 :
105 : atri.p1.setPoint( 100.0f,   0.0f, 100.0f );
106 : atri.p2.setPoint( 200.0f, 200.0f, 200.0f );
107 : atri.p3.setPoint( 300.0f,   0.0f, 100.0f );
108 :
109 : screen = new vScreen ();
110 : vPoint* U= new vPoint ( 160.0f, 0.0f, 0.0f );
111 : vPoint* V= new vPoint ( 0, 90.0f, 0 );
112 : screen->put_U ( *U );
113 : screen->put_V ( *V );
114 :
115 : screen->put_Up ( *( new vPoint(0.0f, 1.0f, 0.0f) ) );
116 : screen->put_C ( *( new vPoint( 0.0f, 0.0f, -50.0f) ));
117 : screen->setWidth ( 640 );
118 : screen->setHeight ( 480 );
119 : screen->setEye ( eye );
120 : screen->LookAt ( *(new vPoint( 0.0f, 0.0f, 0.0f )) );
121 : screen->HowFarFromEve = 320.0f;
122 : screen->calculation_up_UV();
123 : screen->OntheScreen( &g_x, &g_y );
124 :
125 : display_3d = 1;
126 :
127 : printf("display_threeD_initialize=000\r\n");
128 :
129 : lines = new vLine[3];
130 : lines[0].setLine( (new vPoint( -50.0f, 0.0f, 0.0f)), (new vPoint(300.0f,   0.0f, 0.0f)) );
131 : lines[1].setLine( (new vPoint( 0.0f, -50.0f, 0.0f)), (new vPoint(  0.0f, 300.0f, 0.0f)) );
132 : lines[2].setLine( (new vPoint( 0.0f, 0.0f, -50.0f)), (new vPoint(  0.0f, 0.0f, 300.0f)) );
133 :
134 : lines[0].c1 = (char*) "x1";
135 : lines[0].c2 = (char*) "x2";
136 :
137 : printf("display_threeD_initialize=001\r\n");
138 :
139 : lines_2D = new vLine[3];
140 : lines_2D[0].setLine( (new vPoint( 0.0f, 0.0f, 0.0f)), (new vPoint( 300.0f,   0.0f, 0.0f)) );
141 : lines_2D[1].setLine( (new vPoint( 0.0f, 0.0f, 0.0f)), (new vPoint(   0.0f, 300.0f, 0.0f)) );
142 : lines_2D[2].setLine( (new vPoint( 0.0f, 0.0f, 0.0f)), (new vPoint(   0.0f,   0.0f, 300.0f)) );
143 :
144 : printf("display_threeD_initialize=002\r\n");
145 :
146 : lines_patches = (vLine**) malloc ( sizeof(vLine*) * 3 );
147 : lines_patches_2D = (vLine**) malloc ( sizeof(vLine*) * 3 );
148 :
149 : printf("display_threeD_initialize=0021\r\n");
150 :
151 : for( int i=0; i<3; i++ ) {
152 :  lines_patches[i] = new vLine();
153 :  lines_patches_2D[i] = new vLine();
154 : }
155 :
156 : // commented out at 20190518
157 : lines_patches[0]->p1 = new vPoint( 0.0f, 0.0f, 0.0f);
158 : lines_patches[0]->p2 = new vPoint( 0.0f, 0.0f, 0.0f);
159 : lines_patches[1]->p1 = new vPoint( 0.0f, 0.0f, 0.0f);
160 : lines_patches[1]->p2 = new vPoint( 0.0f, 0.0f, 0.0f);
161 : lines_patches[2]->p1 = new vPoint( 0.0f, 0.0f, 0.0f);
162 : lines_patches[2]->p2 = new vPoint( 0.0f, 0.0f, 0.0f);
163 :
164 : printf("display_threeD_initialize=0022\r\n");
165 :
166 : // x lines_patches[0]->setLine( new vPoint( 0.0f, 0.0f, 0.0f), new vPoint( 0.0f, 0.0f, 0.0f) );
167 : // x lines_patches[0]->setLine( new vPoint( 0.0f, 0.0f, 0.0f), new vPoint( 0.0f, 0.0f, 0.0f) );
168 : printf("lines_patches[2]->p2->x %f\r\n", lines_patches[2]->p2->x );
169 :
170 :    printf("display_threeD_initialize=0023\r\n");
171 :
172 : // commented out at 20190518
173 : lines_patches_2D[0]->p1 = new vPoint( 0.0f, 0.0f, 0.0f);
174 : lines_patches_2D[0]->p2 = new vPoint( 0.0f, 0.0f, 0.0f);
175 : lines_patches_2D[1]->p1 = new vPoint( 0.0f, 0.0f, 0.0f);
176 : lines_patches_2D[1]->p2 = new vPoint( 0.0f, 0.0f, 0.0f);
177 : lines_patches_2D[2]->p1 = new vPoint( 0.0f, 0.0f, 0.0f);
178 : lines_patches_2D[2]->p2 = new vPoint( 0.0f, 0.0f, 0.0f);
179 :
180 : lines_patches_2D[0]->c1 = (char *) p_cc;
181 : lines_patches_2D[0]->c1 = (char *) copyof( "x1" );
182 : lines_patches_2D[0]->c2 = (char *) copyof( "x2" );
183 : lines_patches_2D[1]->c1 = (char *) copyof( "y1" );
184 : lines_patches_2D[1]->c2 = (char *) copyof( "y2" );
185 : lines_patches_2D[2]->c1 = (char *) copyof( "z1" );
186 : lines_patches_2D[2]->c2 = (char *) copyof( "z2" );
187 :
188 : vIntersection* intersection = nullptr;
189 : intersection = new vIntersection ();
190 :
191 : //point_intersection = intersection->Intersect( atri, eye, ray );
192 :
193 : printf("display_threeD_initialize=003\r\n");
194 :
195 : // Book a triangle patch
196 : num_patches = 1;
197 : patch_num = (int**) malloc( sizeof(int*) * 1 ) ;
198 : vertexes = (vPoint*) malloc( sizeof(vPoint) * 8 ) ;
199 :
200 : vertexes = new vPoint ( 0.0f, 0.0f, 0.0f );
201 : // scope put a vertex
202 : put_vertex( vertexes + 1, new vPoint ( 5.0f, 10.0f, 0.0f ));
203 : put_vertex( vertexes + 2, new vPoint ( 10.0f, 0.0f, 0.0f ));
204 :
205 : base_num_patches = 3;
206 : printf("display_threeD_initialize=001");
207 : Print_Global_Vertexes ( vertexes, patch_num, num_patches, base_num_patches );
208 : //exit(-1);
209 :
210 :
211 : int* p_tri_patch = (int*) malloc( sizeof(int) * base_num_patches ) ;
212 : p_tri_patch[0] = 0;
213 : p_tri_patch[1] = 1;
214 : p_tri_patch[2] = 2;
215 :
216 : patch_num[0] = p_tri_patch;
217 :
218 : num_patch_lines = 0;
219 : num_patch_lines = base_num_patches*num_patches;
220 :
221 : printf("display_threeD_initialize will return 0.\r\n");
222 : return 0;
223 :}