Gizmo3D

gzLight.h

Go to the documentation of this file.
00001 //*****************************************************************************
00002 // File         : gzLight.h
00003 // Module       : 
00004 // Description  : Class definition of the gzLight classes
00005 // Author       : Anders Modén      
00006 // Product      : Gizmo3D 2.1.1
00007 //      
00008 // Copyright © 2003- Saab Training Systems AB, Sweden
00009 //          
00010 // NOTE:    Gizmo3D is a high performance 3D Scene Graph and effect visualisation 
00011 //          C++ toolkit for Linux, Mac OS X, Windows (Win32) and IRIX® for  
00012 //          usage in Game or VisSim development.
00013 //
00014 //
00015 // Revision History...                          
00016 //                                  
00017 // Who  Date    Description                     
00018 //                                  
00019 // AMO  990312  Created file    
00020 //
00021 //******************************************************************************
00022 #ifndef __GZ_LIGHT_H__
00023 #define __GZ_LIGHT_H__
00024 
00030 class gzContext;    // Forward declaration
00031 
00032 //******************************************************************************
00033 // Class    : gzLightPosition
00034 //                                  
00035 // Purpose  : Position of a light source
00036 //                                  
00037 // Notes    : - 
00038 //                                  
00039 // Revision History...                          
00040 //                                  
00041 // Who  Date    Description                     
00042 //                                  
00043 // AMO  991025  Created 
00044 //                                  
00045 //******************************************************************************
00046 class gzLightPosition
00047 {
00048 public:
00049     GZ_GRAPH_EXPORT gzLightPosition(gzFloat xp=10.0f , gzFloat yp=10.0f, gzFloat zp=0.0f , gzFloat w_local=1.0f ):x(xp),y(yp),z(zp),w(w_local){};
00050 
00051     GZ_GRAPH_EXPORT virtual ~gzLightPosition(){};
00052 
00053     GZ_GRAPH_EXPORT gzFloat *getPositionVector(){ return &x; }
00054 
00055     GZ_GRAPH_EXPORT gzVec4 getPosition();
00056 
00057     GZ_GRAPH_EXPORT gzBool operator==(const gzLightPosition& right);
00058 
00059     GZ_GRAPH_EXPORT gzBool operator!=(const gzLightPosition& right);
00060 
00061     gzFloat x,y,z,w;
00062 };
00063 
00064 //******************************************************************************
00065 // Class    : gzLightDirection
00066 //                                  
00067 // Purpose  : Beam direction of a light source
00068 //                                  
00069 // Notes    : - 
00070 //                                  
00071 // Revision History...                          
00072 //                                  
00073 // Who  Date    Description                     
00074 //                                  
00075 // AMO  991025  Created 
00076 //                                  
00077 //******************************************************************************
00079 class gzLightDirection
00080 
00081 {
00082 public:
00083     GZ_GRAPH_EXPORT gzLightDirection(gzFloat dx=10.0f , gzFloat dy=10.0f, gzFloat dz=0.0f ):x(dx),y(dy),z(dz){};
00084 
00085     GZ_GRAPH_EXPORT virtual ~gzLightDirection(){};
00086 
00087     GZ_GRAPH_EXPORT gzFloat *getDirectionVector(){ return &x; }
00088 
00089     GZ_GRAPH_EXPORT gzVec3 getDirection();
00090 
00091     gzFloat x,y,z;
00092 };
00093 
00094 //******************************************************************************
00095 // Class    : gzLight
00096 //                                  
00097 // Purpose  : The actual definition of a light source
00098 //                                  
00099 // Notes    : - 
00100 //                                  
00101 // Revision History...                          
00102 //                                  
00103 // Who  Date    Description                     
00104 //                                  
00105 // AMO  990312  Created 
00106 //                                  
00107 //******************************************************************************
00109 class gzLight : public gzObject , public gzNameInterface , public gzUpdateIDInterface
00110 {
00111 public:
00112     GZ_DECLARE_TYPE_INTERFACE_EXPORT(GZ_GRAPH_EXPORT);  // typed interface
00113 
00114     GZ_GRAPH_EXPORT gzLight(const gzString & name=GZ_EMPTY_STRING);
00115 
00116     GZ_GRAPH_EXPORT virtual ~gzLight(){};
00117 
00118     GZ_GRAPH_EXPORT gzVoid virtual activate(gzContext *context , gzULong lightIndex , gzULong transformIndex);
00119 
00120     GZ_GRAPH_EXPORT static gzVoid deactivate(gzContext *context , gzULong lightIndex);
00121 
00122 
00124 
00127     GZ_GRAPH_EXPORT gzVoid setAmbientColor(gzFloat red=0.0f , gzFloat green=0.0f, gzFloat blue=0.0f , gzFloat alpha=1.0f );
00128 
00130 
00133     GZ_GRAPH_EXPORT gzVoid setDiffuseColor(gzFloat red=1.0f , gzFloat green=1.0f, gzFloat blue=1.0f , gzFloat alpha=1.0f );
00134 
00136 
00139     GZ_GRAPH_EXPORT gzVoid setSpecularColor(gzFloat red=1.0f , gzFloat green=1.0f, gzFloat blue=1.0f , gzFloat alpha=1.0f );
00140 
00141 
00143     GZ_GRAPH_EXPORT gzVoid setPosition(gzFloat x=0.0f , gzFloat y=0.0f, gzFloat z=1.0f , gzFloat w=1.0f );
00144     GZ_GRAPH_EXPORT gzVoid setSpot(gzFloat dx=0.0f , gzFloat dy=0.0f, gzFloat dz=-1.0f , gzFloat exponent=0.0f , gzFloat cutoff=45.0f);
00145     GZ_GRAPH_EXPORT gzVoid setAttenuation( gzFloat constant=1.0f , gzFloat linear=0.0f , gzFloat quadratic=0.0f );
00146     GZ_GRAPH_EXPORT gzVoid setDirectionalLight(gzFloat dx=0.0f , gzFloat dy=0.0f, gzFloat dz=-1.0f);
00147 
00148     // Vector variants..
00149 
00151 
00154     GZ_GRAPH_EXPORT gzVoid setPosition(const gzVec3 & position);
00155 
00156 
00157     // Get utilities
00158 
00160     GZ_GRAPH_EXPORT gzLightPosition &getPosition();
00161 
00163     GZ_GRAPH_EXPORT gzRGBA  &getAmbientColor();
00164 
00166     GZ_GRAPH_EXPORT gzRGBA  &getSpecularColor();
00167 
00169     GZ_GRAPH_EXPORT gzRGBA  &getDiffuseColor();
00170 
00172 
00177     GZ_GRAPH_EXPORT gzVoid  enableLight(gzBool on=TRUE);
00178     
00180     GZ_GRAPH_EXPORT gzBool  isEnabled();
00181 
00182     GZ_GRAPH_EXPORT gzVoid invertShadowLight(gzBool on);
00183 
00184     GZ_GRAPH_EXPORT gzVoid excludeDiffuseInShadow(gzBool on);
00185 
00186     // ---------- Clone interface ---------------------------------------
00188     GZ_GRAPH_EXPORT virtual gzReference* clone() const;
00189 
00190 private:
00191 
00192     gzLightPosition m_lightpos;
00193 
00194     gzRGBA  m_ambient;
00195     gzRGBA  m_diffuse;
00196     gzRGBA  m_specular;
00197 
00198     gzLightDirection    m_spot_direction;
00199     gzFloat             m_spot_exponent;
00200     gzFloat             m_spot_cutoff;
00201     gzFloat             m_constant_attenuation;
00202     gzFloat             m_linear_attenuation;
00203     gzFloat             m_quadratic_attenuation;
00204 
00205     gzBool              m_enabled:1;
00206     gzBool              m_invertShadowLight:1;
00207     gzBool              m_excludeDiffuseInShadow:1;
00208 
00209 
00210 };
00211 
00212 // Declare smart pointer type
00213 GZ_DECLARE_REFPTR(gzLight);
00214 
00215 const gzULong GZ_NUMBER_OF_ACTIVE_LIGHTS=8;
00216 
00217 //******************************************************************************
00218 // Class    : gzLightState
00219 //                                  
00220 // Purpose  : The actual state of the current lights
00221 //                                  
00222 // Notes    : - 
00223 //                                  
00224 // Revision History...                          
00225 //                                  
00226 // Who  Date    Description                     
00227 //                                  
00228 // AMO  990312  Created 
00229 //                                  
00230 //******************************************************************************
00231 class gzLightState
00232 {
00233 public:
00234 
00235     GZ_GRAPH_EXPORT gzLightState():m_count(0){};
00236     GZ_GRAPH_EXPORT virtual ~gzLightState(){};
00237 
00238     GZ_GRAPH_EXPORT gzVoid  add(gzLightState &lightState);
00239 
00240     GZ_GRAPH_EXPORT gzVoid addLight( gzLight *light);
00241     GZ_GRAPH_EXPORT gzVoid removeLight( gzLight *light);
00242     GZ_GRAPH_EXPORT gzULong getNumberOfLights();
00243     GZ_GRAPH_EXPORT gzLight *getLight(gzULong lightIndex);
00244     GZ_GRAPH_EXPORT gzULong getTransformIndex(gzLight *light);
00245 
00246     GZ_GRAPH_EXPORT gzVoid setAllTransformIndex(gzULong index);
00247 
00248     GZ_GRAPH_EXPORT gzVoid activate(gzContext *context);
00249 
00250     GZ_GRAPH_EXPORT static gzVoid transferActiveLightStates(gzContext *from , gzContext *to);
00251 
00252 private:
00253 
00254     gzRefPointer<gzLight>   m_lights[GZ_NUMBER_OF_ACTIVE_LIGHTS];
00255     gzULong                 m_transformIndex[GZ_NUMBER_OF_ACTIVE_LIGHTS];
00256     gzUByte                 m_count;
00257 
00258 };
00259 
00260 
00261 #endif
00262 

Documentation for Gizmo3D generated at Wed Feb 20 11:54:06 2008 by   Saab Training Systems AB, ¸ (c) 2003-and beyond