MP3D Engine Alpha 33

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: MP3D Engine Alpha 32

Post by Psychophanta »

Great :!:

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()
Many many thanks for the improvements and happy life (an only year sounds a bit frivolous :p )! :D
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Gemorg
New User
New User
Posts: 7
Joined: Tue Feb 17, 2015 9:33 pm

Re: MP3D Engine Alpha 32

Post by Gemorg »

HI!
Can you help me?

How do I remove the 2d physic body?
There is something like MP_2DPhysicBodyRemove? I can't find that.

Thanks.
mpz
Enthusiast
Enthusiast
Posts: 497
Joined: Sat Oct 11, 2008 9:07 pm
Location: Germany, Berlin > member German forum

Re: MP3D Engine Alpha 32

Post by mpz »

Hi 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
Working on - MP3D Library - PB 5.73 version ready for download
Gemorg
New User
New User
Posts: 7
Joined: Tue Feb 17, 2015 9:33 pm

Re: MP3D Engine Alpha 32

Post by Gemorg »

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
Thanks for answer!
But, where I can download a new library?

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.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: MP3D Engine Alpha 32

Post by Psychophanta »

Gemorg wrote:where I can download a new library?
mpz wrote:new lib created for download ready now (see answer before to load lib)

Greetings Michael
http://www.purebasic.fr/english/viewtop ... 25#p458118
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Gemorg
New User
New User
Posts: 7
Joined: Tue Feb 17, 2015 9:33 pm

Re: MP3D Engine Alpha 32

Post by Gemorg »

Maybe I don't understand something, but these libraries don't have the MP_2DPhysicBodyRemove(Body) function.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: MP3D Engine Alpha 32

Post by Psychophanta »

Ok, then Michael must forgot something, sorry.
http://www.zeitgeistmovie.com

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

Re: MP3D Engine Alpha 32

Post by mpz »

Hi,

i am sorry. This was my fault. I made the procedure without dll (ProcedureDLL) and so it was not integrated in the lib. I have actailized the files with PB511 and PB531 and it works now...

Code example

Code: Select all

  If MP_KeyDown( #PB_Key_F1)
    MP_2DPhysicBodyRemove(BallBody)
    BallBody = 0
  EndIf
Greetings and a nice weekend
Working on - MP3D Library - PB 5.73 version ready for download
Gemorg
New User
New User
Posts: 7
Joined: Tue Feb 17, 2015 9:33 pm

Re: MP3D Engine Alpha 32

Post by Gemorg »

Thanks! Perfectly works!
User avatar
IceSoft
Addict
Addict
Posts: 1682
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: MP3D Engine Alpha 32

Post by IceSoft »

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.
You using Chipmunk4PB. Nice to know this.
Hope you can show some of your results here.

Small info:
I am working on an update of the Chipmunk4PB to Chipmunk2D 7.0.0 at this moment.
Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: MP3D Engine Alpha 32

Post by Psychophanta »

Hallo Michael,

I need again to deal with camera view ports, and i find a new bad thing:
when change the viewport of a camera, the old viewport is still shown like if there was a camera watching the world.
To see it, just take a look your own sample few posts ago with my 'if-endif' added in the main loop:

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
http://www.zeitgeistmovie.com

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

Re: MP3D Engine Alpha 32

Post by mpz »

Hello Psychophanta,

i am sorry, but i was on a show for some days and had not time for anything...

Cameras an viewports are own entitys in mp3d. That mean you can have one camera and (for example) 4 viewports. To delete one viewport you need the command (see example code):

MP_FreeEntity(My2Viewport)

But what i found is a problem with the "MP_PickCamera" command. It can only pick the last viewport of a camera and not "all" viewport if you have more as 1. I will repair it an make an update in the next days.

Greetings
Michael

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
Working on - MP3D Library - PB 5.73 version ready for download
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: MP3D Engine Alpha 32

Post by Psychophanta »

I see.
I believed that when you create a new entity with the same variable name, the old one was freed. I think this is a good idea.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Kuzmat
User
User
Posts: 13
Joined: Mon Jan 27, 2014 9:09 am

Re: MP3D Engine Alpha 32

Post by Kuzmat »

Hi mpz. Please make a ThreadSafe&Unicode version for PB5.31
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Sphere texture mapping

Post by Psychophanta »

Since the example "MP_Spherical Mapping mit UV Koodinaten.pb" contained in the examples pack does not perform a correct texture mapping in none of the 4 spheres, i decided to perform a ASM funtion and share it here:

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
http://www.zeitgeistmovie.com

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