user1181445
user1181445

Reputation:

Broken Java 3D Graphics

I am trying to draw a 3D tile grid that can be rotated and elevated.

The grid though, when rotated sometimes, does not show the graphics as it should, and mutilates them. The regular grid should look nothing like this.

The top half should not be present.

enter image description here

Can anyone help explain or give examples as to what may be causing this issue? Just found something else: When you see the spike appear, on one side of your screen, on the opposite, that tile is missing. :

enter image description here

Upvotes: 2

Views: 863

Answers (2)

Luke Woodward
Luke Woodward

Reputation: 64949

I found that if you set azimuth to 133, elevation to 324, zmod to -0.9, leave xmod at 0 and change the grid to 7 × 7 instead of 10 × 10, then only one single point 'misbehaves'. For this one misbehaving point, we have:

  • i = 48, j = 3,
  • x0 = 7.0, y0 = 0.0, z0 = 6.1,
  • x1 = -0.31273127, y1 = 5.4544506, z1 = -7.5074077,
  • near = 6.0 and nearToObj = 1.5,

just before the following two lines:

            x1 = x1 * near / (z1 + near + nearToObj);
            y1 = y1 * near / (z1 + near + nearToObj);

The critical thing here is that z1 + near + nearToObj has crossed below zero. As it crossed below zero, it caused the sign of the values of x1 and y1 calculated by the above two lines to change. This sign change is what causes the grid to appear wrong.

I'm no expert in 3D graphics, but I believe this outcome suggests that you can't plot the point in question because it has gone behind the camera. I'm afraid I'm not sure what the best way to solve this problem would be - that would require more knowledge of 3D graphics than I have.


As for my other answer, it was totally wrong, so I've deleted it. If I was going to claim that the Java 2D graphics API was any doing wrapping using 16-bit integers, I could at least have tried to verify that

g.drawLine(30, 30, 60, 60);

and

g.drawLine(30, 30, 60 + 65536, 60 + 65536);

produced the same output. They do not.

Upvotes: 2

sarnold
sarnold

Reputation: 104020

What's (new BasicStroke(6 / 5)) supposed to do?

6 / 5 is a fancy way to write 1.

$ cat Int.java
class Int {
    public static void main(String args[]) {
        System.out.println("6 / 5 == " + (6 / 5));
        return;
    }
}
$ make Int.class
javac Int.java
$ java Int
6 / 5 == 1
$ 

Upvotes: 1

Related Questions