*/}}

la_tns_curve.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #include "la_5.h"
  2. /*
  3. NUL4.0 - Nick's Best - www.nicksbest.com
  4. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  5. @@ TNS OpenGL 2D/3D Rendering System @@
  6. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  7. @@ __ @@
  8. @@ ___--- | @@
  9. @@ __---- @@ || @@
  10. @@ _--- _ @@@ || @@
  11. @@ | @@@__ @@ || @@
  12. @@ | @@ #@@@#_ @@@ || @@
  13. @@ | @@ `#@@@@ @@ |_ @@
  14. @@ | @@ `#@@@@@_-- @@
  15. @@ | @@ _--' @@
  16. @@ | @@ _--- @@
  17. @@ | @@_--- @@
  18. @@ |_-- _ __ __ __ __@@
  19. @@ | Not Fancy @@
  20. @@ | But Easy @@
  21. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
  22. Author(s):WuYiming - xp8110@outlook.com
  23. Want to join the development?
  24. Append your name in the author list above.
  25. Send feedback to la_support@nicksbest.com
  26. */
  27. #include "la_tns.h"
  28. #include "la_util.h"
  29. #include <math.h>
  30. extern tnsMain *T;
  31. real tnsInterpolate(real L, real R, real T){
  32. return tnsLinearItp(L, R, T);
  33. }
  34. void tnsInterpolate2dv(real *L, real *R, real T, real *Result){
  35. Result[0] = tnsLinearItp(L[0], R[0], T);
  36. Result[1] = tnsLinearItp(L[1], R[1], T);
  37. }
  38. void tnsInterpolate3dv(real *L, real *R, real T, real *Result){
  39. Result[0] = tnsLinearItp(L[0], R[0], T);
  40. Result[1] = tnsLinearItp(L[1], R[1], T);
  41. Result[2] = tnsLinearItp(L[2], R[2], T);
  42. }
  43. //z3 = 1/( linearintp(1/z1),(1/z2),t )
  44. //L,R is GLocation
  45. void tnsInterpolatePerspective4dv(tnsVector4d LG, tnsVector4d RG, tnsVector4d L, tnsVector4d R, real T, tnsVector3d Result){
  46. ////real t = (w - L[3]) / (R[3] - L[3]);
  47. real z = 1 / tnsLinearItp(1 / L[2], 1 / R[2], T);
  48. ////Result[2] = tnsLinearItp(L[2] / L[3], R[2] / R[3], t)*w;
  49. ////Result[0] = tnsLinearItp(L[0] / L[3], R[0] / R[3], t)*w;
  50. ////Result[1] = tnsLinearItp(L[1] / L[3], R[1] / R[3], t)*w;
  51. Result[0] = tnsLinearItp(L[0] / L[2], R[0] / R[2], T) * z;
  52. Result[1] = tnsLinearItp(L[1] / L[2], R[1] / R[2], T) * z;
  53. Result[2] = z;
  54. //real x1z1 = LG[0] / LG[2], x2z2 = RG[0] / RG[2];
  55. //real x3 = tnsLinearItp(LG[0], RG[0], T);
  56. //real z3 = tnsLinearItp(LG[2], RG[2], T);
  57. //real t = (x3 / z3 - x1z1) / (x2z2 - x1z1);
  58. //Result[0] = tnsLinearItp(L[0], R[0], t);
  59. //Result[1] = tnsLinearItp(L[1], R[1], t);
  60. //Result[2] = tnsLinearItp(L[2], R[2], t);
  61. }
  62. tnsLineStrip *tnsCreateLineStrip(){
  63. tnsLineStrip *ls = CreateNew(tnsLineStrip);
  64. return ls;
  65. }
  66. tnsLineStripPoint *tnsAppendPoint(tnsLineStrip *ls, real X, real Y, real Z){
  67. tnsLineStripPoint *lsp = CreateNew(tnsLineStripPoint);
  68. lsp->P[0] = X;
  69. lsp->P[1] = Y;
  70. lsp->P[2] = Z;
  71. lstAppendItem(&ls->Points, lsp);
  72. ls->PointCount++;
  73. return lsp;
  74. }
  75. tnsLineStripPoint *tnsPushPoint(tnsLineStrip *ls, real X, real Y, real Z){
  76. tnsLineStripPoint *lsp = CreateNew(tnsLineStripPoint);
  77. lsp->P[0] = X;
  78. lsp->P[1] = Y;
  79. lsp->P[2] = Z;
  80. lstPushItem(&ls->Points, lsp);
  81. ls->PointCount++;
  82. return lsp;
  83. }
  84. void tnsRemovePoint(tnsLineStrip *ls, tnsLineStripPoint *lsp){
  85. lstRemoveItem(&ls->Points, lsp);
  86. FreeMem(lsp);
  87. }
  88. void tnsDestroyLineStrip(tnsLineStrip *ls){
  89. tnsLineStripPoint *lsp;
  90. while (lsp = lstPopItem(&ls->Points)){
  91. FreeMem(lsp);
  92. }
  93. FreeMem(ls);
  94. }