erebus

view liberebus/src/object.cc @ 48:9971a08f4104

merged
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 24 Feb 2016 00:29:31 +0200
parents 56d504cc555a
children
line source
1 #include <assert.h>
2 #include "object.h"
3 #include "geomobj.h"
4 #include "snode.h"
6 RayHit::RayHit()
7 {
8 dist = 0;
9 node = 0;
10 obj = subobj = 0;
11 }
13 Vec3 RayHit::calc_normal() const
14 {
15 assert(obj->get_type() == ObjType::geom);
16 Vec3 norm = ((const GeomObject*)obj)->calc_normal(*this);
18 const Mat4x4 &xform = node->get_inv_matrix();
19 return norm.transformed(Mat3x3(xform).transposed()).normalized();
20 }
22 Vec3 RayHit::calc_tangent() const
23 {
24 assert(obj->get_type() == ObjType::geom);
25 Vec3 tang = ((const GeomObject*)obj)->calc_tangent(*this);
27 const Mat4x4 &xform = node->get_matrix();
28 return tang.transformed(Mat3x3(xform).transposed());
29 }
31 Vec2 RayHit::calc_texcoords() const
32 {
33 assert(obj->get_type() == ObjType::geom);
34 return ((const GeomObject*)obj)->calc_texcoords(*this);
35 }
38 Object::Object()
39 {
40 name = "<unnamed>";
41 }
43 ObjType Object::get_type() const
44 {
45 return ObjType::null;
46 }
48 void Object::set_name(const char *name)
49 {
50 this->name = name;
51 }
53 const char *Object::get_name() const
54 {
55 return name.c_str();
56 }
58 bool Object::intersect(const Ray &ray, RayHit *hit) const
59 {
60 return false;
61 }