Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 23, 2011, 3:13:31 PM (13 years ago)
Author:
fmauro
Message:

asteroidBelt function added

Location:
code/branches/environment3/data/levels
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/environment3/data/levels/asteroidField.oxw

    r8919 r8946  
    3737    <?lua
    3838        dofile("includes/asteroidField.lua")
    39         asteroidField(0, 0, 0, 150, 50, 12000, 250)
     39        asteroidField(0, 0, 5000, 100, 150, 2000, 50);
     40        asteroidBelt(0, 0, 0, -48, -34, 30, 100, 200, 17000, 21000, 900)
    4041    ?>
    4142   
  • code/branches/environment3/data/levels/includes/asteroidField.lua

    r8919 r8946  
    1010        do
    1111                size = (math.random() * (maxSize - minSize)) + minSize
     12                pX = (2 * math.random() * radius) - radius + posX
     13                pY = (2 * math.random() * radius) - radius + posY
     14                pZ = (2 * math.random() * radius) - radius + posZ
    1215                print("<StaticEntity ")
    1316               
    1417                print("position = \"")
    15                 print((2 * math.random() * radius) - radius + posX) print(",")
    16                 print((2 * math.random() * radius) - radius + posY) print(",")
    17                 print((2 * math.random() * radius) - radius + posZ) print("\"")
     18                print(pX) print(",")
     19                print(pY) print(",")
     20                print(pZ) print("\"")
    1821               
    1922                print("scale = \"") print(size) print("\"")
    2023               
    21                 print("collisionType = static linearDamping = 0.8 angularDamping = 0 collisiondamage = 1 enablecollisiondamage = true>")
     24                print("collisionType = static linearDamping = 0.8 angularDamping = 1 collisiondamage = 1000 enablecollisiondamage = true>")
    2225                print("<attached> <Model mass=\"") print(size * 10) print("\" mesh=\"ast") print(math.mod(i,6) + 1) print(".mesh\" /> </attached>")
    23                 print("<attached> <ForceField position=\"0,0,0\" mode=\"newtonianGravity\" diameter=\"") print(size + (size * 0.2)) print("\" massDiameter=\"") print(size) print("\" mass=\"") print(size * 1000) print("\" /> </attached>")
    24                 print("<collisionShapes> <SphereCollisionShape radius=\"") print(size) print("\" /> </collisionShapes>")
     26                print("<attached> <ForceField position=\"0,0,0\" mode=\"newtonianGravity\" diameter=\"") print(size * 2.7) print("\" massDiameter=\"") print(size * 2) print("\" mass=\"") print(size * 1000) print("\" /> </attached>")
     27                print("<collisionShapes> <SphereCollisionShape radius=\"") print(size*2.5) print("\" /> </collisionShapes>")
    2528                print("</StaticEntity>")
    2629        end
     30end
     31
     32
     33--[[ asteroid belt generator
     34generates asteroid belt
     35        posX, posY, posZ - position in space
     36        yaw, pitch - rotation
     37        minSize, maxSize - size boundaries of each asteroid
     38        radius0, radius1 - inner/outer radius
     39        count - number of asteroids
     40--]]
     41function asteroidBelt(centerX, centerY, centerZ, yaw, pitch, segments, minSize, maxSize, radius0, radius1, count)
     42        dPhi = (2 * math.pi) / segments
     43        width = math.abs(radius1 - radius0)
     44        radius = (radius1 + radius0) / 2
     45        segmentCount = count / segments
    2746       
     47        print("<StaticEntity collisionType=static yaw=")
     48        print(yaw)
     49        print(" pitch=")
     50        print(pitch)
     51        print(" position = \"")
     52                print(centerX) print(",")
     53                print(centerY) print(",")
     54                print(centerZ) print("\"")
     55        print(">")
     56        print("<attached>")
     57       
     58        for i = 0, segments - 1, 1
     59        do
     60                asteroidField((radius * math.cos(i * dPhi)),
     61                                        (radius * math.sin(i * dPhi)),
     62                                        0, minSize, maxSize, width,segmentCount)
     63        end
     64       
     65        print("</attached>")
     66        print("</StaticEntity>")
    2867end
Note: See TracChangeset for help on using the changeset viewer.