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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 一键分享到QQ空间、QQ好友、新浪微博、微信代码

    一键分享到QQ空间、QQ好友、新浪微博、微信代码

    2021年10月28日
    112
  • web服务器短信监控服务是什么_手机web服务器在哪打开

    web服务器短信监控服务是什么_手机web服务器在哪打开服务器监控软件可以进行各种服务器的WEB监控,系统将以WEB的用户的身份按用户指定的时间检测您的WEB是否正常,一旦检测到不正常,将以短信/邮件方式报警。如图所示: 图:WEB监控  图:WEB监控日志记录 相关监控功能:PING监控cpu监控内存监控MySQL监控DB2监控流量监控错误监控TCP服务监控

    2025年6月23日
    3
  • 用python编写猴子吃桃问题_上午给猴子四只香蕉

    用python编写猴子吃桃问题_上午给猴子四只香蕉房内有一个猴子,一个箱子,天花板上挂了一串香蕉,其位置如图1所示,猴子为了拿到香蕉,它必须把箱子搬到香蕉下面,然后再爬到箱子上。

    2022年9月26日
    2
  • asdsad

    asdsad这里写自定义目录标题欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML图表FLowchart流程图导出与导入导出导入欢迎使用Ma…

    2022年4月27日
    50
  • http接口取参方式 – getParameter 和 getParameterValues[通俗易懂]

    http接口取参方式 – getParameter 和 getParameterValues[通俗易懂]前言:最近写http接口时,有了很多关于接口取参方式的疑问,大家都知道Servlet常用的取参方式有getParameter、getParameterValues、getInputStream(读流形式)。SpringMvc常用的有封装好的@RequestParam,RequestBody。这些取参方式都有什么特点,我都写了测试接口,利用postman做了测试…

    2022年7月22日
    20
  • iptables 开放防火墙端口

    iptables 开放防火墙端口总所周知,远程访问centos服务的时候,都要开放相应服务的端口。下面就来说道说道。存在的问题一般情况下,centos下都会存在一个/etc/sysconfig/iptables文件,该文件是用来记录要开放的端口ip的。当然,也不排除新安装的centos,空空如也缺失的,此时就无法执行serviceiptablesrestart。如果你的centos中能正常运…

    2022年10月19日
    0

发表回复

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

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