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: Filip Gospodinov |
---|
13 | co-programmer: |
---|
14 | */ |
---|
15 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_WORLD_ENTITY |
---|
16 | |
---|
17 | |
---|
18 | #include "executor/executor.h" |
---|
19 | #include "util/loading/factory.h" |
---|
20 | #include "util/loading/load_param.h" |
---|
21 | #include "blackscreen.h" |
---|
22 | #include "debug.h" |
---|
23 | #include "material.h" |
---|
24 | #include "state.h" |
---|
25 | |
---|
26 | ObjectListDefinition(BlackScreen); |
---|
27 | CREATE_FACTORY(BlackScreen); |
---|
28 | |
---|
29 | |
---|
30 | |
---|
31 | /** |
---|
32 | * |
---|
33 | */ |
---|
34 | BlackScreen::BlackScreen() |
---|
35 | { |
---|
36 | this->init(); |
---|
37 | |
---|
38 | |
---|
39 | } |
---|
40 | |
---|
41 | |
---|
42 | /** |
---|
43 | * |
---|
44 | */ |
---|
45 | BlackScreen::BlackScreen(const TiXmlElement* root) |
---|
46 | { |
---|
47 | this->init(); |
---|
48 | |
---|
49 | if( root != NULL) |
---|
50 | this->loadParams(root); |
---|
51 | |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | /** |
---|
56 | * |
---|
57 | */ |
---|
58 | BlackScreen::~BlackScreen() |
---|
59 | {} |
---|
60 | |
---|
61 | |
---|
62 | /** |
---|
63 | * |
---|
64 | */ |
---|
65 | void BlackScreen::init() |
---|
66 | { |
---|
67 | this->registerObject(this, BlackScreen::_objectList); |
---|
68 | this->toList(OM_GROUP_00); |
---|
69 | |
---|
70 | this->material = new Material(); |
---|
71 | this->material->setDiffuse(0,0,0); |
---|
72 | this->material->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
---|
73 | |
---|
74 | i=0; |
---|
75 | state=0; |
---|
76 | fadeSpeed=1; |
---|
77 | |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
81 | /** |
---|
82 | * loads the Settings of a MD2Creature from an XML-element. |
---|
83 | * @param root the XML-element to load the MD2Creature's properties from |
---|
84 | */ |
---|
85 | void BlackScreen::loadParams(const TiXmlElement* root) |
---|
86 | { |
---|
87 | WorldEntity::loadParams(root); |
---|
88 | } |
---|
89 | |
---|
90 | |
---|
91 | |
---|
92 | |
---|
93 | void BlackScreen::draw() const |
---|
94 | { |
---|
95 | glPushAttrib(GL_ENABLE_BIT); |
---|
96 | glDisable(GL_LIGHTING); |
---|
97 | glEnable(GL_BLEND); // Turn Blending On |
---|
98 | |
---|
99 | glMatrixMode(GL_MODELVIEW); |
---|
100 | glPushMatrix(); |
---|
101 | /* translate */ |
---|
102 | glTranslatef (this->getAbsCoor ().x, |
---|
103 | this->getAbsCoor ().y, |
---|
104 | this->getAbsCoor ().z); |
---|
105 | Vector tmpRot = this->getAbsDir().getSpacialAxis(); |
---|
106 | glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z ); |
---|
107 | |
---|
108 | this->material->setTransparency(i); |
---|
109 | this->material->select(); |
---|
110 | |
---|
111 | glBegin(GL_QUADS); |
---|
112 | glVertex3f(0.,-100.0f,-100.0f); |
---|
113 | glVertex3f(0., -100.0f,100.0f); |
---|
114 | glVertex3f(0., 100.0f,100.0f); |
---|
115 | glVertex3f(0., 100.0f,-100.0f); |
---|
116 | |
---|
117 | glEnd(); |
---|
118 | |
---|
119 | glPopMatrix(); |
---|
120 | glPopAttrib(); |
---|
121 | } |
---|
122 | |
---|
123 | /** |
---|
124 | * |
---|
125 | */ |
---|
126 | void BlackScreen::tick (float time) |
---|
127 | { |
---|
128 | if (state == true) |
---|
129 | fadeOut(); |
---|
130 | else |
---|
131 | fadeIn(); |
---|
132 | } |
---|
133 | |
---|
134 | void BlackScreen::fadeIn() |
---|
135 | { |
---|
136 | if (i>0) |
---|
137 | i=i-0.005*fadeSpeed; |
---|
138 | else |
---|
139 | this->toList(OM_DEAD); |
---|
140 | } |
---|
141 | |
---|
142 | void BlackScreen::fadeOut() |
---|
143 | { |
---|
144 | if (i<=1) |
---|
145 | i=i+0.005*fadeSpeed; |
---|
146 | } |
---|
147 | |
---|
148 | void BlackScreen::toggleFade () |
---|
149 | { |
---|
150 | this->state= !this->state; |
---|
151 | |
---|
152 | if(state) |
---|
153 | { |
---|
154 | this->toList(OM_COMMON); |
---|
155 | } |
---|
156 | } |
---|
157 | |
---|
158 | void BlackScreen::changeFadeSpeed(float newSpeed) |
---|
159 | { |
---|
160 | fadeSpeed=newSpeed; |
---|
161 | } |
---|
162 | |
---|
163 | bool BlackScreen::isBlack() |
---|
164 | { |
---|
165 | if (i==1) |
---|
166 | return 1; |
---|
167 | else |
---|
168 | return 0; |
---|
169 | } |
---|
170 | |
---|
171 | bool BlackScreen::isTrans() |
---|
172 | { |
---|
173 | if (i==0) |
---|
174 | return 1; |
---|
175 | else |
---|
176 | return 0; |
---|
177 | } |
---|