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