January 26, 2021, 06:12:39 AM

Author Topic: [bb] 3D sprite 'pixel perfect' by Raul [ 1+ years ago ]  (Read 401 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] 3D sprite 'pixel perfect' by Raul [ 1+ years ago ]
« on: June 29, 2017, 12:28:40 AM »
Title : 3D sprite 'pixel perfect'
Author : Raul
Posted : 1+ years ago

Description : The tip is to place camera at : (screen_width / 2)+0.5 , (screen_height / 2)+0.5 , (screen_width / 2).

Note: probably the Z must be "the largest side / 2" (I only have monitors with width > height).


Code :
Code: BlitzBasic
  1. ;---------------------------------------------------------------------------------------------------------------------------
  2. ;3D SPRITE PIXEL PERFECT example :::: work with 64 128 and 256 pixels combinations 64x64, 256x128, 64x128, ...
  3. ;---------------------------------------------------------------------------------------------------------------------------
  4. Graphics3D 800,600,GraphicsDepth(),6 ;NOTE: Width an Height must be multiple of 2
  5. SetBuffer BackBuffer()
  6. ;---------------------------------------------------------------------------------------------------------------------------
  7. font=LoadFont("arial",18,1)
  8. SetFont font
  9. ;---------------------------------------------------------------------------------------------------------------------------
  10. ;function function function function function function function function function function function function function functi
  11. Function MAKEM(s,x1,x2,y1,y2)
  12.                                                         v0=AddVertex (s,x1,y1,0,0,1)
  13.                                                         v1=AddVertex (s,x2,y1,0,1,1)
  14.                                                         v2=AddVertex (s,x2,y2,0,1,0)
  15.                                                         v3=AddVertex (s,x1,y2,0,0,0)
  16.                                                         AddTriangle (s,v0,v2,v1)
  17.                                                         AddTriangle (s,v0,v3,v2)
  18.                                                         AddTriangle (s,v0,v1,v2)
  19.                                                         AddTriangle (s,v0,v2,v3)
  20. End Function
  21. ;function function function function function function function function function function function function function functi
  22. ;---------------------------------------------------------------------------------------------------------------------------
  23. ;sprite 3D sprite 3D sprite 3D sprite 3D sprite 3D sprite 3D sprite 3D sprite 3D sprite 3D sprite 3D sprite 3D sprite 3D spr
  24.                                                         poly1_tex=CreateTexture(64,128)
  25.                                                         poly1=CreateMesh()
  26.                         EntityFX                poly1,5
  27.                                                         surf=CreateSurface(poly1)
  28.                                                         MAKEM(surf,-32,32,-64,64) ;<-- 'MidHandle'
  29.                         EntityTexture   poly1,poly1_tex
  30.                                                         ;-----------------------------------------
  31.                                                         ;you can load a 64x64 pixels image instead
  32.                                                         ClsColor 200,150,100
  33.                                                         SetBuffer TextureBuffer(poly1_tex)
  34.                                                         Cls
  35.                                                         Rect 0,0,64,128,0
  36.                                                         Text 32,4,"Sprite",1
  37.                                                         Text 32,24,"3D",1
  38.                                                         Text 32,104,"64x128",1
  39.                                                         SetBuffer BackBuffer()
  40.                                                         ;-----------------------------------------
  41. ;sprite 3D sprite 3D sprite 3D sprite 3D sprite 3D sprite 3D sprite 3D sprite 3D sprite 3D sprite 3D sprite 3D sprite 3D spr
  42. ;---------------------------------------------------------------------------------------------------------------------------
  43. ;camera camera camera camera camera camera camera camera camera camera camera camera camera camera camera camera camera came
  44.                                                         cam=CreateCamera()
  45.                         CameraClsMode   cam,False,True
  46.                         PositionEntity  cam,Float#(GraphicsWidth()/2)+.5,-Float#(GraphicsHeight()/2)+.5,-(GraphicsWidth()/2)
  47. ;camera camera camera camera camera camera camera camera camera camera camera camera camera camera camera camera camera came
  48. ;---------------------------------------------------------------------------------------------------------------------------
  49. ClsColor 100,150,200
  50. ;---------------------------------------------------------------------------------------------------------------------------
  51. ;MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAI
  52. While Not KeyDown(1)
  53. Cls
  54. Text 10,10,"Lmouse  to fade"
  55. Text 10,50,"Rmouse  to turn"
  56. Text 10,90,"[space] to flip"
  57. PositionEntity poly1,MouseX(),-MouseY(),0
  58. EntityAlpha    poly1,1-poly1_alpha#
  59. RenderWorld
  60. If MouseDown(1) Then poly1_alpha#=poly1_alpha#+.05 : If poly1_alpha#>1 Then poly1_alpha#=0
  61. If MouseHit(2)  Then TurnEntity poly1,0,0,-90
  62. If KeyHit(57)   Then TurnEntity poly1,0,180,0
  63. Flip
  64. Wend
  65. ;MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAIN MAI
  66. ;---------------------------------------------------------------------------------------------------------------------------
  67. End


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal