--- libgender/entity.h 2004/10/02 15:54:43 1.1 +++ libgender/entity.h 2004/10/03 01:14:40 1.3 @@ -21,18 +21,32 @@ struct point { GLfloat x, y, z; + + point () { }; + point (GLfloat x, GLfloat y, GLfloat z) : x(x), y(y), z(z) { }; }; struct colour { GLfloat r, g, b; + colour (GLfloat r = 1., GLfloat g = 1., GLfloat b = 1.) : r(r), g(g), b(b) { }; }; -struct vect { +struct vec3 { GLfloat x, y, z; + vec3 () { }; + vec3 (GLfloat x, GLfloat y, GLfloat z) : x(x), y(y), z(z) { }; + + const vec3 operator -() const + { return vec3 (-x, -y, -z); } }; +const vec3 cross (const vec3 &a, const vec3 &b); +GLfloat dot (const vec3 &a, const vec3 &b); + struct texc { - GLfloat u, v; + GLfloat s, t; + texc () { }; + texc (GLfloat s, GLfloat t) : s(s), t(t) { }; }; struct box { @@ -40,8 +54,8 @@ void reset () { - a.x = a.y = a.z = GLFLOAT_MAX; - b.x = b.y = b.z = GLFLOAT_MIN; + a = point (GLFLOAT_MAX, GLFLOAT_MAX, GLFLOAT_MAX); + b = point (GLFLOAT_MIN, GLFLOAT_MIN, GLFLOAT_MIN); } void add (const box &o); @@ -98,6 +112,7 @@ sector sec; void show (const sector &sec); + void show (); void draw (); }; @@ -106,15 +121,18 @@ }; struct vertex1d { - point v; // vertex colour c; // colour + point p; // vertex }; struct vertex2d { - point v; // vertex colour c; // colour - vect n; // normal + point p; // vertex + vec3 n; // normal texc t; // texture + + vertex2d () { }; + vertex2d (colour c, point p, vec3 n, texc t = texc()) : c(c), p(p), n(n), t(t) { }; }; template @@ -133,15 +151,36 @@ typedef entity_opengl1d entity_points; typedef entity_opengl1d entity_lines; -typedef entity_opengl1d entity_linestrip; -typedef entity_opengl1d entity_lineloop; +typedef entity_opengl1d entity_line_strip; +typedef entity_opengl1d entity_line_loop; typedef entity_opengl2d entity_triangles; -typedef entity_opengl2d entity_trianglestrip; -typedef entity_opengl2d entity_trianglefan; +typedef entity_opengl2d entity_triangle_strip; +typedef entity_opengl2d entity_triangle_fan; typedef entity_opengl2d entity_quads; typedef entity_opengl2d entity_quad_strip; typedef entity_opengl2d entity_polygon; +struct light { + point p; + colour c; + GLfloat intensity; + GLfloat radius; +}; + +struct draw_context { + enum { DEPTH, AMBIENT, LIGHTED } mode; + light *l; +}; + +struct view { + point p; + vec3 d, u; + float fov; + int w, h; + + void draw (const draw_context &c); +}; + #endif