[go: up one dir, main page]

Menu

[f338fb]: / caelum / Cylinder_Sky.cc  Maximize  Restore  History

Download this file

69 lines (57 with data), 1.8 kB

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