Infinite Plane MiniB3D

Tweet blitzmax code-archives effects
(Posted 8 months ago) RonTek

Infinite Planes demo on MiniB3D. This replicates Blitz3D CreatePlane() feature which creates an infinite plane.

Author: SLotman


Import sidesign.miniB3D

Global tex:TTexture
Global camera:TCamera
Global plane:TPlane
Global t:TTimer

Graphics3D 800,600,32,2

AmbientLight 128,128,128

camera = CreateCamera()
CameraRange camera, 1,5000
MoveEntity camera, 0,1,0

plane = TPlane.CreatePlane()

plane.SetTexture tex

While Not KeyHit(KEY_ESCAPE)



    text 10,10, "Arrows: move - A/D: strafe - ESC Exit"


    If KeyDown(KEY_A) Then MoveEntity camera, -0.05,0,0
    If KeyDown(KEY_D) Then MoveEntity camera, 0.05,0,0
    If KeyDown(KEY_UP) Then MoveEntity camera, 0,0,0.05
    If KeyDown(KEY_DOWN) Then MoveEntity camera,0,0,-0.05
    If KeyDown(KEY_RIGHT) Then TurnEntity camera, 0,-1,0
    If KeyDown(KEY_LEFT) Then TurnEntity camera, 0,1,0


Type TPlane
    Global planeList:TList=CreateList()

    Field mesh:TMesh
    Field surf:TSurface
    Field range:Float
    Field texture:TTexture

    Method New()
    End Method

    Method Delete()
    End Method

    Method CopyEntity:TPlane(parent_ent:TEntity=Null)
    End Method

    Method FreeEntity() 
        surf = Null
        mesh = Null
        ListRemove planeList, Self
    End Method

    Method SetTexture(tex:TTexture)
        texture = tex
        If (mesh) Then EntityTexture mesh, texture
    End Method

    Function UpdatePlanes(cam:TCamera)
        Local r# = cam.range_far - cam.range_near

        For Local p:TPlane = EachIn planeList

        If Abs(p.range-r)>0.0001 Or p.mesh=Null Then
            ' changed camera range, rebuild mesh?
            p.range = r
            If (p.mesh) Then p.mesh.FreeEntity()

            p.mesh = CreateMesh()
   = CreateSurface(p.mesh)

            AddVertex, -p.range, 0,  p.range, -p.range,  p.range
            AddVertex, +p.range, 0,  p.range,  p.range,  p.range
            AddVertex, +p.range, 0, -p.range,  p.range, -p.range
            AddVertex, -p.range, 0, -p.range, -p.range, -p.range

            AddTriangle, 0, 1, 2
            AddTriangle, 0, 2, 3
            VertexNormal, 0, 0, 1, 0
            VertexNormal, 1, 0, 1, 0
            VertexNormal, 2, 0, 1, 0
            VertexNormal, 3, 0, 1, 0

            EntityTexture p.mesh, p.texture
        End If

        Local x# = EntityX(cam,True)
        Local z# = EntityZ(cam,True)
        PositionTexture p.texture, -x,-z

        ' re-position plane, on camera x/z position
        PositionEntity p.mesh, x, 0, z
    End Function

    Function CreatePlane:TPlane()
    Local p:TPlane = New TPlane


        ListAddLast planeList, p

        Return p

    End Function

End Type

' Create Texture For ground
Function MakeTexture()

    SetColor 255,255,255
    DrawRect 0,0,16,16
    SetColor 255,0,0
    DrawRect 0,0,8,8
    DrawRect 8,8,8,8
    SetColor 255,255,255


End Function
(Posted 8 months ago) hardcoal commented:

Thanks man ill copy it to blitz max

(Posted 8 months ago) RonTek commented:

Sure thing. Are you still trying out OpenB3DMax? first try porting it I get a blank screen..

(Posted 8 months ago) markcwm commented:

Openb3dmax already has a CreatePlane function, this one is better though as my version is a static plane so eventually you'd reach the edge.

(Posted 8 months ago) RonTek commented:

Agreed Mark, though there is stil a problem with it when you reuse the texture that was used and the solution by SLotman was to store the UV before rendering and then restore it afterwards.

Texture is also inverted, I tried ScaleTexture with -1,1 but the movement is also affected.

btw, just posted the OpenB3DMax version. It's simplified as to not sure why the full code port is not working out of the box.

Also, perhaps suggest to Angelo in integrating or updating with this instead so the feature set will be more in line with Blitz3D?


Reply To Topic (minimum 10 characters)

Please log in to reply