You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

130 lines
3.5 KiB

class Arrow {
constructor(posX, posY, posZ, dirX, dirY, dirZ, c, sp){
this.color = color(c);
this.visible = true;
this.sphere = sp;
this.pos = createVector(posX, posY, posZ);
this.dir = createVector(dirX, dirY, dirZ);
this.end = p5.Vector.add(this.pos, this.dir);
}
static cross(a1, a2, c){
let v = p5.Vector.cross(a1.dir, a2.dir);
return new Arrow(a1.pos.x, a1.pos.y, a1.pos.z, v.x, v.y, v.z, c);
}
show(){
this.pos.mult(scale);
this.dir.mult(scale);
this.end.mult(scale);
stroke(this.color);
strokeWeight(4);
let endV = p5.Vector.add(this.pos, this.dir);
line(this.pos.y, -this.pos.z, this.pos.x, endV.y, -endV.z, endV.x);
if (this.sphere){
push();
translate(this.pos.y, -this.pos.z, this.pos.x);
noStroke();
fill(220, 200, 180);
sphere(5);
pop();
}
this.pos.div(scale);
this.dir.div(scale);
this.end.div(scale);
}
}
class Quad {
constructor(a1, a2, c){
this.color = color(c);
this.visible = true;
this.a1 = a1;
this.a2 = a2;
}
show(){
this.a1.pos.mult(scale);
this.a2.dir.mult(scale);
this.a1.end.mult(scale);
this.a2.end.mult(scale);
ambientLight(this.color);
strokeWeight(1);
beginShape();
vertex(this.a1.pos.y, -this.a1.pos.z, this.a1.pos.x);
vertex(this.a1.end.y, -this.a1.end.z, this.a1.end.x);
vertex(this.a1.end.y + this.a2.dir.y, -this.a1.end.z - this.a2.dir.z, this.a1.end.x + this.a2.dir.x);
vertex(this.a2.end.y, -this.a2.end.z, this.a2.end.x);
endShape();
this.a1.pos.div(scale);
this.a2.dir.div(scale);
this.a1.end.div(scale);
this.a2.end.div(scale);
}
}
class Cuboid {
constructor(a1, a2, a3, c, h){
this.color = color(c);
this.visible = true;
this.showHeight = h;
this.a1 = a1;
this.a2 = a2;
this.a3 = a3;
}
show(){
this.a1.pos.mult(scale);
this.a2.pos.mult(scale);
this.a3.pos.mult(scale);
this.a1.dir.mult(scale);
this.a2.dir.mult(scale);
this.a3.dir.mult(scale);
this.a1.end.mult(scale);
this.a2.end.mult(scale);
this.a3.end.mult(scale);
let endDown = p5.Vector.add(this.a1.end, this.a2.dir);
let endUp = p5.Vector.add(endDown, this.a3.dir);
let a1Up = p5.Vector.add(this.a1.end, this.a3.dir);
let a2Up = p5.Vector.add(this.a2.end, this.a3.dir);
stroke(this.color);
strokeWeight(4);
line(this.a2.end.y, -this.a2.end.z, this.a2.end.x, endDown.y, -endDown.z, endDown.x);
line(this.a1.end.y, -this.a1.end.z, this.a1.end.x, endDown.y, -endDown.z, endDown.x);
line(this.a3.end.y, -this.a3.end.z, this.a3.end.x, a1Up.y, -a1Up.z, a1Up.x);
line(this.a3.end.y, -this.a3.end.z, this.a3.end.x, a2Up.y, -a2Up.z, a2Up.x);
line(a1Up.y, -a1Up.z, a1Up.x, endUp.y, -endUp.z, endUp.x);
line(a2Up.y, -a2Up.z, a2Up.x, endUp.y, -endUp.z, endUp.x);
line(this.a1.end.y, -this.a1.end.z, this.a1.end.x, a1Up.y, -a1Up.z, a1Up.x);
line(this.a2.end.y, -this.a2.end.z, this.a2.end.x, a2Up.y, -a2Up.z, a2Up.x);
line(endDown.y, -endDown.z, endDown.x, endUp.y, -endUp.z, endUp.x);
if (this.showHeight){
stroke(255, 255, 0);
let hDir = p5.Vector.cross(this.a1.dir, this.a2.dir);
let hLength = p5.Vector.dot(this.a3.dir, hDir) / hDir.mag();
hDir.setMag(hLength);
line(this.a3.end.y, -this.a3.end.z, this.a3.end.x, this.a3.end.y - hDir.y, -this.a3.end.z + hDir.z, this.a3.end.x - hDir.x);
}
this.a1.pos.div(scale);
this.a2.pos.div(scale);
this.a3.pos.div(scale);
this.a1.dir.div(scale);
this.a2.dir.div(scale);
this.a3.dir.div(scale);
this.a1.end.div(scale);
this.a2.end.div(scale);
this.a3.end.div(scale);
}
}