Negative1 Posted January 25, 2011 Share Posted January 25, 2011 Hi all, I have the code and formulas to correctly predict bullet drop and trejectory of a projectile however how I would like to simulate it graphically. What would be the best / easiest way to draw a trejectory arc overtop of another window? Thanks, -1 What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world. Link to comment Share on other sites More sharing options...
UEZ Posted January 25, 2011 Share Posted January 25, 2011 I made this awhile ago: expandcollapse popup;Coded by UEZ Build 2010-06-25 #AutoIt3Wrapper_Run_Obfuscator=y #Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0 #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Run_After=del /f /q "GDI+ Ball Trajectory_Obfuscated.au3" #AutoIt3Wrapper_Run_After=upx.exe --ultra-brute "%out%" #include <GDIPlus.au3> #Include <Misc.au3> Opt("MustDeclareVars", 1) Opt("GUIOnEventMode", 1) Opt("MouseCoordMode", 2) Local Const $width = 1024 Local Const $height = 600 Local $hGUI = GUICreate("GDI+ Ball Trajectory by UEZ 2010", $width, $height) GUISetState() _GDIPlus_Startup() Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphics) Local $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 2) _GDIPlus_GraphicsClear($hBuffer, 0xFFF0F0F0) Local $hPen = _GDIPlus_PenCreate(0xFF0000A0, 2) Local $hBrush = _GDIPlus_BrushCreateSolid(0xA000A000) GUISetOnEvent(-3, "_Exit") Local $mpos, $d, $dx,$dy, $lx, $ly, $cl Local Const $deg2rad = 180 / ACos(-1) Local Const $rad2deg = ACos(-1) / 180 Local $lmb = 0 Local $angle = 0 Local $ball_x = 0 Local $ball_y = 0 Local Const $ball_r = 16 Local Const $ball_r2 = $ball_r / 2 Local $fire = 0 Local $power = 2 Local $power_scale = 0 Local Const $max_power = 30 Local Const $gravity = 1 Local Const $max_dist = 350 Local Const $min_dist = 100 While Sleep(30) _GDIPlus_GraphicsClear($hBuffer, 0xE0F0F0F0) $mpos = MouseGetPos() If _IsPressed("01") And $fire = 0 And WinActive($hGUI) Then $lmb = 1 If $power < $max_power Then $power += 1 _GDIPlus_PenSetWidth($hPen, $power) $d = Pixel_Distance(0, $height, $mpos[0], $mpos[1]) If $d > $max_dist Then $angle = ATan(($height - $mpos[1]) / $mpos[0]) * $deg2rad $lx = Cos($angle * $rad2deg) * $max_dist $ly = Sin($angle * $rad2deg) * $max_dist _GDIPlus_GraphicsDrawLine($hBuffer, 0, $height, $lx, $height - $ly, $hPen) $ball_x = $lx $ball_y = $height - $ly $power_scale = 0.005 * $power $dx = -$lx * $power_scale $dy = $ly * $power_scale ElseIf $d < $min_dist Then $angle = ATan(($height - $mpos[1]) / $mpos[0]) * $deg2rad $lx = Cos($angle * $rad2deg) * $min_dist $ly = Sin($angle * $rad2deg) * $min_dist _GDIPlus_GraphicsDrawLine($hBuffer, 0, $height, $lx, $height - $ly, $hPen) $ball_x = $lx $ball_y = $height - $ly $power_scale = 0.005 * $power $dx = -$lx * $power_scale $dy = $ly * $power_scale Else _GDIPlus_GraphicsDrawLine($hBuffer, 0, $height, $mpos[0], $mpos[1], $hPen) $ball_x = $mpos[0] $ball_y = $mpos[1] $dx = -$mpos[0] * 0.005 * $power $dy = ($height - $mpos[1]) * 0.005 * $power EndIf Else If $lmb = 1 Then $fire = 1 $lmb = 0 EndIf $power = 2 _GDIPlus_PenSetWidth($hPen, $power) $d = Pixel_Distance(0, $height, $mpos[0], $mpos[1]) $angle = ATan(($height - $mpos[1]) / $mpos[0]) * $deg2rad If $d > $max_dist Then $lx = Cos($angle * $rad2deg) * $max_dist $ly = Sin($angle * $rad2deg) * $max_dist _GDIPlus_GraphicsDrawLine($hBuffer, 0, $height, $lx, $height - $ly, $hPen) $cl = Pixel_Distance(0, $height, $lx, $height - $ly) ElseIf $d < $min_dist Then $lx = Cos($angle * $rad2deg) * $min_dist $ly = Sin($angle * $rad2deg) * $min_dist _GDIPlus_GraphicsDrawLine($hBuffer, 0, $height, $lx, $height - $ly, $hPen) $cl = Pixel_Distance(0, $height, $lx, $height - $ly) Else _GDIPlus_GraphicsDrawLine($hBuffer, 0, $height, $mpos[0], $mpos[1], $hPen) $cl = Pixel_Distance(0, $height, $mpos[0], $mpos[1]) EndIf EndIf ToolTip("Cannon Angle: " & Int($angle) & "°, Cannon Power: " & $power & ", Cannon Length: " & Int($cl) & ", Ball x: " & Int($ball_x) & ", Ball y: " & Int($ball_y)) If $fire Then _GDIPlus_GraphicsFillEllipse($hBuffer, $ball_x - $ball_r2, $ball_y - $ball_r2, $ball_r, $ball_r, $hBrush) $ball_x -= $dx $ball_y -= $dy $dy -= $gravity If $ball_x > $width Or $ball_y > $height Or $ball_x < -$ball_r Then $fire = 0 $ball_x = 0 $ball_y = 0 EndIf EndIf _GDIPlus_GraphicsDrawString($hBuffer, "Coded by UEZ 2010", $width - 105, $height - 15, "Arial", 8) _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, 0, 0) WEnd Func _Exit() _GDIPlus_BrushDispose($hBrush) _GDIPlus_PenDispose($hPen) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hBuffer) _GDIPlus_Shutdown() GUIDelete($hGUI) Exit EndFunc Func Pixel_Distance($x1, $y1, $x2, $y2) ;Pythagoras theorem Local $a, $b, $c If $x2 = $x1 And $y2 = $y1 Then Return 0 Else $a = $y2 - $y1 $b = $x2 - $x1 $c = Sqrt($a * $a + $b * $b) Return $c EndIf EndFunc ;==>Pixel_Distance Might be helpful for you. Br, UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
smartee Posted January 25, 2011 Share Posted January 25, 2011 (edited) Hi all,I have the code and formulas to correctly predict bullet drop and trejectory of a projectile however how I would like to simulate it graphically. What would be the best / easiest way to draw a trejectory arc overtop of another window?Thanks,-1Have you tried using the GDIPlus functions?EDIT: *sigh* beaten to it :| Edited January 25, 2011 by smartee Link to comment Share on other sites More sharing options...
Negative1 Posted January 25, 2011 Author Share Posted January 25, 2011 Thanks for the script. I'm more looking for help on how to draw on an already open window eg. not my own GUI... Thanks -1 What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world. 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