Tube test - stargate

Everything related to 3D programming
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Tube test - stargate

Post by DK_PETER »

Folder name: texture
filename: 0.png Image filename: 3.bmp Image
filename: 4.bmp Image filename: ancient.jpg Image
filename: concrete.jpg Image filename: ramp.jpg Image
filename: sg_alloy.jpg Image filename: symbols.jpg Image
filename: water.jpg Image filename: water3.jpg Image

Foldername: scripts
filename: stargate.material

Code: Select all

//Simple water/horizon by DK_PETER
material Horizon3
{
    technique
    {
         pass
        {
            lighting on
 
            ambient 0 0 1 1
            diffuse 0 0 1 1
            specular 0 0 1 1
            emissive 0 0 1 1

            texture_unit
            {
                texture water.jpg
                colour_op add
		scale 1 1
		scroll_anim 0.01 0.01
		wave_xform scale sine 0.9 0.1 0.5 0.4
		env_map cubic_reflection
            }

            texture_unit
            {
                texture 3.bmp
		scale 0.1 0.1
                colour_op add
		scroll_anim -0.01 0.02
                wave_xform scale_x sine 0.9 0.4 0.1 0.4
                env_map Sperical
            }

            texture_unit
            {
                texture 4.bmp
		scale 0.1 0.1
                colour_op add
		wave_xform scale sine 0.9 0.1 0.1 0.1
                scroll_anim 0.02 0.1
                env_map Sperical
            }

        }
    }
}
Code:

Code: Select all

;Stargate fonts are available at : http://www.thescifiworld.net/fonts.htm
;Simple simulation of a Stargate... (Pure CreateTube() testing).
;By DK_PETER
;Arrows to move camera  '+' and '-' to rotate symbols
DeclareModule _Pri
  Declare.i CreateTube(meshID, outerRadius.f, innerRadius.f, height.f, numSegBase=16, numSegHeight=1)
EndDeclareModule

Module _Pri
  
  Structure Vector3
    x.f
    y.f
    z.f
  EndStructure
  
  Macro SubVector3(n, v, w)
    n\x = v\x - w\x
    n\y = v\y - w\y
    n\z = v\z - w\z
  EndMacro
  
  Procedure Normalize(*V.Vector3)
    Define.f magSq, oneOverMag
    
    magSq = *V\x * *V\x + *V\y * *V\y + *V\z * *V\z
    If magsq > 0
      oneOverMag = 1.0 / Sqr(magSq)
      *V\x * oneOverMag
      *V\y * oneOverMag
      *V\z * oneOverMag
    EndIf
    
  EndProcedure
  
  Procedure.i CreateTube(meshID, outerRadius.f, innerRadius.f, height.f, numSegBase=16, numSegHeight=1)
    Protected  Normal.Vector3, returnMesh.i
    
    If meshID = #PB_Any
      returnMesh = CreateMesh(#PB_Any)
    Else
      returnMesh = meshID
      CreateMesh(returnMesh)
    EndIf
    
    If numSegBase < 1
      numSegBase = 1
    EndIf
    
    If numSegHeight < 1
      numSegHeight = 1
    EndIf
    
    deltaAngle.f = #PI*2 / numSegBase
    deltaHeight.f = height / numSegHeight
    height2.f = height / 2.0
    offset = 0
    
    For i = 0 To numSegHeight
      For j = 0 To numSegBase
        
        x0.f = outerRadius * Cos(j*deltaAngle)
        z0.f = outerRadius * Sin(j*deltaAngle)
        
        Normal\x = x0
        Normal\y = 0
        Normal\z = z0
        Normalize(@Normal)
        
        MeshVertexPosition(x0, i*deltaHeight-height2, z0)
        MeshVertexNormal(Normal\x, Normal\y, Normal\z)
        MeshVertexTextureCoordinate(j / numSegBase, i / numSegHeight)
        
        If  i <> numSegHeight
          
          MeshIndex(offset + numSegBase + 1)
          MeshIndex(offset)
          MeshIndex(offset + numSegBase)
          MeshIndex(offset + numSegBase + 1)
          MeshIndex(offset + 1)
          MeshIndex(offset)
        EndIf
        offset + 1
      Next
    Next   
    
    For i = 0 To numSegHeight
      For j = 0 To numSegBase
        
        x0.f = innerRadius * Cos(j*deltaAngle)
        z0.f = innerRadius * Sin(j*deltaAngle)
        
        Normal\x = x0
        Normal\y = 0
        Normal\z = z0
        Normalize(@Normal)
        
        MeshVertexPosition(x0, i*deltaHeight-height2, z0)
        MeshVertexNormal(Normal\x, Normal\y, Normal\z)
        MeshVertexTextureCoordinate(j / numSegBase, i / numSegHeight)
        
        If  i <> numSegHeight
          
          MeshIndex(offset + numSegBase + 1)
          MeshIndex(offset + numSegBase)
          MeshIndex(offset)
          MeshIndex(offset + numSegBase + 1)
          MeshIndex(offset)
          MeshIndex(offset + 1)
        EndIf
        offset + 1
      Next
    Next   
    
    ;low cap
    For j = 0 To numSegBase
      
      x0.f = innerRadius * Cos(j * deltaAngle)
      z0.f = innerRadius * Sin(j * deltaAngle)
      MeshVertexPosition(x0, -height2, z0)
      MeshVertexNormal(0, -1, 0)
      MeshVertexTextureCoordinate(j / numSegBase, 1)
      
      x0 = outerRadius * Cos(j * deltaAngle)
      z0 = outerRadius * Sin(j * deltaAngle)
      MeshVertexPosition(x0, -height2, z0)
      MeshVertexNormal(0, -1, 0)
      MeshVertexTextureCoordinate(j / numSegBase, 0)
      
      If j <> numSegBase
        
        MeshIndex(offset)
        MeshIndex(offset + 1)
        MeshIndex(offset + 3)
        MeshIndex(offset + 2)
        MeshIndex(offset)
        MeshIndex(offset + 3)
      EndIf
      offset + 2
    Next
    
    ;high cap
    For j = 0 To numSegBase
      
      x0.f = innerRadius * Cos(j * deltaAngle)
      z0.f = innerRadius * Sin(j * deltaAngle)
      MeshVertexPosition(x0, height2, z0)
      MeshVertexNormal(0, 1, 0)
      MeshVertexTextureCoordinate(j / numSegBase, 0)
      
      x0 = outerRadius * Cos(j * deltaAngle)
      z0 = outerRadius * Sin(j * deltaAngle)
      MeshVertexPosition(x0, height2, z0)
      MeshVertexNormal(0, 1, 0)
      MeshVertexTextureCoordinate(j / numSegBase, 1)
      
      If j <> numSegBase
        
        MeshIndex(offset + 1)
        MeshIndex(offset)
        MeshIndex(offset + 3)
        MeshIndex(offset)
        MeshIndex(offset + 2)
        MeshIndex(offset + 3)
      EndIf
      offset + 2
    Next
    
    FinishMesh(#True)
    ProcedureReturn returnMesh
  EndProcedure   
  
EndModule

UseJPEGImageDecoder()

InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()

Structure walking
  x.f
  y.f
  z.f
  mx.f
  my.f
EndStructure

Structure _Mesh
  id.i
  ms.i
  ma.i
  tx.i
  set.i
EndStructure

Structure ExtraMat
  tx.i
  ma.i
EndStructure

Structure _Room
  nWall._Mesh
  eWall._Mesh
  sWall._Mesh
  wWall._Mesh
  floor._Mesh
  Ceil._Mesh
EndStructure

Structure _Gate
  Outer._Mesh
  Inner._Mesh
  Hole._Mesh
  ramp._Mesh
  stand._Mesh
  Room._Room
  shevron._Mesh[4]
EndStructure

Global sg._Gate, node.i, wk.walking, BaseTex.i,  Chev.ExtraMat, Quit.i = #False

OpenWindow(0, 0, 0, 1024, 768, "StarGate tube test", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, 1024, 768)

Add3DArchive("texture", #PB_3DArchive_FileSystem)
Add3DArchive("scripts", #PB_3DArchive_FileSystem)
Parse3DScripts()

CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, -1, 70)

BaseTex = LoadImage(#PB_Any, GetPathPart(ProgramFilename()) + "texture/concrete.jpg")

With sg\Hole
  \ms = CreateSphere(#PB_Any, 10, 80, 18)
  TransformMesh(\ms, 0, 0, 0, 1, 1, 0.02, 0, 0, 0)
  UpdateMeshBoundingBox(\ms)
  \ma = GetScriptMaterial(#PB_Any, "Horizon3")
  MaterialCullingMode(\ma, #PB_Material_NoCulling)
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma))
  RotateEntity( \id, -180, 0, 90)
EndWith
With sg\Inner
  \ms = _Pri::CreateTube(#PB_Any, 12.5, 10, 0.1, 70, 1)
  \tx = LoadTexture(#PB_Any, "symbols.jpg")
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  ScaleMaterial(\ma, 0.4, 0.9)
  ScrollMaterial(\ma, 0, 0, #PB_Absolute)
  DisableMaterialLighting(\ma, #True)
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma))
  RotateEntity(\id, -90, 0, 90)
EndWith
With sg\Outer
  \ms = _Pri::CreateTube(#PB_Any, 13.5, 12.52, 0.2, 70, 1)
  \tx = LoadTexture(#PB_Any, "ancient.jpg")
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  ScaleMaterial(\ma, 0.2, 0.8)
  ScrollMaterial(\ma, 0, -0.02, #PB_Absolute)
  DisableMaterialLighting(\ma, #True)
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma))
  RotateEntity(\id, -90, 0, 90)
EndWith
With sg\ramp
  \ms = CreatePlane(#PB_Any, 15, 40, 1, 1, 9, 12)
  \tx = LoadTexture(#PB_Any, "ramp.jpg")
  \ma = CreateMaterial(#PB_Any,  TextureID(\tx))
  DisableMaterialLighting(\ma, #True)
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, -13.5, 20)
  RotateEntity(\id, 10, 0, 0, #PB_Absolute)
EndWith
With sg\stand
  \ms = CreateCube(#PB_Any, 10)
  \tx = LoadTexture(#PB_Any, "ramp.jpg")
  \ma = CreateMaterial(#PB_Any,  TextureID(\tx))
  ScaleMaterial(\ma, 0.4,0.4)
  MaterialBlendingMode(\ma, #PB_Material_NoCulling)
  DisableMaterialLighting(\ma, #True)
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, -14, -0.5)
  ScaleEntity(\id, 3, 0.05, 0.6)
EndWith
With sg\shevron[0]
  \ms = CreateCylinder( #PB_Any, 1, 1, 3, 2, 1)
  \tx = LoadTexture(#PB_Any, "sg_alloy.jpg")
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), -13, 0, 0)
  RotateEntity(\id, 90, 0, 0)
EndWith
With sg\shevron[1]
  \ms = CreateCylinder( #PB_Any, 1, 1, 3, 2, 1)
  \tx = LoadTexture(#PB_Any, "sg_alloy.jpg")
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 13, 0, 0)
  RotateEntity(\id, 90, 0, 180)
EndWith
With sg\shevron[2]
  \ms = CreateCylinder( #PB_Any, 1, 1, 3, 2, 1)
  \tx = LoadTexture(#PB_Any, "sg_alloy.jpg")
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 13, 0)
  RotateEntity(\id, 90, 0, -90)
EndWith
With sg\shevron[3]
  \ms = CreateCylinder( #PB_Any, 1, 1, 3, 2, 1)
  \tx = LoadTexture(#PB_Any, "sg_alloy.jpg")
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, -13, 0)
  RotateEntity(\id, 90, 0, 90)
EndWith
With sg\Room\eWall
  \ms = CreatePlane(#PB_Any, 90, 300, 10, 10, 1, 1)
  \tx = CreateTexture(#PB_Any, 1024, 1024)
  StartDrawing(TextureOutput(\tx))
  DrawImage(ImageID(BaseTex),0, 0)
  StopDrawing()
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  MaterialCullingMode(\ma, #PB_Material_NoCulling)
  ScaleMaterial(\ma, 0.1, 0.1)
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), -150, 25, 0)
  RotateEntity(\id, 0, 0, -90)
EndWith
With sg\Room\nWall
  \ms = CreatePlane(#PB_Any, 90, 300, 10, 10, 1, 1)
  \tx = CreateTexture(#PB_Any, 1024, 1024)
  StartDrawing(TextureOutput(\tx))
  DrawImage(ImageID(BaseTex),0, 0)
  StopDrawing()
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  MaterialCullingMode(\ma, #PB_Material_NoCulling)
  ScaleMaterial(\ma, 0.1, 0.1)
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 25, -150)
  RotateEntity(\id, 90, 0, 90)
EndWith
With sg\Room\wWall
  \ms = CreatePlane(#PB_Any, 90, 300, 10, 10, 1, 1)
  \tx = CreateTexture(#PB_Any, 1024, 1024)
  StartDrawing(TextureOutput(\tx))
  DrawImage(ImageID(BaseTex),0, 0)
  StopDrawing()
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  MaterialCullingMode(\ma, #PB_Material_NoCulling)
  ScaleMaterial(\ma, 0.1, 0.1)
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 150, 25, 0)
  RotateEntity(\id, 0, 0, 90)
EndWith
With sg\Room\sWall
  \ms = CreatePlane(#PB_Any, 90, 300, 10, 10, 1, 1)
  \tx = CreateTexture(#PB_Any, 1024, 1024)
  StartDrawing(TextureOutput(\tx))
  DrawImage(ImageID(BaseTex),0, 0)
  StopDrawing()
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  MaterialCullingMode(\ma, #PB_Material_NoCulling)
  ScaleMaterial(\ma, 0.1, 0.1)
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 25, 150)
  RotateEntity(\id, -90, 0, 90)
EndWith
With sg\Room\floor
  \ms = CreatePlane(#PB_Any, 300, 300, 10, 10, 1, 1)
  \tx = CreateTexture(#PB_Any, 1024, 1024)
  StartDrawing(TextureOutput(\tx))
  Box(0, 0, 1024, 1024, $8F918B)
  StopDrawing()
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  MaterialCullingMode(\ma, #PB_Material_NoCulling)
  ScaleMaterial(\ma, 0.1, 0.1)
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, -20, 0)
EndWith
With sg\Room\Ceil
  \ms = CreatePlane(#PB_Any, 300, 300, 10, 10, 1, 1)
  \tx = CreateTexture(#PB_Any, 1024, 1024)
  StartDrawing(TextureOutput(\tx))
  Box(0, 0, 1024, 1024, $D9DEDA)
  StopDrawing()
  \ma = CreateMaterial(#PB_Any, TextureID(\tx))
  MaterialCullingMode(\ma, #PB_Material_NoCulling)
  \id = CreateEntity(#PB_Any, MeshID(\ms), MaterialID(\ma), 0, 70, 0)
  RotateEntity(\id, 180, 0, 0)
EndWith

Repeat
  
  Repeat
    ev = WindowEvent()
    If ev = #PB_Event_CloseWindow : Quit = #True : EndIf
  Until ev = 0
  
  ExamineMouse()
  
  wk\mx = MouseDeltaX() * 0.1
  wk\my = MouseDeltaY() * 0.1
  
  ExamineKeyboard()
  
  
  If KeyboardPushed(#PB_Key_Left)
    wk\x = -0.4
  ElseIf KeyboardPushed(#PB_Key_Right)
    wk\x = 0.4
  Else
    wk\x = 0
  EndIf
  
  If KeyboardPushed(#PB_Key_Up)
    wk\y = -0.4
  ElseIf KeyboardPushed(#PB_Key_Down)
    wk\y = 0.4
  Else
    wk\y = 0
  EndIf
  
  If KeyboardPushed(#PB_Key_Add)
    RotateEntity(sg\Inner\id, 0, 0.2, 0, #PB_Relative)
  ElseIf KeyboardPushed(#PB_Key_Subtract)
    RotateEntity(sg\Inner\id, 0, -0.2, 0, #PB_Relative)
  EndIf
  
  RotateCamera(0, wk\my, -wk\mx, 0, #PB_Relative)
  MoveCamera(0, wk\x, 0, wk\y) 
  
  RenderWorld()
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = #True
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: Tube test - stargate

Post by applePi »

very good star Gate, you are the materials wizard, i prefer to make the sphere z=0.2.
there is a problem with:
BaseTex = LoadImage(#PB_Any, GetPathPart(ProgramFilename()) + "texture/concrete.jpg")
the GetPathPart(ProgramFilename()) return the "C:\Documents and Settings\applepi\Local Settings\Temp" and not the folder of the code, so i have used instead "BaseTex = LoadImage(#PB_Any, "texture\concrete.jpg")". i will check it more later since now i have too much back muscles pain.
also the 3.bmp, 4.bmp: the images server store it as jpg so the user needs to convert it to bmp via irfanview
but the example are very good. thanks
here is the picture, if there is something missing tell me.
Image

EDIT: regarding the problem of GetPathPart(ProgramFilename()) it is discussed and solved here: http://purebasic.fr/english/viewtopic.php?f=13&t=63576
Last edited by applePi on Wed Oct 28, 2015 2:04 pm, edited 1 time in total.
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: Tube test - stargate

Post by DK_PETER »

@applePi

The image looks fine. Hope you'll get over the back pain soon.

Here are three other water scripts. Add it to the existing 'stargate.material' file.

Code: Select all

material water1
{
	technique
	{
		pass
		{
			scene_blend add
			depth_write off

			texture_unit
			{
				texture Water3.jpg
				scroll_anim 0.5 0.01
			}

			texture_unit
			{
				texture Water3.jpg
				rotate_anim -0.3
			}
			texture_unit
			{
				texture Water3.jpg
				scroll_anim 0.1 -0.3
				env_map spherical
			}
		}
	}
}
material water2
{
	technique
	{
		pass
		{
			scene_blend add
			depth_write off

			texture_unit
			{
				texture Water.jpg
				scroll_anim 0.01 0.01
				rotate_anim 0.03
				//env_map spherical
			}
			texture_unit
			{
				texture 4.bmp
				scroll_anim 0.01 0.01
				rotate_anim 0.03
				colour_op_ex modulate src_manual src_current 0.4 
				env_map spherical
			}
		}
	}
}
material water3
{
	technique
	{
		pass
		{
			scene_blend add
			depth_write off

			texture_unit
			{
				texture water.jpg
                                wave_xform scale_x sine 0.5 0.2 0.0 0.1
				env_map planar
			}

			texture_unit
			{
				texture 3.bmp
				colour_op add
				scroll_anim 0.04 0.01
			}
		}
	}
}
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.
ElementE
Enthusiast
Enthusiast
Posts: 139
Joined: Sun Feb 22, 2015 2:33 am

Re: Tube test - stargate

Post by ElementE »

I am having a problem downloading two of the texture image files.

The files:
3.bmp
4.bmp
do not have links that lead to the images.
Think Unicode!
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Tube test - stargate

Post by applePi »

@ElementE: just right click on the small picture and save as (either 3.jpg or 3.png depends on the browser) then open it in paint or irfanview and save it again as 3.bmp, 4.bmp.
@DK_PETER: thanks for the additional materials, the material water3 are impressive, it reminds me of that empty glass sphere which have sparks and lightning inside due to high voltage.
Post Reply