//*********************************************************************************
//                          SPARK Wrapper Glue Demo
//                        Glue systems to dbpro objects
//*********************************************************************************


// lets load our rocket model
autocam off
load object "media\rocket.x" , 1
load image "media\explosion.bmp",1

color backdrop 0


// we load back the explosion just to create a nice rocket explosion 
// textures used by this system starts from 100

explosionProto = sp load system("Explosion.spk",1,100)

// create some simple trail particle system (similar as in BasicDemo)

mySystem = sp create system (0,0,0,0)
myGroup = sp add group (mySystem , 200 , 0.03 , 0,0,0)
sp set group lifetime myGroup , 3.5 , 4.5
myRenderer = sp set quad renderer (myGroup , 1 , 85,85,2,2,2)
scaleInterpolator = sp add interpolator (myGroup , PARAM_SCALE , 2.8 , 6.0 , 12 ,40)
textureInterpolator = sp add interpolator (myGroup , PARAM_ATLAS_DIMENSIONS , 0 , 4 ,1)
angleInterpolator = sp add interpolator (myGroup ,PARAM_ANGLE, 0.01 , 2.2,0)
rgbaInterpolator = sp add rgba interpolator (myGroup , 0x9A300048 , 0x9A800000 , 0)
myEmitter = sp add spheric emitter (myGroup , 0 , 1 , 0 , 0.3 , 0.6 , 25 , 0.1 , 0.5 ,-1 , sp sphere zone(0,0,0 ,5.55))

// we glue the system to the rocket model's 1st limb (the bottom of the rocket).
// set the rotateFlag to 1 to ensure our system rotates with the object
// and set the deleteFlag to 2  so the system will be deleted if becomes inactive
// (not right after the object is deleted)

sp glue system mySystem , 1,1,1,2

do
    
    if object exist(1) = 1
        move object 1,-0.6
        rotate object 1,x# , y# , z#
        x# = x# +0.04
        y# = y# +0.4
        z# = z# +0.4
    endif
    
    position camera 0,0,0,0
    rotate camera 0 ,camera angle x(0)+ mousemovey()*0.2 , camera angle y(0)+ mousemovex()*0.2 ,0
    move camera 0,-350

if spacekey() = 1 and hold=0
    explode = sp copy system(explosionProto , limb position x(1,0) , limb position y(1,0) , limb position z(1,0))
    delete object 1 
    hold=1
    endif
    
    set cursor 0,0
    print "PRESS SPACE TO EXPLODE THE ROCKET !"
   sp update
   
loop
    







