| 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 |  | 
|---|
| 22 | --[[ asteroid field generator | 
|---|
| 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 | 
|---|
| 28 | fog - enable fog 0/1 | 
|---|
| 29 | --]] | 
|---|
| 30 | function asteroidField(posX, posY, posZ, minSize, maxSize, radius, count, fog) | 
|---|
| 31 | for i = 1, count, 1 | 
|---|
| 32 | do | 
|---|
| 33 | size = (math.random() * (maxSize - minSize)) + minSize | 
|---|
| 34 | pX = (2 * math.random() * radius) - radius + posX | 
|---|
| 35 | pY = (2 * math.random() * radius) - radius + posY | 
|---|
| 36 | pZ = (2 * math.random() * radius) - radius + posZ | 
|---|
| 37 | print("<StaticEntity ") | 
|---|
| 38 |  | 
|---|
| 39 | print("position = \"") | 
|---|
| 40 | print(pX) print(",") | 
|---|
| 41 | print(pY) print(",") | 
|---|
| 42 | print(pZ) print("\" ") | 
|---|
| 43 |  | 
|---|
| 44 | print("scale = \"") print(size) print("\" ") | 
|---|
| 45 |  | 
|---|
| 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 |  | 
|---|
| 59 | print("</StaticEntity>") | 
|---|
| 60 |  | 
|---|
| 61 | if fog == 1 and i % 5 == 0 then | 
|---|
| 62 | generateFog(pX, pY, pZ, radius*0.04, 0.2) | 
|---|
| 63 | end | 
|---|
| 64 | end | 
|---|
| 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 | 
|---|
| 75 | fog - enable fog 0/1 | 
|---|
| 76 | --]] | 
|---|
| 77 | function asteroidBelt(centerX, centerY, centerZ, yaw, pitch, segments, minSize, maxSize, radius0, radius1, count, fog) | 
|---|
| 78 | dPhi = (2 * math.pi) / segments | 
|---|
| 79 | width = math.abs(radius1 - radius0) | 
|---|
| 80 | radius = (radius1 + radius0) / 2 | 
|---|
| 81 | segmentCount = count / segments | 
|---|
| 82 |  | 
|---|
| 83 | print("<StaticEntity collisionType=static yaw=") print(yaw) | 
|---|
| 84 | print(" pitch=") print(pitch) | 
|---|
| 85 |  | 
|---|
| 86 | print(" position = \"") | 
|---|
| 87 | print(centerX) print(",") | 
|---|
| 88 | print(centerY) print(",") | 
|---|
| 89 | print(centerZ) print("\"") | 
|---|
| 90 | print(">") | 
|---|
| 91 |  | 
|---|
| 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)), | 
|---|
| 98 | 0, minSize, maxSize, width, segmentCount, fog) | 
|---|
| 99 | end | 
|---|
| 100 |  | 
|---|
| 101 | print("</attached>") | 
|---|
| 102 | print("</StaticEntity>") | 
|---|
| 103 | end | 
|---|