EasyTOK version 1.1

Blitz3D Forums/Blitz3D Programming/EasyTOK version 1.1

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.

Filax,

more problems I'm afriad, just try hitting the left mouse button. RB Spheres still pass thru the AB cubes

;=======================================================================================
; Code : EasyTok librarie example
; Project Title : EasyTok librarie example
; Author : Philippe Agnisola
; Email :                    
; Version : 1.0.0
; Date :              
; Notes : 
;                   
;                   
;=======================================================================================

Include "Inc_TimeMachine.bb"
Include "Inc_EasyTOK.bb"

; ------------------------
; Freelook cam var
; ------------------------
Global Mouse_X_Speed#
Global Mouse_Y_Speed#
Global Camera_VelX#
Global Camera_VelZ#
Global Camera_Pitch
Global Camera_Yaw

; -------------------------------
; Refresh frame number
; -------------------------------
Global AppFPS =60

; ------------------
; Open screen
; ------------------
Graphics3D 1024, 768,32,0
SetBuffer BackBuffer ()

; ----------------------
; Change font text
; ----------------------
AppFont=LoadFont("Arial",15,1,0,0) 
SetFont AppFont

; -------------------------------------
; Setup camera and Easytok
; -------------------------------------
Global Cam=CreateCamera()
PositionEntity Cam,0,25,-40

Proc_CreateVisor()

TOK_InitWorld(0,-40,0,1000,100)
TOK_CreateGround("Floor",150,255,150,10)

; -----------------------------
; Creating demo world
; -----------------------------
Global Light1=CreateLight(2)
PositionEntity Light1,-50,50,-50
LightColor Light1,250,150,50
LightRange Light1,100

Global Light2=CreateLight(2)
PositionEntity Light2,50,50,50
LightColor Light2,50,150,250
LightRange Light2,100

AmbientLight 80,90,100

; -----------------------------
; Create the plateform
; -----------------------------
Global MyCube03=TOK_CreateABCube("Toto0",0,21,0,0,0,0,15,0.25,15,"",255,55,55,1)
TOK_EntityColor("Toto0",110,150,0)

Global Angle#

; -------------
; Main loop
; -------------
FramePeriod = 1000 / AppFPS
FrameTime = MilliSecs () - FramePeriod
MoveMouse GraphicsWidth()/2, GraphicsHeight()/2

Repeat
	; --------------------------
	; Frame rate limiting
	; --------------------------
	Repeat
		FrameElapsed = MilliSecs () - FrameTime
	Until FrameElapsed

	FrameTicks = FrameElapsed / FramePeriod
	FrameTween# = Float (FrameElapsed Mod FramePeriod) / Float (FramePeriod)

	; -----------------------
	; Update tweening
	; -----------------------
	For FrameLimit = 1 To FrameTicks
		If FrameLimit = FrameTicks Then
			CaptureWorld
		EndIf

		FrameTime = FrameTime + FramePeriod
		
		UpdateGame ()
		UpdateWorld
	Next

	; -------------------
	; Redraw world
	; -------------------
	TOK_RefreshEasyTOK()
	RenderWorld FrameTween
	
	; -----------------------
	; FPS Displaying
	; -----------------------
	Proc_CinemaStrip()
	Color 255,255,255
	Information$="<"+Get_FPS()+" FPS> / "+"<Arrow key to move> / <Mouse left to launch objects>"
	Text GraphicsWidth()/2,GraphicsHeight()-30,Information$,True,True
	Flip
Until KeyHit (1)

; -----------
; End App
; -----------
TOK_FreePhysic()
FreeFont  AppFont
End

; -----------------------------------
; Tweening update function
; -----------------------------------
Function UpdateGame ()
	Proc_Freelook(Cam,1.05,0.05)

	; -----------------------------------------
	; Launch a cube and a sphere
	; -----------------------------------------
	If MouseHit(1) Then
;		TOK_CreateRBCube("Toto1",False,Rnd(-10,10),40,Rnd(-10,10),0,0,0,2,2,2,6,"",255,255,1,1,20)
		TOK_CreateRBSphere("Toto2",False,10,40,Rnd(-10,10),0,0,0,2,10,"",255,255,255,1,20)
	EndIf
	
	Angle#=Angle#+2
	TOK_RotateABEntity("Toto0",0,0,Angle)

	; ------------------------------------------
	; Apply impulse to ALL objects
	; ------------------------------------------
	If MouseHit(2) Then
		TOK_ApplyImpulse("",Rnd(-5,5),Rnd(55,65),Rnd(-5,5))
	EndIf
	
	TOK_RefreshPhysic(1.7/AppFPS,10)
End Function

; -----------------------
; Create the visor
; -----------------------
Function Proc_CreateVisor()
	Visor=LoadSprite("./ETOK_Medias/Target.png")
	PositionEntity Visor,EntityX(Cam),EntityY(Cam),EntityZ(Cam)+2
	ScaleSprite Visor,0.1,0.1
	EntityParent Visor,Cam
	EntityOrder Visor,-1
End Function

; ----------------------------------
; Create the cinema strip
; ----------------------------------
Function Proc_CinemaStrip(Size=60)
	Color 1,1,1
	Rect 0,0,GraphicsWidth(),Size
	Rect 0,GraphicsHeight()-Size,GraphicsWidth(),Size
End Function

; ----------------------
; Camera freelook
; ----------------------
Function Proc_Freelook(CamEntity,Velocity#,Speed#)
	Mouse_X_Speed#=MouseXSpeed()*0.5
	Mouse_Y_Speed#=MouseYSpeed()*0.5

	MoveMouse GraphicsWidth()/2,GraphicsHeight()/2
	Camera_Pitch=Camera_Pitch+Mouse_Y_Speed#
	Camera_Yaw=Camera_Yaw+Mouse_X_Speed#

	RotateEntity CamEntity,Camera_Pitch,-Camera_Yaw,0

	If KeyDown(203) Then
		Camera_VelX=Camera_VelX-Speed#
	ElseIf  KeyDown(205)
		Camera_VelX=Camera_VelX+Speed#
	EndIf
	
	If KeyDown(208) Then
		Camera_VelZ=Camera_VelZ-Speed#
	ElseIf  KeyDown(200)
		Camera_VelZ=Camera_VelZ+Speed#
	EndIf
 
	Camera_VelX=Camera_VelX/velocity#
	Camera_VelZ=Camera_VelZ/velocity#
	MoveEntity CamEntity,Camera_VelX,0,Camera_VelZ

	If KeyDown(200) Then
		MoveEntity CamEntity,0,0,Speed#
	EndIf

	If KeyDown(208) Then
		MoveEntity CamEntity,0,0,-Speed#
	EndIf

	If KeyDown(205) Then
		MoveEntity CamEntity,Speed#,0,0
	EndIf

	If KeyDown(203) Then
		MoveEntity CamEntity,-Speed#,0,0
	EndIf
End Function