Round Big Points

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

Round Big Points

Post by applePi »

what makes big points round in opengl works also with big points in PB 3D Ogre engine, but when you compile with opengl option (compiler options -> Library subsystem: opengl)
this is for making big points round:

Code: Select all

glEnable_(#GL_POINT_SMOOTH);
glHint_(#GL_POINT_SMOOTH_HINT, #GL_NICEST);
glEnable_(#GL_BLEND);
glBlendFunc_(#GL_SRC_ALPHA, #GL_ONE_MINUS_SRC_ALPHA); 
to make big points in PB 3D engine we need an external material file with this line:
point_size 20 // as an example
your card may not display big round points, my card can't display more than size 100, some drivers can't display big round points.

save this file as points.material in the same folder as the code:

Code: Select all

material size_200
{
   receive_shadows off
   technique
   {
      pass
      {
         point_size 200
         lighting off
         diffuse vertexcolour
	 //scene_blend alpha_blend
	 
      }
   }
}

material size_100
{
   receive_shadows off
   technique
   {
      pass
      {
         point_size 100
         lighting off
         diffuse vertexcolour
	 //scene_blend alpha_blend
	 //colour_op alpha_blend
	 //colour alpha_blend
	 //colour_op_ex blend_current_alpha src_texture src_current
         //depth_write on
      }
   }
}
material size_50
{
   receive_shadows off
   technique
   {
      pass
      {
         point_size 50
         lighting off
         diffuse vertexcolour
      }
   }
}
material size_20
{
   receive_shadows off
   technique
   {
      pass
      {
         point_size 20
         lighting off
         diffuse vertexcolour

      }
   }
}
material size_10
{
   receive_shadows off
   technique
   {
      pass
      {
         point_size 10
         lighting off
	 diffuse vertexcolour
         //scene_blend alpha_blend
         //depth_write off
      }
   }
}

material size_5
{
   receive_shadows off
   technique
   {
      pass
      {
         point_size 5
         lighting off
         diffuse vertexcolour
	 
      }
   }
}
material size_2
{
   receive_shadows off
   technique
   {
      pass
      {
         point_size 2
         lighting off
         diffuse vertexcolour
      }
   }
}
here is 200000 points with size 10
uncomment line 60 : MaterialBlendingMode(0, #PB_Material_AlphaBlend)
and you may see as if the cube have interior, and the graphics now slower

Code: Select all

Procedure.f RandF(Min.f, Max.f, Resolution.i = 10000)
  ProcedureReturn (Min + (Max - Min) * Random(Resolution) / Resolution)
EndProcedure

Enumeration
   #MESH
   #LIGHT
   
 EndEnumeration
 
 Quit.b = #False
 #CameraSpeed = 1
 Define.f KeyX, KeyY, MouseX, MouseY
 Global flag, alpha

ExamineDesktops()
If OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), " Big Round Points.... use arrow keys and mouse to move the camera", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
;Initialize environment
  InitEngine3D()
  InitSprite()
OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0)


  InitKeyboard()
  InitMouse()


Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Models", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts",#PB_3DArchive_FileSystem)
  
  
Parse3DScripts()

CreateMaterial(3, LoadTexture(3, "snow_1024.jpg"))
CreateMaterial(4, LoadTexture(4, "Geebee2.bmp"))
CreatePlane(3, 200, 200, 5, 5, 5, 5)
CreateEntity(3,MeshID(3),MaterialID(3), 0, -50, 0)
    
    
    
CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(200,200,200))

CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 70, 200)
CameraLookAt(0, 0, -15, 0)


EndIf

CreateMesh(1, #PB_Mesh_PointList, #PB_Mesh_Dynamic )

GetScriptMaterial(0, "size_10")
SetMeshMaterial(1, MaterialID(0))
DisableMaterialLighting(0, #True)

;MaterialBlendingMode(0, #PB_Material_AlphaBlend)
;MaterialBlendingMode(0, #PB_Material_Color)

glEnable_(#GL_POINT_SMOOTH);
glHint_(#GL_POINT_SMOOTH_HINT, #GL_NICEST);
glEnable_(#GL_BLEND);
glBlendFunc_(#GL_SRC_ALPHA, #GL_ONE_MINUS_SRC_ALPHA);   

Global Stars = CreateNode(#PB_Any)
AttachNodeObject(Stars, MeshID(1))

alpha = 255

For i=1 To 200000
MeshVertexPosition(RandF(-50,50),RandF(-50,50), RandF(-50,50))
MeshVertexColor(RGBA(Random(255,10),Random(255,10),Random(255,10), alpha))
;MeshVertexColor(RGB(Random(255,10),Random(255,10),Random(255,10)))
Next
FinishMesh(#False)

flag = 1

Repeat
  Event = WindowEvent()
        
      If ExamineMouse()
        MouseX = -MouseDeltaX()/10 
        MouseY = -MouseDeltaY()/10
      EndIf
      
          
      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
    
   RotateNode(Stars, 0, 1/4, 0, #PB_Relative)
   
   RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera(0, KeyX, 0, KeyY)
            
      RenderWorld()
           
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
    
  
End
big round points size 100 with transparency:
also compile with opengl option

Code: Select all

Procedure.f RandF(Min.f, Max.f, Resolution.i = 10000)
  ProcedureReturn (Min + (Max - Min) * Random(Resolution) / Resolution)
EndProcedure

Enumeration
   #house
   #light
   
 EndEnumeration
 
 Quit.b = #False
 #CameraSpeed = 5
 
 Define.f KeyX, KeyY, MouseX, MouseY

ExamineDesktops()
If OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), " Big Round Points", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
;Initialize environment
  InitEngine3D()
  InitSprite()
OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0)


  InitKeyboard()
  InitMouse()
SetFrameRate(60)


Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Models", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts",#PB_3DArchive_FileSystem)
  
  
Parse3DScripts()

CreateMaterial(3, LoadTexture(3, "snow_1024.jpg"))
CreatePlane(3, 1500, 1500, 5, 5, 5, 5)
CreateEntity(3,MeshID(3),MaterialID(3), 0, -500, 0)
  
    
CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(200,200,200))

CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 4, 550)
CameraLookAt(0, 0, -200, 0)


EndIf

CreateMesh(1, #PB_Mesh_PointList, #PB_Mesh_Dynamic )

GetScriptMaterial(0, "size_100")
SetMeshMaterial(1, MaterialID(0))
DisableMaterialLighting(0, #True)
MaterialBlendingMode(0, #PB_Material_AlphaBlend)

glEnable_(#GL_POINT_SMOOTH);
glHint_(#GL_POINT_SMOOTH_HINT, #GL_NICEST);
glEnable_(#GL_BLEND);
glBlendFunc_(#GL_SRC_ALPHA, #GL_ONE_MINUS_SRC_ALPHA);   

Global Stars = CreateNode(#PB_Any)
AttachNodeObject(Stars, MeshID(1))
MoveNode(Stars, 0, -250,0)

For i=1 To 1000
MeshVertexPosition(RandF(-100,100),RandF(-100,100), RandF(-100,100))
MeshVertexColor(RGBA(Random(255,10),Random(255,10),Random(255,10), 100))
Next
FinishMesh(#False)



;Main loop
Repeat
  Event = WindowEvent()
        
      If ExamineMouse()
        MouseX = -MouseDeltaX()/10 
        MouseY = -MouseDeltaY()/10
      EndIf
      
          
      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
      
  
    
   RotateNode(Stars, 0, 1/4, 0, #PB_Relative)
   
   RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera(0, KeyX, 0, KeyY)
            
      RenderWorld()
           
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
    
  
End
more info : 3d point and line graphs in PB http://purebasic.fr/english/viewtopic.php?f=36&t=61455
Didaktik
User
User
Posts: 79
Joined: Fri Mar 14, 2014 2:12 pm

Re: Round Big Points

Post by Didaktik »

Wow! Thx! It useful for me.

applePi do not tell me how to attach a point to the corners of the 3D models, such as the cube and track the mouse cursor and the collision of these points that we could change the size of a mouse 3d model (cube)?
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Round Big Points

Post by applePi »

Hi Didaktik
it is possible to attach one point only to a cube corner since we can create entity from one point only then attaching it to cube corner with AttachEntityObject. but i have despaired from the behavior of big round points since it deceives the eyes ,
here is an example, just press Z to apply torque to the cube and the big points rotate with it, the cube have a vertical pivot (with HingeJoint)
save this material file as points.material

Code: Select all

material size_50
{
   receive_shadows off
   technique
   {
      pass
      {
         point_size 50
         point_size_attenuation on
	 //point_size_min 0
	 //point_size_max 0
         lighting off
         diffuse vertexcolour
      }
   }
}
save the code in the folder as the material file, and in the IDE choose compiler-> compiler options -> Library Subsystem = opengl

Code: Select all

Procedure.f RandF(Min.f, Max.f, Resolution.i = 10000)
  ProcedureReturn (Min + (Max - Min) * Random(Resolution) / Resolution)
EndProcedure


#plane = 500
#cube = 0
#camera = 0

Define.f KeyX, KeyY, MouseX, MouseY

ExamineDesktops()
OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), " Big Round Points, ....press 'Z' to give rotational torque to the cube", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
;Initialize environment
  InitEngine3D()
  InitSprite()
OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0)


  InitKeyboard()
  InitMouse()
SetFrameRate(60)


Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Models", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts",#PB_3DArchive_FileSystem)

Parse3DScripts()
    
    CreateMaterial(0, LoadTexture(0, "White.jpg"))
    DisableMaterialLighting(0, #True)
    MaterialShadingMode(0, #PB_Material_Wireframe     )
    MaterialCullingMode(0, #PB_Material_NoCulling)
            
    CreateCamera(#camera, 0, 0, 100, 100)
    MoveCamera(#camera, 0, 40, 100, #PB_Absolute)
    ;CameraFOV(#camera, 70)
 
    CameraLookAt(#camera,0,3,0)
        
    CreateLight(0,RGB(255,255,255),-100,40,30)
    AmbientColor(RGB(200,200,200))
    
    CreateMaterial(3, LoadTexture(3, "snow_1024.jpg"))
    DisableMaterialLighting(3, #False)
    SetMaterialColor(3, #PB_Material_AmbientColor, RGB(250, 255, 0))
    SetMaterialColor(3, #PB_Material_SpecularColor, RGB(255, 255, 0))
    
    CreateMaterial(1, LoadTexture(1, "MRAMOR6X6.jpg"))
    MaterialCullingMode(1, #PB_Material_NoCulling)

    CreateMaterial(2, LoadTexture(2, "RustySteel.jpg"))
    MaterialCullingMode(2, #PB_Material_NoCulling)
    
    CreateMaterial(4, LoadTexture(4, "ground_diffuse.png"))
    MaterialCullingMode(4, #PB_Material_NoCulling)
        
    CreatePlane(#plane, 200, 200, 5, 5, 2, 2) ; the ground
    CreateEntity(#plane, MeshID(#plane), MaterialID(4), 0,-25,0)
    CreateEntityBody(#plane, #PB_Entity_StaticBody, 1, 0.1, 1)
    
    CreateCube(#cube,1)
    CreateEntity(#cube, MeshID(#cube), MaterialID(1), 0, 0, 0) ; the static cube
    ScaleEntity(#cube, 16,16,16)
            
    CreateEntityBody(#cube, #PB_Entity_BoxBody, 1, 0.1,2)
    
    CreateMesh(1, #PB_Mesh_PointList, #PB_Mesh_Dynamic )

GetScriptMaterial(0, "size_50")
SetMeshMaterial(1, MaterialID(0))
DisableMaterialLighting(0, #True)
MaterialBlendingMode(0, #PB_Material_AlphaBlend)

glEnable_(#GL_POINT_SMOOTH);
glHint_(#GL_POINT_SMOOTH_HINT, #GL_NICEST);
glEnable_(#GL_BLEND);
glBlendFunc_(#GL_SRC_ALPHA, #GL_ONE_MINUS_SRC_ALPHA);   

MeshVertexPosition(0, 0, 0)
MeshVertexColor(RGBA(255,0,0, 100))
FinishMesh(#True)
CreateEntity(1, MeshID(1), #PB_Material_None , 1,1,1)
AttachEntityObject(#cube,"", EntityID(1))
CopyEntity(1,2)
MoveEntity(2, 1,1,-1)
AttachEntityObject(#cube,"", EntityID(2))

CopyEntity(1,3)
MoveEntity(3, -1,1,-1)
AttachEntityObject(#cube,"", EntityID(3))

CopyEntity(1,4)
MoveEntity(4, -1,1,1)
AttachEntityObject(#cube,"", EntityID(4))
;CreateEntityBody(1, #PB_Entity_SphereBody , 1,0.4,1)


HingeJoint(0, EntityID(#cube),
               0, 8, 0,
               0, 1, 0, 
               EntityID(#plane),
               0, 16, 0, 
               0, 1, 0)

    
  
    Repeat
      Event = WindowEvent()
        
      If ExamineMouse()
        MouseX = -MouseDeltaX()/20 
        MouseY = -MouseDeltaY()/20
      EndIf
      
          
      If ExamineKeyboard()
         
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -1
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = 1
        Else
          KeyX = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -1
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = 1
        Else
          KeyY = 0
        EndIf
        
        If KeyboardReleased(#PB_Key_Space)
          stone = CreateCube(#PB_Any , 0.5)
          stone = CreateEntity(#PB_Any, MeshID(stone),MaterialID(2))
          ScaleEntity(stone,4,2,4)
          MoveEntity(stone, -5,8, 0)
          CreateEntityBody(stone,#PB_Entity_BoxBody,500)
      
        EndIf
        
        If KeyboardPushed(#PB_Key_Z)
          
          ApplyEntityTorque(#cube, 0, 40, 0)

        EndIf
        
  
       EndIf
       
        
      RotateCamera(#Camera, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera(#Camera, KeyX, 0, KeyY)
      
             
      StopDrawing()
      
      RenderWorld()
  
      FlipBuffers()
      
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
  
End


try to move away or closer and the points stay the same, there is in ogre forum http://www.ogre3d.org/docs/manual/manual_16.html a talk about :
point_size_attenuation
point_size_min
point_size_max
but it does not work, if Samuel read this post he may have an opinion. it is possible my graphics card does not support these features.

about giving the point physics property. it works such as the point will fall to the ground but it will penetrate the ground. 2,3 or more will work (needs more testing about this) also you can't use #PB_Entity_ConvexHullBody with the CreateEntityBody() others will work like the following example,
how to attach a point to the corners of the 3D models, such as the cube and track the mouse cursor and the collision of these points that we could change the size of a mouse 3d model (cube)?
i think i know what you want, changing the size is possible with scale entity, but dragging the mouse pointer over the point to scale the cube, i can't remember now the mouse functions , yes there is an example but can't fetch it.

compile with opengl option. not optimized for distances, i cut the code from other example

Code: Select all

Procedure.f RandF(Min.f, Max.f, Resolution.i = 10000)
  ProcedureReturn (Min + (Max - Min) * Random(Resolution) / Resolution)
EndProcedure

Enumeration
   #house
   #light
   
 EndEnumeration
 
 Quit.b = #False
 #CameraSpeed = 5
 
 Define.f KeyX, KeyY, MouseX, MouseY

ExamineDesktops()
If OpenWindow(0, 0, 0, DesktopWidth(0), DesktopHeight(0), " Big Round Points", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  
;Initialize environment
  InitEngine3D()
  InitSprite()
OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0), 0, 0, 0)


  InitKeyboard()
  InitMouse()
SetFrameRate(60)


Add3DArchive(".", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Models", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "Examples/3D/Data/Scripts",#PB_3DArchive_FileSystem)
  
  
Parse3DScripts()

CreateMaterial(3, LoadTexture(3, "snow_1024.jpg"))
CreateMaterial(1, LoadTexture(1, "White.jpg"))
CreatePlane(3, 1500, 1500, 5, 5, 5, 5)
CreateEntity(3,MeshID(3),MaterialID(3), 0, -500, 0)
CreateEntityBody(3, #PB_Entity_StaticBody , 1,1,1)
  
    
CreateLight(0,RGB(255,255,255),-100,40,30)
AmbientColor(RGB(200,200,200))

CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 4, 550)
CameraLookAt(0, 0, -230, 0)


EndIf

CreateMesh(1, #PB_Mesh_PointList, #PB_Mesh_Dynamic )

GetScriptMaterial(0, "size_100")
SetMeshMaterial(1, MaterialID(0))
DisableMaterialLighting(0, #True)
MaterialBlendingMode(0, #PB_Material_AlphaBlend)

glEnable_(#GL_POINT_SMOOTH);
glHint_(#GL_POINT_SMOOTH_HINT, #GL_NICEST);
glEnable_(#GL_BLEND);
glBlendFunc_(#GL_SRC_ALPHA, #GL_ONE_MINUS_SRC_ALPHA);   

For i=1 To 30
MeshVertexPosition(RandF(-100,100),RandF(-100,100), RandF(-100,100))
MeshVertexColor(RGBA(Random(255,10),Random(255,10),Random(255,10), 100))
Next
FinishMesh(#True)
CreateEntity(1, MeshID(1), #PB_Material_None , 0,-250,0)
CreateEntityBody(1, #PB_Entity_SphereBody , 1,0.6,1)

WorldGravity(-50)


;Main loop
Repeat
  Event = WindowEvent()
        
      If ExamineMouse()
        MouseX = -MouseDeltaX()/10 
        MouseY = -MouseDeltaY()/10
      EndIf
      
          
      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
      
  
   
   RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera(0, KeyX, 0, KeyY)
            
      RenderWorld()
           
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
    
  
    End
    
Post Reply