Page 60 of 71

Re: MP3D Engine Alpha 32

Posted: Sat Jul 25, 2015 8:52 am
by applePi
thanks Psychophanta for uploading such a big file, i have downloaded it for a later reference since the complex pendulum are interesting and its simulation in mp3d seems to give precision results.
on the other hand i have found that we can simulate spring by using two adjacent hinge joints, and it seems this is a universal approach and works with other engines.
the two joints such as this:
MP_ConstraintCreateHinge(beam,0,0,1,0,0,0)
MP_ConstraintCreateHinge(beam,0,0,1,0.05,0,0)

when we push one side of the beam and then release it will return to its original position
make the second joint more closely
MP_ConstraintCreateHinge(beam,0,0,1,0,0,0)
MP_ConstraintCreateHinge(beam,0,0,1,0.01,0,0)

and the spring will be very soft
make the joints seperated too much
MP_ConstraintCreateHinge(beam,0,0,1,0,0,0)
MP_ConstraintCreateHinge(beam,0,0,1,0.08,0,0)
and the spring is too hard

Code: Select all

Declare dropWeight(pos.f)
MP_Graphics3D (640, 480, 0, 3)
SetWindowTitle(0, "spring ..Z/X drop weights ")


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

ground = MP_CreateRectangle(5, 0.5, 5)
MP_PositionEntity(ground, 0, -2,0)
MP_EntitySetTexture(ground, tex0)

  
 MP_PositionEntity(cam0, 0, 5, -5) ; to look better
 MP_EntityLookAt(cam0, 0, 1, 0)


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

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


MP_PositionEntity(beam, 0.0, 1.0, 0 )

MP_PhysicInit()

MP_EntityPhysicBody(beam, 2, 0.5)
; Hinge
;MP_ConstraintCreateHinge(beam,0,0,1)
;MP_ConstraintCreateHinge(beam,0.2,0,1)
;MP_ConstraintCreateHinge(Entity, PinX.f, PinY.f, PinZ.f [, Pivotx.f, Pivoty.f, Pivotz.f [, MasterEntity]])
MP_ConstraintCreateHinge(beam,0,0,1,0,0,0)
MP_ConstraintCreateHinge(beam,0,0,1,0.05,0,0)

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(beam, -0.1, 0, 0 ,  0, 0, 2.0)
  If MP_KeyHit(#PB_Key_X) 
    dropWeight(1.8)
  ElseIf MP_KeyHit(#PB_Key_Z) 
    dropWeight(-1.8)
  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
   
the examples needs to be updated: as an example:
**MP_PositionMesh ---> MP_PositionEntity
**all camera move and position to Entity move or position
**MP_ChangeMeshCoord should be deleted
these functions are every where in the examples, i suggest using a utility such as search and replace to replace or delete these obsolete functions

Edit: edited lines 42, 43 so to be compatible with the Docs
;MP_ConstraintCreateHinge(Entity, PinX.f, PinY.f, PinZ.f [, Pivotx.f, Pivoty.f, Pivotz.f [, MasterEntity]])

Code: Select all

MP_ConstraintCreateHinge(beam,0,0,1,0,0,0)
MP_ConstraintCreateHinge(beam,0,0,1,0.05,0,0)
the previous version suppose 2 joints in the center but the second one have different orientation
this version means that the 2 joints have same orientation but separated slightly on X coordinate.

Re: MP3D Engine Alpha 32

Posted: Sun Jul 26, 2015 10:38 am
by Psychophanta
(1) @applePi, nice example, it is a game itself :wink:
When dealing with 'Constraints' i really get anoyed because it is really hard to make things work as you want.
I made a simulation of Cardano joint. I tried it with 'constrints' but no success, so i made it without physic engine:

Code: Select all

; Junta Cardan (Enero 2015)
Define .f
ExamineDesktops()
Global bitplanes.a=DesktopDepth(0),RX.u=DesktopWidth(0)*2/3,RY.u=DesktopHeight(0)*0.6:MP_Graphics3DWindow(0,0,RX,RY,"Junta Cardan",#PB_Window_SizeGadget|#PB_Window_MinimizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SystemMenu):MP_VSync(1):MP_SetAntialiasing(4)
; Global bitplanes.a=DesktopDepth(0),RX.u=DesktopWidth(0),RY.u=DesktopHeight(0):MP_Graphics3D(RX,RY,bitplanes,0):MP_VSync(1):MP_SetAntialiasing(4)
Structure D3DXVECTOR3
  x.f
  y.f
  z.f
EndStructure
Structure Vector3D Extends D3DXVECTOR3
  m.f;<-length(modulo)
EndStructure
Macro ProductoEscalar(a,b)
  (a#\x*b#\x+a#\y*b#\y+a#\z*b#\z)
EndMacro
Macro getmodulo(v)
  (Sqr(ProductoEscalar(v#,v#)))
EndMacro
rot=1*MP_VSyncTime()

Global light.i=MP_CreateLight(2)
MP_LightSetColor(light,$BAE6EB)
MP_PositionEntity(light,-6,10,-5)
MP_AmbientSetLight($e8e8f0)
Global pivotcam.i=MP_CreateMesh(),cam.i=MP_CreateCamera()
MP_CameraSetRange(cam,0.1,1000)
MP_EntitySetParent(cam,pivotcam,0)
MP_PositionEntity(cam,0,0,-2)
MP_TurnEntity(pivotcam,33,0,0,0)

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

Global tamanoletra=0.3,tamanovarilla=0.1,desp=0.6

Global cruceta2.i=MP_CreateCylinder(40,1)
MP_ResizeMesh(cruceta2,0.03,0.03,0.15)
MP_RotateMesh(cruceta2,90,0,0)

cruceta1.i=MP_CopyEntity(cruceta2)
MP_RotateMesh(cruceta1,0,0,90)

letra.i=MP_Create3DText("Lucida Console","U",tamanoletra,#PB_Font_HighQuality|#PB_Font_StrikeOut)

Global pieza1.i=MP_CreateCylinder(40,1),pieza1texture.i=MP_LoadTexture("..\media\8100949-concentric-brushed-metal-texture.jpg",0,0)
MP_ResizeMesh(pieza1,tamanovarilla,tamanovarilla,tamanovarilla*7)
MP_EntitySetTexture(pieza1,pieza1texture,0,0):MP_ScrollTexture(pieza1texture,40,40,0)
MP_RotateMesh(letra,90,0,0)
MP_ScaleMesh(letra,1,2,1)
MP_TranslateMesh(letra,-tamanoletra/3.3,-tamanoletra/3/#PI,tamanovarilla*7/2-tamanoletra/5)
MP_AddMesh(letra,pieza1)
MP_RotateMesh(letra,180,0,0)
MP_AddMesh(letra,pieza1):MP_FreeEntity(letra)
MP_TranslateMesh(pieza1,0,0,-tamanovarilla*7/2-tamanoletra/3)

Global pieza2.i=MP_CopyEntity(pieza1)
MP_TranslateMesh(pieza2,0,0,tamanovarilla*7+tamanoletra/1.5)

; Global pieza3.i=MP_CopyEntity(pieza2)
; MP_TranslateMesh(pieza3,0,0,tamanovarilla*7+tamanoletra/2.25)

MP_RotateMesh(pieza2,0,0,90)

MP_EntitySetParent(cruceta1,pieza1,0)
MP_EntitySetParent(cruceta2,pieza2,0)

MP_UseCursor(10)
While MP_Keyup(#PB_Key_Escape) And WindowEvent()<>#PB_Event_CloseWindow
  MP_TurnEntity(pieza1,0,0,rot,0)
  MP_TurnEntity(pieza2,0,0,rot,0)
  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/3); <- MP_MoveEntity(cam,0,0,mdw)
    EndIf
  ElseIf MP_KeyDown(#PB_Key_1)
    MP_TurnEntity(pieza1,1,0,0,0)
  ElseIf MP_KeyDown(#PB_Key_2)
    MP_TurnEntity(pieza1,-1,0,0,0)
  ElseIf MP_KeyDown(#PB_Key_3)
    MP_TurnEntity(pieza2,1,0,0,0)
  ElseIf MP_KeyDown(#PB_Key_4)
    MP_TurnEntity(pieza2,-1,0,0,0)
  ElseIf MP_KeyDown(#PB_Key_Right)
    rot+0.1
  ElseIf MP_KeyDown(#PB_Key_Left)
    rot-0.1
  EndIf
  MP_RenderWorld()
  MP_Flip():Delay(6)
Wend
(2) In my video doc, remarked in my previuos post, theres is nothing special, but it shows how useful is MP3D to perform visual easy simulations for almost anything.

(3) Since current package of MP3D does not allow Turn nor Rotate an entity over absolute world axis, I had to wrote this (there can be done a macro or function using this way):
NOTICE it has nothing to do with MP_RotateMesh() which rotates vetices of the mesh (which is slower for the VGA), but not the entity.

Code: Select all

Define .f
MP_Graphics3D(640,480,0,3)
SetWindowTitle(0,"TurnEntity over absolute world axis")
pivotcam.i=MP_CreateMesh():camera.i=MP_CreateCamera()
MP_EntitySetParent(camera,pivotcam,0):MP_PositionEntity(camera,0,0,-4)
light.i=MP_CreateLight(1)
If CreateImage(0,255,255)
  Font.i=LoadFont(#PB_Any,"Arial",138)
  StartDrawing(ImageOutput(0))
  Box(0, 0, 128, 128,RGB(255,0,0))
  Box(128, 0, 128, 128,RGB(0,255,0))
  Box(0, 128, 128, 128,RGB(0,0,255))
  Box(128, 128, 128, 128,RGB(255,255,0))
  DrawingFont(FontID(Font))
  DrawingMode(#PB_2DDrawing_Transparent)
  DrawText(73,35,"5",RGB(0,0,0))
  StopDrawing()
EndIf
Sphere.i=MP_CreateSphere(20):MP_EntitySetTexture(Sphere,MP_ImageToTexture(0),0,0)
Structure D3DMATRIX
  _11.f : _12.f : _13.f : _14.f
  _21.f : _22.f : _23.f : _24.f
  _31.f : _32.f : _33.f : _34.f
  _41.f : _42.f : _43.f : _44.f
EndStructure
Procedure.i Matriz4x4xMatriz4x4(*a.D3DMATRIX,*b.D3DMATRIX,*prod.D3DMATRIX); producto
  *prod\_11=*a\_11**b\_11+*a\_12**b\_21+*a\_13**b\_31+*a\_14**b\_41:*prod\_12=*a\_11**b\_12+*a\_12**b\_22+*a\_13**b\_32+*a\_14**b\_42:*prod\_13=*a\_11**b\_13+*a\_12**b\_23+*a\_13**b\_33+*a\_14**b\_43:*prod\_14=*a\_11**b\_14+*a\_12**b\_24+*a\_13**b\_34+*a\_14**b\_44
  *prod\_21=*a\_21**b\_11+*a\_22**b\_21+*a\_23**b\_31+*a\_24**b\_41:*prod\_22=*a\_21**b\_12+*a\_22**b\_22+*a\_23**b\_32+*a\_24**b\_42:*prod\_23=*a\_21**b\_13+*a\_22**b\_23+*a\_23**b\_33+*a\_24**b\_43:*prod\_24=*a\_21**b\_14+*a\_22**b\_24+*a\_23**b\_34+*a\_24**b\_44
  *prod\_31=*a\_31**b\_11+*a\_32**b\_21+*a\_33**b\_31+*a\_34**b\_41:*prod\_32=*a\_31**b\_12+*a\_32**b\_22+*a\_33**b\_32+*a\_34**b\_42:*prod\_33=*a\_31**b\_13+*a\_32**b\_23+*a\_33**b\_33+*a\_34**b\_43:*prod\_34=*a\_31**b\_14+*a\_32**b\_24+*a\_33**b\_34+*a\_34**b\_44
  *prod\_41=*a\_41**b\_11+*a\_42**b\_21+*a\_43**b\_31+*a\_44**b\_41:*prod\_42=*a\_41**b\_12+*a\_42**b\_22+*a\_43**b\_32+*a\_44**b\_42:*prod\_43=*a\_41**b\_13+*a\_42**b\_23+*a\_43**b\_33+*a\_44**b\_43:*prod\_44=*a\_41**b\_14+*a\_42**b\_24+*a\_43**b\_34+*a\_44**b\_44
  ProcedureReturn *prod
EndProcedure
rot.D3DMATRIX
rot1.D3DMATRIX
MP_RotateEntity(Sphere,Random(360),Random(360),Random(360),0)
MP_MouseInWindow()
While MP_KeyUp(#PB_Key_Escape) And WindowEvent()<>#PB_Event_CloseWindow
  mdx=MP_MouseDeltaX():mdy=MP_MouseDeltaY():mdw=MP_MouseDeltaWheel()/400
  If MP_KeyDown(#PB_Key_LeftControl)
    MP_UseCursor(1)
    MP_TurnEntity(pivotcam,mdy,mdx,0,0)
    If mdw
      MP_EntitySetZ(camera,MP_EntityGetZ(camera)+mdw); <- MP_MoveEntity(cam,0,0,mdw)
    EndIf
  Else;If MP_KeyDown(#PB_Key_LeftShift)
    MP_UseCursor(0)
    rotx.D3DMATRIX
    rotx\_11=1:rotx\_12=0:rotx\_13=0:rotx\_14=0
    rotx\_21=0:rotx\_22=Cos(-mdy/200):rotx\_23=Sin(-mdy/200):rotx\_24=0
    rotx\_31=0:rotx\_32=-Sin(-mdy/200):rotx\_33=Cos(-mdy/200):rotx\_34=0
    rotx\_41=0:rotx\_42=0:rotx\_43=0:rotx\_44=1
    roty.D3DMATRIX
    roty\_11=Cos(mdx/200):roty\_12=0:roty\_13=Sin(mdx/200):roty\_14=0
    roty\_21=0:roty\_22=1:roty\_23=0:roty\_24=0
    roty\_31=-Sin(mdx/200):roty\_32=0:roty\_33=Cos(mdx/200):roty\_34=0
    roty\_41=0:roty\_42=0:roty\_43=0:roty\_44=1
    MP_EntitySetMatrix(Sphere,Matriz4x4xMatriz4x4(MP_EntityGetMatrix(Sphere),Matriz4x4xMatriz4x4(@rotx,@roty,@rot1),@rot))
  EndIf
  MP_RenderWorld()
  MP_Flip():Delay(8)
Wend

Re: MP3D Engine Alpha 32

Posted: Mon Jul 27, 2015 11:08 am
by applePi
Psychophanta , me too feel bad with Joints, and i find it always difficult to do, it is better to design it on paper and then programming it. here is a research (and not a complete solution) about Hinge Joints in MP3D may be useful in your cardano joint project
the first example is to make the joint between a rectangular block and a box

Code: Select all

MP_ConstraintCreateHinge(beam,1,0,0, 0,0,2, box)
if you press Left/Right key you will do MP_RotateEntity(box,0,ro,0) and the box will rotate taking with him the beam (rect. block) . (even we should not use the geometry functions in physics actions but it is handy and works sometimes)

Code: Select all

MP_Graphics3D (640, 480, 0, 3)
SetWindowTitle(0, "Right/Left: rotate the box ")

light0 = MP_CreateLight(1)
MP_PositionEntity(light0, 0, 128, 0)
cam0 = MP_CreateCamera()
 MP_PositionEntity(cam0, 0, 5, -5) ; to look better
 MP_EntityLookAt(cam0, 0, 1, 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")

MP_PhysicInit()
box = MP_CreateRectangle(1, 1, 1)
MP_PositionEntity(box, 0, 0.5, 2)
MP_EntitySetTexture(box, tex0)
MP_EntityPhysicBody(box, 2, 3)

ground = MP_CreateRectangle(4, 0.5, 4)
MP_PositionEntity(ground, -1.5, -1, 2)
MP_EntitySetTexture(ground, tex0)
MP_EntityPhysicBody(ground, 1, 1)

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

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


MP_PositionEntity(beam, 1.0, 1.0, 0 )
MP_RotateEntity(beam, 0, -90, 0)



MP_EntityPhysicBody(beam, 2, 0.5)
; Hinge
;MP_ConstraintCreateHinge(Entity, PinX.f, PinY.f, PinZ.f [, Pivotx.f, Pivoty.f, Pivotz.f [, MasterEntity]])
MP_ConstraintCreateHinge(beam,1,0,0, 0,0,2, box)
;MP_LimitHingeAngle(beam, 45)




While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
  
  If MP_KeyDown(#PB_Key_Right) 
    ro.f-0.2
    MP_RotateEntity(box,0,ro,0)
    ;MP_FreeEntity(box)
  ElseIf MP_KeyDown(#PB_Key_Left) 
    ro.f+0.2
    MP_RotateEntity(box,0,ro,0)

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

End

   
second example: after looking at your cardano joint simulation i think we can abstract it to 2 hinge joints
beam 1 attached to space (ie: fixed) by hinge joint

Code: Select all

MP_ConstraintCreateHinge(beam,1,0,0, 0,0,2)
MP_LimitHingeAngle(beam, 45)
note the joint direction are on x axis (in global space) and its position is 0,0,2 relative to the beam center .
beam 2:

Code: Select all

MP_ConstraintCreateHinge(beam2,1,0,0, 0,0,-2, beam)
it's hinge joint is attached to the beam 1, so the whole block is one machine, try to drop stones (with Z/X) and all the machine disturbed. but it will not rotate because beam 1 are fixed to space with its hinge joint. may be if we attach it to a small block like in example 1 we see more interesting behavior
press 1 Or 2 to impulse beam 1 Or beam 2 ..or Z/X to drop boxes over beam 1 so to disturb the all machine

Code: Select all

Declare dropWeight(pos.f)
MP_Graphics3D (640, 480, 0, 3)
SetWindowTitle(0, "press 1/2 impulse to beam 1 or 2....Z/X drop weights ")

light0 = MP_CreateLight(1)
MP_PositionEntity(light0, 0, 128, 0)
cam0 = MP_CreateCamera()
 MP_PositionEntity(cam0, 0, 5, -5) ; to look better
 MP_EntityLookAt(cam0, 0, 1, 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")

ground = MP_CreateRectangle(5, 5, 5)
MP_PositionEntity(ground, 0, -2,1)
MP_EntitySetTexture(ground, tex0)


MP_PhysicInit()
MP_EntityPhysicBody(ground, 1, 1)

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

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


MP_PositionEntity(beam, 1.0, 1.0, 0 )
MP_RotateEntity(beam, 0, -90, 0)


MP_EntityPhysicBody(beam, 2, 0.5)
; Hinge
;MP_ConstraintCreateHinge(Entity, PinX.f, PinY.f, PinZ.f [, Pivotx.f, Pivoty.f, Pivotz.f [, MasterEntity]])
MP_ConstraintCreateHinge(beam,1,0,0, 0,0,2)
MP_LimitHingeAngle(beam, 45)

;;;00000000000000000000000000000000000000000000000000000000000000000
beam2 = MP_CreateRectangle(4,0.2,0.7)
MP_EntitySetTexture(beam2, tex2)
MP_PositionEntity(beam2, 0.0, 2.0, 0 )


MP_PositionEntity(beam2, 0.0, 1.0, 4 )
MP_RotateEntity(beam2, 0,90, 0)

MP_EntityPhysicBody(beam2, 2, 0.5)
MP_ConstraintCreateHinge(beam2,1,0,0, 0,0,-2, beam)
MP_LimitHingeAngle(beam2, 45)

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.2)
  ElseIf MP_KeyHit(#PB_Key_Z) 
    dropWeight(0.7)
  EndIf  
 
  ;MP_EntityAddImpulse(Entity, pointDeltaVelocX.f, pointDeltaVelocY.f, pointDeltaVelocZ.f [, pointPositX.f, pointPositY.f, pointPositZ.f])
  If MP_KeyDown(#PB_Key_1) 
    MP_EntityAddImpulse(beam, 0, 3, 0 , 0, 2, -2)  
    ElseIf  MP_KeyDown(#PB_Key_2) 
    MP_EntityAddImpulse(beam2, 0, 3, 0 , 0, 2, 2)  
  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.0 )
  MP_EntityPhysicBody(box, 2, 10)
   
   EndProcedure
   
notes:
1- it is possible MP_ConstraintCreateBall() can be useful in cardano joint, there is no example yet, i need to read about it in newton forum
2- the MP_LimitHingeAngle() cause some vibrations (if there is no ground) i wonder if the MP_SetPhysicMaterialProperties() and changing the Elasticity will solve the problem !!

Re: MP3D Engine Alpha 32

Posted: Sun Sep 13, 2015 8:02 pm
by Psychophanta
Hi all,

3DPhysics examples are done onto a flat surface or onto a terrain surface.
I tried to perform the behavior of a ball falling inside a hemisphere, this is, inside a concave surface, but no success; the physics engine interprets the concave surface as a plane surface.
Any idea?

PD: Michael, you have a PM

Re: MP3D Engine Alpha 32

Posted: Mon Sep 14, 2015 7:14 am
by applePi
Hi Psychophanta
"flat surface or onto a terrain surface"
this depends on the objects physics needed, and in this case you need physics type (7): such as MP_EntityPhysicBody(sphere , 7, 20).
download this LIB http://www.flasharts.de/mpz/mp33_beta/d ... ibrary.zip
look here: http://purebasic.fr/english/viewtopic.p ... 70#p466410
and replace the original Lib in this path: C:\PureBasic\SubSystems\dx9\purelibraries
an example
Image

note that we have deleted some triangles (as if they are room windows to look through)
note that we must rotate a sphere with a force such as MP_EntityAddImpulse and not by geometrical rotation. also a thick wall half sphere model may be better i haven't tried it yet

Code: Select all

MP_Graphics3D (640, 480, 0, 3)
SetWindowTitle(0, "Space to reverse 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.5
          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: Mon Sep 14, 2015 9:56 am
by Psychophanta
Thank you very much @applePi,
this evening will try it :)

EDIT: Thanks again, it works with the last lib! :wink: :!: (the one i was working with is from february)
By the way, there is a native hemisphere mesh for create, so no need to creat a sphere and then free some vertexes: you have MP_CreateSkySphere() , it is really a hemisphere.

Re: MP3D Engine Alpha 32

Posted: Tue Sep 15, 2015 12:26 pm
by mpz
Hello,

i had made not so much in the last time but have more time now. Here comes little update with a new installer for PB 5.24 to PB 5.40 Beta3 and the actulised lib

! INFO the following Installer works with PB 5.24 < 5.30 and 5.40 Beta 3
http://www.flasharts.de/mpz/mp33_beta/M ... taller.exe

I have made a litte command update

MP_LimitHinge (Entity, Angle.f [, Friction.f])

This is a friction to damping a wheel for example

testcode

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

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 (escape,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 8
angle.f+45

x.f = Cos(Radian(angle)) * 0.5: z.f = Sin(Radian(angle)) * 0.5

Blade = MP_CreateRectangle (0.5,0.05,0.2)

ang+45

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)

MP_TranslateMesh(Mesh,0,0,-0.5)
MP_PositionEntity (Mesh, 0,0,0.5)

;000000000000000000000000000000000000000000000000000000000000000000

MP_EntityPhysicBody(Mesh , 5, 10)


MP_ConstraintCreateHinge (Mesh,0,0,1)


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

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

Blade2 = MP_CreateRectangle (0.5,0.05,0.2)

ang+18

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.3, 0, 1)

MP_EntityPhysicBody(BigGear , 5, 1)
MP_ConstraintCreateHinge (BigGear,0,0,1)

MP_LimitHinge (BigGear, 0,0.1) ; <- new feature change 0.1 and you see what happens

;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()
        Orbitar(camera,-MP_MouseDeltaX()/20,MP_MouseDeltaY()/20,MP_MouseDeltaWheel()/3,mesh,m)
        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, -5.5, 0 , -10.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: Tue Sep 15, 2015 8:33 pm
by applePi
I have made a litte command update
MP_LimitHinge (Entity, Angle.f [, Friction.f])
Michael, this is not a little update but a major big update, i saw users in other 3D engines forums crying for friction feature for a rotating body. so thanks for this update.
i have installed the PB5.40 b3 version successfully
i can run your code successfully and the clock are ticking marvelous, also was able to add friction for the code of the half sphere above. but why i get this error when running the demo examples in 2DDraw and 2d physics + 3d physics like this:
Image

in PB5.31 i got the error "Library missing: VectorDrawing (needed by MP3D_Library)" when running any code.
thanks again

Edit: now i know the reason for the error in PB 5.31
i should choose the option PB 5.40 beta3 to install to purebasic v5.31. so the installer needs correction so it works when we choose PB 5.24 < 5.31

Re: MP3D Engine Alpha 32

Posted: Wed Sep 16, 2015 9:47 am
by applePi
i have posted before a not working simulation of Geneva drive https://www.youtube.com/watch?v=OZiPxV-_oaY
now with the friction for hinge joint added recently by Michael it is possible to simulate any thing. i have used MP_CreateSkySphere() to create hemisphere as referred to by Psychophanta , this simplified the code. it is a show case only, more values or designs can make the Geneva drive better (Geneva drive used to convert continuous rotation to intermittent rotation):
use the latest MP3D posted in the previous page. the example works okay in PB 5.31 or PB5.40 beta 3

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, "press '1' or '2' to change Camera view position")

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, 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_CreateSkySphere(16)
MP_PositionEntity (sphere, 0, 1, 0)
;mp_wireframe(1)     


MP_EntitySetTexture(sphere, tex1)

MP_RotateMesh(sphere , -90 , 0, 180)
MP_ResizeMesh(sphere,1,1,0.5)
hand = MP_CreateCylinder(5,0.2)
MP_ResizeMesh(hand,0.1,0.1,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.90 )
MP_AddMesh(hand , sphere ) : MP_FreeEntity(hand)
MP_PositionEntity(sphere, 0, 0.5, -0.7)

;Debug MP_MeshGetWidth(sphere) ; 1
;Debug MP_MeshGetDepth(sphere) ; 1.44470250606537
;Debug MP_MeshGetHeight(sphere) ; 1.20000100135803

;;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_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, 5)
MP_ConstraintCreateHinge (sphere,0,1,0, 0,0,0)
MP_ConstraintCreateHinge (Mesh,0,1,0, 0.0,0.0,0)
MP_LimitHinge (Mesh, 0,0.5)
MP_LimitHinge (sphere, 0, 2)


MP_EntityAddImpulse(sphere, 10, 0, 0 ,  0, 0, 0.5)
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
  If MP_KeyHit(#PB_Key_1) 
    MP_PositionEntity(cam0, 0, 10, -3)
    MP_EntityLookAt(cam0, 0, 0, 0)
ElseIf MP_KeyHit(#PB_Key_2) 
  MP_PositionEntity(cam0, 0, 3, -7)
  MP_EntityLookAt(cam0, 0, 0, 0)
EndIf

      
      MP_PhysicUpdate()
      MP_EntityAddImpulse(sphere, 0.3, 0, 0 ,  0, 0, 0.5)
      ;MP_TurnEntity (sphere, 0, 1, 0)
      MP_RenderWorld() ; Erstelle die Welt
      MP_Flip () ; Stelle Sie dar
     
Wend

End

Re: MP3D Engine Alpha 32

Posted: Wed Sep 16, 2015 4:30 pm
by Psychophanta
Thank you for all your codes applePi !
IT help us for learn.

Re: MP3D Engine Alpha 32

Posted: Fri Sep 18, 2015 9:25 am
by applePi
i think MP_AddMesh needs optimization, look at the following code to plot 140+144 spheres (8x8 slices) to form a Pine Cone shape, with (8x8) its time is 15 seconds, and with sphere 16x16 its time 60 seconds. compare with the equivalent PB ogre code it is almost instantaneous even with spheres 16x16 slices
the physics and hinge joint code just for fantasia only

it is possible in PB ogre utilizing the GPU more, don't know about the MP3D in this case. the reason i say that look bbanelli notes in bug forum http://purebasic.fr/english/viewtopic.p ... 68#p471515 about the almost zero GPU utilization in PB 5.40beta3 compared to PB5.31
i want to add that there is no addMesh function in purebasic but i have used a work around which is successful
Image
MP3D code:

Code: Select all

Structure coor
 x.f
 y.f
 z.f
EndStructure 

Global z.coor
Global seeds = 1


#golden_angle = 137.508 
Global golden.f = Radian(#golden_angle); = 2.3999 also = golden_angle*PI/180 

Procedure floret(n.i) 
  r.f : ang.f : xc.f : yc.f
  r =(5.3 * Sqr(n*golden))
  ang = (n*golden)
  xc = r*Cos(ang)/100
  yc = r*Sin(ang)/100
  z\x=xc : z\y=yc 
EndProcedure

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 '1' or '2' to change Camera view position")

camera = MP_CreateCamera() ; Kamera erstellen

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

cam = MP_CreateCamera()

MP_PositionEntity(cam, 0, 3, -7)
MP_EntityLookAt(cam, 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)
MP_ResizeMesh(sphere,0.01,0.01,0.01)
;mp_wireframe(1)     


MP_EntitySetTexture(sphere, tex1)
For i=1 To 140
  floret(i) ; calling the procedure to find the one sphere (seed) position 
  sph = MP_CreateSphere(8)
  
     MP_ScaleMesh(sph,(0.11+i/900),(0.11+i/900),(0.11+i/900))

     MP_TranslateMesh(sph, z\x , z\y , i/100) ; position that sphere in specific place
     MP_AddMesh(sph , sphere ) : MP_FreeEntity(sph)
   Next
 For i=144 To 1 Step -1
  floret(i) ; calling the procedure to find the one sphere (seed) position 
     sph = MP_CreateSphere(8)
  
     MP_ScaleMesh(sph,(0.11+i/900),(0.11+i/900),(0.11+i/900))

     MP_TranslateMesh(sph, -z\x , -z\y , 2.2-i/200) ; position that sphere in specific place
     MP_AddMesh(sph , sphere ) : MP_FreeEntity(sph)
 Next
  
   
MP_RotateMesh(sphere, -90,0,0) 
MP_ScaleMesh(sphere,1,1.5,1)
   
stone = MP_CreateSphere(3)
MP_ScaleMesh(stone, 0.3,0.3,0.3)
MP_PositionEntity (stone, 0, 5, 0)


MP_EntitySetNormals (sphere)
MP_MaterialDiffuseColor (sphere,255,255,255,50)
MP_MaterialSpecularColor (sphere, 255, 255 ,255, 155,5)
;;oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo

MP_PhysicInit()

MP_EntityPhysicBody(sphere , 5, 1)

MP_ConstraintCreateHinge (sphere,0,1,0, 0,1,0)

MP_LimitHinge (sphere, 0, 1)
MP_EntityPhysicBody(stone ,3 , 0.01)

MP_EntityAddImpulse(sphere, 10, 0, 0 ,  0, 0, 1)
While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
  If MP_KeyHit(#PB_Key_1) 
    MP_PositionEntity(cam, 0, 10, -3)
    MP_EntityLookAt(cam, 0, 0, 0)
ElseIf MP_KeyHit(#PB_Key_2) 
  MP_PositionEntity(cam, 0, 3, -7)
  MP_EntityLookAt(cam, 0, 0, 0)
EndIf

      
      MP_PhysicUpdate()
      MP_EntityAddImpulse(sphere, 2, 0, 0 ,  0, 0, 1)
      ;MP_TurnEntity (sphere, 0, 1, 0)
      MP_RenderWorld() ; Erstelle die Welt
      MP_Flip () ; Stelle Sie dar
     
Wend

End
PB Ogre 5,31 + 5.40beta4

Code: Select all

Structure coor
 x.f
 y.f
 z.f
EndStructure 

Global z.coor
Global seeds = 1


#golden_angle = 137.508 
Global golden.f = Radian(#golden_angle); = 2.3999 also = golden_angle*PI/180 

Procedure floret(n.i) 
  r.f : ang.f : xc.f : yc.f
  r =(5.3 * Sqr(n*golden))
  ang = (n*golden)
  xc = r*Cos(ang)/100
  yc = r*Sin(ang)/100
  z\x=xc : z\y=yc 
EndProcedure

Enumeration
   
   #LIGHT
   #CAMERA
   #mainwin
   #Plane
   #sphere
  
EndEnumeration
#cameraSpeed = 0.2

Define.f KeyX, KeyY, MouseX, MouseY

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

Define.f KeyX, KeyY

Declare CreateMatrix()


InitEngine3D()
   InitMouse()
   InitKeyboard()
   InitSprite()
   ExamineDesktops()
   
OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "arrow keys+mouse: move/rotate camera...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0)
  Add3DArchive(".",#PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home+"Examples\3D\Data\Textures\",#PB_3DArchive_FileSystem)
  Add3DArchive(#PB_Compiler_Home+"Examples\3D\Data\GUI",#PB_3DArchive_FileSystem)
  Parse3DScripts()
                          
  CreateLight(0,RGB(255, 255, 95),-50,50,100)
         ;;============================================
         OpenWindow3D(0,0,0,300,120,"Engine Stats")
         TextGadget3D(0,2,0,300,30,"")
         TextGadget3D(1,2,0,300,60,"")
         ShowGUI(255,0)
    ;=============================================         
    CreateMaterial(0, LoadTexture(0, "White.jpg"))
    DisableMaterialLighting(0, #True)
    MaterialShadingMode(0, #PB_Material_Wireframe     )
    MaterialCullingMode(0, #PB_Material_NoCulling)
            
    CreateCamera(#camera, 0, 0, 100, 100)
    MoveCamera(#camera, 0, 2, 7, #PB_Absolute)
    CameraBackColor(#camera, RGB(255,200,200))
    CameraLookAt(#camera,0,1,0)
        
    CreateLight(0, RGB(255,255,255), 0, 20, 30)
    AmbientColor(RGB(200, 200, 200))
    
    
    CreateMaterial(1, LoadTexture(1, "ValetCoeur.jpg")) 
    MaterialCullingMode(1, #PB_Material_NoCulling)
    SetMaterialColor(1, #PB_Material_AmbientColor, RGB(250, 255, 255))
    SetMaterialColor(1, #PB_Material_SpecularColor, RGB(255, 255, 255))
    DisableMaterialLighting(1, #False)
            
    CreateMatrix()
    
  RotateEntity(0, -90.0,0.0,0,#PB_Absolute)
  
    Repeat
      Event = WindowEvent()
        
      If ExamineMouse()
        MouseX = -MouseDeltaX()/20 
        MouseY = -MouseDeltaY()/20
      EndIf
      
          
      If ExamineKeyboard()
         
        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
        
        
       If KeyboardPushed(#PB_Key_S)
          SaveMesh(0, "Compound1.mesh")
        EndIf         
        EndIf
       
        rot.f+0.6
        RotateEntity(0, 0.0,0.0,0.5,#PB_Relative)
        RotateCamera(#Camera, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera(#Camera, KeyX, 0, KeyY)
      
      RenderWorld()
      FlipBuffers()
      ;;==============================================
            SetGadgetText3D(0,"FPS: "+StrF(Engine3DStatus(#PB_Engine3D_CurrentFPS )))
            SetGadgetText3D(1,"Tris: "+StrF(Engine3DStatus(#PB_Engine3D_NbRenderedTriangles))) 
      ;;================================================
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
 
End


Procedure CreateMatrix()
  CreateMesh(0, #PB_Mesh_TriangleList, #PB_Mesh_Dynamic)
  
  CreateSphere(30,1, 16,16)
  
   
   For count =1 To 140
   
  AddSubMesh(#PB_Mesh_TriangleList)
  floret(count) ; calling the procedure to find the one sphere (seed) position
  CopyMesh(30,31)
  TransformMesh(31, z\x , z\y , count/100, (0.11+count/900),(0.11+count/900),(0.11+count/900), 0,0,0)
  GetMeshData(31,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_UVCoordinate, 0, MeshVertexCount(31)-1)
  GetMeshData(31,0, MeshDataInd(), #PB_Mesh_Face, 0, MeshIndexCount(31, 0)-1)
  ArrSize = ArraySize(MeshData())
  
  For c=0 To ArrSize
      
      x.f = MeshData(c)\x 
      y.f = MeshData(c)\y
      zz.f = MeshData(c)\z
      MeshVertexPosition(x,y,zz)
      MeshVertexTextureCoordinate(MeshData(c)\u, MeshData(c)\v) 
      
   Next   
   
   ArrSizeInd = ArraySize(MeshDataInd()) 
   For i=0 To ArrSizeInd Step 3
     MeshFace(MeshDataInd(i)\Index, MeshDataInd(i+1)\Index,MeshDataInd(i+2)\Index)
   Next
 
 Next
 
   For count =144 To 1 Step -1
   
  AddSubMesh(#PB_Mesh_TriangleList)
  floret(count) ;calling the procedure to find the one sphere (seed) position
  CopyMesh(30,31)
  TransformMesh(31, -z\x , -z\y , 2.2-count/200, (0.11+count/900),(0.11+count/900),(0.11+count/900), 0,0,0)
  GetMeshData(31,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_UVCoordinate, 0, MeshVertexCount(31)-1)
  GetMeshData(31,0, MeshDataInd(), #PB_Mesh_Face, 0, MeshIndexCount(31, 0)-1)
  ArrSize = ArraySize(MeshData())
  
  For c=0 To ArrSize
      
      x.f = MeshData(c)\x 
      y.f = MeshData(c)\y
      zz.f = MeshData(c)\z
      MeshVertexPosition(x,y,zz)
      MeshVertexTextureCoordinate(MeshData(c)\u, MeshData(c)\v) 
      
   Next   
   
   ArrSizeInd = ArraySize(MeshDataInd()) 
   For i=0 To ArrSizeInd Step 3
     MeshFace(MeshDataInd(i)\Index, MeshDataInd(i+1)\Index,MeshDataInd(i+2)\Index)
   Next
 
 Next
   
  FinishMesh(#True)
  SetMeshMaterial(0, MaterialID(1))
    
  CreateEntity(0, MeshID(0), MaterialID(1), 0,0,0)
  ScaleEntity(0, 1,1,1.5)
    
EndProcedure

Re: MP3D Engine Alpha 32

Posted: Sun Oct 04, 2015 9:37 pm
by mpz
Hello to all,

here comes a little update with bug fixing and a little new function.


! INFO the following Installer works with PB 5.24 < 5.30 and 5.40 Beta 8
http://www.flasharts.de/mpz/mp33_beta/M ... taller.exe

1) First i have deactivate the command

MP_SoundSetEffect (Sound, Effect [[, Var [, AddressofStructur]])

Did anybody use these function ? i think not...

As i start with mp3d PB has all functions in DX7 and so have i rewritten the soundfunctions in DX9. Now i can use the PB Dsound functions and it is easier for me for handling.

2) I fix a bug in the x64 version the commands

MP_VertexGetU()
MP_VertexGetV()

and it works now.

3) i fix a bug in the MP_CameraViewPort() comand, the MP_EntitySetParent work for Viewport cameras too now

4) A new command appears. It is possible to use the 2D PB commands StartDrawing()/StopDrawing() now with MP_Textures

MP_TexturOutput(Texture) ; pipe the output to MP3d_textures


Greetings Michael

@ applePi -> "MP_AddMesh needs optimization". I have checked the command, but in this kind of MP3D engine i use dx9 meshs. That means in your demo the command open two meshs and copy all in a new one 144 x 2 times. This needs time (over 20 k vertex at last). I think in Ogre are using primitives and they work only with buffers. This is faster, but i cant change the meshs in MP3D for this. In the (sometimes coming) mp3d dx11 engine i work only with buffer an i hope this will speed up ;) ...

Greetings Michael


Demo_Bug:

Code: Select all

Define .f
MP_Graphics3D(640,480,0,3)
cam.i=MP_CreateCamera()

;- works now
camViewPortX.u=180:camViewPortY.u=60:camViewPortWidth.u=500:camViewPortHeigh.u=400
camViewPort.i=MP_CameraViewPort(cam,camViewPortX,camViewPortY,camViewPortWidth,camViewPortHeigh,$3B749A)
MP_CameraSetPerspective(cam,45,camViewPortWidth/camViewPortHeigh)
MP_CreateOneShotEmitter(0, 0, 0, 0, 100, 2,0.1, 10, 100)
;-

pivotcam.i=MP_CreateMesh():MP_EntitySetParent(cam,pivotcam,0):MP_PositionEntity(cam,0,0,-4)
light.i=MP_CreateLight(1)
MP_AmbientSetLight($9999)
Object.i=MP_CreateCube()
MP_MaterialDiffuseColor(Object,$aa,$1E,$FA,$EB);    <----     why not MP_MaterialDiffuseColor(Object,$AABBGGRR)   ??
MP_MouseInWindow()
MP_UseCursor(0)
While MP_KeyDown(#PB_Key_Escape)=0 And WindowEvent()<>#PB_Event_CloseWindow
  mdx=MP_MouseDeltaX()/200:mdy=MP_MouseDeltaY()/200:mdw=MP_MouseDeltaWheel()/400
  MP_TurnEntity(pivotcam,mdy*60,mdx*60,0,0)
  If mdw
    MP_EntitySetZ(cam,MP_EntityGetZ(cam)+mdw); <- MP_MoveEntity(cam,0,0,mdw)
  EndIf
  MP_RenderWorld()
  MP_Flip():Delay(8)
Wend
Demo_New_Command

Code: Select all

;- ProgrammStart

MP_Graphics3D (640,480,0,1) ; Erstelle ein WindowsFenster #Window = 0
SetWindowTitle(0, "3D of two cubes with different UV coords") 

camera=MP_CreateCamera() ; Kamera erstellen

light=MP_CreateLight(1) ; Es werde Licht

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

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

;- Tausch die Texturkoordinaten

MP_VertexSetU (Mesh2, 16, 0)
MP_VertexSetV (Mesh2, 16, 0)
MP_VertexSetU (Mesh2, 17, 1)
MP_VertexSetV (Mesh2, 17, 0)
MP_VertexSetU (Mesh2, 18, 1)
MP_VertexSetV (Mesh2, 18, 1)
MP_VertexSetU (Mesh2, 19, 0)
MP_VertexSetV (Mesh2, 19, 1)

Texture = MP_CreateTexture(255, 255 ,1)

    Font = LoadFont(#PB_Any, "Arial"  , 138) 
    
    StartDrawing(MP_TexturOutput(Texture)) ; <- Yes here it is
    
    Box(0, 0, 128, 128,RGB(255,0,0))
    Box(128, 0, 128, 128,RGB(0,255,0))
    Box(0, 128, 128, 128,RGB(0,0,255))
    Box(128, 128, 128, 128,RGB(255,255,0))
    
    DrawingFont(FontID(Font))
    DrawingMode(#PB_2DDrawing_Transparent)
    DrawText(73,35,"5",RGB(0,0,0))
    
    StopDrawing() ; This is absolutely needed when the drawing operations are finished !!! Never forget it !

MP_EntitySetTexture (Mesh, Texture ) ; textur to mesh

MP_EntitySetTexture (Mesh2, Texture ) ; textur to mesh

MP_PositionEntity (Mesh,-1,0,5) ; Position des Würfels

MP_PositionEntity (Mesh2,1,0,5) ; 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,1,0,0) 
    MP_TurnEntity (Mesh2,0,1,0) 
    MP_RenderWorld() ; Erstelle die Welt
    MP_Flip () ; Stelle Sie dar

Wend

Re: MP3D Engine Alpha 32

Posted: Tue Dec 08, 2015 1:23 pm
by hippy
Hey mpz!

Thanks this is great, I used the installer and it worked well on fresh install of PB 5.40 LTS...
Except, every time MP_DrawText() is used, the linking fails

Code: Select all

POLINK: error: Unresolved external symbol '_SYS_CopyString'.
If I comment out MP_DrawText() calls, it compiles just fine.

Do you have any ideas on what is going wrong?

Cheers,
Hip

Re: MP3D Engine Alpha 32

Posted: Tue Dec 08, 2015 8:03 pm
by mpz
Hi Hippy,

it is my fault. i confound the "PB 5.24 < 5.31" and "PB 5.40 LTS" function. Please choose her "PB 5.24 < 5.31" for the PB 5.40 lib.

Now i have actualized the installerfile to version V 0.51 to solve the bug

Greetings Michael

Re: MP3D Engine Alpha 32

Posted: Wed Dec 09, 2015 12:41 pm
by hippy
Thanks mpz! :D

I used the "PB 5.24 < 5.31" installation onto my PB 5.40 LTS x86 install and it worked with all the examples.

Hey I don't suppose you have a Threadsafe compile of this particular version?
I'm not actually drawing in any threads, but PB complains about

Code: Select all

POLINK: error: Unresolved external symbol '_PB_StringBasePosition'. 
in my threaded application, I think it's thread related to MP_DrawText().

I downloaded and tested the http://www.flasharts.de/mpz/Threadsafe/MP3D_Library in PB 5.40 LTS and PB 5.31 though the compiler would freeze in the IDE and it did not work :(

Really cool work by the way, thank you!

Kind Regards,
Hip