Пример #1
0
func (ui *UIText) Draw() {
	if ui.text == "" {
		return
	}

	v := ui.align.Vector()
	v.X = (v.X * ui.width)
	v.Y = (v.Y * ui.height)

	mat := engine.TextureMaterial
	if ui.Font.IsSDF() {
		mat = engine.SDFMaterial
	}
	mat.Begin(ui.GameObject())

	mp := mat.ProjMatrix
	mv := mat.ViewMatrix
	mm := mat.ModelMatrix
	tx := mat.Texture
	ti := mat.Tiling
	of := mat.Offset
	color := mat.AddColor
	_ = color

	ui.buffer.Bind(gl.ARRAY_BUFFER)
	mat.Verts.EnableArray()
	mat.Verts.AttribPointer(3, gl.FLOAT, false, 0, uintptr(0))
	mat.UV.EnableArray()
	mat.UV.AttribPointer(2, gl.FLOAT, false, 0, uintptr(ui.texcoordsIndex))

	camera := engine.GetScene().SceneBase().Camera

	view := camera.InvertedMatrix()
	model := engine.Identity()
	model.Translate(v.X, v.Y, 0)
	model.Mul(ui.GameObject().Transform().Matrix())
	model.Translate(0.75, 0.75, 0)
	/*
		view := camera.Transform().Matrix()
		view = view.Invert()
		model := ui.GameObject().Transform().Matrix()
	*/

	mv.UniformMatrix4fv(false, view)
	mp.UniformMatrix4f(false, (*[16]float32)(camera.Projection))
	mm.UniformMatrix4fv(false, model)
	ti.Uniform2f(1, 1)
	of.Uniform2f(0, 0)

	ui.Font.Bind()
	tx.Uniform1i(0)

	color.Uniform4f(ui.Color.R, ui.Color.G, ui.Color.B, ui.Color.A)

	gl.DrawArrays(gl.QUADS, 0, ui.vertexCount)

}
Пример #2
0
func (sp *ShipController) Shoot() {
	if sp.Missle != nil {
		sp.FireSource.Stop()
		sp.FireSource.Play()

		a := sp.Transform().Rotation()
		//scale := sp.Transform().Scale()
		for i := 0; i < len(sp.MisslesDirection[sp.MissleLevel]); i++ {
			pos := sp.MisslesPosition[i]
			s := sp.Transform().DirectionTransform(sp.MisslesDirection[sp.MissleLevel][i])
			//s = s.Mul(sp.MisslesDirection[i])

			p := sp.Transform().WorldPosition()
			_ = a
			m := engine.Identity()
			//m.Scale(scale.X, scale.Y, scale.Z)
			m.Translate(pos.X, pos.Y, pos.Z)
			m.RotateZ(a.Z, -1)
			m.Translate(p.X, p.Y, p.Z)
			p = m.Translation()

			nfire := sp.Missle.GameObject().Clone()
			nfire.Transform().SetParent2(GameSceneGeneral.Layer3)
			nfire.Transform().SetWorldPosition(p)
			nfire.Physics.Body.IgnoreGravity = true
			nfire.Physics.Body.SetMass(0.1)
			nfire.Tag = MissleTag

			v := sp.GameObject().Physics.Body.Velocity()
			angle := float32(math.Atan2(float64(s.X), float64(s.Y))) * engine.DegreeConst

			nfire.Physics.Body.SetVelocity(float32(v.X), float32(v.Y))
			nfire.Physics.Body.AddForce(s.X*3000, s.Y*3000)

			nfire.Physics.Shape.Group = 1
			nfire.Physics.Body.SetMoment(engine.Inf)
			nfire.Transform().SetRotationf(180 - angle)
		}
	}
}