Page 59 of 71

Re: MP3D Engine Alpha 32

Posted: Fri May 29, 2015 11:05 am
by applePi
Question: Is it possible to make these kind of Physical object in PB -Ogre ? Or has Ogre only a hull version?
Hi michael, i haven't noticed your question, my answer No, it is not possible, look my request here http://purebasic.fr/english/viewtopic.php?f=3&t=55916 to add dynamic compound object. in Bullet engine which PB depends on they said: compound shape , "Multiple convex shapes can be combined into a composite or compound shape, using the btCompoundShape This is a concave shape made out of convex sub parts, called child shapes. Each child shape has its own local offset transform, relative to the btCompoundShape. ." Bullet user manual but it is not implemented in PB version of Ogre/Bullet.
your engine have this feature as it is demonstrated by the gears and the pendulum examples which are posted first here
http://purebasic.fr/english/viewtopic.p ... &start=510
and corrected by you (to work with latest lib) here:
http://purebasic.fr/english/viewtopic.p ... 25#p458129
, and the example at the bottom of my post here
.

now i suggest to add joint with motor feature, this is in newton engine here:
https://github.com/MADEAPPS/newton-dyna ... 93&q=motor
i see several references to the motor such as "CUSTOM_JOINTS_API void EnableMotor_0(bool state); or SetMotorAcceleration etc

there is a motor in PB Ogre/bullet engine:
EnableHingeJointAngularMotor(#Joint, Enable, TargetVelocity, MaxMotorImpulse)
HingeJointMotorTarget(#Joint, Angle, Velocity)
i have provided example in http://www.forums.purebasic.com/english ... 36&t=54556
to move a slope with a joint which have motor very slowly. there are also in the PB official examples CarPhysic.pb demo, and PinBall.pb demo

the reason i ask this for MP3D, is that i am trying to simulate Geneva drive https://www.youtube.com/watch?v=OZiPxV-_oaY
which convert continuous rotation to intermittent rotation
i have made a partially geneva drive example which success sometimes for a few rotations since i can't restrict sphere from not accelerating to high speed, i need a motor for it so it moves in regular speed not by MP_EntityAddImpulse alone over the hinge joint but also with motor own specification such as TargetVelocity, MaxMotorImpulse etc).

Image

code need the latest mp3d lib to replace the older one: http://purebasic.fr/english/viewtopic.p ... 70#p465650

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
  
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

light= MP_CreateLight(2)    ; Es werde Licht
MP_PositionEntity(light, -10, 10, 0)
MP_AmbientSetLight (RGB(0,100,200))

cam0 = MP_CreateCamera()
;MP_PositionEntity(cam0, 0, 10, -3)
;MP_PositionEntity(cam0, 0, 1, -6)
MP_PositionEntity(cam0, 0, 3, -7)
MP_EntityLookAt(cam0, 0, 0, 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)


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, 0)
;mp_wireframe(1)     
MP_EntitySetTexture(sphere, tex1)
MP_RotateMesh(sphere , -90 , 0, 180)
MP_ResizeMesh(sphere,1,1,1)
hand = MP_CreateCylinder(5,0.2)
MP_ResizeMesh(hand,0.2,0.2,0.8)
MP_RotateMesh(hand , 90 , 0, 0)
;MP_TranslateMesh(hand,0.1, -0.3, -1.3 )
MP_TranslateMesh(hand,0.1, -0.3, -0.8 )
MP_AddMesh(hand , sphere ) : MP_FreeEntity(hand)
MP_PositionEntity(sphere, 0, 0.5, -0.8)

;;0000000000000000000000000000000000000000000000000000000000000000000000
Mesh = MP_CreateCylinder(10,0.2)
MP_ResizeMesh(Mesh,0.5,0.5,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)
;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

Mesh2 = MP_CreateRectangle (2,0.5,0.1)
MP_TranslateMesh(Mesh2,0.0,0.2,-0.2)
MP_AddMesh(Mesh2 , Mesh ) : MP_FreeEntity(Mesh2)

Mesh2 = MP_CreateRectangle (2,0.5,0.1)
MP_TranslateMesh(Mesh2,0.0,0.2,0.2)
MP_RotateMesh(Mesh2 , 0 , 90, 0)
MP_AddMesh(Mesh2 , Mesh ) : MP_FreeEntity(Mesh2)
Mesh2 = MP_CreateRectangle (2,0.5,0.1)
MP_TranslateMesh(Mesh2,0.0,0.2,-0.2)
MP_RotateMesh(Mesh2 , 0 , 90, 0)

MP_AddMesh(Mesh2 , Mesh ) : MP_FreeEntity(Mesh2)
Mesh2 = MP_CreateRectangle (2,0.5,0.1)
MP_TranslateMesh(Mesh2,0.0,0.2,0.2)
MP_AddMesh(Mesh2 , Mesh ) : MP_FreeEntity(Mesh2)

;MP_RotateMesh(Mesh , 90 , 0, 0)
MP_EntitySetNormals (Mesh)
MP_MaterialDiffuseColor (Mesh,255,255,255,50)
MP_MaterialSpecularColor (Mesh, 255, 255 ,255, 155,5)

MP_EntitySetTexture(Mesh, tex0)
MP_PositionEntity(Mesh, 0, 0, -2)

MP_RotateEntity(sphere, 0, -90, 0 )
MP_RotateEntity(Mesh, 0, 38, 0 )

;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
MP_PhysicInit()

MP_EntityPhysicBody(sphere , 5, 10)
MP_EntityPhysicBody(Mesh , 5, 10)
MP_ConstraintCreateHinge (sphere,0,1,0, 0,0,0)
MP_ConstraintCreateHinge (Mesh,0,1,0, 0.0,0.0,0)



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

End
Edit: as a guide for using the motor with PB Ogre/Bullet:
we use hinge joint
we EnableHingeJointAngularMotor for that specific hinge joint
we apply force with ApplyEntityImpulse
here the force will be subjected to the limits specified in the EnableHingeJointAngularMotor(#Joint, Enable, TargetVelocity, MaxMotorImpulse)

here is an example, press z to speed the wheel rotation. press x to decrease the wheel rotation
note that we can't make gears here but only wheels

Code: Select all

Enumeration
   #MESH = 100
   #LIGHT
   #camera
   #mainwin
   #plane
   #node
   #wheel
   #wheel2
 EndEnumeration
Global width=20, length=20
Global zcam.f, xcam.f, ycam.f, rotate.b, camRo.f, camZ = 20



ExamineDesktops()
If OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "Z for speed , X to slow down the wheel, arrows to Camera rotate/zoom. W for wire/solid frame", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
;Initialize environment
InitEngine3D()
InitSprite()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0)-6, 0, 0, 0)

InitKeyboard()
SetFrameRate(60)

Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/Sources\Data", #PB_3DArchive_FileSystem)

CreateLight(#LIGHT,RGB(22,222,0),0,-4,0,#PB_Light_Directional )
LightLookAt(#LIGHT, 0, 4, -5)

CreateCamera(#camera, 0, 0, 100, 100)
MoveCamera(#camera, 0, 2, 20)
CameraLookAt(#camera, 0, 2, 0)

EndIf

;SkyDome("clouds.jpg", 100) ;for blue color background
CreateMaterial(2, LoadTexture(2, "Geebee2.bmp"))
CreateSphere(3, 0.5)
CreateEntity(3, MeshID(3), MaterialID(2), -6,  6, 2)

CreateSphere(4, 0.5)
CreateEntity(4, MeshID(4), MaterialID(2), 1,  4, 0)
EntityPhysicBody(3, #PB_Entity_StaticBody)
EntityPhysicBody(4, #PB_Entity_StaticBody)

CreateMaterial(0, LoadTexture(0, "terrain_texture.jpg"))
DisableMaterialLighting(0, #True)
MaterialCullingMode(0, #PB_Material_NoCulling)

CreateCylinder(#wheel,2,1)
NormalizeMesh(#wheel)

CreateEntity(#wheel, MeshID(#wheel), MaterialID(0), -6.7,  4, -1) 
CreateEntity(#wheel, MeshID(#wheel), MaterialID(0), -6.7,  4, -1) 
RotateEntity(#wheel,0,90,0)
EntityPhysicBody(#wheel, #PB_Entity_CylinderBody    , 1.0)
EntityLinearFactor(#wheel, 0, 1, 0)
HingeJoint(1,EntityID(3),0,0,-0.2, 0,0,1, EntityID(#wheel),0,0,0, 0,1,0)
EnableHingeJointAngularMotor(1, #True, 2, 50)
;;;;;;;;;;;;;;
CreateCylinder(#wheel2,2,1)
NormalizeMesh(#wheel2)

CreateEntity(#wheel2, MeshID(#wheel2), MaterialID(0), -0.5,  4, -7) 
ScaleEntity(#wheel2,3,2,3)
EntityPhysicBody(#wheel2, #PB_Entity_CylinderBody  , 1.0)
HingeJoint(2,EntityID(4),0,0,-0.2, 0,0,1, EntityID(#wheel2),0,0,0, 0,1,0)
EnableHingeJointAngularMotor(2, #False, 2, 50) ; note that it is false

speed.f=2
;SetEntityAttribute(1, #PB_Entity_Friction , 10)
CreateMesh(#plane,#PB_Mesh_TriangleList ,#PB_Mesh_Static)
t=0
CreateNode(#node, 0,2,-3)
AttachNodeObject(#node, CameraID(#camera))
;WorldGravity(0)
;WorldDebug(#PB_World_DebugBody)
Repeat
  Event = WindowEvent()
  
  If stopFlag=1
    x + rotx
    y + roty
    z + rotz
  EndIf
   
   RenderWorld()
   FlipBuffers()

   ExamineKeyboard()
   If KeyboardPushed(#PB_Key_Z )
     ApplyEntityImpulse(#wheel,  10, 10, 10,  3,3,3)
     speed=speed+0.1
     If speed > 30: speed = 25:EndIf  
     EnableHingeJointAngularMotor(1, #True, speed, 50)
   ElseIf KeyboardPushed(#PB_Key_X)
     
     speed=speed-0.1
     ;If speed <0: speed=0:EndIf 
     EnableHingeJointAngularMotor(1, #True, speed, 50)
     
   EndIf
   
   If KeyboardReleased(#PB_Key_W) ; display wire frame for the material
      If wireFrame=0
      MaterialShadingMode(0, #PB_Material_Wireframe)
      wireFrame ! 1
         ElseIf wireFrame=1
           MaterialShadingMode(0, #PB_Material_Solid)
           wireFrame ! 1
      EndIf
    EndIf
           
    If KeyboardReleased(#PB_Key_Left)
      rotate ! 1
      camRo = -0.4
      ElseIf KeyboardReleased(#PB_Key_Right)
      rotate ! 1
      camRo = 0.4
    EndIf  
    If KeyboardPushed(#PB_Key_Down)
      camZ=camZ+1
      MoveCamera(#camera, 0, 2, camZ,#PB_Absolute)
      ElseIf KeyboardPushed(#PB_Key_Up)
      camZ=camZ-1
      MoveCamera(#camera, 0, 2, camZ,#PB_Absolute)
     EndIf 
      
    
    If rotate
      RotateNode(#node, 0, camRo, 0, #PB_Relative)
      Else
      RotateNode(#node, 0, 0, 0, #PB_Relative)
    EndIf 
    
    
            
Until KeyboardPushed(#PB_Key_Escape) Or Event = #PB_Event_CloseWindow

Re: MP3D Engine Alpha 32

Posted: Sun May 31, 2015 3:34 pm
by [blendman]
Hi

I have tried to install the mp3d lib for pb5.22LTS (not the 5.24), I have download the installer and I have some error (on some examples files).
But when I'm trying to compile a mp3D example, purebasic tell me "this lib is too old to work with purebasic".

How can I install this lib on win8 with pb 5.22 (or+) ?

Thank you for your answer.

Re: MP3D Engine Alpha 32

Posted: Thu Jun 04, 2015 12:16 pm
by mpz
Hi blendman,

i have checleh this an dfound a problem. If i make with PB 5.31 and Tailbite a lib you cant use it in PB 5.22/5.24. The error message "this lib is too old to work with purebasic" appears. If i make a lib with PB 5.24 and Tailbite i can use it in PB 5.22/5.24 and 5.31. Please test this:

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

Greetings Michael

Re: MP3D Engine Alpha 32

Posted: Thu Jun 04, 2015 11:15 pm
by mpz
Hi applePi,

i have looked in the code an have found some nice information:

1) the commands MP_FreeTriangle ( Entity, Index) and MP_FreeVertex ( Entity ,Index) are integrated since a long time, i had this information forgotten (too much commands :))

I have checked the "Compound Collision" and it works not good for your examples. So i have rewritten two new function parts:

MP_EntityPhysicBody(Entity , Typ, mass.f), the Typ = 5 and the Typ = 6. "Compound Collision" is dependent on the direction of rotation of the triangles
Thas means the Typ 5 is the normal mesh triangle rotation and the Typ 6 is the contrary rotation of the triangles.

For example, with typ 5 the entity is going in the sphere, but cant get out and with the typ 6 the entity is springing away from the sphere.

I changed your example code a little bit code. You must adjust the path of you "cup2.x" file = MP_LoadMesh("c:\temp\cup2.x")

You can choose: #CupOn = 0/1, MP_EntityPhysicBody(sphere , 5/6 , 20) and mp_wireframe(1) on/off

Image

Code: Select all

 
 
MP_Graphics3D (640, 480, 0, 3)
SetWindowTitle(0, "new Physic commands .. ")

#CupOn = 0

camera = MP_CreateCamera() 
light0 = MP_CreateLight(1)
MP_PositionEntity(light0, 0, 128, 0)
cam0 = MP_CreateCamera()
MP_PositionEntity(cam0, 0, 8, -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, 15, 255, 250))
MP_MaterialEmissiveColor(tex1, 0, 122, 132, 132)

If #CupOn
  sphere = MP_LoadMesh("c:\temp\cup2.x")
  MP_ResizeMesh(sphere,1.5,1.3,1.5)
Else 
  sphere = MP_CreateSphere(16)
EndIf

MP_PositionEntity (sphere, 0, 1.5, 0)

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



If #CupOn = 0
  
  Debug "on"
  
   Debug MP_CountVertices(sphere)
  
 MP_PositionEntity(cam0, 0, 4, -5) ; to look better
 MP_EntityLookAt(cam0, 0, 1, 0)
 
 ; Create HalveSphere from Sphere
 For n = 0 To  MP_CountVertices(sphere)-1
   
   Debug MP_VertexGetY(sphere, n) 
   
  If MP_VertexGetY(sphere, n) < 0 
     Debug "§ !"  
    MP_VertexSetY(sphere, n, -MP_VertexGetY(sphere, n)/2 )
    
  EndIf
 Next
 MP_RotateEntity(sphere, 0,0,180)
 
EndIf 

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.5, 2.0, 0 )

MP_PhysicInit()

MP_EntityPhysicBody(sphere , 5, 20) ;  Use for testing MP_EntityPhysicBody(sphere , 6, 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_PhysicUpdate()
      MP_RenderWorld() ; Erstelle die Welt
      MP_Flip () ; Stelle Sie dar
     
Wend

End
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

Greetings Michael

Re: MP3D Engine Alpha 32

Posted: Fri Jun 05, 2015 1:00 pm
by applePi
this is very useful update, thank you Michael very much, we now can deal with dynamic cavities physically. i have used your update with type 5 to make a classic two pan balance.
drop cubes at left or right pan

Code: Select all

Declare dropWeight(pos.f)
MP_Graphics3D (640, 480, 0, 3)
SetWindowTitle(0, "X/Z ..to drop weights on left and right pans .. ")

#CupOn = 0

camera = MP_CreateCamera() 
light0 = MP_CreateLight(1)
MP_PositionEntity(light0, 0, 128, 0)
cam0 = MP_CreateCamera()
MP_PositionEntity(cam0, 0, 10, -4)
MP_EntityLookAt(cam0, 0, 2, 0)

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

tex2 =  MP_LoadTexture(#PB_Compiler_Home + "Examples\3D\Data\Textures\MRAMOR6X6.jpg")
If #CupOn
  sphere = MP_LoadMesh("cup2.x")
  MP_ResizeMesh(sphere,1.5,1.3,1.5)
Else 
  sphere = MP_CreateSphere(16)
EndIf
;MP_AddUVtoEntity(sphere)

MP_EntitySetTexture(sphere, tex2)
MP_PositionEntity (sphere, 1.7, 1.5, 0)

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


If #CupOn = 0
  
  ;Debug "on"
  
   ;Debug MP_CountVertices(sphere)
  
 MP_PositionEntity(cam0, 0, 5, -5) ; to look better
 MP_EntityLookAt(cam0, 0, 1, 0)
 
 ; Create HalveSphere from Sphere
 For n = 0 To  MP_CountVertices(sphere)/2
   
   ;Debug MP_VertexGetY(sphere, n) 
   
  If MP_VertexGetY(sphere, n) < 0
     ;Debug "§ !"  
    MP_VertexSetY(sphere, n, -MP_VertexGetY(sphere, n)/2 )
    
  EndIf
 Next
 MP_RotateEntity(sphere, 0,0,180)
 
EndIf 

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

sphere2 = MP_CopyEntity(sphere)
MP_PositionEntity (sphere2, -1.7, 1.5, 0)

beam = MP_CreateRectangle(4,0.2,0.2)
MP_EntitySetTexture(beam, tex2)
MP_PositionEntity(beam, 0.0, 2.0, 0 )


MP_RotateMesh(sphere , 0 , 0, 180)
MP_TranslateMesh(sphere,1.7, 1,0)
MP_AddMesh(sphere, beam)
MP_FreeEntity(sphere)

MP_RotateMesh(sphere2 , 0 , 0, 180)
MP_TranslateMesh(sphere2,-1.7, 1,0)
MP_AddMesh(sphere2, beam)
MP_FreeEntity(sphere2)

MP_PositionEntity(beam, 0.0, 1.0, 0 )

MP_PhysicInit()

MP_EntityPhysicBody(sphere , 5, 20) ;  Use for testing MP_EntityPhysicBody(sphere , 6, 20)
MP_EntityPhysicBody(sphere2 , 5, 20)
MP_EntityPhysicBody(beam, 2, 0.5)
; Hinge
MP_ConstraintCreateHinge(beam,0,0,1)
MP_EntityPhysicBody(ground, 1, 1)

;weights
box = MP_CreateRectangle(0.2,0.2,0.2)
MP_EntitySetTexture(box, tex1)
MP_PositionEntity(box, -1.7, 1.7, 0 )
;MP_EntityPhysicBody(box, 2, 0.02)
 ;mp_wireframe(1)

While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
           
      ;MP_EntityAddImpulse(beam, -0.1, 0, 0 ,  0, 0, 2.0)
  If MP_KeyHit(#PB_Key_X) 
    dropWeight(1.7)
  ElseIf MP_KeyHit(#PB_Key_Z) 
    dropWeight(-1.7)
  EndIf  


      MP_PhysicUpdate()
      MP_RenderWorld() ; Erstelle die Welt
      MP_Flip () ; Stelle Sie dar
     
Wend

End

Procedure dropWeight(pos.f)
  box = MP_CreateRectangle(0.2,0.2,0.2)
  MP_EntitySetTexture(box, tex1)
  MP_PositionEntity(box, pos.f, 2.7, 0 )
  MP_EntityPhysicBody(box, 2, 0.2)
   
   EndProcedure
   
i will search for a thick concave pan model to test it with the balance.

the second example i have used type 6 to put a cube inside the sphere, by changing this
If MP_VertexGetY(sphere, n) < -1
i don't understand why this happened but it produce a usable hollow sphere with a cube inside

Code: Select all

MP_Graphics3D (640, 480, 0, 3)
SetWindowTitle(0, "new Physic commands .. ")

#CupOn = 0

camera = MP_CreateCamera() 
light0 = MP_CreateLight(1)
MP_PositionEntity(light0, 0, 128, 0)
cam0 = MP_CreateCamera()
MP_PositionEntity(cam0, 0, 8, -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, 15, 255, 250))
MP_MaterialEmissiveColor(tex1, 0, 122, 132, 132)

tex2 =  MP_LoadTexture(#PB_Compiler_Home + "Examples\3D\Data\Textures\MRAMOR6X6.jpg")
If #CupOn
  sphere = MP_LoadMesh("cup2.x")
  MP_ResizeMesh(sphere,1.5,1.3,1.5)
Else 
  sphere = MP_CreateSphere(16)
EndIf
;MP_AddUVtoEntity(sphere)

MP_EntitySetTexture(sphere, tex2)
MP_PositionEntity (sphere, 0, 1.5, 0)

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



If #CupOn = 0
  
  ;Debug "on"
  
   ;Debug MP_CountVertices(sphere)
  
 MP_PositionEntity(cam0, 0, 4, -5) ; to look better
 MP_EntityLookAt(cam0, 0, 1, 0)
 
 ; Create HalveSphere from Sphere
 For n = 0 To  MP_CountVertices(sphere)-1
   
   ;Debug MP_VertexGetY(sphere, n) 
   
  If MP_VertexGetY(sphere, n) < -1
     ;Debug "§ !"  
    MP_VertexSetY(sphere, n, -MP_VertexGetY(sphere, n)/2 )
    
  EndIf
 Next
 MP_RotateEntity(sphere, 0,0,180)
 
EndIf 

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.2, 1.5, 0 )

MP_PhysicInit()

MP_EntityPhysicBody(sphere , 6, 20) ;  Use for testing MP_EntityPhysicBody(sphere , 6, 20)

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

;For i= MP_CountTriangles(sphere) To 200 Step-1
 ; MP_FreeTriangle(sphere,i)
;Next

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_PhysicUpdate()
      MP_RenderWorld() ; Erstelle die Welt
      MP_Flip () ; Stelle Sie dar
     
Wend

End
now look at this:
uncomment lines 74 to 76
For i= MP_CountTriangles(sphere) To 200 Step-1
MP_FreeTriangle(sphere,i)
Next


this will delete most bottom triangles, but it appears the deletion are only visual and not real since the cube behave as it is still inside the whole sphere

at last: the pendulum example as corrected by you here http://purebasic.fr/english/viewtopic.p ... 25#p458129 does not work now correctly like in the previous Lib. i am still looking where it is stuck. in the previous Lib it works okay.

Re: MP3D Engine Alpha 32

Posted: Fri Jun 05, 2015 2:31 pm
by mpz
Hi applePi,

i think it is better to activate the old physic funktion as typ 5 an the both new functions as Typ 6 and 7. I will make a function to change the standard parameters of the Newton Dynamics command = CreateApproximateConvexDecomposition (mesh, maxConcavity.f, backFaceDistanceFactor.f, maxCount, maxVertexPerHull). Then ist is possible to make the physic better

"a usable hollow sphere" -> The command MP_EntityPhysicBody(mesh, typ = 5/6, mass) got the triangles of the mesh. If you delete later the triangles, the newton command doesnot know this and so the physic was not changing. The command to change this is MP_ChangePhysicHull (Entity, Typ). But before you use this comamnd i must integrate the the Typ 5/6/7. The new lib with this function comming soon...

Greetings Michael

Re: MP3D Engine Alpha 32

Posted: Mon Jun 08, 2015 1:46 pm
by Psychophanta
Hi mpz,
I believe i've found a little bug in MOVEEntity.
The piece of code shows it. Load any Skybox of your own.
The matter is that with this code all goes like a charm, but if you remark line
MP_EntitySetZ(cam,MP_EntityGetZ(cam)+mdw)
unremarking line:
; MP_MoveEntity(cam,0,0,mdw)
then the skybox flashes at the background.

Code: Select all

Define .f
ExamineDesktops()
Global bitplanes.a=DesktopDepth(0),RX.u=1280,RY.u=720:MP_Graphics3DWindow(0,0,RX,RY,"Aristos map maker",#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SystemMenu):MP_VSync(1)

Global light.i=MP_CreateLight(2)
MP_LightSetColor(light,$BAE6EB)
MP_PositionEntity(light,-6,10,-5)
MP_AmbientSetLight($e8e890)
Global pivotcam.i=MP_CreateMesh():cam.i=MP_CreateCamera()
MP_EntitySetParent(cam,pivotcam,0)
MP_PositionEntity(cam,0,0,-4)

MP_CreateSkyBox("..\media\skyboxsun25degtest","jpg",100)

Global solido.i=MP_CreateCylinder(80,1)
MP_RotateMesh(solido,-90,0,0)
MP_ScaleMesh(solido,1,0.2,1)

MP_EntitySetColor(solido,$f7db8a)

MP_UseCursor(0)

While MP_KeyUp(#PB_Key_Escape) And WindowEvent()<>#PB_Event_CloseWindow
;   MP_TurnEntity(solido,0,3,0,1)
  mdw=MP_MouseDeltaWheel()/400:mdx=MP_MouseDeltaX():mdy=MP_MouseDeltaY()
  If MP_KeyDown(#PB_Key_LeftControl)
    MP_TurnEntity(pivotcam,mdy,mdx,0,0)
    If mdw
      MP_EntitySetZ(cam,MP_EntityGetZ(cam)+mdw)
;       MP_MoveEntity(cam,0,0,mdw)
    EndIf
  EndIf
  MP_RenderWorld()
  MP_Flip():Delay(9)
Wend

Re: MP3D Engine Alpha 32

Posted: Mon Jun 15, 2015 9:04 pm
by mpz
Hello,

@ applePi i have made 3 new Types for
EntityPhysicBody (Entity, Type, mass.f)

Type = 5 -> old collision typ and your clock demo works fine again. It work only for little modells with only some triangles
and now Typ = 6 and the Typ = 7. "Compound Collision" is dependent on the direction of rotation of the triangles

Please test it...

@Psychophanta

thanks for !bugging! I found the bug in MP_MoveEntity(camera,0,0,mdw), now it works...


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

Greetings Michael

Re: MP3D Engine Alpha 32

Posted: Tue Jun 16, 2015 9:00 pm
by applePi
Hi Michael
i am still testing the new update, but i say that the clock Pendulum http://purebasic.fr/english/viewtopic.p ... 25#p458129 works perfect and better than previously. so i guess the Gears will be also fine, i will test Gears later.
regarding the physics type 7 : it seems suitable for deleting triangles with MP_FreeTriangle such as this sphere we have deleted the above 224 triangles so other balls/cube can go through, and arbitrarily we have deleted successfully a strip of triangles
i will do more tests, thanks for the Update.

Code: Select all

MP_Graphics3D (640, 480, 0, 3)
SetWindowTitle(0, "Space to stop the Impulse on sphere ... W: toggle wireFrame/Solid frame ")

camera = MP_CreateCamera() 
light0 = MP_CreateLight(1)
MP_PositionEntity(light0, 0, 128, 0)
cam0 = MP_CreateCamera()
MP_PositionEntity(cam0, 0, 8, -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, 15, 255, 250))
MP_MaterialEmissiveColor(tex1, 0, 122, 132, 132)

tex2 =  MP_LoadTexture(#PB_Compiler_Home + "Examples\3D\Data\Textures\MRAMOR6X6.jpg")

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

sphere = MP_CreateSphere(16)

MP_EntitySetTexture(sphere, tex2)
MP_PositionEntity (sphere, 0, 1.5, 0)

;Debug MP_CountVertices(sphere)
;Debug MP_CountTriangles(sphere)
  
 MP_PositionEntity(cam0, 0, 4, -5) ; to look better
 MP_EntityLookAt(cam0, 0, 1, 0)
 
 
 ;free 224 triangles from top to bottom
For i= MP_CountTriangles(sphere) To 737 Step -1
 
  MP_FreeTriangle(sphere,i)
Next


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

MP_PhysicInit()


For i= 600 To 545 Step -1
  MP_FreeTriangle(sphere,i)
  
Next


MP_EntityPhysicBody(sphere , 7, 20) ;  Use for testing MP_EntityPhysicBody(sphere , 6, 20)
;MP_ChangePhysicHull(sphere, 7)

MP_ConstraintCreateHinge(sphere,0,1,0)
MP_EntityPhysicBody(ground, 1, 1)

Dim ball(40)
For i=0 To 40 
ball(i) = MP_CreateSphere(16)
MP_ResizeMesh(ball(i),0.35,0.35,0.35)
MP_EntitySetTexture(ball(i), tex1)
MP_PositionEntity(ball(i), 0, Random(20, 1), 0 )
MP_EntityPhysicBody(ball(i), 3, 0.05)
MP_EntitySetGravity(ball(i), 0 , -5 ,0)
Next

sign = MP_CreateRectangle(0.1,0.1,0.1) ; to show there is an Impulse on the sphere
MP_PositionEntity(sign, 1.5, 1.0, 0 )
MP_HideEntity(sign, 0)

rot = 1 : forceX.f = 0.5 : wireFrame = 1
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
           
      MP_EntityAddImpulse(sphere, forceX, 0, 0 ,  0, 0, 2.0)
            
      If MP_KeyHit(#PB_Key_Space)
          If rot
          forceX.f = 0
          rot ! 1 : MP_HideEntity(sign, 1)
            Else 
          forceX.f = 0.5
          rot ! 1 : MP_HideEntity(sign, 0)
       EndIf
      EndIf
      
      If MP_KeyHit(#PB_Key_W)
        
          mp_wireframe(wireFrame)
          wireFrame ! 1
            
       EndIf
      
      MP_PhysicUpdate()
      MP_RenderWorld() ; Erstelle die Welt
      MP_Flip () ; Stelle Sie dar
     
Wend

End

Re: MP3D Engine Alpha 32

Posted: Thu Jun 18, 2015 8:53 am
by applePi
how to texture a submesh differently than the mother mesh
as an example this pendulum clock (still on production research dept. ) i have added gearSmall to the main Mesh
MP_AddMesh(gearSmall , Mesh ) :MP_FreeEntity(gearSmall)
but now the gearSmall is part of the Mesh and get its color and texture
and want to texture the gearSmall differently ??
use the mouse and arrow keys to rotate and zoom camera

Code: Select all

#CameraSpeed = 0.1


Define.f KeyX, KeyY, MouseX, MouseY

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, "press Space for Impulse , Z for more testing ... Mouse+arrow keys to rotate/zoom camera")

camera = MP_CreateCamera()    ; Kamera erstellen

MP_PositionEntity(camera, -7, 0, 7 )
;MP_PositionEntity(camera, 5, 0, -1 )
MP_EntityLookAt(camera,0,0,0)

light= MP_CreateLight(0)    ; Es werde Licht
light2= MP_CreateLight(0) 
MP_PositionEntity (light2,100,10,100)
MP_EntityLookAt(light2,0,0,0)
MP_AmbientSetLight (RGB(0,100,200))

;construction of a gear with 18 teeth
ang=40 ; the angle wanted for every tooth of the gear
Mesh = MP_CreateCylinder(10,0.2)
For i=1 To 18
angle.f+20
x.f = Cos(Radian(angle)) * 1: z.f = Sin(Radian(angle)) * 1
;Debug StrF(x)+"    " +StrF(z)
Mesh2 = MP_CreateRectangle (0.5,0.05,0.2)

ang+20
;MP_RotateMesh(Mesh2 , 0 , 0, ang)
MP_RotateMesh(Mesh2 , 0 , 0, ang)
MP_TranslateMesh(Mesh2,x,z,0)


MP_AddMesh(Mesh2 , Mesh ) : MP_FreeEntity(Mesh2)
Next

MP_EntitySetNormals (Mesh)
MP_MaterialDiffuseColor (Mesh,255,255,255,50)
MP_MaterialSpecularColor (Mesh, 255, 255 ,255, 155,5)
;MP_MeshSetAlpha(Mesh, 1)

escape = MP_CreateRectangle (1.5,0.05,0.2) ;the rod above the gear teeth

escape2 = MP_CreateRectangle (0.5,0.05,0.2) ; the right small piece attached to the rod

MP_RotateMesh(escape2 , 0 , 0, 90)
MP_TranslateMesh(escape2, 0.7, -0.1, 0)

MP_AddMesh(escape2 , escape ) : MP_FreeEntity(escape2)

escape2 = MP_CreateRectangle (0.5,0.05,0.2) ; the left small piece attached to the rod

MP_RotateMesh(escape2 , 0 , 0, -100)
MP_TranslateMesh(escape2, -0.7, -0.1, 0)

MP_AddMesh(escape2 , escape ) : MP_FreeEntity(escape2)

; pendulum
Mesh7 = MP_CreateRectangle (0.05,2.5,0.05)

MP_TranslateMesh(Mesh7, 0, -1.3, -0.3)

MP_AddMesh(Mesh7 , escape ) :MP_FreeEntity(Mesh7)

sphere = MP_CreateSphere(10)
MP_ResizeMesh(sphere,0.5,0.5,0.3)

MP_TranslateMesh(sphere, 0, -2.3,  -0.5)



; repositioning of the rod and its 2 attached pieces above the gear teeth
MP_PositionEntity (escape, 0, 1.35, 0) ; repositioning of the rod and its 2 attached pieces above the gear teeth

MP_EntitySetNormals (escape)
MP_MaterialDiffuseColor (escape,255,33,255,50)
MP_MaterialSpecularColor (escape, 255, 255 ,255, 155,5)

MP_PhysicInit()

MP_AddMesh(sphere , escape ) :MP_FreeEntity(sphere)

MP_EntityPhysicBody(escape , 5, 2)
;MP_ConstraintCreateHinge(Entity, PinX.f, PinY.f, PinZ.f [, Pivotx.f, Pivoty.f, Pivotz.f [, MasterEntity]]); create a Hinge joint functions
MP_ConstraintCreateHinge (escape,0,0,1)

MP_EntityPhysicBody(Mesh , 5, 10)
MP_ConstraintCreateHinge (Mesh,0,0,1)

;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
;construction of a gear with 18 teeth
angle.f = 0
ang=0 ; the angle wanted for every tooth of the gear
gearSmall = MP_CreateCylinder(10,0.2)
MP_ScaleMesh(gearSmall, 0.5,0.5,0.5)
MP_TranslateMesh(gearSmall,0,0,1)

For i=1 To 18
angle.f+20
x.f = Cos(Radian(angle)) * 0.5: z.f = Sin(Radian(angle)) * 0.5

Blade = MP_CreateRectangle (0.5,0.05,0.2)

ang+20

MP_RotateMesh(Blade , 0 , 0, ang)
MP_TranslateMesh(Blade,x,z,0)
MP_TranslateMesh(Blade,0,0,1)

MP_AddMesh(Blade , gearSmall ) : MP_FreeEntity(Blade)
Next

MP_AddMesh(gearSmall , Mesh ) :MP_FreeEntity(gearSmall)
;000000000000000000000000000000000000000000000000000000000000000000

;construction of a big gear with 36 teeth
angle.f = 0
ang=0 ; the angle wanted for every tooth of the gear
BigGear = MP_CreateCylinder(10,0.2)
MP_ResizeMesh(BigGear, 2.5,2.5,0.5)
;MP_TranslateMesh(BigGear,0,0,2)
;MP_TranslateMesh(BigGear,3,0,0)

For i=1 To 36
angle.f+10
x.f = Cos(Radian(angle)) * 1.5: z.f = Sin(Radian(angle)) * 1.5

Blade2 = MP_CreateRectangle (0.5,0.05,0.2)

ang+10

MP_RotateMesh(Blade2 , 0 , 0, ang)
MP_TranslateMesh(Blade2,x,z,0)

MP_AddMesh(Blade2 , BigGear ) : MP_FreeEntity(Blade2)
Next

MP_PositionEntity (BigGear, 2.9, 0, 1)
;MP_PositionEntity (BigGear, 2.4, 0, 1)
MP_EntityPhysicBody(BigGear , 5, 1)
MP_ConstraintCreateHinge (BigGear,0,0,1)

;222222222222222222222222222222222222222222222222222222222222222222
;InitMouse()
Procedure.f MP_EntityDistance(c,o)
  Protected vx.f=MP_EntityGetX(o)-MP_EntityGetX(c),vy.f=MP_EntityGetY(o)-MP_EntityGetY(c),vz.f=MP_EntityGetZ(o)-MP_EntityGetZ(c)
  ProcedureReturn Sqr(vx*vx+vy*vy+vz*vz)
EndProcedure

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'.
  MP_MoveEntity(c,dx,dy,0)
  MP_PointEntity(c,o)
  MP_MoveEntity(c,0,0,Sqr(dx*dx+dy*dy+r*r)-r+dz)
  
EndProcedure
m.f=MP_EntityDistance(camera,mesh)

While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
    Event = WindowEvent()
  ;If ExamineMouse()
  
        ;MouseX.f = -MP_MouseDeltaX()/100
        ;MouseY.f = -MP_MouseDeltaY()/100
        Orbitar(camera,-MP_MouseDeltaX()/20,MP_MouseDeltaY()/20,MP_MouseDeltaWheel()/3,mesh,m)
        ;MP_RotateEntity(camera, MouseY, MouseX, 0)
        ;MP_RotateEntity(camera, 0, 0, 0, 0)
   ;EndIf
      
           
        If MP_KeyDown(#PB_Key_Left)
          KeyX = -#CameraSpeed
        ElseIf MP_KeyDown(#PB_Key_Right)
          KeyX = #CameraSpeed
        Else
          KeyX = 0
          MP_MoveEntity(camera, KeyX, 0, KeyY)
        EndIf
        
        If MP_KeyDown(#PB_Key_Down)
          KeyY = -#CameraSpeed
        ElseIf MP_KeyDown(#PB_Key_Up)
          KeyY = #CameraSpeed
        Else
          KeyY = 0
          MP_MoveEntity(camera, KeyX, 0, KeyY)
        EndIf
        
    MP_EntityAddImpulse(Mesh, 0, -0.5, 0 , -1.7,0, 0)
   
   If MP_KeyHit(#PB_Key_Space)
          MP_EntityAddImpulse(escape, -1, 0, 0 , 1,0, 0)
          MP_EntityAddImpulse(Mesh, 0, -0.1, 0 , -1.7,0, 0)
        ElseIf MP_KeyHit(#PB_Key_Z)
          MP_PositionEntity (escape, 0, 2.5, 0)
         
   EndIf
   
    MP_PhysicUpdate()
   
    MP_RenderWorld() ; Erstelle die Welt
    MP_Flip () ; Stelle Sie dar
   
Wend
 
MP_PhysicEnd()

Re: MP3D Engine Alpha 32

Posted: Mon Jul 06, 2015 6:45 am
by Inner
Game being worked on with your MP3D Engine.

https://www.youtube.com/watch?v=bkvOW3rk1C0

Programming + Music : Myself

Still a lot of work to do on it though.

Re: MP3D Engine Alpha 32

Posted: Mon Jul 06, 2015 9:25 am
by Psychophanta
Inner wrote:Game being worked on with your MP3D Engine.

https://www.youtube.com/watch?v=bkvOW3rk1C0

Programming + Music : Myself

Still a lot of work to do on it though.
Hehehe! I love that classic game.
Just a suggestion: Texture the HERO with a modern texture just like the other sprites.

Re: MP3D Engine Alpha 32

Posted: Mon Jul 06, 2015 11:10 am
by Inner
Psychophanta wrote:
Inner wrote:Game being worked on with your MP3D Engine.

https://www.youtube.com/watch?v=bkvOW3rk1C0

Programming + Music : Myself

Still a lot of work to do on it though.
Hehehe! I love that classic game.
Just a suggestion: Texture the HERO with a modern texture just like the other sprites.
Well, drawing isn't really my strong suit but we'll see most things are just place holders, I've been wanting to write it for many years but 'life' thing and those wall collisions had me stumped for most it.

Re: MP3D Engine Alpha 32

Posted: Tue Jul 21, 2015 4:57 pm
by applePi
accumulation of mesh points step by step
this is a cheat since we don't increase the mesh points in reality, but we build the whole mesh squeezed to a meaningless lonely point, and after that we resurrect the points from its "black hole" point to position it in its orbit according to a formula. and the whole scene build gradually.
instead of showing a useless pile points i will use one of the beautiful formulas posted by Psychophanta here http://www.purebasic.fr/english/viewtop ... 15#p433538 watch the bent disk appears gradually and the growing points will stop when reaching 3000 and the (black hole) point evaporate. i have noticed that sometimes when i run the code several times, it stop to work in some cases. this is in windows xp. more ideas or corrections !!!.

Code: Select all

#Mode=1 ; #Mode=1 or #Mode=7
Structure Vector
  x.f
  y.f
  z.f
  m.f
EndStructure
Structure PointVertex
  x.f
  y.f
  z.f
  CompilerIf #Mode=7
    Size.f ;--- Only if Mode=7
  CompilerEndIf 
  color.l;d3dcolor
EndStructure
Global xres.l=640,yres.l=480
MP_Graphics3D(xres,yres,0,3):MP_VSync(1)
SetWindowTitle(0,"press up/down to move camera")
camera=MP_CreateCamera()
light=MP_CreateLight(2)
MP_LightSetColor(light,RGB(245,245,245))
MP_PositionEntity(light,0,10,20)
MP_EntityLookAt(light,0,0,0)
Global size=3000,objeto.l=1
Global Entity=MP_CreatePrimitives(size,#Mode)
Global *Memory.PointVertex, Dim *OriginVertex.PointVertex(size)
Global Dim TargetVertex.Vector(size)
Global angle.f, stp.f=0.2, ii.l

Procedure DrawMatrix()
  Protected r.w=20,g.w=200,b.w=0,i.l
  *Memory=MP_GetMemPrimitives(Entity)
  For i=0 To size
    *OriginVertex(i)=*Memory+i*SizeOf(PointVertex)
    *OriginVertex(i)\color=MP_ARGB(200,r,g,b)
    *OriginVertex(i)\x=0
    *OriginVertex(i)\y=0
    *OriginVertex(i)\z=0
  Next
  MP_CloseMemPrimitives(Entity)
EndProcedure

;==============================================================
MP_ScaleEntity(Entity,1.5,1.5,1.5)

MP_PrimitivesBlendingMode(Entity,5,2)
MP_PositionEntity(camera,0,0,500)
MP_EntityLookAt(camera,0,0,0)
DrawMatrix()

zz.f=0 :i=0
While MP_KeyUp(#PB_Key_Escape) And WindowEvent()<>#PB_Event_CloseWindow
  WindowEvent()
  If MP_KeyDown(#PB_Key_Up)
    zz.f+20
  ElseIf MP_KeyDown(#PB_Key_Down)
    zz.f-20
  EndIf
  ;00000000000000000000000000000000000000000000000000000000000000000
  ; accumulating points step by step
  
  If i <= size
    *Memory=MP_GetMemPrimitives(Entity)
     xd= Random(500)
     ;xd+1: If xd=200:xd=1:EndIf
     *OriginVertex(i)\x=Cos(i*360/size)*Cos(i*360/size)*70
     *OriginVertex(i)\y=Cos(i*360/size)*Sin(xd)*100
     *OriginVertex(i)\z=Sin(i*360/size)*100
     MP_CloseMemPrimitives(Entity) 
     i+1
   EndIf
   
  ;00000000000000000000000000000000000000000000000000000000000000000
  
  MP_PositionEntity(Entity,0,0,zz)
  MP_TurnEntity(Entity,1.333,0.5,0.2)
  ;MP_DrawText(1,1,"FPS="+Str(MP_FPS()))
  MP_DrawText(1,1,"point= "+Str(i))
  MP_RenderWorld()
  MP_Flip()
Wend

Re: MP3D Engine Alpha 32

Posted: Fri Jul 24, 2015 10:28 am
by Psychophanta
This is my first pro work made with MP3D (I did 2 more pro works with Dreamotion3D, but I have abandoned DM3D months ago).
https://www.dropbox.com/s/s8kqhb1nuuo8fv4/PID.mp4?dl=0
To watch it correctly, it must be downloaded first instead to watch online.

There is also a version in complete native english audio narrator and videocomments, but this is the spanish one (to see 3D simulations never mind audio).

Notice that The simulations made in MP3D is not as smooth as it should, just because i had to capture video while the MP3D engine was working, and my PC is from 2008, so it is not owerful enougth to maintain the original smoothness from the MP3D.

MP3D is almost perfect :wink: