1 /**********************************************************************
2 Copyright (c) 2016 Advanced Micro Devices, Inc. All rights reserved.
3 
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10 
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13 
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21 ********************************************************************/
22 module radeonrays.math.float3;
23 
24 extern(C++,"RadeonRays")
25 {
26 	struct float3
27 	{
28 	public:
29 		//float3(float xx = 0.f, float yy = 0.f, float zz = 0.f, float ww = 0.f) : x(xx), y(yy), z(zz), w(ww) {}
30 		//this(float xx = 0.f, float yy = 0.f, float zz = 0.f, float ww = 0.f)
31 
32 		/*float& operator [](int i)       { return *(&x + i); }
33 		float  operator [](int i) const { return *(&x + i); }
34 		float3 operator-() const        { return float3(-x, -y, -z); }*/
35 		
36 		/*float  sqnorm() const           { return x*x + y*y + z*z; }
37 		void   normalize()              { (*this)/=(std::sqrt(sqnorm()));} 
38 		
39 		float3& operator += (float3 const& o) { x+=o.x; y+=o.y; z+= o.z; return *this;}
40 		float3& operator -= (float3 const& o) { x-=o.x; y-=o.y; z-= o.z; return *this;}
41 		float3& operator *= (float3 const& o) { x*=o.x; y*=o.y; z*= o.z; return *this;}
42 		float3& operator *= (float c) { x*=c; y*=c; z*= c; return *this;}
43 		float3& operator /= (float c) { float cinv = 1.f/c; x*=cinv; y*=cinv; z*=cinv; return *this;}*/
44 		
45 		float x, y, z, w;
46 	};
47 	
48 	alias float3 float4;
49 	
50 	
51 	/*inline float3 operator+(float3 const& v1, float3 const& v2)
52 	{
53 		float3 res = v1;
54 		return res+=v2;
55 	}
56 	
57 	inline float3 operator-(float3 const& v1, float3 const& v2)
58 	{
59 		float3 res = v1;
60 		return res-=v2;
61 	}
62 	
63 	inline float3 operator*(float3 const& v1, float3 const& v2)
64 	{
65 		float3 res = v1;
66 		return res*=v2;
67 	}
68 	
69 	inline float3 operator*(float3 const& v1, float c)
70 	{
71 		float3 res = v1;
72 		return res*=c;
73 	}
74 	
75 	inline float3 operator*(float c, float3 const& v1)
76 	{
77 		return operator*(v1, c);
78 	}
79 	
80 	inline float dot(float3 const& v1, float3 const& v2)
81 	{
82 		return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
83 	}
84 	
85 	inline float3 normalize(float3 const& v)
86 	{
87 		float3 res = v;
88 		res.normalize();
89 		return res;
90 	}
91 	
92 	inline float3 cross(float3 const& v1, float3 const& v2)
93 	{
94 		/// |i     j     k|
95 		/// |v1x  v1y  v1z|
96 		/// |v2x  v2y  v2z|
97 		return float3(v1.y * v2.z - v2.y * v1.z, v2.x * v1.z - v1.x * v2.z, v1.x * v2.y - v1.y * v2.x);
98 	}
99 	
100 	inline float3 vmin(float3 const& v1, float3 const& v2)
101 	{
102 		return float3(std::min(v1.x, v2.x), std::min(v1.y, v2.y), std::min(v1.z, v2.z));
103 	}
104 	
105 	inline void vmin(float3 const& v1, float3 const& v2, float3& v)
106 	{
107 		v.x = std::min(v1.x, v2.x); 
108 		v.y = std::min(v1.y, v2.y);
109 		v.z = std::min(v1.z, v2.z);
110 	}
111 	
112 	inline float3 vmax(float3 const& v1, float3 const& v2)
113 	{
114 		return float3(std::max(v1.x, v2.x), std::max(v1.y, v2.y), std::max(v1.z, v2.z));
115 	}
116 	
117 	inline void vmax(float3 const& v1, float3 const& v2, float3& v)
118 	{
119 		v.x = std::max(v1.x, v2.x); 
120 		v.y = std::max(v1.y, v2.y);
121 		v.z = std::max(v1.z, v2.z);
122 	}*/
123 }