Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10435 was 10433, checked in by patrick, 18 years ago

merged blinki into trunk

File size: 2.1 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
39
40/**
41 * destroys a Blink
42 */
43Blink::~Blink ()
44{
45  if(bBoard)
46    delete bBoard;
47}
48
49
50/**
51 * initializes the Blink
52 */
53void Blink::init()
54{
55  this->registerObject(this, Blink::_objectList);
56  this->setName("Blink");
57
58  this->toList(OM_COMMON);
59
60  this->bBoard = new Billboard;
61  this->bBoard->setVisibiliy(true);
62  this->bBoard->setTexture("maps/star_alpha.png");
63
64  /// Standard values
65  this->bBoard->setAbsCoor(0, 0, 0);
66  // default position if not set in xml
67  this->color = Color(1, 0, 0);
68  // 10x10 pxl if not defined in xml
69  this->size = 10;
70  // default angular rate
71  this->omega = 10;
72
73  // random start angle, blinkies shouldn't blink synchronous
74  this->angle = (float)rand()/(float)RAND_MAX * 2 * M_PI;
75}
76
77
78/**
79 *  load params
80 * @param root TiXmlElement object
81 */
82void Blink::loadParams(const TiXmlElement* root)
83{
84  WorldEntity::loadParams(root);
85
86  LoadParam(root, "position", this, Blink, setPosition);
87  LoadParam(root, "size", this, Blink, setSize);
88  LoadParam(root, "color", this, Blink, setColor);
89  LoadParam(root, "omega", this, Blink, setOmega);
90}
91
92
93/**
94 * ticks the Blink
95 * @param dt the time to ticks
96 */
97void Blink::tick(float dt)
98{
99  this->angle += dt * this->omega;
100
101  while (this->angle > 2 * M_PI)
102    this->angle -= 2 * M_PI;
103
104  // blinkStr should be element of [0, 1]
105  this->blinkStr = (sinf(angle) + 1) / 2;
106
107  this->bBoard->colorTexture(Color(color.r(), color.g(), color.b(), this->blinkStr));
108}
109
110
111/**
112 * draws the blink
113 */
114void Blink::draw() const
115{
116
117}
Note: See TracBrowser for help on using the repository browser.