Table of contents

MTVector

Derived from: none

Declared in: MTVector.h

Library: 3DM.so

This class represents a vector of floats. It can make operations easier to create 3d objects. You can use MTVector ton construct MTPoints objects.


Construction and Destruction


MTVector

                                                         
  

MTVector( )
MTVector( unsigned int nValues , const float * values )
MTVector( const MTVector & src )

Constructs a new vector. The first version creates an empty vector. The second one takes nValues from the array values. The third one copies the vector src.


~MTVector

                                                         
  

~MTVector( )

Destroys the vector.


Static Functions


Constant

                                                         
  

static MTVector Constant( float constant , unsigned int nValues )

Returns a constant vector. It is filled with nValues floats, equal to constant.


GradientInc

                                                         
  

static MTVector GradientInc( float val1 , float val2 , unsigned int nValues )

Returns a vector with nValues floats, going from val1 to var2, including var2.


GradientExc

                                                         
  

static MTVector GradientExc( float val1 , float val2 , unsigned int nValues )

Returns a vector with nValues floats, going from val1 to var2, excluding var2.


Random

                                                         
  

static MTVector Random( float val1 , float val2 , unsigned int nValues )

Returns a vector with nValues random floats, going from val1 to var2.


Member Functions


AddValue

                                                         
  

MTVector & AddValue( float val )

Concatenate the current vector with val. Returns the current vector.


AddValues

                                                         
  

MTVector & AddValues( const MTVector & vect )

Concatenate the current vector with vect. Returns the current vector.


cos

                                                         
  

void cos( )

Applies a cosine function to all the values in the current vector. The values should be in radiants.


NumValues

                                                         
  

inline unsigned int NumValues( ) const

Returns the number of values in the vector.


Repeat

                                                         
  

void Repeat( unsigned int each , unsigned int list )

Repeats each element of the vector each times, and the whole vector list times.

As an example, if a contains 1,2,3 and 4, in this order, it will contain these values after these operations:

a.Repeat(3,1) : 1,1,1,2,2,2,3,3,3,4,4,4

a.Repeat(1,3) : 1,2,3,4,1,2,3,4,1,2,3,4

a.Repeat(2,2) : 1,1,2,2,3,3,4,4,1,1,2,2,3,3,4,4


SetTo

                                                         
  

MTVector & SetTo( const MTVector & src )
MTVector & SetTo( unsigned int nValues , const float * values )

Replaces the current vector by a copy of src, or by a new vector made of the nValues floats stored in the array values.


sin

                                                         
  

void sin( )

Applies a sine function to all the values in the current vector. The values should be in radiants.


tan

                                                         
  

void tan( )

Applies a tangent function to all the values in the current vector. The values should be in radiants.


Values

                                                         
  

const float * Values( ) const

Returns the values stored in the vector, as an array of floats.


Operators

I've documented here all the operators, and sometimes the way I describe them isn't really easy to understand. But in fact they are very intuitive.

You can use the regular operators +,-,*,/,+=,-=,*= and /= with vectors. They work exactly as their float versions, except that they apply to each value of the vectors.

Thus [ 1 2 3 4 ] + [ 0 0 2 2 ] is [ 1 2 5 6), and [ 1 2 3 4 ] * [ 0 1 0 1 ] is [ 0 2 0 4 ]. The two vector used must have the same length

The assignation operator is here also. A = B copies B into A.

The & operator is the concatenation: [ 1 2 ] & [ 3 4 ] is [ 1 2 3 4 ].

And finally The ^ operator is an inderection operator


=

                                                         
  

inline MTVector & operator=( const MTVector & src )

Replaces the current vector by a copy of src.


&=

                                                         
  

inline MTVector & operator&=( const MTVector & src )
inline MTVector & operator&=( float val )

Concatenate the current vector with the vector src or the value val.


&

                                                         
  

MTVector operator&( const MTVector & src ) const
MTVector operator&( float val ) const

Builds and return a new vector, which is the concatenation of the current vector with the vector src or the value val. The current vector isn't modified.


+=

                                                         
  

MTVector & operator+=( const MTVector & src )
MTVector & operator+=( float val )

Adds to each value of the current vector the corresponding value from src, or the value val. The current vector and src must have the same length.


+

                                                         
  

MTVector operator+( const MTVector & src ) const
MTVector operator+( float val ) const

Builds a new vector made by adding each value of the current vector to the corresponding value in src, or the value val. Both vectors must have the same length. The current vector isn't modified.


-=

                                                         
  

MTVector & operator-=( const MTVector & src )
MTVector & operator-=( float val )

Substracts to each value of the current vector the corresponding value from src, or the value val. The current vector and src must have the same length.


-

                                                         
  

MTVector operator-( const MTVector & src ) const
MTVector operator-( float val ) const

Builds a new vector made by substracting to each value of the current vector the corresponding value in src, or the value val. Both vectors must have the same length. The current vector isn't modified.


*=

                                                         
  

MTVector & operator*=( const MTVector & src )
MTVector & operator*=( float val )

Multiplies to each value of the current vector the corresponding value from src, or the value val. The current vector and src must have the same length.


*

                                                         
  

MTVector operator*( const MTVector & src ) const
MTVector operator*( float val ) const

Builds a new vector made by multiplying to each value of the current vector the corresponding value in src, or the value val. Both vectors must have the same length. The current vector isn't modified.


/=

                                                         
  

MTVector & operator/=( const MTVector & src )
MTVector & operator/=( float val )

Divides each value of the current vector by the corresponding value from src, or the value val. The current vector and src must have the same length.


/

                                                         
  

MTVector operator/( const MTVector & src ) const
MTVector operator/( float val ) const

Builds a new vector made by dividing each value of the current vector by the corresponding value in src, or the value val. Both vectors must have the same length. The current vector isn't modified.


[]

                                                         
  

float & operator[]( unsigned int index ) const

This operator lets you access to the individual values of the vector. If index is out of range, the last value is returned.

You can use this operator to read and/or to write a value: A[i] = B[j], where A and B are MTVector objects, is valid and works as expected.


^

                                                         
  

MTVector operator^( const MTVector & src ) const

This is the indirection operator. If you do A = B ^ C, A will be a new vector, with B's length, and whose values will be as follows:

A[i] = C[B[i]]

B[i] is evaluated modulo the number of elements in C, so there is never an overflow.


Global Functions


cos

                                                         
  

extern MTVector cos( const MTVector & src )

Returns a new vector whose values are the cosines of the values in src.


sin

                                                         
  

extern MTVector sin( const MTVector & src )

Returns a new vector whose values are the sines of the values in src.


tan

                                                         
  

extern MTVector tan( const MTVector & src )

Returns a new vector whose values are the tangents of the values in src.