Vous êtes sur la page 1sur 10

Type vertex

m1 As Double

m2 As Double

m3 As Double

m4 As Double

End Type

Type worldmat

m11 As Double

m12 As Double

m13 As Double

m14 As Double

m21 As Double

m22 As Double

m23 As Double

m24 As Double

m31 As Double

m32 As Double

m33 As Double

m34 As Double

m41 As Double

m42 As Double

m43 As Double

m44 As Double

End Type

Public Function AddTriangle(p1 As Long, p2 As Long, p3 As Long)


Dim vert1 As vertex

Dim vert2 As vertex

'num_Triangles = num_Triangles + 1

''ReDim Preserve TriangleList(num_Triangles + 1)

'TriangleList(num_Triangles).p1 = p1

'TriangleList(num_Triangles).p2 = p2

'TriangleList(num_Triangles).p3 = p3

'vert1.m1 = points(p2).m1 - points(p1).m1

'vert1.m2 = points(p2).m2 - points(p1).m2

'vert1.m3 = points(p2).m3 - points(p1).m3

'vert2.m1 = points(p2).m1 - points(p3).m1

'vert2.m1 = points(p2).m2 - points(p3).m2

'vert2.m1 = points(p2).m3 - points(p3).m3

'TriangleList(num_Triangles).Normal = CrossVector(vert1, vert2)

End Function

Public Function Reset_Display()

Form1.Label3 = "0"

Form1.Label4 = "0"

Form1.Label5 = "0"

Form1.Label8 = "0"

Form1.Label10 = "0"

Form1.Label11 = "0"

Form1.Label16 = "0"
Form1.Label17 = "0"

maxfps = 0

fps = 0

mat_world.m11 = 0

mat_world.m12 = 0

mat_world.m13 = 0

mat_world.m14 = 0

mat_world.m21 = 0

mat_world.m22 = 0

mat_world.m23 = 0

mat_world.m24 = 0

mat_world.m31 = 0

mat_world.m32 = 0

mat_world.m33 = 0

mat_world.m34 = 0

mat_world.m41 = 0

mat_world.m42 = 0

mat_world.m43 = 0

mat_world.m44 = 0

End Function

Public Function Restore_position()

For i = 1 To Num_Points

points(i) = Original(i)

Next i
End Function

Public Function Refresh_Display()

If RotateXY Then

Form1.Label3.Caption = Str$(Int(xaxis * 1000) / 1000) + "°"

Form1.Label4.Caption = Str$(Int(yaxis * 1000) / 1000) + "°"

Else

Form1.Label3.Caption = Str$(Int(xaxis * 1000) / 1000)

Form1.Label4.Caption = Str$(Int(yaxis * 1000) / 1000)

End If

Form1.Label16.Caption = num_lines

Form1.Label17.Caption = Num_Points

Form1.Label10.Caption = Str$(RenderTime) + " ms"

Form1.Label11.Caption = Str$(DrawTime) + " ms"

If fps <> 0 Then Form1.Label5.Caption = fps

Form1.Label8.Caption = maxfps

End Function

Public Function AddLine(ByVal p1 As Integer, ByVal p2 As Integer)

If Not Ignore And (p2 < 0 Or p1 < 0 Or p1 > Num_Points Or p2 > Num_Points) Then Exit Function

ReDim Preserve lines(num_lines + 1)

num_lines = num_lines + 1

lines(num_lines).p1 = p1

lines(num_lines).p2 = p2
End Function

Public Function AddPoint(ByVal x As Double, ByVal y As Double, ByVal z As Double)

Num_Points = Num_Points + 1

ReDim Preserve points(Num_Points + 1)

ReDim Preserve Original(Num_Points + 1)

Full_Mat = Mat_Rotate(xsum, ysum)

'points(Num_Points).m1 = x

'points(Num_Points).m2 = -y

'points(Num_Points).m3 = z

'points(Num_Points).m4 = 1

Original(Num_Points).m1 = x

Original(Num_Points).m2 = -y

Original(Num_Points).m3 = z

Original(Num_Points).m4 = 1

points(Num_Points) = transform(Original(Num_Points), Full_Mat)

End Function

Public Function Mat_multiply(Mat_1 As worldmat, Mat_2 As worldmat) As worldmat

Mat_multiply.m11 = Mat_2.m11 * Mat_2.m11 + Mat_1.m12 * Mat_2.m21 + Mat_1.m13 * Mat_2.m31 +


Mat_1.m14 * Mat_2.m41

Mat_multiply.m12 = Mat_2.m11 * Mat_2.m12 + Mat_1.m12 * Mat_2.m22 + Mat_1.m13 * Mat_2.m32 +


Mat_1.m14 * Mat_2.m42
Mat_multiply.m13 = Mat_2.m11 * Mat_2.m13 + Mat_1.m12 * Mat_2.m23 + Mat_1.m13 * Mat_2.m33 +
Mat_1.m14 * Mat_2.m43

Mat_multiply.m14 = Mat_2.m11 * Mat_2.m14 + Mat_1.m12 * Mat_2.m24 + Mat_1.m13 * Mat_2.m34 +


Mat_1.m14 * Mat_2.m44

Mat_multiply.m21 = Mat_2.m21 * Mat_2.m11 + Mat_1.m22 * Mat_2.m21 + Mat_1.m23 * Mat_2.m31 +


Mat_1.m24 * Mat_2.m41

Mat_multiply.m22 = Mat_2.m21 * Mat_2.m12 + Mat_1.m22 * Mat_2.m22 + Mat_1.m23 * Mat_2.m32 +


Mat_1.m24 * Mat_2.m42

Mat_multiply.m23 = Mat_2.m23 * Mat_2.m33 + Mat_1.m22 * Mat_2.m23 + Mat_1.m23 * Mat_2.m33 +


Mat_1.m24 * Mat_2.m43

Mat_multiply.m24 = Mat_2.m24 * Mat_2.m44 + Mat_1.m22 * Mat_2.m24 + Mat_1.m23 * Mat_2.m34 +


Mat_1.m24 * Mat_2.m44

Mat_multiply.m31 = Mat_2.m31 * Mat_2.m11 + Mat_1.m32 * Mat_2.m21 + Mat_1.m33 * Mat_2.m31 +


Mat_1.m34 * Mat_2.m41

Mat_multiply.m32 = Mat_2.m32 * Mat_2.m12 + Mat_1.m32 * Mat_2.m22 + Mat_1.m33 * Mat_2.m32 +


Mat_1.m34 * Mat_2.m42

Mat_multiply.m33 = Mat_2.m33 * Mat_2.m13 + Mat_1.m32 * Mat_2.m23 + Mat_1.m33 * Mat_2.m33 +


Mat_1.m34 * Mat_2.m43

Mat_multiply.m34 = Mat_2.m34 * Mat_2.m14 + Mat_1.m32 * Mat_2.m24 + Mat_1.m33 * Mat_2.m34 +


Mat_1.m34 * Mat_2.m44

Mat_multiply.m41 = Mat_2.m41 * Mat_2.m11 + Mat_1.m42 * Mat_2.m21 + Mat_1.m43 * Mat_2.m31 +


Mat_1.m44 * Mat_2.m41

Mat_multiply.m42 = Mat_2.m42 * Mat_2.m12 + Mat_1.m42 * Mat_2.m22 + Mat_1.m43 * Mat_2.m32 +


Mat_1.m44 * Mat_2.m42

Mat_multiply.m43 = Mat_2.m43 * Mat_2.m13 + Mat_1.m42 * Mat_2.m23 + Mat_1.m43 * Mat_2.m33 +


Mat_1.m44 * Mat_2.m43

Mat_multiply.m44 = Mat_2.m44 * Mat_2.m14 + Mat_1.m42 * Mat_2.m24 + Mat_1.m43 * Mat_2.m34 +


Mat_1.m44 * Mat_2.m44

End Function
Public Function f(ByVal x As Double, ByVal z As Double) As Double

f = 25 * Cos(Radians((Sqr(x * x + z * z) / 255) * 800))

End Function

Public Function transform(point As vertex, mat_transform As worldmat) As vertex

transform.m1 = point.m1 * mat_transform.m11 + point.m2 * mat_transform.m12 + point.m3 *


mat_transform.m13 + point.m4 * mat_transform.m14

transform.m2 = point.m1 * mat_transform.m21 + point.m2 * mat_transform.m22 + point.m3 *


mat_transform.m23 + point.m4 * mat_transform.m24

transform.m3 = point.m1 * mat_transform.m31 + point.m2 * mat_transform.m32 + point.m3 *


mat_transform.m33 + point.m4 * mat_transform.m34

transform.m4 = point.m1 * mat_transform.m41 + point.m2 * mat_transform.m42 + point.m3 *


mat_transform.m43 + point.m4 * mat_transform.m44

End Function

Public Function Radians(degrees As Double) As Double

Radians = (Atn(1) / 45) * degrees

End Function

Public Function Mat_Rotate(x As Double, y As Double) As worldmat

Mat_Rotate.m11 = Cos(Radians(y))

Mat_Rotate.m12 = Sin(Radians(x)) * Sin(Radians(y))

Mat_Rotate.m13 = Cos(Radians(x)) * (-1 * Sin(Radians(y)))

Mat_Rotate.m14 = 0

Mat_Rotate.m21 = 0

Mat_Rotate.m22 = Cos(Radians(x))

Mat_Rotate.m23 = Sin(Radians(x))
Mat_Rotate.m24 = 0

Mat_Rotate.m31 = Sin(Radians(y))

Mat_Rotate.m32 = Cos(Radians(y)) * (-1 * Sin(Radians(x)))

Mat_Rotate.m33 = Cos(Radians(y)) * Cos(Radians(x))

Mat_Rotate.m34 = 0

Mat_Rotate.m41 = 0

Mat_Rotate.m42 = 0

Mat_Rotate.m43 = 0

Mat_Rotate.m44 = 1

End Function

Public Function Mat_Move(x As Double, y As Double, z As Double) As worldmat

Mat_Move.m11 = 1

Mat_Move.m12 = 0

Mat_Move.m13 = 0

Mat_Move.m14 = x

Mat_Move.m21 = 0

Mat_Move.m22 = 1

Mat_Move.m23 = 0

Mat_Move.m24 = y

Mat_Move.m31 = 0

Mat_Move.m32 = 0

Mat_Move.m33 = 1

Mat_Move.m34 = z

Mat_Move.m41 = 0

Mat_Move.m42 = 0

Mat_Move.m43 = 0

Mat_Move.m44 = 1
End Function

Public Function c_degrees(Radians As Double)

c_degrees = (Radians / Atn(1)) * 45

End Function

Public Function GetFile(Filename As String)

Dim Path As String

Dim Fnum As Integer

' On Error GoTo ErrorHandler

' '---filename includes path?

' If InStr(1, File, "\") = 0 Then

' '---otherwise use App.Path

' Path = App.Path

' If Right(Path, 1) <> "\" Then

' File = Path & "\" & File

' Else

' File = Path & File

' End If

' End If

'---read file in one pass!

Fnum = FreeFile

Open Filename For Input As #Fnum

GetFile = Input(LOF(Fnum), Fnum)

Close Fnum
Exit Function

ErrorHandler:

Err.Description = "GetFile: " & Err.Description & " -> " & File

Err.Raise Err.Number

End Function

Vous aimerez peut-être aussi