2 * Copyright 2013 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
23 #include <sys/types.h>
27 // -------------------------------------------------------------------------------------
32 class TVec3 : public TVecProductOperators<TVec3, T>,
33 public TVecAddOperators<TVec3, T>,
34 public TVecUnaryOperators<TVec3, T>,
35 public TVecComparisonOperators<TVec3, T>,
36 public TVecFunctions<TVec3, T>,
37 public TVecDebug<TVec3, T> {
39 enum no_init { NO_INIT };
42 typedef T const& const_reference;
43 typedef size_t size_type;
46 struct { T x, y, z; };
47 struct { T s, t, p; };
48 struct { T r, g, b; };
54 static constexpr size_t SIZE = 3;
55 inline constexpr size_type size() const { return SIZE; }
58 inline constexpr T const& operator[](size_t i) const {
59 #if __cplusplus >= 201402L
60 // only possible in C++0x14 with constexpr
66 inline T& operator[](size_t i) {
71 // -----------------------------------------------------------------------
72 // we want the compiler generated versions for these...
73 TVec3(const TVec3&) = default;
75 TVec3& operator = (const TVec3&) = default;
78 // leaves object uninitialized. use with caution.
80 constexpr TVec3(no_init) { }
82 // default constructor
83 constexpr TVec3() : x(0), y(0), z(0) { }
85 // handles implicit conversion to a tvec4. must not be explicit.
86 template<typename A, typename = typename std::enable_if<std::is_arithmetic<A>::value >::type>
87 constexpr TVec3(A v) : x(v), y(v), z(v) { }
89 template<typename A, typename B, typename C>
90 constexpr TVec3(A x, B y, C z) : x(x), y(y), z(z) { }
92 template<typename A, typename B>
93 constexpr TVec3(const TVec2<A>& v, B z) : x(v.x), y(v.y), z(z) { }
97 constexpr TVec3(const TVec3<A>& v) : x(v.x), y(v.y), z(v.z) { }
99 // cross product works only on vectors of size 3
100 template <typename RT>
102 constexpr TVec3 cross(const TVec3& u, const TVec3<RT>& v) {
110 } // namespace details
112 // ----------------------------------------------------------------------------------------
114 typedef details::TVec3<double> double3;
115 typedef details::TVec3<float> float3;
116 typedef details::TVec3<float> vec3;
117 typedef details::TVec3<half> half3;
118 typedef details::TVec3<int32_t> int3;
119 typedef details::TVec3<uint32_t> uint3;
120 typedef details::TVec3<int16_t> short3;
121 typedef details::TVec3<uint16_t> ushort3;
122 typedef details::TVec3<int8_t> byte3;
123 typedef details::TVec3<uint8_t> ubyte3;
125 // ----------------------------------------------------------------------------------------
126 } // namespace android