Page 1 of 1

entity inside entity with SetEntityCollisionFilter

Posted: Sun Sep 14, 2014 6:25 pm
by Realizimo
I don't get it to work properly.
Am I doing something wrong with SetEntityCollisionFilter or anything else, perhaps it is a bug.
If #sc in row 36 changes to 15 or higher ,it works after a while for me.

Code: Select all

Declare OpenWindow_3D(c.i)
  If InitEngine3D()=0 : End : EndIf 
  InitSprite()
  InitKeyboard()
  InitMouse() 
IncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"
If Screen3DRequester()=0  : End : EndIf
EnableExplicit
Global.f change,height,dist,angle
Global.i Isw,w_frame,c_body,cha
Isw=Sign(IsWindow(0))
  
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures/", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Packs/desert.zip", #PB_3DArchive_Zip)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/GUI", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts", #PB_3DArchive_FileSystem)
Parse3DScripts()
;- -------------  Material  -----------------------------------------
GetScriptMaterial(2, "Color/Red")
CreateMaterial(6, LoadTexture(2, "MRAMOR6X6.jpg"))
;- -------------  Camera  -----------------------------------------
#camera =3
CreateCamera(#Camera, 0, 0, 100, 100)
;- -------------  Light  ---------------------------------------------
CreateLight(0, $FFFFFF, 1560, 900, 500)
AmbientColor($330000)
;- -------------  World  -------------------------------------------
WorldGravity(-50)
SkyBox("desert07.jpg")
OpenWindow_3D(13)
;- -------------  constants ---------------------------------------
#floor=0
#chassi=1
#axel=2

#sc=13.0     ;scale
#chassis_x  =#sc *13
#chassis_y  =#sc *2
#chassis_z  =#sc *21
#axle_x   =#sc *(11/2.0)
#axle_t   =#sc *3
#axle_pos =#sc *14
;- -------------  meshes  -----------------------------------------
CreateCube(1, 1)
;- -------------  entitys  -------------------------------------------
CreateEntity(#floor, MeshID(1), MaterialID(6),  0, -40, 0)
ScaleEntity( #floor, 1500, 0.5, 1500)
CreateEntity(#chassi , MeshID(1), MaterialID(2))
ScaleEntity( #chassi , #chassis_x , #chassis_y , #chassis_z ) ;chassis
CreateEntity(#axel, MeshID(1), MaterialID(6),-0.25-(#axle_x/2),0,-(#axle_pos/2))
ScaleEntity( #axel,#axle_x,#axle_t,#axle_t)
;- -------------  PhysicBody  -----------------------------------
EntityPhysicBody(#floor, #PB_Entity_StaticBody,0,0,4)
EntityPhysicBody(#chassi,#PB_Entity_BoxBody  ,1,1,0)
EntityPhysicBody(#axel, #PB_Entity_BoxBody,0.1,0,0)
;- -------------  CollisionFilter  ---------------------------------
SetEntityCollisionFilter(#chassi, 64 , 512 )     ; chassi
SetEntityCollisionFilter(#axel, 128 , 0 )        ; axel (unneeded)
SetEntityCollisionFilter(#floor, 512 , 64 | 256) ; floor
;- -------------  joints  ---------------------------------------------
HingeJoint(1,EntityID(#chassi),
           -0.1, 3, -(#axle_pos/2),
           0, 0, 1,
           EntityID(#axel),
           (#axle_x/2), 0, 0,
           0, 0, 1)
;- -------------  not sleep  ---------------------------------------
SetEntityAttribute(#chassi, #PB_Entity_LinearSleeping, 0)
SetEntityAttribute(#axel, #PB_Entity_LinearSleeping, 0)
;- -------------  Loop  ----------------------------------------------
  height = 25
  dist=   -315
Repeat
  If Isw And WindowEvent()=#PB_Event_CloseWindow:End:EndIf
  ExamineKeyboard()
  
  ;bumpers    
  EnableHingeJointAngularMotor(1, #True, 0, 100)
  HingeJointMotorTarget(1, -2, 0.1)
   
  If KeyboardReleased(#PB_Key_F1):w_frame+1:If w_frame = 3:w_frame=0:EndIf:CameraRenderMode(#camera,w_frame):EndIf
  If KeyboardReleased(#PB_Key_F2): c_body+1:If c_body = 4 :c_body=0 :EndIf:WorldDebug(c_body):EndIf

  cha=0
  If KeyboardPushed(#PB_Key_Pad4):cha=1:angle-change: EndIf
  If KeyboardPushed(#PB_Key_Pad6):cha=1:angle+change: EndIf
  If KeyboardPushed(#PB_Key_Pad7):cha=1:height+change:EndIf
  If KeyboardPushed(#PB_Key_Pad1):cha=1:height-change:EndIf
  If KeyboardPushed(#PB_Key_Pad8):cha=1:dist+change:EndIf
  If KeyboardPushed(#PB_Key_Pad2):cha=1:dist-change:EndIf
  If cha : change * 0.995+0.1 : Else : change=0 : EndIf
  CameraFollow(   #camera, EntityID(#chassi), angle, Height+EntityY(#chassi) , dist, 0.5, 0.5,1)

  SetGadgetText3D(1, " ch"+   #LF$+"  "+StrF(change,1))
  SetGadgetText3D(3, "cam"+   #LF$+StrF(angle,2)+   #LF$+StrF(height,2)+   #LF$+StrF(dist,2))
  SetGadgetText3D(8, "Speed  "+#LF$+StrF((GetEntityAttribute(#chassi, #PB_Entity_LinearVelocity)/12.6*4),1))
  SetGadgetText3D(10, "        x"+#LF$+"        y"+#LF$+"        z")
  SetGadgetText3D(11, Str(EntityX(#chassi))+#LF$+StrF(EntityY(#chassi),3)+#LF$+Str(EntityZ(#chassi)))
  SetGadgetText3D(13,Str(Engine3DStatus(#PB_Engine3D_CurrentFPS))+#LF$+Str(Engine3DStatus(#PB_Engine3D_NbRenderedTriangles))+#LF$+Str(Engine3DStatus(#PB_Engine3D_NbRenderedBatches)))
  
  RenderWorld()   
  FlipBuffers()
Until KeyboardReleased(#PB_Key_Escape) 

Procedure OpenWindow_3D(c)
  Protected.i a , b , sc_h
  sc_h=ScreenHeight()*0.12
    OpenWindow3D(1, 4, 3, ScreenWidth()-8, sc_h, "",#PB_Window3D_Borderless)
    ShowGUI(200, 0) 
    b=ScreenWidth()/((c+1)*1.03)
    For a=0 To c
    TextGadget3D(a, 10+a * b, 0, 152, sc_h, "")
  Next a
EndProcedure

Re: entity inside entity with SetEntityCollisionFilter

Posted: Mon Sep 15, 2014 9:39 am
by applePi
a nice code which have used several ideas from the physics engine
but i can't follow your complex dimensions and positions , the hinge joint needs to be positioned exactly or at least approx to work.
here is a simple dimensions and positions numbers, i draw the boxes on a paper then positioned the hinge point then measuring the distances of the hinge from the center of the big box and small box , like this
Image

note that the hinge Y relative coordinate are +3 from the big box center while it is -1 from the small box center.
also the bodies weights and the fraction, restitutions needs a care .
now press space key to lift the small box, press it again and it will return. i don't understand this point with "EnableHingeJointAngularMotor(1, #True, 10, 5)"
also i don't understand the
;HingeJointMotorTarget(#Joint, Angle, Velocity)
HingeJointMotorTarget(1, 18, 1)

if we choose 0 for the velocity the small box rotation will be speedier, if we choose 1 it will be slow, if we choose 2 it will be very slow
also the angle 18 it does not stop when the angle is 18, but somehow it works in the example "C:\PureBasic\Examples\3D\Demos\PinBall.pb" may be because it is horizontal and so it has friction there
regarding the SetEntityCollisionFilter , there is an example SetEntityCollisionFilter.pb in the PB examples, seems not necessary here, and i haven't studied it yet.
Realizimo code but modifying the boxes dimensionalities :

Code: Select all

Declare OpenWindow_3D(c.i)
  If InitEngine3D()=0 : End : EndIf 
  InitSprite()
  InitKeyboard()
  InitMouse() 
IncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"
If Screen3DRequester()=0  : End : EndIf
EnableExplicit
Global.f change,height,dist,angle
Global.i Isw,w_frame,c_body,cha
Isw=Sign(IsWindow(0))
  
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures/", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Packs/desert.zip", #PB_3DArchive_Zip)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/GUI", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts", #PB_3DArchive_FileSystem)
Parse3DScripts()
;- -------------  Material  -----------------------------------------
GetScriptMaterial(2, "Color/Red")
CreateMaterial(6, LoadTexture(2, "MRAMOR6X6.jpg"))
;- -------------  Camera  -----------------------------------------
#camera =3
CreateCamera(#Camera, 0, 0, 100, 100)


;- -------------  Light  ---------------------------------------------
CreateLight(0, $FFFFFF, 1560, 900, 500)
AmbientColor($330000)
;- -------------  World  -------------------------------------------
WorldGravity( -9.806 )
SkyBox("desert07.jpg")
OpenWindow_3D(13)
;- -------------  constants ---------------------------------------
#floor=0
#chassi=1
#axel=2


;- -------------  meshes  -----------------------------------------
CreateCube(1, 1)
;- -------------  entitys  -------------------------------------------
CreateEntity(#floor, MeshID(1), MaterialID(6),  0, -20, 0)
ScaleEntity( #floor, 100, 0.5, 100)
CreateEntity(#chassi , MeshID(1), MaterialID(2))
ScaleEntity( #chassi , 20 , 6 , 20 ) ;chassis
CreateEntity(#axel, MeshID(1), MaterialID(6),5,7,10)
ScaleEntity( #axel,10,2,10)
;- -------------  PhysicBody  -----------------------------------
EntityPhysicBody(#floor, #PB_Entity_StaticBody,0,0,4)
EntityPhysicBody(#chassi,#PB_Entity_BoxBody  ,20, 1, 1)
EntityPhysicBody(#axel, #PB_Entity_BoxBody,1, 0.1, 1)
;EntityPhysicBody(#Entity, Type [, Mass [, Restitution, Friction]])

;- -------------  CollisionFilter  ---------------------------------
;SetEntityCollisionFilter(#chassi, 64 , 512 )     ; chassi
;SetEntityCollisionFilter(#axel, 128 , 0 )        ; axel (unneeded)
;SetEntityCollisionFilter(#floor, 512 , 64 | 256) ; floor
;- -------------  joints  ---------------------------------------------
HingeJoint(1,EntityID(#chassi),
           10, 3, 0,
           0, 0, 1,
           EntityID(#axel),
           5, -1, 0,
           0, 0, 1)
;- -------------  not sleep  ---------------------------------------
SetEntityAttribute(#chassi, #PB_Entity_LinearSleeping, 0)
SetEntityAttribute(#axel, #PB_Entity_LinearSleeping, 0)
;- -------------  Loop  ----------------------------------------------
  height = 25
  dist=   50
Repeat
  If Isw And WindowEvent()=#PB_Event_CloseWindow:End:EndIf
  ExamineKeyboard()
  
  ;bumpers    

If KeyboardReleased(#PB_Key_Space) ; to lift the small box
       ;ApplyEntityImpulse(#axel,  0, 4, 0,  6,0,0) ; apply force up
       ;EnableHingeJointAngularMotor(#Joint, Enable, TargetVelocity, MaxMotorImpulse)
       EnableHingeJointAngularMotor(1, #True, 10, 5)
       DisableEntityBody(#axel, 0)
       HingeJointMotorTarget(1, 18, 1)
       ;HingeJointMotorTarget(#Joint, Angle, Velocity)

       
      
EndIf 
  
   
  If KeyboardReleased(#PB_Key_F1):w_frame+1:If w_frame = 3:w_frame=0:EndIf:CameraRenderMode(#camera,w_frame):EndIf
  If KeyboardReleased(#PB_Key_F2): c_body+1:If c_body = 4 :c_body=0 :EndIf:WorldDebug(c_body):EndIf

  cha=0
  If KeyboardPushed(#PB_Key_Pad4):cha=1:angle-change: EndIf
  If KeyboardPushed(#PB_Key_Pad6):cha=1:angle+change: EndIf
  If KeyboardPushed(#PB_Key_Pad7):cha=1:height+change:EndIf
  If KeyboardPushed(#PB_Key_Pad1):cha=1:height-change:EndIf
  If KeyboardPushed(#PB_Key_Pad8):cha=1:dist+change:EndIf
  If KeyboardPushed(#PB_Key_Pad2):cha=1:dist-change:EndIf
  If cha : change * 0.995+0.1 : Else : change=0 : EndIf
  
     
  CameraFollow(   #camera, EntityID(#chassi), angle, Height+EntityY(#chassi) , dist, 0.5, 0.5,1)

  SetGadgetText3D(1, " ch"+   #LF$+"  "+StrF(change,1))
  SetGadgetText3D(3, "cam"+   #LF$+StrF(angle,2)+   #LF$+StrF(height,2)+   #LF$+StrF(dist,2))
  SetGadgetText3D(8, "Speed  "+#LF$+StrF((GetEntityAttribute(#chassi, #PB_Entity_LinearVelocity)/12.6*4),1))
  SetGadgetText3D(10, "        x"+#LF$+"        y"+#LF$+"        z")
  SetGadgetText3D(11, Str(EntityX(#chassi))+#LF$+StrF(EntityY(#chassi),3)+#LF$+Str(EntityZ(#chassi)))
  SetGadgetText3D(13,Str(Engine3DStatus(#PB_Engine3D_CurrentFPS))+#LF$+Str(Engine3DStatus(#PB_Engine3D_NbRenderedTriangles))+#LF$+Str(Engine3DStatus(#PB_Engine3D_NbRenderedBatches)))
  
  RenderWorld()   
  FlipBuffers()
Until KeyboardReleased(#PB_Key_Escape) 

Procedure OpenWindow_3D(c)
  Protected.i a , b , sc_h
  sc_h=ScreenHeight()*0.12
    OpenWindow3D(1, 4, 3, ScreenWidth()-8, sc_h, "",#PB_Window3D_Borderless)
    ShowGUI(200, 0) 
    b=ScreenWidth()/((c+1)*1.03)
    For a=0 To c
    TextGadget3D(a, 10+a * b, 0, 152, sc_h, "")
  Next a
EndProcedure
PS: there is a beautiful demo robot arm here:
http://www.purebasic.fr/french/viewtopi ... 13&t=13671
which have used HingeJointMotorTarget and other motor functions.

PS2: look my example here http://www.purebasic.fr/english/viewtop ... 36&t=54556
i have noted but forget completely that target velocity in the function EnableHingeJointAngularMotor(...) are in radians per second and not Revolutions per minute
http://en.wikipedia.org/wiki/Radian_per_second

Re: entity inside entity with SetEntityCollisionFilter

Posted: Mon Sep 15, 2014 3:24 pm
by applePi
now it seems to work, the slop (the small box) will rotate until it reaches 25 degree using
HingeJointMotorTarget(1, 25, 1) in the main loop
now press space and it will continue to 45 degree, using HingeJointMotorTarget(1, 45, 1) inside the condition. i changed the KeyboardReleased to KeyboardPushed .
release the space key and it will return to 25. and thats good. and have a million of possible uses.

Code: Select all

Declare OpenWindow_3D(c.i)
  If InitEngine3D()=0 : End : EndIf 
  InitSprite()
  InitKeyboard()
  InitMouse() 
IncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"
If Screen3DRequester()=0  : End : EndIf
EnableExplicit
Global.f change,height,dist,angle
Global.i Isw,w_frame,c_body,cha
Isw=Sign(IsWindow(0))
  
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures/", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Packs/desert.zip", #PB_3DArchive_Zip)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/GUI", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts", #PB_3DArchive_FileSystem)
Parse3DScripts()
;- -------------  Material  -----------------------------------------
GetScriptMaterial(2, "Color/Red")
CreateMaterial(6, LoadTexture(2, "MRAMOR6X6.jpg"))
;- -------------  Camera  -----------------------------------------
#camera =3
CreateCamera(#Camera, 0, 0, 100, 100)


;- -------------  Light  ---------------------------------------------
CreateLight(0, $FFFFFF, 1560, 900, 500)
AmbientColor($330000)
;- -------------  World  -------------------------------------------
WorldGravity( -9.806 )
SkyBox("desert07.jpg")
OpenWindow_3D(13)
;- -------------  constants ---------------------------------------
#floor=0
#chassi=1
#axel=2


;- -------------  meshes  -----------------------------------------
CreateCube(1, 1)
;- -------------  entitys  -------------------------------------------
CreateEntity(#floor, MeshID(1), MaterialID(6),  0, -20, 0)
ScaleEntity( #floor, 100, 0.5, 100)
CreateEntity(#chassi , MeshID(1), MaterialID(2))
ScaleEntity( #chassi , 20 , 6 , 20 ) ;chassis
CreateEntity(#axel, MeshID(1), MaterialID(6),5,7,10)
ScaleEntity( #axel,10,2,10)
;- -------------  PhysicBody  -----------------------------------
EntityPhysicBody(#floor, #PB_Entity_StaticBody,0,0,4)
EntityPhysicBody(#chassi,#PB_Entity_BoxBody  ,20, 1, 1)
EntityPhysicBody(#axel, #PB_Entity_BoxBody,1, 0.1, 1)
;EntityPhysicBody(#Entity, Type [, Mass [, Restitution, Friction]])

;- -------------  CollisionFilter  ---------------------------------
;SetEntityCollisionFilter(#chassi, 64 , 512 )     ; chassi
;SetEntityCollisionFilter(#axel, 128 , 0 )        ; axel (unneeded)
;SetEntityCollisionFilter(#floor, 512 , 64 | 256) ; floor
;- -------------  joints  ---------------------------------------------
HingeJoint(1,EntityID(#chassi),
           10, 3, 0,
           0, 0, 1,
           EntityID(#axel),
           5, -1, 0,
           0, 0, 1)
;- -------------  not sleep  ---------------------------------------
SetEntityAttribute(#chassi, #PB_Entity_LinearSleeping, 0)
SetEntityAttribute(#axel, #PB_Entity_LinearSleeping, 0)
;- -------------  Loop  ----------------------------------------------
  height = 25
  dist=   50
Repeat
  If Isw And WindowEvent()=#PB_Event_CloseWindow:End:EndIf
  ExamineKeyboard()
  EnableHingeJointAngularMotor(1, #True, 2, 5)
  DisableEntityBody(#axel, 0)
  HingeJointMotorTarget(1, 25, 1) 
   

If KeyboardPushed(#PB_Key_Space) ; to lift the small box
       ;ApplyEntityImpulse(#axel,  0, 4, 0,  6,0,0) ; apply force up
       ;EnableHingeJointAngularMotor(#Joint, Enable, TargetVelocity, MaxMotorImpulse)
       EnableHingeJointAngularMotor(1, #True, 2, 5)
       DisableEntityBody(#axel, 0)
       HingeJointMotorTarget(1, 45, 1)
       ;HingeJointMotorTarget(#Joint, Angle, Velocity)

       
      
EndIf 
  
   
  If KeyboardReleased(#PB_Key_F1):w_frame+1:If w_frame = 3:w_frame=0:EndIf:CameraRenderMode(#camera,w_frame):EndIf
  If KeyboardReleased(#PB_Key_F2): c_body+1:If c_body = 4 :c_body=0 :EndIf:WorldDebug(c_body):EndIf

  cha=0
  If KeyboardPushed(#PB_Key_Pad4):cha=1:angle-change: EndIf
  If KeyboardPushed(#PB_Key_Pad6):cha=1:angle+change: EndIf
  If KeyboardPushed(#PB_Key_Pad7):cha=1:height+change:EndIf
  If KeyboardPushed(#PB_Key_Pad1):cha=1:height-change:EndIf
  If KeyboardPushed(#PB_Key_Pad8):cha=1:dist+change:EndIf
  If KeyboardPushed(#PB_Key_Pad2):cha=1:dist-change:EndIf
  If cha : change * 0.995+0.1 : Else : change=0 : EndIf
  
     
  CameraFollow(   #camera, EntityID(#chassi), angle, Height+EntityY(#chassi) , dist, 0.5, 0.5,1)

  SetGadgetText3D(1, " ch"+   #LF$+"  "+StrF(change,1))
  SetGadgetText3D(3, "cam"+   #LF$+StrF(angle,2)+   #LF$+StrF(height,2)+   #LF$+StrF(dist,2))
  SetGadgetText3D(8, "Speed  "+#LF$+StrF((GetEntityAttribute(#chassi, #PB_Entity_LinearVelocity)/12.6*4),1))
  SetGadgetText3D(10, "        x"+#LF$+"        y"+#LF$+"        z")
  SetGadgetText3D(11, Str(EntityX(#chassi))+#LF$+StrF(EntityY(#chassi),3)+#LF$+Str(EntityZ(#chassi)))
  SetGadgetText3D(13,Str(Engine3DStatus(#PB_Engine3D_CurrentFPS))+#LF$+Str(Engine3DStatus(#PB_Engine3D_NbRenderedTriangles))+#LF$+Str(Engine3DStatus(#PB_Engine3D_NbRenderedBatches)))
  
  RenderWorld()   
  FlipBuffers()
Until KeyboardReleased(#PB_Key_Escape) 

Procedure OpenWindow_3D(c)
  Protected.i a , b , sc_h
  sc_h=ScreenHeight()*0.12
    OpenWindow3D(1, 4, 3, ScreenWidth()-8, sc_h, "",#PB_Window3D_Borderless)
    ShowGUI(200, 0) 
    b=ScreenWidth()/((c+1)*1.03)
    For a=0 To c
    TextGadget3D(a, 10+a * b, 0, 152, sc_h, "")
  Next a
EndProcedure

Re: entity inside entity with SetEntityCollisionFilter

Posted: Mon Sep 15, 2014 5:03 pm
by Realizimo
thanks applePi for your interest , but
It is the SetEntityCollisionFilter i working with.(what the title says)
If you change the #sc (scal) to 15 or higer (row 36) you can see how it should work i hope.
I have another exampel there everything works perfect, i dont know why one works one does not work
pageup/pagedown will make it rotate
(sorry for my bad english I use Google Translate)

Code: Select all

  If InitEngine3D()=0 : End : EndIf 
  InitSprite()
  InitKeyboard()
  InitMouse() 
IncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"
If Screen3DRequester()=0  : End : EndIf
EnableExplicit
  
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures/", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Packs/desert.zip", #PB_3DArchive_Zip)
;Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/GUI", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts", #PB_3DArchive_FileSystem)
Parse3DScripts()
;- -------------  Material  -----------------------------------------
  CreateMaterial(0, LoadTexture(0, "Dirt.jpg"))
  CreateMaterial(1, LoadTexture(1, "Wood.jpg"))
;- -------------  Camera  -----------------------------------------
  #camera =0
  CreateCamera(#Camera, 0, 0, 100, 100)
  MoveCamera(#camera, 0, 12, 15, #PB_Absolute)
;- -------------  Light  ---------------------------------------------
  CreateLight(0, $FFFFFF, 1560, 900, 500)
  AmbientColor($330000)
;- -------------  World  -------------------------------------------
  WorldGravity(0)
  SkyBox("desert07.jpg")
;- -------------  meshes  -----------------------------------------
  CreateCube(0, 1.0)
;- -------------  entitys  -------------------------------------------
  CreateEntity(0, MeshID(0), MaterialID(0), 0, 0, 0)
  ScaleEntity(0, 2, 4, 0.5)
  CreateEntity(1, MeshID(0), MaterialID(1), 3, 0, 0)
  ScaleEntity(1, 2, 4, 0.5)     
;- -------------  PhysicBody  -----------------------------------
  EntityPhysicBody(0, #PB_Entity_BoxBody, 1.0)
  EntityPhysicBody(1, #PB_Entity_BoxBody, 1.0)    
;- -------------  CollisionFilter  ---------------------------------
  SetEntityCollisionFilter(0      , 128 , 0 ) 
  SetEntityCollisionFilter(1      , 128 , 0 )       
;- -------------  joints  ---------------------------------------------
  HingeJoint(0, EntityID(0),
             0, 0, 0,
             1, 0, 0, 
             EntityID(1),
             0, 0, 0, 
             0, 0, 1)
  SetJointAttribute(0, #PB_HingeJoint_LowerLimit, 0)    
;- -------------  not sleep  ---------------------------------------
  SetEntityAttribute(0, #PB_Entity_LinearSleeping, 0)
  SetEntityAttribute(1, #PB_Entity_LinearSleeping, 0)  
;- -------------  Loop  ----------------------------------------------
#CameraSpeed = 0.3
Define.f KeyX, KeyY, MouseX, MouseY

Repeat
  Screen3DEvents()
  
  If ExamineMouse()
    MouseX = MouseDeltaX() * #CameraSpeed * 0.05
    MouseY = MouseDeltaY() * #CameraSpeed * 0.05
  EndIf
  
  If ExamineKeyboard()    
    If KeyboardPushed(#PB_Key_PageUp): EnableHingeJointAngularMotor(0,1,-1,2): EndIf
    If KeyboardPushed(#PB_Key_PageDown): EnableHingeJointAngularMotor(0,1,1,2): EndIf    
    If KeyboardPushed(#PB_Key_Up)
      KeyY = #CameraSpeed 
    ElseIf KeyboardPushed(#PB_Key_Down)
      KeyY = -#CameraSpeed 
    Else
      KeyY = 0
    EndIf    
  EndIf

  MoveCamera  (#camera, MouseX, KeyY,MouseY)
  CameraLookAt(#camera, 0,0,0)
  
  RenderWorld()
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)

Re: entity inside entity with SetEntityCollisionFilter

Posted: Mon Sep 15, 2014 7:21 pm
by applePi
Hi Realizimo
if what you want to do in the first example is what you have done in the second example, ie the small box rotated inside the big box (even it is prohibited physically) then change lines 54-55 to
EntityPhysicBody(#chassi,#PB_Entity_BoxBody ,100,1,1)
EntityPhysicBody(#axel, #PB_Entity_BoxBody,1, 0.1, 1)

the #chassi needs to be much heavier to stay on the ground, so the #axel can rotate inside the #chassi. i never seen this before since the bodies have a dynamic physics and not static physics. so this may be interesting to make some strange devices .
i hope this is what you want since in the first example after changing the #sc=15 i have waited 2 minutes and the axel stay static as it is over the chassi, it is the whole structure which are rotated , and not someone inside the other like your example 2
the above test are done with v5.30 and v5.31 beta1

Re: entity inside entity with SetEntityCollisionFilter

Posted: Tue Sep 16, 2014 5:26 pm
by Realizimo
Wait max 20 seconds else try with another (higher) #sc value. #sc will only resize, but somehow it also change the physics (maybe just for me).
#axel should lie parallel inside the chassis when it is right(not stick up)

Re: entity inside entity with SetEntityCollisionFilter

Posted: Tue Sep 16, 2014 5:36 pm
by Realizimo
Hi again applePi
For me the #axel flutter, not static.
Has it ever fluttered to you?

Re: entity inside entity with SetEntityCollisionFilter

Posted: Wed Sep 17, 2014 10:35 am
by applePi
Hi Realizimo
it is fluttering, i mean by static : as a whole the small box stay standing on top of the big box without rotation.
i think it is wrong to try to make dynamic entities inside each other , since the physics engine are designed to mimic approximately the real world, and may be the developer will prohibit that in the future. why this example work while the other not , because doing illegal structures will make the engine do unexpected results. in this case the 2 boxes will lose the physics and can't do collisions any more and will go through the floor as if there is no floor , so what is the benefits of forcing entity inside the other ?. it is certainly a bug in the physics engine to allow that.

Re: entity inside entity with SetEntityCollisionFilter

Posted: Wed Sep 17, 2014 6:03 pm
by Realizimo
HI applePi
"so what is the benefits of forcing entity inside the other ?"
I'm trying to make a car in a simple way with the suspension, I have done it without SetEntityCollisionFilter before, but I think it will be better if the Entity's overlap.
SetEntityCollisionFilter is made for overlapping, I think

Re: entity inside entity with SetEntityCollisionFilter

Posted: Tue Oct 21, 2014 6:18 pm
by Realizimo
Best Comtois
Do you have something to say about SetEntityCollisionFilter, will it ever work as I want?

Re: entity inside entity with SetEntityCollisionFilter

Posted: Thu Oct 23, 2014 1:01 pm
by Comtois
SetEntityCollisionFilter () allows you to filter collisions, but does not cancel the constraint (HingeJoint). There is a flag for disabling contact response, I will give it a try.