📄 simprag.rb
字号:
# Set up a scene to $demo the engine
##################
def random(x, y)
return (rand()*(y-x)+x)
end
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
# 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
# Create a new step
def createStep( )
newObject = $objects.createObject( $objects.getNextUniqueName( ), "step" )
newObject.getEntity( ).setAllMaterials( "plank" )
return newObject
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
# Function to create a grunt
def createGrunt( x, y, z )
vector3 = Oasis::Vector3
joint = Oasis::Joint
head = $objects.createObject( $objects.getNextUniqueName( ), "head" )
body = $objects.createObject( $objects.getNextUniqueName( ), "body" )
lleg1 = $objects.createObject( $objects.getNextUniqueName( ), "leg" )
lleg2 = $objects.createObject( $objects.getNextUniqueName( ), "leg" )
rleg1 = $objects.createObject( $objects.getNextUniqueName( ), "leg" )
rleg2 = $objects.createObject( $objects.getNextUniqueName( ), "leg" )
larm1 = $objects.createObject( $objects.getNextUniqueName( ), "arm" )
larm2 = $objects.createObject( $objects.getNextUniqueName( ), "arm" )
rarm1 = $objects.createObject( $objects.getNextUniqueName( ), "arm" )
rarm2 = $objects.createObject( $objects.getNextUniqueName( ), "arm" )
# Show how to link back to your own app
$demo.addReactor( body )
$demo.addReactor( head )
$demo.addReactor( rleg2 )
$demo.addReactor( lleg2 )
head.setPosition( x, y + 4.5, z )
body.setPosition( x, y, z )
lleg1.setPosition( x + 1, y - 4.3, z )
lleg2.setPosition( x + 1, y - 7.6, z )
rleg1.setPosition( x - 1, y - 4.3, z )
rleg2.setPosition( x - 1, y - 7.6, z )
larm1.setPosition( x + 3.3, y + 1.5, z )
larm1.rotate( vector3.new( 0, 0, 1 ), 90 )
larm2.setPosition( x + 6.6, y + 1.5, z )
larm2.rotate( vector3.new( 0, 0, 1 ), 90 )
rarm1.setPosition( x - 3.3, y + 1.5, z )
rarm1.rotate( vector3.new( 0, 0, 1 ), 90 )
rarm2.setPosition( x - 6.6, y + 1.5, z )
rarm2.rotate( vector3.new( 0, 0, 1 ), 90 )
bh = $phys.createJoint( joint::JT_BALL, "bh"+$numGrunts.to_s, body.getPhysics( ), head.getPhysics( ) )
bh.setAnchorPosition( x, y + 3, z )
bll = $phys.createJoint( joint::JT_BALL, "bll"+$numGrunts.to_s, body.getPhysics( ), lleg1.getPhysics( ) )
bll.setAnchorPosition( x + 1, y - 2.6, z )
bll2 = $phys.createJoint( joint::JT_HINGE, "bll2"+$numGrunts.to_s, lleg2.getPhysics( ), lleg1.getPhysics( ) )
bll2.setAnchorPosition( x + 1, y - 5.95, z )
bll2.setAxes( vector3.new( 1, 0, 0 ), vector3.new( 0, 0, 0 ) )
brl = $phys.createJoint( joint::JT_BALL, "brl"+$numGrunts.to_s, body.getPhysics( ), rleg1.getPhysics( ) )
brl.setAnchorPosition( x - 1, y - 2.6, z )
brl2 = $phys.createJoint( joint::JT_HINGE, "brl2"+$numGrunts.to_s, rleg2.getPhysics( ), rleg1.getPhysics( ) )
brl2.setAnchorPosition( x - 1, y - 5.95, z )
brl2.setAxes( vector3.new( 1, 0, 0 ), vector3.new( 0, 0, 0 ) )
bla = $phys.createJoint( joint::JT_BALL, "bla"+$numGrunts.to_s, body.getPhysics( ), larm1.getPhysics( ) )
bla.setAnchorPosition( x + 1.6, y + 1.5, z )
bla2 = $phys.createJoint( joint::JT_HINGE, "bla2"+$numGrunts.to_s, larm2.getPhysics( ), larm1.getPhysics( ) )
bla2.setAnchorPosition( x + 4.95, y + 1.5, z )
bla2.setAxes( vector3.new( 0, 1, 0 ), vector3.new( 0, 0, 0 ) )
bra = $phys.createJoint( joint::JT_BALL, "bra"+$numGrunts.to_s, body.getPhysics( ), rarm1.getPhysics( ) )
bra.setAnchorPosition( x - 1.6, y + 1.5, z )
bra2 = $phys.createJoint( joint::JT_HINGE, "bra2"+$numGrunts.to_s, rarm2.getPhysics( ), rarm1.getPhysics( ) )
bra2.setAnchorPosition( x - 4.95, y + 1.5, z )
bra2.setAxes( vector3.new( 0, 1, 0 ), vector3.new( 0, 0, 0 ) )
$numGrunts = $numGrunts + 1
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 )
# Make steps
for step in 0...15
newStep = createStep( )
newStep.setPosition( 0, step * 2, step * -2 )
newStep.getPhysics( ).setDynamicsEnabled( false, false )
end
# Get our grunt on
createGrunt( 0, 50, 20 )
createGrunt( 15, 50, 20 )
createGrunt( -15, 50, 20 )
createGrunt( 0, 70, 20 )
createGrunt( 15, 70, 20 )
createGrunt( -15, 70, 20 )
end
$numGrunts = 0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -