HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VEX_KVexMath.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: VEX_KVexMath.h (VEX Library, C++)
7  *
8  * COMMENTS: Support math functions for KVEX
9  */
10 
11 // Only valid when compiling KVEX to C++
12 #if defined(__VEX_COMPILING_KVEX__)
13 
14 #ifndef __VEX_KVexMath__
15 #define __VEX_KVexMath__
16 
17 #define KVEX_FUNC_FV(NAME, IMPL) \
18  template <typename VEC_T> inline VEXfloat \
19  NAME(const VEC_T &v) { return IMPL; } \
20  /* end macro */
21 
22 KVEX_FUNC_FV(length__vxmgl_F_U, v.length())
23 KVEX_FUNC_FV(length__vxmgl_F_V, v.length())
24 KVEX_FUNC_FV(length__vxmgl_F_P, v.length())
25 
26 KVEX_FUNC_FV(length2__vxmgl_F_U, v.length2())
27 KVEX_FUNC_FV(length2__vxmgl_F_V, v.length2())
28 KVEX_FUNC_FV(length2__vxmgl_F_P, v.length2())
29 
30 #define KVEX_FUNC_VVVF(NAME, IMPL) \
31  template <typename VEC_T> inline VEC_T \
32  NAME(const VEC_T &a, const VEC_T &b, VEXfloat c) { return IMPL; } \
33  /* end macro */
34 
35 inline VEXfloat
36 lerp__vxmgl_F_FFF(VEXfloat a, VEXfloat b, VEXfloat c)
37 {
38  return a + (b-a)*c;
39 }
40 
41 KVEX_FUNC_VVVF(lerp__vxmgl_U_UUF, a + (b-a)*c)
42 KVEX_FUNC_VVVF(lerp__vxmgl_V_VVF, a + (b-a)*c)
43 KVEX_FUNC_VVVF(lerp__vxmgl_P_PPF, a + (b-a)*c)
44 
45 inline VEXvec3
46 xyztorgb__vxmgl_V_V(const VEXvec3 &xyz)
47 {
48  return VEXvec3(3.2406 * xyz.x() - 1.5372 * xyz.y() - 0.4986 * xyz.z(),
49  -0.9689 * xyz.x() + 1.8758 * xyz.y() + 0.0415 * xyz.z(),
50  0.0557 * xyz.x() - 0.2040 * xyz.y() + 1.0570 * xyz.z());
51 }
52 
53 inline VEXvec3
54 rgbtoxyz__vxmgl_V_V(const VEXvec3 &rgb)
55 {
56  return VEXvec3(0.4124 * rgb.x() + 0.3576 * rgb.y() + 0.1805 * rgb.z(),
57  0.2126 * rgb.x() + 0.7152 * rgb.y() + 0.0722 * rgb.z(),
58  0.0193 * rgb.x() + 0.1192 * rgb.y() + 0.9505 * rgb.z());
59 }
60 
61 #define KVEX_COMPWISE_TERNARY_BASE(FUNC, FLT_FUNC) \
62  inline VEXvec2 FUNC##_U_UUU(const VEXvec2 &a, const VEXvec2 &b, const VEXvec2 &c) { \
63  return VEXvec2(FLT_FUNC(a.x(), b.x(), c.x()), \
64  FLT_FUNC(a.y(), b.y(), c.y())); \
65  } \
66  inline VEXvec3 FUNC##_V_VVV(const VEXvec3 &a, const VEXvec3 &b, const VEXvec3 &c) { \
67  return VEXvec3(FLT_FUNC(a.x(), b.x(), c.x()), \
68  FLT_FUNC(a.y(), b.y(), c.y()), \
69  FLT_FUNC(a.z(), b.z(), c.y())); \
70  } \
71  inline VEXvec4 FUNC##_P_PPP(const VEXvec4 &a, const VEXvec4 &b, const VEXvec4 &c) { \
72  return VEXvec4(FLT_FUNC(a.x(), b.x(), c.x()), \
73  FLT_FUNC(a.y(), b.y(), c.y()), \
74  FLT_FUNC(a.z(), b.z(), c.z()), \
75  FLT_FUNC(a.w(), b.w(), c.w())); \
76  } \
77  /* end macro */
78 
79 #define KVEX_COMPWISE_TERNARY(FUNC) \
80  KVEX_COMPWISE_TERNARY(FUNC) \
81  KVEX_COMPWISE_TERNARY_BASE(FUNC, FUNC##_F_FFF) \
82  /* end macro */
83 
84 #define KVEX_WRAP_TERNARY(FUNC, WRAP_FUNC) \
85  inline VEXvec2 FUNC##_U_UUU(const VEXvec2 &a, const VEXvec2 &b, const VEXvec2 &c) { \
86  return WRAP_FUNC(a, b, c); \
87  } \
88  inline VEXvec3 FUNC##_V_VVV(const VEXvec3 &a, const VEXvec3 &b, const VEXvec3 &c) { \
89  return WRAP_FUNC(a, b, c); \
90  } \
91  inline VEXvec4 FUNC##_P_PPP(const VEXvec4 &a, const VEXvec4 &b, const VEXvec4 &c) { \
92  return WRAP_FUNC(a, b, c); \
93  } \
94 
95 #if defined(KVEX_CPP_UT)
96  KVEX_COMPWISE_TERNARY_BASE(clamp__vxmgl, SYSclamp)
97 #endif
98 
99 #if defined(KVEX_CPP_GUT)
100  KVEX_WRAP_TERNARY(clamp_vxmgl, clamp)
101 #endif
102 
103 #undef KVEX_FUNC_FV
104 #undef KVEX_FUNC_VVVF
105 #undef KVEX_COMPWISE_TERNARY
106 #undef KVEX_COMPWISE_TERNARY_BASE
107 
108 #endif // __VEX_COMPILING_KVEX__
109 
110 #endif
GLenum clamp
Definition: glcorearb.h:1234
const GLdouble * v
Definition: glcorearb.h:837
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
typename VEX_PrecisionResolver< P >::vec3_type VEXvec3
Definition: VEX_PodTypes.h:70
typename VEX_PrecisionResolver< P >::float_type VEXfloat
Definition: VEX_PodTypes.h:67
UT_Vector3T< T > SYSclamp(const UT_Vector3T< T > &v, const UT_Vector3T< T > &min, const UT_Vector3T< T > &max)
Definition: UT_Vector3.h:1059
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222