/* libsegl - Sebas Extended GL Library * Collection of Opengl/3D-Math helpers * * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de * http://www.seba-geek.de * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301, USA. */ #ifndef __GEOTYPES_H #define __GEOTYPES_H #include "punkt3d.h" namespace segl { class Ray; class Box; class Plane; class Sphere { public: Punkt3D pos; float radius; Sphere(Punkt3D _pos, float radius); Sphere(); void set(Punkt3D _pos, float _radius); bool collision(const Sphere &s) const; bool collision(const Ray &r) const; bool collision(const Box & b) const; bool collision(const Plane &p) const; int getIntersectionParam(const Ray &ray, float *param1, float *param2); int getIntersectionPoints(const Ray &ray, segl::Punkt3D *a, segl::Punkt3D *b); bool inSphere(Punkt3D p) const; Punkt3D getPos() const; }; class Ray { public: Punkt3D pos; Punkt3D dir; Ray(); Ray(const Punkt3D &_pos, const Punkt3D &_dir); void set(const Punkt3D &_pos, const Punkt3D &_dir); void setFromPoints(const Punkt3D &a, const Punkt3D &b); Punkt3D get(float x) const; bool onRay(Punkt3D p, int rnd=-1) const; float dist(Punkt3D p) const; float getParam(Punkt3D p, bool onray=false) const; bool collision(const Sphere &s) const; bool collision(const Ray &r) const; bool collision(const Box & b) const; bool collision(const Plane &p) const; }; class Box { public: Punkt3D min; Punkt3D max; Box(); Box(Punkt3D _min, Punkt3D _max); bool collision(const Sphere &s) const; bool collision(const Ray &r) const; bool collision(const Box & b) const; bool collision(const Plane &p) const; }; class Plane { public: Punkt3D pos; Punkt3D norm; Plane(); Plane(Punkt3D _pos, Punkt3D _norm); Plane(float x, float y, float z, float a); bool collision(const Sphere &s) const; bool collision(const Ray &r) const; bool collision(const Box & b) const; bool collision(const Plane &p) const; bool onPlane(const Punkt3D &p) const; bool getIntersectionPoint(const Ray &r, Punkt3D *p) const; float dist(Punkt3D p) const; }; } // namespace segl #endif