MP3D Engine Alpha 33

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
Mythros
Enthusiast
Enthusiast
Posts: 306
Joined: Mon Aug 19, 2013 3:28 pm

Re: MP3D Engine Alpha 32

Post by Mythros »

I second that :mrgreen:
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: MP3D Engine Alpha 32

Post by applePi »

we can simulate a water fountain by reducing the balls sizes and giving them physics, 2 examples the first one the plane and the pot have no physics, the second the plane and the pot have physics property so we can watch the spheres staying on the ground and in every 300 entities produced the program will delete every mesh which his Y are below -2.4 except the plane. the technique are from Michael first example about the Gears, so we don't see the balls accumulated on the ground and degenerate the system. note that in the first example the ball have physics property "3" ie for spheres and the fountain flow are exactly like natural flow, line 83 MP_EntityPhysicBody(stone,3,0.2)
the second example line 82 MP_EntityPhysicBody(stone,2,0.2) the ball have the physics property of cubes so it is more powerfull
the gravity used is -5 and not the natural -9.806
i have used 2 rectangles blocks rotated 135 to each other to form the gear, it is not efficient for water but it is beautiful.
Image
Image
1- the plane and pot have no physics (ie no accumulation of water)

Code: Select all

Declare dropStone()

Declare Gear()

Global Flow.b = 0 
Global accel.f = -5
 ExamineDesktops()
Global bitplanes.b=DesktopDepth(0),RX.w=DesktopWidth(0),RY.w=DesktopHeight(0)
MP_Graphics3D(RX,RY,0,1):MP_VSync(0)
 SetWindowTitle(0, "Push Space to toggle water flow ....Up/ Down to change gravity") 
 Global stone
 camera = MP_CreateCamera()    ; Kamera erstellen

 MP_PositionCamera(camera, 0, 4, -10 )
 ;MP_PositionCamera(camera, -5, 4, -10 )
 ;MP_PositionCamera(camera, -8, 0, -1 )
 MP_CameraLookAt(camera,0,0,0)

 light= MP_CreateLight(1)    ; Es werde Licht
  
 texture = MP_CreateTextureColor(256, 256, RGBA(50, 255, 100, 255))
 texture2 = MP_LoadTexture(#PB_Compiler_Home + "Examples/3D/Data/Textures\Wood.jpg",0) 
 Global texture3 = MP_LoadTexture(#PB_Compiler_Home + "Examples/3D/Data/Textures\grass.jpg",0) 
 
 Global plane = MP_CreateRectangle(20,20,1)
 MP_EntitySetTexture(plane, texture)
 MP_PositionEntity (plane,0,-3,0)
 MP_RotateEntity(plane, 90, 0, 0)
   
 torus = MP_CreateTorus(0.1, 1, 20) ; just a fake pot
 MP_ResizeMesh(torus,6,6,1)
 MP_RotateEntity(torus, 90, 0, 0 )
 MP_PositionEntity (torus,-1,-2, 0)
 MP_EntitySetTexture(torus, texture2)
 
 Global spring = MP_CreateRectangle(2,1,1)
     
 MP_EntitySetNormals(torus) 
 MP_MaterialDiffuseColor(torus,255,255,128,50)
 MP_MaterialSpecularColor(torus,255,255,255,155,5)
 MP_EntitySetTexture(spring, texture2)
 
 MP_PositionEntity (spring, -4.6, 2, 0)
 MP_RotateEntity (spring, 0, 0, 45)
 MP_PhysicInit()
 
 MP_EntityPhysicBody(spring , 1, 100)
 ;MP_EntityPhysicBody(torus , 1, 1)
 ;MP_EntityPhysicBody(plane , 1, 1)
 
 MP_AmbientSetLight (RGB(100,100,230))
 
 Gear() ; call the Gear construction

 While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
   If MP_KeyHit(#PB_Key_Space)
        Flow ! 1
   ElseIf Flow = 1
       dropStone()
   EndIf
     
   If MP_KeyHit(#PB_Key_Up)   
     accel + 1
   ElseIf MP_KeyHit(#PB_Key_Down) 
     accel - 1
     EndIf
           
     MP_PhysicUpdate()
     
     MP_RenderWorld() ; Erstelle die Welt
     MP_Flip () ; Stelle Sie dar
     
 Wend
   
 MP_PhysicEnd()
 
 Procedure dropStone()
   stone=MP_CreateSphere(16)
   MP_ResizeMesh(stone,0.05,0.05,0.05)
   
   MP_PositionEntity(stone,-4.0, 2.8, 0)
   MP_RotateEntity (stone, 0, 0, 45)
   MP_EntityPhysicBody(stone,3,0.2)
   MP_EntitySetGravity(stone, 0 , accel ,0)
  
  ; Kill all meshs with y < -10   
     For n = 0 To MP_ListGetSize(1)-1
       TempMesh = MP_ListGetElement(1, n)
       If MP_EntityGetY(TempMesh) < -10
         
           MP_FreeEntity(TempMesh)
       EndIf
     Next  
  
   EndProcedure
   

Procedure Gear()
  ; we want to make 8 teeth gear from 2 overlapped rectangles rotated by 135
  Mesh = MP_CreateRectangle (2,2,2)
  Mesh2 = MP_CreateRectangle (2,2,2)
  MP_RotateEntity(Mesh2, 0, 0, 135 )
  MP_ChangeMeshCoord(Mesh2)
  MP_AddMesh(Mesh2 , Mesh ) : MP_FreeEntity(Mesh2)
  
  Mesh7 = MP_CreateCylinder (16,5) ; axes for the gear
  MP_ResizeMesh(Mesh7, 0.3, 0.3, 4)
  MP_RotateEntity(Mesh7 , 0 , 180, 90, 1)
  MP_ChangeMeshCoord(Mesh7)
  MP_AddMesh(Mesh7 , Mesh )
  MP_FreeEntity(Mesh7)
  
  MP_PositionEntity (Mesh,-1.4,0,0)
  MP_EntityPhysicBody(Mesh , 5, 150)
  MP_ConstraintCreateHinge (Mesh,0,0,1,0,0,0)

MP_MaterialEmissiveColor(Mesh, 255, 156 ,118, 39)

EndProcedure


2- the plane and the pot have physics so the water can accumulate

Code: Select all

Declare dropStone()

Declare Gear()
Global Flow.b = 0 
Global accel.f = -5
 ExamineDesktops()
Global bitplanes.b=DesktopDepth(0),RX.w=DesktopWidth(0),RY.w=DesktopHeight(0)
MP_Graphics3D(RX,RY,0,1):MP_VSync(0)
 SetWindowTitle(0, "Push Space to toggle water flow ....Up/ Down to change gravity") 
 Global stone
 camera = MP_CreateCamera()    ; Kamera erstellen

 ;MP_PositionCamera(camera, 0, 4, -10 )
 MP_PositionCamera(camera, -5, 4, -10 )
 ;MP_PositionCamera(camera, -8, 0, -1 )
 MP_CameraLookAt(camera,0,0,0)

 light= MP_CreateLight(1)    ; Es werde Licht
  
 texture = MP_CreateTextureColor(256, 256, RGBA(50, 255, 100, 255))
 texture2 = MP_LoadTexture(#PB_Compiler_Home + "Examples/3D/Data/Textures\Wood.jpg",0) 
 Global texture3 = MP_LoadTexture(#PB_Compiler_Home + "Examples/3D/Data/Textures\grass.jpg",0) 
 
 Global plane = MP_CreateRectangle(20,20,1)
 MP_EntitySetTexture(plane, texture)
 MP_PositionEntity (plane,0,-3,0)
 MP_RotateEntity(plane, 90, 0, 0)
   
 torus = MP_CreateTorus(0.1, 1, 20) ; just a fake pot
 MP_ResizeMesh(torus,6,6,1)
 MP_RotateEntity(torus, 90, 0, 0 )
 MP_PositionEntity (torus,-1,-2, 0)
 MP_EntitySetTexture(torus, texture2)
 
 Global spring = MP_CreateRectangle(2,1,1)
     
 MP_EntitySetNormals(torus) 
 MP_MaterialDiffuseColor(torus,255,255,128,50)
 MP_MaterialSpecularColor(torus,255,255,255,155,5)
 MP_EntitySetTexture(spring, texture2)
 
 MP_PositionEntity (spring, -4.6, 2, 0)
 MP_RotateEntity (spring, 0, 0, 45)
 MP_PhysicInit()
 
 MP_EntityPhysicBody(spring , 1, 100)
 MP_EntityPhysicBody(torus , 1, 1)
 MP_EntityPhysicBody(plane , 1, 1)
 
 MP_AmbientSetLight (RGB(100,100,230))
 
 Gear() ; call the Gear construction

 While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
   If MP_KeyHit(#PB_Key_Space)
        Flow ! 1
   ElseIf Flow = 1
       dropStone()
   EndIf
     
   If MP_KeyHit(#PB_Key_Up)   
     accel + 1
   ElseIf MP_KeyHit(#PB_Key_Down) 
     accel - 1
     EndIf
           
     MP_PhysicUpdate()
     
     MP_RenderWorld() ; Erstelle die Welt
     MP_Flip () ; Stelle Sie dar
     
 Wend
   
 MP_PhysicEnd()
 
 Procedure dropStone()
   stone=MP_CreateSphere(16)
   MP_ResizeMesh(stone,0.05,0.05,0.05)
   
   MP_PositionEntity(stone,-4.0, 2.8, 0)
   MP_RotateEntity (stone, 0, 0, 45)
   MP_EntityPhysicBody(stone,2,0.2)
   MP_EntitySetGravity(stone, 0 , accel ,0)
  
   ; Kill all meshs with y < -2.4 except the plane 
   
   meshesNum = MP_ListGetSize(1)-1
   If meshesNum > 300
     For n = 0 To meshesNum
       TempMesh = MP_ListGetElement(1, n)
       If TempMesh <> plane
       If MP_EntityGetY(TempMesh) < -2.4
         
           MP_FreeEntity(TempMesh)
         EndIf
         EndIf
       Next 
    EndIf
             
   EndProcedure
   

Procedure Gear()
  ; we want to make 8 teeth gear from 2 overlapped rectangles rotated by 135
  Mesh = MP_CreateRectangle (2,2,2)
  Mesh2 = MP_CreateRectangle (2,2,2)
  MP_RotateEntity(Mesh2, 0, 0, 135 )
  MP_ChangeMeshCoord(Mesh2)
  MP_AddMesh(Mesh2 , Mesh ) : MP_FreeEntity(Mesh2)
  
  Mesh7 = MP_CreateCylinder (16,5) ; axes for the gear
  MP_ResizeMesh(Mesh7, 0.3, 0.3, 4)
  MP_RotateEntity(Mesh7 , 0 , 180, 90, 1)
  MP_ChangeMeshCoord(Mesh7)
  MP_AddMesh(Mesh7 , Mesh )
  MP_FreeEntity(Mesh7)
  
  MP_PositionEntity (Mesh,-0.4,0,0)
  MP_EntityPhysicBody(Mesh , 5, 150)
  MP_ConstraintCreateHinge (Mesh,0,0,1,0,0,0)
  
  ;MP_EntitySetNormals(Mesh) 
  MP_MaterialEmissiveColor(Mesh, 255, 156 ,118, 39)
  
EndProcedure


User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: MP3D Engine Alpha 32

Post by Psychophanta »

@MP
Please add function:
MP_MeshGetData(Entity, Typ, *Daten, Datenlaenge)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 32

Post by mpz »

Hi,

@Alexi, nice demos. I have seen demos of Water shaders made with particles insteed of meshs. This works with very much particles and GPU power. Put i dont know a way to integrate this in mp3d...

@Psychophanta i thinks i have a commands integrated for that, MP_CatchMesh(Memory , SizeOfMemory ) you can use directx, b3d and 3ds meshs.

Code: Select all

Mesh = MP_CatchMesh( ?Logo , ?Logoend-?Logo )

DataSection
  Logo:
    IncludeBinary "c:\Programme\PureBasic\Examples\DirectX For PB4\Source\tree.x"
  Logoend:
EndDataSection
Greetings Michael
Working on - MP3D Library - PB 5.73 version ready for download
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: MP3D Engine Alpha 32

Post by Psychophanta »

@mpz;
Function MP_MeshGetData(Entity, Typ, *Daten, Datenlaenge) would get the vertex and faces data form an existing and already open Mesh. It would be the complementary function to the existing one: MP_MeshSetData(Entity, Typ, *Daten, Datenlaenge).
So, it has nothing to do with CatchMesh.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Mythros
Enthusiast
Enthusiast
Posts: 306
Joined: Mon Aug 19, 2013 3:28 pm

Re: MP3D Engine Alpha 32

Post by Mythros »

Hi, @mpz.

About the question I asked above...

My answer:
Just the ability to stream an on-website live avi file.

For instance,

I use the url, "http://mywebsite.com/files/videos/mylivestream.avi"

It then allows me to still texture the 3D object with the video texture still playing.
Also, when are we going to see the ability to export into *.b3d, *.3ds, *.x, *.obj, & *.mesh (multi-textured / materials / animated)?

Thanks alot, mpz!
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: MP3D Engine Alpha 32

Post by applePi »

@Alexi , there are a metaball shader here "C:\PureBasic\MP3D Demos\Shader\EffektShader\Metablob.fx . when you run the example MP_BigShaderDemo.pb the metaballs are demo 6 . just correct the 3 cases MP_MeshSetParent to MP_EntitySetParent
i will read about metaballs, but from the videos it seems a core which makes relations cloud with the neighbor balls. and i think the physics engines are designed with a normal mesh in consideration. and most metaballs demos are focused on graphics only and not physics. there is a great demo in Nvidea site http://www.gamephys.com/game-physics/nv ... imulation/
the articles http://www.matthiasmueller.info/publica ... lides.pdf‎
http://www.matthiasmueller.info/publica ... lCells.pdf
describe how it works, too much effort needed. sometimes inventing something from scratch on a new bases are easier than studying what was invented before.

@Psychophanta
there is already MP_GetMeshData() and not MP_MeshGetData()
i have not used it before.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: MP3D Engine Alpha 32

Post by Psychophanta »

applePi wrote:there is already MP_GetMeshData() and not MP_MeshGetData()
i have not used it before.
Yes, but MP_MeshGetData() seems not get a buffer with the vertex data sequence of the mesh but just its vertex format.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 32

Post by mpz »

Hello

you find a new lib on my mp3d forum with a new function "MP_GetMeshData(Entity, Typ) ". I have renamend two older commands. The error handling is not integrated and it is easy to make an error, please test what you do...

Here comes a new demo for the new function 28-30 with a little description of the commands:

; Renamend MP_MeshSetData (Entity, Typ, Daten, Datenlaenge) To MP_SetMeshData (Entity, Typ, Daten, Datenlaenge)

; Renamend MP_MeshGetData(Entity, Typ) to MP_GetMeshInfo(Entity, Typ)

;MP_GetMeshInfo(Entity, Typ)
;The function MP_GetMeshData gets the vertex format of a entity. An entity is in this command mesh.

;Parameter
;Entity = Entity identity

;Typ = Typ is #PB_Mesh_Vertex (1)
; #PB_Mesh_Normal (2)
; #PB_Mesh_Color (4)
; #PB_Mesh_UVCoordinate (8)
; 32 = Gets the fixed vertex function declaration
; 64 = Gets the vertex lenght

;Return value
;#True, D3DFVF form, vertex lenght Or on failure #False

; New function MP_GetMeshData(Entity, Typ) Typ = #PB_Mesh_Vertex and #PB_Mesh_Face

Code: Select all

MP_Graphics3D (640, 480, 0, 3) ; Erstelle ein WindowsFenster mit 3D Funktion #Window = 0
SetWindowTitle(0, "3D Darstellung eine Würfels") ; Setzt einen Fensternamen

camera = MP_CreateCamera() ; Kamera erstellen
;MP_PositionCamera (camera, 0, 0, -3)

light = MP_CreateLight(1) ; Es werde Licht

Mesh = MP_CreateCube() ; Und jetzt eine Würfel

MP_PositionEntity (Mesh, 0, 0, 3) ; Position des Würfels

While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen

  MP_TurnEntity (Mesh, 0, 1, 1) ; dreh den Würfel
  
  vertexlenght = MP_GetMeshInfo (Mesh, 64)
  vertexcount = MP_CountVertices(Mesh)
  
  *Memory = MP_GetMeshData(Mesh, #PB_Mesh_Vertex)
  
  If *Memory
    address = *Memory
    For n = 0 To vertexcount - 1
      address = *Memory + n * vertexlenght
      
      PokeF ( address, PeekF(address) * 1.001 ) ; x.f Coords
      address +4
      PokeF ( address, PeekF(address) * 0.999 ) ; y.f Coords
      address +4
      ;PokeF ( address, PeekF(address) * 1.001 ) ; z.f Coords

    Next  
  EndIf
  
  MP_SetMeshData (Mesh,  #PB_Mesh_Vertex |#PB_Mesh_Normal | #PB_Mesh_Color | #PB_Mesh_UVCoordinate , *Memory, vertexcount)
  
  FreeMemory(*Memory)
  
  MP_RenderWorld() ; Erstelle die Welt
  MP_Flip () ; Stelle Sie dar

Wend

Greetings Michael
Last edited by mpz on Mon Nov 11, 2013 4:14 pm, edited 1 time in total.
Working on - MP3D Library - PB 5.73 version ready for download
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: MP3D Engine Alpha 32

Post by Psychophanta »

Great Michael, i will test today later :D
And please, don't forget to update de manual :?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: MP3D Engine Alpha 32

Post by applePi »

many thanks Michael , i have tried it, works okay until now.
just a note: the example MP_BigShaderDemo.pb in the installed mp3d folder needs a correction in the 3 cases of MP_MeshSetParent to MP_EntitySetParent
thanks
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: MP3D Engine Alpha 32

Post by Psychophanta »

Mhh!
With *Memory=MP_GetMeshData(Mesh, #PB_Mesh_Vertex) the *Memory is taken automatically by the function.
Could the user choose the mem address where to store the MeshData?
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 32

Post by mpz »

Hi,

i can make a optional parameter like

MP_GetMeshData(Mesh, #PB_Mesh_Vertex[,*Memory, Memorylenght])

Then you can choose both methodes the first easy or the professional with a definied memory or dim field

what do you think?

Greetings Michael
Working on - MP3D Library - PB 5.73 version ready for download
Mythros
Enthusiast
Enthusiast
Posts: 306
Joined: Mon Aug 19, 2013 3:28 pm

Re: MP3D Engine Alpha 32

Post by Mythros »

Hi, @mpz. We DEFINITELY need the ability to both save AND load, both the mesh AND its textures and animations in B3D format.

PLEASE add this.

I will add you to the credits in my final game!

Thank You, and have a WONDERFUL evening! :)

Mythros
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: MP3D Engine Alpha 32

Post by Psychophanta »

:D Yes Mike, it would be perfect!
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply