*/}}
1
0

la_tns_curve.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * LaGUI: A graphical application framework.
  3. * Copyright (C) 2022-2023 Wu Yiming
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "la_5.h"
  19. #include "la_tns.h"
  20. #include "la_util.h"
  21. #include <math.h>
  22. extern tnsMain *T;
  23. //z3 = 1/( linearintp(1/z1),(1/z2),t )
  24. //L,R is GLocation
  25. void tnsInterpolatePerspective4dv(tnsVector4d LG, tnsVector4d RG, tnsVector4d L, tnsVector4d R, real T, tnsVector3d Result){
  26. ////real t = (w - L[3]) / (R[3] - L[3]);
  27. real z = 1 / tnsLinearItp(1 / L[2], 1 / R[2], T);
  28. ////Result[2] = tnsLinearItp(L[2] / L[3], R[2] / R[3], t)*w;
  29. ////Result[0] = tnsLinearItp(L[0] / L[3], R[0] / R[3], t)*w;
  30. ////Result[1] = tnsLinearItp(L[1] / L[3], R[1] / R[3], t)*w;
  31. Result[0] = tnsLinearItp(L[0] / L[2], R[0] / R[2], T) * z;
  32. Result[1] = tnsLinearItp(L[1] / L[2], R[1] / R[2], T) * z;
  33. Result[2] = z;
  34. //real x1z1 = LG[0] / LG[2], x2z2 = RG[0] / RG[2];
  35. //real x3 = tnsLinearItp(LG[0], RG[0], T);
  36. //real z3 = tnsLinearItp(LG[2], RG[2], T);
  37. //real t = (x3 / z3 - x1z1) / (x2z2 - x1z1);
  38. //Result[0] = tnsLinearItp(L[0], R[0], t);
  39. //Result[1] = tnsLinearItp(L[1], R[1], t);
  40. //Result[2] = tnsLinearItp(L[2], R[2], t);
  41. }
  42. tnsLineStrip *tnsCreateLineStrip(){
  43. tnsLineStrip *ls = CreateNew(tnsLineStrip);
  44. return ls;
  45. }
  46. tnsLineStripPoint *tnsAppendPoint(tnsLineStrip *ls, real X, real Y, real Z){
  47. tnsLineStripPoint *lsp = CreateNew(tnsLineStripPoint);
  48. lsp->P[0] = X;
  49. lsp->P[1] = Y;
  50. lsp->P[2] = Z;
  51. lstAppendItem(&ls->Points, lsp);
  52. ls->PointCount++;
  53. return lsp;
  54. }
  55. tnsLineStripPoint *tnsPushPoint(tnsLineStrip *ls, real X, real Y, real Z){
  56. tnsLineStripPoint *lsp = CreateNew(tnsLineStripPoint);
  57. lsp->P[0] = X;
  58. lsp->P[1] = Y;
  59. lsp->P[2] = Z;
  60. lstPushItem(&ls->Points, lsp);
  61. ls->PointCount++;
  62. return lsp;
  63. }
  64. void tnsRemovePoint(tnsLineStrip *ls, tnsLineStripPoint *lsp){
  65. lstRemoveItem(&ls->Points, lsp);
  66. FreeMem(lsp);
  67. }
  68. void tnsDestroyLineStrip(tnsLineStrip *ls){
  69. tnsLineStripPoint *lsp;
  70. while (lsp = lstPopItem(&ls->Points)){
  71. FreeMem(lsp);
  72. }
  73. FreeMem(ls);
  74. }