Infinite Plane OpenB3DMax


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

Infinite Plane for OpenB3DMax.

Known Issues:

  • texture applied to plane is also moving when applied to other entities
  • inverted texture

Author: SLotman, RonTek

Image


Strict

Framework Openb3dmax.B3dglgraphics

Local width%=DesktopWidth(),height%=DesktopHeight(),depth%=0,Mode%=2

Graphics3D width,height,depth,Mode

Global cam_near# = 0.1, cam_far# = 5000
Global range#
Global mesh:TMesh
Global surf:TSurface
Global texture:TTexture

Local light:TLight=CreateLight(1)
RotateEntity light,90,0,0

Global camera:TCamera=CreateCamera()
CameraRange camera,cam_near,cam_far
MoveEntity camera,0,1,0

texture = LoadTexture("../media/test.png")

While Not KeyHit(KEY_ESCAPE)

    Cls
    UpdateWorld
    UpdatePlane()
    RenderWorld

    Flip

    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

Wend
End

ClearWorld
EndGraphics
End

Function UpdatePlane()

    Local r# = cam_far - cam_near 

    If Abs(range - r) > 0.0001 Or mesh = Null Then

        range = r
        If mesh Then FreeEntity(mesh)

        mesh = CreateMesh()

        surf = CreateSurface(mesh)

        AddVertex surf,-range,0,range,-range,range,0
        AddVertex surf,+range,0,range,range,range,0
        AddVertex surf,+range,0,-range,range,-range,0
        AddVertex surf,-range,0,-range,-range,-range,0

        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

        EntityTexture mesh,texture

    End If

    Local x#,z#

    x = EntityX(camera,True)
    z = EntityZ(camera,True)

    PositionTexture texture,-x,-z
    PositionEntity mesh,x,0,z

End Function

Reply To Topic (minimum 10 characters)

Please log in to reply