diff options
Diffstat (limited to 'src/platformspecific/macos')
18 files changed, 2362 insertions, 0 deletions
diff --git a/src/platformspecific/macos/assets/courier+lucida_256.abc b/src/platformspecific/macos/assets/courier+lucida_256.abc Binary files differnew file mode 100644 index 0000000..f7e3c2f --- /dev/null +++ b/src/platformspecific/macos/assets/courier+lucida_256.abc diff --git a/src/platformspecific/macos/assets/courier+lucida_256.dds b/src/platformspecific/macos/assets/courier+lucida_256.dds Binary files differnew file mode 100644 index 0000000..5bde760 --- /dev/null +++ b/src/platformspecific/macos/assets/courier+lucida_256.dds diff --git a/src/platformspecific/macos/assets/courier+lucida_512.abc b/src/platformspecific/macos/assets/courier+lucida_512.abc Binary files differnew file mode 100644 index 0000000..2ff7875 --- /dev/null +++ b/src/platformspecific/macos/assets/courier+lucida_512.abc diff --git a/src/platformspecific/macos/assets/courier+lucida_512.dds b/src/platformspecific/macos/assets/courier+lucida_512.dds Binary files differnew file mode 100644 index 0000000..f9e76d9 --- /dev/null +++ b/src/platformspecific/macos/assets/courier+lucida_512.dds diff --git a/src/platformspecific/macos/assets/font.frag b/src/platformspecific/macos/assets/font.frag new file mode 100644 index 0000000..e4673cf --- /dev/null +++ b/src/platformspecific/macos/assets/font.frag @@ -0,0 +1,39 @@ +/**************************************************************************** +** +** Copyright (C) 2007-2008 NVIDIA Corporation. +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt 3D Studio. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +uniform sampler2D fontTex; + +varying lowp vec4 col_var; +varying lowp vec2 tex_var; + +void main() +{ + gl_FragColor = texture2D(fontTex, tex_var).a * col_var; +} + diff --git a/src/platformspecific/macos/assets/font.vert b/src/platformspecific/macos/assets/font.vert new file mode 100644 index 0000000..9f307a2 --- /dev/null +++ b/src/platformspecific/macos/assets/font.vert @@ -0,0 +1,49 @@ +/**************************************************************************** +** +** Copyright (C) 2007-2008 NVIDIA Corporation. +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt 3D Studio. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +// this is set from higher level. think of it as the upper model matrix +uniform mat4 pixelToClipMat; + +uniform vec4 col_uni; + +attribute vec2 pos_attr; +attribute vec2 tex_attr; +attribute vec4 col_attr; + +varying vec4 col_var; +varying vec2 tex_var; + +void main() +{ + // account for translation and rotation of the primitive into [-1,1] spatial default. + gl_Position = pixelToClipMat * vec4(pos_attr.x, pos_attr.y, 0, 1); + + col_var = col_attr * col_uni; + tex_var = tex_attr; +} diff --git a/src/platformspecific/macos/libs/nv_color.h b/src/platformspecific/macos/libs/nv_color.h new file mode 100644 index 0000000..b934752 --- /dev/null +++ b/src/platformspecific/macos/libs/nv_color.h @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2007-2008 NVIDIA Corporation. +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt 3D Studio. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef _QT3DS_COLOR_H +#define _QT3DS_COLOR_H + +/** @file nv_color.h + Simple abstraction for RGBA colors as parameters to various libraries/functions. +*/ + +/** Base type for a single color channel (8-bit unsigned). */ +typedef unsigned char NvPCColor8; + +//#define NV_COLOR_BREAKOLD +#ifdef NV_COLOR_BREAKOLD // uses a struct to break backwards-compat and accidental uses + +typedef struct +{ + NvPCColor8 r; + NvPCColor8 g; + NvPCColor8 b; + NvPCColor8 a; +} NvPackedColor; + +static const NvPackedColor gnvpcwhite = { 255, 255, 255, 255 }; +static const NvPackedColor gnvpcblack = { 0, 0, 0, 255 }; + +#define NV_PACKED_COLOR(r, g, b, a) \ + { \ + (NvPCColor8)(r), (NvPCColor8)(g), (NvPCColor8)(b), (NvPCColor8)(a) \ + } + +#define NV_PC_PREDEF_WHITE gnvpcwhite +#define NV_PC_PREDEF_BLACK gnvpcblack + +#define NV_PC_RED(c) (c.r) +#define NV_PC_GREEN(c) (c.g) +#define NV_PC_BLUE(c) (c.b) +#define NV_PC_ALPHA(c) (c.a) + +#define NV_PC_PACK_UINT(c) (*(unsigned int *)(&(c))) + +#define NV_PC_EQUAL(x, y) ((x).r == (y).r && (x).g == (y).g && (x).b == (y).b && (x).a == (y).a) + +#else /* code that doesn't break old pass-as-uint stuff */ + +/** Main type declaration for a packed 4-color construct. */ +typedef unsigned int NvPackedColor; + +/** A macro to build a packed color, passing in RGBA as four 8-bit integer values. */ +#define NV_PACKED_COLOR(r, g, b, a) \ + ((NvPackedColor)(((((int)(a)) & 0xFF) << 24) | ((((int)(b)) & 0xFF) << 16) \ + | ((((int)(g)) & 0xFF) << 8) | ((((int)(r)) & 0xFF)))) + +/** A predefined constant for WHITE. */ +#define NV_PC_PREDEF_WHITE NV_PACKED_COLOR(0xFF, 0xFF, 0xFF, 0xFF) +/** A predefined constant for BLACK. */ +#define NV_PC_PREDEF_BLACK NV_PACKED_COLOR(0x00, 0x00, 0x00, 0xFF) + +/** A macro for 'extracting' the red value from an NvPackedColor. */ +#define NV_PC_RED(c) ((c >> 0) & 0xff) +/** A macro for 'extracting' the green value from an NvPackedColor. */ +#define NV_PC_GREEN(c) ((c >> 8) & 0xff) +/** A macro for 'extracting' the blue value from an NvPackedColor. */ +#define NV_PC_BLUE(c) ((c >> 16) & 0xff) +/** A macro for 'extracting' the alpha value from an NvPackedColor. */ +#define NV_PC_ALPHA(c) ((c >> 24) & 0xff) + +/** A macro requesting the packed color repacked into a 32-bit unsigned int. + This is a no-op for the color-as-uint approach. +*/ +#define NV_PC_PACK_UINT(c) (c) +/** A macro for testing the equality of two NvPackedColors. */ +#define NV_PC_EQUAL(x, y) (x == y) +#endif + +/** A macro for mapping a single packed color channel into its floating point [0,1] rep. */ +#define NV_PC_TO_FLOAT(c) (c / 255.0f) + +#endif /*_QT3DS_COLOR_H*/ diff --git a/src/platformspecific/macos/libs/nv_debug.h b/src/platformspecific/macos/libs/nv_debug.h new file mode 100644 index 0000000..2559dd6 --- /dev/null +++ b/src/platformspecific/macos/libs/nv_debug.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2009-2011 NVIDIA Corporation. +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt 3D Studio. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef __INCLUDED_QT3DS_DEBUG_H +#define __INCLUDED_QT3DS_DEBUG_H + +#define CT_ASSERT(tag, cond) enum { COMPILE_TIME_ASSERT__##tag = 1 / (cond) } + +#define dimof(x) (sizeof(x) / sizeof(x[0])) +#include <android/log.h> + +#define DBG_DETAILED 0 + +#if 0 + + // the detailed prefix can be customised by setting DBG_DETAILED_PREFIX. See + // below as a reference. + // NOTE: fmt is the desired format string and must be in the prefix. + //#ifndef DBG_DETAILED_PREFIX + // #define DBG_DETAILED_PREFIX "%s, %s, line %d: " fmt, __FILE__, __FUNCTION__, __LINE__, + //#endif + //#define DEBUG_D_(fmt, args...) + //#define DEBUG_D(fmt, args...) __android_log_print(ANDROID_LOG_DEBUG, MODULE, (DBG_DETAILED_PREFIX) ## args) + +#else + +#ifdef STRINGIFY +#pragma push_macro("STRINGIFY") +#undef STRINGIFY +#define STRINGIFYPUSHED_____ +#endif +#define STRINGIFY(x) #x + +// debug macro, includes file name function name and line number +#define TO(x) typeof(x) +#define DEBUG_D_(file, line, fmt, args...) \ + __android_log_print(ANDROID_LOG_DEBUG, MODULE, file ", %s, line(" STRINGIFY(line) "): " fmt, \ + __FUNCTION__, ##args) +#define DEBUG_D(fmt, args...) DEBUG_D_(__FILE__, __LINE__, fmt, ##args) + +#ifdef STRINGIFYPUSHED_____ +#undef STRINGIFYPUSHED_____ +#pragma pop_macro("STRINGIFY") +#endif + +#endif + +// basic debug macro +#define DEBUG_(fmt, args...) (__android_log_print(ANDROID_LOG_DEBUG, MODULE, fmt, ##args)) + +// Debug macro that can be switched to spew a file name, +// function and line number using DEBUG_DETAILED +#if DBG_DETAILED == 1 +#define DEBUG(fmt, args...) DEBUG_D(fmt, ##args) +#else +#define DEBUG(fmt, args...) __android_log_print(ANDROID_LOG_DEBUG, MODULE, fmt, ##args) +#endif + +#endif diff --git a/src/platformspecific/macos/libs/nv_global.h b/src/platformspecific/macos/libs/nv_global.h new file mode 100644 index 0000000..9d23d45 --- /dev/null +++ b/src/platformspecific/macos/libs/nv_global.h @@ -0,0 +1,36 @@ +/**************************************************************************** +** +** Copyright (C) 2009-2011 NVIDIA Corporation. +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt 3D Studio. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef __INCLUDED_QT3DS_GLOBAL_H +#define __INCLUDED_QT3DS_GLOBAL_H + +#include "nv_types.h" + +#endif diff --git a/src/platformspecific/macos/libs/nv_math/NvVec.h b/src/platformspecific/macos/libs/nv_math/NvVec.h new file mode 100644 index 0000000..4e5b09c --- /dev/null +++ b/src/platformspecific/macos/libs/nv_math/NvVec.h @@ -0,0 +1,316 @@ +/**************************************************************************** +** +** Copyright (C) 2009-2011 NVIDIA Corporation. +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt 3D Studio. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef INCLUDED_QT3DS_MATH_CPP_VEC_H +#define INCLUDED_QT3DS_MATH_CPP_VEC_H + +#include "misc.h" + +struct _NvVec3 +{ + union { + struct + { + float x, y, z; + }; + float v[3]; + }; +}; + +struct NvVec3 : public _NvVec3 +{ + NvVec3() { zero(); } + + NvVec3(float x, float y, float z) + { + v[0] = x; + v[1] = y; + v[2] = z; + } + + NvVec3(NvVec3 const &that) + { + v[0] = that.v[0]; + v[1] = that.v[1]; + v[2] = that.v[2]; + } + + inline void zero() + { + v[0] = 0.0f; + v[1] = 0.0f; + v[2] = 0.0f; + } + + inline float &operator[](int i) + { + assert((i < 3) && (i >= 0)); + return v[i]; + } + + inline float const &operator[](int i) const + { + assert((i < 3) && (i >= 0)); + return v[i]; + } + + NvVec3 &operator+=(NvVec3 const &that) + { + v[0] += that.v[0]; + v[1] += that.v[1]; + v[2] += that.v[2]; + return *this; + } + + NvVec3 &operator-=(NvVec3 const &that) + { + v[0] -= that.v[0]; + v[1] -= that.v[1]; + v[2] -= that.v[2]; + return *this; + } + + NvVec3 &operator*=(float s) + { + v[0] *= s; + v[1] *= s; + v[2] *= s; + return *this; + } + + NvVec3 &operator/=(float s) + { + v[0] /= s; + v[1] /= s; + v[2] /= s; + return *this; + } +}; + +inline float dot(NvVec3 const &a, NvVec3 const &b) +{ + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; +} + +inline NvVec3 operator+(NvVec3 const &a, NvVec3 const &b) +{ + + return NvVec3(a.v[0] + b.v[0], a.v[1] + b.v[1], a.v[2] + b.v[2]); +} + +inline NvVec3 operator-(NvVec3 const &a, NvVec3 const &b) +{ + + return NvVec3(a.v[0] - b.v[0], a.v[1] - b.v[1], a.v[2] - b.v[2]); +} + +inline NvVec3 operator-(NvVec3 const &a) +{ + + return NvVec3(-a.v[0], -a.v[1], -a.v[2]); +} + +inline NvVec3 operator*(NvVec3 const &a, float s) +{ + + return NvVec3(a.v[0] * s, a.v[1] * s, a.v[2] * s); +} + +inline NvVec3 operator*(float s, NvVec3 const &a) +{ + + return NvVec3(s * a.v[0], s * a.v[1], s * a.v[2]); +} + +inline NvVec3 operator/(NvVec3 const &a, float s) +{ + + return NvVec3(a.v[0] / s, a.v[1] / s, a.v[2] / s); +} + +inline float magnitude(NvVec3 const &v) +{ + return sqrtf(dot(v, v)); +} + +inline NvVec3 normalize(NvVec3 const &v) +{ + float l = magnitude(v); + return NvVec3(v[0] / l, v[1] / l, v[2] / l); +} + +inline NvVec3 cross(NvVec3 const &a, NvVec3 const &b) +{ + + return NvVec3(a.v[1] * b.v[2] - a.v[2] * b.v[1], a.v[2] * b.v[0] - a.v[0] * b.v[2], + a.v[0] * b.v[1] - a.v[1] * b.v[0]); +} + +inline bool operator==(NvVec3 const &a, NvVec3 const &b) +{ + return (a.v[0] == b.v[0] && a.v[1] == b.v[1] && a.v[2] == b.v[2]); +} + +inline bool operator!=(NvVec3 const &a, NvVec3 const &b) +{ + return (a.v[0] != b.v[0] || a.v[1] != b.v[1] || a.v[2] != b.v[2]); +} + +struct NvVec2f +{ + union { + struct + { + float x, y; + float v[2]; + }; + }; + + NvVec2f() { zero(); } + + NvVec2f(float x, float y) + { + v[0] = x; + v[1] = y; + } + + NvVec2f(NvVec2f const &that) + { + v[0] = that.v[0]; + v[1] = that.v[1]; + } + + inline void zero() + { + v[0] = 0.0f; + v[1] = 0.0f; + } + + inline float &operator[](int i) + { + assert((i < 2) && (i >= 0)); + return v[i]; + } + + inline float const &operator[](int i) const + { + assert((i < 2) && (i >= 0)); + return v[i]; + } + + NvVec2f &operator+=(NvVec2f const &that) + { + v[0] += that.v[0]; + v[1] += that.v[1]; + return *this; + } + + NvVec2f &operator-=(NvVec2f const &that) + { + v[0] -= that.v[0]; + v[1] -= that.v[1]; + return *this; + } + + NvVec2f &operator*=(float s) + { + v[0] *= s; + v[1] *= s; + return *this; + } + + NvVec2f &operator/=(float s) + { + v[0] /= s; + v[1] /= s; + return *this; + } +}; + +inline float dot(NvVec2f const &a, NvVec2f const &b) +{ + + return a[0] * b[0] + a[1] * b[1]; +} + +inline NvVec2f operator+(NvVec2f const &a, NvVec2f const &b) +{ + + return NvVec2f(a.v[0] + b.v[0], a.v[1] + b.v[1]); +} + +inline NvVec2f operator-(NvVec2f const &a, NvVec2f const &b) +{ + + return NvVec2f(a.v[0] - b.v[0], a.v[1] - b.v[1]); +} + +inline NvVec2f operator-(NvVec2f const &a) +{ + + return NvVec2f(-a.v[0], -a.v[1]); +} + +inline NvVec2f operator*(NvVec2f const &a, float s) +{ + + return NvVec2f(a.v[0] * s, a.v[1] * s); +} + +inline NvVec2f operator*(float s, NvVec2f const &a) +{ + + return NvVec2f(s * a.v[0], s * a.v[1]); +} + +inline NvVec2f operator/(NvVec2f const &a, float s) +{ + + return NvVec2f(a.v[0] / s, a.v[1] / s); +} + +inline float magnitude(NvVec2f const &v) +{ + return sqrtf(dot(v, v)); +} + +inline NvVec2f normalize(NvVec2f const &v) +{ + float l = dot(v, v); + return NvVec2f(v[0] / l, v[1] / l); +} + +inline float cross(NvVec2f const &a, NvVec2f const &b) +{ + + return a.v[0] * b.v[1] - b.v[0] * a.v[1]; +} + +#endif diff --git a/src/platformspecific/macos/libs/nv_math/misc.h b/src/platformspecific/macos/libs/nv_math/misc.h new file mode 100644 index 0000000..983410f --- /dev/null +++ b/src/platformspecific/macos/libs/nv_math/misc.h @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** Copyright (C) 2009-2011 NVIDIA Corporation. +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt 3D Studio. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef INCLUDED_QT3DS_MATH_CPP_MISC_H +#define INCLUDED_QT3DS_MATH_CPP_MISC_H + +inline bool nvIsPowerOfTwo(unsigned int i) +{ + return (i & (i - 1)) == 0; +} + +inline float nvDegToRadf(float d) +{ + return d * 3.14159265358979323846f / 180.0f; +} + +inline float nvRadToDegf(float r) +{ + return r * 180.0f / 3.14159265358979323846f; +} + +/* + 'mod' differs from '%' in that it behaves correctly when either the + numerator or denominator is negative. +*/ + +inline int nvMod(int n, int d) +{ + int m = n % d; + return (((m < 0) && (d > 0)) || ((m > 0) && (d < 0))) ? (m + d) : m; +} + +inline int nvAbs(int n) +{ + if (n < 0) + return -n; + return n; +} + +inline int nvSign(int n) +{ + if (n > 0) + return 1; + if (n < 0) + return -1; + return 0; +} + +/* + This returns the smallest amplitude value x such that + nvMod(b + x, m) == a +*/ + +inline int nvDifMod(int a, int b, int m) +{ + + int x1 = a - b; + int x2 = (x1 > 0) ? x1 - m : x1 + m; + return (nvAbs(x1) < nvAbs(x2)) ? x1 : x2; +} + +inline float nvWrapf(float a, float min, float max) +{ + + assert(max > min); + + float d = max - min; + float s = a - min; + float q = s / d; + float m = q - floorf(q); + return m * d + min; +} + +inline float nvClampf(float a, float min, float max) +{ + return (a < min) ? min : ((a > max) ? max : a); +} + +inline int nvClampi(int i, int min, int max) +{ + return (i < min) ? min : ((i > max) ? max : i); +} + +inline float nvGaussian(float x, float s) +{ + float c = s * sqrtf(2.0f * 3.14159265358979323846f); + return expf(-(x * x) / (2.0f * s * s)) / c; +} + +inline float nvLerpf(float a, float b, float t) +{ + return a * (1.0f - t) + b * t; +} + +inline float nvEasef(float t) +{ + + float t_2 = t * t; + float t_3 = t_2 * t; + return 3.0f * t_2 - 2.0f * t_3; +} + +#endif diff --git a/src/platformspecific/macos/libs/nv_math/nv_math.cpp b/src/platformspecific/macos/libs/nv_math/nv_math.cpp new file mode 100644 index 0000000..b83cb39 --- /dev/null +++ b/src/platformspecific/macos/libs/nv_math/nv_math.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2009-2011 NVIDIA Corporation. +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt 3D Studio. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "nv_math.h" + +static const double a = 16807.0; +static const double m = 2147483647.0; + +static double nextSeed(double seed) +{ + double t = a * seed; + return t - m * (double)((int)(t / m)); +} + +GLfloat NvRandf() +{ + static double seed = 1.0; + seed = nextSeed(seed); + return (GLfloat)(seed * (1 / m)); +} + +GLfloat NvClockDiffInSecs(long long int newTime, long long int oldTime) +{ + // kdGetTimeUST is never supposed to decrease (i.e. that + // means it can't wrap, either. IIRC, it will wrap in + // 593 years). So we ignore that option... + + // Used for frame-to-frame diffs, this will fit in 32b + // as long as the times are < ~4.3s apart + long long int diffTime = newTime - oldTime; + + // Need to find a better way to do this. + // However, I believe we will be uSec precise (not run + // out of mantissa bits for uSecs) as long as the diff + // is < ~16s (1e-6 * (2^24)) + return ((GLfloat)diffTime) / 1.0e9f; +} diff --git a/src/platformspecific/macos/libs/nv_math/nv_math.h b/src/platformspecific/macos/libs/nv_math/nv_math.h new file mode 100644 index 0000000..e777e40 --- /dev/null +++ b/src/platformspecific/macos/libs/nv_math/nv_math.h @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2009-2011 NVIDIA Corporation. +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt 3D Studio. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef _QT3DS_MATH_H +#define _QT3DS_MATH_H + +#include <OpenGL/gl.h> + +GLfloat NvRandf(); + +/* These are the recommended "safer" ways to use GLfloat for time */ + +/* Returns the seconds between the two given times */ +GLfloat NvClockDiffInSecs(long long int newTime, long long int oldTime); + +#define QT3DS_MILISECS_TO_UST(ms) ((long long int)(ms)*1000000) + +#endif diff --git a/src/platformspecific/macos/libs/nv_math/nv_matrix.cpp b/src/platformspecific/macos/libs/nv_math/nv_matrix.cpp new file mode 100644 index 0000000..e208ac3 --- /dev/null +++ b/src/platformspecific/macos/libs/nv_math/nv_matrix.cpp @@ -0,0 +1,1030 @@ +/**************************************************************************** +** +** Copyright (C) 2009-2011 NVIDIA Corporation. +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt 3D Studio. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "nv_matrix.h" + +int NvDifferentMatsf(GLfloat a[4][4], const GLfloat b[4][4]) +{ + return ((&a[3][3] < &b[0][0]) || (&b[3][3] < &a[0][0])); +} + +void NvCopyMatf(GLfloat r[4][4], const GLfloat m[4][4]) +{ + r[0][0] = m[0][0]; + r[0][1] = m[0][1]; + r[0][2] = m[0][2]; + r[0][3] = m[0][3]; + + r[1][0] = m[1][0]; + r[1][1] = m[1][1]; + r[1][2] = m[1][2]; + r[1][3] = m[1][3]; + + r[2][0] = m[2][0]; + r[2][1] = m[2][1]; + r[2][2] = m[2][2]; + r[2][3] = m[2][3]; + + r[3][0] = m[3][0]; + r[3][1] = m[3][1]; + r[3][2] = m[3][2]; + r[3][3] = m[3][3]; +} + +void NvExtract3x3Matf(GLfloat r[3][3], const GLfloat m[4][4]) +{ + r[0][0] = m[0][0]; + r[0][1] = m[0][1]; + r[0][2] = m[0][2]; + + r[1][0] = m[1][0]; + r[1][1] = m[1][1]; + r[1][2] = m[1][2]; + + r[2][0] = m[2][0]; + r[2][1] = m[2][1]; + r[2][2] = m[2][2]; +} + +GLfloat NvVecLengthf(const GLfloat v[3]) +{ + return sqrtf(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); +} + +void NvNormalizeVecf(GLfloat r[3], const GLfloat v[3]) +{ + GLfloat const l = NvVecLengthf(v); + r[0] = v[0] / l; + r[1] = v[1] / l; + r[2] = v[2] / l; +} + +void NvAddVecf(GLfloat r[3], const GLfloat a[3], const GLfloat b[3]) +{ + r[0] = a[0] + b[0]; + r[1] = a[1] + b[1]; + r[2] = a[2] + b[2]; +} + +void NvSubVecf(GLfloat r[3], const GLfloat a[3], const GLfloat b[3]) +{ + r[0] = a[0] - b[0]; + r[1] = a[1] - b[1]; + r[2] = a[2] - b[2]; +} + +void NvCrossProductf(GLfloat r[3], const GLfloat a[3], const GLfloat b[3]) +{ + GLfloat t[3]; + + t[0] = a[1] * b[2] - a[2] * b[1]; + t[1] = a[2] * b[0] - a[0] * b[2]; + t[2] = a[0] * b[1] - a[1] * b[0]; + + r[0] = t[0]; + r[1] = t[1]; + r[2] = t[2]; +} + +void NvTransformPointf(GLfloat r[3], const GLfloat m[4][4], const GLfloat a[3]) +{ + GLfloat inv_w = 1.0f / (m[0][3] * a[0] + m[1][3] * a[1] + m[2][3] * a[2] + m[3][3]); + + r[0] = m[0][0] * a[0] + m[1][0] * a[1] + m[2][0] * a[2] + m[3][0] * inv_w; + r[1] = m[0][1] * a[0] + m[1][1] * a[1] + m[2][1] * a[2] + m[3][1] * inv_w; + r[2] = m[0][2] * a[0] + m[1][2] * a[1] + m[2][2] * a[2] + m[3][2] * inv_w; +} + +void NvTransformHomPointf(GLfloat r[4], const GLfloat m[4][4], const GLfloat a[4]) +{ + r[0] = m[0][0] * a[0] + m[1][0] * a[1] + m[2][0] * a[2] + m[3][0] * a[3]; + r[1] = m[0][1] * a[0] + m[1][1] * a[1] + m[2][1] * a[2] + m[3][1] * a[3]; + r[2] = m[0][2] * a[0] + m[1][2] * a[1] + m[2][2] * a[2] + m[3][2] * a[3]; + r[3] = m[0][3] * a[0] + m[1][3] * a[1] + m[2][3] * a[2] + m[3][3] * a[3]; +} + +void NvTransformVecf(GLfloat r[3], const GLfloat m[4][4], const GLfloat a[3]) +{ + r[0] = m[0][0] * a[0] + m[1][0] * a[1] + m[2][0] * a[2]; + r[1] = m[0][1] * a[0] + m[1][1] * a[1] + m[2][1] * a[2]; + r[2] = m[0][2] * a[0] + m[1][2] * a[1] + m[2][2] * a[2]; +} + +static void NvMultMat3x3f(GLfloat r[4][4], const GLfloat a[4][4], const GLfloat b[4][4]) +{ + assert(NvDifferentMatsf(r, a) && NvDifferentMatsf(r, b)); + + r[0][0] = a[0][0] * b[0][0] + a[1][0] * b[0][1] + a[2][0] * b[0][2]; + r[0][1] = a[0][1] * b[0][0] + a[1][1] * b[0][1] + a[2][1] * b[0][2]; + r[0][2] = a[0][2] * b[0][0] + a[1][2] * b[0][1] + a[2][2] * b[0][2]; + r[0][3] = 0.0f; + + r[1][0] = a[0][0] * b[1][0] + a[1][0] * b[1][1] + a[2][0] * b[1][2]; + r[1][1] = a[0][1] * b[1][0] + a[1][1] * b[1][1] + a[2][1] * b[1][2]; + r[1][2] = a[0][2] * b[1][0] + a[1][2] * b[1][1] + a[2][2] * b[1][2]; + r[1][3] = 0.0f; + + r[2][0] = a[0][0] * b[2][0] + a[1][0] * b[2][1] + a[2][0] * b[2][2]; + r[2][1] = a[0][1] * b[2][0] + a[1][1] * b[2][1] + a[2][1] * b[2][2]; + r[2][2] = a[0][2] * b[2][0] + a[1][2] * b[2][1] + a[2][2] * b[2][2]; + r[2][3] = 0.0f; + + r[3][0] = 0.0f; + r[3][1] = 0.0f; + r[3][2] = 0.0f; + r[3][3] = 1.0f; +} + +static void NvMultMat4x3f(GLfloat r[4][4], const GLfloat a[4][4], const GLfloat b[4][4]) +{ + assert(NvDifferentMatsf(r, a) && NvDifferentMatsf(r, b)); + + r[0][0] = a[0][0] * b[0][0] + a[1][0] * b[0][1] + a[2][0] * b[0][2]; + r[0][1] = a[0][1] * b[0][0] + a[1][1] * b[0][1] + a[2][1] * b[0][2]; + r[0][2] = a[0][2] * b[0][0] + a[1][2] * b[0][1] + a[2][2] * b[0][2]; + r[0][3] = 0.0f; + + r[1][0] = a[0][0] * b[1][0] + a[1][0] * b[1][1] + a[2][0] * b[1][2]; + r[1][1] = a[0][1] * b[1][0] + a[1][1] * b[1][1] + a[2][1] * b[1][2]; + r[1][2] = a[0][2] * b[1][0] + a[1][2] * b[1][1] + a[2][2] * b[1][2]; + r[1][3] = 0.0f; + + r[2][0] = a[0][0] * b[2][0] + a[1][0] * b[2][1] + a[2][0] * b[2][2]; + r[2][1] = a[0][1] * b[2][0] + a[1][1] * b[2][1] + a[2][1] * b[2][2]; + r[2][2] = a[0][2] * b[2][0] + a[1][2] * b[2][1] + a[2][2] * b[2][2]; + r[2][3] = 0.0f; + + r[3][0] = a[0][0] * b[3][0] + a[1][0] * b[3][1] + a[2][0] * b[3][2] + a[3][0]; + r[3][1] = a[0][1] * b[3][0] + a[1][1] * b[3][1] + a[2][1] * b[3][2] + a[3][1]; + r[3][2] = a[0][2] * b[3][0] + a[1][2] * b[3][1] + a[2][2] * b[3][2] + a[3][2]; + r[3][3] = 1.0f; +} + +static void NvMultMat4x4f(GLfloat r[4][4], const GLfloat a[4][4], const GLfloat b[4][4]) +{ + assert(NvDifferentMatsf(r, a) && NvDifferentMatsf(r, b)); + + r[0][0] = a[0][0] * b[0][0] + a[1][0] * b[0][1] + a[2][0] * b[0][2] + a[3][0] * b[0][3]; + r[0][1] = a[0][1] * b[0][0] + a[1][1] * b[0][1] + a[2][1] * b[0][2] + a[3][1] * b[0][3]; + r[0][2] = a[0][2] * b[0][0] + a[1][2] * b[0][1] + a[2][2] * b[0][2] + a[3][2] * b[0][3]; + r[0][3] = a[0][3] * b[0][0] + a[1][3] * b[0][1] + a[2][3] * b[0][2] + a[3][3] * b[0][3]; + + r[1][0] = a[0][0] * b[1][0] + a[1][0] * b[1][1] + a[2][0] * b[1][2] + a[3][0] * b[1][3]; + r[1][1] = a[0][1] * b[1][0] + a[1][1] * b[1][1] + a[2][1] * b[1][2] + a[3][1] * b[1][3]; + r[1][2] = a[0][2] * b[1][0] + a[1][2] * b[1][1] + a[2][2] * b[1][2] + a[3][2] * b[1][3]; + r[1][3] = a[0][3] * b[1][0] + a[1][3] * b[1][1] + a[2][3] * b[1][2] + a[3][3] * b[1][3]; + + r[2][0] = a[0][0] * b[2][0] + a[1][0] * b[2][1] + a[2][0] * b[2][2] + a[3][0] * b[2][3]; + r[2][1] = a[0][1] * b[2][0] + a[1][1] * b[2][1] + a[2][1] * b[2][2] + a[3][1] * b[2][3]; + r[2][2] = a[0][2] * b[2][0] + a[1][2] * b[2][1] + a[2][2] * b[2][2] + a[3][2] * b[2][3]; + r[2][3] = a[0][3] * b[2][0] + a[1][3] * b[2][1] + a[2][3] * b[2][2] + a[3][3] * b[2][3]; + + r[3][0] = a[0][0] * b[3][0] + a[1][0] * b[3][1] + a[2][0] * b[3][2] + a[3][0] * b[3][3]; + r[3][1] = a[0][1] * b[3][0] + a[1][1] * b[3][1] + a[2][1] * b[3][2] + a[3][1] * b[3][3]; + r[3][2] = a[0][2] * b[3][0] + a[1][2] * b[3][1] + a[2][2] * b[3][2] + a[3][2] * b[3][3]; + r[3][3] = a[0][3] * b[3][0] + a[1][3] * b[3][1] + a[2][3] * b[3][2] + a[3][3] * b[3][3]; +} + +void NvMultMatf(GLfloat result[4][4], const GLfloat a[4][4], const GLfloat b[4][4]) +{ + /* + Use a temporary matrix for the result and copy the temporary + into the result when finished. Doing this instead of writing + the result directly guarantees that the routine will work even + if the result overlaps one or more of the arguments in + memory. + */ + + GLfloat r[4][4]; + + if ((a[0][3] == 0.0f) && (a[1][3] == 0.0f) && (a[2][3] == 0.0f) && (a[2][3] == 1.0f) + && (b[0][3] == 0.0f) && (b[1][3] == 0.0f) && (b[2][3] == 0.0f) && (b[2][3] == 1.0f)) { + if ((a[3][0] == 0.0f) && (a[3][1] == 0.0f) && (a[3][2] == 0.0f) && (b[3][0] == 0.0f) + && (b[3][1] == 0.0f) && (b[3][2] == 0.0f)) { + NvMultMat3x3f(r, a, b); + } else { + NvMultMat4x3f(r, a, b); + } + } else { + NvMultMat4x4f(r, a, b); + } + + NvCopyMatf(result, r); +} + +static void NvInvMat3x3f(GLfloat r[4][4], const GLfloat m[4][4]) +{ + GLfloat d = m[0][0] * m[1][1] * m[2][2] + m[0][1] * m[1][2] * m[2][0] + + m[0][2] * m[1][0] * m[2][1] + -m[0][0] * m[1][2] * m[2][1] + -m[0][1] * m[1][0] * m[2][2] + + -m[0][2] * m[1][1] * m[2][0]; + + assert(NvDifferentMatsf(r, m)); + + r[0][0] = (m[1][1] * m[2][2] - m[1][2] * m[2][1]) / d; + r[0][1] = (m[0][2] * m[2][1] - m[0][1] * m[2][2]) / d; + r[0][2] = (m[0][1] * m[1][2] - m[0][2] * m[1][1]) / d; + r[0][3] = 0.0f; + + r[1][0] = (m[1][2] * m[2][0] - m[1][0] * m[2][2]) / d; + r[1][1] = (m[0][0] * m[2][2] - m[0][2] * m[2][0]) / d; + r[1][2] = (m[0][2] * m[1][0] - m[0][0] * m[1][2]) / d; + r[1][3] = 0.0f; + + r[2][0] = (m[1][0] * m[2][1] - m[1][1] * m[2][0]) / d; + r[2][1] = (m[0][1] * m[2][0] - m[0][0] * m[2][1]) / d; + r[2][2] = (m[0][0] * m[1][1] - m[0][1] * m[1][0]) / d; + r[2][3] = 0.0f; + + r[3][0] = 0.0f; + r[3][1] = 0.0f; + r[3][2] = 0.0f; + r[3][3] = 1.0f; +} + +static void NvInvMat4x3f(GLfloat r[4][4], const GLfloat m[4][4]) +{ + GLfloat d = m[0][0] * m[1][1] * m[2][2] + m[0][1] * m[1][2] * m[2][0] + + m[0][2] * m[1][0] * m[2][1] + -m[0][0] * m[1][2] * m[2][1] + -m[0][1] * m[1][0] * m[2][2] + + -m[0][2] * m[1][1] * m[2][0]; + + assert(NvDifferentMatsf(r, m)); + + r[0][0] = (m[1][1] * m[2][2] - m[1][2] * m[2][1]) / d; + r[0][1] = (m[0][2] * m[2][1] - m[0][1] * m[2][2]) / d; + r[0][2] = (m[0][1] * m[1][2] - m[0][2] * m[1][1]) / d; + r[0][3] = 0.0f; + + r[1][0] = (m[1][2] * m[2][0] - m[1][0] * m[2][2]) / d; + r[1][1] = (m[0][0] * m[2][2] - m[0][2] * m[2][0]) / d; + r[1][2] = (m[0][2] * m[1][0] - m[0][0] * m[1][2]) / d; + r[1][3] = 0.0f; + + r[2][0] = (m[1][0] * m[2][1] - m[1][1] * m[2][0]) / d; + r[2][1] = (m[0][1] * m[2][0] - m[0][0] * m[2][1]) / d; + r[2][2] = (m[0][0] * m[1][1] - m[0][1] * m[1][0]) / d; + r[2][3] = 0.0f; + + /* x */ + + r[3][0] = (m[1][0] * m[2][2] * m[3][1] + m[1][1] * m[2][0] * m[3][2] + + m[1][2] * m[2][1] * m[3][0] + -m[1][0] * m[2][1] * m[3][2] + + -m[1][1] * m[2][2] * m[3][0] + -m[1][2] * m[2][0] * m[3][1]) + / d; + + /* y */ + + r[3][1] = (m[0][0] * m[2][1] * m[3][2] + m[0][1] * m[2][2] * m[3][0] + + m[0][2] * m[2][0] * m[3][1] + -m[0][0] * m[2][2] * m[3][1] + + -m[0][1] * m[2][0] * m[3][2] + -m[0][2] * m[2][1] * m[3][0]) + / d; + + /* z */ + + r[3][2] = (m[0][0] * m[1][2] * m[3][1] + m[0][1] * m[1][0] * m[3][2] + + m[0][2] * m[1][1] * m[3][0] + -m[0][0] * m[1][1] * m[3][2] + + -m[0][1] * m[1][2] * m[3][0] + -m[0][2] * m[1][0] * m[3][1]) + / d; + + r[3][3] = 1.0f; +} + +static void NvInvMat4x4f(GLfloat r[4][4], const GLfloat m[4][4]) +{ + GLfloat d = m[0][0] * m[1][1] * m[2][2] * m[3][3] + m[0][0] * m[1][2] * m[2][3] * m[3][1] + + m[0][0] * m[1][3] * m[2][1] * m[3][2] + m[0][1] * m[1][0] * m[2][3] * m[3][2] + + m[0][1] * m[1][2] * m[2][0] * m[3][3] + m[0][1] * m[1][3] * m[2][2] * m[3][0] + + m[0][2] * m[1][0] * m[2][1] * m[3][3] + m[0][2] * m[1][1] * m[2][3] * m[3][0] + + m[0][2] * m[1][3] * m[2][0] * m[3][1] + m[0][3] * m[1][0] * m[2][2] * m[3][1] + + m[0][3] * m[1][1] * m[2][0] * m[3][2] + m[0][3] * m[1][2] * m[2][1] * m[3][0] + + -m[0][0] * m[1][1] * m[2][3] * m[3][2] + -m[0][0] * m[1][2] * m[2][1] * m[3][3] + + -m[0][0] * m[1][3] * m[2][2] * m[3][1] + -m[0][1] * m[1][0] * m[2][2] * m[3][3] + + -m[0][1] * m[1][2] * m[2][3] * m[3][0] + -m[0][1] * m[1][3] * m[2][0] * m[3][2] + + -m[0][2] * m[1][0] * m[2][3] * m[3][1] + -m[0][2] * m[1][1] * m[2][0] * m[3][3] + + -m[0][2] * m[1][3] * m[2][1] * m[3][0] + -m[0][3] * m[1][0] * m[2][1] * m[3][2] + + -m[0][3] * m[1][1] * m[2][2] * m[3][0] + -m[0][3] * m[1][2] * m[2][0] * m[3][1]; + + assert(NvDifferentMatsf(r, m)); + + r[0][0] = (m[1][1] * m[2][2] * m[3][3] + m[1][2] * m[2][3] * m[3][1] + + m[1][3] * m[2][1] * m[3][2] + -m[1][1] * m[2][3] * m[3][2] + + -m[1][2] * m[2][1] * m[3][3] + -m[1][3] * m[2][2] * m[3][1]) + / d; + + r[0][1] = (m[0][1] * m[2][3] * m[3][2] + m[0][2] * m[2][1] * m[3][3] + + m[0][3] * m[2][2] * m[3][1] + -m[0][1] * m[2][2] * m[3][3] + + -m[0][2] * m[2][3] * m[3][1] + -m[0][3] * m[2][1] * m[3][2]) + / d; + + r[0][2] = (m[0][1] * m[1][2] * m[3][3] + m[0][2] * m[1][3] * m[3][1] + + m[0][3] * m[1][1] * m[3][2] + -m[0][1] * m[1][3] * m[3][2] + + -m[0][2] * m[1][1] * m[3][3] + -m[0][3] * m[1][2] * m[3][1]) + / d; + + r[0][3] = (m[0][1] * m[1][3] * m[2][2] + m[0][2] * m[1][1] * m[2][3] + + m[0][3] * m[1][2] * m[2][1] + -m[0][1] * m[1][2] * m[2][3] + + -m[0][2] * m[1][3] * m[2][1] + -m[0][3] * m[1][1] * m[2][2]) + / d; + + r[1][0] = (m[1][0] * m[2][3] * m[3][2] + m[1][2] * m[2][0] * m[3][3] + + m[1][3] * m[2][2] * m[3][0] + -m[1][0] * m[2][2] * m[3][3] + + -m[1][2] * m[2][3] * m[3][0] + -m[1][3] * m[2][0] * m[3][2]) + / d; + + r[1][1] = (m[0][0] * m[2][2] * m[3][3] + m[0][2] * m[2][3] * m[3][0] + + m[0][3] * m[2][0] * m[3][2] + -m[0][0] * m[2][3] * m[3][2] + + -m[0][2] * m[2][0] * m[3][3] + -m[0][3] * m[2][2] * m[3][0]) + / d; + + r[1][2] = (m[0][0] * m[1][3] * m[3][2] + m[0][2] * m[1][0] * m[3][3] + + m[0][3] * m[1][2] * m[3][0] + -m[0][0] * m[1][2] * m[3][3] + + -m[0][2] * m[1][3] * m[3][0] + -m[0][3] * m[1][0] * m[3][2]) + / d; + + r[1][3] = (m[0][0] * m[1][2] * m[2][3] + m[0][2] * m[1][3] * m[2][0] + + m[0][3] * m[1][0] * m[2][2] + -m[0][0] * m[1][3] * m[2][2] + + -m[0][2] * m[1][0] * m[2][3] + -m[0][3] * m[1][2] * m[2][0]) + / d; + + r[2][0] = (m[1][0] * m[2][1] * m[3][3] + m[1][1] * m[2][3] * m[3][0] + + m[1][3] * m[2][0] * m[3][1] + -m[1][0] * m[2][3] * m[3][1] + + -m[1][1] * m[2][0] * m[3][3] + -m[1][3] * m[2][1] * m[3][0]) + / d; + + r[2][1] = + (-m[0][0] * m[2][1] * m[3][3] + -m[0][1] * m[2][3] * m[3][0] + -m[0][3] * m[2][0] * m[3][1] + + m[0][0] * m[2][3] * m[3][1] + m[0][1] * m[2][0] * m[3][3] + m[0][3] * m[2][1] * m[3][0]) + / d; + + r[2][2] = (m[0][0] * m[1][1] * m[3][3] + m[0][1] * m[1][3] * m[3][0] + + m[0][3] * m[1][0] * m[3][1] + -m[0][0] * m[1][3] * m[3][1] + + -m[0][1] * m[1][0] * m[3][3] + -m[0][3] * m[1][1] * m[3][0]) + / d; + + r[2][3] = (m[0][0] * m[1][3] * m[2][1] + m[0][1] * m[1][0] * m[2][3] + + m[0][3] * m[1][1] * m[2][0] + -m[0][1] * m[1][3] * m[2][0] + + -m[0][3] * m[1][0] * m[2][1] + -m[0][0] * m[1][1] * m[2][3]) + / d; + + r[3][0] = (m[1][0] * m[2][2] * m[3][1] + m[1][1] * m[2][0] * m[3][2] + + m[1][2] * m[2][1] * m[3][0] + -m[1][0] * m[2][1] * m[3][2] + + -m[1][1] * m[2][2] * m[3][0] + -m[1][2] * m[2][0] * m[3][1]) + / d; + + r[3][1] = (m[0][0] * m[2][1] * m[3][2] + m[0][1] * m[2][2] * m[3][0] + + m[0][2] * m[2][0] * m[3][1] + -m[0][0] * m[2][2] * m[3][1] + + -m[0][1] * m[2][0] * m[3][2] + -m[0][2] * m[2][1] * m[3][0]) + / d; + + r[3][2] = (m[0][0] * m[1][2] * m[3][1] + m[0][1] * m[1][0] * m[3][2] + + m[0][2] * m[1][1] * m[3][0] + -m[0][0] * m[1][1] * m[3][2] + + -m[0][1] * m[1][2] * m[3][0] + -m[0][2] * m[1][0] * m[3][1]) + / d; + + r[3][3] = (m[0][0] * m[1][1] * m[2][2] + m[0][1] * m[1][2] * m[2][0] + + m[0][2] * m[1][0] * m[2][1] + -m[0][0] * m[1][2] * m[2][1] + + -m[0][1] * m[1][0] * m[2][2] + -m[0][2] * m[1][1] * m[2][0]) + / d; +} + +void NvInvMatf(GLfloat result[4][4], const GLfloat m[4][4]) +{ + /* + Use a temporary matrix for the result and copy the temporary + into the result when finished. Doing this instead of writing + the result directly guarantees that the routine will work even + if the result overlaps one or more of the arguments in + memory. + */ + + GLfloat r[4][4]; + + if ((m[0][3] == 0.0f) && (m[1][3] == 0.0f) && (m[2][3] == 0.0f) && (m[2][3] == 1.0f)) { + if ((m[3][0] == 0.0f) && (m[3][1] == 0.0f) && (m[3][2] == 0.0f)) { + NvInvMat3x3f(r, m); + } else { + NvInvMat4x3f(r, m); + } + } else { + NvInvMat4x4f(r, m); + } + + NvCopyMatf(result, r); +} + +void NvBuildIdentityMatf(GLfloat r[4][4]) +{ + r[0][0] = 1.0f; + r[0][1] = 0.0f; + r[0][2] = 0.0f; + r[0][3] = 0.0f; + + r[1][0] = 0.0f; + r[1][1] = 1.0f; + r[1][2] = 0.0f; + r[1][3] = 0.0f; + + r[2][0] = 0.0f; + r[2][1] = 0.0f; + r[2][2] = 1.0f; + r[2][3] = 0.0f; + + r[3][0] = 0.0f; + r[3][1] = 0.0f; + r[3][2] = 0.0f; + r[3][3] = 1.0f; +} + +void NvBuildTranslateMatf(GLfloat r[4][4], GLfloat x, GLfloat y, GLfloat z) +{ + r[0][0] = 1.0f; + r[0][1] = 0.0f; + r[0][2] = 0.0f; + r[0][3] = 0.0f; + + r[1][0] = 0.0f; + r[1][1] = 1.0f; + r[1][2] = 0.0f; + r[1][3] = 0.0f; + + r[2][0] = 0.0f; + r[2][1] = 0.0f; + r[2][2] = 1.0f; + r[2][3] = 0.0f; + + r[3][0] = x; + r[3][1] = y; + r[3][2] = z; + r[3][3] = 1.0f; +} + +void NvMultTranslateMatf(GLfloat result[4][4], const GLfloat m[4][4], GLfloat x, GLfloat y, + GLfloat z) +{ + GLfloat r[4][4]; /*temporary storage for result */ + + r[0][0] = m[0][0]; + r[0][1] = m[0][1]; + r[0][2] = m[0][2]; + r[0][3] = m[0][3]; + + r[1][0] = m[1][0]; + r[1][1] = m[1][1]; + r[1][2] = m[1][2]; + r[1][3] = m[1][3]; + + r[2][0] = m[2][0]; + r[2][1] = m[2][1]; + r[2][2] = m[2][2]; + r[2][3] = m[2][3]; + + r[3][0] = m[0][0] * x + m[1][0] * y + m[2][0] * z + m[3][0]; + r[3][1] = m[0][1] * x + m[1][1] * y + m[2][1] * z + m[3][1]; + r[3][2] = m[0][2] * x + m[1][2] * y + m[2][2] * z + m[3][2]; + r[3][3] = m[0][3] * x + m[1][3] * y + m[2][3] * z + m[3][3]; + + NvCopyMatf(result, r); +} + +void NvBuildScaleMatf(GLfloat r[4][4], GLfloat x, GLfloat y, GLfloat z) +{ + r[0][0] = x; + r[0][1] = 0.0f; + r[0][2] = 0.0f; + r[0][3] = 0.0f; + + r[1][0] = 0.0f; + r[1][1] = y; + r[1][2] = 0.0f; + r[1][3] = 0.0f; + + r[2][0] = 0.0f; + r[2][1] = 0.0f; + r[2][2] = z; + r[2][3] = 0.0f; + + r[3][0] = 0.0f; + r[3][1] = 0.0f; + r[3][2] = 0.0f; + r[3][3] = 1.0f; +} + +void NvMultScaleMatf(GLfloat result[4][4], const GLfloat m[4][4], GLfloat x, GLfloat y, GLfloat z) +{ + + GLfloat r[4][4]; + + r[0][0] = m[0][0] * x; + r[0][1] = m[0][1] * x; + r[0][2] = m[0][2] * x; + r[0][3] = m[0][3] * x; + + r[1][0] = m[1][0] * y; + r[1][1] = m[1][1] * y; + r[1][2] = m[1][2] * y; + r[1][3] = m[1][3] * y; + + r[2][0] = m[2][0] * z; + r[2][1] = m[2][1] * z; + r[2][2] = m[2][2] * z; + r[2][3] = m[2][3] * z; + + r[3][0] = m[3][0]; + r[3][1] = m[3][1]; + r[3][2] = m[3][2]; + r[3][3] = m[3][3]; + + NvCopyMatf(result, r); +} + +void NvBuildRotXRadMatf(GLfloat r[4][4], GLfloat radians) +{ + GLfloat const s = sinf(radians); + GLfloat const c = cosf(radians); + + r[0][0] = 1.0f; + r[0][1] = 0.0f; + r[0][2] = 0.0f; + r[0][3] = 0.0f; + + r[1][0] = 0.0f; + r[1][1] = c; + r[1][2] = s; + r[1][3] = 0.0f; + + r[2][0] = 0.0f; + r[2][1] = -s; + r[2][2] = c; + r[2][3] = 0.0f; + + r[3][0] = 0.0f; + r[3][1] = 0.0f; + r[3][2] = 0.0f; + r[3][3] = 1.0f; +} + +void NvBuildRotYRadMatf(GLfloat r[4][4], GLfloat radians) +{ + + GLfloat const s = sinf(radians); + GLfloat const c = cosf(radians); + + r[0][0] = c; + r[0][1] = 0.0f; + r[0][2] = -s; + r[0][3] = 0.0f; + + r[1][0] = 0.0f; + r[1][1] = 1.0f; + r[1][2] = 0.0f; + r[1][3] = 0.0f; + + r[2][0] = s; + r[2][1] = 0.0f; + r[2][2] = c; + r[2][3] = 0.0f; + + r[3][0] = 0.0f; + r[3][1] = 0.0f; + r[3][2] = 0.0f; + r[3][3] = 1.0f; +} + +void NvBuildRotZRadMatf(GLfloat r[4][4], GLfloat radians) +{ + + GLfloat const s = sinf(radians); + GLfloat const c = cosf(radians); + + r[0][0] = c; + r[0][1] = s; + r[0][2] = 0.0f; + r[0][3] = 0.0f; + + r[1][0] = -s; + r[1][1] = c; + r[1][2] = 0.0f; + r[1][3] = 0.0f; + + r[2][0] = 0.0f; + r[2][1] = 0.0f; + r[2][2] = 1.0f; + r[2][3] = 0.0f; + + r[3][0] = 0.0f; + r[3][1] = 0.0f; + r[3][2] = 0.0f; + r[3][3] = 1.0f; +} + +void NvMultRotXRadMatf(GLfloat result[4][4], const GLfloat m[4][4], GLfloat radians) +{ + + GLfloat const s = sinf(radians); + GLfloat const c = cosf(radians); + + GLfloat r[4][4]; + + r[0][0] = m[0][0]; + r[0][1] = m[0][1]; + r[0][2] = m[0][2]; + r[0][3] = m[0][3]; + + r[1][0] = m[1][0] * c + m[2][0] * s; + r[1][1] = m[1][1] * c + m[2][1] * s; + r[1][2] = m[1][2] * c + m[2][2] * s; + r[1][3] = m[1][3] * c + m[2][3] * s; + + r[2][0] = m[1][0] * -s + m[2][0] * c; + r[2][1] = m[1][1] * -s + m[2][1] * c; + r[2][2] = m[1][2] * -s + m[2][2] * c; + r[2][3] = m[1][3] * -s + m[2][3] * c; + + r[3][0] = m[3][0]; + r[3][1] = m[3][1]; + r[3][2] = m[3][2]; + r[3][3] = m[3][3]; + + NvCopyMatf(result, r); +} + +void NvMultRotYRadMatf(GLfloat result[4][4], const GLfloat m[4][4], GLfloat radians) +{ + + GLfloat const s = sinf(radians); + GLfloat const c = cosf(radians); + + GLfloat r[4][4]; + + r[0][0] = m[0][0] * c + m[2][0] * -s; + r[0][1] = m[0][1] * c + m[2][1] * -s; + r[0][2] = m[0][2] * c + m[2][2] * -s; + r[0][3] = m[0][3] * c + m[2][3] * -s; + + r[1][0] = m[1][0]; + r[1][1] = m[1][1]; + r[1][2] = m[1][2]; + r[1][3] = m[1][3]; + + r[2][0] = m[0][0] * s + m[2][0] * c; + r[2][1] = m[0][1] * s + m[2][1] * c; + r[2][2] = m[0][2] * s + m[2][2] * c; + r[2][3] = m[0][3] * s + m[2][3] * c; + + r[3][0] = m[3][0]; + r[3][1] = m[3][1]; + r[3][2] = m[3][2]; + r[3][3] = m[3][3]; + + NvCopyMatf(result, r); +} + +void NvMultRotZRadMatf(GLfloat result[4][4], const GLfloat m[4][4], GLfloat radians) +{ + + GLfloat const s = sinf(radians); + GLfloat const c = cosf(radians); + + GLfloat r[4][4]; + + r[0][0] = m[0][0] * c + m[1][0] * s; + r[0][1] = m[0][1] * c + m[1][1] * s; + r[0][2] = m[0][2] * c + m[1][2] * s; + r[0][3] = m[0][3] * c + m[1][3] * s; + + r[1][0] = m[0][0] * -s + m[1][0] * c; + r[1][1] = m[0][1] * -s + m[1][1] * c; + r[1][2] = m[0][2] * -s + m[1][2] * c; + r[1][3] = m[0][3] * -s + m[1][3] * c; + + r[2][0] = m[2][0]; + r[2][1] = m[2][1]; + r[2][2] = m[2][2]; + r[2][3] = m[2][3]; + + r[3][0] = m[3][0]; + r[3][1] = m[3][1]; + r[3][2] = m[3][2]; + r[3][3] = m[3][3]; + + NvCopyMatf(result, r); +} + +void NvBuildRotRadMatf(GLfloat result[4][4], const GLfloat axis[3], GLfloat radians) +{ + /* build a quat first */ + + GLfloat i, j, k, r; + + /* should be */ + GLfloat dst_l = sinf(radians / 2.0f); + + /* actually is */ + GLfloat const src_l = sqrtf(axis[0] * axis[0] + axis[1] * axis[1] + axis[2] * axis[2]); + + if (src_l <= KD_FLT_EPSILON) { + i = 0.0f; + j = 0.0f; + k = 0.0f; + r = 1.0f; + } else { + GLfloat const s = dst_l / src_l; + i = axis[0] * s; + j = axis[1] * s; + k = axis[2] * s; + r = cosf(radians / 2.0f); + } + + /* build a matrix from the quat */ + + result[0][0] = 1.0f - 2.0f * (j * j + k * k); + result[0][1] = 2.0f * (i * j + r * k); + result[0][2] = 2.0f * (i * k - r * j); + result[0][3] = 0.0f; + + result[1][0] = 2.0f * (i * j - r * k); + result[1][1] = 1.0f - 2.0f * (i * i + k * k); + result[1][2] = 2.0f * (j * k + r * i); + result[1][3] = 0.0f; + + result[2][0] = 2.0f * (i * k + r * j); + result[2][1] = 2.0f * (j * k - r * i); + result[2][2] = 1.0f - 2.0f * (i * i + j * j); + result[2][3] = 0.0f; + + result[3][0] = 0.0f; + result[3][1] = 0.0f; + result[3][2] = 0.0f; + result[3][3] = 1.0f; +} + +void NvMultRotRadMatf(GLfloat result[4][4], const GLfloat m[4][4], const GLfloat axis[3], + GLfloat radians) +{ + GLfloat r[4][4]; + + { + /* build a quat first */ + + GLfloat i, j, k, r; + + /* should be */ + GLfloat const dst_l = sinf(radians / 2.0f); + + /* actually is */ + GLfloat const src_l = sqrtf(axis[0] * axis[0] + axis[1] * axis[1] + axis[2] * axis[2]); + + if (src_l <= KD_FLT_EPSILON) { + i = 0.0f; + j = 0.0f; + k = 0.0f; + r = 1.0f; + } else { + GLfloat const s = dst_l / src_l; + i = axis[0] * s; + j = axis[1] * s; + k = axis[2] * s; + r = cosf(radians / 2.0f); + } + + { + /* build a matrix from the quat */ + + GLfloat const a00 = 1.0f - 2.0f * (j * j + k * k); + GLfloat const a01 = 2.0f * (i * j + r * k); + GLfloat const a02 = 2.0f * (i * k - r * j); + + GLfloat const a10 = 2.0f * (i * j - r * k); + GLfloat const a11 = 1.0f - 2.0f * (i * i + k * k); + GLfloat const a12 = 2.0f * (j * k + r * i); + + GLfloat const a20 = 2.0f * (i * k + r * j); + GLfloat const a21 = 2.0f * (j * k - r * i); + GLfloat const a22 = 1.0f - 2.0f * (i * i + j * j); + + result[0][0] = m[0][0] * a00 + m[1][0] * a01 + m[2][0] * a02; + result[0][1] = m[0][1] * a00 + m[1][1] * a01 + m[2][1] * a02; + result[0][2] = m[0][2] * a00 + m[1][2] * a01 + m[2][2] * a02; + result[0][3] = m[0][3] * a00 + m[1][3] * a01 + m[2][3] * a02; + + result[1][0] = m[0][0] * a10 + m[1][0] * a11 + m[2][0] * a12; + result[1][1] = m[0][1] * a10 + m[1][1] * a11 + m[2][1] * a12; + result[1][2] = m[0][2] * a10 + m[1][2] * a11 + m[2][2] * a12; + result[1][3] = m[0][3] * a10 + m[1][3] * a11 + m[2][3] * a12; + + result[2][0] = m[0][0] * a20 + m[1][0] * a21 + m[2][0] * a22; + result[2][1] = m[0][1] * a20 + m[1][1] * a21 + m[2][1] * a22; + result[2][2] = m[0][2] * a20 + m[1][2] * a21 + m[2][2] * a22; + result[2][3] = m[0][3] * a20 + m[1][3] * a21 + m[2][3] * a22; + + result[3][0] = m[3][0]; + result[3][1] = m[3][1]; + result[3][2] = m[3][2]; + result[3][3] = m[3][3]; + } + } + + NvCopyMatf(result, r); +} + +void NvBuildRotXDegMatf(GLfloat r[4][4], GLfloat degrees) +{ + NvBuildRotXRadMatf(r, degrees * KD_DEG_TO_RAD_F); +} + +void NvBuildRotYDegMatf(GLfloat r[4][4], GLfloat degrees) +{ + NvBuildRotYRadMatf(r, degrees * KD_DEG_TO_RAD_F); +} + +void NvBuildRotZDegMatf(GLfloat r[4][4], GLfloat degrees) +{ + NvBuildRotZRadMatf(r, degrees * KD_DEG_TO_RAD_F); +} + +void NvMultRotXDegMatf(GLfloat r[4][4], const GLfloat m[4][4], GLfloat degrees) +{ + NvMultRotXRadMatf(r, m, degrees * KD_DEG_TO_RAD_F); +} + +void NvMultRotYDegMatf(GLfloat r[4][4], const GLfloat m[4][4], GLfloat degrees) +{ + NvMultRotYRadMatf(r, m, degrees * KD_DEG_TO_RAD_F); +} + +void NvMultRotZDegMatf(GLfloat r[4][4], const GLfloat m[4][4], GLfloat degrees) +{ + NvMultRotZRadMatf(r, m, degrees * KD_DEG_TO_RAD_F); +} + +void NvBuildRotDegMatf(GLfloat r[4][4], const GLfloat axis[3], GLfloat degrees) +{ + NvBuildRotRadMatf(r, axis, degrees * KD_DEG_TO_RAD_F); +} + +void NvMultRotDegMatf(GLfloat r[4][4], const GLfloat m[4][4], const GLfloat axis[3], + GLfloat degrees) +{ + NvMultRotRadMatf(r, m, axis, degrees * KD_DEG_TO_RAD_F); +} + +void NvBuildLookatMatf(GLfloat r[4][4], const GLfloat eye[3], const GLfloat obj[3], + const GLfloat up[3]) +{ + GLfloat ev[3]; + GLfloat z[3]; + GLfloat x_tmp[3]; + GLfloat x[3]; + GLfloat y[3]; + + NvSubVecf(ev, eye, obj); + + NvNormalizeVecf(z, ev); + + NvCrossProductf(x_tmp, up, z); + + NvNormalizeVecf(x, x_tmp); + + NvCrossProductf(y, z, x); + + r[0][0] = x[0]; + r[0][1] = y[0]; + r[0][2] = z[0]; + r[0][3] = 0.0f; + + r[1][0] = x[1]; + r[1][1] = y[1]; + r[1][2] = z[1]; + r[1][3] = 0.0f; + + r[2][0] = x[2]; + r[2][1] = y[2]; + r[2][2] = z[2]; + r[2][3] = 0.0f; + + r[3][0] = -x[0] * eye[0] + -x[1] * eye[1] + -x[2] * eye[2]; + r[3][1] = -y[0] * eye[0] + -y[1] * eye[1] + -y[2] * eye[2]; + r[3][2] = -z[0] * eye[0] + -z[1] * eye[1] + -z[2] * eye[2]; + r[3][3] = 1.0f; +} + +void NvBuildFrustumMatf(GLfloat r[4][4], GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, + GLfloat znear, GLfloat zfar) +{ + GLfloat const m00 = znear * 2.0f / (right - left); + GLfloat const m11 = znear * 2.0f / (top - bottom); + GLfloat const m22 = -(zfar + znear) / (zfar - znear); + + GLfloat const m20 = (right + left) / (right - left); + GLfloat const m21 = (top + bottom) / (top - bottom); + + GLfloat const m32 = -(2.0f * zfar * znear) / (zfar - znear); + GLfloat const m23 = -1.0f; + + r[0][0] = m00; + r[0][1] = 0.0f; + r[0][2] = 0.0f; + r[0][3] = 0.0f; + + r[1][0] = 0.0f; + r[1][1] = m11; + r[1][2] = 0.0f; + r[1][3] = 0.0f; + + r[2][0] = m20; + r[2][1] = m21; + r[2][2] = m22; + r[2][3] = m23; + + r[3][0] = 0.0f; + r[3][1] = 0.0f; + r[3][2] = m32; + r[3][3] = 0.0f; +} + +void NvBuildOrtho2Matf(GLfloat r[4][4], GLfloat left, GLfloat right, GLfloat bottom, GLfloat top) +{ + GLfloat const sx = 2.0f / (right - left); + GLfloat const sy = 2.0f / (top - bottom); + + GLfloat const tx = -(right + left) / (right - left); + GLfloat const ty = -(top + bottom) / (top - bottom); + + r[0][0] = sx; + r[0][1] = 0.0f; + r[0][2] = 0.0f; + r[0][3] = 0.0f; + + r[1][0] = 0.0f; + r[1][1] = sy; + r[1][2] = 0.0f; + r[1][3] = 0.0f; + + r[2][0] = 0.0f; + r[2][1] = 0.0f; + r[2][2] = 1.0f; + r[2][3] = 0.0f; + + r[3][0] = tx; + r[3][1] = ty; + r[3][2] = 0.0f; + r[3][3] = 1.0f; +} + +void NvBuildOrthoMatf(GLfloat r[4][4], GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, + GLfloat znear, GLfloat zfar) +{ + GLfloat const sx = 2.0f / (right - left); + GLfloat const sy = 2.0f / (top - bottom); + GLfloat const sz = -2.0f / (zfar - znear); + + GLfloat const tx = -(right + left) / (right - left); + GLfloat const ty = -(top + bottom) / (top - bottom); + GLfloat const tz = -(zfar + znear) / (zfar - znear); + + r[0][0] = sx; + r[0][1] = 0.0f; + r[0][2] = 0.0f; + r[0][3] = 0.0f; + + r[1][0] = 0.0f; + r[1][1] = sy; + r[1][2] = 0.0f; + r[1][3] = 0.0f; + + r[2][0] = 0.0f; + r[2][1] = 0.0f; + r[2][2] = sz; + r[2][3] = 0.0f; + + r[3][0] = tx; + r[3][1] = ty; + r[3][2] = tz; + r[3][3] = 1.0f; +} diff --git a/src/platformspecific/macos/libs/nv_math/nv_matrix.h b/src/platformspecific/macos/libs/nv_math/nv_matrix.h new file mode 100644 index 0000000..0709f11 --- /dev/null +++ b/src/platformspecific/macos/libs/nv_math/nv_matrix.h @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2009-2011 NVIDIA Corporation. +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt 3D Studio. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef INCLUDED_MATRIX_H +#define INCLUDED_MATRIX_H + +#include <OpenGL/gl.h> +#include <math.h> +#include <assert.h> + +#define KD_FLT_EPSILON 1.19209290E-07F +#define KD_DEG_TO_RAD_F 0.0174532924F +#define KD_RAD_TO_DEG_F 57.2957802F + +void NvCopyMatf(GLfloat r[4][4], const GLfloat m[4][4]); +void NvExtract3x3Matf(GLfloat r[3][3], const GLfloat m[4][4]); + +/* vector utilities */ + +GLfloat NvVecLengthf(const GLfloat v[3]); + +void NvNormalizeVecf(GLfloat r[3], const GLfloat v[3]); + +void NvAddVecf(GLfloat r[3], const GLfloat a[3], const GLfloat b[3]); + +void NvSubVecf(GLfloat r[3], const GLfloat a[3], const GLfloat b[3]); + +void NvCrossProductf(GLfloat r[3], const GLfloat a[3], const GLfloat b[3]); + +void NvTransformPointf(GLfloat r[3], const GLfloat m[4][4], const GLfloat a[3]); +void NvTransformHomPointf(GLfloat r[4], const GLfloat m[4][4], const GLfloat a[4]); +void NvTransformVecf(GLfloat r[3], const GLfloat m[4][4], const GLfloat a[3]); + +/* matrix utilities */ + +void NvMultMatf(GLfloat r[4][4], const GLfloat a[4][4], const GLfloat b[4][4]); + +void NvInvMatf(GLfloat r[4][4], const GLfloat m[4][4]); + +/* matrix building utilities */ + +void NvBuildIdentityMatf(GLfloat r[4][4]); + +void NvBuildTranslateMatf(GLfloat r[4][4], GLfloat x, GLfloat y, GLfloat z); + +void NvBuildScaleMatf(GLfloat r[4][4], GLfloat x, GLfloat y, GLfloat z); + +void NvBuildRotXDegMatf(GLfloat r[4][4], GLfloat degrees); +void NvBuildRotYDegMatf(GLfloat r[4][4], GLfloat degrees); +void NvBuildRotZDegMatf(GLfloat r[4][4], GLfloat degrees); + +void NvBuildRotDegMatf(GLfloat r[4][4], const GLfloat axis[3], GLfloat degrees); + +void NvBuildRotXRadMatf(GLfloat r[4][4], GLfloat radians); +void NvBuildRotYRadMatf(GLfloat r[4][4], GLfloat radians); +void NvBuildRotZRadMatf(GLfloat r[4][4], GLfloat radians); + +void NvBuildRotRadMatf(GLfloat r[4][4], const GLfloat axis[3], GLfloat radians); + +void NvBuildLookatMatf(GLfloat r[4][4], const GLfloat eye[3], const GLfloat obj[3], + const GLfloat up[3]); + +void NvBuildFrustumMatf(GLfloat r[4][4], GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, + GLfloat znear, GLfloat zfar); + +void NvBuildOrtho2Matf(GLfloat r[4][4], GLfloat left, GLfloat right, GLfloat bottom, GLfloat top); + +void NvBuildOrthoMatf(GLfloat r[4][4], GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, + GLfloat znear, GLfloat zfar); + +/* matrix concatenation utilities */ + +void NvMultTranslateMatf(GLfloat r[4][4], const GLfloat m[4][4], GLfloat x, GLfloat y, GLfloat z); +void NvMultScaleMatf(GLfloat r[4][4], const GLfloat m[4][4], GLfloat x, GLfloat y, GLfloat z); + +void NvMultRotXDegMatf(GLfloat r[4][4], const GLfloat m[4][4], GLfloat degrees); +void NvMultRotYDegMatf(GLfloat r[4][4], const GLfloat m[4][4], GLfloat degrees); +void NvMultRotZDegMatf(GLfloat r[4][4], const GLfloat m[4][4], GLfloat degrees); + +void NvMultRotDegMatf(GLfloat r[4][4], const GLfloat m[4][4], const GLfloat axis[3], + GLfloat degrees); + +void NvMultRotXRadMatf(GLfloat r[4][4], const GLfloat m[4][4], GLfloat radians); +void NvMultRotYRadMatf(GLfloat r[4][4], const GLfloat m[4][4], GLfloat radians); +void NvMultRotZRadMatf(GLfloat r[4][4], const GLfloat m[4][4], GLfloat radians); + +void NvMultRotRadMatf(GLfloat r[4][4], const GLfloat m[4][4], const GLfloat axis[3], + GLfloat radians); + +#endif diff --git a/src/platformspecific/macos/libs/nv_math/nv_quat.cpp b/src/platformspecific/macos/libs/nv_math/nv_quat.cpp new file mode 100644 index 0000000..ec49794 --- /dev/null +++ b/src/platformspecific/macos/libs/nv_math/nv_quat.cpp @@ -0,0 +1,199 @@ +/**************************************************************************** +** +** Copyright (C) 2009-2011 NVIDIA Corporation. +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt 3D Studio. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "nv_quat.h" +#include <stdlib.h> +#include <memory.h> + +void NvQuatCopy(GLfloat r[4], const GLfloat q[4]) +{ + memcpy(r, q, 4 * sizeof(GLfloat)); +} + +void NvQuatConvertTo3x3Mat(GLfloat r[3][3], const GLfloat q[4]) +{ + // Assumes that the quaternion is normalized! + GLfloat x2 = q[0] * 2.0f; + GLfloat y2 = q[1] * 2.0f; + GLfloat z2 = q[2] * 2.0f; + GLfloat xSq2 = x2 * q[0]; + GLfloat ySq2 = y2 * q[1]; + GLfloat zSq2 = z2 * q[2]; + GLfloat xy2 = x2 * q[1]; + GLfloat xz2 = x2 * q[2]; + GLfloat xw2 = x2 * q[3]; + GLfloat yz2 = y2 * q[2]; + GLfloat yw2 = y2 * q[3]; + GLfloat zw2 = z2 * q[3]; + + /* Matrix is + * | 1 - 2y^2 - 2z^2 2xy - 2zw 2xz + 2yw | + * | 2xy + 2zw 1 - 2x^2 - 2z^2 2yz - 2xw | + * | 2xz - 2yw 2yz + 2xw 1 - 2x^2 - 2y^2 | + */ + r[0][0] = 1.0f - ySq2 - zSq2; + r[0][1] = xy2 - zw2; + r[0][2] = xz2 + yw2; + + r[1][0] = xy2 + zw2; + r[1][1] = 1.0f - xSq2 - zSq2; + r[1][2] = yz2 - xw2; + + r[2][0] = xz2 - yw2; + r[2][1] = yz2 + xw2; + r[2][2] = 1.0f - xSq2 - ySq2; +} + +void NvQuatIdentity(GLfloat r[4]) +{ + r[0] = 0.0f; + r[1] = 0.0f; + r[2] = 0.0f; + r[3] = 1.0f; +} + +void NvQuatFromAngleAxis(GLfloat r[4], GLfloat radians, const GLfloat axis[3]) +{ + GLfloat cosa = cosf(radians * 0.5f); + GLfloat sina = sinf(radians * 0.5f); + + r[0] = axis[0] * sina; + r[1] = axis[1] * sina; + r[2] = axis[2] * sina; + r[3] = cosa; +} + +void NvQuatX(GLfloat r[4], GLfloat radians) +{ + GLfloat cosa = cosf(radians * 0.5f); + GLfloat sina = sinf(radians * 0.5f); + + r[0] = sina; + r[1] = 0.0f; + r[2] = 0.0f; + r[3] = cosa; +} + +void NvQuatY(GLfloat r[4], GLfloat radians) +{ + GLfloat cosa = cosf(radians * 0.5f); + GLfloat sina = sinf(radians * 0.5f); + + r[0] = 0.0f; + r[1] = sina; + r[2] = 0.0f; + r[3] = cosa; +} + +void NvQuatZ(GLfloat r[4], GLfloat radians) +{ + GLfloat cosa = cosf(radians * 0.5f); + GLfloat sina = sinf(radians * 0.5f); + + r[0] = 0.0f; + r[1] = 0.0f; + r[2] = sina; + r[3] = cosa; +} + +void NvQuatFromEuler(GLfloat r[4], GLfloat heading, GLfloat pitch, GLfloat roll) +{ + GLfloat h[4], p[4], ro[4]; + + NvQuatY(h, heading); + NvQuatX(p, pitch); + NvQuatZ(ro, roll); + + NvQuatMult(r, h, p); + NvQuatMult(r, ro, r); +} + +void NvQuatFromEulerReverse(GLfloat r[4], GLfloat heading, GLfloat pitch, GLfloat roll) +{ + GLfloat h[4], p[4], ro[4]; + + NvQuatZ(ro, roll); + NvQuatX(p, pitch); + NvQuatY(h, heading); + + NvQuatMult(r, p, h); + NvQuatMult(r, r, ro); +} + +GLfloat NvQuatDot(const GLfloat q1[4], const GLfloat q2[4]) +{ + return q1[0] * q2[0] + q1[1] * q2[1] + q1[2] * q2[2] + q1[3] * q2[3]; +} + +void NvQuatMult(GLfloat r[4], const GLfloat q1[4], const GLfloat q2[4]) +{ + const GLfloat q1x = q1[0]; + const GLfloat q1y = q1[1]; + const GLfloat q1z = q1[2]; + const GLfloat q1w = q1[3]; + const GLfloat q2x = q2[0]; + const GLfloat q2y = q2[1]; + const GLfloat q2z = q2[2]; + const GLfloat q2w = q2[3]; + + r[0] = q1y * q2z - q2y * q1z + q1w * q2x + q2w * q1x; + r[1] = q1z * q2x - q2z * q1x + q1w * q2y + q2w * q1y; + r[2] = q1x * q2y - q2x * q1y + q1w * q2z + q2w * q1z; + r[3] = q1w * q2w - q1x * q2x - q1y * q2y - q1z * q2z; +} + +void NvQuatNLerp(GLfloat r[4], const GLfloat q1[4], const GLfloat q2[4], GLfloat t) +{ + GLfloat omt = 1.0f - t; + + if (NvQuatDot(q1, q2) < 0.0f) { + r[0] = -q1[0] * omt + q2[0] * t; + r[1] = -q1[1] * omt + q2[1] * t; + r[2] = -q1[2] * omt + q2[2] * t; + r[3] = -q1[3] * omt + q2[3] * t; + } else { + r[0] = q1[0] * omt + q2[0] * t; + r[1] = q1[1] * omt + q2[1] * t; + r[2] = q1[2] * omt + q2[2] * t; + r[3] = q1[3] * omt + q2[3] * t; + } + + NvQuatNormalize(r, r); +} + +void NvQuatNormalize(GLfloat r[4], const GLfloat q[4]) +{ + GLfloat invLength = 1.0f / sqrtf(NvQuatDot(q, q)); + + r[0] = invLength * q[0]; + r[1] = invLength * q[1]; + r[2] = invLength * q[2]; + r[3] = invLength * q[3]; +} diff --git a/src/platformspecific/macos/libs/nv_math/nv_quat.h b/src/platformspecific/macos/libs/nv_math/nv_quat.h new file mode 100644 index 0000000..2afdcb7 --- /dev/null +++ b/src/platformspecific/macos/libs/nv_math/nv_quat.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2009-2011 NVIDIA Corporation. +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt 3D Studio. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef INCLUDED_QUAT_H +#define INCLUDED_QUAT_H + +#include <OpenGL/gl.h> +#include <math.h> +#include <assert.h> + +void NvQuatCopy(GLfloat r[4], const GLfloat q[4]); +void NvQuatConvertTo3x3Mat(GLfloat r[3][3], const GLfloat q[4]); + +void NvQuatIdentity(GLfloat r[4]); + +void NvQuatFromAngleAxis(GLfloat r[4], GLfloat radians, const GLfloat axis[3]); + +void NvQuatX(GLfloat r[4], GLfloat radians); + +void NvQuatY(GLfloat r[4], GLfloat radians); + +void NvQuatZ(GLfloat r[4], GLfloat radians); + +void NvQuatFromEuler(GLfloat r[4], GLfloat heading, GLfloat pitch, GLfloat roll); + +void NvQuatFromEulerReverse(GLfloat r[4], GLfloat heading, GLfloat pitch, GLfloat roll); + +GLfloat NvQuatDot(const GLfloat q1[4], const GLfloat q2[4]); + +void NvQuatMult(GLfloat r[4], const GLfloat q1[4], const GLfloat q2[4]); + +void NvQuatNLerp(GLfloat r[4], const GLfloat q1[4], const GLfloat q2[4], GLfloat t); + +void NvQuatNormalize(GLfloat r[4], const GLfloat q[4]); + +#endif diff --git a/src/platformspecific/macos/libs/nv_types.h b/src/platformspecific/macos/libs/nv_types.h new file mode 100644 index 0000000..1d1b030 --- /dev/null +++ b/src/platformspecific/macos/libs/nv_types.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2009-2011 NVIDIA Corporation. +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt 3D Studio. +** +** $QT_BEGIN_LICENSE:GPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 or (at your option) any later version +** approved by the KDE Free Qt Foundation. The licenses are as published by +** the Free Software Foundation and appearing in the file LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef __INCLUDED_QT3DS_TYPES_H +#define __INCLUDED_QT3DS_TYPES_H + +typedef unsigned char NvU8; // 0 to 255 +typedef unsigned short NvU16; // 0 to 65535 +typedef unsigned int NvU32; // 0 to 4294967295 +typedef unsigned long long NvU64; // 0 to 18446744073709551615 +typedef signed char NvS8; // -128 to 127 +typedef signed short NvS16; // -32768 to 32767 +typedef signed int NvS32; // -2147483648 to 2147483647 +typedef signed long long NvS64; // 2^-63 to 2^63-1 + +// Explicitly sized floats +typedef float NvF32; // IEEE Single Precision (S1E8M23) +typedef double NvF64; // IEEE Double Precision (S1E11M52) + +// Boolean type +#define QT3DS_FALSE 0 +#define QT3DS_TRUE 1 +typedef NvU8 NvBool; + +// Result of sizeof operator +typedef unsigned long NvSize; + +// Type large enough to hold a relative file offset +typedef long NvOffset; + +// Base NULL type. +#define QT3DS_NULL 0 + +// Error related +typedef enum { + NvError_Success = 0, + NvError_NotSupported, + NvError_NotInitialized, + NvError_BadParameter, + NvError_InsufficientMemory, + NvError_NoEntries, + NvError_UnknownError, +} NvError; + +#if 1 // defined(_DEBUG) // !!!!TBD TODO +#define NvAssert(c) +#else +#define NvAssert(c) ((void)((c) ? 0 : (NvHandleAssertion(#c, __FILE__, __LINE__), 0))) +#endif + +// Other standardized typedefs +typedef NvU64 NvUST; // U64 unadjusted system time value + +#endif |