@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g.create();
// Create and spawn cuboid
for(Cuboid cuboid : ObjectHandler.getCuboids()) {
cuboid.setLocation(cuboid.getLocation().getX() - x, cuboid.getLocation().getY(), cuboid.getLocation().getZ());
}
x++;
Camera.renderView(getWidth(), getHeight(), 1200, g);
g2.dispose();
}
public static void renderView(int width, int height, double depth, Graphics g) {
BufferedImage view = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
double angleX = 1.4; // Horizontal field of view adjustment
double angleY = 1.18; // Vertical field of view adjustment
Point rayTarget = new Point(0, 0, 0);
// Iterate over pixel coordinates for rendering
for (int i = -height / 2; i < height / 2; i++) {
for (int j = -width / 2; j < width / 2; j++) {
// Calculate ray target based on angles and current pixel
rayTarget.setLocation(i * angleX, j * angleY, 200);
// Cast the ray and check for hits
RaycastHit hit = Raycast.castRay(new Point(0, 0, 0), rayTarget, depth);
if (hit != null) {
int color = hit.getColor();
// Set the pixel color in the BufferedImage
try {
view.setRGB(i + (width / 2), j + (height / 2), color);
} catch(ArrayIndexOutOfBoundsException e) {
e.printStackTrace();
}
}
}
}
// Draw the generated BufferedImage onto the provided Graphics object
g.drawImage(view, 0, 0, null);
}
```As you can see, everything is cut off at the left and right hand side. thanks for your help!
#BufferedImage positioned/behaving unexpectedly
1 messages · Page 1 of 1 (latest)
Detected code, here are some useful tools:
[WARNING] The code couldn't end properly...
Problematic source code:
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g.create();
// Create and spawn cuboid
for(Cuboid cuboid : ObjectHandler.getCuboids()) {
cuboid.setLocation(cuboid.getLocation().getX() - x, cuboid.getLocation().getY(), cuboid.getLocation().getZ());
}
x++;
Camera.renderView(getWidth(), getHeight(), 1200, g);
g2.dispose();
}```
Cause:
The code doesn't compile:
cannot find symbol
symbol: class Graphics
location: class
static methods cannot be annotated with @Override
non-static variable super cannot be referenced from a static context
cannot find symbol
symbol: class Graphics2D
location: class
cannot find symbol
symbol: class Graphics2D
location: class
cannot find symbol
symbol: variable ObjectHandler
location: class
cannot find symbol
symbol: class Cuboid
location: class
cannot find symbol
symbol: variable x
location: class
cannot find symbol
symbol: variable x
location: class
cannot find symbol
symbol: variable Camera
location: class
cannot find symbol
symbol: method getWidth()
location: class
cannot find symbol
symbol: method getHeight()
location: class
Remaining code:
```java
public static void renderView(int width, int height, double depth, Graphics g) {
BufferedImage view = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
double angleX = 1.4; // Horizontal field of view adjustment
double angleY = 1.18; // Vertical field of view adjustment
Point rayTarget = new Point(0, 0, 0);
// Iterate over pixel coordinates for rendering
for (int i = -height / 2; i < height / 2; i++) {
for (int j = -width / 2; j < width / 2; j++) {
// Calculate ray target based on angles and current pixel
rayTarget.setLocation(i * angleX, j * angleY, 200);
// Cast the ray and check for hits
RaycastHit hit = Raycast.castRay(new Point(0, 0, 0), rayTarget, depth);
if (hit != null) {
int color = hit.getColor();
// Set the pixel color in the BufferedImage
try {
view.setRGB(i + (width / 2), j + (height / 2), color);
} catch(ArrayIndexOutOfBoundsException e) {
e.printStackTrace();
}
}
}
}
// Draw the generated BufferedImage onto the provided Graphics object
g.drawImage(view, 0, 0, null);
}```
## System out
[Nothing]
<@&987246399047479336> please have a look, thanks.