00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef __RE_Light_H__
00026 #define __RE_Light_H__
00027
00028 #include "RE_API.h"
00029 #include "RE_Types.h"
00030 #include <string.h>
00031 #include <UT/UT_String.h>
00032 #include <UT/UT_LinkList.h>
00033 #include <UT/UT_Vector3.h>
00034 #include <UT/UT_Matrix4.h>
00035
00036 class UT_Raster;
00037 class RE_Texture2DMap;
00038
00039 class RE_API RE_LightFlag
00040 {
00041 public:
00042 RE_LightFlag()
00043 {
00044 cone = 0;
00045 infinite = 0;
00046 ambient = 0;
00047 mapprojector = 0;
00048 clampprojectormap = 0;
00049 projectormapdirty = 0;
00050 }
00051
00052 unsigned mapprojector:1,
00053 cone:1,
00054 infinite:1,
00055 ambient:1,
00056 clampprojectormap:1,
00057 projectormapdirty:1;
00058 };
00059
00060
00061 class RE_API RE_Light {
00062 public:
00063 RE_Light(const char *n = 0);
00064
00065 const char *getName() const { return myName; }
00066 void setName(const char *name) { myName.harden(name); }
00067
00068 virtual void setForDelete();
00069
00070 const UT_Vector3 &getPosition() const { return pos; }
00071 UT_Vector3 &getPosition() { return pos; }
00072 void setPosition(const UT_Vector3 &p) { pos = p; }
00073
00074 const UT_Vector3 &getDirection() const { return dir; }
00075 UT_Vector3 &getDirection() { return dir; }
00076 void setDirection(const UT_Vector3 &d) { dir = d; }
00077
00078 const UT_Vector3 &getColor() const { return clr; }
00079 UT_Vector3 &getColor() { return clr; }
00080 void setColor(const UT_Vector3 &c) { clr = c; }
00081
00082 const UT_Matrix4 &getTransform() const { return xform; }
00083 UT_Matrix4 &getTransform() { return xform; }
00084 void setTransform(const UT_Matrix4 &m) { xform = m; }
00085
00086 int isCone() const { return flag.cone; }
00087 int isInfinite() const { return flag.infinite; }
00088 int isAmbient() const { return flag.ambient; }
00089 int isMapProjector() const { return flag.mapprojector; }
00090
00091 int isDiffuse() const { return myContribDiff; }
00092 int isSpecular() const { return myContribSpec; }
00093
00094 bool isShadowed() const { return myUseShadows; }
00095
00096
00097
00098
00099 void setInfinite(int onoff) { flag.infinite = onoff; }
00100 void setAmbient(int onoff) { flag.ambient = onoff; }
00101 void setCone(int onoff) { flag.cone = onoff; }
00102 void setDiffuse(int onoff) { myContribDiff = onoff; }
00103 void setSpecular(int onoff) { myContribSpec = onoff; }
00104 void setShadowed(bool onoff) { myUseShadows = onoff; }
00105 void setConeAttrib(float a = 45, float d = 10, float r = 1)
00106 {
00107 coneAngle = a;
00108 coneDelta = d;
00109 coneRoll = r;
00110 setCone((a*.5 + d >= 180) ? 0 : 1);
00111 }
00112 float getConeAngle() const { return coneAngle; }
00113 float getConeDelta() const { return coneDelta; }
00114 float getConeRoll() const { return coneRoll; }
00115
00116
00117
00118 void setZoom(float z) { zoom = z; }
00119 float getZoom() const { return zoom; }
00120
00121 void setFocalLength(float focal) { myFocalLength = focal; }
00122 float getFocalLength() const { return myFocalLength; }
00123
00124 void setAperture(float aper) { myAperture = aper; }
00125 float getAperture() const { return myAperture; }
00126
00127 void setOrthoWidth(float width) { myOrthoWidth = width; }
00128 float getOrthoWidth() const { return myOrthoWidth; }
00129
00130 void setNearDistance(float znear) { myNearDist = znear; }
00131 float getNearDistance() const { return myNearDist; }
00132
00133 void setFarDistance(float zfar) { myFarDist = zfar; }
00134 float getFarDistance() const { return myFarDist; }
00135
00136 #if RE_OGL_SINGLE_CONTEXT
00137 int getIndex() const { return myIndex; }
00138 void setIndex(int idx);
00139 #endif
00140
00141 int getConeTextureIndex() const
00142 { return myGLConeTextureIndex;}
00143 void setConeTextureIndex(int idx)
00144 { myGLConeTextureIndex = idx; }
00145
00146 int needConeGLReset() const { return myGLConeNeedReset; }
00147 void needConeGLReset(int f) { myGLConeNeedReset = f; }
00148
00149
00150
00151
00152
00153
00154
00155 void setMaskPic(UT_Raster *r) { maskPic = r; }
00156 void setShadowPic(UT_Raster *r) { shadowPic = r; }
00157 void setDiffusePic(UT_Raster *r) { diffusePic = r; }
00158 void setReflectPic(UT_Raster *r) { reflectPic = r; }
00159 void setProjectMap(const char *name,
00160 const char *relativeTo);
00161 void setProjectMapClamp(int onoff);
00162
00163 UT_Raster *getMaskPic() const { return maskPic; }
00164 UT_Raster *getShadowPic() const { return shadowPic; }
00165 UT_Raster *getDiffusePic() const { return diffusePic; }
00166 UT_Raster *getReflectPic() const { return reflectPic; }
00167 RE_Texture2DMap *getProjectMap();
00168
00169 virtual void getVexShader(UT_String &str, float now);
00170 virtual void getVexShadow(UT_String &str, float now);
00171 virtual void getAttenuation(float atten[3]) const;
00172
00173 protected:
00174 #ifdef LINUX
00175 public:
00176 virtual ~RE_Light();
00177 protected:
00178 #else
00179 virtual ~RE_Light();
00180 #endif
00181
00182 #if RE_OGL_SINGLE_CONTEXT
00183 int myIndex;
00184 #endif
00185 int myGLConeTextureIndex;
00186 unsigned myGLConeNeedReset:1,
00187 myContribDiff:1,
00188 myContribSpec:1,
00189 myUseShadows:1;
00190 #if RE_OGL_SINGLE_CONTEXT
00191 int myDeletePending;
00192 #endif
00193 RE_LightFlag flag;
00194 UT_String myName;
00195 UT_Vector3 pos;
00196 UT_Vector3 dir;
00197 UT_Vector3 clr;
00198 UT_Matrix4 xform;
00199 float coneAngle, coneDelta, coneRoll;
00200 float myAperture, myFocalLength;
00201 float myOrthoWidth;
00202 float myNearDist;
00203 float myFarDist;
00204 float zoom;
00205 UT_Raster *maskPic;
00206 UT_Raster *shadowPic;
00207 UT_Raster *diffusePic;
00208 UT_Raster *reflectPic;
00209 RE_Texture2DMap *projectMap;
00210
00211 UT_String myProjectMapName;
00212 UT_String myProjectMapRelativeTo;
00213 };
00214 #endif