gpuray_glsl

view src/plane.cc @ 4:2ed3da7dc0bc

broken
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 10 Nov 2014 01:26:00 +0200
parents
children
line source
1 #include "plane.h"
3 Plane::Plane()
4 : normal(0.0, 1.0, 0.0)
5 {
6 dist = 0.0;
7 }
9 Plane::Plane(const Vector3 &norm, float dist)
10 : normal(norm)
11 {
12 normal.normalize();
13 this->dist = dist;
14 }
16 bool Plane::intersect(const Ray &inray, HitPoint *pt) const
17 {
18 Ray ray = inray.transformed(inv_xform);
20 float ndotdir = dot_product(normal, ray.dir);
21 if(fabs(ndotdir) < 1e-5) {
22 return false; // ray parallel to the plane
23 }
25 Vector3 planept = normal * dist;
26 Vector3 pptdir = planept - ray.origin;
28 float t = dot_product(normal, pptdir) / ndotdir;
29 if(t < 1e-4) {
30 return false; // discard intersections behind the origin
31 }
33 // fill the HitPoint structure
34 pt->obj = this;
35 pt->dist = t;
37 pt->pos = ray.origin + ray.dir * t;
39 pt->texcoord.x = pt->pos.x;
40 pt->texcoord.y = pt->pos.z;
42 pt->pos.transform(xform);
43 pt->normal = normal.transformed(dir_xform);//.normalized();
44 return true;
45 }