![]() |
Tipp 0060
|
2D-Rotation
|
 |
|
Autor/Einsender: Datum: |
|
Detlev Schubert 19.05.2001 |
|
Entwicklungsumgebung: |
|
VB 5 |
|
|
Was mit den Grafik-Methoden von Visual Basic alles möglich ist, wird mit diesem Tipp demonstriert,
in dem ein Vieleck um eine Achse rotiert wird, wobei noch zusätzlich gezeigt wird, wie die Rotation
automatisiert werden kann.
|
|
|
Option Explicit
Dim x(4) As Long
Dim Y(4) As Long
Dim Z(4) As Long
Dim Xr(4) As Long
Dim Yr(4) As Long
Dim Zr(4) As Long
Dim Xd(4) As Long
Dim Yd(4) As Long
Dim Points As Long
Private Sub Form_Load()
Points = 4
x(0) = 100
Y(0) = 100
Z(0) = 1000
x(1) = -100
Y(1) = 100
Z(1) = 1000
x(2) = -100
Y(2) = -100
Z(2) = 2000
x(3) = 100
Y(3) = -100
Z(3) = 2000
End Sub
Private Sub Command1_Click()
Dim CenterX As Long, CenterY As Long
Dim i As Integer, Rad As Double
CenterX = Picture1.ScaleWidth / 2
CenterY = Picture1.ScaleHeight / 2
Command3.Enabled = True
Rad = 6.28 / 100 * VScroll1.Value
For i = 0 To Points - 1
Xr(i) = Cos(Rad) * (x(i)) + Sin(Rad) * (Y(i))
Yr(i) = Cos(Rad) * (Y(i)) - Sin(Rad) * (x(i))
Zr(i) = Z(i)
Xd(i) = Xr(i) * 512 / Zr(i) + CenterX
Yd(i) = Yr(i) * 512 / Zr(i) + CenterY
Next i
Picture1.Cls
For i = 0 To Points - 2
Picture1.Line (Xd(i), Yd(i))-(Xd(i + 1), Yd(i + 1)), _
RGB(255, 0, 0)
Next i
Picture1.Line (Xd(Points - 1), Yd(Points - 1))-(Xd(0), _
Yd(0)), RGB(255, 0, 0)
End Sub
Private Sub Command3_Click()
Dim x As Integer
For x = VScroll1.Min To VScroll1.Max
VScroll1.Value = x
Next
End Sub
Private Sub VScroll1_Change()
Command1_Click
End Sub
Private Sub VScroll1_Scroll()
Command1_Click
End Sub
|
|
|
|
|
Windows-Version |
95 |
 |
|
98/SE |
 |
|
ME |
 |
|
NT |
 |
|
2000 |
 |
|
XP |
 |
|
Vista |
 |
|
Win
7 |
 |
|
|
VB-Version |
VBA 5 |
 |
|
VBA 6 |
 |
|
VB 4/16 |
 |
|
VB 4/32 |
 |
|
VB 5 |
 |
|
VB 6 |
 |
|
|
|
Download (2,1 kB)
|
Downloads bisher: [ 2861 ]
|
|
|