Page 1 of 1

Convert everything on this page to PureBasic

Posted: Tue Feb 11, 2014 7:13 am
by VB6_to_PBx
it would be great if someone could convert
everything on this Webpage Link to PureBasic source code :D

Link :
http://paulbourke.net/geometry/

Re: Convert everything on this page to PureBasic

Posted: Tue Feb 11, 2014 8:02 am
by PB
What price are you offering?

Re: Convert everything on this page to PureBasic

Posted: Tue Feb 11, 2014 9:20 am
by VB6_to_PBx
PB wrote:What price are you offering?
nothing , unfortunately :(

i thought that Link would give new ideas to explore , to anyone interested

Re: Convert everything on this page to PureBasic

Posted: Tue Feb 11, 2014 10:15 am
by Bananenfreak
Bezier curves seems interesting...

Re: Convert everything on this page to PureBasic

Posted: Tue Feb 11, 2014 11:06 am
by applePi
certainly a great site with too many goodies, thanks.
i remember while struggling with Klein Bottle i visited this site i may have used his formula (can't remember) for the Klein Bottle
too many goodies. if i can display other shapes i will reply here

Re: Convert everything on this page to PureBasic

Posted: Tue Feb 11, 2014 11:24 am
by PB
> i thought that Link would give new ideas to explore , to anyone interested

Oh, I thought you wanted someone to convert it all for you. Sorry!

Re: Convert everything on this page to PureBasic

Posted: Tue Feb 11, 2014 12:20 pm
by luis
Many inspirational ideas...I've already seen something I want to try...thanks for the link.

Re: Convert everything on this page to PureBasic

Posted: Wed Feb 12, 2014 9:36 pm
by applePi
tear drop equations:
x = 0.5 * (1 - cos(u)) * sin(u) * cos(v)
y = 0.5 * (1 - cos(u)) * sin(u) * sin(v)
z = cos(u)
0<=v<=2*Pi
0<=u<=Pi

i have searched for the easiest equations in the page and find the http://paulbourke.net/geometry/teardrop/ the author describe it as a tear drop but i find it like a spinning Top toy
Image
it uses a parametric equations which can be recognized by the variables such as x,y,z which its value depends on other 2 variables such as u, v
i have used the example MeshManualParametrics.pb in C:\PureBasic\Examples\3D\Demos as a major tool to plot and connect the points
the following is plotting the object as points, the next one the points connected by triangle lists.

Code: Select all

Declare toy()
Enumeration
   #LIGHT
   #CAMERA
   #BUTTON
   #mainwin
 EndEnumeration
 
Quit.b = #False
rot.l=1 :stopFlag = 1
xs.f = 0.3:ys.f = 0.3:zs.f = 0.3
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
up.f = 1.8: depth.f=0

ExamineDesktops()
If OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "PgUp PgD scale mesh..Arrows for rotation, space: stop/rotate,  QA far/near, key_pad R/L/U/D", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ButtonGadget(#BUTTON, 0, DesktopHeight(0)-60, 60, 30, "rotate/stop") 

;Initialize environment
InitEngine3D()
InitSprite()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0)-60, 0, 0, 0)
;WorldShadows(#PB_Shadow_Additive)

InitKeyboard()
SetFrameRate(60)

Add3DArchive("/", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/Sources\Data", #PB_3DArchive_FileSystem)

CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(100,100,100))

CreateCamera(#CAMERA, 0, 0, 400, 400)
MoveCamera(#CAMERA, 0, 4, 9)
CameraLookAt(#CAMERA, 0, 2, 0)

RotateCamera(#CAMERA, -15, 0, 0)
EndIf

SetActiveGadget(#BUTTON)
;SkyDome("clouds.jpg", 100) ;for blue color background
; material for the plot
CreateMaterial(0, LoadTexture(0, "white.jpg"))
;MaterialShadingMode(0, #PB_Material_Wireframe)
MaterialCullingMode(0, #PB_Material_NoCulling)
DisableMaterialLighting(0, #True)
CreateMesh(1, #PB_Mesh_PointList , #PB_Mesh_Static )
SetMeshMaterial(1, MaterialID(0))

;;oooooooooooooooooooooooooooooooooooooooooooooooooooo
  toy() ; call the top_toy construction procedure
    NormalizeMesh(1)
    FinishMesh(#True)
    CreateEntity(1, MeshID(1), MaterialID(0))  
    ScaleEntity(1,5, 5, 5)
  ;Main loop
  MoveEntity(1,0,up,depth,#PB_Absolute) 
   
  x = 180: y=0: z=0 : h.f
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
  
   RotateEntity(1, x, y, z)
      
   RenderWorld()
   FlipBuffers()

   ExamineKeyboard()
   
  If KeyboardPushed(#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 KeyboardPushed(#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 KeyboardPushed(#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 KeyboardPushed(#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 KeyboardPushed(#PB_Key_PageUp) ; scale up model
    xs.f = 1.1:ys.f = 1.1:zs.f = 1.1
    ScaleEntity(1,xs,ys,zs)
    
  ElseIf KeyboardPushed(#PB_Key_PageDown) ; scale down model
    xs = 0.9:ys = 0.9:zs= 0.9
    ScaleEntity(1,xs,ys,zs)
    
  EndIf
  If KeyboardPushed(#PB_Key_Pad8) ; up move
    up + 0.1
    MoveEntity(1,h,up,depth,#PB_Absolute)
   ElseIf KeyboardPushed(#PB_Key_Pad2) ; down move
    up - 0.1
    MoveEntity(1,h,up,depth,#PB_Absolute)
  ElseIf KeyboardPushed(#PB_Key_Pad6)
    h + 0.1
    MoveEntity(1,h,up,depth,#PB_Absolute)
    ElseIf KeyboardPushed(#PB_Key_Pad4)
    h - 0.1
    MoveEntity(1,h,up,depth,#PB_Absolute)
    
    ElseIf KeyboardPushed(#PB_Key_Q) ; forward move
    depth - 0.1
    MoveEntity(1,h,up,depth,#PB_Absolute)
    ElseIf KeyboardPushed(#PB_Key_A) ; inward move
    depth + 0.1
    MoveEntity(1,h,up,depth,#PB_Absolute)

  EndIf
   If KeyboardPushed(#PB_Key_Escape)
      Quit = #True
    EndIf
    
    
  Until Quit = #True Or Event = #PB_Event_CloseWindow
  
  Macro Vertex(u, v)
  
  x.f = 0.5 * (1 - Cos(u)) * Sin(u) * Cos(v)
  y.f = 0.5 * (1 - Cos(u)) * Sin(u) * Sin(v)
  z.f = Cos(u)
      
  MeshVertexPosition(x, y, z);
  MeshVertexColor(RGB(0,255, 0))
  
  MeshVertexNormal(x, y, z)
      
  
EndMacro

Procedure toy()
  
  Protected.f u, v, Delta = 2*#PI/100
  Protected.f x, y, z
  txu.f : txv.f
    
  u = 0
  v = 0
  While u <= 1 * #PI
    While v <= 2 * #PI ; change 2 to 1 and will get half of the object
      
      Vertex(u, v)
      Vertex(u + Delta, v)
      Vertex(u + Delta, v + Delta)
      Vertex(u, v + Delta)
            
      v + Delta
      
    Wend
    
    v = 0
    u + Delta
  Wend
  ;Debug VertexIndex
EndProcedure

now in the connected points example if you change line 197 from While v <= 2 * #PI to While v <= 1 * #PI
you will get the shape of a boat, or a musical instrument.
press ( W ) to toggle wire Frame or solid Frame..
there are too many subjects in which every one is a research subject by its own.
i hope i can study the HyperSpace page.
Image
Image

Code: Select all

Declare toy()
Enumeration
   #LIGHT
   #CAMERA
   #BUTTON
   #mainwin
 EndEnumeration
 
Quit.b = #False
rot.l=1 :stopFlag = 1
xs.f = 0.3:ys.f = 0.3:zs.f = 0.3
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
up.f = 1.8: depth.f=0

ExamineDesktops()
If OpenWindow(#mainwin, 0, 0, DesktopWidth(0), DesktopHeight(0), "PgUp PgD scale mesh..Arrows for rotation, space: stop/rotate,  QA far/near, key_pad R/L/U/D", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  ButtonGadget(#BUTTON, 0, DesktopHeight(0)-60, 60, 30, "rotate/stop") 

;Initialize environment
InitEngine3D()
InitSprite()
OpenWindowedScreen(WindowID(#mainwin), 0, 0, DesktopWidth(0), DesktopHeight(0)-60, 0, 0, 0)
;WorldShadows(#PB_Shadow_Additive)

InitKeyboard()
SetFrameRate(60)

Add3DArchive("/", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/Sources\Data", #PB_3DArchive_FileSystem)

CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(100,100,100))

CreateCamera(#CAMERA, 0, 0, 400, 400)
MoveCamera(#CAMERA, 0, 4, 9)
CameraLookAt(#CAMERA, 0, 2, 0)

RotateCamera(#CAMERA, -15, 0, 0)
EndIf

SetActiveGadget(#BUTTON)
SkyDome("clouds.jpg", 100) ;for blue color background
; material for the plot
CreateMaterial(0, LoadTexture(0, "ground_diffuse.png"))
;MaterialShadingMode(0, #PB_Material_Wireframe)
MaterialCullingMode(0, #PB_Material_NoCulling)
DisableMaterialLighting(0, #True)
CreateMesh(1, #PB_Mesh_TriangleList , #PB_Mesh_Static )
SetMeshMaterial(1, MaterialID(0))

;;oooooooooooooooooooooooooooooooooooooooooooooooooooo
  toy() ; call the top_toy construction procedure
    NormalizeMesh(1)
    FinishMesh(#True)
    CreateEntity(1, MeshID(1), MaterialID(0))  
    ScaleEntity(1,5, 5, 5)
  ;Main loop
  MoveEntity(1,0,up,depth,#PB_Absolute) 
   
  x = 180: y=0: z=0 : h.f
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
  
   RotateEntity(1, x, y, z)
      
   RenderWorld()
   FlipBuffers()

   ExamineKeyboard()
   If KeyboardReleased(#PB_Key_W) ; display wire frame for the material
      If wireFrame=0
      MaterialShadingMode(0, #PB_Material_Wireframe)
      wireFrame ! 1
         ElseIf wireFrame=1
           MaterialShadingMode(0, #PB_Material_Solid)
           wireFrame ! 1
      EndIf
    EndIf
  If KeyboardPushed(#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 KeyboardPushed(#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 KeyboardPushed(#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 KeyboardPushed(#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 KeyboardPushed(#PB_Key_PageUp) ; scale up model
    xs.f = 1.1:ys.f = 1.1:zs.f = 1.1
    ScaleEntity(1,xs,ys,zs)
    
  ElseIf KeyboardPushed(#PB_Key_PageDown) ; scale down model
    xs = 0.9:ys = 0.9:zs= 0.9
    ScaleEntity(1,xs,ys,zs)
    
  EndIf
  If KeyboardPushed(#PB_Key_Pad8) ; up move
    up + 0.1
    MoveEntity(1,h,up,depth,#PB_Absolute)
   ElseIf KeyboardPushed(#PB_Key_Pad2) ; down move
    up - 0.1
    MoveEntity(1,h,up,depth,#PB_Absolute)
  ElseIf KeyboardPushed(#PB_Key_Pad6)
    h + 0.1
    MoveEntity(1,h,up,depth,#PB_Absolute)
    ElseIf KeyboardPushed(#PB_Key_Pad4)
    h - 0.1
    MoveEntity(1,h,up,depth,#PB_Absolute)
    
    ElseIf KeyboardPushed(#PB_Key_Q) ; forward move
    depth - 0.1
    MoveEntity(1,h,up,depth,#PB_Absolute)
    ElseIf KeyboardPushed(#PB_Key_A) ; inward move
    depth + 0.1
    MoveEntity(1,h,up,depth,#PB_Absolute)

  EndIf
   If KeyboardPushed(#PB_Key_Escape)
      Quit = #True
    EndIf
    
    
  Until Quit = #True Or Event = #PB_Event_CloseWindow
  
  Macro Vertex(u, v)
  
  x.f = 0.5 * (1 - Cos(u)) * Sin(u) * Cos(v)
  y.f = 0.5 * (1 - Cos(u)) * Sin(u) * Sin(v)
  z.f = Cos(u)
          
  MeshVertexPosition(x, y, z);
  MeshVertexTextureCoordinate(txu, txv)
  MeshVertexNormal(x, y, z)
      
  
EndMacro

Procedure toy()
  
  Protected.f u, v, Delta = 2*#PI/100
  Protected.f x, y, z
  txu.f : txv.f
    
  u = 0
  v = 0
  While u <= 1 * #PI
    While v <= 2 * #PI ; change 2 to 1 and will get half of the object
      
      Vertex(u, v)
      txv = txv + 1/50 ; for texturing
      Vertex(u + Delta, v)
      Vertex(u + Delta, v + Delta)
      Vertex(u, v + Delta)
            
      MeshFace(VertexIndex, VertexIndex + 1, VertexIndex + 2)
      MeshFace(VertexIndex, VertexIndex + 2, VertexIndex + 3)
      
      VertexIndex + 4
      
      v + Delta
      
    Wend
    txv = 0
    txu = txu + 1/25 ; for texturing
    v = 0
    u + Delta
  Wend
  ;Debug VertexIndex
EndProcedure

Re: Convert everything on this page to PureBasic

Posted: Thu Feb 13, 2014 10:24 am
by Kwai chang caine
Splendid !!! :shock:
Thanks for sharing 8)

Re: Convert everything on this page to PureBasic

Posted: Thu Feb 13, 2014 11:03 am
by Kelebrindae
A long time ago, I made this little thing to create platonic solids (listed here on Paul Bourke's page: http://paulbourke.net/geometry/platonic/ ):
The code's quite rough around the edges (I was Oh so much younger), but hey, it works.... :wink:

Link to the french forum: http://www.purebasic.fr/french/viewtopi ... 276#p80276

Code:

Code: Select all

; Author: Kelebrindae (modification of the "cylinder 3D" demo, from Comtois)
; Date: march,13, 2006, last updated febr, 13, 2014
; PB version: v4.61, updated to 5.21
;- Controls: F1 to F7 to change visualization

Enumeration
  #tetrahedron
  #cube
  #octahedron
  #dodecahedron
  #icosahedron
EndEnumeration

;- Initialisation 
If MessageRequester("Platonic Solids","Full Screen ?",#PB_MessageRequester_YesNo) = #PB_MessageRequester_Yes      
  FullScreen=#True
Else            
  FullScreen=#False
EndIf 

If InitEngine3D() = 0 
  MessageRequester( "Error" , "Can't initialize 3D, check if engine3D.dll is available" , 0 ) 
End 
ElseIf InitSprite() = 0 Or InitKeyboard() = 0 
  MessageRequester( "Error" , "Can't find DirectX 7.0 or above" , 0 ) 
  End 
EndIf 

;- Open screen
If Fullscreen  
  OpenScreen(800,600,32,"Platonic Solids") 
Else 
  OpenWindow(0,0, 0, 800 , 600 ,"Platonic Solids",#PB_Window_ScreenCentered) 
  OpenWindowedScreen(WindowID(0),0,0, 800 , 600,0,0,0) 
EndIf 


EnableExplicit

;- ---- Procedures ----
;************************************************************************************
; Name: CreatePlatonicMesh
; Purpose: Create a platonic solid mesh, scaled and UV mapped dynamically
; Parameters:
;   - solide: #tetrahedron,#cube,#octahedron,#dodecahedron, or #icosahedron
;   - X size
;   - Y size
;   - Z size
;   - origin of mapping coord U 
;   - origin of mapping coord V
;   - Vertices color
; Return value: mesh number, or -1 if an error occurs
;************************************************************************************
Procedure.i CreatePlatonicMesh(solid.i,sizeX.f = 1,sizeY.f = 1,sizeZ.f = 1,Uorigin.f = 0,Vorigin.f = 0,Uscale.f = 1,Vscale.f = 1,color.i = $FFFFFF) 

  Protected nbVert.i , nbTri.i              ; Number of vertices and faces
  Protected x.f,y.f,z.f                     ; vertex position
  Protected nx.f,ny.f,nz.f                  ; vertex normals
  Protected u.f,v.f                         ; vertex UV coords (texture mapping)
  Protected newmesh.i                       ; Procedure Result
  Protected i.i,v1.i,v2.i,v3.i
  
  ; Restore the good set of meshdatas
  Select solid
    Case #tetrahedron
      Restore tetrahedron
    
    Case #cube
      Restore cube
    
    Case #octahedron
      Restore octahedron
    
    Case #dodecahedron
      Restore dodecahedron
      
    Case #icosahedron
      Restore icosahedron
    
    Default
      ProcedureReturn -1 
  EndSelect 

  ; Read number of vertices and triangles
  Read nbVert
  Read nbTri

  ; Read position, normals, uv coords, and add the vertex to the mesh
  newMesh = CreateMesh(#PB_Any)
  For i = 1 To nbVert
    Read.f x
    Read.f y
    Read.f z
    Read.f nx
    Read.f ny
    Read.f nz
    Read.f u
    Read.f v
    
    MeshVertexPosition(x * sizex,y * sizey,z * sizez)
    MeshVertexNormal(nx,ny,nz)
    MeshVertexColor(color)
    MeshVertexTextureCoordinate(uorigin + (u * uscale),vorigin + (v * vscale))
    
  Next i    
  
  ; Add the faces
  For i=1 To nbTri 
    Read.i v1
    Read.i v2
    Read.i v3 
    
    MeshFace(v1,v2,v3)
  Next i 
     
  ; Finalize as static mesh
  FinishMesh(#True)
  
  ProcedureReturn newMesh
EndProcedure    

DisableExplicit

;- ---- Main loop ----
;-Mesh 
; Change parameters 2 to 8 to test the effects on size and texturing
myTetraMesh.i = CreatePlatonicMesh(#tetrahedron,3,3,3)
myCubeMesh.i = CreatePlatonicMesh(#cube,3,3,3) 
myOctaMesh.i = CreatePlatonicMesh(#octahedron,3,3,3) 
myDodecaMesh.i = CreatePlatonicMesh(#dodecahedron,3,3,3) 
myIcosaMesh.i = CreatePlatonicMesh(#icosahedron,3,3,3) 


;-Entity 
CreateEntity(0,MeshID(myTetraMesh),#PB_Material_None) 
CreateEntity(1,MeshID(myCubeMesh),#PB_Material_None) 
CreateEntity(2,MeshID(myOctaMesh),#PB_Material_None) 
CreateEntity(3,MeshID(myDodecaMesh),#PB_Material_None) 
CreateEntity(4,MeshID(myIcosaMesh),#PB_Material_None) 

MoveEntity(0,5,5,0,#PB_Absolute)
MoveEntity(1,-5,5,0,#PB_Absolute)
MoveEntity(2,10,-5,0,#PB_Absolute)
MoveEntity(3,0,-5,0,#PB_Absolute)
MoveEntity(4,-10,-5,0,#PB_Absolute)

;-Camera 
CreateCamera(0, 0, 0 , 100 , 100) 
MoveCamera(0,0,0,-30,#PB_Absolute) 
CameraLookAt(0,0,0,0) 
viewlabel.s = "Platonic Solids"

;-Light 
AmbientColor(RGB(105,105,105)) 
CreateLight(0,RGB(160,160,255),200,300,0) 
CreateLight(1,RGB(255,127,0),-200,-200,200) 


pas.f = 0.8
angle.f = 0
Repeat 
   If fullscreen = 0 
      While WindowEvent() : Wend 
   EndIf
   
   ; Rotate solids, rotate! Oh, you're so gorgeous... ;)
   Angle + Pas 
   RotateEntity(0, angle,angle/2,-angle,#PB_Absolute) 
   RotateEntity(1, angle/2,-angle,angle,#PB_Absolute) 
   RotateEntity(2, -angle,angle,angle/2,#PB_Absolute) 
   RotateEntity(3, -angle,angle/2,angle,#PB_Absolute) 
   RotateEntity(4, angle,-angle/2,-angle,#PB_Absolute) 

   ; Manage camera views
   If ExamineKeyboard() 
     If KeyboardReleased(#PB_Key_F1) 
      MoveCamera(0,EntityX(0),EntityY(0),EntityZ(0) - 10,#PB_Absolute) 
      CameraLookAt(0,EntityX(0),EntityY(0),EntityZ(0)) 
      viewlabel = "Tetrahedron"
      ClearDebugOutput(): Debug viewlabel
     EndIf 
     If KeyboardReleased(#PB_Key_F2) 
      MoveCamera(0,EntityX(1),EntityY(1),EntityZ(1) - 10,#PB_Absolute) 
      CameraLookAt(0,EntityX(1),EntityY(1),EntityZ(1)) 
      viewlabel = "Cube"
      ClearDebugOutput(): Debug viewlabel
     EndIf 
     If KeyboardReleased(#PB_Key_F3) 
      MoveCamera(0,EntityX(2),EntityY(2),EntityZ(2) - 10,#PB_Absolute) 
      CameraLookAt(0,EntityX(2),EntityY(2),EntityZ(2)) 
      viewlabel = "Octahedron"
      ClearDebugOutput(): Debug viewlabel
     EndIf 
     If KeyboardReleased(#PB_Key_F4) 
      MoveCamera(0,EntityX(3),EntityY(3),EntityZ(3) - 10,#PB_Absolute) 
      CameraLookAt(0,EntityX(3),EntityY(3),EntityZ(3)) 
      viewlabel = "Dodecahedron"
      ClearDebugOutput(): Debug viewlabel
     EndIf 
     If KeyboardReleased(#PB_Key_F5) 
      MoveCamera(0,EntityX(4),EntityY(4),EntityZ(4) - 10,#PB_Absolute) 
      CameraLookAt(0,EntityX(4),EntityY(4),EntityZ(4)) 
      viewlabel = "Icosahedron"
      ClearDebugOutput(): Debug viewlabel
     EndIf 
     If KeyboardReleased(#PB_Key_F6) 
      MoveCamera(0,0,0,-30,#PB_Absolute) 
      CameraLookAt(0,0,0,0) 
      viewlabel = "Platonic Solids"
      ClearDebugOutput(): Debug viewlabel
     EndIf 
     If KeyboardReleased(#PB_Key_F7) 
       CameraMode=1-CameraMode 
       CameraRenderMode(0,CameraMode) 
       AmbientColor(RGB(105+cameramode*150,105+cameramode*150,105+cameramode*150)) 
     EndIf 
   EndIf 
  
  ; show it all
  RenderWorld() 
   
  ; Flip buffers to avoid tearing  
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) 

;- Solids datas
DataSection:
tetrahedron:
; Nb sommets / Nb faces
Data.i 10,4

; Vertices: pos / normals / uv
Data.f 0.817497,0.578350,0
Data.f 0,1,0
Data.f 0.5,0.5
Data.f -0.815497,0.578350,0
Data.f 0,1,0
Data.f 0.5,1.5
Data.f 0,-0.576350,0.817497
Data.f 0,0.577351,0.816496
Data.f -0.5,1
Data.f 0,-0.576350,-0.815497
Data.f 0,0.577351,-0.816496
Data.f -0.5,1
Data.f 0,-0.576350,-0.815497
Data.f 0.816496,-0.577351,0
Data.f -0.5,1.5
Data.f 0,-0.576350,0.817497
Data.f 0.816496,-0.577351,0
Data.f 0.5,1.5
Data.f 0.817497,0.578350,0
Data.f 0.816496,-0.577351,0
Data.f 0,0.5
Data.f 0,-0.576350,-0.815497
Data.f -0.816496,-0.577351,0
Data.f -0.5,1.5
Data.f -0.815497,0.578350,0
Data.f -0.816496,-0.577351,0
Data.f 0,0.5
Data.f 0,-0.576350,0.817497
Data.f -0.816496,-0.577351,0
Data.f 0.5,1.5

; Faces
Data.i 0,1,2
Data.i 1,0,3
Data.i 4,6,5
Data.i 7,9,8

cube:
; Nb sommets / Nb faces
Data.i 24,12

; Vertices: pos / normals / uv
Data.f -0.5,0.5,-0.5
Data.f 0,1,0
Data.f 0,0
Data.f 0.5,0.5,-0.5
Data.f 0,1,0
Data.f 0,1
Data.f 0.5,0.5,0.5
Data.f 0,1,0
Data.f 1,1
Data.f -0.5,0.5,0.5
Data.f 0,1,0
Data.f 1,0
Data.f -0.5,-0.5,0.5
Data.f 0,-1,0
Data.f 0,0
Data.f 0.5,-0.5,0.5
Data.f 0,-1,0
Data.f 0,1
Data.f 0.5,-0.5,-0.5
Data.f 0,-1,0
Data.f 1,1
Data.f -0.5,-0.5,-0.5
Data.f 0,-1,0
Data.f 1,0
Data.f -0.5,0.5,0.5
Data.f 0,0,1
Data.f 0,0
Data.f 0.5,0.5,0.5
Data.f 0,0,1
Data.f 0,1
Data.f 0.5,-0.5,0.5
Data.f 0,0,1
Data.f 1,1
Data.f -0.5,-0.5,0.5
Data.f 0,0,1
Data.f 1,0
Data.f 0.5,0.5,-0.5
Data.f 0,0,-1
Data.f 0,0
Data.f -0.5,0.5,-0.5
Data.f 0,0,-1
Data.f 0,1
Data.f -0.5,-0.5,-0.5
Data.f 0,0,-1
Data.f 1,1
Data.f 0.5,-0.5,-0.5
Data.f 0,0,-1
Data.f 1,0
Data.f -0.5,0.5,-0.5
Data.f -1,0,0
Data.f 0,0
Data.f -0.5,0.5,0.5
Data.f -1,0,0
Data.f 0,1
Data.f -0.5,-0.5,0.5
Data.f -1,0,0
Data.f 1,1
Data.f -0.5,-0.5,-0.5
Data.f -1,0,0
Data.f 1,0
Data.f 0.5,0.5,0.5
Data.f 1,0,0
Data.f 0,0
Data.f 0.5,0.5,-0.5
Data.f 1,0,0
Data.f 0,1
Data.f 0.5,-0.5,-0.5
Data.f 1,0,0
Data.f 1,1
Data.f 0.5,-0.5,0.5
Data.f 1,0,0
Data.f 1,0

; Faces
Data.i 2,1,0
Data.i 0,3,2
Data.i 6,5,4
Data.i 4,7,6
Data.i 10,9,8
Data.i 8,11,10
Data.i 14,13,12
Data.i 12,15,14
Data.i 18,17,16
Data.i 16,19,18
Data.i 22,21,20
Data.i 20,23,22


octahedron:
; Nb sommets / Nb faces
Data.i 18,8

; Vertices: pos / normals / uv
Data.f 0,0.708107,0.708107
Data.f 0,1,0
Data.f 0,0.5
Data.f 0,0.708107,-0.706107
Data.f 0,1,0
Data.f 0,1.5
Data.f 1.001000,0,0
Data.f 1,0,0
Data.f 0.5,1
Data.f 0,-0.706107,0.708107
Data.f 0,0,1
Data.f -0.5,1
Data.f -0.999000,0,0
Data.f -1,0,0
Data.f 0,1.5
Data.f 0,-0.706107,-0.706107
Data.f 0,0,-1
Data.f -0.5,1
Data.f 1.001000,0,0
Data.f 0.577350,0,0.816496
Data.f 0,0.5
Data.f 0,0.708107,0.708107
Data.f 0.577350,0,0.816496
Data.f 0.5,1
Data.f 0,0.708107,0.708107
Data.f -0.577350,0,0.816496
Data.f 0.5,1
Data.f -0.999000,0,0
Data.f -0.577350,0.816496,0
Data.f -0.5,1
Data.f 0,0.708107,-0.706107
Data.f -0.577350,0,-0.816496
Data.f 0.5,1
Data.f 1.001000,0,0
Data.f 0.577350,0,-0.816496
Data.f 0,0.5
Data.f 0,0.708107,-0.706107
Data.f 0.577350,0,-0.816496
Data.f 0.5,1
Data.f 0,-0.706107,-0.706107
Data.f 0.577350,-0.816496,0
Data.f 0,1.5
Data.f 0,-0.706107,0.708107
Data.f 0.577350,-0.816496,0
Data.f 0,0.5
Data.f -0.999000,0,0
Data.f -0.577350,-0.816496,0
Data.f -0.5,1
Data.f 0,-0.706107,0.708107
Data.f -0.577350,-0.816496,0
Data.f 0,0.5
Data.f 0,-0.706107,-0.706107
Data.f -0.577350,-0.816496,0
Data.f 0,1.5

; Faces
Data.i 1,0,2
Data.i 6,7,3
Data.i 3,8,4
Data.i 9,0,1
Data.i 4,10,5
Data.i 5,12,11
Data.i 2,14,13
Data.i 15,17,16

dodecahedron:
; Nb sommets / Nb faces
Data.i 72,36

; Vertices: pos / normals / uv
Data.f 0.357822,0.935172,0
Data.f 0,0.955423,0.295242
Data.f 0.190983,1
Data.f -0.355822,0.935172,0
Data.f 0,0.955423,-0.295242
Data.f -0.190983,1
Data.f 0.578350,0.578350,0.578350
Data.f 0.688191,0.587785,0.425325
Data.f 0.309017,0.690983
Data.f 0,0.357822,0.935172
Data.f 0,0.850651,0.525731
Data.f 0,0.5
Data.f -0.576350,0.578350,0.578350
Data.f 0,0.850651,0.525731
Data.f -0.309017,0.690983
Data.f -0.576350,0.578350,-0.576350
Data.f 0,0.850651,-0.525731
Data.f -0.309017,1.309020
Data.f 0,0.357822,-0.933172
Data.f 0,0.850651,-0.525731
Data.f 0,1.5
Data.f 0.578350,0.578350,-0.576350
Data.f 0,0.850651,-0.525731
Data.f 0.309017,1.309020
Data.f 0.935172,0,0.357822
Data.f 1,0,0
Data.f 0.190983,1
Data.f 0.935172,0,-0.355822
Data.f 1,0,0
Data.f -0.190983,1
Data.f 0,-0.355822,-0.933172
Data.f 0,0,-1
Data.f -0.190983,1
Data.f 0.578350,-0.576350,-0.576350
Data.f 0.525731,0,-0.850651
Data.f -0.309017,0.690983
Data.f 0.578350,-0.576350,0.578350
Data.f 0.850651,-0.525731,0
Data.f 0.309017,1.309020
Data.f 0.357822,-0.933172,0
Data.f 0.850651,-0.525731,0
Data.f 0,1.5
Data.f -0.576350,-0.576350,-0.576350
Data.f -0.425325,-0.688191,-0.587785
Data.f -0.309017,1.309020
Data.f -0.355822,-0.933172,0
Data.f 0,-0.992447,0.122673
Data.f -0.190983,1
Data.f 0,-0.355822,0.935172
Data.f 0,-0.850651,0.525731
Data.f 0,0.5
Data.f -0.576350,-0.576350,0.578350
Data.f 0,-0.850651,0.525731
Data.f -0.309017,0.690983
Data.f -0.933172,0,-0.355822
Data.f -0.979432,-0.201774,0
Data.f -0.190983,1
Data.f -0.933172,0,0.357822
Data.f -0.992447,0.122673,0
Data.f 0.190983,1
Data.f 0.578350,0.578350,-0.576350
Data.f 0.850651,0.525731,0
Data.f -0.309017,0.690983
Data.f 0.578350,0.578350,-0.576350
Data.f 0.850651,0.525731,0
Data.f -0.309017,0.690983
Data.f 0.578350,0.578350,-0.576350
Data.f 0.850651,0.525731,0
Data.f -0.309017,0.690983
Data.f 0.357822,0.935172,0
Data.f 0.850651,0.525731,0
Data.f 0,0.5
Data.f 0.578350,0.578350,-0.576350
Data.f 0.525731,0,-0.850651
Data.f 0.309017,0.690983
Data.f 0,0.357822,-0.933172
Data.f 0.525731,0,-0.850651
Data.f 0.190983,1
Data.f 0.578350,0.578350,-0.576350
Data.f 0.525731,0,-0.850651
Data.f 0.309017,0.690983
Data.f 0.578350,0.578350,-0.576350
Data.f 0.525731,0,-0.850651
Data.f 0.309017,0.690983
Data.f 0.935172,0,-0.355822
Data.f 0.525731,0,-0.850651
Data.f 0,0.5
Data.f 0.578350,-0.576350,-0.576350
Data.f 0.850651,-0.525731,0
Data.f -0.309017,1.309020
Data.f 0.578350,-0.576350,-0.576350
Data.f 0.850651,-0.525731,0
Data.f -0.309017,1.309020
Data.f 0.578350,-0.576350,-0.576350
Data.f 0.850651,-0.525731,0
Data.f -0.309017,1.309020
Data.f 0.578350,-0.576350,-0.576350
Data.f 0,-0.850651,-0.525731
Data.f 0.309017,1.309020
Data.f 0,-0.355822,-0.933172
Data.f 0,-0.850651,-0.525731
Data.f 0,1.5
Data.f 0.578350,-0.576350,-0.576350
Data.f 0,-0.850651,-0.525731
Data.f 0.309017,1.309020
Data.f 0.578350,-0.576350,-0.576350
Data.f 0,-0.850651,-0.525731
Data.f 0.309017,1.309020
Data.f 0.357822,-0.933172,0
Data.f 0,-0.850651,-0.525731
Data.f 0.190983,1
Data.f 0.578350,-0.576350,0.578350
Data.f 0,-0.850651,0.525731
Data.f 0.309017,0.690983
Data.f 0.578350,-0.576350,0.578350
Data.f 0,-0.850651,0.525731
Data.f 0.309017,0.690983
Data.f 0.357822,-0.933172,0
Data.f 0,-0.850651,0.525731
Data.f 0.190983,1
Data.f -0.355822,-0.933172,0
Data.f -0.850651,-0.525731,0
Data.f 0,1.5
Data.f -0.355822,-0.933172,0
Data.f -0.850651,-0.525731,0
Data.f 0,1.5
Data.f -0.355822,-0.933172,0
Data.f -0.850651,-0.525731,0
Data.f 0,1.5
Data.f -0.576350,-0.576350,0.578350
Data.f -0.850651,-0.525731,0
Data.f 0.309017,1.309020
Data.f -0.933172,0,0.357822
Data.f -0.525731,0,0.850651
Data.f 0,1.5
Data.f -0.576350,0.578350,0.578350
Data.f -0.525731,0,0.850651
Data.f 0.309017,1.309020
Data.f 0,0.357822,0.935172
Data.f -0.525731,0,0.850651
Data.f 0.190983,1
Data.f -0.933172,0,0.357822
Data.f -0.525731,0,0.850651
Data.f 0,1.5
Data.f 0,0.357822,0.935172
Data.f -0.525731,0,0.850651
Data.f 0.190983,1
Data.f 0,-0.355822,0.935172
Data.f -0.525731,0,0.850651
Data.f -0.190983,1
Data.f -0.933172,0,0.357822
Data.f -0.525731,0,0.850651
Data.f 0,1.5
Data.f 0,-0.355822,0.935172
Data.f -0.525731,0,0.850651
Data.f -0.190983,1
Data.f -0.576350,-0.576350,0.578350
Data.f -0.525731,0,0.850651
Data.f -0.309017,1.309020
Data.f -0.576350,0.578350,-0.576350
Data.f -0.850651,0.525731,0
Data.f -0.309017,0.690983
Data.f -0.576350,0.578350,-0.576350
Data.f -0.850651,0.525731,0
Data.f -0.309017,0.690983
Data.f -0.355822,0.935172,0
Data.f -0.850651,0.525731,0
Data.f 0,0.5
Data.f -0.355822,0.935172,0
Data.f -0.850651,0.525731,0
Data.f 0,0.5
Data.f -0.576350,0.578350,0.578350
Data.f -0.850651,0.525731,0
Data.f 0.309017,0.690983
Data.f -0.933172,0,-0.355822
Data.f -0.525731,0,-0.850651
Data.f 0,1.5
Data.f -0.933172,0,-0.355822
Data.f -0.525731,0,-0.850651
Data.f 0,1.5
Data.f 0,0.357822,-0.933172
Data.f -0.525731,0,-0.850651
Data.f 0.190983,1
Data.f -0.933172,0,-0.355822
Data.f -0.525731,0,-0.850651
Data.f 0,1.5
Data.f 0,0.357822,-0.933172
Data.f -0.525731,0,-0.850651
Data.f 0.190983,1
Data.f -0.576350,0.578350,-0.576350
Data.f -0.525731,0,-0.850651
Data.f 0.309017,1.309020
Data.f 0,0.357822,0.935172
Data.f 0.525731,0,0.850651
Data.f 0.190983,1
Data.f 0.935172,0,0.357822
Data.f 0.525731,0,0.850651
Data.f 0,0.5
Data.f 0,0.357822,0.935172
Data.f 0.525731,0,0.850651
Data.f 0.190983,1
Data.f 0.935172,0,0.357822
Data.f 0.525731,0,0.850651
Data.f 0,0.5
Data.f 0.578350,-0.576350,0.578350
Data.f 0.525731,0,0.850651
Data.f -0.309017,0.690983
Data.f 0,0.357822,0.935172
Data.f 0.525731,0,0.850651
Data.f 0.190983,1
Data.f 0.578350,-0.576350,0.578350
Data.f 0.525731,0,0.850651
Data.f -0.309017,0.690983
Data.f 0,-0.355822,0.935172
Data.f 0.525731,0,0.850651
Data.f -0.190983,1

; Faces
Data.i 0,3,2
Data.i 0,4,3
Data.i 0,1,4
Data.i 1,6,5
Data.i 1,7,6
Data.i 1,0,7
Data.i 20,8,9
Data.i 21,2,8
Data.i 22,23,2
Data.i 24,10,25
Data.i 26,11,10
Data.i 27,28,11
Data.i 29,12,13
Data.i 30,8,12
Data.i 31,9,8
Data.i 32,14,33
Data.i 34,15,14
Data.i 35,36,15
Data.i 15,16,17
Data.i 15,37,16
Data.i 15,39,38
Data.i 40,18,14
Data.i 41,19,18
Data.i 42,43,19
Data.i 44,46,45
Data.i 47,49,48
Data.i 50,52,51
Data.i 19,53,18
Data.i 19,55,54
Data.i 19,57,56
Data.i 58,10,14
Data.i 59,60,10
Data.i 61,63,62
Data.i 64,65,2
Data.i 66,68,67
Data.i 69,71,70

icosahedron:
; Nb sommets / Nb faces
Data.i 42,20

; Vertices: pos / normals / uv
Data.f 0,0.851651,0.526731
Data.f 0,1,0
Data.f 0,0.690983
Data.f 0,0.851651,-0.524731
Data.f 0,1,0
Data.f 0,1.309020
Data.f 0.851651,0.526731,0
Data.f 0.356822,0.934172,0
Data.f 0.5,1
Data.f 0.526731,0,0.851651
Data.f 0.810146,0,0.586227
Data.f 0.5,1
Data.f -0.524731,0,0.851651
Data.f 0,0,1
Data.f 0,1.309020
Data.f -0.849651,0.526731,0
Data.f -0.934172,0.356822,0
Data.f 0,0.690983
Data.f -0.524731,0,-0.849651
Data.f -0.810146,0,-0.586227
Data.f -0.5,1
Data.f 0.526731,0,-0.849651
Data.f 0,0,-1
Data.f 0,0.690983
Data.f 0.851651,-0.524731,0
Data.f 0.934172,-0.356822,0
Data.f 0,1.309020
Data.f 0,-0.849651,-0.524731
Data.f 0,-0.356822,-0.934172
Data.f -0.5,1
Data.f 0,-0.849651,0.526731
Data.f 0,-0.707107,0.707107
Data.f 0.309017,1.5
Data.f -0.849651,-0.524731,0
Data.f -0.934172,-0.356822,0
Data.f 0,1.309020
Data.f 0.851651,0.526731,0
Data.f 0.577350,0.577350,0.577350
Data.f 0,0.690983
Data.f 0,0.851651,0.526731
Data.f 0.577350,0.577350,0.577350
Data.f 0.309017,0.5
Data.f 0.526731,0,0.851651
Data.f 0,0.356822,0.934172
Data.f 0,0.690983
Data.f 0,0.851651,0.526731
Data.f 0,0.356822,0.934172
Data.f 0.5,1
Data.f -0.524731,0,0.851651
Data.f -0.577350,0.577350,0.577350
Data.f 0.5,1
Data.f 0,0.851651,0.526731
Data.f -0.577350,0.577350,0.577350
Data.f 0.309017,0.5
Data.f -0.849651,0.526731,0
Data.f -0.356822,0.934172,0
Data.f -0.5,1
Data.f 0,0.851651,-0.524731
Data.f -0.577350,0.577350,-0.577350
Data.f -0.309017,0.5
Data.f -0.524731,0,-0.849651
Data.f 0,0.356822,-0.934172
Data.f 0,1.309020
Data.f 0,0.851651,-0.524731
Data.f 0,0.356822,-0.934172
Data.f 0.5,1
Data.f 0.526731,0,-0.849651
Data.f 0.577350,0.577350,-0.577350
Data.f -0.5,1
Data.f 0.851651,0.526731,0
Data.f 0.577350,0.577350,-0.577350
Data.f 0,0.690983
Data.f 0,0.851651,-0.524731
Data.f 0.577350,0.577350,-0.577350
Data.f -0.309017,0.5
Data.f 0.851651,0.526731,0
Data.f 0.934172,0,0.356822
Data.f 0,0.690983
Data.f 0.851651,0.526731,0
Data.f 0.934172,0,-0.356822
Data.f 0,0.690983
Data.f 0.526731,0,-0.849651
Data.f 0.934172,0,-0.356822
Data.f -0.5,1
Data.f -0.524731,0,-0.849651
Data.f 0,-0.356822,-0.934172
Data.f 0,1.309020
Data.f 0,-0.849651,-0.524731
Data.f 0.577350,-0.577350,-0.577350
Data.f -0.309017,1.5
Data.f 0.526731,0,-0.849651
Data.f 0.577350,-0.577350,-0.577350
Data.f -0.5,1
Data.f 0.851651,-0.524731,0
Data.f 0.356822,-0.934172,0
Data.f 0.5,1
Data.f 0,-0.849651,-0.524731
Data.f 0.356822,-0.934172,0
Data.f 0,1.309020
Data.f 0,-0.849651,0.526731
Data.f 0.356822,-0.934172,0
Data.f 0,0.690983
Data.f 0,-0.849651,-0.524731
Data.f -0.577350,-0.577350,-0.577350
Data.f -0.309017,1.5
Data.f -0.849651,-0.524731,0
Data.f -0.356822,-0.934172,0
Data.f -0.5,1
Data.f 0,-0.849651,0.526731
Data.f -0.356822,-0.934172,0
Data.f 0,0.690983
Data.f 0,-0.849651,-0.524731
Data.f -0.356822,-0.934172,0
Data.f 0,1.309020
Data.f 0,-0.849651,0.526731
Data.f 0,-0.356822,0.934172
Data.f -0.5,1
Data.f 0.526731,0,0.851651
Data.f 0,-0.356822,0.934172
Data.f 0,0.690983
Data.f -0.524731,0,0.851651
Data.f -0.577350,-0.577350,0.577350
Data.f 0.5,1
Data.f -0.524731,0,0.851651
Data.f -0.934172,0,0.356822
Data.f 0.5,1

; Faces
Data.i 1,0,2
Data.i 12,13,3
Data.i 14,15,4
Data.i 16,17,5
Data.i 18,0,1
Data.i 5,19,6
Data.i 20,21,7
Data.i 22,24,23
Data.i 25,3,8
Data.i 26,8,27
Data.i 28,7,9
Data.i 29,30,8
Data.i 8,3,10
Data.i 31,33,32
Data.i 6,34,11
Data.i 35,37,36
Data.i 38,39,4
Data.i 10,40,11
Data.i 6,11,5
Data.i 5,11,41

EndDataSection

Re: Convert everything on this page to PureBasic

Posted: Thu Feb 13, 2014 11:12 pm
by davido
@applePi
@Kelebrindae

Very nice examples.
Thank you both for sharing. :D