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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. int getIntersectionParam(const Ray &ray, float *param1, float *param2);
  41. int getIntersectionPoints(const Ray &ray, segl::Punkt3D *a, segl::Punkt3D *b);
  42. bool inSphere(Punkt3D p) const;
  43. Punkt3D getPos() const;
  44. };
  45. class Ray {
  46. public:
  47. Punkt3D pos;
  48. Punkt3D dir;
  49. Ray();
  50. Ray(const Punkt3D &_pos, const Punkt3D &_dir);
  51. void set(const Punkt3D &_pos, const Punkt3D &_dir);
  52. void setFromPoints(const Punkt3D &a, const Punkt3D &b);
  53. Punkt3D get(float x) const;
  54. bool onRay(Punkt3D p, int rnd=-1) const;
  55. float dist(Punkt3D p) const;
  56. float getParam(Punkt3D p, bool onray=false) const;
  57. bool collision(const Sphere &s) const;
  58. bool collision(const Ray &r) const;
  59. bool collision(const Box & b) const;
  60. bool collision(const Plane &p) const;
  61. };
  62. class Box {
  63. public:
  64. Punkt3D min;
  65. Punkt3D max;
  66. Box();
  67. Box(Punkt3D _min, Punkt3D _max);
  68. bool collision(const Sphere &s) const;
  69. bool collision(const Ray &r) const;
  70. bool collision(const Box & b) const;
  71. bool collision(const Plane &p) const;
  72. };
  73. class Plane {
  74. public:
  75. Punkt3D pos;
  76. Punkt3D norm;
  77. Plane();
  78. Plane(Punkt3D _pos, Punkt3D _norm);
  79. Plane(float x, float y, float z, float a);
  80. bool collision(const Sphere &s) const;
  81. bool collision(const Ray &r) const;
  82. bool collision(const Box & b) const;
  83. bool collision(const Plane &p) const;
  84. bool onPlane(const Punkt3D &p) const;
  85. bool getIntersectionPoint(const Ray &r, Punkt3D *p) const;
  86. float dist(Punkt3D p) const;
  87. };
  88. } // namespace segl
  89. #endif