4
Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
6
This program is free software; you can redistribute it and/or modify it
7
under the terms of the GNU General Public License as published by the
8
Free Software Foundation; either version 2 of the License, or (at your
9
option) any later version.
11
This program is distributed in the hope that it will be useful, but WITHOUT
12
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16
You should have received a copy of the GNU General Public License along
17
with this program; if not, write to the Free Software Foundation, Inc.,
18
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
contact: plee-the-bear@gamned.org
22
Please add the tag [Bear] in the subject of your mails.
25
* \file code/path_trace.cpp
26
* \brief Implementation of the bear::path_trace class.
27
* \author Julien Jorge
29
#include "generic_items/path_trace.hpp"
31
#include "visual/scene_polygon.hpp"
33
BASE_ITEM_EXPORT(path_trace, bear)
35
/*----------------------------------------------------------------------------*/
39
bear::path_trace::path_trace()
40
: m_progress(&path_trace::progress_void),
41
m_fill_color(claw::graphic::black_pixel), m_opacity(1), m_fade_out_speed(1)
45
set_can_move_items(false);
46
} // path_trace::path_trace()
48
/*----------------------------------------------------------------------------*/
51
* \param ref The item to trace.
53
bear::path_trace::path_trace( const base_item& ref )
54
: m_progress(&path_trace::progress_alive), m_item(ref),
55
m_fill_color(claw::graphic::black_pixel), m_opacity(1), m_fade_out_speed(1)
59
set_can_move_items(false);
61
set_z_position(ref.get_z_position() - 1);
62
set_bounding_box( ref.get_bounding_box() );
63
} // path_trace::path_trace()
65
/*----------------------------------------------------------------------------*/
67
* \brief Set the color of the trace.
68
* \param c The new color.
70
void bear::path_trace::set_fill_color( const visual::color_type& c )
73
} // path_trace::set_fill_color()
75
/*----------------------------------------------------------------------------*/
77
* \brief Set the item to trace.
78
* \param ref The item to trace.
80
void bear::path_trace::set_item( const base_item& ref )
82
set_z_position(ref.get_z_position() - 1);
83
set_bounding_box( ref.get_bounding_box() );
85
m_previous_top.clear();
86
m_previous_bottom.clear();
88
m_progress = &path_trace::progress_alive;
90
m_previous_top.push_back( ref.get_top_middle() );
91
m_previous_bottom.push_back( ref.get_bottom_middle() );
92
} // path_trace::set_item()
94
/*----------------------------------------------------------------------------*/
96
* \brief Set the speed of the fade out of the trace when the traced item is
98
* \param s Units of opacity lost per second.
100
void bear::path_trace::set_fade_out_speed( double s )
102
m_fade_out_speed = (s > 0) ? s : 0;
103
} // path_trace::set_fade_out_speed()
105
/*----------------------------------------------------------------------------*/
107
* \brief Do one step in the progression of the item.
108
* \param elapsed_time Elapsed time since the last call.
110
void bear::path_trace::progress( universe::time_type elapsed_time )
112
super::progress(elapsed_time);
114
(this->*m_progress)( elapsed_time );
115
} // path_trace::progress()
117
/*----------------------------------------------------------------------------*/
119
* \brief Get the visuals of this item.
120
* \param visuals (out) The visuals.
123
bear::path_trace::get_visual( std::list<engine::scene_visual>& visuals ) const
125
CLAW_PRECOND( m_previous_bottom.size() == m_previous_top.size() );
127
if ( m_previous_top.empty() )
130
std::vector<visual::position_type> p(4);
132
position_list::const_iterator bottom_it = m_previous_bottom.begin();
133
position_list::const_iterator top_it = m_previous_top.begin();
135
position_list::const_iterator next_top(top_it);
138
while ( next_top != m_previous_top.end() )
153
visual::scene_polygon e(0, 0, m_fill_color, p);
154
e.get_rendering_attributes().set_opacity(m_opacity);
155
visuals.push_back( engine::scene_visual(e) );
158
} // path_trace::get_visual()
160
/*----------------------------------------------------------------------------*/
162
* \brief Do one step in the progression of this item, when there is no traced
164
* \param elapsed_time Elapsed time since the last call.
166
void bear::path_trace::progress_void( universe::time_type elapsed_time )
169
} // path_trace::progress_void()
171
/*----------------------------------------------------------------------------*/
173
* \brief Do one step in the progression of this item, while the traced item is
175
* \param elapsed_time Elapsed time since the last call.
177
void bear::path_trace::progress_alive( universe::time_type elapsed_time )
179
if ( m_item == NULL )
181
m_progress = &path_trace::progress_dead;
185
m_previous_top.push_back( m_item->get_top_middle() );
186
m_previous_bottom.push_back( m_item->get_bottom_middle() );
188
set_bounding_box( get_bounding_box().join(m_item->get_bounding_box()) );
189
} // path_trace::progress_alive()
191
/*----------------------------------------------------------------------------*/
193
* \brief Do one step in the progression of this item, once the traced item is
195
* \param elapsed_time Elapsed time since the last call.
197
void bear::path_trace::progress_dead( universe::time_type elapsed_time )
199
m_opacity -= m_fade_out_speed * elapsed_time;
203
} // path_trace::progress_dead()