jzy3d / jzy3d-api

A Java API for 3d and 2d charts
BSD 3-Clause "New" or "Revised" License
282 stars 145 forks source link

jGL matrix inversion get full of NaN values on XZ or YZ projections #286

Open jzy3d opened 2 years ago

jzy3d commented 2 years ago

Symptom

The impact for EmulGL (only) is that - without hack - the 2D to 3D projection provides Coord3D(0,0,0), leading to invisible tick and axis labels placed on the upper left corner for XZ and YZ projection only.

image

This is not the case for XY projection, and this never happens with Native charts.

image

Origin

When Camera.screenToModel is called by TextRenderer.to3D, The GLU.inverseMatrix44 method returns matrices full of NaN values.

A solution could be to provide a new implementation of inverseMatrix44, without confidence that it would be as efficient as this one. NB : the code comments let us think that this implementation is the second attempt.

Workaround

In order to get a quick (and dirty) fix, we simply let the view shift a little bit the viewpoint (only in the case of EmulGL) to ensure we do not fall in the case.

image

This is sometime not even visible, e.g. fix for XZ

image

This is sometime visible a bit, e.g. fix for YZ

image

Reproduce

See this integration test and run the test as a program rather than a unit test

public class ITTest_2D_Colorbar extends ITTest {
  public static void main(String[] args) {
    open(new ITTest_2D_Colorbar().when2DChartWithColorbarAndMargins(WT.EmulGL_AWT, HiDPI.ON, View2D.YZ));
  }
}