第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

glGetFloat(GL_MODELVIEW_MATRIX, modelview) 返回單位矩陣

glGetFloat(GL_MODELVIEW_MATRIX, modelview) 返回單位矩陣

躍然一笑 2021-09-29 17:20:27
我正在嘗試將 3d 點坐標(biāo)轉(zhuǎn)換為 2d 屏幕坐標(biāo)。但是,問題是當(dāng)我實現(xiàn)它并運行程序時,即使我改變了相機(jī)位置,輸出也沒有變化。盡管我可以完全看到 3d 模型,但輸出通常超出屏幕坐標(biāo)范圍(因此任何點或三角形都沒有機(jī)會超出屏幕坐標(biāo))。將 3d 坐標(biāo)轉(zhuǎn)換為 2d 坐標(biāo)的方法:public Vector2f get2DFrom3D(float x, float y, float z){    FloatBuffer screen_coords = BufferUtils.createFloatBuffer(4);    IntBuffer viewport = BufferUtils.createIntBuffer(16);    FloatBuffer modelview = BufferUtils.createFloatBuffer(16);    FloatBuffer projection = BufferUtils.createFloatBuffer(16);    GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelview);    System.out.println("modelview:");    displayFloatBuffer(modelview);    GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projection);    System.out.println("projection:");    displayFloatBuffer(projection);    GL11.glGetInteger(GL11.GL_VIEWPORT, viewport);    System.out.println("viewport:");    displayIntBuffer(viewport);    boolean result = GLU.gluProject(x, y, z, modelview, projection, viewport, screen_coords);    if (result)    {        System.out.printf("Convert [ %6.2f %6.2f %6.2f ] -> Screen [ %4d %4d ]\n", x, y, z, (int)screen_coords.get(0), (int)(screen_coords.get(3)-screen_coords.get(1)));        return new Vector2f((int)screen_coords.get(0), (int)(screen_coords.get(3)-screen_coords.get(1)));    }    else    {        return null;    }}投影矩陣通過這個方法創(chuàng)建并直接加載到頂點著色器中:private void createProjectionMatrix(){        float aspectRatio = (float) Display.getWidth() / (float) Display.getHeight();        float y_scale = (float) ((1f / Math.tan(Math.toRadians(FOV / 2f))) * aspectRatio);        float x_scale = y_scale / aspectRatio;        float frustum_length = FAR_PLANE - NEAR_PLANE;        projectionMatrix = new Matrix4f();        projectionMatrix.m00 = x_scale;        projectionMatrix.m11 = y_scale;        projectionMatrix.m22 = -((FAR_PLANE + NEAR_PLANE) / frustum_length);        projectionMatrix.m23 = -1;        projectionMatrix.m32 = -((2 * NEAR_PLANE * FAR_PLANE) / frustum_length);        projectionMatrix.m33 = 0;    }我認(rèn)為只有視口是正確的,但模型視圖和投影矩陣看起來好像沒有加載為它們計算的值。注意:我目前使用的是 lwjgl 2.9.3。
查看完整描述

1 回答

?
繁星淼淼

TA貢獻(xiàn)1775條經(jīng)驗 獲得超11個贊

我找到了解決我的問題的方法,并且效果很好。這是我的新 get2DFrom3D 方法:


public Vector2f get2DFrom3D(float x, float y, float z)

{

    FloatBuffer screen_coords = BufferUtils.createFloatBuffer(4);

    IntBuffer viewport = BufferUtils.createIntBuffer(16);

    FloatBuffer modelview = BufferUtils.createFloatBuffer(16);  

    FloatBuffer projection = BufferUtils.createFloatBuffer(16);


    Matrix4f modelviewMatrix = new Matrix4f();

    Matrix4f transformationMatrix = new Matrix4f();

    Matrix4f.mul(transformationMatrix

            , Maths.createViewMatrix(camera)

            , modelviewMatrix);


    modelviewMatrix.store(modelview);

    modelview.rewind();


    projectionMatrix.store(projection);

    projection.rewind();


    GL11.glGetInteger(GL11.GL_VIEWPORT, viewport);


    boolean result = GLU.gluProject(x, y, z, modelview, projection, viewport, screen_coords);


    if (result)

    {

        Vector2f vector = new Vector2f((int)screen_coords.get(0), (int)(screen_coords.get(1)));

        return vector;

    }

    else

    {

        return null;

    }

}

而不是使用 glGetFloat 方法來獲取模型視圖和投影矩陣。我改為使用我已經(jīng)在其他類中創(chuàng)建的矩陣并將這些矩陣作為參數(shù)傳遞。然后,我將矩陣轉(zhuǎn)換為緩沖區(qū),以便我可以使用它們。倒帶它們之后,我終于能夠從 gluProject 中獲得一個點的正確屏幕坐標(biāo)。


即使問題解決了,我仍然不知道為什么這些行不起作用:


  GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelview);

    System.out.println("modelview:");

    displayFloatBuffer(modelview);


    GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projection);


查看完整回答
反對 回復(fù) 2021-09-29
  • 1 回答
  • 0 關(guān)注
  • 380 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號