~ubuntu-branches/ubuntu/trusty/plee-the-bear/trusty-proposed

« back to all changes in this revision

Viewing changes to bear-engine/lib/src/generic_items/link/code/chain_link_visual.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Jorge, Julien Jorge
  • Date: 2010-11-17 20:13:34 UTC
  • mfrom: (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20101117201334-o4dp7uq437to7oxb
Tags: 0.5.1-1
[ Julien Jorge ]
* New upstream release (Closes: #565062, #546514).
* Add armhf architecture (Closes: #604689).
* Remove patches integrated upstream: rpath-editors.diff, rpath-game.diff,
  editors-menu-section.diff.
* Bump the Standard-Version, no changes.
* Update my email address.
* Set build dependency of libclaw to 1.6.0.
* Add the missing ${misc:Depends} in debian/control.
* List gettext translations in bear-factory.install and plee-the-bear.install.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Bear Engine
 
3
 
 
4
  Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
 
5
 
 
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.
 
10
 
 
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
 
14
  more details.
 
15
 
 
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
 
19
 
 
20
  contact: plee-the-bear@gamned.org
 
21
 
 
22
  Please add the tag [Bear] in the subject of your mails.
 
23
*/
 
24
/**
 
25
 * \file chain_link_visual.cpp
 
26
 * \brief Implementation of the bear::chain_link_visual class.
 
27
 * \author Julien Jorge
 
28
 */
 
29
#include "generic_items/link/chain_link_visual.hpp"
 
30
 
 
31
#include "engine/export.hpp"
 
32
 
 
33
BASE_ITEM_EXPORT( chain_link_visual, bear )
 
34
 
 
35
/*----------------------------------------------------------------------------*/
 
36
/**
 
37
 * \brief Constructor.
 
38
 */
 
39
bear::chain_link_visual::chain_link_visual()
 
40
  : m_link_count(0), m_max_fall(0)
 
41
{
 
42
 
 
43
} // chain_link_visual::chain_link_visual()
 
44
 
 
45
/*----------------------------------------------------------------------------*/
 
46
/**
 
47
 * \brief Set a field of type <real>.
 
48
 * \param name The name of the field.
 
49
 * \param value The value of the field.
 
50
 */
 
51
bool bear::chain_link_visual::set_real_field
 
52
( const std::string& name, double value )
 
53
{
 
54
  bool result = true;
 
55
 
 
56
  if ( name == "chain_link_visual.max_fall" )
 
57
    m_max_fall = value;
 
58
  else
 
59
    result = super::set_real_field(name, value);
 
60
 
 
61
  return result;
 
62
} // chain_link_visual::set_real_field()
 
63
 
 
64
/*----------------------------------------------------------------------------*/
 
65
/**
 
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.
 
69
 */
 
70
bool bear::chain_link_visual::set_u_integer_field
 
71
( const std::string& name, unsigned int value )
 
72
{
 
73
  bool result = true;
 
74
 
 
75
  if ( name == "chain_link_visual.links_count" )
 
76
    m_link_count = value;
 
77
  else
 
78
    result = super::set_u_integer_field(name, value);
 
79
 
 
80
  return result;
 
81
} // chain_link_visual::set_u_integer_field()
 
82
 
 
83
/*----------------------------------------------------------------------------*/
 
84
/**
 
85
 * \brief Get the visuals of this item.
 
86
 * \param visuals (out) The visuals.
 
87
 */
 
88
void bear::chain_link_visual::get_visual
 
89
( std::list<engine::scene_visual>& visuals ) const
 
90
{
 
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());
 
97
 
 
98
  universe::vector_type ortho;
 
99
 
 
100
  if ( get_end_position().x < get_start_position(). x )
 
101
    ortho = dir.get_orthonormal_anticlockwise();
 
102
  else
 
103
    ortho = dir.get_orthonormal_clockwise();
 
104
 
 
105
  ortho.normalize();
 
106
  dir /= n-1;
 
107
  const visual::position_type origin( get_start_position() - s.get_size() / 2 );
 
108
 
 
109
  for (std::size_t i=0; i!=n; ++i)
 
110
    {
 
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;
 
115
 
 
116
      visuals.push_front
 
117
        ( engine::scene_visual( origin + p, s, get_z_position() ) );
 
118
    }
 
119
} // chain_link_visual::get_visual()