confetty/simulation/projectile.go
2021-11-05 00:36:00 -04:00

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)
}