有了坐标系的概念,还需要一整套相对应的数学系统来描述和操作坐标系,例如需要移动、旋转以及缩放坐标系等,这涉及到向量、矩阵、四元数等数学概念。

由于向量、矩阵以及四元数这些操作具有很强的通用性,可以使用别人造好的轮子,这样可以更加关注如何使用。

因此笔者在github上比较了glMatrix和TSM(纯TypeScript实现,更加符合本书风格)这两个WebGL数学库后,决定选择TSM作为本书Demo演示使用的数学库。

TSM数学库是TypeScript Vector And Matrix Math Library (TypeScript向量与矩阵数学库)的缩写,包含vec2、vec3、vec4、mat2、mat3、mat4以及quat这七个常用的3D数学操作类。你可以通过https://github.com/matthiasferch/tsm 网址获取到TSM数学库。

由于TSM数学库使用了较为宽松的协议,本书所有数学相关的操作都是建立在TSM数学库上的。TSM数学库的版权信息如下所示:

Copyright (c) 2012, 2018 Matthias FerchProject homepage: https://github.com/matthiasferch/tsmThis software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:1.The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.2.Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.3.This notice may not be removed or altered from any source distribution.