Page 58 of 71

Re: MP3D Engine Alpha 32

Posted: Thu May 21, 2015 12:07 pm
by mpz
Hi Psychophanta,

This is very cool and thanks for these function!

I have "repaired" the "MP_PickCamera" function. Now it works with different "viewport". I don't have published the new lib, because i am working on a Threadsafe and unicode lib of mp3d. The informations about these libs find you in my mp3d forum. If i have solved all the problems i got with the unicode function, i will published 4 versions: normal, unicode, Threadsafe and unicode & Threadsafe for PB 5.31

Greetings Michael

About MP_KeyUp() function:

Posted: Thu May 21, 2015 1:01 pm
by Psychophanta
Thanks Mich,

By the way, you forgot this:

About MP_KeyUp() function:
Psychophanta wrote:What is the reason to be for a function which is just the inverse of another existing one?, I mean, if you already have 'MP_KeyDown(key)' the user should use 'Not MP_KeyDown(key)' and not another different function for it, what do you think?
Apart of it, there is not an equivalent function for 'KeyboardReleased(Key)', and there is often useful.
mpz wrote:Hello,

@Psychophanta, yes the command MP_KeyUp double. i will kill them. I will have a look on 'KeyboardReleased(Key)' and can make a new command with this function
:?

Re: MP3D Engine Alpha 32

Posted: Thu May 21, 2015 1:58 pm
by mpz
Hi Psychophanta,

i have killed the command MP_KeyUp() now.

The function MP_KeyHit(key) is the same like KeyboardReleased(Key)'

Greetings Michael

Re: MP3D Engine Alpha 32

Posted: Thu May 21, 2015 10:00 pm
by Psychophanta
Thanks for answer.

Another issue, related with physics 3D:
When a floor is under any physic entity all the behaviour is good, like in the "Domino Day" example, but when program rotate or move the floor, the pieces onto it does not move with floor, is this normal?

Example to show it:

Code: Select all

MP_Graphics3DWindow(0, 0, 1024, 768, "",0)
light0 = MP_CreateLight(1)
MP_PositionEntity(light0, 0, 128, 0)
cam0 = MP_CreateCamera()
MP_CameraSetRange(cam0, 2, 2024)
MP_PositionEntity(cam0, -10, 22, -60)
MP_EntityLookAt(cam0, 0, 0, 0)
MP_PhysicInit()

tex0 = MP_CreateTextureColor(128, 128, RGBA(0, 255, 0, 0))
MP_MaterialEmissiveColor(tex0, 0, 122, 132, 132)


bodenplatte = MP_CreateRectangle(15, 1, 15)
MP_ScaleMesh( bodenplatte ,0.6,0.6,0.6)
MP_EntitySetTexture(bodenplatte, tex0)
MP_EntityPhysicBody(bodenplatte, 1, 0)

Mesh = MP_CreateRectangle(1.5,3,0.4);,0.1)
MP_EntityPhysicBody(Mesh, 2, 20)

MP_MaterialDiffuseColor(Mesh,255,Random(255),Random(255),Random(255)) 

MP_PositionEntity(Mesh,0,1.6,0)
    
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow
  
  MP_Turnentity(bodenplatte,0,1,0,0)
  MP_PhysicUpdate()
  MP_RenderWorld()
  MP_Flip()  
  
Wend

MP_PhysicEnd()

Re: MP3D Engine Alpha 32

Posted: Fri May 22, 2015 8:35 am
by applePi
Psychophanta, this is normal , the same with PB Ogre. this is because MP_Turnentity() turn the floor geometrically and not physically, yes the geometrical functions have some physical effects but not fully implemented.
to affect the cube resting over a plane we should apply force to the plane, here is an example : the circular plane have a hinge and we apply small force to rotate it, a cube with small weight rest over the plane and it will rotate with it
Edit:increase the force from -0.02 to -0.1 and we will see the centrifugal force effect over the cube
line 36: MP_EntityAddImpulse(Mesh, -0.1, 0, 0 , 0, 0, 1.7)

Code: Select all

ExamineDesktops()
Global bitplanes.b=DesktopDepth(0),RX.w=DesktopWidth(0),RY.w=DesktopHeight(0),s_bg.i
MP_Graphics3D(RX,RY,0,1);MP_VSync(0)
SetWindowTitle(0, "tests")

camera = MP_CreateCamera()    ; Kamera erstellen

MP_PositionEntity(camera, 3, 2, -3 )
MP_EntityLookAt(camera,0,0,0)

light= MP_CreateLight(2)    ; Es werde Licht
MP_PositionEntity(light, -10, 10, 0)

MP_AmbientSetLight (RGB(0,100,200))


Mesh = MP_CreateCylinder(10,0.2)
MP_RotateMesh(Mesh , 90 , 0, 0)

MP_EntitySetNormals (Mesh)
MP_MaterialDiffuseColor (Mesh,255,255,255,50)
MP_MaterialSpecularColor (Mesh, 255, 255 ,255, 155,5)

box = MP_CreateRectangle(0.2,0.2,0.2)
MP_PositionEntity(box, 0.5, 0.5, 0 )

MP_PhysicInit()

MP_EntityPhysicBody(Mesh , 5, 10)
MP_ConstraintCreateHinge (Mesh,0,1,0)
MP_EntityPhysicBody(box, 2, 0.1)


While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
       
    MP_EntityAddImpulse(Mesh, -0.02, 0, 0 ,  0, 0, 1.7)
   
   
    MP_PhysicUpdate()
   
    MP_RenderWorld() ; Erstelle die Welt
    MP_Flip () ; Stelle Sie dar
   
Wend
 
MP_PhysicEnd()
 

now rotate the plane with MP_Turnentity and the cube will not rotate with it:

Code: Select all

ExamineDesktops()
Global bitplanes.b=DesktopDepth(0),RX.w=DesktopWidth(0),RY.w=DesktopHeight(0),s_bg.i
MP_Graphics3D(RX,RY,0,1);MP_VSync(0)
SetWindowTitle(0, "tests")

camera = MP_CreateCamera()    ; Kamera erstellen

MP_PositionEntity(camera, 3, 2, -3 )
MP_EntityLookAt(camera,0,0,0)

light= MP_CreateLight(2)    ; Es werde Licht
MP_PositionEntity(light, -10, 10, 0)

MP_AmbientSetLight (RGB(0,100,200))


Mesh = MP_CreateCylinder(10,0.2)
MP_RotateMesh(Mesh , 90 , 0, 0)

MP_EntitySetNormals (Mesh)
MP_MaterialDiffuseColor (Mesh,255,255,255,50)
MP_MaterialSpecularColor (Mesh, 255, 255 ,255, 155,5)

box = MP_CreateRectangle(0.2,0.2,0.2)
MP_PositionEntity(box, 0.5, 0.5, 0 )

MP_PhysicInit()

MP_EntityPhysicBody(Mesh , 5, 0)
;MP_ConstraintCreateHinge (Mesh,0,1,0)
MP_EntityPhysicBody(box, 2, 0.1)


While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
       
    ;MP_EntityAddImpulse(Mesh, -0.02, 0, 0 ,  0, 0, 1.7)
   MP_Turnentity(Mesh,0,1,0,0)
   
    MP_PhysicUpdate()
   
    MP_RenderWorld() ; Erstelle die Welt
    MP_Flip () ; Stelle Sie dar
   
Wend
 
MP_PhysicEnd()
 

Re: MP3D Engine Alpha 32

Posted: Fri May 22, 2015 9:28 am
by Psychophanta
Thank you Apllepi, that is useful to me now. 8)

Re: MP3D Engine Alpha 32

Posted: Fri May 22, 2015 11:11 am
by IdeasVacuum
i will published 4 versions: normal, unicode, Threadsafe and unicode & Threadsafe for PB 5.31
You are creating a rod for your own back there mpz! Perhaps the 'highest level', Unicode and Threadsafe, is all that's needed? What do you think Psychophanta, ApplePi?

Re: MP3D Engine Alpha 32

Posted: Fri May 22, 2015 12:34 pm
by applePi
not sure what Michael wants to do IdeasVacuum , but surely there are users who ask for special versions at http://www.morty-productions.de/gamedev/ . of course the unicode version is a must.
i have added a remark to my example above (the first one)

Re: MP3D Engine Alpha 32

Posted: Fri May 22, 2015 2:13 pm
by Psychophanta
At the moment personally don't need unicode nor thread , but anyway, it would be good.

Re: MP3D Engine Alpha 32

Posted: Fri May 22, 2015 3:30 pm
by mpz
Hi,

now it is possible for me to compile the lib in ASCII, unicode an Threadsafe mode. I think unicode is important for the future of this lib.

So it is easier to make a new working lib if the LTS cicle will end and a new PB version will come:
"So we decided to remove the ability to compile in ascii mode in the PB version that follows after the next LTS version"
http://www.purebasic.fr/english/viewtop ... 14&t=60214

P.S: I make my first steps in DX11 programming and test it to make a mp3d command compatible version of it. DX 11 shader are great...

Greetings Michael

Re: MP3D Engine Alpha 32

Posted: Sun May 24, 2015 8:45 am
by applePi
how to use the MP_GetMeshData with #PB_Mesh_Face ??
the following are using MP_GetMeshData with #PB_Mesh_Vertex
we check the sphere vertices\Y which are < 0 and and make them = 0 so i get a dome. its ground in reality was the sphere bottom .
but what is needed is to remove the sphere bottom to get a real half sphere
my partial code below show the dome
the following code depends on Michael example posted here: http://forums.purebasic.com/english/vie ... 55#p430641

Code: Select all

Structure bgraCol
  b.b
  g.b
  r.b
  a.b
  
EndStructure

Structure MyVertex 
    x.f : y.f : z.f    ; vertices coordinates 
    nx.f : ny.f : nz.f ; normal coordinates
    Color.bgraCol            ; color 
    u.f : v.f          ; texture coordinates 
;    u1.f : v1.f          ; texture coordinates 2 
;    u2.f : v2.f          ; texture coordinates 2 
  EndStructure 

MP_Graphics3D (640, 480, 0, 3)
SetWindowTitle(0, "..not complete Half Sphere .. ") 

camera = MP_CreateCamera() ; Kamera erstellen
light0 = MP_CreateLight(1)
MP_PositionEntity(light0, 0, 128, 0)
cam0 = MP_CreateCamera()
MP_PositionEntity(cam0, 0, 3, -4)
MP_EntityLookAt(cam0, 0, 1, 0)

tex0 = MP_CreateTextureColor(128, 128, RGBA(0, 255, 0, 0))
MP_MaterialEmissiveColor(tex0, 0, 122, 132, 132)
tex1 = MP_CreateTextureColor(128, 128, RGBA(25, 255, 255, 0))
MP_MaterialEmissiveColor(tex1, 0, 122, 132, 132)

sphere = MP_CreateSphere(16)
MP_PositionEntity (sphere, 0, 1, 0)
vertexcount = MP_CountVertices(sphere)
vertexlenght = MP_GetMeshInfo (sphere, 64)
Dim Vert.MyVertex (vertexcount)

MP_GetMeshData(sphere, #PB_Mesh_Vertex,@Vert(),vertexlenght * vertexcount)


ground = MP_CreateRectangle(5, 0.5, 5)
MP_EntitySetTexture(ground, tex0)

For n = 0 To vertexcount-1
   
   If Vert(n)\y < 0
     Vert(n)\y = 0
   EndIf
Next
 
MP_SetMeshData (sphere,  #PB_Mesh_Vertex |#PB_Mesh_Normal | #PB_Mesh_Color | #PB_Mesh_UVCoordinate , @Vert(), vertexcount) 
mp_wireframe(1)     
MP_EntitySetTexture(sphere, tex1)


    While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
      
      MP_TurnEntity (sphere, 0, 0.4, 0) 
      MP_RenderWorld() ; Erstelle die Welt
      MP_Flip () ; Stelle Sie dar
      
    Wend

End
what is needed is like this in PB Ogre, note we use Global Dim MeshDataInd.PB_MeshFace(0) here, and we rebuild the faces like this:

Code: Select all

For i=0 To ArrSizeInd Step 3 
     MeshFace(MeshDataInd(i)\Index, MeshDataInd(i+1)\Index,MeshDataInd(i+2)\Index)
Next  
may be like this approximately in MP3D:
MP_AddTriangle(halfSphere, Indx(i)\Index, Indx(i+1)\Index,Indx(i+2)\Index)

Code: Select all

IncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb"
 
#CameraSpeed = 0.1

#Nb = 50 ; number of sphere Segments and Rings
#Radius = 4
#TempSphere = 30

Global Dim MeshData.PB_MeshVertex(0)
Global Dim MeshDataInd.PB_MeshFace(0)

Global flag=0

Declare HalfSphere()


Define.f KeyX, KeyY, MouseX, MouseY

InitEngine3D()
  
  Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts",#PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Packs/desert.zip", #PB_3DArchive_Zip)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  ExamineDesktops()
  OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "press W for wireframe/ SolidFrame ,____ move by keyboard and mouse", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0)-10, 0, 0, 0)   
      
    ;Materials
    CreateMaterial(0, LoadTexture(0, "ground_diffuse.png"))
    GetScriptMaterial(1, "SphereMap/SphereMappedRustySteel")
    CreateMaterial(2, LoadTexture(2, "Dirt.jpg"))
    GetScriptMaterial(3, "Scene/GroundBlend")
    CreateMaterial(5, LoadTexture(5, "snow_1024.jpg"))
    MaterialCullingMode(5, #PB_Material_NoCulling )
        
    ; Ground
    CreatePlane(3, 200, 200, 5, 5, 5, 5)
    CreateEntity(3,MeshID(3),MaterialID(5), 0, 0, 0)
    EntityPhysicBody(3, #PB_Entity_BoxBody, 0, 1, 1)
    
    ; Camera
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 0, 10, -10, #PB_Absolute)
    CameraLookAt(0, 0,3,0)
    CameraBackColor(0, RGB(224,225,241))
    
    CreateLight(0, RGB(255, 255, 255), 200, 300, 0)
    
    AmbientColor(RGB(255, 255, 255))
    
    CreateMaterial(4, LoadTexture(4, "ValetCoeur.jpg"))
    MaterialCullingMode(4, #PB_Material_NoCulling )
    MaterialShadingMode(4, #PB_Material_Wireframe)
  
    HalfSphere()

    FinishMesh(1)
  
  CreateEntity(7, MeshID(7), MaterialID(4), 0,3,0)
  
wireFrame = 0
    Repeat
      Screen3DEvents()
      
      If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.3
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.3
      EndIf
      
      If ExamineKeyboard()
        If KeyboardReleased(#PB_Key_W)
          If wireFrame
           MaterialShadingMode(4, #PB_Material_Wireframe)
          wireFrame ! 1
        Else 
          MaterialShadingMode(4, #PB_Material_Solid)
          wireFrame ! 1
        EndIf
        EndIf
      
        
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed
        Else
          KeyX = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed
        Else
          KeyY = 0
        EndIf
        
      EndIf
      
      MoveCamera  (0, KeyX, 0, KeyY)
      RotateCamera(0,  MouseY, MouseX, 0, #PB_Relative)
      RotateEntity(7, 0,0.2,0, #PB_Relative)
           
      RenderWorld()
      Screen3DStats()
      FlipBuffers()
      
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1

End
Procedure HalfSphere()
CreateMesh(7, #PB_Mesh_TriangleList, #PB_Mesh_Dynamic)

  CreateSphere(#TempSphere,#Radius, #Nb, #Nb)
  GetMeshData(#TempSphere,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_Normal | #PB_Mesh_UVCoordinate , 0, MeshVertexCount(#TempSphere)-1)
  GetMeshData(#TempSphere,0, MeshDataInd(), #PB_Mesh_Face, 0, MeshIndexCount(#TempSphere, 0)-1)
  ArrSize = ArraySize(MeshData())
 
   For c=0 To ArrSize
      
      x.f = MeshData(c)\x 
      y.f = MeshData(c)\y
      z.f = MeshData(c)\z
      
      If y >= 0 ; to discard the sphere bottom in which the MeshData(c)\y < 0
         MeshVertexPosition(x,y,z)
         MeshVertexTextureCoordinate(MeshData(c)\u, MeshData(c)\v) 
         MeshVertexNormal(MeshData(c)\NormalX, MeshData(c)\NormalY, MeshData(c)\NormalZ)
         
      EndIf   
   Next   
   
   ArrSizeInd = ArraySize(MeshDataInd())/2-((#Nb*6)+6) ; every square = 2 triangles = 6 vertexes
   
   For i=0 To ArrSizeInd Step 3 
     MeshFace(MeshDataInd(i)\Index, MeshDataInd(i+1)\Index,MeshDataInd(i+2)\Index)
     ;Debug Str(MeshDataInd(i)\Index)+"  "+Str(MeshDataInd(i+1)\Index)+"   " +Str(MeshDataInd(i+2)\Index)
   Next  
 EndProcedure

Re: MP3D Engine Alpha 32

Posted: Mon May 25, 2015 8:37 pm
by mpz
Hello to all,

@applePi, thanks for you good samples :)

how to use the MP_GetMeshData with #PB_Mesh_Face ??
the following are using MP_GetMeshData with #PB_Mesh_Vertex

Oh i have made this command, but i have not testet it. So i found some bugs and solved them.

I have made a new testlib for PB 5.22/5.24/5.31 (x86) to check these commands:
http://www.flasharts.de/mpz/mp33_beta/d ... ibrary.zip

MP_GetMeshData(sphere, #PB_Mesh_Face,@Tris(),Triscount*12)
and
MP_SetMeshData (sphere, #PB_Mesh_Face , @Tris(), Triscount)

if needed i can also make a command: MP_SubTriangle and MP_SubVertex too...

Code: Select all

Structure bgraCol
  b.b
  g.b
  r.b
  a.b
 
EndStructure

Structure MyVertex_
    x.f : y.f : z.f    ; vertices coordinates
    nx.f : ny.f : nz.f ; normal coordinates
    Color.bgraCol            ; color
    u.f : v.f          ; texture coordinates
;    u1.f : v1.f          ; texture coordinates 2
;    u2.f : v2.f          ; texture coordinates 2
EndStructure
  
Structure MyTris
    v1.l : v2.l : v3.l    ; vertices coordinates
EndStructure
  
MP_Graphics3D (640, 480, 0, 3)
SetWindowTitle(0, "..not complete Half Sphere .. ")

camera = MP_CreateCamera() ; Kamera erstellen
light0 = MP_CreateLight(1)
MP_PositionEntity(light0, 0, 128, 0)
cam0 = MP_CreateCamera()
MP_PositionEntity(cam0, 0, 3, -4)
MP_EntityLookAt(cam0, 0, 1, 0)

tex0 = MP_CreateTextureColor(128, 128, RGBA(0, 255, 0, 0))
MP_MaterialEmissiveColor(tex0, 0, 122, 132, 132)
tex1 = MP_CreateTextureColor(128, 128, RGBA(25, 255, 255, 0))
MP_MaterialEmissiveColor(tex1, 0, 122, 132, 132)

sphere = MP_CreateSphere(16)
MP_PositionEntity (sphere, 0, 1, 0)
vertexcount = MP_CountVertices(sphere)
vertexlenght = MP_GetMeshInfo (sphere, 64)
Triscount = MP_CountTriangles(sphere)
Dim Vert.MyVertex_ (vertexcount)
Dim Tris.MyTris (Triscount)

MP_GetMeshData(sphere, #PB_Mesh_Vertex,@Vert(),vertexlenght * vertexcount)
MP_GetMeshData(sphere, #PB_Mesh_Face,@Tris(),Triscount*12)

ground = MP_CreateRectangle(5, 0.5, 5)
MP_EntitySetTexture(ground, tex0)

; To look in the Tris
;     For m = 0 To Triscount-1
;       Debug "Tris = "+Str(m)
;       Debug Tris(m)\v1
;       Debug Tris(m)\v2
;       Debug Tris(m)\v3
;     Next 

For n = 0 To vertexcount-1
   
   If Vert(n)\y < 0
     For m = 0 To Triscount-1
       
       If Tris(m)\v1 = n : Tris(m)\v1 = 0 : Tris(m)\v2 = 0: Tris(m)\v3 = 0 : EndIf
       If Tris(m)\v2 = n : Tris(m)\v1 = 0 : Tris(m)\v2 = 0: Tris(m)\v3 = 0 : EndIf
       If Tris(m)\v3 = n : Tris(m)\v1 = 0 : Tris(m)\v2 = 0: Tris(m)\v3 = 0 : EndIf
       
     Next 
   EndIf
   
 Next
 
MP_SetMeshData (sphere,  #PB_Mesh_Vertex |#PB_Mesh_Normal | #PB_Mesh_Color | #PB_Mesh_UVCoordinate , @Vert(), vertexcount)
MP_SetMeshData (sphere,  #PB_Mesh_Face , @Tris(), Triscount)

mp_wireframe(1)     
MP_EntitySetTexture(sphere, tex1)

    While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
     
      MP_TurnEntity (sphere, 0, 0.4, 0)
      MP_RenderWorld() ; Erstelle die Welt
      MP_Flip () ; Stelle Sie dar
     
    Wend

End
Greetings Michael

Re: MP3D Engine Alpha 32

Posted: Tue May 26, 2015 10:17 am
by applePi
thats a great achievement Michael , and usable, i have only a few notes:
1- when we replace :

Code: Select all

MP_GetMeshData(sphere, #PB_Mesh_Vertex,@Vert(),vertexlenght * vertexcount)
with:

Code: Select all

MP_GetMeshData(sphere, #PB_Mesh_Vertex |#PB_Mesh_Normal | #PB_Mesh_Color | #PB_Mesh_UVCoordinate,@Vert(),vertexlenght * vertexcount)
it seems the objects destroyed, but if we keep the first one before the second one it will work (lines 47-48) but not the vice versa

Code: Select all

Structure bgraCol
  b.b
  g.b
  r.b
  a.b
 
EndStructure

Structure MyVertex_
    x.f : y.f : z.f    ; vertices coordinates
    nx.f : ny.f : nz.f ; normal coordinates
    Color.bgraCol            ; color
    u.f : v.f          ; texture coordinates
;    u1.f : v1.f          ; texture coordinates 2
;    u2.f : v2.f          ; texture coordinates 2
EndStructure

;#PB_Mesh_Vertex |#PB_Mesh_Normal | #PB_Mesh_Color | #PB_Mesh_UVCoordinate

Structure MyTris
    v1.l : v2.l : v3.l    ; vertices coordinates
EndStructure
  
MP_Graphics3D (640, 480, 0, 3)
SetWindowTitle(0, "..not complete Half Sphere .. ")

camera = MP_CreateCamera() ; Kamera erstellen
light0 = MP_CreateLight(1)
MP_PositionEntity(light0, 0, 128, 0)
cam0 = MP_CreateCamera()
MP_PositionEntity(cam0, 0, 3, -3)
MP_EntityLookAt(cam0, 0, 1, 0)

tex0 = MP_CreateTextureColor(128, 128, RGBA(0, 255, 0, 0))
MP_MaterialEmissiveColor(tex0, 0, 122, 132, 132)
tex1 = MP_CreateTextureColor(128, 128, RGBA(25, 15, 255, 250))
MP_MaterialEmissiveColor(tex1, 0, 122, 132, 132)

sphere = MP_CreateSphere(16)
MP_PositionEntity (sphere, 0, 1, 0)
vertexcount = MP_CountVertices(sphere)
vertexlenght = MP_GetMeshInfo (sphere, 64)
Triscount = MP_CountTriangles(sphere)
Dim Vert.MyVertex_ (vertexcount)
Dim Tris.MyTris (Triscount)

MP_GetMeshData(sphere, #PB_Mesh_Vertex,@Vert(),vertexlenght * vertexcount)
;MP_GetMeshData(sphere, #PB_Mesh_Vertex |#PB_Mesh_Normal | #PB_Mesh_Color | #PB_Mesh_UVCoordinate,@Vert(),vertexlenght * vertexcount)
MP_GetMeshData(sphere, #PB_Mesh_Face,@Tris(),Triscount*12)

ground = MP_CreateRectangle(5, 0.5, 5)
MP_EntitySetTexture(ground, tex0)

; To look in the Tris
;     For m = 0 To Triscount-1
;       Debug "Tris = "+Str(m)
;       Debug Tris(m)\v1
;       Debug Tris(m)\v2
;       Debug Tris(m)\v3
;     Next 

For n = 0 To vertexcount-1
   
   If Vert(n)\y < 0
     For m = 0 To Triscount-1
       
       If Tris(m)\v1 = n : Tris(m)\v1 = 0 : Tris(m)\v2 = 0: Tris(m)\v3 = 0 : EndIf
       If Tris(m)\v2 = n : Tris(m)\v1 = 0 : Tris(m)\v2 = 0: Tris(m)\v3 = 0 : EndIf
       If Tris(m)\v3 = n : Tris(m)\v1 = 0 : Tris(m)\v2 = 0: Tris(m)\v3 = 0 : EndIf
       
     Next 
   EndIf
   
 Next
 
MP_SetMeshData (sphere,  #PB_Mesh_Vertex |#PB_Mesh_Normal | #PB_Mesh_Color | #PB_Mesh_UVCoordinate , @Vert(), vertexcount)
MP_SetMeshData (sphere,  #PB_Mesh_Face , @Tris(), Triscount)
MP_PositionEntity (sphere, 0, 1.5, 0)
MP_RotateEntity(sphere, 0,0,180)


texture =  MP_LoadTexture(#PB_Compiler_Home + "Examples\3D\Data\Textures\MRAMOR6X6.jpg")
MP_EntitySetTexture(sphere, texture)

box = MP_CreateRectangle(0.2,0.2,0.2)
MP_EntitySetTexture(box, tex1)
MP_PositionEntity(box, 0.0, 2.0, 0 )

MP_PhysicInit()

MP_EntityPhysicBody(sphere , 5, 20)
MP_ConstraintCreateHinge(sphere,0,1,0)
MP_EntityPhysicBody(box, 2, 0.5)
MP_EntityPhysicBody(ground, 1, 1)

;mp_wireframe(1) 
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
           
      MP_EntityAddImpulse(sphere, -0.6, 0, 0 ,  0, 0, 2.0)
      ;MP_TurnEntity (sphere, 0, 0.4, 0)
      
      MP_PhysicUpdate()
      MP_RenderWorld() ; Erstelle die Welt
      MP_Flip () ; Stelle Sie dar
     
    Wend

End
2- when we give the half sphere physics type 5 (for dynamic concave geometry) then dropping a cube inside it will float as if the half sphere still have a ground, but it will go on if the half sphere have physics of type 1 (static)
3- it appears that the number of triangles stay the same before and after the operations.
4- i have made a copy of the sphere

Code: Select all

For m = 0 To Triscount-1
   MP_AddTriangle(testSphere,Tris(m)\v1,Tris(m)\v2,Tris(m)\v3)
 Next
it display the same behaviour

Code: Select all

Structure bgraCol
  b.b
  g.b
  r.b
  a.b
 
EndStructure

Structure MyVertex_
    x.f : y.f : z.f    ; vertices coordinates
    nx.f : ny.f : nz.f ; normal coordinates
    Color.bgraCol            ; color
    u.f : v.f          ; texture coordinates
;    u1.f : v1.f          ; texture coordinates 2
;    u2.f : v2.f          ; texture coordinates 2
EndStructure
  
Structure MyTris
    v1.l : v2.l : v3.l    ; vertices coordinates
EndStructure
  
MP_Graphics3D (640, 480, 0, 3)
SetWindowTitle(0, "..not complete Half Sphere .. ")

camera = MP_CreateCamera() ; Kamera erstellen
light0 = MP_CreateLight(1)
MP_PositionEntity(light0, 0, 128, 0)
cam0 = MP_CreateCamera()
MP_PositionEntity(cam0, 0, 3, -3)
MP_EntityLookAt(cam0, 0, 1, 0)

tex0 = MP_CreateTextureColor(128, 128, RGBA(0, 255, 0, 0))
MP_MaterialEmissiveColor(tex0, 0, 122, 132, 132)
tex1 = MP_CreateTextureColor(128, 128, RGBA(25, 15, 255, 250))
MP_MaterialEmissiveColor(tex1, 0, 122, 132, 132)

sphere = MP_CreateSphere(16)
Triscount = MP_CountTriangles(sphere)
Debug "triangle counts before the operations over the sphere= "+ Str(Triscount)
MP_PositionEntity (sphere, 0, 1, 0)
vertexcount = MP_CountVertices(sphere)
vertexlenght = MP_GetMeshInfo (sphere, 64)
Triscount = MP_CountTriangles(sphere)
Dim Vert.MyVertex_ (vertexcount)
Dim Tris.MyTris (Triscount)

MP_GetMeshData(sphere, #PB_Mesh_Vertex,@Vert(),vertexlenght * vertexcount)
MP_GetMeshData(sphere, #PB_Mesh_Vertex |#PB_Mesh_Normal | #PB_Mesh_Color | #PB_Mesh_UVCoordinate  ,@Vert(),vertexlenght * vertexcount)
MP_GetMeshData(sphere, #PB_Mesh_Face,@Tris(),Triscount*12)

;ground = MP_CreateRectangle(5, 0.5, 5)
;MP_EntitySetTexture(ground, tex0)

testSphere = MP_CreateMesh()

; To look in the Tris
     ;For m = 0 To Triscount-1
      ; Debug "Tris = "+Str(m)
       ;Debug Tris(m)\v1
       ;Debug Tris(m)\v2
       ;Debug Tris(m)\v3
    ; Next 

For n = 0 To vertexcount-1
  MP_AddVertex(testSphere, Vert(n)\x,Vert(n)\y, Vert(n)\z, vert(n)\Color, Vert(n)\u, Vert(n)\v, vert(n)\nx, vert(n)\ny, vert(n)\nz)
  ;MP_AddVertex(testSphere, Vert(n)\x,Vert(n)\y, Vert(n)\z)
   If Vert(n)\y < 0
     For m = 0 To Triscount-1
       
       If Tris(m)\v1 = n : Tris(m)\v1 = 0 : Tris(m)\v2 = 0: Tris(m)\v3 = 0 :EndIf
       If Tris(m)\v2 = n : Tris(m)\v1 = 0 : Tris(m)\v2 = 0: Tris(m)\v3 = 0 :EndIf
       If Tris(m)\v3 = n : Tris(m)\v1 = 0 : Tris(m)\v2 = 0: Tris(m)\v3 = 0 :EndIf
       
     Next 
   EndIf
   
 Next
 
 For m = 0 To Triscount-1
   MP_AddTriangle(testSphere,Tris(m)\v1,Tris(m)\v2,Tris(m)\v3)
 Next
 
 MP_PositionEntity (testSphere, 0, 0, 0) 
 MP_EntitySetTexture(testSphere, tex0)
 MP_RotateEntity(testSphere, 0,0,180)
 ;Tr = MP_CountTriangles(testSphere)
 ;Debug Tr
 
MP_SetMeshData (sphere,  #PB_Mesh_Vertex |#PB_Mesh_Normal | #PB_Mesh_Color | #PB_Mesh_UVCoordinate , @Vert(), vertexcount)
MP_SetMeshData (sphere,  #PB_Mesh_Face , @Tris(), Triscount)
MP_PositionEntity (sphere, 0, 2.0, 0)
MP_RotateEntity(sphere, 0,0,180)
MP_PositionEntity (testSphere, 0, 0.5, 0)


texture =  MP_LoadTexture(#PB_Compiler_Home + "Examples\3D\Data\Textures\MRAMOR6X6.jpg")
MP_EntitySetTexture(sphere, texture)
MP_EntitySetTexture(testSphere, texture)

box = MP_CreateRectangle(0.2,0.2,0.2)
MP_EntitySetTexture(box, tex1)
MP_PositionEntity(box, 0.0, 2.0, 0 )

box2 = MP_CreateRectangle(0.2,0.2,0.2)
MP_EntitySetTexture(box2, tex0)
MP_PositionEntity(box2, 0.0, 1.0, 0 )

MP_PhysicInit()

MP_EntityPhysicBody(sphere , 5, 20)
MP_EntityPhysicBody(testSphere , 5, 20)
MP_ConstraintCreateHinge(sphere,0,1,0)
MP_ConstraintCreateHinge(testSphere,0,1,0)
MP_EntityPhysicBody(box, 2, 0.5)
MP_EntityPhysicBody(box2, 2, 0.5)
;MP_EntityPhysicBody(ground, 1, 1)

Triscount = MP_CountTriangles(sphere)
Debug "count after the operations = " +Str(Triscount)
Triscount = MP_CountTriangles(testSphere)
Debug "count of the copy at the screen bottom= "+Str(Triscount)
;mp_wireframe(1) 
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
  
      MP_EntityAddImpulse(Sphere, 0.6, 0, 0 ,  0, 0, 2.0)
      MP_EntityAddImpulse(testSphere, -0.6, 0, 0 ,  0, 0, 2.0)
      ;MP_TurnEntity (sphere, 0, 0.4, 0)
      
      MP_PhysicUpdate()
      MP_RenderWorld() ; Erstelle die Welt
      MP_Flip () ; Stelle Sie dar
     
    Wend

End
regarding the MP_SubTriangle and MP_SubVertex , every addition to the mesh functions will be great, i imagine it is may be like addSubMesh in PB ogre !! but not sure . but take your full time, we are not hurry
on the other hand : are there friction property for the joints in newton engine ??
such as: MP_ConstraintCreateHinge(sphere,0,1,0) and under a small force will rotate the sphere very rapidly unless we put some weight over it to make it rotate in regular speed.
thanks

Re: MP3D Engine Alpha 32

Posted: Tue May 26, 2015 2:41 pm
by applePi
Hi Michael, i have found that the floating cube over a hollow half sphere are not a special problem so no need to waste time for it, since the same phenomena happened with a hollow cup model with physics type 5, while when we give the model a physics type 1 the cube fall inside the cup and stay there. here is the cup2.x file
http://www.2shared.com/file/4IkCeNzW/cup2.html (click on the smaller download button and not the big one))
change physics type to 1 in line 79 to allow the cube to go inside the cup. the cup are downloaded from https://directxtk.codeplex.com/wikipage ... 0a%20model as obj file and converted it to dirctx (JT) x file using milkshape

Code: Select all

Structure bgraCol
  b.b
  g.b
  r.b
  a.b
 
EndStructure

Structure MyVertex_
    x.f : y.f : z.f    ; vertices coordinates
    nx.f : ny.f : nz.f ; normal coordinates
    Color.bgraCol            ; color
    u.f : v.f          ; texture coordinates
;    u1.f : v1.f          ; texture coordinates 2
;    u2.f : v2.f          ; texture coordinates 2
EndStructure

;#PB_Mesh_Vertex |#PB_Mesh_Normal | #PB_Mesh_Color | #PB_Mesh_UVCoordinate

Structure MyTris
    v1.l : v2.l : v3.l    ; vertices coordinates
EndStructure
  
MP_Graphics3D (640, 480, 0, 3)
SetWindowTitle(0, "..not complete Half Sphere .. ")

camera = MP_CreateCamera() ; Kamera erstellen
light0 = MP_CreateLight(1)
MP_PositionEntity(light0, 0, 128, 0)
cam0 = MP_CreateCamera()
MP_PositionEntity(cam0, 0, 3, -3)
MP_EntityLookAt(cam0, 0, 1, 0)

tex0 = MP_CreateTextureColor(128, 128, RGBA(0, 255, 0, 0))
MP_MaterialEmissiveColor(tex0, 0, 122, 132, 132)
tex1 = MP_CreateTextureColor(128, 128, RGBA(25, 15, 255, 250))
MP_MaterialEmissiveColor(tex1, 0, 122, 132, 132)

;sphere = MP_CreateSphere(16)
sphere = MP_LoadMesh("cup2.x")
MP_ResizeMesh(sphere,1.5,1.3,1.5)

MP_PositionEntity (sphere, 0, 1, 0)
vertexcount = MP_CountVertices(sphere)
vertexlenght = MP_GetMeshInfo (sphere, 64)
Triscount = MP_CountTriangles(sphere)
Dim Vert.MyVertex_ (vertexcount)
Dim Tris.MyTris (Triscount)

MP_GetMeshData(sphere, #PB_Mesh_Vertex,@Vert(),vertexlenght * vertexcount)
;MP_GetMeshData(sphere, #PB_Mesh_Vertex |#PB_Mesh_Normal | #PB_Mesh_Color | #PB_Mesh_UVCoordinate,@Vert(),vertexlenght * vertexcount)
MP_GetMeshData(sphere, #PB_Mesh_Face,@Tris(),Triscount*12)

;ground = MP_CreateRectangle(5, 0.5, 5)
;MP_EntitySetTexture(ground, tex0)

; To look in the Tris
;     For m = 0 To Triscount-1
;       Debug "Tris = "+Str(m)
;       Debug Tris(m)\v1
;       Debug Tris(m)\v2
;       Debug Tris(m)\v3
;     Next 


MP_PositionEntity (sphere, 0, 1.0, 0)
;MP_RotateEntity(sphere, 0,0,180)


texture =  MP_LoadTexture(#PB_Compiler_Home + "Examples\3D\Data\Textures\MRAMOR6X6.jpg")
MP_EntitySetTexture(sphere, texture)

box = MP_CreateRectangle(0.3,0.3,0.3)
MP_EntitySetTexture(box, tex1)
MP_PositionEntity(box, 0.0, 2.0, 0 )

MP_PhysicInit()

MP_EntityPhysicBody(sphere , 5, 20)
;MP_ChangePhysicHull(sphere,1) 
MP_ConstraintCreateHinge(sphere,0,1,0)
MP_EntityPhysicBody(box, 5, 0.1)
;MP_EntityPhysicBody(ground, 1, 1)

mp_wireframe(1) 
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
           
      MP_EntityAddImpulse(sphere, -0.6, 0, 0 ,  0, 0, 2.0)
      ;MP_TurnEntity (sphere, 0, 0.4, 0)
      
      MP_PhysicUpdate()
      MP_RenderWorld() ; Erstelle die Welt
      MP_Flip () ; Stelle Sie dar
     
    Wend

End
as we know the physics type 5 works okay as demonstrated in the pendulum example, and in Gears demos, and now i am trying to simulate geneva drive device.

Re: MP3D Engine Alpha 32

Posted: Wed May 27, 2015 9:45 am
by mpz
Hi Applepi,

Thanks for the information. I could not found a bug in my program, but it makes only a hull and not this kind of special object. I will ask in the newton dynamics forum about this problem. I hope they can help ...

Question: Is it possible to make these kind of Physical object in PB -Ogre ? Or has Ogre only a hull version?

Greetings Michael