win32 physics test

BlitzMax Modules Forums/MiniB3D/win32 physics test

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

thx guys :)

I have stated to integrate a kind of interface with minib3d so
my current test code looks like this (everything oop yet, but I will provide procedural functions later).

I'm interrested what you guys currently think about how it looks in the code: (easiness, readability etc.)

Framework sidesign.minib3d

Strict


Local width=640,height=480,depth=16,mode=0

Graphics3D width,height,depth,mode

Local cam:TCamera=CreateCamera()
PositionEntity cam,0,0,-15

Local light:TLight=CreateLight()
RotateEntity light,45,0,0


' used by camera code
Local mxs#=0
Local mys#=0
Local move#=0.5
MouseXSpeed() ' flush
MouseYSpeed() ' flush

' used by fps code
Local old_ms=MilliSecs()
Local renders
Local fps

Local Physic:TPhysic = TPhysic.Init() 'Will disapear to the inernals


'This will be replaced and also disapear
Local MatID:Int = NewtonMaterialGetDefaultGroupID(TPhysic.World)
NewtonMaterialSetDefaultElasticity(TPhysic.World,MatID,MatID,.6)


SeedRnd(MilliSecs())

'Creating some Balls and cubes to play with

For Local I:Int = 0 To 200
	If Rand(10) < 5 Then 
		Local sphere:TMesh=CreateSphere()
		EntityRadius sphere,2
		EntityPickMode sphere,2
		PositionEntity sphere,Rnd(-20,20),Rnd(0,100),Rnd(-20,20)
		EntityColor(sphere,Rand(255),Rand(255),Rand(255))
		
		Local NSphere:TNewtonObject = TNewtonObject.Create(Sphere,PHYS_SPHERE_HULL) 'Create the Collision Hull (Parameters are set automatically)
		NSphere.SetMass(1.0,1.0,1.0,1.0) ' Make it movable and a accurate ball
		Physic.AddObject(NSphere) 'Give it to the Physic engine
	Else
		Local cube:TMesh=CreateCube()
		EntityRadius cube,2
		EntityPickMode cube,2
		PositionEntity cube,Rnd(-20,20),Rnd(0,100),Rnd(-20,20)
		EntityColor(cube,Rand(255),Rand(255),Rand(255))
		
		Local NCube:TNewtonObject = TNewtonObject.Create(cube,PHYS_BOX_HULL) 'Create the Collision Hull (Parameters are set automatically)
		NCube.SetMass(1.0,1.0,1.0,1.0) ' Make it movable and a accurate cube
		Physic.AddObject(NCube) 'Give it to the Physic engine
	EndIf
Next


Local Plane:TMesh = CreateCube()
PositionEntity(Plane,0,-30,0)
ScaleEntity(Plane,80,5,80)
EntityColor plane,20,100,30


Local NPlane:TNewtonObject = TNewtonObject.Create(Plane,PHYS_BOX_HULL)
NPlane.SetMass(0.0,0.0,0.0,0.0) ' Set it solid
Physic.AddObject(NPlane) 'Give it to the Physic engine



Local Timestep:Int = MilliSecs()

Global  pick:TEntity
While Not KeyDown(KEY_ESCAPE)		
	
	Pick = Null
	
	If KeyHit(KEY_ENTER) Then DebugStop

	'' control camera
	
	' mouse look
	
	mxs#=mxs#+(MouseXSpeed()/5.0)
	mys#=mys#+(MouseYSpeed()/5.0)

	RotateEntity cam,mys#,-mxs#,0

	If KeyDown(KEY_SPACE)=False
		MoveMouse width/2,height/2
		MouseXSpeed() ' flush
		MouseYSpeed() ' flush
	EndIf

	' move camera forwards/backwards/left/right with cursor keys
	
	If KeyDown(KEY_UP)=True Then MoveEntity cam,0,0,move# ' move camera forward
	If KeyDown(KEY_DOWN)=True Then MoveEntity cam,0,0,-move# ' move camera back

	If KeyDown(KEY_LEFT)=True Then MoveEntity cam,-move#,0,0 ' move camera left
	If KeyDown(KEY_RIGHT)=True Then MoveEntity cam,move#,0,0 ' move camera right
	
	

	' if mousehit then perform camerapick
	If MouseHit(1)
	
				

		pick=CameraPick(cam,MouseX(),MouseY())
		
		If pick<>Null
			Local XP:Float = Rnd(-15.0,15.0)
			Local YP:Float = Rnd(-15.0,15.0)
			Local ZP:Float = Rnd(-15.0,15.0)
			' Apply a random impulse to the picked ball
			Physic.ApplyImpulse(pick,PickedX(),PickedY(),PickedZ(),XP,YP,ZP)
		EndIf
		
	
	EndIf
	
	
	Physic.Update() ' Update the physics (Update time is automatically calculated and passed as Deltatime within the engine)
	UpdateWorld()
	RenderWorld()
	renders=renders+1

	If MilliSecs()-old_ms>=1000
		
		old_ms=MilliSecs()
		fps=renders
		renders=0
	EndIf
		
	
	
	SetBlend AlphaBlend
	Text 0,0,"FPS: "+String(fps)
	Flip 

Wend
End