- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
demoII5_3.cpp
资源名称:Source.rar [点击查看]
上传用户:husern
上传日期:2018-01-20
资源大小:42486k
文件大小:3k
源码类别:
游戏
开发平台:
Visual C++
- // DEMOII5_3.CPP - 3D plane-parametric line intersector
- // INCLUDES ///////////////////////////////////////////////////
- #define WIN32_LEAN_AND_MEAN
- #ifndef INITGUID
- #define INITGUID // you need this or DXGUID.LIB
- #endif
- #include <windows.h> // include important windows stuff
- #include <windowsx.h>
- #include <mmsystem.h>
- #include <objbase.h>
- #include <iostream.h> // include important C/C++ stuff
- #include <conio.h>
- #include <stdlib.h>
- #include <malloc.h>
- #include <memory.h>
- #include <string.h>
- #include <stdarg.h>
- #include <stdio.h>
- #include <math.h>
- #include <io.h>
- #include <fcntl.h>
- #include <direct.h>
- #include <wchar.h>
- #include <ddraw.h> // needed for defs in T3DLIB1.H
- #include "T3DLIB1.H" // T3DLIB4 is based on some defs in this
- #include "T3DLIB4.H"
- // DEFINES ////////////////////////////////////////////////////
- // TYPES //////////////////////////////////////////////////////
- // CLASSES ////////////////////////////////////////////////////
- // GLOBALS ////////////////////////////////////////////////////
- // define vars expected by graphics engine to compile
- HWND main_window_handle;
- // FUNCTIONS //////////////////////////////////////////////////
- void main()
- {
- VECTOR3D plane_n; // plane normal
- POINT3D plane_p; // point on plane
- PLANE3D plane; // the plane
- printf("n3D Plane-Parametric Line Intersectorn");
- // get the normal to the plane
- printf("nEnter normal to plane: nx, ny, nz?");
- scanf("%f, %f, %f", &plane_n.x, &plane_n.y, &plane_n.z);
- // get a point on the plane
- printf("nEnter a point on the plane: x,y,z?");
- scanf("%f, %f, %f", &plane_p.x, &plane_p.y, &plane_p.z);
- // create the plane from the point and normal
- PLANE3D_Init(&plane, &plane_p, &plane_n, TRUE);
- POINT3D p1, p2; // our endpoints
- PARMLINE3D pl1; // our line
- while(1) {
- printf("nEnter coords parametric line from p1 to p2 in form: x1,y1,z1, x2,y2,z2?");
- scanf("%f, %f, %f, %f, %f, %f",&p1.x, &p1.y, &p1.z, &p2.x, &p2.y, &p2.z);
- // create a parametric line from p1 to p2
- Init_Parm_Line3D(&p1, &p2, &pl1);
- float t; // intersection parameter
- POINT3D pt; // intersection point
- // compute intersection
- int intersection_type = Intersect_Parm_Line3D_Plane3D(&pl1, &plane, &t, &pt);
- // based on type of intersection display results
- switch(intersection_type)
- {
- case PARM_LINE_NO_INTERSECT:
- {
- printf("nThe plane and line does not intersect!");
- } break;
- case PARM_LINE_INTERSECT_IN_SEGMENT:
- {
- POINT3D pt;
- Compute_Parm_Line3D(&pl1, t, &pt);
- printf("nThe line and plane intersects when t=%f at (%f, %f, %f)",t,pt.x, pt.y, pt.z);
- } break;
- case PARM_LINE_INTERSECT_OUT_SEGMENT:
- {
- POINT3D pt;
- Compute_Parm_Line3D(&pl1, t, &pt);
- printf("nThe line and plane intersects when t=%f at (%f, %f, %f)",t,pt.x, pt.y, pt.z);
- printf("nNote that the intersection occurs out of range of the line segment");
- } break;
- default: break;
- } // end switch
- } // end while
- } // end main