EasyTOK version 1.1

Blitz3D Forums/Blitz3D Programming/EasyTOK version 1.1

I'm sorry but what exactly your problem ????

I have post the method to know if your RBODY Collide with
ABODY ! What do you want more ?

In you previous example put :

TOK_EntityType("Floor",1)
TOK_EntityType("Toto2",2)
EntityRadius TOK_GetRBMesh ("Toto2"),5
Collisions 2,1,2,3

Instead :

TOK_EntityType("Floor",1)
TOK_EntityType("Toto2",2)
Collisions 1,2,2,3

And in debug mode you will know when Ball hit floor !

;=======================================================================================
; 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 800,600,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,20,-40

Proc_CreateVisor()

TOK_InitWorld(0,-40,0,1000,100)
TOK_CreateGround("Floor",150,255,150,10)
	TOK_ApplyMaterial("Floor",TOK_TypeAnimBody%,"Plastic")

; -----------------------------
; 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

Global Angle#

TOK_CreateRBSphere("Toto2",False,10,40,Rnd(-10,10),0,0,0,2,10,"",255,255,255,1,20)


TOK_EntityType("Floor",1)
TOK_EntityType("Toto2",2)
EntityRadius TOK_GetRBMesh ("Toto2"),5

Collisions 2,1,2,3



; -------------
; 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)
;	EndIf
	

	; ------------------------------------------
	; Apply impulse to ALL objects
	; ------------------------------------------
	If MouseHit(2) Then
		TOK_ApplyImpulse("",Rnd(-5,5),Rnd(255,265),Rnd(-5,5))
	EndIf


;	If MouseDown(1) Then
;		Proc_CameraPick(Cam)
;	EndIf

	count = CountCollisions (TOK_GetABMesh ("Floor"))

	If count>0 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

Function Proc_CameraPick(Camera)
	Local PEntity = 0 : CameraPick(Camera,GraphicsWidth()/2,GraphicsHeight()/2)
	PickedEntityID = PickedEntity()
	
	If PickedEntityID<>0

	DebugLog "pickeed"
		If TOK_IsRigidBody(PickedEntityID)=True Then
			Tmp_Name$=TOK_GetRBName$(PickedEntityID)
			
			TOK_EntityAlpha(Tmp_Name$,0.5)
			TOK_ApplyImpulse(Tmp_Name$,0,PickedNY#()*30,0)
			TOK_ApplyTwist(Tmp_Name$,0,60,0)
		EndIf 
	EndIf
End Function