-
Apr 26th, 2013, 08:37 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Trayectory calculation problem.
I am lost , far time ago I was capable to resolve things like this, but now I haven't inspiration.
I needs to reposition a form in such way that it is placed far from the mouse position, BUT, it must respond to the mouse movement, positioning this form in the back from the mouse actual trayectory movement.
So if the mouse moves to the left, this form must be back on the right from the actual mouse position.
if the mouse change its trayectory the form must change its position nicely.
rules, no parts of this form be on the current mouse position.
so I have a current mouse position , and an old mouse position. Using a differential (-) will get trayectory, I needs to expand the trayectory far away from the mouse pointer.
until now I have this, But I thinks I am doing it wrong.
Code:
Private Sub PosScreener()
Dim T As POINTAPI
Dim TrX As Double
Dim TrY As Double
Dim ResultLeft As Long
Dim ResultTop As Long
Dim ResultWidth As Long
Dim ResultHeight As Long
ResultWidth = FormScreen.Width / Screen.TwipsPerPixelX
ResultHeight = FormScreen.Height / Screen.TwipsPerPixelY
' Calcula trayectoria.
T.X = m_CursorPos.X - LastKnownMousePositionX
T.Y = m_CursorPos.Y - LastKnownMousePositionY
' Verifica si tiene una trayectoria.
If T.X = 0 And T.Y = 0 Then
' No se pudo calcular una trayectoria debido a que el mouse no se ha movido.
' Verifica la posiciĆ³n horizontal actual del mouse.
If m_CursorPos.X * Screen.TwipsPerPixelX > Screen.Width / 2 Then
' Del lado derecho de la pantalla.
T.X = 1
Else
' Del lado izquierdo de la pantalla.
T.X = -1
End If
End If
If T.X >= 0 And T.Y >= 0 Then
' Trayectoria hacia el cuadrante inferior derecho.
Else
If T.X >= 0 And T.Y < 0 Then
' Trayectoria hacia el cuadrante superior derecho.
Else
If T.X < 0 And T.Y >= 0 Then
' Trayectoria hacia el cuadrante inferior izquierdo.
Else
' Trayectoria hacia el cuadrante superior izquierdo.
End If
End If
End If
End Sub
someone can helpme with this?
the whole idea is like TAILING the mouse smoothly like a dragon tail.
Last edited by flyguille; Apr 26th, 2013 at 08:47 AM.
-
Apr 26th, 2013, 10:01 AM
#2
Thread Starter
Fanatic Member
Re: Trayectory calculation problem.
I thinks I must change the approach
I needs to convert those differencial T.x and T.y and gets the Angle in radianes, then use it with cos()*diameterWanted + sin()* diameterWanted in way to put it away back from the mouse trayectory movement.
But, I don't figure out how to convert T.x and T.y (dfference between the actual mouse position and the LaskKnownMousePosition, in an radianAngle value).
-
Apr 26th, 2013, 10:41 AM
#3
Thread Starter
Fanatic Member
Re: Trayectory calculation problem.
never mind, find the function here
Code:
Public Function GetDirection(ByVal xVelocity As Long, ByVal yVelocity As Long) As Single
Dim Direction As Single
Dim PI As Single
PI = 4 * Atn(1)
If yVelocity <> 0 Then
Direction = Atn(xVelocity / yVelocity)
If xVelocity = 0 Then
If yVelocity > 0 Then
Direction = 3 * PI / 2
Else
Direction = PI / 2
End If
ElseIf yVelocity < 0 Then
If xVelocity < 0 Then
Direction = PI - Direction
Else
Direction = PI / 2 + Direction
End If
ElseIf xVelocity > 0 Then
If yVelocity < 0 Then
Direction = PI / 2 + Direction
Else
Direction = 3 * PI / 2 + Direction
End If
Else
Direction = 3 * PI / 2 + Direction
End If
Else
If xVelocity > 0 Then
Else
Direction = PI + Direction
End If
End If
GetDirection = Direction
End Function
I was trying to do it with one single VB line using atn or tan..... impossible.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|