Java Code Examples for org.lwjgl.util.vector.Matrix4f#invert()
The following examples show how to use
org.lwjgl.util.vector.Matrix4f#invert() .
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: TransformProvider.java From OpenModsLib with MIT License | 6 votes |
public Transformation(Orientation orientation) { final javax.vecmath.Matrix4f originalMatrix = new javax.vecmath.Matrix4f(); originalMatrix.set(orientation.getLocalToWorldMatrix()); asMatrix = TRSRTransformation.toLwjgl(originalMatrix); asBuffer = BufferUtils.createFloatBuffer(16); asMatrix.store(asBuffer); asBuffer.rewind(); asInverseMatrix = new Matrix4f(); Matrix4f.invert(asMatrix, asInverseMatrix); asInverseBuffer = BufferUtils.createFloatBuffer(16); asInverseMatrix.store(asInverseBuffer); asInverseBuffer.rewind(); }
Example 2
Source File: MouseActions.java From ldparteditor with MIT License | 5 votes |
public void translateViewport(float dx, float dy, Matrix4f viewport_translation, Matrix4f viewport_rotation, PerspectiveCalculator perspective) { Vector4f xAxis4f_translation = new Vector4f(dx, 0, 0, 1.0f); Vector4f yAxis4f_translation = new Vector4f(0, dy, 0, 1.0f); Matrix4f ovr_inverse2 = Matrix4f.invert(viewport_rotation, null); Matrix4f.transform(ovr_inverse2, xAxis4f_translation, xAxis4f_translation); Matrix4f.transform(ovr_inverse2, yAxis4f_translation, yAxis4f_translation); Vector3f xAxis3 = new Vector3f(xAxis4f_translation.x, xAxis4f_translation.y, xAxis4f_translation.z); Vector3f yAxis3 = new Vector3f(yAxis4f_translation.x, yAxis4f_translation.y, yAxis4f_translation.z); Matrix4f.load(old_viewport_translation, viewport_translation); Matrix4f.translate(xAxis3, old_viewport_translation, viewport_translation); Matrix4f.translate(yAxis3, viewport_translation, viewport_translation); perspective.calculateOriginData(); }
Example 3
Source File: KeyStateManager.java From ldparteditor with MIT License | 5 votes |
private static void translateView(Composite3D c3d, float dx, float dy) { PerspectiveCalculator perspective = c3d.getPerspectiveCalculator(); Matrix4f viewport_rotation = c3d.getRotation(); Matrix4f viewport_translation = c3d.getTranslation(); Matrix4f old_viewport_translation = new Matrix4f(); Matrix4f.load(c3d.getTranslation(), old_viewport_translation); Vector4f xAxis4f_translation = new Vector4f(dx, 0, 0, 1.0f); Vector4f yAxis4f_translation = new Vector4f(0, dy, 0, 1.0f); Matrix4f ovr_inverse2 = Matrix4f.invert(viewport_rotation, null); Matrix4f.transform(ovr_inverse2, xAxis4f_translation, xAxis4f_translation); Matrix4f.transform(ovr_inverse2, yAxis4f_translation, yAxis4f_translation); Vector3f xAxis3 = new Vector3f(xAxis4f_translation.x, xAxis4f_translation.y, xAxis4f_translation.z); Vector3f yAxis3 = new Vector3f(yAxis4f_translation.x, yAxis4f_translation.y, yAxis4f_translation.z); Matrix4f.load(old_viewport_translation, viewport_translation); Matrix4f.translate(xAxis3, old_viewport_translation, viewport_translation); Matrix4f.translate(yAxis3, viewport_translation, viewport_translation); perspective.calculateOriginData(); c3d.getVertexManager().getResetTimer().set(true); if (c3d.isSyncTranslation()) { float tx = c3d.getTranslation().m30; float ty = c3d.getTranslation().m31; float tz = c3d.getTranslation().m32; for (OpenGLRenderer renderer : Editor3DWindow.getRenders()) { Composite3D c3d2 = renderer.getC3D(); if (!c3d2.isDisposed() && c3d != c3d2 && c3d.getLockableDatFileReference().equals(c3d2.getLockableDatFileReference())) { c3d2.getTranslation().m30 = tx; c3d2.getTranslation().m31 = ty; c3d2.getTranslation().m32 = tz; ((ScalableComposite) c3d2.getParent()).redrawScales(); c3d2.getPerspectiveCalculator().initializeViewportPerspective(); } } } }
Example 4
Source File: GLUProjection.java From seppuku with GNU General Public License v3.0 | 4 votes |
/** * Updates the matrices. Needed whenever the viewport or one of the matrices has changed. * * @param viewport Viewport * @param modelview Modelview matrix * @param projection Projection matrix * @param widthScale (GUI Width) / (Display Width) * @param heightScale (GUI Height) / (Display Height) */ public void updateMatrices(IntBuffer viewport, FloatBuffer modelview, FloatBuffer projection, double widthScale, double heightScale) { this.viewport = viewport; this.modelview = modelview; this.projection = projection; this.widthScale = widthScale; this.heightScale = heightScale; //Get fov and display dimensions float fov = (float) Math.toDegrees(Math.atan(1.0D / this.projection.get(5)) * 2.0D); this.fovY = fov; this.displayWidth = this.viewport.get(2); this.displayHeight = this.viewport.get(3); this.fovX = (float) Math.toDegrees(2.0D * Math.atan((this.displayWidth / this.displayHeight) * Math.tan(Math.toRadians(this.fovY) / 2.0D))); //Getting modelview vectors Vector3D lv = new Vector3D(this.modelview.get(0), this.modelview.get(1), this.modelview.get(2)); Vector3D uv = new Vector3D(this.modelview.get(4), this.modelview.get(5), this.modelview.get(6)); Vector3D fv = new Vector3D(this.modelview.get(8), this.modelview.get(9), this.modelview.get(10)); //Default axes Vector3D nuv = new Vector3D(0, 1.0D, 0); Vector3D nlv = new Vector3D(1.0D, 0, 0); //Calculate yaw and pitch from modelview double yaw = Math.toDegrees(Math.atan2(nlv.cross(lv).length(), nlv.dot(lv))) + 180.0D; if (fv.x < 0.0D) { yaw = 360.0D - yaw; } double pitch = 0.0D; if ((-fv.y > 0.0D && yaw >= 90.0D && yaw < 270.0D) || (fv.y > 0.0D && !(yaw >= 90.0D && yaw < 270.0D))) { pitch = Math.toDegrees(Math.atan2(nuv.cross(uv).length(), nuv.dot(uv))); } else { pitch = -Math.toDegrees(Math.atan2(nuv.cross(uv).length(), nuv.dot(uv))); } this.lookVec = this.getRotationVector(yaw, pitch); //Get modelview matrix and invert it Matrix4f modelviewMatrix = new Matrix4f(); modelviewMatrix.load(this.modelview.asReadOnlyBuffer()); modelviewMatrix.invert(); //Get frustum position this.frustumPos = new Vector3D(modelviewMatrix.m30, modelviewMatrix.m31, modelviewMatrix.m32); this.frustum = this.getFrustum(this.frustumPos.x, this.frustumPos.y, this.frustumPos.z, yaw, pitch, fov, 1.0F, displayWidth / displayHeight); this.invFrustum = this.getFrustum(this.frustumPos.x, this.frustumPos.y, this.frustumPos.z, yaw - 180, -pitch, fov, 1.0F, displayWidth / displayHeight); //Set view vec this.viewVec = this.getRotationVector(yaw, pitch).normalized(); //Calculate screen border angles this.bra = Math.toDegrees(Math.acos((displayHeight * heightScale) / Math.sqrt(displayWidth * widthScale * displayWidth * widthScale + displayHeight * heightScale * displayHeight * heightScale))); this.bla = 360 - this.bra; this.tra = this.bla - 180; this.tla = this.bra + 180; //Create screen border lines this.rb = new Line(this.displayWidth * this.widthScale, 0, 0, 0, 1, 0); this.tb = new Line(0, 0, 0, 1, 0, 0); this.lb = new Line(0, 0, 0, 0, 1, 0); this.bb = new Line(0, this.displayHeight * this.heightScale, 0, 1, 0, 0); }
Example 5
Source File: Manipulator.java From ldparteditor with MIT License | 4 votes |
public FloatBuffer getTempTransformation() { Matrix4f.invert(result, resultinv); result.store(matrix); matrix.position(0); return matrix; }
Example 6
Source File: GDataCSG.java From ldparteditor with MIT License | 4 votes |
private static Integer selectCSG_helper(Composite3D c3d, Event event) { final PowerRay powerRay = new PowerRay(); final DatFile df = c3d.getLockableDatFileReference(); final HashBiMap<Integer, GData> dpl = df.getDrawPerLine_NOCLONE(); registeredData.putIfAbsent(df, new HashSet<GDataCSG>()); PerspectiveCalculator perspective = c3d.getPerspectiveCalculator(); Matrix4f viewport_rotation = c3d.getRotation(); Vector4f zAxis4f = new Vector4f(0, 0, -1f, 1f); Matrix4f ovr_inverse2 = Matrix4f.invert(viewport_rotation, null); Matrix4f.transform(ovr_inverse2, zAxis4f, zAxis4f); Vector4f rayDirection = (Vector4f) new Vector4f(zAxis4f.x, zAxis4f.y, zAxis4f.z, 0f).normalise(); rayDirection.w = 1f; Vertex[] triQuadVerts = new Vertex[3]; Vector4f orig = perspective.get3DCoordinatesFromScreen(event.x, event.y); Vector4f point = new Vector4f(orig); double minDist = Double.MAX_VALUE; final double[] dist = new double[1]; Integer result = null; GDataCSG resultObj = null; for (CSG csg : linkedCSG.putIfAbsent(df, new HashMap<String, CSG>()).values()) { for(Entry<GData3, IdAndPlane> pair : csg.getResult(df).entrySet()) { final GData3 triangle = pair.getKey(); triQuadVerts[0] = new Vertex(triangle.x1, triangle.y1, triangle.z1); triQuadVerts[1] = new Vertex(triangle.x2, triangle.y2, triangle.z2); triQuadVerts[2] = new Vertex(triangle.x3, triangle.y3, triangle.z3); if (powerRay.TRIANGLE_INTERSECT(orig, rayDirection, triQuadVerts[0], triQuadVerts[1], triQuadVerts[2], point, dist)) { if (dist[0] < minDist) { Integer result2 = pair.getValue().id; if (result2 != null) { for (GDataCSG c : registeredData.get(df)) { if (dpl.containsValue(c) && idToGDataCSG.putIfAbsent(df, new HashBiMap<Integer, GDataCSG>()).containsKey(result2)) { if (c.type == CSG.TRANSFORM && c.ref1 != null && c.ref2 != null || c.ref1 != null && c.ref2 == null && c.ref3 == null && c.type != CSG.COMPILE) { resultObj = idToGDataCSG.get(df).getValue(result2); if (resultObj != null && resultObj.ref1 != null && resultObj.ref1.endsWith("#>null")) { //$NON-NLS-1$ minDist = dist[0]; result = result2; break; } } } } } } } } } selectedBodyMap.putIfAbsent(df, new HashSet<GDataCSG>()); if (!(c3d.getKeys().isCtrlPressed() || (Cocoa.isCocoa && c3d.getKeys().isCmdPressed()))) { selectedBodyMap.get(df).clear(); } selectedBodyMap.get(df).add(resultObj); return result; }
Example 7
Source File: Joint.java From OpenGL-Animation with The Unlicense | 3 votes |
/** * This is called during set-up, after the joints hierarchy has been * created. This calculates the model-space bind transform of this joint * like so: </br> * </br> * {@code bindTransform = parentBindTransform * localBindTransform}</br> * </br> * where "bindTransform" is the model-space bind transform of this joint, * "parentBindTransform" is the model-space bind transform of the parent * joint, and "localBindTransform" is the bone-space bind transform of this * joint. It then calculates and stores the inverse of this model-space bind * transform, for use when calculating the final animation transform each * frame. It then recursively calls the method for all of the children * joints, so that they too calculate and store their inverse bind-pose * transform. * * @param parentBindTransform * - the model-space bind transform of the parent joint. */ protected void calcInverseBindTransform(Matrix4f parentBindTransform) { Matrix4f bindTransform = Matrix4f.mul(parentBindTransform, localBindTransform, null); Matrix4f.invert(bindTransform, inverseBindTransform); for (Joint child : children) { child.calcInverseBindTransform(bindTransform); } }
Example 8
Source File: Composite3D.java From ldparteditor with MIT License | 2 votes |
/** * Sets the transformation matrix of the viewport * * @param matrix * the matrix to set. */ public void setViewport(Matrix4f matrix) { GData.CACHE_viewByProjection.clear(); viewport_matrix.load(matrix); viewport_matrix_inv = (Matrix4f) matrix.invert(); }
Example 9
Source File: CompositePrimitive.java From ldparteditor with MIT License | 2 votes |
/** * Sets the transformation matrix of the viewport * * @param matrix * the matrix to set. */ public void setViewport(Matrix4f matrix) { viewport_matrix.load(matrix); viewport_matrix_inv = (Matrix4f) matrix.invert(); }