Re: Probleme Collision 3D
Publié : lun. 24/juin/2013 17:26
Bonjour,
Je vais en avoir des code a analyser pour la 3D, Merci.
Cordialement,
GallyHC
Je vais en avoir des code a analyser pour la 3D, Merci.
Cordialement,
GallyHC
Code : Tout sélectionner
;Ville automatique 3D
; By spock
Enumeration
#Camera
#Entity
#mesh
#material
#texture
;
#sol
#Entity_sol
#material_sol
;
#Mesh_tour
#entity_tour
#material_tour
#texture_tour
EndEnumeration
#CameraSpeed = 20
IncludeFile "Screen3DRequester.pb"
Define.f KeyX, Keyz, MouseX, MouseY
Declare.s ParseDirectory(folder.s, id.l = 0)
Declare Create_batiment(x,y,taille_x,taille_y,taille_h)
Global x=-800
Global y=-800
Global NewList list_objet(), coll,entity_c_obj,Entity_sol
If InitEngine3D()
Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive("Data/Models", #PB_3DArchive_FileSystem)
InitSprite()
InitKeyboard()
InitMouse()
EnableWorldPhysics(#True)
WorldDebug(#PB_World_DebugBody)
If Screen3DRequester()
AmbientColor(RGB(255, 255, 255))
;{ ***************** les Creations d'objets **********************************
; ******* le Sol **************************************
;-creation Sol
CreateMaterial(#material_sol, LoadTexture(#texture, "grass.jpg"))
CreatePlane(#sol, 1600,1600,100,100,100, 100)
Entity_sol=CreateEntity(#PB_Any, MeshID(#sol), MaterialID(#material_sol))
MoveEntity(Entity_sol,0,0,0)
EntityPhysicBody(Entity_sol, #PB_Entity_StaticBody,999,0,0.2)
; *****************************************************
;
; *********** la camera **********************************
;-creation Camera
CreateCamera(#Camera, 0, 0, 100, 100) ; Front camera
CameraBackColor(#Camera , RGB(120, 120, 255))
;Creation de l'objet camera .. (pour collision )
c_obj=CreateCube(#PB_Any,5)
entity_c_obj=CreateEntity(#PB_Any,MeshID(c_obj), MaterialID(#material_sol),0,2.5,25)
MoveCamera(#Camera , 0, 2.5, 25, #PB_Absolute)
AttachEntityObject(entity_c_obj, "", CameraID(#Camera))
EntityPhysicBody(entity_c_obj, #PB_Entity_BoxBody,0.1,0,0)
; *********************************************************
; *************** matiere des batiments ********************************²
;-creation batiments
CreateMaterial(#material_tour, LoadTexture(#texture_tour, "wall.jpg"))
; **************************************************************
; ************* Creation des Batiments *******************
nombre_de_batiments=300
For i = 1 To nombre_de_batiments
Taille_x=Random(10,2)/10.0
Taille_y=Random(10,2)/10.0
Taille_h=Random(800,5)/10.0
x=-800+Random(1600,Taille_x)
y=-800+Random(1600,Taille_y)
Create_batiment(x,y,taille_x,taille_y,taille_h)
Next
; ****************************************************
;}
Repeat
;-debut boucle principale
Screen3DEvents()
; *********** les controles ***************************************************
;-les controles
If ExamineMouse()
MouseX = -MouseDeltaX() * #CameraSpeed * 0.01
MouseY = -MouseDeltaY() * #CameraSpeed * 0.01
EndIf
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
KeyX = -#CameraSpeed
xc=keyx
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = #CameraSpeed
xc=keyx
Else
KeyX = 0
xc=0
EndIf
If KeyboardPushed(#PB_Key_Up)
Keyz = -#CameraSpeed
zc=keyz
ElseIf KeyboardPushed(#PB_Key_Down)
Keyz = #CameraSpeed
zc=keyz
Else
Keyz = 0
zc=0
EndIf
EndIf
; ***********************************************************
; *************** Test des collisions ****************************************
;- test des collisions
ForEach list_objet()
coll=EntityCollide(entity_c_obj,list_objet())
If coll<>0
ClearDebugOutput()
Debug "Collision avec l'objet " + Str(list_objet())
Break
EndIf
Next list_objet()
; *************************************************************************
; ******************** deplacements et affichage ****************************************
;- deplacements et affichage
; On ne touche qu'au cube. Comme la caméra y est attachée, elle suivra.
RotateEntity(entity_c_obj,0, MouseX, 0, #PB_Relative )
MoveEntity (entity_c_obj, KeyX,0, Keyz,#PB_Local )
RenderWorld()
Screen3DStats()
FlipBuffers()
; *************************************************************************************
;-Fin Boucle principale
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
EndIf
Else
MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
End
;- ******* Zone Procedures *************************************
Procedure Create_batiment(x,y,taille_x,taille_y,taille_h)
; *************** les batiments *************************************
type=Random(3,1)
Select Type
Case 1 ; les tours
id=CreateCylinder(#PB_Any, taille_x*10,taille_h*4)
entity=CreateEntity(#PB_Any,MeshID(id), MaterialID(#material_tour))
MoveEntity(entity,x,(taille_h*4)/2,y)
RotateEntity(Entity,0, 0, 0 )
Case 2 ; les immeubles
id=CreateCube(#PB_Any, taille_h)
entity=CreateEntity(#PB_Any,MeshID(id), MaterialID(#material_tour))
MoveEntity(entity,x,taille_h/2,y)
RotateEntity(Entity, 0, Random(359,0)/4, 0 )
Case 3 ; les immeubles aussi
id= CreateCube(#PB_Any, taille_h)
entity=CreateEntity(#PB_Any,MeshID(id), MaterialID(#material_tour))
MoveEntity(entity,x,taille_h/2,y)
RotateEntity(Entity,0, Random(359,0)/4, 0 )
EndSelect
EntityPhysicBody(entity, #PB_Entity_StaticBody,1,1,1)
AddElement(list_objet())
list_objet()=entity
; *************************************************************
EndProcedure
Code : Tout sélectionner
IncludeFile "Screen3DRequester.pb"
Non, tu as pris des mauvaises habitudes ,par exemple appeler un terrain "matrix" & fournir un lot de commande sur les matrix3 était une énorme confusion pour moi qui débutait la programmation.Spock a écrit : plus serieusement , grace au Darkbasic d'ou je venais avant de polluer tes forums
j'ai acquis quelques notions de 3D , c'est pourquoi je me permet les comparaisons de "facilité" de codage
Merci