Hello,
Can anyone tell me what exactly am I doing wrong in my code?
1. the mapped image is not showing
2. the whole body of my object disappears when I add the texture() function to my code.
Code:
PImage itten;
void setup(){
size(1000, 1000, P3D);
itten = loadImage("B_shapes.gif");
}
void draw(){
background(255);
lights();
translate(width/2, height/2);
rotateY(map(mouseX, 0, width, 0, PI));
rotateZ(map(mouseY, 0, height, 0, -PI));
noStroke();
fill(#999999);//hex color
teapot(40, 70, 80, 18);
spout(6, 10, 40, 18);
handle(6, 6, 30, 4);
}
void teapot(float top, float bottom, float tHeight, int facets){
float angle = 0;
float angleInc = TWO_PI/facets;
beginShape(QUAD_STRIP);
for (int i = 0; i < facets+1; ++i){
tTop(top, angle);
tBottom(bottom, tHeight, angle);
angle += angleInc;
}
endShape();
if(bottom != 0){
angle = 0;
beginShape(TRIANGLE_FAN);
vertex(0, tHeight, 0);
for (int i = 0; i < facets + 1; i++){
vertex(bottom * cos(angle), tHeight, bottom * sin(angle));
angle += angleInc;
}
endShape();
}
}
void spout(float top, float bottom, float tHeight, int facets){
//same code as the teapot function
fill(#999999);
pushMatrix();
translate(72, 10, -40);
rotateZ(PI/2);
rotateY(PI/3);
rotateX(PI/4);
float angle = 0;
float angleInc = TWO_PI/facets;
beginShape(QUAD_STRIP);
for (int i = 0; i < facets+1; ++i){
vertex(top*cos(angle), 0, top*sin(angle));
vertex(bottom*cos(angle), tHeight, bottom*sin(angle));
angle += angleInc;
}
endShape();
popMatrix();
}
void handle(float top, float bottom, float tHeight, int facets){
fill(#333333);
rotateZ(PI/2);
rotateY(map(900, 0, width, 0, PI));
rotateX(map(160, 0, height, 0, -PI));
float angle = 0;
float angleInc = TWO_PI/facets;
pushMatrix();
translate(-40, 45, 25);
beginShape(QUAD_STRIP);
for (int i = 0; i < facets+1; ++i){
vertex(top*cos(angle), 0, top*sin(angle));
vertex(bottom*cos(angle), tHeight, bottom*sin(angle));
angle += angleInc;
}
endShape();
if(top != 0){
angle = 0;
beginShape(TRIANGLE_FAN);
//center point
vertex(0, 0, 0);
for (int i = 0; i < facets + 1; i++){
vertex(top * cos(angle), 0, top * sin(angle));
angle += angleInc;
}
endShape();
}
if(bottom != 0){
angle = 0;
beginShape(TRIANGLE_FAN);
//center point
vertex(0, tHeight, 0);
for (int i = 0; i < facets + 1; i++){
vertex(bottom * cos(angle), tHeight, bottom * sin(angle));
angle += angleInc;
}
endShape();
}
popMatrix();
}
void tTop(float top, float ang){
texture(itten);
vertex(top*cos(ang), 0, top*sin(ang));
}
void tBottom(float bottom, float tHeight, float ang){
vertex(bottom*cos(ang), tHeight, bottom*sin(ang));
}
Thank you for your help!!