mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
examples: use math.vec in examples/sokol/particles (#16780)
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by an MIT license file distributed with this software package
|
||||
module particle
|
||||
|
||||
import particle.vec2
|
||||
import math.vec
|
||||
import sokol.sgl
|
||||
|
||||
const (
|
||||
@@ -11,11 +11,11 @@ const (
|
||||
)
|
||||
|
||||
// * Module public
|
||||
pub fn new(location vec2.Vec2) &Particle {
|
||||
pub fn new(location vec.Vec2[f64]) &Particle {
|
||||
p := &Particle{
|
||||
location: location
|
||||
velocity: vec2.Vec2{0, 0}
|
||||
acceleration: vec2.Vec2{0, 0}
|
||||
velocity: vec.Vec2[f64]{0, 0}
|
||||
acceleration: vec.Vec2[f64]{0, 0}
|
||||
color: particle.default_v_color
|
||||
life_time: particle.default_life_time
|
||||
life_time_init: particle.default_life_time
|
||||
@@ -30,9 +30,9 @@ fn remap(v f64, min f64, max f64, new_min f64, new_max f64) f64 {
|
||||
// Particle
|
||||
pub struct Particle {
|
||||
mut:
|
||||
location vec2.Vec2
|
||||
velocity vec2.Vec2
|
||||
acceleration vec2.Vec2
|
||||
location vec.Vec2[f64]
|
||||
velocity vec.Vec2[f64]
|
||||
acceleration vec.Vec2[f64]
|
||||
color Color
|
||||
life_time f64
|
||||
life_time_init f64
|
||||
@@ -40,7 +40,7 @@ mut:
|
||||
|
||||
pub fn (mut p Particle) update(dt f64) {
|
||||
mut acc := p.acceleration
|
||||
acc.multiply_f64(dt)
|
||||
acc.multiply_scalar(dt)
|
||||
p.velocity = p.velocity.add(acc)
|
||||
p.location = p.location.add(p.velocity)
|
||||
lt := p.life_time - (1000 * dt)
|
||||
|
||||
Reference in New Issue
Block a user