erebus
view liberebus/src/object.cc @ 23:56d504cc555a
- debugging scale factor for render size
- fixed un-normalized normals after transforms in the SceneNode
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Thu, 29 May 2014 07:47:52 +0300 |
parents | e9da2916bc79 |
children | c4d48a21bc4a |
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()).normalized();
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 }