Rotate axis labels

709 views
Skip to first unread message

BrittaF

unread,
Oct 29, 2012, 5:52:23 PM10/29/12
to jz...@googlegroups.com
Has anyone ever tried to rotate the z axis label or have any hints as to how i might do that? So that the label is parallel to the z axis and maybe moved outside of the tick labels.

Martin Pernollet

unread,
Nov 1, 2012, 5:25:44 PM11/1/12
to jz...@googlegroups.com
Each axis label is renderer by AxeBox.drawTicks [1]. Search for variable declaration axeLabel. It stand at line 500 on the latest commit.
It may be a little headache since there's one drawTicks method for all axis.
If you refactor a more flexible AxeBox, please let us know :)
Cheers,

BrittaF

unread,
Dec 3, 2012, 11:53:29 AM12/3/12
to jz...@googlegroups.com
Sorry this has taken so long but i'm just getting back to this now.
 
Do you know how i might rotate the text? In AxeBox.drawTicks i tried implementing a custom text renderer for the drawText call. In the custom renderer I tried using glRotatef after searching around online and have tried a few different things with it but am not sure how to use it with these objects maybe.
 
Generally when I see JOGL examples online they are something like:
 
renderer.beginRendering(int, int);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glRotatef(45, 0, 0, 01);
renderer.draw(..);
renderer.endRendering();
glPopMatrix();
 
 
So I've tried a few things in the CustomTextRenderer (trying to implement custom TextBitMapRenderer) but am not sure how this should work with the way the strings are drawn. Currently the default renderer does:
 


// sets position to draw string at 
gl.glRasterPos3f(posReal.x + sceneOffset.x, posReal.y + sceneOffset.y, posReal.z + sceneOffset.z);
// draws string at that position
glut.glutBitmapString(font, s);
 
 
And one thing i've tried is doing gl.glRotatef(); before these two lines, but that just moves the text around the graph and doesn't rotate it, like so that it's parallel the the z axis. I've also tried using textRenderer.draw(..) as in my first example, but using render3D() and draw3D(); but nothing gets drawn at all.  
 
Do you have any knowledge or tips of where i might look or what else i might try to rotate the text?
 
Thanks

Martin Pernollet

unread,
Dec 5, 2012, 8:14:57 AM12/5/12
to Jzy3d
Hi,
I never tried myself rotating text, but I think glRotate is a good approach. Some possible reasons for a bad placement may be: 
1) rotation point is not on the text, but somewhere else (0,0?)
2) your scene is squared, which applies a global scaling that cause problem to your transform in that case just desactivate scaling.
3) you forgot to call glLoadIdentity right after pushMatrix (doing so should be enough to avoid the "squared scene" stuff)
concerning your sample gl code:
1) modelview is not necessary, jzy3d handles it already
2) maybe call beginrendering after push matrix
 
Please let us now if this work with these hints.
Martin

BrittaF

unread,
Jan 24, 2013, 3:44:30 PM1/24/13
to jz...@googlegroups.com
For an update, I think that one of my main problems was that the bitmap strings don't rotate. I tried glut.glutStrokeString(font, s); instead and i can get it to rotate now, but I have to figure out the positioning. I'm looking at some tutorials and posts online trying to figure that out. The steps seem to be:
 
gl.glPushMatrix();
gl.glLoadIdentity();
gl.glRotatef(90, 0, 1, 0);
gl.glTranslatef(x,y,y); // this is the piece i am trying to figure out and am now having trouble with
gl.glScalef(-4f, -4f, -4f); // also working on this still, the 4 seems to be a good size but when and how to flip the string in each direction will be tricky
glut.glutStrokeString(font, s);
gl.glPopMatrix();
 
I'll let you know if I get it working. Also note that the font has to be one of the two stroke fonts, so I'm not sure if I can change it to be the same as current font yet or not.
 
Thanks

BrittaF

unread,
Jan 24, 2013, 4:47:27 PM1/24/13
to jz...@googlegroups.com
Also, I was using the TextBitMapRender class, since that seems to be what's used in chart by default, I haven't investigated the other Text renders to see if it would be easier to try rotation in one of those, might try that next.

BrittaF

unread,
Feb 5, 2013, 11:23:56 AM2/5/13
to jz...@googlegroups.com
FYI I think there may be a minor bug in Camera.side(Coord3d point) method. I was looking at this method for trying to position my text better (for some reason with TextRenderer I am having trouble getting the text to line up as well). While debugging it I noticed that the point being passed in is not scaled whereas it looks like eye and target are scaled points. I had noticed sometimes in my graph that my tick labels would overlap the tick lines on the axes when rotating every two times or so, and when debugging I noticed that the hAlign that was calculated in AxeBox using side was incorrect when this was happening.. It seemed to be every few rotations it would either overlap or not overlap the tick marks. But I tried out scaling the point first and now so far I'm not seeing the tick labels ever overlapping the tick lines.

Martin Pernollet

unread,
Feb 5, 2013, 5:41:27 PM2/5/13
to Jzy3d
Indeed, camera points are scaled geometries, whereas other objects (drawable, etc) are scaled using gl transforms.
Many thanks for reporting that solution.
Martin


2013/2/5 BrittaF <britta....@gmail.com>
--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes Jzy3d.
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse jzy3d+un...@googlegroups.com.
Pour plus d'options, visitez le site https://groups.google.com/groups/opt_out .
 
 

BrittaF

unread,
Feb 6, 2013, 2:36:23 PM2/6/13
to jz...@googlegroups.com
Ok I got this looking good enough to my liking.
 
I think I already posted most of this, but here's what I ended up doing:
 
1. extended AxeBox to fix the use of Camera.side() to use a scaled point (point.mul(scale)), and to use the custom text renderer I created. I also used side() to tell me which side my axis labels are on (similarly to how the tick labels are done) so that I could adjust the rotated text to be outside the tick labels far enough, since there's some weirdness with positioning when rotating.
2. extended TextBitMapRenderer to create my own drawText method. Decided to extend this class so for all the other methods I don't care about for now it will use this class. based on the alignment and whether I want the text rotated, adjusted the text left, right, up or down similarly to what was being done in TextBitMapRenderer but with some trial and error for the rotated text. The new text drawing is doen using TextRenderer as such:
 

renderer.beginRendering(renderingWidth, renderingHeight);

renderer.setColor(color.

r, color.g, color.b, color.a);

gl.glMatrixMode(GL2.

GL_MODELVIEW);

gl.glPushMatrix();

gl.glLoadIdentity();

gl.glTranslatef(posScreenShifted.

x, posScreenShifted.y, 0);

if (rotate) {

gl.glRotatef((

float) angleInDegrees, 0, 0, 1);

rendererBounds = renderer.getBounds(s);

stringHorizontalWidth = (

float) rendererBounds.getHeight();

stringVerticalHeight = (

float) rendererBounds.getWidth();

renderer.draw(s, 0, 0);

}

else {

stringHorizontalWidth = (

float) rendererBounds.getWidth();

stringVerticalHeight = (

float) rendererBounds.getHeight();

renderer.draw(s, 0, 0);

// renderer.flush();

}

renderer.flush();

gl.glPopMatrix();

renderer.endRendering();

 

Sorry let me know  if there's a better way to format code. And then I replaced the strllen and fontheight usage with the rendererBounds stuff, seems to work ok.

Martin

unread,
Feb 7, 2013, 7:34:07 AM2/7/13
to jz...@googlegroups.com
Hi,
Thanks for sharing the hints. Feel free to send some java code, so that it can be contributed to the API. Do not forget to add @author in the class comment :)
Concerning java code formatting in the forum, use the { } button from the group web page (https://groups.google.com/forum/...).
Cheers,
Martin

Martin Pernollet

unread,
Oct 10, 2014, 8:50:52 AM10/10/14
to Jzy3d
Hi Britta,

I tried to apply your label rotation code for 2d charts [1], wishing to have the Y axis label displayed vertically, but unfortunately it fails.

Do you have a suggestion to make it work?

Thanks in advance for sharing your experience!

Horizontal Y label

Images intégrées 2


Failing Vertical Y label

Images intégrées 1


--

BrittaF

unread,
Oct 13, 2014, 12:23:01 AM10/13/14
to jz...@googlegroups.com
In my example I used TextRenderer since i couldn't get the bitmap strings to rotate, and i think i found that they will not rotate. Earlier on before i got it working i tried glutStrokeString or something and the rotation worked but i couldn't figure out the position so i went with TextRenderer and that worked well.
Message has been deleted

can v

unread,
Feb 11, 2020, 8:56:55 AM2/11/20
to Jzy3d
Hello, I know, the topic is old, but no solution was found. 
Maybe there is some news on how to turn the axis name?
rotate_label.PNG

Martin Pernollet

unread,
Feb 18, 2020, 6:09:12 AM2/18/20
to jz...@googlegroups.com
No, this feature has not been added to the API yet.

I have created the enhancement request : https://github.com/jzy3d/jzy3d-api/issues/119



On Tue, Feb 11, 2020 at 2:56 PM can v <aleksand...@gmail.com> wrote:
Hello, I know, the topic is old, but no solution was found. 
Maybe there is some news on how to turn the axis name?

--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "Jzy3d".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse jzy3d+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages