CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Common/Math/lin/matrix4x4.cpp
Views: 1401
#include "Common/Math/lin/matrix4x4.h"12#include <cstdio>34#include "Common/Math/lin/vec3.h"5#include "Common/Math/fast/fast_matrix.h"67#ifdef _WIN328#undef far9#undef near10#endif1112// See http://code.google.com/p/oolongengine/source/browse/trunk/Oolong+Engine2/Math/neonmath/neon_matrix_impl.cpp?spec=svn143&r=143 when we need speed13// no wait. http://code.google.com/p/math-neon/1415namespace Lin {1617Matrix4x4 Matrix4x4::transpose() const18{19Matrix4x4 out;20out.xx = xx;out.xy = yx;out.xz = zx;out.xw = wx;21out.yx = xy;out.yy = yy;out.yz = zy;out.yw = wy;22out.zx = xz;out.zy = yz;out.zz = zz;out.zw = wz;23out.wx = xw;out.wy = yw;out.wz = zw;out.ww = ww;24return out;25}2627Matrix4x4 Matrix4x4::operator * (const Matrix4x4 &other) const28{29Matrix4x4 temp;30fast_matrix_mul_4x4(temp.m, other.m, this->m);31return temp;32}3334void Matrix4x4::setViewFrame(const Vec3 &pos, const Vec3 &vRight, const Vec3 &vView, const Vec3 &vUp) {35xx = vRight.x; xy = vUp.x; xz=vView.x; xw = 0.0f;36yx = vRight.y; yy = vUp.y; yz=vView.y; yw = 0.0f;37zx = vRight.z; zy = vUp.z; zz=vView.z; zw = 0.0f;3839wx = -pos * vRight;40wy = -pos * vUp;41wz = -pos * vView;42ww = 1.0f;43}4445void Matrix4x4::setOrtho(float left, float right, float bottom, float top, float near, float far) {46empty();47xx = 2.0f / (right - left);48yy = 2.0f / (top - bottom);49zz = 2.0f / (far - near);50wx = -(right + left) / (right - left);51wy = -(top + bottom) / (top - bottom);52wz = -(far + near) / (far - near);53ww = 1.0f;54}5556void Matrix4x4::setOrthoD3D(float left, float right, float bottom, float top, float near, float far) {57empty();58xx = 2.0f / (right - left);59yy = 2.0f / (top - bottom);60zz = 1.0f / (far - near);61wx = -(right + left) / (right - left);62wy = -(top + bottom) / (top - bottom);63wz = -near / (far - near);64ww = 1.0f;65}6667void Matrix4x4::setOrthoVulkan(float left, float right, float top, float bottom, float near, float far) {68empty();69xx = 2.0f / (right - left);70yy = 2.0f / (bottom - top);71zz = 1.0f / (far - near);72wx = -(right + left) / (right - left);73wy = -(top + bottom) / (bottom - top);74wz = -near / (far - near);75ww = 1.0f;76}7778void Matrix4x4::toText(char *buffer, int len) const {79snprintf(buffer, len, "%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n%f %f %f %f\n",80xx,xy,xz,xw,81yx,yy,yz,yw,82zx,zy,zz,zw,83wx,wy,wz,ww);84buffer[len - 1] = '\0';85}8687void Matrix4x4::print() const {88char buffer[256];89toText(buffer, 256);90puts(buffer);91}9293}949596