Mexican Hat Curve in Purebasic 3D Engine

Everything related to 3D programming
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Mexican Hat Curve in Purebasic 3D Engine

Post by applePi »

using the formula of the Mexican Hat i have used in OpenGL demo with the example MeshManual2.pb in the Purebasic 3D examples it is even better in shape when we create the mesh as #PB_Mesh_TriangleList
Image

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - MeshManual 
;
;    (c) 2012 - Fantaisie Software
;
; ------------------------------------------------------------
Declare DrawMatrix()

#CameraSpeed = 1
#scale = 3

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

If InitEngine3D()
  
  Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/fonts", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/Scripts", #PB_3DArchive_FileSystem)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    ;- Material
    CreateMaterial(0, LoadTexture(0, "White.jpg"))
    DisableMaterialLighting(0, #True)
    MaterialCullingMode(0, #PB_Material_NoCulling)
    MaterialShadingMode(0, #PB_Material_Wireframe     )
    
    ;- Mesh Mexican Hat
    
    CreateMesh(0, #PB_Mesh_TriangleList, #PB_Mesh_Static)
    DrawMatrix()
   
    FinishMesh(#False)
    
    SetMeshMaterial(0, MaterialID(0))
    node = CreateNode(#PB_Any, -5, 0, 0)
    AttachNodeObject(node, MeshID(0))
    
    ;- Mesh Stars
    CreateMesh(1, #PB_Mesh_PointList, #PB_Mesh_Static)
    For i = 0 To 10000
      MeshVertexPosition(Random(200)-100, Random(200)-100, Random(200)-100)
      MeshVertexColor(RGB(255,255,0))
    Next i 
    FinishMesh(#False)
    
    SetMeshMaterial(1, MaterialID(0))
    
    Stars = CreateNode(#PB_Any)
    AttachNodeObject(Stars, MeshID(1))
    
    ;-Camera
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 0, 10, 5, #PB_Absolute)
    CameraFOV(0, 40)
    CameraLookAt(0, NodeX(node),  NodeY(node),  NodeZ(node))
    CameraBackColor(0, RGB(0, 0, 40))
    
    ;-Light
    CreateLight(0, RGB(255,255,255), -10, 60, 10)
    AmbientColor(RGB(90, 90, 90))
    
    Repeat
      Screen3DEvents()
      
      ExamineKeyboard()
      
      RotateNode(node, 0.3, -0.3, -0.3, #PB_Relative)
      RotateNode(Stars, 0.1, 0.1, 0.1, #PB_Relative)
      
      RenderWorld()
      
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf

End

Procedure DrawMatrix()
  Protected.l a, b, Nb
  Protected.w P1, P2, P3, P4
  Protected.f x, z
  NbX=30
  NbZ=30
    
  ;xMin.f = -1 : yMin.f = -1: zMin.f = -1 : xMax.f = 1: yMax = 1 : zMax = 1
  xMin.f = -3 : yMin.f = -3: zMin.f = -3 : xMax.f = 3: yMax = 3 : zMax = 3
  ;xMin.f = -10 : zMin.f = -10 : xMax.f = 10: zMax = 10
  range = xMax - xMin
  step1.f = range / NbX
  x.f = xMin: z.f = zMin : y.f = yMin
  For b=0 To NbZ
    
    For a=0 To NbX
      
      
      ;distance.f = Sqr(Pow((0-x),2) + Pow((0-z),2)) ; distance between plotted point and center 0,0
      ;If distance <= 2.0
      ;y.f = Sin(10*(x*x+z*z))/10
      y.f =(1 - x*x -z*z) * Exp(-1/2 * (x*x + z*z)) ; Mexican Hat
      MeshVertexPosition(x, y, z) 
      
      If y>=0
        MeshVertexColor(RGB(255,100,0))
           Else
        MeshVertexColor(RGB(230,240,0))  
     EndIf
     
     ;EndIf 
      x.f + step1
      
    Next a
    
    x = xMin
    z.f + step1
  Next b
  
  
  Nb=Nbx+1
    
  For b=0 To NbZ-1
      
    For a=0 To NbX-1
      
      P1=a+(b*Nb)
      P2=P1+1
      P3=a+(b+1)*Nb
      P4=P3+1
  
      MeshFace(P3, P2, P1)
      MeshFace(P2, P3, P4)
     
    Next
    
  Next
EndProcedure 



but if we try to make it round we will get chaos figure, i am always feel bad with connecting triangles.
the second code is using #PB_Mesh_PointList so we can easily making a round Hat exactly like a UFO
Image

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - MeshManual 
;
;    (c) 2012 - Fantaisie Software
;
; ------------------------------------------------------------
Declare DrawMatrix()

#CameraSpeed = 1
#scale = 3

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

If InitEngine3D()
  
  Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/fonts", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/Scripts", #PB_3DArchive_FileSystem)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    ;- Material
    CreateMaterial(0, LoadTexture(0, "White.jpg"))
    DisableMaterialLighting(0, #True)
    MaterialCullingMode(0, #PB_Material_NoCulling)
    MaterialShadingMode(0, #PB_Material_Wireframe     )
    
    ;- Mesh Mexican Hat
    
    ;CreateMesh(0, #PB_Mesh_TriangleList, #PB_Mesh_Static)
    CreateMesh(0, #PB_Mesh_PointList, #PB_Mesh_Static)
    DrawMatrix()
   
    FinishMesh(#False)
    
    SetMeshMaterial(0, MaterialID(0))
    node = CreateNode(#PB_Any, -5, 0, 0)
    AttachNodeObject(node, MeshID(0))
    
    ;- Mesh Stars
    CreateMesh(1, #PB_Mesh_PointList, #PB_Mesh_Static)
    For i = 0 To 10000
      MeshVertexPosition(Random(200)-100, Random(200)-100, Random(200)-100)
      MeshVertexColor(RGB(255,255,0))
    Next i 
    FinishMesh(#False)
    
    SetMeshMaterial(1, MaterialID(0))
    
    Stars = CreateNode(#PB_Any)
    AttachNodeObject(Stars, MeshID(1))
    
    ;-Camera
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 0, 7, 4, #PB_Absolute)
    CameraFOV(0, 40)
    CameraLookAt(0, NodeX(node),  NodeY(node),  NodeZ(node))
    CameraBackColor(0, RGB(0, 0, 40))
    
    ;-Light
    CreateLight(0, RGB(255,255,255), -10, 60, 10)
    AmbientColor(RGB(90, 90, 90))
    
    Repeat
      Screen3DEvents()
      
      ExamineKeyboard()
      
      RotateNode(node, 0.3, -0.3, -0.3, #PB_Relative)
      RotateNode(Stars, 0.1, 0.1, 0.1, #PB_Relative)
      
      RenderWorld()
      
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf

End

Procedure DrawMatrix()
  Protected.l a, b, Nb
  Protected.w P1, P2, P3, P4
  Protected.f x, z
  NbX=180
  NbZ=180
    
  ;xMin.f = -1 : yMin.f = -1: zMin.f = -1 : xMax.f = 1: yMax = 1 : zMax = 1
  xMin.f = -3 : yMin.f = -3: zMin.f = -3 : xMax.f = 3: yMax = 3 : zMax = 3
  ;xMin.f = -10 : zMin.f = -10 : xMax.f = 10: zMax = 10
  range = xMax - xMin
  step1.f = range / NbX
  x.f = xMin: z.f = zMin : y.f = yMin
  For b=0 To NbZ
    
    For a=0 To NbX
      
      
      distance.f = Sqr(Pow((0-x),2) + Pow((0-z),2)) ; distance between plotted point and center 0,0
      If distance <= 2.0
      ;y.f = Sin(10*(x*x+z*z))/10
      y.f =(1 - x*x -z*z) * Exp(-1/2 * (x*x + z*z)) ; Mexican Hat
      MeshVertexPosition(x, y, z) 
      
      If y>=0
        MeshVertexColor(RGB(255,100,0))
           Else
        MeshVertexColor(RGB(230,240,0))  
      EndIf
      
      EndIf
      
      x.f + step1
      
    Next a
    
    x = xMin
    z.f + step1
  Next b
  
  
  Nb=Nbx+1
    
  
EndProcedure 



also try the formula using the last code in my thread General purpose 3D /2D functions Plotting , there you will see it is textured with wood, just scale it down, but without the Red summit, i will search for that.
Last edited by applePi on Sun Jul 06, 2014 11:31 am, edited 1 time in total.
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Mexican Hat in Purebasic 3D Engine

Post by DK_PETER »

Looks good.
Thank you, Applepi. ;-)
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Mexican Hat Curve in Purebasic 3D Engine

Post by applePi »

thanks DK_PETER , another way is to connect the points with line strips using #PB_Mesh_LineStrip and using the index of the vertex (this is called i think indexed geometry) but we should do it in a zigzag way else it will not work
Image

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - MeshManual 
;
;    (c) 2012 - Fantaisie Software
;
; ------------------------------------------------------------
Declare DrawMatrix()

#CameraSpeed = 1
#scale = 3


IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

If InitEngine3D()
  
  Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/fonts", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/Scripts", #PB_3DArchive_FileSystem)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
    
  If Screen3DRequester()
    
    ;- Material
    CreateMaterial(0, LoadTexture(0, "White.jpg"))
    DisableMaterialLighting(0, #True)
    MaterialCullingMode(0, #PB_Material_NoCulling)
    MaterialShadingMode(0, #PB_Material_Wireframe     )
    
    ;- Mesh Mexican Hat
    
    CreateMesh(0, #PB_Mesh_LineStrip, #PB_Mesh_Static)
    DrawMatrix()
   
    FinishMesh(#False)
    
    SetMeshMaterial(0, MaterialID(0))
    node = CreateNode(#PB_Any, -5, 0, 0)
    AttachNodeObject(node, MeshID(0))
    
    ;- Mesh Stars
    CreateMesh(1, #PB_Mesh_PointList, #PB_Mesh_Static)
    For i = 0 To 10000
      MeshVertexPosition(Random(200)-100, Random(200)-100, Random(200)-100)
      MeshVertexColor(RGB(255,255,0))
    Next i 
    FinishMesh(#False)
    
    SetMeshMaterial(1, MaterialID(0))
    
    Stars = CreateNode(#PB_Any)
    AttachNodeObject(Stars, MeshID(1))
    
    ;-Camera
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 0, 10, 5, #PB_Absolute)
    CameraFOV(0, 40)
    CameraLookAt(0, NodeX(node),  NodeY(node),  NodeZ(node))
    CameraBackColor(0, RGB(0, 0, 40))
    
    ;-Light
    CreateLight(0, RGB(255,255,255), -10, 60, 10)
    AmbientColor(RGB(90, 90, 90))
    
    Repeat
      Screen3DEvents()
      
      ExamineKeyboard()
      
      RotateNode(node, 0.3, -0.3, -0.3, #PB_Relative)
      RotateNode(Stars, 0.1, 0.1, 0.1, #PB_Relative)
      
      RenderWorld()
      
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf

End

Procedure DrawMatrix()
  Protected.l a, b, Nb
  Protected.w P1, P2, P3, P4
  Protected.f x, z
  NbX=50
  NbZ=50
    
  ;xMin.f = -1 : yMin.f = -1: zMin.f = -1 : xMax.f = 1: yMax = 1 : zMax = 1
  xMin.f = -3 : yMin.f = -3: zMin.f = -3 : xMax.f = 3: yMax = 3 : zMax = 3
  ;xMin.f = -10 : zMin.f = -10 : xMax.f = 10: zMax = 10
  range = xMax - xMin
  step1.f = range / NbX
  x.f = xMin: z.f = zMin : y.f = yMin
  For b=0 To NbZ
    
    For a=0 To NbX
      
      
      ;distance.f = Sqr(Pow((0-x),2) + Pow((0-z),2)) ; distance between plotted point and center 0,0
      ;If distance <= 2.0
      ;y.f = Sin(10*(x*x+z*z))/10
      y.f =(1 - x*x -z*z) * Exp(-1/2 * (x*x + z*z)) ; Mexican Hat
      MeshVertexPosition(x, y, z) 
      v+1
      If y>=0
        MeshVertexColor(RGB(255,100,0))
           Else
        MeshVertexColor(RGB(230,240,0))  
     EndIf
     
     ;EndIf 
      x.f + step1
      
    Next a
    
    x = xMin
    z.f + step1
  Next b
  
     
xx=0  
   ;;oooooooooooooooooooooooooooooooooooo
  
direction = 0
For colm=0 To NbZ
  If direction = 1
    direction ! 1
    xx = xx + NbX + 1
    
    For i=xx To xx-NbX Step -1
        MeshIndex(i)
        
      Next
     
    xx+1
    
  Else
    
    direction ! 1
       
    For i=xx To xx+NbX
        MeshIndex(i)
        
    Next
    xx = i - 1
    
  EndIf
      
Next

EndProcedure 


for who want to do experiments in indexed geometry, in addition to the MeshManual2.pb (the Grid part), here is a small version to plot S
the connections between the vertices are done like this:
MeshIndex(0)
MeshIndex(1)
MeshIndex(2)

MeshIndex(5)
MeshIndex(4)
MeshIndex(3)

MeshIndex(6)
MeshIndex(7)
MeshIndex(8)


but to apply this in automatic connecting procedure suitable for big numbers of points :the grid here are (3 X 3)
direction = 0
For y=0 To 2
If direction = 1
direction ! 1
x + 3
For i=x To x-2 Step -1
MeshIndex(i)
Next
x+1
Else
direction ! 1
For i=x To x+2
MeshIndex(i)
Next
x = i - 1
EndIf
Next


follow this figure, and in the program below reposition the MeshIndex(..) lines so it will produce the figure Z
Image

there may be a more direct way to draw the lines in a zigzag way.

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - MeshManual 
;
;    (c) 2012 - Fantaisie Software
;
; ------------------------------------------------------------
;

#CameraSpeed = 1
#scale = 3

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

If InitEngine3D()
  
  Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/fonts", #PB_3DArchive_FileSystem)
  Add3DArchive("Data/Scripts", #PB_3DArchive_FileSystem)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    ;- Material
    CreateMaterial(0, LoadTexture(0, "White.jpg"))
    DisableMaterialLighting(0, #True)
            
    ;- Mesh Plane (using MeshIndex)
    CreateMesh(4, #PB_Mesh_LineStrip, #PB_Mesh_Static)
    Dim asd(2,2)
    ; Define vertex position of index 0..3
    MeshVertexPosition(-10, -10, 0) 
    MeshVertexPosition(-7, -10, 0 ) 
    MeshVertexPosition( -4, -10, 0) 
    
    MeshVertexPosition( -10, -7,0)
    MeshVertexPosition( -7, -7,0)
    MeshVertexPosition( -4, -7,0)
    
    MeshVertexPosition( -10, -4,0)
    MeshVertexPosition( -7, -4,0)
    MeshVertexPosition( -4, -4,0)
    ; Define usage of vertices by referring To the indexes
    ;MeshIndex(0)
    ;MeshIndex(1)
    ;MeshIndex(2)
        
    ;MeshIndex(5)
    ;MeshIndex(4)
    ;MeshIndex(3)
      
    ;MeshIndex(6)
    ;MeshIndex(7)
    ;MeshIndex(8)
;the following is a replacement of the above 9 code lines
direction = 0
For y=0 To 2
  If direction = 1
    direction ! 1
    x + 3
    For i=x To x-2 Step -1
       MeshIndex(i)
       Next
    x+1
  Else
    direction ! 1
    For i=x To x+2
        MeshIndex(i)
    Next
    x = i - 1
  EndIf
Next
    
    FinishMesh(#False)
    
    
    SetMeshMaterial(4, MaterialID(0))
    Plane2 = CreateNode(#PB_Any, 0, 10, 0)
    AttachNodeObject(Plane2, MeshID(4))
    
    ;- Mesh Box (using MeshIndex) 
    CreateMesh(5, #PB_Mesh_LineList, #PB_Mesh_Static)
    
     ;-Camera
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 0, 10, 50, #PB_Absolute)
    CameraFOV(0, 40)
    CameraLookAt(0, NodeX(plane2),  NodeY(plane2),  NodeZ(plane2))
    CameraBackColor(0, RGB(0, 0, 40))
    
    ;-Light
    CreateLight(0, RGB(255,255,255), -10, 60, 10)
    AmbientColor(RGB(90, 90, 90))
    
    Repeat
      Screen3DEvents()
      
      ExamineKeyboard()
      
      ;RotateNode(Plane2, 0.0, 0.3, 0.0, #PB_Relative) 
      
      RenderWorld()
      
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  EndIf
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf

End

EDIT:
at last succeeded in weaving a grid correctly using lineStrip in horizontal zigzag and vertical zigzag. it is exactly like the one here: http://upload.wikimedia.org/wikipedia/c ... aph_04.png

to change the resolution change the numbers in line 98-99
NbX=60
NbZ=60

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - MeshManual 
;
;    (c) 2012 - Fantaisie Software
;
; ------------------------------------------------------------
Declare DrawMatrix()

#CameraSpeed = 1
#scale = 3
ScreenX = GetSystemMetrics_(#SM_CXSCREEN)
ScreenY = GetSystemMetrics_(#SM_CYSCREEN)

;IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY

InitEngine3D()
InitSprite()
  InitKeyboard()
  InitMouse()
  ExamineDesktops()
OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), "Mexican Hat Curve .... ", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0)
  
  Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
  
      
    ;- Material
    CreateMaterial(0, LoadTexture(0, "White.jpg"))
    DisableMaterialLighting(0, #True)
    MaterialCullingMode(0, #PB_Material_NoCulling)
    MaterialShadingMode(0, #PB_Material_Wireframe     )
    
    ;- Mesh Mexican Hat
    
    CreateMesh(0, #PB_Mesh_LineStrip, #PB_Mesh_Static)
    DrawMatrix()
   
    FinishMesh(#False)
    
    SetMeshMaterial(0, MaterialID(0))
    node = CreateNode(#PB_Any, -5, 0, 0)
    AttachNodeObject(node, MeshID(0))
    
    ;- Mesh Stars
    CreateMesh(1, #PB_Mesh_PointList, #PB_Mesh_Static)
    For i = 0 To 10000
      MeshVertexPosition(Random(200)-100, Random(200)-100, Random(200)-100)
      MeshVertexColor(RGB(255,255,0))
    Next i 
    FinishMesh(#False)
    
    SetMeshMaterial(1, MaterialID(0))
    
    Stars = CreateNode(#PB_Any)
    AttachNodeObject(Stars, MeshID(1))
    
    ;-Camera
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 0, 10, 5, #PB_Absolute)
    CameraFOV(0, 40)
    CameraLookAt(0, NodeX(node),  NodeY(node),  NodeZ(node))
    CameraBackColor(0, RGB(0, 0, 40))
    
    ;-Light
    CreateLight(0, RGB(255,255,255), -10, 60, 10)
    AmbientColor(RGB(90, 90, 90))
    
    Repeat

      
      ExamineKeyboard()
      
      RotateNode(node, 0.3, -0.3, -0.3, #PB_Relative)
      RotateNode(Stars, 0.1, 0.1, 0.1, #PB_Relative)
      
      RenderWorld()
      
      FlipBuffers()
     Repeat
    event = WindowEvent()
    If event = #PB_Event_CloseWindow
      quit = #True
    EndIf
  Until event = 0 Or quit = #True
  
  Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
 
End

Procedure DrawMatrix()
  Protected.l a, b, Nb
  Protected.w P1, P2, P3, P4
  Protected.f x, z
  NbX=60
  NbZ=60
    
  ;xMin.f = -1 : yMin.f = -1: zMin.f = -1 : xMax.f = 1: yMax = 1 : zMax = 1
  xMin.f = -3 : yMin.f = -3: zMin.f = -3 : xMax.f = 3: yMax = 3 : zMax = 3
  ;xMin.f = -10 : zMin.f = -10 : xMax.f = 10: zMax = 10
  range = xMax - xMin
  step1.f = range / NbX
  x.f = xMin: z.f = zMin : y.f = yMin
  For b=0 To NbZ
    
    For a=0 To NbX
     
      y.f =(1 - x*x -z*z) * Exp(-1/2 * (x*x + z*z)) ; Mexican Hat
      MeshVertexPosition(x, y, z) 
      v+1
      If y>=0
        MeshVertexColor(RGB(255,100,0))
           Else
        MeshVertexColor(RGB(230,240,0))  
     EndIf
     
      x.f + step1
      
    Next a
    
    x = xMin
    z.f + step1
  Next b
  
     
   ;;oooooooooooooooooooooooooooooooooooo
;doing lineStrip in horizontal zigzag and vertical zigzag
 
direction = 0
For yy=0 To NbX
  If direction = 1
    direction ! 1
    xx + NbX + 1
    For i=xx To xx-NbX Step -1
       MeshIndex(i)
       Next
    xx+1
  Else
    direction ! 1
    For i=xx To xx+NbX
        MeshIndex(i)
    Next
    xx = i - 1
  EndIf
Next

xx=(NbX+1)*(NbZ+1) -1
direction = 0
For yy=0 To NbX
  If direction = 1
    direction ! 1
    i=xx
    x2 = xx+(NbX+1)*NbZ 
    While i<= xx+(NbX+1)*NbZ  
      
      MeshIndex(i)
      i+NbX+1
     Wend
     
     i-(NbX+1)
     
    xx = i-1
    
  Else
    direction ! 1
    i=xx
    x2 = xx-(NbX+1)*NbZ 
    While i>= x2 
      MeshIndex(i)
      i-(NbX+1)
    Wend
    
    i+NbX+1
    xx = i - 1
    
  EndIf
Next
EndProcedure 

Last edited by applePi on Mon Jul 07, 2014 5:03 pm, edited 4 times in total.
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Mexican Hat Curve in Purebasic 3D Engine

Post by DK_PETER »

Excellent Applepi!
I'll study the examples closely. ;-)
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
Post Reply