Trying to Make an Eye of Providence Application

edited December 2017 in GLSL / Shaders

Hi guys! I'm currently working on a term project that requires I make a 3D application with the following requirements:

(1) Have at least 5 global variables;

(2) The program flow should have at least two loops and three conditional controls

(3) Have at least two customized functions (other than setup() and draw() – you need to write your OWN function);

(4) Have at least one set of Geometric Transformation (Translate, Scale, and Rotate);

(5) Have at least three user interactions (e.g. mouse tracking, right click, buttons);

(6) Import at least one third-party library;

(7) The 3D scene must contain at least one non-default, non- primitive 3D object (cannot be cube, sphere, cylinder, or cone) created using PShape with your own defined vertices. You can create your object by using non-default primitive shapes and geometric transformations, or create your own meshes within the 3D ordinate system by defining every vertex). Imported object from other applications are not allowed.

(8) At least one lighting source;

(9) At least one Shader (shading script – vertex shader and fragment shader);

(10) At least one texture applied to your customized object;

(11)For (7) to (10), there should be buttons (or keys) via which you can show different views of the object, for example, one key to rotate camera, one key to show object model mesh, one key to show shading effect, etc.

I'm trying to make an Eye of Providence wherein the eye will move inside the pyramid according to where the mouse is pointed, and change color when the spacebar is pressed, and reset with a mouse click so far this is what I've got so far; It's not much but I'm pretty stuck

   import peasy.*;
import peasy.org.apache.commons.math.*;
import peasy.org.apache.commons.math.geometry.*;


PeasyCam cam;
PImage img;
float myAngle= 0.0;
void setup(){
  size(600,600, P3D);
  cam = new PeasyCam(this, 500);
  img = loadImage("Pyramid_Texture.jpg");
}
void draw() {
  background(30, 0, 80);
  translate(width/2, height/2-150);
  rotateX(PI/2);
  rotateZ(myAngle);
  stroke(255);
  drawPyramid();
  myAngle = myAngle + 0.01;

}

  void drawPyramid() {
  // this creates a pyramid shape by defining
  // vertex points in 3D space (x, y, z)
  beginShape();
  texture(img);
    // triangle 1
    fill(#FFCBFE);
    vertex(-100, -100, -100);
    vertex( 100, -100, -100);
    vertex(   0,    0,  100);
  endShape(CLOSE);
  beginShape();
  texture (img);
    // triangle 2
    //fill(#015F21);
    vertex( 100, -100, -100);
    vertex( 100,  100, -100);
    vertex(   0,    0,  100);
  endShape(CLOSE);
  beginShape();
  texture(img);

    // triangle 3
   // fill(#8DDBDE);
    vertex( 100, 100, -100);
    vertex(-100, 100, -100);
    vertex(   0,   0,  100);
 endShape(CLOSE);
 beginShape();
 texture(img);
    // triangle 4
    //fill(#5D2D00);
    vertex(-100,  100, -100);
    vertex(-100, -100, -100);
    vertex(   0,    0,  100);
endShape(CLOSE);
beginShape();
texture(img);
    // pyramid base
    //fill(#9CA24D);
    vertex(-100, -100, -100);
    vertex( 100, -100, -100);
    vertex( 100, 100, -100);
    vertex(-100,  100, -100);
endShape(CLOSE);
  }

I know it's still very barebones but I'm trying to figure out how to get the pyramid to stay still while allowing a sphere to move inside it, and how to apply texture, shaders and lighting to the scene. Any help is greatly appreciated!

Answers

  • I hope you did some progress, and finished your term project. :)

  • //
    
    import peasy.*;
    import peasy.org.apache.commons.math.*;
    import peasy.org.apache.commons.math.geometry.*;
    
    
    PeasyCam cam;
    
    PImage img;
    float myAngle= 0.0, eyeAngle;
    
    color colEye2 = color(255, 2, 2); 
    float sizeEye2 = 4; 
    
    void setup() {
      size(1200, 600, P3D);
      cam = new PeasyCam(this, 500);
      img = loadImage("Pyramid_Texture.jpg");
    }
    
    void draw() {
      background(30, 0, 80);
      lights(); 
      // translate(width/4, height/2-150);
      rotateX(PI/2);
      rotateZ(myAngle);
      stroke(255);
      drawPyramid();
    
      pushMatrix();
      //
      fill(255);//red
      noStroke();
      rotateY(eyeAngle); 
      sphere(12); 
      translate (12, 0, 0);
      fill(colEye2);//red
      sphere(sizeEye2);
      popMatrix();
    
      myAngle = myAngle + 0.01;
      eyeAngle += 0.07;
    
      cam.beginHUD();
      fill(255); 
      text("Peasy Cam usage, mouse click to change eye color, keyboard to change eye size", 14, 14); 
      cam.endHUD();
    }
    
    //---------------------------------------------------------------------------------------
    
    void mousePressed() {
      colEye2=color(random(255), random(255), random(255));
    }
    
    void keyPressed() {
      sizeEye2 = random( 2, 11);
    }
    
    //---------------------------------------------------------------------------------------
    
    void drawPyramid() {
      // this creates a pyramid shape by defining
      // vertex points in 3D space (x, y, z)
      beginShape();
      //  texture(img);
      // triangle 1
      //fill(#FFCBFE);
      noFill();
      vertex(-100, -100, -100);
      vertex( 100, -100, -100);
      vertex(   0, 0, 100);
      endShape(CLOSE);
      beginShape();
      texture (img);
      // triangle 2
      //fill(#015F21);
      vertex( 100, -100, -100);
      vertex( 100, 100, -100);
      vertex(   0, 0, 100);
      endShape(CLOSE);
      beginShape();
      texture(img);
    
      // triangle 3
      // fill(#8DDBDE);
      vertex( 100, 100, -100);
      vertex(-100, 100, -100);
      vertex(   0, 0, 100);
      endShape(CLOSE);
      beginShape();
      texture(img);
      // triangle 4
      //fill(#5D2D00);
      vertex(-100, 100, -100);
      vertex(-100, -100, -100);
      vertex(   0, 0, 100);
      endShape(CLOSE);
      beginShape();
      texture(img);
      // pyramid base
      //fill(#9CA24D);
      vertex(-100, -100, -100);
      vertex( 100, -100, -100);
      vertex( 100, 100, -100);
      vertex(-100, 100, -100);
      endShape(CLOSE);
    }
    //
    
Sign In or Register to comment.