Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10507 was 10491, checked in by patrick, 18 years ago

merged blinki branche back to trunk

File size: 2.7 KB
RevLine 
[10175]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:
[10431]11   main-programmer: Lieni
[10175]12*/
13
14#include "blink.h"
15
16#include "util/loading/load_param.h"
17#include "util/loading/factory.h"
18#include "debug.h"
[10253]19#include "state.h"
[10407]20#include "effects/billboard.h"
[10175]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
[10431]35  if(root)
[10175]36    this->loadParams(root);
[10445]37
38  // calculation of the symbolTime
39  this->symbolTime = this->period / this->blinkSequence.length();
[10491]40  //PRINTF(0)("\n\n\nperiod: %f\n\n\n", this->period);
[10175]41}
42
43
44/**
45 * destroys a Blink
46 */
47Blink::~Blink ()
48{
[10431]49  if(bBoard)
50    delete bBoard;
[10175]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
[10407]64  this->bBoard = new Billboard;
65  this->bBoard->setVisibiliy(true);
[10445]66  this->bBoard->setTexture("textures/light/blink.png");
[10407]67
[10325]68  /// Standard values
[10431]69  this->bBoard->setAbsCoor(0, 0, 0);
70  // default position if not set in xml
[10426]71  this->color = Color(1, 0, 0);
[10429]72  // 10x10 pxl if not defined in xml
[10253]73  this->size = 10;
[10445]74  // default period
75  this->period = 1;
76  // default blink sequence
77  this->blinkSequence = "00011234567889998876543211";
[10431]78
[10445]79  // start values of non-loadable variables
80  this->blinkStr = 0;
81  this->timer = 0;
82  this->seqCounter = 0;
[10491]83
84  // ugly hack continued
85  this->setCoor = true;
[10175]86}
87
88
89/**
90 *  load params
91 * @param root TiXmlElement object
92 */
93void Blink::loadParams(const TiXmlElement* root)
94{
[10253]95  WorldEntity::loadParams(root);
96
[10491]97  LoadParam(root, "position", this, Blink, PNode::setAbsCoor);
[10253]98  LoadParam(root, "size", this, Blink, setSize);
[10325]99  LoadParam(root, "color", this, Blink, setColor);
[10445]100  LoadParam(root, "period", this, Blink, setPeriod);
101  LoadParam(root, "sequence", this, Blink, loadBlinkSequence);
[10175]102}
103
104
105/**
106 * ticks the Blink
107 * @param dt the time to ticks
108 */
109void Blink::tick(float dt)
110{
[10491]111  // ugly hack continued, set absCoor only once
112  if(this->setCoor) {
113    this->bBoard->setAbsCoor(this->getAbsCoor());
114    this->setCoor = false;
115    this->symbolTime = this->period / this->blinkSequence.length();
116  }
117
[10445]118  timer += dt;
[10325]119
[10445]120  while(this->timer >= this->symbolTime)
121  {
122    this->blinkStr = (float)((int)(blinkSequence[seqCounter]) - 48) / 9;
[10325]123
[10445]124    this->timer -= symbolTime;
[10427]125
[10445]126    seqCounter++;
127    seqCounter %= this->blinkSequence.length();
128  }
129
[10431]130  this->bBoard->colorTexture(Color(color.r(), color.g(), color.b(), this->blinkStr));
[10175]131}
132
133
134/**
135 * draws the blink
136 */
137void Blink::draw() const
138{
139
140}
Note: See TracBrowser for help on using the repository browser.