Node and Collision

Everything related to 3D programming
User avatar
Lexicon
User
User
Posts: 98
Joined: Mon Jul 22, 2013 6:16 am
Contact:

Node and Collision

Post by Lexicon »

Hello guys!

Please explain me how can I check the collision between node with attached camera and some entities? NodeCollision (or somethink like that) are not present. :(

Thanks
PureBasic 5.11 | WinXP | 2GB RAM | GForce GT240
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: Node and Collision

Post by Comtois »

You can use a hidden sphere with a body
Please correct my english
http://purebasic.developpez.com/
User avatar
Lexicon
User
User
Posts: 98
Joined: Mon Jul 22, 2013 6:16 am
Contact:

Re: Node and Collision

Post by Lexicon »

Comtois wrote:You can use a hidden sphere with a body
Thanks Comtois. But the sphere begins to roll on the ground. I'm exhausted by searching for a solution.
PureBasic 5.11 | WinXP | 2GB RAM | GForce GT240
User avatar
Lexicon
User
User
Posts: 98
Joined: Mon Jul 22, 2013 6:16 am
Contact:

Re: Node and Collision

Post by Lexicon »

Comtois wrote:You can use a hidden sphere with a body
Hm... I have to attach a sphere to the node or vice versa?
PureBasic 5.11 | WinXP | 2GB RAM | GForce GT240
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Re: Node and Collision

Post by Comtois »

here is an example, copy this code in Examples\3D

Code: Select all

IncludeFile "Screen3DRequester.pb"

#CameraSpeed = 2

#Sphere = 0
#Mesh = 1
#Line = #Mesh + 1
#Ground = 0
#Entity = 1
#Camera = 0

Define.f KeyX, KeyY, MouseX, MouseY, Speed1, Speed2, TimeSinceLastFrame, d = 0.4

If InitEngine3D(3)
 
 
  InitSprite()
  InitKeyboard()
  InitMouse()
 
  If Screen3DRequester()
   
    Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
    Add3DArchive("Data/Packs/skybox.zip", #PB_3DArchive_Zip)
    Parse3DScripts()
   
    WorldShadows(#PB_Shadow_Modulative, 100)
   
    CreateMaterial(0, LoadTexture(0, "Dirt.jpg"))
    CreateMaterial(1, LoadTexture(1, "DosCarte.png"))
    CreateMaterial(2, LoadTexture(2, "Wood.jpg"))
   
    CreateSphere(#Sphere, 0.06)
    CreateCube(#Mesh, 0.1)
   
    ;-Ground
    CreateEntity(#Ground,MeshID(#Mesh),MaterialID(0))
    ScaleEntity(#Ground, 150, 1, 150)
    EntityRenderMode(#Ground, 0)
    EntityPhysicBody(#Ground, #PB_Entity_BoxBody, 0, 0, 0.1)
   
    CreateEntity(#Entity, MeshID(#Sphere), MaterialID(1), 0, 0.2, 0)
   HideEntity(#Entity, 1)
    EntityPhysicBody(#Entity, #PB_Entity_SphereBody, 0.5, 0, 0.0)
   
    For i = 0 To 100
      If Random(100)>50
        Ent = CreateEntity(#PB_Any, MeshID(#Mesh), MaterialID(2), 7.5-Random(15), 0.5, 7.5-Random(15))
        EntityPhysicBody(Ent, #PB_Entity_BoxBody, 0.1, 0, 0.3)
      Else
        Ent = CreateEntity(#PB_Any, MeshID(#Mesh), MaterialID(0), 7.5-Random(15), 0.1, 7.5-Random(15))
        EntityPhysicBody(Ent, #PB_Entity_BoxBody, 0, 0, 0.3)
      EndIf
    Next
   
    SkyBox("stevecube.jpg")
   
    CreateCamera(#Camera, 0, 0, 100, 100)
    CameraRange(#Camera, 0.01, 50)
    CameraLookAt(#Camera, 0, 0, 1)     
    AttachEntityObject(#Entity, "", CameraID(#Camera))
   
    CreateLight(0, RGB(155, 155, 155), 330, 500, 330)
    AmbientColor(RGB(100, 100, 100))
   
    Repeat
      Screen3DEvents()
     
      If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.4
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.5
      EndIf
     
      Speed1 * 0.9
      Speed2 * 0.9
      If ExamineKeyboard()
       
        If KeyboardPushed(#PB_Key_Left)
          Speed2 = Speed2 + 0.1 * ((0.02 * TimeSinceLastFrame) - Speed2)
        ElseIf KeyboardPushed(#PB_Key_Right)
          Speed2 = Speed2 + 0.1 * ((-0.02 * TimeSinceLastFrame) - Speed2)
        EndIf
       
        If KeyboardPushed(#PB_Key_Up)
          Speed1 = Speed1 + 0.05 * ((0.03 * TimeSinceLastFrame) - Speed1)
        ElseIf KeyboardPushed(#PB_Key_Down)
          Speed1 = Speed1 + 0.05 * ((-0.03 * TimeSinceLastFrame) - Speed1)
        EndIf   
       
      EndIf
     
      RotateEntity(#Entity, 0, MouseX * TimeSinceLastFrame/100, 0, #PB_Relative)
      MoveEntity(#Entity, Speed2, 0, Speed1, #PB_Local)
   
      TimeSinceLastFrame = RenderWorld(50)
      Screen3DStats()
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
 
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf

End
Please correct my english
http://purebasic.developpez.com/
User avatar
Lexicon
User
User
Posts: 98
Joined: Mon Jul 22, 2013 6:16 am
Contact:

Re: Node and Collision

Post by Lexicon »

Thanks Comtois. I'll see...
PureBasic 5.11 | WinXP | 2GB RAM | GForce GT240
Post Reply