Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/world_entities/planet.cc @ 6566

Last change on this file since 6566 was 6525, checked in by patrick, 19 years ago

network: the gamemenu now looks quite nice. but there is more to come! much more! muahahahahaha… i'm realy tired…

File size: 3.7 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   ### File Specific:
12   main-programmer: Patrick Boenzli
13   co-programmer: ...
14*/
15
16#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY
17
18#include "planet.h"
19
20#include "load_param.h"
21#include "factory.h"
22#include "static_model.h"
23
24#include "material.h"
25#include "texture.h"
26
27#include "network_game_manager.h"
28#include "converter.h"
29
30using namespace std;
31
32
33CREATE_FACTORY(Planet, CL_PLANET);
34
35
36
37/**
38 *  initializes a skybox from a XmlElement
39*/
40Planet::Planet(const TiXmlElement* root)
41{
42  this->setClassID(CL_PLANET, "Planet");
43  this->toList(OM_GROUP_01);
44
45  this->material = new Material();
46  this->material->setIllum(10);
47
48  this->loadParams(root);
49}
50
51
52/**
53 *  default destructor
54*/
55Planet::~Planet()
56{
57  PRINTF(5)("Deleting Planet\n");
58  if( this->material)
59    delete this->material;
60}
61
62
63void Planet::loadParams(const TiXmlElement* root)
64{
65  static_cast<WorldEntity*>(this)->loadParams(root);
66
67  LoadParam(root, "texture", this, Planet, setTexture)
68      .describe("Sets the material on the Planet. The string must be the path relative to the data-dir, and without a trailing .jpg");
69
70  LoadParam(root, "size", this, Planet, setSize)
71      .describe("Sets the Size of the Planet (normally this should be 90% of the maximal viewing Distance).");
72}
73
74
75/**
76 *  Defines which textures should be loaded onto the Planet.
77 * @param textureName the top texture.
78*/
79void Planet::setTexture(const char* textureName)
80{
81  this->material->setDiffuseMap(textureName);
82}
83
84
85/**
86 * @param size The new size of the Planet
87
88 * do not forget to rebuild the Planet after this.
89*/
90void Planet::setSize(float size)
91{
92  this->size = size;
93}
94
95
96
97void Planet::draw() const
98{
99
100  glMatrixMode(GL_MODELVIEW);
101  glPushMatrix();
102
103  /* translate */
104  glTranslatef (this->getAbsCoor ().x,
105                this->getAbsCoor ().y,
106                this->getAbsCoor ().z);
107
108
109  this->material->select();
110
111
112  Vector c;
113  double r = this->size;
114  int n = 200;
115  int method = 1;
116  double theta1 = 0;
117  double theta2 = 2 * M_PI;
118  double phi1 = -M_PI/2.0;
119  double phi2 = M_PI/2.0;
120
121
122  int i,j;
123  double jdivn,j1divn,idivn,dosdivn,unodivn=1/(double)n,ndiv2=(double)n/2,t1,t2,t3,cost1,cost2,cte1,cte3;
124  cte3 = (theta2-theta1)/n;
125  cte1 = (phi2-phi1)/ndiv2;
126  dosdivn = 2*unodivn;
127  Vector e,p,e2,p2;
128
129
130  t2=phi1;
131  cost2=cos(phi1);
132  j1divn=0;
133  for (j=0;j<ndiv2;j++) {
134    t1 = t2;//t1 = phi1 + j * cte1;
135    t2 += cte1;//t2 = phi1 + (j + 1) * cte1;
136    t3 = theta1 - cte3;
137    cost1 = cost2;//cost1=cos(t1);
138    cost2 = cos(t2);
139    e.y = sin(t1);
140    e2.y = sin(t2);
141    p.y = c.y + r * e.y;
142    p2.y = c.y + r * e2.y;
143
144    if (method == 0)
145      glBegin(GL_QUAD_STRIP);
146    else
147      glBegin(GL_TRIANGLE_STRIP);
148
149    idivn=0;
150    jdivn=j1divn;
151    j1divn+=dosdivn;//=2*(j+1)/(double)n;
152    for (i=0;i<=n;i++) {
153       //t3 = theta1 + i * (theta2 - theta1) / n;
154      t3 += cte3;
155      e.x = cost1 * cos(t3);
156       //e.y = sin(t1);
157      e.z = cost1 * sin(t3);
158      p.x = c.x + r * e.x;
159       //p.y = c.y + r * e.y;
160      p.z = c.z + r * e.z;
161      glNormal3f(e.x,e.y,e.z);
162      glTexCoord2f(idivn,jdivn);
163      glVertex3f(p.x,p.y,p.z);
164
165
166      e2.x = cost2 * cos(t3);
167       //e.y = sin(t2);
168      e2.z = cost2 * sin(t3);
169      p2.x = c.x + r * e2.x;
170       //p.y = c.y + r * e.y;
171      p2.z = c.z + r * e2.z;
172      glNormal3f(e2.x,e2.y,e2.z);
173      glTexCoord2f(idivn,j1divn);
174      glVertex3f(p2.x,p2.y,p2.z);
175      idivn += unodivn;
176    }
177    glEnd();
178  }
179}
180
181
182
Note: See TracBrowser for help on using the repository browser.