Java Code Examples for processing.core.PMatrix3D#apply()

The following examples show how to use processing.core.PMatrix3D#apply() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PaperScreen.java    From PapARt with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
     * *
     * Works only in 3D mode with beginDraw3D(). Change the currernt matrix to
     * the location of another PaperScreen. This could be used for drawing
     * objects or putting lights at another PaperScreen location.
     *
     * @param paperScreen PaperScreen to go to.
     */
    public void goTo(PaperScreen paperScreen) {

        if (this.isDrawingOnScreen == true) {
            throw new RuntimeException("Impossible to draw on another board. You need to draw using beginDraw3D() to do so.");
        }

//        if (this.currentGraphics != graphics) {
//            throw new RuntimeException("The given graphics context is not valid. Use the one given by beginDraw3D().");
//        }
        // get the location of this board...
        PMatrix3D loc = this.getLocation().get();
        loc.invert();
        loc.apply(paperScreen.getLocation());

        applyMatrix(loc);
    }
 
Example 2
Source File: DwShadowMap.java    From PixelFlow with MIT License 6 votes vote down vote up
public PMatrix3D getProjection(){
  pg_shadowmap.updateProjmodelview();

  // 1) create shadowmap matrix, 
  //    to transform positions from camera-space to the shadowmap-space (light-space)
  PMatrix3D mat_shadow = new PMatrix3D();
  // ndc (shadowmap) -> normalized (shadowmap) 
  //         [-1,+1] -> [0,1]
  mat_shadow.scale(0.5f);
  mat_shadow.translate(1,1,1);

  // model (world) -> modelview (shadowmap) -> ndc (shadowmap)
  mat_shadow.apply(pg_shadowmap.projection);
  
  return mat_shadow;
}
 
Example 3
Source File: DwShadowMap.java    From PixelFlow with MIT License 5 votes vote down vote up
public PMatrix3D getShadowmapMatrix(){
  // 1) create shadowmap matrix, 
  //    to transform positions from camera-space to the shadowmap-space (light-space)
  PMatrix3D mat_shadow = new PMatrix3D();
  // ndc (shadowmap) -> normalized (shadowmap) 
  //         [-1,+1] -> [0,1]
  mat_shadow.scale(0.5f);
  mat_shadow.translate(1,1,1);

  // model (world) -> modelview (shadowmap) -> ndc (shadowmap)
  mat_shadow.apply(pg_shadowmap.projmodelview);
  
  return mat_shadow;
}
 
Example 4
Source File: MarkerBoard.java    From PapARt with GNU Lesser General Public License v3.0 5 votes vote down vote up
public PMatrix3D getTransfoRelativeTo(Camera camera, MarkerBoard board2) {

        PMatrix3D tr1 = getTransfoMat(camera);
        PMatrix3D tr2 = board2.getTransfoMat(camera);

        tr2.apply(tr1);
        return tr2;
    }
 
Example 5
Source File: PaperScreen.java    From PapARt with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get a copy of the overall transform (after tracking and second
 * transform).
 *
 * @param camera
 * @return
 */
public PMatrix3D getLocation(Camera camera) {
    if ((!markerBoard.isTrackedBy(camera) && !this.useManualLocation)) {
        return extrinsics.get();
    }
    PMatrix3D combinedTransfos = getMainLocation(camera);
    combinedTransfos.apply(extrinsics);
    return combinedTransfos;
}
 
Example 6
Source File: PaperScreen.java    From PapARt with GNU Lesser General Public License v3.0 5 votes vote down vote up
private PVector getRelativePos(PVector v) {

        PMatrix3D location = this.getLocation().get();
        location.translate(v.x, v.y, v.z);
        PMatrix3D t = tableInv.get();
        t.apply(location);
        PVector tableRelativePos = new PVector(t.m03, t.m13, t.m23);

        return tableRelativePos;
    }
 
Example 7
Source File: Skylight_BulletPhysics_Basic.java    From PixelFlow with MIT License 4 votes vote down vote up
public void setup() {
    
    surface.setLocation(viewport_x, viewport_y);
    
    float SCENE_SCALE = 1000;
    
    capture = new DwFrameCapture(this, "examples/");
    font12 = createFont("../data/SourceCodePro-Regular.ttf", 12);

    cam = new PeasyCam(this, 0, 0, 0, SCENE_SCALE);
    perspective(60 * DEG_TO_RAD, width/(float)height, 2, SCENE_SCALE * 250);

    group_bulletbodies = createShape(GROUP);
    
//    Vector3f min = new Vector3f(-200, -200,    0);
//    Vector3f max = new Vector3f(+200, +200, +400);
//    physics = new BPhysics(min, max);
    physics = new BPhysics(); // no bounding box
    physics.world.setGravity(new Vector3f(0, 0, -300));
   
    pg_render = (PGraphics3D) createGraphics(width, height, P3D);
    pg_render.smooth(0);
    pg_render.beginDraw();
    pg_render.endDraw();
    
    
    // compute scene bounding-sphere
    DwBoundingSphere scene_bs = new DwBoundingSphere();
    scene_bs.set(0, 0, 200, 450);
    PMatrix3D mat_bs = scene_bs.getUnitSphereMatrix();

    // matrix, to place (centering, scaling) the scene in the viewport
    mat_scene_view = new PMatrix3D();
    mat_scene_view.scale(SCENE_SCALE);
    mat_scene_view.apply(mat_bs);

    // matrix, to place the scene in the skylight renderer
    mat_scene_bounds = mat_scene_view.get();
    mat_scene_bounds.invert();
    mat_scene_bounds.preApply(mat_bs);

    // callback for rendering the scene
    DwSceneDisplay scene_display = new DwSceneDisplay(){
      @Override
      public void display(PGraphics3D canvas) {
        displayScene(canvas);  
      }
    };
    
    // library context
    context = new DwPixelFlow(this);
    context.print();
    context.printGL();
    
    // postprocessing filters
    filter = DwFilter.get(context);
    
    // init skylight renderer
    skylight = new DwSkyLight(context, scene_display, mat_scene_bounds);
    
    // parameters for sky-light
    skylight.sky.param.iterations     = 50;
    skylight.sky.param.solar_azimuth  = 0;
    skylight.sky.param.solar_zenith   = 0;
    skylight.sky.param.sample_focus   = 1; // full sphere sampling
    skylight.sky.param.intensity      = 1.0f;
    skylight.sky.param.rgb            = new float[]{1,1,1};
    skylight.sky.param.shadowmap_size = 512; // quality vs. performance
    
    // parameters for sun-light
    skylight.sun.param.iterations     = 50;
    skylight.sun.param.solar_azimuth  = 35;
    skylight.sun.param.solar_zenith   = 65;
    skylight.sun.param.sample_focus   = 0.1f;
    skylight.sun.param.intensity      = 1.0f;
    skylight.sun.param.rgb            = new float[]{1,1,1};
    skylight.sun.param.shadowmap_size = 512;
    
    // postprocessing AA
    smaa = new SMAA(context);
    pg_aa = (PGraphics3D) createGraphics(width, height, P3D);
    pg_aa.smooth(0);
    pg_aa.textureSampling(5);
    
    
    dof = new DepthOfField(context);
    geombuffer = new DwScreenSpaceGeometryBuffer(context, scene_display);
    
    pg_tmp = (PGraphics3D) createGraphics(width, height, P3D);
    pg_tmp.smooth(0);
    DwUtils.changeTextureFormat(pg_tmp, GL2.GL_RGBA16F, GL2.GL_RGBA, GL2.GL_FLOAT);

    
    // fresh start
    reset();
    
    frameRate(60);
  }
 
Example 8
Source File: DwSkyLightShader.java    From PixelFlow with MIT License 4 votes vote down vote up
void setUniforms() {

    // 1) modelview (camera) -> model (world)
    PMatrix3D mat_modelviewInv = geombuffer.pg_geom.modelviewInv.get();

    // camera -> world -> shadowmap
    PMatrix3D mat_shadow = shadowmap.getShadowmapMatrix();
    mat_shadow.apply(mat_modelviewInv);
    mat_shadow.transpose(); // processing
    
    PMatrix3D mat_shadow_normal = mat_shadow.get();
    mat_shadow_normal.invert();
    mat_shadow_normal.transpose(); // processing
    
    PMatrix3D mat_shadow_normal_modelview = shadowmap.getModelView().get();
    mat_shadow_normal_modelview.apply(mat_modelviewInv);
    mat_shadow_normal_modelview.transpose(); // processing
    mat_shadow_normal_modelview.invert();
    mat_shadow_normal_modelview.transpose(); // processing
    
    PMatrix3D mat_shadow_normal_projection = shadowmap.getProjection().get();
    mat_shadow_normal_projection.invert();
    mat_shadow_normal_projection.transpose(); // processing
    
//    PMatrix3D mat_shadow_modelview = new PMatrix3D(shadowmap.pg_shadowmap.modelview);
//    mat_shadow_modelview.apply(mat_modelviewInv);
//    mat_shadow_modelview.transpose();

    // 2) transform light direction into camera space = inverse-transpose-modelView * direction
    mat_modelviewInv.transpose();
    PVector light_dir_cameraspace = mat_modelviewInv.mult(shadowmap.lightdir, null);
    light_dir_cameraspace.normalize();
    
    // projection matrix of the geometry buffer
    PMatrix3D mat_projection = geombuffer.pg_geom.projection.get();
    mat_projection.transpose(); // processing
    
    // temporal averaging
    float pass_mix = RENDER_PASS/(RENDER_PASS+1.0f);
    
    float w_shadow = shadowmap.pg_shadowmap.width;
    float h_shadow = shadowmap.pg_shadowmap.height;
    
    // shadow offset
    float shadow_map_size = Math.min(w_shadow, h_shadow);
    float shadow_bias_mag = 0.33f/shadow_map_size;
    
//    shadow_bias_mag = scene_scale/ shadow_map_size;

    
//    PMatrix3D mat_screen_to_eye = new PMatrix3D();
//    mat_screen_to_eye.scale(w, h, 1);
//    mat_screen_to_eye.scale(0.5f);
//    mat_screen_to_eye.translate(1,1,1);
//    mat_screen_to_eye.apply(pg.projection);
//    mat_screen_to_eye.invert();
//    mat_screen_to_eye.transpose(); // processing, row-col switch
    

    
    // 3) update shader uniforms
    shader.set("mat_projection"              , mat_projection                    );
    shader.set("mat_shadow"                  , mat_shadow                        );
    shader.set("mat_shadow_normal_modelview" , mat_shadow_normal_modelview , true);
    shader.set("mat_shadow_normal_projection", mat_shadow_normal_projection, true);
//    shader.set("mat_shadow_normal", mat_shadow_normal);
//    shader.set("mat_screen_to_eye", mat_screen_to_eye);
//    shader.set("mat_shadow_modelview", mat_shadow_modelview);
    shader.set("dir_light", light_dir_cameraspace);
    shader.set("pass_mix", pass_mix);
    shader.set("wh_shadow", w_shadow, h_shadow); // should match the dimensions of the shading buffers
    shader.set("shadow_bias_mag", shadow_bias_mag);

    
//    getBuffer(buf_mat_projection              , mat_projection                    );
//    getBuffer(buf_mat_shadow                  , mat_shadow                        );
//    getBuffer(buf_mat_shadow_normal_modelview , mat_shadow_normal_modelview , true);
//    getBuffer(buf_mat_shadow_normal_projection, mat_shadow_normal_projection, true);
//
//    boolean transpose = !false;
//    shader_.uniformMatrix4fv("mat_projection"              , 1, transpose, buf_mat_projection              , 0);
//    shader_.uniformMatrix4fv("mat_shadow"                  , 1, transpose, buf_mat_shadow                  , 0);
//    shader_.uniformMatrix3fv("mat_shadow_normal_modelview" , 1, transpose, buf_mat_shadow_normal_modelview , 0);
//    shader_.uniformMatrix3fv("mat_shadow_normal_projection", 1, transpose, buf_mat_shadow_normal_projection, 0);
//    shader_.uniform3f       ("dir_light", light_dir_cameraspace.x, light_dir_cameraspace.y, light_dir_cameraspace.z);
//    shader_.uniform1f       ("pass_mix", pass_mix);
//    shader_.uniform2f       ("wh_shadow", w_shadow, h_shadow);
//    shader_.uniform1f       ("shadow_bias_mag", shadow_bias_mag);
  }
 
Example 9
Source File: PickAndMove.java    From PixelFlow with MIT License 4 votes vote down vote up
public void updateMouseAction(){
  
  if(obj_sel == null){
    if(mouseX >= 0 && mouseX <  pg_pick.width && mouseY >= 0 && mouseY <  pg_pick.height) {
      int idx_curr = pg_pick.pixels[mouseY * pg_pick.width + mouseX];
      
      if(idx_prev != -1){
        scene_objects[idx_prev].shp_render.setFill(col_prev);
        idx_prev = -1;
      }
      
      // no mouse-over, just return
      if(idx_curr == 0){
        return;
      }

      // mouse-over, change fill color
      idx_curr &= 0x00FFFFFF;
      col_prev =  scene_objects[idx_curr].shp_render.getFill(0);
      scene_objects[idx_curr].shp_render.setFill(color(255, 64, 0));
      idx_prev = idx_curr;
      
      // mouse-over AND selection mode is active -> keep the object, and
      // keep a backup of its transformation matrix
      if(SELECT_OBJECT){
        obj_sel = scene_objects[idx_curr];
        obj_mat.set(obj_sel.mat);
        obj_off = null;
      }
    } 
  }
  
  // object selected and ready to be moved
  if(obj_sel != null){
    PGraphics3D pg_canvas = (PGraphics3D) this.g;
    
    // build object matrix
    PMatrix3D mvp = pg_canvas.projmodelview.get();
    mvp.apply(obj_mat);
    
    transform.useCurrentTransformationMatrix(pg_canvas, mvp);

    // transform object to screen-coords
    float[] screen = new float[4];
    float[] world  = new float[4];
    transform.worldToScreen(world, screen);
    
    // respect mouse-offset (to object center)
    if(obj_off == null){
      obj_off = new float[2];
      obj_off[0] = mouseX - screen[0];
      obj_off[1] = mouseY - screen[1];
    }
    
    // transform object (new screen-coords!) back to world-coords
    screen[0] = mouseX - obj_off[0];
    screen[1] = mouseY - obj_off[1];
    transform.screenToWorld(screen, world);

    // modify object matrix
    obj_sel.mat.set(obj_mat);
    obj_sel.mat.translate(world[0], world[1], world[2]);
    obj_sel.udpateShapesTransform();
  }
}
 
Example 10
Source File: Skylight_BulletPhysics_TowerDemolition.java    From PixelFlow with MIT License 4 votes vote down vote up
public void setup() {
    
    surface.setLocation(viewport_x, viewport_y);
    
    float SCENE_SCALE = 1000;
    
    capture = new DwFrameCapture(this, "examples/");
    
    font12 = createFont("../data/SourceCodePro-Regular.ttf", 12);
    font96 = createFont("../data/SourceCodePro-Regular.ttf", 32);
    
    cam = new PeasyCam(this, 0, 0, 0, SCENE_SCALE);
    perspective(60 * DEG_TO_RAD, width/(float)height, 2, SCENE_SCALE * 250);

    group_bulletbodies = createShape(GROUP);
    
//    Vector3f min = new Vector3f(-300, -300,    0);
//    Vector3f max = new Vector3f(+300, +300, +1000);
//    physics = new BPhysics(min, max);
    physics = new BPhysics(); // no bounding box
    physics.world.setGravity(new Vector3f(0, 0, -30));
   
    pg_render = (PGraphics3D) createGraphics(width, height, P3D);
    pg_render.smooth(0);
    pg_render.beginDraw();
    pg_render.endDraw();
    
    
    // compute scene bounding-sphere
    DwBoundingSphere scene_bs = new DwBoundingSphere();
    scene_bs.set(0, 0, 200, 450);
    PMatrix3D mat_bs = scene_bs.getUnitSphereMatrix();

    // matrix, to place (centering, scaling) the scene in the viewport
    mat_scene_view = new PMatrix3D();
    mat_scene_view.scale(SCENE_SCALE);
    mat_scene_view.apply(mat_bs);

    // matrix, to place the scene in the skylight renderer
    mat_scene_bounds = mat_scene_view.get();
    mat_scene_bounds.invert();
    mat_scene_bounds.preApply(mat_bs);

    // callback for rendering the scene
    DwSceneDisplay scene_display = new DwSceneDisplay(){
      @Override
      public void display(PGraphics3D canvas) {
        displayScene(canvas);  
      }
    };
    
    // library context
    context = new DwPixelFlow(this);
    context.print();
    context.printGL();
    
    // postprocessing filters
    filter = DwFilter.get(context);
    
    // init skylight renderer
    skylight = new DwSkyLight(context, scene_display, mat_scene_bounds);
    
    // parameters for sky-light
    skylight.sky.param.iterations     = 50;
    skylight.sky.param.solar_azimuth  = 0;
    skylight.sky.param.solar_zenith   = 0;
    skylight.sky.param.sample_focus   = 1; // full sphere sampling
    skylight.sky.param.intensity      = 1.0f;
    skylight.sky.param.rgb            = new float[]{1,1,1};
    skylight.sky.param.shadowmap_size = 512; // quality vs. performance
    
    // parameters for sun-light
    skylight.sun.param.iterations     = 50;
    skylight.sun.param.solar_azimuth  = 35;
    skylight.sun.param.solar_zenith   = 65;
    skylight.sun.param.sample_focus   = 0.1f;
    skylight.sun.param.intensity      = 1.0f;
    skylight.sun.param.rgb            = new float[]{1,1,1};
    skylight.sun.param.shadowmap_size = 512;
    
    // postprocessing AA
    smaa = new SMAA(context);
    pg_aa = (PGraphics3D) createGraphics(width, height, P3D);
    pg_aa.smooth(0);
    pg_aa.textureSampling(5);
    
    
    dof = new DepthOfField(context);
    geombuffer = new DwScreenSpaceGeometryBuffer(context, scene_display);
    
    pg_tmp = (PGraphics3D) createGraphics(width, height, P3D);
    pg_tmp.smooth(0);
    DwUtils.changeTextureFormat(pg_tmp, GL2.GL_RGBA16F, GL2.GL_RGBA, GL2.GL_FLOAT);
    
    // fresh start
    reset();
    createBuildings(BUILDING);
    frameRate(60);
  }
 
Example 11
Source File: TrackedView.java    From PapARt with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void computeCorners() {

        PMatrix3D pos = null;

        if (useManualConrers) {
            return;
        }

        if (usePaperLocation) {
            pos = paperScreen.getLocation();
        }

        if (useBoardLocation) {
            pos = board.getTransfoMat(camera).get();
        }

        if (pos == null) {
            throw new RuntimeException("ERROR in TrackedView, report this.");
        }

        PMatrix3D tmp = new PMatrix3D();

        tmp.apply(pos);

        for (int i = 0; i < 4; i++) {
            corner3DPos[i] = new PVector();
        }
        if (isYUp) {

            // bottom left
            tmp.translate(topLeftCorner.x, topLeftCorner.y);
            corner3DPos[0].x = tmp.m03;
            corner3DPos[0].y = tmp.m13;
            corner3DPos[0].z = tmp.m23;

            // bottom right
            tmp.translate(captureSizeMM.x, 0);
            corner3DPos[1].x = tmp.m03;
            corner3DPos[1].y = tmp.m13;
            corner3DPos[1].z = tmp.m23;

            // top right
            tmp.translate(0, -captureSizeMM.y, 0);
            corner3DPos[2].x = tmp.m03;
            corner3DPos[2].y = tmp.m13;
            corner3DPos[2].z = tmp.m23;

            // top left
            tmp.translate(-captureSizeMM.x, 0, 0);
            corner3DPos[3].x = tmp.m03;
            corner3DPos[3].y = tmp.m13;
            corner3DPos[3].z = tmp.m23;

        } else {

            // TODO: use BottowLeftCorner here ?!! 
            // top left
            tmp.translate(topLeftCorner.x, paperScreen.getDrawingSize().y - topLeftCorner.y);
            corner3DPos[3].x = tmp.m03;
            corner3DPos[3].y = tmp.m13;
            corner3DPos[3].z = tmp.m23;

            // top right
            tmp.translate(captureSizeMM.x, 0);
            corner3DPos[2].x = tmp.m03;
            corner3DPos[2].y = tmp.m13;
            corner3DPos[2].z = tmp.m23;

            // bottom right
            tmp.translate(0, -captureSizeMM.y, 0);
            corner3DPos[1].x = tmp.m03;
            corner3DPos[1].y = tmp.m13;
            corner3DPos[1].z = tmp.m23;

            // bottom left
            tmp.translate(-captureSizeMM.x, 0, 0);
            corner3DPos[0].x = tmp.m03;
            corner3DPos[0].y = tmp.m13;
            corner3DPos[0].z = tmp.m23;
        }

        screenPixelCoordinates.clear();
        for (int i = 0; i < 4; i++) {
            screenPixelCoordinates.add(camera.pdp.worldToPixel(corner3DPos[i], true));
        }
        cornersSet = true;
    }
 
Example 12
Source File: Skylight_BulletPhysics_Breakable3.java    From PixelFlow with MIT License 4 votes vote down vote up
public void setup() {
  
  surface.setLocation(viewport_x, viewport_y);
  
  float SCENE_SCALE = 1000;
  
  // for screenshot
  capture = new DwFrameCapture(this, "examples/");
  
  font12 = createFont("../data/SourceCodePro-Regular.ttf", 12);

  cam = new PeasyCam(this, 0, 0, 0, SCENE_SCALE);
  perspective(60 * DEG_TO_RAD, width/(float)height, 2, SCENE_SCALE * 250);

  group_bulletbodies = createShape(GROUP);
  
  physics = new MyBPhysics(); // no bounding box
  physics.world.setGravity(new Vector3f(0, 0, -100));
 
  pg_render = (PGraphics3D) createGraphics(width, height, P3D);
  pg_render.smooth(0);
  pg_render.beginDraw();
  pg_render.endDraw();
  
  
  // compute scene bounding-sphere
  DwBoundingSphere scene_bs = new DwBoundingSphere();
  scene_bs.set(0, 0, 200, 450);
  PMatrix3D mat_bs = scene_bs.getUnitSphereMatrix();

  // matrix, to place (centering, scaling) the scene in the viewport
  mat_scene_view = new PMatrix3D();
  mat_scene_view.scale(SCENE_SCALE);
  mat_scene_view.apply(mat_bs);

  // matrix, to place the scene in the skylight renderer
  mat_scene_bounds = mat_scene_view.get();
  mat_scene_bounds.invert();
  mat_scene_bounds.preApply(mat_bs);

  // callback for rendering the scene
  DwSceneDisplay scene_display = new DwSceneDisplay(){
    @Override
    public void display(PGraphics3D canvas) {
      displayScene(canvas);  
    }
  };
  
  // library context
  context = new DwPixelFlow(this);
  context.print();
  context.printGL();
  
  // postprocessing filters
  filter = DwFilter.get(context);
  
  // init skylight renderer
  skylight = new DwSkyLight(context, scene_display, mat_scene_bounds);
  
  // parameters for sky-light
  skylight.sky.param.iterations     = 50;
  skylight.sky.param.solar_azimuth  = 0;
  skylight.sky.param.solar_zenith   = 0;
  skylight.sky.param.sample_focus   = 1; // full sphere sampling
  skylight.sky.param.intensity      = 1.0f;
  skylight.sky.param.rgb            = new float[]{1,1,1};
  skylight.sky.param.shadowmap_size = 512; // quality vs. performance
  
  // parameters for sun-light
  skylight.sun.param.iterations     = 50;
  skylight.sun.param.solar_azimuth  = 35;
  skylight.sun.param.solar_zenith   = 65;
  skylight.sun.param.sample_focus   = 0.1f;
  skylight.sun.param.intensity      = 1.0f;
  skylight.sun.param.rgb            = new float[]{1,1,1};
  skylight.sun.param.shadowmap_size = 512;
  
  // postprocessing AA
  smaa = new SMAA(context);
  pg_aa = (PGraphics3D) createGraphics(width, height, P3D);
  pg_aa.smooth(0);
  pg_aa.textureSampling(5);
  
  
  dof = new DepthOfField(context);
  geombuffer = new DwScreenSpaceGeometryBuffer(context, scene_display);
  
  pg_tmp = (PGraphics3D) createGraphics(width, height, P3D);
  pg_tmp.smooth(0);
  DwUtils.changeTextureFormat(pg_tmp, GL2.GL_RGBA16F, GL2.GL_RGBA, GL2.GL_FLOAT);
  
  // fresh start
  reset();
  
  createFractureShape();
  
  frameRate(60);
}
 
Example 13
Source File: Skylight_BulletPhysics_MengerSponge.java    From PixelFlow with MIT License 4 votes vote down vote up
public void setup() {
  
  surface.setLocation(viewport_x, viewport_y);
  
  float SCENE_SCALE = 1000;
  
  // for screenshot
  capture = new DwFrameCapture(this, "examples/");
  
  font12 = createFont("../data/SourceCodePro-Regular.ttf", 12);

  cam = new PeasyCam(this, 0, 0, 0, SCENE_SCALE);
  perspective(60 * DEG_TO_RAD, width/(float)height, 2, SCENE_SCALE * 250);

  group_bulletbodies = createShape(GROUP);
  
  physics = new BPhysics(); // no bounding box
  physics.world.setGravity(new Vector3f(0, 0, -50));
 
  pg_render = (PGraphics3D) createGraphics(width, height, P3D);
  pg_render.smooth(0);
  pg_render.beginDraw();
  pg_render.endDraw();
  
  
  // compute scene bounding-sphere
  DwBoundingSphere scene_bs = new DwBoundingSphere();
  scene_bs.set(0, 0, 200, 450);
  PMatrix3D mat_bs = scene_bs.getUnitSphereMatrix();

  // matrix, to place (centering, scaling) the scene in the viewport
  mat_scene_view = new PMatrix3D();
  mat_scene_view.scale(SCENE_SCALE);
  mat_scene_view.apply(mat_bs);

  // matrix, to place the scene in the skylight renderer
  mat_scene_bounds = mat_scene_view.get();
  mat_scene_bounds.invert();
  mat_scene_bounds.preApply(mat_bs);

  // callback for rendering the scene
  DwSceneDisplay scene_display = new DwSceneDisplay(){
    @Override
    public void display(PGraphics3D canvas) {
      displayScene(canvas);  
    }
  };
  
  // library context
  context = new DwPixelFlow(this);
  context.print();
  context.printGL();
  
  // postprocessing filters
  filter = DwFilter.get(context);
  
  // init skylight renderer
  skylight = new DwSkyLight(context, scene_display, mat_scene_bounds);
  
  // parameters for sky-light
  skylight.sky.param.iterations     = 50;
  skylight.sky.param.solar_azimuth  = 0;
  skylight.sky.param.solar_zenith   = 0;
  skylight.sky.param.sample_focus   = 1; // full sphere sampling
  skylight.sky.param.intensity      = 1.0f;
  skylight.sky.param.rgb            = new float[]{1,1,1};
  skylight.sky.param.shadowmap_size = 512; // quality vs. performance
  
  // parameters for sun-light
  skylight.sun.param.iterations     = 50;
  skylight.sun.param.solar_azimuth  = 35;
  skylight.sun.param.solar_zenith   = 70;
  skylight.sun.param.sample_focus   = 0.1f;
  skylight.sun.param.intensity      = 1.0f;
  skylight.sun.param.rgb            = new float[]{1,1,1};
  skylight.sun.param.shadowmap_size = 512;
  
  // postprocessing AA
  smaa = new SMAA(context);
  pg_aa = (PGraphics3D) createGraphics(width, height, P3D);
  pg_aa.smooth(0);
  pg_aa.textureSampling(5);
  
  
  dof = new DepthOfField(context);
  geombuffer = new DwScreenSpaceGeometryBuffer(context, scene_display);
  
  pg_tmp = (PGraphics3D) createGraphics(width, height, P3D);
  pg_tmp.smooth(0);
  DwUtils.changeTextureFormat(pg_tmp, GL2.GL_RGBA16F, GL2.GL_RGBA, GL2.GL_FLOAT);

  // fresh start
  reset();
  
  createFractureShape();
  
  frameRate(60);
}
 
Example 14
Source File: Skylight_BulletPhysics_CellFracture.java    From PixelFlow with MIT License 4 votes vote down vote up
public void setup() {
  
  surface.setLocation(viewport_x, viewport_y);
  
  float SCENE_SCALE = 1000;
  
  // for screenshot
  capture = new DwFrameCapture(this, "examples/");
  
  font12 = createFont("../data/SourceCodePro-Regular.ttf", 12);

  cam = new PeasyCam(this, 0, 0, 0, SCENE_SCALE);
  perspective(60 * DEG_TO_RAD, width/(float)height, 2, SCENE_SCALE * 250);

  group_bulletbodies = createShape(GROUP);
  
  physics = new BPhysics(); // no bounding box
  physics.world.setGravity(new Vector3f(0, 0, -100));
 
  pg_render = (PGraphics3D) createGraphics(width, height, P3D);
  pg_render.smooth(0);
  pg_render.beginDraw();
  pg_render.endDraw();
  
  
  // compute scene bounding-sphere
  DwBoundingSphere scene_bs = new DwBoundingSphere();
  scene_bs.set(0, 0, 200, 450);
  PMatrix3D mat_bs = scene_bs.getUnitSphereMatrix();

  // matrix, to place (centering, scaling) the scene in the viewport
  mat_scene_view = new PMatrix3D();
  mat_scene_view.scale(SCENE_SCALE);
  mat_scene_view.apply(mat_bs);

  // matrix, to place the scene in the skylight renderer
  mat_scene_bounds = mat_scene_view.get();
  mat_scene_bounds.invert();
  mat_scene_bounds.preApply(mat_bs);

  // callback for rendering the scene
  DwSceneDisplay scene_display = new DwSceneDisplay(){
    @Override
    public void display(PGraphics3D canvas) {
      displayScene(canvas);  
    }
  };
  
  // library context
  context = new DwPixelFlow(this);
  context.print();
  context.printGL();
  
  // postprocessing filters
  filter = DwFilter.get(context);
  
  // init skylight renderer
  skylight = new DwSkyLight(context, scene_display, mat_scene_bounds);
  
  // parameters for sky-light
  skylight.sky.param.iterations     = 50;
  skylight.sky.param.solar_azimuth  = 0;
  skylight.sky.param.solar_zenith   = 0;
  skylight.sky.param.sample_focus   = 1; // full sphere sampling
  skylight.sky.param.intensity      = 1.0f;
  skylight.sky.param.rgb            = new float[]{1,1,1};
  skylight.sky.param.shadowmap_size = 512; // quality vs. performance
  
  // parameters for sun-light
  skylight.sun.param.iterations     = 50;
  skylight.sun.param.solar_azimuth  = 35;
  skylight.sun.param.solar_zenith   = 65;
  skylight.sun.param.sample_focus   = 0.1f;
  skylight.sun.param.intensity      = 1.0f;
  skylight.sun.param.rgb            = new float[]{1,1,1};
  skylight.sun.param.shadowmap_size = 512;
  
  // postprocessing AA
  smaa = new SMAA(context);
  pg_aa = (PGraphics3D) createGraphics(width, height, P3D);
  pg_aa.smooth(0);
  pg_aa.textureSampling(5);
  
  
  dof = new DepthOfField(context);
  geombuffer = new DwScreenSpaceGeometryBuffer(context, scene_display);
  
  pg_tmp = (PGraphics3D) createGraphics(width, height, P3D);
  pg_tmp.smooth(0);
  DwUtils.changeTextureFormat(pg_tmp, GL2.GL_RGBA16F, GL2.GL_RGBA, GL2.GL_FLOAT);


  // fresh start
  reset();
  
  createFractureShape();
  
  frameRate(60);
}
 
Example 15
Source File: PaperScreen.java    From PapARt with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Init VR rendering. The VR rendering creates a 3D "screen". It is used to
 * create 3D pop-up effects.
 *
 * @param cam Rendering origin.
 * @param userPos Position of the user, relative to the PaperScreen
 * @param nearPlane Close disance for OpengL in millimeters.
 * @param farPlane Far distance for OpenGL in millimeters.
 * @param isAnaglyph Use Anaglyph.
 * @param isLeft When analygph is it left or right, ignored otherwise.
 */
public void initDraw(Camera cam, PVector userPos, float nearPlane, float farPlane, boolean isAnaglyph, boolean isLeft) {

    PGraphicsOpenGL graphics = getGraphics();

    if (initPosM == null) {
        this.isOpenGL = true;
        // Transformation  Camera -> Marker

        initPosM = this.getLocation(cam);

        initPosM.translate(this.getRenderingSizeX() / 2, this.getRenderingSizeY() / 2);
        // All is relative to the paper's center. not the corner. 
        initPosM.scale(-1, 1, 1);

    }

    // get the current transformation... 
    PMatrix3D newPos = this.getLocation(cam);

    newPos.translate(this.getRenderingSizeX() / 2, this.getRenderingSizeY() / 2);
    newPos.scale(-1, 1, 1);

    newPos.invert();
    newPos.apply(initPosM);

    PVector user = new PVector();

    if (isAnaglyph && isLeft) {
        userPos.add(-halfEyeDist * 2, 0, 0);
    }
    newPos.mult(userPos, user);
    PVector paperCameraPos = user;

    // Camera must look perpendicular to the screen. 
    graphics.camera(paperCameraPos.x, paperCameraPos.y, paperCameraPos.z,
            paperCameraPos.x, paperCameraPos.y, 0,
            0, 1, 0);

    // http://www.gamedev.net/topic/597564-view-and-projection-matrices-for-vr-window-using-head-tracking/
    float nearFactor = nearPlane / paperCameraPos.z;

    float left = nearFactor * (-drawingSize.x / 2f - paperCameraPos.x);
    float right = nearFactor * (drawingSize.x / 2f - paperCameraPos.x);
    float top = nearFactor * (drawingSize.y / 2f - paperCameraPos.y);
    float bottom = nearFactor * (-drawingSize.y / 2f - paperCameraPos.y);

    graphics.frustum(left, right, bottom, top, nearPlane, farPlane);
    graphics.projection.m11 = -graphics.projection.m11;

    // No detection?
    PMatrix3D transformation = this.getLocation(cam);
    if (transformation.m03 == 0 && transformation.m13 == 0 && transformation.m23 == 0) {
        resetPos();
    }
}
 
Example 16
Source File: Skylight_BulletPhysics_Cubes.java    From PixelFlow with MIT License 4 votes vote down vote up
public void setup() {
  
  surface.setLocation(viewport_x, viewport_y);
  
  float SCENE_SCALE = 1000;
  
  // for screenshot
  capture = new DwFrameCapture(this, "examples/");
  
  font12 = createFont("../data/SourceCodePro-Regular.ttf", 12);

  cam = new PeasyCam(this, 0, 0, 0, SCENE_SCALE);
  perspective(60 * DEG_TO_RAD, width/(float)height, 2, SCENE_SCALE * 250);

  group_bulletbodies = createShape(GROUP);
  
  physics = new BPhysics(); // no bounding box
  physics.world.setGravity(new Vector3f(0, 0, -50));
 
  pg_render = (PGraphics3D) createGraphics(width, height, P3D);
  pg_render.smooth(0);
  pg_render.beginDraw();
  pg_render.endDraw();
  
  
  // compute scene bounding-sphere
  DwBoundingSphere scene_bs = new DwBoundingSphere();
  scene_bs.set(0, 0, 200, 450);
  PMatrix3D mat_bs = scene_bs.getUnitSphereMatrix();

  // matrix, to place (centering, scaling) the scene in the viewport
  mat_scene_view = new PMatrix3D();
  mat_scene_view.scale(SCENE_SCALE);
  mat_scene_view.apply(mat_bs);

  // matrix, to place the scene in the skylight renderer
  mat_scene_bounds = mat_scene_view.get();
  mat_scene_bounds.invert();
  mat_scene_bounds.preApply(mat_bs);

  // callback for rendering the scene
  DwSceneDisplay scene_display = new DwSceneDisplay(){
    @Override
    public void display(PGraphics3D canvas) {
      displayScene(canvas);  
    }
  };
  
  // library context
  context = new DwPixelFlow(this);
  context.print();
  context.printGL();
  
  // postprocessing filters
  filter = DwFilter.get(context);
  
  // init skylight renderer
  skylight = new DwSkyLight(context, scene_display, mat_scene_bounds);
  
  // parameters for sky-light
  skylight.sky.param.iterations     = 50;
  skylight.sky.param.solar_azimuth  = 0;
  skylight.sky.param.solar_zenith   = 0;
  skylight.sky.param.sample_focus   = 1; // full sphere sampling
  skylight.sky.param.intensity      = 1.0f;
  skylight.sky.param.rgb            = new float[]{1,1,1};
  skylight.sky.param.shadowmap_size = 512; // quality vs. performance
  
  // parameters for sun-light
  skylight.sun.param.iterations     = 50;
  skylight.sun.param.solar_azimuth  = 35;
  skylight.sun.param.solar_zenith   = 70;
  skylight.sun.param.sample_focus   = 0.1f;
  skylight.sun.param.intensity      = 1.0f;
  skylight.sun.param.rgb            = new float[]{1,1,1};
  skylight.sun.param.shadowmap_size = 512;
  
  // postprocessing AA
  smaa = new SMAA(context);
  pg_aa = (PGraphics3D) createGraphics(width, height, P3D);
  pg_aa.smooth(0);
  pg_aa.textureSampling(5);
  
  
  dof = new DepthOfField(context);
  geombuffer = new DwScreenSpaceGeometryBuffer(context, scene_display);
  
  pg_tmp = (PGraphics3D) createGraphics(width, height, P3D);
  pg_tmp.smooth(0);
  DwUtils.changeTextureFormat(pg_tmp, GL2.GL_RGBA16F, GL2.GL_RGBA, GL2.GL_FLOAT);

  // fresh start
  reset();
  
  createFractureShape();
  
  frameRate(60);
}
 
Example 17
Source File: PaperScreen.java    From PapARt with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Get a copy of the overall transform (after tracking and second
 * transform).
 *
 * @param trackedLocation
 * @return
 */
public PMatrix3D getLocation(PMatrix3D trackedLocation) {
    PMatrix3D combinedTransfos = trackedLocation.get();
    combinedTransfos.apply(extrinsics);
    return combinedTransfos;
}