Skip to content

Commit

Permalink
little little into the middle
Browse files Browse the repository at this point in the history
  • Loading branch information
atahankilc committed Dec 23, 2022
1 parent bb00893 commit a8724b3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
25 changes: 19 additions & 6 deletions Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ bool Scene::clipLine(Vec4 &v0, Vec4 &v1) {

void Scene::wireRasterization(Vec4 v0, Vec4 v1) {
if (this->clipLine(v0, v1)) {
int increment;
double m = (v1.y - v0.y) / (v1.x - v0.x);
if (m > 1 || m < -1) {
double dummy0 = v0.x, dummy1 = v1.x;
Expand All @@ -89,15 +90,27 @@ void Scene::wireRasterization(Vec4 v0, Vec4 v1) {
v1.y = dummy1;
}
if (v1.x < v0.x) {
swap(v0, v1);
double dummyX = v0.x, dummyY = v0.y, dummyZ = v0.z, dummyT = v0.t;
auto dummyColor = Color(v0.color);
v0.x = v1.x;
v0.y = v1.y;
v0.z = v1.z;
v0.t = v1.t;
v0.color = Color(v1.color);
v1.x = dummyX;
v1.y = dummyY;
v1.z = dummyZ;
v1.t = dummyT;
v1.color = Color(dummyColor);
}
int increment = 1;
if (v1.y < v0.y) {
if (v1.y > v0.y) {
increment = 1;
} else {
increment = -1;
}
double diffX = v1.x - v0.x, diffY = v0.y - v1.y;
int y = (int) v0.y;
int d = (int) (diffY + (increment * 0.5 * diffX));
int d = (int) (diffY + increment * 0.5 * diffX);
Color c = Color(v0.color.r,
v0.color.g,
v0.color.b);
Expand All @@ -109,7 +122,7 @@ void Scene::wireRasterization(Vec4 v0, Vec4 v1) {
int(c.b + 0.5));
if (d * increment < 0) {
y += increment;
d += (int) (diffY + (increment * diffX));
d += (int) (diffY + increment * diffX);
} else
d += (int) diffY;
c = Color(c.r + dc.r,
Expand All @@ -123,7 +136,7 @@ void Scene::wireRasterization(Vec4 v0, Vec4 v1) {
int(c.b + 0.5));
if (d * increment < 0) {
y += increment;
d += (int) (diffY + (increment * diffX));
d += (int) (diffY + increment * diffX);
} else
d += (int) diffY;
c = Color(c.r + dc.r,
Expand Down
14 changes: 3 additions & 11 deletions Transformation/Rotation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,9 @@ Rotation::Rotation() : Base(0) {

Rotation::Rotation(int id, double angle, double x, double y, double z) : Base(id, x, y, z) {
this->angle = angle;
Vec3 u = Vec3(x, y, z, Color()), v, w;
double minComp = std::min(std::min(abs(x), abs(y)), abs(z));
if (minComp == abs(x))
v = Vec3(0, -1 * z, y, Color());
else if (minComp == abs(y))
v = Vec3(-1 * z, 0, x, Color());
else if (minComp == abs(z))
v = Vec3(-1 * y, x, 0, Color());
w = crossProductVec3(u, v);
v = normalizeVec3(v);
w = normalizeVec3(w);
Vec3 u = normalizeVec3(Vec3(x, y, z, Color()));
Vec3 v = normalizeVec3(Vec3(0, -1 * z, y, Color()));
Vec3 w = normalizeVec3(crossProductVec3(u, v));
double translate[4][4] = {{u.x, u.y, u.z, 0},
{v.x, v.y, v.z, 0},
{w.x, w.y, w.z, 0},
Expand Down

0 comments on commit a8724b3

Please sign in to comment.