Page 57 of 71
Re: MP3D Engine Alpha 32
Posted: Fri Jan 02, 2015 9:59 am
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 )!

Re: MP3D Engine Alpha 32
Posted: Tue Feb 17, 2015 9:40 pm
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.
Re: MP3D Engine Alpha 32
Posted: Wed Feb 18, 2015 11:42 pm
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
Re: MP3D Engine Alpha 32
Posted: Sun Feb 22, 2015 11:53 am
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.
Re: MP3D Engine Alpha 32
Posted: Sun Feb 22, 2015 12:20 pm
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
Re: MP3D Engine Alpha 32
Posted: Sun Feb 22, 2015 1:46 pm
by Gemorg
Maybe I don't understand something, but these libraries don't have the MP_2DPhysicBodyRemove(Body) function.
Re: MP3D Engine Alpha 32
Posted: Sun Feb 22, 2015 2:01 pm
by Psychophanta
Ok, then Michael must forgot something, sorry.
Re: MP3D Engine Alpha 32
Posted: Sun Feb 22, 2015 4:09 pm
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
Re: MP3D Engine Alpha 32
Posted: Sun Feb 22, 2015 5:38 pm
by Gemorg
Thanks! Perfectly works!
Re: MP3D Engine Alpha 32
Posted: Mon Feb 23, 2015 7:23 am
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.
Re: MP3D Engine Alpha 32
Posted: Thu Apr 16, 2015 8:12 pm
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
Re: MP3D Engine Alpha 32
Posted: Tue Apr 28, 2015 2:07 pm
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
Re: MP3D Engine Alpha 32
Posted: Tue Apr 28, 2015 5:40 pm
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.
Re: MP3D Engine Alpha 32
Posted: Fri May 01, 2015 6:55 am
by Kuzmat
Hi mpz. Please make a ThreadSafe&Unicode version for PB5.31
Sphere texture mapping
Posted: Wed May 20, 2015 10:05 pm
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