Raster render updates

This commit is contained in:
IlyaShurupov 2024-11-04 22:54:10 +03:00 committed by Ilya Shurupov
parent 543534bf61
commit 0b279163de
10 changed files with 121 additions and 39 deletions

View file

@ -117,16 +117,20 @@ void Camera::rotate(halnf angleX, halnf angleY) {
Vec3F wup(0, 0, 1);
mPos -= mTarget;
mat3f rotZ = mat3f::rotatorDir(wup, angleX);
Mat3F rotZ = Mat3F::rotatorDir(wup, angleX);
mPos = rotZ * mPos;
mUp = rotZ * mUp;
Vec3F f = mPos.unitV();
Vec3F s = mUp * f;
mPos = mat3f::rotatorDir(s, -angleY) * mPos;
mPos = Mat3F::rotatorDir(s, -angleY) * mPos;
mPos += mTarget;
lookAtPoint(mTarget, mPos, mUp);
}
void Camera::setPos(Vec3F pos) {
mPos = pos;
}

View file

@ -18,6 +18,7 @@ namespace tp {
void setRatio(halnf ratio);
void setFOV(halnf fov);
void setFar(halnf far);
void setPos(Vec3F pos);
[[nodiscard]] const Vec3F& getPos() const;
[[nodiscard]] const Vec3F& getTarget() const;

View file

@ -495,8 +495,8 @@ namespace tp {
};
template <typename Type>
using mat3 = Mat<Type, 3, 3>;
using mat3f = mat3<halnf>;
using Mat3 = Mat<Type, 3, 3>;
using Mat3F = Mat3<halnf>;
template <typename Type>
class Mat<Type, 3, 3> {
@ -647,22 +647,22 @@ namespace tp {
Mat inv() { return cofactors() /= det(); }
Mat rotatorX(alnf angle) {
Mat rotatorX(alnf angle) const {
alnf cosA = (alnf) cos(angle);
alnf sinA = (alnf) sin(angle);
return { { 1, 0, 0 }, { 0, cosA, -sinA }, { 0, sinA, cosA } };
}
Mat rotatorY(alnf angle) {
Mat rotatorY(alnf angle) const {
alnf cosA = (alnf) cos(angle);
alnf sinA = (alnf) sin(angle);
return { { cosA, 0, sinA }, { 0, 1, 0 }, { -sinA, 0, cosA } };
}
Mat rotatorZ(alnf angle) {
alnf cosA = (alnf) cos(angle);
alnf sinA = (alnf) sin(angle);
return { { cosA, -sinA, 0 }, { sinA, cosA, 0 }, { 0, 0, 1 } };
static Mat rotatorZ(alnf angle) {
Type cosA = (Type) cos(angle);
Type sinA = (Type) sin(angle);
return { vec{ cosA, -sinA, 0 }, vec{ sinA, cosA, 0 }, vec{ 0, 0, 1 } };
}
static Mat rotatorDir(vec dir, alnf angle) {
@ -707,4 +707,14 @@ namespace tp {
Type det() { return Type(); }
};
template<typename Type>
Mat<Type, 4, 4> toMat4(const Mat<Type, 3, 3>& in) {
Mat<Type, 4, 4> out;
out[0] = { in[0][0], in[0][1], in[0][2], 0 };
out[1] = { in[1][0], in[1][1], in[1][2], 0 };
out[2] = { in[2][0], in[2][1], in[2][2], 0 };
out[3] = Type(1);
return out;
}
}

View file

@ -30,7 +30,7 @@ namespace tp {
struct Topology {
Vec3F Origin = { 0, 0, 0 };
mat3f Basis = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
Mat3F Basis = { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 } };
Buffer<Vec3F> Points;
Buffer<Vec3F> Normals;

View file

@ -110,6 +110,13 @@ namespace tp {
return *this;
}
Vec& operator=(Type val) {
for (ualni i = 0; i < tSize; i++) {
get(i) = val;
}
return *this;
}
void assign(Type val) {
for (ualni i = 0; i < tSize; i++) {
get(i) = val;
@ -576,4 +583,14 @@ namespace tp {
using Vec4F = Vec4<halnf>;
using Vec4I = Vec4<halni>;
template <typename Type>
Vec<Type, 4> toVec4(const Vec<Type, 3>& in) {
Vec<Type, 4> out;
out[0] = in[0];
out[1] = in[1];
out[2] = in[2];
out[3] = 0;
return out;
}
}