[8961] | 1 | --[[ fog generator |
---|
| 2 | generates fog |
---|
| 3 | posX, posY, posZ - position in space |
---|
| 4 | size - size of billboard |
---|
| 5 | brightness - [0,1] fog brightness |
---|
| 6 | --]] |
---|
| 7 | function generateFog(posX, posY, posZ, size, brightness) |
---|
| 8 | print("<Billboard ") |
---|
| 9 | print("position = \"") |
---|
| 10 | print(posX) print(",") |
---|
| 11 | print(posY) print(",") |
---|
| 12 | print(posZ) print("\" ") |
---|
| 13 | print("colour=\"") |
---|
| 14 | print(brightness) print(",") |
---|
| 15 | print(brightness) print(",") |
---|
| 16 | print(brightness) print("\" ") |
---|
| 17 | print("material=\"Smoke/Smoke\" scale=") |
---|
| 18 | print(size) |
---|
| 19 | print(" />") |
---|
| 20 | end |
---|
| 21 | |
---|
[8917] | 22 | --[[ asteroid field generator |
---|
[8919] | 23 | generates asteroid field |
---|
| 24 | posX, posY, posZ - position in space |
---|
| 25 | minSize, maxSize - size boundaries of each asteroid |
---|
| 26 | radius - size of the cube around position in space |
---|
| 27 | count - number of asteroids |
---|
[8961] | 28 | fog - enable fog 0/1 |
---|
[8919] | 29 | --]] |
---|
[8961] | 30 | function asteroidField(posX, posY, posZ, minSize, maxSize, radius, count, fog) |
---|
[8889] | 31 | for i = 1, count, 1 |
---|
| 32 | do |
---|
[8917] | 33 | size = (math.random() * (maxSize - minSize)) + minSize |
---|
[8946] | 34 | pX = (2 * math.random() * radius) - radius + posX |
---|
| 35 | pY = (2 * math.random() * radius) - radius + posY |
---|
| 36 | pZ = (2 * math.random() * radius) - radius + posZ |
---|
[8917] | 37 | print("<StaticEntity ") |
---|
[8889] | 38 | |
---|
| 39 | print("position = \"") |
---|
[8946] | 40 | print(pX) print(",") |
---|
| 41 | print(pY) print(",") |
---|
[8947] | 42 | print(pZ) print("\" ") |
---|
[8889] | 43 | |
---|
[8947] | 44 | print("scale = \"") print(size) print("\" ") |
---|
[8889] | 45 | |
---|
[8947] | 46 | print("collisionType = static linearDamping = 0.8 angularDamping = 1 ") |
---|
| 47 | print("collisiondamage = 1000 enablecollisiondamage = true>") |
---|
| 48 | |
---|
| 49 | print("<attached>") |
---|
| 50 | print("<Model mass=\"") print(size * 10) print("\" ") |
---|
| 51 | print("mesh=\"ast") print(math.mod(i,6) + 1) print(".mesh\" />") |
---|
| 52 | print("</attached>") |
---|
| 53 | |
---|
| 54 | print("<collisionShapes> ") |
---|
| 55 | print("<SphereCollisionShape radius=\"") |
---|
| 56 | print(size * 2.5) print("\" />") |
---|
| 57 | print("</collisionShapes>") |
---|
| 58 | |
---|
[8917] | 59 | print("</StaticEntity>") |
---|
[8961] | 60 | |
---|
| 61 | if fog == 1 and i % 5 == 0 then |
---|
[8972] | 62 | generateFog(pX, pY, pZ, radius*0.04, 0.2) |
---|
[8961] | 63 | end |
---|
[8889] | 64 | end |
---|
[8946] | 65 | end |
---|
| 66 | |
---|
| 67 | |
---|
| 68 | --[[ asteroid belt generator |
---|
| 69 | generates asteroid belt |
---|
| 70 | posX, posY, posZ - position in space |
---|
| 71 | yaw, pitch - rotation |
---|
| 72 | minSize, maxSize - size boundaries of each asteroid |
---|
| 73 | radius0, radius1 - inner/outer radius |
---|
| 74 | count - number of asteroids |
---|
[8961] | 75 | fog - enable fog 0/1 |
---|
[8946] | 76 | --]] |
---|
[8961] | 77 | function asteroidBelt(centerX, centerY, centerZ, yaw, pitch, segments, minSize, maxSize, radius0, radius1, count, fog) |
---|
[8946] | 78 | dPhi = (2 * math.pi) / segments |
---|
| 79 | width = math.abs(radius1 - radius0) |
---|
| 80 | radius = (radius1 + radius0) / 2 |
---|
| 81 | segmentCount = count / segments |
---|
[8889] | 82 | |
---|
[8947] | 83 | print("<StaticEntity collisionType=static yaw=") print(yaw) |
---|
| 84 | print(" pitch=") print(pitch) |
---|
| 85 | |
---|
[8946] | 86 | print(" position = \"") |
---|
| 87 | print(centerX) print(",") |
---|
| 88 | print(centerY) print(",") |
---|
| 89 | print(centerZ) print("\"") |
---|
| 90 | print(">") |
---|
[8947] | 91 | |
---|
[8946] | 92 | print("<attached>") |
---|
| 93 | |
---|
| 94 | for i = 0, segments - 1, 1 |
---|
| 95 | do |
---|
| 96 | asteroidField((radius * math.cos(i * dPhi)), |
---|
| 97 | (radius * math.sin(i * dPhi)), |
---|
[8961] | 98 | 0, minSize, maxSize, width, segmentCount, fog) |
---|
[8946] | 99 | end |
---|
| 100 | |
---|
| 101 | print("</attached>") |
---|
| 102 | print("</StaticEntity>") |
---|
[8889] | 103 | end |
---|