mirror of
https://github.com/lloeki/ld48-29.git
synced 2025-12-06 11:04:39 +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()
|
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()
|
gl.LoadIdentity()
|
||||||
texture.Bind(gl.TEXTURE_2D)
|
texture.Bind(gl.TEXTURE_2D)
|
||||||
gl.Translatef(float32(x), float32(y), 0)
|
gl.Translatef(float32(x), float32(y), 0)
|
||||||
|
gl.Rotatef(float32(deg), 0.0, 0.0, 1.0);
|
||||||
gl.CallList(list)
|
gl.CallList(list)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// main
|
// main
|
||||||
|
|
||||||
func 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.TEXTURE_2D)
|
||||||
gl.Enable(gl.LIGHTING)
|
gl.Enable(gl.LIGHTING)
|
||||||
|
|
||||||
drawSprite(textures["sprites"], 0, 0, lists["test"])
|
drawSprite(textures["sprites"], 0, 0, 0, lists["test"])
|
||||||
drawSprite(textures["sprites"], 320, 0, lists["test"])
|
drawSprite(textures["sprites"], 320, 0, 0, lists["test"])
|
||||||
drawSprite(textures["sprites"], 640, 0, lists["test"])
|
drawSprite(textures["sprites"], 640, 0, 0, lists["test"])
|
||||||
drawSprite(textures["sprites"], 320, 240, lists["test"])
|
drawSprite(textures["sprites"], 320, 240, 0, lists["test"])
|
||||||
drawSprite(textures["sprites"], 320, 480, lists["test"])
|
drawSprite(textures["sprites"], 320, 480, 0, lists["test"])
|
||||||
drawSprite(textures["sprites"], 0, 240, lists["test"])
|
drawSprite(textures["sprites"], 0, 240, 0, lists["test"])
|
||||||
drawSprite(textures["sprites"], 0, 480, lists["test"])
|
drawSprite(textures["sprites"], 0, 480, 0, lists["test"])
|
||||||
drawSprite(textures["sprites"], 640, 240, lists["test"])
|
drawSprite(textures["sprites"], 640, 240, 0, lists["test"])
|
||||||
drawSprite(textures["sprites"], 640, 480, lists["test"])
|
drawSprite(textures["sprites"], 640, 480, 0, lists["test"])
|
||||||
|
|
||||||
t := float64(time.Now().UnixNano()) / math.Pow(10, 9)
|
t := float64(time.Now().UnixNano()) / math.Pow(10, 9)
|
||||||
|
|
||||||
x := (math.Sin(2*math.Pi*t/60) + 1)/2 * float64(width)
|
a := 2 * math.Pi * t / 60
|
||||||
y := (math.Cos(2*math.Pi*t/60) + 1)/2 * float64(height)
|
x := (math.Sin(a) + 1) / 2 * float64(width)
|
||||||
drawSprite(textures["sprites"], x, y, lists["test"])
|
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)
|
a = 10 * 2 * math.Pi * t / 60
|
||||||
y = (math.Cos(10*2*math.Pi*t/60) + 1)/2 * float64(height)
|
x = (math.Sin(a) + 1) / 2 * float64(width)
|
||||||
drawSprite(textures["sprites"], x, y, lists["test"])
|
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)
|
a = 60 * 2 * math.Pi * t / 60
|
||||||
y = (math.Cos(60*2*math.Pi*t/60) + 1)/2 * float64(height)
|
x = (math.Sin(a) + 1) / 2 * float64(width)
|
||||||
drawSprite(textures["sprites"], x, y, lists["test"])
|
y = (math.Cos(a) + 1) / 2 * float64(height)
|
||||||
|
drawSprite(textures["sprites"], x, y, -a, lists["test"])
|
||||||
}
|
}
|
||||||
|
|
|
||||||
14
log.mdown
14
log.mdown
|
|
@ -79,3 +79,17 @@ All time is CEST
|
||||||
After much fight against GLOrtho, now having arbitrary sprite positioning in viewport coordinates.
|
After much fight against GLOrtho, now having arbitrary sprite positioning in viewport coordinates.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
- 17:55
|
||||||
|
|
||||||
|
Girlfriend back home. Let's take a break and have a walk outside.
|
||||||
|
|
||||||
|
- 19:15
|
||||||
|
|
||||||
|
Back to the task!
|
||||||
|
|
||||||
|
- 19:40
|
||||||
|
|
||||||
|
Sprite rotation support
|
||||||
|
|
||||||
|

|
||||||
|
|
|
||||||
BIN
screenshots/4.gif
Normal file
BIN
screenshots/4.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.8 MiB |
Loading…
Add table
Add a link
Reference in a new issue