|
@@ -320,7 +320,7 @@ OLIVECDEF void olivec_line(Olivec_Canvas oc, int x1, int y1, int x2, int y2, uin
|
|
OLIVECDEF void olivec_triangle(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, uint32_t color);
|
|
OLIVECDEF void olivec_triangle(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, uint32_t color);
|
|
OLIVECDEF void olivec_triangle3c(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, uint32_t c1, uint32_t c2, uint32_t c3);
|
|
OLIVECDEF void olivec_triangle3c(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, uint32_t c1, uint32_t c2, uint32_t c3);
|
|
OLIVECDEF void olivec_triangle3z(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, float z1, float z2, float z3);
|
|
OLIVECDEF void olivec_triangle3z(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, float z1, float z2, float z3);
|
|
-OLIVECDEF void olivec_triangle3uv(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, Uv uv1, Uv uv2, Uv uv3, Olivec_Canvas texture);
|
|
|
|
|
|
+OLIVECDEF void olivec_triangle3uv(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, Uv uv1, Uv uv2, Uv uv3, float z1, float z2, float z3, Olivec_Canvas texture);
|
|
OLIVECDEF void olivec_text(Olivec_Canvas oc, const char *text, int x, int y, Olivec_Font font, size_t size, uint32_t color);
|
|
OLIVECDEF void olivec_text(Olivec_Canvas oc, const char *text, int x, int y, Olivec_Font font, size_t size, uint32_t color);
|
|
OLIVECDEF void olivec_sprite_blend(Olivec_Canvas oc, int x, int y, int w, int h, Olivec_Canvas sprite);
|
|
OLIVECDEF void olivec_sprite_blend(Olivec_Canvas oc, int x, int y, int w, int h, Olivec_Canvas sprite);
|
|
OLIVECDEF void olivec_sprite_copy(Olivec_Canvas oc, int x, int y, int w, int h, Olivec_Canvas sprite);
|
|
OLIVECDEF void olivec_sprite_copy(Olivec_Canvas oc, int x, int y, int w, int h, Olivec_Canvas sprite);
|
|
@@ -733,24 +733,27 @@ OLIVECDEF void olivec_triangle3z(Olivec_Canvas oc, int x1, int y1, int x2, int y
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-OLIVECDEF void olivec_triangle3uv(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, Uv uv1, Uv uv2, Uv uv3, Olivec_Canvas texture)
|
|
|
|
|
|
+OLIVECDEF void olivec_triangle3uv(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, Uv uv1, Uv uv2, Uv uv3, float z1, float z2, float z3, Olivec_Canvas texture)
|
|
{
|
|
{
|
|
if (y1 > y2) {
|
|
if (y1 > y2) {
|
|
OLIVEC_SWAP(int, x1, x2);
|
|
OLIVEC_SWAP(int, x1, x2);
|
|
OLIVEC_SWAP(int, y1, y2);
|
|
OLIVEC_SWAP(int, y1, y2);
|
|
OLIVEC_SWAP(Uv, uv1, uv2);
|
|
OLIVEC_SWAP(Uv, uv1, uv2);
|
|
|
|
+ OLIVEC_SWAP(float, z1, z2);
|
|
}
|
|
}
|
|
|
|
|
|
if (y2 > y3) {
|
|
if (y2 > y3) {
|
|
OLIVEC_SWAP(int, x2, x3);
|
|
OLIVEC_SWAP(int, x2, x3);
|
|
OLIVEC_SWAP(int, y2, y3);
|
|
OLIVEC_SWAP(int, y2, y3);
|
|
OLIVEC_SWAP(Uv, uv2, uv3);
|
|
OLIVEC_SWAP(Uv, uv2, uv3);
|
|
|
|
+ OLIVEC_SWAP(float, z2, z3);
|
|
}
|
|
}
|
|
|
|
|
|
if (y1 > y2) {
|
|
if (y1 > y2) {
|
|
OLIVEC_SWAP(int, x1, x2);
|
|
OLIVEC_SWAP(int, x1, x2);
|
|
OLIVEC_SWAP(int, y1, y2);
|
|
OLIVEC_SWAP(int, y1, y2);
|
|
OLIVEC_SWAP(Uv, uv1, uv2);
|
|
OLIVEC_SWAP(Uv, uv1, uv2);
|
|
|
|
+ OLIVEC_SWAP(float, z1, z2);
|
|
}
|
|
}
|
|
|
|
|
|
int dx12 = x2 - x1;
|
|
int dx12 = x2 - x1;
|
|
@@ -769,12 +772,17 @@ OLIVECDEF void olivec_triangle3uv(Olivec_Canvas oc, int x1, int y1, int x2, int
|
|
int u1, u2, det;
|
|
int u1, u2, det;
|
|
barycentric(x1, y1, x2, y2, x3, y3, x, y, &u1, &u2, &det);
|
|
barycentric(x1, y1, x2, y2, x3, y3, x, y, &u1, &u2, &det);
|
|
int u3 = det - u1 - u2;
|
|
int u3 = det - u1 - u2;
|
|
|
|
+ float z = z1*u1/det + z2*u2/det + z3*(det - u1 - u2)/det;
|
|
Uv uv = olivec_uv(
|
|
Uv uv = olivec_uv(
|
|
uv1.u*u1/det + uv2.u*u2/det + uv3.u*u3/det,
|
|
uv1.u*u1/det + uv2.u*u2/det + uv3.u*u3/det,
|
|
uv1.v*u1/det + uv2.v*u2/det + uv3.v*u3/det
|
|
uv1.v*u1/det + uv2.v*u2/det + uv3.v*u3/det
|
|
);
|
|
);
|
|
- int texture_x = uv.u*texture.width;
|
|
|
|
- int texture_y = uv.v*texture.height;
|
|
|
|
|
|
+ int texture_x = uv.u/z*texture.width;
|
|
|
|
+ if (texture_x < 0) texture_x = 0;
|
|
|
|
+ if ((size_t) texture_x >= texture.width) texture_x = texture.width - 1;
|
|
|
|
+ int texture_y = uv.v/z*texture.height;
|
|
|
|
+ if (texture_y < 0) texture_y = 0;
|
|
|
|
+ if ((size_t) texture_y >= texture.height) texture_y = texture.height - 1;
|
|
OLIVEC_PIXEL(oc, x, y) = OLIVEC_PIXEL(texture, texture_x, texture_y);
|
|
OLIVEC_PIXEL(oc, x, y) = OLIVEC_PIXEL(texture, texture_x, texture_y);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -796,12 +804,17 @@ OLIVECDEF void olivec_triangle3uv(Olivec_Canvas oc, int x1, int y1, int x2, int
|
|
int u1, u2, det;
|
|
int u1, u2, det;
|
|
barycentric(x1, y1, x2, y2, x3, y3, x, y, &u1, &u2, &det);
|
|
barycentric(x1, y1, x2, y2, x3, y3, x, y, &u1, &u2, &det);
|
|
int u3 = det - u1 - u2;
|
|
int u3 = det - u1 - u2;
|
|
|
|
+ float z = z1*u1/det + z2*u2/det + z3*(det - u1 - u2)/det;
|
|
Uv uv = olivec_uv(
|
|
Uv uv = olivec_uv(
|
|
uv1.u*u1/det + uv2.u*u2/det + uv3.u*u3/det,
|
|
uv1.u*u1/det + uv2.u*u2/det + uv3.u*u3/det,
|
|
uv1.v*u1/det + uv2.v*u2/det + uv3.v*u3/det
|
|
uv1.v*u1/det + uv2.v*u2/det + uv3.v*u3/det
|
|
);
|
|
);
|
|
- int texture_x = uv.u*texture.width;
|
|
|
|
- int texture_y = uv.v*texture.height;
|
|
|
|
|
|
+ int texture_x = uv.u/z*texture.width;
|
|
|
|
+ if (texture_x < 0) texture_x = 0;
|
|
|
|
+ if ((size_t) texture_x >= texture.width) texture_x = texture.width - 1;
|
|
|
|
+ int texture_y = uv.v/z*texture.height;
|
|
|
|
+ if (texture_y < 0) texture_y = 0;
|
|
|
|
+ if ((size_t) texture_y >= texture.height) texture_y = texture.height - 1;
|
|
OLIVEC_PIXEL(oc, x, y) = OLIVEC_PIXEL(texture, texture_x, texture_y);
|
|
OLIVEC_PIXEL(oc, x, y) = OLIVEC_PIXEL(texture, texture_x, texture_y);
|
|
}
|
|
}
|
|
}
|
|
}
|