mirror of
https://github.com/lloeki/ld48-29.git
synced 2025-12-06 02:54:40 +01:00
sprite rotation
This commit is contained in:
parent
08a38a9db5
commit
238cc63dff
3 changed files with 39 additions and 19 deletions
44
ld48-29.go
44
ld48-29.go
|
|
@ -146,13 +146,16 @@ func scaledSpriteQuad(x int, y int, w int, h int, scale float32) {
|
|||
gl.End()
|
||||
}
|
||||
|
||||
func drawSprite(texture gl.Texture, x float64, y float64, list uint) {
|
||||
func drawSprite(texture gl.Texture, x float64, y float64, a float64, list uint) {
|
||||
deg := math.Mod(360 * float64(a) / (2 * math.Pi), 360.0)
|
||||
gl.LoadIdentity()
|
||||
texture.Bind(gl.TEXTURE_2D)
|
||||
gl.Translatef(float32(x), float32(y), 0)
|
||||
gl.Rotatef(float32(deg), 0.0, 0.0, 1.0);
|
||||
gl.CallList(list)
|
||||
}
|
||||
|
||||
|
||||
// main
|
||||
|
||||
func main() {
|
||||
|
|
@ -269,27 +272,30 @@ func render(textures map[string]gl.Texture, lists map[string]uint) {
|
|||
gl.Enable(gl.TEXTURE_2D)
|
||||
gl.Enable(gl.LIGHTING)
|
||||
|
||||
drawSprite(textures["sprites"], 0, 0, lists["test"])
|
||||
drawSprite(textures["sprites"], 320, 0, lists["test"])
|
||||
drawSprite(textures["sprites"], 640, 0, lists["test"])
|
||||
drawSprite(textures["sprites"], 320, 240, lists["test"])
|
||||
drawSprite(textures["sprites"], 320, 480, lists["test"])
|
||||
drawSprite(textures["sprites"], 0, 240, lists["test"])
|
||||
drawSprite(textures["sprites"], 0, 480, lists["test"])
|
||||
drawSprite(textures["sprites"], 640, 240, lists["test"])
|
||||
drawSprite(textures["sprites"], 640, 480, lists["test"])
|
||||
drawSprite(textures["sprites"], 0, 0, 0, lists["test"])
|
||||
drawSprite(textures["sprites"], 320, 0, 0, lists["test"])
|
||||
drawSprite(textures["sprites"], 640, 0, 0, lists["test"])
|
||||
drawSprite(textures["sprites"], 320, 240, 0, lists["test"])
|
||||
drawSprite(textures["sprites"], 320, 480, 0, lists["test"])
|
||||
drawSprite(textures["sprites"], 0, 240, 0, lists["test"])
|
||||
drawSprite(textures["sprites"], 0, 480, 0, lists["test"])
|
||||
drawSprite(textures["sprites"], 640, 240, 0, lists["test"])
|
||||
drawSprite(textures["sprites"], 640, 480, 0, lists["test"])
|
||||
|
||||
t := float64(time.Now().UnixNano()) / math.Pow(10, 9)
|
||||
|
||||
x := (math.Sin(2*math.Pi*t/60) + 1)/2 * float64(width)
|
||||
y := (math.Cos(2*math.Pi*t/60) + 1)/2 * float64(height)
|
||||
drawSprite(textures["sprites"], x, y, lists["test"])
|
||||
a := 2 * math.Pi * t / 60
|
||||
x := (math.Sin(a) + 1) / 2 * float64(width)
|
||||
y := (math.Cos(a) + 1) / 2 * float64(height)
|
||||
drawSprite(textures["sprites"], x, y, -a, lists["test"])
|
||||
|
||||
x = (math.Sin(10*2*math.Pi*t/60) + 1)/2 * float64(width)
|
||||
y = (math.Cos(10*2*math.Pi*t/60) + 1)/2 * float64(height)
|
||||
drawSprite(textures["sprites"], x, y, lists["test"])
|
||||
a = 10 * 2 * math.Pi * t / 60
|
||||
x = (math.Sin(a) + 1) / 2 * float64(width)
|
||||
y = (math.Cos(a) + 1) / 2 * float64(height)
|
||||
drawSprite(textures["sprites"], x, y, -a, lists["test"])
|
||||
|
||||
x = (math.Sin(60*2*math.Pi*t/60) + 1)/2 * float64(width)
|
||||
y = (math.Cos(60*2*math.Pi*t/60) + 1)/2 * float64(height)
|
||||
drawSprite(textures["sprites"], x, y, lists["test"])
|
||||
a = 60 * 2 * math.Pi * t / 60
|
||||
x = (math.Sin(a) + 1) / 2 * float64(width)
|
||||
y = (math.Cos(a) + 1) / 2 * float64(height)
|
||||
drawSprite(textures["sprites"], x, y, -a, lists["test"])
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue