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: hdavid, amaechler |
---|
13 | Taken from SkySphere |
---|
14 | */ |
---|
15 | |
---|
16 | // TODO: Vektortextur erzeugen und Regionen auswaehlen, Sky... |
---|
17 | |
---|
18 | #include "cloud_effect.h" |
---|
19 | |
---|
20 | #include "util/loading/load_param.h" |
---|
21 | #include "util/loading/factory.h" |
---|
22 | |
---|
23 | #include "glincl.h" |
---|
24 | #include "material.h" |
---|
25 | #include <math.h> |
---|
26 | #include "material.h" |
---|
27 | #include "state.h" |
---|
28 | #include "p_node.h" |
---|
29 | |
---|
30 | #include "parser/tinyxml/tinyxml.h" |
---|
31 | |
---|
32 | using namespace std; |
---|
33 | |
---|
34 | CREATE_FACTORY(CloudEffect, CL_CLOUD_EFFECT); |
---|
35 | |
---|
36 | CloudEffect::CloudEffect(const TiXmlElement* root) |
---|
37 | { |
---|
38 | this->setClassID(CL_CLOUD_EFFECT, "CloudEffect"); |
---|
39 | |
---|
40 | this->init(); |
---|
41 | |
---|
42 | if (root != NULL) |
---|
43 | this->loadParams(root); |
---|
44 | |
---|
45 | this->activate(); |
---|
46 | } |
---|
47 | |
---|
48 | CloudEffect::~CloudEffect() |
---|
49 | { |
---|
50 | this->deactivate(); |
---|
51 | |
---|
52 | //delete this->skyMaterial; |
---|
53 | //gluDeleteQuadric(this->sphereObj); |
---|
54 | } |
---|
55 | |
---|
56 | |
---|
57 | bool CloudEffect::init() |
---|
58 | { |
---|
59 | PRINTF(1)("Initializing CloudEffect\n"); |
---|
60 | |
---|
61 | this->sphereObj = gluNewQuadric(); |
---|
62 | //this->setParentMode(PNODE_MOVEMENT); |
---|
63 | |
---|
64 | gluQuadricTexture(this->sphereObj, GL_TRUE); |
---|
65 | gluQuadricOrientation(this->sphereObj, GLU_INSIDE); |
---|
66 | |
---|
67 | |
---|
68 | this->setRadius(1900.0); |
---|
69 | |
---|
70 | mover = 0.0f; |
---|
71 | |
---|
72 | // Initializing default values |
---|
73 | this->cloudSpeed = 1.0f; |
---|
74 | this->cloudTexture = "pictures/sky/cloud1.jpg"; |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | void CloudEffect::loadParams(const TiXmlElement* root) |
---|
79 | { |
---|
80 | WeatherEffect::loadParams(root); |
---|
81 | |
---|
82 | LoadParam(root, "speed", this, CloudEffect, setCloudAnimation); |
---|
83 | LoadParam(root, "texture", this, CloudEffect, setCloudTexture); |
---|
84 | } |
---|
85 | |
---|
86 | |
---|
87 | bool CloudEffect::activate() |
---|
88 | { |
---|
89 | PRINTF(0)( "Activating CloudEffect with Material %s\n", this->cloudTexture.c_str()); |
---|
90 | |
---|
91 | this->cloudMaterial = new Material("Sky"); |
---|
92 | this->cloudMaterial->setIllum(3); |
---|
93 | this->cloudMaterial->setAmbient(1.0, 1.0, 1.0); |
---|
94 | this->cloudMaterial->setDiffuseMap(this->cloudTexture); |
---|
95 | } |
---|
96 | |
---|
97 | bool CloudEffect::deactivate() |
---|
98 | { |
---|
99 | PRINTF(0)("Deactivating CloudEffect\n"); |
---|
100 | } |
---|
101 | |
---|
102 | void CloudEffect::draw() const |
---|
103 | { |
---|
104 | /* TODO: |
---|
105 | -Load a texture, for now from an existing image, a cloud texture |
---|
106 | -Blend / Overlay this with a blue sky like in the tutorial |
---|
107 | -Animate it (for now move it along the sky) |
---|
108 | */ |
---|
109 | |
---|
110 | glMatrixMode(GL_MODELVIEW); |
---|
111 | glPushMatrix(); |
---|
112 | |
---|
113 | // Move sphere along with the camera |
---|
114 | Vector r = State::getCameraNode()->getAbsCoor(); |
---|
115 | glTranslatef(r.x, r.y, r.z); |
---|
116 | |
---|
117 | // Sky movement |
---|
118 | glRotatef(mover, 0, 0, 1); |
---|
119 | |
---|
120 | cloudMaterial->select(); |
---|
121 | gluSphere(this->sphereObj, this->sphereRadius, 20, 20); |
---|
122 | glPopMatrix(); |
---|
123 | } |
---|
124 | |
---|
125 | void CloudEffect::tick (float dt) |
---|
126 | { |
---|
127 | mover = mover + this->cloudSpeed * dt; |
---|
128 | } |
---|
129 | |
---|
130 | |
---|
131 | /** |
---|
132 | * sets the Radius of the Sphere. |
---|
133 | * @param radius The Radius of The Sphere |
---|
134 | */ |
---|
135 | void CloudEffect::setRadius(float radius) |
---|
136 | { |
---|
137 | this->sphereRadius = radius; |
---|
138 | } |
---|
139 | |
---|
140 | |
---|