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 chain_link_visual.cpp
26
* \brief Implementation of the bear::chain_link_visual class.
27
* \author Julien Jorge
29
#include "generic_items/link/chain_link_visual.hpp"
31
#include "engine/export.hpp"
33
BASE_ITEM_EXPORT( chain_link_visual, bear )
35
/*----------------------------------------------------------------------------*/
39
bear::chain_link_visual::chain_link_visual()
40
: m_link_count(0), m_max_fall(0)
43
} // chain_link_visual::chain_link_visual()
45
/*----------------------------------------------------------------------------*/
47
* \brief Set a field of type <real>.
48
* \param name The name of the field.
49
* \param value The value of the field.
51
bool bear::chain_link_visual::set_real_field
52
( const std::string& name, double value )
56
if ( name == "chain_link_visual.max_fall" )
59
result = super::set_real_field(name, value);
62
} // chain_link_visual::set_real_field()
64
/*----------------------------------------------------------------------------*/
66
* \brief Set a field of type <unsigned int>.
67
* \param name The name of the field.
68
* \param value The value of the field.
70
bool bear::chain_link_visual::set_u_integer_field
71
( const std::string& name, unsigned int value )
75
if ( name == "chain_link_visual.links_count" )
78
result = super::set_u_integer_field(name, value);
81
} // chain_link_visual::set_u_integer_field()
83
/*----------------------------------------------------------------------------*/
85
* \brief Get the visuals of this item.
86
* \param visuals (out) The visuals.
88
void bear::chain_link_visual::get_visual
89
( std::list<engine::scene_visual>& visuals ) const
91
const std::size_t n(m_link_count+2);
92
universe::vector_type dir = get_end_position() - get_start_position();
93
const double intensity =
94
std::abs(get_end_position().x - get_start_position().x)
95
/ get_end_position().distance(get_start_position());
96
const visual::sprite s(get_sprite());
98
universe::vector_type ortho;
100
if ( get_end_position().x < get_start_position(). x )
101
ortho = dir.get_orthonormal_anticlockwise();
103
ortho = dir.get_orthonormal_clockwise();
107
const visual::position_type origin( get_start_position() - s.get_size() / 2 );
109
for (std::size_t i=0; i!=n; ++i)
111
visual::position_type p = dir * i;
112
double fall_distance = std::sin( (double)i / n * 3.14159 )
113
* intensity * m_max_fall;
114
p += ortho * fall_distance;
117
( engine::scene_visual( origin + p, s, get_z_position() ) );
119
} // chain_link_visual::get_visual()