]>
Dogcows Code - chaz/yoink/blob - cml/mathlib/misc.h
1 /* -*- C++ -*- ------------------------------------------------------------
3 Copyright (c) 2007 Jesse Anders and Demian Nave http://cmldev.net/
5 The Configurable Math Library (CML) is distributed under the terms of the
6 Boost Software License, v1.0 (see cml/LICENSE for details).
8 *-----------------------------------------------------------------------*/
16 #include <cml/mathlib/checking.h>
18 /* A few miscellaneous functions and helper classes.
20 * @note: This is somewhat ad-hoc and will probably all be replaced in a future
21 * version of the CML (I don't think I even bothered to document these functions
27 //////////////////////////////////////////////////////////////////////////////
29 //////////////////////////////////////////////////////////////////////////////
31 /** Return an N-d zero vector */
33 vector
< double, fixed
<N
> > zero()
35 typedef vector
< double, fixed
<N
> > vector_type
;
42 /** Return an N-d cardinal axis by index */
44 vector
< double, fixed
<N
> > axis(size_t i
)
47 detail::CheckValidArg(i
< N
);
49 typedef vector
< double, fixed
<N
> > vector_type
;
55 /** Return an NxM zero matrix */
56 template < size_t N
, size_t M
>
57 matrix
< double, fixed
<N
,M
>, row_basis
, row_major
> zero()
59 typedef matrix
< double, fixed
<N
,M
>, row_basis
, row_major
> matrix_type
;
66 /** Return an NxN identity matrix */
68 matrix
< double, fixed
<N
,N
>, row_basis
, row_major
> identity()
70 typedef matrix
< double, fixed
<N
,N
>, row_basis
, row_major
> matrix_type
;
77 /** Return an NxM identity transform */
78 template < size_t N
, size_t M
>
79 matrix
< double, fixed
<N
,M
>, row_basis
, row_major
> identity_transform()
81 typedef matrix
< double, fixed
<N
,M
>, row_basis
, row_major
> matrix_type
;
84 identity_transform(result
);
88 //////////////////////////////////////////////////////////////////////////////
90 //////////////////////////////////////////////////////////////////////////////
92 /** Return the 2D zero vector */
93 inline vector
< double, fixed
<2> > zero_2D() {
97 /** Return the 3D zero vector */
98 inline vector
< double, fixed
<3> > zero_3D() {
102 /** Return the 4D zero vector */
103 inline vector
< double, fixed
<4> > zero_4D() {
107 //////////////////////////////////////////////////////////////////////////////
109 //////////////////////////////////////////////////////////////////////////////
111 /** Return a 2D cardinal axis by index */
112 inline vector
< double, fixed
<2> > axis_2D(size_t i
) {
116 /** Return a 3D cardinal axis by index */
117 inline vector
< double, fixed
<3> > axis_3D(size_t i
) {
121 /** Return a the 2D x cardinal axis */
122 inline vector
< double, fixed
<2> > x_axis_2D() {
126 /** Return a the 2D y cardinal axis */
127 inline vector
< double, fixed
<2> > y_axis_2D() {
131 /** Return a the 3D x cardinal axis */
132 inline vector
< double, fixed
<3> > x_axis_3D() {
136 /** Return a the 3D y cardinal axis */
137 inline vector
< double, fixed
<3> > y_axis_3D() {
141 /** Return a the 3D z cardinal axis */
142 inline vector
< double, fixed
<3> > z_axis_3D() {
146 //////////////////////////////////////////////////////////////////////////////
148 //////////////////////////////////////////////////////////////////////////////
150 /** Return the 2x2 zero matrix */
151 inline matrix
< double, fixed
<2,2>, row_basis
, row_major
> zero_2x2() {
155 /** Return the 3x3 zero matrix */
156 inline matrix
< double, fixed
<3,3>, row_basis
, row_major
> zero_3x3() {
160 /** Return the 4x4 zero matrix */
161 inline matrix
< double, fixed
<4,4>, row_basis
, row_major
> zero_4x4() {
165 //////////////////////////////////////////////////////////////////////////////
167 //////////////////////////////////////////////////////////////////////////////
169 /** Return the 2x2 identity matrix */
170 inline matrix
< double, fixed
<2,2>, row_basis
, row_major
> identity_2x2() {
171 return identity
<2>();
174 /** Return the 3x3 identity matrix */
175 inline matrix
< double, fixed
<3,3>, row_basis
, row_major
> identity_3x3() {
176 return identity
<3>();
179 /** Return the 4x4 identity matrix */
180 inline matrix
< double, fixed
<4,4>, row_basis
, row_major
> identity_4x4() {
181 return identity
<4>();
184 //////////////////////////////////////////////////////////////////////////////
185 // Identity transform matrix
186 //////////////////////////////////////////////////////////////////////////////
188 /** Return a 3x2 identity transform */
189 inline matrix
< double,fixed
<3,2>,row_basis
,row_major
> identity_transform_3x2() {
190 return identity_transform
<3,2>();
193 /** Return a 2x3 identity transform */
194 inline matrix
< double,fixed
<2,3>,col_basis
,col_major
> identity_transform_2x3() {
195 return identity_transform
<2,3>();
198 /** Return a 4x3 identity transform */
199 inline matrix
< double,fixed
<4,3>,row_basis
,row_major
> identity_transform_4x3() {
200 return identity_transform
<4,3>();
203 /** Return a 3x4 identity transform */
204 inline matrix
< double,fixed
<3,4>,col_basis
,col_major
> identity_transform_3x4() {
205 return identity_transform
<3,4>();
This page took 0.046727 seconds and 4 git commands to generate.