New example: models/rlgl_solar_system
This commit is contained in:
parent
5b33862cc1
commit
af2e6d755e
1 changed files with 28 additions and 36 deletions
|
@ -23,12 +23,15 @@ import (
|
||||||
const (
|
const (
|
||||||
screenWidth = 800
|
screenWidth = 800
|
||||||
screenHeight = 450
|
screenHeight = 450
|
||||||
|
|
||||||
sunRadius = 4.0
|
sunRadius = 4.0
|
||||||
earthRadius = 0.6
|
earthRadius = 0.6
|
||||||
earthOrbitRadius = 8.0
|
|
||||||
moonRadius = 0.16
|
moonRadius = 0.16
|
||||||
|
|
||||||
|
earthOrbitRadius = 8.0
|
||||||
moonOrbitRadius = 1.5
|
moonOrbitRadius = 1.5
|
||||||
rings, slices int32 = 16, 16
|
|
||||||
|
rings, slices = 16, 16
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -122,42 +125,31 @@ func DrawSphereBasic(color rl.Color) {
|
||||||
rl.Begin(rl.Triangles)
|
rl.Begin(rl.Triangles)
|
||||||
rl.Color4ub(color.R, color.G, color.B, color.A)
|
rl.Color4ub(color.R, color.G, color.B, color.A)
|
||||||
|
|
||||||
for i := int32(0); i < (rings + 2); i++ {
|
for ring := int32(0); ring < (rings + 2); ring++ {
|
||||||
for j := int32(0); j < slices; j++ {
|
for slice := int32(0); slice < slices; slice++ {
|
||||||
ii := float64(i)
|
rl.Vertex3f(getCoords(ring, slice))
|
||||||
jj := float64(j)
|
rl.Vertex3f(getCoords(ring+1, slice+1))
|
||||||
|
rl.Vertex3f(getCoords(ring+1, slice))
|
||||||
x, y, z := getXYZ(ii, jj)
|
rl.Vertex3f(getCoords(ring, slice))
|
||||||
rl.Vertex3f(x, y, z)
|
rl.Vertex3f(getCoords(ring, slice+1))
|
||||||
|
rl.Vertex3f(getCoords(ring+1, slice+1))
|
||||||
x, y, z = getXYZ(ii+1, jj+1)
|
|
||||||
rl.Vertex3f(x, y, z)
|
|
||||||
|
|
||||||
x, y, z = getXYZ(ii+1, jj)
|
|
||||||
rl.Vertex3f(x, y, z)
|
|
||||||
|
|
||||||
x, y, z = getXYZ(ii, jj)
|
|
||||||
rl.Vertex3f(x, y, z)
|
|
||||||
|
|
||||||
x, y, z = getXYZ(ii, jj+1)
|
|
||||||
rl.Vertex3f(x, y, z)
|
|
||||||
|
|
||||||
x, y, z = getXYZ(ii+1, jj+1)
|
|
||||||
rl.Vertex3f(x, y, z)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rl.End()
|
rl.End()
|
||||||
}
|
}
|
||||||
|
|
||||||
func getXYZ(i, j float64) (float32, float32, float32) {
|
func getCoords(ring, slice int32) (x, y, z float32) {
|
||||||
|
ringF := float64(ring)
|
||||||
|
sliceF := float64(slice)
|
||||||
|
|
||||||
// Calculate angels
|
// Calculate angels
|
||||||
alpha := rl.Deg2rad * (270 + (180/(float64(rings)+1))*i)
|
alpha := rl.Deg2rad * (270 + (180/(float64(rings)+1))*ringF)
|
||||||
beta := rl.Deg2rad * (j * 360 / float64(slices))
|
beta := rl.Deg2rad * (sliceF * 360 / float64(slices))
|
||||||
|
|
||||||
// Calculate coords
|
// Calculate coords
|
||||||
x := float32(math.Cos(alpha) * math.Sin(beta))
|
x = float32(math.Cos(alpha) * math.Sin(beta))
|
||||||
y := float32(math.Sin(alpha))
|
y = float32(math.Sin(alpha))
|
||||||
z := float32(math.Cos(alpha) * math.Cos(beta))
|
z = float32(math.Cos(alpha) * math.Cos(beta))
|
||||||
|
|
||||||
return x, y, z
|
return x, y, z
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue