Page 43 of 71

Re: MP3D Engine Alpha 32

Posted: Thu Dec 26, 2013 3:05 pm
by N_Gnom
Like i write in my last post, i have copied it in the \subsystems\DX9 folder.

Don´t run

see: Image


edit: now it runs.Why? I don´t know.New installed on user\documents...GO!

Re: MP3D Engine Alpha 32

Posted: Fri Dec 27, 2013 12:02 pm
by applePi
here is a cup and a pot.
Image
it is made from a cone parametric formula which are in fact a tube with one mouth smaller than the other. the cube making begins from the base and up
the pot are made from a copy of the cup , then applying MP_FreeTriangle(pot, 1) 2563 times from the base and up, if you continue you will make a hole in the pot.
look that the cup have a closed bowl bottom, this is because we close its handle in line 207

Code: Select all

If i = 61     ; the end of the cup handle 
  Nozzle = 0  ; to close the cup handle
EndIf 
so we have the unreal thing like this:
Image
but comment line 207 and the body making will continue so we will have a perfect shape like this
Image
but heh with a hole at the bottom of the cup and a hole at the bottom of the pot
may be we can use MP_AddMesh(source_mesh,dest_mesh) also , i will try it later.
one problem with the objects made from a thin wall is that it has poor physics collision and the objects pass through them easily.
the only important part in this long code is the very short cup procedure the other code are just for controlling the figure by keys

Code: Select all

#BUTTON = 6
Global stop = 0

Structure vector3d
  x.f
  y.f
  z.f
EndStructure
    
Declare cup(incr.f) 
Quit.b = #False

ExamineDesktops()
MP_Graphics3D (DesktopWidth(0),DesktopHeight(0),0,2) ; Erstelle ein WindowsFenster #Window = 0
SetWindowTitle(0, "Tubes .. press space to toggle rotation, press S  to save to knot.x file") 
ButtonGadget(#BUTTON, 0, DesktopHeight(0)-60, 60, 30, "rotate/stop") 
MP_Viewport(0,0,DesktopWidth(0),DesktopHeight(0)-60)
camera=MP_CreateCamera()

light=MP_CreateLight(2)
MP_LightSetColor (light, RGB(255,255,255))

MP_PositionEntity(light, 0, 10, 20)
MP_EntityLookAt(light,0,0,0)

Global Mesh = MP_CreateMesh()
SetActiveGadget(#BUTTON)
  

Quit.b = #False 

;==============================================================
tex$ = #PB_Compiler_Home + "Examples/3D/Data/Textures/" + "clouds.jpg"
Texture = MP_LoadTexture(tex$)
MP_EntitySetTexture (Mesh, Texture )
MP_MaterialEmissiveColor (Texture,0,255,255,255)

MP_PositionCamera(camera, 0, 2, 5)
MP_CameraLookAt(camera,0,0,0)
MP_PositionEntity(light, 0 , 0, 10)
MP_EntityLookAt(light,0,0,0)
cup(0.5) ;its coefficient determines the radius of the bigger nozzle

MP_ScaleEntity(Mesh, 0.1, 0.1, 0.1)
MP_RotateEntity(Mesh, -90, 0, 0)
pot = MP_CopyEntity(Mesh) ; copy the cup to pot
For i=0 To 2562
  MP_FreeTriangle(pot, 1) ; converting the glass shape to a pot
Next  
rot.l=1 :stopFlag = 1 : wireFrame.b = 0
xs.f = 0.1:ys.f = 0.1:zs.f = 0.1
x.f: y.f :z.f: x0.f: y0.f=1 :z0.f
rotx.f:roty.f=0.5:rotz.f :rotx0.f: roty0.f: rotz0.f
h.f=0:up.f = -6 :depth.f=-10
x.f=90: y.f=0: z.f=0 :indx = 126
MP_PositionEntity(Mesh,h+3,up,depth)
MP_PositionEntity(pot,h-5,up-3,depth)
Repeat
  
  Event = WindowEvent()
  If Event = #PB_Event_Gadget
    Select EventGadget()
      Case #BUTTON
        If rot = 0
          rot = 1
          rotx= rotx0:roty=roty0:rotz=rotz0 ; restore rotation status
          stopFlag = 1
          
        Else
          rot = 0
          rotx0= rotx:roty0=roty:rotz0=rotz ;back up rotation status
          rotx=0:roty=0:rotz=0
          stopFlag = 0
          
        EndIf
                    
    EndSelect
  EndIf 
  If stopFlag=1
    x + rotx
    y + roty
    z + rotz
  EndIf
  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
  If MP_KeyDown(#PB_Key_Up)  ; rotate left
    rotx=1:roty=0:rotz=0
    rotx0 = rotx: roty0 = roty :rotz0 = rotz
    x + rotx
    y + roty
    z + rotz
    stopFlag=0
    rot = 0
  ElseIf MP_KeyDown(#PB_Key_Down) ; rotate right
    rotx=-1:roty=0:rotz=0
    rotx0 = rotx: roty0 = roty :rotz0 = rotz
    x + rotx
    y + roty
    z + rotz
    stopFlag=0
    rot = 0
  ElseIf MP_KeyDown(#PB_Key_Right)   ; rotate up
    rotx=0:roty=1:rotz=0
    rotx0 = rotx: roty0 = roty :rotz0 = rotz
    x + rotx
    y + roty
    z + rotz
    stopFlag=0
    rot = 0
  ElseIf MP_KeyDown(#PB_Key_Left) ; rotate down
    rotx=0:roty=-1:rotz=0 
    rotx0 = rotx: roty0 = roty :rotz0 = rotz
    x + rotx
    y + roty
    z + rotz
    stopFlag=0
    rot = 0
  EndIf 
  
  If MP_KeyDown(#PB_Key_PageUp) ; scale up model
    xs.f + 0.01:ys.f + 0.01:zs.f + 0.01
    MP_ScaleEntity(Mesh,xs,ys,zs)
    
  ElseIf MP_KeyDown(#PB_Key_PageDown) ; scale down model
    xs -0.01:ys -0.01:zs- 0.01
    If xs<0 :xs=0:ys=0:zs=0:EndIf
    MP_ScaleEntity(Mesh,xs,ys,zs)
    
  EndIf
  If MP_KeyDown(#PB_Key_Pad8) ; up move
    up + 0.1
    MP_PositionEntity(Mesh,h,up,depth)
   ElseIf MP_KeyDown(#PB_Key_Pad2) ; down move
    up - 0.1
    MP_PositionEntity(Mesh,h,up,depth)
  ElseIf MP_KeyDown(#PB_Key_Pad6)
    h - 0.1
    MP_PositionEntity(Mesh,h,up,depth)
    ElseIf MP_KeyDown(#PB_Key_Pad4)
    h + 0.1
    MP_PositionEntity(Mesh,h,up,depth)
    
    ElseIf MP_KeyDown(#PB_Key_Q) ; forward move
    depth - 0.1
    MP_PositionEntity(Mesh,h,up,depth)
    ElseIf MP_KeyDown(#PB_Key_A) ; inward move
    depth + 0.1
    MP_PositionEntity(Mesh,h,up,depth)
    ElseIf MP_KeyHit(#PB_Key_W) ; display wire frame for the material
      If wireFrame=0
      MP_Wireframe (1) 
      wireFrame ! 1
         ElseIf wireFrame=1
           MP_Wireframe (0)
           wireFrame ! 1 
      EndIf
    ElseIf MP_KeyDown(#PB_Key_D) 
      MP_FreeTriangle(Mesh, 1)
      ;indx -1: MP_FreeVertex(Mesh ,indx)
    ElseIf MP_KeyDown(#PB_Key_S)  
      MP_SaveMesh("glass.x",Mesh)

        
  EndIf
   If MP_KeyDown(#PB_Key_Escape)
      Quit = #True
    EndIf
  MP_DrawText (1,1,"press W _wireFrame, D _ delete triangles")  
  MP_DrawText (1,15,"keyPad keys: up.down.left.right")
  ;MP_RotateEntity(Mesh, 90+x, y, z)
  MP_RotateEntity(Mesh, -180+x, y, z)
  MP_RotateEntity(pot, -180+x, y, z)
  MP_RenderWorld() ; Erstelle die Welt
  MP_Flip ()  
    
Until Quit = #True Or Event = #PB_Event_CloseWindow


; main program
 Procedure cup(incr.f)
  x.f: y.f :z.f : u.f: v.f: r.f
      majorOrbit.l = 100 : minorOrbit.l = 20
      majorStep.f   = 2 * #PI / majorOrbit
      minorStep.f   = 2 * #PI / minorOrbit
      i.l: j.l: txu.f : txv.f
      Zincr.f 
       
      Nozzle.f = -15  ; determine the radius of the smaller nozzle of the funnel
      Nozzle2.f = 4
      
      For i = 0 To majorOrbit
        
        If i <= 20
          Nozzle.f  + incr
          
          Zincr = 0.3 ; Zincr determine the rate of increase/decrease the circles radius over time
        EndIf
        
        If i <= 60 And i > 20
         
          Zincr = 0.45
          Nozzle = 4
        EndIf 
                
            If i = 61     ; the end of the cup handle and the begening of its big cone (which contains the Liquid)
           
              Nozzle = 0  ; to close the cup handle, it will close the big cone bottom
            EndIf 
       
        If i > 61  ; the begening of the big cone (which contains the Liquid)
          
         ; Zincr = 0.45
                     
          Nozzle2.f  + incr  ; incr determines the radius of the bigger nozzle
          Nozzle = Nozzle2
        EndIf 
        
        v = i * majorStep
        For j = 0 To minorOrbit
          u = j * minorStep
          
          x = Cos(u)*Nozzle 
          y = Sin(u)*Nozzle
         
          
          MP_AddVertex (Mesh, x, y,z,0,txu,txv)
          ; texture the whole mesh with one picture stretched
          txv = txv + 1/minorOrbit ; texture coordinates
          
        Next
        
        If i > 61
            y2.f = 0.25 * x * x - 1.5 * x + 0.25 ;parabola curve
            Zincr = y2/40
          EndIf
        z + Zincr
        
        
        txv = 0
        txu = txu + 1/majorOrbit 
      Next
      For i = 0 To majorOrbit-1
      For j = 0 To minorOrbit
         
          MP_AddTriangle (Mesh,t,t+1,t + minorOrbit+1)
          MP_AddTriangle (Mesh,t + minorOrbit+1,t + minorOrbit+2,t+1 )
          
          If i=majorOrbit-1 And j=minorOrbit-1 ;bypass the last triangle
            minorOrbit-1
          EndIf 
          t + 1   
          
     Next
     
   Next  
      
    
  EndProcedure
  
  

Re: MP3D Engine Alpha 32

Posted: Fri Dec 27, 2013 2:19 pm
by mpz
Hi,

@Psychophanta and @applePi much thanks, i love to create these kinds of meshs :)

Greetings
Michael

Re: MP3D Engine Alpha 32

Posted: Fri Dec 27, 2013 7:46 pm
by Psychophanta
Here you can find more surfaces in a mathematical way:
http://www.mathcurve.com/surfaces/superficies.shtml

Re: MP3D Engine Alpha 32

Posted: Tue Jan 07, 2014 1:56 am
by Mythros
Edit: Sorry for the double post. The server messed up when I hit submit >.<

Re: MP3D Engine Alpha 32

Posted: Thu Jan 09, 2014 12:19 pm
by N_Gnom
If i turn the camera with MP_TurnCamera and then i would move it with MP_MoveCamera it don´t move with the new directions applied with MP_TurnCamera.

Btw.: TurnCamera and TurnEntity works not the same way with the x,y,z axes.

Btw2.: Parenting works not correctly with the camera commands.
Maybe its better MP_MoveEntity and MP_RotateEntity and MP_TurnEntity should work with the camera as Entity.

only my 2 cents.


Btw.: very good work by you mpz....

Re: MP3D Engine Alpha 32

Posted: Thu Jan 09, 2014 4:16 pm
by Mythros
Hi, @mpz. For some reason, the MP3D alpha 33 threadsafe / unicode is still silently crashing on my PB 5.11... :(

Re: MP3D Engine Alpha 32

Posted: Thu Jan 09, 2014 4:34 pm
by N_Gnom
try the actually mp3d for pb5.2x and install 5.2x before!!!
unicode crashes not but there is a font draw problem...
btw. i hope mpz could solve the problems some posts ago

Re: MP3D Engine Alpha 32

Posted: Sat Jan 11, 2014 8:50 am
by N_Gnom
Have a problem.
Test this code.
MP_TurnCamera doesn´t work correctly.
Code should explain all.
Second problem: press W or S to turn the camera and then move forward.
The moving isn´t correct in the new direction.
It should be a simple camera movement.

Code: Select all

MP_Graphics3DWindow(0, 0, 800, 600, "MP3D", 0)
MP_VSync(2)
light0 = MP_CreateLight(1)
MP_PositionEntity(light0, 0, 0, 0)
cam = MP_CreateCamera()

MP_PositionCamera(cam, 0, 0, -35)
MP_AmbientSetLight (RGB( 0, 154, 205))
cube = MP_CreateCube()
MP_PositionEntity(cube, 0, 0, 0)

cube2= MP_CreateSphere(1)
MP_PositionEntity(cube2,0,0,-25)

While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow
  
    
  If MP_KeyDown(#PB_Key_Down) = 1
    MP_MoveCamera(cam,0,0,-3)
  EndIf   
  If MP_KeyDown(#PB_Key_Up) = 1
    MP_MoveCamera(cam,0,0,3)
  EndIf 
  If MP_KeyDown(#PB_Key_Left) = 1
    MP_MoveCamera(cam,-5,0,0)
  EndIf 
  If MP_KeyDown(#PB_Key_Right) = 1
    MP_MoveCamera(cam,5,0,0)
  EndIf 
    If MP_KeyDown(#PB_Key_W) = 1 
    MP_TurnCamera(cam,0,0,1)      ; its the Z axis, should be X Axis
  EndIf 
    If MP_KeyDown(#PB_Key_S) = 1
    MP_TurnCamera(cam,0,0,-1)
  EndIf 

  MP_DrawText(1,10,"FPS = "+Str(MP_FPS()))
  MP_DrawText(1,25,"MP_EntityGetPitch(cam) = "+MP_EntityGetPitch(cam))
  MP_DrawText(1,45,"MP_EntityGetYaw(cam) = "+MP_EntityGetYaw(cam))
  MP_DrawText(1,65,"MP_EntityGetRoll(cam) = "+MP_EntityGetRoll(cam))
  MP_DrawText(1,85,"Press W to look up and S to look down")
  MP_RenderWorld()
  MP_Flip()  
Wend

Re: MP3D Engine Alpha 32

Posted: Sat Jan 11, 2014 10:08 am
by Psychophanta
N_Gnom wrote:Have a problem.
MP_TurnCamera doesn´t work correctly.
Confirmed, the 3 axis are swapped!

Re: MP3D Engine Alpha 32

Posted: Sat Jan 11, 2014 11:33 am
by N_Gnom
Not only that.
If i look a bit up(i.e. 10 steps) and i move forward it moves -10 steps in downside direction.(sorry about my bad english sometimes...smile)

My example should help mpz to test if it is correctly.

Btw.: Parenting with camera doesn´t work too.

Re: MP3D Engine Alpha 32

Posted: Sun Jan 12, 2014 12:09 am
by mpz
Hi,

i had a problem with the MP_TurnCamera and PB_511 and PB_521. The lib with th esame soucecode works differnt with both version. I hope i find the problem an solved it. I have actualized the lbs and 3 tes codes:

x86 for PB 511 and older
http://www.flasharts.de/mpz/mp33/pb511/MP3D_Library.zip

x86 for pb 520 and newer
http://www.flasharts.de/mpz/mp33/pb520/MP3D_Library.zip

Turn the camera

Code: Select all

MP_Graphics3DWindow(0, 0, 800, 600, "MP3D", 0)
MP_VSync(2)
light0 = MP_CreateLight(1)
MP_PositionEntity(light0, 0, 0, 0)
cam = MP_CreateCamera()

MP_PositionCamera(cam, 0, 0, -35)
MP_AmbientSetLight (RGB( 0, 154, 205))
cube = MP_CreateCube()
MP_PositionEntity(cube, 0, 0, 0)

;cube2 = MP_CreateSphere(1)

cube2 = MP_CreateTeapot()

MP_PositionEntity(cube2,0,0,-25)

While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow
 
  If MP_KeyDown(#PB_Key_Down) = 1 ; down
    MP_TurnCamera(cam,0,-1,0)
  EndIf   
  
  If MP_KeyDown(#PB_Key_Up) = 1 ; up
    MP_TurnCamera(cam,0,1,0)
  EndIf
  
  If MP_KeyDown(#PB_Key_Left) = 1 ; left
    MP_TurnCamera(cam,-1,0,0)
  EndIf
  
  If MP_KeyDown(#PB_Key_Right) = 1 ; right
    MP_TurnCamera(cam,1,0,0)
  EndIf
 
  If MP_KeyDown(#PB_Key_W) = 1 ; front
    MP_TurnCamera(cam,0,0,1)      ; its the Z axis, should be X Axis
  EndIf
  
  If MP_KeyDown(#PB_Key_S) = 1 ; back
    MP_TurnCamera(cam,0,0,-1)
  EndIf

  
  MP_DrawText(1,10,"FPS = "+Str(MP_FPS()))
  MP_DrawText(1,25,"MP_EntityGetPitch(cam) = "+MP_EntityGetPitch(cam))
  MP_DrawText(1,45,"MP_EntityGetYaw(cam) = "+MP_EntityGetYaw(cam))
  MP_DrawText(1,65,"MP_EntityGetRoll(cam) = "+MP_EntityGetRoll(cam))
  MP_DrawText(1,85,"Press W to turn left and S to tunr right")
  MP_RenderWorld()
  MP_Flip() 
Wend
Move the camera

Code: Select all

MP_Graphics3DWindow(0, 0, 800, 600, "MP3D", 0)
MP_VSync(2)
light0 = MP_CreateLight(1)
MP_PositionEntity(light0, 0, 0, 0)
cam = MP_CreateCamera()

MP_PositionCamera(cam, 0, 0, -35)
MP_AmbientSetLight (RGB( 0, 154, 205))
cube = MP_CreateCube()
MP_PositionEntity(cube, 0, 0, 0)

;cube2 = MP_CreateSphere(1)

cube2 = MP_CreateTeapot()

MP_PositionEntity(cube2,0,0,-25)

While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow
 
   
  If MP_KeyDown(#PB_Key_Down) = 1
    MP_MoveCamera(cam,0,-1,0)
  EndIf   
 If MP_KeyDown(#PB_Key_Up) = 1
    MP_MoveCamera(cam,0,1,0)
  EndIf
  If MP_KeyDown(#PB_Key_Left) = 1
    MP_MoveCamera(cam,-1,0,0)
  EndIf
  If MP_KeyDown(#PB_Key_Right) = 1
    MP_MoveCamera(cam,1,0,0)
  EndIf
  
  
  If MP_KeyDown(#PB_Key_W) = 1
    MP_MoveCamera(cam,0,0,1)      ; its the Z axis, should be X Axis
  EndIf
    If MP_KeyDown(#PB_Key_S) = 1
    MP_MoveCamera(cam,0,0,-1)
  EndIf
  

  MP_DrawText(1,10,"FPS = "+Str(MP_FPS()))
  MP_DrawText(1,25,"MP_EntityGetPitch(cam) = "+MP_EntityGetPitch(cam))
  MP_DrawText(1,45,"MP_EntityGetYaw(cam) = "+MP_EntityGetYaw(cam))
  MP_DrawText(1,65,"MP_EntityGetRoll(cam) = "+MP_EntityGetRoll(cam))
  MP_DrawText(1,85,"Press W to go front and S to go back down")

  MP_RenderWorld()
  MP_Flip() 
Wend
turn and move camera

Code: Select all

MP_Graphics3DWindow(0, 0, 800, 600, "MP3D", 0)
MP_VSync(2)
light0 = MP_CreateLight(1)
MP_PositionEntity(light0, 0, 0, 0)
cam = MP_CreateCamera()

MP_PositionCamera(cam, 0, 0, -35)
MP_AmbientSetLight (RGB( 0, 154, 205))
cube = MP_CreateCube()
MP_PositionEntity(cube, 0, 0, 0)

cube2= MP_CreateSphere(1)
MP_PositionEntity(cube2,0,0,-25)

While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow
 
   
  If MP_KeyDown(#PB_Key_Down) = 1
    MP_TurnCamera(cam,0,-1,0)
  EndIf   
  If MP_KeyDown(#PB_Key_Up) = 1
    MP_TurnCamera(cam,0,1,0)
  EndIf
  If MP_KeyDown(#PB_Key_Left) = 1
    MP_TurnCamera(cam,-1,0,0)
  EndIf
  If MP_KeyDown(#PB_Key_Right) = 1
    MP_TurnCamera(cam,1,0,0)
  EndIf
    If MP_KeyDown(#PB_Key_W) = 1
    MP_MoveCamera(cam,0,0,1)      ; its the Z axis, should be X Axis
  EndIf
    If MP_KeyDown(#PB_Key_S) = 1
    MP_MoveCamera(cam,0,0,-1)
  EndIf

  MP_DrawText(1,10,"FPS = "+Str(MP_FPS()))
  MP_DrawText(1,25,"MP_EntityGetPitch(cam) = "+MP_EntityGetPitch(cam))
  MP_DrawText(1,45,"MP_EntityGetYaw(cam) = "+MP_EntityGetYaw(cam))
  MP_DrawText(1,65,"MP_EntityGetRoll(cam) = "+MP_EntityGetRoll(cam))
  MP_DrawText(1,85,"Press W to go front and S to go back down")

  MP_RenderWorld()
  MP_Flip() 
Wend
i hope these helps...

Greetings Michael

Re: MP3D Engine Alpha 32

Posted: Sun Jan 12, 2014 12:56 am
by N_Gnom
Well, i know that the parameters x,y and z are swapped....
Z now works correctly.
X and Y you must change.

And then if you turn the camera up and down on the x axis and then you move the camera it doesn´t move in the new direction.
Try you last code in your code.
Move the camera up or down and then move it....then you should see it.

Re: MP3D Engine Alpha 32

Posted: Sun Jan 12, 2014 4:34 pm
by Psychophanta
@mpz
N_Gnom is right.
Please take a look.
2 examples:
MP_TurnCamera(cam,0,-1,0) now turns camera around x axis and it should turn around y axis, decrementing the Yaw value, and rotating camera clockwise while watching to the camera from up-side to downwards.
MP_TurnCamera(cam,-1,0,0) now turns camera around y axis and it should be around x axis, decrementing the Pitch value, and rotating camera clockwise while watching to the camera from right-side to leftwards.

By the way:
MP_EntityGetPitch() is right done.
MP_EntityGetRoll() is right done.
MP_EntityGetYaw() has the sign changed.

Re: MP3D Engine Alpha 32

Posted: Sun Jan 12, 2014 4:50 pm
by Psychophanta
Is this a bug?:

Code: Select all

Define .f
ExamineDesktops()
Global bitplanes.b=DesktopDepth(0),RX.w=DesktopWidth(0),RY.w=DesktopHeight(0)
MP_Graphics3D(RX,RY,0,1):MP_VSync(1)
SetWindowTitle(0,"e")
Global.i camera,light,arrow
camera=MP_CreateCamera()
MP_PositionCamera(camera,0,5,-10)
MP_CameraLookAt(camera,0,0,0)
light=MP_CreateLight(2)
MP_LightSetColor(light,RGB(219,118,50))
MP_PositionEntity(light,-6,10,-5)
MP_AmbientSetLight(RGB(0,100,200))

arrow=MP_CreateCylinder(60,200)
MP_PositionMesh(arrow,0,0,0)
MP_RotateEntity(arrow,0,0,0)
Repeat
  MP_TurnCamera(camera,0,0,0); <- with this line you will see nothing  o_O (Why?) . Delete it to see all working nice.
  MP_RenderWorld()
  MP_Flip()
Until MP_KeyDown(#PB_Key_Escape) Or WindowEvent()=#PB_Event_CloseWindow