LWJGL Forum

Programming => OpenGL => Topic started by: Peilot on January 24, 2017, 15:56:10

Title: Can someone give me a code sample that renders 2 cubes at different Z-axis?
Post by: Peilot on January 24, 2017, 15:56:10
Since I've had trouble rendering on Z-axis, I would like to see how you do it!
Title: Re: Can someone give me a code sample that renders 2 cubes at different Z-axis?
Post by: bobjob on January 25, 2017, 04:54:55
have you tried having a look at the LWJGL Demos (https://github.com/LWJGL/lwjgl3-demos/blob/master/src/org/lwjgl/demo/bgfx/Cubes.java)?

to draw a cube at a different z level.

Either create 2 cubes with different z values (not what you want), or simply translate the mesh then re draw it.

notice the model translate method in the code:
model
.identity()
.translate(
-15.0f + xx * 3.0f,
-15.0f + yy * 3.0f,
0.0f) // <-- change this value here to effect the position on the z-axis
.rotateAffineXYZ(
time + xx * 0.21f,
time + yy * 0.37f,
0.0f)


keep in mind that the example demo sets the limit of the depth range to 0.1 - 100 if your second cube is positioned outside of this range from the camera view it will not display