Dreamotion3d (and PhysX) continuation...

Advanced game related topics
User avatar
Comtois
Addict
Addict
Posts: 1429
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

PureBlock using Dreamotion3D.

Code: Select all

;Comtois 21/10/07
; Include files
IncludePath "Include\"  :  IncludeFile "dreamotion3d.pbi"

EnableExplicit

Enumeration
  #Nord
  #Est
  #Sud
  #Ouest
  #Vertical
EndEnumeration

#Taille=12
#Taille2 = #Taille/2

Structure f_Vecteur
  x.f
  y.f
  z.f
EndStructure

Structure i_Vecteur
  x.l
  y.l
  z.l
EndStructure

Structure s_Cube
  Angle.f
  p.f_Vecteur
  s.f_Vecteur
  t.f_Vecteur
  Type.l
  Sens.l
  Case1.I_Vecteur
  Case2.I_Vecteur
  Origine.I_Vecteur
EndStructure

Global Cube.s_Cube, Px.l, Pz.l, Perdu.l, MapX.l, MapZ.l
Define.l Options, i, j, n, Tombe

Restore Niveau1
Read MapX
Read MapZ
Dim Map(MapX+1,MapZ+1)
Read Cube\Origine\X
Read Cube\Origine\Z
For j=1 To MapZ
  For i = 1 To MapX
    Read Map(i,j)
  Next i
Next j

;- Ouverture de la fenêtre et de l'écran
InitSprite()
InitKeyboard()
DM_Graphics3D(800, 600, 32,  0, 1)

;- Declaration des procédures
Declare MakeMesh()
Declare Animation()
Declare CreateFaces()
Declare CreateFacesBlock()

Macro RENDER_WORLD()
   DM_BeginScene()
     DM_RenderWorld()
   DM_EndScene()
EndMacro

;-Mesh
Global   *ent.CEntity
CreateFaces()

;-Blox
Global *entity.CEntity
Global *brush.CBrush
;Initialise le cube
Cube\p\x=Cube\Origine\X*#Taille
Cube\p\y=#Taille
Cube\p\z=Cube\Origine\Z*#Taille
Cube\Type = #Vertical
Cube\Sens = #Vertical
CreateFacesBlock()
MakeMesh()

;-Construit le jeu
For j=1 To MapZ
  For i=1 To MapX
    If Map(i,j)=1
      Map(i,j)=DM_CopyEntity(*ent)
      DM_ScaleEntity(Map(i,j), #Taille, 2, #Taille)
      DM_PositionEntity(Map(i,j), i*#Taille, -1, j*#Taille)
    EndIf
  Next i
Next j     
;Libère l'entity 
DM_FreeEntity(*ent)

;-Camera
Global *camera.CEntity
Global *Bidon.CEntity
*bidon=DM_CreatePivot() ; Pour orienter la camera
*camera   = DM_CreateCamera()
DM_PositionEntity(*camera, 0, 110, -16*#Taille)
DM_PositionEntity(*bidon, 5*#Taille, 0, 3*#Taille)
DM_PointEntity(*camera, *bidon)
DM_CameraClsColor(*camera, 5, 5, 85)
DM_CameraZoom(*camera, -0.42)

;-Light
DM_AmbientLight(185,  185,  185)
Global *light
*light=DM_CreateLight()
DM_LightColor(*light, 255,  255,  55, 255)
DM_PositionEntity(*light,500,500,500)
  
;Transparence du Blox, à placer après la création de l'ensemble des entitys
*brush=DM_GetBrush(*entity)
DM_EntityLast(*entity)
DM_BrushAlpha(*brush, 150,2,3)
   
;- **** MAIN ****

Repeat
  While WindowEvent() : Wend
  If ExamineKeyboard()
   
    If Cube\Sens = #Vertical
      If KeyboardPushed(#PB_Key_Left)
        Cube\Sens = #Ouest : MakeMesh()
      ElseIf KeyboardPushed(#PB_Key_Right)
        Cube\Sens = #Est   : MakeMesh()
      ElseIf KeyboardPushed(#PB_Key_Up)
        Cube\Sens = #Nord  : MakeMesh()
      ElseIf KeyboardPushed(#PB_Key_Down)
        Cube\Sens = #Sud   : MakeMesh()
      EndIf
    EndIf
  EndIf
 
  Animation()
  RENDER_WORLD()
 
Until KeyboardPushed(#PB_Key_Escape)

DM_ClearGraphics()
End
 
Procedure MakeMesh()
  Define *surface.CSurface
  Define.f x,y,z,u,v
  Define i
  With Cube
  Select \type
    Case #Vertical
      \s\x = 1 : \s\y = 2 : \s\z = 1
    Case #Nord, #Sud
      \s\x = 1 : \s\y = 1 : \s\z = 2
    Case #Ouest, #Est
      \s\x = 2 : \s\y = 1 : \s\z = 1
  EndSelect
 
  Select \Sens
    Case #Nord
      \t\x = 0.5 : \t\y = 0.5 : \t\z = -0.5
    Case #Sud
      \t\x = 0.5 : \t\y = 0.5 : \t\z = 0.5
    Case #Ouest
      \t\x = 0.5 : \t\y = 0.5 : \t\z = 0
    Case #Est
      \t\x = -0.5 : \t\y = 0.5 : \t\z = 0
    Case #Vertical
      \t\x = 0 : \t\y = 0.5 : \t\z = 0
  EndSelect
 
  *surface=DM_GetSurface(*entity)
  Restore sommets
  For i = 0 To 23
    Read x : Read y : Read z
    Read u : Read v
    DM_VertexCoords(*surface, i,(x + \t\x) * \s\x*#Taille, (y + \t\y) * \s\y*#Taille, (z + \t\z) * \s\z*#Taille)
  Next i
   
  DM_PositionEntity(*entity, \p\x-\t\x*\s\x*#Taille, 0, \p\z-\t\z*\s\z*#taille)
  EndWith
EndProcedure

Procedure Animation()
  Define.f Delta
  Delta = 4.5
 
  Select Cube\Sens

    Case #Ouest
      Cube\Angle + Delta
      DM_RotateEntity(*Entity,0,0,Cube\Angle)

      If Int(Cube\Angle) = 90
        Cube\Angle = 0 : Cube\Sens = #Vertical
        If Cube\Type = #Vertical
          Cube\Type = #Ouest
          Cube\p\x - 1.5*#Taille
        ElseIf Cube\Type = #Est Or Cube\Type = #Ouest
          Cube\Type = #Vertical
          Cube\p\x - 1.5*#Taille
        Else
          Cube\p\x - #Taille
        EndIf
      EndIf
     
    Case #Est
      Cube\Angle - Delta
      DM_RotateEntity(*Entity,0,0,Cube\Angle)
   
      If Int(Cube\Angle) = -90
        Cube\Angle = 0 : Cube\Sens = #Vertical
         
        If Cube\Type = #Vertical
          Cube\Type = #Est
          Cube\p\x + 1.5*#Taille
        ElseIf Cube\Type = #Est Or Cube\Type = #Ouest
          Cube\Type = #Vertical
          Cube\p\x + 1.5*#Taille
        Else
          Cube\p\x + #Taille
        EndIf
       
      EndIf   
     
  Case #Nord
      Cube\Angle + Delta
      DM_RotateEntity(*Entity,Cube\Angle, 0, 0)

      If Int(Cube\Angle) = 90
        Cube\Angle = 0 : Cube\Sens = #Vertical
 
        If Cube\Type = #Vertical
          Cube\Type = #Nord
          Cube\p\z + 1.5*#Taille
        ElseIf Cube\Type = #Nord Or Cube\Type = #Sud
          Cube\Type = #Vertical
          Cube\p\z + 1.5*#Taille
        Else
          Cube\p\z + #Taille
        EndIf
       
      EndIf
           
  Case #Sud
      Cube\Angle - Delta
      DM_RotateEntity(*Entity,Cube\Angle,0,0)
     
      If Int(Cube\Angle) = -90
        Cube\Angle = 0 :  Cube\Sens = #Vertical
 
        If Cube\Type = #Vertical
          Cube\Type = #Sud
          Cube\p\z - 1.5*#Taille
        ElseIf Cube\Type = #Nord Or Cube\Type = #Sud
          Cube\Type = #Vertical
          Cube\p\z - 1.5*#Taille
        Else
          Cube\p\z - #Taille
        EndIf

      EndIf
  EndSelect
     
EndProcedure

 
Procedure CreateFacesBlock()
  Protected *bb.CBrush
  Protected *texture.CTexture
  Protected *surface.CSurface
  Define i
  Define x.f,y.f,z.f, u.f, v.f
  Define s1.w,s2.w,s3.w

  *entity = DM_CreateMesh()
  *surface = DM_CreateSurface(*entity)

  Restore sommets
  For i = 0 To 23
    Read x : Read y : Read z
    Read u : Read v
    DM_AddVertex(*surface, x, y, z , u,v )
  Next i

  For i = 1 To 12 
    Read s1 : Read s2 : Read s3
    DM_AddTriangle(*surface, s1,s2,s3)
  Next i

  *bb = DM_CreateBrush("cube")
  *texture = DM_CreateTexture(256,256)
  DM_SetBuffer(*texture)
  DM_BeginScene()
    DM_ClsScreen($66,$66,$77,50) ; efface le buffer avec une couleur
    DM_SetColor($99, $99 ,$99,255) ; change couleur du trait
    DM_DrawRect(0,0,255,255)  ; dessin d'un rectangle 2D
  DM_EndScene()
  DM_SetBuffer(#Null)
 
  DM_BrushTexture(*bb, *texture,0)
  ; affecte la brush créee a notre entity
  DM_PaintEntity(*entity, *bb)
  ; génératon auto des normales de l'entity créée
  DM_UpdateNormal(*entity) 
   ProcedureReturn
EndProcedure
 
Procedure CreateFaces()
  Protected *bb.CBrush
  Protected *texture.CTexture
  Protected *surface.CSurface
  Define i
  Define x.f,y.f,z.f, u.f, v.f
  Define s1.w,s2.w,s3.w
 
 
  ; défine mesh
  *ent = DM_CreateMesh()
  *surface = DM_CreateSurface(*ent)
  Restore sommets
  For i = 0 To 23
    Read x : Read y : Read z
    Read u : Read v
    DM_AddVertex(*surface, x, y, z , u,v )
  Next i
  For i = 1 To 12 
    Read s1 : Read s2 : Read s3
    DM_AddTriangle(*surface, s1,s2,s3)
  Next i

  *bb = DM_CreateBrush("cube")
 
  ; creation d'une texture vide de 256x256
  *texture = DM_CreateTexture(256,256)
  ; ré-oriente le buffer de sortie graphique vers notre texture
  DM_SetBuffer(*texture)
  ; debut d'un rendu
  DM_BeginScene()
    DM_ClsScreen(255,255,255,0) ; efface le buffer avec une couleur
    DM_SetColor(0, 0 ,0,255)    ; change couleur du trait
    ;DM_DrawRect(1,1,254,254)   ; dessin d'un rectangle 2D
    DM_DrawRect(0,0,255,255)    ; dessin d'un rectangle 2D
  DM_EndScene()
  ; de nouveau le buffer vers l'ecran
  DM_SetBuffer(#Null)
 
 
  DM_BrushTexture(*bb, *texture,0)
  DM_PaintEntity(*ent, *bb)
  DM_UpdateNormal(*ent) 
EndProcedure

;{ Définition du cube
DataSection
Sommets:
;Dessus 0 à 3
Data.f -0.5,0.5,-0.5
Data.f 0,0

Data.f 0.5,0.5,-0.5
Data.f 0,1

Data.f 0.5,0.5,0.5
Data.f 1,1

Data.f -0.5,0.5,0.5
Data.f 1,0

;Dessous 4 à 7
Data.f -0.5,-0.5,0.5
Data.f 0,0

Data.f 0.5,-0.5,0.5
Data.f 0,1

Data.f 0.5,-0.5,-0.5
Data.f 1,1

Data.f -0.5,-0.5,-0.5
Data.f 1,0

;Devant 8 à 11
Data.f -0.5,0.5,0.5
Data.f 0,0

Data.f 0.5,0.5,0.5
Data.f 0,1

Data.f 0.5,-0.5,0.5
Data.f 1,1

Data.f -0.5,-0.5,0.5
Data.f 1,0

;Derrière 12 à 15
Data.f 0.5,0.5,-0.5
Data.f 0,0

Data.f -0.5,0.5,-0.5
Data.f 0,1

Data.f -0.5,-0.5,-0.5
Data.f 1,1

Data.f 0.5,-0.5,-0.5
Data.f 1,0

;Cote gauche 16 à 19
Data.f -0.5,0.5,-0.5
Data.f 0,0

Data.f -0.5,0.5,0.5
Data.f 0,1

Data.f -0.5,-0.5,0.5
Data.f 1,1

Data.f -0.5,-0.5,-0.5
Data.f 1,0

;Cote droit 20 à 23
Data.f 0.5,0.5,0.5
Data.f 0,0

Data.f 0.5,0.5,-0.5
Data.f 0,1

Data.f 0.5,-0.5,-0.5
Data.f 1,1

Data.f 0.5,-0.5,0.5
Data.f 1,0

Triangles:
;Face en Haut
Data.w 2,1,0
Data.w 0,3,2
;Face en Bas
Data.w 6,5,4
Data.w 4,7,6
;Face Avant
Data.w 10,9,8
Data.w 8,11,10
;Face Arrière
Data.w 14,13,12
Data.w 12,15,14
;Face Gauche
Data.w 18,17,16
Data.w 16,19,18
;Face Droite
Data.w 22,21,20
Data.w 20,23,22

Niveau1:
Data.l 10,6
Data.l 2, 2
Data.l 1,1,1,0,0,0,0,0,0,0
Data.l 1,1,1,1,1,1,0,0,0,0
Data.l 1,1,1,1,1,1,1,1,1,0
Data.l 0,1,1,1,1,1,1,1,1,1
Data.l 0,0,0,0,0,1,1,2,1,1
Data.l 0,0,0,0,0,0,1,1,1,0
EndDataSection
;}
Please correct my english
http://purebasic.developpez.com/
User avatar
dobro
Enthusiast
Enthusiast
Posts: 766
Joined: Sun Oct 31, 2004 10:54 am
Location: France
Contact:

Post by dobro »

very nice !! m'sieur :D
Image
Windows 98/7/10 - PB 5.42
■ sites : http://michel.dobro.free.fr/
Marco2007
Enthusiast
Enthusiast
Posts: 638
Joined: Tue Jun 12, 2007 10:30 am
Location: not there...

Post by Marco2007 »

just an info:
Dreamotion3D V4 is available
For C/C++ and PureBasic, BMax version coming soon.

============================================================
Initially, the two most important changes are:
- the code of the engine becomes OpenSource
- Dreamotion3D becomes only one render engine.
It thus does not manage any more the collision and physics.
In the future we will try to write a complementary module
for the management of the collisions and the physics, which
will be based on the API one of PhysX.

for the principal improvements of the engine:
- the terrain engine was re-examined and improve
- the system of octree was re-examined,
- better ressource managements (better stability),
- direct access with the classes of the elements created by the engines,
- complete documentation and in English (still summary, but who should quickly fill out)

The next major changes will be:
- real mesh animation system,
- real shadows mapping system.
- lensFlare for terrain engine
- reflection system.
============================================================
http://www.dreamotion3d.com/download.php
User avatar
Psychophanta
Addict
Addict
Posts: 4968
Joined: Wed Jun 11, 2003 9:33 pm
Location: Lípetsk, Russian Federation
Contact:

DM ver 5: DM_OrbitEntity() bug

Post by Psychophanta »

http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB :mrgreen:
User avatar
Psychophanta
Addict
Addict
Posts: 4968
Joined: Wed Jun 11, 2003 9:33 pm
Location: Lípetsk, Russian Federation
Contact:

Re: Dreamotion3d (and PhysX) continuation...

Post by Psychophanta »

Ask me if you want the complete package for the PB5.31 :wink: !

BTW, a new fast way to orbitate:

Code: Select all

IncludePath "Include\":IncludeFile "dreamotion3d.pbi"
InitSprite():InitKeyboard():InitMouse()
DM_Graphics3D(800,600,32,0,1,0,"Orbitar")
*light=DM_CreateLight(3)
*mesh=DM_CreateTeapot()
*camera=DM_CreateCamera()
DM_PositionEntity(*camera,0,0,-6)
Procedure Orbitar(*c,dx.d,dy.d,dz.d,*o,r.d)
  ;Funcion para orbitar una entidad '*c' alrededor de otra '*o' siendo 'dx' y 'dy' los incrementos de las coordenadas sobre la superficie de una esfera de orbitación de radio 'r'. 'dz' es el incremento del radio 'r'.
  ;Function to make a 3D entity '*c' to orbitate around another 3D entity '*o' being 'dx' y 'dy' the increments of the coords over the orbitation sphere surface with radius 'r'. 'dz' is the increment of the radius 'r'.
  DM_MoveEntity(*c,dx,dy,0)
  DM_PointEntity(*c,*o)
  DM_MoveEntity(*c,0,0,Sqr(dx*dx+dy*dy+r*r)-r+dz)
EndProcedure
m.f=DM_EntityDistance(*camera,*mesh)
Repeat
	ExamineKeyboard()
	ExamineMouse()
  Orbitar(*camera,-MouseDeltaX()/20,MouseDeltaY()/20,MouseWheel()/3,*Mesh,m)
  DM_BeginScene()
	DM_RenderWorld(*camera)
 	DM_EndScene()
Until KeyboardReleased(#PB_Key_Escape) Or WindowEvent()=#PB_Event_CloseWindow
24064 bytes of .exe file is the result of the compilation from this code using PB4.31 (even you need 'Dreamotion3D.dll' and 'D3DX9_37.dll' libraries)
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB :mrgreen:
User avatar
Psychophanta
Addict
Addict
Posts: 4968
Joined: Wed Jun 11, 2003 9:33 pm
Location: Lípetsk, Russian Federation
Contact:

Re: Dreamotion3d (and PhysX) continuation...

Post by Psychophanta »

Maybe this inspires to somebody. Cube has 1 color per face (6 color in total).
User can make the cube to "walk" onto 6 floors, 1 floor per cube face, using only mouse: to change floor and make the cube "walk" just use the 2 mouse keys and the wheel.

http://radicalshare.com/bpaunzb9k3pf/ari.rar.html
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend
Will never leave this forum until the absolute bugfree PB :mrgreen:
Post Reply