diff options
author | Jacek Antonelli | 2008-08-15 23:45:42 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:45:42 -0500 |
commit | ce28e056c20bf2723f565bbf464b87781ec248a2 (patch) | |
tree | ef7b0501c4de4b631a916305cbc2a5fdc125e52d /linden/indra/newview/llrendersphere.cpp | |
parent | Second Life viewer sources 1.19.1.4b (diff) | |
download | meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.zip meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.tar.gz meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.tar.bz2 meta-impy-ce28e056c20bf2723f565bbf464b87781ec248a2.tar.xz |
Second Life viewer sources 1.20.2
Diffstat (limited to 'linden/indra/newview/llrendersphere.cpp')
-rw-r--r-- | linden/indra/newview/llrendersphere.cpp | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/linden/indra/newview/llrendersphere.cpp b/linden/indra/newview/llrendersphere.cpp new file mode 100644 index 0000000..6e5c850 --- /dev/null +++ b/linden/indra/newview/llrendersphere.cpp | |||
@@ -0,0 +1,171 @@ | |||
1 | /** | ||
2 | * @file llrendersphere.cpp | ||
3 | * @brief implementation of the LLRenderSphere class. | ||
4 | * | ||
5 | * $LicenseInfo:firstyear=2001&license=internal$ | ||
6 | * | ||
7 | * Copyright (c) 2001-2008, Linden Research, Inc. | ||
8 | * | ||
9 | * The following source code is PROPRIETARY AND CONFIDENTIAL. Use of | ||
10 | * this source code is governed by the Linden Lab Source Code Disclosure | ||
11 | * Agreement ("Agreement") previously entered between you and Linden | ||
12 | * Lab. By accessing, using, copying, modifying or distributing this | ||
13 | * software, you acknowledge that you have been informed of your | ||
14 | * obligations under the Agreement and agree to abide by those obligations. | ||
15 | * | ||
16 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
17 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
18 | * COMPLETENESS OR PERFORMANCE. | ||
19 | * $/LicenseInfo$ | ||
20 | */ | ||
21 | |||
22 | // Sphere creates a set of display lists that can then be called to create | ||
23 | // a lit sphere at different LOD levels. You only need one instance of sphere | ||
24 | // per viewer - then call the appropriate list. | ||
25 | |||
26 | #include "llviewerprecompiledheaders.h" | ||
27 | #include "llrendersphere.h" | ||
28 | #include "llerror.h" | ||
29 | |||
30 | #include "llglheaders.h" | ||
31 | |||
32 | GLUquadricObj *gQuadObj2 = NULL; | ||
33 | LLRenderSphere gSphere; | ||
34 | |||
35 | void drawSolidSphere(GLdouble radius, GLint slices, GLint stacks); | ||
36 | |||
37 | void drawSolidSphere(GLdouble radius, GLint slices, GLint stacks) | ||
38 | { | ||
39 | if (!gQuadObj2) | ||
40 | { | ||
41 | gQuadObj2 = gluNewQuadric(); | ||
42 | if (!gQuadObj2) | ||
43 | { | ||
44 | llwarns << "drawSolidSphere couldn't allocate quadric" << llendl; | ||
45 | return; | ||
46 | } | ||
47 | } | ||
48 | |||
49 | gluQuadricDrawStyle(gQuadObj2, GLU_FILL); | ||
50 | gluQuadricNormals(gQuadObj2, GLU_SMOOTH); | ||
51 | // If we ever changed/used the texture or orientation state | ||
52 | // of quadObj, we'd need to change it to the defaults here | ||
53 | // with gluQuadricTexture and/or gluQuadricOrientation. | ||
54 | gluQuadricTexture(gQuadObj2, GL_TRUE); | ||
55 | gluSphere(gQuadObj2, radius, slices, stacks); | ||
56 | } | ||
57 | |||
58 | |||
59 | // lat = 0 is Z-axis | ||
60 | // lon = 0, lat = 90 at X-axis | ||
61 | void lat2xyz(LLVector3 * result, F32 lat, F32 lon) | ||
62 | { | ||
63 | // Convert a latitude and longitude to x,y,z on a normal sphere and return it in result | ||
64 | F32 r; | ||
65 | result->mV[VX] = (F32) (cos(lon * DEG_TO_RAD) * sin(lat * DEG_TO_RAD)); | ||
66 | result->mV[VY] = (F32) (sin(lon * DEG_TO_RAD) * sin(lat * DEG_TO_RAD)); | ||
67 | r = (F32) pow(result->mV[VX] * result->mV[VX] + result->mV[VY] * result->mV[VY], 0.5f); | ||
68 | if (r == 1.0f) | ||
69 | { | ||
70 | result->mV[VZ] = 0.0f; | ||
71 | } | ||
72 | else | ||
73 | { | ||
74 | result->mV[VZ] = (F32) pow(1 - r*r, 0.5f); | ||
75 | if (lat > 90.01) | ||
76 | { | ||
77 | result->mV[VZ] *= -1.0; | ||
78 | } | ||
79 | } | ||
80 | } | ||
81 | |||
82 | void lat2xyz_rad(LLVector3 * result, F32 lat, F32 lon) | ||
83 | { | ||
84 | // Convert a latitude and longitude to x,y,z on a normal sphere and return it in result | ||
85 | F32 r; | ||
86 | result->mV[VX] = (F32) (cos(lon) * sin(lat)); | ||
87 | result->mV[VY] = (F32) (sin(lon) * sin(lat)); | ||
88 | r = (F32) pow(result->mV[VX] * result->mV[VX] + result->mV[VY] * result->mV[VY], 0.5f); | ||
89 | if (r == 1.0f) | ||
90 | result->mV[VZ] = 0.0f; | ||
91 | else | ||
92 | { | ||
93 | result->mV[VZ] = (F32) pow(1 - r*r, 0.5f); | ||
94 | if (lat > F_PI_BY_TWO) result->mV[VZ] *= -1.0; | ||
95 | } | ||
96 | } | ||
97 | |||
98 | // A couple thoughts on sphere drawing: | ||
99 | // 1) You need more slices than stacks, but little less than 2:1 | ||
100 | // 2) At low LOD, setting stacks to an odd number avoids a "band" around the equator, making things look smoother | ||
101 | void LLRenderSphere::prerender() | ||
102 | { | ||
103 | // Create a series of display lists for different LODs | ||
104 | mDList[0] = glGenLists(1); | ||
105 | glNewList(mDList[0], GL_COMPILE); | ||
106 | drawSolidSphere(1.0, 30, 20); | ||
107 | glEndList(); | ||
108 | |||
109 | mDList[1] = glGenLists(1); | ||
110 | glNewList(mDList[1], GL_COMPILE); | ||
111 | drawSolidSphere(1.0, 20, 15); | ||
112 | glEndList(); | ||
113 | |||
114 | mDList[2] = glGenLists(1); | ||
115 | glNewList(mDList[2], GL_COMPILE); | ||
116 | drawSolidSphere(1.0, 12, 8); | ||
117 | glEndList(); | ||
118 | |||
119 | mDList[3] = glGenLists(1); | ||
120 | glNewList(mDList[3], GL_COMPILE); | ||
121 | drawSolidSphere(1.0, 8, 5); | ||
122 | glEndList(); | ||
123 | } | ||
124 | |||
125 | void LLRenderSphere::cleanupGL() | ||
126 | { | ||
127 | for (S32 detail = 0; detail < 4; detail++) | ||
128 | { | ||
129 | glDeleteLists(mDList[detail], 1); | ||
130 | mDList[detail] = 0; | ||
131 | } | ||
132 | |||
133 | if (gQuadObj2) | ||
134 | { | ||
135 | gluDeleteQuadric(gQuadObj2); | ||
136 | gQuadObj2 = NULL; | ||
137 | } | ||
138 | } | ||
139 | |||
140 | // Constants here are empirically derived from my eyeballs, JNC | ||
141 | // | ||
142 | // The toughest adjustment is the cutoff for the lowest LOD | ||
143 | // Maybe we should have more LODs at the low end? | ||
144 | void LLRenderSphere::render(F32 pixel_area) | ||
145 | { | ||
146 | S32 level_of_detail; | ||
147 | |||
148 | if (pixel_area > 10000.f) | ||
149 | { | ||
150 | level_of_detail = 0; | ||
151 | } | ||
152 | else if (pixel_area > 800.f) | ||
153 | { | ||
154 | level_of_detail = 1; | ||
155 | } | ||
156 | else if (pixel_area > 100.f) | ||
157 | { | ||
158 | level_of_detail = 2; | ||
159 | } | ||
160 | else | ||
161 | { | ||
162 | level_of_detail = 3; | ||
163 | } | ||
164 | glCallList(mDList[level_of_detail]); | ||
165 | } | ||
166 | |||
167 | |||
168 | void LLRenderSphere::render() | ||
169 | { | ||
170 | glCallList(mDList[0]); | ||
171 | } | ||