LoginLogin

Can LFILTER create a Mode7 effect?

Root / Programming Questions / [.]

kitesinpowerlinesCreated:
Can LFILTER horizontal transformation be used to create a mode7 effect? I am trying to display a map on the “floor” and tried to use LFILTER horizontal deformation to get a mode7-like effect, but I can’t seem to transform the layer properly. Has someone already done this? Is there an easier way to achieve this effect? (All mode7 engines I’ve found were for SB3…) I can probably use the Spooky Maze raycast engine to get the effect I want, but I want to see if LFILTER can work first.

LMATRIX array mode allows you to transform an entire layer as if it were a plane in 3D space, so it's what you should actually be using. I don't know how though...

I thought so too but the demo in the sample folder just showed the layer moving around by changing the origin point so I didn’t pursue that route. I’ll revisit LMATRIX and see what I can do. Edit: I found the guide here on SBS for LMATRIX. “matrix#[] is a 4x4 array based on the OpenGL transformation matrix, meaning any arbitrary transformation or projection that can be expressed in OpenGL can be applied.” Doesn’t help me much but it gives me a place to start.

I'll preface this by stating that I don't fully understand how to use LMATRIX, but I do know enough to create a simple Mode7-esc effect using it. First, you need a layer with graphics on it to be transformed. Maybe just use LOADG to quickly fill layer 0 for testing purposes. Then, create an array that'll be used for the LMATRIX transformation. In this case, we'll do
DIM LMATRIX_ARRAY[]=[0,0,0,1,1,0,0,0,0,0,0,0,0,-10,0,0]
Now change LMATRIX_ARRAY[12] and LMATRIX_ARRAY[15] to the X and Y positions, respectively, that you want the viewpoint to be at. X and Y here refers to a point on the 2D graphics layer, not 3D space. LMATRIX_ARRAY[3] and LMATRIX_ARRAY[4] are scale X and scale Y, respectively. LMATRIX_ARRAY[13] is essentially the viewpoint height. Decrease it to raise the viewpoint, or increase it to lower the viewpoint. I find that at a X/Y scale of 1, -10 will have it positioned approximately on the 'ground'. Once you have all this configured to your liking, you can do
LMATRIX <layer id>,LMATRIX_ARRAY
and you should have your simple Mode 7-esc effect. However, critically, I am not aware of a way to rotate the 'camera' using LMATRIX alone, horizontally or vertically. For camera rotation, unless you can figure it out a way to do it via LMATRIX that I couldn't, you're gonna have to get creative and experiment with other ways to rotate the camera (i.e. you can mimic horizontal camera rotation with TROT if you're using text screens for the graphics being transformed by LMATRIX). It is doable. But I think pretty much any method for serviceably accomplishing it during real time gameplay is gonna be a pain in the arse. Unless you have the patience to get that sorted out, or just don't need camera rotation for what you're doing, you may just want to cut your losses and look for other means besides LMATRIX.

Replying to:SBH_plus
I'll preface this by stating that I don't fully understand how to use LMATRIX, but I do know enough to create a simple Mode7-esc effect using it. First, you need a layer with graphics on it to be transformed. Maybe just use LOADG to quickly fill layer 0 for testing purposes. Then, create an array that'll be used for the LMATRIX transformation. In this case, we'll do
DIM LMATRIX_ARRAY[]=[0,0,0,1,1,0,0,0,0,0,0,0,0,-10,0,0]
Now change LMATRIX_ARRAY[12] and LMATRIX_ARRAY[15] to the X and Y positions, respectively, that you want the viewpoint to be at. X and Y here refers to a point on the 2D graphics layer, not 3D space. LMATRIX_ARRAY[3] and LMATRIX_ARRAY[4] are scale X and scale Y, respectively. LMATRIX_ARRAY[13] is essentially the viewpoint height. Decrease it to raise the viewpoint, or increase it to lower the viewpoint. I find that at a X/Y scale of 1, -10 will have it positioned approximately on the 'ground'. Once you have all this configured to your liking, you can do
LMATRIX <layer id>,LMATRIX_ARRAY
and you should have your simple Mode 7-esc effect. However, critically, I am not aware of a way to rotate the 'camera' using LMATRIX alone, horizontally or vertically. For camera rotation, unless you can figure it out a way to do it via LMATRIX that I couldn't, you're gonna have to get creative and experiment with other ways to rotate the camera (i.e. you can mimic horizontal camera rotation with TROT if you're using text screens for the graphics being transformed by LMATRIX). It is doable. But I think pretty much any method for serviceably accomplishing it during real time gameplay is gonna be a pain in the arse. Unless you have the patience to get that sorted out, or just don't need camera rotation for what you're doing, you may just want to cut your losses and look for other means besides LMATRIX.
Thanks, this helps a lot. I checked OpenGL documentation on transformation and it’s pretty much as you said. It also explains how to rotate on x,y, and z axis, but I won’t need to rotate the graphic.