home *** CD-ROM | disk | FTP | other *** search
- VERSION 1.0 CLASS
- BEGIN
- MultiUse = -1 'True
- END
- Attribute VB_Name = "ObjDisk"
- Attribute VB_Creatable = False
- Attribute VB_Exposed = False
- Option Explicit
-
- ' The plane that contains the disk.
- Private plane As New ObjPlane
-
- Private Center As Point3D ' Coordinates of center.
- Private Radius As Integer ' Radius.
-
- ' ************************************************
- ' Set constants for reflection.
- ' ************************************************
- Sub SetKr(r As Single, G As Single, B As Single)
- plane.SetKr r, G, B
- End Sub
-
- ' ************************************************
- ' Return the red, green, and blue components of
- ' the surface at the hit position.
- ' ************************************************
- Public Sub HitColor(depth As Integer, Objects As Collection, r As Integer, G As Integer, B As Integer)
- plane.HitColor depth, Objects, r, G, B
- End Sub
-
- ' ************************************************
- ' Compute the distance from point (px, py, pz)
- ' along vector <vx, vy, vz> to the disk.
- ' ************************************************
- Public Function RayDistance(px As Single, py As Single, pz As Single, Vx As Single, Vy As Single, Vz As Single) As Single
- Dim dist As Single
- Dim x As Single
- Dim y As Single
- Dim z As Single
- Dim dx As Single
- Dim dy As Single
- Dim dz As Single
-
- ' Find the distance to the plane.
- dist = plane.RayDistance(px, py, pz, Vx, Vy, Vz)
-
- ' If there is no good intersection with the
- ' plane, there's none with the disk.
- If dist >= INFINITY Then
- RayDistance = INFINITY
- Exit Function
- End If
-
- ' See if the point of intersection lies within
- ' the disk.
-
- ' Get the hit location.
- plane.HitLocation x, y, z
-
- ' See if the point lies within distance Radius
- ' of the center.
- dx = Center.trans(1) - x
- dy = Center.trans(2) - y
- dz = Center.trans(3) - z
- If Sqr(dx * dx + dy * dy + dz * dz) > Radius Then
- RayDistance = INFINITY
- Exit Function
- End If
-
- RayDistance = dist
- End Function
-
-
-
- ' ***********************************************
- ' Define the plane that contains the disk.
- ' ***********************************************
- Public Sub Initialize(r As Single, cx As Single, cy As Single, cz As Single, nx As Single, ny As Single, nz As Single)
- Radius = r
- Center.coord(1) = cx
- Center.coord(2) = cy
- Center.coord(3) = cz
- Center.coord(4) = 1
- plane.Initialize cx, cy, cz, nx, ny, nz
- End Sub
-
-
-
- ' ************************************************
- ' Set constants for diffuse reflection.
- ' ************************************************
- Sub SetKd(r As Single, G As Single, B As Single)
- plane.SetKd r, G, B
- End Sub
- ' ************************************************
- ' Set constants for ambient light.
- ' ************************************************
- Sub SetKa(r As Single, G As Single, B As Single)
- plane.SetKa r, G, B
- End Sub
- ' ************************************************
- ' Set N and Ks for specular reflection.
- ' ************************************************
- Sub SetSpec(n As Single, s As Single)
- plane.SetSpec n, s
- End Sub
-
- ' ************************************************
- ' Apply a transformation matrix to the object.
- ' ************************************************
- Public Sub Apply(M() As Single)
- m3Apply Center.coord, M, Center.trans
- plane.Apply M
- End Sub
-
-
-
-
-
-
-