Hi guys,
I've been promising an update to AppGameKit 2.0 for my existing ebook Teach Yourself Game Programming. Now that 2.015b is out and the command set is fixed I can begin work. The following is a free physics demonstration from the upcoming ebook update.
This is a simple 3D ball bounce on a rubber surface demo, with a twist of hit detection thrown in for good measure. The balls will fall, recycle, and fall again. They will bounce off each other, and behave like balls falling onto a hard rubber surface. They each have a text notation indicating contact with another 3D object. This mostly occurs when the ball is rolling across the table.
Those of you interested in the ebook can find out more on the following thread:
https://forum.thegamecreators.com/thread/203773
// set window properties
SetSyncRate( 0, 1 )
SetWindowTitle( "Cameras" )
SetWindowSize( 1024, 768, 0 )
SetRandomSeed( 12 )
SetRandomSeed2( 18 )
Create3DPhysicsWorld()
Set3DPhysicsGravity( 0, -3, 0 )
Dim Sphere[ 99 ]
Dim Text[ 99 ]
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
SetCameraPosition( 1, -150, 50, 0 )
SetCameraLookAt( 1, 0, 0, 0, 0 )
Box = CreateObjectBox( 100, 10, 100 )
SetObjectRotation( Box, 1.0, 1.0, 1.0 )
SetObjectcolor( Box, random( 32, 255 ), random( 32, 255 ), random( 32, 255 ), 255 )
Create3DPhysicsKinematicBody( Box )
SetObject3DPhysicsRestitution( Box, 0.75 )
SetObjectShapeBox( Box )
SetObjectPosition( Box, 0, -50, 0 )
Print( "Floor generated" ) : Sync()
For i = 0 to 99
Sphere[ i ] = CreateObjectSphere( 5, 16, 16 )
SetObjectPosition( Sphere[ i ], random2( -10, 10 ), random2( 50, 150 ), random( -10, 10 ) )
Create3DPhysicsDynamicBody( Sphere[ i ] )
SetObjectcolor( Sphere[ i ], random( 32, 255 ), random( 32, 255 ), random( 32, 255 ), 255 )
SetObjectShapeSphere( Sphere[ i ] )
SetObject3DPhysicsRollingFriction( Sphere[ i ], 0 )
SetObject3DPhysicsRestitution( Sphere[ i ], 0.95 )
Print( "Object " + str( i ) + " of 99 created" )
Sync()
Text[ i ] = CreateText( "" )
SetTextSize( Text[ i ], 12 )
SetTextColor( Text[ i ], 255, 255, 255, 255 )
Next i
SetSyncRate( 60, 1 )
do
For i = 0 to 99
If GetObjectY( Sphere[ i ] ) < -150
Delete3DPhysicsBody( Sphere[ i ] )
SetObjectPosition( Sphere[ i ], random2( -10, 10 ), random2( 50, 150 ), random( -10, 10 ) )
Create3DPhysicsDynamicBody( Sphere[ i ] )
SetObjectShapeSphere( Sphere[ i ] )
SetObject3DPhysicsRollingFriction( Sphere[ i ], 0 )
SetObject3DPhysicsRestitution( Sphere[ i ], 1.0 )
EndIf
Next i
For i = 0 to 99
If GetObject3DPhysicsFirstContact( Sphere[ i ] ) = 1
SetTextString( Text[ i ], "Hit" )
SetTextColor( Text[ i ], 255, 0, 0, 128 )
SetTextPosition( Text[ i ], GetScreenXFrom3D( GetObjectX( Sphere[ i ] ), GetObjectY( Sphere[ i ] ), GetObjectZ( Sphere[ i ] ) ), GetScreenYFrom3D( GetObjectX( Sphere[ i ] ), GetObjectY( Sphere[ i ] ), GetObjectZ( Sphere[ i ] ) ) )
GetObject3DPhysicsNextContact()
Else
SetTextString( Text[ i ], "No hit" )
SetTextColor( Text[ i ], 0, 255, 0, 128 )
SetTextPosition( Text[ i ], GetScreenXFrom3D( GetObjectX( Sphere[ i ] ), GetObjectY( Sphere[ i ] ), GetObjectZ( Sphere[ i ] ) ), GetScreenYFrom3D( GetObjectX( Sphere[ i ] ), GetObjectY( Sphere[ i ] ), GetObjectZ( Sphere[ i ] ) ) )
EndIf
Next i
Print( ScreenFPS() )
Step3DPhysicsWorld()
Sync()
loop