Computer Science Canada rotation |
Author: | metachief [ 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? |
Author: | Sean [ Sun Feb 17, 2008 6:35 pm ] |
Post subject: | Re: rotation |
Pic.Rotate to your Mouse X and Y variables? |
Author: | fishtastic [ 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.
|
Author: | metachief [ 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. |
Author: | fishtastic [ 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 |
Author: | metachief [ 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? |
Author: | fishtastic [ Sun Feb 17, 2008 7:43 pm ] |
Post subject: | RE:rotation |
my code above |
Author: | Sean [ 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. |
Author: | metachief [ 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 Pic.Draw (gun(0), (player_x * 10)+4, (player_y * 20)+5, picMerge) 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. |
Author: | metachief [ 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 Pic.Draw (gun(0), (px * 20)+4, (py * 20)+5, picMerge) View.Update 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 |
Author: | CodeMonkey2000 [ 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). |
Author: | CodeMonkey2000 [ Sun Feb 17, 2008 8:22 pm ] |
Post subject: | RE:rotation2 |
Please stick to one thread. |
Author: | metachief [ 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 |
Author: | CodeMonkey2000 [ 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.
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. |
Author: | fishtastic [ Sun Feb 17, 2008 8:59 pm ] |
Post subject: | RE:rotation |
metachief I already answered your question, dont drag more people in to answer the same question. you said "but how do i plug in the mouse coordinates as the angle?" i already answered it before you ask that. CodeMonkey2000 was nice enough to help, but read the reply before posting a new one. dont expect people to give you exactly what you need. |
Author: | ericfourfour [ Sun Feb 17, 2008 11:39 pm ] | ||
Post subject: | Re: rotation | ||
I didn't use any test cases so I'm unsure if it will give the correct angle but I think it does the best job explaining how to get the angle.
If you have taken grade 10 math, this is stuff is in your notes. For more information: http://en.wikipedia.org/wiki/Cartesian_coordinate_system. |
Author: | OneOffDriveByPoster [ Mon Feb 18, 2008 9:32 am ] |
Post subject: | Re: rotation |
In many programming languages, there is an atan2(y, x) function for this. It is important to understand what goes behind it though--not all implementations work the same. |
Author: | metachief [ Mon Feb 18, 2008 10:09 am ] |
Post subject: | RE:rotation |
thank you very much guys, you were alot of help..sorry for making it a big deal, it's just im a beginner at this, and im trying to get ahead fast |