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