Tube test - stargate
Posted: Mon Oct 26, 2015 10:53 pm
Folder name: texture
filename: 0.png
filename: 3.bmp 
filename: 4.bmp
filename: ancient.jpg 
filename: concrete.jpg
filename: ramp.jpg 
filename: sg_alloy.jpg
filename: symbols.jpg 
filename: water.jpg
filename: water3.jpg 
Foldername: scripts
filename: stargate.material
Code:
filename: 0.png
filename: 3.bmp 
filename: 4.bmp
filename: ancient.jpg 
filename: concrete.jpg
filename: ramp.jpg 
filename: sg_alloy.jpg
filename: symbols.jpg 
filename: water.jpg
filename: water3.jpg 
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: 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
