108 lines
2.5 KiB
C++
108 lines
2.5 KiB
C++
/* 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;
|
|
|
|
bool inSphere(Punkt3D p) const;
|
|
Punkt3D getPos() const;
|
|
};
|
|
|
|
class Ray {
|
|
public:
|
|
Punkt3D pos;
|
|
Punkt3D dir;
|
|
|
|
Ray();
|
|
Ray(Punkt3D _pos, Punkt3D _dir);
|
|
|
|
void set(Punkt3D _pos, Punkt3D _dir);
|
|
Punkt3D get(float x);
|
|
bool onRay(Punkt3D p, int rnd=-1);
|
|
float dist(Punkt3D p);
|
|
float getParam(Punkt3D p, bool onray=false);
|
|
|
|
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;
|
|
|
|
float dist(Punkt3D p) const;
|
|
};
|
|
|
|
} // namespace segl
|
|
|
|
#endif
|