title: Stretch 2D plane to 3D cube
body: <p>I'm working on a Java game that has both a 2D game panel and "pseudo"-3D one.</p>
  
  <p>It isn't real 3D as it's merely some 2D planes put in a 3D environment (no custom created models).</p>
  
  <p>I'm using jPCT as render engine and I'm currently looking into getting the walls rendered.</p>
  
  <p>In the 2D view, they look like this:<br>
  <a href="https://i.stack.imgur.com/QYiIL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QYiIL.png" alt="enter image description here"></a></p>
  
  <p>In the 3D view, I'm trying to get them to look like this:<br>
  <a href="https://i.stack.imgur.com/en1UL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/en1UL.png" alt="enter image description here"></a></p>
  
  <p>This works by stacking 10 planes on top of each other and that gives the illusion of a 3D wall.</p>
  
  <p>The code to get this is:</p>
  
  <pre><code>    Object3D obj = new Object3D(20);
  
      for (int y=0; y &lt; 10; y++) {
          float fY = y / -10f;
          obj.addTriangle(new SimpleVector(-1, fY, 1), 0, 0,
                          new SimpleVector(-1, fY, -1), 0, 1,
                          new SimpleVector(1, fY, -1), 1, 1,
                          textureManager.getTextureID(topTexture));
          obj.addTriangle(new SimpleVector(1, fY, -1), 1, 1,
                          new SimpleVector(1, fY, 1), 1, 0,
                          new SimpleVector(-1, fY, 1), 0, 0,
                          textureManager.getTextureID(topTexture));
      }
  </code></pre>
  
  <p>Problem is that when looking straight at it, you get this effect:<br>
  <a href="https://i.stack.imgur.com/s8hyX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s8hyX.png" alt="http://i.stack.imgur.com/s8hyX.png"></a></p>
  
  <p>This could be reduced by increasing the amount of planes and putting them closer together, but I'm looking for a more efficient way of getting the same effect.</p>
  
  <p>I was thinking of rendering a cube with the 2D image as top texture and using the last line of pixels as textures for the sides, e.g. extract a 40x1 image at (0,0) and (0,39) from the base image and stretch these across the sides of the cubes (the original images are 40x40).</p>
  
  <p>This won't work perfectly though because the visible part of these images are smaller than 40x40 (e.g. the top and bottom 40x9 pixels are transparent for a horizontal wall), so I should do some edge-detection and start cutting there.</p>
  
  <p>Any better suggestions to try to do same?</p>