Updated geotypes, sphereintersection still broken
This commit is contained in:
parent
a9b6ce3000
commit
801a164446
24
geotypes.cpp
24
geotypes.cpp
|
@ -43,7 +43,7 @@ bool Sphere::collision(const Sphere &s) const {
|
|||
}
|
||||
|
||||
bool Sphere::collision(const Ray &r) const {
|
||||
return true;
|
||||
return (r.dist(pos) <= radius);
|
||||
}
|
||||
|
||||
bool Sphere::collision(const Box & b) const {
|
||||
|
@ -66,26 +66,26 @@ Ray::Ray() {
|
|||
dir.set(0.0f, 1.0f, 0.0f);
|
||||
}
|
||||
|
||||
Ray::Ray(Punkt3D _pos, Punkt3D _dir) {
|
||||
Ray::Ray(const Punkt3D &_pos, const Punkt3D &_dir) {
|
||||
set(_pos, _dir);
|
||||
}
|
||||
|
||||
void Ray::set(Punkt3D _pos, Punkt3D _dir) {
|
||||
void Ray::set(const Punkt3D &_pos, const Punkt3D &_dir) {
|
||||
pos = _pos;
|
||||
dir = _dir;
|
||||
}
|
||||
|
||||
void Ray::setFromPoints(Punkt3D a, Punkt3D b) {
|
||||
void Ray::setFromPoints(const Punkt3D &a, const Punkt3D &b) {
|
||||
pos = a;
|
||||
dir = b - a;
|
||||
}
|
||||
|
||||
Punkt3D Ray::get(float x) {
|
||||
Punkt3D Ray::get(float x) const {
|
||||
return pos + dir*x;
|
||||
}
|
||||
|
||||
// TODO: Heavy Testing
|
||||
bool Ray::onRay(Punkt3D p, int rnd) {
|
||||
bool Ray::onRay(Punkt3D p, int rnd) const {
|
||||
float r1 = 0.0f, r2 = 0.0f, r3 = 0.0f;
|
||||
short fcount = 0;
|
||||
bool g1=true, g2=true, g3=true;
|
||||
|
@ -135,11 +135,19 @@ bool Ray::onRay(Punkt3D p, int rnd) {
|
|||
return ((r1 == r2) == r3);
|
||||
}
|
||||
|
||||
float Ray::dist(Punkt3D p) {
|
||||
float Ray::dist(Punkt3D p) const {
|
||||
return abs(p - get( getParam(p) ));
|
||||
}
|
||||
|
||||
float Ray::getParam(Punkt3D p, bool onray) {
|
||||
int getIntersectionParam(const std::Ray &ray, float *param1, float *param2) {
|
||||
|
||||
}
|
||||
|
||||
int getIntersectionParam(const std::Ray &ray, segl::Punkt3D *a, segl::Punkt3D *b) {
|
||||
|
||||
}
|
||||
|
||||
float Ray::getParam(Punkt3D p, bool onray) const {
|
||||
if(onray) {
|
||||
if(!onRay(p))
|
||||
return 0.0f;
|
||||
|
|
14
geotypes.h
14
geotypes.h
|
@ -57,14 +57,14 @@ class Ray {
|
|||
Punkt3D dir;
|
||||
|
||||
Ray();
|
||||
Ray(Punkt3D _pos, Punkt3D _dir);
|
||||
Ray(const Punkt3D &_pos, const Punkt3D &_dir);
|
||||
|
||||
void set(Punkt3D _pos, Punkt3D _dir);
|
||||
void setFromPoints(Punkt3D a, Punkt3D b);
|
||||
Punkt3D get(float x);
|
||||
bool onRay(Punkt3D p, int rnd=-1);
|
||||
float dist(Punkt3D p);
|
||||
float getParam(Punkt3D p, bool onray=false);
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue