home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / Post-Proce2076087182007.psc / clsPostProcessing.cls < prev    next >
Text File  |  2007-07-17  |  5KB  |  264 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "clsPostProcessing"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14.  
  15. Option Explicit
  16.  
  17.  
  18. Private Type structVertex
  19.   pos As D3DVECTOR
  20.   tex0 As D3DVECTOR2
  21.   tex1 As D3DVECTOR2
  22.   tex2 As D3DVECTOR2
  23.   tex3 As D3DVECTOR2
  24.   tex4 As D3DVECTOR2
  25. End Type
  26.  
  27. Private arrStream() As structVertex
  28. Private vBuffer As Direct3DVertexBuffer8
  29.  
  30. Private Const vShader As Long = D3DFVF_XYZ Or D3DFVF_TEX5
  31. Private Const vBytes As Long = 52
  32.  
  33.  
  34. Public Function objCreate5Tap(Width As Long, Height As Long) As Boolean
  35.  
  36.   Static epsWidth As Single
  37.   Static epsHeight As Single
  38.   epsWidth = 0.5 / Width
  39.   epsHeight = 0.5 / Height
  40.  
  41.   ReDim arrStream(0 To 5) As structVertex
  42.   
  43.   With arrStream(0)
  44.     .pos.X = -1
  45.     .pos.Y = 1
  46.     .pos.Z = 0
  47.     .tex0.X = 0 + epsWidth
  48.     .tex0.Y = 0 + epsHeight
  49.     .tex1.X = 0 + 2 * epsWidth
  50.     .tex1.Y = 0 + 2 * epsHeight
  51.     .tex2.X = 0
  52.     .tex2.Y = 0 + 2 * epsHeight
  53.     .tex3.X = 0
  54.     .tex3.Y = 0
  55.     .tex4.X = 0 + 2 * epsWidth
  56.     .tex4.Y = 0
  57.   End With
  58.   
  59.   With arrStream(1)
  60.     .pos.X = 1
  61.     .pos.Y = 1
  62.     .pos.Z = 0
  63.     .tex0.X = 1 + epsWidth
  64.     .tex0.Y = 0 + epsHeight
  65.     .tex1.X = 1 + 2 * epsWidth
  66.     .tex1.Y = 0 + 2 * epsHeight
  67.     .tex2.X = 1
  68.     .tex2.Y = 0 + 2 * epsHeight
  69.     .tex3.X = 1
  70.     .tex3.Y = 0
  71.     .tex4.X = 1 + 2 * epsWidth
  72.     .tex4.Y = 0
  73.   End With
  74.   
  75.   With arrStream(2)
  76.     .pos.X = -1
  77.     .pos.Y = -1
  78.     .pos.Z = 0
  79.     .tex0.X = 0 + epsWidth
  80.     .tex0.Y = 1 + epsHeight
  81.     .tex1.X = 0 + 2 * epsWidth
  82.     .tex1.Y = 1 + 2 * epsHeight
  83.     .tex2.X = 0
  84.     .tex2.Y = 1 + 2 * epsHeight
  85.     .tex3.X = 0
  86.     .tex3.Y = 1
  87.     .tex4.X = 0 + 2 * epsWidth
  88.     .tex4.Y = 1
  89.   End With
  90.   
  91.   arrStream(3) = arrStream(1)
  92.   
  93.   With arrStream(4)
  94.     .pos.X = 1
  95.     .pos.Y = -1
  96.     .pos.Z = 0
  97.     .tex0.X = 1 + epsWidth
  98.     .tex0.Y = 1 + epsHeight
  99.     .tex1.X = 1 + 2 * epsWidth
  100.     .tex1.Y = 1 + 2 * epsHeight
  101.     .tex2.X = 1
  102.     .tex2.Y = 1 + 2 * epsHeight
  103.     .tex3.X = 1
  104.     .tex3.Y = 1
  105.     .tex4.X = 1 + 2 * epsWidth
  106.     .tex4.Y = 1
  107.   End With
  108.   
  109.   arrStream(5) = arrStream(2)
  110.   
  111.   Set vBuffer = objD3DDev.CreateVertexBuffer(vBytes * 2 * 3, 0, vShader, D3DPOOL_DEFAULT)
  112.   D3DVertexBuffer8SetData vBuffer, 0, vBytes * 2 * 3, 0, arrStream(0)
  113.   objCreate5Tap = True
  114.  
  115. End Function
  116.  
  117.     
  118. Public Function objCreate() As Boolean
  119.  
  120.   ReDim arrStream(0 To 5) As structVertex
  121.   
  122.   With arrStream(0)
  123.     .pos.X = -1
  124.     .pos.Y = 1
  125.     .pos.Z = 0
  126.     .tex0.X = 0
  127.     .tex0.Y = 0
  128.     .tex1 = .tex0
  129.   End With
  130.   
  131.   With arrStream(1)
  132.     .pos.X = 1
  133.     .pos.Y = 1
  134.     .pos.Z = 0
  135.     .tex0.X = 1
  136.     .tex0.Y = 0
  137.     .tex1 = .tex0
  138.   End With
  139.   
  140.   With arrStream(2)
  141.     .pos.X = -1
  142.     .pos.Y = -1
  143.     .pos.Z = 0
  144.     .tex0.X = 0
  145.     .tex0.Y = 1
  146.     .tex1 = .tex0
  147.   End With
  148.   
  149.   arrStream(3) = arrStream(1)
  150.   
  151.   With arrStream(4)
  152.     .pos.X = 1
  153.     .pos.Y = -1
  154.     .pos.Z = 0
  155.     .tex0.X = 1
  156.     .tex0.Y = 1
  157.     .tex1 = .tex0
  158.   End With
  159.   
  160.   arrStream(5) = arrStream(2)
  161.   
  162.   Set vBuffer = objD3DDev.CreateVertexBuffer(vBytes * 2 * 3, 0, vShader, D3DPOOL_DEFAULT)
  163.   D3DVertexBuffer8SetData vBuffer, 0, vBytes * 2 * 3, 0, arrStream(0)
  164.   objCreate = True
  165.  
  166. End Function
  167.  
  168.  
  169. Public Function objCreateUser(X1 As Single, Y1 As Single, X2 As Single, Y2 As Single) As Boolean
  170.  
  171.   ReDim arrStream(0 To 5) As structVertex
  172.   
  173.   With arrStream(0)
  174.     .pos.X = X1
  175.     .pos.Y = Y1
  176.     .pos.Z = 0
  177.     .tex0.X = 0
  178.     .tex0.Y = 0
  179.     .tex1 = .tex0
  180.   End With
  181.   
  182.   With arrStream(1)
  183.     .pos.X = X2
  184.     .pos.Y = Y1
  185.     .pos.Z = 0
  186.     .tex0.X = 1
  187.     .tex0.Y = 0
  188.     .tex1 = .tex0
  189.   End With
  190.   
  191.   With arrStream(2)
  192.     .pos.X = X1
  193.     .pos.Y = Y2
  194.     .pos.Z = 0
  195.     .tex0.X = 0
  196.     .tex0.Y = 1
  197.     .tex1 = .tex0
  198.   End With
  199.   
  200.   arrStream(3) = arrStream(1)
  201.   
  202.   With arrStream(4)
  203.     .pos.X = X2
  204.     .pos.Y = Y2
  205.     .pos.Z = 0
  206.     .tex0.X = 1
  207.     .tex0.Y = 1
  208.     .tex1 = .tex0
  209.   End With
  210.   
  211.   arrStream(5) = arrStream(2)
  212.   
  213.   Set vBuffer = objD3DDev.CreateVertexBuffer(vBytes * 2 * 3, 0, vShader, D3DPOOL_DEFAULT)
  214.   D3DVertexBuffer8SetData vBuffer, 0, vBytes * 2 * 3, 0, arrStream(0)
  215.   objCreateUser = True
  216.  
  217. End Function
  218.  
  219.  
  220. Public Function objRender() As Boolean
  221.  
  222.   On Error Resume Next
  223.  
  224.   With objD3DDev
  225.     
  226.     Static matWorld As D3DMATRIX
  227.     Static matView As D3DMATRIX
  228.     Static matProjection As D3DMATRIX
  229.     D3DXMatrixIdentity matWorld
  230.     D3DXMatrixIdentity matView
  231.     D3DXMatrixIdentity matProjection
  232.     .SetTransform D3DTS_WORLD, matWorld
  233.     .SetTransform D3DTS_VIEW, matView
  234.     .SetTransform D3DTS_PROJECTION, matProjection
  235.  
  236.     .SetVertexShader vShader
  237.     .SetStreamSource 0, vBuffer, vBytes
  238.     .SetRenderState D3DRS_ZENABLE, 0
  239.     .DrawPrimitive D3DPT_TRIANGLELIST, 0, 2
  240.     .SetRenderState D3DRS_ZENABLE, 1
  241.     
  242.   End With
  243.   
  244.   If Not Err.Number = 0 Then
  245.     Err.Clear
  246.     objRender = False
  247.   Else
  248.     objRender = True
  249.   End If
  250.   
  251. End Function
  252.  
  253.  
  254. Public Function memClear() As Boolean
  255.  
  256.   Erase arrStream()
  257.   Set vBuffer = Nothing
  258.   
  259.   memClear = True
  260.   
  261. End Function
  262.  
  263.  
  264.