Başlangıç > Kodlar > Visual basic 6 ile DLL kullanmadan 3 boyutlu animasyon yapmak

Visual basic 6 ile DLL kullanmadan 3 boyutlu animasyon yapmak

Kodlarla oynayabilmeniz için biraz matematik bilgisine ihtiyaç duyar
Timer ekleyin..

Kodlar:

Option Explicit

Private Type Point_3D
X As Single
Y As Single
Z As Single
End Type

Private Const PI As Single = 3.14159265358979
Private Const RADIAN As Single = PI / 180
Private Const FOV As Single = 90
Private Vertex_List() As Point_3D
Private Temp() As Point_3D
Private Local_Vertex() As Point_3D
Private Camera() As Point_3D
Private Perspective() As Point_3D
Private Screen() As Point_3D
Private Camera_Distance As Single
Private Number_Of_Vertices As Long
Private Viewport_Width As Single
Private Viewport_Height As Single
Private Viewplane_Width As Single
Private Viewplane_Height As Single
Private Distance As Single
Private Camera_Pos As Point_3D
Private ASPECT_RATIO As Single
Private Angle As Single

Private Sub Create_Polygons()
Number_Of_Vertices = 4
ReDim Vertex_List(Number_Of_Vertices) As Point_3D
ReDim Temp(Number_Of_Vertices) As Point_3D
ReDim Local_Vertex(Number_Of_Vertices) As Point_3D
ReDim Camera(Number_Of_Vertices) As Point_3D
ReDim Perspective(Number_Of_Vertices) As Point_3D
ReDim Screen(Number_Of_Vertices) As Point_3D
Vertex_List(0).X = -50: Vertex_List(0).Y = 50: Vertex_List(0).Z = 50
Vertex_List(1).X = 50: Vertex_List(1).Y = 50: Vertex_List(1).Z = 50
Vertex_List(2).X = -50: Vertex_List(2).Y = -50: Vertex_List(2).Z = 50
Vertex_List(3).X = 50: Vertex_List(3).Y = -50: Vertex_List(3).Z = 50
End Sub

Private Sub Rotate(Angle_X As Single, Angle_Y As Single, Angle_Z As Single)
Dim Current_Vertex As Long
For Current_Vertex = 0 To Number_Of_Vertices - 1
Temp(Current_Vertex).X = Vertex_List(Current_Vertex).X * (Cos(Angle_Y * RADIAN) * Cos(Angle_Z * RADIAN)) + Vertex_List(Current_Vertex).Y * ((Sin(Angle_X * RADIAN) * Sin(Angle_Y * RADIAN) * Cos(Angle_Z * RADIAN)) + (Cos(Angle_X * RADIAN) * -Sin(Angle_Z * RADIAN))) + Vertex_List(Current_Vertex).Z * (Cos(Angle_X * RADIAN) * Sin(Angle_Y * RADIAN) * Cos(Angle_Z * RADIAN)) + (-Sin(Angle_X * RADIAN) * -Sin(Angle_Z * RADIAN))
Temp(Current_Vertex).Y = Vertex_List(Current_Vertex).X * (Cos(Angle_Y * RADIAN) * Sin(Angle_Z * RADIAN)) + Vertex_List(Current_Vertex).Y * ((Sin(Angle_X * RADIAN) * Sin(Angle_Y * RADIAN) * Sin(Angle_Z * RADIAN)) + (Cos(Angle_X * RADIAN) * Cos(Angle_Z * RADIAN))) + Vertex_List(Current_Vertex).Z * (Cos(Angle_X * RADIAN) * Sin(Angle_Y * RADIAN) * Sin(Angle_Z * RADIAN)) + (-Sin(Angle_X * RADIAN) * Cos(Angle_Z * RADIAN))
Temp(Current_Vertex).Z = Vertex_List(Current_Vertex).X * (-Sin(Angle_Y * RADIAN)) + Vertex_List(Current_Vertex).Y * (Sin(Angle_X * RADIAN) * Cos(Angle_Y * RADIAN)) + Vertex_List(Current_Vertex).Z * (Cos(Angle_X * RADIAN) * Cos(Angle_Y * RADIAN))
Local_Vertex(Current_Vertex) = Temp(Current_Vertex)
Next Current_Vertex
End Sub

Private Sub Main()
AutoRedraw = True
ScaleMode = 3
DrawWidth = 4
Viewport_Width = Me.ScaleWidth
Viewport_Height = Me.ScaleHeight
ASPECT_RATIO = Viewport_Width / Viewport_Height
Viewplane_Width = 2
Viewplane_Height = 2 / ASPECT_RATIO
Distance = 0.5 * Viewplane_Width * Tan(PI * (FOV / 2) / 180)
Camera_Pos.Z = 400
Create_Polygons
Timer1.Interval = 1
Timer1.Enabled = True
End Sub

Private Sub Form_Activate()
Main
End Sub

Private Sub Timer1_Timer()
Dim Current_Vertex As Long
Dim Alpha As Single
Dim Beta As Single
Cls
Rotate 0, Angle, 0
Angle = Angle + 1
Angle = Angle Mod 360
For Current_Vertex = 0 To Number_Of_Vertices - 1
Camera(Current_Vertex).X = Local_Vertex(Current_Vertex).X + Camera_Pos.X
Camera(Current_Vertex).Y = Local_Vertex(Current_Vertex).Y + Camera_Pos.Y
Camera(Current_Vertex).Z = Local_Vertex(Current_Vertex).Z + Camera_Pos.Z
Perspective(Current_Vertex).X = Distance * Camera(Current_Vertex).X / Camera(Current_Vertex).Z
Perspective(Current_Vertex).Y = Distance * Camera(Current_Vertex).Y * ASPECT_RATIO / Camera(Current_Vertex).Z
Alpha = 0.5 * Viewport_Width - 0.5 'Center X
Beta = 0.5 * Viewport_Height - 0.5 'Center Y
Screen(Current_Vertex).X = Alpha + Alpha * Perspective(Current_Vertex).X
Screen(Current_Vertex).Y = Beta - Beta * Perspective(Current_Vertex).Y
PSet (Screen(Current_Vertex).X, Screen(Current_Vertex).Y)
Next Current_Vertex
End Sub

Reklamlar
  1. Henüz yorum yapılmamış.
  1. No trackbacks yet.

Bir Cevap Yazın

Aşağıya bilgilerinizi girin veya oturum açmak için bir simgeye tıklayın:

WordPress.com Logosu

WordPress.com hesabınızı kullanarak yorum yapıyorsunuz. Çıkış  Yap / Değiştir )

Twitter resmi

Twitter hesabınızı kullanarak yorum yapıyorsunuz. Çıkış  Yap / Değiştir )

Facebook fotoğrafı

Facebook hesabınızı kullanarak yorum yapıyorsunuz. Çıkış  Yap / Değiştir )

Google+ fotoğrafı

Google+ hesabınızı kullanarak yorum yapıyorsunuz. Çıkış  Yap / Değiştir )

Connecting to %s

%d blogcu bunu beğendi: