OMEGA_H_INLINE Matrix<3, 3> matrix_3x3( Real a, Real b, Real c, Real d, Real e, Real f, Real g, Real h, Real i) { Matrix<3, 3> o; o[0] = vector_3(a, d, g); o[1] = vector_3(b, e, h); o[2] = vector_3(c, f, i); return o; }
void apply_rotation_xyz(matrix_3x3 matrix, float& x, float& y, float& z) { vector_3 vector = vector_3(x, y, z); vector.apply_rotation(matrix); x = vector.x; y = vector.y; z = vector.z; }
matrix_3x3 matrix_3x3::create_look_at(vector_3 target) { vector_3 z_row = target.get_normal(); vector_3 x_row = vector_3(1, 0, -target.x/target.z).get_normal(); vector_3 y_row = vector_3(0, 1, -target.y/target.z).get_normal(); // x_row.debug("x_row"); // y_row.debug("y_row"); // z_row.debug("z_row"); // create the matrix already correctly transposed matrix_3x3 rot = matrix_3x3::create_from_rows(x_row, y_row, z_row); // rot.debug("rot"); return rot; }
vector_3 plan_get_position() { vector_3 position = vector_3(st_get_position_mm(X_AXIS), st_get_position_mm(Y_AXIS), st_get_position_mm(Z_AXIS)); //position.debug("in plan_get position"); //plan_bed_level_matrix.debug("in plan_get_position"); matrix_3x3 inverse = matrix_3x3::transpose(plan_bed_level_matrix); //inverse.debug("in plan_get inverse"); position.apply_rotation(inverse); //position.debug("after rotation"); return position; }
/** * Get the XYZ position of the steppers as a vector_3. * * On CORE machines XYZ is derived from ABC. */ vector_3 Planner::adjusted_position() { vector_3 pos = vector_3(stepper.get_axis_position_mm(X_AXIS), stepper.get_axis_position_mm(Y_AXIS), stepper.get_axis_position_mm(Z_AXIS)); //pos.debug("in Planner::adjusted_position"); //bed_level_matrix.debug("in Planner::adjusted_position"); matrix_3x3 inverse = matrix_3x3::transpose(bed_level_matrix); //inverse.debug("in Planner::inverse"); pos.apply_rotation(inverse); //pos.debug("after rotation"); return pos; }
vector_3 vector_3::get_normal() { vector_3 normalized = vector_3(x, y, z); normalized.normalize(); return normalized; }
vector_3 vector_3::operator-(vector_3 v) { return vector_3((x - v.x), (y - v.y), (z - v.z)); }
vector_3 vector_3::operator+(vector_3 v) { return vector_3((x + v.x), (y + v.y), (z + v.z)); }
vector_3 vector_3::cross(vector_3 left, vector_3 right) { return vector_3(left.y * right.z - left.z * right.y, left.z * right.x - left.x * right.z, left.x * right.y - left.y * right.x); }
OMEGA_H_INLINE Vector<3> cross(Vector<3> a, Vector<3> b) { return vector_3(a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]); }
int main() { //**************// //** jVector2 **// //**************// // Create an "empty" jVector2: (0,0) jVector2 vector1; // Create "partial" jVector2: (5,0) jVector2 vector2(5.0f); // Create "full" jVector2: (1,2) jVector2 vector3(1.0f, 2.0f); // print the vectors out std::cout << vector1.toString() << std::endl; std::cout << vector2.toString() << std::endl; std::cout << vector3.toString() << std::endl; // add two vectors together jVector2 sum23 = vector2 + vector3; std::cout << sum23.toString() << std::endl; // subtract two vectors jVector2 diff = jVector2(6.0f, 4.0f) - jVector2(10.0f, 2.0f); std::cout << diff.toString() << std::endl; // multiply vector by scalar std::cout << (vector3 * 1.25f).toString() << std::endl; // divide vector by scalar std::cout << (sum23 / 10.0f).toString() << std::endl; // test equality std::cout << (sum23 == diff) << std::endl; // test inequality std::cout << (diff != vector1) << std::endl; // get magnitude std::cout << vector3.magnitude_sqr() << std::endl; // normalize vector std::cout << (vector3.normalized()).toString() << std::endl; //////////////////////////////////////////////////// // jVector3 jVector3 vector_1; jVector3 vector_2(5.0f); jVector3 vector_3(1.0f, 2.0f, 3.0f); std::cout << vector_1.toString() << std::endl; std::cout << vector_2.toString() << std::endl; std::cout << vector_3.toString() << std::endl; // This will be put into the jDebug namespace/class. /* #ifdef linux #else // And this is why programming for Windows sucks... HANDLE h_stdout = GetStdHandle( STD_OUTPUT_HANDLE ); CONSOLE_SCREEN_BUFFER_INFO csbi; GetConsoleScreenBufferInfo( h_stdout, &csbi ); // Foreground B G R I // Colors 0 0 1 1 // Background B G R I // Colors 0 0 0 1 // All together, 00110001 is like this: SetConsoleTextAttribute( h_stdout, 0x31 ); std::cout << vector_1 << std::endl; SetConsoleTextAttribute( h_stdout, csbi.wAttributes ); #endif */ jDebug::LogError("An error has occurred!"); jDebug::LogWarning("A warning has occurred!"); jDebug::Log("A notification has appeared."); jDebug::AddLogger("main", "logs/main.log"); jDebug::LogError("main", "A test error to be found in main.log"); jDebug::Log("main", "A test notification to be found in main.log"); // Don't forget your cleanup! jDebug::DestructLoggers(); return 0; }