00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CS_PROCSKYTEX_H__
00020 #define __CS_PROCSKYTEX_H__
00021
00022 #include "csgeom/math3d.h"
00023 #include "csgfx/rgbpixel.h"
00024 #include "csutil/cscolor.h"
00025 #include "cstool/proctex.h"
00026
00027 class csProcSky;
00028
00032 class csProcSkyTexture : public csProcTexture
00033 {
00035 csProcSky *sky;
00037 csProcSkyTexture *next;
00038
00040 csVector3 txtorig, txtu, txtv;
00042 csVector3 *isect;
00044 bool forcerender;
00045
00046 public:
00048 csProcSkyTexture(csProcSky *par);
00050 virtual ~csProcSkyTexture();
00051
00052 void SetNextSky(csProcSkyTexture *n) {next = n;}
00053 csProcSkyTexture *GetNextSky() const {return next;}
00054
00055 virtual bool PrepareAnim ();
00056
00058 virtual void Animate (csTicks current_time);
00059
00061 int GetWidth() const {return mat_w;}
00063 int GetHeight() const {return mat_h;}
00065 void GetTextureSpace(csVector3& orig, csVector3& u, csVector3& v) const
00066 { orig = txtorig; u = txtu; v = txtv; }
00068 void SetIntersect(csVector3 *icache) {isect = icache;}
00070 csVector3 *GetIntersect() const {return isect;}
00071
00073 void ForceRerender() {forcerender = true;}
00075 bool MustRender() const {return forcerender;}
00077 void UnsetForceRender() {forcerender = false;}
00079 bool AnimPrepared () {return anim_prepared;}
00089 void SetTextureSpace(const csVector3& tex_orig, const csVector3& total_u,
00090 const csVector3& total_v) {txtorig=tex_orig; txtu=total_u; txtv=total_v;}
00091 };
00092
00093
00098 class csProcSky
00099 {
00101 csProcSkyTexture *firstsky;
00102
00104 float radius;
00106 csVector3 center;
00108 csVector3 cam;
00110 csVector3 sunpos;
00112 csColor suncolor;
00114 csRGBcolor maxhaze;
00115
00117 int nr_octaves;
00119 int octsize;
00121 uint8 *octaves;
00123 uint8** enlarged;
00124
00125
00127 bool animated;
00129 int *periods;
00131 int *curposition;
00136 uint8 *startoctaves, *endoctaves;
00138 csTicks old_time;
00140 csVector2 windpos;
00142 csVector2 winddir;
00143
00145 void Initialize();
00147 void InitOctave(uint8 *octs, int nr);
00149 void SmoothOctave(uint8 *octs, int nr, int smoothpower);
00151 void Enlarge(uint8 *dest, uint8 *src, int factor, int rshift);
00153 void Combine(uint8 *dest, uint8 *start, uint8 *end, int pos, int max, int nr);
00155 void AnimOctave(int nr, int elapsed);
00157 uint8& GetOctave(uint8 *octaves, int oct, int x, int y)
00158 { return octaves [ oct*octsize*octsize + y*octsize + x ]; }
00159 void SetOctave(uint8 *octaves, int oct, int x, int y, uint8 val)
00160 { octaves[ oct*octsize*octsize + y*octsize + x ] = val; }
00162 void CopyOctave(uint8 *srcocts, int srcnr, uint8 *destocts, int destnr);
00163
00165 bool SphereIntersect(const csVector3& point, csVector3& isect);
00167 csRGBcolor GetSkyBlue(const csVector3& spot, float& haze, float sundist,
00168 bool& below);
00170 uint8 GetCloudVal(int x, int y);
00172 float GetSundist(const csVector3& spot);
00173
00174 public:
00175 csProcSky();
00176 ~csProcSky();
00177
00179 void DrawToTexture (csProcSkyTexture *skytex, csTicks current_time,
00180 iObjectRegistry* object_reg);
00181
00183 void MakeIntersectCache(csProcSkyTexture *skytex);
00184
00193 void SetAnimated (iObjectRegistry* object_reg,
00194 bool anim=true, csTicks current_time=0);
00196 bool GetAnimated() const {return animated;}
00198 csProcSkyTexture *GetFirstSky() const {return firstsky;}
00200 void SetFirstSky(csProcSkyTexture *s) {firstsky = s;}
00201 };
00202
00203 #endif // __CS_PROCSKYTEX_H__