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


相关推荐

  • 标准正态分布的分布函数服从均匀分布_python 正态分布

    标准正态分布的分布函数服从均匀分布_python 正态分布三种由(0,1)均匀分布构造标准正态分布随机变量的方法:Box–Muller算法,中心极限定理和KindermanandMonahanmethod。

    2025年7月21日
    5
  • 怎样实现给DEDE的栏目增加栏目图片(2)

    怎样实现给DEDE的栏目增加栏目图片(2)

    2021年9月23日
    47
  • Linux时间戳转换_时间戳转换软件

    Linux时间戳转换_时间戳转换软件在大多数UNIX系统中,当前时间存储为自特定时刻以来经过的时间以简化,将时间保持为长整数。所有UNIX系统普遍接受的时刻是1970年1月1日凌晨12:00:00。这称为UNIX时间戳,并被所有现代UNIX/Linux系统识别。Linux时间戳date命令例如,如果我们希望找到2022年1月1日的UNIX时间戳,我们可以使用date命令。date尝试将字符串解析为格式化的日期和时间(或者,如果未指定时间戳,则假定时间为00:00AM),然后打印出给定

    2022年10月2日
    4
  • 机器学习 之 Haar特征

    机器学习 之 Haar特征Haar特征Haar特征原理综述Haar特征是一种反映图像的灰度变化的,像素分模块求差值的一种特征。它分为三类:边缘特征、线性特征、中心特征和对角线特征。用黑白两种矩形框组合成特征模板,在特征模板内用黑色矩形像素和减去白色矩形像素和来表示这个模版的特征值。例如:脸部的一些特征能由矩形模块差值特征简单的描述,如:眼睛要比脸颊颜色要深,鼻梁两侧比鼻梁颜色要深,嘴巴比周围颜色要深等。但矩形特征只对一

    2022年6月16日
    42
  • 激活成功教程无线网络密码-BT3如何使用3

    激活成功教程无线网络密码-BT3如何使用3BT3虚拟机SNOOPWEP2激活成功教程无线网络WEP密钥图解1.下载BT3光盘映像文件(ISO格式),比如:bt3-final.iso;用WinISO或UltraISO(这个还支持DVD

    2022年7月4日
    27
  • android设计个人简历页面_Android程序员个人简历模板下载(Word格式)[通俗易懂]

    android设计个人简历页面_Android程序员个人简历模板下载(Word格式)[通俗易懂]求职意向:Android程序员熟悉Android系统体系结构和软件开发技术,熟悉Eclipse集成开发环境以及Git代码管理工具;熟悉网络通信协议Http,Socket编程,XMPP协议以及JSON数据解析;熟悉Android程序开发,熟悉四大组件、常用UI组件、多线程等操作及原理;熟练掌握SQLite数据库、SharedPreferences以及文件存储等存储方式;衷情于互联网技术应用。XXXX…

    2022年4月28日
    122

发表回复

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

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