1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
//Matrix.cpp
//omitted includes
//many omitted constructors and functions
class Matrix
{
/*the Matrix class creates matrices that can
be multiplied with others from a 2D array
-dimensions rows,cols
-matrix[r][c]*/
public:
//constructors
Matrix();
//display function-error here
void display(void);
//variables
float **matrix;
int rows,cols;
};
Matrix::Matrix() //create an empty matrix with dimension(0,0)
{
rows=0;cols=0;
}
void Matrix::display() //diplays a matrix in a nice way
{ /*this function is causing a problem probly when it is called, however it works fine when called from the constructor*/
/*however it works with the Matrix class but not with the RotationMatrix...*/
cout.precision(3);
cout << "[";
for(int y=0; y<rows; y++)
{
if(y!=0)
cout << ' ';
cout << '[';
for(int x=0; x<cols; x++)
{
cout.width(11);
cout << matrix[y][x]; //this prints out random numbers... when called from outside
if(x!=cols-1)
cout << ',';
}
cout << ']';
if(y!=rows-1)
cout << '\n';
}
cout << "]\n";
}
class RotationMatrix: public Matrix
{
/*creates a rotation matrix derived
from the matrix class*/
public:
//constructors
RotationMatrix(float, char);
};
RotationMatrix::RotationMatrix(float angle, char axis=0) //creates a rotation matrix by x angle around a axis
{
rows=3; cols=3;
float temp[3][3];
//OMITTED statements initializing matrix with arguments given
//if...
//else
{
//testing matrix
temp= {{1,4,7},
{2,5,8},
{3,6,9}};
}
matrix=new float*[3];
for(int i=0;i<rows;i++) //initializes pointer to array
{
matrix[i]=new float[cols];
matrix[i]=temp[i];
}
}
|