PageRenderTime 39ms CodeModel.GetById 14ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llrender/llrendersphere.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 91 lines | 49 code | 14 blank | 28 comment | 5 complexity | a579d516696ed184833bf7a5e5567162 MD5 | raw file
 1/** 
 2 * @file llrendersphere.cpp
 3 * @brief implementation of the LLRenderSphere class.
 4 *
 5 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
 6 * Second Life Viewer Source Code
 7 * Copyright (C) 2010, Linden Research, Inc.
 8 * 
 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation;
12 * version 2.1 of the License only.
13 * 
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * Lesser General Public License for more details.
18 * 
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 * 
23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
24 * $/LicenseInfo$
25 */
26
27//	Sphere creates a set of display lists that can then be called to create 
28//	a lit sphere at different LOD levels.  You only need one instance of sphere 
29//	per viewer - then call the appropriate list.  
30
31#include "linden_common.h"
32
33#include "llrendersphere.h"
34#include "llerror.h"
35
36#include "llglheaders.h"
37
38LLRenderSphere gSphere;
39
40void LLRenderSphere::render()
41{
42	renderGGL();
43	gGL.flush();
44}
45
46inline LLVector3 polar_to_cart(F32 latitude, F32 longitude)
47{
48	return LLVector3(sin(F_TWO_PI * latitude) * cos(F_TWO_PI * longitude),
49					 sin(F_TWO_PI * latitude) * sin(F_TWO_PI * longitude),
50					 cos(F_TWO_PI * latitude));
51}
52
53
54void LLRenderSphere::renderGGL()
55{
56	S32 const LATITUDE_SLICES = 20;
57	S32 const LONGITUDE_SLICES = 30;
58
59	if (mSpherePoints.empty())
60	{
61		mSpherePoints.resize(LATITUDE_SLICES + 1);
62		for (S32 lat_i = 0; lat_i < LATITUDE_SLICES + 1; lat_i++)
63		{
64			mSpherePoints[lat_i].resize(LONGITUDE_SLICES + 1);
65			for (S32 lon_i = 0; lon_i < LONGITUDE_SLICES + 1; lon_i++)
66			{
67				F32 lat = (F32)lat_i / LATITUDE_SLICES;
68				F32 lon = (F32)lon_i / LONGITUDE_SLICES;
69
70				mSpherePoints[lat_i][lon_i] = polar_to_cart(lat, lon);
71			}
72		}
73	}
74	
75	gGL.begin(LLRender::TRIANGLES);
76
77	for (S32 lat_i = 0; lat_i < LATITUDE_SLICES; lat_i++)
78	{
79		for (S32 lon_i = 0; lon_i < LONGITUDE_SLICES; lon_i++)
80		{
81			gGL.vertex3fv(mSpherePoints[lat_i][lon_i].mV);
82			gGL.vertex3fv(mSpherePoints[lat_i][lon_i+1].mV);
83			gGL.vertex3fv(mSpherePoints[lat_i+1][lon_i].mV);
84
85			gGL.vertex3fv(mSpherePoints[lat_i+1][lon_i].mV);
86			gGL.vertex3fv(mSpherePoints[lat_i][lon_i+1].mV);
87			gGL.vertex3fv(mSpherePoints[lat_i+1][lon_i+1].mV);
88		}
89	}
90	gGL.end();
91}