• Dear Cerberus X User!

    As we prepare to transition the forum ownership from Mike to Phil (TripleHead GmbH), we need your explicit consent to transfer your user data in accordance with our amended Terms and Rules in order to be compliant with data protection laws.

    Important: If you accept the amended Terms and Rules, you agree to the transfer of your user data to the future forum owner!

    Please read the new Terms and Rules below, check the box to agree, and click "Accept" to continue enjoying your Cerberus X Forum experience. The deadline for consent is April 5, 2024.

    Do not accept the amended Terms and Rules if you do not wish your personal data to be transferred to the future forum owner!

    Accepting ensures:

    - Continued access to your account with a short break for the actual transfer.

    - Retention of your data under the same terms.

    Without consent:

    - You don't have further access to your forum user account.

    - Your account and personal data will be deleted after April 5, 2024.

    - Public posts remain, but usernames indicating real identity will be anonymized. If you disagree with a fictitious name you have the option to contact us so we can find a name that is acceptable to you.

    We hope to keep you in our community and see you on the forum soon!

    All the best

    Your Cerberus X Team

Inifinite Planes for MiniB3D

SLotman

Active member
3rd Party Module Dev
Tutorial Author
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 ^_^


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:
Back
Top Bottom