00001 /* 00002 * renderable.h 00003 * 00004 * Copyright (C) 2008,2009 Thomas A. Vaughan 00005 * All rights reserved. 00006 * 00007 * 00008 * Redistribution and use in source and binary forms, with or without 00009 * modification, are permitted provided that the following conditions are met: 00010 * * Redistributions of source code must retain the above copyright 00011 * notice, this list of conditions and the following disclaimer. 00012 * * Redistributions in binary form must reproduce the above copyright 00013 * notice, this list of conditions and the following disclaimer in the 00014 * documentation and/or other materials provided with the distribution. 00015 * * Neither the name of the <organization> nor the 00016 * names of its contributors may be used to endorse or promote products 00017 * derived from this software without specific prior written permission. 00018 * 00019 * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY 00020 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00021 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00022 * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY 00023 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00024 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00025 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00026 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00027 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 * 00030 * 00031 */ 00032 00033 #ifndef WAVE_GLUT_GLUT_RENDERABLE_H__ 00034 #define WAVE_GLUT_GLUT_RENDERABLE_H__ 00035 00036 // includes -------------------------------------------------------------------- 00037 #include "wave-glut.h" 00038 #include "camera.h" 00039 00040 #include "geometry/geometry_2d.h" 00041 #include "geometry/geometry_3d.h" 00042 #include "geometry/placement.h" 00043 00044 00045 namespace glut { 00046 00047 /// \ingroup glut 00048 /*@{*/ 00049 00050 typedef rect2d_t<int> recti_t; 00051 00052 00053 /// rendering context 00054 struct render_context_t { 00055 // constructor, manipulators 00056 render_context_t(void) throw() { this->clear(); } 00057 void clear(void) throw() { 00058 viewport.clear(); 00059 placement.clear(); 00060 viewer.clear(); 00061 camera.clear(); 00062 } 00063 00064 // data fields 00065 recti_t viewport; ///< where we draw on screen 00066 placement_t placement; ///< object position and orientation 00067 Viewer viewer; ///< viewer position and orientation 00068 camera_t camera; ///< camera information 00069 }; 00070 00071 00072 00073 /// stores information necessary to render a polygon later 00074 struct poly_request_t { 00075 // public enums 00076 enum eContants { 00077 eMaxVertices = 8 00078 }; 00079 00080 // constructor, manipulators 00081 void clear(void) throw() { 00082 textureId = 0; 00083 nVertices = 0; 00084 } 00085 00086 // data fields 00087 int textureId; ///< OpenGL texture ID to use 00088 point3d_t normal; ///< normal to polygon 00089 int nVertices; ///< number of vertices for this poly 00090 float u[eMaxVertices];///< texture u-coordinate 00091 float v[eMaxVertices];///< texture v-coordinate 00092 point3d_t vertex[eMaxVertices];///< texture coordinates 00093 }; 00094 00095 00096 00097 /// queue of requests 00098 class RenderQueue { 00099 public: 00100 // virtual destructor -------------------------------------------------- 00101 virtual ~RenderQueue(void) throw(); 00102 00103 // glut::RenderQueue class interface methods --------------------------- 00104 00105 /// grabs the next available request slot. Returns NULL if there are 00106 /// no more slots available. This effectively pushes a new request 00107 /// slot on the queue, and the client can fill it in using the 00108 /// poly_request_t pointer. 00109 virtual poly_request_t * grabRequestSlot(void) throw() = 0; 00110 00111 /// pops a request off the queue. Returns NULL if there are no more 00112 /// requests (slots) in the queue. 00113 virtual poly_request_t * popRequest(void) throw() = 0; 00114 00115 // static factory methods ---------------------------------------------- 00116 static smart_ptr<RenderQueue> create(IN int nSlots); 00117 }; 00118 00119 00120 00121 /// rendering interface -- anything that wants to draw has to implement this 00122 /// interface! 00123 class Renderable { 00124 public: 00125 // virtual destructor -------------------------------------------------- 00126 virtual ~Renderable(void) throw(); 00127 00128 // glut::Render class interface methods -------------------------------- 00129 00130 /// this method is called to actually draw the object. The object can 00131 /// assume that all necessary transforms (translation, rotation, 00132 /// scaling, etc.) have already been applied. There is no default 00133 /// implementation since this method is the whole point of the 00134 /// interface! 00135 virtual void render(IN const render_context_t& rc, 00136 IN RenderQueue * rq) = 0; 00137 00138 /// here the object must provide a bounding box. This is a bounding 00139 /// box in model-relative coordinates, not world coordinates. So 00140 /// this bounding box does <b>not</b> depend on where the model is 00141 /// positioned or how it is rotated, for instance. There is no 00142 /// default implementation since an accurate bounding box is 00143 /// critical for performance when rendering. 00144 virtual rect3d_t getBoundingBox(void) const throw() = 0; 00145 00146 00147 /// does this object support animations? Default answer is false. 00148 /// (random aside: did you know "animateable" is not a word?) 00149 virtual bool isAnimateable(void) const throw(); 00150 00151 00152 /// the object must provide current animation state. Default 00153 /// implementation returns empty state string. 00154 virtual void getAnimationState(OUT std::string& state); 00155 00156 00157 /// the object should update its animation state. Returns false if 00158 /// the object doesn't understand the provided state. Default 00159 /// implementation returns false. 00160 virtual bool setAnimationState(IN const char * state); 00161 00162 /// the object should return the full list of animation verbs it 00163 /// supports. The default implementation returns an empty list. 00164 virtual void getAnimationVerbs(OUT VecString& verbs); 00165 00166 00167 /// please update animations based on requested verb. Returns false 00168 /// if verb is not supported. Default implementation returns false. 00169 virtual bool setAnimation(IN const char * verb); 00170 }; 00171 00172 00173 00174 }; // glut namespace 00175 00176 #endif // WAVE_GLUT_GLUT_RENDERABLE_H__ 00177