Java Code Examples for processing.core.PMatrix3D#mult()
The following examples show how to use
processing.core.PMatrix3D#mult() .
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: DwFoldingTile.java From PixelFlow with MIT License | 6 votes |
public DwFoldingTile(TileData DEF, DwIndexedFaceSet ifs, int verts_idx, int faces_idx, PMatrix3D mat){ this.DEF = DEF; float[][] verts = new float[DEF.VERTS_COUNT][3]; for(int i = 0; i < DEF.VERTS_COUNT; i++){ mat.mult(DEF.VERTS[i], verts[i]); } int[][] faces = new int[DEF.FACES_COUNT][3]; for(int i = 0; i < DEF.FACES_COUNT; i++){ faces[i][0] = DEF.FACES[i][0] + verts_idx; faces[i][1] = DEF.FACES[i][1] + verts_idx; faces[i][2] = DEF.FACES[i][2] + verts_idx; } this.faces = faces; System.arraycopy(verts, 0, ifs.verts, verts_idx, DEF.VERTS_COUNT); System.arraycopy(faces, 0, ifs.faces, faces_idx, DEF.FACES_COUNT); }
Example 2
Source File: PaperScreen.java From PapARt with GNU Lesser General Public License v3.0 | 6 votes |
/** * Get the Location of a point located in another PaperScreen. Example: In * paperScreenA, there is an object at location (10, 10). We want to know * the 3D location of this point relative to this PaperScreen. * * @param paperScreen * @param point * @return */ public PVector getCoordFrom(PaperScreen paperScreen, PVector point) { // get a copy PMatrix3D thisLocationInv = this.getLocation().get(); thisLocationInv.invert(); PMatrix3D otherLocation = paperScreen.getLocation(); PVector cameraViewOfPoint = new PVector(); otherLocation.mult(point, cameraViewOfPoint); PVector thisViewOfPoint = new PVector(); thisLocationInv.mult(cameraViewOfPoint, thisViewOfPoint); if (Float.isNaN(thisViewOfPoint.x)) { return INVALID_VECTOR; } return thisViewOfPoint; }
Example 3
Source File: MarkerBoard.java From PapARt with GNU Lesser General Public License v3.0 | 5 votes |
public PVector getBoardLocation(Camera camera, ARDisplay display) { int id = getId(camera); PVector v = getPositionVector(id); // Apply extrinsics if required. if (display.hasExtrinsics()) { PMatrix3D extr = display.getExtrinsics(); PVector v2 = new PVector(); extr.mult(v, v2); v = v2; } PVector px = display.getProjectiveDeviceP().worldToPixel(v, true); return px; }
Example 4
Source File: _prmatmult.java From mesh with MIT License | 5 votes |
public static Tuple invoke(final Object arg0, final double x, final double y, final double z) { final PMatrix3D mat = (PMatrix3D)arg0; final float[] in = new float[]{(float)x, (float)y, (float)z}; final float[] out = new float[3]; mat.mult(in, out); return Tuple.from((double)out[0], (double)out[1], (double)out[2]); }
Example 5
Source File: DwSkyLightShader.java From PixelFlow with MIT License | 4 votes |
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 6
Source File: PaperScreen.java From PapARt with GNU Lesser General Public License v3.0 | 4 votes |
/** * 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(); } }