Et la seconde ta méthode.


2 autres captures plus flagrantes.


Tu vois ce que je veux dir?

merci chaos - ah oui 3 Mo c'est pour çà peut être que tmyke ne l'a pas l'incluscha0s a écrit :http://www.dreamotion3d.com/PureBasic/PhysXPB.zip j'ai eu le meme problem je pense aussi qu'il serait mieux de le metre dans le pack
Code : Tout sélectionner
IncludePath "Include\"
IncludeFile "d3dx9.pbi"
IncludeFile "dreamotion3d.pbi"
IncludeFile "PhysX.pbi"
Structure s_Vecteur
x.f
y.f
z.f
EndStructure
Structure s_Rayon
;Informations dans R3
Origine.s_Vecteur
Direction.s_Vecteur
;Informations Dans la base de l'ellipsoide
OrigineDansBaseE.s_Vecteur
DirectionDansBaseE.s_Vecteur
;Informations collisions
CollisionDetectee.l
DistanceLaPlusCourte.f
PointIntersection.s_Vecteur
EndStructure
Macro COS_DEG(Angle)
Cos((Angle) * 0.0174533)
EndMacro
Macro SIN_DEG(Angle)
Sin((Angle) * 0.0174533)
EndMacro
Macro TAN_DEG(Angle)
Tan((Angle) * 0.0174533)
EndMacro
Macro NORME(V)
(Sqr(V\x * V\x + V\y * V\y + V\z * V\z))
EndMacro
Global *camera
Global *mesh
Global *Sphere
Global *font
Global *Light1
Global MouseX.f, MouseY.f, CameraAngleX.f, CameraAngleY.f
Global Rayon.s_Rayon
Global *resul.CEntity
Global *sph.CEntity
Global face.l
Global *line.CEntity
Global Dim tri.l(3)
Global Dim v0.f(3), Dim v1.f(3), Dim v2.f(3)
Global mat.D3DXMATRIX
; first init
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
End
EndIf
;-------------------
; 3D engine init
;-------------------
ScreenWidth.l = 800
ScreenHeight.l = 600
ScreenWidth2.f = ScreenWidth/2.0
ScreenHeight2.f = ScreenHeight/2.0
ScreenDepth.l = 32
OpenScreen(ScreenWidth, ScreenHeight, ScreenDepth, "Dreamotion3D...")
DM_InitGraphics(ScreenID(), ScreenDepth, 1, 1)
*DM_d3d9 = DM_GetD3D9()
*DM_d3dDev9 = DM_GetDevice9()
DM_WIDTH = ScreenWidth
DM_HEIGHT = ScreenHeight
SetCurrentDirectory("medias/")
;---------------------------------
; INIT DU MOTEUR PHYSIQUE
;---------------------------------
NX_Init(*DM_d3dDev9)
NX_SetGravity(0.0, -50.0, 0.0)
; Charge une font
*font = DM_LoadFont("Arial",8 , 1)
DM_SetColorText (*font, 198,198,198,255)
;------------------------
; load a B3D file
*mesh = DM_LoadEntity("SacredPlace.b3d", #Null, #False)
NX_CreateStaticElement(*mesh, 10, 0)
*Sphere = DM_CreateSphere()
DM_PositionEntity(*Sphere, 100 + COS_DEG(0) * 1000, 150,100 - SIN_DEG(0) * 1000)
;- camera
*camera = DM_CreateCamera(#Null)
DM_PositionEntity(*camera, 100, 150, 100)
DM_CameraClsColor(*camera, 0, 0, 0)
DM_CameraProjRatio(*camera, 800,600, 6000)
DM_PointEntity(*camera, *Sphere)
NX_CreateCharacter(*camera, 0, 126, 0, 25.0, 150, 0.1)
NX_EntityCollideCallBack(*camera, Collision)
NX_SetCharacterGroup(*camera, 4)
NX_SetSpeedJumpCharacter(*camera, 5.5)
;------------------------------
; une p'tite ligne
;------------------------------
*line = DM_CreateLine(4)
DM_LinePoint(*line, 0,20,10, 0,255,0)
DM_LinePoint(*line, 10,20,0, 0,250,0)
DM_LinePoint(*line, 10,20,10, 0,250,0)
DM_CloseLine(*line)
;-Light
DM_AmbiantLight(80, 80, 80)
*Light1 = DM_CreateLight(1, null)
DM_LightColor(*Light1, 255, 255, 0, 100)
DM_LightAttenuation(*Light1, 2, 2, 2)
Declare.f WrapValue(angle.f)
Declare Normalise(*N.s_Vecteur)
;-----------------------------
; ------- main loop --------
;------------------------------
CameraAngleX = 90
Repeat
ExamineKeyboard()
ExamineMouse()
MouseX = (MouseDeltaX() / 10) * 5 / 3
MouseY = (MouseDeltaY() / 10) * 5 / 3
;MemMouseX + MouseX
CameraAngleX = WrapValue(CameraAngleX + MouseX)
DM_TurnEntity(*camera, 0, MouseX, 0)
If MouseY > 0 And CameraAngleY < 60
CameraAngleY + MouseY
DM_TurnEntity(*camera, MouseY, 0, 0)
ElseIf MouseY < 0 And CameraAngleY > -60
CameraAngleY + MouseY
DM_TurnEntity(*camera, MouseY, 0, 0)
EndIf
If MouseButton(1)
Rayon\Direction\x = COS_DEG(CameraAngleX)
Rayon\Direction\y = TAN_DEG(-CameraAngleY)
Rayon\Direction\z = -SIN_DEG(CameraAngleX)
Normalise(Rayon\Direction)
*resul = NX_RayCastAnyShape(DM_EntityX(*camera), DM_EntityY(*camera), DM_EntityZ(*camera), Rayon\Direction\x, Rayon\Direction\y, Rayon\Direction\z)
;récupère la face trouvée
face = NX_RaycasFaceID()
; récupère les vertex associé
DM_TriangleVertex(*resul, face, @tri(0))
; transpose dans des tableau de vertex pour traitement
v0(0) = DM_VertexX(*resul, tri(0))
v0(1) = DM_VertexY(*resul, tri(0))
v0(2) = DM_VertexZ(*resul, tri(0))
v1(0) = DM_VertexX(*resul, tri(1))
v1(1) = DM_VertexY(*resul, tri(1))
v1(2) = DM_VertexZ(*resul, tri(1))
v2(0) = DM_VertexX(*resul, tri(2))
v2(1) = DM_VertexY(*resul, tri(2))
v2(2) = DM_VertexZ(*resul, tri(2))
; recup la matrice d'attitude du mesh ttrouvé
DM_EntityWorld(*resul, @mat)
; transpose les coordonnées brut des vertices dans le world de représentation du mesh trouvé
D3DXVec3TransformCoord(@v0(0), @v0(0), @mat)
D3DXVec3TransformCoord(@v1(0), @v1(0), @mat)
D3DXVec3TransformCoord(@v2(0), @v2(0), @mat)
; modifie les point du line pour une représentation graphique de la face
DM_LinePosition(*line, 0, v0(0), v0(1), v0(2) )
DM_LinePosition(*line, 1, v1(0), v1(1), v1(2) )
DM_LinePosition(*line, 2, v2(0), v2(1), v2(2) )
DM_LinePosition(*line, 3, v0(0), v0(1), v0(2) )
;Dist.f = NX_RaycasDistance()
;DM_PositionEntity(*Sphere, \Origine\x + Dist * \Direction\x, \Origine\y + Dist * \Direction\y,\Origine\z + Dist * \Direction\z)
EndIf
If KeyboardPushed(#PB_Key_Space)
NX_JumpCharacter(*camera, 350.0)
EndIf
If KeyboardPushed(#PB_Key_Up)
NX_MoveCharacter(*camera, 320.0)
ElseIf KeyboardPushed(#PB_Key_Down)
NX_MoveCharacter(*camera, -320.0)
EndIf
If KeyboardPushed(#PB_Key_Right)
NX_StrafeCharacter(*camera, CameraAngleX+90, 320)
ElseIf KeyboardPushed(#PB_Key_Left)
NX_StrafeCharacter(*camera, CameraAngleX-90, 320)
EndIf
NX_Update()
DM_PositionEntity(*Light1,DM_EntityX(*camera), DM_EntityY(*camera)+ 40, DM_EntityZ(*camera))
DM_BeginScene()
DM_RenderWorld()
DM_DrawText(*font, 0, 0, Str(DM_FPS()))
DM_DrawText(*font, 0, 20, StrF(Rayon\Direction\x,1) + " " + StrF(Rayon\Direction\y,1) + " " + StrF(Rayon\Direction\z,1))
DM_SetColor2D(255, 255, 255, 255)
DM_DrawLine(ScreenWidth2-5,ScreenHeight2-5,ScreenWidth2+6,ScreenHeight2+6)
DM_DrawLine(ScreenWidth2-5,ScreenHeight2+5,ScreenWidth2+6,ScreenHeight2-6)
DM_EndScene()
Until KeyboardPushed(#PB_Key_Escape)
DM_ClearGraphics()
End
Procedure Normalise(*N.s_Vecteur)
Define.f NormeVecteur
NormeVecteur = NORME(*N)
If NormeVecteur <> 0.0
*N\x / NormeVecteur
*N\y / NormeVecteur
*N\z / NormeVecteur
EndIf
EndProcedure
Procedure.f WrapValue(angle.f); <- wraps a value into [0,360) fringe
;Psychophanta : http://purebasic.fr/english/viewtopic.php?t=18635
!fild dword[@f] ; <- now i have 360 into st0
!fld dword[p.v_angle]
!fprem
!fadd st1,st0
!fldz
!fcomip st1
!fcmovnbe st0,st1
!fstp st1
ProcedureReturn
!@@:dd 360
EndProcedure
Code : Tout sélectionner
; Fichiers Include
IncludePath "includeDr\"
IncludeFile "d3dx9.pbi"
IncludeFile "dreamotion3d.pbi"
Enumeration
#Win_main
#Win_new
#Win_Scene
#Gadget_Panel
#Gadget_NewOk
#Gadget_NewAnnuler
#Gadget_NewTxtQuad
#Gadget_NewTxtFacette
#Gadget_NewTxtSize
#Gadget_NewIllustration
#Gadget_NewSpinFacette
#Gadget_NewSpinSize
#Gadget_NewSpinQuad
#Menu_New
#Menu_Quit
#Menu_Save
#Menua_SaveAS
#ImgIllustration
EndEnumeration
Global *camera.CEntity
Global *brush.CBrush
Global *texture.CTexture
; Initialisation des différents modules
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
End
EndIf
UsePNGImageDecoder()
LoadImage(#ImgIllustration, "include\ilustation.png")
Procedure NewSceneWindow()
OpenWindow(#Win_new,0,0,490,310,"Nouvelle Scene", #PB_Window_WindowCentered )
DisableWindow(#Win_main, 1)
If CreateGadgetList(WindowID(#Win_new))
TextGadget(#Gadget_NewTxtQuad, 10, 10, 190, 20, "Nombre de quad" +Chr(9)+" :", #PB_Text_Center)
TextGadget(#Gadget_NewTxtFacette, 10, 60, 190, 20, "Facette par quad :", #PB_Text_Center)
TextGadget(#Gadget_NewTxtSize, 10, 110, 190, 20, "Taille" +Chr(9) +Chr(9)+" :", #PB_Text_Center)
ImageGadget(#Gadget_NewIllustration, 200, 5, 260, 260, ImageID(#ImgIllustration))
SpinGadget(#Gadget_NewSpinQuad, 50, 30, 100, 20, 2, 512 ,#PB_Spin_Numeric)
SpinGadget(#Gadget_NewSpinFacette, 50, 80, 100, 20, 2, 512 ,#PB_Spin_Numeric)
SpinGadget(#Gadget_NewSpinSize, 50, 130, 100, 20, 1, 10000 ,#PB_Spin_Numeric)
SetGadgetText(#Gadget_NewSpinQuad, "16")
SetGadgetText(#Gadget_NewSpinFacette, "16")
SetGadgetText(#Gadget_NewSpinSize, "2048")
ButtonGadget(#Gadget_NewOk, 10, 270, 80, 30, "Ok")
ButtonGadget(#Gadget_NewAnnuler, 110, 270, 80, 30, "Annuler")
Else
End
EndIf
EndProcedure
winID.l=OpenWindow(#Win_main,0,0,800,600,"Yame 3D editor", #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
If winID
If CreateGadgetList(WindowID(#Win_main))
PanelGadget (#Gadget_Panel, 600, 0, 200, 600 - MenuHeight())
AddGadgetItem (#Gadget_Panel, -1, "Scene")
AddGadgetItem (#Gadget_Panel, -1, "Elements")
EndIf
If CreateMenu(0, WindowID(#Win_main))
MenuTitle("&Projet")
MenuItem(#Menu_New, "Ouvrir" +Chr(9)+"Ctrl+O")
MenuItem(#Menu_Save, "Enregistrer" +Chr(9)+"Ctrl+E")
MenuItem(#Menua_SaveAS, "Enregistrer sous"+Chr(9)+"Ctrl+R")
MenuItem(#Menu_Quit, "Fermer" +Chr(9)+"Ctrl+F")
MenuTitle("&Edition")
MenuTitle("&Option")
MenuTitle("&Aide")
EndIf
winID2 = OpenWindow(#Win_Scene, 0, 0, 600, 600 - MenuHeight(), "" , #PB_Window_BorderLess ,WindowID(#Win_main))
OpenWindowedScreen(WindowID(#Win_Scene), 0, 0, 600, 600 - MenuHeight(), 0, 0, 0)
SetParent_(WindowID(#Win_Scene), WindowID(#Win_main))
res= DM_InitGraphics(winID2, 32, 0 ,0)
*DM_d3d9 = DM_GetD3D9()
*DM_d3dDev9 = DM_GetDevice9()
DM_WIDTH = 600
DM_HEIGHT = 600 - MenuHeight()
EndIf
DM_AmbiantLight(125, 125, 125)
*camera = DM_CreateCamera(#Null)
DM_MoveEntity(*camera, 0,0,-50.0)
DM_CameraClsColor(*camera, 125, 125, 125)
DM_CameraProjRatio(*camera, 600,600 - MenuHeight(), 800)
DM_CameraViewPort(*camera, 0, 0, 600, 600 - MenuHeight())
NewSceneWindow()
Procedure refresh(Nul.b)
Repeat
DM_BeginScene()
DM_RenderWorld()
DM_EndScene()
ForEver
EndProcedure
Thread = CreateThread(@refresh(),0)
Repeat
Event.l = WindowEvent()
Select Event
;-Event gadget
Case #PB_Event_Gadget
Select EventGadget()
;Annuler nouvelle scene
Case #Gadget_NewAnnuler
CloseWindow(#Win_new)
DisableWindow(#Win_main, 0)
;Nouvelle Scene
Case #Gadget_NewOk
DM_SetTerrain(Val(GetGadgetText(#Gadget_NewSpinQuad)), Val(GetGadgetText(#Gadget_NewSpinFacette)), Val(GetGadgetText(#Gadget_NewSpinSize)))
SetCurrentDirectory("include/")
DM_CreateTerrain("hm.bmp", 1)
*brush = DM_QuadBrush(0)
; Etablit la premiere texture
*texture = DM_GetTexture(*brush, 0)
DM_LoadTexture(*texture, "backcolor.bmp")
; Etablit la seconde texture
*texture = DM_GetTexture(*brush, 1)
DM_LoadTexture(*texture, "grille.bmp")
; Répercute sur les brushs de tous les Quad
DM_MultiQuadBrush(0, 16, *brush)
CloseWindow(#Win_new)
DisableWindow(#Win_main, 0)
EndSelect
;-Event menu
Case #PB_Event_Menu
Select EventMenu()
Case #Menu_New
NewSceneWindow()
Case #Menu_Quit
End
EndSelect
EndSelect
;Delay(1)
Until Event = #PB_Event_CloseWindow
KillThread(Thread)
DM_ClearGraphics()
End
l'intérêt de faire un fichier desc, c'est qu'on aura la syntaxe de la commande qui s'affiche dans l'IDE avec une ligne d'aide (comme pour les commandes de PureBasic) , ça serait le topC:\LibraryMaker.exe c:\PureBasicDesc\ /TO C:\PureBasic\PureLibraries\ /ALL /COMPRESSED
Code : Tout sélectionner
; ------------------------------------------------------------
; DreaMotion3D
;
; Exemple : Alpha
; Historique :
; 01/11/06 00:00 DreaMotion3D Team
; 04/11/06 19:16 TMyke
;
; ------------------------------------------------------------
; Fichiers Include
IncludePath "..\Include\"
IncludeFile "d3dx9.pbi"
IncludeFile "dreamotion3d.pbi"
Global view_3D.b=#True
Global camera.l
Global mesh.l
Global font.l
;- Window Constants
Enumeration
#Window_0
EndEnumeration
;- MenuBar Constants
;
Enumeration
#MenuBar_0
EndEnumeration
Enumeration
#MENU_1
#MENU_2
#MENU_3
#MENU_4
#MENU_5
EndEnumeration
;- Gadget Constants
;
Enumeration
#Panel_0
#Combo_0
#Frame3D_0
#Text_0
#Text_1
#Combo_1
#Frame3D_1
#Text_2
#Combo_2
#Button_0
EndEnumeration
Declare Open_Window_0()
Declare Open_Material_0()
; ---------------------------------------
; Initialise la fenêtre graphique
; ---------------------------------------
Open_Window_0()
Open_Material_0() : HideGadget(#Panel_0, 1)
res= DM_InitGraphics(DM_hwnd, 0, 0 ,1)
*DM_d3d9 = DM_GetD3D9()
*DM_d3dDev9 = DM_GetDevice9()
DM_WIDTH = 800
DM_HEIGHT = 600
; Charge une font
font = DM_LoadFont( "Arial",8 , 1)
DM_SetColorText (font, 198,198,198,255)
; Définit la couleur ambiante
DM_AmbiantLight(255, 255, 255)
; ---------------------------------------
; Gestion des meshs
; ---------------------------------------
DM_EntityFormat(2)
SetCurrentDirectory("media/")
mesh = DM_LoadEntity("Harvester.B3D");sacred2.b3d")
; ---------------------------------------
; Gestion des caméras
; ---------------------------------------
radius_mesh = DM_EntityRadius(mesh)
camera = DM_CreateCamera()
DM_MoveEntity(camera, 0, radius_mesh/5, -radius_mesh * 2)
DM_CameraClsColor(camera, 125, 125, 125)
; ---------------------------------------
; Boucle principale
; ---------------------------------------
Repeat
Event.l = WindowEvent()
Select Event
;-Event gadget
;-Event menu
Case #PB_Event_Gadget
Select EventGadget()
;confirme
Case #Button_0
view_3D = #True
HideGadget(#Panel_0, 1)
EndSelect
Case #PB_Event_Menu
Select EventMenu()
Case #MENU_1
view_3D = #False
DM_BeginScene()
DM_ClsScreen(212, 208, 200, 255)
DM_EndScene()
SetWindowColor ( #Window_0 , RGB (212,208,200))
HideGadget(#Panel_0, 0)
Case #MENU_4
End
EndSelect
; end event windows
EndSelect
If (view_3D=#True)
DM_TurnEntity(mesh, 0,0.1,0)
; ---------------
; Rendu
; ---------------
DM_BeginScene()
DM_RenderWorld()
; Affichage du texte
DM_DrawText(font, 10, 15, "FPS : "+Str(DM_FPS()))
DM_EndScene()
EndIf
Until Event = #PB_Event_CloseWindow
DM_ClearGraphics()
End
;---------------------------------------------------------
;
;---------------------------------------------------------
Procedure Open_Material_0()
If CreateGadgetList(WindowID(#Window_0))
;- Panel0
PanelGadget(#Panel_0, 20, 40, 570, 440)
AddGadgetItem(#Panel_0, -1, "General")
ComboBoxGadget(#Combo_0, 68, 38, 180, 30, #PB_ComboBox_Editable)
Frame3DGadget(#Frame3D_0, 8, 18, 540, 60, "")
TextGadget(#Text_0, 18, 38, 50, 20, "Material")
TextGadget(#Text_1, 298, 38, 40, 20, "Stage")
ComboBoxGadget(#Combo_1, 338, 38, 70, 20, #PB_ComboBox_Editable)
Frame3DGadget(#Frame3D_1, 8, 88, 540, 270, "Rendering Style:")
TextGadget(#Text_2, 28, 118, 110, 20, "Rendering Method:")
ComboBoxGadget(#Combo_2, 138, 118, 260, 20)
ButtonGadget(#Button_0, 428, 378, 80, 30, "Apply")
AddGadgetItem(#Panel_0, -1, "Textures")
AddGadgetItem(#Panel_0, -1, "Color")
CloseGadgetList()
EndIf
EndProcedure
Procedure Open_Window_0()
DM_hwnd = OpenWindow(0, 0, 0, 614, 600, "Dreamotion3D", #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar)
If CreateMenu(#MenuBar_0, WindowID(#Window_0))
MenuTitle("Projet")
MenuItem(#MENU_1, "Load")
MenuItem(#MENU_2, "Save")
MenuItem(#MENU_3, "Save As...")
MenuItem(#MENU_4, "Close")
MenuTitle("Edit")
MenuTitle("Option")
MenuTitle("Help")
EndIf
EndProcedure
Code : Tout sélectionner
DM_EntityWorld(*camera, @mat)
*resul = NX_RayCastAnyShape(DM_EntityX(*camera), DM_EntityY(*camera), DM_EntityZ(*camera), mat\_31, mat\_32, mat\_33)