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)
上一篇 2025年11月2日 下午8:01
下一篇 2025年11月2日 下午8:22


相关推荐

  • STM32H743 TFTP Boot 简录

    STM32H743 TFTP Boot 简录文章目录 stm32h743 存储简况区域划分分散加载问题引出默认的分散加载文件修改分散加载文件 CubeMX 部分配置 boot 的 jump to appapp 中断向量表偏移 app 分散加载文件修改最简升级 py 脚本 MCU 处理参考 stm32h743 存储简况如下 2MBFlash 分 2 个 bank 存储区 可在两个 banks 并行执行读 编程 擦除操作 1Flash Word 8Words 32Bytes 256bits 其实 1Flash Word 还有额外的 10bitsECC

    2026年3月17日
    2
  • oracle number数据类型的精度

    oracle number数据类型的精度1、number(p,s)  p:1—38  s:-84—127  a、s>0(精确到小数点右边s位,并四舍五入。然后检验有效数位是否     例如:number(5,2)有效数字最多是5位,保留小数点后2位;     123.45 — 123.45     123    — 123.00     1.2356 

    2022年7月24日
    72
  • LoadLibrary失败,GetLastError= 193

    LoadLibrary失败,GetLastError= 193LoadLibrary失败,GetLastError=193LoadLibrary失败,GetLastError报错193时,一般是加载的dll所依赖的某个dll它的依赖项不存在所报的错,可以用DependencyWalker验证该dll所依赖的加载项是否都存在。DependencyWalker安装vs时一般都自带有,如果没有也可以去官网下载http://www.dependencywal…

    2022年7月13日
    20
  • 保姆级部署指南——Mac/Windows双平台30分钟搞定OpenClaw

    保姆级部署指南——Mac/Windows双平台30分钟搞定OpenClaw

    2026年3月14日
    3
  • pycharm远程调试python_pycharm调试教程

    pycharm远程调试python_pycharm调试教程pycharm远程开发与调试0.为pycharm添加远程服务器配置如果你已经为该服务器配置过远程服务器,可忽略此步骤。打开pycharm,tools->Deployment->Configuration,在左边栏点“+“号添加远程服务器。右边配置如下图,只需要配置connection,注意”Visibleonlyforthisproject”的勾去掉!…

    2022年8月29日
    10
  • ThingsBoard——Docker重启失败,报错Connection to localhost:5432 refused的解决方法

    ThingsBoard——Docker重启失败,报错Connection to localhost:5432 refused的解决方法一、问题现在还没编译好thingsboard源代码,用的是docker搭建起来的环境。在写自定义节点,要打包好扔到docker里,再重启docker。后来发现经常重启失败,报错的错误也都是这样:2022-03-0508:53:23,164[main]ERRORcom.zaxxer.hikari.pool.HikariPool-HikariPool-1-Exceptionduringpoolinitialization.org.postgresql.util.PSQLExcepti

    2022年6月19日
    62

发表回复

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

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