PDA

Click to See Complete Forum and Search --> : Any Suggestions???


tim_l_012
Mar 13th, 2001, 10:47 PM
I have the tip of a gun showing in frame1 in the
bottom - center.
I want a laser beam to follow the cursor from the point of the gun. Any Suggestions??

Arbiter
Mar 14th, 2001, 02:32 AM
Not a lot of information to go on there...

If you calculate the offset of the tip of the gun, from the top left of the control it's in, this will give you a start point for where to place your laser beam image.

e.g.

If the control holding your gun image is 40 x 40 and the tip of the gun is at bottom of the control in the middle, then the start point for the laser graphic (or effect or whatever) would be

guncontrol.left+20
guncontrol.top+40

This help?

Arbiter
Mar 14th, 2001, 02:33 AM
Forgot to add,

The end point for the laser would be the mouse co-ordinates...

Mar 14th, 2001, 10:26 AM
Are you working in 2D, or 3D? If you want to work in 2D, it is simple. Use the line method to draw a Line from GunPoint.X and .Y to CursorPos.X and .Y:

Declare blah blah blah GetCursorPos blah()
'// dont copy that line, use the API viewer
Private Type POINTAPI
X As Long
Y As Long
End Type

Sub DrawMeLine()
Dim CursorPos as POINTAPI
CursorPos = GetCursorPos

Canvas.Line(GunPoint.X, GunPoint.Y)-(CursorPos.X, CursorPos.Y) '//where Canvas is a valid PictureBox, Form, or (though i doubt youll use this one) Printer Object
'//Do other drawing stuff here
End Sub


That will do the trick, with a bit of simple modification(The GunPoint variable, for example).

Z.

[edit]
The syntax for GetCursorPos should be:

dim retval as long
retval = GetCursorPos(CursorPos)