|
|
|
@ -62,6 +62,51 @@ Punkt3D Sphere::getPos() const {
|
|
|
|
|
return pos;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Sphere::getIntersectionParam(const Ray &ray, float *param1, float *param2) {
|
|
|
|
|
int numerg;
|
|
|
|
|
// ax^2 + bx + c = 0
|
|
|
|
|
segl::Punkt3D ehv(1.0f, 1.0f, 1.0f);
|
|
|
|
|
float a = ray.dir*ehv;
|
|
|
|
|
float b = 2*(ray.pos*ehv + pos*ehv);
|
|
|
|
|
float c = ray.pos*ray.pos + pos*pos - 2*(ray.pos*pos) - radius*radius;
|
|
|
|
|
|
|
|
|
|
float p = b/a;
|
|
|
|
|
float q = c/a;
|
|
|
|
|
|
|
|
|
|
if((p*p)/4.0f<q) {
|
|
|
|
|
numerg = 0;
|
|
|
|
|
} else if((p*p)/4.0f==q) {
|
|
|
|
|
numerg = 1;
|
|
|
|
|
if(param1!=0) {
|
|
|
|
|
*param1 = -p/2.0f;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
numerg = 2;
|
|
|
|
|
if(param1!=0 || param2!=0) {
|
|
|
|
|
if(param1!=0) {
|
|
|
|
|
*param1 = -p/2.0f + sqrt(((p*p)/4.0f)-q);
|
|
|
|
|
}
|
|
|
|
|
if(param2!=0) {
|
|
|
|
|
*param2 = -p/2.0f - sqrt(((p*p)/4.0f)-q);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return numerg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int Sphere::getIntersectionPoints(const Ray &ray, segl::Punkt3D *a, segl::Punkt3D *b) {
|
|
|
|
|
float pa, pb;
|
|
|
|
|
int numerg = getIntersectionParam(ray, &pa, &pb);
|
|
|
|
|
if(a)
|
|
|
|
|
*a = ray.get(pa);
|
|
|
|
|
|
|
|
|
|
if(b)
|
|
|
|
|
*b = ray.get(pb);
|
|
|
|
|
|
|
|
|
|
return numerg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ray::Ray() {
|
|
|
|
|
dir.set(0.0f, 1.0f, 0.0f);
|
|
|
|
|
}
|
|
|
|
@ -139,14 +184,6 @@ float Ray::dist(Punkt3D p) const {
|
|
|
|
|
return abs(p - get( getParam(p) ));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int getIntersectionParam(const Ray &ray, float *param1, float *param2) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int getIntersectionParam(const Ray &ray, segl::Punkt3D *a, segl::Punkt3D *b) {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float Ray::getParam(Punkt3D p, bool onray) const {
|
|
|
|
|
if(onray) {
|
|
|
|
|
if(!onRay(p))
|
|
|
|
|