Results 1 to 5 of 5

Thread: [RESOLVED] Rotate Matrix

  1. #1

    Thread Starter
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Resolved [RESOLVED] Rotate Matrix

    Ok i don't know anything about DX8 and probably never will but for some reason i'm going ok (i've been learning from JR's Tutorial + another one i found on the net). I'm currently stuck rotating a simple 2D square. The problem seems to be in the way i initialise DX8 cause if i use code out of examples it works, but if i try and write the code it doesn't . I'm guessing its something very simple but i can't seem to figure it out.




    VB Code:
    1. Public Const COLOR_DEPTH_16_BIT As Long = D3DFMT_R5G6B5
    2. Public Const COLOR_DEPTH_24_BIT As Long = D3DFMT_A8R8G8B8
    3. Public Const COLOR_DEPTH_32_BIT As Long = D3DFMT_X8R8G8B8
    4.  
    5. Public DirectX8 As DirectX8 'The master DirectX object.
    6. Public Direct3D As Direct3D8 'Controls all things 3D.
    7. Public Direct3DX As D3DX8
    8. Public Direct3D_Device As Direct3DDevice8 'Represents the hardware rendering.
    9.  
    10. Public Sub StartDirectX(MainForm As Form, ScreenWidth As Single, ScreenHeight As Single, ColourDepth As Single, FullScreen As Boolean)
    11. On Error GoTo errmsg
    12.  
    13.     Dim Display_Mode As D3DDISPLAYMODE 'Display mode desciption.
    14.     Dim Direct3D_Window As D3DPRESENT_PARAMETERS 'Backbuffer and viewport description.
    15.    
    16.     Set DirectX8 = New DirectX8 'Creates the DirectX object.
    17.     Set Direct3D = DirectX8.Direct3DCreate() 'Creates the Direct3D object using the DirectX object.
    18.        
    19.    
    20.     'Now that we are working with fullscreen mode, we must set up the
    21.     'screen resolution to switch to, rather than use the default screen
    22.     'resolution.
    23.     Select Case ColourDepth
    24.         Case 16
    25.             Display_Mode.Format = COLOR_DEPTH_16_BIT
    26.         Case 24
    27.             Display_Mode.Format = COLOR_DEPTH_24_BIT
    28.         Case 32
    29.             Display_Mode.Format = COLOR_DEPTH_32_BIT
    30.         Case Else
    31.             MsgBox "Invalid Colour Depth. Using Defualt"
    32.             Display_Mode.Format = COLOR_DEPTH_16_BIT
    33.     End Select
    34.    
    35.         Display_Mode.Width = ScreenWidth
    36.         Display_Mode.Height = ScreenHeight
    37.        
    38.         Direct3D_Window.BackBufferCount = 1 '1 backbuffer only
    39.         Direct3D_Window.BackBufferFormat = Display_Mode.Format 'Sets the format that was retrieved into the backbuffer.
    40.         Direct3D_Window.BackBufferWidth = Display_Mode.Width 'Match the backbuffer width with the display width
    41.         Direct3D_Window.BackBufferHeight = Display_Mode.Height 'Match the backbuffer height with the display height
    42.         Direct3D_Window.hDeviceWindow = MainForm.hWnd 'Use frmMain as the device window.
    43.         Direct3D_Window.AutoDepthStencilFormat = D3DFMT_D16
    44.        
    45.    
    46.     If FullScreen = True Then
    47.         Direct3D_Window.Windowed = False 'The app will be in fullscreen mode.
    48.     Else
    49.    
    50.         'Direct3D.GetAdapterDisplayMode D3DADAPTER_DEFAULT, Display_Mode 'Use the current display mode that you
    51.                                                                         'are already on. Incase you are confused, I'm
    52.                                                                         'talking about your current screen resolution. ;)
    53.        
    54.         Direct3D_Window.Windowed = True 'The app will be in windowed mode.
    55.    
    56.     End If
    57.    
    58.     Direct3D_Window.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC 'Refresh when the monitor does.
    59.      
    60.    
    61.     'Creates the rendering device with some useful info, along with the info
    62.     'we've already setup for Direct3D_Window.
    63.     Set Direct3D_Device = Direct3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, MainForm.hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, Direct3D_Window)
    64.  
    65.        
    66.     Direct3D_Device.SetVertexShader FVF_TLVERTEX 'Set the type of vertex shading. (Required)
    67.    
    68.     'Direct3D_Device.SetRenderState D3DRS_SRCBLEND, D3DBLEND_SRCALPHA
    69.     Direct3D_Device.SetRenderState D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA
    70.     Direct3D_Device.SetRenderState D3DRS_ALPHABLENDENABLE, True
    71.    
    72.     Direct3D_Device.SetRenderState D3DRS_LIGHTING, 0   '//Disable lighting.
    73.     Direct3D_Device.SetRenderState D3DRS_ZENABLE, 1
    74.     Direct3D_Device.SetRenderState D3DRS_CULLMODE, D3DCULL_NONE
    75.    
    76.    
    77.     Direct3D_Device.SetTextureStageState 0, D3DTSS_MINFILTER, D3DTEXF_POINT
    78.     Direct3D_Device.SetTextureStageState 0, D3DTSS_MAGFILTER, D3DTEXF_POINT
    79.    
    80.     Running = True 'Initializations all set. It's now ok to activate the game loop.
    81.    
    82.    
    83.    
    84. '    '//configure the world matrices
    85. '
    86. '    '//1. The World Matrix
    87. '    D3DXMatrixIdentity matWorld
    88. '    Direct3D_Device.SetTransform D3DTS_WORLD, matWorld 'commit this matrix to the device
    89. '
    90. '    '//2. The View Matrix
    91. '    D3DXMatrixLookAtLH matView, MakeVector(0, 5, 2), MakeVector(0, 0, 0), MakeVector(0, 1, 0)
    92. '    Direct3D_Device.SetTransform D3DTS_VIEW, matView
    93. '
    94. '    '//3. The projection Matrix
    95. '    D3DXMatrixPerspectiveFovLH matProj, pi / 3, 1, 0.1, 75
    96. '    Direct3D_Device.SetTransform D3DTS_PROJECTION, matProj
    97.    
    98.    
    99.    
    100.     MainForm.GameLoop
    101.    
    102. Exit Sub
    103. errmsg:
    104. MsgBox "Error number " & Err.Number & vbNewLine & Err.Description
    105. Running = False
    106. CloseDirectX
    107. End Sub
    and to start DX i use
    VB Code:
    1. StartDirectX Me, 1024, 768, 16, True
    to rotate i use
    VB Code:
    1. D3DXMatrixIdentity matWorld
    2.    
    3.     D3DXMatrixIdentity matTemp
    4.     D3DXMatrixRotationX matTemp, Angle * RAD
    5.     D3DXMatrixMultiply matWorld, matWorld, matTemp
    6.    
    7.     D3DXMatrixIdentity matTemp
    8.     D3DXMatrixRotationY matTemp, Angle * RAD
    9.     D3DXMatrixMultiply matWorld, matWorld, matTemp
    10.    
    11.     D3DXMatrixIdentity matTemp
    12.     D3DXMatrixRotationZ matTemp, Angle * RAD
    13.     D3DXMatrixMultiply matWorld, matWorld, matTemp
    14.    
    15.     Angle = Angle + 1
    16.    
    17.     Direct3D_Device.SetTransform D3DTS_WORLD, matWorld

    Thanks

  2. #2
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Rotate Matrix

    Those rotation functions only work with 3D vertices. They will not affect 2D vertices at all, which is why it must be done manually.

  3. #3

    Thread Starter
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Rotate Matrix

    But it works perfectly if i use a different way to initialise DX8.
    If i use this then i'm able to rotate the square, i just don't know what i'm missing

    (from a tutorial on the web)
    VB Code:
    1. Public Function Initialise() As Boolean
    2. On Error GoTo ErrHandler:
    3.  
    4.  
    5.  
    6. Dim DispMode As D3DDISPLAYMODE '//Describes our Display Mode
    7. Dim Direct3D_Window As D3DPRESENT_PARAMETERS 'Backbuffer and viewport description.
    8.  
    9. Set DirectX8 = New DirectX8  '//Create our Master Object
    10. Set Direct3D = DirectX8.Direct3DCreate() '//Let our Master Object create the Direct3D Interface
    11.  
    12. '##################
    13. '##  FULLSCREEN MODE ##
    14. '#################
    15.  
    16.  
    17. DispMode.Format = D3DFMT_R5G6B5
    18. Debug.Print "CHECKDISP(1024,768,16) = ", DispMode.Format, D3DFMT_UNKNOWN
    19. If DispMode.Format > D3DFMT_UNKNOWN Then
    20.     '640x480x32 is supported
    21.     Debug.Print "USING 1024x480x32 Display Mode"
    22.     DispMode.Width = 1024: DispMode.Height = 768
    23. End If
    24.  
    25. Direct3D_Window.BackBufferCount = 1
    26. Direct3D_Window.BackBufferFormat = DispMode.Format
    27. Direct3D_Window.BackBufferWidth = DispMode.Width
    28. Direct3D_Window.BackBufferHeight = DispMode.Height
    29. Direct3D_Window.hDeviceWindow = frmmain.hWnd
    30. Direct3D_Window.AutoDepthStencilFormat = D3DFMT_D16
    31. 'Direct3D_Window.EnableAutoDepthStencil = 1
    32. Direct3D_Window.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC
    33.  
    34.  
    35. '//This line creates a device that uses a hardware device if possible; software vertex processing and uses the form as it's target
    36. '//See the lesson text for more information on this line...
    37. Set Direct3D_Device = Direct3D.CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, _
    38.                                                     frmmain.hWnd, _
    39.                                                     D3DCREATE_SOFTWARE_VERTEXPROCESSING, _
    40.                                                         Direct3D_Window)
    41.                                                        
    42. '//Configure the rendering device
    43. Direct3D_Device.SetVertexShader FVF_LVERTEX '//Tell it what type of vertex we are using
    44. Direct3D_Device.SetRenderState D3DRS_LIGHTING, 0  '//Disable lighting.
    45. Direct3D_Device.SetRenderState D3DRS_ZENABLE, 1
    46. Direct3D_Device.SetRenderState D3DRS_CULLMODE, D3DCULL_NONE
    47.  
    48.  
    49. 'InitialiseGeometry '//Setup the vertices
    50.  
    51. Initialise = True '//We succeeded
    52. Exit Function
    53.  
    54. ErrHandler:
    55. Debug.Print "Error Number Returned: " & Err.Number, Err.Description
    56. Initialise = False

  4. #4
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: Rotate Matrix

    Which line of code from that will allow you to rotate the square using the built in functions? Might as well play around with commenting/uncommenting some lines out.

  5. #5

    Thread Starter
    Frenzied Member Andrew G's Avatar
    Join Date
    Nov 2005
    Location
    Sydney
    Posts
    1,587

    Re: Rotate Matrix

    Don't worry i fixed the problem. Cause i'm blind i missed something. Instead of

    Direct3D_Device.SetVertexShader FVF_LVERTEX

    I should have used

    Direct3D_Device.SetVertexShader FVF_VERTEX

    Thanks anyway for the help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width