problème de placement des objets et de leurs corps

Généralités sur la programmation 3D
Avatar de l’utilisateur
graph100
Messages : 1318
Inscription : sam. 21/mai/2005 17:50

problème de placement des objets et de leurs corps

Message par graph100 »

Dans le code suivant il se passe des trucs un peu bizarre :

- le bloc bleu et l'assemblage vert sautent en l'air... pourquoi ?
- l'assemblage orange a l'air de réagir correctement : il se pose sur le sol
- le bloc rouge ignore les autres... Il leurs passe au travers et va se poser sur rien un peu plus bas !

je suis dépassé là :x

Code : Tout sélectionner

;
; ------------------------------------------------------------
;
;   PureBasic - Static Geometry
;
;    (c) 2012 - Fantaisie Software
;
; ------------------------------------------------------------
;


Define.f KeyX, KeyY, MouseX, MouseY
Define Boost.f = 25, Yaw.f, Pitch.f



;{ initialisation de la 3D

IncludeFile "Screen3DRequester.pb"

If InitEngine3D() = 0
	MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf

InitSprite()
InitKeyboard()
InitMouse()

If Screen3DRequester() = 0 : End : EndIf

WorldShadows(#PB_Shadow_Additive)

AmbientColor(0)
KeyboardMode(1)

;}


;{ lumière
; node for Light and Billboard (Sun)
CreateNode(0, 0, 0, 0)

;Create light
CreateLight(0, RGB(110, 135, 142), 0, 0, 0)
AttachNodeObject(0, LightID(0))

LightAttenuation(0, 100000, 0)
;}


;{ Static geometry, un plancher et un mur
;

; Create Entity
CreateCube(0, 1)

CreateTexture(0, 1, 1)
CreateTexture(1, 1, 1)

StartDrawing(TextureOutput(1))
	Box(0, 0, 1, 1, #White)
StopDrawing()

CreateMaterial(0, TextureID(0))
CreateMaterial(1, TextureID(1))

CreateEntity(0, MeshID(0), MaterialID(0))
CreateEntity(1, MeshID(0), MaterialID(1))
CreateEntity(2, MeshID(0), #PB_Material_None)

; Create Static geometry
CreateStaticGeometry(0, 1000, 1000, 1000, #True)

; entity = 1
; For z = -10 To 10
; 	For x = -10 To 10
; 		; Dallage du sol pour une meilleur ombre
; 		AddStaticGeometryEntity(0, EntityID(entity), x * 1000, -5, z * 1000, 1000,  10, 1000, 0, 0, 0)        
; 		
; 		entity = (1 - entity)
; 	Next
; Next

; construction des murs
For i = -10 To 10
	For j = 0 To 2
		AddStaticGeometryEntity(0, EntityID(2), i * 1000, j * 1000 + 500 - 100, 10000 + 500, 1000, 1000, 10, 0, 0, 0)
		AddStaticGeometryEntity(0, EntityID(2), -i * 1000, j * 1000 + 500 - 100, -10000 - 500, 1000, 1000, 10, 0, 0, 0)
		
		AddStaticGeometryEntity(0, EntityID(2), 10000 + 500, j * 1000 + 500 - 100, i * 1000, 10, 1000, 1000, 0, 0, 0)
		AddStaticGeometryEntity(0, EntityID(2), -10000 - 500, j * 1000 + 500 - 100, -i * 1000, 10, 1000, 1000, 0, 0, 0)
	Next
Next


; Build the static geometry
BuildStaticGeometry(0)

FreeEntity(#PB_All)
FreeMesh(#PB_All)




text_plan = CreateTexture(#PB_Any, 200, 200)
StartDrawing(TextureOutput(text_plan))
	Box(0, 0, 100, 100, #White)
	Box(100, 100, 100, 100, #White)
StopDrawing()
mat_plan = CreateMaterial(#PB_Any, TextureID(text_plan))

mesh_plan = CreatePlane(#PB_Any, 21000, 21000, 20, 20, 10, 10)
entity_plan = CreateEntity(#PB_Any, MeshID(mesh_plan), MaterialID(mat_plan), 0, -50, 0)
EntityRenderMode(entity_plan, 0) 
EntityPhysicBody(entity_plan, #PB_Entity_BoxBody, 0, 1, 1)



;}


;{ construction du robot


;{ structure et macro

Structure sub_entity
	mesh.l
	entity.l
EndStructure

Structure entity
	entity.l
	texture.l
	material.l
	
	List submesh.sub_entity()
EndStructure


Structure Bras_Robot
	base.entity
	pivot.entity
	bras.entity
	avant_bras.entity
EndStructure

Macro AddMesh_to_robot(_mesh, liste)
	AddElement(liste) : liste\mesh = _mesh
EndMacro

;}

robot.Bras_Robot

;{ textures
robot\base\texture = CreateTexture(#PB_Any, 1, 1)
StartDrawing(TextureOutput(robot\base\texture))
	Box(0, 0, 1, 1, #Blue)
StopDrawing()

robot\pivot\texture = CreateTexture(#PB_Any, 1, 1)
StartDrawing(TextureOutput(robot\pivot\texture))
	Box(0, 0, 1, 1, #Green)
StopDrawing()

robot\bras\texture = CreateTexture(#PB_Any, 1, 1)
StartDrawing(TextureOutput(robot\bras\texture))
	Box(0, 0, 1, 1, #Red)
StopDrawing()

robot\avant_bras\texture = CreateTexture(#PB_Any, 1, 1)
StartDrawing(TextureOutput(robot\avant_bras\texture))
	Box(0, 0, 1, 1, RGB(255, 127, 0))
StopDrawing()

robot\base\material = CreateMaterial(#PB_Any, TextureID(robot\base\texture))
robot\pivot\material = CreateMaterial(#PB_Any, TextureID(robot\pivot\texture))
robot\bras\material = CreateMaterial(#PB_Any, TextureID(robot\bras\texture))
robot\avant_bras\material = CreateMaterial(#PB_Any, TextureID(robot\avant_bras\texture))

;}

;{ entitées

; Base
AddMesh_to_robot(CreateCube(#PB_Any, 1000), robot\base\submesh())
TransformMesh(robot\base\submesh()\mesh, 0, 0, 0, 1, 0.05, 1, 0, 0, 0)
FirstElement(robot\base\submesh())
robot\base\entity = CreateEntity(#PB_Any, MeshID(robot\base\submesh()\mesh), MaterialID(robot\base\material), 0, 50, 0)

EntityPhysicBody(robot\base\entity, #PB_Entity_BoxBody) 

; Pivot
AddMesh_to_robot(CreateCylinder(#PB_Any, 500, 200), robot\pivot\submesh())
FirstElement(robot\pivot\submesh())
robot\pivot\entity = CreateEntity(#PB_Any, MeshID(robot\pivot\submesh()\mesh), MaterialID(robot\pivot\material), 0, 200, 0)


AddMesh_to_robot(CreateCube(#PB_Any, 1000), robot\pivot\submesh())
TransformMesh(robot\pivot\submesh()\mesh, 0, 0, 0, 0.700, 1.5, 0.700, 0, 0, 0)
robot\pivot\submesh()\entity = CreateEntity(#PB_Any, MeshID(robot\pivot\submesh()\mesh), MaterialID(robot\pivot\material), 0, 750, 0)
AttachEntityObject(robot\pivot\entity, "", EntityID(robot\pivot\submesh()\entity))


AddMesh_to_robot(CreateCube(#PB_Any, 1000), robot\pivot\submesh())
TransformMesh(robot\pivot\submesh()\mesh, 0, 0, 0, 0.700, 0.5, 0.200, 0, 0, 0)
robot\pivot\submesh()\entity = CreateEntity(#PB_Any, MeshID(robot\pivot\submesh()\mesh), MaterialID(robot\pivot\material), 0, 1500 + 250, 350 - 100)
AttachEntityObject(robot\pivot\entity, "", EntityID(robot\pivot\submesh()\entity))

AddMesh_to_robot(CreateCube(#PB_Any, 1000), robot\pivot\submesh())
TransformMesh(robot\pivot\submesh()\mesh, 0, 0, 0, 0.700, 0.5, 0.200, 0, 0, 0)
robot\pivot\submesh()\entity = CreateEntity(#PB_Any, MeshID(robot\pivot\submesh()\mesh), MaterialID(robot\pivot\material), 0, 1500 + 250, -350 + 100)
AttachEntityObject(robot\pivot\entity, "", EntityID(robot\pivot\submesh()\entity))

EntityPhysicBody(robot\pivot\entity, #PB_Entity_ConvexHullBody) 

; Bras
AddMesh_to_robot(CreateCube(#PB_Any, 1000), robot\bras\submesh())
TransformMesh(robot\bras\submesh()\mesh, 0, 0, 0, 2.5, 0.30, 0.290, 0, 0, 0)
FirstElement(robot\bras\submesh())
robot\bras\entity = CreateEntity(#PB_Any, MeshID(robot\bras\submesh()\mesh), MaterialID(robot\bras\material), 750 + 500, 1800 + 250 + 500, 0)

EntityPhysicBody(robot\bras\entity, #PB_Entity_BoxBody) 

; AvantBras
AddMesh_to_robot(CreateCube(#PB_Any, 1000), robot\avant_bras\submesh())
TransformMesh(robot\avant_bras\submesh()\mesh, 0, 0, 0, 0.300, 1.5, 0.300, 0, 0, 0)
FirstElement(robot\avant_bras\submesh())
robot\avant_bras\entity = CreateEntity(#PB_Any, MeshID(robot\avant_bras\submesh()\mesh), MaterialID(robot\avant_bras\material), 2500 - 150, 1800 + 250 - 750 - 300, 0)

AddMesh_to_robot(CreateCube(#PB_Any, 1000), robot\avant_bras\submesh())
TransformMesh(robot\avant_bras\submesh()\mesh, 0, 0, 0, 0.300, 0.650, 0.100, 0, 0, 0)
robot\avant_bras\submesh()\entity = CreateEntity(#PB_Any, MeshID(robot\avant_bras\submesh()\mesh), MaterialID(robot\avant_bras\material), 0, 125 + 750, 200)
AttachEntityObject(robot\avant_bras\entity, "", EntityID(robot\avant_bras\submesh()\entity))

AddMesh_to_robot(CreateCube(#PB_Any, 1000), robot\avant_bras\submesh())
TransformMesh(robot\avant_bras\submesh()\mesh, 0, 0, 0, 0.300, 0.650, 0.100, 0, 0, 0)
robot\avant_bras\submesh()\entity = CreateEntity(#PB_Any, MeshID(robot\avant_bras\submesh()\mesh), MaterialID(robot\avant_bras\material), 0, 125 + 750, -200)
AttachEntityObject(robot\avant_bras\entity, "", EntityID(robot\avant_bras\submesh()\entity))

EntityPhysicBody(robot\avant_bras\entity, #PB_Entity_ConvexHullBody) 

;}


;}

;{ Camera
;
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 2000, 2000, 2000, #PB_Absolute)
CameraLookAt(0, 0, 0, 0)
CameraRange (0, 2, 1000)
CameraFOV   (0, 60)
CameraBackColor(0, RGB(30, 100, 255))

MoveCamera(0, 2000, 100, 2000, #PB_Absolute | #PB_World)
CameraLookAt(0, 0, 0, 0)
;}


; EnableWorldPhysics(#True)
; WorldGravity(-9.806)

Repeat
	
	;{ souris
	If ExamineMouse()
		Yaw   = -MouseDeltaX() * 0.15
		Pitch = -MouseDeltaY() * 0.15
	EndIf
	;}
	
	;{ clavier
	
	If ExamineKeyboard()
		
		If KeyboardPushed(#PB_Key_Up) Or KeyboardPushed(#PB_Key_Z)    
			MoveCamera(0,  0, 0, -2 * Boost)
		ElseIf KeyboardPushed(#PB_Key_Down) Or KeyboardPushed(#PB_Key_S)    
			MoveCamera(0,  0, 0,  2 * Boost)
		EndIf 
		
		If KeyboardPushed(#PB_Key_Left) Or KeyboardPushed(#PB_Key_Q)    
			MoveCamera(0, -2 * Boost, 0, 0) 
		ElseIf KeyboardPushed(#PB_Key_Right) Or KeyboardPushed(#PB_Key_D)    
			MoveCamera(0,  2 * Boost, 0, 0)
		EndIf 
		
		If KeyboardPushed(#PB_Key_Space)  
			MoveCamera(0, 0, 2 * Boost, 0) 
		ElseIf KeyboardPushed(#PB_Key_V)
			MoveCamera(0, 0, -2 * Boost, 0)
		EndIf 
		
		MoveNode(0, CameraX(0), CameraY(0), CameraZ(0), #PB_Absolute)
		
	EndIf
	;}
	
	
	RotateCamera(0, Pitch, Yaw, 0, #PB_Relative)
	
	
	RenderWorld()
	Screen3DStats()
	
	Screen3DEvents()
	
	FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1



End
_________________________________________________
Mon site : CeriseCode (Attention Chantier perpétuel ;))
Avatar de l’utilisateur
graph100
Messages : 1318
Inscription : sam. 21/mai/2005 17:50

Re: problème de placement des objets et de leurs corps

Message par graph100 »

Personne pour une petite réponse ? (genre un pro de la 3D en PB ?)

J'essaye simplement de créer un modèle simple d'un bras robot dans l'objectif d'en simuler la commande (au lieu d'un vrai bras mécanique), pour avoir un visuel.

Mon problème se ramène à ça :

Comment créer un assemblage de mesh simple (genre cylindre / cube) pour avoir une entity légèrement plus complexe et un body qui suis la forme de cette entity, même si elle est concave ?
Faut-il créer plusieurs entity convexe ?
Faut-il assembler les entity avec AttachEntityObject() ?
Faut-il utiliser les node ? les joints ?
_________________________________________________
Mon site : CeriseCode (Attention Chantier perpétuel ;))
comtois
Messages : 5186
Inscription : mer. 21/janv./2004 17:48
Contact :

Re: problème de placement des objets et de leurs corps

Message par comtois »

si tu veux un body c'est pour les collisions ? dans ce cas il faut passer par les joints.
http://purebasic.developpez.com/
Je ne réponds à aucune question technique en PV, utilisez le forum, il est fait pour ça, et la réponse peut profiter à tous.
Répondre