Small OpenGL based c++ rendering library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

emath_opengl.cpp 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* libsegl - Sebas Extended GL Library
  2. * Collection of Opengl/3D-Math helpers
  3. *
  4. * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de
  5. * http://www.seba-geek.de
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Library General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Library General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public
  18. * License along with this library; if not, write to the
  19. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  20. * Boston, MA 02110-1301, USA.
  21. */
  22. #include "emath_opengl.h"
  23. namespace segl {
  24. void rotFrom2VecTo2Vec(Punkt3D a, Punkt3D b, Punkt3D c, Punkt3D d, Punkt3D *rvec, float *rvecdeg, Punkt3D *rvec2, float *rvecdeg2) {
  25. Punkt3D rotvec, rotvec2, nullvec;
  26. float rotvecdeg = 0.0f, rotvecdeg2 = 0.0f;
  27. rotvec = a.kreuzprodukt(b);
  28. rotvecdeg = a.calcAngle(b);
  29. if(std::abs(rotvecdeg)==180.0f) {
  30. rotvec = a.getOrtographic();
  31. }
  32. if(rotvec==nullvec) {
  33. rotvec.set(1.0f, 0.0f, 0.0f);
  34. rotvecdeg = 0.0f;
  35. }
  36. Rotationsmatrix rotnobj(rotvec, -rotvecdeg);
  37. c = Rotationsmatrix(rotvec, rotvecdeg) * c;
  38. rotvec2 = c.kreuzprodukt(d);
  39. rotvecdeg2 = c.calcAngle(d);
  40. if(std::abs(rotvecdeg2)==180.0f) {
  41. rotvec2 = b;
  42. }
  43. if(rotvec2==nullvec) {
  44. rotvec2.set(1.0f, 0.0f, 0.0f);
  45. rotvecdeg2 = 0.0f;
  46. }
  47. rotvec2 = rotnobj * rotvec2;
  48. *rvec = rotvec;
  49. *rvecdeg = rotvecdeg;
  50. *rvec2 = rotvec2;
  51. *rvecdeg2 = rotvecdeg2;
  52. }
  53. void rotFrom2VecTo2Vec(Punkt3D a, Punkt3D b, Punkt3D c, Punkt3D d) {
  54. Punkt3D rvec, rvec2;
  55. float rvecdeg, rvecdeg2;
  56. rotFrom2VecTo2Vec(a, b, c, d, &rvec, &rvecdeg, &rvec2, &rvecdeg2);
  57. // if(rvecdeg)
  58. glRotatef(rvecdeg, rvec);
  59. // if(rvecdeg2)
  60. glRotatef(rvecdeg2, rvec2);
  61. // std::cout << rvecdeg << ", " << rvecdeg2 << std::endl;
  62. // rvec.print("rvecdeg");
  63. // rvec2.print("rvecdeg2");
  64. }
  65. void rotvec2(Punkt3D a, Punkt3D b, Punkt3D c, Punkt3D d, float *dega, Punkt3D *veca, float *degb, Punkt3D *vecb) {
  66. *dega = a.calcAngle(b);
  67. if(*dega==180.0f)
  68. *veca = a.getOrtographic();
  69. else if(*dega==0.0f)
  70. veca->set(1.0f, 0.0f, 0.0f);
  71. else
  72. *veca = a.kreuzprodukt(b);
  73. *degb = 0.0f;
  74. vecb->set(1.0f, 0.0f, 0.0f);
  75. c = Rotationsmatrix(*veca, *dega) * c;
  76. *degb = c.calcAngle(d);
  77. if(*degb==180.0f)
  78. *vecb = c.getOrtographic();
  79. else if(*degb==0.0f)
  80. vecb->set(1.0f, 0.0f, 0.0f);
  81. else
  82. *vecb = c.kreuzprodukt(d);
  83. }
  84. } // namespace segl