Skip to main content

AppGameKit - Example: Physics 3D - SimpleDemo

Please, read the EULAs and Licenses of the programs and websites listed before use and don’t register if you are not sure that you need the service offered!!!

Use this information at your own risk


// AppGameKit 2
// SimpleDemo example modified, use the up down cursors to move the ball
// www.150games.com
// www.150juegos.com

// set window properties
SetWindowTitle( "Simple 3D Physics" )
SetWindowSize( 1024, 768, 0 )

// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
SetScissor(0, 0, 0, 0)

Create3DPhysicsWorld()
Set3DPhysicsGravity(0, -1, 0)

CreateObjectBox( 1, 20,10,10 )
SetObjectColor( 1, 0,255,0, 255)
Create3DPhysicsStaticBody( 1 )
SetObjectShapeBox(1)

CreateObjectSphere( 2, 16,16,16 )
SetObjectPosition( 2, 5.1,30,0 )
SetObjectColor( 2, 255,0,0, 255)
Create3DPhysicsDynamicBody( 2 )
SetObjectShapeSphere(2)
SetObject3DPhysicsMass(2, 1.0)
SetObject3DPhysicsFriction(2, 0.5)

SetCameraPosition( 1, 0,30,-80 )
SetCameraLookAt( 1, 0,10,0, 0 )

Create3DPhysicsStaticPlane(0.0, 1.0, 0.0, -10.0)

do

    if ( (GetObject3DPhysicsLinearVelocityX( 2 ) = 0.000000) and (GetObject3DPhysicsLinearVelocityY( 2 ) = 0.000000) and (GetObject3DPhysicsLinearVelocityZ( 2 ) = 0.000000) and (GetObject3DPhysicsAngularVelocityX( 2 ) = 0.000000) and (GetObject3DPhysicsAngularVelocityY( 2 ) = 0.000000) and (GetObject3DPhysicsAngularVelocityZ( 2 ) = 0.000000) )
		Print("...")
		Create3DPhysicsDynamicBody( 2 )
		SetObjectShapeSphere(2)
		SetObject3DPhysicsMass(2, 1.0)
		SetObject3DPhysicsFriction(2, 0.5)
	endif

	// move the camera with keys
	if ( GetKeyboardExists() = 1 )

		if ( GetRawKeyPressed( 27 ) = 1 )
			end
		endif

		if ( GetRawKeyPressed( 38 ) = 1 )
			Print("Up")
			//SetObject3DPhysicsLinearVelocity( 2, 1.0, 0.0, 0.0, 50.0 )
			SetObject3DPhysicsAngularVelocity( 2, 0.0, 0.0, 1.0, 60.0 )
		endif

		if ( GetRawKeyPressed( 40 ) = 1 )
			Print("Down")
			//SetObject3DPhysicsLinearVelocity( 2, -1.0, 0.0, 0.0, 50.0 )
			SetObject3DPhysicsAngularVelocity( 2, 0.0, 0.0, -1.0, 60.0 )
		endif

	endif

	Step3DPhysicsWorld()
	Sync()

	Print( ScreenFPS() )

	Print( "Linear velocity X: " + str(GetObject3DPhysicsLinearVelocityX( 2 )) )
	Print( "Linear velocity Y: " + str(GetObject3DPhysicsLinearVelocityY( 2 )) )
	Print( "Linear velocity Z: " + str(GetObject3DPhysicsLinearVelocityZ( 2 )) )

	Print( "Angular velocity X: " + str(GetObject3DPhysicsAngularVelocityX( 2 )) )
	Print( "Angular velocity Y: " + str(GetObject3DPhysicsAngularVelocityY( 2 )) )
	Print( "Angular velocity Z: " + str(GetObject3DPhysicsAngularVelocityZ( 2 )) )

loop