对于glm数学库 项目的交叉编译,该项目难度并不大。该文章的目标是编译一套aarch64 Linux Debian嵌入式版本上可以运行的版本库,基本无坑。老套路,先把linux桌面版搞好,然后 移植到嵌入式Linux Debian 板子上。
为啥要搞这么数学库出来呢?OpenGl中在进行图形变换的时候需要使用几何数学库,GLM算是最常用的数学库了。同时兼容性也很好,为啥呢?因为OpenGL Mathematics (GLM) 是基于OpenGL着色语言(GLSL)规范的图形软件的头文件C ++数学库。也就是说 不用链接 静态库、动态库,直接包含hpp文件,然后编写代码就可以了。
GLM提供的类和函数使用与GLSL相同的命名约定和功能设计和实现,因此使用GLSL的人都可以在C ++中使用GLM,当然 这个项目不限于GLSL的功能,还有一些扩展能力:矩阵变换,四元数,数据打包,随机数,噪声实现(使用计算机渲染精致的物体式非常的容易的,但在真实的世界中物体往往不是这样的,它们经常是带污渍、凹痕、磨损的,Ken Perlin在20世纪80年代进行了深入的研究,提出了一种直到现在也很有用的技术——噪声。噪声我们可以认为是一些无规律的数据,类似老电视机中没有信号时出现的随机的雪花像素点)等等。
如果想了解更多,相关内容如下:
对于glm库来说,直接在ubuntu上编译还是很方便的,如下所示:
- $mkdir build
- $cd build
- $cmake ..
- $make
- $make DESTDIR=$PWD/out_x86_64 install
最后生成内容为:
- ── usr
- └── local
- ├── include
- │ └── glm
- │ ├── common.hpp
- │ ├── detail
- │ │ ├── compute_common.hpp
- │ │ ├── compute_vector_relational.hpp
- │ │ ├── _features.hpp
- │ │ ├── _fixes.hpp
- │ │ ├── func_common.inl
- │ │ ├── func_common_simd.inl
- │ │ ├── func_exponential.inl
- │ │ ├── func_exponential_simd.inl
- │ │ ├── func_geometric.inl
- │ │ ├── func_geometric_simd.inl
- │ │ ├── func_integer.inl
- │ │ ├── func_integer_simd.inl
- │ │ ├── func_matrix.inl
- │ │ ├── func_matrix_simd.inl
- │ │ ├── func_packing.inl
- │ │ ├── func_packing_simd.inl
- │ │ ├── func_trigonometric.inl
- │ │ ├── func_trigonometric_simd.inl
- │ │ ├── func_vector_relational.inl
- │ │ ├── func_vector_relational_simd.inl
- │ │ ├── glm.cpp
- │ │ ├── _noise.hpp
- │ │ ├── qualifier.hpp
- │ │ ├── setup.hpp
- │ │ ├── _swizzle_func.hpp
- │ │ ├── _swizzle.hpp
- │ │ ├── type_float.hpp
- │ │ ├── type_half.hpp
- │ │ ├── type_half.inl
- │ │ ├── type_mat2x2.hpp
- │ │ ├── type_mat2x2.inl
- │ │ ├── type_mat2x3.hpp
- │ │ ├── type_mat2x3.inl
- │ │ ├── type_mat2x4.hpp
- │ │ ├── type_mat2x4.inl
- │ │ ├── type_mat3x2.hpp
- │ │ ├── type_mat3x2.inl
- │ │ ├── type_mat3x3.hpp
- │ │ ├── type_mat3x3.inl
- │ │ ├── type_mat3x4.hpp
- │ │ ├── type_mat3x4.inl
- │ │ ├── type_mat4x2.hpp
- │ │ ├── type_mat4x2.inl
- │ │ ├── type_mat4x3.hpp
- │ │ ├── type_mat4x3.inl
- │ │ ├── type_mat4x4.hpp
- │ │ ├── type_mat4x4.inl
- │ │ ├── type_mat4x4_simd.inl
- │ │ ├── type_quat.hpp
- │ │ ├── type_quat.inl
- │ │ ├── type_quat_simd.inl
- │ │ ├── type_vec1.hpp
- │ │ ├── type_vec1.inl
- │ │ ├── type_vec2.hpp
- │ │ ├── type_vec2.inl
- │ │ ├── type_vec3.hpp
- │ │ ├── type_vec3.inl
- │ │ ├── type_vec4.hpp
- │ │ ├── type_vec4.inl
- │ │ ├── type_vec4_simd.inl
- │ │ └── _vectorize.hpp
- │ ├── exponential.hpp
- │ ├── ext
- │ │ ├── matrix_clip_space.hpp
- │ │ ├── matrix_clip_space.inl
- │ │ ├── matrix_common.hpp
- │ │ ├── matrix_common.inl
- │ │ ├── matrix_double2x2.hpp
- │ │ ├── matrix_double2x2_precision.hpp
- │ │ ├── matrix_double2x3.hpp
- │ │ ├── matrix_double2x3_precision.hpp
- │ │ ├── matrix_double2x4.hpp
- │ │ ├── matrix_double2x4_precision.hpp
- │ │ ├── matrix_double3x2.hpp
- │ │ ├── matrix_double3x2_precision.hpp
- │ │ ├── matrix_double3x3.hpp
- │ │ ├── matrix_double3x3_precision.hpp
- │ │ ├── matrix_double3x4.hpp
- │ │ ├── matrix_double3x4_precision.hpp
- │ │ ├── matrix_double4x2.hpp
- │ │ ├── matrix_double4x2_precision.hpp
- │ │ ├── matrix_double4x3.hpp
- │ │ ├── matrix_double4x3_precision.hpp
- │ │ ├── matrix_double4x4.hpp
- │ │ ├── matrix_double4x4_precision.hpp
- │ │ ├── matrix_float2x2.hpp
- │ │ ├── matrix_float2x2_precision.hpp
- │ │ ├── matrix_float2x3.hpp
- │ │ ├── matrix_float2x3_precision.hpp
- │ │ ├── matrix_float2x4.hpp
- │ │ ├── matrix_float2x4_precision.hpp
- │ │ ├── matrix_float3x2.hpp
- │ │ ├── matrix_float3x2_precision.hpp
- │ │ ├── matrix_float3x3.hpp
- │ │ ├── matrix_float3x3_precision.hpp
- │ │ ├── matrix_float3x4.hpp
- │ │ ├── matrix_float3x4_precision.hpp
- │ │ ├── matrix_float4x2.hpp
- │ │ ├── matrix_float4x2_precision.hpp
- │ │ ├── matrix_float4x3.hpp
- │ │ ├── matrix_float4x3_precision.hpp
- │ │ ├── matrix_float4x4.hpp
- │ │ ├── matrix_float4x4_precision.hpp
- │ │ ├── matrix_int2x2.hpp
- │ │ ├── matrix_int2x2_sized.hpp
- │ │ ├── matrix_int2x3.hpp
- │ │ ├── matrix_int2x3_sized.hpp
- │ │ ├── matrix_int2x4.hpp
- │ │ ├── matrix_int2x4_sized.hpp
- │ │ ├── matrix_int3x2.hpp
- │ │ ├── matrix_int3x2_sized.hpp
- │ │ ├── matrix_int3x3.hpp
- │ │ ├── matrix_int3x3_sized.hpp
- │ │ ├── matrix_int3x4.hpp
- │ │ ├── matrix_int3x4_sized.hpp
- │ │ ├── matrix_int4x2.hpp
- │ │ ├── matrix_int4x2_sized.hpp
- │ │ ├── matrix_int4x3.hpp
- │ │ ├── matrix_int4x3_sized.hpp
- │ │ ├── matrix_int4x4.hpp
- │ │ ├── matrix_int4x4_sized.hpp
- │ │ ├── matrix_integer.hpp
- │ │ ├── matrix_integer.inl
- │ │ ├── matrix_projection.hpp
- │ │ ├── matrix_projection.inl
- │ │ ├── matrix_relational.hpp
- │ │ ├── matrix_relational.inl
- │ │ ├── matrix_transform.hpp
- │ │ ├── matrix_transform.inl
- │ │ ├── matrix_uint2x2.hpp
- │ │ ├── matrix_uint2x2_sized.hpp
- │ │ ├── matrix_uint2x3.hpp
- │ │ ├── matrix_uint2x3_sized.hpp
- │ │ ├── matrix_uint2x4.hpp
- │ │ ├── matrix_uint2x4_sized.hpp
- │ │ ├── matrix_uint3x2.hpp
- │ │ ├── matrix_uint3x2_sized.hpp
- │ │ ├── matrix_uint3x3.hpp
- │ │ ├── matrix_uint3x3_sized.hpp
- │ │ ├── matrix_uint3x4.hpp
- │ │ ├── matrix_uint3x4_sized.hpp
- │ │ ├── matrix_uint4x2.hpp
- │ │ ├── matrix_uint4x2_sized.hpp
- │ │ ├── matrix_uint4x3.hpp
- │ │ ├── matrix_uint4x3_sized.hpp
- │ │ ├── matrix_uint4x4.hpp
- │ │ ├── matrix_uint4x4_sized.hpp
- │ │ ├── quaternion_common.hpp
- │ │ ├── quaternion_common.inl
- │ │ ├── quaternion_common_simd.inl
- │ │ ├── quaternion_double.hpp
- │ │ ├── quaternion_double_precision.hpp
- │ │ ├── quaternion_exponential.hpp
- │ │ ├── quaternion_exponential.inl
- │ │ ├── quaternion_float.hpp
- │ │ ├── quaternion_float_precision.hpp
- │ │ ├── quaternion_geometric.hpp
- │ │ ├── quaternion_geometric.inl
- │ │ ├── quaternion_relational.hpp
- │ │ ├── quaternion_relational.inl
- │ │ ├── quaternion_transform.hpp
- │ │ ├── quaternion_transform.inl
- │ │ ├── quaternion_trigonometric.hpp
- │ │ ├── quaternion_trigonometric.inl
- │ │ ├── scalar_common.hpp
- │ │ ├── scalar_common.inl
- │ │ ├── scalar_constants.hpp
- │ │ ├── scalar_constants.inl
- │ │ ├── scalar_integer.hpp
- │ │ ├── scalar_integer.inl
- │ │ ├── scalar_int_sized.hpp
- │ │ ├── scalar_packing.hpp
- │ │ ├── scalar_packing.inl
- │ │ ├── scalar_reciprocal.hpp
- │ │ ├── scalar_reciprocal.inl
- │ │ ├── scalar_relational.hpp
- │ │ ├── scalar_relational.inl
- │ │ ├── scalar_uint_sized.hpp
- │ │ ├── scalar_ulp.hpp
- │ │ ├── scalar_ulp.inl
- │ │ ├── vector_bool1.hpp
- │ │ ├── vector_bool1_precision.hpp
- │ │ ├── vector_bool2.hpp
- │ │ ├── vector_bool2_precision.hpp
- │ │ ├── vector_bool3.hpp
- │ │ ├── vector_bool3_precision.hpp
- │ │ ├── vector_bool4.hpp
- │ │ ├── vector_bool4_precision.hpp
- │ │ ├── vector_common.hpp
- │ │ ├── vector_common.inl
- │ │ ├── vector_double1.hpp
- │ │ ├── vector_double1_precision.hpp
- │ │ ├── vector_double2.hpp
- │ │ ├── vector_double2_precision.hpp
- │ │ ├── vector_double3.hpp
- │ │ ├── vector_double3_precision.hpp
- │ │ ├── vector_double4.hpp
- │ │ ├── vector_double4_precision.hpp
- │ │ ├── vector_float1.hpp
- │ │ ├── vector_float1_precision.hpp
- │ │ ├── vector_float2.hpp
- │ │ ├── vector_float2_precision.hpp
- │ │ ├── vector_float3.hpp
- │ │ ├── vector_float3_precision.hpp
- │ │ ├── vector_float4.hpp
- │ │ ├── vector_float4_precision.hpp
- │ │ ├── vector_int1.hpp
- │ │ ├── vector_int1_sized.hpp
- │ │ ├── vector_int2.hpp
- │ │ ├── vector_int2_sized.hpp
- │ │ ├── vector_int3.hpp
- │ │ ├── vector_int3_sized.hpp
- │ │ ├── vector_int4.hpp
- │ │ ├── vector_int4_sized.hpp
- │ │ ├── vector_integer.hpp
- │ │ ├── vector_integer.inl
- │ │ ├── vector_packing.hpp
- │ │ ├── vector_packing.inl
- │ │ ├── vector_reciprocal.hpp
- │ │ ├── vector_reciprocal.inl
- │ │ ├── vector_relational.hpp
- │ │ ├── vector_relational.inl
- │ │ ├── vector_uint1.hpp
- │ │ ├── vector_uint1_sized.hpp
- │ │ ├── vector_uint2.hpp
- │ │ ├── vector_uint2_sized.hpp
- │ │ ├── vector_uint3.hpp
- │ │ ├── vector_uint3_sized.hpp
- │ │ ├── vector_uint4.hpp
- │ │ ├── vector_uint4_sized.hpp
- │ │ ├── vector_ulp.hpp
- │ │ └── vector_ulp.inl
- │ ├── ext.hpp
- │ ├── fwd.hpp
- │ ├── geometric.hpp
- │ ├── glm.hpp
- │ ├── gtc
- │ │ ├── bitfield.hpp
- │ │ ├── bitfield.inl
- │ │ ├── color_space.hpp
- │ │ ├── color_space.inl
- │ │ ├── constants.hpp
- │ │ ├── constants.inl
- │ │ ├── epsilon.hpp
- │ │ ├── epsilon.inl
- │ │ ├── integer.hpp
- │ │ ├── integer.inl
- │ │ ├── matrix_access.hpp
- │ │ ├── matrix_access.inl
- │ │ ├── matrix_integer.hpp
- │ │ ├── matrix_inverse.hpp
- │ │ ├── matrix_inverse.inl
- │ │ ├── matrix_transform.hpp
- │ │ ├── matrix_transform.inl
- │ │ ├── noise.hpp
- │ │ ├── noise.inl
- │ │ ├── packing.hpp
- │ │ ├── packing.inl
- │ │ ├── quaternion.hpp
- │ │ ├── quaternion.inl
- │ │ ├── quaternion_simd.inl
- │ │ ├── random.hpp
- │ │ ├── random.inl
- │ │ ├── reciprocal.hpp
- │ │ ├── round.hpp
- │ │ ├── round.inl
- │ │ ├── type_aligned.hpp
- │ │ ├── type_precision.hpp
- │ │ ├── type_precision.inl
- │ │ ├── type_ptr.hpp
- │ │ ├── type_ptr.inl
- │ │ ├── ulp.hpp
- │ │ ├── ulp.inl
- │ │ └── vec1.hpp
- │ ├── gtx
- │ │ ├── associated_min_max.hpp
- │ │ ├── associated_min_max.inl
- │ │ ├── bit.hpp
- │ │ ├── bit.inl
- │ │ ├── closest_point.hpp
- │ │ ├── closest_point.inl
- │ │ ├── color_encoding.hpp
- │ │ ├── color_encoding.inl
- │ │ ├── color_space.hpp
- │ │ ├── color_space.inl
- │ │ ├── color_space_YCoCg.hpp
- │ │ ├── color_space_YCoCg.inl
- │ │ ├── common.hpp
- │ │ ├── common.inl
- │ │ ├── compatibility.hpp
- │ │ ├── compatibility.inl
- │ │ ├── component_wise.hpp
- │ │ ├── component_wise.inl
- │ │ ├── dual_quaternion.hpp
- │ │ ├── dual_quaternion.inl
- │ │ ├── easing.hpp
- │ │ ├── easing.inl
- │ │ ├── euler_angles.hpp
- │ │ ├── euler_angles.inl
- │ │ ├── extended_min_max.hpp
- │ │ ├── extended_min_max.inl
- │ │ ├── extend.hpp
- │ │ ├── extend.inl
- │ │ ├── exterior_product.hpp
- │ │ ├── exterior_product.inl
- │ │ ├── fast_exponential.hpp
- │ │ ├── fast_exponential.inl
- │ │ ├── fast_square_root.hpp
- │ │ ├── fast_square_root.inl
- │ │ ├── fast_trigonometry.hpp
- │ │ ├── fast_trigonometry.inl
- │ │ ├── float_notmalize.inl
- │ │ ├── functions.hpp
- │ │ ├── functions.inl
- │ │ ├── gradient_paint.hpp
- │ │ ├── gradient_paint.inl
- │ │ ├── handed_coordinate_space.hpp
- │ │ ├── handed_coordinate_space.inl
- │ │ ├── hash.hpp
- │ │ ├── hash.inl
- │ │ ├── integer.hpp
- │ │ ├── integer.inl
- │ │ ├── intersect.hpp
- │ │ ├── intersect.inl
- │ │ ├── io.hpp
- │ │ ├── io.inl
- │ │ ├── log_base.hpp
- │ │ ├── log_base.inl
- │ │ ├── matrix_cross_product.hpp
- │ │ ├── matrix_cross_product.inl
- │ │ ├── matrix_decompose.hpp
- │ │ ├── matrix_decompose.inl
- │ │ ├── matrix_factorisation.hpp
- │ │ ├── matrix_factorisation.inl
- │ │ ├── matrix_interpolation.hpp
- │ │ ├── matrix_interpolation.inl
- │ │ ├── matrix_major_storage.hpp
- │ │ ├── matrix_major_storage.inl
- │ │ ├── matrix_operation.hpp
- │ │ ├── matrix_operation.inl
- │ │ ├── matrix_query.hpp
- │ │ ├── matrix_query.inl
- │ │ ├── matrix_transform_2d.hpp
- │ │ ├── matrix_transform_2d.inl
- │ │ ├── mixed_product.hpp
- │ │ ├── mixed_product.inl
- │ │ ├── normal.hpp
- │ │ ├── normal.inl
- │ │ ├── normalize_dot.hpp
- │ │ ├── normalize_dot.inl
- │ │ ├── norm.hpp
- │ │ ├── norm.inl
- │ │ ├── number_precision.hpp
- │ │ ├── number_precision.inl
- │ │ ├── optimum_pow.hpp
- │ │ ├── optimum_pow.inl
- │ │ ├── orthonormalize.hpp
- │ │ ├── orthonormalize.inl
- │ │ ├── pca.hpp
- │ │ ├── pca.inl
- │ │ ├── perpendicular.hpp
- │ │ ├── perpendicular.inl
- │ │ ├── polar_coordinates.hpp
- │ │ ├── polar_coordinates.inl
- │ │ ├── projection.hpp
- │ │ ├── projection.inl
- │ │ ├── quaternion.hpp
- │ │ ├── quaternion.inl
- │ │ ├── range.hpp
- │ │ ├── raw_data.hpp
- │ │ ├── raw_data.inl
- │ │ ├── rotate_normalized_axis.hpp
- │ │ ├── rotate_normalized_axis.inl
- │ │ ├── rotate_vector.hpp
- │ │ ├── rotate_vector.inl
- │ │ ├── scalar_multiplication.hpp
- │ │ ├── scalar_relational.hpp
- │ │ ├── scalar_relational.inl
- │ │ ├── spline.hpp
- │ │ ├── spline.inl
- │ │ ├── std_based_type.hpp
- │ │ ├── std_based_type.inl
- │ │ ├── string_cast.hpp
- │ │ ├── string_cast.inl
- │ │ ├── texture.hpp
- │ │ ├── texture.inl
- │ │ ├── transform2.hpp
- │ │ ├── transform2.inl
- │ │ ├── transform.hpp
- │ │ ├── transform.inl
- │ │ ├── type_aligned.hpp
- │ │ ├── type_aligned.inl
- │ │ ├── type_trait.hpp
- │ │ ├── type_trait.inl
- │ │ ├── vec_swizzle.hpp
- │ │ ├── vector_angle.hpp
- │ │ ├── vector_angle.inl
- │ │ ├── vector_query.hpp
- │ │ ├── vector_query.inl
- │ │ ├── wrap.hpp
- │ │ └── wrap.inl
- │ ├── integer.hpp
- │ ├── mat2x2.hpp
- │ ├── mat2x3.hpp
- │ ├── mat2x4.hpp
- │ ├── mat3x2.hpp
- │ ├── mat3x3.hpp
- │ ├── mat3x4.hpp
- │ ├── mat4x2.hpp
- │ ├── mat4x3.hpp
- │ ├── mat4x4.hpp
- │ ├── matrix.hpp
- │ ├── packing.hpp
- │ ├── simd
- │ │ ├── common.h
- │ │ ├── exponential.h
- │ │ ├── geometric.h
- │ │ ├── integer.h
- │ │ ├── matrix.h
- │ │ ├── neon.h
- │ │ ├── packing.h
- │ │ ├── platform.h
- │ │ ├── trigonometric.h
- │ │ └── vector_relational.h
- │ ├── trigonometric.hpp
- │ ├── vec2.hpp
- │ ├── vec3.hpp
- │ ├── vec4.hpp
- │ └── vector_relational.hpp
- └── lib
- └── cmake
- └── glm
- ├── glmConfig.cmake
- └── glmConfigVersion.cmake
说明:这里要注意,使用glm数学库不用加载和链接库,只需要需要引用hpp文件即可。引用方式具体如下所示,方便很多:
- #include
// glm::vec3 - #include
// glm::vec4 - #include
// glm::mat4 - #include
// glm::translate, glm::rotate, glm::scale - #include
// glm::perspective - #include
// glm::pi -
- glm::mat4 camera(float Translate, glm::vec2 const& Rotate)
- {
- glm::mat4 Projection = glm::perspective(glm::pi<float>() * 0.25f, 4.0f / 3.0f, 0.1f, 100.f);
- glm::mat4 View = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -Translate));
- View = glm::rotate(View, Rotate.y, glm::vec3(-1.0f, 0.0f, 0.0f));
- View = glm::rotate(View, Rotate.x, glm::vec3(0.0f, 1.0f, 0.0f));
- glm::mat4 Model = glm::scale(glm::mat4(1.0f), glm::vec3(0.5f));
- return Projection * View * Model;
- }
因为是用aarch64交叉编译,需要提前配置环境,安装如下软件:
- sudo apt install binutils-aarch64-linux-gnu-dbg binutils-aarch64-linux-gnu cpp-aarch64-linux-gnu \
- g++-10-aarch64-linux-gnu g++-9-aarch64-linux-gnu g++-aarch64-linux-gnu g++ \
- gcc-10-aarch64-linux-gnu-base gcc-9-aarch64-linux-gnu-base gcc-aarch64-linux-gnu \
- pkg-config-aarch64-linux-gnu qemu-efi-aarch64 gcc arch-test
对于glm的交叉编译就简单很多了,只需要执行aarch64交叉编译相关命令,如下:
- $mkdir aarch64build
- $cd aarch64build
- $CC=aarch64-linux-gnu-gcc CXX=aarch64-linux-gnu-g++ cmake ..
- $make
- $make DESTDIR=$PWD/out_aarch64 install
最后生成内容与ubuntu PC端内容相同。