
3d hidden surfaces, Z buffer ? good 3d implementation must see this code.
hi,
i am working in 3d coord. system.
I built my plane type elements and formed a box with that 4 planes. But as i
rotate the system, some overlappings occur. The planes that should be behind
the front ones are not. and vice versa.. I need a hiding algorithm.(i heard
z buffering).PLS ASSIST...
i need a code that hides the planes that are behind others or lines....!!!
there is a formula but dont know if it is ok or not :
(z=(x1-x0)*(y2-y0)-(y1-yo)*(x2-xo) if z<0 then not visible)
i think this formula is for triangular shapes what should be the one for
planes (4 sides)???
thanks
Devrim Pakkan
www.alargesoft.com
MY METHOD OF DRAWING AND STORING 3D POINTS...
'***********************************
Public Type plane
x(1 To 4) As Double
y(1 To 4) As Double
z(1 To 4) As Double
sx(1 To 4) As Long ' for 2d projection
sy(1 To 4) As Long
End Type
Public Type building3d
key As Integer
walls(1 To 4) As plane
name As String
color As ColorConstants
width As Double
height As Double
length As Double
End Type
'drawing algorithm....
For kk = 1 To 4
For k = 1 To 4
x(k) = bul3d(i).duvar(kk).x(k)
y(k) = bul3d(i).duvar(kk).y(k)
z(k) = bul3d(i).duvar(kk).z(k)
Call Rotate3D(x(k), y(k), z(k), yaw, pit, rol)
'perspective
x(k) = (((canvas.ScaleWidth / 1) * x(k)) / ((canvas.ScaleWidth / 1)
+ z(k))) + 0
y(k) = (((canvas.ScaleHeight / 1) * y(k)) / ((canvas.ScaleHeight /
1) + z(k))) + 0
'origin adjustment and zoom
bul3d(i).duvar(kk).sx(k) = (x(k) * zoomfac + coord.x)
bul3d(i).duvar(kk).sy(k) = (y(k) * zoomfac + coord.y)
Points(k).x = bul3d(i).duvar(kk).sx(k)
Points(k).y = bul3d(i).duvar(kk).sy(k)
Next k
Call Polygon(canvas.hdc, Points(1), NumPoints) ' API CALLS
Next kk
'********************************************
thanks
Atakan Devrim Pakkan