Вопрос

I am having trouble with a program i am writing. Currently i am reading a OBJ file and rendering it correctly. But my problem is, some images don't fit my window.

I've tried to scale it using glScalef, but the image is still deformed. (almost always on Z)

and here is how i set my window:

gl.glMatrixMode(GL.GL_PROJECTION); 
    gl.glLoadIdentity(); 
    float w = gLDrawable.getWidth(); 
    float h = gLDrawable.getHeight(); 

    if(w > h) gl.glOrtho(-1.0*(w/h), 1.0*w/h, -1.0, 1.0, -1.0, 1.0); 
    else gl.glOrtho(-1.0, 1.0, -1.0*(h/w), 1.0*h/w, -1.0, 1.0); 

Here is my Scale attempt

        if(m.getXVertexMax() - m.getXVertexMin() >  w) gl.glScalef(w/(m.getXVertexMax() - m.getXVertexMin()), 1, 1);
    else gl.glScalef(1/(m.getXVertexMax() - m.getXVertexMin()), 1, 1);

    if(m.getYVertexMax() - m.getYVertexMin() > h) gl.glScalef(1, h/(m.getYVertexMax() - m.getYVertexMin()), 1);
    else gl.glScalef(1, 1/(m.getYVertexMax() - m.getYVertexMin()), 1);

    gl.glScalef(1, 1, (1/(m.getZVertexMax() - m.getZVertexMin())));

enter image description here

enter image description here

No mater what i try, the image is always either short on the x or very large on the z!

Can someone please give a hand here? Thanks :-)

Это было полезно?

Решение

You need to scale uniformly, if you scale the X axis, scale the Y and Z by the same amount.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top