présent sur DM3D, plus le moteur y gagnera

Code : Tout sélectionner
; Fichiers Include
IncludePath "Include\"
IncludeFile "d3dx9.pbi"
IncludeFile "dreamotion3d.pbi"
IncludeFile "PhysX.pbi"
; Globales
Global anglex.f, angley.f, flagXDown.w
Global mox.f, omx.f, moy.l, omy.l
Global *camera.CEntity
Global *rs.CEntity
Global *cs.CEntity
Global *st.CEntity
Global *cap.CEntity
Global *base.CEntity
Global *font.CFont
Global *light.CEntity
Global angle.f
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
; Initialisation des différents modules
If InitSprite() = 0 Or InitKeyboard() = 0 Or InitMouse() = 0
End
EndIf
; Initialise la fenêtre graphique
DM_Graphics3D(800, 600, 32, 0, 1)
; Charge une font
*font = DM_LoadFont("Arial",8 , 1)
DM_SetColorText (*font, 198,198,198,255)
SetCurrentDirectory("media/")
;---------------------------------
; INIT DU MOTEUR PHYSIQUE
;---------------------------------
NX_Init(*DM_d3dDev9)
;------------------------------
; P'TITE LUMIERE
;------------------------------
*light = DM_CreateLight(1, null)
DM_LightRange(*light ,50)
DM_LightAttenuation(*light, 1.0, 0.0, 0.0)
DM_TranslateEntity(*light, 0,200,35)
;--------------------------------------------------------------
; CHARGE UN SOL
;--------------------------------------------------------------
; charge un sol pour avoir une référence
*base = DM_LoadEntity("land.x", Null, False)
NX_CreateStaticElement(*base,10,0)
*base = DM_LoadEntity("square.3ds", null, false)
DM_TranslateEntity(*base, 2,140,35)
NX_CreateStaticElement(*base, 10,0)
*sph = DM_LoadEntity("sphere2.x")
DM_PositionEntity(*sph, 100,100,-50)
;------------------------------
; create CHARACTER
;------------------------------
*cap = DM_LoadEntity("mariorun.x", null, false)
NX_CreateCharacter(*cap, 0,26,0, 6.0,8.5, 0.1)
;NX_EntityCollideCallBack(*cap, Collision)
NX_SetCharacterGroup(*cap, 4)
NX_SetSpeedJumpCharacter(*cap, 3.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)
angle=180.0
; ---------------------------------------
; Gestion des caméras
; ---------------------------------------
*camera = DM_CreateCamera(#Null)
DM_MoveEntity(*camera, 207,150,101)
DM_TurnEntity(*camera, 17,-140,0)
DM_CameraClsColor(*camera, 25, 25, 25)
; ---------------------------------------
; Boucle principale
; ---------------------------------------
; si plein ecran, permet d'avoir la fleche
;change_curseur( #IDC_ARROW )
Repeat
ExamineKeyboard()
ExamineMouse()
ShowCursor_(1)
If KeyboardReleased(#PB_Key_Escape) Or WindowEvent()=#PB_Event_CloseWindow
Quit=1
EndIf
If KeyboardPushed(#PB_Key_Q)
DM_TranslateEntity(*sph, 1,0,0)
EndIf
If KeyboardPushed(#PB_Key_W)
DM_TranslateEntity(*sph, -1,0,0)
EndIf
; If KeyHit(#PB_Key_R)
dirx.f =0
dirz.f =0
diry.f = -1
*resul = NX_RayCastAnyShape(DM_EntityX(*sph), DM_EntityY(*sph), DM_EntityZ(*sph), dirx, diry, dirz)
;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) )
; EndIf
; Gestion de la caméra
If KeyboardPushed(#PB_Key_Up)
DM_MoveEntity(*camera, 0,0,4)
ElseIf KeyboardPushed(#PB_Key_Down)
DM_MoveEntity(*camera, 0,0,-4)
EndIf
If MouseButton(#PB_MouseButton_Left)
If flagXdown=0
omx = MouseX()
omy = MouseY()
flagXDown=11
Else
moy = MouseY()-omy
angley=(moy/5.0)
omy= MouseY()
mox = MouseX()-omx
anglex=(mox/5.0)
omx= MouseX()
DM_TurnEntity(*camera, angley,anglex,0)
EndIf
Else
flagXDown=0
EndIf
; ---------------
; Rendu
; ---------------
; mise a jour de la physique
NX_Update()
DM_BeginScene()
DM_RenderWorld()
; Affichage du texte
DM_DrawText(*font, 10, 32, "Control Mario: Y/B move G/H turn T/U strafe SPACE jump")
DM_EndScene()
Until Quit=1
NX_Exit()
DM_ClearGraphics()
End
Je vais voir cela, je te fais signe...Progi1984 a écrit :En fait, si tu peux transformer ce code (http://purebasic.hmt-forum.com/viewtopic.php?t=5678) tout en collant du texte sur la texture 0, il n'y aura aucun problème....