Sure =) thx for the quick respond! here goes!
Code:class Cube {
int w, h, d;
Vec3D vertice1, vertice2, vertice3, vertice4, vertice5, vertice6, vertice7, vertice8;
Cube(int w, int h, int d ){
this.w = w;
this.h = h;
this.d = d;
vertice1 = new Vec3D(-w/2,-h/2,-d/2);
vertice2 = new Vec3D(w,-h/2,-d/2);
vertice3 = new Vec3D(w,h,-d/2);
vertice4 = new Vec3D(-w/2,h,-d/2);
vertice5 = new Vec3D(-w/2,-h/2,d);
vertice6 = new Vec3D(w,-h/2,d);
vertice7 = new Vec3D(w,h,d);
vertice8 = new Vec3D(-w/2,h,d);
}
Cube(Vec3D v1, Vec3D v2, Vec3D v3, Vec3D v4, Vec3D v5, Vec3D v6, Vec3D v7, Vec3D v8) {
vertice1 = v1;
vertice2 = v2;
vertice3 = v3;
vertice4 = v4;
vertice5 = v5;
vertice6 = v6;
vertice7 = v7;
vertice8 = v8;
}
void setVertices(Vec3D v1, Vec3D v2, Vec3D v3, Vec3D v4, Vec3D v5, Vec3D v6, Vec3D v7, Vec3D v8) {
vertice1 = v1;
vertice2 = v2;
vertice3 = v3;
vertice4 = v4;
vertice5 = v5;
vertice6 = v6;
vertice7 = v7;
vertice8 = v8;
}
Vec3D[] getVertices() {
Vec3D temporal[] = new Vec3D[8];
temporal[0] = vertice1;
temporal[1] = vertice2;
temporal[2] = vertice3;
temporal[3] = vertice4;
temporal[4] = vertice5;
temporal[5] = vertice6;
temporal[6] = vertice7;
temporal[7] = vertice8;
return temporal;
}
void drawCube(){
beginShape(QUADS);
//cara frontal
vertex(vertice1.x, vertice1.y, vertice1.z);
vertex(vertice2.x, vertice2.y, vertice2.z);
vertex(vertice3.x, vertice3.y, vertice3.z);
vertex(vertice4.x, vertice4.y, vertice4.z);
//cara trasera
vertex(vertice5.x, vertice5.y, vertice5.z);
vertex(vertice6.x, vertice6.y, vertice6.z);
vertex(vertice7.x, vertice7.y, vertice7.z);
vertex(vertice8.x, vertice8.y, vertice8.z);
//cara izquierda
vertex(vertice1.x, vertice1.y, vertice1.z);
vertex(vertice4.x, vertice4.y, vertice4.z);
vertex(vertice8.x, vertice8.y, vertice8.z);
vertex(vertice5.x, vertice5.y, vertice5.z);
//cara derecha
vertex(vertice2.x, vertice2.y, vertice2.z);
vertex(vertice6.x, vertice6.y, vertice6.z);
vertex(vertice7.x, vertice7.y, vertice7.z);
vertex(vertice3.x, vertice3.y, vertice3.z);
// cara de arriba
vertex(vertice1.x, vertice1.y, vertice1.z);
vertex(vertice2.x, vertice2.y, vertice2.z);
vertex(vertice6.x, vertice6.y, vertice6.z);
vertex(vertice5.x, vertice5.y, vertice5.z);
//cara de abajo
vertex(vertice4.x, vertice4.y, vertice4.z);
vertex(vertice3.x, vertice3.y, vertice3.z);
vertex(vertice7.x, vertice7.y, vertice7.z);
vertex(vertice8.x, vertice8.y, vertice8.z);
endShape();
}
}
Thats the cube class and here is the Vec3D class from unlekker =)
Code:// Vec3D - simple 3D vector class
// processing.unlekker.net
class Vec3D {
float x,y,z;
Vec3D(float _x,float _y,float _z) {
x=_x;
y=_y;
z=_z;
}
Vec3D(Vec3D v) {
x=v.x;
y=v.y;
z=v.z;
}
void set(float _x,float _y,float _z) {
x=_x;
y=_y;
z=_z;
}
void set(Vec3D v) {
x=v.x;
y=v.y;
z=v.z;
}
void add(float _x,float _y,float _z) {
x+=_x;
y+=_y;
z+=_z;
}
void add(Vec3D v) {
x+=v.x;
y+=v.y;
z+=v.z;
}
void sub(float _x,float _y,float _z) {
x-=_x;
y-=_y;
z-=_z;
}
void sub(Vec3D v) {
x-=v.x;
y-=v.y;
z-=v.z;
}
void mult(float m) {
x*=m;
y*=m;
z*=m;
}
void div(float m) {
x/=m;
y/=m;
z/=m;
}
float length() {
return sqrt(x*x+y*y+z*z);
}
void normalise() {
float l=length();
if(l!=0) {
x/=l;
y/=l;
z/=l;
}
}
void rotateX(float val) {
double cosval=Math.cos(val);
double sinval=Math.sin(val);
double tmp1=y*cosval - z*sinval;
double tmp2=y*sinval + z*cosval;
y=(float)tmp1;
z=(float)tmp2;
}
void rotateY(float val) {
double cosval=Math.cos(val);
double sinval=Math.sin(val);
double tmp1=x*cosval - z*sinval;
double tmp2=x*sinval + z*cosval;
x=(float)tmp1;
z=(float)tmp2;
}
void rotateZ(float val) {
double cosval=Math.cos(val);
double sinval=Math.sin(val);
double tmp1=x*cosval - y*sinval;
double tmp2=x*sinval + y*cosval;
x=(float)tmp1;
y=(float)tmp2;
}
}
Really appreciate this =)