Page 45 of 71

Re: MP3D Engine Alpha 32

Posted: Sat Jan 18, 2014 11:02 pm
by Mythros
Hi all. Can someone please help me with my 3D object selector? I basically need to be able to hold control & hold down left mouse button to select multiple objects and turn them to half alpha to show they are selected, and when control is NOT held, the ability to hold down the left mouse button, and select only ONE object at a time, halving it's alpha as well until the next object is selected. When you click the background, all objects with half alpha go back to completely non-alpha, same thing when you click on the same object or objects that have been already highlighted. I would be eternally greatful for someones help!

Here's the code:

Code: Select all

Macro Instr(Begin,OriginalString,StringToFind)
  FindString(OriginalString,StringToFind,Begin)
EndMacro

Structure DSBCAPS
  dwSize.l
  dwFlags.l
  dwBufferBytes.l
  dwUnlockTransferRate.l
  dwPlayCpuOverhead.l
EndStructure

Structure MasterStructure
  nwid.i
  enid.i
  msid.i
  mtid.i
  txid.i  
  mnme.s
  xpos.f
  ypos.f
  zpos.f
  xrot.f
  yrot.f
  zrot.f
  xscl.f
  yscl.f
  zscl.f
EndStructure

Structure Entities Extends MasterStructure
EndStructure
 
Global max_structures = 999
 
Dim Entities.MasterStructure(max_structures)
 
Structure SelectedMasterStructure
  selected.b
  nwid.i
  enid.i
  msid.i
  mtid.i
  txid.i
  mnme.s
  xpos.f
  ypos.f
  zpos.f
  xrot.f
  yrot.f
  zrot.f
  xscl.f
  yscl.f
  zscl.f
EndStructure

Structure SelectedEntities Extends SelectedMasterStructure
EndStructure
 
Global max_selected_structures = 9999999
 
Dim SelectedEntities.SelectedMasterStructure(max_selected_structures)
 
MP_Graphics3D(800, 600, 0, 2)

SetWindowTitle(0, "Multi-Pick Demo")

cam=MP_CreateCamera()
MP_CreateLight(1)

Max = 4

Global objcount

For n = 0 To Max
      Entities.MasterStructure(n)\xpos = 10-Random(20)
      Entities.MasterStructure(n)\ypos = 10-Random(20)
      Entities.MasterStructure(n)\zpos = 24+Random(40)
     
      Entities.MasterStructure(n)\enid = MP_CreateSphere(100)
      MP_PositionEntity (Entities.MasterStructure(n)\enid, Entities.MasterStructure(n)\xpos, Entities.MasterStructure(n)\ypos, Entities.MasterStructure(n)\zpos)
      MP_EntitySetColor(Entities.MasterStructure(n)\enid, RGBA(Random(255, 0), Random(255, 0), Random(255, 0), 255))
      objcount+1
Next n

  max_hex = 999
  Dim Which_Hex(max_hex)
   
  Which_Hex(0) = $FF
  Which_Hex(1) = $FF
  Which_Hex(2) = $00
  Which_Hex(3) = $00
   
  A1 = Which_Hex(0)
  R1 = Which_Hex(1)
  G1 = Which_Hex(2)
  B1 = Which_Hex(3)

  While Not MP_KeyDown(#PB_Key_Escape) And Not Quit
   
    event = WindowEvent()
   
    If event = #PB_Event_CloseWindow
      Quit = 1
    EndIf
 
    If GetAsyncKeyState_(#VK_CONTROL)
           
      If MP_MouseButtonDown(0)
     
        If GetFocus_()=WindowID(0)
               
          SelectedEntities.SelectedMasterStructure(0)\enid = MP_PickCamera (cam,WindowMouseX(0),WindowMouseY(0))
             
          If SelectedEntities.SelectedMasterStructure(0)\enid
                     
            SelectedEntities.SelectedMasterStructure(0)\selected = #True
               
          Else
               
            SelectedEntities.SelectedMasterStructure(0)\selected = #False
                     
          EndIf
         
        EndIf
     
      EndIf
           
    ElseIf MP_MouseButtonHit(0)
     
      If GetFocus_()=WindowID(0)
             
        SelectedEntities.SelectedMasterStructure(0)\enid = MP_PickCamera (cam,WindowMouseX(0),WindowMouseY(0))
           
        If SelectedEntities.SelectedMasterStructure(0)\enid
                   
          SelectedEntities.SelectedMasterStructure(0)\selected = #True
             
        Else
             
          SelectedEntities.SelectedMasterStructure(0)\selected = #False
                   
        EndIf
           
      EndIf
                   
    EndIf
           
    If SelectedEntities.SelectedMasterStructure(0)\selected
             
      If SelectedEntities.SelectedMasterStructure(0)\enid
             
        For i = 1 To MP_CountVertices(SelectedEntities.SelectedMasterStructure(0)\enid)
                         
          color = MP_VertexGetColor(SelectedEntities.SelectedMasterStructure(0)\enid, i)
                           
          MP_VertexSetColor(SelectedEntities.SelectedMasterStructure(0)\enid, i, MP_ARGB(A1, R1, G1, B1))
                           
          If i = MP_CountVertices(SelectedEntities.SelectedMasterStructure(0)\enid)
                             
            Break
                             
          EndIf
                           
        Next
               
      EndIf
             
    EndIf
             
    If mode = 1
               
      If SelectedEntities.SelectedMasterStructure(0)\selected
                 
        If MP_KeyDown(#PB_Key_Up) Or MP_KeyDown(#PB_Key_W): MP_MoveEntity(SelectedEntities.SelectedMasterStructure(0)\enid, 0, 1, 0): EndIf
        If MP_KeyDown(#PB_Key_Down) Or MP_KeyDown(#PB_Key_S): MP_MoveEntity(SelectedEntities.SelectedMasterStructure(0)\enid, 0, -1, 0): EndIf
                               
      EndIf
                 
    EndIf
           
    If MP_MouseButtonDown(1)
           
      If GetFocus_()=WindowID(0)
                     
        SelectedEntities.SelectedMasterStructure(0)\enid = MP_PickCamera (cam,WindowMouseX(0),WindowMouseY(0))
       
        If SelectedEntities.SelectedMasterStructure(0)\enid
          MP_FreeEntity (SelectedEntities.SelectedMasterStructure(0)\enid)
        EndIf
           
      EndIf
                   
    EndIf
   
    MP_DrawText (100,40, "Mesh "+Str(SelectedEntities.SelectedMasterStructure(0)\enid)+" selected",0)
    MP_DrawText (100,60, "Mesh Count: "+Str(MeshCount),0)
   
    MP_RenderWorld()
    MP_Flip ()
 
  Wend

End
Thank You so much and have a good day!

Mythros

Re: MP3D Engine Alpha 32

Posted: Sun Jan 19, 2014 4:41 pm
by mpz
Hi Mythros,

your code has some problems. It is not easy for me to understand what exactly you want to do with yout structures and extends?! You use a dimfield, but you use all times the same entry, so it is not possible to select more than one mesh. Second problem, in every render loop you color all vertices of a selected mesh (MP_VertexSetColor(SelectedEntities.SelectedMasterStructure(0)\enid, i, MP_ARGB(A1, R1, G1, B1))). The function is not very fast and so the program is very slows.

To solve the problems:
Please use lists(NewList Name.<Typ>() ), it is more easier to handle. And make a query about coloring a mesh

I hope i could help a little bit...

Greetings Michael

Re: MP3D Engine Alpha 32

Posted: Sun Jan 19, 2014 5:20 pm
by mpz
Hi Mythos,

Here a litte demo with multiselect with strg key


Greetings Michael

Code: Select all

;-
;- ProgrammStart
;////////////////////////////////////////////////////////////////
;//
;// Project Title: MP 3D Engine
;// File Title: MP_PickingDemo.pb
;// Created On: 14.1.2009
;// Updated On: 
;// Author: Michael Paulwitz
;// OS:Windows
;// 
;// Demofile für PickBefehl
;// 
;////////////////////////////////////////////////////////////////


Structure findmesh
  Entity.i
  what_ever_you_need.i
EndStructure

MP_Graphics3D (640,480,0,1) ; Erstelle ein WindowsFenster #Window = 0
 
SetWindowTitle(0, "Picking Demo, left mouse show mesh, right one delete the mesh") 

cam=MP_CreateCamera() ; Kamera erstellen
MP_CreateLight(1) ; Es werde Licht

Max = 40 ; Was der Rechner kann = ?

For n = 0 To Max

    Meshs = MP_CreateSphere(10)
    MP_PositionEntity (Meshs,10-Random(20),10-Random(20),24+Random(40))
    
Next n


NewList MyMesh.findmesh()

While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
  
   Timer + 1

   If MP_MouseButtonDown(0) ; Linke Maustaste gedrückt?
   
      If GetFocus_()=WindowID(0) ; Fenster aktiv? 
         
        If GetAsyncKeyState_(#VK_CONTROL)
          
         Meshfound = MP_PickCamera (cam,WindowMouseX(0),WindowMouseY(0))
         If Meshfound   
               MP_DrawText (100,40,"Mesh "+Str(Meshfound)+" found")
               ForEach MyMesh()
                 If MyMesh()\Entity = Meshfound
                     Meshfound = 0
                     Break
                 EndIf
               Next
               If Meshfound
                 AddElement(MyMesh())
                 MyMesh()\Entity = Meshfound
               EndIf  
         EndIf
     Else  
         Meshfound = MP_PickCamera (cam,WindowMouseX(0),WindowMouseY(0))
         If Meshfound   
               MP_DrawText (100,40,"Mesh "+Str(Meshfound)+" found")
               ClearList(MyMesh())
               AddElement(MyMesh())
               MyMesh()\Entity = Meshfound
         EndIf
       EndIf
     EndIf
    EndIf

   If MP_MouseButtonDown(1) ; Rechte Maustaste gedrückt?
   
      If GetFocus_()=WindowID(0) ; Fenster aktiv? 
         
         Meshfound = MP_PickCamera (cam,WindowMouseX(0),WindowMouseY(0))

         If Meshfound   
               MP_FreeEntity (Meshfound)
         EndIf
  
     EndIf
    EndIf
    
    If Timer = 15
       ForEach MyMesh()
         MP_ScaleEntity (MyMesh()\Entity, 1.2 , 1.2, 1.2)
       Next
    EndIf
    
    If Timer = 30
       ForEach MyMesh()
         MP_ScaleEntity (MyMesh()\Entity, 0.8 , 0.8, 0.8)
       Next
       Timer = 0
    EndIf
    
   MP_RenderWorld() ; Erstelle die Welt
   MP_Flip () ; Stelle Sie dar

Wend

Re: MP3D Engine Alpha 32

Posted: Tue Jan 21, 2014 3:58 pm
by applePi
version 0.001 of the tornado:
Image
here is a short story.
no physics but visual effects.
the program is looping over 50000 trials, picking only what are inside a virtual cylinder, then again picking only what are inside a cross section from a virtual cone at a specific y . then adding this point to the Entity as a green color point.
the resulting shape will be like a cone. but with may be index 1 have y = 500. so i want to sort it so index 1 have y = 0 and so on. since i don't know how to sort the Structure PointVertex , i have made a new Structure tmpArray and copying the PointVertex to tmpArray. then sorting this one with the great SortStructuredArray

Code: Select all

SortStructuredArray(tmpArr(), 0, OffsetOf(tmpArray\y), TypeOf(tmpArray\y)) 
after that copying tmpArray again to PointVertex.
that is not necessary, but for a possible future play, as an example look at the unnecessary loop at line 194 and uncomment lines 197..198
If *myvertex\y > 400 And *myvertex\y < 440
;*myvertex\x + 70 ; to shift a slice at 400 < y < 440
;*myvertex\z + 70

to see a shifted slice at that position
my end purpose is to bent the cone like a tornado shape and to rotate a garbage around it
Image

Code: Select all

#Mode = 7 ; #Mode = 1 or #Mode = 7

    Structure PointVertex
      x.f
      y.f
      z.f
      CompilerIf #Mode = 7
        Size.f ;--- Only if Mode = 7
      CompilerEndIf  
      Color.l;d3dcolor
    EndStructure
    
    Structure tmpArray
      index.l
      x.f
      y.f
      z.f
    EndStructure

      
    Global mAngle.f = Cos(-0.05)
    Global pAngle.f = Sin(0.05)
    Global move.f = 0
    
    ; code for MP3D
    Declare DrawMatrix()
    Declare isolate()
    
    Global angle.f
    
ExamineDesktops()
MP_Graphics3D (DesktopWidth(0),DesktopHeight(0),0,3) ; Erstelle ein WindowsFenster #Window = 0
MP_Viewport(0,0,DesktopWidth(0),DesktopHeight(0)-5)
SetWindowTitle(0, "A/Z to move up.down ,...press Up/Down to move tornado, ; press T  to texture the plane ")

    camera=MP_CreateCamera()

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

        
    Global size = 4000
    Global tot  
    Global Entity= MP_CreatePrimitives (size, #Mode)   
     

    Define.f red, green, blue


    Quit.b = #False

    ;==============================================================
    
    DrawMatrix()
    MP_PrimitivesBlendingMode(Entity, 5,2)

    MP_PositionCamera(camera, 0, 300, 700)
    MP_CameraLookAt(camera,0,100,0)
    MP_PositionEntity(light, 0 , 0, 10)
    MP_EntityLookAt(light,0,0,0)
    
    texture2 = MP_LoadTexture(#PB_Compiler_Home + "Examples/3D/Data/Textures/soil_wall.jpg" )

    texture = MP_CreateTextureColor(256, 256, MP_ARGB(255,255,200,200))

plane = MP_CreatePlane(600, 600)

MP_RotateEntity(plane,-90, 0, 90)
MP_PositionEntity(plane, 0,20, 50)
MP_PositionEntity(Entity, 0, 10, 0)
    MP_VSync(0)
        
    xx.f=0 :zz.f=0 : camY=300
    While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow
     
      If MP_KeyDown(#PB_Key_T)
        MP_EntitySetTexture(plane, texture2)
      
      EndIf  
        
      
      If MP_KeyDown(#PB_Key_Up)
       
        zz.f + 20
      ElseIf MP_KeyDown(#PB_Key_Down)
       
        zz.f - 20
     
      EndIf
      If MP_KeyDown(#PB_Key_A)
        camY-10
        MP_PositionCamera(camera, 0, camY, 700)
          ElseIf MP_KeyDown(#PB_Key_Z)
            camY+10
            MP_PositionCamera(camera, 0, camY, 700)
                         
            
        EndIf
                
        MP_TurnEntity(Entity,0,1,0)
               
        isolate(); call the routine for rotating every  point
        
        MP_EntityGetX(Entity , xx)
        MP_EntityGetX(Entity , zz)

        xx = 1 * xx - 0.01 * zz
        zz = 1 * zz + 0.01 * xx
        MP_PositionEntity(Entity, xx, -200, zz)
        
        MP_DrawText (1,1,"FPS = "+Str(MP_FPS()))
        
      MP_RenderWorld()
       
      MP_Flip ()

    Wend
    
   Procedure DrawMatrix()
      
    *Memory = MP_GetMemPrimitives(Entity)
    i = -1
   For j=0 To 50000 
        ;draw points inside an elongated rectangle
      x = Random(400)-200:y = Random(400): z = Random(400)-200
      q.f = (Pow(x,2) + Pow(z,2))
     
   If q <= 20000 ; we choose only what is inside a cylinder
       
    ;check if point inside a specific horizontal cone cross section (circle at specific y position)
    ; the radius of the cone at the height y : r1 = r * h1/h
    ;r1 = r * h1/h
    r1.f = 100 * y / 400 ; the radius of the cone cross secion at the height y
    rr.f = Pow((Pow(x,2) + Pow(z,2)), 0.5)
    If rr <= r1
      i + 1 
      *myvertex.PointVertex = *Memory + i * SizeOf(PointVertex)
     
      r=0:g=255:b=0
      If y < 110:Goto jmp:EndIf ; just to cut the tip of the cone
              
        *myvertex\x = x
        *myvertex\y = y*1.5 ; i am not happy with this but i can't do it from the cone formula above
        *myvertex\z = z
       
        *myvertex\color = MP_ARGB(255,r,g,b)
        
      Else
        
          
      EndIf
    EndIf
    jmp:

      Next
      ;Debug i
      tot = i
      Dim tmpArr.tmpArray(tot)
      *Memory = MP_GetMemPrimitives(Entity)
      *myvertex.PointVertex = *Memory
      
      For i=0 To tot
      
        tmpArr(i)\index = i
        tmpArr(i)\x = *myvertex\x
        tmpArr(i)\y = *myvertex\y
        tmpArr(i)\z = *myvertex\z
        
        *myvertex + SizeOf(PointVertex)
            
      Next
      
      SortStructuredArray(tmpArr(), 0, OffsetOf(tmpArray\y), TypeOf(tmpArray\y))
      
      *Memory = MP_GetMemPrimitives(Entity) 
      *myvertex.PointVertex = *Memory
      
      For i=0 To tot
        ;Debug Str(tmpArr(i)\index) + "    " +Str(tmpArr(i)\y)
        tmpArr(i)\index = i
        *myvertex\x = tmpArr(i)\x 
        *myvertex\y = tmpArr(i)\y
        *myvertex\z = tmpArr(i)\z
                
        *myvertex + SizeOf(PointVertex)
       
        
      Next
      
  
    *Memory = MP_GetMemPrimitives(Entity)
    *myvertex.PointVertex = *Memory
    
    For i=0 To tot ; nothing loop just for testing
     ;Debug "y= " + Str(*myvertex\y) + "    " + "index = " +Str(i)
     If *myvertex\y > 400 And *myvertex\y < 440
        ;*myvertex\x + 70 ; to shift a slice at 400 < y < 440
        ;*myvertex\z + 70
      EndIf 
        *myvertex + SizeOf(PointVertex)
     Next
    
    MP_CloseMemPrimitives(Entity)
      
    EndProcedure 

    Procedure isolate() ; rotate the points
      
      *Memory = MP_GetMemPrimitives(Entity)
      *myvertex.PointVertex = *Memory
      
    For i=0 To tot
      
      x.f = *myvertex\x
      z.f = *myvertex\z
      *myvertex\x = mAngle * x - pAngle * z
      *myvertex\z = mAngle * z + pAngle * x
      
            
                 
      CompilerIf #Mode = 7
        *myvertex\Size = 2.5 ;--- Only if Mode = 7
      CompilerEndIf
     
    
    *myvertex + SizeOf(PointVertex)
      
       Next
       
       MP_CloseMemPrimitives(Entity)

     EndProcedure
    

Re: MP3D Engine Alpha 32

Posted: Fri Jan 24, 2014 2:59 am
by Mythros
Thanks, @mpz. Is there a way if I click on the background OR on an already selected object, to deselect that object? Thank You so kindly! =)

Re: MP3D Engine Alpha 32

Posted: Fri Jan 24, 2014 10:23 am
by mpz
Hi Mythors,

the samecode, but you can deselect a mesh with Shift + left mouseclick

Greetings

Code: Select all

    ;-
    ;- ProgrammStart
    ;////////////////////////////////////////////////////////////////
    ;//
    ;// Project Title: MP 3D Engine
    ;// File Title: MP_PickingDemo.pb
    ;// Created On: 14.1.2009
    ;// Updated On:
    ;// Author: Michael Paulwitz
    ;// OS:Windows
    ;//
    ;// Demofile für PickBefehl
    ;//
    ;////////////////////////////////////////////////////////////////


    Structure findmesh
      Entity.i
      what_ever_you_need.i
    EndStructure

    MP_Graphics3D (640,480,0,1) ; Erstelle ein WindowsFenster #Window = 0
     
    SetWindowTitle(0, "Picking Demo, left mouse show mesh, right one delete the mesh")

    cam=MP_CreateCamera() ; Kamera erstellen
    MP_CreateLight(1) ; Es werde Licht

    Max = 40 ; Was der Rechner kann = ?

    For n = 0 To Max

        Meshs = MP_CreateSphere(10)
        MP_PositionEntity (Meshs,10-Random(20),10-Random(20),24+Random(40))
       
    Next n


    NewList MyMesh.findmesh()

    While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow; Esc abfrage oder Windows Schliessen
     
       Timer + 1

       If MP_MouseButtonDown(0) ; Linke Maustaste gedrückt?
       
          If GetFocus_()=WindowID(0) ; Fenster aktiv?
             
            If GetAsyncKeyState_(#VK_CONTROL)
             
             Meshfound = MP_PickCamera (cam,WindowMouseX(0),WindowMouseY(0))
             If Meshfound   
                   MP_DrawText (100,40,"Mesh "+Str(Meshfound)+" found")
                   ForEach MyMesh()
                     If MyMesh()\Entity = Meshfound
                         Meshfound = 0
                         Break
                     EndIf
                   Next
                   If Meshfound
                     AddElement(MyMesh())
                     MyMesh()\Entity = Meshfound
                   EndIf 
             EndIf
         ElseIf  GetAsyncKeyState_(#VK_SHIFT)  
           
             Meshfound = MP_PickCamera (cam,WindowMouseX(0),WindowMouseY(0))
             If Meshfound   
                   MP_DrawText (100,40,"Mesh "+Str(Meshfound)+" found")
                   ForEach MyMesh()
                     If MyMesh()\Entity = Meshfound
                       
                         DeleteElement(MyMesh()) ; New
                         Break
                     EndIf
                   Next
             EndIf
             
         Else 
             Meshfound = MP_PickCamera (cam,WindowMouseX(0),WindowMouseY(0))
             If Meshfound   
                   MP_DrawText (100,40,"Mesh "+Str(Meshfound)+" found")
                   ClearList(MyMesh())
                   AddElement(MyMesh())
                   MyMesh()\Entity = Meshfound
             EndIf
           EndIf
         EndIf
        EndIf

       If MP_MouseButtonDown(1) ; Rechte Maustaste gedrückt?
       
          If GetFocus_()=WindowID(0) ; Fenster aktiv?
             
             Meshfound = MP_PickCamera (cam,WindowMouseX(0),WindowMouseY(0))

             If Meshfound   
                   MP_FreeEntity (Meshfound)
             EndIf
     
         EndIf
        EndIf
       
        If Timer = 15
           ForEach MyMesh()
             MP_ScaleEntity (MyMesh()\Entity, 1.2 , 1.2, 1.2)
           Next
        EndIf
       
        If Timer = 30
           ForEach MyMesh()
             MP_ScaleEntity (MyMesh()\Entity, 0.8 , 0.8, 0.8)
           Next
           Timer = 0
        EndIf
       
       MP_RenderWorld() ; Erstelle die Welt
       MP_Flip () ; Stelle Sie dar

    Wend

Re: MP3D Engine Alpha 32

Posted: Fri Jan 24, 2014 10:41 am
by mpz
Hi applePi,

i was searching for a tornado shader too, but doesn't found one in the internet....

Here comes a little changing of your code. Now the rotation speed is in the tornado different, on the ground slow and in the sky faster....

:D
Greetings Michael

Code: Select all

    #Mode = 7 ; #Mode = 1 or #Mode = 7

        Structure PointVertex
          x.f
          y.f
          z.f
          CompilerIf #Mode = 7
            Size.f ;--- Only if Mode = 7
          CompilerEndIf 
          Color.l;d3dcolor
        EndStructure
       
        Structure tmpArray
          index.l
          x.f
          y.f
          z.f
        EndStructure

         
        Global mAngle.f = Cos(-0.05)
        Global pAngle.f = Sin(0.05)
        Global move.f = 0
       
        ; code for MP3D
        Declare DrawMatrix()
        Declare isolate()
       
        Global angle.f
       
    ExamineDesktops()
    MP_Graphics3D (DesktopWidth(0),DesktopHeight(0),0,3) ; Erstelle ein WindowsFenster #Window = 0
    MP_Viewport(0,0,DesktopWidth(0),DesktopHeight(0)-5)
    SetWindowTitle(0, "A/Z to move up.down ,...press Up/Down to move tornado, ; press T  to texture the plane ")

        camera=MP_CreateCamera()

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

           
        Global size = 4000
        Global tot 
        Global Entity= MP_CreatePrimitives (size, #Mode)   
         

        Define.f red, green, blue


        Quit.b = #False

        ;==============================================================
       
        DrawMatrix()
        MP_PrimitivesBlendingMode(Entity, 5,2)

        MP_PositionCamera(camera, 0, 300, 700)
        MP_CameraLookAt(camera,0,100,0)
        MP_PositionEntity(light, 0 , 0, 10)
        MP_EntityLookAt(light,0,0,0)
       
        texture2 = MP_LoadTexture(#PB_Compiler_Home + "Examples/3D/Data/Textures/soil_wall.jpg" )

        texture = MP_CreateTextureColor(256, 256, MP_ARGB(255,255,200,200))

    plane = MP_CreatePlane(600, 600)

    MP_RotateEntity(plane,-90, 0, 90)
    MP_PositionEntity(plane, 0,20, 50)
    MP_PositionEntity(Entity, 0, 10, 0)
        MP_VSync(0)
           
        xx.f=0 :zz.f=0 : camY=300
        While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow
         
          If MP_KeyDown(#PB_Key_T)
            MP_EntitySetTexture(plane, texture2)
         
          EndIf 
           
         
          If MP_KeyDown(#PB_Key_Up)
           
            zz.f + 20
          ElseIf MP_KeyDown(#PB_Key_Down)
           
            zz.f - 20
         
          EndIf
          If MP_KeyDown(#PB_Key_A)
            camY-10
            MP_PositionCamera(camera, 0, camY, 700)
              ElseIf MP_KeyDown(#PB_Key_Z)
                camY+10
                MP_PositionCamera(camera, 0, camY, 700)
                             
               
            EndIf
                   
            MP_TurnEntity(Entity,0,1,0)
                   
            isolate(); call the routine for rotating every  point
           
            MP_EntityGetX(Entity , xx)
            MP_EntityGetX(Entity , zz)

            xx = 1 * xx - 0.01 * zz
            zz = 1 * zz + 0.01 * xx
            MP_PositionEntity(Entity, xx, -200, zz)
           
            MP_DrawText (1,1,"FPS = "+Str(MP_FPS()))
           
          MP_RenderWorld()
           
          MP_Flip ()

        Wend
       
       Procedure DrawMatrix()
         
        *Memory = MP_GetMemPrimitives(Entity)
        i = -1
       For j=0 To 50000
            ;draw points inside an elongated rectangle
          x = Random(400)-200:y = Random(400): z = Random(400)-200
          q.f = (Pow(x,2) + Pow(z,2))
         
       If q <= 20000 ; we choose only what is inside a cylinder
           
        ;check if point inside a specific horizontal cone cross section (circle at specific y position)
        ; the radius of the cone at the height y : r1 = r * h1/h
        ;r1 = r * h1/h
        r1.f = 100 * y / 400 ; the radius of the cone cross secion at the height y
        rr.f = Pow((Pow(x,2) + Pow(z,2)), 0.5)
        If rr <= r1
          i + 1
          *myvertex.PointVertex = *Memory + i * SizeOf(PointVertex)
         
          r=0:g=255:b=0
          If y < 110:Goto jmp:EndIf ; just to cut the tip of the cone
                 
            *myvertex\x = x
            *myvertex\y = y*1.5 ; i am not happy with this but i can't do it from the cone formula above
            *myvertex\z = z
           
            *myvertex\color = MP_ARGB(255,r,g,b)
           
          Else
           
             
          EndIf
        EndIf
        jmp:

          Next
          ;Debug i
          tot = i
          Dim tmpArr.tmpArray(tot)
          *Memory = MP_GetMemPrimitives(Entity)
          *myvertex.PointVertex = *Memory
         
          For i=0 To tot
         
            tmpArr(i)\index = i
            tmpArr(i)\x = *myvertex\x
            tmpArr(i)\y = *myvertex\y
            tmpArr(i)\z = *myvertex\z
           
            *myvertex + SizeOf(PointVertex)
               
          Next
         
          SortStructuredArray(tmpArr(), 0, OffsetOf(tmpArray\y), TypeOf(tmpArray\y))
         
          *Memory = MP_GetMemPrimitives(Entity)
          *myvertex.PointVertex = *Memory
         
          For i=0 To tot
            ;Debug Str(tmpArr(i)\index) + "    " +Str(tmpArr(i)\y)
            tmpArr(i)\index = i
            *myvertex\x = tmpArr(i)\x
            *myvertex\y = tmpArr(i)\y
            *myvertex\z = tmpArr(i)\z
                   
            *myvertex + SizeOf(PointVertex)
           
           
          Next
         
     
        *Memory = MP_GetMemPrimitives(Entity)
        *myvertex.PointVertex = *Memory
       
        For i=0 To tot ; nothing loop just for testing
         ;Debug "y= " + Str(*myvertex\y) + "    " + "index = " +Str(i)
         If *myvertex\y > 400 And *myvertex\y < 440
            ;*myvertex\x + 70 ; to shift a slice at 400 < y < 440
            ;*myvertex\z + 70
          EndIf
            *myvertex + SizeOf(PointVertex)
         Next
       
        MP_CloseMemPrimitives(Entity)
         
        EndProcedure

        Procedure isolate() ; rotate the points
         
          *Memory = MP_GetMemPrimitives(Entity)
          *myvertex.PointVertex = *Memory
         
        For i=0 To tot
         
          x.f = *myvertex\x
          z.f = *myvertex\z
          
          y.f = *myvertex\y/4000

          
          *myvertex\x = Cos(-y) * x - Sin(y) * z
          *myvertex\z = Cos(-y) * z + Sin(y) * x
                     
          CompilerIf #Mode = 7
            *myvertex\Size = 2.5 ;--- Only if Mode = 7
          CompilerEndIf
         
       
        *myvertex + SizeOf(PointVertex)
         
           Next
           
           MP_CloseMemPrimitives(Entity)

         EndProcedure
        

Re: MP3D Engine Alpha 32

Posted: Fri Jan 24, 2014 11:17 am
by Danilo

Re: MP3D Engine Alpha 32

Posted: Fri Jan 24, 2014 1:16 pm
by applePi
@Michael , thank you for the code i will look at it.
@Danilo, i agree there is a need for a new complete setup package. the reason i guess is that Michael are contentiously updating the Library

install one of the setup complete packages listed here:
http://www.purebasic.fr/english/viewtop ... 27&t=43601
for me (winxp 32bit) it is
http://www.flasharts.de/mpz/Install_MP3D_32_x86.exe
then replace the Library "MP3D_Library" (no extension) in the folder:
C:\PureBasic\SubSystems\DX9\purelibraries\userlibraries\
with the one from here http://www.morty-productions.de/gamedev ... hp?tid=160
for me it is
x86 for pb 520 and newer
http://www.flasharts.de/mpz/mp33/pb520/MP3D_Library.zip
then close PB and run again
the compiler option for the MP3D code is dx9

Re: MP3D Engine Alpha 32

Posted: Fri Jan 24, 2014 3:50 pm
by Mythros
Hi, @mpz. Thank you so much for helping me, and continuing to help me! I truly appreciate it from the bottom of my heart! :)

Anyways, I have one more small question.

Is there a way to not have to hold down shift when deselecting and being able to deselect by clicking on the object(s) as well as being able to left click on the black background to also deselect?

Thanks once again! :)

Re: MP3D Engine Alpha 32

Posted: Fri Jan 24, 2014 4:06 pm
by mpz
Dear Mythros,

everything is possible. You must add an mesh to the list or delete a mesh from the list. You see the different "if cases" and must change this. I can help you and show you a way or give you ideas, but in this case the best ways is "learning by doing".

-> Get the code, change the code -> use debug to look what happens like:

Code: Select all

debug "who many meshs"+str(ListSize(MyMesh()))
ForEach MyMesh()
  debug MyMesh()
next
testing, learning, doing, this is the way a programmer works :)

Greetings Michael

Re: MP3D Engine Alpha 32

Posted: Sun Jan 26, 2014 12:44 pm
by N_Gnom
Maybe anybody can help.
Have problems with a perpixel light shader and i don´t know why it doesn´t work.

as texture it should be possible to use another one.
But here the used textur: http://www.nuclear-forum.de/home/dl/Roc ... ecular.png

Code: Select all

Procedure MP_TranslateEntity(ent, x.f, y.f, z.f)
  MP_PositionEntity(ent, MP_EntityGetX(ent) + x, MP_EntityGetY(ent) + y, MP_EntityGetZ(ent) + z)
EndProcedure 

Procedure MP_TranslateCamera(camera, x.f, y.f, z.f)
  MP_PositionCamera(camera, MP_CameraGetX(camera) + x, MP_CameraGetY(camera) + y, MP_CameraGetZ(camera) + z)
EndProcedure 


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, -50)
MP_UseCursor(0)
plane = MP_CreatePlane(1,1)
texture = MP_LoadTexture("Rockwall_Specular.png")
MP_ScaleEntity(plane, 5,5,5)
MP_EntitySetTexture(plane, texture)

tLightSpr=MP_CreateSphere(8)

MP_PositionEntity(tLightSpr,0,0,-1)
Structure d3dxvector3
  r.f
  g.f
  b.f
  a.f
EndStructure 

Structure d3dxvector3_1
  x.f
  y.f
  z.f
EndStructure 

ambient.d3dxvector3
    ambient\r = 0.25
    ambient\g = 0.3
    ambient\b = 0.35
    
lcolor.d3dxvector3
    lcolor\r = 1
    lcolor\g = 0.8
    lcolor\b = 0.6
    
sphere.d3dxvector3_1
sphere\x = MP_EntityGetX(tLightSpr)
sphere\y = MP_EntityGetY(tLightSpr)
sphere\z = MP_EntityGetZ(tLightSpr)
    
If ReadFile(0, "PerPixelLight.fx")   ; wenn die Datei geöffnet werden konnte, setzen wir fort...

   While Eof(0) = 0           ; sich wiederholende Schleife bis das Ende der Datei ("end of file") erreicht ist
     dummy.s + ReadString(0) + Chr(10)      ; Zeile für Zeile im Debugger-Fenster anzeigen
   Wend
   CloseFile(0)               ; schließen der zuvor geöffneten Datei

   MyShader = MP_CreateMyShader (dummy)
   
 EndIf
 
MP_SetTechniqueMyShader (MyShader,"Technique0")
MP_ShaderSetTexture (MyShader,"tDiffuse",texture)
;MP_UseTextureShader(MyShader, texture)
 
 
MP_ShaderSet_D3DMATRIX (MyShader,"MatWorldViewProj",MP_ShaderGetWorldView (plane)) 
MP_ShaderSet_D3DMATRIX (MyShader,"MatWorld",MP_ShaderGetView (plane))  
 
MP_ShaderSet_Float3(MyShader,	"AmbientClr",@ambient.d3dxvector3)
MP_ShaderSet_Float3(MyShader,	"LightClr",@lcolor.d3dxvector3)
MP_ShaderSetVar_f(MyShader,		"LightInt",2)
MP_ShaderSetVar_f(MyShader,		"RngLight",40)

 
 
 


 While Not MP_KeyDown(#PB_Key_Escape) And Not WindowEvent() = #PB_Event_CloseWindow

  If MP_KeyDown(#PB_Key_O) = 1
    MP_MoveEntity(tLightSpr,0.05,0,0)
  EndIf
    If MP_KeyDown(#PB_Key_L) = 1
    MP_MoveEntity(tLightSpr,-0.05,0,0)
  EndIf
   
   MP_ShaderSet_Float4(MyShader,"PosLight",@sphere.d3dxvector3_1)

  If MP_KeyDown(#PB_Key_Down) = 1
    MP_MoveCamera(cam,0,0,-1)
  EndIf   
  If MP_KeyDown(#PB_Key_Up) = 1
    MP_MoveCamera(cam,0,0,1)
  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_TurnCamera(cam,1,0,0)
  EndIf 
    If MP_KeyDown(#PB_Key_S) = 1
    MP_TurnCamera(cam,-1,0,0)
  EndIf 
 
  MouseX.f = MP_MouseDeltaX()
  MouseY.f = MP_MouseDeltaY()

  MP_TurnCamera(cam, -MouseY*2, MouseX*2, 0)
  turnX = 0:turnY = 0
  
  If MP_KeyDown(#PB_Key_I) = 1
    MP_TranslateCamera(cam, 0, 0, 1)
  EndIf 
  MP_DrawText(1,10,"FPS = "+Str(MP_FPS()))
  MP_DrawText(1,25,"MP_EntityGetPitch(cam) = "+MP_LimitTo360(MP_EntityGetPitch(cam)))
  MP_DrawText(1,45,"MP_EntityGetYaw(cam) = "+MP_LimitTo360(MP_EntityGetYaw(cam)))
  MP_DrawText(1,65,"MP_EntityGetRoll(cam) = "+MP_LimitTo360(MP_EntityGetRoll(cam)))
  MP_DrawText(1,85,"Press O and L to move the sphere")
  MP_DrawText(1,95,"X"+MP_EntityGetZ(cam))
  
  MP_RenderWorld()
  MP_Flip()  
Wend

shader

Code: Select all



//##################  Varriables  ##################
const float4x4 MatWorldViewProj;
const float4x4 MatWorld;

// Light
const float3 AmbientClr;		// Ambient Color
const float3 LightClr;			// Light Color
const float LightInt;			// Light Intensity

// Positions
float4 PosLight;				// Light Position
float RngLight;					// Light Range
float DotLight;					// Light Soft

// Other
static float3 Color;
static float4 cD;

static float3 nLight;



//##################  Textures  ##################
const texture tDiffuse : TEXTURE_0;			// Diffuse Texture
sampler TexDiffuse=sampler_state {
    Texture   = <tDiffuse>;
    ADDRESSU  = WRAP;
    ADDRESSV  = WRAP;
    ADDRESSW  = WRAP;
    MAGFILTER = LINEAR;
    MINFILTER = LINEAR;
    MIPFILTER = LINEAR;
};


//##################  Input VS  ##################
struct VS_INPUT {
   float4 Position : POSITION0;
   float4 Normal : NORMAL;
   float2 TexCoords : TEXCOORD0;
};
//##################  Output VS  ##################
struct VS_OUTPUT {
	float4 Position : POSITION0;
	float4 pWorld : TEXCOORD0;
	float4 Normal : TEXCOORD1;
	float2 TexCoords : TEXCOORD2;
};


//##################  VS  ##################
VS_OUTPUT mysh(VS_INPUT IN, VS_OUTPUT  OUT) {


	OUT.Position	= mul(IN.Position,MatWorldViewProj);
	OUT.pWorld      = mul(IN.Position,MatWorld);
                OUT.Normal      = mul(IN.Normal,MatWorld);
	OUT.Normal	= normalize(OUT.Normal);
	OUT.TexCoords	= IN.TexCoords;
return OUT;

}

//##################  PS  ##################

float4 psPoint(VS_OUTPUT IN) : COLOR {
	cD			= tex2D(TexDiffuse,IN.TexCoords);
	
	float tPosLight	= normalize(PosLight-IN.pWorld);
	nLight		= saturate(dot(PosLight,IN.Normal));
	
	Color		= cD.rgb*AmbientClr+(cD.rgb*nLight*LightClr*LightInt);
	
	return float4(Color,cD.a);
}




technique Technique0 {
	pass p0 {
		AlphaBlendEnable= false;
		vertexshader	= compile vs_2_0 mysh();
		pixelshader		= compile ps_2_0 psPoint();
	}
}

Re: MP3D Engine Alpha 32

Posted: Sun Feb 02, 2014 12:55 pm
by Sveinung
The shaders are failing on Windows 8.1. Needed to install Directx 9 SDK to get them running. How much of a hassel is it to make this lib DX11? Or can you include the dx9 dll that you are using in the package? Again this regards ONLY shaders.

Regards
Sveinung

Re: MP3D Engine Alpha 32

Posted: Sun Feb 02, 2014 1:23 pm
by N_Gnom
of course you need to install dx9 redist.
mp3d based on dx9.

Re: MP3D Engine Alpha 32

Posted: Sun Feb 02, 2014 2:01 pm
by Sveinung
N_Gnom wrote:of course you need to install dx9 redist.
mp3d based on dx9.
I know it is DX9...may question was if MPZ could mak it DX11, and sorry for may poor atempt to ask that question :oops:

Sveinung