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.

geotypes.h 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. #ifndef __GEOTYPES_H
  23. #define __GEOTYPES_H
  24. #include "punkt3d.h"
  25. namespace segl {
  26. class Ray;
  27. class Box;
  28. class Plane;
  29. class Sphere {
  30. public:
  31. Punkt3D pos;
  32. float radius;
  33. Sphere(Punkt3D _pos, float radius);
  34. Sphere();
  35. void set(Punkt3D _pos, float _radius);
  36. bool collision(const Sphere &s) const;
  37. bool collision(const Ray &r) const;
  38. bool collision(const Box & b) const;
  39. bool collision(const Plane &p) const;
  40. bool inSphere(Punkt3D p) const;
  41. Punkt3D getPos() const;
  42. };
  43. class Ray {
  44. public:
  45. Punkt3D pos;
  46. Punkt3D dir;
  47. Ray();
  48. Ray(Punkt3D _pos, Punkt3D _dir);
  49. void set(Punkt3D _pos, Punkt3D _dir);
  50. Punkt3D get(float x);
  51. bool onRay(Punkt3D p, int rnd=-1);
  52. float dist(Punkt3D p);
  53. float getParam(Punkt3D p, bool onray=false);
  54. bool collision(const Sphere &s) const;
  55. bool collision(const Ray &r) const;
  56. bool collision(const Box & b) const;
  57. bool collision(const Plane &p) const;
  58. };
  59. class Box {
  60. public:
  61. Punkt3D min;
  62. Punkt3D max;
  63. Box();
  64. Box(Punkt3D _min, Punkt3D _max);
  65. bool collision(const Sphere &s) const;
  66. bool collision(const Ray &r) const;
  67. bool collision(const Box & b) const;
  68. bool collision(const Plane &p) const;
  69. };
  70. class Plane {
  71. public:
  72. Punkt3D pos;
  73. Punkt3D norm;
  74. Plane();
  75. Plane(Punkt3D _pos, Punkt3D _norm);
  76. Plane(float x, float y, float z, float a);
  77. bool collision(const Sphere &s) const;
  78. bool collision(const Ray &r) const;
  79. bool collision(const Box & b) const;
  80. bool collision(const Plane &p) const;
  81. float dist(Punkt3D p) const;
  82. };
  83. } // namespace segl
  84. #endif