Thank you for your response.
I am trying develop this code to render 3D objects. It is still not helping. Do you want to send you whole code and you look at it.
Here is the code.
int scr_width = 1200;
int scr_height = 800;
int x_coord = 0;
int y_coord = 0;
int z_coord = 0;
int cube = new int[8];
int cube_list = {{1, 2, 3, 4}, {1, 2, 6, 5}, {1, 4, 8, 5}, {2, 3, 7, 6}, {3, 4, 8, 7}, {5, 6, 7, 8}};
int cube_portray = new int[8][2];
int center = {50, 50, 50};
int cube_radius = 20;
float x_angle = 0;
float y_angle = 0;
float z_angle = 0;
float fov = PI/2;
float aspect = scr_width/scr_height;
float near = 0;
float far = 0;
float speed = 1;
float cube_corner(){
float c = new float[8][3][1];
int f = 0;
for(int i = -1; i < 2; i += 2){
for(int j = -1; j < 2; j += 2){
for(int k = -1; k < 2; k += 2){
c[f][0][0] = (float)center[0]+cube_radiusi;
c[f][1][0] = (float)center[1]+cube_radiusj;
c[f][2][0] = (float)center[2]+cube_radiusk;
f += 1;
}
}
}
return c;
}
float[][] matmul(float[][] a, float[][] b){
float c[][] = new float[a.length][b[0].length];
for (int i = 0; i < a.length; i++){
float d[] = new float[a.length];
for (int j = 0; j < b[0].length; j++){
float e = 0;
for (int k = 0; k < b.length; k++){
e += a[i][k]b[k][j];
}
d[j] = e;
}
c[i] = d;
}
return c;
}
float[][] projmul(float[][] a){
float projection[][] = {{1/(aspecttan(fov/2)), 0, 0, 0}, {0, 1/(tan(fov/2)), 0, 0}, {}, {}};
float x_rot[][] = {{1, 0, 0, 0}, {0, cos(x_angle), -sin(x_angle), 0}, {0, sin(x_angle), cos(x_angle), 0}, {0, 0, 0, 1}};
float y_rot[][] = {{cos(y_angle), 0, sin(y_angle), 0}, {0, 1, 0, 0}, {-sin(y_angle), 0, cos(y_angle), 0}, {0, 0, 0, 1}};
float z_rot[][] = {{cos(z_angle), -sin(z_angle), 0, 0}, {sin(z_angle), cos(z_angle), 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}};
float viewport[][] = {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}};
float view[][] = {{1, 0, 0, 0}, {0, 1, 0, 0}, {0, 0, 1, 0}, {0, 0, 0, 1}};
a = matmul(viewport, a);
a = matmul(view, a);
a = matmul(x_rot, a);
a = matmul(y_rot, a);
a = matmul(z_rot, a);
a = matmul(projection, a);
return a;
}
void keyPressed(){
if(key == ‘w’){
x_coord += speedcos(x_angle);
z_coord += speedsin(x_angle);
}
if(key == ‘a’){
x_coord -= speedsin(x_angle);
z_coord += speedcos(x_angle);
}
if(key == ‘s’){
x_coord -= speedcos(x_angle);
z_coord -= speedsin(x_angle);
}
if(key == ‘d’){
x_coord += speedsin(x_angle);
z_coord -= speed*cos(x_angle);
}
}
void setup(){
size(1200, 800);
}
void draw(){
float coords_list = cube_corner();
float proj_list = new float[8][4][1];
for(int i = 0; i < coords_list.length; i++){
float vec = projmul(coords_list[i]);
for(int j = 0; j < 3; j++){
proj_list[i][j][0] = vec[j][0];
}
proj_list[i][4][0] = 1;
}
background(0);
for(int i : cube_list){
beginShape();
for(int j = 0; j < 4; j++){
vertex(proj_list[i[j]][0][0], proj_list[i[j]][1][0]);
}
endShape();
}
}