PB 5.00 : EntityLinearFactor () and PB_Entity_MaxVelocity

Everything related to 3D programming
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

PB 5.00 : EntityLinearFactor () and PB_Entity_MaxVelocity

Post by Comtois »

An example that shows how to use the commands:
SetEntityAttribute (Sphere, PB_Entity_MaxVelocity # 80) To limit the speed of the ball
EntityLinearFactor (Sphere, 0.7, 0, 0.7) for the ball remains on the board and is not shipped in the stars (the Y-axis is zero)

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Flipper
;
;    (c) 2011 - Fantaisie Software
;
; ------------------------------------------------------------
;

IncludeFile "Screen3DRequester.pb"

#PB_Entity_MaxVelocity = 10

#CameraSpeed = 1
#Nb = 30
Define.f KeyX, KeyY, MouseX, MouseY, Angle = 145
Dim Planche(#Nb)

If InitEngine3D()
  
  Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/Scripts",#PB_3DArchive_FileSystem)
  Add3DArchive("Data/Packs/desert.zip", #PB_3DArchive_Zip)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    
    WorldShadows(#PB_Shadow_Modulative)
    
    ;-Materials
    CreateMaterial(0, LoadTexture(0, "Wood.jpg"))
    GetScriptMaterial(1, "SphereMap/SphereMappedRustySteel")
    GetScriptMaterial(2, "Color/Blue")
    GetScriptMaterial(3, "Scene/GroundBlend")
    
    ;-Ground
    CreatePlane(0, 100, 100, 10, 10, 15, 15)
    CreateEntity(0,MeshID(0),MaterialID(3), 0, 0, 0)
    EntityRenderMode(0, 0) 
    EntityPhysicBody(0, #PB_Entity_BoxBody, 0, 0, 1)
    
    ;-Mesh
    CreateCube(1, 1.0)
    CreateSphere(2, 2, 30, 30)
    CreateCylinder(3, 2, 10)
    
    ;-Entity
    Sphere = CreateEntity(#PB_Any, MeshID(2), MaterialID(1), 21, 2.1, 0)
    EntityPhysicBody(Sphere, #PB_Entity_SphereBody, 0.5, 1, 1)
    EntityLinearFactor(Sphere, 0.7, 0, 0.7)
    
    ; Cadre
    BiaisD = CreateEntity(#PB_Any, MeshID(1), MaterialID(2), 20, 2, -40)
    ScaleEntity(BiaisD, 10, 4, 1)
    RotateEntity(BiaisD, 0, -45, 0)
    EntityPhysicBody(BiaisD, #PB_Entity_BoxBody, 0, 1, 1)
    Haut = CreateEntity(#PB_Any, MeshID(1), MaterialID(2), 0, 2, -45)
    ScaleEntity(Haut, 50, 4, 1)
    EntityPhysicBody(Haut, #PB_Entity_BoxBody, 0, 1, 1)
    Bas = CreateEntity(#PB_Any, MeshID(1), MaterialID(2), 0, 2, 45)
    ScaleEntity(Bas, 50, 4, 1)
    EntityPhysicBody(Bas, #PB_Entity_BoxBody, 0, 1.5, 1)
    Gauche = CreateEntity(#PB_Any, MeshID(1), MaterialID(2), -25, 2, 0)
    ScaleEntity(Gauche, 1, 4, 90)
    EntityPhysicBody(Gauche, #PB_Entity_BoxBody, 0, 1, 1)
    Droit = CreateEntity(#PB_Any, MeshID(1), MaterialID(2), 25, 2, 0)
    ScaleEntity(Droit, 1, 5, 90)
    EntityPhysicBody(Droit, #PB_Entity_BoxBody, 0, 1, 1)
    Couloir = CreateEntity(#PB_Any, MeshID(1), MaterialID(2), 17, 2, 10)
    ScaleEntity(Couloir, 1, 4, 70)
    EntityPhysicBody(Couloir, #PB_Entity_BoxBody, 0, 0.1, 1)
    
    ; Bumper
    Cylinder = CreateEntity(#PB_Any, MeshID(3), MaterialID(0), 0, 0, -16)
    EntityPhysicBody(Cylinder, #PB_Entity_CylinderBody, 0, 1.5, 1)  
    Cylinder = CreateEntity(#PB_Any, MeshID(3), MaterialID(0), 0, 0, 0)
    EntityPhysicBody(Cylinder, #PB_Entity_CylinderBody, 0, 1.5, 1)  
    Cylinder = CreateEntity(#PB_Any, MeshID(3), MaterialID(0), -8, 0, -8)
    EntityPhysicBody(Cylinder, #PB_Entity_CylinderBody, 0, 1.5, 1)  
    Cylinder = CreateEntity(#PB_Any, MeshID(3), MaterialID(0), 8, 0, -8)
    EntityPhysicBody(Cylinder, #PB_Entity_CylinderBody, 0, 1.5, 1)  
    Cylinder = CreateEntity(#PB_Any, MeshID(3), MaterialID(0), 0, 0, 32)
    EntityPhysicBody(Cylinder, #PB_Entity_CylinderBody, 0, 1.5, 1)     
    
    ;-Camera
    CreateCamera(0, 0, 0, 100, 100)
    CameraLocate(0, 0, 35, 70)
    CameraLookAt(0, 0, 0, 10)
    
    ;-Skybox
    SkyBox("desert07.jpg")
    
    ;-Light
    CreateLight(0, RGB(255, 255, 255), 100, 800, -500)
    AmbientColor(RGB(20, 20, 20))
    
    Repeat
      Screen3DEvents()
      
      If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
      EndIf
      
      If ExamineKeyboard()
        
        If KeyboardPushed(#PB_Key_Space)
          ApplyEntityImpulse(Sphere, 0, 0, -30)
        EndIf      
        If KeyboardPushed(#PB_Key_LeftShift)
          ApplyEntityImpulse(Sphere, 3, 0, 0)
        EndIf         
        If KeyboardPushed(#PB_Key_RightShift)
          ApplyEntityImpulse(Sphere, -3, 0, 0)
        EndIf   
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed
        Else
          KeyX = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed
        Else
          KeyY = 0
        EndIf
        
      EndIf
      
      ApplyEntityImpulse(Sphere, 0, 0, 0.3)
      SetEntityAttribute(Sphere, #PB_Entity_MaxVelocity, 80)
      MoveCamera  (0, KeyX, 0, KeyY)
      RotateCamera(0,  MouseY, MouseX, 0, #PB_Relative)
      RenderWorld()
      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/
Fred
Administrator
Administrator
Posts: 18384
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: PB 5.00 : EntityLinearFactor () and PB_Entity_MaxVelocit

Post by Fred »

Nice flipper :)
Post Reply