Page 1 of 2

Deep Space Explorer - Tranquility (Flyby and follow)

Posted: Wed Mar 02, 2016 10:06 pm
by DK_PETER
Engine humming sound...
https://www.dropbox.com/s/xre5veks7e4qa ... 2.zip?dl=0

Create a folder called sound and place the rock2.wav (or any other humming sound) inside it.
Save the code below in parent to 'sound' folder.
If it won't run - try setting OpenGL as subsystem.

Code has been fixed and works perfectly on x86 too.
Thank you applePi. :wink:
I completely forgot about the cone parameter problem. :oops:

Code: Select all

;Deep Space Explorer - Tranquility (Flyby and follow)
;Create a folder called sound and
;Add an engine humming sound and load it. (rock2.wav)
;Have fun with this sloppy code :-)
InitEngine3D()
InitSprite()
InitKeyboard()
InitSound()

Structure Vector3
  x.f
  y.f
  z.f
EndStructure

Structure _par
  id.i
  tx.i
  ma.i
EndStructure 

Structure _mes
  id.i
  ms.i
  tx.i
  ma.i
EndStructure

Structure _object
  block._mes
  box._mes
  connect._mes[7]
  eng._mes[2]
  sections._mes[3]  
  par._par[3]
  main.i
  rot.i[2]
  snod.i
EndStructure


Declare.i CreateShip()
Declare.i ReturnHabitatTexture(Win.i = #True)
Declare.i ReturnConnectionTexture()
Declare.i FakeSkyTexture()
Declare   Normalize(*V.Vector3)
Declare   CreateTube(meshID.i, outerRadius.f, innerRadius.f, height.f, numSegBase.i=16, numSegHeight.i=1)
Declare.i ReturnFlareTexture(Color = $FF00FFF3)

Global shp._object, sn.i, ret.i

OpenWindow(0, 0, 0, 1024, 768, "Deep Space Explorer - Tranquility (DK_PETER)", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(0), 0, 0, 1024, 768)
Add3DArchive("sound", #PB_3DArchive_FileSystem)
CreateCamera(0, 0, 0, 100, 100)
CameraRange(0, 0, 505)
CameraFOV(0, 46)

;Home made Skybox
shp\box\ms = CreateCube(#PB_Any, 250)
shp\box\tx = FakeSkyTexture()
shp\box\ma = CreateMaterial(#PB_Any, TextureID(shp\box\tx))
MaterialCullingMode(shp\box\ma, #PB_Material_NoCulling)
shp\box\id = CreateEntity(#PB_Any, MeshID(shp\box\ms), MaterialID(shp\box\ma), 0, 0, 0)
Debug "Skybox created... MaterialID: " + Str(MaterialID(shp\box\ma))

ret = CreateShip()

;Check if there is sound and attach it...
sn = LoadSound3D(#PB_Any, "rock2.wav")
If IsSound3D(sn)
  Debug "3D sound loaded - SoundID" + Str(SoundID3D(sn))
  SoundVolume3D(sn, 100)
  SoundRange3D(sn, 0, 1)
  PlaySound3D(sn)
  AttachNodeObject(shp\snod, SoundID3D(sn))  
  AttachNodeObject(shp\main, NodeID(shp\snod))
  Debug "3D sound attached.."
Else
  Debug "no sound"
EndIf
RotateNode(shp\main, 0, -90, 0)
MoveNode(shp\main, 0.2, 0.3, 3)

Repeat
  
  Repeat
    ev = WindowEvent()
    If ev = #PB_Event_CloseWindow:Quit = 1:EndIf
  Until  ev = 0
  RotateNode(shp\rot[0], 0.1, 0, 0,#PB_Relative)
  RotateNode(shp\rot[1], 0.1, 0, 0,#PB_Relative)
  MoveNode(shp\main, 0, 0, -0.002, #PB_Relative) 
  SoundListenerLocate(NodeX(shp\snod), NodeY(shp\snod), NodeZ(shp\snod))
  RenderWorld()
  ExamineKeyboard()
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)

Procedure.i ReturnHabitatTexture(Win.i = #True)
  Protected im.i, tx.i, x.i, y.i, ma
  im = CreateImage(#PB_Any, 2048, 2048)
  StartDrawing(ImageOutput(im))
  DrawingMode(#PB_2DDrawing_AlphaBlend)
  Box(0,0,2048,2048, $FF111111)
  For x = 0 To 2048 Step 30
    For y = 0 To 2048 Step 50
      Box(x, y, 15, 5, RGBA(255, 255, 255, Random(255,20)))
    Next y
  Next x
  If Win = #True : Box(1024, 1010, 1024, 30, $FFEB4A00) : EndIf
  StopDrawing()
  ResizeImage(im, 1024, 1024)
  tx = CreateTexture(#PB_Any, 1024, 1024)
  StartDrawing(TextureOutput(tx))
  DrawImage(ImageID(im), 0, 0)
  StopDrawing()
  FreeImage(im)
  Debug "ReturnHabitatTexture() : TextureID: " + Str(TextureID(tx))
  ProcedureReturn tx
EndProcedure

Procedure.i ReturnConnectionTexture()
  Protected im.i, ma.i, tx.i, x.i, y.i, w.i, h.i, c.i, co.i
  im = CreateImage(#PB_Any, 2048, 2048)
  StartDrawing(ImageOutput(im))
  For c = 0 To 200
    x = -50 + Random(2300,0) : y = -50 + Random(2300,0)
    w = Random(200, 10) : h = Random(200, 10)
    DrawingMode(#PB_2DDrawing_AlphaBlend|#PB_2DDrawing_Gradient)
    co = Random(200, 100)
    FrontColor(RGBA(co, co, co, Random(255,210)))
    BackColor(RGBA(co, co, co, 50))
    LinearGradient(x, y, w, h)
    Box(x, y, w, h)
    DrawingMode(#PB_2DDrawing_AlphaBlend|#PB_2DDrawing_Outlined)
    Box(x, y, w, h, RGBA(20, 20, 20, Random(255,70)))    
  Next c
  Box(1024, 1010, 256, 30, $FFEB4A00)
  StopDrawing()
  ResizeImage(im, 1024, 1024)
  tx = CreateTexture(#PB_Any, 1024, 1024)
  StartDrawing(TextureOutput(tx))
  DrawImage(ImageID(im), 0, 0)
  StopDrawing()
  FreeImage(im)
  Debug "ReturnConnectionTexture() : TextureID: " + Str(TextureID(tx))
  ProcedureReturn tx
EndProcedure

Procedure.i FakeSkyTexture()
  Protected im.i, ma.i, tx.i, x.i, y.i, w.i, h.i, c.i, co.i
  im = CreateImage(#PB_Any, 1024, 1024)
  StartDrawing(ImageOutput(im))
  For c = 0 To 20000
    x = Random(1024,0) : y = Random(1024,0)
    w = Random(200, 10) : h = Random(200, 10)
    DrawingMode(#PB_2DDrawing_AlphaBlend)
    co = Random(200, 100)
    Plot(Random(1023,1), Random(1023,1), RGBA(co, co, co, Random(255,10)))
  Next c
  Box(1024, 1010, 256, 30, $FFEB4A00)
  StopDrawing()
  ResizeImage(im, 1024, 1024)
  tx = CreateTexture(#PB_Any, 1024, 1024)
  StartDrawing(TextureOutput(tx))
  DrawImage(ImageID(im), 0, 0)
  StopDrawing()
  FreeImage(im)
  Debug "FakeSkyTexture() : TextureID: " + Str(TextureID(tx))
  ProcedureReturn tx
EndProcedure

Procedure.i ReturnFlareTexture(Color = $FF00FFF3)
  Protected enmat.i, entex.i
  Entex = CreateTexture(#PB_Any, 20, 20)
  StartDrawing(TextureOutput(entex))
  DrawingMode(#PB_2DDrawing_Gradient)
  FrontColor(Color)
  BackColor($FFFFFFFF)
  CircularGradient(10, 10, 7)
  Circle(10, 10, 8)
  StopDrawing()
  Debug "ReturnFlareTexture() : TextureID: " + Str(TextureID(entex))
  ProcedureReturn entex
EndProcedure

Procedure.i CreateShip()
  Protected before.s, After.s
  before = Str((MemoryStatus(#PB_System_FreePhysical) / 1024) / 1024) + " mb."
  Debug "Memory Before creation : " + before

  shp\main = CreateNode(#PB_Any, 0, 0, 0) ;attaching everything below to nodes
  shp\snod = CreateNode(#PB_Any, 1.825, 0, 0)
  
  shp\rot[0] = CreateNode(#PB_Any, -0.7, 0, 0)
  shp\rot[1] = CreateNode(#PB_Any, 0.7, 0, 0)
  
  shp\sections[0]\ms = CreateSphere(#PB_Any, 0.2)
  shp\sections[0]\tx = ReturnHabitatTexture()
  shp\sections[0]\ma = CreateMaterial(#PB_Any, TextureID(shp\sections[0]\tx))
  MaterialCullingMode(shp\sections[0]\ma, #PB_Material_NoCulling)
  MaterialFilteringMode(shp\sections[0]\ma, #PB_Material_Anisotropic, 8)
  SetMaterialAttribute(shp\sections[0]\ma, #PB_Material_DepthWrite, #True)
  shp\sections[0]\id = CreateEntity(#PB_Any,MeshID(shp\sections[0]\ms), MaterialID(shp\sections[0]\ma), -1.5, 0, 0)
  Debug "1 - Section 0 - MaterialID: " + Str(MaterialID(shp\sections[0]\ma))
  
  shp\sections[1]\tx = ReturnHabitatTexture(#False)
  shp\sections[1]\ma = CreateMaterial(#PB_Any, TextureID(shp\sections[1]\tx))
  MaterialCullingMode(shp\sections[1]\ma, #PB_Material_NoCulling)
  MaterialFilteringMode(shp\sections[1]\ma, #PB_Material_Anisotropic, 8)
  SetMaterialAttribute(shp\sections[1]\ma, #PB_Material_DepthWrite, #True)
  shp\sections[1]\ms = CreateSphere(#PB_Any, 0.2)
  shp\sections[1]\id = CreateEntity(#PB_Any,MeshID(shp\sections[1]\ms), MaterialID(shp\sections[1]\ma), 0, 0, 0)
  Debug "2 - Section 1 - MaterialID: " + Str(MaterialID(shp\sections[1]\ma))
  
  shp\sections[2]\tx = ReturnHabitatTexture(#False)
  shp\sections[2]\ma = CreateMaterial(#PB_Any, TextureID(shp\sections[2]\tx))
  MaterialCullingMode(shp\sections[2]\ma, #PB_Material_NoCulling)
  MaterialFilteringMode(shp\sections[2]\ma, #PB_Material_Anisotropic, 8)
  SetMaterialAttribute(shp\sections[2]\ma, #PB_Material_DepthWrite, #True)
  shp\sections[2]\ms = CreateSphere(#PB_Any, 0.2)
  shp\sections[2]\id = CreateEntity(#PB_Any,MeshID(shp\sections[2]\ms), MaterialID(shp\sections[2]\ma), 1.2, 0, 0)
  Debug "3 - Section 2 - MaterialID: " + Str(MaterialID(shp\sections[2]\ma))
  
  shp\connect[0]\tx = ReturnConnectionTexture()
  shp\connect[0]\ma = CreateMaterial(#PB_Any,  TextureID(shp\connect[0]\tx))
  MaterialCullingMode(shp\connect[0]\ma, #PB_Material_NoCulling)
  MaterialFilteringMode(shp\connect[0]\ma, #PB_Material_Anisotropic, 8)
  SetMaterialAttribute(shp\connect[0]\ma, #PB_Material_DepthWrite, #True)
  shp\connect[0]\ms = CreateCylinder(#PB_Any, 0.025, 3.2)
  shp\connect[0]\id = CreateEntity(#PB_Any, MeshID(shp\connect[0]\ms), MaterialID(shp\connect[0]\ma), 0, 0, 0)
  RotateEntity(shp\connect[0]\id, 0, 0, 90)
  Debug "4 - Connect 0 - MaterialID: " + Str(MaterialID(shp\connect[0]\ma))
  
  shp\block\tx = ReturnConnectionTexture()
  shp\block\ma = CreateMaterial(#PB_Any,  TextureID(shp\block\tx))
  MaterialCullingMode(shp\block\ma, #PB_Material_NoCulling)
  MaterialFilteringMode(shp\block\ma, #PB_Material_Anisotropic, 8)
  SetMaterialAttribute(shp\block\ma, #PB_Material_DepthWrite, #True)
  ScaleMaterial(shp\block\ma, 2, 2)
  shp\block\ms = CreateCube(#PB_Any, 0.2)
  shp\block\id = CreateEntity(#PB_Any, MeshID(shp\block\ms), MaterialID(shp\block\ma), 1.7, 0, 0)
  Debug "5 - Blok - MaterialID: " + Str(MaterialID(shp\block\ma))
  
  shp\eng[0]\tx = ReturnConnectionTexture()
  shp\eng[0]\ma = CreateMaterial(#PB_Any,  TextureID(shp\eng[0]\tx))
  MaterialCullingMode(shp\eng[0]\ma, #PB_Material_NoCulling)
  MaterialFilteringMode(shp\eng[0]\ma, #PB_Material_Anisotropic, 8)
  SetMaterialAttribute(shp\eng[0]\ma, #PB_Material_DepthWrite, #True)
  shp\eng[0]\ms = CreateCone(#PB_Any, 0.03, 0.04, 16, 16)
  shp\eng[0]\id = CreateEntity(#PB_Any, MeshID(shp\eng[0]\ms),MaterialID(shp\eng[0]\ma), 1.8, -0.05, 0)
  RotateEntity(shp\eng[0]\id, 0, 0, 90)
  Debug "6 - Engine 0 - MaterialID: " + Str(MaterialID(shp\eng[0]\ma))
  
  shp\eng[1]\tx = ReturnConnectionTexture()
  shp\eng[1]\ma = CreateMaterial(#PB_Any,  TextureID(shp\eng[1]\tx))
  MaterialCullingMode(shp\eng[1]\ma, #PB_Material_NoCulling)
  MaterialFilteringMode(shp\eng[1]\ma, #PB_Material_Anisotropic, 8)
  SetMaterialAttribute(shp\eng[1]\ma, #PB_Material_DepthWrite, #True)
  shp\eng[1]\ms = CreateCone(#PB_Any, 0.03, 0.04, 16, 16)
  shp\eng[1]\id = CreateEntity(#PB_Any, MeshID(shp\eng[1]\ms),MaterialID(shp\eng[1]\ma), -1.8, -0.05, 0)
  RotateEntity(shp\eng[1]\id, 0, 0, 90)
  Debug "7 - Engine 1 - MaterialID: " + Str(MaterialID(shp\eng[1]\ma))
  
  shp\connect[1]\tx = ReturnConnectionTexture()
  shp\connect[1]\ma = CreateMaterial(#PB_Any, TextureID(shp\connect[1]\tx))
  MaterialCullingMode(shp\connect[1]\ma, #PB_Material_NoCulling)
  MaterialFilteringMode(shp\connect[1]\ma, #PB_Material_Anisotropic, 8)
  SetMaterialAttribute(shp\connect[1]\ma, #PB_Material_DepthWrite, #True)
  shp\connect[1]\ms = CreateCylinder(#PB_Any, 0.01, 1)
  shp\connect[1]\id = CreateEntity(#PB_Any, MeshID(shp\connect[1]\ms), MaterialID(shp\connect[1]\ma), 0, 0, 0)
  RotateEntity(shp\connect[1]\id, 90, 0, 90)  
  Debug "8 - Connect 1 - MaterialID: " + Str(MaterialID(shp\connect[1]\ma))
  
  shp\connect[2]\tx = ReturnConnectionTexture()
  shp\connect[2]\ma = CreateMaterial(#PB_Any, TextureID(shp\connect[2]\tx))
  MaterialCullingMode(shp\connect[2]\ma, #PB_Material_NoCulling)
  MaterialFilteringMode(shp\connect[2]\ma, #PB_Material_Anisotropic, 8)
  SetMaterialAttribute(shp\connect[2]\ma, #PB_Material_DepthWrite, #True)
  shp\connect[2]\ms = CreateCylinder(#PB_Any, 0.01, 1)
  shp\connect[2]\id = CreateEntity(#PB_Any, MeshID(shp\connect[2]\ms), MaterialID(shp\connect[2]\ma), 0, 0, 0)
  RotateEntity(shp\connect[2]\id, 0, 90, 0)  
  Debug "9 - Connect 2 - MaterialID: " + Str(MaterialID(shp\connect[2]\ma))
  
  shp\connect[5]\tx = ReturnConnectionTexture()
  shp\connect[5]\ma = CreateMaterial(#PB_Any, TextureID(shp\connect[5]\tx))
  MaterialCullingMode(shp\connect[5]\ma, #PB_Material_NoCulling)
  MaterialFilteringMode(shp\connect[5]\ma, #PB_Material_Anisotropic, 8)
  SetMaterialAttribute(shp\connect[5]\ma, #PB_Material_DepthWrite, #True)
  ScaleMaterial(shp\connect[5]\ma, 1,20)
  shp\connect[5]\ms = CreateTube(#PB_Any, 0.55, 0.50, 0.07, 40, 1)
  shp\connect[5]\id = CreateEntity(#PB_Any, MeshID(shp\connect[5]\ms), MaterialID(shp\connect[5]\ma), 0, 0, 0)
  RotateEntity(shp\connect[5]\id, 0, 90, 90)
  Debug "10 - Connect 5 - MaterialID: " + Str(MaterialID(shp\connect[5]\ma))
  
  shp\connect[3]\tx = ReturnConnectionTexture()
  shp\connect[3]\ma = CreateMaterial(#PB_Any, TextureID(shp\connect[3]\tx))
  MaterialCullingMode(shp\connect[3]\ma, #PB_Material_NoCulling)
  MaterialFilteringMode(shp\connect[3]\ma, #PB_Material_Anisotropic, 8)
  SetMaterialAttribute(shp\connect[3]\ma, #PB_Material_DepthWrite, #True)
  shp\connect[3]\ms = CreateCylinder(#PB_Any, 0.01, 1)
  shp\connect[3]\id = CreateEntity(#PB_Any, MeshID(shp\connect[3]\ms), MaterialID(shp\connect[3]\ma), 0, 0, 0)
  RotateEntity(shp\connect[3]\id, 90, 0, 90)  
  Debug "11 - Connect 3 - MaterialID: " + Str(MaterialID(shp\connect[3]\ma))
  
  shp\connect[4]\tx = ReturnConnectionTexture()
  shp\connect[4]\ma = CreateMaterial(#PB_Any, TextureID(shp\connect[4]\tx))
  MaterialCullingMode(shp\connect[4]\ma, #PB_Material_NoCulling)
  MaterialFilteringMode(shp\connect[4]\ma, #PB_Material_Anisotropic, 8)
  SetMaterialAttribute(shp\connect[4]\ma, #PB_Material_DepthWrite, #True)
  shp\connect[4]\ms = CreateCylinder(#PB_Any, 0.01, 1)
  shp\connect[4]\id = CreateEntity(#PB_Any, MeshID(shp\connect[4]\ms), MaterialID(shp\connect[4]\ma), 0, 0, 0)
  RotateEntity(shp\connect[4]\id, 0, 90, 0)
  Debug "12 - Connect 4 - MaterialID: " + Str(MaterialID(shp\connect[4]\ma))
  
  shp\connect[6]\tx = ReturnConnectionTexture()
  shp\connect[6]\ma = CreateMaterial(#PB_Any, TextureID(shp\connect[6]\tx))
  MaterialCullingMode(shp\connect[6]\ma, #PB_Material_NoCulling)
  MaterialFilteringMode(shp\connect[6]\ma, #PB_Material_Anisotropic, 8)
  SetMaterialAttribute(shp\connect[6]\ma, #PB_Material_DepthWrite, #True)
  ScaleMaterial(shp\connect[6]\ma, 1, 20)
  shp\connect[6]\ms = CreateTube(#PB_Any, 0.55, 0.50, 0.07, 40, 1)
  shp\connect[6]\id = CreateEntity(#PB_Any, MeshID(shp\connect[6]\ms), MaterialID(shp\connect[6]\ma), 0, 0, 0)
  RotateEntity(shp\connect[6]\id, 0, 90, 90)
  Debug "13 - Connect 6 - MaterialID: " + Str(MaterialID(shp\connect[6]\ma))
  
  shp\par[0]\id = CreateParticleEmitter(#PB_Any, 0.001, 0.001, 0.001, #PB_Particle_Point, 0, 0.046, 0)
  shp\par[0]\tx  = ReturnFlareTExture()
  shp\par[0]\ma = CreateMaterial(#PB_Any, TextureID(shp\par[0]\tx))
  MaterialBlendingMode(shp\par[0]\ma, #PB_Material_Add)
  AddMaterialLayer(shp\par[0]\ma, TextureID(shp\par[0]\tx), #PB_Material_Add)
  ParticleMaterial(shp\par[0]\id, MaterialID(shp\par[0]\ma))
  ParticleEmissionRate(shp\par[0]\id, 50)
  ParticleVelocity(shp\par[0]\id, 0.001, 0.001)
  ParticleSpeedFactor(shp\par[0]\id, 0.4)
  ParticleSize(shp\par[0]\id, 0.055, 0.055)
  ParticleTimeToLive(shp\par[0]\id, 0.01, 0.01)
  Debug "14 - Engine par 0 - MaterialID: " + Str(MaterialID(shp\par[0]\ma))
  
  shp\par[1]\id = CreateParticleEmitter(#PB_Any, 0.001, 0.001, 0.001, #PB_Particle_Point, 0, -0.046, 0)
  shp\par[1]\tx  = ReturnFlareTexture()
  shp\par[1]\ma = CreateMaterial(#PB_Any, TextureID(shp\par[0]\tx))
  MaterialBlendingMode(shp\par[1]\ma, #PB_Material_Add)
  AddMaterialLayer(shp\par[1]\ma, TextureID(shp\par[1]\tx), #PB_Material_Add)
  ParticleMaterial(shp\par[1]\id, MaterialID(shp\par[1]\ma))
  ParticleEmissionRate(shp\par[1]\id, 50)
  ParticleVelocity(shp\par[1]\id, 0.001, 0.001)
  ParticleSpeedFactor(shp\par[1]\id, 0.4)
  ParticleSize(shp\par[1]\id, 0.055, 0.055)
  ParticleTimeToLive(shp\par[1]\id, 0.01, 0.01)
  Debug "15 - Engine par 1 - MaterialID: " + Str(MaterialID(shp\par[1]\ma))
  
  shp\par[2]\id = CreateParticleEmitter(#PB_Any, 150, 150, 20, #PB_Particle_Point, 0, 0, -400)
  shp\par[2]\tx = ReturnFlareTexture($FFFFFFFF)
  shp\par[2]\ma = CreateMaterial(#PB_Any, TextureID(shp\par[2]\tx))
  MaterialBlendingMode(shp\par[2]\ma, #PB_Material_Add)
  ParticleMaterial(shp\par[2]\id, MaterialID(shp\par[2]\ma))
  ParticleSize(shp\par[2]\id, 0.2, 0.2)
  ParticleEmissionRate(shp\par[2]\id, 200)
  ParticleTimeToLive(shp\par[2]\id, 2, 12)
  ParticleVelocity(shp\par[2]\id, 3, 20)
  ParticleEmitterDirection(shp\par[2]\id, 0, 0, 1)
  Debug "16 - star par 2 - MaterialID: " + Str(MaterialID(shp\par[2]\ma))
  Debug "--------------------------"
  Debug "Attaching objects to nodes"
  
  Debug "Node and ids:"
  Debug "Attaching Emitter 0 (ID): " + Str(ParticleEmitterID(shp\par[0]\id)) + "  to Node (ID): " + Str(NodeID(shp\snod))
  AttachNodeObject(shp\snod, ParticleEmitterID(shp\par[0]\id))
  Debug "Attaching Emitter 1 (ID): " + Str(ParticleEmitterID(shp\par[1]\id)) + "  to Node (ID): " + Str(NodeID(shp\snod))
  AttachNodeObject(shp\snod, ParticleEmitterID(shp\par[1]\id))
  
  Debug "Attaching Connect Entity 1 (ID): " + Str(EntityID(shp\connect[1]\id)) + "  to Node (ID): " + Str(NodeID(shp\rot[0]))
  AttachNodeObject(shp\rot[0], EntityID(shp\connect[1]\id))
  Debug "Attaching Connect Entity 2 (ID): " + Str(EntityID(shp\connect[2]\id)) + "  to Node (ID): " + Str(NodeID(shp\rot[0]))
  AttachNodeObject(shp\rot[0], EntityID(shp\connect[2]\id))
  Debug "Attaching Connect Entity 5 (ID): " + Str(EntityID(shp\connect[5]\id)) + "  to Node (ID): " + Str(NodeID(shp\rot[0]))
  AttachNodeObject(shp\rot[0], EntityID(shp\connect[5]\id))
  
  Debug "Attaching Connect Entity 3 (ID): " + Str(EntityID(shp\connect[3]\id)) + "  to Node (ID): " + Str(NodeID(shp\rot[1]))
  AttachNodeObject(shp\rot[1], EntityID(shp\connect[3]\id))
  Debug "Attaching Connect Entity 4 (ID): " + Str(EntityID(shp\connect[4]\id)) + "  to Node (ID): " + Str(NodeID(shp\rot[1]))
  AttachNodeObject(shp\rot[1], EntityID(shp\connect[4]\id))
  Debug "Attaching Connect Entity 6 (ID): " + Str(EntityID(shp\connect[6]\id)) + "  to Node (ID): " + Str(NodeID(shp\rot[1]))
  AttachNodeObject(shp\rot[1], EntityID(shp\connect[6]\id))
  
  ;Put it all together
  AttachNodeObject(shp\main, EntityID(shp\block\id))
  AttachNodeObject(shp\main, EntityID(shp\eng[0]\id))
  AttachNodeObject(shp\main, EntityID(shp\eng[1]\id))
  AttachNodeObject(shp\main, EntityID(shp\sections[0]\id))
  AttachNodeObject(shp\main, EntityID(shp\sections[1]\id))
  AttachNodeObject(shp\main, EntityID(shp\sections[2]\id))
  AttachNodeObject(shp\main, EntityID(shp\connect[0]\id))
  AttachNodeObject(shp\main, NodeID(shp\rot[0]))
  AttachNodeObject(shp\main, NodeID(shp\rot[1]))

  ProcedureReturn #True
EndProcedure

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 CreateTube(meshID.i, outerRadius.f, innerRadius.f, height.f, numSegBase.i=16, numSegHeight.i=1)
  
  Protected  Normal.Vector3, returnMesh.i
  
  If meshID = -1
    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   

https://www.dropbox.com/s/p3hi39iv5r8kb ... t.jpg?dl=0

Re: Deep Space Explorer - Tranquility (Flyby and follow)

Posted: Wed Mar 02, 2016 10:18 pm
by bbanelli
W7 x64, i5 4440, Quadro K600, PB 5.42 LTS

On PB x86 (OGL and non-OGL), error on line 193:

\eng[1]\id = CreateEntity(#PB_Any, MeshID(\eng[1]\ms),MaterialID(enma), 1.8, 0.05, 0)

[ERROR] The specified #Material is not initialised.

And after that, it chrashes,

On x64, just a crash.

Code: Select all

Problem signature:
  Problem Event Name:	APPCRASH
  Application Name:	PureBasic_Compilation0.exe
  Application Version:	0.0.0.0
  Application Timestamp:	56d7582b
  Fault Module Name:	KERNELBASE.dll
  Fault Module Version:	6.1.7601.19110
  Fault Module Timestamp:	56842600
  Exception Code:	e06d7363
  Exception Offset:	0000c42d
  OS Version:	6.1.7601.2.1.0.256.1
  Locale ID:	1050
  Additional Information 1:	0a9e
  Additional Information 2:	0a9e372d3b4ad19135b953a78882e789
  Additional Information 3:	0a9e
  Additional Information 4:	0a9e372d3b4ad19135b953a78882e789

Read our privacy statement online:
  http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409

If the online privacy statement is not available, please read our privacy statement offline:
  C:\Windows\system32\en-US\erofflps.txt

Re: Deep Space Explorer - Tranquility (Flyby and follow)

Posted: Wed Mar 02, 2016 10:32 pm
by DK_PETER
bbanelli wrote:W7 x64, i5 4440, Quadro K600, PB 5.42 LTS

On PB x86 (OGL and non-OGL), error on line 193:

\eng[1]\id = CreateEntity(#PB_Any, MeshID(\eng[1]\ms),MaterialID(enma), 1.8, 0.05, 0)

[ERROR] The specified #Material is not initialised.

And after that, it chrashes,

On x64, just a crash.

Code: Select all

Problem signature:
  Problem Event Name:	APPCRASH
  Application Name:	PureBasic_Compilation0.exe
  Application Version:	0.0.0.0
  Application Timestamp:	56d7582b
  Fault Module Name:	KERNELBASE.dll
  Fault Module Version:	6.1.7601.19110
  Fault Module Timestamp:	56842600
  Exception Code:	e06d7363
  Exception Offset:	0000c42d
  OS Version:	6.1.7601.2.1.0.256.1
  Locale ID:	1050
  Additional Information 1:	0a9e
  Additional Information 2:	0a9e372d3b4ad19135b953a78882e789
  Additional Information 3:	0a9e
  Additional Information 4:	0a9e372d3b4ad19135b953a78882e789

Read our privacy statement online:
  http://go.microsoft.com/fwlink/?linkid=104288&clcid=0x0409

If the online privacy statement is not available, please read our privacy statement offline:
  C:\Windows\system32\en-US\erofflps.txt
Edit3:
@bbanelli
PB x86 (for Windows) returns an IMA....for now.
Could you try again with x64 and report back again?
Thanks.

Re: Deep Space Explorer - Tranquility (Flyby and follow)

Posted: Thu Mar 03, 2016 9:48 am
by DK_PETER
Code cleaned up a bit.

@Comtois

Any chance you could you try the code?
PB 5.42 x86 LTS Final for Windows throws an IMA.
PB 5.42 x64 LTS Final for Windows works for me...

Thanks.

Re: Deep Space Explorer - Tranquility (Flyby and follow)

Posted: Thu Mar 03, 2016 9:52 am
by bbanelli
x86, DX and OpenGL

Code: Select all

Skybox created... MaterialID: 60309456
1 - Section 0 - MaterialID: 60380480
2 - Section 1 - MaterialID: 60393800
3 - Section 2 - MaterialID: 60404736
4 - Connect 0 - MaterialID: 60415672
5 - Blok - MaterialID: 60425584
6 - Engine 0 - MaterialID: 60434984
7 - Engine 1 - MaterialID: 60444896
8 - Connect 1 - MaterialID: 60454808
9 - Connect 2 - MaterialID: 60464720
10 - Connect 5 - MaterialID: 60474632
11 - Connect 3 - MaterialID: 60485568
12 - Connect 4 - MaterialID: 60495480
13 - Connect 6 - MaterialID: 60505392
14 - Engine par 0 - MaterialID: 60518080
15 - Engine par 1 - MaterialID: 60529000
16 - star par 2 - MaterialID: 60537584
--------------------------
Attaching objects to nodes
Done
After that, procedure CreateShip():

Code: Select all

[09:49:10] [ERROR] test.pb (Line: 383)
[09:49:10] [ERROR] Illegal instruction. (executing binary data?)
x64, DX and OpenGL

Same debugger output, but you get this:

Code: Select all

Problem signature:
  Problem Event Name:	APPCRASH
  Application Name:	PureBasic_Compilation0.exe
  Application Version:	0.0.0.0
  Application Timestamp:	56d7fb1b
  Fault Module Name:	KERNELBASE.dll
  Fault Module Version:	6.1.7601.19110
  Fault Module Timestamp:	568429dd
  Exception Code:	e06d7363
  Exception Offset:	000000000000b16d
  OS Version:	6.1.7601.2.1.0.256.1
  Locale ID:	1050
  Additional Information 1:	05fc
  Additional Information 2:	05fc01b6fc1abb725d83ab788ac9e3a8
  Additional Information 3:	418c
  Additional Information 4:	418ca4c01b249892e7ace834085adcca

Re: Deep Space Explorer - Tranquility (Flyby and follow)

Posted: Thu Mar 03, 2016 10:00 am
by DK_PETER
@bbanelli

It's really odd. Could you please try without 3Dsound?
Comment out lines 69 to 81 (sound specific)
and line: 94 - the sound listener

Thanks for trying.

Re: Deep Space Explorer - Tranquility (Flyby and follow)

Posted: Thu Mar 03, 2016 10:24 am
by bbanelli
Removing sound didn't help. I've even updated drivers to latest Quadro 361.91 WHQL but no change.

No clue how to help you, I'm not really into graphics, but maybe there's something wrong with #PB_Any again? Just wild guessing, really...

http://imgur.com/9Z4UnhV

Re: Deep Space Explorer - Tranquility (Flyby and follow)

Posted: Thu Mar 03, 2016 10:51 am
by DK_PETER
@bbanelli
Currently I'm at a loss. The code seems okay.
I've added more debug info and I can't see any
invalid values..

Thanks for trying - I appreciate it. :wink:

I hope Comtois stops by and tries the code.
He might see my blunder or discover something else.

Re: Deep Space Explorer - Tranquility (Flyby and follow)

Posted: Thu Mar 03, 2016 12:51 pm
by applePi
DK_PETER, it is the same problem in 86x we have discussed before in your code named "MIDEVAL" http://purebasic.fr/english/viewtopic.p ... AL#p474665
the solution was in (x86) add NbBaseSegments, NbHeightSegments to the createcone
in your code here there are 2 cases of CreateCone, so add 16,16 to the end of each one and it will work on windows xp 32bit as i have tried it just now
edit: my system winxp + PB 5.42 final/32bit

Re: Deep Space Explorer - Tranquility (Flyby and follow)

Posted: Thu Mar 03, 2016 1:06 pm
by DK_PETER
@applePi
Thank you! :wink:

Re: Deep Space Explorer - Tranquility (Flyby and follow)

Posted: Fri Mar 04, 2016 2:46 pm
by Hades
Hi DK_PETER,

I'm sad to report that it still crashes here.
Compiled with PB 5.42 LTS (x64)
crashes on :

Code: Select all

sn = LoadSound3D(#PB_Any, "rock2.wav")
Any ideas?

Runs perfect without that line though. Really nice job, loving it. :D

Edit: Everything is just fine, I've messed up somewhere and broke his code when trying to make it run.

Re: Deep Space Explorer - Tranquility (Flyby and follow)

Posted: Fri Mar 04, 2016 4:02 pm
by Julian
Hades wrote:Hi DK_PETER,

I'm sad to report that it still crashes here.
Compiled with PB 5.42 LTS (x64)
crashes on :

Code: Select all

sn = LoadSound3D(#PB_Any, "rock2.wav")
Any ideas?

Runs perfect without that line though. Really nice job, loving it. :D
Hmm seems like a bug in LoadSound3D, did you download the wav from the OP and put it next to the saved source file?

Re: Deep Space Explorer - Tranquility (Flyby and follow)

Posted: Fri Mar 04, 2016 4:22 pm
by Hades
Yep, doesn't work. Not even as an .exe

Might be something very basic I'm missing, though. Took me a while to figure out that I have to load the OpenGL subsystem to avoid crashing with most 3d stuff, too.
Was gone for a long while...

Re: Deep Space Explorer - Tranquility (Flyby and follow)

Posted: Fri Mar 04, 2016 4:33 pm
by Julian
Hades wrote:Yep, doesn't work. Not even as an .exe

Might be something very basic I'm missing, though. Took me a while to figure out that I have to load the OpenGL subsystem to avoid crashing with most 3d stuff, too.
Was gone for a long while...
Ah, what platform are you on? Win/Mac/Linux? Version etc?

Re: Deep Space Explorer - Tranquility (Flyby and follow)

Posted: Fri Mar 04, 2016 4:56 pm
by Hades
Windows 7 / PB 5.42 LTS (x64)
Skylake 6700K

Is there maybe anything that is so obvious to you (and everyone else but me :oops: ), that you don't even consider it?