home *** CD-ROM | disk | FTP | other *** search
- VERSION 4.00
- Begin VB.Form UpForm
- Appearance = 0 'Flat
- BackColor = &H00C0C0C0&
- Caption = "Up"
- ClientHeight = 5505
- ClientLeft = 330
- ClientTop = 1020
- ClientWidth = 9060
- BeginProperty Font
- name = "MS Sans Serif"
- charset = 1
- weight = 700
- size = 8.25
- underline = 0 'False
- italic = 0 'False
- strikethrough = 0 'False
- EndProperty
- ForeColor = &H80000008&
- Height = 6195
- KeyPreview = -1 'True
- Left = 270
- LinkTopic = "Form1"
- ScaleHeight = 5505
- ScaleWidth = 9060
- Top = 390
- Width = 9180
- Begin VB.PictureBox PPict
- AutoRedraw = -1 'True
- Height = 2175
- Left = 6840
- ScaleHeight = -10
- ScaleLeft = -5
- ScaleMode = 0 'User
- ScaleTop = 5
- ScaleWidth = 10
- TabIndex = 12
- Top = 2760
- Width = 2175
- End
- Begin VB.PictureBox Pict
- AutoRedraw = -1 'True
- Height = 2175
- Index = 0
- Left = 1200
- ScaleHeight = -10
- ScaleLeft = -5
- ScaleMode = 0 'User
- ScaleTop = 5
- ScaleWidth = 10
- TabIndex = 5
- Top = 0
- Width = 2175
- End
- Begin VB.PictureBox Pict
- AutoRedraw = -1 'True
- Height = 2175
- Index = 1
- Left = 3480
- ScaleHeight = -10
- ScaleLeft = -5
- ScaleMode = 0 'User
- ScaleTop = 5
- ScaleWidth = 10
- TabIndex = 4
- Top = 0
- Width = 2175
- End
- Begin VB.PictureBox Pict
- AutoRedraw = -1 'True
- Height = 2175
- Index = 2
- Left = 5760
- ScaleHeight = -10
- ScaleLeft = -5
- ScaleMode = 0 'User
- ScaleTop = 5
- ScaleWidth = 10
- TabIndex = 3
- Top = 0
- Width = 2175
- End
- Begin VB.PictureBox Pict
- AutoRedraw = -1 'True
- Height = 2175
- Index = 3
- Left = 0
- ScaleHeight = -10
- ScaleLeft = -5
- ScaleMode = 0 'User
- ScaleTop = 5
- ScaleWidth = 10
- TabIndex = 2
- Top = 2760
- Width = 2175
- End
- Begin VB.PictureBox Pict
- AutoRedraw = -1 'True
- Height = 2175
- Index = 4
- Left = 2280
- ScaleHeight = -10
- ScaleLeft = -5
- ScaleMode = 0 'User
- ScaleTop = 5
- ScaleWidth = 10
- TabIndex = 1
- Top = 2760
- Width = 2175
- End
- Begin VB.PictureBox Pict
- AutoRedraw = -1 'True
- Height = 2175
- Index = 5
- Left = 4560
- ScaleHeight = -10
- ScaleLeft = -5
- ScaleMode = 0 'User
- ScaleTop = 5
- ScaleWidth = 10
- TabIndex = 0
- Top = 2760
- Width = 2175
- End
- Begin VB.Label Label1
- Alignment = 2 'Center
- Caption = "Final projection"
- Height = 255
- Index = 6
- Left = 6840
- TabIndex = 13
- Top = 5040
- Width = 2175
- WordWrap = -1 'True
- End
- Begin VB.Label Label1
- Alignment = 2 'Center
- Caption = "Original picture"
- Height = 255
- Index = 0
- Left = 1200
- TabIndex = 11
- Top = 2280
- Width = 2175
- WordWrap = -1 'True
- End
- Begin VB.Label Label1
- Alignment = 2 'Center
- Caption = "Translate focus to origin"
- Height = 255
- Index = 1
- Left = 3480
- TabIndex = 10
- Top = 2280
- Width = 2175
- WordWrap = -1 'True
- End
- Begin VB.Label Label1
- Alignment = 2 'Center
- Caption = "Rotate center of projection into Y-Z plane"
- Height = 495
- Index = 2
- Left = 5760
- TabIndex = 9
- Top = 2280
- Width = 2175
- WordWrap = -1 'True
- End
- Begin VB.Label Label1
- Alignment = 2 'Center
- Caption = "Rotate center of projection into Z axis"
- Height = 375
- Index = 3
- Left = 0
- TabIndex = 8
- Top = 5040
- Width = 2175
- WordWrap = -1 'True
- End
- Begin VB.Label Label1
- Alignment = 2 'Center
- Caption = "Rotate UP into Y-Z plane"
- Height = 255
- Index = 4
- Left = 2280
- TabIndex = 7
- Top = 5040
- Width = 2175
- WordWrap = -1 'True
- End
- Begin VB.Label Label1
- Alignment = 2 'Center
- Caption = "Project onto X-Y plane"
- Height = 255
- Index = 5
- Left = 4560
- TabIndex = 6
- Top = 5040
- Width = 2175
- WordWrap = -1 'True
- End
- Begin VB.Menu mnuFile
- Caption = "&File"
- Begin VB.Menu mnuFileExit
- Caption = "E&xit"
- End
- End
- Attribute VB_Name = "UpForm"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
- Dim FirstCube As Integer
- ' Viewing parameters.
- Dim EyeR As Single ' Center of projection.
- Dim EyeTheta As Single
- Dim EyePhi As Single
- Const FocusX = 0# ' Focus point.
- Const FocusY = 0#
- Const FocusZ = 0#
- ' Projection parameters.
- Dim UpX As Single ' Up vector.
- Dim UpY As Single
- Dim UpZ As Single
- Dim cx As Single ' Center of projection.
- Dim cy As Single
- Dim cz As Single
- Dim Fx As Single ' Focus point.
- Dim Fy As Single
- Dim Fz As Single
- ' Matrices used for the projection.
- Dim M(0 To 5) As Transformation
- Dim Projector(1 To 4, 1 To 4) As Single
- Dim P(1 To 4, 1 To 4) As Single
- ' ***********************************************
- ' Create transformation matrices for perspective
- ' projection with:
- ' focus point (focx, focy, focz)
- ' center of projection (ex, ey, ez)
- ' up vector <ux, uy, uz>
- ' ***********************************************
- Sub CreateMatrices(focx As Single, focy As Single, focz As Single, ex As Single, ey As Single, ez As Single, ux As Single, uy As Single, uz As Single)
- Dim sin1 As Single
- Dim cos1 As Single
- Dim sin2 As Single
- Dim cos2 As Single
- Dim sin3 As Single
- Dim cos3 As Single
- Dim A As Single
- Dim B As Single
- Dim C As Single
- Dim d1 As Single
- Dim d2 As Single
- Dim d3 As Single
- Dim up1(1 To 4) As Single
- Dim up2(1 To 4) As Single
- ' Identity transformation.
- m3Identity M(0).M
- ' Translate the focus to the origin.
- m3Translate M(1).M, -focx, -focy, -focz
- A = ex - focx
- B = ey - focy
- C = ez - focz
- d1 = Sqr(A * A + C * C)
- sin1 = -A / d1
- cos1 = C / d1
- d2 = Sqr(A * A + B * B + C * C)
- sin2 = B / d2
- cos2 = d1 / d2
- ' Rotate around the Y axis to place the
- ' center of projection in the Y-Z plane.
- m3Identity M(2).M
- M(2).M(1, 1) = cos1
- M(2).M(1, 3) = -sin1
- M(2).M(3, 1) = sin1
- M(2).M(3, 3) = cos1
- ' Rotate around the X axis to place the
- ' center of projection in the Z axis.
- m3Identity M(3).M
- M(3).M(2, 2) = cos2
- M(3).M(2, 3) = sin2
- M(3).M(3, 2) = -sin2
- M(3).M(3, 3) = cos2
- ' Apply the rotations to the UP vector.
- up1(1) = ux
- up1(2) = uy
- up1(3) = uz
- up1(4) = 1
- m3Apply up1, M(2).M, up2
- m3Apply up2, M(3).M, up1
- ' Rotate around the Z axis to put the UP
- ' vector in the Y-Z plane.
- d3 = Sqr(up1(1) * up1(1) + up1(2) * up1(2))
- sin3 = up1(1) / d3
- cos3 = up1(2) / d3
- m3Identity M(4).M
- M(4).M(1, 1) = cos3
- M(4).M(1, 2) = sin3
- M(4).M(2, 1) = -sin3
- M(4).M(2, 2) = cos3
- ' Project.
- m3PerspectiveXZ M(5).M, d2
- ' Compute the projection all in one shot.
- m3Project P, m3Perspective, ex, ey, ez, focx, focy, focz, ux, uy, uz
- End Sub
- ' ***********************************************
- ' Let the user change the location of the eye.
- ' ***********************************************
- Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
- Const Dtheta = PI / 20
- Const Dx = 0.25
- Dim inc As Single
- If Shift And 1 Then
- inc = Dx
- Else
- inc = -Dx
- End If
- Select Case KeyCode
- Case vbKeyLeft
- EyeTheta = EyeTheta - Dtheta
-
- Case vbKeyRight
- EyeTheta = EyeTheta + Dtheta
-
- Case vbKeyUp
- EyePhi = EyePhi - Dtheta
-
- Case vbKeyDown
- EyePhi = EyePhi + Dtheta
-
- Case Asc("X")
- UpX = UpX + inc
- Case Asc("Y")
- UpY = UpY + inc
- Case Asc("Z")
- UpZ = UpZ + inc
-
- Case Else
- Exit Sub
- End Select
- ' Redraw the pictures.
- DrawTheData
- End Sub
- Private Sub Form_Load()
- ' Initialize the viewing parameters.
- EyeR = 3
- EyeTheta = PI * 0.35
- EyePhi = PI * 0.1
- ' Initialize projection parameters.
- UpX = -1
- UpY = 1.5
- UpZ = 0
- cx = 2
- cy = 2.5
- cz = 3
- Fx = 1
- Fy = 1
- Fz = 1
- ' Create, project, and draw the data.
- DrawTheData
- End Sub
- ' ***********************************************
- ' Draw all the pictures.
- ' ***********************************************
- Sub DrawTheData()
- Dim i As Integer
- CreateData
- CreateMatrices Fx, Fy, Fz, cx, cy, cz, UpX, UpY, UpZ
- ' Compute the projection matrix.
- m3PProject Projector, m3Parallel, EyeR, EyePhi, EyeTheta, FocusX, FocusY, FocusZ, 0, 1, 0
- For i = 0 To 5
- TransformData M(i).M, FirstCube, NumSegments
- SetPoints FirstCube, NumSegments
- TransformData Projector, 1, NumSegments
- DrawSomeData Pict(i), 1, NumSegments - 2, ForeColor, True
- Pict(i).DrawWidth = 3
- DrawSomeData Pict(i), NumSegments - 1, NumSegments - 1, vbRed, False
- DrawSomeData Pict(i), NumSegments, NumSegments, vbGreen, False
- Pict(i).DrawWidth = DrawWidth
- Pict(i).Refresh
- Next i
- ' For the final view use the transformation
- ' given by m3PerspectiveProjectionUp
- CreateData
- TransformData P, FirstCube, NumSegments
- DrawSomeData PPict, FirstCube, NumSegments - 2, ForeColor, True
- PPict.DrawWidth = 3
- DrawSomeData PPict, NumSegments - 1, NumSegments - 1, vbRed, False
- DrawSomeData PPict, NumSegments, NumSegments, vbGreen, False
- PPict.DrawWidth = DrawWidth
- PPict.Refresh
- End Sub
- Sub CreateData()
- ' Start with no data.
- NumSegments = 0
- ' Create the axes.
- MakeSegment 0, 0, 0, 4, 0, 0 ' X axis.
- MakeSegment 0, 0, 0, 0, 4, 0 ' Y axis.
- MakeSegment 0, 0, 0, 0, 0, 4 ' Z axis.
-
- FirstCube = NumSegments + 1
- ' Create the object to reflect.
- MakeSegment -1, -1, -1, -1, -1, 3
- MakeSegment -1, -1, 3, -1, 3, 3
- MakeSegment -1, 3, 3, -1, 3, -1
- MakeSegment -1, 3, -1, -1, -1, -1
- MakeSegment 3, -1, -1, 3, -1, 3
- MakeSegment 3, -1, 3, 3, 3, 3
- MakeSegment 3, 3, 3, 3, 3, -1
- MakeSegment 3, 3, -1, 3, -1, -1
- MakeSegment -1, -1, -1, 3, -1, -1
- MakeSegment -1, -1, 3, 3, -1, 3
- MakeSegment -1, 3, 3, 3, 3, 3
- MakeSegment -1, 3, -1, 3, 3, -1
- ' Up vector.
- MakeSegment Fx, Fy, Fz, Fx + UpX, Fy + UpY, Fz + UpZ
- ' Center of projection.
- MakeSegment Fx, Fy, Fz, cx, cy, cz
- End Sub
- Private Sub mnuFileExit_Click()
- Unload Me
- End Sub
-