Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 6524 was 6524, checked in by patrick, 18 years ago

network: added the planet to the menu

File size: 3.6 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}
59
60
61void Planet::loadParams(const TiXmlElement* root)
62{
63  static_cast<WorldEntity*>(this)->loadParams(root);
64
65  LoadParam(root, "texture", this, Planet, setTexture)
66      .describe("Sets the material on the Planet. The string must be the path relative to the data-dir, and without a trailing .jpg");
67
68  LoadParam(root, "size", this, Planet, setSize)
69      .describe("Sets the Size of the Planet (normally this should be 90% of the maximal viewing Distance).");
70}
71
72
73/**
74 *  Defines which textures should be loaded onto the Planet.
75 * @param textureName the top texture.
76*/
77void Planet::setTexture(const char* textureName)
78{
79  this->material->setDiffuseMap(textureName);
80}
81
82
83/**
84 * @param size The new size of the Planet
85
86 * do not forget to rebuild the Planet after this.
87*/
88void Planet::setSize(float size)
89{
90  this->size = size;
91}
92
93
94
95void Planet::draw() const
96{
97
98  glMatrixMode(GL_MODELVIEW);
99  glPushMatrix();
100
101  /* translate */
102  glTranslatef (this->getAbsCoor ().x,
103                this->getAbsCoor ().y,
104                this->getAbsCoor ().z);
105
106
107  this->material->select();
108
109
110  Vector c;
111  double r = this->size;
112  int n = 100;
113  int method = 1;
114  double theta1 = 0;
115  double theta2 = 2 * M_PI;
116  double phi1 = -M_PI/2.0;
117  double phi2 = M_PI/2.0;
118
119
120  int i,j;
121  double jdivn,j1divn,idivn,dosdivn,unodivn=1/(double)n,ndiv2=(double)n/2,t1,t2,t3,cost1,cost2,cte1,cte3;
122  cte3 = (theta2-theta1)/n;
123  cte1 = (phi2-phi1)/ndiv2;
124  dosdivn = 2*unodivn;
125  Vector e,p,e2,p2;
126
127
128  t2=phi1;
129  cost2=cos(phi1);
130  j1divn=0;
131  for (j=0;j<ndiv2;j++) {
132    t1 = t2;//t1 = phi1 + j * cte1;
133    t2 += cte1;//t2 = phi1 + (j + 1) * cte1;
134    t3 = theta1 - cte3;
135    cost1 = cost2;//cost1=cos(t1);
136    cost2 = cos(t2);
137    e.y = sin(t1);
138    e2.y = sin(t2);
139    p.y = c.y + r * e.y;
140    p2.y = c.y + r * e2.y;
141
142    if (method == 0)
143      glBegin(GL_QUAD_STRIP);
144    else
145      glBegin(GL_TRIANGLE_STRIP);
146
147    idivn=0;
148    jdivn=j1divn;
149    j1divn+=dosdivn;//=2*(j+1)/(double)n;
150    for (i=0;i<=n;i++) {
151       //t3 = theta1 + i * (theta2 - theta1) / n;
152      t3 += cte3;
153      e.x = cost1 * cos(t3);
154       //e.y = sin(t1);
155      e.z = cost1 * sin(t3);
156      p.x = c.x + r * e.x;
157       //p.y = c.y + r * e.y;
158      p.z = c.z + r * e.z;
159      glNormal3f(e.x,e.y,e.z);
160      glTexCoord2f(idivn,jdivn);
161      glVertex3f(p.x,p.y,p.z);
162
163
164      e2.x = cost2 * cos(t3);
165       //e.y = sin(t2);
166      e2.z = cost2 * sin(t3);
167      p2.x = c.x + r * e2.x;
168       //p.y = c.y + r * e.y;
169      p2.z = c.z + r * e2.z;
170      glNormal3f(e2.x,e2.y,e2.z);
171      glTexCoord2f(idivn,j1divn);
172      glVertex3f(p2.x,p2.y,p2.z);
173      idivn += unodivn;
174    }
175    glEnd();
176  }
177}
178
179
180
Note: See TracBrowser for help on using the repository browser.