Convert glm::vec4 to glm::vec3

感情迁移 提交于 2019-12-03 23:03:22

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());

and gives this output

fvec3(1.000000, 2.000000, 3.000000)

SystemParadox

Swizzling is not enabled by default in glm as it uses macros which might cause naming conflicts. To enable it:

#define GLM_SWIZZLE
#include <glm/glm.hpp>

In glm, swizzling is done using functions:

vec3 v3 = v4.xyz();

See: http://glm.g-truc.net/0.9.2/api/a00002.html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!