Esempio n. 1
0
func onPaint(sz size.Event) {
	gl.ClearColor(rgb(156), rgb(39), rgb(176), 1)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	var rotationMatrix = []float32{
		f32.Cos(-alpha), -f32.Sin(-alpha), 0.0,
		f32.Sin(-alpha), f32.Cos(-alpha), 0.0,
		0.0, 0.0, 1.0,
	}

	gl.UseProgram(program)
	// setting color
	gl.Uniform4f(color, rgb(255), rgb(255), rgb(255), 1)
	gl.UniformMatrix3fv(matrixId, rotationMatrix)
	gl.Uniform1f(resolutionId, resIndex)

	gl.BindBuffer(gl.ARRAY_BUFFER, swasBuffer)

	gl.EnableVertexAttribArray(position)
	gl.VertexAttribPointer(position, 3, gl.FLOAT, false, 0, 0)
	gl.DrawArrays(gl.LINES, 0, 16)
	gl.DisableVertexAttribArray(position)

	gl.UseProgram(texProgram)
	// setting color
	gl.Uniform4f(color2, rgb(130), rgb(50), rgb(80), 1)
	gl.Uniform1f(resolutionId2, resIndex)
	gl.UniformMatrix3fv(matrixId2, rotationMatrix)

	gl.BindBuffer(gl.ARRAY_BUFFER, quadBuffer)
	gl.EnableVertexAttribArray(position2)
	gl.VertexAttribPointer(position2, 3, gl.FLOAT, false, 0, 0)

	gl.BindBuffer(gl.ARRAY_BUFFER, quadTexBuffer)
	gl.EnableVertexAttribArray(textureCoords)
	gl.VertexAttribPointer(textureCoords, 2, gl.FLOAT, false, 0, 0)

	gl.Uniform1i(gl.GetUniformLocation(texProgram, "myTexture"), 0)
	gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, textureId)

	gl.DrawArrays(gl.TRIANGLES, 0, 6)
	gl.DisableVertexAttribArray(position2)
	gl.DisableVertexAttribArray(textureCoords)

	if spin == true {
		alpha += 0.1
	}

	if alpha >= 360 {
		alpha = 0.0
	}

}
Esempio n. 2
0
func (sprite *KonaSprite) Apply() {
	curPosX := sprite.posX
	curPosY := sprite.posY
	r := sprite.radian * 3.141592653 / 180
	affine = &f32.Affine{
		{sprite.width * f32.Cos(r), sprite.height * -f32.Sin(r),
			curPosX - (sprite.width/2)*f32.Cos(r) + (sprite.height/2)*f32.Sin(r)},
		{sprite.width * f32.Sin(r), sprite.height * f32.Cos(r),
			curPosY - (sprite.height/2)*f32.Cos(r) - (sprite.width/2)*f32.Sin(r)},
	}
	eng.SetTransform(sprite.node, *affine)
}
Esempio n. 3
0
func genCircleTriangles(Xcenter, Ycenter, radius float32) []byte {
	points := make([]float32, 192)
	i := 1
	points[0] = Xcenter
	points[1] = Ycenter
	points[2] = radius
	for angle := float32(0.0); angle < 3.14159*2; angle += 0.1 {
		points[3*i] = radius * f32.Cos(angle)
		points[3*i+1] = radius * f32.Sin(angle)
		points[3*i+2] = float32(0.0)
		fmt.Println(angle, points[3*i], points[3*i+1], points[3*i+2])
		i++
	}
	return byteList(binary.LittleEndian, points)
}
Esempio n. 4
0
func loadScene() {
	texs := loadTextures()
	scene = &sprite.Node{}
	eng.Register(scene)
	eng.SetTransform(scene, f32.Affine{
		{1, 0, 0},
		{0, 1, 0},
	})

	var n *sprite.Node

	n = newNode()
	eng.SetSubTex(n, texs[texBooks])
	eng.SetTransform(n, f32.Affine{
		{36, 0, 0},
		{0, 36, 0},
	})

	n = newNode()
	eng.SetSubTex(n, texs[texFire])
	eng.SetTransform(n, f32.Affine{
		{72, 0, 144},
		{0, 72, 144},
	})

	n = newNode()
	n.Arranger = arrangerFunc(func(eng sprite.Engine, n *sprite.Node, t clock.Time) {
		// TODO: use a tweening library instead of manually arranging.
		t0 := uint32(t) % 120
		if t0 < 60 {
			eng.SetSubTex(n, texs[texGopherR])
		} else {
			eng.SetSubTex(n, texs[texGopherL])
		}

		u := float32(t0) / 120
		u = (1 - f32.Cos(u*2*math.Pi)) / 2

		tx := 18 + u*48
		ty := 36 + u*108
		sx := 36 + u*36
		sy := 36 + u*36
		eng.SetTransform(n, f32.Affine{
			{sx, 0, tx},
			{0, sy, ty},
		})
	})
}
Esempio n. 5
0
func loadScene(c event.Config) {
	gl.Enable(gl.BLEND)
	gl.BlendEquation(gl.FUNC_ADD)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	w, h := float32(c.Width), float32(c.Height)

	texs = loadTextures()
	scene = &sprite.Node{}
	eng.Register(scene)
	a := f32.Affine{
		{1, 0, 0},
		{0, 1, 0},
	}

	if h > w {
		w, h = h, w
		angle := float32(-math.Pi / 2)
		a = f32.Affine{
			{f32.Cos(angle), -f32.Sin(angle), 0},
			{f32.Sin(angle), f32.Cos(angle), w},
		}
	}
	scale = w / 1100
	eng.SetTransform(scene, a)
	x0 = w/2 - 500*scale
	y0 = h/2 - 100*scale
	//log.Printf("width:%f height:%f scale:%f x0:%f y0:%f", w, h, scale, x0, y0)

	timeNode := newTimeNode()
	scene.AppendChild(timeNode)

	startNode := newStartNode()
	scene.AppendChild(startNode)

	endNode := newEndNode()
	scene.AppendChild(endNode)

	startVisilbe, endVisible := false, false
	scene.Arranger = arrangerFunc(func(eng sprite.Engine, n *sprite.Node, t clock.Time) {
		switch state {
		case stateStart:
			if !startVisilbe {
				startVisilbe = true
				eng.SetSubTex(startNode, texs["GO"])
			}

			if endVisible {
				eng.SetSubTex(endNode, sprite.SubTex{})
				endVisible = false
			}
		case stateRunning:
			if startVisilbe {
				eng.SetSubTex(startNode, sprite.SubTex{})
				startVisilbe = false
			}
		case stateEnd:
			if !endVisible {
				endVisible = true
				eng.SetSubTex(endNode, texs["gooon"])
			}
		}
	})
}