Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickupsFS14/data/levels/includes/asteroidField.lua @ 10037

Last change on this file since 10037 was 9348, checked in by landauf, 12 years ago

merged branch presentation2012merge back to trunk

  • Property svn:eol-style set to native
File size: 3.1 KB
Line 
1--[[ fog generator
2generates fog
3    posX, posY, posZ - position in space
4    size - size of billboard
5    brightness - [0,1] fog brightness
6--]]
7function 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(" />")
20end
21
22--[[ asteroid field generator
23generates 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--]]
30function asteroidField(posX, posY, posZ, minSize, maxSize, radius, count, fog)
31    for i = 1, count, 1 do
32        size = (math.random() * (maxSize - minSize)) + minSize
33        pX = (2 * math.random() * radius) - radius + posX
34        pY = (2 * math.random() * radius) - radius + posY
35        pZ = (2 * math.random() * radius) - radius + posZ
36        print("<StaticEntity ")
37
38        print("position = \"")
39        print(pX) print(",")
40        print(pY) print(",")
41        print(pZ) print("\" ")
42
43        print("scale = \"") print(size) print("\" ")
44
45        print("collisionType = static linearDamping = 0.8 angularDamping = 1 ")
46        print("collisiondamage = 1000 enablecollisiondamage = true>")
47
48        print("<attached>")
49            print("<Model mass=\"") print(size * 10) print("\" ")
50            print("mesh=\"ast") print(math.mod(i,6) + 1) print(".mesh\" />")
51        print("</attached>")
52
53        print("<collisionShapes> ")
54            print("<SphereCollisionShape radius=\"")
55            print(size * 2.5) print("\" />")
56        print("</collisionShapes>")
57
58        print("</StaticEntity>")
59
60        if fog == 1 and i % 5 == 0 then
61            generateFog(pX, pY, pZ, radius*0.04, 0.2)
62        end
63    end
64end
65
66
67--[[ asteroid belt generator
68generates asteroid belt
69    posX, posY, posZ - position in space
70    yaw, pitch - rotation
71    minSize, maxSize - size boundaries of each asteroid
72    radius0, radius1 - inner/outer radius
73    count - number of asteroids
74    fog - enable fog 0/1
75--]]
76function asteroidBelt(centerX, centerY, centerZ, yaw, pitch, segments, minSize, maxSize, radius0, radius1, count, fog)
77    dPhi = (2 * math.pi) / segments
78    width = math.abs(radius1 - radius0)
79    radius = (radius1 + radius0) / 2
80    segmentCount = count / segments
81
82    print("<StaticEntity collisionType=static yaw=") print(yaw)
83    print(" pitch=") print(pitch)
84
85    print(" position = \"")
86        print(centerX) print(",")
87        print(centerY) print(",")
88        print(centerZ) print("\"")
89    print(">")
90
91    print("<attached>")
92
93    for i = 0, segments - 1, 1 do
94        asteroidField((radius * math.cos(i * dPhi)),
95                    (radius * math.sin(i * dPhi)),
96                    0, minSize, maxSize, width, segmentCount, fog)
97    end
98
99    print("</attached>")
100    print("</StaticEntity>")
101end
Note: See TracBrowser for help on using the repository browser.