1 | |
---|
2 | /* |
---|
3 | orxonox - the future of 3D-vertical-scrollers |
---|
4 | |
---|
5 | Copyright (C) 2004 orx |
---|
6 | |
---|
7 | This program is free software; you can redistribute it and/or modify |
---|
8 | it under the terms of the GNU General Public License as published by |
---|
9 | the Free Software Foundation; either version 2, or (at your option) |
---|
10 | any later version. |
---|
11 | |
---|
12 | ### File Specific: |
---|
13 | main-programmer: David Gruetter |
---|
14 | co-programmer: Benjamin Grauer |
---|
15 | |
---|
16 | Created by Dave: this file is actually quite similar to player.cc and so is |
---|
17 | skybox.h similar to player.h |
---|
18 | With that said, things should be clear:) |
---|
19 | |
---|
20 | Edited: |
---|
21 | Bensch: more constructors, changeability, comments... |
---|
22 | Patrick: giving it the common orxonox style, not much to do... good work Dave! |
---|
23 | |
---|
24 | */ |
---|
25 | |
---|
26 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
27 | |
---|
28 | |
---|
29 | #include "skybox.h" |
---|
30 | #include "stdincl.h" |
---|
31 | |
---|
32 | #include "material.h" |
---|
33 | #include "vector.h" |
---|
34 | #include "resource_manager.h" |
---|
35 | #include "model.h" |
---|
36 | //#include "world_entity.h" |
---|
37 | |
---|
38 | |
---|
39 | using namespace std; |
---|
40 | |
---|
41 | /** |
---|
42 | \brief Constructs a SkyBox and takes fileName as a map. |
---|
43 | \param fileName the file to take as input for the SkyBox |
---|
44 | */ |
---|
45 | SkyBox::SkyBox(char* fileName) |
---|
46 | { |
---|
47 | this->setClassName("SkyBox"); |
---|
48 | |
---|
49 | this->model = NULL; |
---|
50 | |
---|
51 | this->setMode(PNODE_MOVEMENT); |
---|
52 | |
---|
53 | this->setSize(1900.0); |
---|
54 | this->rebuild(); |
---|
55 | |
---|
56 | this->material = new Material*[6]; |
---|
57 | for (int i = 0; i <6; i++) |
---|
58 | { |
---|
59 | this->material[i] = new Material(); |
---|
60 | this->material[i]->setIllum(3); |
---|
61 | this->material[i]->setAmbient(1.0, 1.0, 1.0); |
---|
62 | } |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | /** |
---|
67 | \brief default destructor |
---|
68 | */ |
---|
69 | SkyBox::~SkyBox() |
---|
70 | { |
---|
71 | PRINTF(5)("Deleting the SkyBox\n"); |
---|
72 | |
---|
73 | for (int i = 0; i < 6; i++) |
---|
74 | delete this->material[i]; |
---|
75 | delete []this->material; |
---|
76 | } |
---|
77 | |
---|
78 | |
---|
79 | void SkyBox::rebuild() |
---|
80 | { |
---|
81 | if (this->model) |
---|
82 | delete model; |
---|
83 | model = new Model(); |
---|
84 | |
---|
85 | model->addVertex (-0.5*size, -0.5*size, 0.5*size); |
---|
86 | model->addVertex (0.5*size, -0.5*size, 0.5*size); |
---|
87 | model->addVertex (-0.5*size, 0.5*size, 0.5*size); |
---|
88 | model->addVertex (0.5*size, 0.5*size, 0.5*size); |
---|
89 | model->addVertex (-0.5*size, 0.5*size, -0.5*size); |
---|
90 | model->addVertex (0.5*size, 0.5*size, -0.5*size); |
---|
91 | model->addVertex (-0.5*size, -0.5*size, -0.5*size); |
---|
92 | model->addVertex (0.5*size, -0.5*size, -0.5*size); |
---|
93 | |
---|
94 | model->addVertexTexture (0.0, 0.0); |
---|
95 | model->addVertexTexture (1.0, 0.0); |
---|
96 | model->addVertexTexture (0.0, 1.0); |
---|
97 | model->addVertexTexture (1.0, 1.0); |
---|
98 | model->addVertexTexture (0.0, 2.0); |
---|
99 | model->addVertexTexture (1.0, 2.0); |
---|
100 | model->addVertexTexture (0.0, 3.0); |
---|
101 | model->addVertexTexture (1.0, 3.0); |
---|
102 | model->addVertexTexture (0.0, 4.0); |
---|
103 | model->addVertexTexture (1.0, 4.0); |
---|
104 | model->addVertexTexture (2.0, 0.0); |
---|
105 | model->addVertexTexture (2.0, 1.0); |
---|
106 | model->addVertexTexture (-1.0, 0.0); |
---|
107 | model->addVertexTexture (-1.0, 1.0); |
---|
108 | |
---|
109 | model->addVertexNormal (0.0, 0.0, 1.0); |
---|
110 | model->addVertexNormal (0.0, 0.0, 1.0); |
---|
111 | model->addVertexNormal (0.0, 0.0, 1.0); |
---|
112 | model->addVertexNormal (0.0, 0.0, 1.0); |
---|
113 | model->addVertexNormal (0.0, 1.0, 0.0); |
---|
114 | model->addVertexNormal (0.0, 1.0, 0.0); |
---|
115 | model->addVertexNormal (0.0, 1.0, 0.0); |
---|
116 | model->addVertexNormal (0.0, 1.0, 0.0); |
---|
117 | model->addVertexNormal (0.0, 0.0, -1.0); |
---|
118 | model->addVertexNormal (0.0, 0.0, -1.0); |
---|
119 | model->addVertexNormal (0.0, 0.0, -1.0); |
---|
120 | model->addVertexNormal (0.0, 0.0, -1.0); |
---|
121 | model->addVertexNormal (0.0, -1.0, 0.0); |
---|
122 | model->addVertexNormal (0.0, -1.0, 0.0); |
---|
123 | model->addVertexNormal (0.0, -1.0, 0.0); |
---|
124 | model->addVertexNormal (0.0, -1.0, 0.0); |
---|
125 | model->addVertexNormal (1.0, 0.0, 0.0); |
---|
126 | model->addVertexNormal (1.0, 0.0, 0.0); |
---|
127 | model->addVertexNormal (1.0, 0.0, 0.0); |
---|
128 | model->addVertexNormal (1.0, 0.0, 0.0); |
---|
129 | model->addVertexNormal (-1.0, 0.0, 0.0); |
---|
130 | model->addVertexNormal (-1.0, 0.0, 0.0); |
---|
131 | model->addVertexNormal (-1.0, 0.0, 0.0); |
---|
132 | model->addVertexNormal (-1.0, 0.0, 0.0); |
---|
133 | |
---|
134 | model->addUseMtl(material[0]); |
---|
135 | model->addFace (4, 3, 1,1,1, 2,2,2, 4,4,3, 3,3,4); |
---|
136 | model->addUseMtl(material[1]); |
---|
137 | model->addFace (4, 3, 3,3,5, 4,4,6, 6,6,7, 5,5,8); |
---|
138 | model->addUseMtl(material[2]); |
---|
139 | model->addFace (4, 3, 5,5,9, 6,6,10, 8,8,11, 7,7,12); |
---|
140 | model->addUseMtl(material[3]); |
---|
141 | model->addFace (4, 3, 7,7,13, 8,8,14, 2,10,15, 1,9,16); |
---|
142 | model->addUseMtl(material[4]); |
---|
143 | model->addFace (4, 3, 2,2,17, 8,11,18, 6,12,19, 4,4,20); |
---|
144 | model->addUseMtl(material[5]); |
---|
145 | model->addFace (4, 3, 7,13,21, 1,1,22, 3,3,23, 5,14,24); |
---|
146 | } |
---|
147 | |
---|
148 | /** |
---|
149 | \brief Defines which texture should be loaded onto the SkyBox. |
---|
150 | \param fileName The filename of the Texture |
---|
151 | */ |
---|
152 | void SkyBox::setTexture(char* top, char* bottom, char* left, char* right, char* front, char* back) |
---|
153 | { |
---|
154 | this->material[0]->setDiffuseMap(top); |
---|
155 | this->material[1]->setDiffuseMap(bottom); |
---|
156 | this->material[2]->setDiffuseMap(left); |
---|
157 | this->material[3]->setDiffuseMap(right); |
---|
158 | this->material[4]->setDiffuseMap(front); |
---|
159 | this->material[5]->setDiffuseMap(back); |
---|
160 | } |
---|
161 | |
---|
162 | |
---|
163 | /** |
---|
164 | \brief draws the SkyBox |
---|
165 | |
---|
166 | This part is normally precessed in the "Painting Phase". |
---|
167 | */ |
---|
168 | void SkyBox::draw() |
---|
169 | { |
---|
170 | glPushMatrix(); |
---|
171 | glMatrixMode(GL_MODELVIEW); |
---|
172 | Vector r = this->getAbsCoor(); |
---|
173 | glTranslatef(r.x, r.y, r.z); |
---|
174 | |
---|
175 | this->material[1]->select(); |
---|
176 | |
---|
177 | this->model->draw(); |
---|
178 | |
---|
179 | glPopMatrix(); |
---|
180 | } |
---|
181 | |
---|
182 | |
---|
183 | /** |
---|
184 | \brief sets the Radius of the Sphere. |
---|
185 | \param radius The Radius of The Sphere |
---|
186 | */ |
---|
187 | void SkyBox::setSize(float size) |
---|
188 | { |
---|
189 | this->size = size; |
---|
190 | } |
---|