November 25, 2020, 05:23:32 AM

Author Topic: [bb] RenderWireFrame by * [ 1+ years ago ]  (Read 533 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] RenderWireFrame by * [ 1+ years ago ]
« on: June 29, 2017, 12:28:40 AM »
Title : RenderWireFrame
Author : *
Posted : 1+ years ago

Description : Render a wireframe representation of any 3d mesh, useful for hud effects etc.

Code :
Code: BlitzBasic
  1. ;RenderWireFrame by EdzUp
  2.  
  3. ;Safe wireframe rendering of a mesh, useful for hud effects.
  4. ;NOTE: this rendering isnt depth specific so you will be able to see the render through ALL
  5. ;3d objects (basically it draws the representation to the screen.
  6.  
  7. ;If you find this useful please give credit where its due ;)
  8.  
  9. Graphics3D 640,480,16
  10. SetBuffer BackBuffer()
  11.  
  12. Global Camera = CreateCamera()
  13.  
  14. AmbientLight 255, 255, 255
  15.  
  16. Global Mesh = CreateSphere( 8 )
  17. AmbientLight 255, 255, 255
  18.  
  19. MoveEntity camera, 0, 0, -5
  20.  
  21. While Not KeyDown(1)
  22.         TurnEntity Mesh, 0, 1, 0
  23.         UpdateWorld
  24.         RenderWorld
  25.         Color 255, 255, 255
  26.         Color 255, 0, 0
  27.         RenderWireFrame( Mesh )
  28.         Flip
  29. Wend
  30. End
  31.  
  32. Function RenderWireFrame( MeshEntity )
  33.        
  34.         Local SC = CountSurfaces( MeshEntity )
  35.         Local Vert1=0, C1X#, C1Y#, C1Z#
  36.         Local Vert2=0, C2X#, C2Y#, C2Z#
  37.         Local Vert3=0, C3X#, C3Y#, C3Z#
  38.  
  39.         For CS = 1 To SC
  40.                 GS = GetSurface( MeshEntity, CS )
  41.                 For CT =0 To CountTriangles( GS )-1
  42.                         Vert1 = TriangleVertex( GS, CT, 0 )
  43.                         Vert2 = TriangleVertex( GS, CT, 1 )
  44.                         Vert3 = TriangleVertex( GS, CT, 2 )
  45.  
  46.                         TFormPoint VertexX#( GS, Vert1 ), VertexY#( GS, Vert1 ), VertexZ#( GS, Vert1 ), MeshEntity, 0
  47.                         CameraProject Camera, TFormedX#(), TFormedY#(), TFormedZ#()
  48.                         C1X# = ProjectedX#()
  49.                         C1Y# = ProjectedY#()
  50.                         C1Z# = ProjectedZ#()
  51.                         TFormPoint VertexX#( GS, Vert2 ), VertexY#( GS, Vert2 ), VertexZ#( GS, Vert2 ), MeshEntity, 0
  52.                         CameraProject Camera, TFormedX#(), TFormedY#(), TFormedZ#()
  53.                         C2X# = ProjectedX#()
  54.                         C2Y# = ProjectedY#()
  55.                         C2Z# = ProjectedZ#()
  56.                         TFormPoint VertexX#( GS, Vert3 ), VertexY#( GS, Vert3 ), VertexZ#( GS, Vert3 ), MeshEntity, 0
  57.                         CameraProject Camera, TFormedX#(), TFormedY#(), TFormedZ#()
  58.                         C3X# = ProjectedX#()
  59.                         C3Y# = ProjectedY#()
  60.                         C3Z# = ProjectedZ#()
  61.                        
  62.                         Line C1X#, C1Y#, C2X#, C2Y#
  63.                         Line C2X#, C2Y#, C3X#, C3Y#
  64.                         Line C3X#, C3Y#, C1X#, C1Y#
  65.                 Next
  66.         Next
  67. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal