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 } }
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) }
func GenOscilator(freq float32) Oscilator { k := 2.0 * Pi * freq T := 1.0 / freq dt := 1.0 / float32(SampleRate) t := float32(0.0) return func() float32 { res := f32.Sin(k * t) t += dt if t > T { t -= T } return res } }
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) }
// NewPianoKey returns a key for our piano. func NewPianoKey(pos mgl32.Vec3, lightColor mgl32.Vec3, white bool, freq float32) PianoKey { var color mgl32.Vec4 var keySize float32 if white { color = mgl32.Vec4{0.98, 0.97, 0.94} keySize = 2 } else { color = mgl32.Vec4{0.1, 0.1, 0.1, 1.0} keySize = 1 } pk := PianoKey{Pos: pos, Angle: 0, Color: color, Frequency: freq, Finger: -1, white: white, LightColor: lightColor} pk.BBox[0] = pos.Sub(mgl32.Vec3{0.5, 0.6, keySize}) pk.BBox[1] = pos.Add(mgl32.Vec3{0.5, 0.6, keySize}) pk.source = al.GenSources(1)[0] pk.source.SetGain(1.0) pk.source.SetPosition(al.Vector{pos.X(), pos.Y(), pos.Z()}) pk.source.SetVelocity(al.Vector{}) pk.buffers = al.GenBuffers(3) var samples [1024 * 16]int16 sampleRate := 44100 amplitude := float32(0.8 * 0x7FFF) for i := 0; i < len(samples); i++ { val := f32.Sin((2.0 * math.Pi * freq) / float32(sampleRate) * float32(i)) samples[i] = int16(amplitude * val) } buf := &bytes.Buffer{} binary.Write(buf, binary.LittleEndian, &samples) pk.buffers[0].BufferData(al.FormatMono16, buf.Bytes(), 44100) f, _ := os.Create("audio.raw") binary.Write(f, binary.LittleEndian, &samples) f.Close() return pk }
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"]) } } }) }