demoII5_3.cpp
上传用户:husern
上传日期:2018-01-20
资源大小:42486k
文件大小:3k
源码类别:

游戏

开发平台:

Visual C++

  1. // DEMOII5_3.CPP - 3D plane-parametric line intersector
  2. // INCLUDES ///////////////////////////////////////////////////
  3. #define WIN32_LEAN_AND_MEAN  
  4. #ifndef INITGUID
  5. #define INITGUID       // you need this or DXGUID.LIB
  6. #endif
  7. #include <windows.h>   // include important windows stuff
  8. #include <windowsx.h> 
  9. #include <mmsystem.h>
  10. #include <objbase.h>
  11. #include <iostream.h> // include important C/C++ stuff
  12. #include <conio.h>
  13. #include <stdlib.h>
  14. #include <malloc.h>
  15. #include <memory.h>
  16. #include <string.h>
  17. #include <stdarg.h>
  18. #include <stdio.h>
  19. #include <math.h>
  20. #include <io.h>
  21. #include <fcntl.h>
  22. #include <direct.h>
  23. #include <wchar.h>
  24. #include <ddraw.h>      // needed for defs in T3DLIB1.H 
  25. #include "T3DLIB1.H"    // T3DLIB4 is based on some defs in this 
  26. #include "T3DLIB4.H"
  27. // DEFINES ////////////////////////////////////////////////////
  28. // TYPES //////////////////////////////////////////////////////
  29. // CLASSES ////////////////////////////////////////////////////
  30. // GLOBALS ////////////////////////////////////////////////////
  31. // define vars expected by graphics engine to compile
  32. HWND main_window_handle;
  33. // FUNCTIONS //////////////////////////////////////////////////
  34. void main()
  35. {
  36. VECTOR3D plane_n; // plane normal
  37. POINT3D  plane_p; // point on plane
  38. PLANE3D plane;    // the plane
  39. printf("n3D Plane-Parametric Line Intersectorn");
  40. // get the normal to the plane
  41. printf("nEnter normal to plane: nx, ny, nz?");
  42. scanf("%f, %f, %f", &plane_n.x, &plane_n.y, &plane_n.z);
  43. // get a point on the plane
  44. printf("nEnter a point on the plane: x,y,z?");
  45. scanf("%f, %f, %f", &plane_p.x, &plane_p.y, &plane_p.z);
  46. // create the plane from the point and normal
  47. PLANE3D_Init(&plane, &plane_p, &plane_n, TRUE);
  48. POINT3D p1, p2;  // our endpoints
  49. PARMLINE3D pl1; // our line
  50. while(1) {
  51. printf("nEnter coords parametric line from p1 to p2 in form: x1,y1,z1, x2,y2,z2?");
  52. scanf("%f, %f, %f, %f, %f, %f",&p1.x, &p1.y, &p1.z, &p2.x, &p2.y, &p2.z);
  53. // create a parametric line from p1 to p2
  54. Init_Parm_Line3D(&p1, &p2, &pl1);
  55. float t;    // intersection parameter
  56. POINT3D pt; // intersection point
  57. // compute intersection
  58. int intersection_type = Intersect_Parm_Line3D_Plane3D(&pl1, &plane, &t, &pt);
  59. // based on type of intersection display results
  60. switch(intersection_type)
  61.       {
  62.       case PARM_LINE_NO_INTERSECT:
  63.            {
  64.            printf("nThe plane and line does not intersect!");
  65.            } break;
  66.       case PARM_LINE_INTERSECT_IN_SEGMENT:
  67.            {
  68.            POINT3D pt;
  69.            Compute_Parm_Line3D(&pl1, t, &pt);
  70.            printf("nThe line and plane intersects when t=%f at (%f, %f, %f)",t,pt.x, pt.y, pt.z);
  71.            } break;
  72.       case PARM_LINE_INTERSECT_OUT_SEGMENT:
  73.            {
  74.            POINT3D pt;
  75.            Compute_Parm_Line3D(&pl1, t, &pt);
  76.            printf("nThe line and plane intersects when t=%f at (%f, %f, %f)",t,pt.x, pt.y, pt.z);
  77.            printf("nNote that the intersection occurs out of range of the line segment");
  78.            } break;
  79.       default: break;
  80.  
  81.       } // end switch
  82. } // end while
  83. } // end main