NvBlastMath.h
Go to the documentation of this file.
1 // This code contains NVIDIA Confidential Information and is disclosed to you
2 // under a form of NVIDIA software license agreement provided separately to you.
3 //
4 // Notice
5 // NVIDIA Corporation and its licensors retain all intellectual property and
6 // proprietary rights in and to this software and related documentation and
7 // any modifications thereto. Any use, reproduction, disclosure, or
8 // distribution of this software and related documentation without an express
9 // license agreement from NVIDIA Corporation is strictly prohibited.
10 //
11 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
12 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
13 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
14 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
15 //
16 // Information and code furnished is believed to be accurate and reliable.
17 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
18 // information or for any infringement of patents or other rights of third parties that may
19 // result from its use. No license is granted by implication or otherwise under any patent
20 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
21 // This code supersedes and replaces all information previously supplied.
22 // NVIDIA Corporation products are not authorized for use as critical
23 // components in life support devices or systems without express written approval of
24 // NVIDIA Corporation.
25 //
26 // Copyright (c) 2016-2020 NVIDIA Corporation. All rights reserved.
27 
28 
29 #ifndef NVBLASTMATH_H
30 #define NVBLASTMATH_H
31 
32 #include <math.h>
33 
34 namespace Nv
35 {
36 namespace Blast
37 {
38 
39 namespace VecMath
40 {
41 
42 
43 NV_INLINE void div(float a[3], float divisor)
44 {
45  for (int i = 0; i < 3; i++)
46  a[i] /= divisor;
47 }
48 
49 NV_INLINE void mul(float a[3], float multiplier)
50 {
51  for (int i = 0; i < 3; i++)
52  a[i] *= multiplier;
53 }
54 
55 NV_INLINE void add(const float a[3], float b[3])
56 {
57  for (int i = 0; i < 3; i++)
58  b[i] = a[i] + b[i];
59 }
60 
61 NV_INLINE void add(const float a[3], const float b[3], float r[3])
62 {
63  for (int i = 0; i < 3; i++)
64  r[i] = a[i] + b[i];
65 }
66 
67 NV_INLINE void sub(const float a[3], const float b[3], float r[3])
68 {
69  for (int i = 0; i < 3; i++)
70  r[i] = a[i] - b[i];
71 }
72 
73 NV_INLINE float dot(const float a[3], const float b[3])
74 {
75  float r = 0;
76  for (int i = 0; i < 3; i++)
77  r += a[i] * b[i];
78  return r;
79 }
80 
81 NV_INLINE float length(const float a[3])
82 {
83  return sqrtf(dot(a, a));
84 }
85 
86 NV_INLINE float dist(const float a[3], const float b[3])
87 {
88  float v[3];
89  sub(a, b, v);
90  return length(v);
91 }
92 
93 NV_INLINE float normal(const float a[3], float r[3])
94 {
95  float d = length(a);
96  for (int i = 0; i < 3; i++)
97  r[i] = a[i] / d;
98 
99  return d;
100 }
101 
102 
103 } // namespace VecMath
104 
105 } // namespace Blast
106 } // namespace Nv
107 
108 
109 #endif // #ifndef NVBLASTMATH_H
NV_INLINE void add(const float a[3], float b[3])
Definition: NvBlastMath.h:55
NV_INLINE float dist(const float a[3], const float b[3])
Definition: NvBlastMath.h:86
NV_INLINE float normal(const float a[3], float r[3])
Definition: NvBlastMath.h:93
NV_INLINE void sub(const float a[3], const float b[3], float r[3])
Definition: NvBlastMath.h:67
NV_INLINE void div(float a[3], float divisor)
Definition: NvBlastMath.h:43
#define NV_INLINE
Definition: NvPreprocessor.h:350
NV_INLINE float dot(const float a[3], const float b[3])
Definition: NvBlastMath.h:73
NV_INLINE void mul(float a[3], float multiplier)
Definition: NvBlastMath.h:49
NV_INLINE float length(const float a[3])
Definition: NvBlastMath.h:81
Definition: NvBlastArray.h:37