Infinite Plane OpenB3DMax
👉 BlitzCoder will be building a new platform and other plans to preserve and continue the Blitz legacy.
To be able to achieve this goal, we need your support by becoming a Patreon Paid Member 👈
Tweet blitzmax code-archives effects openb3d
Infinite Plane for OpenB3DMax.
Known Issues:
- texture applied to plane is also moving when applied to other entities
- inverted texture
Author: SLotman, RonTek
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
"Exception Access Violation"
Any idea why I would get that? It doesn't happen if I remove the updateplane() function so it's something to do with it.
Didn't expect to figure that one out:
texture = LoadTexture("../media/test.png")
I changed to:
texture = LoadTexture("./media/test.png")
Removed one dot before the directory name. :P
I don't know why it double posted but it'd be nice if I could delete the extra posts...
Welcome to the forums PlastikCogLiquid
Nice you figured that one out and don't worry about the double post and yes will eventually consider adding a delete posts.
I finally added this to Blitzmax Openb3d. It has sub-divisions up to 64 and uses ClearSurface instead of FreeEntity. It scales depending on camera range far which means you can increase sub-division detail if you want.
Blitz3d planes are a bit odd, they're not meshes and when you look at them in wireframe they don't have normal perspective. They also have their v coord the wrong way round.
Thanks Ron for the original code by Slotman.
They also have their v coord the wrong way round.
Yes, that is normal because of the coordinate system and texture coordinate, B3D is DX (Left hand) like what I have mentioned and suggested here..
Hi Ron,
OK, I thought I had done this in the wrapper at least for XYZ coords but I never took into account left-handed texture UV coords.
A quick look at this guide https://filemodo.net/en/opengl-vs-directx-coordinates/ tells me that the UV coordinates in DirectX are thought to be the same in OpenGL.
But the big difference in 2D space is that DirectX stores video memory starting from the top-left but OpenGL starts from the bottom-left, this is the same with window origin or textures.
So this should be the only issue affecting UV coordinates. In that the V coord needs to be flipped, where V represents Y in 2D space.
So this should be the only issue affecting UV coordinates. In that the V coord needs to be flipped, where V represents Y in 2D space.
Yes, that's basically it in regards to uv coordinates as you may have first noticed.
OK, I'm a bit confused, can you give an example of something in Bmx Openb3d you found that wasn't left-handed?
Also, don't you think it strange that plane textures in Blitz3d are inverted by default, I guess I'll need to do the same in Bmx anyway though.
As it said on stackoverflow, the best thing is to have a const that lets you switch between left or right-handed coordinates.
Thanks.
OK, I'm a bit confused, can you give an example of something in Bmx Openb3d you found that wasn't left-handed?
I opened a few issues re: matching blitz3d coord system..
https://sourceforge.net/p/minib3d/discussion/1263110/thread/b15a669c94/
https://sourceforge.net/p/minib3d/discussion/1263110/thread/9d10261e85/
it's really a must have for devs transitioning from b3d to openb3d so there should be minimal effort.
If you'd also notice, most multi-renderer engines like Irrlicht, Orgre, Torque3d have this, but the def. coordinate system depends per engine (usually DX left).
Torque is left handed since it started with DX and then added OGL later on.
Reply To Topic (minimum 10 characters)
Please log in to reply