PS. You know that this is the PlayBasic user forum, and not the talk to kevin forum right ?
LOL. Yes I was merely refering to author of the program I was modiyfing
So to clip on the near plane, what you do is check if any vertex of the polygon your drawing has a Z lower than 1 (after transformation). (you can't project a vert with transformed z of 0 or lower)
Yes, I discovered that when I did the math for a program just like this. a copy of the same dots were on the screen but they were moving in reverse.
We'll I re-modified the program again but instead of trying to use 1 object with 20wx20hx20d vertex's I created 20wx20hx20d objects with 8 vertex's to make each object a cube just to make it easier to acess each cube but as soon as do more than 5wx20hx20d it crashes. On another computer I get a limited number of objects.
; PROJECT : 3dDepths2
; AUTHOR : Kevin Picone
; CREATED : 17/01/2006
; EDITED : 1/27/2009
; ---------------------------------------------------------------------
#Include "VertexObjects"
MakeBitmapFont 1,$ffffff
sw=GetScreenWidth()
sh=GetScreenHeight()
ProjectionX#=400
ProjectionY#=400
; Init the Size of the Source and rotated Vertexs
Constant SrcVertSize =12
Constant DestVertSize =20
Global Xpos#
Global Ypos#
Global Zpos#
Global Map_X
Global Map_Y
Global Map_Z
Type tObject
status
; Object Bank
ObjectBank
; Vertex Bank
VertexBank
; Rotation Speeds for this object
RotSpeedX#
RotSpeedY#
RotSpeedZ#
NumberOFVerts
EndType
Dim Object(8000) As tObject
NumberOfVertex=8
Obj=1
; ==================================
; make the corner pillars
; ==================================
;x=-9
;z=-9
;y=0
sizex=50
Sizey=50
sizez=50
For z=-9 To 9
For y=-5 To 5
For x=-9 To 9
NewObject(obj,x*100,y*100,z*100,SizeX,SizeY,SizeZ,8)
Inc obj
Next x
Next y
Next z
; Create Camera Object
; =====================================
CameraObject=CreateVertexObject(0,0,0)
VertexObjectProjectionMode(CameraObject,1,ProjectionX#,ProjectionY#)
; =====================================
; Create Desitnation Vertex Buffer
; =====================================
DestVertexBank=NewBank(8000*DestVertSize)
; =======================================================
; Pre-calc the shading
; =======================================================
Dim ShadeBufferBuffer(20000)
NumberOfVertexdepth#=1000
scaler#=100/NumberOfVertexdepth#
col=RGB(255,255,255)
For lp=0 To NumberOfVertexdepth#
ShadeBufferBuffer(lp)=RGBFade(col,(NumberOfVertexdepth#-lp)*scaler#)
Next
CreateCamera 1
StartTime=Timer()+5000
Do
CaptureToScene
ClsScene
; Rotate vertex list (with XYZ rotation order)
CameraAddress=GetBankPtr(CameraObject)
DestVertexbufferAddress =GetBankPtr(DestVertexBank)
TotalNumberOFVertexs=0
For Obj=0 To GetArrayElements(Object().tObject,1)
If Object(obj).status=True
ThisObject=Object(obj).ObjectBank
ax#,ay#,az#=GetVertexObjectRotation(ThisObject)
ax#=WrapAngle(ax#,object(obj).rotspeedx)
ay#=WrapAngle(ay#,object(obj).rotspeedy)
az#=WrapAngle(az#,object(obj).rotspeedz)
RotateVertexObject ThisObject,ax#,ay#,az#
ObjectAddress=GetBankPtr(ThisObject)
SrcVertexBufferAddress=GetBankPtr(Object(obj).vertexbank)
NumberOfVertex=object(obj).NumberOFVerts
TotalNumberOFVertexs=TotalNumberOFVertexs+NumberOFVertex
RotateVertexListToCamera CameraAddress,ObjectAddress,SrcVertexBufferAddress,SrcVertSize,DestVertexbufferAddress,DestVertSize,NumberOfVertex
Address=DestVertexbufferAddress+8
Do
z#=PeekFloat(Address)
ScrnX=400+PeekFloat(Address+4)
ScrnY=300+PeekFloat(Address+8)
If z#>10
CaptureDepth z#
DotC ScrnX,ScrnY,$ffffff;,ShadeBufferBuffer(z#)
EndIf
address=address+destVertSize
DecLoop NumberOfVertex
EndIf
Next
DrawCamera 1
speed#=10
Control_Camera(CameraObject,20)
If KeyPressed=False
If ScanCode()<>0 Then KeyPressed=True
If SpaceKey()
DemoMOde=1-demoMOde
EndIf
Else
If ScanCode()=0 Then KeyPressed=False
EndIf
SetCursor 0,0
Print "Rotating Vertex Lists To Viewer/Camera"
Print Str$(TotalNumberOFVertexs)+" Shaded Z buffered Vertex"
Print "Fps:"+Str$(FPS())
Print "Map X Pos:"+Str$(Map_X)
Print "Map Y Pos:"+Str$(Map_Y)
Print "Map Z Pos:"+Str$(Map_Z)
If Timer()<StartTime
CenterText sw/2,sh/2,"Use Arrow Keys + Mouse"
EndIf
Sync
Loop
Function NewObject(obj,x,y,z,SizeX,SizeY,SizeZ,Verts)
Object(obj).status=True
VertexObject=CreateVertexObject(x,y,z)
Object(obj).ObjectBank=VertexObject
; create Vertex Obejct Structure
VertexObjectRotationMode(VertexObject,Rnd(1)) ; ZYX
Object(obj).VertexBank=Make_Random_Vertex_region(sizex,sizey,sizez,Verts)
object(obj).NumberOFVerts=Verts
EndFunction
Function Make_Random_Vertex_region(sizex,sizey,sizez,NumberOfVertex)
; Create Vertex Buffers
VertexBank=NewBank((NumberOfVertex+1)*SrcVertSize)
Address=GetBankPtr(VertexBank)
For z=-SizeZ To SizeZ Step 100
For y=-SizeY To SizeY Step 100
For x=-SizeX To SizeX Step 100
PokeFloat Address,Float(x)
PokeFloat Address+4,Float(y)
PokeFloat Address+8,Float(z)
Address=Address+SrcVertSize
Next X
Next Y
Next z
EndFunction VertexBank
Psub Control_Camera(CameraObject,camspeed#)
W=GetScreenWidth()
H=GetScreenHeight()
x1=GetScreenXpos()
Y1=GetScreenYpos()
x2=x1+w
y2=y1+h
MMX#=MouseMoveX()
MMY#=MouseMoveY()
x#=x1+MouseX()
y#=y1+MouseY()
flag=0
If x#=<(x1+75) Then x#=x1+(w/2): flag=1
If x#=>(x2-75) And flag=0 Then x#=x1+(w/2): flag=1
If y#=<(y1+75) Then y#=y1+(h/2): flag=1
If y#=>(y2-75) Then y#=y1+(h/2): flag=1
If flag=1
SetMouse x#,y#
MMX2#=MouseMoveX()
MMY2#=MouseMoveY()
SetMouse x#,y#
EndIf
camf#=0
camx#=WrapAngle(camx#,Mmy#*0.7)
camy#=WrapAngle(camy#,mmx#*0.7)
acamx#=CurveAngle(camx#,acamx#,6.2)
acamy#=CurveAngle(camy#,acamy#,6.2)
RotateVertexObject(CameraObject,acamx#,acamy#,0)
If UpKey()=1 Then camf#=camf#+camspeed#
If DownKey()=1 Then camf#=camf#-camspeed#
If camf#<>0
movementx#,movementy#,movementz#=CalcMovement(acamx#,acamy#,0.0,Camf#)
X#,Y#,Z#=GetVertexObjectPosition(CameraObject)
x#=x#+movementx#
;If x#<2000 Then x#=x#+100:Dec Map_X
;If x#>2100 Then x#=x#-100:Inc Map_X
y#=y#+movementy#
;If y#<2000 Then y#=y#+100:Dec Map_Y
;If y#>2100 Then y#=y#-100:Inc Map_Y
z#=z#+movementz#
;If z#<2000 Then z#=z#+100:Dec Map_Z
; If z#>2100 Then z#=z#-100:Inc Map_Z
; clip the camera to 20 on y axis
;If y#<20 Then y#=20
PositionVertexObject(CameraObject,x#,y#,z#)
xpos#=x#
ypos#=y#
ZPos#=z#
;camAZ#
EndIf
EndPsub
Function CalcMovement(Anglex#,angley#,anglez#,Speed#)
` invert angles
anglex#=360-anglex#
angley#=WrapAngle(90,-angley#)
anglez#=360-anglez#
` precalc cos+sin for rotation
cx#=Cos(anglex#)
sx#=Sin(anglex#)
cy#=Cos(angley#)
sy#=Sin(angley#)
Zpos#=Speed#
z#=(cx#*Zpos#)
y#=(sx#*zpos#)
` Around Y axis
x2#=(cY#*Z#)-(sy#*X#)
z#=((cy#*X#)+(sy#*Z#))
EndFunction x2#,y#,z#
I'm guessing it's a memory issue or some sort of limitation. I can't see any other problem with the code.