~ubuntu-branches/ubuntu/natty/plee-the-bear/natty

« back to all changes in this revision

Viewing changes to bear-engine/core/src/visual/code/scene_sprite.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
1
/*
2
2
  Bear Engine
3
3
 
4
 
  Copyright (C) 2005-2009 Julien Jorge, Sebastien Angibaud
 
4
  Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
5
5
 
6
6
  This program is free software; you can redistribute it and/or modify it
7
7
  under the terms of the GNU General Public License as published by the
28
28
 */
29
29
#include "visual/scene_sprite.hpp"
30
30
 
 
31
#include "visual/base_screen.hpp"
31
32
#include "visual/scene_element.hpp"
32
33
 
33
34
#include <limits>
81
82
 
82
83
  if ( m_sprite.get_angle() != 0 )
83
84
    {
84
 
      position_type left_top( std::numeric_limits<coordinate_type>::max(),
 
85
      position_type left_bottom( std::numeric_limits<coordinate_type>::max(),
85
86
                              std::numeric_limits<coordinate_type>::max() );
86
 
      position_type right_bottom( 0,0 );
 
87
      position_type right_top( 0,0 );
87
88
 
88
89
      position_type center( get_position().x + w / 2, get_position().y + h / 2);
89
90
 
90
91
      update_side_box( position_type(get_position().x, get_position().y),
91
 
                       center, left_top, right_bottom);
 
92
                       center, left_bottom, right_top);
92
93
 
93
94
      update_side_box( position_type(get_position().x + w, get_position().y),
94
 
                       center, left_top, right_bottom);
 
95
                       center, left_bottom, right_top);
95
96
 
96
97
      update_side_box( position_type(get_position().x, get_position().y + h),
97
 
                       center, left_top, right_bottom);
 
98
                       center, left_bottom, right_top);
98
99
 
99
100
      update_side_box
100
101
        ( position_type(get_position().x + w, get_position().y + h), center,
101
 
          left_top, right_bottom);
 
102
          left_bottom, right_top);
102
103
 
103
 
      result.set( left_top.x, left_top.y, right_bottom.x - left_top.x,
104
 
                  right_bottom.y - left_top.y );
 
104
      result = rectangle_type( left_bottom, right_top );
105
105
    }
106
106
  else
107
 
    result.set( get_position().x, get_position().y, w, h );
 
107
    result =
 
108
      rectangle_type
 
109
      ( get_position().x, get_position().y, get_position().x + w,
 
110
        get_position().y + h );
108
111
 
109
112
  return result;
110
113
} // scene_sprite::get_bounding_box()
113
116
/**
114
117
 * \brief Split the sprite in sub sprites.
115
118
 * \param boxes The boxes describing how to split the sprite.
116
 
 * \param output The resulting sprites (they are inserted to the front).
 
119
 * \param output The resulting sprites (they are inserted to the back).
117
120
 */
118
121
void bear::visual::scene_sprite::burst
119
122
( const rectangle_list& boxes, scene_element_list& output ) const
127
130
       || attr.is_flipped()
128
131
       || attr.is_mirrored()
129
132
       || (attr.get_angle() != 0) )
130
 
    output.push_front( scene_element(*this) );
 
133
    output.push_back( scene_element(*this) );
131
134
  else
132
135
    {
133
136
      rectangle_list::const_iterator it;
134
 
      const rectangle_type my_box( get_position(), m_sprite.get_size() );
 
137
      const rectangle_type my_box
 
138
        ( get_position(), get_position() + m_sprite.get_size() );
135
139
 
136
140
      for (it=boxes.begin(); it!=boxes.end(); ++it)
137
141
        if ( my_box.intersects(*it) )
138
142
          {
139
143
            const rectangle_type inter = my_box.intersection(*it);
140
144
 
141
 
            if( (inter.width > 0) && (inter.height > 0) )
 
145
            if( (inter.width() > 0) && (inter.height() > 0) )
142
146
              {
143
 
                const position_type pos = inter.position;
 
147
                const position_type pos( inter.bottom_left() );
144
148
                const claw::math::rectangle<unsigned int> clip
145
 
                  ( pos - get_position() + m_sprite.clip_rectangle().position,
146
 
                    inter.size() );
 
149
                  ( pos.x - get_position().x
 
150
                    + m_sprite.clip_rectangle().position.x,
 
151
                    get_position().y + m_sprite.height() - inter.top()
 
152
                    + m_sprite.clip_rectangle().position.y,
 
153
                    inter.width(), inter.height() );
147
154
 
148
155
                sprite spr(m_sprite);
149
156
                spr.set_clip_rectangle(clip);
152
159
                scene_sprite scene_spr(*this);
153
160
                scene_spr.set_position( pos.x, pos.y );
154
161
                scene_spr.set_sprite( spr );
155
 
                output.push_front( scene_spr );
 
162
                output.push_back( scene_spr );
156
163
              }
157
164
          }
158
165
    }
165
172
 */
166
173
void bear::visual::scene_sprite::render( base_screen& scr ) const
167
174
{
 
175
  if ( !m_sprite.is_valid() )
 
176
    return;
 
177
 
168
178
  sprite s(m_sprite);
169
179
  s.combine( get_rendering_attributes() );
170
180
  s.set_size
189
199
 *
190
200
 * \param pos The point to rotate.
191
201
 * \param center The center of the rotation.
192
 
 * \param left_top (out) The left_top position of the bounding box.
193
 
 * \param right_bottom (out) The right_bottom position of the bounding box.
 
202
 * \param left_bottom (out) The left_bottom position of the bounding box.
 
203
 * \param right_top (out) The right_top position of the bounding box.
194
204
 */
195
205
void bear::visual::scene_sprite::update_side_box
196
206
( const position_type& pos, const position_type& center,
197
 
  position_type& left_top, position_type& right_bottom) const
 
207
  position_type& left_bottom, position_type& right_top) const
198
208
{
199
209
  bear::visual::position_type result(center);
200
210
 
201
 
  // According to the direction of y axis, we take the opposite angle.
202
 
  GLdouble new_a = -m_sprite.get_angle();
203
 
 
204
 
  result.x +=
205
 
    (pos.x - center.x) * cos(new_a) + (pos.y - center.y) * sin(new_a);
206
 
  result.y +=
207
 
    -(pos.x - center.x) * sin(new_a) + (pos.y - center.y) * cos(new_a);
208
 
 
209
 
  if ( result.x < left_top.x )
210
 
    left_top.x = result.x;
211
 
 
212
 
  if ( result.y < left_top.y )
213
 
    left_top.y = result.y;
214
 
 
215
 
  if ( result.x > right_bottom.x )
216
 
    right_bottom.x = result.x;
217
 
 
218
 
  if ( result.y > right_bottom.y )
219
 
    right_bottom.y = result.y;
 
211
  const double a = m_sprite.get_angle();
 
212
 
 
213
  result.x += (pos.x - center.x) * cos(a) - (pos.y - center.y) * sin(a);
 
214
  result.y += (pos.x - center.x) * sin(a) + (pos.y - center.y) * cos(a);
 
215
 
 
216
  if ( result.x < left_bottom.x )
 
217
    left_bottom.x = result.x;
 
218
 
 
219
  if ( result.y < left_bottom.y )
 
220
    left_bottom.y = result.y;
 
221
 
 
222
  if ( result.x > right_top.x )
 
223
    right_top.x = result.x;
 
224
 
 
225
  if ( result.y > right_top.y )
 
226
    right_top.y = result.y;
220
227
} // scene_sprite::update_side_box()