Opening Window Shutters Simulation
in
Contributed Library Questions
•
8 months ago
Can someone help me to apply texture to shutter...
- import processing.opengl.*;
- import codeanticode.glgraphics.*;
- import de.looksgood.ani.*;
- GLModel texquad;
- GLTexture tex;
- int numPoints = 4;
- float diameter = 1000.0;
- float Xwindow = 500.0;
- float Ywindow = 300.0;
- float yyG = -1 * (sqrt(diameter*diameter/4 - Xwindow*Xwindow/4)) - Ywindow/2;
- float yyD = sqrt(diameter*diameter/4 - Xwindow*Xwindow/4) - Ywindow/2;
- PVector oS1 = new PVector(0, -Ywindow/2);
- PVector oE1 = new PVector(-Xwindow/2, yyG + diameter/2);
- PVector oP1 = new PVector(-Xwindow/2, yyG);
- PVector oR1 = new PVector();
- PVector oS2 = new PVector(0, Ywindow/2);
- PVector oE2 = new PVector(-Xwindow/2, -yyG - diameter/2);
- PVector oP2 = new PVector(-Xwindow/2, -yyG);
- PVector oR2 = new PVector();
- float theta1 = 0.0;
- float theta2 = 0.0;
- float angle;
- void setup() {
- size(1280, 720, GLConstants.GLGRAPHICS);
- //Ani.init(this);
- angle = asin(Xwindow/diameter);
- // The model is dynamic, which means that its coordinates can be
- // updating during the drawing loop.
- texquad = new GLModel(this, numPoints, QUADS, GLModel.DYNAMIC);
- // Updating the vertices to their initial positions.
- texquad.beginUpdateVertices();
- texquad.updateVertex(0, -100, -100, 0);
- texquad.updateVertex(1, 100, -100, 0);
- texquad.updateVertex(2, 100, 100, 0);
- texquad.updateVertex(3, -100, 100, 0);
- texquad.endUpdateVertices();
- // Enabling the use of texturing...
- texquad.initTextures(1);
- // ... and loading and setting texture for this model.
- //tex = new GLTexture(this, "milan.jpg");
- texquad.setTexture(0, tex);
- // Setting the texture coordinates.
- texquad.beginUpdateTexCoords(0);
- texquad.updateTexCoord(0, 0, 0);
- texquad.updateTexCoord(1, 1, 0);
- texquad.updateTexCoord(2, 1, 1);
- texquad.updateTexCoord(3, 0, 1);
- texquad.endUpdateTexCoords();
- }
- void draw() {
- noStroke();
- //GLGraphics renderer = (GLGraphics)g;
- //renderer.beginGL();
- background(100);
- translate(width/2, height/2);
- //rotateY(frameCount * 0.01);
- // LEFT
- fill(255, 200, 200, 30);
- ellipse(-Xwindow/2, yyG, diameter, diameter);
- ellipse(-Xwindow/2, -yyG, diameter, diameter);
- // RIGHT
- fill(200, 255, 200, 30);
- ellipse(Xwindow/2, yyG, diameter, diameter);
- ellipse(Xwindow/2, -yyG, diameter, diameter);
- // WINDOW
- fill(255, 0, 0, 150);
- rect(-Xwindow/2, -Ywindow/2, Xwindow, Ywindow);
- //float theta = radians(frameCount/10);
- theta1 += 0.2;
- theta2 -= 0.2;
- //Ani.to(this, 2.0, "theta1", -degrees(angle), Ani.QUAD_IN);
- //Ani.to(this, 2.0, "theta2", -degrees(angle), Ani.QUAD_IN);
- if (theta1 >= degrees(angle)) theta1 = 0.0;
- if (theta2 <= -degrees(angle)) theta2 = 0.0;
- float cosTheta1 = cos(radians(theta1));
- float sinTheta1 = sin(radians(theta1));
- float cosTheta2 = cos(radians(theta2));
- float sinTheta2 = sin(radians(theta2));
- oR1.x = oP1.x + (oS1.x - oP1.x)*cosTheta1 - (oS1.y - oP1.y)*sinTheta1;
- oR1.y = oP1.y + (oS1.x - oP1.x)*sinTheta1 + (oS1.y - oP1.y)*cosTheta1;
- oR2.x = oP2.x + (oS2.x - oP2.x)*cosTheta2 - (oS2.y - oP2.y)*sinTheta2;
- oR2.y = oP2.y + (oS2.x - oP2.x)*sinTheta2 + (oS2.y - oP2.y)*cosTheta2;
- strokeWeight(2);
- stroke(0, 0, 255, 75);
- line(oP1.x, oP1.y, oR1.x, oR1.y);
- line(oP2.x, oP2.y, oR2.x, oR2.y);
- noStroke();
- fill(0, 255, 0);
- ellipse(oR1.x, oR1.y, 10, 10);
- ellipse(oR2.x, oR2.y, 10, 10);
- beginShape();
- fill(255, 255, 0);
- vertex(-Xwindow/2, -Ywindow/2);
- vertex(oR1.x, oR1.y);
- vertex(oR2.x, oR2.y);
- vertex(-Xwindow/2, Ywindow/2);
- endShape();
- /*
- texquad.beginUpdateVertices();
- texquad.displaceVertex(0, -Xwindow/2, Ywindow/2);
- texquad.displaceVertex(1, oR2.x, oR2.y);
- texquad.displaceVertex(2, oR1.x, oR1.y);
- texquad.displaceVertex(3, -Xwindow/2, -Ywindow/2);
- texquad.endUpdateVertices();
- */
- //renderer.model(texquad);
- //renderer.endGL();
- }
1