Using Tok + Blitz Collision, will it work?

Blitz3D Forums/Blitz3D Programming/Using Tok + Blitz Collision, will it work?

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.

RaGr; You should take up story writing. That responce was extremly articulate. I love this part "OrcSlayer, this is one of those remarks when you as reader believe you are in a nightmare and not in a programmers forum..." LOL

Orcslayer: Ya once you get into Tokamak, it realy handles things nicely.
Here is a very basic example I did. It was my first thing in tokamak, realy just and expansion of one of the examples, and Bottbuilders code and comments on blitzcoder, and a hackjob of Marks camera in the castle demo. Sorry its kind of messy. Also in a real game I am working on, I am doing a FPS using censors, and is quite stable, and fast, and I use blitz collitions as a backup to tokamaks, and it works ok.

Const Rigid_Bodies=30,Animated_Bodies=1
TOKSIM_SetRigidBodiesCount Rigid_Bodies
TOKSIM_SetAnimatedBodiesCount Animated_Bodies
TOKSIM_SetRigidParticleCount 0
TOKSIM_SetControllersCount 0
TOKSIM_SetGeometriesCount Rigid_bodies+Animated_Bodies ;Assuming each one only has one geometry.  Not true with more complex rigid bodies and animated bodies.
TOKSIM_CreateSimulator(0,-10,0) ;sets the gravity that acts on rigid bodies

SeedRnd MilliSecs()

Graphics3D 800,600

Type ChaseCam
	Field entity,camera,target,heading,sky
End Type


Const fps=60
l=CreateLight()
PositionEntity l,10,20,0
;centerpoint=CreatePivot()
;Global cam=CreateCamera(centerpoint)
;PositionEntity cam,0,10,-50

 ;Setup The scene

ground=CreateCube()
EntityColor ground,5,5,55 
ScaleEntity ground,150,5,150 
PositionEntity ground,0,-5,0
;PointEntity l,centerpoint
;Now, we'll set up the animated body For the ground. In this Case, it never actually moves.
abground = TOKAB_Create();TOKAB_Create creates an animated body And returns its Handle.
TOKAB_AddBox(abground,300.0,10.0,300.0);TOKAB_AddBox adds a box To the animated body. 
;The parameters are AnimatedBody, Width, Height, Depth.
TOKAB_SetPosition(abground,0.0,-5.0,0.0);TOKAB_SetPosition sets the position of the animated body. 
;The parameters are AnimatedBody, X, Y, Z.
;Here is the rest of the animated bodies setup:  

;Next, we create a rigid box.************************************************************************
Dim obj(Rigid_Bodies)                      ;Create a rigid box                                    
Dim rb(Rigid_Bodies)                                                                              
                                                                                                   
For i=1 To Rigid_Bodies                                                                                               
                                                                                                   
obj(i) = CreateCube() 
EntityColor obj(i),200,0,0 
If i <= 1 Then 
	EntityColor obj(i),255,0,255 
EndIf                                                                           
ScaleEntity obj(i),2.0,2.0,2.0 ;                                                                         
rb(i) = TOKRB_Create() ;create rigid body                                                                           
TOKRB_AddBox rb(i),4.0,4.0,4.0 ;width*2,height*2,depth*2                                                                    
TOKRB_SetPosition rb(i),0,10+(i*3),0  ;x,y,z                                                                  
TOKRB_SetLinearDamping rb(i),0.004 ;0-to-1                                                               
TOKRB_SetAngularDamping rb(i),0.01;                                                                 	
TOKRB_SetMass rb(i),2.0                                                                           
TOKRB_SetBoxInertiaTensor rb(i),6.0,6.0,6.0,2.0 ;width*2,height*2,depth*2 
PositionEntity obj(i),TOKRB_GetX#(rb(i)),TOKRB_GetY#(rb(i)),TOKRB_GetZ#(rb(i)) 
Next                                                   
;****************************************************************************************************
CreateChaseCam.ChaseCam( obj(1) )


period=1000/FPS
time=MilliSecs()-period

imptime=MilliSecs()

While Not KeyHit(1)
 Repeat
  elapsed=MilliSecs()-time
 Until elapsed
	
 ticks=elapsed/period
 tween#=Float(elapsed Mod period)/Float(period)
 For k=1 To ticks
  time=time+period
  If k=ticks Then
   CaptureWorld
   

   For i=1 To Rigid_Bodies
	For c.ChaseCam=Each ChaseCam

		UpdateChaseCam( c )
	Next 

    PositionEntity obj(i),TOKRB_GetX#(rb(i)),TOKRB_GetY#(rb(i)),TOKRB_GetZ#(rb(i)) 
    RotateEntity obj(i),TOKRB_GetPitch#(rb(i)),TOKRB_GetYaw#(rb(i)),TOKRB_GetRoll#(rb(i)),False 

    If KeyDown(57) Then
     TOKRB_ApplyImpulse (rb(i),0,3,0)
	 ;TOKRB_ApplyImpulse2 rb(i),0,0,1,10,10,10


    EndIf
	
	
	If KeyDown(200) Then ;upkey
		TFormVector 0,0,.05,obj(1),0 
		TOKRB_ApplyImpulse (rb(1),TFormedX#(),TFormedY#(),TFormedZ#())

		

	EndIf
	 
	If KeyDown(208) Then ;downkey
		TFormVector 0,0,-.05,obj(1),0
		TOKRB_ApplyImpulse (rb(1),TFormedX#(),TFormedY#(),TFormedZ#())


	
	EndIf
	 
	If KeyDown(205) Then ;rightkey
		TFormVector 0,10,0,obj(1),0

	    TOKRB_ApplyTwist (rb(1),0,TFormedY#(),0)
		
		
	EndIf 
	
	If KeyDown(203) Then ;leftkey 
		TFormVector 0,-10,0,obj(1),0

	 	TOKRB_ApplyTwist (rb(1),0,TFormedY#(),0)

		

	EndIf 
	
	
	
	If KeyDown(45) Then ;xkeykey 
		TFormVector -6,0,0,obj(1),0

	 	TOKRB_ApplyTwist (rb(1),TFormedX#(),TFormedY#(),TFormedZ#())

		

	EndIf 
	
	If KeyDown(44) Then ;zkeykey 
		TFormVector 0,0,-6,obj(1),0

	 	TOKRB_ApplyTwist (rb(1),TFormedX#(),TFormedY#(),TFormedZ#())

		

	EndIf 

	
Next
   
  
	

  EndIf 
  TOKSIM_Advance(1.5/FPS,1)
  UpdateWorld
 Next
;For i=1 To Rigid_Bodies


 
 ;camx#=Cos(rot#)*50
 ;camz#=Sin(rot#)*50

 ;PositionEntity centerpoint,EntityX(obj(i)),EntityY(obj(i)),EntityZ(obj(i))
 ;rot#=rot#+MouseXSpeed()
;Next
  


 ;If rot#>360 Then rot#=0
 ;PositionEntity cam,camx#,10,camz#
 ;PointEntity cam,centerpoint

 
 RenderWorld tween
 Flip False
Wend

TOKSIM_DestroySimulator()
End

Function CreateChaseCam.ChaseCam( entity )
	c.ChaseCam=New ChaseCam
	c\entity=entity
	c\camera=CreateCamera()
	
	c\target=CreatePivot( entity )
	PositionEntity c\target,0,3,-10
	EntityType c\target,TYPE_TARGET
	
	c\heading=CreatePivot( entity )
	PositionEntity c\heading,0,0,20
	;c\sky=CopyEntity( sky )
	Return c
End Function

Function UpdateChaseCam( c.ChaseCam )

	;If KeyDown(200)
		;TranslateEntity c\heading,0,-3,0
	;Else If KeyDown(208)
		;TranslateEntity c\heading,0,+3,0
	;EndIf
	
	dx#=EntityX(c\target,True)-EntityX(c\camera,True)
	dy#=EntityY(c\target,True)-EntityY(c\camera,True)
	dz#=EntityZ(c\target,True)-EntityZ(c\camera,True)
	
	;TranslateEntity c\camera,dx*.01,dy*.01,(dz*.1)+speed*.01
	TranslateEntity c\camera,dx,dy,dz

	PointEntity c\camera,c\heading
		
	PositionEntity c\target,0,0,0
	ResetEntity c\target
	PositionEntity c\target,0,3,-20

	;PositionEntity c\sky,EntityX(c\camera),EntityY(c\camera),EntityZ(c\camera)
End Function