Skip to content
Advertisement

Rendering 3D objects on 2D Canvas using Java AWT

I’m trying to port this JS code on Java because I got bored with programming a prototype of my 2D Java Game and I wanted to make my game into 3D, then I got this weird rendering bug, I think my math or logic was off…

enter image description here

Sample data:

JavaScript

Legend:

Cube: the actual cube, has a transform of x, y, z

1 and 2: I don’t get this part, it’s like traces the lines and vertices of the cube

Plotting 1 and 2 returns this: enter image description here

1 Project and 2 Project: The lines to be drawn I think (1 Project is the starting point, 2 Project is the endpoint)

Plotting 1 Project and 2 Project returns this: enter image description here

The code:

JavaScript

Advertisement

Answer

changing

float scaleProjected = FIELD_OF_VIEW / (FIELD_OF_VIEW * z);

to

float scaleProjected = FIELD_OF_VIEW / (FIELD_OF_VIEW + z);

fixes the problem…

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement