Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

iobject.h

Go to the documentation of this file.
00001 /*
00002     toxic - A Global Illumination Renderer
00003     Copyright (C) 2003-2004 Francois Beaune
00004     Contact: http://toxicengine.sourceforge.net/
00005 
00006     This file is part of toxic.
00007 
00008     toxic is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     toxic is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with toxic; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 */
00022 
00023 #ifndef TOXIC_RENDERER_IOBJECT_H
00024 #define TOXIC_RENDERER_IOBJECT_H
00025 
00026 #include "common/math/matrix4.h"
00027 #include "basis.h"
00028 #include "globals.h"
00029 
00030 namespace toxic {
00031 
00032     class Context;
00033     class Framebuffer;
00034     class Hit;
00035     class ICamera;
00036     class ISurfaceShader;
00037     class Ray;
00038     class Scene;
00039 
00040     class IObject : public Basis {
00041     public:
00042         enum IntersectionMask {
00043             INTERSECT_NO_RAYS = 0,
00044             INTERSECT_VISIBILITY_RAYS = 1,
00045             INTERSECT_PRIMARY_RAYS = 2,
00046             INTERSECT_REFLECTED_RAYS = 4,
00047             INTERSECT_SHADOW_RAYS = 8,
00048             INTERSECT_PHOTON_RAYS = 16,
00049             INTERSECT_PRIMARY_FG_RAYS = 32,
00050             INTERSECT_SECONDARY_FG_RAYS = 64,
00051             INTERSECT_AUTOFOCUS_RAYS = 128,
00052 
00053             //! Handy shortcut.
00054             INTERSECT_ALL_RAYS =
00055                 INTERSECT_VISIBILITY_RAYS |
00056                 INTERSECT_PRIMARY_RAYS |
00057                 INTERSECT_REFLECTED_RAYS |
00058                 INTERSECT_SHADOW_RAYS |
00059                 INTERSECT_PHOTON_RAYS |
00060                 INTERSECT_PRIMARY_FG_RAYS |
00061                 INTERSECT_SECONDARY_FG_RAYS |
00062                 INTERSECT_AUTOFOCUS_RAYS
00063         };
00064 
00065 #ifdef USE_MAILBOXES
00066         //!\todo Allocate one ray id per rendering thread.
00067         mutable int m_mailbox_ray_id;   //!< Id of the last ray tested against this object.
00068 #endif  // USE_MAILBOXES
00069 
00070         //! m is the object space to world space transformation matrix.
00071         //! The 'surface_shader' pointer may be null because some objects
00072         //! (like the Collection and Octree objects) don't need a shader.
00073         IObject(
00074             const sheep::Matrix4 &m,
00075             const ISurfaceShader *surface_shader = 0,
00076             IntersectionMask intersection_mask = INTERSECT_ALL_RAYS
00077         );
00078 
00079         virtual ~IObject() {}
00080 
00081         //! This method must be called only once, after the object is completely
00082         //! configured, and before it is used for the first time.
00083         virtual void Finalize(const Context &context) {}
00084 
00085         //! This method returns the number of objects contained into this object.
00086         //! For primitives, it returns 1. For composite objects (like the Collection
00087         //! object), it returns the number of child objects.
00088         virtual int GetObjectCount() const { return 1; }
00089 
00090         void SetSurfaceShader(const ISurfaceShader *surface_shader);
00091         const ISurfaceShader *GetSurfaceShader() const;
00092 
00093         //! This method returns true if the ray intersect the object, or false otherwise.
00094         //! If 'hit' is not null, intersection data are reported through the 'hit' parameter
00095         //! (only if an intersection has been found; if no intersection has been found, the
00096         //! 'hit' parameter is left unchanged). The ray is expressed in world space.
00097         virtual bool Intersect(
00098             const Context &context,
00099             const Ray &ray,
00100             Hit *hit = 0
00101         ) const = 0;
00102 
00103         virtual void Annotate(
00104             const Context &context,
00105             const ICamera *camera,
00106             Framebuffer *framebuffer
00107         ) const {}
00108 
00109     protected:
00110         const ISurfaceShader *m_surface_shader;
00111         IntersectionMask m_intersection_mask;
00112     };
00113 
00114 #include "iobject.inl"
00115 
00116 }
00117 
00118 #endif  // !TOXIC_RENDERER_IOBJECT_H

Generated on Tue May 11 01:31:50 2004 for toxic by doxygen 1.3.6