3

I'm working on a Java game that has both a 2D game panel and "pseudo"-3D one.

It isn't real 3D as it's merely some 2D planes put in a 3D environment (no custom created models).

I'm using jPCT as render engine and I'm currently looking into getting the walls rendered.

In the 2D view, they look like this:
enter image description here

In the 3D view, I'm trying to get them to look like this:
enter image description here

This works by stacking 10 planes on top of each other and that gives the illusion of a 3D wall.

The code to get this is:

    Object3D obj = new Object3D(20);

    for (int y=0; y < 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));
    }

Problem is that when looking straight at it, you get this effect:
https://i.stack.imgur.com/s8hyX.png

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.

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).

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.

Any better suggestions to try to do same?

Vitim.us
  • 20,746
  • 15
  • 92
  • 109
srdoso
  • 31
  • 2
  • What exactly are you asking? It's fairly clear that drawing cubes is the sensible thing to do here. If the question is just about how to texture the cubes then can you try and clarify what the problem is with the textures you are using? – YXD May 14 '11 at 18:34
  • 1
    I know how to texture a cube, the problem is that the original 2D wall images aren't fully covered with pixels (see http://i.imgur.com/46Gwz.png , about 9 pixels left and right are transparent). So I can't just create a cube and texture it. I'd need to determine the edges of the image and create a polygon based on that . Then I'd need to cut off small slices of the edges and use those as textures for the sides of the cube. – srdoso May 14 '11 at 18:42
  • Yes what you just described can be done. Look for raster-to-vector or raster-vectorization algorithms. – karmakaze May 15 '11 at 21:58

1 Answers1

0

The simplest but likely least performant solution is for any pixel in your image that is next to both a transparent pixel and a non transparent pixel, render a tall rectangular cube for just that pixel.

Phil Martin
  • 466
  • 4
  • 4