Cars, cars and more cars

Everything related to 3D programming
User avatar
minimy
Enthusiast
Enthusiast
Posts: 619
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Cars, cars and more cars

Post by minimy »

Many diferent cars lowpoly, with texture and European license plate :mrgreen:
Move with WASD, hold shift for faster

Code: Select all




;{ GLOBALES
  Global.b sal
  Global.l contador
  Global.b pantallaCompleta
;}

  ;{ FUENTES
  Global  fontLit= LoadFont(#PB_Any,"Arial",9)
  Global  fontMed= LoadFont(#PB_Any,"Arial",16)
  Global  fontBig= LoadFont(#PB_Any,"Arial",24)
  ;}
  
  ;borde
  Global borde_mat
  
  ;{ SISTEMA 3D
  Procedure   showImage(img)
    If IsImage(img)
      SetWindowColor(OpenWindow(#PB_Any,0,0,ImageWidth(img),ImageHeight(img),"Test imagen: "+Str(img)) , $ff0000)
      
      ImageGadget(#PB_Any,0,0,ImageWidth(img),ImageHeight(img),ImageID(img))
    EndIf
  EndProcedure
  Procedure   showModosPantalla()
    If ExamineScreenModes()
      While NextScreenMode()
        Debug Str(ScreenModeWidth())+"x"+Str(ScreenModeHeight())+"x"+Str(ScreenModeDepth())+"@"+Str(ScreenModeRefreshRate())+"Hz"
      Wend
    EndIf
  EndProcedure
  Procedure   spr2DText(spr, txt.s, ink.l=$ff00ffff)
    Protected n,y=2,tl= CountString(txt,#CR$)
    Protected tx.s
    StartDrawing(SpriteOutput(spr))
    DrawingMode(#PB_2DDrawing_AlphaChannel)
      Box(0,0,OutputWidth(),OutputHeight(),$00000000)
    DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Transparent)
      Box(0,0,OutputWidth(),OutputHeight(),$aa000000)
      DrawingFont(FontID(fontLit))
      For n=1 To tl+1
        tx= StringField(txt,n,#CR$)
        DrawText(5,y,tx,ink)
        y+16
      Next n
      DrawingMode(#PB_2DDrawing_AlphaBlend | #PB_2DDrawing_Outlined)
      Box(0,0,OutputWidth(),OutputHeight(),ink)
    StopDrawing()
  EndProcedure
  Procedure   creaSuelo(size=50, col1.l=$0,col2.l=$aaaaaa, res=256)
  Protected.i suelo_tx3D, suelo_mate, suelo_mesh, suelo
    suelo_tx3D=   CreateTexture(#PB_Any,res,res)
    StartDrawing(TextureOutput(suelo_tx3D))
      Box(0,0,OutputWidth(),OutputHeight(),col1)
      Box(2,2,OutputWidth()-4,OutputHeight()-4,col2)
    StopDrawing()
    
    suelo_mesh=   CreatePlane(#PB_Any,size,size,1,1,1,1)
    suelo_mate=   CreateMaterial(#PB_Any,TextureID(suelo_tx3D))
                  ScaleMaterial(suelo_mate,1/size,1/size)
    suelo=        CreateEntity(#PB_Any, MeshID(suelo_mesh), MaterialID(suelo_mate))
  ProcedureReturn suelo
  EndProcedure
  
  Procedure   eventosWindows()
    Repeat
      event= WindowEvent()
      Select event
        Case #PB_Event_Gadget
          EventGadget=  EventGadget()
          EventType=    EventType()
          
        Case #PB_Event_CloseWindow
          sal= 1
      EndSelect
    Until event= 0
  EndProcedure
  Procedure   eventos3D(camara, speed.f=1, mouseSpd.f=0.05)
    Protected.f KeyX,KeyY, MouseX,MouseY
    If KeyboardPushed(#PB_Key_Escape)
      sal=1
    EndIf
    
    If KeyboardPushed(#PB_Key_C)
      SetClipboardText(Str(CameraX(camara))+","+Str(CameraY(camara))+","+Str(CameraZ(camara)) )
    EndIf
    
    If KeyboardPushed(#PB_Key_A)
      KeyX= -speed
    ElseIf KeyboardPushed(#PB_Key_D)
      KeyX= speed
    Else
      KeyX= 0
    EndIf
    
    If KeyboardPushed(#PB_Key_W)
      KeyY= -speed
    ElseIf KeyboardPushed(#PB_Key_S)
      KeyY= speed
    Else
      KeyY= 0
    EndIf
    
    If KeyboardPushed(#PB_Key_LeftShift)
      keyY * 10
      keyX * 10
    EndIf

    MouseX = -MouseDeltaX() * mouseSpd
    MouseY = -MouseDeltaY() * mouseSpd
    
    RotateCamera(camara, MouseY, MouseX, 0, #PB_Relative)
    MoveCamera (camara, KeyX, 0, KeyY)
  EndProcedure
  Procedure   iniDX(title.s="Agua")
    Protected w,h
    InitEngine3D()
      InitSprite()
      InitKeyboard()
      InitMouse()
      OpenWindow(0,0,0,1280,720,title,#PB_Window_ScreenCentered|#PB_Window_BorderLess|#PB_Window_Maximize)
      w= WindowWidth(0):h=WindowHeight(0)
      AntialiasingMode(#PB_AntialiasingMode_None)
      OpenWindowedScreen(WindowID(0), 0, 0, w,h, 0,0,0,#PB_Screen_NoSynchronization)
      KeyboardMode(#PB_Keyboard_International)
      
      Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
      Add3DArchive("Data/Model", #PB_3DArchive_FileSystem)
      Parse3DScripts()
      WorldShadows(#PB_Shadow_Additive, -1, RGB(s,s,s), 2048)
  EndProcedure
  
  iniDX("Base 3D")
  sprInfo=  CreateSprite(#PB_Any,100,200,#PB_Sprite_AlphaBlending)
  ;}
  
  ;---- CAR GEN
  ;{ GEN CAR
  Structure   carMesh_stru
    v.Vector3[8]
    w.f
    h.f
    mesh.i
    tx3d.i
    mate.i
    enti.i
    entiBorde.i
    matricula.s
  EndStructure
  Global NewList carMesh.carMesh_stru()
  Procedure   carGenFront(x1.f,y1.f,x2.f,y2.f)
    AddElement(carMesh())
    carMesh()\v[0]\z= x1
    carMesh()\v[0]\y= y1
    carMesh()\v[1]\z= x2
    carMesh()\v[1]\y= y2
  EndProcedure
  Procedure   carGenFrontGlass(x1.f,y1.f,x2.f,y2.f)
    carMesh()\v[2]\z= x1
    carMesh()\v[2]\y= y1
    carMesh()\v[3]\z= x2
    carMesh()\v[3]\y= y2
  EndProcedure
  Procedure   carGenBBackGlass(x1.f,y1.f,x2.f,y2.f)
    carMesh()\v[4]\z= x1
    carMesh()\v[4]\y= y1
    carMesh()\v[5]\z= x2
    carMesh()\v[5]\y= y2
  EndProcedure
  Procedure   carGenBBack(x1.f,y1.f,x2.f,y2.f)
    carMesh()\v[6]\z= x1
    carMesh()\v[6]\y= y1
    carMesh()\v[7]\z= x2
    carMesh()\v[7]\y= y2
  EndProcedure
  
  Procedure   carTextura(color.l=$ffff0000,glass.l=$ff774422, res=24)
    Protected   g= 10
    Protected   sizeZ= (carMesh()\v[0]\z - carMesh()\v[7]\z) * res
    Protected   sizeY= (carMesh()\v[3]\y - carMesh()\v[0]\y) * res
    Protected.s l, text= RSet(Str(Random(9999)),4,"0")
    Protected.d part, fn
    Protected.i i=CreateImage(#PB_Any,sizeZ,sizeY*2,32,#PB_Image_Transparent)
    Protected   cz= sizeZ- (carMesh()\v[0]\z * res)
    Protected   cy= sizeY- (Abs(carMesh()\v[7]\y) * res)
    carMesh()\w= carMesh()\v[0]\z - carMesh()\v[7]\z
    carMesh()\h= carMesh()\v[3]\y - carMesh()\v[0]\y 
    
    StartVectorDrawing(ImageVectorOutput(i))
      ;lateral
      VectorSourceColor(color)
      FillVectorOutput()
      part= Abs(carMesh()\v[0]\y - carMesh()\v[1]\y) * res
      VectorSourceColor($88000000)
      ;defensa
      AddPathBox(0,sizeY-(part*0.6), sizeZ*0.1, part*0.6)
      AddPathBox(sizeZ-(sizeZ*0.1),sizeY-(part*0.6), sizeZ*0.1, part*0.6)
      FillPath()
      ;;----- puertas
      VectorSourceColor($55000000)
      ;delantera
      MovePathCursor( cz+(carMesh()\v[2]\z * res), cy+((carMesh()\v[2]\y * res)*-1) )
        AddPathLine(cz+(carMesh()\v[3]\z * res), cy+((carMesh()\v[3]\y * res)*-1))
        AddPathLine(cz, cy+((carMesh()\v[3]\y * res)*-1))
        AddPathLine(cz, cy+((carMesh()\v[0]\y * res)*-1))
        AddPathLine(cz+(carMesh()\v[3]\z * res), cy+((carMesh()\v[0]\y * res)*-1))
        AddPathLine(cz+(carMesh()\v[2]\z * res), cy+((carMesh()\v[2]\y * res)*-1))
        StrokePath(4)
        ;cristal
        VectorSourceColor(glass)
        MovePathCursor( cz+(carMesh()\v[2]\z * res)-(g*3), cy+((carMesh()\v[2]\y * res)*-1)-g )
          AddPathLine( cz+(carMesh()\v[3]\z * res)-g, cy+((carMesh()\v[3]\y * res)*-1)+g )
          AddPathLine( cz+g, cy+((carMesh()\v[3]\y * res)*-1)+g )
          AddPathLine( cz+g, cy+((carMesh()\v[2]\y * res)*-1)-g )
          FillPath()
        VectorSourceColor($ff000000)
        MovePathCursor( cz+(carMesh()\v[2]\z * res)-(g*3), cy+((carMesh()\v[2]\y * res)*-1)-g )
          AddPathLine( cz+(carMesh()\v[3]\z * res)-g, cy+((carMesh()\v[3]\y * res)*-1)+g )
          AddPathLine( cz+g, cy+((carMesh()\v[3]\y * res)*-1)+g )
          AddPathLine( cz+g, cy+((carMesh()\v[2]\y * res)*-1)-g )
          StrokePath(1,#PB_Path_RoundCorner)
        ;cerradura del
        VectorSourceColor($77ffffff)
        AddPathBox(1+cz+Random(res/2,res/4), 1+cy+((carMesh()\v[2]\y * res)*-1), res, res/6)
          FillPath()
        VectorSourceColor($99000000)
        AddPathBox(cz+Random(res/2,res/4), cy+((carMesh()\v[2]\y * res)*-1), res, res/6)
          FillPath()
        
      ;trasera
      VectorSourceColor($55000000)
      MovePathCursor( cz, cy+((carMesh()\v[3]\y * res)*-1) )
        AddPathLine(cz+(carMesh()\v[4]\z * res), cy+((carMesh()\v[4]\y * res)*-1) )
        AddPathLine(cz+(carMesh()\v[5]\z * res), cy+((carMesh()\v[5]\y * res)*-1) )
        AddPathLine(cz+(carMesh()\v[4]\z * res), cy+((carMesh()\v[0]\y * res)*-1) )
        AddPathLine(cz+(carMesh()\v[3]\z * res), cy+((carMesh()\v[0]\y * res)*-1) )
        StrokePath(4)
        ;cristal trasero
        VectorSourceColor(glass)
        MovePathCursor( cz+(carMesh()\v[4]\z * res)+g, cy+((carMesh()\v[4]\y * res)*-1)+g )
          AddPathLine( cz+(carMesh()\v[5]\z * res)+(g*3), cy+((carMesh()\v[5]\y * res)*-1)-g )
          AddPathLine( cz-g, cy+((carMesh()\v[5]\y * res)*-1)-g )
          AddPathLine( cz-g, cy+((carMesh()\v[4]\y * res)*-1)+g )
          FillPath()
        VectorSourceColor($ff000000)
        MovePathCursor( cz+(carMesh()\v[4]\z * res)+g, cy+((carMesh()\v[4]\y * res)*-1)+g )
          AddPathLine( cz+(carMesh()\v[5]\z * res)+(g*3), cy+((carMesh()\v[5]\y * res)*-1)-g )
          AddPathLine( cz-g, cy+((carMesh()\v[5]\y * res)*-1)-g )
          AddPathLine( cz-g, cy+((carMesh()\v[4]\y * res)*-1)+g )
          StrokePath(1,#PB_Path_RoundCorner)
        ;cerradura tras
        VectorSourceColor($77ffffff)
        AddPathBox(10+cz+(carMesh()\v[5]\z * res), 1+cy+((carMesh()\v[2]\y * res)*-1), res, res/6)
          FillPath()
        VectorSourceColor($99000000)
        AddPathBox(12+cz+(carMesh()\v[5]\z * res), cy+((carMesh()\v[2]\y * res)*-1), res, res/6)
          FillPath()
      ;;----- arriba
      VectorSourceColor(color)
      AddPathBox(     0,sizeY, VectorOutputWidth(),sizeY)
      FillPath()
      part= sizeZ / 7
      ;defensa
        VectorSourceColor($aa000000)
        ;trasera
        AddPathBox(     0,sizeY, part*0.6,sizeY)
        FillPath()
        ;frontal
        AddPathBox(part*6.4,sizeY, part*0.6,sizeY)
        FillPath()
          AddPathCircle(part*6.1,sizeY*1.5,part*0.05)
          FillPath()
          ;logocar
          VectorSourceColor($bb555555)
          Select Random(2)
            Case 0
            AddPathCircle(part*0.9,sizeY*1.5,part*0.08)
            FillPath()
            Case 1
            AddPathBox(part*0.85,sizeY*1.45,part*0.1,sizeY*0.1)
            FillPath()
            Case 2
            AddPathCircle(part*0.9,sizeY*1.5,part*0.08)
            FillPath()
            AddPathBox(part*0.85,sizeY*1.45,part*0.1,sizeY*0.1)
            FillPath()
          EndSelect

      ;maletero
      VectorSourceColor($55000000)
      AddPathBox((part*4.9)+5  ,sizeY+5, (part*1.3)-5,sizeY-10)
      StrokePath(1)
      MovePathCursor(part*4.95  ,sizeY*1.1)
      AddPathLine(part*6.2  ,sizeY*1.25)
      MovePathCursor(part*6.2  ,sizeY*1.75)
      AddPathLine(part*4.95 ,sizeY*1.9)
      StrokePath(3)
      ;capo
      VectorSourceColor($55000000)
      AddPathBox(part*0.8  ,sizeY+5, part*1.25,sizeY-10)
      StrokePath(1)
      MovePathCursor(part*0.8  ,sizeY*1.25)
      AddPathLine(part*2.05  ,sizeY*1.1)
      MovePathCursor(part*0.8  ,sizeY*1.75)
      AddPathLine(part*2.05  ,sizeY*1.9)
      StrokePath(3)
      ;cristal trasero
      VectorSourceColor(glass)
      AddPathBox((part*2)+10  ,sizeY+5, part-20,sizeY-10)
      FillPath()
      ;cristal delantero
      AddPathBox((part*4)+10  ,sizeY+5, part-20,sizeY-10)
      FillPath()
      VectorSourceColor($ff000000)
      AddPathBox((part*2)+10  ,sizeY+5, part-20,sizeY-10)
      AddPathBox((part*4)+10  ,sizeY+5, part-20,sizeY-10)
      StrokePath(1)
      ;luces traseras
      VectorSourceColor($ff0000ff)
      AddPathBox(part*6.5  ,sizeY, part*0.25,sizeY*0.25)
      AddPathBox(part*6.5  ,sizeY*1.75, part*0.25,sizeY*0.25)
      FillPath()
      VectorSourceColor($ff0077ff)
      AddPathBox(part*6.5  ,sizeY, part*0.25,sizeY*0.05)
      AddPathBox(part*6.5  ,sizeY*1.95, part*0.25,sizeY*0.05)
      FillPath()
      VectorSourceColor($ff000000)
      AddPathBox(part*6.5  ,sizeY, part*0.25,sizeY*0.25)
      AddPathBox(part*6.5  ,sizeY*1.75, part*0.25,sizeY*0.25)
      StrokePath(1)
      ;radiador
      VectorSourceColor($ff888888)
      AddPathBox(part*0.5  ,sizeY*1.25, part*0.25,sizeY*0.5)
      FillPath()
      VectorSourceColor($ff000000)
      For p= sizeY*1.25 To sizeY*1.75 Step 4
        MovePathCursor(part*0.5,p)
        AddPathLine(part*0.75,p)
      Next p
      AddPathBox(part*0.5  ,sizeY*1.25, part*0.25,sizeY*0.5)
      StrokePath(1)
      ;luces
      If Random(10)<3
        VectorSourceColor($ffffffff)
        AddPathBox(part*0.5  ,sizeY, part*0.25,sizeY*0.25)
        AddPathBox(part*0.5  ,sizeY*1.75, part*0.25,sizeY*0.25)
        FillPath()
        VectorSourceColor($ff000000)
        AddPathBox(part*0.5  ,sizeY, part*0.25,sizeY*0.25)
        AddPathBox(part*0.5  ,sizeY*1.75, part*0.25,sizeY*0.25)
        StrokePath(1)
        ;intermitentes
          VectorSourceColor($ff0077ff)
          AddPathBox(part*0.5  ,sizeY, part*0.25,sizeY*0.05)
          AddPathBox(part*0.5  ,sizeY*1.95, part*0.25,sizeY*0.05)
          FillPath()
          VectorSourceColor($ff000000)
          AddPathBox(part*0.5  ,sizeY, part*0.25,sizeY*0.05)
          AddPathBox(part*0.5  ,sizeY*1.95, part*0.25,sizeY*0.05)
          StrokePath(1)
      ElseIf Random(10)>2 And Random(10)<6
        VectorSourceColor($ffffffff)
        AddPathCircle(part*0.5  ,sizeY*1.2, sizeY*0.1)
        AddPathCircle(part*0.5  ,sizeY*1.8, sizeY*0.1)
        FillPath()
        VectorSourceColor($ff000000)
        AddPathCircle(part*0.5  ,sizeY*1.2, sizeY*0.1)
        AddPathCircle(part*0.5  ,sizeY*1.8, sizeY*0.1)
        StrokePath(1)
        ;intermitentes
          VectorSourceColor($ff0077ff)
          AddPathCircle(part*0.5  ,sizeY*1.05, part*0.1)
          AddPathCircle(part*0.5  ,sizeY*1.95, part*0.1)
          FillPath()
          VectorSourceColor($ff000000)
          AddPathCircle(part*0.5  ,sizeY*1.05, part*0.1)
          AddPathCircle(part*0.5  ,sizeY*1.95, part*0.1)
          StrokePath(1)
      Else
        VectorSourceColor($ffffffff)
        AddPathCircle(part*0.5  ,sizeY*1.1, sizeY*0.1)
        AddPathCircle(part*0.5  ,sizeY*1.9, sizeY*0.1)
        FillPath()
        VectorSourceColor($ff000000)
        AddPathCircle(part*0.5  ,sizeY*1.1, sizeY*0.1)
        AddPathCircle(part*0.5  ,sizeY*1.9, sizeY*0.1)
        StrokePath(1)
        ;intermitentes
          VectorSourceColor($ff0077ff)
          AddPathCircle(part*0.15  ,sizeY*1.05, part*0.1)
          AddPathCircle(part*0.15  ,sizeY*1.95, part*0.1)
          FillPath()
          VectorSourceColor($ff000000)
          AddPathCircle(part*0.15  ,sizeY*1.05, part*0.1)
          AddPathCircle(part*0.15  ,sizeY*1.95, part*0.1)
          StrokePath(1)
      EndIf
      ;matricula
      VectorSourceColor($ffffffff)
      AddPathBox(part*0.1  ,sizeY*1.3, part*0.2,sizeY*0.4)
      FillPath()
      VectorSourceColor($ffff3300)
      AddPathBox(part*0.1  ,sizeY*1.3, part*0.2,sizeY*0.1)
      FillPath()
      fn= (16 * res) / 32
      VectorFont(FontID(fontLit),fn)
      VectorSourceColor($ffffffff)
      MovePathCursor(part*0.29  ,sizeY*1.32)
      RotateCoordinates(part*0.15  ,sizeY*1.5, 90)
      l= Chr(Random(90,65))
      DrawVectorText(l)
      ResetCoordinates()
      VectorFont(FontID(fontLit),fn)
      VectorSourceColor($ff000000)
      MovePathCursor(part*0.29  ,sizeY*1.45)
      RotateCoordinates(part*0.15  ,sizeY*1.5, 90)
      DrawVectorText(text)
      carMesh()\matricula= l+"-"+text
    StopVectorDrawing()
    Protected ii= GrabImage(i,#PB_Any,part*0.1  ,sizeY*1.3, part*0.2,sizeY*0.4)
    StartVectorDrawing(ImageVectorOutput(i))
      MovePathCursor(part*6.7  ,sizeY*1.7)
      RotateCoordinates(part*0.6  ,sizeY*1.5, 180)
      DrawVectorImage(ImageID(ii))
    StopVectorDrawing()
    carMesh()\tx3d= CreateTexture(#PB_Any,sizeZ,sizeY*2)
    StartDrawing(TextureOutput(carMesh()\tx3d))
      DrawImage(ImageID(i),0,0)
      ;techo corredizo
      If Random(10)>5
        If Random(10)>5
          DrawingMode(#PB_2DDrawing_Default)
          RoundBox((part*3)+10  ,sizeY+5, (part*0.5)-5,sizeY-10,10,10,glass)
        EndIf
        DrawingMode(#PB_2DDrawing_Outlined)
        RoundBox((part*3)+10  ,sizeY+5, (part*0.5)-5,sizeY-10,10,10,$55000000)
      EndIf
    StopDrawing()
    FreeImage(i)
    FreeImage(ii)
    
    carMesh()\mate= CreateMaterial(#PB_Any,TextureID(carMesh()\tx3d))
    MaterialFilteringMode(carMesh()\mate,#PB_Material_Trilinear)

  EndProcedure
  
  Procedure   carFinish(px,py,pz, ang=0, extrude.f=10)
    Protected.f z,y, d
    carMesh()\w= carMesh()\v[0]\z - carMesh()\v[7]\z
    carMesh()\h= carMesh()\v[3]\y - carMesh()\v[0]\y 
    carMesh()\mesh= CreateMesh(#PB_Any)
    ;derecha
    For p= 0 To 7
      z= (1/carMesh()\w) * (carMesh()\v[p]\z + (carMesh()\w / 2) )
      y= (1 - ( (1/carMesh()\h) *  (carMesh()\v[p]\y + Abs(carMesh()\v[0]\y)) ) ) / 2
      carMesh()\v[p]\x= -(extrude/2)
      MeshVertex(carMesh()\v[p]\x,carMesh()\v[p]\y,carMesh()\v[p]\z, z,y,$ffffff)
    Next p
    MeshFace(0,1,2,5)
    MeshFace(2,3,4,5)
    MeshFace(0,5,6,7)
    SetMeshMaterial(carMesh()\mesh,MaterialID(carMesh()\mate),0)
    ;izquierda
    AddSubMesh()
    For p= 0 To 7
      z= (1/carMesh()\w) * (carMesh()\v[p]\z + (carMesh()\w / 2) )
      y= (1 - ( (1/carMesh()\h) *  (carMesh()\v[p]\y + Abs(carMesh()\v[0]\y)) ) ) / 2
      carMesh()\v[p]\x= extrude/2
      MeshVertex(carMesh()\v[p]\x,carMesh()\v[p]\y,carMesh()\v[p]\z, z,y,$ffffff)
    Next p
    MeshFace(5,2,1,0)
    MeshFace(5,4,3,2)
    MeshFace(0,7,6,5)
    SetMeshMaterial(carMesh()\mesh,MaterialID(carMesh()\mate),1)
    
    ;centro
    AddSubMesh()
    For p= 0 To 7 Step 2
      z= (1/7) * p
      y= 0.5
      carMesh()\v[p]\x= -(extrude/2)
      MeshVertex(carMesh()\v[p  ]\x,      carMesh()\v[p  ]\y,carMesh()\v[p]\z,    z,y ,$ffffff)
      MeshVertex(carMesh()\v[p  ]\x,      carMesh()\v[p+1]\y,carMesh()\v[p+1]\z,  z+(1/7),y ,$ffffff)
      MeshVertex(carMesh()\v[p]\x+extrude,carMesh()\v[p+1]\y,carMesh()\v[p+1]\z,  z+(1/7),1 ,$ffffff)
      MeshVertex(carMesh()\v[p]\x+extrude,carMesh()\v[p  ]\y,carMesh()\v[p]\z,    z,1 ,$ffffff)
      MeshFace(a+3,a+2,a+1,a)
      a+4
    Next p
    For p= 1 To 6 Step 2
      z= (1/7) * p
      y= 0.5
      carMesh()\v[p]\x= -(extrude/2)
      MeshVertex(carMesh()\v[p  ]\x,      carMesh()\v[p  ]\y,carMesh()\v[p]\z,    z,y ,$ffffff)
      MeshVertex(carMesh()\v[p  ]\x,      carMesh()\v[p+1]\y,carMesh()\v[p+1]\z,  z+(1/7),y ,$ffffff)
      MeshVertex(carMesh()\v[p]\x+extrude,carMesh()\v[p+1]\y,carMesh()\v[p+1]\z,  z+(1/7),1 ,$ffffff)
      MeshVertex(carMesh()\v[p]\x+extrude,carMesh()\v[p  ]\y,carMesh()\v[p]\z,    z,1 ,$ffffff)
      MeshFace(a+3,a+2,a+1,a)
      a+4
    Next p  
    
    SetMeshMaterial(carMesh()\mesh,MaterialID(carMesh()\mate),2)
    
    FinishMesh(#True)
    NormalizeMesh(carMesh()\mesh)
    BuildMeshShadowVolume(carMesh()\mesh)
    
    carMesh()\enti= CreateEntity(#PB_Any,MeshID(carMesh()\mesh),#Null,px,py,pz)
    RotateEntity(carMesh()\enti,0,ang,0,#PB_Absolute)
    
    ProcedureReturn carMesh()\enti
  EndProcedure
  
  
  ;}
  
  Global borde_col=  $000000
  Global borde_tex=CreateTexture(#PB_Any,32,32) : StartDrawing(TextureOutput(borde_tex)) : Box(0,0,OutputWidth(),OutputHeight(),borde_col) : StopDrawing()
  Global borde_mat=    CreateMaterial(#PB_Any, TextureID(borde_tex))
  MaterialCullingMode(borde_mat,#PB_Material_AntiClockWiseCull)
  DisableMaterialLighting(borde_mat,1)
  
  ;{ CÁMARA Y LUZ
  luz=          CreateLight(#PB_Any,$ffffff,30,50,50,#PB_Light_Point)
  
  
  camara=       CreateCamera(#PB_Any,0,0,100,100)
                MoveCamera(camara,-23,12,20)
                CameraLookAt(camara,0,0,0)
                CameraRange(camara, 0.1,1000)
                CameraBackColor(camara,$555555)
  ;}
                
  ;{ car1
  creaSuelo(500)
  
  x=0:z=0
  For p= 0 To 29
    l= Random(14,10)
    carGenFront(l,-2, l,Random(15,5)*0.1)
    a= Random(7,1)
    b= Random(9,a+1)
    carGenFrontGlass(b,2, a,5)
    a= Random(8,1)
    b= Random(9,a+1)
    carGenBBackGlass(-a,5, -b,2)
    carGenBBack(-l,1, -l,-2)
    carTextura(RGBA(Random(255),Random(255),Random(255),255), $ff774422, 16)
    carFinish(x,3,z+Random(3,1), Random(10)-5, l)
    x+16:If x>32:x=0:z-(32+Random(3)):EndIf
  Next p
  FirstElement(carMesh())
  ;}
  
;---- BUCLE
                
  ;{ BUCLE PRINCIPAL
  Repeat
    ;{ PROCESO EVENTOS
    If pantallaCompleta= 0
      eventosWindows()
    EndIf
    ;}
    
    ExamineKeyboard()
    ExamineMouse()
    eventos3D(camara, 0.1)
    
    spd.f= 0.4
    If KeyboardPushed(#PB_Key_Up)
      MoveEntity(carMesh()\enti,0,0,spd,#PB_Relative)
    ElseIf KeyboardPushed(#PB_Key_Down)
      MoveEntity(carMesh()\enti,0,0,-spd,#PB_Relative)
    EndIf
    If KeyboardPushed(#PB_Key_Left)
      RotateEntity(carMesh()\enti,0,1,0,#PB_Relative)
    ElseIf KeyboardPushed(#PB_Key_Right)
      RotateEntity(carMesh()\enti,0,-1,0,#PB_Relative)
    EndIf
    
    
    ElapsedTime = RenderWorld()
    
    ;{ HUD
    If contador % 25 = 0
      txt.s= "FPS: "+Str(Engine3DStatus(#PB_Engine3D_CurrentFPS)) +#CR$+
             Str(ScreenWidth())+" x "+Str(ScreenHeight()) +#CR$+
             "WASD move" +#CR$+
             "SHIFT fast"
      spr2DText(sprInfo,txt, $ff00ffff)
    EndIf
    DisplayTransparentSprite(sprInfo,ScreenWidth()-110,10)
    ;}
    
    FlipBuffers()
    contador +1
    Delay(1)
  Until sal=1
  ;}
  

change line 540 with this:

Code: Select all

For p= 0 To 299
if you have a good machine, to have 300 cars
If translation=Error: reply="Sorry, Im Spanish": Endif
miso
Enthusiast
Enthusiast
Posts: 466
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: Cars, cars and more cars

Post by miso »

NIce one! Procedural generation is one of my favourite things ;)
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 386
Joined: Thu Jul 09, 2015 9:07 am

Re: Cars, cars and more cars

Post by pf shadoko »

great,

I'm waiting for v2 with wheels
User avatar
minimy
Enthusiast
Enthusiast
Posts: 619
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: Cars, cars and more cars

Post by minimy »

miso wrote: Mon Sep 16, 2024 1:58 pm NIce one! Procedural generation is one of my favourite things ;)
Hey miso, i like procedural generation too. Im trying to make more things like this with buildings, roads, etc. :D
Comming soon :mrgreen:
pf shadoko wrote: Mon Sep 16, 2024 6:57 pm great,

I'm waiting for v2 with wheels
Hey pf shadoko, this cars are for the future, no need wheels :lol:
Was only a test to make other version better. But is true we need wheels.
Every body is waiting for you next amazing demo.

Thanks for comments to both!! :D
If translation=Error: reply="Sorry, Im Spanish": Endif
threedslider
Enthusiast
Enthusiast
Posts: 397
Joined: Sat Feb 12, 2022 7:15 pm

Re: Cars, cars and more cars

Post by threedslider »

Good job on these cars ;)

Nice looking ! And keep it up.

Thanks for sharing.
User avatar
minimy
Enthusiast
Enthusiast
Posts: 619
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: Cars, cars and more cars

Post by minimy »

Hey threeslider! Im glad you like this. Thanks to you for your comments! :D
If translation=Error: reply="Sorry, Im Spanish": Endif
Post Reply