Archived

This topic is now archived and is closed to further replies.

benhus

2D Rotation in VB

Recommended Posts

Hi, I''m really new to the math for games programming. Can any of you give me an example of how I can accomplish the following : I have a line: P1(X1,Y1)---------------------P2(X2,Y2) I want to transform point 2 90 degrees so I''ll get this line: P1(X1,Y1) | | | | | | | | P2(X2,Y2) How can I do this? Can any of you give me a Visual Basic example? Thanks.

Share this post


Link to post
Share on other sites
Hi!

Private Sub Form_Load()
Me.Show
Me.AutoRedraw = True
Me.ScaleMode = 3

Line (50, 50)-(50 + 100 * Cos(90/57.3), 50 + 100 * Sin(90/57.3)), RGB(255, 0, 0)
End Sub

x = cos(angle)
y = sin(angle)


[edited by - axodoss on June 6, 2002 6:12:45 AM]

Share this post


Link to post
Share on other sites
AxoDosS,

I appologize. I''ve been doing some more playing around with the code, and now it''s working fine. Thank you very much. And again, my appologies for me being a bit impatient.
I''ve absolutely 0,0 knowledgde of game math. Do you perhaps have some good resources.

And again...thanks!

Share this post


Link to post
Share on other sites
Ok I'm an expert, here is what you do. If you want to rotate a line to any degrees all you have to do it this:

Private Const PI = 3.14159

Private Type POINTAPI
X as Single
Y as Single
end type

'Make our line array
Private Line(1) as POINTAPI

'The two variables we need for or rotation
Private lineRotationAngle as Single, lineLength as integer

Private Sub Form_Load()
'This will set the rotation angle to 90 degrees in radians
lineRotationAngle = Deg2Rad(90)

'This will set the length of the line in pixels
lineLength = 10

'This will rotate the second point around the first one.
Line(1).X = Line(0).X + Cos(lineRotationAngle) * lineLength
Line(1).Y = Line(0).Y + Sin(lineRotationAngle) * lineLength

'Draw the line
Me.Line (Line(0).X, Line(0).Y)-(Line(1).X, Line(1).Y)
End sub

Private Function Deg2Rad(AngleDeg as integer) as Single
'This will return the angle in radians
Deg2Rad = AngleDeg * (PI / 180)
End Function

That will do everything you need to rotate the line. You have to convert degrees to radians before you can do any math with the points. I have done this in the above example. Good Luck! If you need anymore help you can e-mail me at Dildan2004@hotmail.com

Horny Farmer (Jolly Rancher)

[edited by - VisualB4BigD on June 6, 2002 6:54:45 AM]

Share this post


Link to post
Share on other sites
Hi!

The most inportante thing is that it works.

Hmm try the links below for tutorials and programs.

http://www.acky.net/vb/
http://www.vbcn.com.ar/
http://www.vb-helper.com/howto.htm

Share this post


Link to post
Share on other sites