[RESOLVED] direction vectors !!!
Hi all,
Hope someone out there can help me.I am tring to make an image controller fly from one point to another point ..But I seem to have problems locating the
following code. All I have is an "image" name=graphic ..What is P2:X or P1.Y ?:sick: ..Could you make it work...?
thanks
VB Code:
Private Sub Timer1_Timer()
Dim speed As Long
Dim X As Long
Dim Y As Long
speed = 10
DistX = p2.X - p1.X
distY = p2.Y - p1.Y
dist = Sqr(DistX * DistX + distY * distY)
Unitx = DistX / dist
Unity = distY / dist
graphic.Move graphic.Left + speed * Unitx, graphic.Top + speed * Unity
End Sub
Re: direction vectors !!!
try this,
VB Code:
Private Type POINTAPI
x As Long
y As Long
End Type
Dim p1 As POINTAPI
Dim p2 As POINTAPI
Private Sub Form_Load()
p1.x = 1000
p1.y = 1000
p2.x = 5000
p2.y = 100
End Sub
Private Sub Timer1_Timer()
Dim speed As Long
speed = 50
DistX = p2.x - p1.x
DistY = p2.y - p1.y
dist = Sqr(DistX * DistX + DistY * DistY)
Unitx = DistX / dist
Unity = DistY / dist
graphic.Move graphic.Left + speed * Unitx, graphic.Top + speed * Unity
End Sub
although this will move the image forever, even make it cross the form boundaries, so you need to make it stop it at one time, according to your project need.
Harsh Gupta
Re: direction vectors !!!
BTW, i forgot. changes the speed value to 50 from 10, because it was tooo.. slow!!
Harsh Gupta
Re: direction vectors !!!
Thanks Harsh, :wave:
I understood the logic..it works ok.. :thumb:
Actually the speed value is not too slow for me .. I use /Form/ScaleMode/Pixel
one more question..What is the shortest code for a scrolling background ?
Re: [RESOLVED] direction vectors !!!
Scrolling background?? do you mean that a picture in the background is automatically moving from 1 side to another?
Re: [RESOLVED] direction vectors !!!
Scrolling background?? do you mean that a picture in the background is automatically moving from 1 side to another?
__________________
yes
1 Attachment(s)
Re: [RESOLVED] direction vectors !!!
all right, i tried a small project, but very noobish kinda project. i am sure that there are more better solutions available for this.
Harsh Gupta
EDIT: if you want to get more results, you could remove the RESOLVED thing from the subject line
Re: [RESOLVED] direction vectors !!!
Unless you are using DirectX/OpenGL, scrolling picture is always a very slow and processor intensive job on GDI.
Try this code. It claims it is faster.