erebus

annotate liberebus/src/object.cc @ 47:4b91c9a501d8

minor fix of strange code structure in the thread func
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 01 Feb 2016 14:56:15 +0200
parents e9da2916bc79
children c4d48a21bc4a
rev   line source
nuclear@17 1 #include <assert.h>
nuclear@2 2 #include "object.h"
nuclear@17 3 #include "geomobj.h"
nuclear@17 4 #include "snode.h"
nuclear@17 5
nuclear@17 6 RayHit::RayHit()
nuclear@17 7 {
nuclear@17 8 dist = 0;
nuclear@17 9 node = 0;
nuclear@17 10 obj = subobj = 0;
nuclear@17 11 }
nuclear@17 12
nuclear@17 13 Vector3 RayHit::calc_normal() const
nuclear@17 14 {
nuclear@17 15 assert(obj->get_type() == ObjType::geom);
nuclear@17 16 Vector3 norm = ((const GeomObject*)obj)->calc_normal(*this);
nuclear@17 17
nuclear@17 18 const Matrix4x4 &xform = node->get_inv_matrix();
nuclear@23 19 return norm.transformed(Matrix3x3(xform).transposed()).normalized();
nuclear@17 20 }
nuclear@17 21
nuclear@17 22 Vector3 RayHit::calc_tangent() const
nuclear@17 23 {
nuclear@17 24 assert(obj->get_type() == ObjType::geom);
nuclear@17 25 Vector3 tang = ((const GeomObject*)obj)->calc_tangent(*this);
nuclear@17 26
nuclear@17 27 const Matrix4x4 &xform = node->get_matrix();
nuclear@17 28 return tang.transformed(Matrix3x3(xform).transposed());
nuclear@17 29 }
nuclear@17 30
nuclear@17 31 Vector2 RayHit::calc_texcoords() const
nuclear@17 32 {
nuclear@17 33 assert(obj->get_type() == ObjType::geom);
nuclear@17 34 return ((const GeomObject*)obj)->calc_texcoords(*this);
nuclear@17 35 }
nuclear@17 36
nuclear@2 37
nuclear@2 38 Object::Object()
nuclear@2 39 {
nuclear@2 40 name = "<unnamed>";
nuclear@2 41 }
nuclear@2 42
nuclear@2 43 ObjType Object::get_type() const
nuclear@2 44 {
nuclear@2 45 return ObjType::null;
nuclear@2 46 }
nuclear@2 47
nuclear@2 48 void Object::set_name(const char *name)
nuclear@2 49 {
nuclear@2 50 this->name = name;
nuclear@2 51 }
nuclear@2 52
nuclear@2 53 const char *Object::get_name() const
nuclear@2 54 {
nuclear@2 55 return name.c_str();
nuclear@2 56 }
nuclear@2 57
nuclear@2 58 bool Object::intersect(const Ray &ray, RayHit *hit) const
nuclear@2 59 {
nuclear@2 60 return false;
nuclear@2 61 }