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


相关推荐

  • w7设置双显示器_4K+144Hz 支持FreeSync Acer XV273K显示器评测

    w7设置双显示器_4K+144Hz 支持FreeSync Acer XV273K显示器评测2018年末,AMD宣布旗下FreeSync技术正式升级为RadeonFreeSync2HDR技术,带来了亮度、对比度、层次感更加完美的游戏画面,尤其是针对HDR游戏。而在随后的CES2019上,NVIDIA对G-Sync进行了重新分级,其中G-SyncCompatible标准正式开启FreeSync显示器兼容模式。两大“劲敌”的一系列动作意味着,未来FreeSync显示器或将成为更多游…

    2022年5月6日
    68
  • 瑞芯微rk3399pro_arm主板定制开发

    瑞芯微rk3399pro_arm主板定制开发深圳市宁远电子科技有限公司于2015年在中国广东省深圳市成立,公司自成立以来一直专注于工业嵌入式产品的软硬件研发和生产,以及相应的增值服务。公司拥有强大的研发技术实力,创始团队来自于华为,三星十年工作经验以上资深研发人员。  深圳市宁远电子科技有限公司专注于工来控制产品的研发,是ARM在中国最具实力的方案公司.  公司定位于中高端产品的研发,基于RK3288,RK3399等处理器,,开发了…

    2022年10月14日
    6
  • C语言的字符串分割

    说起来很有意思,自认为对C语言理解得还是比较深刻的。但居然到今天才知道有个strtok函数,试用了一下突然感慨以前做了多少重复劳动。每次需要解析配置文件,每次需要分割字符串,居然都是自己去分割字符串,

    2021年12月24日
    40
  • 流水线上的思考——异步程序开发模型(3)

    流水线上的思考——异步程序开发模型(3)

    2022年3月8日
    44
  • 十大经典思维面试题_JS面试题大全

    十大经典思维面试题_JS面试题大全年轻人你不讲武德,耗子尾汁~~~总结就是为了形成自己的js知识网,提升自己,加油!开始干1、介绍js的基本数据类型  答:Undefined、Null、Boolean、Number、String2、js有哪些内置对象? 答:数据封装类对象:Object、Array、Boolean、Number和String  其他对象:Function、Arguments、Math、Date、RegExp、Error  3、this对象的理解 答:this总是指向函数的直接调用者(而非间接调用者

    2022年8月26日
    6
  • ubuntu clion激活码【2021.8最新】[通俗易懂]

    (ubuntu clion激活码)这是一篇idea技术相关文章,由全栈君为大家提供,主要知识点是关于2021JetBrains全家桶永久激活码的内容IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html1STL5S9V8F-eyJsa…

    2022年3月27日
    115

发表回复

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

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