Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 rotation
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
metachief




PostPosted: 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
Sponsor
sponsor
Sean




PostPosted: Sun Feb 17, 2008 6:35 pm   Post subject: Re: rotation

Pic.Rotate to your Mouse X and Y variables?
fishtastic




PostPosted: 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.

Turing:

View.Set ("offscreenonly")
var x2, y2, mc : int
loop
    cls
    mousewhere (x2, y2, mc)
    var d := Math.Distance (x2, y2, maxx div 2, maxx div 2)
    if d > 0 then
        var angle := arccosd ((x2 - maxx div 2) / d)
        if y2 - maxx div 2 < 0 then
            angle := 360 - angle
        end if
        Draw.ThickLine (maxx div 2, maxx div 2, x2, y2, 3,black)
        put angle : 2 : 2
        View.Update
    end if
end loop
metachief




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: Sun Feb 17, 2008 7:43 pm   Post subject: RE:rotation

my code above
Sean




PostPosted: 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
Sponsor
sponsor
metachief




PostPosted: 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.
metachief




PostPosted: 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
CodeMonkey2000




PostPosted: 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




PostPosted: Sun Feb 17, 2008 8:22 pm   Post subject: RE:rotation2

Please stick to one thread.
metachief




PostPosted: 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




PostPosted: 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.



example.zip
 Description:

Download
 Filename:  example.zip
 Filesize:  853 Bytes
 Downloaded:  89 Time(s)

fishtastic




PostPosted: 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.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 18 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: