SDL_d3dmath.c (3974B)
1/* 2 Simple DirectMedia Layer 3 Copyright (C) 1997-2014 Sam Lantinga <slouken@libsdl.org> 4 5 This software is provided 'as-is', without any express or implied 6 warranty. In no event will the authors be held liable for any damages 7 arising from the use of this software. 8 9 Permission is granted to anyone to use this software for any purpose, 10 including commercial applications, and to alter it and redistribute it 11 freely, subject to the following restrictions: 12 13 1. The origin of this software must not be misrepresented; you must not 14 claim that you wrote the original software. If you use this software 15 in a product, an acknowledgment in the product documentation would be 16 appreciated but is not required. 17 2. Altered source versions must be plainly marked as such, and must not be 18 misrepresented as being the original software. 19 3. This notice may not be removed or altered from any source distribution. 20*/ 21#include "../SDL_internal.h" 22 23#if (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11) && !SDL_RENDER_DISABLED 24#include "SDL_stdinc.h" 25 26#include "SDL_d3dmath.h" 27 28/* Direct3D matrix math functions */ 29 30Float4X4 MatrixIdentity() 31{ 32 Float4X4 m; 33 SDL_zero(m); 34 m._11 = 1.0f; 35 m._22 = 1.0f; 36 m._33 = 1.0f; 37 m._44 = 1.0f; 38 return m; 39} 40 41Float4X4 MatrixMultiply(Float4X4 M1, Float4X4 M2) 42{ 43 Float4X4 m; 44 m._11 = M1._11 * M2._11 + M1._12 * M2._21 + M1._13 * M2._31 + M1._14 * M2._41; 45 m._12 = M1._11 * M2._12 + M1._12 * M2._22 + M1._13 * M2._32 + M1._14 * M2._42; 46 m._13 = M1._11 * M2._13 + M1._12 * M2._23 + M1._13 * M2._33 + M1._14 * M2._43; 47 m._14 = M1._11 * M2._14 + M1._12 * M2._24 + M1._13 * M2._34 + M1._14 * M2._44; 48 m._21 = M1._21 * M2._11 + M1._22 * M2._21 + M1._23 * M2._31 + M1._24 * M2._41; 49 m._22 = M1._21 * M2._12 + M1._22 * M2._22 + M1._23 * M2._32 + M1._24 * M2._42; 50 m._23 = M1._21 * M2._13 + M1._22 * M2._23 + M1._23 * M2._33 + M1._24 * M2._43; 51 m._24 = M1._21 * M2._14 + M1._22 * M2._24 + M1._23 * M2._34 + M1._24 * M2._44; 52 m._31 = M1._31 * M2._11 + M1._32 * M2._21 + M1._33 * M2._31 + M1._34 * M2._41; 53 m._32 = M1._31 * M2._12 + M1._32 * M2._22 + M1._33 * M2._32 + M1._34 * M2._42; 54 m._33 = M1._31 * M2._13 + M1._32 * M2._23 + M1._33 * M2._33 + M1._34 * M2._43; 55 m._34 = M1._31 * M2._14 + M1._32 * M2._24 + M1._33 * M2._34 + M1._34 * M2._44; 56 m._41 = M1._41 * M2._11 + M1._42 * M2._21 + M1._43 * M2._31 + M1._44 * M2._41; 57 m._42 = M1._41 * M2._12 + M1._42 * M2._22 + M1._43 * M2._32 + M1._44 * M2._42; 58 m._43 = M1._41 * M2._13 + M1._42 * M2._23 + M1._43 * M2._33 + M1._44 * M2._43; 59 m._44 = M1._41 * M2._14 + M1._42 * M2._24 + M1._43 * M2._34 + M1._44 * M2._44; 60 return m; 61} 62 63Float4X4 MatrixScaling(float x, float y, float z) 64{ 65 Float4X4 m; 66 SDL_zero(m); 67 m._11 = x; 68 m._22 = y; 69 m._33 = z; 70 m._44 = 1.0f; 71 return m; 72} 73 74Float4X4 MatrixTranslation(float x, float y, float z) 75{ 76 Float4X4 m; 77 SDL_zero(m); 78 m._11 = 1.0f; 79 m._22 = 1.0f; 80 m._33 = 1.0f; 81 m._44 = 1.0f; 82 m._41 = x; 83 m._42 = y; 84 m._43 = z; 85 return m; 86} 87 88Float4X4 MatrixRotationX(float r) 89{ 90 float sinR = SDL_sinf(r); 91 float cosR = SDL_cosf(r); 92 Float4X4 m; 93 SDL_zero(m); 94 m._11 = 1.0f; 95 m._22 = cosR; 96 m._23 = sinR; 97 m._32 = -sinR; 98 m._33 = cosR; 99 m._44 = 1.0f; 100 return m; 101} 102 103Float4X4 MatrixRotationY(float r) 104{ 105 float sinR = SDL_sinf(r); 106 float cosR = SDL_cosf(r); 107 Float4X4 m; 108 SDL_zero(m); 109 m._11 = cosR; 110 m._13 = -sinR; 111 m._22 = 1.0f; 112 m._31 = sinR; 113 m._33 = cosR; 114 m._44 = 1.0f; 115 return m; 116} 117 118Float4X4 MatrixRotationZ(float r) 119{ 120 float sinR = SDL_sinf(r); 121 float cosR = SDL_cosf(r); 122 Float4X4 m; 123 SDL_zero(m); 124 m._11 = cosR; 125 m._12 = sinR; 126 m._21 = -sinR; 127 m._22 = cosR; 128 m._33 = 1.0f; 129 m._44 = 1.0f; 130 return m; 131 132} 133 134#endif /* (SDL_VIDEO_RENDER_D3D || SDL_VIDEO_RENDER_D3D11) && !SDL_RENDER_DISABLED */ 135 136/* vi: set ts=4 sw=4 expandtab: */