dbf-halloween2015
diff src/object.h @ 0:50683c78264e
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 01 Nov 2015 00:09:12 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/object.h Sun Nov 01 00:09:12 2015 +0200 1.3 @@ -0,0 +1,64 @@ 1.4 +#ifndef OBJECT_H_ 1.5 +#define OBJECT_H_ 1.6 + 1.7 +#include "mesh.h" 1.8 +#include "geom.h" 1.9 +#include "vmath/vmath.h" 1.10 + 1.11 +struct Material { 1.12 + Vector3 diffuse; 1.13 + Vector3 specular; 1.14 + float shininess; 1.15 + float alpha; 1.16 + 1.17 + Material(); 1.18 +}; 1.19 + 1.20 +struct RenderOps { 1.21 + bool zwrite; 1.22 + bool cast_shadows; 1.23 + bool transparent; 1.24 + 1.25 + RenderOps(); 1.26 + void setup() const; 1.27 +}; 1.28 + 1.29 +class Object { 1.30 +private: 1.31 + Mesh *mesh; 1.32 + Matrix4x4 matrix; 1.33 + unsigned int tex; 1.34 + Matrix4x4 tex_matrix; 1.35 + unsigned int sdr; 1.36 + 1.37 +public: 1.38 + Material mtl; 1.39 + RenderOps rop; 1.40 + 1.41 + Object(); 1.42 + ~Object(); 1.43 + 1.44 + Matrix4x4 &xform(); 1.45 + const Matrix4x4 &xform() const; 1.46 + 1.47 + Matrix4x4 &tex_xform(); 1.48 + const Matrix4x4 &tex_xform() const; 1.49 + 1.50 + void set_mesh(Mesh *m); 1.51 + Mesh *get_mesh() const; 1.52 + 1.53 + void set_texture(unsigned int tex); 1.54 + unsigned int get_texture() const; 1.55 + void set_shader(unsigned int sdr); 1.56 + unsigned int get_shader() const; 1.57 + 1.58 + void draw() const; 1.59 + void draw_wire(const Vector4 &col = Vector4(1, 1, 1, 1)) const; 1.60 + void draw_vertices(const Vector4 &col = Vector4(1, 0.3, 0.2, 1)) const; 1.61 + void draw_normals(float len = 1.0, const Vector4 &col = Vector4(0.1, 0.2, 1.0, 1)) const; 1.62 + void draw_tangents(float len = 1.0, const Vector4 &col = Vector4(0.1, 1.0, 0.2, 1)) const; 1.63 + 1.64 + bool intersect(const Ray &ray, HitPoint *hit) const; 1.65 +}; 1.66 + 1.67 +#endif // OBJECT_H_