1

So basically i have created an application that renders a curve in a 2D-Dimension (X and Y). This application also uses a haptic device, which is represented as a cursor inside of the frame where the curve is also rendered.

The only thing i want to achieve is to map the y-axis of my projection to my z-axis of the haptic workspace of my haptic device. So basically i want to mantain the logic of the curve and cursor rendering and only change the used axis for my haptic workspace. I used this question: Swap axis y and z

as a guidance. Practically i just have to use glRotatef(90, 1, 0, 0) to achieve what i want. I tried rotating only the projection matrix of my haptic workspace, but this sadly doesnt work for me.

This is how my normal curve looks: Normal Curve

Those are the results, while trying different options: enter image description here

enter image description here

This is my code

reshapeCallback:

void reshapeCallback(int width, int height) {
glViewport(0, 0, width, height);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(minX, maxX, minY, maxY, -1, 11);
// glRotatef(90, 1, 0, 0) [4th Try]
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// glRotatef(90, 1, 0, 0) [5th Try]

updateWorkspace();
}

updateWorkspace():

void updateWorkspace() {
GLdouble modelview[16];
GLdouble projection[16];
GLint viewport[4];

glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
//glRotatef(90, 1, 0, 0) [2nd try]
glGetDoublev(GL_PROJECTION_MATRIX, projection);
//glRotatef(90, 1, 0, 0) [1st try]
glGetIntegerv(GL_VIEWPORT, viewport);

hlMatrixMode(HL_TOUCHWORKSPACE);
hlLoadIdentity();
//glRotatef(90, 1, 0, 0) [3rd try]

// Fit haptic workspace to view volume.
hluFitWorkspace(projection);

// Compute cursor scale.
gCursorScale = hluScreenToModelScale(modelview, projection, viewport);
gCursorScale *= CURSOR_SIZE_PIXELS;
}

drawLine():

void drawLine() {
static GLuint displayList = 0;

if (displayList)
{
    glCallList(displayList);
}
else
{
    displayList = glGenLists(1);
    glNewList(displayList, GL_COMPILE_AND_EXECUTE);
    glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT);
    glDisable(GL_LIGHTING);
    glLineWidth(2.0);
    glBegin(GL_LINE_STRIP);
    for (int i = 0; i < vertices.size(); i += 2) {
        glVertex2f(vertices[i], vertices[i + 1]);
    }
    glEnd();
    glPopAttrib();
    glEndList();
}
}

I numerated the tries of glRotatef() for different positions. I hope someone can give me a hint where my thought process went wrong.

Spektre
  • 49,595
  • 11
  • 110
  • 380
LoveAndMercy
  • 27
  • 1
  • 1
  • 6
  • You only have coordinates that have only 2 components (x, y). Then why do you swap y and z? This would make y become zero. – Rabbid76 Sep 27 '22 at 16:22
  • see [Understanding 4x4 homogenous transform matrices](https://stackoverflow.com/a/28084380/2521214) so you just swap the 2 columsn in your matrix ... – Spektre Sep 28 '22 at 07:36
  • Thank your for your answers. My haptics device has 3 coordinates, even if im only using his x and y coordinates. Also those are the ones that i wanted to swap. Inserting hlRotatef() instead of glRotatef() fixed my problem. glRotatef() was rotate my openGL matrices instead of my touchworkspace matrix, so here was the problem. – LoveAndMercy Sep 29 '22 at 07:28

1 Answers1

0

Point the first: For the love of God USE SHADERS AND NOT OLD OPENGL.

With shaders, it is a trivial task of swapping 2 arguments, changing

gl_Position = vec4(x, y, z, 1);

to

gl_Position = vec4(x, z, y, 1);

I would recommend looking at this tutorial for shaders.

Other that that, in my opinion the code looks like it should work, but if it doesn't I know how finicky glRotate can be, so I really have no advice other that to try things until it works.

Sorry I couldn't give a full, direct answer.

cs1349459
  • 911
  • 9
  • 27