PageRenderTime 90ms CodeModel.GetById 29ms RepoModel.GetById 5ms 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
Possible License(s): LGPL-2.1
  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. // Sphere creates a set of display lists that can then be called to create
  27. // a lit sphere at different LOD levels. You only need one instance of sphere
  28. // per viewer - then call the appropriate list.
  29. #include "linden_common.h"
  30. #include "llrendersphere.h"
  31. #include "llerror.h"
  32. #include "llglheaders.h"
  33. LLRenderSphere gSphere;
  34. void LLRenderSphere::render()
  35. {
  36. renderGGL();
  37. gGL.flush();
  38. }
  39. inline LLVector3 polar_to_cart(F32 latitude, F32 longitude)
  40. {
  41. return LLVector3(sin(F_TWO_PI * latitude) * cos(F_TWO_PI * longitude),
  42. sin(F_TWO_PI * latitude) * sin(F_TWO_PI * longitude),
  43. cos(F_TWO_PI * latitude));
  44. }
  45. void LLRenderSphere::renderGGL()
  46. {
  47. S32 const LATITUDE_SLICES = 20;
  48. S32 const LONGITUDE_SLICES = 30;
  49. if (mSpherePoints.empty())
  50. {
  51. mSpherePoints.resize(LATITUDE_SLICES + 1);
  52. for (S32 lat_i = 0; lat_i < LATITUDE_SLICES + 1; lat_i++)
  53. {
  54. mSpherePoints[lat_i].resize(LONGITUDE_SLICES + 1);
  55. for (S32 lon_i = 0; lon_i < LONGITUDE_SLICES + 1; lon_i++)
  56. {
  57. F32 lat = (F32)lat_i / LATITUDE_SLICES;
  58. F32 lon = (F32)lon_i / LONGITUDE_SLICES;
  59. mSpherePoints[lat_i][lon_i] = polar_to_cart(lat, lon);
  60. }
  61. }
  62. }
  63. gGL.begin(LLRender::TRIANGLES);
  64. for (S32 lat_i = 0; lat_i < LATITUDE_SLICES; lat_i++)
  65. {
  66. for (S32 lon_i = 0; lon_i < LONGITUDE_SLICES; lon_i++)
  67. {
  68. gGL.vertex3fv(mSpherePoints[lat_i][lon_i].mV);
  69. gGL.vertex3fv(mSpherePoints[lat_i][lon_i+1].mV);
  70. gGL.vertex3fv(mSpherePoints[lat_i+1][lon_i].mV);
  71. gGL.vertex3fv(mSpherePoints[lat_i+1][lon_i].mV);
  72. gGL.vertex3fv(mSpherePoints[lat_i][lon_i+1].mV);
  73. gGL.vertex3fv(mSpherePoints[lat_i+1][lon_i+1].mV);
  74. }
  75. }
  76. gGL.end();
  77. }