From 801a164446c28d8c14a8da7ce4f5f6b9e505e593 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 21 Sep 2009 23:36:56 +0200 Subject: [PATCH] Updated geotypes, sphereintersection still broken --- geotypes.cpp | 24 ++++++++++++++++-------- geotypes.h | 14 +++++++------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/geotypes.cpp b/geotypes.cpp index bb08484..0f5c4f9 100644 --- a/geotypes.cpp +++ b/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; diff --git a/geotypes.h b/geotypes.h index a00d275..0631dd8 100644 --- a/geotypes.h +++ b/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;