37#include "../math/LinearSpace.h"
38#include "../math/box.h"
43#define VectorT typename L::vector_t
44#define ScalarT typename L::vector_t::scalar_t
73 inline __both__
AffineSpaceT (
const L & other ) { l = other ; p = VectorT(ZeroTy()); }
76 inline __both__
AffineSpaceT(
const VectorT& vx,
const VectorT& vy,
const VectorT& vz,
const VectorT& p ) : l(vx,vy,vz), p(p) {}
77 inline __both__
AffineSpaceT(
const L& l,
const VectorT& p ) : l(l), p(p) {}
85 inline AffineSpaceT( ZeroTy ) : l(ZeroTy()), p(ZeroTy()) {}
86 inline AffineSpaceT( OneTy ) : l(OneTy()), p(ZeroTy()) {}
101 static inline AffineSpaceT rotate(
const VectorT& p,
const VectorT& u,
const ScalarT& r) {
return translate(+p) *
rotate(u,r) * translate(-p); }
105 VectorT Z = normalize(point-eye);
106 VectorT U = normalize(cross(Z,up));
107 VectorT V = cross(U,Z);
118 template<
typename L>
inline AffineSpaceT<L> operator +(
const AffineSpaceT<L>& a ) {
return AffineSpaceT<L>(+a.l,+a.p); }
121 AffineSpaceT<L> rcp(
const AffineSpaceT<L>& a ) {
123 return AffineSpaceT<L>(il,-(il*a.p));
130 template<
typename L>
inline AffineSpaceT<L> operator +(
const AffineSpaceT<L>& a,
const AffineSpaceT<L>& b ) {
return AffineSpaceT<L>(a.l+b.l,a.p+b.p); }
131 template<
typename L>
inline AffineSpaceT<L> operator -(
const AffineSpaceT<L>& a,
const AffineSpaceT<L>& b ) {
return AffineSpaceT<L>(a.l-b.l,a.p-b.p); }
133 template<
typename L>
inline __both__ AffineSpaceT<L> operator *(
const ScalarT & a,
const AffineSpaceT<L>& b ) {
return AffineSpaceT<L>(a*b.l,a*b.p); }
134 template<
typename L>
inline __both__ AffineSpaceT<L> operator *(
const AffineSpaceT<L>& a,
const AffineSpaceT<L>& b ) {
return AffineSpaceT<L>(a.l*b.l,a.l*b.p+a.p); }
135 template<
typename L>
inline AffineSpaceT<L> operator /(
const AffineSpaceT<L>& a,
const AffineSpaceT<L>& b ) {
return a * rcp(b); }
136 template<
typename L>
inline AffineSpaceT<L> operator /(
const AffineSpaceT<L>& a,
const ScalarT & b ) {
return a * rcp(b); }
138 template<
typename L>
inline AffineSpaceT<L>& operator *=( AffineSpaceT<L>& a,
const AffineSpaceT<L>& b ) {
return a = a * b; }
139 template<
typename L>
inline AffineSpaceT<L>& operator *=( AffineSpaceT<L>& a,
const ScalarT & b ) {
return a = a * b; }
140 template<
typename L>
inline AffineSpaceT<L>& operator /=( AffineSpaceT<L>& a,
const AffineSpaceT<L>& b ) {
return a = a / b; }
141 template<
typename L>
inline AffineSpaceT<L>& operator /=( AffineSpaceT<L>& a,
const ScalarT & b ) {
return a = a / b; }
143 template<
typename L>
inline __both__
const VectorT xfmPoint (
const AffineSpaceT<L>& m,
const VectorT& p) {
return madd(VectorT(p.x),m.l.vx,madd(VectorT(p.y),m.l.vy,madd(VectorT(p.z),m.l.vz,m.p))); }
144 template<
typename L>
inline __both__
const VectorT xfmVector(
const AffineSpaceT<L>& m,
const VectorT& v) {
return xfmVector(m.l,v); }
145 template<
typename L>
inline __both__
const VectorT xfmNormal(
const AffineSpaceT<L>& m,
const VectorT& n) {
return xfmNormal(m.l,n); }
152 template<
typename L>
inline bool operator ==(
const AffineSpaceT<L>& a,
const AffineSpaceT<L>& b ) {
return a.l == b.l && a.p == b.p; }
153 template<
typename L>
inline bool operator !=(
const AffineSpaceT<L>& a,
const AffineSpaceT<L>& b ) {
return a.l != b.l || a.p != b.p; }
159 template<
typename L>
inline std::ostream& operator<<(std::ostream& cout,
const AffineSpaceT<L>& m) {
160 return cout <<
"{ l = " << m.l <<
", p = " << m.p <<
" }";
167 using AffineSpace2f = AffineSpaceT<LinearSpace2f>;
168 using AffineSpace3f = AffineSpaceT<LinearSpace3f>;
169 using AffineSpace3fa = AffineSpaceT<LinearSpace3fa>;
170 using OrthonormalSpace3f = AffineSpaceT<Quaternion3f >;
172 using affine2f = AffineSpace2f;
173 using affine3f = AffineSpace3f;
184 inline __both__ box3f xfmBounds(
const affine3f &xfm,
188 const vec3f lo = box.lower;
189 const vec3f hi = box.upper;
190 dst.extend(xfmPoint(xfm,vec3f(lo.x,lo.y,lo.z)));
191 dst.extend(xfmPoint(xfm,vec3f(lo.x,lo.y,hi.z)));
192 dst.extend(xfmPoint(xfm,vec3f(lo.x,hi.y,lo.z)));
193 dst.extend(xfmPoint(xfm,vec3f(lo.x,hi.y,hi.z)));
194 dst.extend(xfmPoint(xfm,vec3f(hi.x,lo.y,lo.z)));
195 dst.extend(xfmPoint(xfm,vec3f(hi.x,lo.y,hi.z)));
196 dst.extend(xfmPoint(xfm,vec3f(hi.x,hi.y,lo.z)));
197 dst.extend(xfmPoint(xfm,vec3f(hi.x,hi.y,hi.z)));
Definition: AffineSpace.h:52
static AffineSpaceT lookat(const VectorT &eye, const VectorT &point, const VectorT &up)
Definition: AffineSpace.h:104
static AffineSpaceT rotate(const ScalarT &r)
Definition: AffineSpace.h:95
static AffineSpaceT scale(const VectorT &s)
Definition: AffineSpace.h:89
static AffineSpaceT rotate(const VectorT &p, const VectorT &u, const ScalarT &r)
Definition: AffineSpace.h:101
static AffineSpaceT translate(const VectorT &p)
Definition: AffineSpace.h:92
static AffineSpaceT rotate(const VectorT &u, const ScalarT &r)
Definition: AffineSpace.h:98
static LinearSpace2 rotate(const scalar_t &r)
Definition: LinearSpace.h:102