示例#1
0
  public void addVertex(float x, float y, float z, float u, float v) {
    PVector vert = new PVector(x, y, z);
    PVector texCoord = new PVector(u, v);

    PVector vertNorm = PVector.div(vert, vert.mag());

    vertices.add(vert);
    texCoords.add(texCoord);
    normals.add(vertNorm);
  }
示例#2
0
 /**
  * Returns the normalized axis direction of the rotation represented by the Quaternion.
  *
  * <p>The result is null for an identity Quaternion.
  *
  * @see #angle()
  */
 public final PVector axis() {
   PVector res = new PVector(this.x, this.y, this.z);
   float sinus = res.mag();
   if (sinus > 1E-8f) res.div(sinus);
   if (PApplet.acos(this.w) <= HALF_PI) return res;
   else {
     res.x = -res.x;
     res.y = -res.y;
     res.z = -res.z;
     return res;
   }
 }
  public void setup() {

    mFont = createFont("ArialRoundedMTBold-36", 48);
    size(1440, 900, OPENGL);
    background(0);
    frameRate(120);
    //  model   = new OBJModel(this, "alyson_laugh.obj", "absolute", TRIANGLES);
    model = new OBJModel(this, "alyson_scared.obj", "absolute", TRIANGLES);
    //  model   = new OBJModel(this, "alyson_crying.obj", "absolute", TRIANGLES);

    smooth();
    colorMode(HSB);
    strokeWeight(4);

    model.scale(800);
    model.translateToCenter();

    detailValue = 3;
    scaleValue = 10;
    vertices = new ArrayList();
    ps = new ParticleSystem(this, scaleValue);

    PVector averagePosition = new PVector(0, 0, 0);

    for (int i = 0; i < model.getVertexCount(); i += detailValue) {
      PVector destinationPoint = model.getVertex(i);

      vertices.add(destinationPoint);

      averagePosition.add(destinationPoint);
    }

    averagePosition.div(vertices.size());

    for (int i = 0; i < vertices.size(); i++) {
      PVector destination = (PVector) vertices.get(i);
      Particle p = new Particle(this, averagePosition, destination);
      ps.addParticle(p);
    }
  }
示例#4
0
  /** Initializes the preview applet layout according to the graph's dimension. */
  private void initAppletLayout() {
    //            graphSheet.setMargin(MARGIN);
    if (model != null && model.getDimensions() != null && model.getTopLeftPosition() != null) {

      // initializes zoom
      Dimension dimensions = model.getDimensions();
      Point topLeftPostition = model.getTopLeftPosition();
      PVector box = new PVector((float) dimensions.getWidth(), (float) dimensions.getHeight());
      float ratioWidth = width / box.x;
      float ratioHeight = height / box.y;
      scaling = ratioWidth < ratioHeight ? ratioWidth : ratioHeight;

      // initializes move
      PVector semiBox = PVector.div(box, 2);
      PVector topLeftVector = new PVector((float) topLeftPostition.x, (float) topLeftPostition.y);
      PVector center = new PVector(width / 2f, height / 2f);
      PVector scaledCenter = PVector.add(topLeftVector, semiBox);
      trans.set(center);
      trans.sub(scaledCenter);
      lastMove.set(trans);
    }
  }
示例#5
0
 /**
  * ( begin auto-generated from PVector_normalize.xml )
  *
  * <p>Normalize the vector to length 1 (make it a unit vector).
  *
  * <p>( end auto-generated )
  *
  * @webref pvector:method
  * @usage web_application
  * @brief Normalize the vector to a length of 1
  */
 public void normalize() {
   float m = mag();
   if (m != 0 && m != 1) {
     div(m);
   }
 }
 public void applyForce(PVector f) {
   // generic enough to work for any force, including gravity
   acceleration = PVector.div(f, mass);
 }