Esempio n. 1
0
// CreateBeam - creates a square prism oriented along the vector
func CreateBeam(width float32, vector mgl32.Vec3) *Geometry {
	direction := vector.Normalize()
	geo := CreateBoxWithOffset(width, width, -width*0.5, -width*0.5)
	geo2 := CreateBoxWithOffset(width, width, -width*0.5, -width*0.5)
	facingTx := util.Mat4From(mgl32.Vec3{1, 1, 1}, mgl32.Vec3{}, util.FacingOrientation(0, direction, mgl32.Vec3{0, 0, 1}, mgl32.Vec3{1, 0, 0}))
	geo.Transform(facingTx)
	facingTx = util.Mat4From(mgl32.Vec3{1, 1, 1}, vector, util.FacingOrientation(0, direction, mgl32.Vec3{0, 0, -1}, mgl32.Vec3{1, 0, 0}))
	geo2.Optimize(geo, facingTx)
	geo.Indicies = append(geo.Indicies, 0, 1, 4, 4, 5, 0) //top
	geo.Indicies = append(geo.Indicies, 1, 2, 7, 7, 4, 1) //side
	geo.Indicies = append(geo.Indicies, 2, 3, 6, 6, 7, 2) //bottom
	geo.Indicies = append(geo.Indicies, 3, 0, 5, 5, 6, 3) //side
	return geo
}
Esempio n. 2
0
func (ps *ParticleSystem) updateParticle(p *Particle, dt float64) {
	//set translation
	p.Translation = p.Translation.Add(p.Velocity.Mul(float32(dt)))
	p.Velocity = p.Velocity.Add(ps.Settings.Acceleration.Mul(float32(dt)))
	//set orientation / rotation
	p.Rotation = p.Rotation + (p.RotationVelocity * float32(dt))
	p.LifeRemaining = p.LifeRemaining - float32(dt)
	// set valuew based on life remaining
	lifeRatio := p.LifeRemaining / p.Life
	p.Scale = util.Vec3Lerp(ps.Settings.EndSize, ps.Settings.StartSize, lifeRatio)
	p.Color = lerpColor(ps.Settings.EndColor, ps.Settings.StartColor, lifeRatio)
	p.Frame = int((1.0 - lifeRatio) * float32(ps.Settings.TotalFrames))
	//face the camera
	if ps.FaceCamera {
		p.Orientation = util.FacingOrientation(p.Rotation, ps.cameraPosition.Sub(p.Translation), mgl32.Vec3{0, 0, 1}, mgl32.Vec3{-1, 0, 0})
	} else {
		p.Orientation = mgl32.QuatRotate(p.Rotation, mgl32.Vec3{0, 0, 1})
	}
	//is particle dead
	if p.LifeRemaining <= 0 {
		p.active = false
	}
	if ps.Settings.OnParticleUpdate != nil && p.active {
		ps.Settings.OnParticleUpdate(p)
	}
}
Esempio n. 3
0
func (sprite *Sprite) Update(dt float64) {
	if sprite.FaceCamera {
		orientation := util.FacingOrientation(sprite.Rotation, sprite.cameraPosition.Sub(sprite.Node.Translation), mgl32.Vec3{0, 0, 1}, mgl32.Vec3{-1, 0, 0})
		sprite.Node.SetOrientation(orientation)
	}
}