Rotating a lineshape in visual c++

Pages: 12
It's right, notice that sin/cos from <cmath> take radian arguments, 1rad ≈ 57deg
to convert degrees to radians, use this relation: Rad = Deg * π / 180
Also notice that you may have to translate the origin of rotation to get what you want ( get the initial coords as if you had to draw your things with (0,0) as center; rotate using the formula; move the resulting coords to where you want the actual center )
look bazzy, heres my source. I written it in visual basic couse its easier, after its working i will rewrite in c++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
Imports System.Math
Public Class Form1
    Dim xold As Double
    Dim yold As Double
    Dim x2old As Double
    Dim y2old As Double
    Dim theta As Double

    Private Sub LineShape1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LineShape1.Click

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer1.Start()

        ' x() ' = x cos ( theta ) - y sin ( theta )
        '  y() ' = x sin ( theta ) + y cos ( theta ) : y() ' = x sin ( theta ) + y cos ( theta )

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        LineShape1.X1 -= 250
        LineShape1.Y1 -= 250
        LineShape1.X2 -= 250
        LineShape1.Y2 -= 250
        theta = 0.05
        xold = LineShape1.X1
        yold = LineShape1.Y1
        x2old = LineShape1.X2
        y2old = LineShape1.Y2
        LineShape1.X1 = xold * Cos(theta) - yold * Sin(theta)
        LineShape1.Y1 = xold * Sin(theta) + yold * Cos(theta)
        LineShape1.X2 = x2old * Cos(theta) - y2old * Sin(theta)
        LineShape1.Y2 = x2old * Sin(theta) + y2old * Cos(theta)
        LineShape1.X1 += 250
        LineShape1.Y1 += 250
        LineShape1.X2 += 250
        LineShape1.Y2 += 250

    End Sub
End Class 


Now the problem is, its rotating in...well... i dont even know how to describe it :D
Here, i uploaded a .exe to 2shared. link is here :

http://www.2shared.com/file/vAqpsRL0/WindowsApplication1.html

Any ideas?
The code looks good to me, I can't download your program because I don't have Windows
Which are the initial values for the coordinates?
I bet you are using linux. I think you probably heard about wine?
I cant get you the old coords, couse something is wron with my vb installation, doesn't want to open up project files for some reason. But its in the middle of the screen, approximately 300,300,320,320
If the shape occupies that region, it's center should be at (310,310) not at (250,250) so you should fix your translation
Topic archived. No new replies allowed.
Pages: 12