Galaxy Shape from points collection

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

Galaxy Shape from points collection

Post by applePi »

i was designing this galaxy shape when discovered a possible bug reported in my previous post http://purebasic.fr/english/viewtopic.php?f=36&t=65511.
so enjoy the galaxy with easy code.
Image
Image

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
Image

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
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Galaxy Shape from points collection

Post by DK_PETER »

Very good, applePi. :)

Here's another galaxy using point sprites.

You need these images - or something else which suits you.

Temporary images to test with:

ImageImageImageImage
ImageImageImage
Image

Material script:

Code: Select all

material RedSmokeSprite
{
   technique
   {
      pass
      {

         scene_blend add
         depth_write off
         
         point_sprites on
         point_size 150

         texture_unit
         {
            texture red.png
         }
      }
   }
}

material GreenSmokeSprite
{
   technique
   {
      pass
      {

         scene_blend add
         depth_write off
         
         point_sprites on
         point_size 100

         texture_unit
         {
            texture green.png
         }
      }
   }
}

material BlueSmokeSprite
{
   technique
   {
      pass
      {

         scene_blend add
         depth_write off
         
         point_sprites on
         point_size 100

         texture_unit
         {
            texture blue.png
         }
      }
   }
}


material GreySmokeSprite
{
   technique
   {
      pass
      {

         scene_blend add
         depth_write off
         
         point_sprites on
         point_size 120

         texture_unit
         {
            texture grey.png
         }
      }
   }
}

material Spark1
{
   technique
   {
      pass
      {

         scene_blend add
         depth_write off
         
         point_sprites on
         point_size 40

         texture_unit
         {
            texture spark1.png
         }
      }
   }
}

material Spark2
{
   technique
   {
      pass
      {

         scene_blend add
         depth_write off
         
         point_sprites on
         point_size 50

         texture_unit
         {
            texture spark2.png
         }
      }
   }
}

material Spark3
{
   technique
   {
      pass
      {

         scene_blend add
         depth_write off
         
         point_sprites on
         point_size 45

         texture_unit
         {
            texture spark3.png
         }
      }
   }
}

material Spark4
{
   technique
   {
      pass
      {

         ambient 0.5 0.5 1.0
         diffuse 1.0 1.0 1.0         
	 scene_blend add
         depth_write off
         
         point_sprites on
         point_size 20

         texture_unit
         {
            texture grey.png
         }
      }
   }
}

material Ring
{
   technique
   {
      pass
      {

         scene_blend add
         depth_write off
         
         point_sprites on
         point_size 45

         texture_unit
         {
            texture ring_flare.png
         }
      }
   }
}
Perticle script:

Code: Select all

particle_system Jetstream1
{
	quota	15000
	particle_width	0.1
	particle_height	100
	cull_each	false
	renderer	billboard
	billboard_type	point

	emitter Point
	{
		angle 0.2
		colour 1 1 1 1
		colour_range_start 1 1 1 1
		colour_range_end 0.208333 0.474227 1 0.645833
		direction 0 -1 0
		emission_rate 300
		position 0 0 0
		velocity 100
		velocity_min 100
		velocity_max 1000
		time_to_live 1
		time_to_live_min 1
		time_to_live_max 20
		duration 0
		duration_min 0
		duration_max 0
		repeat_delay 0
		repeat_delay_min 0
		repeat_delay_max 0
	}

	affector Scaler
	{
	    rate 30
	}
}

particle_system Jetstream2
{
	quota	15000
	particle_width	0.1
	particle_height	100
	cull_each	false
	renderer	billboard
	billboard_type	point

	emitter Point
	{
		angle	0.2
		colour	1 1 1 1
		colour_range_start 1 1 1 1
		colour_range_end 0.208333 0.474227 1 0.645833
		direction 0 1 0
		emission_rate 300
		position 0 0 0
		velocity 100
		velocity_min 100
		velocity_max 1000
		time_to_live 1
		time_to_live_min 1
		time_to_live_max 20
		duration 0
		duration_min 0
		duration_max 0
		repeat_delay 0
		repeat_delay_min 0
		repeat_delay_max 0
	}

	affector Scaler
	{
	    rate 30
	}
}

particle_system Explode
{
	quota	20000
	particle_width	5
	particle_height	5
	cull_each	false
	renderer	billboard
	billboard_type	point

	emitter Ellipsoid
	{
		angle	120
		colour	1 1 1 1
		colour_range_start 1 1 1 1
		colour_range_end 1 1 1 1
		direction 0 0 -1
		emission_rate 5000
		position 0 0 0
		velocity 1
		velocity_min 1
		velocity_max 1
		time_to_live 3
		time_to_live_min 3
		time_to_live_max 6
		duration 0
		duration_min 0
		duration_max 0
		repeat_delay 0
		repeat_delay_min 0
		repeat_delay_max 0
		width	8000
		height 4000
		depth	8000
	}

	affector Scaler
	{
	    rate 100
	}
}
The code:

Code: Select all

; Simple Script example to create a VERY LARGE galaxy
;             By DK_PETER
;---------------------------------------
; Use mouse and WASD keys to move around
;---------------------------------------
If InitEngine3D() = 0
  End
EndIf
If InitSprite() = 0
  End
EndIf
If InitMouse() = 0
  End
EndIf
If InitKeyboard() = 0
  End
EndIf

DeclareModule _Galaxy
  
  Declare.i SetResolution(Width.i = 1024, Height.i = 768, FullScreen.i = #False)
  Declare.i Run()
  
EndDeclareModule

Module _Galaxy
  
  Structure object
    id.i
    ma.i
    ms.i
    tx.i
  EndStructure
  Global NewList ob.object()
  Global Dim par.object(2)
  
  Structure Vector3D
    x.f
    y.f
    z.f
  EndStructure
  
  Structure Vector2D
    x.f
    y.f
  EndStructure
  
  Declare   OrbitCalc3D(*ReturnVec.Vector3D, CenterX.f, CenterY.f, CenterZ.f, AngleX.f, AngleY.f, Radius.i)
  Declare.i MakeIt()
  Declare.f RandomF(Min.f, Max.f, Res.i = 100000)
  
  Global fs.i, no.i, key.Vector3D, m.Vector2D

  Procedure.i SetResolution(Width.i = 1024, Height.i = 768, FullScreen.i = #False)
    fs = FullScreen
    If FullScreen = #False
      OpenWindow(0, 0, 0, Width, Height, "Simple Galaxy - Use mouse and WASD keys to move around",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
      OpenWindowedScreen(WindowID(0), 0, 0, Width, Height)
    Else
      OpenScreen(Width, Height, 32, "Simple Galaxy - Use mouse and WASD keys to move around")
    EndIf
    Add3DArchive(".", #PB_3DArchive_FileSystem)
    Parse3DScripts()
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 0, 0, 400)
  EndProcedure
  
  Procedure OrbitCalc3D(*ReturnVec.Vector3D, CenterX.f, CenterY.f, CenterZ.f, AngleX.f, AngleY.f, Radius.i)
    *ReturnVec\X = CenterX + Radius*Cos(AngleY)*Cos(AngleX)
    *ReturnVec\Y = CenterY + Radius*Sin(AngleX)
    *ReturnVec\Z = CenterZ + Radius*Sin(AngleY)*Cos(AngleX)
  EndProcedure

  Procedure.f RandomF(Min.f, Max.f, Res.i = 100000)
    ProcedureReturn (Min + (Max - Min) * Random(Res) / Res)
  EndProcedure
  
  Procedure.i MakeIt()
    Protected v.Vector3D, z.i, y.i, x.i, angx.f, angy.f
 
    AddElement(ob())
    With ob()
      \ms = CreateMesh(#PB_Any, #PB_Mesh_PointList, #PB_Mesh_Static)
      For x = 0 To 360 Step 16 
        For y = 0 To 360 Step 16
          For z = 0 To 360  Step 8
            OrbitCalc3D(v, 0, 0, 0, z, x, 500)
            MeshVertexPosition(randomf(-300, 300) + v\x, randomf(-300, 300) + v\y, randomf(-300, 300) + v\z)
          Next z
        Next y
      Next x
      FinishMesh(#True)
      \ma = GetScriptMaterial(#PB_Any, "Spark1")
      \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 0, 0)
      ScaleEntity(\id, 12, 1, 12)
    EndWith
    
    AddElement(ob())
    With ob()
      \ms = CreateMesh(#PB_Any, #PB_Mesh_PointList, #PB_Mesh_Static)
      For x = 0 To 360 Step 16 
        For y = 0 To 360 Step 32
          For z = 0 To 360  Step 16
            OrbitCalc3D(v, 0, 0, 0, z, x, 1000)
            MeshVertexPosition(randomf(-300, 300) + v\x, randomf(-300, 300) + v\y, randomf(-300, 300) + v\z)
          Next z
        Next y
      Next x
      FinishMesh(#True)
      \ma = GetScriptMaterial(#PB_Any, "Spark1")
      \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 0, 0)
      ScaleEntity(\id, 12, 0.5, 12)
    EndWith
    
    AddElement(ob())
    With ob()
      \ms = CreateMesh(#PB_Any, #PB_Mesh_PointList, #PB_Mesh_Static)
      For x = 0 To 360 Step 32 
        For y = 0 To 360 Step 16
          For z = 0 To 360  Step 8
            OrbitCalc3D(v, 0, 0, 0, z, x, 2000)
            MeshVertexPosition(randomf(-400, 400) + v\x, randomf(-400, 400) + v\y, randomf(-400, 400) + v\z)
          Next z
        Next y
      Next x
      FinishMesh(#True)
      \ma = GetScriptMaterial(#PB_Any, "Spark2")
      \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 0, 0)
      ScaleEntity(\id, 15, 0.3, 15)
    EndWith
    
    AddElement(ob())
    With ob()
      \ms = CreateMesh(#PB_Any, #PB_Mesh_PointList, #PB_Mesh_Static)
      For x = 0 To 360 Step 16 
        For y = 0 To 360 Step 16
          For z = 0 To 360  Step 16
            OrbitCalc3D(v, 0, 0, 0, z, x, 2400)
            MeshVertexPosition(randomf(-700, 700) + v\x, randomf(-200, 200) + v\y, randomf(-700, 700) + v\z)
          Next z
        Next y
      Next x
      FinishMesh(#True)
      \ma = GetScriptMaterial(#PB_Any, "Spark3")
      \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 0, 0)
      ScaleEntity(\id, 10, 0.2, 10)
    EndWith
    
    AddElement(ob())
    With ob()
      \ms = CreateMesh(#PB_Any, #PB_Mesh_PointList, #PB_Mesh_Static)
      For x = 0 To 360 Step 32 
        For y = 0 To 360 Step 32
          For z = 0 To 360  Step 32
            OrbitCalc3D(v, 0, 0, 0, z, x, 1000)
            MeshVertexPosition(randomf(-400, 400) + v\x, randomf(-400, 400) + v\y, randomf(-400, 400) + v\z)
          Next z
        Next y
      Next x
      FinishMesh(#True)
      \ma = GetScriptMaterial(#PB_Any, "BlueSmokeSprite")
      \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 0, 0)
      ScaleEntity(\id, 16, 0.3, 16)
    EndWith
    
    AddElement(ob())
    With ob()
      \ms = CreateMesh(#PB_Any, #PB_Mesh_PointList, #PB_Mesh_Static)
      For x = 0 To 360 Step 32 
        For y = 0 To 360 Step 32
          For z = 0 To 360  Step 32
            OrbitCalc3D(v, 0, 0, 0, z, x, 1000)
            MeshVertexPosition(randomf(-500, 500) + v\x, randomf(-200, 200) + v\y, randomf(-500, 500) + v\z)
          Next z
        Next y
      Next x
      FinishMesh(#True)
      \ma = GetScriptMaterial(#PB_Any, "GreenSmokeSprite")
      \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 0, 0)
      ScaleEntity(\id, 10, 1, 10)
    EndWith

    AddElement(ob())
    With ob()
      \ms = CreateMesh(#PB_Any, #PB_Mesh_PointList, #PB_Mesh_Static)
      For x = 0 To 360 Step 32 
        For y = 0 To 360 Step 32
          For z = 0 To 360  Step 32
            OrbitCalc3D(v, 0, 0, 0, z, x, 1000)
            MeshVertexPosition(randomf(-700, 700) + v\x, randomf(-100, 100) + v\y, randomf(-700, 700) + v\z)
          Next z
        Next y
      Next x
      FinishMesh(#True)
      \ma = GetScriptMaterial(#PB_Any, "RedSmokeSprite")
      \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 0, 0)
      ScaleEntity(\id, 17, 0.8, 17)
    EndWith

    With par(0)
      \id = GetScriptParticleEmitter(#PB_Any, "Jetstream1")
      \ma = GetScriptMaterial(#PB_Any, "Spark3")
      ParticleMaterial(\id, MaterialID(\ma))
    EndWith
    
    With par(1)
      \id = GetScriptParticleEmitter(#PB_Any, "Jetstream2")
      \ma = GetScriptMaterial(#PB_Any, "Spark3")
       ParticleMaterial(\id, MaterialID(\ma))
   EndWith
   
    With par(2)
      \id = GetScriptParticleEmitter(#PB_Any, "Explode")
      \ma = GetScriptMaterial(#PB_Any, "Ring")
       ParticleMaterial(\id, MaterialID(\ma))
   EndWith
   
    no = CreateNode(#PB_Any, 0, 0, -14000)
    ForEach ob()
      AttachNodeObject(no, EntityID(ob()\id))
    Next 
    
    AttachNodeObject(no, ParticleEmitterID(par(0)\id))
    AttachNodeObject(no, ParticleEmitterID(par(1)\id))
    AttachNodeObject(no, ParticleEmitterID(par(2)\id))
    
    AddElement(ob())
    With ob()
      \ms = CreateMesh(#PB_Any, #PB_Mesh_PointList, #PB_Mesh_Static)
      For x = 0 To 3000
         MeshVertexPosition(randomf(-90000,90000) , randomf(-90000,90000), randomf(-90000,90000))
      Next x
      FinishMesh(#True)
      \ma = GetScriptMaterial(#PB_Any, "Spark4")
      \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 0, -5000)
    EndWith
    
    ProcedureReturn #True
  EndProcedure
  
  Procedure.i Run()
    ret = MakeIt()
    
    Repeat
      
      If fs = #False
        Repeat
          ev = WindowEvent()
        Until ev = 0
      EndIf
      
      RotateNode(no, 0, 0.03, 0, #PB_Relative)

      RenderWorld()
      
      ExamineMouse()
      m\x = -MouseDeltaX()/10 ;Fix this if mouse movement isn't suitable for you
      m\y = -MouseDeltaY()/10 ;Fix this if mouse movement isn't suitable for you
      
      ExamineKeyboard()
      
        If KeyboardPushed(#PB_Key_A)
          Key\x = -30
        ElseIf KeyboardPushed(#PB_Key_D)
          Key\x = 30
        Else
          Key\x = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_W)
          Key\y = -30
        ElseIf KeyboardPushed(#PB_Key_S)
          Key\y = 30
        Else
          Key\y = 0
        EndIf
       RotateCamera(0, m\y, m\x, 0, #PB_Relative)
       MoveCamera(0, Key\x, 0, Key\y)

      FlipBuffers()
      
    Until KeyboardPushed(#PB_Key_Escape)

  EndProcedure

EndModule

_Galaxy::SetResolution() ;Set your resolution - default: 1024x768 Windowed
_Galaxy::Run()
Bye :wink:
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: Galaxy Shape from points collection

Post by applePi »

Thank you DK_PETER , you are the material magician, yes it is a very large galaxy and at first i haven't recognized that me the watcher is inside the galaxy until rotating with the mouse and going Up to see the disk shape galaxy. i have to disable the debugger.
it seems your program creates more than 63000 stars there with sprites running okay on my machine, i have tested it on winxp/32 and ubuntu 14.x/64 and it works okay .
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Galaxy Shape from points collection

Post by Olliv »

Hello... Excuse me to be a little bit weight but, normally, it seems that we can exchange code simply. Imagine, I make a code of galaxy.

I prefer "follow" to keep a team spirit, and a functionnal coherence.

1st stop, my browser : Do want to use this as browser by default ?!?
No... I just want to upload a code.

2nd stop, my search engine : Your search engine uses cookie etc...
No. I just want to upload my f.. !

3th stop, the forum : Do you know tapatalk ? Do you want to...
NO. I just want to...

4th stop, the forum : Ad... LA MARINE NATIONALE RECRUTE.
Noo! I just want share my w... ! Sh...

Okay now, I reach the dialog I do not describe to you, such it is shame or ergonomy...

We are in 2020, and the law of Moore I do not see the progress
of the net...

I just wanted to say you this little message, dear contributors above : none of your links are available, no image, nothing...

Sure I am able to communicate with you privately, or not. Sure my work below is not the best code of the century. Sure it is not the first equation I discover before the best mathematician. But just it represents MY pleasure I want to share with you : simple !!!

1) you copy the code from here and paste it on your IDE
2) you paste it, execute it, and it is okaaaay !

Just a fly in the dark of the space.
I drew 2 galaxies. And KCC asked me if the speed should be rightly accelerated. So I multiplied by 100 the initial.

Now all the physicians on the world want to kill me because the speed is wildly over the light speed, but... It was his wish to KCC...

You fly in the only with the mouse.

Left, right, front and back mouse direction to rotate.( z and x axis)
Left and right click to rotate (y axis)
Wheel up and down to speed.


Have a good fly !!
Thank you !

Code: Select all

;***************************************************************************************************************************************************************************************************************************************************
Global.D cg, ZZ = 1000.0, PowMount = 80.0, Radius, Teta, Anti, Teta2, Rho2, axCam, ayCam, azCam, vxCam, vyCam, vzCam
Global BackGC = 31
InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
ExamineDesktops()
OpenScreen(DesktopWidth(0), DesktopHeight(0), 32, "", #PB_Screen_SmartSynchronization, DesktopFrequency(0) )
CreateTexture(1, 1, 1, "")
If StartDrawing(TextureOutput(1) ) 
       Box(0, 0, 1, 1, RGB(255, 255, 255) )
       StopDrawing()
EndIf
CreateMaterial(0, TextureID(1) )
DisableMaterialLighting(0, #True)
For J = 1 To 2
       CreateMesh(J, #PB_Mesh_PointList, #PB_Mesh_Dynamic)
       SetMeshMaterial(J, MaterialID(0))              
       For i = 1 To 3 * (300000 - ((J - 1) * 295000) )
              Radius = 1.0 + Random(Random(10000) ) / 100.0
              Teta = Random(1) * #PI
              Teta2.D = Random(628) / 100.0
              Rho2.D = Random(1500) / 100.0
              MeshVertexPosition((Cos(Radius / 8.0 + Teta) * Radius + (Cos(Teta2) * Rho2))*ZZ, (Random(8000.0 / Sqr(Sqr(Radius) ) ) / 1000.0 * ((Random(1) * 2.0) - 1.0))*ZZ, (Sin(Radius / 8.0 + Teta) * Radius + (Sin(Teta2) * Rho2)) *ZZ)
              cg = BackGC + Pow(Random(100)/100, PowMount)*(255 - BackGC)
              MeshVertexColor(RGBA(cg,cg, cg, cg))
       Next i 
       FinishMesh(#False)
       CreateNode(J)
       AttachNodeObject(J, MeshID(J))
Next       
MoveNode(2, 100000, 1000000, 0, #PB_Absolute)
RotateNode(2, 0, 30, 0)
CreateCamera(0, 0, 0, 100, 100)
cams = CreateNode(#PB_Any)
AttachNodeObject(cams, CameraID(0))
CameraRange(0, 1, 1000000000)
MoveNode(cams, 0, 40, 150, #PB_Absolute)
CameraFOV(0, 90)
NodeLookAt(cams, NodeX(1),  NodeY(1),  NodeZ(1))
MoveNode(cams, 0.0, 0.0, -100)
Repeat
       ExamineKeyboard()
       ExamineMouse()
       vyCam + 0.01 * (Bool(MouseButton(1) ) - Bool(MouseButton(2) ) )
       vyCam * 0.99
       RotateNode(cams, 0.0, vyCam, 0.0, #PB_Relative)
       NodeFixedYawAxis(cams, #False)
       axCam = MouseDeltaY() / 100.0
       vxCam + axCam
       vxCam * 0.9
       RotateNode(cams, vxCam, 0.0,  0.0, #PB_Relative)                                     
       NodeFixedYawAxis(cams, #False)
       azCam = - MouseDeltaX() / 100.0
       vzCam + azCam
       vzCam * 0.9
       RotateNode(cams, 0.0,  0.0, vzCam, #PB_Relative)
       NodeFixedYawAxis(cams, #False)
       camz.D - MouseWheel() * 10.0
       MoveNode(cams, 0.0, 0.0, camz, #PB_Absolute | #PB_Local)                     
       RenderWorld()
       FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1 Or MouseButton(3)
and where is f... button to submit : it is behind the dialog box!!! (I must turn the smartphone to get it... Unable to use clipboard... 6 gigabytes of updating datas 2020... 2020 progress...)
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Galaxy Shape from points collection

Post by DK_PETER »

Nice example Olliv..
It is easy to substitute the images used. look at the materials and
create/download images to your liking with the same filenames.
Anyway: here's my galaxy with all images..
https://www.dropbox.com/s/hy7myie3x3f2c ... Y.rar?dl=0
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.
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 385
Joined: Thu Jul 09, 2015 9:07 am

Re: Galaxy Shape from points collection

Post by pf shadoko »

very impressive

I've made some modifications

PS: I didn't know that you could display a mesh without an entity.

Code: Select all

Global.D cg, ZZ = 1000.0, PowMount = 80.0, Radius, Teta, Anti, Teta2, Rho2
Global.d starnb,px,py,pz,dist,vit
Global BackGC = 31
InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
ExamineDesktops()
OpenScreen(DesktopWidth(0), DesktopHeight(0), 32, "", #PB_Screen_SmartSynchronization, DesktopFrequency(0) )
CreateTexture(1, 1, 1, "")
If StartDrawing(TextureOutput(1) )
    Box(0, 0, 1, 1, RGB(255, 255, 255) )
    StopDrawing()
EndIf
CreateMaterial(0, TextureID(1) )
DisableMaterialLighting(0, #True)
RandomSeed(0)
For J = 1 To 100
    If j>1
    px=Random(2000000)-1000000
    py=Random(2000000)-1000000
    pz=Random(2000000)-1000000
    dist=Sqr(px*px+py*py+pz*pz)
    EndIf
    CreateMesh(J, #PB_Mesh_PointList)
    SetMeshMaterial(J, MaterialID(0))  
    starnb=2000000000/(1000+dist)
    For i = 1 To starnb
        Radius = 1.0 + Random(10000) / 100.0
        Teta = Random(1) * #PI
        Teta2.D = Random(628) / 100.0
        Rho2.D = Random(1500) / 100.0
        MeshVertexPosition((Cos(Radius / 8.0 + Teta) * Radius + (Cos(Teta2) * Rho2))*ZZ, (Random(8000.0 / Sqr(Sqr(Radius) ) ) / 1000.0 * ((Random(1) * 2.0) - 1.0))*ZZ, (Sin(Radius / 8.0 + Teta) * Radius + (Sin(Teta2) * Rho2)) *ZZ)
        cg = BackGC + Pow(Random(100)/100, PowMount)*(255 - BackGC)
        MeshVertexColor(RGBA(cg,cg, cg, cg))
    Next i
    FinishMesh(1)
    CreateEntity(j,MeshID(j),#PB_Material_None)
    MoveEntity(j, px, py, pz, #PB_Absolute)
    RotateEntity(j, Random(360), Random(360), Random(360))
Next       
CreateCamera(0, 0, 0, 100, 100)
CameraRange(0, 1, 1000000000)
CameraFOV(0, 90)
CreateNode(0)
AttachNodeObject(0,CameraID(0))
vit=100
Repeat
    ExamineKeyboard()
    ExamineMouse()
    RotateNode(0,MouseDeltaY()*0.1,  0.5 * (Bool(MouseButton(2) ) - Bool(MouseButton(1) )), -MouseDeltaX()*0.1,#PB_Relative)
    vit+MouseWheel()*10
    MoveNode(0,0,0,-vit,#PB_Local)
    RenderWorld()
    FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1 Or MouseButton(3)
User avatar
Olliv
Enthusiast
Enthusiast
Posts: 542
Joined: Tue Sep 22, 2009 10:41 pm

Re: Galaxy Shape from points collection

Post by Olliv »

@Shadoku

I got your version and will test it... Many difficulties to link on line codes and lockdown IDE...
Post Reply