Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/world_entities/effects/blink.cc @ 10535

Last change on this file since 10535 was 10530, checked in by stefalie, 18 years ago
File size: 2.9 KB
Line 
1/*
2
3   Copyright (C) 2006 orx
4
5   This program is free software; you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation; either version 2, or (at your option)
8   any later version.
9
10### File Specific:
11   main-programmer: Lieni
12*/
13
14#include "blink.h"
15
16#include "util/loading/load_param.h"
17#include "util/loading/factory.h"
18#include "debug.h"
19#include "state.h"
20#include "effects/billboard.h"
21
22
23
24
25ObjectListDefinition(Blink);
26CREATE_FACTORY(Blink);
27
28/**
29 * standart constructor
30 */
31Blink::Blink (const TiXmlElement* root)
32{
33  this->init();
34
35  if(root)
36    this->loadParams(root);
37
38  // calculation of the symbolTime
39  this->symbolTime = this->period / this->blinkSequence.length();
40  //PRINTF(0)("\n\n\nperiod: %f\n\n\n", this->period);
41}
42
43
44/**
45 * destroys a Blink
46 */
47Blink::~Blink ()
48{
49  if(bBoard)
50    delete bBoard;
51}
52
53
54/**
55 * initializes the Blink
56 */
57void Blink::init()
58{
59  this->registerObject(this, Blink::_objectList);
60  this->setName("Blink");
61
62  this->toList(OM_COMMON);
63
64  this->bBoard = new Billboard;
65  this->bBoard->setVisibility(true);
66  this->bBoard->setTexture("textures/light/blink.png");
67
68  /// Standard values
69  this->bBoard->setAbsCoor(0, 0, 0);
70  // default position if not set in xml
71  this->color = Color(1, 0, 0);
72  // 10x10 pxl if not defined in xml
73  this->size = 10;
74  // default period
75  this->period = 1;
76  // default blink sequence
77  this->blinkSequence = "00011234567889998876543211";
78
79  // start values of non-loadable variables
80  this->blinkStr = 0;
81  this->timer = 0;
82  this->seqCounter = 0;
83
84  // ugly hack continued
85  this->setCoor = true;
86}
87
88
89/**
90 *  load params
91 * @param root TiXmlElement object
92 */
93void Blink::loadParams(const TiXmlElement* root)
94{
95  WorldEntity::loadParams(root);
96
97  LoadParam(root, "position", this, Blink, PNode::setAbsCoor);
98  LoadParam(root, "size", this, Blink, setSize);
99  LoadParam(root, "color", this, Blink, setColor);
100  LoadParam(root, "period", this, Blink, setPeriod);
101  LoadParam(root, "sequence", this, Blink, loadBlinkSequence);
102}
103
104
105/**
106 * ticks the Blink
107 * @param dt the time to ticks
108 */
109void Blink::tick(float dt)
110{
111  // ugly hack continued, set absCoor only once
112  if(this->setCoor) {
113    this->bBoard->setAbsCoor(this->getAbsCoor());
114    this->bBoard->setAbsDir(this->getAbsDir());
115    this->bBoard->setRelCoor(this->getRelCoor());
116    this->bBoard->setRelDir(this->getRelDir());
117    this->bBoard->setParent(this);
118    this->setCoor = false;
119    this->symbolTime = this->period / this->blinkSequence.length();
120  }
121
122  timer += dt;
123
124  while(this->timer >= this->symbolTime)
125  {
126    this->blinkStr = (float)((int)(blinkSequence[seqCounter]) - 48) / 9;
127
128    this->timer -= symbolTime;
129
130    seqCounter++;
131    seqCounter %= this->blinkSequence.length();
132  }
133
134  this->bBoard->colorTexture(Color(color.r(), color.g(), color.b(), this->blinkStr));
135}
136
137
138/**
139 * draws the blink
140 */
141void Blink::draw() const
142{
143
144}
Note: See TracBrowser for help on using the repository browser.