🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Math World 3D: how avoid hidden parts?

Started by
3 comments, last by Tom Sloper 4 years ago

i have a function for create a plane just using Math 3D:

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

heres the function for convert 3D to 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

when the plane\areas are drawed outside the camera, i get drawed incorrectly(like 2 triangles)…
how can avoid, correctly, drawed the hidden areas of the plane?

Advertisement

Visual Basic isn't a programming language used by many game developers. I can't remember the last time I saw a VB question here. Not to say you can't use it successfully, but you're not going to find many people able to help with VB + game dev question.

🙂🙂🙂🙂🙂<←The tone posse, ready for action.

fleabay: i belive you have right… but forgetting that it's VB… do you know a way for draw a floor(it's more big than camera)?
when i move forward, the floor will be drawed incorrectly… maybe it's the ConvertPositon3DTo2D() calculations, but i don't know.. what you can advice me?

This question did not belong in the Game Design forum (it's not a game design question). It has been moved to a more appropriate forum.

-- Tom Sloper -- sloperama.com

This topic is closed to new replies.

Advertisement