i'm learning Math for 3D...
for now i can draw a plane and convert 3D to 2D(the screen is 2D):
Private Function ConvertPositon3DTo2D(Position As Position3D, World3DSize As Size3D) As POINTAPI
Dim ConvertedPosition As POINTAPI
Dim PosZZDepth As Long
PosZZDepth = Position.Z + World3DSize.Distance
If (PosZZDepth = 0) Then PosZZDepth = 1 'avoiding division by zero
Dim Width As Double
Dim Height As Double
Width = World3DSize.Width / 2
If (Width = 0) Then Width = 0
Height = World3DSize.Height / 2
If (Height = 0) Then Height = 0
ConvertedPosition.X = (Position.X * World3DSize.Distance / PosZZDepth) + Width
ConvertedPosition.Y = (Position.Y * World3DSize.Distance / PosZZDepth) + Height
ConvertPositon3DTo2D = ConvertedPosition
End Function
Private Sub DrawPlane(Position As Position3D, Size As Size3D, Rotation As Angle3D, WorldSize As Size3D, color As ColorConstants)
Dim Points(4) As POINTAPI
Dim NewPoint As POINTAPI
Dim NewPosition3D As Position3D
Dim RotatedPosition As Position3D
Dim DestinyPosition As Position3D
Static FixedPoint0(4) As Position3D
Dim sizeD As Size3D
Dim temp As Double
FillSize3D sizeD, 0, 0, 0
'FillPosition3D RotatedPosition, Position.X + Size.Width / 2, Position.Y + Size.Height / 2, Position.Z + Size.ZDepth / 2
With Player1.Position
FillPosition3D RotatedPosition, .X, .Y, .Z 'Camera Position
End With
If (IsCollision3D(camera1.Position, camera1.Size, Position, Size) = False) Then Exit Sub
'Floor:
'Vector1
FillPosition3D NewPosition3D, Position.X, Position.Y, Position.Z
NewPosition3D = Rotate(NewPosition3D, Rotation, RotatedPosition)
If (IsOnCamera(NewPosition3D, sizeD, camera1.Position, camera1.Size) = True) Then
FixedPoint0(0) = NewPosition3D
Else
NewPosition3D = FixedPoint0(0)
End If
NewPoint = ConvertPositon3DTo2D(NewPosition3D, camera1.Size)
Points(0) = NewPoint
'Vector2
FillPosition3D NewPosition3D, Position.X, Position.Y, Position.Z + Size.ZDepth
NewPosition3D = Rotate(NewPosition3D, Rotation, RotatedPosition)
If (IsOnCamera(NewPosition3D, sizeD, camera1.Position, camera1.Size) = True) Then
FixedPoint0(1) = NewPosition3D
Else
NewPosition3D = FixedPoint0(1)
End If
NewPoint = ConvertPositon3DTo2D(NewPosition3D, camera1.Size)
Points(1) = NewPoint
'Vector3
FillPosition3D NewPosition3D, Position.X + Size.Width, Position.Y, Position.Z + Size.ZDepth
NewPosition3D = Rotate(NewPosition3D, Rotation, RotatedPosition)
If (IsOnCamera(NewPosition3D, sizeD, camera1.Position, camera1.Size) = True) Then
FixedPoint0(2) = NewPosition3D
Else
NewPosition3D = FixedPoint0(2)
End If
NewPoint = ConvertPositon3DTo2D(NewPosition3D, camera1.Size)
Points(2) = NewPoint
'Vector4
FillPosition3D NewPosition3D, Position.X + Size.Width, Position.Y + Size.Height, Position.Z
NewPosition3D = Rotate(NewPosition3D, Rotation, RotatedPosition)
If (IsOnCamera(NewPosition3D, sizeD, camera1.Position, camera1.Size) = True) Then
FixedPoint0(3) = NewPosition3D
Else
NewPosition3D = FixedPoint0(3)
End If
NewPoint = ConvertPositon3DTo2D(NewPosition3D, camera1.Size)
Points(3) = NewPoint
FillStyle = vbFSSolid
FillColor = color
Polygon Me.hdc, Points(0), 4
End Sub
the plane is drawed correctly but when we move, the plane is like transformed into 2 triangles...
for avoid these i must avoid draw the hidde parts...
i'm trying it using the:
Private Function IsOnCamera(VerticePosition As Position3D, VerticeSize As Size3D, CameraPosition As Position3D, CameraSize As Size3D) As Boolean
If ((VerticePosition.Z) >= CameraPosition.Z And (VerticePosition.Z) <= (CameraPosition.Z + CameraSize.ZDepth) _
And ((VerticePosition.Y) >= CameraPosition.Y And (VerticePosition.Y) <= (CameraPosition.Y + CameraSize.Height))) Then
'And ((VerticePosition.X) >= CameraPosition.X And VerticePosition.X <= (CameraPosition.X + CameraSize.Width))) Then
Me.Caption = CStr(CameraPosition.X)
IsOnCamera = True
Else
IsOnCamera = False
End If
End Function
but i'm getting trouble on control the 'X'... can anyone explain to me how avoid drawing the hidden parts on a shape?