Now ythat you mention it, I have tried doing what I know I've done before, and what Gfk suggested, and it doesn't seem to work now :S - strange. Unless Gfk (or someone else maybe) has a different method?
Anyway, how's trhis for memory? As I thought back to when I wanted something similar, there was anotgher topic around at the time.
Skidracer posted this which I hope is helpful:
; wired2.bb
; 3d wire frame system
; wires are lines in 3D space with start and end widths
; CreateWireMesh creates single surface mesh with quad per wire type
; UpdateWireMesh positions wire quad so as to face the camera
Type wire
Field x0#,y0#,z0#,w0#
Field x1#,y1#,z1#,w1#
End Type
Function CreateWire.wire(x0#,y0#,z0#,w0#,x1#,y1#,z1#,w1#)
w.wire=New wire
w\x0=x0
w\y0=y0
w\z0=z0
w\w0=w0
w\x1=x1
w\y1=y1
w\z1=z1
w\w1=w1
End Function
Function CreateWireMesh()
m=CreateMesh()
EntityFX m,16 ;double sided flag so no tricky flip testing required
s=CreateSurface(m,b)
For w.wire=Each wire
AddVertex s,0,0,0,0,0
AddVertex s,0,0,0,1,0
AddVertex s,0,0,0,1,1
AddVertex s,0,0,0,0,1
AddTriangle s,v+0,v+1,v+2
AddTriangle s,v+0,v+2,v+3
v=v+4
Next
Return m
End Function
Function UpdateWireMesh(cam,mesh)
s=GetSurface(mesh,1)
camx#=EntityX(cam)
camy#=EntityY(cam)
camz#=EntityZ(cam)
For w.wire=Each wire
px#=w\x1-w\x0
py#=w\y1-w\y0
pz#=w\z1-w\z0
l#=1.0/Sqr(px*px+py*py+pz*pz)
px=px*l
py=py*l
pz=pz*l
cx#=w\x0-camx
cy#=w\y0-camy
cz#=w\z0-camz
l#=1.0/Sqr(cx*cx+cy*cy+cz*cz)
cx=cx*l
cy=cy*l
cz=cz*l
l=w\w0
ex#=l*(-py*cz+pz*cy)
ey#=l*(+px*cz-pz*cx)
ez#=l*(py*cx+px*cy)
VertexCoords s,v+0,w\x0+ex,w\y0+ey,w\z0+ez
VertexCoords s,v+3,w\x0-ex,w\y0-ey,w\z0-ez
cx#=w\x1-camx
cy#=w\y1-camy
cz#=w\z1-camz
l#=1.0/Sqr(cx*cx+cy*cy+cz*cz)
cx=cx*l
cy=cy*l
cz=cz*l
l=w\w1
ex=l*(-py*cz+pz*cy)
ey=l*(+px*cz-pz*cx)
ez=l*(py*cx+px*cy)
VertexCoords s,v+1,w\x1+ex,w\y1+ey,w\z1+ez
VertexCoords s,v+2,w\x1-ex,w\y1-ey,w\z1-ez
v=v+4
Next
End Function
Graphics3D 1024,768
Function CreateBox(x#,y#,z#,w#,h#,d#)
; front square
CreateWire(x-w,y+h,z+d,2, x+w,y+h,z+d,2)
CreateWire(x-w,y-h,z+d,2, x+w,y-h,z+d,2)
CreateWire(x-w,y-h,z+d,2, x-w,y+h,z+d,2)
CreateWire(x+w,y+h,z+d,2, x+w,y-h,z+d,2)
; side lines
CreateWire(x-w,y-h,z+d,2, x-w,y-h,z-d,2)
CreateWire(x+w,y-h,z+d,2, x+w,y-h,z-d,2)
CreateWire(x+w,y+h,z+d,2, x+w,y+h,z-d,2)
CreateWire(x-w,y+h,z+d,2, x-w,y+h,z-d,2)
; back square
CreateWire(x-w,y+h,z-d,2, x+w,y+h,z-d,2)
CreateWire(x-w,y-h,z-d,2, x+w,y-h,z-d,2)
CreateWire(x-w,y-h,z-d,2, x-w,y+h,z-d,2)
CreateWire(x+w,y+h,z-d,2, x+w,y-h,z-d,2)
End Function
For i=1 To 1000
CreateBox(Rnd(-1000,1000),Rnd(-1000,1000),Rnd(-1000,1000),Rnd(100),Rnd(100),Rnd(100))
Next
mesh=CreateWireMesh()
cam=CreateCamera()
;CameraClsColor cam,20,60,80
CameraRange cam,1,10000
tube=CreateTexture(1,4,4)
brush=CreateBrush()
BrushTexture brush,tube
t=TextureBuffer(tube)
WritePixel 0,0,0,t
WritePixel 0,1,-1,t
WritePixel 0,2,-1,t
WritePixel 0,3,0,t
PaintMesh mesh,brush
While Not KeyHit(1)
RotateEntity cam,0,MouseX(),.3
PositionEntity cam,0,0,0
MoveEntity cam,0,0,-MouseY()*10.0
UpdateWireMesh(cam,mesh)
UpdateWorld
RenderWorld
Flip
Wend
End
|