How to create billboard matrix in glm

前端 未结 2 559
北荒
北荒 2021-02-10 03:35

How to create a billboard translation matrix from a point in space using glm?

2条回答
  •  自闭症患者
    2021-02-10 04:11

    mat4 billboard(vec3 position, vec3 cameraPos, vec3 cameraUp) {
        vec3 look = normalize(cameraPos - position);
        vec3 right = cross(cameraUp, look);
        vec3 up2 = cross(look, right);
        mat4 transform;
        transform[0] = vec4(right, 0);
        transform[1] = vec4(up2, 0);
        transform[2] = vec4(look, 0);
        // Uncomment this line to translate the position as well
        // (without it, it's just a rotation)
        //transform[3] = vec4(position, 0);
        return transform;
    }
    

提交回复
热议问题