Posted: Sun Feb 17, 2008 6:31 pm Post subject: rotation
Could someone tell me how to make a picture rotate according to the direction my mouse is pointing to?
Sponsor Sponsor
Sean
Posted: Sun Feb 17, 2008 6:35 pm Post subject: Re: rotation
Pic.Rotate to your Mouse X and Y variables?
fishtastic
Posted: Sun Feb 17, 2008 7:05 pm Post subject: Re: rotation
ah... i think i know what you mean.
what you need is to figure out the mouse angle.
based on the x,y coordinate of the picture and the coordinate of the mouse.
Posted: Sun Feb 17, 2008 7:11 pm Post subject: RE:rotation
um..what i meant was , for example: if i have a triangle, i want one of the angles to point at the location of the mouse.
So i know it has somethig to do with Pic.Rotate, but i am not sure.
fishtastic
Posted: Sun Feb 17, 2008 7:35 pm Post subject: RE:rotation
1.draw a triangle
2.use pic.new to take a picture
3.figure out the angle of the mouse
4.use pic.rotate to create a rotated picture
5.draw the pic returned by pic.rotate
metachief
Posted: Sun Feb 17, 2008 7:41 pm Post subject: RE:rotation
thanks i got the consept , but how do i plug in the mouse coordinates as the angle?
fishtastic
Posted: Sun Feb 17, 2008 7:43 pm Post subject: RE:rotation
my code above
Sean
Posted: Sun Feb 17, 2008 7:43 pm Post subject: Re: rotation
Your Mouse X and Mouse Y would equal a position, then you would want one of your rotating angles to equal the mouses.
Sponsor Sponsor
metachief
Posted: Sun Feb 17, 2008 7:50 pm Post subject: RE:rotation
Here's my code:
var gun: array 0..35 of int
gun (0) := Pic.FileNew ("gun.bmp")
for angle : 0..35
gun(angle):= Pic.Rotate (gun (0),angle*10,player_x,player_y)
end for
i don't know how to make the mouse coordinates into the angle of the picture.
PS: The code above doesn't work, because i ca't do math distance for some reason.
metachief
Posted: Sun Feb 17, 2008 8:20 pm Post subject: rotation2
Me again. I tried, but i ran into another problem.
This is my code:
Mouse.Where (z,t,button)
var d := Math.Distance (z, t, maxx div 2, maxx div 2)
if d > 0 then
var angle := arccosd ((z - maxx div 2) / d)
if t - maxx div 2 < 0 then
angle := 360 - angle
end if
gun (0) := Pic.FileNew ("gun.bmp")
gun(0):= Pic.Rotate (gun(0),round(angle),px,py)
end if
The problem with it is that my picture doesn't stay in the same place, but instead when i move my mouse around it rotates in circles
CodeMonkey2000
Posted: Sun Feb 17, 2008 8:20 pm Post subject: RE:rotation
For make a function called getAngle. This function will take the position of the mouse and the position of the picture and get the angle between them. Next when you draw the picture you will draw picture(calculated angle divided by 10).
CodeMonkey2000
Posted: Sun Feb 17, 2008 8:22 pm Post subject: RE:rotation2
Please stick to one thread.
metachief
Posted: Sun Feb 17, 2008 8:25 pm Post subject: RE:rotation2
what difference does it make?
By the way do u think u could help me
CodeMonkey2000
Posted: Sun Feb 17, 2008 8:46 pm Post subject: RE:rotation
Basically you need to find the angle between the player and the mouse. To do this you will need to know some trigonometry. More specifically you need the tangent and tangent inverse functions. Now I assume that you are in grade 10 and thus have a limited knowledge of trig. So being the nice guy I am here is my angle function.
code:
fcn angle (px, py, tx, ty : int) : real
var adjecent : real := tx - px
var opposite : real := ty - py
if adjecent = 0 and ty > py then
result 90
elsif adjecent = 0 and ty <= py then
result 270
end if
if opposite = 0 and tx > px then
result 0
end if
if opposite = 0 and tx < px then
result 180
end if
if ty < py then
if arctand (opposite / adjecent) > 0 then
result 180 + arctand (opposite / adjecent)
else
result 360 + arctand (opposite / adjecent)
end if
result 180 + arctand (opposite / adjecent)
else
if arctand (opposite / adjecent) < 0 then
result 180 + arctand (opposite / adjecent)
else
result arctand (opposite / adjecent)
end if
end if
end angle
Just pass in the player x,y and the mouse x,y and this function will return the angle. I programmed this when I was in grade 10, so this code is really messy and inefficient. And if you still don't know what to do, here is an example.