help with meshes?

Advanced game related topics
GBeebe
Enthusiast
Enthusiast
Posts: 263
Joined: Sat Oct 09, 2004 6:52 pm
Location: Franklin, PA - USA
Contact:

help with meshes?

Post by GBeebe »

I haven't done much (if any) 3d programming in my life. I think i'm kinda getting the hang of it though. But I have one problem that I can't figure out...

Sprite3D only works in Windows... I want my game to run in both Windows and Linux (without changing the source for either OS).

I have played around with Billboards, but they don't react to any light, and there's an awakward glitch when a new billboard appears behind an older one.

I've tried to make a mesh, which I think is my best bet. but I can't figure it out and mostly get runtime errors.

So, my question is Can someone show me how to make a flat mesh that I can put an image on so it looks like a 2d sprite in my 3d world? Or even point me in the right direction? I've looked that the cubes and other demos/examples that came with PB, but they don't really tutor on that subject.
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - Manul Mesh
;
;    (c) 2003 - Fantaisie Software
;
; ------------------------------------------------------------
;

#CameraSpeed = 5

IncludeFile "Screen3DRequester.pb"

DefType.f KeyX, KeyY, MouseX, MouseY

If InitEngine3D()

  Add3DArchive("Data\"          , #PB_3DArchive_FileSystem)
  Add3DArchive("Data\Skybox.zip", #PB_3DArchive_Zip)
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
  
    ; Create a Plain, manually.. See the DataSetion, for more precisions
    ;
    Restore PlainEntete
    Read   Nbpoint   ; Nombre de Points 
    Read   NbTriangle; Nombre de Triangles 
    CreateMesh(0)
    SetMeshData(0, #PB_Mesh_Vertices     , ?PlainPoints    , Nbpoint)
    SetMeshData(0, #PB_Mesh_Triangles    , ?PlainTriangles , NbTriangle)
    SetMeshData(0, #PB_Mesh_Normals      , ?PlainNormales  , Nbpoint)
    SetMeshData(0, #PB_Mesh_UVCoordinates, ?PlainTextures  , Nbpoint) 
    CreateEntity(0, MeshID(0), CreateMaterial(0, LoadTexture(0,"Data/terrain_texture.jpg" )))
    ;ScrollMaterial(0, 0.2, 0.2, 1)  ; Just for fun, use an animated material
   
    ScaleEntity(0, 128, 1, 128)
    
    CreateCamera(0, 0, 0, 100, 100)
    CameraLocate(0,0,0,20)
    
    Repeat
      Screen3DEvents()
      
      ClearScreen(0, 0, 0)
            
      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
      
      If ExamineMouse()
        MouseX = -(MouseDeltaX()/10)*#CameraSpeed/2
        MouseY = -(MouseDeltaY()/10)*#CameraSpeed/2
      EndIf

      RotateEntity(0, 1, 1, 1)
      
      RotateCamera(0, MouseX, MouseY, RollZ)
      MoveCamera  (0, KeyX, 0, KeyY)
      
      RenderWorld()
      Screen3DStats()      
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or quit = 1
  EndIf
    
Else
  MessageRequester("Error", "The 3D Engine can't be initialized",0)
EndIf
  
End
 
DataSection 
;{/Plain 
PlainEntete: 
Data.l 4 ; Nombre de Points 
Data.l 4 ; Nombre de Triangles 
PlainPoints: 
Data.f -0.5,0,-0.5 
Data.f 0.5,0,-0.5 
Data.f -0.5,0,0.5 
Data.f 0.5,0,0.5 
PlainTriangles: 
Data.w 0,3,1   ;Recto
Data.w 3,0,2   ;Recto 
Data.w 1,3,0   ;Verso
Data.w 2,0,3   ;Verso 
PlainNormales: 
Data.f 0,1,0 
Data.f 0,1,0 
Data.f 0,1,0 
Data.f 0,1,0 
PlainTextures: 
Data.f 0.0,1.0 
Data.f 1.0,1.0 
Data.f 0.0,0.0 
Data.f 1.0,0.0
EndDataSection
And read this

viewtopic.php?t=11527
Please correct my english
http://purebasic.developpez.com/
GBeebe
Enthusiast
Enthusiast
Posts: 263
Joined: Sat Oct 09, 2004 6:52 pm
Location: Franklin, PA - USA
Contact:

ummm

Post by GBeebe »

So, it doesn't matter what order I plot the vertices, but when making "lines" for faces, i have to do them clockwise?

and I HAVE TO make it a closed object by doing the back side as well?

So, can I just go counter-clockwise to close of the back of a rectangle that is made of only 2 triangles?
Post Reply