home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / LordLucifer / win32asm / files / TasmD3DRMdemo.ZIP / d3drotate.asm next >
Encoding:
Assembly Source File  |  1999-08-13  |  12.9 KB  |  402 lines

  1. ; Direct3D Fullscreen Application
  2. ; by Minde, montana@is.lt (c) 1999.08.12
  3.  
  4. .386
  5. .MODEL  FLAT, STDCALL
  6.  
  7. ;// INCLUDES ///////////////////////////////////////////////
  8. .const
  9. include winerror.inc
  10. include include.inc
  11. include tddraw.inc
  12. include td3dtypes.inc
  13. include td3drmdef.inc
  14. include td3drmobj.inc
  15. include td3drm.inc
  16.  
  17. ;// PROTOTYPES /////////////////////////////////////////////
  18. Setup3D         PROCDESC STDCALL
  19. CreateScene     PROCDESC STDCALL
  20. OnDestroy       PROCDESC STDCALL
  21. UpdateScreen    PROCDESC STDCALL
  22. ScaleMesh       PROCDESC STDCALL :DWORD, :DWORD
  23.  
  24. .data
  25. ;// GLOBALS ////////////////////////////////////////////////
  26. ddraw       DD 0;
  27. primsurf    DD 0;
  28. backsurf    DD 0;
  29. zbufsurf    DD 0;
  30.  
  31. d3drm       DD 0;
  32. scene       DD 0;
  33. camera      DD 0;
  34. device      DD 0;
  35. viewport    DD 0;
  36. meshbuilder DD 0;
  37.  
  38. szAppName       DB "FULL3D",0
  39.  
  40. modewidth   = 640;
  41. modeheight  = 480;
  42. modedepth   = 16;
  43.  
  44. .data?
  45. hWnd            DD ?
  46. hThisInstance   DD ?
  47. lpCmdLine       DD ?
  48. nCmdShow        SDWORD ?
  49. msg             MSGSTRUCT <?>
  50. wc              WNDCLASS <?>
  51. desc            DDSURFACEDESC <?>
  52. ddscaps         DDSCAPS <?>
  53.  
  54.  
  55. .code
  56. Start:  call  GetModuleHandleA, NULL   ; get our module's handle
  57.         mov hThisInstance, eax
  58.         call  GetCommandLineA      ; and the command line
  59.         mov lpCmdLine, eax
  60.         mov nCmdShow, SW_SHOWDEFAULT
  61.  
  62.         call WinMain, hThisInstance, 0, lpCmdLine, nCmdShow
  63.         call ExitProcess, eax    ; eax == Exit Code
  64.  
  65. ;/////////////////////////////////////////////////////////////////////////////
  66. ;/////////////////////////////////////////////////////////////////////////////
  67. WinMain PROC STDCALL, hInst:DWORD, hPrevInst:DWORD, lpszCmdParam:DWORD, CmdShow:SDWORD
  68.         call InitWindow, hThisInstance, nCmdShow
  69.         .IF eax == FALSE
  70.             dec eax
  71.             ret
  72.         .ENDIF
  73.         call Setup3D
  74.         .IF eax == FALSE
  75.             dec eax
  76.             ret
  77.         .ENDIF
  78.         call CreateScene
  79.         .IF eax == FALSE
  80.             dec eax
  81.             ret
  82.          .ENDIF
  83.         .WHILE TRUE
  84.             call PeekMessageA, offset msg, NULL,0,0,PM_NOREMOVE
  85.             .IF eax != 0
  86.                 call GetMessageA, offset msg, NULL, 0, 0
  87.                 .BREAK .IF eax == 0
  88.                 call TranslateMessage, offset msg
  89.                 call DispatchMessageA, offset msg   
  90.             .ELSE
  91.                 call UpdateScreen
  92.             .ENDIF
  93.         .ENDW
  94.         mov eax, msg.msg_wParam
  95.         ret
  96. WinMain ENDP
  97. ;//////////////////////////////////////////////////////////////////////////////
  98. ;//////////////////////////////////////////////////////////////////////////////
  99. WndFunc PROC STDCALL, hwnd:DWORD, wmsg:DWORD, wParam:DWORD, lParam:DWORD
  100.     mov eax, [wmsg]
  101.     .if eax == WM_KEYDOWN
  102.             mov eax, wParam
  103.             .if eax == VK_ESCAPE
  104.                 call OnDestroy
  105.                 call PostQuitMessage, 0
  106.                 return0
  107.             .endif
  108.             return1
  109.     .elseif eax == WM_DESTROY
  110.             call OnDestroy
  111.             call PostQuitMessage, 0
  112.             return0
  113.     .else
  114.             call DefWindowProcA, hwnd, wmsg, wParam, lParam
  115.             ret
  116.     .endif
  117. WndFunc ENDP
  118. ;//////////////////////////////////////////////////////////////////////////
  119. ;//////////////////////////////////////////////////////////////////////////
  120. OnDestroy PROC
  121.     .if (ddraw != 0)
  122.         mcall [ddraw],DDRelease
  123.         mov ddraw, 0
  124.     .endif
  125.     .if (primsurf != 0)
  126.         mcall [primsurf], DDRelease
  127.         mov primsurf, 0
  128.     .endif
  129.     .if (backsurf != 0)
  130.         mcall [backsurf],DDRelease
  131.         mov backsurf, 0
  132.     .endif
  133.     .if (zbufsurf != 0)
  134.         mcall [zbufsurf],DDRelease
  135.         mov zbufsurf, 0
  136.     .endif
  137.     .if (d3drm != 0)
  138.         mcall [d3drm],DDRelease
  139.         mov d3drm, 0
  140.     .endif
  141.     .if (scene != 0)
  142.         mcall [scene], DDRelease
  143.         mov scene, 0
  144.     .endif
  145.     .if (camera != 0)
  146.         mcall [camera], DDRelease
  147.         mov camera, 0
  148.     .endif
  149.     .if (device != 0)
  150.         mcall [device], DDRelease
  151.         mov device, 0
  152.     .endif
  153.     .if (viewport != 0)
  154.         mcall [viewport], DDRelease
  155.         mov viewport, 0
  156.     .endif
  157.     .if (meshbuilder != 0)
  158.         mcall [meshbuilder], DDRelease
  159.         mov meshbuilder, 0
  160.     .endif
  161.     ret
  162. OnDestroy ENDP
  163. ;//////////////////////////////////////////////////////////////////////////
  164. ;//////////////////////////////////////////////////////////////////////////
  165. InitWindow  PROC
  166.         mov wc.style, CS_DBLCLKS
  167.         mov eax, offset WndFunc
  168.         mov wc.lpfnWndProc, eax ;       //the windows message handling function  
  169.         mov wc.cbClsExtra, 0;         //not used anymore 
  170.         mov wc.cbWndExtra, 0;         //not used anymore 
  171.         mov eax, hThisInstance
  172.         mov wc.hInstance, eax   ;     //you can run the windows programs more than once, which one is this
  173.         call LoadIconA, 0, IDI_APPLICATION
  174.         mov wc.hIcon, eax       ;  //icon used for window
  175.         call LoadCursorA, 0, IDC_ARROW
  176.         mov wc.hCursor, eax     ;      //type of mouse cursor used
  177.         call GetStockObject, BLACK_BRUSH
  178.         mov wc.hbrBackground, eax ;      //background color of window
  179.         mov wc.lpszMenuName, NULL;                  //not used
  180.         mov wc.lpszClassName, offset  szAppName;             //name for this windows class   
  181.         call RegisterClassA,  offset wc
  182.         call CreateWindowExA, \
  183.                     WS_EX_TOPMOST, \
  184.                     offset szAppName, \
  185.                     offset szAppName, \
  186.                     WS_VISIBLE | WS_POPUP, \
  187.                     CW_USEDEFAULT,\         
  188.                     CW_USEDEFAULT, \        
  189.                     modewidth,   \
  190.                     modeheight,  \
  191.                     NULL,         \         
  192.                     NULL,         \         
  193.                     hThisInstance,\        
  194.                     NULL
  195.         mov hWnd, eax
  196.         .if eax == FALSE
  197.             ret
  198.         .endif
  199.         call ShowWindow, hwnd, nCmdShow
  200.         call UpdateWindow, hwnd
  201.         call ShowCursor, FALSE
  202.         ret
  203. InitWindow  ENDP
  204. ;//////////////////////////////////////////////////////////////////////////
  205. ;//////////////////////////////////////////////////////////////////////////
  206. Setup3D PROC
  207. ;    //create d3d retained mode interface
  208.     call Direct3DRMCreate, offset d3drm
  209.  
  210. ;    //create directdraw interface
  211.     call DirectDrawCreate, 0, offset ddraw, 0
  212.     mcall [ddraw], DDSetCooperativeLevel, <hWnd>, <DDSCL_EXCLUSIVE + DDSCL_FULLSCREEN>
  213.     mcall [ddraw], DDSetDisplayMode, <modewidth>, <modeheight>, <modedepth>
  214.  
  215. ;    //create the primary surface(with attached back surface)
  216.     mov desc.ddsurfacedesc_dwSize, size desc
  217.     mov desc.ddsurfacedesc_dwFlags, DDSD_BACKBUFFERCOUNT + DDSD_CAPS
  218.     mov desc.ddsurfacedesc_dwBackBufferCount, 1
  219.     mov desc.ddsurfacedesc_ddssurfCaps.dwCaps,DDSCAPS_PRIMARYSURFACE + DDSCAPS_3DDEVICE + DDSCAPS_FLIP + DDSCAPS_COMPLEX
  220.     mcall [ddraw], DDCreateSurface, <offset desc>, <offset primsurf>, 0
  221.  
  222. ;    //create the attached back surface
  223.     mov ddscaps.dwCaps, DDSCAPS_BACKBUFFER;
  224.     mcall [primsurf], DDSGetAttachedSurface, <offset ddscaps>, <offset backsurf>
  225.  
  226. ;    //create the zbuffer
  227.     call RtlZeroMemory, offset desc, SIZE desc
  228.     mov desc.ddsurfacedesc_dwSize, size desc
  229.     mov desc.ddsurfacedesc_dwFlags, DDSD_WIDTH + DDSD_HEIGHT + DDSD_CAPS + DDSD_ZBUFFERBITDEPTH;
  230.     mov desc.ddsurfacedesc_dwWidth, modewidth
  231.     mov desc.ddsurfacedesc_dwHeight, modeheight
  232.     mov desc.ddsurfacedesc_dwZBufferBitDepth, modedepth
  233.     mov desc.ddsurfacedesc_ddssurfCaps.dwCaps, DDSCAPS_ZBUFFER + DDSCAPS_SYSTEMMEMORY;
  234.     mcall [ddraw], DDCreateSurface, <offset desc>, <offset zbufsurf>,0
  235.     mcall [backsurf], DDSAddAttachedSurface, <zbufsurf>
  236.  
  237. ;    //create d3d device from directdraw surface
  238.     mcall [d3drm], D3DRMCreateDeviceFromSurface, 0,<ddraw>,<backsurf>,<offset device>
  239.     mcall [device], D3DRMDSetQuality, D3DRMRENDER_WIREFRAME;WIREFRAME;GOURAUD
  240.     return1
  241. Setup3D ENDP
  242. ;//////////////////////////////////////////////////////////////////////////
  243. ;//////////////////////////////////////////////////////////////////////////
  244. CreateScene PROC
  245. ;    //create scene frame, the root frame
  246.     mcall [d3drm], D3DRMCreateFrame, 0, <offset scene>
  247.     
  248. ;    //load a mesh
  249. .data
  250. bin         db "desk.x",0
  251.  
  252. .code
  253.     mcall [d3drm], D3DRMCreateMeshBuilder, <offset meshbuilder>
  254.     mcall [meshbuilder], D3DRMMBLoad,<offset bin>, 0,D3DRMLOAD_FROMFILE,0,0
  255.     .if eax != D3DRM_OK
  256.         return0
  257.     .endif
  258.     call ScaleMesh, meshbuilder, 1108082688 ; //just to make sure it's a size we want
  259.     
  260. ;    //create a meshframe, attach to scene
  261. .data?
  262.     meshframe DD ?
  263. .code
  264.     mcall [d3drm], D3DRMCreateFrame, <scene>, <offset meshframe>
  265.     mcall [meshframe], D3DRMFAddVisual, <meshbuilder>
  266.  
  267.  
  268. ;    //note: adding the automatic rotation means in the update() function we have to call the move() 
  269. ;    //member function to initiate the auto update.
  270.     mcall [meshframe],D3DRMFSetRotation,<scene>,0,1065353216,1045220557,1028443341
  271.     mcall [meshframe],D3DRMFRelease
  272.     mov meshframe, 0;
  273.  
  274. ;    //create a light
  275. .data?
  276.     slight          DD ?
  277.     slightframe     DD ?
  278. .code
  279.     mcall [d3drm], D3DRMCreateLightRGB,2,1065353216,1065353216,1065353216,<offset slight>
  280.     
  281. ;    //create the frame to attach the light to, 
  282. ;    //everything needs to attach to a frame then to the scene frame.
  283.     mcall [d3drm], D3DRMCreateFrame,<scene>,<offset slightframe>
  284.     mcall [slightframe], D3DRMFSetPosition,<scene>,0,1084227584,-1029701632
  285.     mcall [slightframe], D3DRMFSetOrientation,<scene>,0,0,1065353216,0,1065353216,0
  286.     mcall [slightframe], D3DRMFAddLight,<slight>
  287.     mcall [slightframe], D3DRMFRelease
  288.     mov slightframe, 0
  289.     mcall [slight], D3DRMFRelease
  290.     mov slight, 0
  291.     
  292. ;    //create a frame to act as the camera, attach to scene
  293.     mcall [d3drm], D3DRMCreateFrame,<scene>,<offset camera>
  294.     mcall [camera], D3DRMFSetPosition,<scene>,0,1097859072,-1032847360
  295.     
  296. ;    //create the renderer, the viewport
  297. .data?
  298. temp1   DD ?
  299. temp2   DD ?
  300. .code
  301.     mcall [device], <D3DRMDGetHeight>
  302.     mov temp2, eax
  303.     mcall [device], <D3DRMDGetWidth>
  304.     mov temp1, eax
  305.     mcall [d3drm], <D3DRMCreateViewport>,<device>,<camera>,0,0,<temp1>,<temp2>,<offset viewport>
  306.     return1
  307. CreateScene ENDP
  308. ;//////////////////////////////////////////////////////////////////////////
  309. ;//////////////////////////////////////////////////////////////////////////
  310. UpdateScreen PROC
  311.     mcall [primsurf], DDSIsLost
  312.     .if eax == DDERR_SURFACELOST
  313.         mcall [primsurf], DDSRestore
  314.     .endif    
  315. .data?
  316.     bltfx DDBLTFX <?>
  317. .code
  318.     call RtlZeroMemory, offset bltfx, size bltfx
  319.     mov bltfx.ddbltfx_dwSize, size bltfx
  320.     mov bltfx.ddbltfx_dwFillColor, 0
  321.     mcall [backsurf], DDSBlt,0,0,0,<DDBLT_COLORFILL + DDBLT_WAIT>,<offset bltfx>
  322.  
  323. ;    //if you setrotation or some other auto updating frame function you must
  324. ;    //call ->Move() to update it
  325.     mcall [scene], D3DRMFMove,1065353216
  326.  
  327.     mcall [viewport],D3DRMVClear
  328.     mcall [viewport],D3DRMVRender,<scene>
  329.     mcall [device], D3DRMDUpdate
  330.     
  331.     mcall [primsurf], DDSFlip, 0, <DDFLIP_WAIT>
  332.     ret
  333. UpdateScreen ENDP
  334. ;//////////////////////////////////////////////////////////////////////////
  335. ;//////////////////////////////////////////////////////////////////////////
  336. ScaleMesh PROC, mesh:DWORD, dim:D3DVALUE
  337. .data?
  338.     box         D3DRMBOX <?>
  339.     sizex       D3DVALUE ?
  340.     sizey       D3DVALUE ?
  341.     sizez       D3DVALUE ?
  342.     scalefactor D3DVALUE ?
  343.     largedim    D3DVALUE ?
  344.     dimm        D3DVALUE ?
  345. .code
  346.     mov eax, dim
  347.     mov dimm, eax
  348.     ; method D3DRMMGetBox
  349.     mcall [mesh], 64, <offset box>
  350.  
  351.     fld box.d3drmbox_max.d3dvector_x
  352.     fsub box.d3drmbox_min.d3dvector_x
  353.     fstp sizex
  354.     fld box.d3drmbox_max.d3dvector_y
  355.     fsub box.d3drmbox_min.d3dvector_y
  356.     fstp sizey
  357.     fld box.d3drmbox_max.d3dvector_z
  358.     fsub box.d3drmbox_min.d3dvector_z
  359.     fstp sizez
  360.  
  361.     fld sizex
  362.     fcomp largedim
  363.     fnstsw ax
  364.     sahf
  365.     .if !carry? ; if st >= operand
  366.         mov eax, sizex
  367.         mov largedim, eax
  368.     .endif
  369.  
  370.     fld sizey
  371.     fcomp largedim
  372.     fnstsw ax
  373.     sahf
  374.     .if !carry? ; if st >= operand
  375.         mov eax, sizey
  376.         mov largedim, eax
  377.     .endif
  378.  
  379.     fld sizez
  380.     fcomp largedim
  381.     fnstsw ax
  382.     sahf
  383.     .if !carry? ; if st >= operand
  384.         mov eax, sizez
  385.         mov largedim, eax
  386.     .endif
  387.  
  388.     fld dimm
  389.     fdiv largedim
  390.     fstp scalefactor
  391.  
  392.     ; method D3DRMMScale
  393.     mcall [mesh], 52,<scalefactor>,<scalefactor>,<scalefactor>
  394.  
  395.     ret
  396. ScaleMesh ENDP
  397.  
  398. end Start
  399. ;//////////////////////////////////////////////////////////////////////////
  400. ;//////////////////////// END OF FILE /////////////////////////////////////
  401. ;//////////////////////////////////////////////////////////////////////////
  402.