# Problem with gluLookAt

I am moving around my “image” by specifying the XYZ-Coordinates of my view-point (obtained interactively) which is then used as the Eye-Coordinates in gluLookAt which has the center-coordinates always as 0,0,0 and the Vertical coordinates appropriately set via the following code (in VB):

``````xEye = xRot: yEye = yRot: zEye = zRot
xVer = 0: yVer = 0: zVer = 1
If xRot = 0 And yRot = 0 Then
yVer = zRot: zVer = 0
End If
``````

So far everything works perfect.
Then I’ve added a little XYZ-Axis, each having a different color, in a corner of my window in order to know and see the where about of my view-point. In doing this, having done the gluLookAt, I TRANSFER to a corner and then draw three lines (each 10 units in length) along the X-, Y- and Z-Axis with corresponding color for each one.
Again, so far so good!

Then I decided to add the Axis-Letter at the end of each axis as UPRIGHT and FACING ME and the problem started. In doing this, obviously, I had to transfer to (10,0,0) and write “X”, transfer to (0,10,0) and write “Y” and transfer to (0,0,10) and write “Z”, after the gluLookAt and TRANSFER to the CORNER call.

The problem is that the letters are not shown as expected and I have to call another gluLookAt with another set of Eye-Coordinates and Vertical-Coordinates (the center being kept at 0,0,0!?!?) which are set up via the following code:

``````xEyeC = 0#: yEyeC = 1#: zEyeC = 0#
xVerC = 0#: yVerC = 0#: zVerC = Sgn(yRot)
If yRot = 0 And xRot &lt;&gt; 0 Then
xVerC = Sgn(xRot): zVerC = 0#: zEyeC = Sgn(zRot)
ElseIf xRot = 0 And yRot &lt;&gt; 0 Then
zEyeC = Sgn(zRot)
ElseIf xRot = 0 And yRot = 0 And zRot &lt;&gt; 0 Then
yEyeC = 0#: zEyeC = Sgn(zRot)
yVerC = Sgn(zRot): zVerC = 0#
ElseIf xRot = 0 And yRot = 0 And zRot = 0 Then
zVerC = -1#
End If
``````

But still, out of 26 (Unit) View-Points:
-1,-1,-1
-1,-1,0
-1,-1,1
-1,0,-1
-1,0,0
-1,0,1
-1,1,-1
-1,1,0
-1,1,1
0,-1,-1
0,-1,0
0,-1,1
0,0,-1
0,0,1
0,1,-1
0,1,0
0,1,1
1,-1,-1
1,-1,0
1,-1,1
1,0,-1
1,0,0
1,0,1
1,1,-1
1,1,0
1,1,1
some like (1,1,1) show the Axis-Letters as “Skewed” (i.e. tilted and/or rotated to some extent) PLUS when I use non-unit View-Points such as (1,2,3), the problem gets worse (while the image is viewed correctly)!?!?!

Is there a simple and more effective way of “drawing text as UPRIGHT and FACED TO USER in an ‘rotaing space’ created by gluLookAt”?

My highest appreciation is attached.

What are you using to draw the letters? Bitmap fonts? Textured fonts? Outlined fonts?

Hi and thank you for being so kind.

Here is the code and I think it’s Bitmap!?

Public Sub buildFont()
Dim font As Long

base = glGenLists(128)
font = CreateFont(-12, 0, 0, 0, FW_BOLD, False, False, False, ANSI_CHARSET, _
OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY, _
FF_DONTCARE Or DEFAULT_PITCH, “Arial”)
SelectObject ghDC, font

wglUseFontOutlines ghDC, 0, 128, base, 0, 0.04, WGL_FONT_POLYGONS, gmf(0)
End Sub

That would be an outlined font. Bitmap fonts won’t actually rotate, though the initial raster position can be modified by the MODELVIEW matrix.

I think what you want to do is similar to billboarding. That is, rotate your text so that it is always facing you.

If you are always looking at 0,0,0 it should be easy to figure out what angle you are looking from.

It will take a little bit of math, but you can use tricks with the dot product and cross products to get the axis to rotate around, and the angle to rotate.

The cross product of the vector from 0,0,0 to the eye point you give to gluLookAt and the vector for the positive Z axis will give you the axis coordinates to rotate around, or if you only rotate around the X, Y, or Z axis you can just use those.

Once you have the axis you rotate around, you use the dot product of that axis and the vector of your eye point to get the cos (or was it sin, I never remember) of the angle you need to rotate. If you keep track of the rotation increments, you can just use that for the angle.

Once you have the above information, you should be able to do something like this…

drawAxes();

// Draw X
glPushMatrix();
glTranslatef(xPos, 0, 0);
glRotatef(angle, axis.X, axis.Y, axis.Z);
drawText(“X”);
glPopMatrix();

// Draw Y
glPushMatrix();
glTranslatef(0, yPos, 0);
glRotatef(angle, axis.X, axis.Y, axis.Z);
drawText(“Y”);
glPopMatrix();

// Draw Z
glPushMatrix();
glTranslatef(0, 0, zPos);
glRotatef(angle, axis.X, axis.Y, axis.Z);
drawText(“Z”);
glPopMatrix();

I may have missed something there (it’s been one of those mornings) but I think that should at least give you something to get you started on a way to work out your problem.

Thanks a lot!

I understand your suggestion quite well and I am sure I can figure out the math and the procedure to get from my View-Point coordinates to Rotation Angles.

I did a little experiment on (1,1,1) and it actually worked great!
(I had to rotate 90 on X and then 135 on Y as my XYZ’s are always drawn on X-Y plane up on Z-Axis)

Thanks again.