MCPcopy Create free account
hub / github.com/17cupsofcoffee/nova / push_sprite

Method push_sprite

src/graphics/batch.rs:281–364  ·  view source on GitHub ↗
(
        &mut self,
        texture: Option<&Texture>,
        source: Rectangle,
        dest: Rectangle,
        params: DrawParams,
    )

Source from the content-addressed store, hash-verified

279 }
280
281 fn push_sprite(
282 &mut self,
283 texture: Option<&Texture>,
284 source: Rectangle,
285 dest: Rectangle,
286 params: DrawParams,
287 ) {
288 let fx = -params.origin.x * params.scale.x;
289 let fy = -params.origin.y * params.scale.y;
290 let fx2 = (dest.width - params.origin.x) * params.scale.x;
291 let fy2 = (dest.height - params.origin.y) * params.scale.y;
292
293 let sin = params.rotation.sin();
294 let cos = params.rotation.cos();
295
296 let mut tl = Vec2::new(
297 dest.x + (cos * fx) - (sin * fy),
298 dest.y + (sin * fx) + (cos * fy),
299 );
300
301 let mut bl = Vec2::new(
302 dest.x + (cos * fx) - (sin * fy2),
303 dest.y + (sin * fx) + (cos * fy2),
304 );
305
306 let mut br = Vec2::new(
307 dest.x + (cos * fx2) - (sin * fy2),
308 dest.y + (sin * fx2) + (cos * fy2),
309 );
310
311 let mut tr = Vec2::new(
312 dest.x + (cos * fx2) - (sin * fy),
313 dest.y + (sin * fx2) + (cos * fy),
314 );
315
316 // TODO: It may be faster to do this on the GPU, but that would cause a new batch every
317 // time that a new matrix is pushed. Would need to benchmark.
318 if let Some(m) = self.matrices.last() {
319 tl = m.transform_point2(tl);
320 bl = m.transform_point2(bl);
321 br = m.transform_point2(br);
322 tr = m.transform_point2(tr);
323 }
324
325 let (l_offset, r_offset) = if params.flip.x {
326 (source.width, 0.0)
327 } else {
328 (0.0, source.width)
329 };
330
331 let (t_offset, b_offset) = if params.flip.y {
332 (source.height, 0.0)
333 } else {
334 (0.0, source.height)
335 };
336
337 let tl_uv = Vec2::new(source.x + l_offset, source.y + t_offset);
338 let bl_uv = Vec2::new(source.x + l_offset, source.y + b_offset);

Callers 4

rectMethod · 0.80
textureMethod · 0.80
texture_regionMethod · 0.80
texture_destMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected