#ifndef polyhedron_h #define polyhedron_h #include <iostream.h> #include "groupobject.h" class rtl_polyhedron; class rtl_triangle : public rtl_groupmem { public: rtl_triangle( rtl_polyhedron*, jUInt, jUInt, jUInt ); jInt vertex( jByte i ) const { return p[i]; } rtl_material* material(); void backrtl_materialindex( jInt i ) { bm_idx = i; } protected: rtl_polyhedron* poly() { return (rtl_polyhedron*)mobj; } const rtl_polyhedron* poly() const { return (rtl_polyhedron*)mobj; } jFlt intersect( const rtl_ray&, bool = false ); bool volintersect( const jBBox& ) const; jNorm3 normal(); jNorm3 N; jInt bm_idx; jByte i1,i2; jFlt d; jUInt p[3]; }; class rtl_polyhedron : public rtl_groupobj { public: enum VertexOrder { cw, ccw }; /* Reads a polyhedron from the given stream. The format is:<br> <dd>int:#materials int:#vertices int:#polygons <dd>material* <dd>vertex* <dd>polygon* <p> A vertex is float:x float:y float:z float:u float:v int:front-mat int:back-mat<br> A polygon is int:p0 int:p1 int:p2<p> Vertex normals are inferred by the average of the face normals for the polys that use it. */ // rtl_polyhedron( istream& ); rtl_polyhedron( jInt v_cnt, VertexOrder = cw ); rtl_polyhedron( rtl_polyhedron* ); ~rtl_polyhedron(); void addvertex( jInt, jFlt, jFlt, jFlt, jFlt=0, jFlt=0, jInt=-1, jInt=-1 ); void setnormal( jInt, jFlt, jFlt, jFlt ); void computenormals(); rtl_material* material() { return (last_hit ? last_hit->material() : rtl_object::material()); } void scale( bool = false ); jVec3& getVertex( int i ) { return v_tbl[i].os; } int vertexCount() const { return v_cnt; } Type type() const { return objPolyhedron; } protected: jFlt intersect( const rtl_ray&, bool = false ); bool volintersect( const jBBox& box ) const { return voxel->volume().intersect(box); } jVec2 uv( const jVec3& ); void setMaterial( rtl_material* ); struct vertex { jVec3 os; jVec2 ts; jVec3 n; // normal but must be a vector jInt fmi, bmi; jByte acomp; }; int v_cnt; vertex* v_tbl; rtl_material imat; VertexOrder v_ord; private: jFlt alpha,beta,gamma,ray_t; bool backside; friend class rtl_triangle; }; #endif