1 //  Cylinder_Sky.cc - Cylindrical image mapping for Caelum.
2 //
3 //  Copyright (C) 2003 Sam Varner
4 //
5 //  This program is free software; you can redistribute it and/or modify
6 //  it under the terms of the GNU General Public License as published by
7 //  the Free Software Foundation; either version 2 of the License, or
8 //  (at your option) any later version.
9 //
10 //  This program is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU General Public License for more details.
14 //
15 //  You should have received a copy of the GNU General Public License
16 //  along with this program; if not, write to the Free Software
17 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 
19 #include <cassert>
20 
21 #include <GL/gl.h>
22 
23 #include "../geometry/Constants.h"
24 
25 #include "Cylinder_Sky.h"
26 
27 using Vamos_Geometry::pi;
28 
Cylinder_Sky(int divisions,std::string image,int width,int height)29 Cylinder_Sky::Cylinder_Sky (int divisions, std::string image,
30 							int width, int height) :
31   Sky (image, width, height),
32   m_z_divisions (divisions)
33 {
34   assert (m_z_divisions > 1);
35 }
36 
37 void
draw()38 Cylinder_Sky::draw ()
39 {
40   // Draw the cylinder.
41   for (int i = 0; i < m_z_divisions; i++)
42 	{
43 	  glBegin (GL_QUAD_STRIP);
44 	  for (int j = 0; j <= m_z_divisions * 2; j++)
45 		{
46 		  double tex_x = j / (m_z_divisions * 2.0);
47 		  double x = cos (j * pi / m_z_divisions);
48 		  double y = sin (j * pi / m_z_divisions);
49 		  double tex_z = 1.0 - double (i) / m_z_divisions;
50 		  double z = (2.0 * i) / m_z_divisions - 1.0;
51 
52 		  z = (z + z_pos ()) / z_mag ();
53 		  tex_x += z_rot ();
54 
55 		  glTexCoord2d (tex_x, tex_z);
56 		  glVertex3d (x, y, z);
57 
58 		  tex_z = 1.0 - (i + 1.0) / m_z_divisions;
59 		  z = (2.0 * (i + 1.0)) / m_z_divisions - 1.0;
60 		  z = (z + z_pos ()) / z_mag ();
61 
62 		  glTexCoord2d (tex_x, tex_z);
63 		  glVertex3d (x, y, z);
64 		}
65 	  glEnd ();
66 	}
67 }
68