MCPcopy Create free account
hub / github.com/CleanCut/rusty_engine / change_last_collider_point

Method change_last_collider_point

src/sprite.rs:158–182  ·  view source on GitHub ↗

Change the last collider point. `p` is a `Vec2` in worldspace (usually the mouse coordinate). See the `collider` example.

(&mut self, mut p: Vec2)

Source from the content-addressed store, hash-verified

156 /// Change the last collider point. `p` is a `Vec2` in worldspace (usually the mouse
157 /// coordinate). See the `collider` example.
158 pub fn change_last_collider_point(&mut self, mut p: Vec2) {
159 self.collider_dirty = true;
160 // If there isn't a collider, create one with a "last point" to change
161 if self.collider == Collider::NoCollider {
162 self.collider = Collider::Poly(vec![Vec2::ZERO]);
163 }
164 // Add the current point to the collider
165 if let Collider::Poly(points) = &mut self.collider {
166 // If the collider exists, but doesn't have any points, add a "last point" to modify.
167 if points.is_empty() {
168 points.push(Vec2::ZERO);
169 }
170 // untranslate (make p relative to the sprite's origin instead of the world's origin)
171 p -= self.translation;
172 // unscale (make p the same scale as the sprite)
173 p *= 1.0 / self.scale;
174 // unrotate (make p the same rotation as the sprite)
175 let length = points.len();
176 let p2 = points.get_mut(length - 1).unwrap(); // mutable reference to "last point"
177 let sin = (-self.rotation).sin();
178 let cos = (-self.rotation).cos();
179 p2.x = p.x * cos - p.y * sin;
180 p2.y = p.x * sin + p.y * cos;
181 }
182 }
183}
184
185use std::{

Callers 1

game_logicFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected