#ifndef world_h #define world_h #include <jgl/image.h> #include "voxel.h" #include "illumination.h" #include "ray.h" #include "flags.h" #include "texture.h" #include "material.h" class rtl_world { public: rtl_world( jFlt = 45.0, jFlt = 1000 ); virtual void raytrace( jImage&, jInt=-1, jInt=-1, jInt=-1, jInt=-1 ); virtual void raytrace( jUInt, jUInt, jImage&, jInt=-1, jInt=-1, jInt=-1, jInt=-1 ); jInt screenX() const { return sx; } jInt screenY() const { return sy; } void lookat( const jVec3&, const jVec3&, const jNorm3& ); const jVec3& camera() const { return viewpos; } void identity(); void translate( jFlt, jFlt, jFlt ); void scale( jFlt, jFlt, jFlt ); void rotate( int, jFlt ); void matrix( const jMat4& ); void push(); void pop(); void material( rtl_material* ); rtl_material* material(); void texture( rtl_texture* ); rtl_texture* texture(); const jMat4& top() const; enum composite { Union, Intersection, Difference }; void begin( composite ); rtl_object* end( jULng = 0 ); void add( rtl_object*, jULng = 0 ); void illumination( rtl_illumination& ); void illumination( rtl_illumination* ); rtl_illumination* illumination() { return I; } const jColour& ambient() const { return amb; } void ambient( const jColour& _amb ) { amb = _amb; } jFlt inifinity() const { return inf; } jFlt fieldofview() const { return fov; } void fieldofview( jFlt _fov ) { fov = deg2rad(_fov); } const jBBox& bounds() const { return voxel.box; } rtl_voxel* voxelspace() { return &voxel; } void progress( bool(*)(int,int,void*), void* ); const rtl_flags& flags() const { return f; } rtl_flags& flags() { return f; } static const jULng ShowProgress; static const jULng InColour; static rtl_world* current; struct viewinfo { /// width of the viewplane. jInt dx; /// height of the viewplane. jInt dy; /// Aspect ratio of the viewplane. jFlt ar; /// screen height in world space coordinates. jFlt sh; /// screen width in world space coordinates. jFlt sw; /// pixel width in world space coordinates. jFlt pw; /// pixel height in world space coordinates. jFlt ph; /// World space x-coordinate of the origin of the viewplane. jFlt ox; /// World space y-coordinate of the origin of the viewplane. jFlt oy; }; viewinfo* initView( jInt, jInt ); bool shoot( viewinfo*, jInt, jInt, jColour&, jVec3& ); void killViewInfo( viewinfo* ); private: jVec3 viewpos; rtl_voxel voxel; rtl_illumination* I; jFlt fov,inf; jInt sx,sy; jMat4 T,L; rtl_material* mat; rtl_texture* tex; rtl_object *l, *r; composite cot; jColour amb; jUInt objcnt; rtl_flags f; bool(*progressproc)(int,int,void*); void* ppdta; struct csg_stack { csg_stack( composite, rtl_object*, rtl_object*, csg_stack* ); composite cot; rtl_object *l, *r; csg_stack* prev; } *cstack; struct mtl_stack { mtl_stack( const jMat4&, rtl_material*, rtl_texture*, mtl_stack* ); jMat4 T; rtl_material* mat; rtl_texture* tex; mtl_stack* prev; } *mstack; jFlt ydist( jFlt*, jUInt ); friend class rtl_ray; }; #endif