- Joined
- Jul 3, 2017
- Messages
- 261
So, I had this working for MiniB3d / BlitzMax - and now I kind of ported it to MiniB3d / Monkey-X / Cerberus-X.
Why "kind of", you ask? Because I had this integrated into myown version of miniB3D. This code, you'll have to import "TPlane" yourself, and also call TPlane.UpdatePlanes(camera) before RenderWorld.
I'm not entirely sure this is 100% correct either, but from my initial tests, it is. I didn't try "CopyEntity" to see if it's working well enough, or not.
This should behave more or less like CreatePlane from Blitz3D, you just call TPlane.CreatePlane()
Worst case scenario, this can be used for a proper implementation ^_^
Why "kind of", you ask? Because I had this integrated into myown version of miniB3D. This code, you'll have to import "TPlane" yourself, and also call TPlane.UpdatePlanes(camera) before RenderWorld.
I'm not entirely sure this is 100% correct either, but from my initial tests, it is. I didn't try "CopyEntity" to see if it's working well enough, or not.
This should behave more or less like CreatePlane from Blitz3D, you just call TPlane.CreatePlane()
Worst case scenario, this can be used for a proper implementation ^_^
Cerberus:
Import minib3d.minib3d
Class TPlane Extends TMesh
Global plane_list:List<TPlane>=New List<TPlane>
Field range:Float
Field mesh:TMesh
Field sub_divs:Int
Field origU:Float[8], origV:Float[8]
Field CamX:Float, CamZ:Float
Method FreeEntity()
plane_list.RemoveFirst(Self)
Super.FreeEntity()
End Method
Method CopyEntity:TEntity(parent_ent:TEntity=Null)
Local p:TPlane = New TPlane
p.mesh = TMesh(mesh.CopyEntity(parent_ent))
p.range = range
p.sub_divs = sub_divs
plane_list.AddLast(p)
Return TEntity(p.mesh)
End Method
Method Update()
If (mesh) Then
For Local surf:TSurface = Eachin mesh.surf_list
If (surf) Then
' change texture coordinates
surf.VertexTexCoords(0,-range+CamX, range+CamZ)
surf.VertexTexCoords(1, range+CamX, range+CamZ)
surf.VertexTexCoords(2, range+CamX, -range+CamZ)
surf.VertexTexCoords(3,-range+CamX, -range+CamZ)
End If
Next
' re-position plane, on camera x/z position
mesh.PositionEntity CamX, mesh.py, CamZ, True
End If
End Method
Function UpdatePlanes(cam:TCamera)
If cam = Null Then Return
Local r:Float = cam.range_far - cam.range_near
Local x:Float = cam.EntityX(True)
Local z:Float = cam.EntityZ(True)
For Local p:TPlane = Eachin plane_list
p.CamX = x
p.CamZ = z
If Abs(p.range-r)>0.0001 Then
' changed range, re-scale mesh
For Local surf:TSurface = Eachin p.mesh.surf_list
If (surf) Then
r*=2
' change vertex positions
surf.VertexCoords(0, -r, 0, r)
surf.VertexCoords(1, r, 0, r)
surf.VertexCoords(2, r, 0, -r)
surf.VertexCoords(3, -r, 0, -r)
' change texture coordinates
surf.VertexTexCoords(0,-r, r)
surf.VertexTexCoords(1, r, r)
surf.VertexTexCoords(2, r, -r)
surf.VertexTexCoords(3,-r, -r)
p.range = r
End If
Next
End If
Next
End Function
Function CreatePlane:TMesh(sub_divs:Int=1, parent_ent:TEntity=Null)
Local p:TPlane = New TPlane()
p.range=0.001
p.mesh = TPlane.CreateMesh(parent_ent)
p.classname="Plane"
p.sub_divs = sub_divs
Local surf:TSurface=p.mesh.CreateSurface()
AddVertex surf, -p.range, 0, p.range, -p.range, p.range
AddVertex surf, +p.range, 0, p.range, p.range, p.range
AddVertex surf, +p.range, 0, -p.range, p.range, -p.range
AddVertex surf, -p.range, 0, -p.range, -p.range, -p.range
AddTriangle surf, 0, 1, 2
AddTriangle surf, 0, 2, 3
VertexNormal surf, 0, 0, 1, 0
VertexNormal surf, 1, 0, 1, 0
VertexNormal surf, 2, 0, 1, 0
VertexNormal surf, 3, 0, 1, 0
p.px = 0
p.py = 0
p.pz = 0
plane_list.AddLast(p)
entity_list.AddLast(p)
p.mesh.EntityFX(16)
Return p.mesh
End Function
End Class
Last edited: