📄 boxstack.rb
字号:
# Set up a scene to demo the engine
###################
def random(x, y)
return (rand()*(y-x)+x)
end
## Function for adding things to the scene
def triggerScene( )
o = createBox( )
o.getPhysics( ).setLinearVelocity( $camera.getDirection( ) * 170 )
o.getPhysics( ).setAngularVelocity( random( -2, 2 ),
random( -7, 7 ),
random( -2, 2 ) )
o.setPosition( $camera.getPosition( ) )
end
# Function to update the scene
def updateScene( time )
end
# Function to go forward
def doForward( )
end
# Function to go backward
def doBackward( )
end
# Function to go left
def doLeft( )
end
# Function to go right
def doRight( )
end
# Function to go forward
def doForward( )
end
# Create a new box
def createBox( )
newObject = $objects.createObject( $objects.getNextUniqueName( ), "box" )
newObject.getEntity( ).setAllMaterials( "box" )
# Show how to link back to your own app
Sample::Demo::get().addReactor( newObject )
return newObject
end
# Create a new sphere
def createSphere( )
newObject = $objects.createObject( $objects.getNextUniqueName( ), "sphere" )
newObject.getEntity( ).setAllMaterials( "box" )
return newObject
end
# Function to setup a scene
def resetScene( )
# Position $camera
$camera.setPosition( 0, 10, 100 )
# Reset object pool
$objects.clearPool( )
# Clear the $physics
$phys.reset( )
# Setup a "floor" object
floor = $objects.createObject( "theFloor", "floor" )
floor.getEntity( ).setAllMaterials( "floor" )
floor.setPosition( 0, 0, 0 )
# Make sure it's not being dynamcially updated
p = floor.getPhysics( )
p.setDynamicsEnabled(false,false)
# Look at the floor
$camera.lookAt( floor )
# Real gravity
$phys.setGravity( 0, -20, 0 )
# Make the scene look a little prettier
$graph.setAmbientLight( 0.8, 0.8, 0.8 )
$graph.setSkyBox( true, "background", 7000, true )
$graph.setFog( Oasis::GraphicsSystem::FM_EXP,
Oasis::Colour.new( 1.0, 1.0, 1.0, 1.0 ), 0.005, 0, 1 )
# Setup some blocks to play with
rows = 9
blockSize = 2
for x in 0...rows
for y in 0...(rows - x)
o = createBox( )
o.setPosition( ( x * ( blockSize / 2 ) )+( y * blockSize )-
( ( rows / 2 ) * blockSize ),
( ( x - 1 ) * blockSize ) + 1.5,
0 )
o.getPhysics( ).setDynamicsEnabled( true, false)
end
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -