Skip to content

Commit

Permalink
for issue #80
Browse files Browse the repository at this point in the history
  • Loading branch information
NevilClavain committed Jul 31, 2023
1 parent 4b0047d commit 56fd47f
Show file tree
Hide file tree
Showing 5 changed files with 281 additions and 266 deletions.
5 changes: 2 additions & 3 deletions drawspacecore_project/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ ${CMAKE_SOURCE_DIR}/src/ds_types.h
${CMAKE_SOURCE_DIR}/src/exceptions.h
${CMAKE_SOURCE_DIR}/src/primitives.h
${CMAKE_SOURCE_DIR}/src/singleton.h
${CMAKE_SOURCE_DIR}/src/maths.h
)

source_group(maths FILES
${CMAKE_SOURCE_DIR}/src/maths.h
${CMAKE_SOURCE_DIR}/src/quaternion.h
${CMAKE_SOURCE_DIR}/src/quaternion.cpp
${CMAKE_SOURCE_DIR}/src/matrix.cpp
${CMAKE_SOURCE_DIR}/src/matrix.h
)

source_group(aspect FILES
Expand Down Expand Up @@ -219,8 +220,6 @@ ${CMAKE_SOURCE_DIR}/src/filesystem.cpp
${CMAKE_SOURCE_DIR}/src/filesystem.h
${CMAKE_SOURCE_DIR}/src/jsonparser.cpp
${CMAKE_SOURCE_DIR}/src/jsonparser.h
${CMAKE_SOURCE_DIR}/src/matrix.cpp
${CMAKE_SOURCE_DIR}/src/matrix.h
${CMAKE_SOURCE_DIR}/src/md5.h
${CMAKE_SOURCE_DIR}/src/memalloc.cpp
${CMAKE_SOURCE_DIR}/src/memalloc.h
Expand Down
157 changes: 157 additions & 0 deletions src/matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,163 @@ Matrix::Matrix( void )
zero();
}

void Matrix::zero(void)
{
m_matrix[0][0] = 0.0;
m_matrix[0][1] = 0.0;
m_matrix[0][2] = 0.0;
m_matrix[0][3] = 0.0;

m_matrix[1][0] = 0.0;
m_matrix[1][1] = 0.0;
m_matrix[1][2] = 0.0;
m_matrix[1][3] = 0.0;

m_matrix[2][0] = 0.0;
m_matrix[2][1] = 0.0;
m_matrix[2][2] = 0.0;
m_matrix[2][3] = 0.0;

m_matrix[3][0] = 0.0;
m_matrix[3][1] = 0.0;
m_matrix[3][2] = 0.0;
m_matrix[3][3] = 0.0;

m_configinfos.type = ConfigurationType::CONFIG_ZERO;

m_configinfos.values[0] = 0.0;
m_configinfos.values[1] = 0.0;
m_configinfos.values[2] = 0.0;
m_configinfos.values[3] = 0.0;
}

void Matrix::identity(void)
{
zero();
m_matrix[0][0] = 1.0;
m_matrix[1][1] = 1.0;
m_matrix[2][2] = 1.0;
m_matrix[3][3] = 1.0;

m_configinfos.type = ConfigurationType::CONFIG_IDENTITY;

m_configinfos.values[0] = 0.0;
m_configinfos.values[1] = 0.0;
m_configinfos.values[2] = 0.0;
m_configinfos.values[3] = 0.0;
}

void Matrix::translation(dsreal p_x, dsreal p_y, dsreal p_z)
{
identity();
m_matrix[3][0] = p_x;
m_matrix[3][1] = p_y;
m_matrix[3][2] = p_z;

m_configinfos.type = ConfigurationType::CONFIG_TRANSLATION;
m_configinfos.values[0] = p_x;
m_configinfos.values[1] = p_y;
m_configinfos.values[2] = p_z;
m_configinfos.values[3] = 0.0;

}

void Matrix::translation(const Utils::Vector& p_pos)
{
identity();
m_matrix[3][0] = p_pos[0];
m_matrix[3][1] = p_pos[1];
m_matrix[3][2] = p_pos[2];

m_configinfos.type = ConfigurationType::CONFIG_TRANSLATION;
m_configinfos.values[0] = p_pos[0];
m_configinfos.values[1] = p_pos[1];
m_configinfos.values[2] = p_pos[2];
m_configinfos.values[3] = 0.0;

}

void Matrix::perspective(dsreal p_w, dsreal p_h, dsreal p_zn, dsreal p_zf)
{
zero();
m_matrix[0][0] = 2.0f * p_zn / p_w;
m_matrix[1][1] = 2.0f * p_zn / p_h;
m_matrix[2][2] = p_zf / (p_zf - p_zn);
m_matrix[3][2] = -p_zn * m_matrix[2][2];
m_matrix[2][3] = 1.0f;

m_configinfos.type = ConfigurationType::CONFIG_UNDETERMINED;
}


void Matrix::transpose(void)
{
dsreal msave[4][4];

memcpy(&msave, m_matrix, 16 * sizeof(dsreal));

m_matrix[0][1] = msave[1][0];
m_matrix[0][2] = msave[2][0];
m_matrix[0][3] = msave[3][0];

m_matrix[1][0] = msave[0][1];

m_matrix[1][2] = msave[2][1];
m_matrix[1][3] = msave[3][1];

m_matrix[2][0] = msave[0][2];
m_matrix[2][1] = msave[1][2];

m_matrix[2][3] = msave[3][2];

m_matrix[3][0] = msave[0][3];
m_matrix[3][1] = msave[1][3];
m_matrix[3][2] = msave[2][3];

m_configinfos.type = ConfigurationType::CONFIG_UNDETERMINED;
}

void Matrix::scale(dsreal p_sx, dsreal p_sy, dsreal p_sz)
{
zero();
m_matrix[0][0] = p_sx;
m_matrix[1][1] = p_sy;
m_matrix[2][2] = p_sz;
m_matrix[3][3] = 1.0;

m_configinfos.type = ConfigurationType::CONFIG_SCALING;
m_configinfos.values[0] = p_sx;
m_configinfos.values[1] = p_sy;
m_configinfos.values[2] = p_sz;
m_configinfos.values[3] = 0.0;

}

void Matrix::scale(const Utils::Vector& p_pos)
{
zero();
m_matrix[0][0] = p_pos[0];
m_matrix[1][1] = p_pos[1];
m_matrix[2][2] = p_pos[2];
m_matrix[3][3] = 1.0;

m_configinfos.type = ConfigurationType::CONFIG_SCALING;
m_configinfos.values[0] = p_pos[0];
m_configinfos.values[1] = p_pos[1];
m_configinfos.values[2] = p_pos[2];
m_configinfos.values[3] = 0.0;

}


void Matrix::clearTranslation(void)
{
m_matrix[3][0] = 0.0;
m_matrix[3][1] = 0.0;
m_matrix[3][2] = 0.0;

m_configinfos.type = ConfigurationType::CONFIG_UNDETERMINED;
}

void Matrix::inverse( void )
{
Expand Down
170 changes: 11 additions & 159 deletions src/matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,47 +46,17 @@ namespace DrawSpace

};

typedef struct
struct ConfigurationInfo
{
ConfigurationType type;
Utils::Vector values;

} ConfigurationInfo;
};


Matrix( void );
~Matrix( void ) = default;

void zero( void )
{
m_matrix[0][0] = 0.0;
m_matrix[0][1] = 0.0;
m_matrix[0][2] = 0.0;
m_matrix[0][3] = 0.0;

m_matrix[1][0] = 0.0;
m_matrix[1][1] = 0.0;
m_matrix[1][2] = 0.0;
m_matrix[1][3] = 0.0;

m_matrix[2][0] = 0.0;
m_matrix[2][1] = 0.0;
m_matrix[2][2] = 0.0;
m_matrix[2][3] = 0.0;

m_matrix[3][0] = 0.0;
m_matrix[3][1] = 0.0;
m_matrix[3][2] = 0.0;
m_matrix[3][3] = 0.0;

m_configinfos.type = ConfigurationType::CONFIG_ZERO;

m_configinfos.values[0] = 0.0;
m_configinfos.values[1] = 0.0;
m_configinfos.values[2] = 0.0;
m_configinfos.values[3] = 0.0;

}
void zero(void);

dsreal operator()( int p_row, int p_col ) const
{
Expand All @@ -99,133 +69,15 @@ namespace DrawSpace
return m_matrix[p_row][p_col];
};

void identity( void )
{
zero();
m_matrix[0][0] = 1.0;
m_matrix[1][1] = 1.0;
m_matrix[2][2] = 1.0;
m_matrix[3][3] = 1.0;

m_configinfos.type = ConfigurationType::CONFIG_IDENTITY;

m_configinfos.values[0] = 0.0;
m_configinfos.values[1] = 0.0;
m_configinfos.values[2] = 0.0;
m_configinfos.values[3] = 0.0;

}

void translation( dsreal p_x, dsreal p_y, dsreal p_z )
{
identity();
m_matrix[3][0] = p_x;
m_matrix[3][1] = p_y;
m_matrix[3][2] = p_z;

m_configinfos.type = ConfigurationType::CONFIG_TRANSLATION;
m_configinfos.values[0] = p_x;
m_configinfos.values[1] = p_y;
m_configinfos.values[2] = p_z;
m_configinfos.values[3] = 0.0;

}

void translation( const Utils::Vector& p_pos )
{
identity();
m_matrix[3][0] = p_pos[0];
m_matrix[3][1] = p_pos[1];
m_matrix[3][2] = p_pos[2];

m_configinfos.type = ConfigurationType::CONFIG_TRANSLATION;
m_configinfos.values[0] = p_pos[0];
m_configinfos.values[1] = p_pos[1];
m_configinfos.values[2] = p_pos[2];
m_configinfos.values[3] = 0.0;

}

void transpose( void )
{
dsreal msave[4][4];

memcpy( &msave, m_matrix, 16 * sizeof( dsreal ) );
void identity(void);
void translation(dsreal p_x, dsreal p_y, dsreal p_z);
void translation(const Utils::Vector& p_pos);
void transpose(void);
void perspective(dsreal p_w, dsreal p_h, dsreal p_zn, dsreal p_zf);

m_matrix[0][1] = msave[1][0];
m_matrix[0][2] = msave[2][0];
m_matrix[0][3] = msave[3][0];

m_matrix[1][0] = msave[0][1];

m_matrix[1][2] = msave[2][1];
m_matrix[1][3] = msave[3][1];

m_matrix[2][0] = msave[0][2];
m_matrix[2][1] = msave[1][2];

m_matrix[2][3] = msave[3][2];

m_matrix[3][0] = msave[0][3];
m_matrix[3][1] = msave[1][3];
m_matrix[3][2] = msave[2][3];

m_configinfos.type = ConfigurationType::CONFIG_UNDETERMINED;
}

void perspective( dsreal p_w, dsreal p_h, dsreal p_zn, dsreal p_zf )
{
zero();
m_matrix[0][0] = 2.0f * p_zn / p_w;
m_matrix[1][1] = 2.0f * p_zn / p_h;
m_matrix[2][2] = p_zf / ( p_zf - p_zn );
m_matrix[3][2] = - p_zn * m_matrix[2][2];
m_matrix[2][3] = 1.0f;

m_configinfos.type = ConfigurationType::CONFIG_UNDETERMINED;
}

void scale( dsreal p_sx, dsreal p_sy, dsreal p_sz )
{
zero();
m_matrix[0][0] = p_sx;
m_matrix[1][1] = p_sy;
m_matrix[2][2] = p_sz;
m_matrix[3][3] = 1.0;

m_configinfos.type = ConfigurationType::CONFIG_SCALING;
m_configinfos.values[0] = p_sx;
m_configinfos.values[1] = p_sy;
m_configinfos.values[2] = p_sz;
m_configinfos.values[3] = 0.0;

}

void scale( const Utils::Vector& p_pos )
{
zero();
m_matrix[0][0] = p_pos[0];
m_matrix[1][1] = p_pos[1];
m_matrix[2][2] = p_pos[2];
m_matrix[3][3] = 1.0;

m_configinfos.type = ConfigurationType::CONFIG_SCALING;
m_configinfos.values[0] = p_pos[0];
m_configinfos.values[1] = p_pos[1];
m_configinfos.values[2] = p_pos[2];
m_configinfos.values[3] = 0.0;

}


void clearTranslation( void )
{
m_matrix[3][0] = 0.0;
m_matrix[3][1] = 0.0;
m_matrix[3][2] = 0.0;

m_configinfos.type = ConfigurationType::CONFIG_UNDETERMINED;
}
void scale(dsreal p_sx, dsreal p_sy, dsreal p_sz);
void scale(const Utils::Vector& p_pos);
void clearTranslation(void);

void rotation( const Utils::Vector& p_axis, dsreal p_angle );
void inverse( void );
Expand Down
Loading

0 comments on commit 56fd47f

Please sign in to comment.