Skip to content

Instantly share code, notes, and snippets.

@heatblazer
Created January 25, 2020 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heatblazer/cf112dfe48e9bf6141d77fce5cffd476 to your computer and use it in GitHub Desktop.
Save heatblazer/cf112dfe48e9bf6141d77fce5cffd476 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
struct vec3d
{
float data[3];
vec3d() : data{0.0f} {}
vec3d(float x, float y, float z) { data[0] = x; data[1] = y; data[2] = z;}
void print()
{
std::cout << "[" << data[0] << "][" << data[1] << "]["<< data[2] << "]" <<std::endl;
}
};
struct mat3d
{
vec3d data[3];
mat3d(const vec3d& row1, const vec3d& row2, const vec3d& row3)
{
data[0] = row1; data[1] = row2; data[2] = row3;
}
void print()
{
for (size_t i=0; i < sizeof(data)/sizeof(data[0]); ++i)
data[i].print();
}
};
static vec3d mult_vec_mat(const vec3d& v, const mat3d& mat)
{
vec3d result;
for(int i=0; i < 3; ++i)
{
float tmp = 0;
for (int j=0; j < 3; ++j)
{
tmp += mat.data[i].data[j] * v.data[j];
}
result.data[i] = tmp;
}
return result;
}
int main()
{
vec3d v (2, 1, 3);
mat3d m (vec3d(1,2,3), vec3d(4,5,6), vec3d(7,8,9));
auto result = mult_vec_mat(v, m);
result.print();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment