home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2002 March / PCWMAR02.iso / software / turbocad / v8trial / TurboCADv8ProfessionalNoReg.exe / Data.Cab / F40749_frmCamera.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2001-10-16  |  11.1 KB  |  354 lines

  1. VERSION 5.00
  2. Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} frmCamera 
  3.    Caption         =   "SDK Camera Test"
  4.    ClientHeight    =   5760
  5.    ClientLeft      =   36
  6.    ClientTop       =   336
  7.    ClientWidth     =   8832
  8.    OleObjectBlob   =   "frmCamera.frx":0000
  9.    StartUpPosition =   1  'CenterOwner
  10. Attribute VB_Name = "frmCamera"
  11. Attribute VB_GlobalNameSpace = False
  12. Attribute VB_Creatable = False
  13. Attribute VB_PredeclaredId = True
  14. Attribute VB_Exposed = False
  15. '******************************************************************'
  16. '*                                                                *'
  17. '*                      TurboCAD for Windows                      *'
  18. '*                   Copyright (c) 1993 - 2001                    *'
  19. '*             International Microcomputer Software, Inc.         *'
  20. '*                            (IMSI)                              *'
  21. '*                      All rights reserved.                      *'
  22. '*                                                                *'
  23. '******************************************************************'
  24. Const zoom_factor = 1.5
  25. Const slide_factor = 0.1
  26. Const tilt_pan_factor = 3.14159265358979 / 18 ' 10 degrees
  27. Const rotate_factor = 3.14159265358979 / 18 ' 10 degrees
  28. Private hwndForm As Long
  29. Private vwForm As View
  30. 'FindWindow Win32 API
  31. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
  32.    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  33. Private Sub ClearCameraParams()
  34.     tbxPosX = "Not available"
  35.     tbxPosY = "Not available"
  36.     tbxPosZ = "Not available"
  37.     tbxLookAtX = "Not available"
  38.     tbxLookAtY = "Not available"
  39.     tbxLookAtZ = "Not available"
  40.     tbxDirX = "Not available"
  41.     tbxDirY = "Not available"
  42.     tbxDirZ = "Not available"
  43.     tbxUpX = "Not available"
  44.     tbxUpY = "Not available"
  45.     tbxUpZ = "Not available"
  46.     tbxRightX = "Not available"
  47.     tbxRightY = "Not available"
  48.     tbxRightZ = "Not available"
  49.     btnPerspective.Caption = "Not available"
  50. End Sub
  51. Private Sub RefreshCameraParams(gxCam As Camera)
  52.     Dim gxVrt As Vertex
  53.     Set gxVrt = gxCam.Location
  54.     tbxPosX = Round(gxVrt.X, 6)
  55.     tbxPosY = Round(gxVrt.Y, 6)
  56.     tbxPosZ = Round(gxVrt.Z, 6)
  57.     Set gxVrt = gxCam.LookAt
  58.     tbxLookAtX = Round(gxVrt.X, 6)
  59.     tbxLookAtY = Round(gxVrt.Y, 6)
  60.     tbxLookAtZ = Round(gxVrt.Z, 6)
  61.     Set gxVrt = gxCam.Direction
  62.     tbxDirX = Round(gxVrt.X, 6)
  63.     tbxDirY = Round(gxVrt.Y, 6)
  64.     tbxDirZ = Round(gxVrt.Z, 6)
  65.     Set gxVrt = gxCam.Up
  66.     tbxUpX = Round(gxVrt.X, 6)
  67.     tbxUpY = Round(gxVrt.Y, 6)
  68.     tbxUpZ = Round(gxVrt.Z, 6)
  69.     Set gxVrt = gxCam.Right
  70.     tbxRightX = Round(gxVrt.X, 6)
  71.     tbxRightY = Round(gxVrt.Y, 6)
  72.     tbxRightZ = Round(gxVrt.Z, 6)
  73.     If (gxCam.Perspective) Then
  74.         btnPerspective.Caption = "Perspective"
  75.     Else
  76.         btnPerspective.Caption = "Not Perspective"
  77.     End If
  78. End Sub
  79. Private Sub RefreshViewParams(gxVw As View)
  80.     tbxVwLeft = Round(gxVw.ViewLeft, 6)
  81.     tbxVwTop = Round(gxVw.ViewTop, 6)
  82.     tbxVwWidth = Round(gxVw.ViewWidth, 6)
  83.     tbxVwHeight = Round(gxVw.ViewHeight, 6)
  84. End Sub
  85. Private Sub btnOrbit_Click()
  86.     Dim gxVw As View
  87.     Dim gxCam As Camera
  88.     Dim rf As Double
  89.     rf = rotate_factor
  90.     Set gxVw = ActiveDrawing.ActiveView
  91.     If (gxVw.SpaceMode = imsiModelSpace) Then
  92.         Set gxCam = gxVw.Camera
  93.         gxCam.Perspective = True
  94.         gxCam.Orbit rf, True, 10, 0, 0
  95.         gxVw.Refresh
  96.         gxCam.Perspective = False
  97.         RefreshCameraParams gxCam
  98.     Else
  99.         MsgBox "Not available for Paper Space view"
  100.     End If
  101.     RefreshViewParams gxVw
  102. End Sub
  103. Private Sub btnPan_Click()
  104.     Dim gxVw As View
  105.     Dim gxCam As Camera
  106.     Dim pf As Double
  107.     pf = tilt_pan_factor
  108.     Set gxVw = ActiveDrawing.ActiveView
  109.     If (gxVw.SpaceMode = imsiModelSpace) Then
  110.         Set gxCam = gxVw.Camera
  111.         gxCam.Pan pf
  112.         gxVw.Refresh
  113.        RefreshCameraParams gxCam
  114.     Else
  115.         MsgBox "Not available for Paper Space view"
  116.     End If
  117.     RefreshViewParams gxVw
  118. End Sub
  119. Private Sub btnRotate_Click()
  120.     Dim gxVw As View
  121.     Dim gxCam As Camera
  122.     Dim rf As Double
  123.     rf = rotate_factor
  124.     Set gxVw = ActiveDrawing.ActiveView
  125.     If (gxVw.SpaceMode = imsiModelSpace) Then
  126.         Set gxCam = gxVw.Camera
  127.         gxCam.Perspective = True
  128.         gxCam.Rotate rf, True, 10, 0, 0
  129.         gxVw.Refresh
  130.         gxCam.Perspective = False
  131.        RefreshCameraParams gxCam
  132.     Else
  133.         MsgBox "Not available for Paper Space view"
  134.     End If
  135.     RefreshViewParams gxVw
  136. End Sub
  137. Private Sub ScrollViewLeftOrRight(ByVal gxVw As View, ByVal sf As Double)
  138.     Dim gxCam As Camera
  139.     Dim dSlide As Double
  140.     dSlide = sf * gxVw.ViewWidth
  141.     If (gxVw.SpaceMode = imsiModelSpace) Then
  142.         Set gxCam = gxVw.Camera
  143.         gxCam.Slide 0, dSlide
  144.         gxVw.Refresh
  145.        RefreshCameraParams gxCam
  146.     Else
  147.         gxVw.Update = False
  148.         gxVw.Left = gxVw.Left + dSlide
  149.         gxVw.Update = False
  150.     End If
  151.     RefreshViewParams gxVw
  152. End Sub
  153. Private Sub ScrollViewUpOrDown(ByVal gxVw As View, ByVal sf As Double)
  154.     Dim gxCam As Camera
  155.     Dim dSlide As Double
  156.     dSlide = sf * gxVw.ViewHeight
  157.     If (gxVw.SpaceMode = imsiModelSpace) Then
  158.         Set gxCam = gxVw.Camera
  159.         gxCam.Slide dSlide, 0
  160.         gxVw.Refresh
  161.        RefreshCameraParams gxCam
  162.     Else
  163.         gxVw.Update = False
  164.         gxVw.Top = gxVw.Top + dSlide
  165.         gxVw.Update = False
  166.     End If
  167.     RefreshViewParams gxVw
  168. End Sub
  169. Private Sub btnScrollLeft_Click()
  170.     ScrollViewLeftOrRight ActiveDrawing.ActiveView, -slide_factor
  171. End Sub
  172. Private Sub btnScrollRight_Click()
  173.     ScrollViewLeftOrRight ActiveDrawing.ActiveView, slide_factor
  174. End Sub
  175. Private Sub btnScrollUp_Click()
  176.     ScrollViewUpOrDown ActiveDrawing.ActiveView, -slide_factor
  177. End Sub
  178. Private Sub btnScrollDown_Click()
  179.     ScrollViewUpOrDown ActiveDrawing.ActiveView, slide_factor
  180. End Sub
  181. Private Sub btnTilt_Click()
  182.     Dim gxVw As View
  183.     Dim gxCam As Camera
  184.     Dim tf As Double
  185.     tf = tilt_pan_factor
  186.     Set gxVw = ActiveDrawing.ActiveView
  187.     If (gxVw.SpaceMode = imsiModelSpace) Then
  188.         Set gxCam = gxVw.Camera
  189.         gxCam.Tilt tf
  190.         gxVw.Refresh
  191.         RefreshCameraParams gxCam
  192.     Else
  193.         MsgBox "Not available for Paper Space view"
  194.     End If
  195.     RefreshViewParams gxVw
  196. End Sub
  197. Private Sub ZoomView(ByVal gxVw As View, ByVal zf As Double)
  198.     Dim gxCam As Camera
  199.     Dim x0 As Double
  200.     Dim y0 As Double
  201.     If (gxVw.SpaceMode = imsiModelSpace) Then
  202.         Set gxCam = gxVw.Camera
  203.         gxCam.zoom zf
  204.         gxVw.Refresh
  205.         RefreshCameraParams gxCam
  206.     Else
  207.         x0 = gxVw.Left + gxVw.ViewWidth / 2
  208.         y0 = gxVw.Top - gxVw.ViewHeight / 2
  209.         gxVw.Update = False
  210.         
  211.         gxVw.ViewWidth = gxVw.ViewWidth / zf
  212.         gxVw.ViewHeight = gxVw.ViewHeight / zf
  213.         
  214.         gxVw.Left = x0 - gxVw.ViewWidth / 2
  215.         gxVw.Top = y0 + gxVw.ViewHeight / 2
  216.         gxVw.Update = False
  217.     End If
  218.     RefreshViewParams gxVw
  219. End Sub
  220. Private Sub ZoomViewToExtents(ByVal gxVw As View)
  221.     Dim gxCam As Camera
  222.     gxVw.ZoomToExtents
  223.     If (gxVw.SpaceMode = imsiModelSpace) Then
  224.         Set gxCam = gxVw.Camera
  225.         RefreshCameraParams gxCam
  226.     Else
  227.         ClearCameraParams
  228.     End If
  229.     RefreshViewParams gxVw
  230. End Sub
  231. Private Sub btnZoomIn_Click()
  232.     ZoomView ActiveDrawing.ActiveView, 1 / zoom_factor
  233. End Sub
  234. Private Sub btnZoomOut_Click()
  235.     ZoomView ActiveDrawing.ActiveView, zoom_factor
  236. End Sub
  237. Private Sub btnZoomAll_Click()
  238.     Dim vwActive As View
  239.     Set vwActive = ActiveDrawing.ActiveView
  240.     If Not vwForm Is Nothing Then
  241.         ZoomViewToExtents vwForm
  242.     End If
  243.     ZoomViewToExtents vwActive
  244. End Sub
  245. Private Sub btnPerspective_Click()
  246.     Dim gxVw As View
  247.     Dim gxCam As Camera
  248.     Set gxVw = ActiveDrawing.ActiveView
  249.     If (gxVw.SpaceMode = imsiModelSpace) Then
  250.         Set gxCam = gxVw.Camera
  251.         
  252.         If (gxCam.Perspective) Then
  253.             gxCam.Perspective = False
  254.         Else
  255.             gxCam.Perspective = True
  256.         End If
  257.         
  258.         gxVw.Refresh
  259.         
  260.         RefreshCameraParams gxCam
  261.         RefreshViewParams gxCam
  262.     Else
  263.         MsgBox "Not available for Paper Space view"
  264.     End If
  265. End Sub
  266. Private Sub btnHiddenLine_Click()
  267.     Dim gxVw As View
  268.     Dim gxRVw As RenderView
  269.     Dim gxRnds As Renders
  270.     Dim gxRnd As Render
  271.     Set gxVw = ActiveDrawing.ActiveView
  272.     If (gxVw.SpaceMode = imsiModelSpace) Then
  273.         Set gxRVw = gxVw.RenderView
  274.         
  275.         If (gxRVw.IsRenderRunned) Then
  276.             gxRVw.EndRender
  277.         Else
  278.             Set gxRnds = Application.Renders
  279.             Set gxRnd = gxRnds("Hidden Line")
  280.                 
  281.             gxRnd.Run gxVw
  282.         End If
  283.     Else
  284.         MsgBox "Not available for Paper Space view"
  285.     End If
  286. End Sub
  287. Private Sub AddFormView()
  288.     Dim vwActive As View
  289.     Dim dScale As Double
  290.     On Error GoTo NoView
  291.     If vwForm Is Nothing Then
  292.         hwndForm = FindWindow(vbNullString, frmCamera.Caption)
  293.         If hwndForm = 0 Then GoTo NoView
  294.         
  295.         Set vwActive = ActiveDrawing.ActiveView
  296.         Set vwForm = ActiveDrawing.Views.Add(hwndForm)
  297.         
  298.         'Set up basic View behavior
  299.         vwForm.FixedAspectRatio = True
  300.         vwForm.Margins = True
  301.         vwForm.CenterOnExtents = True
  302.         vwForm.SpaceMode = vwActive.SpaceMode
  303.         
  304.         'Scale from dialog units to pixels
  305.         dScale = 4# / 3#
  306.         vwForm.ScreenWidth = fraView.width * dScale
  307.         vwForm.ScreenHeight = fraView.height * dScale
  308.         vwForm.ScreenLeft = fraView.Left * dScale
  309.         vwForm.ScreenTop = fraView.Top * dScale
  310.         
  311.         'Copy the rest from primary view
  312.         vwForm.ViewWidth = vwActive.ViewWidth
  313.         vwForm.ViewHeight = vwActive.ViewHeight
  314.         vwForm.ViewLeft = vwActive.ViewLeft
  315.         vwForm.ViewTop = vwActive.ViewTop
  316.         
  317.         'And camera
  318.         vwForm.Camera.Location = vwActive.Camera.Location
  319.         vwForm.Camera.Up = vwActive.Camera.Up
  320.         vwForm.Camera.LookAt = vwActive.Camera.LookAt
  321.         
  322.         ZoomViewToExtents vwForm
  323.     End If
  324.     Exit Sub
  325. NoView:
  326.     Set vwForm = Nothing
  327.     MsgBox "Error setting up view"
  328. End Sub
  329. Private Sub UserForm_Activate()
  330.     Dim gxVw As View
  331.     Dim gxCam As Camera
  332.     Set gxVw = ActiveDrawing.ActiveView
  333.     If (gxVw.SpaceMode = imsiModelSpace) Then
  334.         Set gxCam = gxVw.Camera
  335.         RefreshCameraParams gxCam
  336.     Else
  337.         ClearCameraParams
  338.     End If
  339.     AddFormView
  340.     RefreshViewParams gxVw
  341. End Sub
  342. Private Sub UserForm_Click()
  343.     Dim gxVw As View
  344.     Dim gxCam As Camera
  345.     Set gxVw = ActiveDrawing.ActiveView
  346.     RefreshViewParams gxVw
  347.     If (gxVw.SpaceMode = imsiModelSpace) Then
  348.         Set gxCam = gxVw.Camera
  349.         RefreshCameraParams gxVw
  350.     Else
  351.         ClearCameraParams
  352.     End If
  353. End Sub
  354.