将glm :: vec4转换为glm :: vec3 [英] Convert glm::vec4 to glm::vec3

查看:190
本文介绍了将glm :: vec4转换为glm :: vec3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将glm::vec4转换为glm::vec3?

仅需要xyz-可以删除w组件.

Only x, y, z is required- the w component can be dropped.

在GLSL中,可以使用.xyz [1]完成此操作,但是在glm中,这会导致编译错误:

In GLSL this can be done with .xyz[1], but in glm this results in a compile error:

error: 'glm::vec4' has no member named 'xyz'

[1] http://en.wikibooks.org/wiki/GLSL_Programming/Vector_and_Matrix_Operations #Components

推荐答案

只需使用vec3 构造函数.在0.9.5分支上,这里:

Just use vec3 constructor. Here, on 0.9.5 branch:

glm::vec4 v4(1, 2, 3, 4);
glm::vec3 v(v4);
printf("%s\n", glm::to_string(v).c_str());

并给出此输出

fvec3(1.000000,2.000000,3.000000)

fvec3(1.000000, 2.000000, 3.000000)

这篇关于将glm :: vec4转换为glm :: vec3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆