# 3d wall not rendering correctly

• 05-13-2014, 04:37 AM
Andrew_3ds
3d wall not rendering correctly
I am making a game based off of a tutorial on YouTube, and I watched the video a few times and my code looks the same to me. The "wall" is always facing the camera as if it were a sprite, although it shouldn't. It should be facing the way it always is. Can someone check my code to see if anything is wrong with it?

Here are the variables defined before the method(I didn't want to show the whole class; it's long and I don't want you to read unnecessary code.);

Code:

```public double[] zBuffer;         public double renderDistance = 6250;         private double forward, right, up, cosine, sine;         public Render3D(int width, int height) {                 super(width, height);                 zBuffer = new double[width * height];         }                 forward = game.controls.z;                 right = game.controls.x;                 up = game.controls.y;                 double floorPosition = 8;                 double ceilingPosition = 8;                 double walking = Math.sin(game.time / 8.0) * 0.8;                 double rotation = //Math.sin(game.time / 40.0) * 0.5;                 game.controls.rotation;                 cosine = Math.cos(rotation);                 sine = Math.sin(rotation);                 if (Controller.crouchWalk) {                         walking = Math.sin(game.time / 6.0) * 0.25;                 }                 if (Controller.runWalk) {                         walking = Math.sin(game.time / 4.5) * 1;                 }```
Here is where the actual wall rendering happens.
Code:

```public void renderWall(double xLeft, double xRight, double zDistance, double yHeight) {                 double xcLeft = ((xLeft) - right) * 2;                 double zcLeft = ((zDistance) - forward) * 2;                 double rotLeftSideX = xcLeft * cosine - zcLeft * sine;                 double yCornerTL = ((-yHeight) - up) * 2;                 double yCornerBL = ((+0.5 - yHeight) - up) * 2;                 double rotLeftSideZ = zcLeft * cosine + xcLeft * sine;                 double xcRight = ((xRight) - right) * 2;                 double zcRight = ((zDistance) - forward) * 2;                 double rotRightSideX = xcRight * cosine - zcRight * sine;                 double yCornerTR = ((-yHeight) - up) * 2;                 double yCornerBR = ((+0.5 - yHeight) - up) * 2;                 double rotRightSideZ = zcRight * cosine + xcRight * sine;                 double xPixelLeft = (rotLeftSideX / rotLeftSideZ * height + width / 2);                 double xPixelRight = (rotRightSideX / rotRightSideZ * height + width / 2);                 if (xPixelLeft >= xPixelRight) {                         System.out.println("ERROR: xPixelLeft >= xpixelRight");                         return;                 }                 int xPixelLeftInt = (int) (xPixelLeft);                 int xPixelRightInt = (int) (xPixelRight);                 if (xPixelLeftInt < 0) {                         xPixelLeftInt = 0;                 }                 if (xPixelRightInt > width) {                         xPixelRightInt = width;                 }                 double yPixelLeftTop = (yCornerTL / rotLeftSideZ * height + height / 2);                 double yPixelLeftBottom = (yCornerBL / rotLeftSideZ * height + height / 2);                 double yPixelRightTop = (yCornerTR / rotLeftSideZ * height + height / 2);                 double yPixelRightBottom = (yCornerBR / rotLeftSideZ * height + height / 2);                 double tex1 = 1 / rotLeftSideZ;                 double tex2 = 1 / rotRightSideZ;                 double tex3 = 0 / rotLeftSideZ;                 double tex4 = 8 / rotRightSideZ - tex3;                 for (int x = xPixelLeftInt; x < xPixelRightInt; x++) {                         double pixelRotation = (x - xPixelLeft) / (xPixelRight - xPixelLeft);                         int xTexture = (int) ((tex3 + tex4 * pixelRotation) / tex1 + (tex2 - tex1) * pixelRotation);                         double yPixelTop = yPixelLeftTop + (yPixelRightTop - yPixelLeftTop) * pixelRotation;                         double yPixelBottom = yPixelLeftBottom + (yPixelRightBottom - yPixelLeftBottom) * pixelRotation;                         int yPixelTopInt = (int) (yPixelTop);                         int yPixelBottomInt = (int) (yPixelBottom);                         if (yPixelTopInt < 0) {                                 System.out.println("ERROR: yPixelTopInt < 0");                                 yPixelTopInt = 0;                         }                         if (yPixelBottomInt > height) {                                 System.out.println("ERROR: yPixelTopInt > height");                                 yPixelBottomInt = height;                         }                         for (int y = yPixelTopInt; y < yPixelBottomInt; y++) {                                 pixels[x + y * width] = xTexture * 100;                                 zBuffer[x + y * width] = 0;                         }                 }         }```
I attached the actual .jar file if you need to test it to see what's going on.