Added partial impl. triangulation
This commit is contained in:
parent
56c0f92ba4
commit
bc79111c07
@ -22,6 +22,10 @@ Matrix1::Matrix1(float* data, int size) : data(data), size(size) {
|
|||||||
this->externalData = true;
|
this->externalData = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector3 Matrix1::ToVector3() {
|
||||||
|
return Vector3(this->data[0], this->data[1], this->data[2]);
|
||||||
|
}
|
||||||
|
|
||||||
Matrix1 LinearAlgebra::Matrix1::FromQuaternion(Quaternion q) {
|
Matrix1 LinearAlgebra::Matrix1::FromQuaternion(Quaternion q) {
|
||||||
Matrix1 r = Matrix1(4);
|
Matrix1 r = Matrix1(4);
|
||||||
float* data = r.data;
|
float* data = r.data;
|
||||||
@ -37,7 +41,15 @@ Quaternion LinearAlgebra::Matrix1::ToQuaternion() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Matrix1 Matrix1::Slice(int start, int stop) {
|
Matrix1 Matrix1::Slice(int start, int stop) {
|
||||||
return Matrix1();
|
if (start < 0 || stop >= this->size)
|
||||||
|
std::cerr << "Slice index out of range." << std::endl;
|
||||||
|
|
||||||
|
Matrix1 result(stop - start);
|
||||||
|
int resultIx = 0;
|
||||||
|
for (int ix = start; ix < stop; ix++)
|
||||||
|
result.data[resultIx++] = this->data[ix];
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Matrix1
|
// Matrix1
|
||||||
@ -251,6 +263,26 @@ Matrix2 Matrix2::GetRows(int from, int to) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector3 Matrix2::GetRow3(int rowIx) {
|
||||||
|
int cellIx = rowIx * this->nCols;
|
||||||
|
Vector3 row(this->data[cellIx, 0], this->data[cellIx, 1],
|
||||||
|
this->data[cellIx, 2]);
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Matrix2::SetRow(int rowIx, Matrix1 source) {
|
||||||
|
int cellIx = rowIx * this->nCols;
|
||||||
|
for (int ix = 0; ix < source.size; ix++)
|
||||||
|
this->data[cellIx + ix] = source.data[ix];
|
||||||
|
}
|
||||||
|
|
||||||
|
void Matrix2::SetRow3(int rowIx, Vector3 v) {
|
||||||
|
int cellIx = rowIx * this->nCols;
|
||||||
|
this->data[cellIx + 0] = v.x;
|
||||||
|
this->data[cellIx + 1] = v.y;
|
||||||
|
this->data[cellIx + 2] = v.z;
|
||||||
|
}
|
||||||
|
|
||||||
Matrix2 Matrix2::Slice(int rowStart, int rowStop, int colStart, int colStop) {
|
Matrix2 Matrix2::Slice(int rowStart, int rowStop, int colStart, int colStop) {
|
||||||
Matrix2 r = Matrix2(rowStop - rowStart, colStop - colStart);
|
Matrix2 r = Matrix2(rowStop - rowStart, colStop - colStart);
|
||||||
|
|
||||||
|
@ -16,6 +16,8 @@ class Matrix1 {
|
|||||||
Matrix1(int size);
|
Matrix1(int size);
|
||||||
Matrix1(float* data, int size);
|
Matrix1(float* data, int size);
|
||||||
|
|
||||||
|
Vector3 ToVector3();
|
||||||
|
|
||||||
static Matrix1 FromQuaternion(Quaternion q);
|
static Matrix1 FromQuaternion(Quaternion q);
|
||||||
Quaternion ToQuaternion();
|
Quaternion ToQuaternion();
|
||||||
|
|
||||||
@ -120,8 +122,11 @@ class Matrix2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Matrix2 GetRows(int from, int to);
|
Matrix2 GetRows(int from, int to);
|
||||||
|
Vector3 GetRow3(int rowIx);
|
||||||
|
|
||||||
|
void SetRow(int rowIx, Matrix1 source);
|
||||||
|
void SetRow3(int rowIx, Vector3 v);
|
||||||
|
|
||||||
void SetRow(int rowIx, Matrix1 source) {}
|
|
||||||
Matrix2 Slice(int rawStart, int rowStop, int colStart, int colStop);
|
Matrix2 Slice(int rawStart, int rowStop, int colStart, int colStop);
|
||||||
|
|
||||||
void UpdateSlice(int rowStart,
|
void UpdateSlice(int rowStart,
|
||||||
|
@ -168,6 +168,10 @@ Quaternion Quaternion::Inverse(Quaternion r) {
|
|||||||
return Quaternion(-r.x / n, -r.y / n, -r.z / n, r.w / n);
|
return Quaternion(-r.x / n, -r.y / n, -r.z / n, r.w / n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Quaternion Quaternion::Reflect(Quaternion q) {
|
||||||
|
return Quaternion(-q.x, -q.y, -q.z, q.w);
|
||||||
|
}
|
||||||
|
|
||||||
Quaternion Quaternion::LookRotation(const Vector3& forward) {
|
Quaternion Quaternion::LookRotation(const Vector3& forward) {
|
||||||
Vector3 up = Vector3(0, 1, 0);
|
Vector3 up = Vector3(0, 1, 0);
|
||||||
return LookRotation(forward, up);
|
return LookRotation(forward, up);
|
||||||
|
@ -126,6 +126,8 @@ struct Quaternion : Quat {
|
|||||||
/// needed</param> <returns>The inverted quaternion</returns>
|
/// needed</param> <returns>The inverted quaternion</returns>
|
||||||
static Quaternion Inverse(Quaternion quaternion);
|
static Quaternion Inverse(Quaternion quaternion);
|
||||||
|
|
||||||
|
static Quaternion Reflect(Quaternion q);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A rotation which looks in the given direction
|
/// A rotation which looks in the given direction
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user