October 28, 2020, 05:33:18 AM

Author Topic: [bb] Wireframe Overlay by David Bird(Birdie) [ 1+ years ago ]  (Read 1173 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
Title : Wireframe Overlay
Author : David Bird(Birdie)
Posted : 1+ years ago

Description : Combine wireframe with solid entities

Code :
Code: BlitzBasic
  1. ;
  2. ; Wireframe for Mixed Modes 3d n 2d
  3. ; David Bird.  dave@birdie72.freeserve.co.uk
  4. ; Warning this is slow at high polys
  5. ;
  6. Graphics3D 640,480
  7. SetBuffer BackBuffer()
  8.  
  9. cam=CreateCamera()
  10. PositionEntity cam,0,0,-4
  11.  
  12. mesh=CreateCylinder(10)
  13. ScaleMesh mesh,1,2,1
  14.  
  15. light=CreateLight(2)
  16. PositionEntity light,-4,4,-4
  17. sphere=CreateSphere()
  18. PositionEntity sphere,-1,0,2
  19.  
  20. While Not KeyDown(1)
  21.         TurnEntity mesh,1.2,1,0
  22.         UpdateWorld
  23.         RenderWorld
  24.         Draw_Wire_2D(mesh,cam)
  25.         Color 255,255,255
  26.         Flip
  27. Wend
  28.  
  29. FreeEntity cam
  30. EndGraphics
  31. End
  32.  
  33. ; Slow method to draw all polys in a mesh
  34. ; Wireframe
  35. ; (c)2001 David Bird
  36. Function Draw_Wire_2D(mesh,cam,red=0,grn=0,blu=0)
  37.         Color red,grn,blu
  38.         If EntityInView(mesh,cam)=False Then Return
  39.         cnt=CountSurfaces(mesh)
  40.         For a=1 To cnt
  41.                 surf=GetSurface(mesh,a)
  42.                 For tri=0 To CountTriangles(surf)-1
  43.                         TFormPoint VertexX(surf,TriangleVertex(surf,tri,0)),VertexY(surf,TriangleVertex(surf,tri,0)),VertexZ(surf,TriangleVertex(surf,tri,0)),mesh,0
  44.                         CameraProject(cam,TFormedX(),TFormedY(),TFormedZ())
  45.                         sx1=ProjectedX()
  46.                         sy1=ProjectedY()
  47.                         TFormPoint VertexX(surf,TriangleVertex(surf,tri,1)),VertexY(surf,TriangleVertex(surf,tri,1)),VertexZ(surf,TriangleVertex(surf,tri,1)),mesh,0
  48.                         CameraProject(cam,TFormedX(),TFormedY(),TFormedZ())
  49.                         sx2=ProjectedX()
  50.                         sy2=ProjectedY()
  51.                         TFormPoint VertexX(surf,TriangleVertex(surf,tri,2)),VertexY(surf,TriangleVertex(surf,tri,2)),VertexZ(surf,TriangleVertex(surf,tri,2)),mesh,0
  52.                         CameraProject(cam,TFormedX(),TFormedY(),TFormedZ())
  53.                         sx3=ProjectedX()
  54.                         sy3=ProjectedY()
  55.                         If Check_Cull_2D(sx1,sy1,sx2,sy2,sx3,sy3)<0
  56.                                 Line sx1,sy1,sx2,sy2
  57.                                 Line sx2,sy2,sx3,sy3
  58.                                 Line sx3,sy3,sx1,sy1   
  59.                         End If
  60.                 Next                   
  61.         Next
  62. End Function
  63.  
  64. ;Check for cw poly
  65. ;returns <0 for clockwise
  66. ;(c)2001 David Bird
  67. Function Check_Cull_2D(x1,y1,x2,y2,x3,y3)
  68.          Return (x1-x2)*(y3-y2)-(y1-y2)*(x3-x2)
  69. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal