3D: Use not new but malloc for allocation if you would like array.
And double * is going to be one of your habitats.
.\001-display_threeD.cpp 1 :#include2 :#include 3 :#include 4 : 5 :#include 6 :#include 7 : 8 :#include "array_counter.h" 9 :#include "wTextarea.h" 10 :#include "clipboard.h" 11 : 12 :#include "vPoint.h" 13 :#include "vLine.h" 14 :#include "vTriangle.h" 15 :#include "vCalculation.h" 16 :#include "vIntersection.h" 17 :#include "vScreen.h" 18 : 19 :#include "vLine.h" 20 : 21 :#include "vPointStructure.h" 22 :#include "vPointLinear.h" 23 :#include "display_threeD.h" 24 : 25 :int display_threeD_initialize () ; 26 :int getchar_something_word_proc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) ; 27 :int getchar_display_threeD_proc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) ; 28 : 29 :int wmpaint_display_threeD_proc_org ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) ; 30 :int wmpaint_display_threeD_proc ( HWND hWnd, HDC hDC, PAINTSTRUCT* ps, UINT uMsg, WPARAM wParam, LPARAM lParam ) ; 31 : 32 :int wmpaint_display_patches ( HWND hWnd, HDC hDC, PAINTSTRUCT* ps, UINT uMsg, WPARAM wParam, LPARAM lParam ) ; 33 : 34 : 35 :void GamePaint_006(HDC hDC) ; 36 :void GamePaint_007(HDC hDC) ; 37 :void GamePaint_008(HDC hDC, POINT* points) ; 38 : 39 :void GamePaint_009(HDC hDC, vLine* line ) ; 40 :void GamePaint_010(HDC hDC, vPoint* point ) ; 41 :void GamePaint_011(HDC hDC, vLine* line ) ; 42 : 43 : 44 :int getchar_up () ; 45 :void Print_Global_Vertexes ( vPoint* points, int** numbering, int num_patches, int base_num_patches) ; 46 : 47 :vPoint* pointss = nullptr; 48 :int** patches = nullptr; 49 :vLine* patch_lines = nullptr; 50 : 51 :int num_patches = 0; 52 :int base_num_patches = 0; 53 :int num_patch_lines = 0; 54 : 55 :vTriangle atri; 56 :vTriangle screen_tri; 57 :// static vPoint eye; 58 : 59 :vPoint ray; 60 :vPoint point_intersection; 61 :float g_x, g_y; 62 :int display_3d = 0; 63 :vLine** lines = nullptr; // axes in the 3-D. 64 :vLine** lines_2D = nullptr; // axes on the screen. 65 : 66 :vLine** lines_patches = nullptr; 67 :vLine** lines_patches_2D = nullptr; 68 : 69 :vScreen* screen = nullptr; 70 :HWND hWindow; 71 : 72 :static int call_once_display_threeD_initialize = 0; 73 :vLine* to_screen( vLine** v3d_line, int num ) ; 74 :int count_screen( char* pchar_vline ) ; 75 : 76 :void put_vertex( vPoint* be_set, vPoint* p1 ); 77 : 78 :vPoint* vertexes = nullptr; 79 :int** patch_num = nullptr; 80 : 81 :// scope : 20190217 82 :void put_vertex( vPoint* be_set, vPoint* p1 ) { 83 : be_set->setPoint( p1->x, p1->y, p1->z ); 84 :} 85 : 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 = (vLine**) malloc ( sizeof(vLine*) * 3 ); 130 : lines_2D = (vLine**) malloc ( sizeof(vLine*) * 3 ); 131 : for( int i=0; i<3; i++ ) { 132 : lines[i] = new vLine(); 133 : lines_2D[i] = new vLine(); 134 : } 135 : 136 : lines[0]->setLine( (new vPoint( -50.0f, 0.0f, 0.0f)), (new vPoint(300.0f, 0.0f, 0.0f)) ); 137 : lines[1]->setLine( (new vPoint( 0.0f, -50.0f, 0.0f)), (new vPoint( 0.0f, 300.0f, 0.0f)) ); 138 : lines[2]->setLine( (new vPoint( 0.0f, 0.0f, -50.0f)), (new vPoint( 0.0f, 0.0f, 300.0f)) ); 139 : lines[0]->c1 = (char*) "x1"; 140 : lines[0]->c2 = (char*) "x2"; 141 : 142 : printf("display_threeD_initialize=001\r\n"); 143 : 144 : lines_2D[0]->setLine( (new vPoint( 0.0f, 0.0f, 0.0f)), (new vPoint( 300.0f, 0.0f, 0.0f)) ); 145 : lines_2D[1]->setLine( (new vPoint( 0.0f, 0.0f, 0.0f)), (new vPoint( 0.0f, 300.0f, 0.0f)) ); 146 : lines_2D[2]->setLine( (new vPoint( 0.0f, 0.0f, 0.0f)), (new vPoint( 0.0f, 0.0f, 300.0f)) ); 147 : 148 : printf("display_threeD_initialize=002\r\n"); 149 : 150 : lines_patches = (vLine**) malloc ( sizeof(vLine*) * 3 ); 151 : lines_patches_2D = (vLine**) malloc ( sizeof(vLine*) * 3 ); 152 : 153 : printf("display_threeD_initialize=0021\r\n"); 154 : 155 : for( int i=0; i<3; i++ ) { 156 : lines_patches[i] = new vLine(); 157 : lines_patches_2D[i] = new vLine(); 158 : } 159 : 160 : // commented out at 20190518 161 : lines_patches[0]->p1 = new vPoint( 0.0f, 0.0f, 0.0f); 162 : lines_patches[0]->p2 = new vPoint( 0.0f, 0.0f, 0.0f); 163 : lines_patches[1]->p1 = new vPoint( 0.0f, 0.0f, 0.0f); 164 : lines_patches[1]->p2 = new vPoint( 0.0f, 0.0f, 0.0f); 165 : lines_patches[2]->p1 = new vPoint( 0.0f, 0.0f, 0.0f); 166 : lines_patches[2]->p2 = new vPoint( 0.0f, 0.0f, 0.0f); 167 : 168 : printf("display_threeD_initialize=0022\r\n"); 169 : 170 : // x lines_patches[0]->setLine( new vPoint( 0.0f, 0.0f, 0.0f), new vPoint( 0.0f, 0.0f, 0.0f) ); 171 : // x lines_patches[0]->setLine( new vPoint( 0.0f, 0.0f, 0.0f), new vPoint( 0.0f, 0.0f, 0.0f) ); 172 : printf("lines_patches[2]->p2->x %f\r\n", lines_patches[2]->p2->x ); 173 : 174 : printf("display_threeD_initialize=0023\r\n"); 175 : 176 : // commented out at 20190518 177 : lines_patches_2D[0]->p1 = new vPoint( 0.0f, 0.0f, 0.0f); 178 : lines_patches_2D[0]->p2 = new vPoint( 0.0f, 0.0f, 0.0f); 179 : lines_patches_2D[1]->p1 = new vPoint( 0.0f, 0.0f, 0.0f); 180 : lines_patches_2D[1]->p2 = new vPoint( 0.0f, 0.0f, 0.0f); 181 : lines_patches_2D[2]->p1 = new vPoint( 0.0f, 0.0f, 0.0f); 182 : lines_patches_2D[2]->p2 = new vPoint( 0.0f, 0.0f, 0.0f); 183 : 184 : lines_patches_2D[0]->c1 = (char *) p_cc; 185 : lines_patches_2D[0]->c1 = (char *) copyof( "x1" ); 186 : lines_patches_2D[0]->c2 = (char *) copyof( "x2" ); 187 : lines_patches_2D[1]->c1 = (char *) copyof( "y1" ); 188 : lines_patches_2D[1]->c2 = (char *) copyof( "y2" ); 189 : lines_patches_2D[2]->c1 = (char *) copyof( "z1" ); 190 : lines_patches_2D[2]->c2 = (char *) copyof( "z2" ); 191 : 192 : vIntersection* intersection = nullptr; 193 : intersection = new vIntersection (); 194 : 195 : //point_intersection = intersection->Intersect( atri, eye, ray ); 196 : 197 : printf("display_threeD_initialize=003\r\n"); 198 : 199 : // Book a triangle patch 200 : num_patches = 1; 201 : patch_num = (int**) malloc( sizeof(int*) * 1 ) ; 202 : vertexes = (vPoint*) malloc( sizeof(vPoint) * 8 ) ; 203 : 204 : vertexes = new vPoint ( 0.0f, 0.0f, 0.0f ); 205 : // scope put a vertex 206 : put_vertex( vertexes + 1, new vPoint ( 5.0f, 10.0f, 0.0f )); 207 : put_vertex( vertexes + 2, new vPoint ( 10.0f, 0.0f, 0.0f )); 208 : 209 : base_num_patches = 3; 210 : printf("display_threeD_initialize=001"); 211 : Print_Global_Vertexes ( vertexes, patch_num, num_patches, base_num_patches ); 212 : //exit(-1); 213 : 214 : 215 : int* p_tri_patch = (int*) malloc( sizeof(int) * base_num_patches ) ; 216 : p_tri_patch[0] = 0; 217 : p_tri_patch[1] = 1; 218 : p_tri_patch[2] = 2; 219 : 220 : patch_num[0] = p_tri_patch; 221 : 222 : num_patch_lines = 0; 223 : num_patch_lines = base_num_patches*num_patches; 224 : 225 : printf("display_threeD_initialize will return 0.\r\n"); 226 : return 0; 227 :} 228 : 229 :// 230 :// 231 :// 232 :int get_cooordinate_on_screen ( vPoint lp, float* lx, float* ly ) { 233 : vCalculation calc; 234 :// vTriangle screen_tri; 235 : 236 : ray = calc.subtract( lp, screen->eye); 237 : ray = calc.normal(ray); 238 : // if ( ray.x == 0 && ray.y == 0 && ray.z == 0 ) return -1; 239 : 240 : screen_tri.p1 = screen->C; 241 : screen_tri.p2 = calc.add( screen->C, screen->U ); 242 : screen_tri.p3 = calc.add( screen->C, screen->V ); 243 : 244 : vIntersection* intersection = nullptr; 245 : intersection = new vIntersection (); 246 : vPoint point_intersection = intersection->Intersect( screen_tri, screen->eye, ray ); 247 : 248 : printf("intersection = "); 249 : point_intersection.print(); 250 :// 251 :// vPoint result; 252 :// screen->setPoint(lp); 253 :// screen->OntheScreen( lp, &result ); 254 : 255 : int result = screen->OntheScreen( point_intersection, lx, ly ); 256 : 257 : return 0; 258 :} 259 : 260 :// 261 :// 262 :// 263 :// 264 :// 265 :int getchar_display_threeD_proc ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { 266 :// int key_w = wParam; 267 : 268 : printf("getchar = %d\r\n", wParam ); 269 : //exit(-1); 270 : switch ( wParam ) { 271 : case 'j': // UP 272 : getchar_up (); 273 : break; 274 : case 40: // DOWN 275 : break; 276 : } 277 : 278 : return 0; 279 :} 280 : 281 :// 282 :// 283 :// 284 :// 285 :int getchar_up () { 286 : 287 : printf("getchar_up :\r\n"); 288 : vCalculation this_calc; 289 : float depth = this_calc.length ( this_calc.subtract( screen->eye, screen->lookat ) ); 290 : 291 : screen->eye = this_calc.add( screen->eye, screen->up ); 292 : printf("screen->eye = "); 293 : screen->eye.print(); 294 : 295 : vPoint ray = this_calc.subtract( screen->eye, screen->lookat ); 296 : ray = this_calc.normal( ray ); 297 : printf("ray = "); 298 : ray.print(); 299 : ray = this_calc.scale( ray, depth ); 300 : printf("ray = "); 301 : ray.print(); 302 : screen->eye = this_calc.add( screen->lookat, ray ); 303 : 304 : printf("screen->up = "); 305 : screen->up.print(); 306 : printf("screen->eye = "); 307 : screen->eye.print(); 308 : screen->calculation_up_UV(); 309 : 310 : printf("screen->eye = "); 311 : screen->eye.print(); 312 : printf("screen->lookat = "); 313 : screen->lookat.print(); 314 :// exit(-1); 315 : return 0; 316 :} 317 : 318 :// 319 :// 320 :// 321 :// 322 :// 323 :int wmpaint_display_threeD_proc_org ( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) { 324 : 325 : HDC hDC; 326 : PAINTSTRUCT ps; 327 : 328 : // this is not called at 20190406 329 : // exit(-1); 330 : hDC = BeginPaint( hWnd, &ps); 331 : 332 : GamePaint_007( hDC ); 333 : 334 : EndPaint(hWnd, &ps); 335 : return 0; 336 :} 337 : 338 :// 339 :// 340 :// 341 :// 342 :void Print_Global_Vertexes ( vPoint* points, int** numbering, int num_patches, int base_num_patches) 343 :{ 344 :// 20190217 345 :// p( 10.000000, 0.000000, 0.000000) 346 :// p( 0.000000, 186447550218240.000000, -0.000000) 347 :// p( 0.000000, 0.000000, 300.000000) 348 : 349 : int num = num_patches*base_num_patches; 350 : for(int i=0; i< num; i++ ) { 351 : ( points + i )->print(); 352 : } 353 :} 354 : 355 :// 356 :// 357 :// 358 :// 359 :// 360 :int calculation_pathes () { 361 : 362 : vPointLinear mpl; 363 : 364 : float t = 0.0f; 365 : vPoint* c1 = new vPoint ( 0.0f, 0.0f, 0.0f ); 366 : vPoint* c2 = new vPoint ( 0.0f, 0.0f, 0.0f ); 367 : 368 : vPointLinear* pl = new vPointLinear(); 369 : pl->calculation (); 370 : 371 : for ( int i=0; i< 100; i++ ) { 372 : double di = i; 373 : t = di/100.0 ; 374 :// vPoint result = (vPoint) pl->additional_positionP( c1, c2, t ); 375 :// result = (vPoint) mpl.additional_positionP( c1, c2, t ); 376 : 377 : } 378 : 379 : return 0; 380 :} 381 : 382 :// 383 :// 384 :// 385 :// 386 :// 387 :int wmpaint_display_patches ( HWND hWnd, HDC hDC, PAINTSTRUCT* ps, UINT uMsg, WPARAM wParam, LPARAM lParam ) { 388 : 389 : calculation_pathes (); 390 : 391 : GamePaint_009( hDC, lines_patches_2D[0] ); 392 :} 393 : 394 :// 395 :// lines : 396 :// lines_2D : 397 :// lines_patches_2D : 398 :// lines_patches : 399 :// 400 :int wmpaint_display_threeD_proc ( HWND hWnd, HDC hDC, PAINTSTRUCT* ps, UINT uMsg, WPARAM wParam, LPARAM lParam ) { 401 : float lx, ly; 402 : float fx[3], fy[3]; 403 : POINT points[3]; 404 : vCalculation l_calc; 405 : 406 : if ( display_3d == 0 ) return -1; 407 : 408 :// vLine* v3d_line = l_calc.Lines_from_Mesh( vertexes, patch_num, num_patches, base_num_patches ); 409 : // Print Global Vertexesx 410 : Print_Global_Vertexes ( vertexes, patch_num, num_patches, base_num_patches ); 411 : 412 : printf("atri.p1="); 413 : atri.p1.print(); 414 : printf("atri.p2="); 415 : atri.p2.print(); 416 : printf("atri.p3="); 417 : atri.p3.print(); 418 : 419 : printf("screen C="); 420 : screen->C.print(); 421 : 422 : get_cooordinate_on_screen ( atri.p1, &fx[0], &fy[0] ); 423 : lines_patches_2D[0]->p1->x = fx[0]; 424 : lines_patches_2D[0]->p1->y = fy[0]; 425 : lines_patches_2D[2]->p2->x = fx[0]; 426 : lines_patches_2D[2]->p2->y = fy[0]; 427 : 428 : get_cooordinate_on_screen ( atri.p2, &fx[1], &fy[1] ); 429 : lines_patches_2D[0]->p2->x = fx[1]; 430 : lines_patches_2D[0]->p2->y = fy[1]; 431 : lines_patches_2D[1]->p1->x = fx[1]; 432 : lines_patches_2D[1]->p1->y = fy[1]; 433 : 434 : get_cooordinate_on_screen ( atri.p3, &fx[2], &fy[2] ); 435 : lines_patches_2D[1]->p2->x = fx[2]; 436 : lines_patches_2D[1]->p2->y = fy[2]; 437 : lines_patches_2D[2]->p1->x = fx[2]; 438 : lines_patches_2D[2]->p1->y = fy[2]; 439 : 440 : GamePaint_011( hDC, lines_patches_2D[0] ); 441 : GamePaint_011( hDC, lines_patches_2D[1] ); 442 : GamePaint_011( hDC, lines_patches_2D[2] ); 443 : 444 : // vLine** v3d_line = l_calc.Lines_from_Mesh( vertexes, patch_num, num_patches, base_num_patches ); 445 : // vLine* v2d_line = (vLine*) to_screen( v3d_line, num_patches*base_num_patches ); 446 : // GamePaint_009( hDC, v2d_line ); 447 : 448 : return 0; 449 :} 450 : 451 : 452 : 453 : 454 : 455 :// 456 :// 457 :// 458 :// 459 :// 460 :vLine* to_screen( vLine** v3d_line, int num ) { 461 : vLine* v2d_line = nullptr; 462 : vLine a; 463 : int b[3]; 464 : vLine l[3]; 465 : float x, y; 466 : 467 :// int num = sizeof(v3d_line) / sizeof( vLine ) ; 468 : a.p1 = new vPoint( 0.0f, 0.0f, 0.0f ); 469 : 470 : v2d_line = (vLine*) malloc( sizeof(vLine) * num ); 471 : for( int i=0; i<num; i++ ) { 472 : vLine* line = ( v2d_line + i ) ; 473 : line->p1 = new vPoint(); 474 : line->p2 = new vPoint(); 475 : } 476 : 477 : 478 : //printf("b=%d int size = %d\r\n", sizeof(b), sizeof(int) ); 479 : //printf("l=%d vLine size = %d\r\n", sizeof(l), sizeof(vLine) ); 480 : //printf("v2d_line=%d vLine size = %d conunt array %d\r\n", sizeof(v2d_line), sizeof(vLine), count_screen((char*)(&l[0])) ); 481 : 482 :// printf("num=%d %d %d / %d sizeof a vLine %d &vLine %d\r\n", num, sizeof( v3d_line ), sizeof( *v3d_line ), sizeof( vLine ), sizeof(a), sizeof(&a) ); 483 : 484 : printf("set of to_screen.\r\n"); 485 : 486 : for ( int i=0; i<num; i++ ) { 487 : vLine* l1 = *( v3d_line + i ); 488 : vLine* l2 = ( v2d_line + i ); 489 : 490 : printf(" %d / %d \r\n", i, num ); 491 : 492 : vPoint* p1 = l1->p1; 493 : vPoint* p2 = l1->p2; 494 : 495 : vPoint* d2_p1 = l2->p1; 496 : vPoint* d2_p2 = l2->p2; 497 : 498 : get_cooordinate_on_screen ( *(a.p1), &x, &y ); 499 : 500 : // exit(-1); 501 : p1->print(); 502 : 503 :// get_cooordinate_on_screen ( *(p1), &x, &y ); 504 :// get_cooordinate_on_screen ( *p1, &( d2_p2->x ), &( d2_p2->y ) ); 505 :// get_cooordinate_on_screen ( *(l1->p2), &(l2->p2->x), &(l2->p2->y) ); 506 : 507 : // the below parts are all error. 508 :// get_cooordinate_on_screen ( *(l1->p1), &(l1->p1->x), &(l1->p1->y) ); 509 :// get_cooordinate_on_screen ( *(l1->p2), &(l1->p2->x), &(l1->p2->y) ); 510 :// get_cooordinate_on_screen ( *(l2->p1), &(l2->p1->x), &(l2->p1->y) ); 511 :// get_cooordinate_on_screen ( *(l2->p2), &(l2->p2->x), &(l2->p2->y) ); 512 : } 513 : 514 : printf("end of to_screen.\r\n"); 515 : // exit(-1); 516 : 517 : return v2d_line; 518 :} 519 : 520 :// 521 :// 522 :// 523 :// 524 :// 525 :int count_screen( char* pchar_vline ) { 526 : 527 : int result = 0; 528 : for( int i=0; i=256*256; i++ ) { 529 : result++; 530 : char* c = pchar_vline++; 531 : if ( *c == '\0' ) break; 532 : } 533 : 534 : return result; 535 :} 536 : 537 :// Very Thanks to: http://www.informit.com/articles/article.aspx?p=328647&seqNum=3 538 :// int FillRect(HDC hDC, CONST RECT *lprc, HBRUSH hbr); 539 :// BOOL Rectangle(HDC hDC, int xLeft, int yTop, int xRight, int yBottom); 540 :// BOOL MoveToEx(HDC hDC, int x, int y, LPPOINT pt); 541 :// BOOL LineTo(HDC hDC, int x, int y); 542 :// BOOL TextOut(HDC hDC, int x, int y, LPCTSTR szString, int iLength); 543 :// HPEN CreatePen(int iPenStyle, int iWidth, COLORREF crColor); 544 :// HPEN hBluePen = CreatePen(PS_SOLID, 1, RGB(0, 0, 255)); 545 :// HBRUSH hPurpleBrush = CreateSolidBrush(RGB(255, 0, 255)); 546 :// HPEN hPen = SelectObject(hDC, hBluePen); 547 :// SelectObject(hDC, hPen); 548 :// DeleteObject(hBluePen); 549 :// HBRUSH hBrush = SelectObject(hDC, hPurpleBrush); 550 :// // *** Do some drawing here! *** 551 :// SelectObject(hDC, hBrush); 552 :// DeleteObject(hPurpleBrush); 553 : 554 :// case WM_PAINT: 555 :// HDC hDC; 556 :// PAINTSTRUCT ps; 557 :// hDC = BeginPaint(hWindow, &ps); 558 : 559 :// // Paint the game 560 :// GamePaint(hDC); 561 :// 562 :// EndPaint(hWindow, &ps); 563 :// return 0; 564 :// 565 :// 566 :// 567 :// 568 : 569 :// 570 :// 571 :// 572 :// 573 :// 574 :void GamePaint_000(HDC hDC) 575 :{ 576 : MoveToEx(hDC, 0, 0, NULL); 577 : LineTo(hDC, 50, 50); 578 :} 579 : 580 :void GamePaint_001(HDC hDC) 581 :{ 582 : TextOut(hDC, 10, 10, TEXT("Michael Morrison"), 16); 583 :} 584 : 585 :void GamePaint_002(HDC hDC) 586 :{ 587 : RECT rect; 588 : GetClientRect(hWindow, &rect); 589 : DrawText(hDC, TEXT("Michael Morrison"), -1, &rect, 590 : DT_SINGLELINE | DT_CENTER | DT_VCENTER); 591 :} 592 : 593 :void GamePaint_003(HDC hDC) 594 :{ 595 : MoveToEx(hDC, 10, 40, NULL); 596 : LineTo(hDC, 44, 10); 597 : LineTo(hDC, 78, 40); 598 :} 599 : 600 :void GamePaint_004(HDC hDC) 601 :{ 602 : Rectangle(hDC, 16, 36, 72, 70); 603 : Rectangle(hDC, 34, 50, 54, 70); 604 :} 605 : 606 :void GamePaint_005(HDC hDC) 607 :{ 608 : Ellipse(hDC, 40, 55, 48, 65); 609 :} 610 : 611 :void GamePaint_006(HDC hDC) 612 :{ 613 : POINT points[3]; 614 : points[0] = { 305, 10 }; 615 : points[1] = { 355, 50 }; 616 : points[2] = { 325, 55 }; 617 : Polygon( hDC, points, 3 ); 618 :} 619 : 620 :void GamePaint_007(HDC hDC) { 621 : RECT msg_clip; 622 : 623 : SetRect ( &msg_clip, 300, 0, 400, 50); 624 :// DrawText( hdc, TEXT( m_pastestr ), -1, &msg_clip, DT_NOCLIP); 625 : DrawText( hDC, TEXT( "GamePaint_007" ), -1, &msg_clip, DT_NOCLIP); 626 :} 627 : 628 :// 3 points :triangle 629 :void GamePaint_008(HDC hDC, POINT* points) 630 :{ 631 : POINT p = points[0]; 632 : printf("point 1: %ld %ld\r\n", p.x, p.y ); 633 : Polygon( hDC, points, 3 ); 634 :} 635 : 636 :void GamePaint_009(HDC hDC, vLine* line ) 637 :{ 638 : vPoint *p1, *p2; 639 : p1 = line->p1; 640 : p2 = line->p2; 641 : 642 : printf("GamePaint_009: line : %f %f - %f %f\r\n", p1->x, p1->y, p2->x, p2->y ); 643 :// printf("GamePaint_009: line : %f %f - %f %f\r\n", line->p1->x, line->p1->y, line->p2->x, line->p2->y ); 644 : MoveToEx(hDC, (int)line->p1->x, (int)line->p1->y, NULL); 645 : LineTo(hDC, (int)(line->p2)->x, (int)(line->p2)->y ); 646 :} 647 : 648 :// 649 :// 650 :// 651 :// vPoint 652 :// 653 :void GamePaint_010(HDC hDC, vPoint* point ) { 654 : 655 : MoveToEx(hDC, (int)point->x, (int)point->y, NULL); 656 : LineTo(hDC, (int)point->x, (int)point->y ); 657 :} 658 : 659 : 660 : 661 :// customized from GamePaint_009 662 :// 663 :// 664 :// 665 :// 666 :void GamePaint_011(HDC hDC, vLine* line ) { 667 : 668 : int scale_2 = 30; 669 : static RECT rect_2, rect; 670 : 671 : MoveToEx(hDC, (int)line->p1->x, (int)line->p1->y, NULL); 672 : LineTo(hDC, (int)(line->p2)->x, (int)(line->p2)->y ); 673 : 674 : if ( line->c1 != nullptr ) { 675 : SetRect( &rect, (int)line->p1->x - scale_2, (int)line->p1->y - scale_2, (int)line->p1->x + scale_2, (int)line->p1->y + scale_2 ); 676 : DrawText( hDC, TEXT( line->c1 ), -1, &rect, DT_NOCLIP ); 677 : } 678 : 679 : if ( line->c2 != nullptr ) { 680 : SetRect( &rect_2, (int)line->p2->x - scale_2, (int)line->p2->y - scale_2, (int)line->p2->x + scale_2, (int)line->p2->y + scale_2 ); 681 : DrawText( hDC, TEXT( line->c2 ), -1, &rect_2, DT_NOCLIP ); 682 : } 683 : 684 : return; 685 :} 686 : 687 : 688 :