However, i have a curiosity which perhaps does not worth to fix it: shouldn't last tip work with these 2 lines commented? :
Code: Select all
; MP_FreeEntity(cam2)
; cam2=MP_CreateCamera()

Code: Select all
; MP_FreeEntity(cam2)
; cam2=MP_CreateCamera()

Thanks for answer!mpz wrote:Hi to all,
@Gemorg,
1) new command MP_2DPhysicBodyRemove(Body) integrated, new lib created for download ready now (see answer before to load lib)
Greetings Michael

Gemorg wrote:where I can download a new library?
http://www.purebasic.fr/english/viewtop ... 25#p458118mpz wrote:new lib created for download ready now (see answer before to load lib)
Greetings Michael
Maybe I don't understand something, but these libraries don't have the MP_2DPhysicBodyRemove(Body) function.Psychophanta wrote:http://www.purebasic.fr/english/viewtop ... 25#p458118


Code: Select all
  If MP_KeyDown( #PB_Key_F1)
    MP_2DPhysicBodyRemove(BallBody)
    BallBody = 0
  EndIfYou using Chipmunk4PB. Nice to know this.Gemorg wrote: P.s. I saw Your message and tried to use Chipmunk4PB. After removal of a body by means of cpBodyFree(*par1.cpBody), MP_2DPhysicUpdate() incorrectly works.

Code: Select all
    WindowWidth=640:WindowHeigh=480
    MP_Graphics3D(WindowWidth,WindowHeigh,0,2)
    ViewPortX=300:ViewPortY=60:ViewPortWidth=100:ViewPortHeigh=400
    light=MP_CreateLight(1)
    m=MP_CreateCube()
    MP_EntitySetZ(m,8)
    cam=MP_CreateCamera()
    MP_CameraViewPort(cam,ViewPortX,ViewPortY,ViewPortWidth,ViewPortHeigh,$008B340A)
    MP_CameraSetPerspective(cam,45,ViewPortWidth/ViewPortHeigh)
    ViewPortX2=400:ViewPortY2=80:ViewPortWidth2=200:ViewPortHeigh2=300
    cam2=MP_CreateCamera()
    MP_CameraViewPort(cam2,ViewPortX2,ViewPortY2,ViewPortWidth2,ViewPortHeigh2,$00346B0A)
    MP_CameraSetPerspective(cam2,45,ViewPortWidth2/ViewPortHeigh2)
    m2=MP_CreateCube()
    MP_EntitySetZ(m2,-1000)
    MP_PositionEntity(cam2,0,0,-995)
    MP_PointEntity(cam2,m2)
    MP_AmbientSetLight (RGB(120,34,123)) ; purple backgroundcolor
    While WindowEvent()<>#PB_Event_CloseWindow
      picked=MP_PickCamera(cam,WindowMouseX(0),WindowMouseY(0))
      MP_DrawText(100,40,"Mesh "+Hex(picked)+" found")
      ;
      If MP_KeyHit(#PB_Key_Left)
        MP_CameraViewPort(cam2,ViewPortX2-350,ViewPortY2,ViewPortWidth2,ViewPortHeigh2,$006B340A); <- after this, the old view port remains active for watching world.
      EndIf
      ;
      picked2=MP_PickCamera(cam2,WindowMouseX(0),WindowMouseY(0))
      MP_DrawText(100,70,"Mesh2 "+Hex(picked2)+" found")
      MP_TurnEntity(m,-0.1,0.3,-0.23)
      MP_TurnEntity(m2,0.3,-0.23,-0.1)
      MP_RenderWorld()
      MP_Flip()
    Wend

Code: Select all
    WindowWidth=640:WindowHeigh=480
    MP_Graphics3D(WindowWidth,WindowHeigh,0,2)
    
    ViewPortX=300:ViewPortY=60:ViewPortWidth=100:ViewPortHeigh=400
    
    light=MP_CreateLight(1)
    m=MP_CreateCube()
    MP_EntitySetZ(m,8)
    cam=MP_CreateCamera()
    
    My1Viewport = MP_CameraViewPort(cam,ViewPortX,ViewPortY,ViewPortWidth,ViewPortHeigh,$008B340A)
    MP_CameraSetPerspective(cam,45,ViewPortWidth/ViewPortHeigh)
    ViewPortX2=400:ViewPortY2=80:ViewPortWidth2=200:ViewPortHeigh2=300
    cam2=MP_CreateCamera()
    
    My2Viewport = MP_CameraViewPort(cam2,ViewPortX2,ViewPortY2,ViewPortWidth2,ViewPortHeigh2,$00346B0A)
    MP_CameraSetPerspective(cam2,45,ViewPortWidth2/ViewPortHeigh2)
    m2=MP_CreateCube()
    MP_EntitySetZ(m2,-1000)
    MP_PositionEntity(cam2,0,0,-995)
    MP_PointEntity(cam2,m2)
    MP_AmbientSetLight (RGB(120,34,123)) ; purple backgroundcolor
    While WindowEvent()<>#PB_Event_CloseWindow
      picked=MP_PickCamera(cam,WindowMouseX(0),WindowMouseY(0))
      MP_DrawText(100,40,"Mesh "+Hex(picked)+" found")
      ;
      If MP_KeyHit(#PB_Key_Left)
        MP_FreeEntity(My2Viewport)
        My2Viewport = MP_CameraViewPort(cam2,ViewPortX2-350,ViewPortY2,ViewPortWidth2,ViewPortHeigh2,$006B340A); <- after this, the old view port remains active for watching world.
      EndIf
      ;
      picked2=MP_PickCamera(cam2,WindowMouseX(0),WindowMouseY(0))
      MP_DrawText(100,70,"Mesh2 "+Hex(picked2)+" found")
      MP_TurnEntity(m,-0.1,0.3,-0.23)
      MP_TurnEntity(m2,0.3,-0.23,-0.1)
      MP_RenderWorld()
      MP_Flip()
    Wend

Code: Select all
MP_Graphics3D(640,480,0,3)
SetWindowTitle(0,"Spherical Mapping")
camera=MP_CreateCamera()
MP_PositionEntity(camera,0,0,-4)
light=MP_CreateLight(1)
If CreateImage(0,255,255)
  Font=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
Procedure.f TurnToUnity(x.f,y.f); <- returns angle (given its sine and cosine) into a value between 0 and 1 , being 1 a complete turn (360 degrees)
  !fld1
  !fldpi
  !fadd st0,st0; <- now i have 2*pi into st0, in st1 is 1
  !fld dword[p.v_y]; <- now i have 2*pi into st1, y in st0, in st2 is 1
  !fld dword[p.v_x]; <- now i have 2*pi into st2, y in st1, x in st0, in st3 is 1
  !fpatan; <- now is 2*pi into st1, atan(y/x) in st0, in st2 is 1
  !fdivrp st1,st0; <- now is (atan(y/x)) / (2*pi) in st0, in st1 is 1
  !fadd st1,st0; <- Now in st1 is (1 + (atan(y/x)) / (2*pi)), in st0 (atan(y/x)) / (2*pi)
  !fldz; <- Now in st0 is 0, in st2 is (1 + (atan(y/x)) / (2*pi)), in st1 (atan(y/x)) / (2*pi)
  !fcomip st1; <- just compare 0 with (atan(y/x)) / (2*pi). Now in st1 is (1 + (atan(y/x)) / (2*pi)), in st0 is (atan(y/x)) / (2*pi)
  !fcmovnbe st0,st1; <- transfer to st0 if not below or equal than 0
  !fstp st1
  ProcedureReturn
EndProcedure
Sphere2=MP_CreateSphere(30)
For n=0 To MP_CountVertices(Sphere2)-1
  x.f=MP_VertexGetX(Sphere2,n)
  y.f=MP_VertexGetY(Sphere2,n)
  z.f=MP_VertexGetZ(Sphere2,n)
  MP_VertexSetU(Sphere2,n,TurnToUnity(x,z))
  MP_VertexSetV(Sphere2,n,ACos(y)/#PI)
Next
MP_EntitySetTexture(Sphere2,MP_ImageToTexture(0))
While MP_KeyUp(#PB_Key_Escape) And WindowEvent()<>#PB_Event_CloseWindow
  MP_TurnEntity(Sphere2,0,1,0)
  MP_RenderWorld()
  MP_Flip():Delay(8)
Wend