1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2021 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.v._11 = 1.0f;
35 m.v._22 = 1.0f;
36 m.v._33 = 1.0f;
37 m.v._44 = 1.0f;
38 return m;
39}
40
41Float4X4 MatrixMultiply(Float4X4 M1, Float4X4 M2)
42{
43 Float4X4 m;
44 m.v._11 = M1.v._11 * M2.v._11 + M1.v._12 * M2.v._21 + M1.v._13 * M2.v._31 + M1.v._14 * M2.v._41;
45 m.v._12 = M1.v._11 * M2.v._12 + M1.v._12 * M2.v._22 + M1.v._13 * M2.v._32 + M1.v._14 * M2.v._42;
46 m.v._13 = M1.v._11 * M2.v._13 + M1.v._12 * M2.v._23 + M1.v._13 * M2.v._33 + M1.v._14 * M2.v._43;
47 m.v._14 = M1.v._11 * M2.v._14 + M1.v._12 * M2.v._24 + M1.v._13 * M2.v._34 + M1.v._14 * M2.v._44;
48 m.v._21 = M1.v._21 * M2.v._11 + M1.v._22 * M2.v._21 + M1.v._23 * M2.v._31 + M1.v._24 * M2.v._41;
49 m.v._22 = M1.v._21 * M2.v._12 + M1.v._22 * M2.v._22 + M1.v._23 * M2.v._32 + M1.v._24 * M2.v._42;
50 m.v._23 = M1.v._21 * M2.v._13 + M1.v._22 * M2.v._23 + M1.v._23 * M2.v._33 + M1.v._24 * M2.v._43;
51 m.v._24 = M1.v._21 * M2.v._14 + M1.v._22 * M2.v._24 + M1.v._23 * M2.v._34 + M1.v._24 * M2.v._44;
52 m.v._31 = M1.v._31 * M2.v._11 + M1.v._32 * M2.v._21 + M1.v._33 * M2.v._31 + M1.v._34 * M2.v._41;
53 m.v._32 = M1.v._31 * M2.v._12 + M1.v._32 * M2.v._22 + M1.v._33 * M2.v._32 + M1.v._34 * M2.v._42;
54 m.v._33 = M1.v._31 * M2.v._13 + M1.v._32 * M2.v._23 + M1.v._33 * M2.v._33 + M1.v._34 * M2.v._43;
55 m.v._34 = M1.v._31 * M2.v._14 + M1.v._32 * M2.v._24 + M1.v._33 * M2.v._34 + M1.v._34 * M2.v._44;
56 m.v._41 = M1.v._41 * M2.v._11 + M1.v._42 * M2.v._21 + M1.v._43 * M2.v._31 + M1.v._44 * M2.v._41;
57 m.v._42 = M1.v._41 * M2.v._12 + M1.v._42 * M2.v._22 + M1.v._43 * M2.v._32 + M1.v._44 * M2.v._42;
58 m.v._43 = M1.v._41 * M2.v._13 + M1.v._42 * M2.v._23 + M1.v._43 * M2.v._33 + M1.v._44 * M2.v._43;
59 m.v._44 = M1.v._41 * M2.v._14 + M1.v._42 * M2.v._24 + M1.v._43 * M2.v._34 + M1.v._44 * M2.v._44;
60 return m;
61}
62
63Float4X4 MatrixScaling(float x, float y, float z)
64{
65 Float4X4 m;
66 SDL_zero(m);
67 m.v._11 = x;
68 m.v._22 = y;
69 m.v._33 = z;
70 m.v._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.v._11 = 1.0f;
79 m.v._22 = 1.0f;
80 m.v._33 = 1.0f;
81 m.v._44 = 1.0f;
82 m.v._41 = x;
83 m.v._42 = y;
84 m.v._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.v._11 = 1.0f;
95 m.v._22 = cosR;
96 m.v._23 = sinR;
97 m.v._32 = -sinR;
98 m.v._33 = cosR;
99 m.v._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.v._11 = cosR;
110 m.v._13 = -sinR;
111 m.v._22 = 1.0f;
112 m.v._31 = sinR;
113 m.v._33 = cosR;
114 m.v._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.v._11 = cosR;
125 m.v._12 = sinR;
126 m.v._21 = -sinR;
127 m.v._22 = cosR;
128 m.v._33 = 1.0f;
129 m.v._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: */
137