erebus
annotate liberebus/src/object.cc @ 46:c4d48a21bc4a
in the middle of the vmath->gph-math port
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 24 Feb 2016 00:26:50 +0200 |
parents | 56d504cc555a |
children |
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@46 | 13 Vec3 RayHit::calc_normal() const |
nuclear@17 | 14 { |
nuclear@17 | 15 assert(obj->get_type() == ObjType::geom); |
nuclear@46 | 16 Vec3 norm = ((const GeomObject*)obj)->calc_normal(*this); |
nuclear@17 | 17 |
nuclear@46 | 18 const Mat4x4 &xform = node->get_inv_matrix(); |
nuclear@46 | 19 return norm.transformed(Mat3x3(xform).transposed()).normalized(); |
nuclear@17 | 20 } |
nuclear@17 | 21 |
nuclear@46 | 22 Vec3 RayHit::calc_tangent() const |
nuclear@17 | 23 { |
nuclear@17 | 24 assert(obj->get_type() == ObjType::geom); |
nuclear@46 | 25 Vec3 tang = ((const GeomObject*)obj)->calc_tangent(*this); |
nuclear@17 | 26 |
nuclear@46 | 27 const Mat4x4 &xform = node->get_matrix(); |
nuclear@46 | 28 return tang.transformed(Mat3x3(xform).transposed()); |
nuclear@17 | 29 } |
nuclear@17 | 30 |
nuclear@46 | 31 Vec2 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 } |