erebus
view liberebus/src/object.cc @ 18:09028848f276
- implemented Box object intersection
- implemented interactive camera manipulation
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 26 May 2014 23:34:12 +0300 |
parents | a932848de652 |
children | 56d504cc555a |
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 Vector3 RayHit::calc_normal() const
14 {
15 assert(obj->get_type() == ObjType::geom);
16 Vector3 norm = ((const GeomObject*)obj)->calc_normal(*this);
18 const Matrix4x4 &xform = node->get_inv_matrix();
19 return norm.transformed(Matrix3x3(xform).transposed());
20 }
22 Vector3 RayHit::calc_tangent() const
23 {
24 assert(obj->get_type() == ObjType::geom);
25 Vector3 tang = ((const GeomObject*)obj)->calc_tangent(*this);
27 const Matrix4x4 &xform = node->get_matrix();
28 return tang.transformed(Matrix3x3(xform).transposed());
29 }
31 Vector2 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 }