TC 3D model drawing

xiaoxiao2021-03-05  23

/ * This program is used to describe a 3D object of a user given an equation, and the user can control this 3D body motion by the keyboard to understand the surface details of the object. The control bond defined by the program is as follows: A, S, W: Yes 3D Left, then, before, right movement (default) C: Function switch key, when the odd times presses this button, A, S, W: Get function is left, down, upper, right, rotate the corresponding number key keypad, making 3D body along its body-centered correspond rotation 0: any other key to exit the program: the 3D body still maintain the current state program was completed in August 2003, author: Jia Shenghua If any of the program Improved opinions or suggestions, please send an email to xiajia_1981@163.com

/ * The following is the header file * / # include #include #include

#define pi 3.1415926 # Define maxRow 32 # Define Maxline 16

Struct _3dpoint {float x; float y; float z;};

Struct _3dobjPosition {// Spatial Displacement Coordinate Struct_3dpoint Point; // Audience Attitude Clarion Double User_Angely; Double User_Angelz; // Self - attitude Double Agely; Double Angelz;};

Struct _2dpoint {float x; float y;

Struct _ProccessBox {struct _2dpoint point; int longth; int higth; int backgcolor; int mycolor; char mytext [13];

float GetResult (float r, float angel1, float angel2); void GraphicsInit (int mode, int driver); / * Function image initialization * / void ProccessBoxInit (struct _ProccessBox * p); / * progress bar initialization function * / void ProccessBoxSet (INT N, STRUCT _PROCCESSBOX * P); / * Progress Bar Set function * / float halfway (float angel1, float angel2); / * Di-point method to solve Code Function * / void init3dobj (struct _3dobjPosition * P); / * Initializes object the posture data * / void Change3DObjPosition (char order, struct _3DObjPosition * p); / * 3D object pose parameter setting functions * / void Change3dTO2D (struct _3DPoint SousePoint, struct _3DObjPosition P, struct _3DPoint * ArmPoint); / * 3D data is transferred 2D Function * / void showsmallmap (void);

Void main (void) {INT I, J; / * Cycle Variable * / INT L, N, K = 0; / * Status tag variable used in program * / char presskey = '6'; float angarpha, Angelthetar; / * Angle variable * / float r, smallmap [2] [2] = {0}; struct _proccessbox proccess; struct _3dpoint sourceData [maxROW] [maxline]; / * Record the original calculation data of the object space dot matrix * / Struct _3dobjPosition Object ; struct _3DPoint TempPoint; struct _3DPoint changedData [MAXROW] [MAXLINE] [2] = {0}; / * record through the lattice data * / ProccessBoxInit (& Proccess) the user space transformation; Init3DObj (& Object); GraphicsInit (VGAHI, VGA); / * Graphic mode initialization * / / * The following code is used to calculate the spatial point of the surface given by the user * / clearDevice (); / * clear screen * / for (i = 0; i

/ * Below the next time you accept the user's space to display dynamic images on the screen * / cleardevice (); l = 0; angelthetar = 0;

For (;;;) / * Start processing user control * / {if (kbhit ()) presskey = getch (); / * Determine if the user is typed * / switch (presskey) {case 'c': / * switching into Turn or move, that is, change L = 0 or = 1 * / case 'c': {L = (L-1) * (L-1); PressKey = 'q'; Break;} case '0': { EXIT (0); Break;} / * Exit Program * / Default: {IF (PressKey <'0' || PressKey> '9') {// Non - digital IF (l == 1) {// lowercase IF ( PressKey <'a') PressKey = 'a' -'a ';} else {// Upper write IF (PressKey> =' a ') presskey - =' a '-'a';}} Change3DobjPosition (PressKey, & Object }}} / * The following is three-dimensional two-dimensional conversion * / k = (1 - k) * (1 - k); for (i = 0; i 2D Conversion * / {for (j = 0; j 2D * / ChangeDData [i] [j] [k] .y = temppoint.y 240; / * The 320 and 240 here will put the origin in the middle of the screen * / ChangedData [ I] [j] [k] .z = Temppoint.z;}} n = (1-k) * (1-k); for (i = 0; i 0) && (ChangeDData) [i] [j] .z> 0)) {setColor (0); line (ChangeDData [i] [j] [n] .x, changedata [i] [j] [n] .y, changedata [i] [j 1] [n] .x, changedata [i] [j 1] [n] .y);} f ((ChangeDData [i] [j 1] [k] .z> 0 ) && (ChangeData [i] [j] [k] .z> 0)) {setColor (9); line (ChangeDData [i] [j] [k] .x, changedata [i] [j] [k] Changeddata [i] [j

1] [k] .x, changedata [i] [j 1] [k] .y);} IF (i <(maxRow-1)) {IF ((ChangeDData [i 1] [j] [n ] .z> 0) && (ChangeDATA [i] [j] [n] .z> 0)) {setColor (0); line (ChangeDData [i] [j] [n] .x, changedata [i] [ j] [n] .y, changedata [i 1] [j] [n] .x, changeddata [i 1] [j] [n] .y);} if ((ChangeDData [i 1] [ J] [K] .z> 0) && (ChangeDATA [i] [j] [k] .z> 0)) {setColor (9); line (ChangeDData [i] [j] [k] .x, changedata [i] [j] [k] .y, changedata [i 1] [j] [k] .x, changeddata [i 1] [j] [k] .y);}} f (i == Maxrow-1) {IF ((ChangedData [0] [J] [N] .z> 0) && (ChangeDData [i] [j] [n] .z> 0)) {setColor (0); line (ChangeDData) [i] [j] [n] .x, changedata [i] [j] [n] .y, changedata [0] [j] [n] .x, changedata [0] [j] [n] .y .y );} IF (Changeddata [0] [J] [K] .z> 0) && (ChangeDData [i] [j] [k] .z> 0)) {setColor (9); line (ChangeDATA [i ] [j] [k] .x, changedata [i] [j] [k] .y, changeddata [0] [j] [k] .x, changedata [0] [j] [k] .y); }}}} / * Insert a small map of the upper left corner * / smallmap [k] [0] = OBJ Ect.point.x * cos (object.user_angelz) - Object.point.y * sin (object.user_angelz); SmallMap [K] [1] = sin (Object.user_Angelz) * Object.point.x Cos (Object) .User_angelz) * Object.point.y; SmallMap [k] [1] = smallmap [k] [1] * COS (Object.usel_angely); setColor (0); circle (smallmap [n] [0] / 20 26, 26 - SmallMap [N] [1] / 20, 5); setColor (12); Circle (SmallMap [K] [0] / 20 26, 26 - SmallMap [K] [1] / 20, 5) Showsmallmap ();}} void proccessboxinit (struct _ProccessBox * p) {// data initialization (* p) .point.x = 230; (* p) .point.y = 240; (* p) .longth = 100 (* P) ​​.higth = 10; (* p). Backgcolor = 0; (* p) .mycolor = 1;

STRCPY ((* p) .mytext, "complete%");} void init3dobj (struct _3dobjPosition * p) {(* p) .point.x = 0; (* p) .point.y = 0; (* p) ) .point.z = 0; (* p) .user_Angely = 0; (* p) .user_angelz = 0; (* p) .angely = 0; (* p) .angelz = 0;}

Void showsmallmap () {setColor (14); Circle (26, 26, 25); line (21, 26, 31, 26); line (26, 21, 26, 31); line (310, 240, 330, 240); line (320, 230, 320, 250) SetColor (2); Line (26, 26, 17, 5); line (26, 26, 35, 5);}

void Change3dTO2D (struct _3DPoint SourcePoint, struct _3DObjPosition P, struct _3DPoint * ArmPoint) {struct _3DPoint TempPoint [4]; float Deep; TempPoint [0] .x = SourcePoint.x; / * Solving receiving data * / TempPoint [0]. Y = sourcePoint.y; Temppoint [0] .z = sourcePoint.z; Temppoint [1] .x = Temppoint [0] .x * cos (p.ANgely) - Temppoint [0] .z * sin (P.ANgely ); / * Deflection calculation of y-axis * / temppoint [1] .z = sin (p.Angely) * Temppoint [0] .x cos (p.Angely) * Temppoint [0] .z; tempppoint [1 ] .y = temppoint [0] .y; temppoint [2] .x = Temppoint [1] .x * COS (P.Angelz) - Temppoint [1] .y * sin (p.Angelz) P.Point. X; / * extension Z-axis deflection calculation * / temppoint [2] .y = sin (p.Angelz) * Temppoint [1] .x cos (p.Angelz) * Temppoint [1] .y p.point .y; temppoint [2] .z = Temppoint [1] .z P.Point.z; Temppoint [3] .x = Temppoint [2] .x * cos (p.user_angelz) - Temppoint [2] .y * sin (p.user_angelz); / * Implement a fixed point rotation * / temppoint [1] .y = sin (p.user_angelz) * Temppoint [2] .x cos (p.user_angelz) * Temppoint [2] .y; Temppoint [3] .y = Temppoint [1] .y * cos (p.user_angely) - Temppoint [2] .z * sin (p.user_ Angely); Temppoint [2] .z = sin (p.user_angely) * Temppoint [1] .y cos (p.user_angely) * Temppoint [2] .z; deep = 1 / (0.1 0.001 * Pow (Temppoint [3] .x * temppoint [3] .x temppoint [3] .y * tempp [3] .y tempp [2] .z * temppoint [2] .z, 0.5)); / * This line is used Calculate * / temppoint [2] .x = Temppoint [2] .x * deep; tempppoint [2] .z = tempp [2] .z * deep; (* armpoint) .x = Temppoint [2] .x; (* armpoint) .y = Temppoint [2] .z; (* armpoint) .z = Temppoint [3] .y;}

Void change3DobjPosition (char order, struct _3dobjPosition * p) {switch (order) {case 'w': {(* p) .user_Angely - = 0.002; / * Turn down * / Break;} Case 'W': {IF (POW ((* p) .point.y-1, 2) POW ((* p) .point.x, 2) <490000) (* p) .point.y - = 1; / * Put forward * / Break;} case 'a': {(* p) .user_angelz - = 0.002; / * Rotate * / Break;} Case 'A': {IF (POW ((* p) .point.y , 2) POW ((* p) .point.x 1, 2) <490000) (* p) .point.x = 1; / * To the left, translation * / Break;} case 's': { (* p) .user_Angely = 0.002; / * Turn up * / BREAK;} Case 's': {IF (POW ((* p) .point.y 1, 2) POW ((* P). Point.x, 2) <490000) (* p) .point.y = 1; / * Down translation * / Break;} case 'd': {(* p) .user_angelz = 0.002; / * Left rotation * / Break;} case 'd': {if (POW ((* p) .point.y, 2) POW ((* p) .point.x-1, 2) <490000) (* p) .point.x - = 1; / * Power-to-right * / Break;} case '6': {(* p) .angel Z = 0.01; Break;} / * Left * / case '8': {(* p) .angely = 0.01; Break;} / * Upload * / case '2': {(* P). Angely - = 0.01; break;} / * down * / case '4': {(* p). Nangelz - = 0.01; Break;} / * Right Transfer * / Case '9': {(* P). Angelz = 0.01; (* p) .angely = 0.01; Break;} / * Right * / Case '1': {(* p) .Angelz - = 0.01; (* p) .angely - = 0.01; Break } / * Left * / case '7'

: {(* P) ​​.Angelz - = 0.01; (* p). Nangely = 0.01; Break;} / * Left * / case '3': {(* p) .Angelz = 0.01; (* p) .angely - = 0.01; Break;} / * Right * / default:; / * Other buttons, for pause * /}} Float Halfway (Float Angel1, Float Angel2) {// This function is 0 to 150 Float headdata, enddata; float r [3]; r [0] = 0; headdata = getResult (R [0], Angel1, Angel2); R [1] = 150; enddata = getResult (r [1], Angel1, Angel2); R [2] = 150; if (HeadData * enddata <0) {for (;;) {r [2] = (R [0] R [1]) / 2; Millddata = GetResult ( R [2], Angel1, Angel2; IF (Millddata * Milldata <0.00001) Break; if (Millddata * HeadData> = 0) {headdata = MillData; R [0] = r [2];} else {enddata = Millddata ; R [1] = r [2];}}} return r [2];

Void ProccessBoxSet (INT N, STRUCT _PROCCESSBOX * P) {Rectangle ((* p) .point.x -1, (* p) .point.y -1, (* p) .point.x (* p). Longth 1, (* p) .point.y (* p) .higth 1); setfillstyle (1, (* p) .mycolor); bar ((* p) .point.x, (* p) .point.y, (* p) .point.x (* p) .longth * n / 100, (* p) .point.y (* p) .higth); (* p) .mytext [10 ] = N% 10 48; (* p) .mytext [9] = N / 10 48; SetFillStyle (1, (* p) .backgcolor); bar ((* p) .point.x (* p) ) .Longth 10, (* p) .point.y, (* p) .point.x (* p) .longth 10 104, (* p) .Point.y (* p) .higth ); Outtextxy ((* p) .point.x (* p) .longth 10, (* p) .point.y, (* p) .mytext);}

Void Graphicsinit (INT MODE, INT Driver); / * This line of code is to include the display driver, when the program compiles this line error, shield this line of code * / IITGRAPH (& Driver, & Mode, "/ / TC ");

转载请注明原文地址:https://www.9cbs.com/read-35883.html

New Post(0)