erebus
diff liberebus/src/object.cc @ 17:e9da2916bc79
fixed the normal bug
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 26 May 2014 05:41:28 +0300 |
parents | a932848de652 |
children | 56d504cc555a |
line diff
1.1 --- a/liberebus/src/object.cc Sun May 25 02:23:39 2014 +0300 1.2 +++ b/liberebus/src/object.cc Mon May 26 05:41:28 2014 +0300 1.3 @@ -1,4 +1,39 @@ 1.4 +#include <assert.h> 1.5 #include "object.h" 1.6 +#include "geomobj.h" 1.7 +#include "snode.h" 1.8 + 1.9 +RayHit::RayHit() 1.10 +{ 1.11 + dist = 0; 1.12 + node = 0; 1.13 + obj = subobj = 0; 1.14 +} 1.15 + 1.16 +Vector3 RayHit::calc_normal() const 1.17 +{ 1.18 + assert(obj->get_type() == ObjType::geom); 1.19 + Vector3 norm = ((const GeomObject*)obj)->calc_normal(*this); 1.20 + 1.21 + const Matrix4x4 &xform = node->get_inv_matrix(); 1.22 + return norm.transformed(Matrix3x3(xform).transposed()); 1.23 +} 1.24 + 1.25 +Vector3 RayHit::calc_tangent() const 1.26 +{ 1.27 + assert(obj->get_type() == ObjType::geom); 1.28 + Vector3 tang = ((const GeomObject*)obj)->calc_tangent(*this); 1.29 + 1.30 + const Matrix4x4 &xform = node->get_matrix(); 1.31 + return tang.transformed(Matrix3x3(xform).transposed()); 1.32 +} 1.33 + 1.34 +Vector2 RayHit::calc_texcoords() const 1.35 +{ 1.36 + assert(obj->get_type() == ObjType::geom); 1.37 + return ((const GeomObject*)obj)->calc_texcoords(*this); 1.38 +} 1.39 + 1.40 1.41 Object::Object() 1.42 {