PeriDyno 1.0.0
Loading...
Searching...
No Matches
Vector3D.h
Go to the documentation of this file.
1#pragma once
2#include <glm/vec3.hpp>
3#include <iostream>
4
5#include "VectorBase.h"
6
7namespace dyno {
8
9 template <typename T, int Dim> class SquareMatrix;
10
11 /*
12 * Vector<T,3> are defined for C++ fundamental integer types and floating-point types
13 */
14
15 template <typename T>
16 class Vector<T, 3>
17 {
18 public:
19 typedef T VarType;
20
21 DYN_FUNC Vector();
22 DYN_FUNC explicit Vector(T);
23 DYN_FUNC Vector(T x, T y, T z);
24 DYN_FUNC Vector(const Vector<T, 3>&);
25 DYN_FUNC ~Vector();
26
27 DYN_FUNC static int dims() { return 3; }
28
29 DYN_FUNC T& operator[] (unsigned int);
30 DYN_FUNC const T& operator[] (unsigned int) const;
31
32 DYN_FUNC const Vector<T, 3> operator+ (const Vector<T, 3> &) const;
33 DYN_FUNC Vector<T, 3>& operator+= (const Vector<T, 3> &);
34 DYN_FUNC const Vector<T, 3> operator- (const Vector<T, 3> &) const;
35 DYN_FUNC Vector<T, 3>& operator-= (const Vector<T, 3> &);
36 DYN_FUNC const Vector<T, 3> operator* (const Vector<T, 3> &) const;
37 DYN_FUNC Vector<T, 3>& operator*= (const Vector<T, 3> &);
38 DYN_FUNC const Vector<T, 3> operator/ (const Vector<T, 3> &) const;
39 DYN_FUNC Vector<T, 3>& operator/= (const Vector<T, 3> &);
40
41
42 DYN_FUNC Vector<T, 3>& operator= (const Vector<T, 3> &);
43
44 DYN_FUNC bool operator== (const Vector<T, 3> &) const;
45 DYN_FUNC bool operator!= (const Vector<T, 3> &) const;
46
47 DYN_FUNC const Vector<T, 3> operator* (T) const;
48 DYN_FUNC const Vector<T, 3> operator- (T) const;
49 DYN_FUNC const Vector<T, 3> operator+ (T) const;
50 DYN_FUNC const Vector<T, 3> operator/ (T) const;
51
52 DYN_FUNC Vector<T, 3>& operator+= (T);
53 DYN_FUNC Vector<T, 3>& operator-= (T);
54 DYN_FUNC Vector<T, 3>& operator*= (T);
55 DYN_FUNC Vector<T, 3>& operator/= (T);
56
57 DYN_FUNC const Vector<T, 3> operator - (void) const;
58
59 DYN_FUNC T norm() const;
60 DYN_FUNC T normSquared() const;
61 DYN_FUNC Vector<T, 3>& normalize();
62 DYN_FUNC Vector<T, 3> cross(const Vector<T, 3> &) const;
63 DYN_FUNC T dot(const Vector<T, 3>&) const;
64 // DYN_FUNC const SquareMatrix<T,3> outerProduct(const Vector<T,3>&) const;
65
66 DYN_FUNC Vector<T, 3> minimum(const Vector<T, 3>&) const;
67 DYN_FUNC Vector<T, 3> maximum(const Vector<T, 3>&) const;
68
69 DYN_FUNC T* getDataPtr() { return &data_.x; }
70
71 friend std::ostream& operator<<(std::ostream &out, const Vector<T, 3>& vec)
72 {
73 out << "(" << vec[0] << ", " << vec[1] << ", " << vec[2] << ")";
74 return out;
75 }
76
77 public:
78 union
79 {
80#ifdef VK_BACKEND
81 DYN_ALIGN_16 glm::tvec3<T> data_; //default: zero vector
82 struct { T x, y, z, dummy; };
83#else
84 glm::tvec3<T> data_; //default: zero vector
85 struct { T x, y, z; };
86#endif // VK_BACKEND
87 };
88 };
89
90 template class Vector<float, 3>;
91 template class Vector<double, 3>;
92 //convenient typedefs
99
100} //end of namespace dyno
101
102#include "Vector3D.inl"
#define DYN_ALIGN_16
Definition VectorBase.h:10
DYN_FUNC ~Vector()
Definition VectorBase.h:27
DYN_FUNC Vector()
Definition VectorBase.h:26
#define T(t)
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
Vector< uint, 3 > Vec3u
Definition Vector3D.h:96
DYN_FUNC Vector< T, 3 > cross(Vector< T, 3 > const &U, Vector< T, 3 > const &V)
Definition SimpleMath.h:211
Vector< int, 3 > Vec3i
Definition Vector3D.h:95
DYN_FUNC T dot(Vector< T, 2 > const &U, Vector< T, 2 > const &V)
Definition SimpleMath.h:199
Vector< char, 3 > Vec3c
Definition Vector3D.h:97
Vector< double, 3 > Vec3d
Definition Vector3D.h:94
DYN_FUNC const Complex< T > operator/(S scale, const Complex< T > &complex)
Definition Complex.inl:253
DYN_FUNC T minimum(const T &v0, const T &v1)
Definition SimpleMath.h:120
DYN_FUNC const Complex< T > operator*(S scale, const Complex< T > &complex)
Definition Complex.inl:247
Vector< float, 3 > Vec3f
Definition Vector3D.h:93
DYN_FUNC bool operator==(const priority_queue< T, Container, Compare > &a, const priority_queue< T, Container, Compare > &b)
DYN_FUNC bool operator!=(const priority_queue< T, Container, Compare > &a, const priority_queue< T, Container, Compare > &b)
DYN_FUNC T maximum(const T &v0, const T &v1)
Definition SimpleMath.h:160
DYN_FUNC const Complex< T > operator-(S scale, const Complex< T > &complex)
Definition Complex.inl:241
Vector< uchar, 3 > Vec3uc
Definition Vector3D.h:98
DYN_FUNC const Complex< T > operator+(S scale, const Complex< T > &complex)
Definition Complex.inl:235
TEMPLATE_TYPENAME_T VEC2_T normalize(const VEC2_T &v)
Definition vgMath.h:421