easy : rotate 45° (pi/4) Direct3D8 & VB 
Author Message
 easy : rotate 45° (pi/4) Direct3D8 & VB

x-posted to:
microsoft.public.win32.programmer.directx.graphics;microsoft.public.vb.direc
tx

Hello,

I'm new to DirectX (but not to vb, so don't worry ;-) and I can't get a
simple rotation to work.

Through Direct3D8, I render multiple times 2 triangles in order to form a
square upon the scene, once done, I wish to rotate the whole scene 45
clockwise, the shifting point being the middle of the scene (width /2;
height /2).

The problem is I can't get the scene to rotate, calling device.SetTransform
d3dts..., my_matrix doesn't do anything. I've tried several combinations
(cut & paste from tutorials) but nothing works. I can't set the
transformations of the world, view and projection to anything that works.

Below is some (short) snippets to understand how I render the scene.

Thanks to anybody who can help, as I'm sure this is a common question.
Julien

=====>SNIPPETS<=====
Private Type D3DCUSTOMVERTEX
    X        As Single
    Y        As Single
    Z        As Single '// this is always = 0
    rhw      As Single '// this is always set to 1
    color    As Long
    specular As Long '// this is always
    tu       As Single
    tv       As Single
End Type

Private Const D3DFVF_CUSTOMVERTEX = D3DFVF_XYZRHW Or D3DFVF_TEX1 Or
D3DFVF_DIFFUSE Or D3DFVF_SPECULAR

sub directX_Initialize
        (...)
        '// Window
        With oD3DWindow
            .Windowed = 1&
            .BackBufferCount = 1&
            .BackBufferFormat = oDispMode.Format
            .SwapEffect = D3DSWAPEFFECT_DISCARD
            .EnableAutoDepthStencil = 1&
            .AutoDepthStencilFormat = D3DFMT_D16
        End With

        '// Create the device
        Set oDevice = oDirect3D.CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL, objSurface.hWnd, _

D3DCREATE_HARDWARE_VERTEXPROCESSING, oD3DWindow)

        '// Set device mode
            oDevice.SetRenderState D3DRS_CULLMODE, D3DCULL_NONE '// Turn off

        '// Create the viewport
        With oViewPort
            .MinZ = 0
            .MaxZ = 1
            .X = 0
            .Y = 0
            .Height = m_lSurfPxHeight
            .Width = m_lSurfPxWidth
        End With
        oDevice.SetViewport oViewPort
(...)
End Function

====>RENDER<====
sub render
    oDevice.Clear 0&, ByVal 0&, D3DCLEAR_TARGET, vbBlack, 1#, 0&
    oDevice.BeginScene
    xDraw_DrawBackground
    xDraw_Rotate
    oDevice.EndScene
    oDevice.Present ByVal 0&, ByVal 0&, 0&, ByVal 0&
end sub

Private Sub xDraw_DrawBackground()
    Dim I&, J&
    Dim aVertice(0 To 5) As D3DCUSTOMVERTEX
    Dim oVertexBuffer As DxVBLibA.Direct3DVertexBuffer8
    Dim lVSize&

    lVSize = Len(aVertice(0))
    Set oVertexBuffer = oDevice.CreateVertexBuffer(lVSize * 5, 0&,
D3DFVF_CUSTOMVERTEX, 3DPOOL_DEFAULT)

    oDevice.SetStreamSource 0&, oVertexBuffer, lVSize
    oDevice.SetVertexShader D3DFVF_CUSTOMVERTEX
(...)
            D3DVertexBuffer8SetData oVertexBuffer, 0&, lVSize * 6, 0&,
aVertice(0)
            oDevice.DrawPrimitive D3DPT_TRIANGLELIST, 0&, 2&
        Next
    Next

    Set oVertexBuffer = Nothing
end sub

sub xDraw_Rotate
'// where do i go from here ? thanks for your help
end sub



Mon, 25 Apr 2005 07:55:12 GMT  
 easy : rotate 45° (pi/4) Direct3D8 & VB
[Please do not mail me a copy of your followup]



Quote:
>The problem is I can't get the scene to rotate, calling device.SetTransform
>d3dts..., my_matrix doesn't do anything. I've tried several combinations
>(cut & paste from tutorials) but nothing works. I can't set the
>transformations of the world, view and projection to anything that works.

>Below is some (short) snippets to understand how I render the scene.

>=====>SNIPPETS<=====
>Private Type D3DCUSTOMVERTEX
>    X        As Single
>    Y        As Single
>    Z        As Single '// this is always = 0
>    rhw      As Single '// this is always set to 1
>    color    As Long
>    specular As Long '// this is always
>    tu       As Single
>    tv       As Single
>End Type

>Private Const D3DFVF_CUSTOMVERTEX = D3DFVF_XYZRHW Or D3DFVF_TEX1 Or
>D3DFVF_DIFFUSE Or D3DFVF_SPECULAR

XYZRHW vertices are already transformed into screen space and don't
participate in vertex processing.  YOu need to use XYZ vertices to
have them transformed.
--
Ask me about my upcoming book on Direct3D from Addison-Wesley!
  Direct3D Book <http://www.xmission.com/~legalize/book/>
    izfree: Open source tools for Windows Installer
            <http://izfree.sourceforge.net>


Mon, 25 Apr 2005 07:58:37 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. . 45 degrees rotate

2. Rotate Picturebox 45 degrees ?

3. http://www.vb-world.net/tips/api.html

4. EASY EASY EASY question

5. Bitmap Transparency & Rotate

6. Resize , Move & Rotate Controls

7. TWAIN: Looking for (easy) TWAIN-access-module (16&32bit)

8. Help Wanted: Quick & Easy List Box Saving

9. easiest way to prototype & design reports

 

 
Powered by phpBB® Forum Software