[3411] | 1 | |
---|
[3416] | 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 |
---|
[3421] | 14 | co-programmer: Benjamin Grauer |
---|
[3484] | 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! |
---|
[3416] | 23 | |
---|
[3411] | 24 | */ |
---|
| 25 | |
---|
[3590] | 26 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
| 27 | |
---|
[3608] | 28 | |
---|
[3796] | 29 | #include "skybox.h" |
---|
[3411] | 30 | #include "stdincl.h" |
---|
[3608] | 31 | |
---|
| 32 | #include "material.h" |
---|
[3411] | 33 | #include "vector.h" |
---|
[3796] | 34 | #include "resource_manager.h" |
---|
| 35 | #include "model.h" |
---|
[3608] | 36 | //#include "world_entity.h" |
---|
[3411] | 37 | |
---|
[3608] | 38 | |
---|
[3411] | 39 | using namespace std; |
---|
| 40 | |
---|
[3416] | 41 | /** |
---|
[3796] | 42 | \brief Constructs a SkyBox and takes fileName as a map. |
---|
| 43 | \param fileName the file to take as input for the SkyBox |
---|
[3419] | 44 | */ |
---|
[3796] | 45 | SkyBox::SkyBox(char* fileName) |
---|
[3419] | 46 | { |
---|
[3796] | 47 | this->setClassName("SkyBox"); |
---|
[3801] | 48 | this->material = new Material*[6]; |
---|
| 49 | for (int i = 0; i <6; i++) |
---|
| 50 | { |
---|
| 51 | this->material[i] = new Material(); |
---|
| 52 | this->material[i]->setIllum(3); |
---|
[3805] | 53 | this->material[i]->setDiffuse(0.0,0.0,0.0); |
---|
| 54 | this->material[i]->setSpecular(0.0,0.0,0.0); |
---|
| 55 | this->material[i]->setAmbient(2.0, 2.0, 2.0); |
---|
[3801] | 56 | } |
---|
[3803] | 57 | this->setMode(PNODE_MOVEMENT); |
---|
| 58 | |
---|
| 59 | this->setSize(1900.0); |
---|
[3411] | 60 | } |
---|
| 61 | |
---|
[3507] | 62 | |
---|
[3416] | 63 | /** |
---|
| 64 | \brief default destructor |
---|
| 65 | */ |
---|
[3796] | 66 | SkyBox::~SkyBox() |
---|
[3411] | 67 | { |
---|
[3801] | 68 | PRINTF(5)("Deleting the SkyBox\n"); |
---|
| 69 | |
---|
| 70 | for (int i = 0; i < 6; i++) |
---|
| 71 | delete this->material[i]; |
---|
| 72 | delete []this->material; |
---|
[3419] | 73 | } |
---|
[3411] | 74 | |
---|
[3803] | 75 | /** |
---|
| 76 | \brief sets A set of textures when just giving a Name and an extension: |
---|
[3763] | 77 | |
---|
[3803] | 78 | usage: give this function an argument like |
---|
| 79 | setTexture("skybox", "jpg"); |
---|
| 80 | and it will convert this to |
---|
| 81 | setTextures("skybox_top.jpg", "skybox_bottom.jpg", "skybox_left.jpg", |
---|
| 82 | "skybox_right.jpg", "skybox_front.jpg", "skybox_back.jpg"); |
---|
| 83 | */ |
---|
| 84 | void SkyBox::setTexture(const char* name, const char* extension) |
---|
| 85 | { |
---|
| 86 | char* top = new char[strlen(name)+strlen(extension)+ 6]; |
---|
| 87 | char* bottom = new char[strlen(name)+strlen(extension)+ 9]; |
---|
| 88 | char* left = new char[strlen(name)+strlen(extension)+ 7]; |
---|
| 89 | char* right = new char[strlen(name)+strlen(extension)+ 8]; |
---|
| 90 | char* front = new char[strlen(name)+strlen(extension)+ 8]; |
---|
| 91 | char* back = new char[strlen(name)+strlen(extension)+ 7]; |
---|
| 92 | |
---|
| 93 | sprintf(top, "%s_top.%s", name, extension); |
---|
| 94 | sprintf(bottom, "%s_bottom.%s", name, extension); |
---|
| 95 | sprintf(left, "%s_left.%s", name, extension); |
---|
| 96 | sprintf(right, "%s_right.%s", name, extension); |
---|
| 97 | sprintf(front, "%s_front.%s", name, extension); |
---|
| 98 | sprintf(back, "%s_back.%s", name, extension); |
---|
| 99 | |
---|
| 100 | this->setTextures(top, bottom, left, right, front, back); |
---|
| 101 | |
---|
| 102 | delete []top; |
---|
| 103 | delete []bottom; |
---|
| 104 | delete []left; |
---|
| 105 | delete []right; |
---|
| 106 | delete []front; |
---|
| 107 | delete []back; |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | /** |
---|
| 111 | \brief Defines which textures should be loaded onto the SkyBox. |
---|
| 112 | \param top the top texture. |
---|
| 113 | \param bottom the bottom texture. |
---|
| 114 | \param left the left texture. |
---|
| 115 | \param right the right texture. |
---|
| 116 | \param front the front texture. |
---|
| 117 | \param back the back texture. |
---|
| 118 | */ |
---|
| 119 | void SkyBox::setTextures(const char* top, const char* bottom, const char* left, const char* right, const char* front, const char* back) |
---|
| 120 | { |
---|
| 121 | this->material[0]->setDiffuseMap(top); |
---|
| 122 | this->material[1]->setDiffuseMap(bottom); |
---|
| 123 | this->material[2]->setDiffuseMap(left); |
---|
| 124 | this->material[3]->setDiffuseMap(right); |
---|
| 125 | this->material[4]->setDiffuseMap(front); |
---|
| 126 | this->material[5]->setDiffuseMap(back); |
---|
[3805] | 127 | |
---|
| 128 | this->rebuild(); |
---|
[3803] | 129 | } |
---|
| 130 | |
---|
| 131 | /** |
---|
[3806] | 132 | \param size The new size of the SkyBox |
---|
[3803] | 133 | */ |
---|
| 134 | void SkyBox::setSize(float size) |
---|
| 135 | { |
---|
| 136 | this->size = size; |
---|
[3805] | 137 | |
---|
| 138 | this->rebuild(); |
---|
[3803] | 139 | } |
---|
| 140 | |
---|
| 141 | /** |
---|
[3807] | 142 | \brief draws the SkyBox |
---|
| 143 | */ |
---|
| 144 | void SkyBox::draw() |
---|
| 145 | { |
---|
| 146 | glPushMatrix(); |
---|
| 147 | glMatrixMode(GL_MODELVIEW); |
---|
| 148 | Vector r = this->getAbsCoor(); |
---|
| 149 | glTranslatef(r.x, r.y, r.z); |
---|
| 150 | |
---|
| 151 | this->model->draw(); |
---|
| 152 | |
---|
| 153 | glPopMatrix(); |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | |
---|
| 157 | /** |
---|
[3803] | 158 | \brief rebuilds the SkyBox |
---|
| 159 | |
---|
| 160 | this must be done, when changing the Size of the Skybox (runtime-efficency) |
---|
| 161 | */ |
---|
[3801] | 162 | void SkyBox::rebuild() |
---|
| 163 | { |
---|
| 164 | if (this->model) |
---|
| 165 | delete model; |
---|
| 166 | model = new Model(); |
---|
| 167 | |
---|
[3805] | 168 | model->addVertex (-0.5*size, -0.5*size, 0.5*size); |
---|
[3801] | 169 | model->addVertex (0.5*size, -0.5*size, 0.5*size); |
---|
| 170 | model->addVertex (-0.5*size, 0.5*size, 0.5*size); |
---|
| 171 | model->addVertex (0.5*size, 0.5*size, 0.5*size); |
---|
| 172 | model->addVertex (-0.5*size, 0.5*size, -0.5*size); |
---|
| 173 | model->addVertex (0.5*size, 0.5*size, -0.5*size); |
---|
| 174 | model->addVertex (-0.5*size, -0.5*size, -0.5*size); |
---|
| 175 | model->addVertex (0.5*size, -0.5*size, -0.5*size); |
---|
| 176 | |
---|
| 177 | model->addVertexTexture (0.0, 0.0); |
---|
| 178 | model->addVertexTexture (1.0, 0.0); |
---|
[3805] | 179 | model->addVertexTexture (1.0, 1.0); |
---|
[3801] | 180 | model->addVertexTexture (0.0, 1.0); |
---|
| 181 | |
---|
| 182 | model->addVertexNormal (0.0, 0.0, 1.0); |
---|
| 183 | model->addVertexNormal (0.0, 1.0, 0.0); |
---|
| 184 | model->addVertexNormal (0.0, 0.0, -1.0); |
---|
| 185 | model->addVertexNormal (0.0, -1.0, 0.0); |
---|
| 186 | model->addVertexNormal (1.0, 0.0, 0.0); |
---|
| 187 | model->addVertexNormal (-1.0, 0.0, 0.0); |
---|
| 188 | |
---|
| 189 | model->addUseMtl(material[0]); |
---|
[3805] | 190 | model->addFace (4, 3, 3,2,4, 4,3,4, 6,4,4, 5,1,4); // top |
---|
[3801] | 191 | model->addUseMtl(material[1]); |
---|
[3805] | 192 | model->addFace (4, 3, 7,4,2, 8,1,2, 2,2,2, 1,3,2); // bottom |
---|
[3801] | 193 | model->addUseMtl(material[2]); |
---|
[3805] | 194 | model->addFace (4, 3, 1,1,3, 2,2,3, 4,3,3, 3,4,3); // left |
---|
[3801] | 195 | model->addUseMtl(material[3]); |
---|
[3805] | 196 | model->addFace (4, 3, 5,3,1, 6,4,1, 8,1,1, 7,2,1); // right |
---|
[3801] | 197 | model->addUseMtl(material[4]); |
---|
[3805] | 198 | model->addFace (4, 3, 2,1,6, 8,2,6, 6,3,6, 4,4,6); // front |
---|
[3801] | 199 | model->addUseMtl(material[5]); |
---|
[3805] | 200 | model->addFace (4, 3, 7,1,5, 1,2,5, 3,3,5, 5,4,5); // back |
---|
[3803] | 201 | |
---|
| 202 | model->finalize(); |
---|
[3801] | 203 | } |
---|