*/}}

la_tns_curve.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. //z3 = 1/( linearintp(1/z1),(1/z2),t )
  32. //L,R is GLocation
  33. void tnsInterpolatePerspective4dv(tnsVector4d LG, tnsVector4d RG, tnsVector4d L, tnsVector4d R, real T, tnsVector3d Result){
  34. ////real t = (w - L[3]) / (R[3] - L[3]);
  35. real z = 1 / tnsLinearItp(1 / L[2], 1 / R[2], T);
  36. ////Result[2] = tnsLinearItp(L[2] / L[3], R[2] / R[3], t)*w;
  37. ////Result[0] = tnsLinearItp(L[0] / L[3], R[0] / R[3], t)*w;
  38. ////Result[1] = tnsLinearItp(L[1] / L[3], R[1] / R[3], t)*w;
  39. Result[0] = tnsLinearItp(L[0] / L[2], R[0] / R[2], T) * z;
  40. Result[1] = tnsLinearItp(L[1] / L[2], R[1] / R[2], T) * z;
  41. Result[2] = z;
  42. //real x1z1 = LG[0] / LG[2], x2z2 = RG[0] / RG[2];
  43. //real x3 = tnsLinearItp(LG[0], RG[0], T);
  44. //real z3 = tnsLinearItp(LG[2], RG[2], T);
  45. //real t = (x3 / z3 - x1z1) / (x2z2 - x1z1);
  46. //Result[0] = tnsLinearItp(L[0], R[0], t);
  47. //Result[1] = tnsLinearItp(L[1], R[1], t);
  48. //Result[2] = tnsLinearItp(L[2], R[2], t);
  49. }
  50. tnsLineStrip *tnsCreateLineStrip(){
  51. tnsLineStrip *ls = CreateNew(tnsLineStrip);
  52. return ls;
  53. }
  54. tnsLineStripPoint *tnsAppendPoint(tnsLineStrip *ls, real X, real Y, real Z){
  55. tnsLineStripPoint *lsp = CreateNew(tnsLineStripPoint);
  56. lsp->P[0] = X;
  57. lsp->P[1] = Y;
  58. lsp->P[2] = Z;
  59. lstAppendItem(&ls->Points, lsp);
  60. ls->PointCount++;
  61. return lsp;
  62. }
  63. tnsLineStripPoint *tnsPushPoint(tnsLineStrip *ls, real X, real Y, real Z){
  64. tnsLineStripPoint *lsp = CreateNew(tnsLineStripPoint);
  65. lsp->P[0] = X;
  66. lsp->P[1] = Y;
  67. lsp->P[2] = Z;
  68. lstPushItem(&ls->Points, lsp);
  69. ls->PointCount++;
  70. return lsp;
  71. }
  72. void tnsRemovePoint(tnsLineStrip *ls, tnsLineStripPoint *lsp){
  73. lstRemoveItem(&ls->Points, lsp);
  74. FreeMem(lsp);
  75. }
  76. void tnsDestroyLineStrip(tnsLineStrip *ls){
  77. tnsLineStripPoint *lsp;
  78. while (lsp = lstPopItem(&ls->Points)){
  79. FreeMem(lsp);
  80. }
  81. FreeMem(ls);
  82. }