so enjoy the galaxy with easy code.


bigpoints.material ..save this file in the same folder as the code
Code: Select all
material BigPoints
{
receive_shadows off
technique
{
pass
{
point_size 2
lighting off
diffuse vertexcolour
}
}
}
Code: Select all
Enumeration
#sphere = 20
#bigPoints
EndEnumeration
Procedure.f RandF(Min.f, Max.f, Resolution.i = 10000) ; by kenmo
ProcedureReturn (Min + (Max - Min) * Random(Resolution) / Resolution)
EndProcedure
Procedure.i _Random(Max.i, Min.i = 0) ; by kenmo
ProcedureReturn Random(Max - Min) + Min
EndProcedure
Global Dim MeshData.PB_MeshVertex(0)
Global Dim MeshData2.PB_MeshVertex(0)
#CameraSpeed = 0.1
Global indx, indx2, size = 300000
Global incr.f = 0.02
Define.f KeyX, KeyY, MouseX, MouseY
Declare DrawMatrix()
Declare DrawMatrix2()
Declare isolateRed()
ExamineDesktops()
InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
OpenWindow(0,0,0,DesktopWidth(0), DesktopHeight(0),"mouse/arrow keys for the camera",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,DesktopWidth(0), DesktopHeight(0),1,0,0,#PB_Screen_WaitSynchronization)
Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts", #PB_3DArchive_FileSystem)
Parse3DScripts()
;- Material
CreateMaterial(0, LoadTexture(0, "White.jpg"))
DisableMaterialLighting(0, #True)
CreateMaterial(1, LoadTexture(1, "terrain_texture.jpg"))
GetScriptMaterial(#bigPoints, "BigPoints")
;-Camera
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0,0,3,7, #PB_Absolute)
CameraLookAt(0, 0, 0, 0)
CameraBackColor(0, RGB(100, 100, 100))
;-Light
CreateLight(0, RGB(255, 255, 255), 20, 150, 120)
AmbientColor(RGB(90, 90, 90))
;-Mesh
DrawMatrix()
DrawMatrix2() ; for the thick white points
FinishMesh(#True)
SetMeshMaterial(0, MaterialID(0),0)
SetMeshMaterial(0, MaterialID(#BigPoints),1) ; set submesh 1 to thick points material
;DisableMaterialLighting(#BigPoints, #True)
CreateEntity(0, MeshID(0), #PB_Material_None, 0,0,0)
GetMeshData(0,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_Color, 0, MeshVertexCount(0,0)-1)
GetMeshData(0,1, MeshData2(), #PB_Mesh_Vertex | #PB_Mesh_Color, 0, MeshVertexCount(0,1)-1)
UpdateMeshBoundingBox(0) ; essential to prevent dissappearance of mesh at some angles
SetEntityMaterial(0,MaterialID(0),0)
SetEntityMaterial(0,MaterialID(#bigPoints),1)
CreateSphere(#sphere, 0.2)
CreateEntity(#sphere, MeshID(#sphere), MaterialID(1), 0, 0.2, 2.9)
AttachEntityObject(0, "", EntityID(#sphere))
indx + indx2
Repeat
Repeat
Until WindowEvent()=0
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
KeyX = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = #CameraSpeed
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = #CameraSpeed
Else
KeyY = 0
EndIf
If KeyboardPushed(#PB_Key_A)
incr.f = 0.02
isolateRed()
ElseIf KeyboardPushed(#PB_Key_Z)
incr.f = -0.02
isolateRed()
EndIf
EndIf
If ExamineMouse()
MouseX = -(MouseDeltaX()/10)
MouseY = -(MouseDeltaY()/10)
EndIf
;isolateRed() ; uncomment this and the blue bump will move automatic , press A/Z to direct the movement
MoveCamera (0, KeyX, 0, KeyY)
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
RotateEntity(0, 0, 0.1, 0, #PB_Relative)
RotateEntity(#sphere, 0, 1, 0, #PB_Relative)
RenderWorld()
SetWindowTitle(0, "points = "+Str(indx)+" " + " "+"FPS : "+Str(Engine3DStatus(#PB_Engine3D_CurrentFPS )) + " .. press 'A' ,'Z' to move the Bump up/down")
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
End
;-Procedures
Procedure DrawMatrix()
CreateMesh(0, #PB_Mesh_PointList, #PB_Mesh_Dynamic)
e.f = 2.718281828459
x.f=-4: y.f: z.f=-4
While z<= 4
While x<=4
If x*x+z*z<=13
y = Pow(e,(0.1-x*x-z*z)) ; the formula
If y<=0.8
Repeat
rand.i = _Random(1, -1)
Until rand.i <> 0 ; to get rid of value zero
y1.f = y * rand + RandF(0.1, 0.2); let the bump go up and down, and let the disk have some thickness
MeshVertexPosition(x,y1,z)
indx + 1
EndIf
If y<=0.00005
MeshVertexColor(RGB(50,255,0)) ;green
ElseIf y<=0.001
MeshVertexColor(RGB(255,200,0)) ; orange
ElseIf y<=0.01
MeshVertexColor(RGB(255,20,0)) ;red
ElseIf y<=0.8
MeshVertexColor(RGB(0,160,255)) ; bluesh
Else
MeshVertexColor(RGB(255,255,255)) ; white
EndIf
EndIf
x+0.015
Wend
x = -4
z+0.015
Wend
EndProcedure
Procedure DrawMatrix2()
; just to draw the thick white points
AddSubMesh(#PB_Mesh_PointList)
e.f = 2.718281828459
x.f=-1: y.f: z.f=-1: indx2 = 0
While z<= 1
While x<=1
If x*x+z*z<=13
y = Pow(e,(0.1-x*x-z*z)) ; the formula
If y>0.8
Repeat
rand.i = _Random(1, -1)
Until rand.i <> 0 ; to get rid of value zero
y = y * rand + RandF(0.1, 0.2); let the bump go up and down, and let the disk have some thickness
MeshVertexPosition(x,y,z)
MeshVertexColor(RGB(255,255,255)) ; white
indx2+1
EndIf
EndIf
x+0.015
Wend
x = -1
z+0.015
Wend
EndProcedure
Procedure isolateRed()
GetMeshData(0, 0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_Color, 0, MeshVertexCount(0,0)-1)
For i = 0 To ArraySize(MeshData())
If MeshData(i)\Color = RGB(255,160,0) Or MeshData(i)\Color = RGB(255,255,255)
MeshData(i)\y + incr ; either move up or down, depends on incr value
EndIf
Next
SetMeshData(0,0, MeshData(), #PB_Mesh_Vertex | #PB_Mesh_Color, 0, MeshVertexCount(0,0)-1)
GetMeshData(0, 1, MeshData2(), #PB_Mesh_Vertex | #PB_Mesh_Color, 0, MeshVertexCount(0,1)-1)
For i = 0 To ArraySize(MeshData2())
If MeshData2(i)\Color = RGB(255,255,255)
MeshData2(i)\y + incr ; either move up or down, depends on incr value
EndIf
Next
SetMeshData(0,1, MeshData2(), #PB_Mesh_Vertex | #PB_Mesh_Color, 0, MeshVertexCount(0,1)-1)
EndProcedure
this is done differently, we make mesh from 100000 points previously, "as if it is Dim Mesh(100000)", all points with position 0,0,0. after that we give the points other values depends on equations
the equation here is from the Psychophanta code posted in MP3D forum here http://purebasic.fr/english/viewtopic.p ... 15#p433538

Code: Select all
Enumeration
#sphere = 20
EndEnumeration
Procedure.f RandF(Min.f, Max.f, Resolution.i = 10000)
RandomSeed(Random(100000, 1))
ProcedureReturn (Min + (Max - Min) * Random(Resolution) / Resolution)
EndProcedure
Global Dim MeshData.PB_MeshVertex(0)
#CameraSpeed = 5
Global indx, size = 100000
Define.f KeyX, KeyY, MouseX, MouseY
Declare CreateMatrix()
Declare DrawMatrix()
ExamineDesktops()
InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
OpenWindow(0,0,0,DesktopWidth(0), DesktopHeight(0),"mouse/arrow keys for the camera",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,DesktopWidth(0), DesktopHeight(0),1,0,0,#PB_Screen_WaitSynchronization)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Scripts", #PB_3DArchive_FileSystem)
Parse3DScripts()
;- Material
CreateMaterial(0, LoadTexture(0, "White.jpg"))
DisableMaterialLighting(0, #True)
CreateMaterial(1, LoadTexture(1, "terrain_texture.jpg"))
;-Camera
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0,0,100,300, #PB_Absolute)
CameraLookAt(0, 5, 0, 0)
CameraBackColor(0, RGB(0, 0, 0))
;-Light
CreateLight(0, RGB(255, 255, 255), 20, 150, 120)
AmbientColor(RGB(90, 90, 90))
CreateSphere(#sphere, 4, 32,32)
CreateEntity(#sphere, MeshID(#sphere), MaterialID(1), 0,0,0)
;-Mesh
CreateMatrix()
DrawMatrix()
Global vertTot
Repeat
Repeat
Until WindowEvent()=0
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
KeyX = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = #CameraSpeed
Else
KeyX = 0
EndIf
If KeyboardPushed(#PB_Key_Up)
KeyY = -#CameraSpeed
ElseIf KeyboardPushed(#PB_Key_Down)
KeyY = #CameraSpeed
Else
KeyY = 0
EndIf
EndIf
If ExamineMouse()
MouseX = -(MouseDeltaX()/10)
MouseY = -(MouseDeltaY()/10)
EndIf
MoveCamera (0, KeyX, 0, KeyY)
RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
RotateEntity(0, 0, 0.5, 0, #PB_Relative)
RenderWorld()
SetWindowTitle(0, "points = "+Str(indx) + " "+"FPS : "+Str(Engine3DStatus(#PB_Engine3D_CurrentFPS )))
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
End
;LineXY(
;-Procedures
Procedure DrawMatrix()
For indx =0 To size
xd=Random(1800)
;MeshData(indx)\x = Cos(xd)*Cos(indx*360/size)*100
;MeshData(indx)\y = Cos(xd)*Sin(indx*360/size)*100
;MeshData(indx)\z = Sin(xd)*100
;MeshData(indx)\x = Cos(indx*360/size)*Cos(indx*360/size)*100
;MeshData(indx)\y = Cos(indx*360/size)*Sin(xd)*100
;MeshData(indx)\z = Sin(indx*360/size)*100
MeshData(indx)\x = Sin(indx*360/size)*Cos(indx*360/size)*Sin(xd)*100
MeshData(indx)\y = Cos(indx*360/size)*Sin(xd)*Cos(xd)*100
MeshData(indx)\z = Sin(xd)*Cos(indx*360/size)*100
; try also the commented equations above
Next
SetMeshData(0,0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(0)-1)
EndProcedure
Procedure CreateMatrix()
CreateMesh(0, #PB_Mesh_PointList, #PB_Mesh_Dynamic)
For i=0 To size; just a shapeless mesh for the usage later
MeshVertexPosition(0,0,0) ; plotted to the same point 0,0,0
MeshVertexColor(RGB(0,255,0))
Next
FinishMesh(#True)
SetMeshMaterial(0, MaterialID(0))
CreateEntity(0, MeshID(0), #PB_Material_None, 10,0,0)
GetMeshData(0,0, MeshData(), #PB_Mesh_Vertex, 0, MeshVertexCount(0)-1)
EndProcedure