Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/effects/wobblegrid.cc @ 10442

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

merged the branche playability into the trunk

File size: 4.5 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: David Hasenfratz
13*/
14
15#include "wobblegrid.h"
16
17#include "util/loading/load_param.h"
18#include "util/loading/factory.h"
19
20#include "graphics_engine.h"
21#include "material.h"
22#include "glincl.h"
23#include "state.h"
24#include "grid.h"
25
26#include <assert.h>
27#include "debug.h"
28
29
30
31ObjectListDefinition(Wobblegrid);
32CREATE_FACTORY(Wobblegrid);
33
34/**
35 * Wobble Grids are grids which "wobble"
36 * Wobbling is realized through fixed center and sin wave outwards
37 * For the beginning the grid will be a 5x5
38 */
39
40/**
41 * standart constructor
42 */
43Wobblegrid::Wobblegrid (const TiXmlElement* root)
44{
45  this->size  = 5;
46
47  this->init();
48
49  if( root)
50    this->loadParams(root);
51}
52
53Wobblegrid::Wobblegrid (int size, const TiXmlElement* root)
54{
55  this->size  = size;
56
57  this->init();
58
59  if( root)
60    this->loadParams(root);
61}
62
63
64/**
65 * destroys a Wobblegrid
66 */
67Wobblegrid::~Wobblegrid ()
68{
69  if (this->material)
70    delete this->material;
71}
72
73
74/**
75 * initializes the Wobblegrid
76 */
77void Wobblegrid::init()
78{
79  this->registerObject(this, Wobblegrid::_objectList);
80  this->setName("Wobblegrid");
81
82  this->material = new Material();
83  this->material->setBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
84  this->setAbsCoor(0, 0, 0);
85  //this->setVisibiliy(true);
86 
87  this->subdivision = 5;
88
89  this->grid  = new Grid( this->size, this->size, this->subdivision, this->subdivision);
90  this->angularSpeed = M_PI; //180;
91  this->setModel(this->grid);
92
93  this->setUpdateFunction((*sinf));
94}
95
96
97/**
98 *  load params
99 * @param root TiXmlElement object
100 */
101void Wobblegrid::loadParams(const TiXmlElement* root)
102{
103  /*LoadParam(root, "texture", this->material, Material, setDiffuseMap)
104      .describe("the texture-file to load onto the Wobblegrid");
105
106  LoadParam(root, "size", this, Wobblegrid, setSize)
107  .describe("the size of the Wobblegrid in Pixels");*/
108}
109
110
111
112/**
113 * sets the material to load
114 * @param textureFile The texture-file to load
115 */
116void Wobblegrid::setTexture(const std::string& textureFile)
117{
118  this->material->setBlendFunc(GL_SRC_ALPHA,GL_ONE);
119  this->material->setDiffuseMap(textureFile);
120}
121
122
123/**
124 * ticks the Wobblegrid
125 * @param dt the time to ticks
126 */
127void Wobblegrid::tick(float dt)
128{
129  angle += dt * angularSpeed;
130  if (angle > 2 * M_PI)
131    angle -= 2 * M_PI;
132
133  //Vector vec;
134  float fac = 1.0 / (this->subdivision - 1);
135  for( int z=1; z < 4; z++)
136  {
137    for( int x=1; x < 4; x++)
138    {
139      //if(x==2 && z == 2)
140      //  continue;
141
142      Vector2D& vec = this->grid->texCoord(z*this->subdivision + x);
143      vec.= (x * fac + sgn(x-2)*updateWobble(angle)*fac/2.0);
144      vec.= (z * fac + sgn(z-2)*updateWobble(angle)*fac/2.0);
145    }
146  }
147  //this->grid->finalize();
148  this->orient();
149}
150
151
152/**
153 * draws the billboard
154 */
155void Wobblegrid::draw() const
156{
157
158//   this->material->select();
159//   WorldEntity::draw();
160//   return;
161
162
163  if( !this->isVisible())
164    return;
165
166  glPushAttrib(GL_ENABLE_BIT);
167  glDisable(GL_LIGHTING);
168  glDisable(GL_FOG);
169
170  glMatrixMode(GL_MODELVIEW);
171  glPushMatrix();
172
173  //glTranslatef(this->getAbsCoor().x, this->getAbsCoor().y, this->getAbsCoor().z);
174  //glTranslatef(0,0,0);
175  this->material->select();
176
177  glDisable(GL_BLEND);
178  glEnable( GL_ALPHA_TEST);
179  glAlphaFunc( GL_GEQUAL, .5);
180
181  glTranslatef (this->getAbsCoor ().x,
182                  this->getAbsCoor ().y,
183                  this->getAbsCoor ().z);
184
185  Vector tmpRot = this->getAbsDir().getSpacialAxis();
186  glRotatef (this->getAbsDir().getSpacialAxisAngle(), tmpRot.x, tmpRot.y, tmpRot.z );
187
188  //Quaternion  dir = Quaternion(this->getAbsDir().getSpacialAxisAngle(),view);
189  //this->setAbsDir(dir);
190  //glRotatef(this->angle, 0.0, 0.0, 1.0);
191  this->grid->draw();
192
193  glPopMatrix();
194
195  glPopAttrib();
196}
197
198void Wobblegrid::orient()
199{
200
201  Vector view = this->getAbsCoor() - State::getCameraNode()->getAbsCoor();
202//   view.normalize();
203
204  Vector up = Vector(0, 1, 0);
205//   if ( up.dot(view) == 0 )
206//     up = Vector(1, 0, 0);
207//   if ( up.dot(view) == 0 )
208//     up = Vector (0, 0, 1);
209
210  Vector h = up.cross(view.getNormalized());
211  up = h.cross(view.getNormalized());
212  Quaternion dir = Quaternion::lookAt( this->getAbsCoor(), this->getAbsCoor() + up, view);
213//   Quaternion dir = Quaternion::lookAt( Vector(), view, up);
214  this->setAbsDir(dir);
215}
Note: See TracBrowser for help on using the repository browser.