Ive been getting an issue with the code below, there is no issue with the rotation around the y axis but when I try to rotate around the x axis it doesnt act properly ie the values dont change accordingly they compress up into a cluster at the town of the screen when I increase the xrot value.
public void drawline(int x, int y, int xx, int yy) {
double grad = Math.atan2(xx - x, yy - y);
double cx = x;
double cy = y;
double dist = Math.sqrt((Math.abs(xx - x)) * (Math.abs(xx - x))
+ (Math.abs(yy - y)) * (Math.abs(yy - y)));
double nx = Math.sin(grad);
double ny = Math.cos(grad);
for (int i = 0; i < dist; i++) {
cx = (i*nx)+x;
cy = (i*ny)+y;
if (cx < core.WIDTH && cy < core.HEIGHT) {
if (cx > 0 && cy > 0) {
core.screen.map[(int) cx][(int) cy] = 0xFF00FF;
}
}
}
}
public void drawnet(vertex v1, vertex v2, vertex v3, vertex v4, Camera c) {
vertex[] v = new vertex[4];
Positionalobject[] po = new Positionalobject[4];
for (int i = 0; i < 4; i++) {
po[i] = new Positionalobject();
}
v[0] = v1;
v[1] = v2;
v[2] = v3;
v[3] = v4;
for (int i = 0; i < 4; i++) {
double tx = v[i].x - c.x;
double ty = v[i].y - c.y;
double tz = v[i].z - c.z;
if (tz < 500) {
double sinex = Math.sin(c.rotx);
double cosx = Math.cos(c.rotx);
double cosy = Math.cos(c.roty);
double siny = Math.sin(c.roty);
double dx = 0;
double my = 0;
double mz = 0;
double dz = 0;
dx = tz * siny + tx * cosy;
dz = tz * cosy - tx * siny;
my = ty * cosx - dz * sinex;
mz = dz * sinex + dz * cosx;
double nx = (dx) * (scalex / mz) + (core.WIDTH / 2);
double ny = (my) * (scaley / mz) + (core.HEIGHT / 2);
nx = (scalex * dx / mz) + (core.WIDTH / 2);
ny = (scaley * my / mz) + (core.HEIGHT / 2);
double mmz = ((mz-c.z)+(nx-c.x));
po[i].x = nx;
po[i].y = ny;
po[i].z = mmz;
}
}
if (po[0].x < core.WIDTH && po[0].y < core.HEIGHT && po[0].x > 0
&& po[0].y > 0) {
drawline((int) po[0].x, (int) po[0].y, (int) po[1].x, (int) po[1].y);
drawline((int) po[1].x, (int) po[1].y, (int) po[2].x, (int) po[2].y);
drawline((int) po[2].x, (int) po[2].y, (int) po[3].x, (int) po[3].y);
drawline((int) po[3].x, (int) po[3].y, (int) po[0].x, (int) po[0].y);
}
}