mirror of
https://github.com/maaslalani/confetty.git
synced 2024-11-15 04:06:43 +00:00
34 lines
729 B
Go
34 lines
729 B
Go
|
package simulation
|
||
|
|
||
|
type Projectile struct {
|
||
|
Position Point
|
||
|
Velocity Vector
|
||
|
Acceleration Vector
|
||
|
DeltaTime float64
|
||
|
}
|
||
|
|
||
|
type Point struct {
|
||
|
X, Y, Z float64
|
||
|
}
|
||
|
|
||
|
type Vector struct {
|
||
|
X, Y, Z float64
|
||
|
}
|
||
|
|
||
|
var Gravity = Vector{0, -9.81, 0}
|
||
|
var TerminalGravity = Vector{0, 9.81, 0}
|
||
|
|
||
|
func NewProjectile(del float64, pos Point, vel, acc Vector) *Projectile {
|
||
|
return &Projectile{pos, vel, acc, del}
|
||
|
}
|
||
|
|
||
|
func (p *Projectile) Update() {
|
||
|
p.Position.X += (p.Velocity.X * p.DeltaTime)
|
||
|
p.Position.Y += (p.Velocity.Y * p.DeltaTime)
|
||
|
p.Position.Z += (p.Velocity.Z * p.DeltaTime)
|
||
|
|
||
|
p.Velocity.X += (p.Acceleration.X * p.DeltaTime)
|
||
|
p.Velocity.Y += (p.Acceleration.Y * p.DeltaTime)
|
||
|
p.Velocity.Z += (p.Acceleration.Z * p.DeltaTime)
|
||
|
}
|