home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 4 / CD_Magazyn_EXEC_nr_4.iso / Recent / dev / c / GSys.lha / gsys / g3d / G3DVertex.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-03-29  |  5.0 KB  |  349 lines

  1.  
  2. /* Author Anders Kjeldsen */
  3.  
  4. #ifndef GVERTEXMET
  5. #define GVERTEXMET
  6.  
  7. GVertex::GVertex()
  8. {
  9.     memset((void*)this, 0, sizeof (class GVertex));
  10. }
  11.  
  12. void GVertex::PrintfAll()
  13. {
  14.     printf("Vertex at $%x:\t", this);
  15.     printf("X: %f ", X);
  16.     printf("Y: %f ", Y);
  17.     printf("Z: %f.\n", Z);
  18. }
  19.  
  20. BOOL GVertex::CopyVertex(GVertex *Destination)
  21. {
  22.     if (Destination)
  23.     {
  24.         memcpy((APTR)Destination, (APTR)this, sizeof (class GVertex));
  25.         return TRUE;
  26.     }
  27.     else return FALSE;
  28. }
  29.  
  30.  
  31. BOOL GVertex::AddVector(class GVector *Source)
  32. {
  33.     if (Source)
  34.     {
  35.         X+=Source->DeltaX;
  36.         Y+=Source->DeltaY;
  37.         Z+=Source->DeltaZ;
  38.         U+=Source->DeltaU;
  39.         V+=Source->DeltaV;
  40.  
  41. #if OBJ_VTX_TEX3D == TRUE
  42.         TEX3D+=Source->DeltaTEX3D;
  43. #endif
  44.  
  45. #if OBJ_VTX_W == TRUE
  46.         W+=Source->DeltaW;
  47. #endif
  48.  
  49. #if OBJ_VTX_COLOR == TRUE
  50.         COLOR.r+=Source->DeltaCOLOR.r;
  51.         COLOR.g+=Source->DeltaCOLOR.g;
  52.         COLOR.b+=Source->DeltaCOLOR.b;
  53.         COLOR.a+=Source->DeltaCOLOR.a;
  54. #endif
  55.  
  56. #if OBJ_VTX_SPEC == TRUE
  57.         SPEC.r+=Source->DeltaSPEC.r;
  58.         SPEC.g+=Source->DeltaSPEC.g;
  59.         SPEC.b+=Source->DeltaSPEC.b;
  60. #endif
  61.  
  62. #if OBJ_VTX_L == TRUE
  63.         L+=Source->DeltaL;
  64. #endif
  65.  
  66.         return TRUE;
  67.     }
  68.     else return FALSE;
  69. }
  70.  
  71.  
  72. GVertex operator +(class GVertex &V1, class GVertex &V2)
  73. {
  74.     GVertex dest;
  75. //    if (V1 && V2)
  76. //    {
  77.         dest.X = V1.X + V2.X;
  78.         dest.Y = V1.Y + V2.Y;
  79.         dest.Z = V1.Z + V2.Z;
  80.         dest.U = V1.U + V2.U;
  81.         dest.V = V1.V + V2.V;
  82.  
  83. #if OBJ_VTX_TEX3D == TRUE
  84.         dest.TEX3D = V1.TEX3D + V2.TEX3D;
  85. #endif
  86.  
  87. #if OBJ_VTX_W == TRUE
  88.         dest.W = V1.W + V2.W;
  89. #endif
  90.  
  91. #if OBJ_VTX_COLOR == TRUE
  92.         dest.COLOR.r = V1.COLOR.r + V2.COLOR.r;
  93.         dest.COLOR.g = V1.COLOR.g + V2.COLOR.g;
  94.         dest.COLOR.b = V1.COLOR.b + V2.COLOR.b;
  95.         dest.COLOR.a = V1.COLOR.a + V2.COLOR.a;
  96. #endif
  97.  
  98. #if OBJ_VTX_SPEC == TRUE
  99.         dest.SPEC.r = V1.SPEC.r + V2.SPEC.r;
  100.         dest.SPEC.g = V1.SPEC.g + V2.SPEC.g;
  101.         dest.SPEC.b = V1.SPEC.b + V2.SPEC.b;
  102. #endif
  103.  
  104. #if OBJ_VTX_L == TRUE
  105.         dest.L = V1.L + V2.L;
  106. #endif
  107. //    }
  108.     return dest;
  109. }
  110.  
  111. GVertex operator -(class GVertex &V1, class GVertex &V2)
  112. {
  113.     GVertex dest;
  114. //    if (V1 && V2)
  115. //    {
  116.         dest.X = V1.X - V2.X;
  117.         dest.Y = V1.Y - V2.Y;
  118.         dest.Z = V1.Z - V2.Z;
  119.         dest.U = V1.U - V2.U;
  120.         dest.V = V1.V - V2.V;
  121.  
  122. #if OBJ_VTX_TEX3D == TRUE
  123.         dest.TEX3D = V1.TEX3D - V2.TEX3D;
  124. #endif
  125.  
  126. #if OBJ_VTX_W == TRUE
  127.         dest.W = V1.W - V2.W;
  128. #endif
  129.  
  130. #if OBJ_VTX_COLOR == TRUE
  131.         dest.COLOR.r = V1.COLOR.r - V2.COLOR.r;
  132.         dest.COLOR.g = V1.COLOR.g - V2.COLOR.g;
  133.         dest.COLOR.b = V1.COLOR.b - V2.COLOR.b;
  134.         dest.COLOR.a = V1.COLOR.a - V2.COLOR.a;
  135. #endif
  136.  
  137. #if OBJ_VTX_SPEC == TRUE
  138.         dest.SPEC.r = V1.SPEC.r - V2.SPEC.r;
  139.         dest.SPEC.g = V1.SPEC.g - V2.SPEC.g;
  140.         dest.SPEC.b = V1.SPEC.b - V2.SPEC.b;
  141. #endif
  142.  
  143. #if OBJ_VTX_L == TRUE
  144.         dest.L = V1.L - V2.L;
  145. #endif
  146. //    }
  147.     return dest;
  148. }
  149.  
  150. GVertex operator *(GVertex &V1, float t)
  151. {
  152.     GVertex dest;
  153.  
  154.     dest.X = V1.X * t;
  155.     dest.Y = V1.Y * t;
  156.     dest.Z = V1.Z * t;
  157.     dest.U = V1.U * t;
  158.     dest.V = V1.V * t;
  159.  
  160. #if OBJ_VTX_TEX3D == TRUE
  161.     dest.TEX3D = V1.TEX3D * t;
  162. #endif
  163.  
  164. #if OBJ_VTX_W == TRUE
  165.     dest.W = V1.W * t;
  166. #endif
  167.  
  168. #if OBJ_VTX_COLOR == TRUE
  169.     dest.COLOR.r = V1.COLOR.r * t;
  170.     dest.COLOR.g = V1.COLOR.g * t;
  171.     dest.COLOR.b = V1.COLOR.b * t;
  172.     dest.COLOR.a = V1.COLOR.a * t;
  173. #endif
  174.  
  175. #if OBJ_VTX_SPEC == TRUE
  176.     dest.SPEC.r = V1.SPEC.r * t;
  177.     dest.SPEC.g = V1.SPEC.g * t;
  178.     dest.SPEC.b = V1.SPEC.b * t;
  179. #endif
  180.  
  181. #if OBJ_VTX_L == TRUE
  182.     dest.L = V1.L * t;
  183. #endif
  184.     return dest;
  185. }
  186.  
  187. BOOL GVertex::DivideByX()
  188. {
  189.     if (X)
  190.     {
  191.         Y/= X;
  192.         Z/= X;
  193.         U = X;
  194.         V/= X;
  195.  
  196. #if OBJ_VTX_TEX3D == TRUE
  197.         TEX3D/= X;
  198. #endif
  199.  
  200. #if OBJ_VTX_W == TRUE
  201.         W/= X;
  202. #endif
  203.  
  204. #if OBJ_VTX_COLOR == TRUE
  205.         COLOR.r/= X;
  206.         COLOR.g/= X;
  207.         COLOR.b/= X;
  208.         COLOR.a/= X;
  209. #endif
  210.  
  211. #if OBJ_VTX_SPEC == TRUE
  212.         SPEC.r/= X;
  213.         SPEC.g/= X;
  214.         SPEC.b/= X;
  215. #endif
  216.  
  217. #if OBJ_VTX_L == TRUE
  218.         L/= X;
  219. #endif
  220.  
  221.         X = 1.0;
  222.  
  223.         return TRUE;
  224.     }
  225.     else return FALSE;
  226. }
  227.  
  228.  
  229. BOOL GVertex::DivideByY()
  230. {
  231.     if (Y)
  232.     {
  233.         X/= Y;
  234.         Z/= Y;
  235.         U = Y;
  236.         V/= Y;
  237.  
  238. #if OBJ_VTX_TEX3D == TRUE
  239.         TEX3D/= Y;
  240. #endif
  241.  
  242. #if OBJ_VTX_W == TRUE
  243.         W/= Y;
  244. #endif
  245.  
  246. #if OBJ_VTX_COLOR == TRUE
  247.         COLOR.r/= Y;
  248.         COLOR.g/= Y;
  249.         COLOR.b/= Y;
  250.         COLOR.a/= Y;
  251. #endif
  252.  
  253. #if OBJ_VTX_SPEC == TRUE
  254.         SPEC.r/= Y;
  255.         SPEC.g/= Y;
  256.         SPEC.b/= Y;
  257. #endif
  258.  
  259. #if OBJ_VTX_L == TRUE
  260.         L/= Y;
  261. #endif
  262.  
  263.         Y = 1.0;
  264.  
  265.         return TRUE;
  266.     }
  267.     else return FALSE;
  268. }
  269.  
  270. BOOL GVertex::DivideByZ()
  271. {
  272.     if (Z)
  273.     {
  274.         X/= Z;
  275.         Y/= Z;
  276.         U/= Z;
  277.         V/= Z;
  278.  
  279. #if OBJ_VTX_TEX3D == TRUE
  280.         TEX3D/= Z;
  281. #endif
  282.  
  283. #if OBJ_VTX_W == TRUE
  284.         W/= Z;
  285. #endif
  286.  
  287. #if OBJ_VTX_COLOR == TRUE
  288.         COLOR.r/= Z;
  289.         COLOR.g/= Z;
  290.         COLOR.b/= Z;
  291.         COLOR.a/= Z;
  292. #endif
  293.  
  294. #if OBJ_VTX_SPEC == TRUE
  295.         SPEC.r/= Z;
  296.         SPEC.g/= Z;
  297.         SPEC.b/= Z;
  298. #endif
  299.  
  300. #if OBJ_VTX_L == TRUE
  301.         L/= Z;
  302. #endif
  303.  
  304.         Z = 1.0;
  305.  
  306.         return TRUE;
  307.     }
  308.     else return FALSE;
  309. }
  310.  
  311.  
  312. void GVertex::operator=(GVertex &b)
  313. {
  314. //    memcpy((void*)this, &b, sizeof (class GVertex));
  315.         X = b.X;
  316.         Y = b.Y;
  317.         Z = b.Z;
  318.         U = b.U;
  319.         V = b.V;
  320.  
  321. #if OBJ_VTX_TEX3D == TRUE
  322.         TEX3D = b.TEX3D;
  323. #endif
  324.  
  325. #if OBJ_VTX_W == TRUE
  326.         W = b.W;
  327. #endif
  328.  
  329. #if OBJ_VTX_COLOR == TRUE
  330.         COLOR.r = b.COLOR.r;
  331.         COLOR.g = b.COLOR.g;
  332.         COLOR.b = b.COLOR.b;
  333.         COLOR.a = b.COLOR.a;
  334. #endif
  335.  
  336. #if OBJ_VTX_SPEC == TRUE
  337.         SPEC.r = b.SPEC.r;
  338.         SPEC.g = b.SPEC.g;
  339.         SPEC.b = b.SPEC.b;
  340. #endif
  341.  
  342. #if OBJ_VTX_L == TRUE
  343.         L = b.L;
  344. #endif
  345.  
  346. }
  347.  
  348. #endif /* GVERTEXMET */
  349.