Werty Posted November 22, 2010 Share Posted November 22, 2010 (edited) I'm attempting to change terrain example (#11) to have the 3D view take up less space on the gui, so I can have buttons and the like, but whatever I try changing doesnt do anything, the view still takes up all gui space.So I have added it to a child window instead, and got it working, except when the gui is deactivated and then activated again, then my keyboard goes ding ding ding when using the wasd keys for movement.The code.. (TerrainApp.au3 in the D3D example #11)expandcollapse popup#include "Camera.au3" #include "Terrain.au3" #include <GUIConstantsEx.au3> #include <Misc.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> ;Opt("MustDeclareVars", 1) Opt("GUIOnEventMode", 1) ;Local Const $sHMapfile = ".\Heightmaps\dont_use_spaces\dont_use_spaces_8b.pgm" ;Local Const $sTerrainTex = ".\Heightmaps\dont_use_spaces\dont_use_spaces.bmp" Local Const $sHMapfile = ".\..\..\Media\map128.raw" Local Const $sTerrainTex = ".\..\..\Media\Background.jpg" ; Weight modifier used by the weighted averaging of the mouse movement history array ; As the modifier value increases, the camera gets rotated smoothly but takes longer to rotate to the target. Local Const $nWeightModifier = 0.3 Local Const $iWidth = 800, $iHeight = 600 Local Const $iCenterX = $iWidth/2, $iCenterY = $iHeight/2 ; Camera mouse movement sensitivity. Decrease for faster scroll, increase for slower, yet more accurate scroll.. Local Const $nSensitivity = 100 Local $gui = GUICreate("Viewer", 1024, 600, 300, 200) ;GUICtrlCreateLabel("", 0, 0, 0, 0) ; <----------- stuff i've been trying ;filemenu $filemenu = GUICtrlCreateMenu("File") $openg2c = GUICtrlCreateMenuItem("Open project", $filemenu) GUICtrlCreateMenuItem("", $filemenu) $exit = GUICtrlCreateMenuItem("Exit", $filemenu) ;viewmenu $viewmenu = GUICtrlCreateMenu("View") $viewtextured = GUICtrlCreateMenuItem("Textured", $viewmenu) $viewwireframe = GUICtrlCreateMenuItem("Wireframe", $viewmenu) $viewgradient = GuiCtrlCreateMenuItem("Gradient", $viewmenu) ;helpmenuw $helpmenu = GUICtrlCreateMenu("Help") $help = GUICtrlCreateMenuItem("Help", $helpmenu) $about = GUICtrlCreateMenuItem("About", $helpmenu) GUISetState() Local $hGUI = GUICreate("Viewer", 800, 600, 0, 0, $WS_CHILD, Default, $gui) ;GUISwitch($gui); <----------- stuff i've been trying ;GUICtrlCreateLabel("", 0, 0, 0, 0); <----------- stuff i've been trying GUISetState() ;_WinAPI_SetParent($hGui, $gui); <----------- stuff i've been trying GUISwitch($gui) GUICtrlCreateLabel("", 0, 0, 0, 0) Local $pDevice, $oDevice ; Offset to the window's center from the screen left-top Local $iWndCenterX, $iWndCenterY ; History array used to hold last X mouse movement deltas, ; so we can use smooth mouse filtering. Smooth mouse filtering reduces ; the jerky motion of the camera caused by the native jerky mouse movement Local $aHistory[10][2] ; Camera and terrain objects Local $tCamera, $tTerrain ; Direction to light holds the opposite vector of the light dir ; so if we're lighting our terrain with a source of light [0, -1, 0] or downward, ; the direction to light should be [0, 1, 0] or upward. Local $tDirToLight ; Terrain texturing switch Local $fSwitch _D3D_Startup() ; Check if failed to load necessary dlls If @error Then If @error = 1 Then Exit MsgBox(0x10, "Error", 'Could not load "d3d9.dll"') Else Exit MsgBox(0x10, "Error", 'Could not load "d3dx9_36.dll"') EndIf EndIf $pDevice = _D3D_Init($hGUI, $iWidth, $iHeight) $oDevice = _AutoItObject_WrapperCreate($pDevice, $tagIDirect3DDevice9) _Setup() GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit") ; Change terrain texturing using spacebar GUIRegisterMsg($WM_KEYDOWN, "_WM_KEYDOWN") OnAutoItExitRegister("_Cleanup") GUISetState() While 1 _Render() _HighPrecisionSleep(8000) WEnd Func _Render() ; Allow user to update the camera view Local $iRunFactor, $aDeltas, $tCameraPos, $nHeight, $tView, $tWorld If WinActive("Viewer") Then ;GUISwitch($gui) If _IsPressed("02")Then ; Left shift to run If _IsPressed("A0") Then $iRunFactor = 0.5 If _IsPressed("57") Then ; W - move forward _CameraWalk($tCamera, 0.7 + $iRunFactor) ElseIf _IsPressed("53") Then ; S - move backward _CameraWalk($tCamera, -0.7 - $iRunFactor) EndIf If _IsPressed("41") Then ; A - move leftward _CameraStrafe($tCamera, -0.7 - $iRunFactor) ElseIf _IsPressed("44") Then ; S - move rightward _CameraStrafe($tCamera, 0.7 + $iRunFactor) EndIf $aDeltas = _MouseSmoothFilter($aHistory) _CameraYaw ($tCamera, $aDeltas[0] / $nSensitivity) _CameraPitch($tCamera, $aDeltas[1] / $nSensitivity) If IsDllStruct($tTerrain) Then _CameraGetPos($tCamera, $tCameraPos) $nHeight = _TerrainGetHeight($tTerrain, DllStructGetData($tCameraPos, "x"), DllStructGetData($tCameraPos, "z")) DllStructSetData($tCameraPos, "y", 50) _CameraSetPos($tCamera, $tCameraPos) EndIf ; Get the camera view matrix $oDevice.SetTransform("long", "int", $D3DTS_VIEW, "ptr", _CameraGetView($tCamera, $tView)) ; Draw the scene, clear the depth and back buffers $oDevice.Clear("long", "uint", 0, "ptr", 0, "uint", BitOR($D3DCLEAR_TARGET, $D3DCLEAR_ZBUFFER), "uint", 0xFF5D6FA2, "float", 1, "uint", 0) $oDevice.BeginScene("long") If IsDllStruct($tTerrain) Then _D3DX_MatrixIdentity($tWorld) _TerrainDraw($tTerrain, $tWorld) EndIf $oDevice.EndScene("long") $oDevice.Present("long", "ptr", 0, "ptr", 0, "hwnd", 0, "ptr", 0) EndIf EndIf EndFunc Func _MouseSmoothFilter(ByRef $aMovement) Local $aPos, $iDX, $iDY ; Get cursor position $aPos = _GetCursorPos() ; Reset mouse position back to the center of the window _SetCursorPos($iWndCenterX, $iWndCenterY) $iDX = $aPos[0] - $iWndCenterX $iDY = $aPos[1] - $iWndCenterY _MousePerformFiltering($aMovement, $iDX, $iDY) Return _MousePerformSmoothing($aMovement) EndFunc Func _MousePerformFiltering(ByRef $aMovement, $nDX, $nDY) Local $aDeltas[2], $nAvgX, $nAvgY, $nAvgSum, $nCurrWeight = 1 ; Update the arraw by pushing all elements of the array, thus the array contains the last X deltas ; where X is the size of the array For $i = UBound($aMovement)-1 To 1 Step -1 $aMovement[$i][0] = $aMovement[$i - 1][0] $aMovement[$i][1] = $aMovement[$i - 1][1] Next $aMovement[0][0] = $nDX $aMovement[0][1] = $nDY ; Weighted average of deltas For $i = 0 To UBound($aMovement)-1 $nAvgX += $aMovement[$i][0] * $nCurrWeight $nAvgY += $aMovement[$i][1] * $nCurrWeight $nAvgSum += $nCurrWeight $nCurrWeight *= $nWeightModifier Next $aDeltas[0] = $nAvgX / $nAvgSum $aDeltas[1] = $nAvgY / $nAvgSum ; Update the current mouse movement delta with the weighted delta $aMovement[0][0] = $aDeltas[0] $aMovement[0][1] = $aDeltas[1] Return $aDeltas EndFunc Func _MousePerformSmoothing(ByRef $aMovement) Local $aDeltas[2] $aDeltas[0] = ($aMovement[0][0] + $aMovement[1][0]) * 0.5 $aDeltas[1] = ($aMovement[0][1] + $aMovement[1][1]) * 0.5 Return $aDeltas EndFunc Func _Setup() Local $tProj, $aPos, $aRet, $iSize ; Use the square root of the file size for dimensions of the terrain $iSize = Int(Sqrt(FileGetSize($sHMapfile))) ; Create the first person camera object. Land object camera type. $tCamera = _CameraCreate($CAMERATYPE_LANDOBJECT) ; Create the direction to light vector for colors shading. Light rays travel at -45 degrees down relative to the x-axis ; so the direction to light is upword at 135 degrees relative to the x-axis ; Note that the direction to light vector is a unit vector. _D3D_CreateVector3($tDirToLight, -0.707, 0.707, 0) ; Higher cell spaced terrains are said to be lower resolution terrains. $tTerrain = _TerrainCreate($pDevice, $sHMapfile, $iSize, $iSize, 2, 0.5) If Not @error Then _TerrainLoadTexture($sTerrainTex) ;_TerrainGenerateTexture($tTerrain, $tDirToLight) EndIf ; Set texture filters $oDevice.SetSamplerState("long", "uint", 0, "int", $D3DSAMP_MAGFILTER, "uint", $D3DTEXF_LINEAR) $oDevice.SetSamplerState("long", "uint", 0, "int", $D3DSAMP_MINFILTER, "uint", $D3DTEXF_LINEAR) $oDevice.SetSamplerState("long", "uint", 0, "int", $D3DSAMP_MIPFILTER, "uint", $D3DTEXF_LINEAR) ; Set projection matrix (45 degrees) $oDevice.SetTransform("long", "int", $D3DTS_PROJECTION, "ptr", _D3DX_MatrixPerspectiveFovLH($tProj, ASin(1)/2, $iWidth/$iHeight, 1, 5000)) ; Calculate the screen position of our window's center $aPos = WinGetPos($hGUI) $iWndCenterX = $aPos[0] + $iCenterX $iWndCenterY = $aPos[1] + $iCenterY ; Reset mouse to the center of the window and hide the mouse cursor ;_SetCursorPos($iWndCenterX, $iWndCenterY) ;GUISetCursor(16) EndFunc Func _WM_KEYDOWN($hWnd, $iMsg, $iwParam, $ilParam) If $iwParam = 0x20 Then If IsDllStruct($tTerrain) Then _TerrainSwitchTexture($fSwitch) $fSwitch = Not $fSwitch EndIf EndIf Return $GUI_RUNDEFMSG EndFunc Func _Quit() Exit EndFunc Func _Cleanup() $oDevice = 0 GUIDelete() _D3D_Shutdown() EndFunc ; #FUNCTION#;=============================================================================== ; ; Name...........: _HighPrecisionSleep() ; Description ...: Sleeps down to 0.1 microseconds ; Syntax.........: _HighPrecisionSleep( $iMicroSeconds, $hDll=False) ; Parameters ....: $iMicroSeconds - Amount of microseconds to sleep ; $hDll - Can be supplied so the UDF doesn't have to re-open the dll all the time. ; Return values .: None ; Author ........: Andreas Karlsson (monoceres) ; Modified.......: ; Remarks .......: Even though this has high precision you need to take into consideration that it will take some time for autoit to call the function. ; Related .......: ; Link ..........; ; Example .......; No ; ;;========================================================================================== Func _HighPrecisionSleep($iMicroSeconds,$hDll=False) Local $hStruct, $bLoaded If Not $hDll Then $hDll=DllOpen("ntdll.dll") $bLoaded=True EndIf $hStruct=DllStructCreate("int64 time;") DllStructSetData($hStruct,"time",-1*($iMicroSeconds*10)) DllCall($hDll,"dword","ZwDelayExecution","int",0,"ptr",DllStructGetPtr($hStruct)) If $bLoaded Then DllClose($hDll) EndFunc Func _GetCursorPos() Local $aRet[2], $tPoint = DllStructCreate("int;int") DllCall("user32.dll", "bool", "GetCursorPos", "ptr", DllStructGetPtr($tPoint)) $aRet[0] = DllStructGetData($tPoint, 1) ; X $aRet[1] = DllStructGetData($tPoint, 2) ; Y Return $aRet EndFunc Func _SetCursorPos($iX, $iY) DllCall("user32.dll", "bool", "SetCursorPos", "int", $iX, "int", $iY) EndFuncHold down right mouse button and use wasd for movement, then try deactivating the gui by doing something else like notepad or focus on this browser window, and then go back to the gui, then it goes ding ding when using the wasd keys.I've been reading around ofcourse and tried some stuff like the "empty label trick" I've heard mentioned, and guiswitch() and setparent(), but cant get it working,Ultimately, get rid of the child window and just have the D3D view not take up all the gui space. Thanks. Edited November 22, 2010 by Werty Some guy's script + some other guy's script = my script! Link to comment Share on other sites More sharing options...
Werty Posted November 23, 2010 Author Share Posted November 23, 2010 24 hour bump Some guy's script + some other guy's script = my script! Link to comment Share on other sites More sharing options...
Werty Posted December 7, 2010 Author Share Posted December 7, 2010 I still need this, really Some guy's script + some other guy's script = my script! Link to comment Share on other sites More sharing options...
funkey Posted December 7, 2010 Share Posted December 7, 2010 Your attached code is not executable without the dependencies! This is the reason you got no answer! Try GUISetAccelerators() for all keys that are used. Use a dummy function for them. Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning. Link to comment Share on other sites More sharing options...
Werty Posted December 7, 2010 Author Share Posted December 7, 2010 (edited) Your attached code is not executable without the dependencies! This is the reason you got no answer!No, I dont get any answers because ppl are lazy Try GUISetAccelerators() for all keys that are used. Use a dummy function for them.I'll look into that, thanks.If I'm unsuccessfull I'll look into making another example (new thread!) that doesnt require any extras. Edited December 7, 2010 by Werty Some guy's script + some other guy's script = my script! Link to comment Share on other sites More sharing options...
bogQ Posted December 8, 2010 Share Posted December 8, 2010 (edited) Edit:And ofc my old topic on identical problem shud help i hope Edited December 8, 2010 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now