java glm,OpenGL / GLM-切换坐标系方向

java glm,OpenGL / GLM-切换坐标系方向Iamconvertin DirectXandOp OpenGLisrigh DirectXislef Iknowthatint Iwou

java glm,OpenGL / GLM-切换坐标系方向

I am converting some old software to support OpenGL. DirectX and OpenGL have different coordinate systems (OpenGL is right, DirectX is left). I know that in the old fixed pipeline functionality, I would use:

glScalef(1.0f, 1.0f, -1.0f);

This time around, I am working with GLM and shaders and need a compatible solution. I have tried multiplying my camera matrix by a scaling vector with no luck.

Here is my camera set up:

// Calculate the direction, right and up vectors

direction = glm::vec3(cos(anglePitch) * sin(angleYaw), sin(anglePitch), cos(anglePitch) * cos(angleYaw));

right = glm::vec3(sin(angleYaw – 3.14f/2.0f), 0, cos(angleYaw – 3.14f/2.0f));

up = glm::cross(right, direction);

// Update our camera matrix, projection matrix and combine them into my view matrix

cameraMatrix = glm::lookAt(position, position+direction, up);

projectionMatrix = glm::perspective(50.0f, 4.0f / 3.0f, 0.1f, 1000.f);

viewMatrix = projectionMatrix * cameraMatrix;

I have tried a number of things including reversing the vectors and reversing the z coordinate in the shader. I have also tried multiplying by the inverse of the various matrices and vectors and multiplying the camera matrix by a scaling vector.

解决方案

Don’t think about the handedness that much. It’s true, they use different conventions, but you can just choose not to use them and it boils down to almost the same thing in both APIs. My advice is to use the exact same matrices and setups in both APIs except for these two things:

All you should need to do to port from DX to GL is:

Reverse the cull-face winding – DX culls counter-clockwise by default, while that’s what GL keeps.

Adjust for the different depth range: DX uses a depth range of 0(near) to 1(far), while GL uses a signed range from -1 for near and 1 for far. You can just do this as “a last step” in the projection matrix.

DX9 also has issues with pixel-coordinate offsets, but that’s something else entirely and it’s no longer an issue with DX10 onward.

From what you describe, the winding is probably your problem, since you are using the GLM functions to generate matrices that should be alright for OpenGL.

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/232084.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 二十、Sql Server 保留几位小数的两种做法

    二十、Sql Server 保留几位小数的两种做法问题:数据库里的floatmomey类型,都会精确到多位小数。但有时候我们不需要那么精确,例如,只精确到两位有效数字。解决:1.使用Round()函数,如Round(@num,2)参数2表示保留两位有效数字。2.更好的方法是使用Convert(decimal(18,2),@num)实现转换,decimal(18,2)…

    2022年7月20日
    32
  • Toast弹窗_androidshowtoast

    Toast弹窗_androidshowtoast安卓toast弹窗toast弹窗是安卓的一个常用控件,它可以便利的获取上下文对象的地方,进行弹窗提示。本文不追究其中原理,只研究方法。toast的几个常用方法有四种。分别是普通弹窗,改变位置的弹窗,图片弹窗,自定义弹窗。1,普通toast弹窗Toast.makeText()是一个有参函数,参数值有三个。第一个参数是当前的上下文控件,getApplicationContext()获取上下文对象或this获取当前对象。第二个参数是你自己要显示的文字。第三个参数是显示的时间长短。有两种形态的值

    2022年9月25日
    4
  • vs2017安装和使用教程(详细)

    vs2017安装和使用教程(详细)vs2019已于4月2日推出,用户不用卸载vs2017,因为这二者互相独立,项目也兼容,安装教程也是本篇的姊妹篇:vs2019安装和使用教程(详细)vs2017如此强大,不仅仅是C语言,Python,R,F#,ios,Android,Web,Node.js,Azure,Unity,HTML,JavaScript等开发都可以执行,大家快来使用它吧~如果想编写Java的话,可以使用vsc…

    2022年4月26日
    58
  • 天气太冷不想出被窝?来DIY一个离线语音控制器[通俗易懂]

    天气太冷不想出被窝?来DIY一个离线语音控制器[通俗易懂]天气太冷不想出被窝?来DIY一个离线语音控制器点击上方“Embeded小飞哥”,选择“置顶/星标公众号”干货福利,第一时间送达!成就一番伟业的唯一途径就是热爱自己的事业。如果你还没能找到让自己热爱的事业,继续寻找,不要放弃。跟随自己的心,总有一天你会找到的。——乔布斯  你去关灯,你去,你去,。。我去。。小伙伴们有没有在天气寒冷时候,想去关灯,却离不开心爱的被窝的经历呢,有的话,跟着小飞哥一起来DIY一个离线语音控制器,有了它,我们

    2022年6月23日
    25
  • 最强大的疯狂java学习路线图,java学习者必看「建议收藏」

    最强大的疯狂java学习路线图,java学习者必看「建议收藏」双击有图片放大效果

    2022年6月29日
    21
  • 判断端口通不通的几种方法「建议收藏」

    判断端口通不通的几种方法「建议收藏」判断端口通不通的几种方法

    2022年4月23日
    38

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号