3

I've got a particular model that acts as controls in the viewer. The user can click on different parts of it to perform transformations on another model in the viewer (like controls/handles in applications like Unity or Blender).

We'd like the controls to remain the same size regardless how zoomed in/out the camera is. I've tried scaling the size of it based on the distance between the object and the camera but it isn't quite right. Is there a standard way of accomplishing something like this?

The controls are rendered using the fixed pipeline, but we've got other components using the programmable pipeline.

Boumbles
  • 2,473
  • 3
  • 24
  • 42
  • I'm not quite sure what the problem here is. I assume you know the difference between a perspective and orthographic projection? It sounds like all you need is the latter. – Andon M. Coleman Aug 21 '15 at 15:21

2 Answers2

0

The easy answer is "use the programmable pipeline" because it's not that difficult to write

if(normalObject) {
    gl_Position = projection * view * model * vertex;
} else {
    gl_Position = specialMVPMatrix * vertex;
}

Whereas you'll spend a lot more code trying to get this to work in the Fixed-Function-Pipeline and plenty more CPU cycles rendering it.

Xirema
  • 19,889
  • 4
  • 32
  • 68
  • I don't see why this is related to fixed function vs programmable pipeline. In both cases, just a different matrix is used for rendering, making the condition in your shader quite pointless. Instead of changing `normalObject`, the matrix could be changed directly. – derhass Aug 21 '15 at 15:42
  • There's a million ways to program it. My code was just an example. The important part is, if they stick with FFP, it becomes a greater hassle to adjust how the controls are rendered. – Xirema Aug 21 '15 at 15:46
  • Well, I'm not arguing against shaders (and I'm not the one who downvoted this). But in this particular case, I don't see any relevant difference for shaders vs. fixed pipeline. This is just about what matrix is used for rendering. – derhass Aug 21 '15 at 15:48
0

With the fixed pipeline, the easiest way to do this is to simply not apply any transformations when you render the controls:

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

// draw controls

glPopMatrix();

glMatrixMode(GL_MODELVIEW);
glPopMatrix();

The glPushMatrix()/glPopMatrix() calls will make sure that the previous matrices are restored at the end of this code fragment.

With no transformation at all, the range of coordinates mapped to the window will be [-1.0 .. 1.0] in both coordinate directions. If you need anything else, you can apply the necessary transformations before you start drawing the controls.

Reto Koradi
  • 53,228
  • 8
  • 93
  • 133