4
Copyright (C) 2005-2009 Julien Jorge, Sebastien Angibaud
4
Copyright (C) 2005-2010 Julien Jorge, Sebastien Angibaud
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
82
83
if ( m_sprite.get_angle() != 0 )
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 );
88
89
position_type center( get_position().x + w / 2, get_position().y + h / 2);
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);
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);
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);
100
101
( position_type(get_position().x + w, get_position().y + h), center,
101
left_top, right_bottom);
102
left_bottom, right_top);
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 );
107
result.set( get_position().x, get_position().y, w, h );
109
( get_position().x, get_position().y, get_position().x + w,
110
get_position().y + h );
110
113
} // scene_sprite::get_bounding_box()
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).
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) );
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() );
136
140
for (it=boxes.begin(); it!=boxes.end(); ++it)
137
141
if ( my_box.intersects(*it) )
139
143
const rectangle_type inter = my_box.intersection(*it);
141
if( (inter.width > 0) && (inter.height > 0) )
145
if( (inter.width() > 0) && (inter.height() > 0) )
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,
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() );
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 );
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.
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
199
209
bear::visual::position_type result(center);
201
// According to the direction of y axis, we take the opposite angle.
202
GLdouble new_a = -m_sprite.get_angle();
205
(pos.x - center.x) * cos(new_a) + (pos.y - center.y) * sin(new_a);
207
-(pos.x - center.x) * sin(new_a) + (pos.y - center.y) * cos(new_a);
209
if ( result.x < left_top.x )
210
left_top.x = result.x;
212
if ( result.y < left_top.y )
213
left_top.y = result.y;
215
if ( result.x > right_bottom.x )
216
right_bottom.x = result.x;
218
if ( result.y > right_bottom.y )
219
right_bottom.y = result.y;
211
const double a = m_sprite.get_angle();
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);
216
if ( result.x < left_bottom.x )
217
left_bottom.x = result.x;
219
if ( result.y < left_bottom.y )
220
left_bottom.y = result.y;
222
if ( result.x > right_top.x )
223
right_top.x = result.x;
225
if ( result.y > right_top.y )
226
right_top.y = result.y;
220
227
} // scene_sprite::update_side_box()