<% axis_names_3 = ["x", "y", "z"] axis_names_4 = ["x", "y", "z", "w"] value_types = ["d", "f", "i", "x", "u"] def convert(value, type_1, type_2) if type_1 == "x" then if type_2 == "d" then return "xtod(#{value})" end if type_2 == "f" then return "xtof(#{value})" end if type_2 == "i" || type_2 == "u" then return "#{value} >> 16" end end if type_2 == "x" then if type_1 == "d" then return "dtox(#{value})" end if type_1 == "f" then return "ftox(#{value})" end if type_1 == "i" || type_1 == "u" then return "#{value} << 16" end end return value end -%> /* Copyright (c) 2015 Alex Diener This 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. Alex Diener alex@ludobloom.com */ #ifndef __VectorConversions_H__ #define __VectorConversions_H__ #ifdef __cplusplus extern "C" { #endif <% 2.upto(4) do |axis_count| -%> <% value_types.each do |type_suffix| -%> <% value_types.each do |type_suffix_2| -%> <% next if type_suffix == type_suffix_2 -%> #define Vector<%= axis_count %><%= type_suffix %>_toVector<%= axis_count %><%= type_suffix_2 %>(vector) VECTOR<%= axis_count %><%= type_suffix_2 %>(<%= convert("vector.x", type_suffix, type_suffix_2) %><% 1.upto(axis_count - 1) do |axis| %>, <%= convert("vector.#{axis_names_4[axis]}", type_suffix, type_suffix_2) %><% end %>) <% end %> <% end -%> <% end -%> <% value_types.each do |type_suffix| -%> #define Vector2<%= type_suffix %>_yx(vector) VECTOR2<%= type_suffix %>(vector.y, vector.x) <% end -%> <% value_types.each do |type_suffix| -%> <% axis_names_3.permutation do |axes| -%> <% next if axes[0] == "x" && axes[1] == "y" && axes[2] == "z" -%> #define Vector3<%= type_suffix %>_<%= axes[0] + axes[1] + axes[2] %>(vector) VECTOR3<%= type_suffix %>(vector.<%= axes[0] %>, vector.<%= axes[1] %>, vector.<%= axes[2] %>) <% end %> <% end -%> <% value_types.each do |type_suffix| -%> <% axis_names_4.permutation do |axes| -%> <% next if axes[0] == "x" && axes[1] == "y" && axes[2] == "z" && axes[3] == "w" -%> #define Vector4<%= type_suffix %>_<%= axes[0] + axes[1] + axes[2] + axes[3] %>(vector) VECTOR4<%= type_suffix %>(vector.<%= axes[0] %>, vector.<%= axes[1] %>, vector.<%= axes[2] %>, vector.<%= axes[3] %>) <% end %> <% end -%> <% value_types.each do |type_suffix| -%> <% axis_names_3.permutation do |axes| -%> #define Vector3<%= type_suffix %>_<%= axes[0] + axes[1] %>(vector) VECTOR2<%= type_suffix %>(vector.<%= axes[0] %>, vector.<%= axes[1] %>) <% end %> <% end -%> <% value_types.each do |type_suffix| -%> <% axis_names_4.permutation do |axes| -%> #define Vector4<%= type_suffix %>_<%= axes[0] + axes[1] + axes[2] %>(vector) VECTOR3<%= type_suffix %>(vector.<%= axes[0] %>, vector.<%= axes[1] %>, vector.<%= axes[2] %>) <% end %> <% end -%> <% value_types.each do |type_suffix| -%> <% axis_names_4.permutation.to_a.collect {|entry| entry[0..1]}.uniq.each do |axes| -%> #define Vector4<%= type_suffix %>_<%= axes[0] + axes[1] %>(vector) VECTOR2<%= type_suffix %>(vector.<%= axes[0] %>, vector.<%= axes[1] %>) <% end %> <% end -%> #define Quaternionf_toQuaternionx(quaternion) QUATERNIONx(ftox(quaternion.x), ftox(quaternion.y), ftox(quaternion.z), ftox(quaternion.w)) #define Quaternionx_toQuaternionf(quaternion) QUATERNIONf(xtof(quaternion.x), xtof(quaternion.y), xtof(quaternion.z), xtof(quaternion.w)) #define Matrix4x4f_toMatrix4x4x(matrix) MATRIX4x4x(ftox(matrix.m[0]), ftox(matrix.m[4]), ftox(matrix.m[8]), ftox(matrix.m[12]), \ ftox(matrix.m[1]), ftox(matrix.m[5]), ftox(matrix.m[9]), ftox(matrix.m[13]), \ ftox(matrix.m[2]), ftox(matrix.m[6]), ftox(matrix.m[10]), ftox(matrix.m[14]), \ ftox(matrix.m[3]), ftox(matrix.m[7]), ftox(matrix.m[11]), ftox(matrix.m[15])) #define Matrix4x4x_toMatrix4x4f(matrix) MATRIX4x4f(xtof(matrix.m[0]), xtof(matrix.m[4]), xtof(matrix.m[8]), xtof(matrix.m[12]), \ xtof(matrix.m[1]), xtof(matrix.m[5]), xtof(matrix.m[9]), xtof(matrix.m[13]), \ xtof(matrix.m[2]), xtof(matrix.m[6]), xtof(matrix.m[10]), xtof(matrix.m[14]), \ xtof(matrix.m[3]), xtof(matrix.m[7]), xtof(matrix.m[11]), xtof(matrix.m[15])) #ifdef __cplusplus } #endif #endif