So i'm currently attempting to write a 3D renderer. From no prior knowledge because I want to challenge myself. But I'm stuck here, and thought I'd bring it to StackExchange because I always see brilliant solutions! If more code is needed please just ask!
This Is My Square Render Code:
public void renderSquare(int xPos, int yPos, float zPos, int width, int height, int color) { clearArray(); for(int y = 0; y < height; y++ ) { int yy = y + yPos; for(int x = 0;x < width; x++) { int xx = xPos + x; float xS = -1f, yS = -1f; if(xx < centerX ) { xS = ((xx / zPos)) + centerX; }else { xS = ((xx / zPos)) - centerX; } if(yy < centerY) { yS = ((yy / zPos) - 0.5f) + centerY; }else { yS = ((yy / zPos) - 0.5f) - centerY; } setPixel((int)xS, (int)yS, color); } } } Plus How I Set Pixels:
public void setPixel(int xPix, int yPix, int color) { if(xPix < 0 || xPix > width || yPix < 0 || yPix > height) return; try { render_buffer[xPix + yPix * width] = color; }catch(Exception e) { return; } } Any help is appreciated
]1
