aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llwaterpatch.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--linden/indra/newview/llwaterpatch.h317
1 files changed, 0 insertions, 317 deletions
diff --git a/linden/indra/newview/llwaterpatch.h b/linden/indra/newview/llwaterpatch.h
deleted file mode 100644
index f4eddf6..0000000
--- a/linden/indra/newview/llwaterpatch.h
+++ /dev/null
@@ -1,317 +0,0 @@
1/**
2 * @file llwaterpatch.h
3 * @brief LLWaterTri class header file
4 *
5 * Copyright (c) 2001-2007, Linden Research, Inc.
6 *
7 * Second Life Viewer Source Code
8 * The source code in this file ("Source Code") is provided by Linden Lab
9 * to you under the terms of the GNU General Public License, version 2.0
10 * ("GPL"), unless you have obtained a separate licensing agreement
11 * ("Other License"), formally executed by you and Linden Lab. Terms of
12 * the GPL can be found in doc/GPL-license.txt in this distribution, or
13 * online at http://secondlife.com/developers/opensource/gplv2
14 *
15 * There are special exceptions to the terms and conditions of the GPL as
16 * it is applied to this Source Code. View the full text of the exception
17 * in the file doc/FLOSS-exception.txt in this software distribution, or
18 * online at http://secondlife.com/developers/opensource/flossexception
19 *
20 * By copying, modifying or distributing this software, you acknowledge
21 * that you have read and understood your obligations described above,
22 * and agree to abide by those obligations.
23 *
24 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
25 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
26 * COMPLETENESS OR PERFORMANCE.
27 */
28
29#ifndef LL_WATER_PATCH_H
30#define LL_WATER_PATCH_H
31
32#include "llmath.h"
33#include "v3math.h"
34#include "llroam.h"
35
36const U8 MAX_LEVEL = 10;
37
38class LL2Coord
39{
40protected:
41 S32 mX;
42 S32 mY;
43public:
44 LL2Coord() {}
45 //LL2Coord() : mX(0), mY(0) {}
46 LL2Coord (S32 i, S32 j) : mX(i), mY(j) {}
47 LL2Coord operator+ (const LL2Coord& c) const
48 {
49 return LL2Coord(mX + c.mX, mY + c.mY);
50 }
51 LL2Coord operator* (F32 c) const
52 {
53 return LL2Coord(llround(mX * c), llround(mY * c));
54 }
55 S32 x() const { return mX; }
56 S32 y() const { return mY; }
57
58 S32& x() { return mX; }
59 S32& y() { return mY; }
60
61 LL2Coord middle(const LL2Coord& c2) const
62 {
63 return LL2Coord((x() + c2.x()) >> 1, (y() + c2.y()) >> 1);
64 }
65
66 S32 distance2(const LL2Coord& c2) const
67 {
68 S32 dx = x() - c2.x();
69 S32 dy = y() - c2.y();
70
71 return dx * dx + dy * dy;
72 }
73
74 F32 distance(const LL2Coord& c2) const
75 {
76 return (F32) sqrt((F32)distance2(c2));
77 }
78};
79
80
81
82
83
84
85class LLWaterGrid;
86
87class LLWaterTri : public LLRoamTriNode
88{
89protected:
90 LL2Coord mLvtx; // Left vertex
91 LL2Coord mRvtx; // Right vertex
92 LL2Coord mTvtx; // Top vertex
93 LL2Coord mMiddle; // Top vertex
94
95 F32 mSize;
96
97 BOOL mCurr;
98 BOOL mRefine;
99
100public:
101 static LL2Coord sCam;
102 static F32 sClipFar;
103 static U32 sMaxDivLevel;
104 static U32 sMinStep;
105
106 static BOOL sCurrRound;
107
108
109public:
110 LLWaterTri (const LL2Coord& l, const LL2Coord& r, const LL2Coord& t):
111 LLRoamTriNode(0, 0, 0), mLvtx(l), mRvtx(r), mTvtx(t), mRefine(FALSE)
112 {
113 mSize = mLvtx.distance(mRvtx) * sMinStep;
114 mCurr = sCurrRound;
115 mMiddle = mLvtx.middle(mRvtx);
116 }
117
118 LLWaterTri (U8 level = 0, S8 type = 0, LLWaterTri* par = 0);
119
120 virtual LLRoamTriNode* newLChild()
121 {
122 return new LLWaterTri(mLevel+1, -1, this);
123 }
124 virtual LLRoamTriNode* newRChild()
125 {
126 return new LLWaterTri(mLevel+1, 1, this);
127 }
128
129 virtual ~LLWaterTri() {}
130
131 const LL2Coord& Lvtx() const { return mLvtx; }
132 const LL2Coord& Rvtx() const { return mRvtx; }
133 const LL2Coord& Tvtx() const { return mTvtx; }
134
135 F32 size() const { return mSize; }
136
137 LL2Coord middleSide() const { return mMiddle; }//middle(mLvtx, mRvtx); }
138
139 void setLvtx(const LL2Coord& c) { mLvtx = c; }
140 void setRvtx(const LL2Coord& c) { mRvtx = c; }
141 void setTvtx(const LL2Coord& c) { mTvtx = c; }
142
143 void updatePassive();
144 BOOL refine();
145 void initForcefulRefine()
146 {
147 setUpToDate();
148 mRefine = TRUE;
149 }
150 void flushFromQueue() { setUpToDate(); }
151
152 BOOL upToDate() const { return mCurr == sCurrRound; }
153 void setUpToDate() { mCurr = sCurrRound; }
154 void setNotUpToDate() { mCurr = !sCurrRound; }
155 static void nextRound() { sCurrRound = !sCurrRound; }
156
157 BOOL checkUpToDate() const
158 {
159 BOOL ok = leaf() ? upToDate() :
160 upToDate() && ((LLWaterTri*)Lchild())->upToDate() && ((LLWaterTri*)Rchild())->upToDate();
161 if (!ok)
162 return ok;
163 else
164 return ok;
165 }
166
167};
168
169
170
171
172class LLWaterPatch : public LLRoamPatch
173{
174protected:
175 LL2Coord mOrig; // Bottom left vertex
176 U32 mSize;
177 U32 mRegionWidth;
178 LLVector3 mCenter;
179 BOOL mVis;
180
181public:
182 LLWaterPatch() :
183 LLRoamPatch(MAX_LEVEL, TRUE), mOrig(0, 0), mSize(32), mRegionWidth(256) {}
184
185 LLWaterPatch(const LL2Coord o, U32 size, U32 width, const LLVector3& center,
186 U8 max_level = MAX_LEVEL, BOOL back_slash = TRUE) :
187 LLRoamPatch(back_slash, max_level), mOrig(o), mSize(size), mRegionWidth(width), mCenter(center)
188 { createTris(); }
189
190 LLWaterPatch(S32 o1, S32 o2, U32 size, U32 width, const LLVector3& center,
191 U8 max_level = MAX_LEVEL, BOOL back_slash = TRUE) :
192 LLRoamPatch(back_slash, max_level), mOrig(o1, o2), mSize(size), mRegionWidth(width), mCenter(center)
193 { createTris(); }
194
195
196 const LL2Coord& orig() const { return mOrig; }
197 void set (S32 o1, S32 o2, U32 size, U32 width, const LLVector3& center,
198 U8 max_level = MAX_LEVEL, BOOL back_slash = TRUE)
199 {
200 deleteTris();
201 mBackSlash = back_slash;
202 mMaxLevel = max_level;
203 mOrig.x() = o1;
204 mOrig.y() = o2;
205 mSize = size;
206 mCenter = center;
207 mRegionWidth = width;
208 mNumTris = 0;
209 createTris();
210 }
211
212 void setMaxLevel (U8 max_level) { mMaxLevel = max_level; }
213
214 void createTris()
215 {
216 if (mBackSlash)
217 {
218 mTri[0] = new LLWaterTri(LL2Coord(mOrig.x() + mSize, mOrig.y()),
219 LL2Coord(mOrig.x(), mOrig.y() + mSize), mOrig);
220 mTri[1] = new LLWaterTri(LL2Coord(mOrig.x(), mOrig.y() + mSize),
221 LL2Coord(mOrig.x() + mSize, mOrig.y()),
222 LL2Coord(mOrig.x() + mSize, mOrig.y() + mSize));
223 } else {
224 mTri[0] = new LLWaterTri(mOrig,
225 LL2Coord(mOrig.x() + mSize, mOrig.y() + mSize),
226 LL2Coord(mOrig.x(), mOrig.y() + mSize));
227 mTri[1] = new LLWaterTri(LL2Coord(mOrig.x() + mSize, mOrig.y() + mSize),
228 mOrig,
229 LL2Coord(mOrig.x() + mSize, mOrig.y()));
230 }
231 setTris();
232 ((LLWaterTri*)mTri[0])->setUpToDate();
233 ((LLWaterTri*)mTri[1])->setUpToDate();
234 }
235 //virtual ~LLWaterPatch() {}
236 void setInvisible() { mVis = FALSE; }
237 void setVisible() { mVis = TRUE; }
238
239 BOOL visible() const { return mVis; }
240
241 BOOL updateTree(const LLVector3 &camera_pos, const LLVector3 &look_at, const LLVector3 &reg_orig)
242 {
243 const static F32 patch_rad = mRegionWidth * F_SQRT2 * 0.5f;
244
245 LLVector3 to_patch = reg_orig + mCenter - camera_pos;
246 F32 to_patch_dist = to_patch.normVec();
247
248 if ( to_patch_dist < patch_rad)
249 {
250 setVisible();
251 update();
252 } else {
253 const F32 sin_min_angle = patch_rad / to_patch_dist;
254 const F32 cos_min_angle = (F32)sqrt(1.f - sin_min_angle * sin_min_angle);
255 const F32 cos_max = OO_SQRT2 * (cos_min_angle - sin_min_angle);
256
257 if (to_patch * look_at > cos_max)
258 {
259 setVisible();
260 update();
261 } else {
262 setInvisible();
263 updatePassive();
264 }
265 }
266
267 return mVis;
268 }
269
270 BOOL updateVisibility(const LLVector3 &camera_pos, const LLVector3 &look_at, const LLVector3 &reg_orig)
271 {
272 const static F32 patch_rad = mRegionWidth * F_SQRT2 * 0.5f;
273 const static U32 reg_width_half = mRegionWidth / 2;
274 //const static F32 patch_rad2 = patch_rad * patch_rad;
275
276 LLVector3 to_patch = reg_orig + mCenter - camera_pos;
277 //const F32 to_patch_dist2D2 = to_patch.mV[VX] * to_patch.mV[VX] + to_patch.mV[VY] * to_patch.mV[VY];
278
279 if (fabs(to_patch.mV[VX]) <= reg_width_half && fabs(to_patch.mV[VY]) <= reg_width_half)
280 //if ( to_patch_dist2D2 < patch_rad2)
281 {
282 setVisible();
283 } else {
284 F32 to_patch_dist = to_patch.normVec();
285 //const F32 to_patch_dist = sqrt(to_patch_dist2D2 + to_patch.mV[VZ] * to_patch.mV[VZ]);
286 const F32 sin_min_angle = patch_rad / to_patch_dist;
287 if (sin_min_angle >= 1)
288 {
289 setVisible();
290 } else {
291 const F32 cos_min_angle = (F32)sqrt(1.f - sin_min_angle * sin_min_angle);
292 const F32 cos_max = OO_SQRT2 * (cos_min_angle - sin_min_angle);
293
294 if (to_patch * look_at > cos_max)
295 {
296 setVisible();
297 } else {
298 setInvisible();
299 }
300 }
301 }
302
303 return mVis;
304 }
305 void checkUpToDate() const
306 {
307 for (U8 h = 0; h < 2; h++)
308 {
309 ((LLWaterTri*)left())->checkUpToDate();
310 ((LLWaterTri*)right())->checkUpToDate();
311 }
312 }
313
314};
315
316
317#endif