Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/blink/src/world_entities/effects/blink.cc @ 10325

Last change on this file since 10325 was 10325, checked in by stefalie, 17 years ago
File size: 5.1 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2006 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:
13*/
14
15#include "blink.h"
16
17#include "util/loading/load_param.h"
18#include "util/loading/factory.h"
19#include "debug.h"
20#include "state.h"
21
22
23#include "material.h"
24
25
26
27
28
29
30ObjectListDefinition(Blink);
31CREATE_FACTORY(Blink);
32
33/**
34 * standart constructor
35 */
36Blink::Blink (const TiXmlElement* root)
37{
38  this->init();
39
40  if( root)
41    this->loadParams(root);
42}
43
44
45/**
46 * destroys a Blink
47 */
48Blink::~Blink ()
49{
50  if (this->material)
51    delete this->material;
52}
53
54
55/**
56 * initializes the Blink
57 */
58void Blink::init()
59{
60  this->registerObject(this, Blink::_objectList);
61  this->setName("Blink");
62
63  this->toList(OM_COMMON);
64
65  this->material = new Material();
66  //this->material->setIllum(0);
67  //this->material->setDiffuse(1.0,1.0,1.0);
68  //this->material->setTransparency(0.0);
69 // this->material->setSpecular(0.0,0.0,0.0);
70 // this->material->setAmbient(1.0, 1.0, 1.0);
71  //this->material->setBlendFunc(GL_ZERO,GL_ZERO);
72  //this->material->setDiffuseMap("pictures/rblink2.png");
73  this->material->setDiffuseMap("maps/star_alpha.png");
74  //this->setAbsCoor(0, 0, 0);d
75  //this->setVisibiliy(true);
76  // this->setSize(5, 5);
77
78  //srand((unsigned)time(NULL));
79
80
81  /// Standard values
82  this->setAbsCoor(0, 0, 0); 
83  this->position = Vector(0, 0, 0); ///remove
84  this->color = Vector(255, 255, 255);
85  this->size = 10;
86  this->omega = 10;
87  this->angle = rand() % 1000;
88  PRINTF(0)("\n\n\n\n\n\n\nangle: %f\n\n\n\n\n\n\n\n", this->angle);
89  this->angle *= 2 * M_PI;
90  PRINTF(0)("\n\n\n\n\n\n\nangle: %f\n\n\n\n\n\n\n\n", this->angle);
91}
92
93
94/**
95 *  load params
96 * @param root TiXmlElement object
97 */
98void Blink::loadParams(const TiXmlElement* root)
99{
100  WorldEntity::loadParams(root);
101
102  LoadParam(root, "position", this, Blink, setPosition);
103  LoadParam(root, "size", this, Blink, setSize);
104  LoadParam(root, "color", this, Blink, setColor);
105  LoadParam(root, "omega", this, Blink, setOmega);
106//   LoadParam(root, "watersize", this, Blink, setWaterSize);
107//   LoadParam(root, "wateruv", this, Blink, setWaterUV);
108//   LoadParam(root, "waterflow", this, Blink, setWaterFlow);
109//   LoadParam(root, "lightpos", this, Blink, setLightPos);
110//   LoadParam(root, "waterangle", this, Blink, setWaterAngle);
111//   LoadParam(root, "normalmapscale", this, Blink, setNormalMapScale);
112//   LoadParam(root, "shinesize", this, Blink, setShineSize);
113//   LoadParam(root, "shinestrength", this, Blink, setShineStrength);
114//   LoadParam(root, "reflstrength", this, Blink, setReflStrength);
115//   LoadParam(root, "refraction", this, Blink, setRefraction);
116//   LoadParam(root, "watercolor", this, Blink, setWaterColor);
117  /*LoadParam(root, "texture", this->material, Material, setDiffuseMap)
118      .describe("the texture-file to load onto the Blink");
119
120  LoadParam(root, "size", this, Blink, setSize)
121  .describe("the size of the Blink in Pixels");*/
122}
123
124
125/**
126 * ticks the Blink
127 * @param dt the time to ticks
128 */
129void Blink::tick(float dt)
130{
131  this->angle += dt * this->omega;
132
133  if (this->angle > 2 * M_PI)
134    this->angle -= 2 * M_PI;
135
136  this->blinkStr = sinf(angle);
137}
138
139
140/**
141 * draws the blink
142 */
143void Blink::draw() const
144{
145  glPushAttrib(GL_ENABLE_BIT);
146  glEnable(GL_LIGHTING); //glDisable(GL_LIGHTING);
147  glDisable(GL_FOG);
148  glMatrixMode(GL_MODELVIEW);
149  glPushMatrix();
150
151//   Vector pos = this->getAbsCoor();
152//   Vector dir = pos - State::getCameraNode()->getAbsCoor();
153//   dir.normalize();
154//
155//   Vector up = Vector(0, 1, 0);
156//   Vector h = dir.cross(up);
157//
158//   Vector pos = this->getAbsCoor();
159//   glTranslatef(pos.x, pos.y, pos.z);
160
161    /* translate */
162//     glTranslatef (this->getAbsCoor ().x,
163//                   this->getAbsCoor ().y,
164//                   this->getAbsCoor ().z);
165//     Vector tmpRot = this->getAbsDir().getSpacialAxis();
166//     glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
167
168//   glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Set The Blending Function For Translucency
169//   glEnable(GL_BLEND);
170//   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
171//   glShadeModel(GL_SMOOTH);
172
173
174  Vector camCoor = State::getCameraNode()->getAbsCoor();
175  Vector diff = camCoor - this->position;
176
177  //glTranslatef(position.x + size/2, position.y + size/2, position.z);
178
179  glTranslatef(this->position.x - this->size/2, this->position.y - this->size/2, this->position.z);
180
181//   Vector view = this->getAbsCoor() - State::getCameraNode()->getAbsCoor();
182//   view.normalize();
183//
184//   Vector up = Vector(0, 1, 0);
185//   Vector h = view.cross(up);
186
187  this->material->select();
188
189
190  glColor4ub(this->color.x, this->color.y, this->color.z, 127.5*(this->blinkStr + 1));
191  glBegin(GL_QUADS);
192    glTexCoord2f(1, 1); glVertex3f(0, 0, 0);
193    glTexCoord2f(1, 0); glVertex3f(this->size, 0, 0);
194    glTexCoord2f(0, 0); glVertex3f(this->size, this->size, 0);
195    glTexCoord2f(0, 1); glVertex3f(0, this->size, 0);
196  glEnd();
197
198
199  glPopMatrix();
200  glPopAttrib();
201}
Note: See TracBrowser for help on using the repository browser.