News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

directx tutorial pages

Started by dancho, December 07, 2006, 04:19:22 PM

Previous topic - Next topic

dancho

atm Im learnig how to code some directx stuff and in the process I found
this great tutorial about directx...

check it out: http://www.directtutorial.com/index.php

btw,if you need some help pm me,
I have done lesson 1 and lesson 2   :bg


dancho

well I have a problem with lesson 5 - http://www.directtutorial.com/DX9/Direct3D/dx9-B5.php#still

this is C++ line that I dont understand...

static float index = 0.0f; index+=0.05f;    // an ever-increasing float value

comment said an ever-increasing float value but there isnt any loop around,
how it can be ever increasing ??

thx for help

   

TNick

As far as I know all that statement does is to increase ONCE the value of index by 0.05.
Maybe there was a
for (static float index = 0.0f; index+=0.05f)
{

}

PS: I don't know C very good, some mistakes may be there.
Regards,
Nick

dancho

this is render frame function from tutorial:

void render_frame(void)
{
    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

    d3ddev->BeginScene();

    // select which vertex format we are using
    d3ddev->SetFVF(CUSTOMFVF);

    // SET UP THE PIPELINE

    D3DXMATRIX matRotateY;    // a matrix to store the rotation information

    static float index = 0.0f; index+=0.05f;    // an ever-increasing float value

    // build a matrix to rotate the model based on the increasing float value
    D3DXMatrixRotationY(&matRotateY, index);

    // tell Direct3D about our matrix
    d3ddev->SetTransform(D3DTS_WORLD, &matRotateY);

    D3DXMATRIX matView;    // the view transform matrix

    D3DXMatrixLookAtLH(&matView,
                       &D3DXVECTOR3 (0.0f, 0.0f, 10.0f),    // the camera position
                       &D3DXVECTOR3 (0.0f, 0.0f, 0.0f),    // the look-at position
                       &D3DXVECTOR3 (0.0f, 1.0f, 0.0f));    // the up direction

    d3ddev->SetTransform(D3DTS_VIEW, &matView);    // set the view transform to matView

    D3DXMATRIX matProjection;     // the projection transform matrix

    D3DXMatrixPerspectiveFovLH(&matProjection,
                               D3DXToRadian(45),    // the horizontal field of view
                               SCREEN_WIDTH / SCREEN_HEIGHT,     // the aspect ratio
                                              1.0f,    // the near view-plane
                               100.0f);    // the far view-plane

    d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);    // set the projection

    // select the vertex buffer to display
    d3ddev->SetStreamSource(0, t_buffer, 0, sizeof(CUSTOMVERTEX));

    // copy the vertex buffer to the back buffer
    d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

    d3ddev->EndScene();

    d3ddev->Present(NULL, NULL, NULL, NULL);

    return;
}


and this is mine render frame function in masm:

Render_Frame proc ;this is the function used to render a single frame
LOCAL matRotateY:D3DXMATRIX ;a matrix to store the rotation information
LOCAL matView:D3DXMATRIX ;the view transform matrix
LOCAL matProjection:D3DXMATRIX ;the projection transform matrix

cinvoke d3ddev,Clear,0,NULL,D3DCLEAR_TARGET,($D3DCOLOR_XRGB(0,0,0)),var1,0
cinvoke d3ddev,BeginScene ;begins the 3D scene

;select which vertex format we are using
cinvoke d3ddev,SetFVF,CUSTOMFVF

;SET UP THE PIPELINE

                fld    index0 ;load 0.0
                fadd index1 ;add 0.05
                fst index     ;store in index
;build a matrix to rotate the model based on the increasing float value
;invoke D3DXMatrixRotationY,addr matRotateY,index

;tell Direct3D about our matrix
cinvoke d3ddev,SetTransform,D3DTS_WORLD,addr matRotateY

invoke D3DXMatrixLookAtLH,addr matView,addr argm1,addr argm2,addr argm3

;set the view transform to matView
    cinvoke d3ddev,SetTransform,D3DTS_VIEW,addr matView                                        
                                                 
    invoke D3DXMatrixPerspectiveFovLH,addr matProjection,var3,AR,var1,var2   
   
    ;set the projection
    cinvoke d3ddev,SetTransform,D3DTS_PROJECTION,addr matProjection                                                 

;select the vertex buffer to display
cinvoke d3ddev,SetStreamSource,0,t_buffer,0,sizeof CUSTOMVERTEX

;copy the vertex buffer to the back buffer
cinvoke d3ddev,DrawPrimitive,D3DPT_TRIANGLELIST,0,1


cinvoke d3ddev,EndScene ;ends the 3D scene
    cinvoke d3ddev,Present,NULL,NULL,NULL,NULL ;displays the created frame

ret
Render_Frame endp


and with this code I just dont get rotating triangle,
just static one...

Synfire

Quote from: dancho on December 08, 2006, 06:05:34 PMwell I have a problem with lesson 5 - http://www.directtutorial.com/DX9/Direct3D/dx9-B5.php#still

this is C++ line that I dont understand...

static float index = 0.0f; index+=0.05f;    // an ever-increasing float value

comment said an ever-increasing float value but there isnt any loop around,
how it can be ever increasing ??

thx for help

It is within a loop. Remember that this function gets called repeatedly by the message loop. See, the static float index = 0.0f; is only executed the first time the procedure is ran. This means that each time the procedure is called, the value is incremented by 0.05f which is causes the rotation. Static variables are similiar to global variables in that they keep their value through subsequent calls. The major difference is that they can't be used by other procedures within the program because they are still defined as local. If you are going to do this in assembly, just create the index variable in your .data section and don't worry about the ideas of "static vs global". It's more of a compiler convention anyways.

Regards,
Bryant Keller

EDIT: A buddy of mine passed me this page which might explain static variables a little better for you.

dancho

@Synfire
I created index variable in data section but it doesnt work for me...

but still this msg loop is quit interesting,I never seen nothing like that before...

while(TRUE)
    {
        DWORD starting_point = GetTickCount();

        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            if (msg.message == WM_QUIT)
                break;

            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

        render_frame();

        // check the 'escape' key
        if(KEY_DOWN(VK_ESCAPE))
            PostMessage(hWnd, WM_DESTROY, 0, 0);

        while ((GetTickCount() - starting_point) < 25);
    }

    // clean up DirectX and COM
    cleanD3D();


What GetTickCount function doing in msg loop ?!

EduardoS

Slowing down the code  :wink
For some reason the author wants at least 25 ticks between two frames.

Synfire

Quote from: dancho on December 08, 2006, 08:18:41 PM@Synfire
I created index variable in data section but it doesnt work for me...

Change

                fld    index0 ;load 0.0
                fadd index1 ;add 0.05
                fst index     ;store in index


To

                fld    index ; load index
                fadd index1 ;add 0.05 to index
                fst index     ;update index


What you were doing is represented by the expression 'index = 0.0 + 0.05' whereas what you need to be doing is 'index = index + 0.05' where index is a variable in the data section whose original value is 0.0.

Quote from: dancho on December 08, 2006, 08:18:41 PMbut still this msg loop is quit interesting,I never seen nothing like that before...

CODE OMMITTED

What GetTickCount function doing in msg loop ?!

That is the standard method used for game programming. When doing games, you want your loop to be fairly consistant across multiple processors. Since processors will execute code at different speeds, game programmers tend to use GetTickCount to stall the loop so the refresh rate of their game will be consistant. The line while ((GetTickCount() - starting_point) < 25); lets us know that this game should display a frame (ie update it's screen) every 25ms no matter what the system's processor speed is.

Hope this helps,
Bryant Keller

EDIT:
To extend on what I wasy saying about the delay. Think of it like this. Say you have a game which an object is supposed to rotate at a steady pace, such as your triangle in this example. If you did a normal message loop, the triangle would rotate at the speed that your processor executed your message loop. Therefore, on an AMD-K6 the triangle would slowly rotate while on a PIV the triangle would rotate a LOT faster. With this stall, it makes the triangle rotate at the same speed on both systems. I learned this the hard way while coding an RPG as a project for a friend of mine. On my system, the character walked along fine and game play seemed to be perfect. But when my friend got a copy, one push of the direction key would send the character flying across the screen. This is because I developed the game on an old 486 machine while he played it on a Prescott. Adding the GetTickCount() stall fixed the problem and made the RPG run smoothly across both platforms.

dancho

@Synfire
thx for help,but
now I think that my msg loop is where problem is...

      invoke GetTickCount
mov starting_point,eax
.repeat
invoke PeekMessage,addr msg,NULL,0,0,PM_REMOVE
.if (eax)
.if msg.message==WM_QUIT
.break
.endif
invoke TranslateMessage,addr msg
invoke DispatchMessage,addr msg
invoke Render_Frame
invoke GetAsyncKeyState,VK_ESCAPE
.if eax!=0
invoke PostMessage,hWnd,WM_DESTROY,0,0
.endif
.endif
invoke GetTickCount
sub eax,starting_point
.until eax<25


I just dont know did I translate this loop right...
from tutorial (C++)

while(TRUE)
    {
        DWORD starting_point = GetTickCount();
        .
        .
        .
while ((GetTickCount() - starting_point) < 25);

EduardoS

No... You don't translate it right...

invoke GetTickCount
mov starting_point,eax
.repeat
invoke PeekMessage,addr msg,NULL,0,0,PM_REMOVE
.if (eax)
.if msg.message==WM_QUIT
.break
.endif
invoke TranslateMessage,addr msg
invoke DispatchMessage,addr msg
invoke Render_Frame
invoke GetAsyncKeyState,VK_ESCAPE
.if eax!=0
invoke PostMessage,hWnd,WM_DESTROY,0,0
.endif
.endif

.repeat
invoke GetTickCount
sub eax,starting_point
.until eax > 24; while ((GetTickCount() - starting_point) < 25);

.until 0; while(TRUE) ins't it?

dancho

@EduardoS
thx for reply,but it doesnt work...

anyway,
I submit full RadAsm project,so if anyone else wanna give it a try,good luck...

ps
you will need latest dx9.0c revision...


[attachment deleted by admin]

TheGreatJason

Cool, DirectX tutorials!  I will try these too.  Might as well start at lesson 1 since I haven't tried DirectX before...  I'll tell you when I get 5 to work in assembly.  And I don't have any of the .NET tools so I can't try those really...

If I manage to get the whole set working in MASM I will upload it here.  I hope it isn't too hard...  Well, I do have dx9.0c and a 3D accelerator graphics card which is a good start really! :bg (Even though I am stuck with this 800MHz Pentium III... :()

Edit: Oh yeah I need the DirectX SDK stuff.  Only 506MB of it like...  A couple of hours before I can actually start...


Synfire

dancho,

Where did you get the masm directx9 include files from.

include d3d9_.inc
include d3dx9math_.inc
include d3d9caps_.inc
include d3d9types_.inc
include d3dx9core_.inc


I've gotten the lib files, but I still need to hunt down the include files. I primarily do any 3D stuff with OpenGL so this machine isn't really equiped to handle the DirectX project.

dancho

those inc files are from 2 sources,
part from ObjAsm,part from DSDK,
all with some my modification to them to
accept ariel's macros...( stdmethod,cinvoke,com,lcom)

[attachment deleted by admin]