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?

## All 17 Replies

i'm sorry rproffitt, but is there a tutorial for i see more about it?
even trying using keywords, on google, i'm getting trouble to find something about it :(

@c. The words that find so many priors and more are: hidden line algorithm

Given there are many algorithms you need to find one you can use or implement in your code.

In parting, take more care with your tags. The code does not look like it will run in all three languages you tagged with.

rproffitt: the code is Visual Basic 6... so works fine with Visual Studio 6.0
thanks so much for all.. i will try more search

To me Line 42 above seems to answer the question. Wait, is this a setup for another 42 joke?

i'm sorry, but why you said that?

the floor, for exemple is more big than camera... so how can i show the floor using the camera position?
here at least the Z is the same

Why? Remember you wrote this code (hope that you did since I can only grok it so much) and line 42 looks to use IsOnCamera() so that point would be on camera.

https://www.google.com/search?client=opera&q=FillPosition3D+NewPosition3D%2C+Position.X+%2B+Size.Width%2C+Position.Y%2C+Position.Z+%2B+Size.ZDepth seems to show you posting across many forums. Are folk responding out there?

commented: not always... so i'm on next step to learn or understand what i'm doing wrong :( +4

to be honest i'm sorry something... i did that by 1 reason, but not all agree with it :(
i'm trying learning what i can about it, but isn't easy... and i'm not on school\university.... i'm learning these area by me and start(i repeat) start without a big book(hundreds or thousdans pages)... after that i'm more close to understand the book(English... i'm Portuguese.
i'm sorry something but isn't for be rude... sometimes isn't easy

commented: You're doing fine. +15

I want to add a thing here. Very few will write such from scratch. IRL (in real life) I see folk use libraries and toolkits. This way they can focus on their app and avoiding the need to recreate the wheel.

HOWEVER if you were on some platform that is full custom like an Arduino custom built for someone, then you get to craft it from the bottom up.

yes some languages uses DirectX ou even OpenGL(or others)... the C\C++ have Directx, but OpenGL must be added...
DirectX is for Windows, but OpenGL(i think) can be used on any Operation System.
even API functions are for Windows but never Linux...
to be honest i'm using in Math way for learn.... i even, by me, learned how create a compiler.... it's just a translater: convert the new language to C\C++ and then the free C\C++ compiler make the exe.. isn't finished, but it's in good way ;)

I'll be dating myself here but with LEX and YACC you could create a compiler in, well, almost any language you can imagine.
There are tutorials about that older than https://www.tldp.org/HOWTO/text/Lex-YACC-HOWTO

Back in the 80's we had to create such tools from scratch. Today it's rarely done as we have things like lex, yacc, libraries and more.

thank you so much
with sometime i will fix my function..
let me ask you 1 thing: the plane, on world 3D, is drawed using several triangles?

Right-click the drawing view and select Properties. Select the Hide/Show Components tab. Select a component from either the drawing view or the FeatureManager design tree to add it to the list of items to be hidden. Click Apply to see the effect of your selection.When I make a drawing with this assembly, the hidden part shows up which I don't want(Obviously!!!). How do I prevent this part from showing ...

thank you so much, but i was asking if is normal do it for planes(like floor)?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.