VR-Link API Documentation for DIS
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
13.1 - Vector and Matrix Classes

Table of Contents

This section describes the classes that you use for vectors and matrices, DtVector and DtDcm.

13.1.1 Using the DtVector Class

You can use the DtVector class (defined in vlVector.h) to represent vectors in three dimensional space.

You can initialize DtVectors with their three components, as in:

DtVector vec(10.0, 20.0, 30.0);

The default constructor, which takes no arguments, constructs a vector containing three zeros.

The copy constructor, assignment operator, equivalence, and subscripting operators are defined, so you can do things like:

DtVector vec(10.0, 20.0, 30.0);
DtVector vec2(vec);
DtVector vec3 = vec;
DtVector vec4;
vec4 = vec;
if (vec == vec2) {...}

and:

double x = vec[0];
double y = vec[1];
double z = vec[2];

or:

vec[0] = x;
vec[1] = y;
vec[2] = z;

DtVector also has a string() member function that returns a text representation of the contents of the vector, for example:

{ 10.000, 20.000, 30.000}

The following static member functions of DtVector return some commonly used vectors:

zero() {0,0,0}
i() {1,0,0}
j() {0,1,0}
k() {0,0,1}
ones() {1,1,1}

13.1.2 Using the DtDcm Class

DtDcm (defined in vlDcm.h) is used to represent 3x3 matrices. The name DCM stands for direction cosine matrix, and reflects the fact that we often use the class to store that particular type of matrix to represent an orientation. (Alternatively, you can represent orientation as a set of three Euler angles in the Tait Bryan sequence, using the DtTaitBryan class. For more information, please see 13.2 - Orientation, Euler Angles, and DtTaitBryan.)

A DtDcm can be constructed from its components, as in:

DtDcm mat(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0);

or from three component vectors:

If the constructor is used with no arguments, a matrix containing nine zeros is constructed.

The copy constructor and assignment operators are defined, so you can do things like:

DtDcm mat(1,2,3,4,5,6,7,8,9);
DtDcm mat2(mat);
DtDcm mat3 = mat;
DtDcm mat4;
mat4 = mat;

The subscripting operator is defined as well, so you can obtain any of the three vectors that make up the matrix:

DtVector firstRow = mat[0];

In conjunction with DtVector's subscripting operator, the familiar double subscript syntax is supported:

double upperLeft = mat[0][0];
double lowerRight = mat[2][2];

or:

mat[0][0] = 10.0;
mat[2][2] = 20.0;

DtDcm has static member functions, zero() and identity(), that return the zero matrix and identity matrix respectively.

13.1.3 DtVector and DtDcm Semantics

Although VR-Link functions usually employ pass-by-pointer semantics when expecting objects that they will modify, functions that operate on DtVectors and DtDcms are exceptions. These objects are usually passed to VR-Link functions by reference, so that the subscripting operator can be used without the awkwardness of having to dereference a pointer. In functions that do not change DtVectors and DtDcms, they are passed by const reference, just like other VR-Link classes. The table lists typedefs used to make this explicit.

DtVector and DtDcm typedefs
Function Equivalent function
DtVectorRef DtVector&
DtDcmRef DtDcm&
DtConstVector const DtVector&
DtConstDcm const DtDcm&

DtVector can be passed to a function that takes a DtVectorRef or DtConstVector, while a DtDcm can be passed to a function that takes a DtDcmRef or DtConstDcm.

13.1.4 Vector and Matrix Manipulation Functions

LibMatrix.h contains C-style functions that operate on DtVector and DtDcm. The standard operations are included, such as:

[Home] [Top of Page] [Orientation, Euler Angles, and DtTaitBryan >>]


Document ID: Generated on Mon Apr 25 03:39:01 EDT 2022 from SVN revision 242502
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)