e : tagSet.entrySet()) {\n TagAction ta = e.getKey().getAction(TagAction.class);\n if(ta==null) {\n listener.error(e.getKey()+\" doesn't have CVS tag associated with it. Skipping\");\n continue;\n }\n listener.getLogger().println(\"Tagging \"+e.getKey()+\" to \"+e.getValue());\n try {\n e.getKey().keepLog();\n } catch (IOException x) {\n x.printStackTrace(listener.error(\"Failed to mark \"+e.getKey()+\" for keep\"));\n }\n ta.perform(e.getValue(), listener);\n listener.getLogger().println();\n }\n }\n }\n\n /**\n * Temporary hack for assisting trouble-shooting.\n *\n * \n * Setting this property to true would cause cvs log to dump a lot of messages.\n */\n public static boolean debugLogging = false;\n\n private static final long serialVersionUID = 1L;\n}\n"},"message":{"kind":"string","value":"improved the error message.\n\n\ngit-svn-id: 28f34f9aa52bc55a5ddd5be9e183c5cccadc6ee4@3810 71c3de6d-444a-0410-be80-ed276b4c234a\n"},"old_file":{"kind":"string","value":"core/src/main/java/hudson/scm/CVSSCM.java"},"subject":{"kind":"string","value":"improved the error message."}}},{"rowIdx":1440,"cells":{"lang":{"kind":"string","value":"Java"},"license":{"kind":"string","value":"mit"},"stderr":{"kind":"string","value":""},"commit":{"kind":"string","value":"5047c4e828bc4a2976727194a77c66e3d3ccef4d"},"returncode":{"kind":"number","value":0,"string":"0"},"repos":{"kind":"string","value":"bcoe/enronsearch,sarwarbhuiyan/enronsearch,bcoe/enronsearch,sarwarbhuiyan/enronsearch,sarwarbhuiyan/enronsearch,bcoe/enronsearch"},"new_contents":{"kind":"string","value":"package com.bcoe.enronsearch;\n\nimport java.io.IOException;\n\nimport org.elasticsearch.client.Client;\n\nimport org.elasticsearch.common.xcontent.XContentBuilder;\nimport org.elasticsearch.common.xcontent.XContentFactory;\n\nimport org.elasticsearch.action.admin.indices.create.*;\nimport org.elasticsearch.action.admin.indices.delete.*;\nimport org.elasticsearch.action.admin.indices.flush.*;\n\nimport org.elasticsearch.action.admin.cluster.health.*;\n\nimport org.elasticsearch.common.settings.*;\nimport org.elasticsearch.common.settings.ImmutableSettings;\n\nimport org.elasticsearch.action.search.SearchResponse;\nimport org.elasticsearch.action.search.SearchType;\nimport org.elasticsearch.index.query.FilterBuilders.*;\nimport org.elasticsearch.index.query.QueryBuilders;\n\nimport org.elasticsearch.client.transport.*;\nimport org.elasticsearch.common.transport.InetSocketTransportAddress;\n\n/*\nWrapper for ElasticSearch, performs\nsearching and indexing tasks.\n*/\npublic class ElasticSearch {\n\n private static String indexName = \"enron-messages\";\n private static String mappingName = \"message\";\n private Client client;\n\n public ElasticSearch() {\n client = new TransportClient()\n .addTransportAddress(new InetSocketTransportAddress(\n System.getenv(\"ES_HOST\"),\n Integer.parseInt( System.getenv(\"ES_PORT\") )\n ));\n }\n\n public void index() {\n deleteIndex();\n createIndex();\n putMapping();\n }\n\n private void deleteIndex() {\n try {\n client.admin()\n .indices()\n .delete(new DeleteIndexRequest(indexName))\n .actionGet();\n } catch (Exception e) {\n System.out.println(e);\n }\n }\n\n private void createIndex() {\n Settings indexSettings = ImmutableSettings.settingsBuilder()\n .put(\"number_of_shards\", 1)\n .put(\"number_of_replicas\", 0)\n .put(\"analysis.analyzer.default.tokenizer\", \"uax_url_email\")\n .build();\n\n CreateIndexRequestBuilder createIndexBuilder = client.admin()\n .indices()\n .prepareCreate(indexName);\n\n createIndexBuilder.setSettings(indexSettings);\n\n CreateIndexResponse createIndexResponse = createIndexBuilder\n .execute()\n .actionGet();\n\n waitForYellow();\n }\n\n private void waitForYellow() {\n ClusterHealthRequestBuilder healthRequest = client.admin()\n .cluster()\n .prepareHealth();\n \n healthRequest.setIndices(indexName);\n healthRequest.setWaitForYellowStatus();\n\n ClusterHealthResponse healthResponse = healthRequest.execute()\n .actionGet();\n }\n\n private void putMapping() {\n try {\n\n XContentBuilder mapping = XContentFactory.jsonBuilder()\n .startObject()\n .startObject(\"message\")\n .startObject(\"properties\")\n .startObject(\"to\")\n .field(\"type\", \"string\")\n .field(\"store\", \"yes\")\n .endObject()\n .startObject(\"from\")\n .field(\"type\", \"string\")\n .field(\"store\", \"yes\")\n .endObject()\n .startObject(\"subject\")\n .field(\"type\", \"string\")\n .field(\"store\", \"yes\")\n .endObject()\n .startObject(\"body\")\n .field(\"type\", \"string\")\n .field(\"store\", \"yes\")\n .endObject()\n .endObject()\n .endObject()\n .endObject();\n\n client.admin()\n .indices() \n .preparePutMapping(indexName) \n .setType(mappingName) \n .setSource(mapping) \n .execute()\n .actionGet(); \n\n flush();\n } catch (IOException e) {\n System.out.println(\"Failed to put mapping: \" + e);\n }\n }\n\n private void flush() {\n client.admin()\n .indices()\n .flush(new FlushRequest(indexName))\n .actionGet();\n }\n\n public void indexMessage(Message message) {\n try {\n XContentBuilder document = XContentFactory.jsonBuilder()\n .startObject()\n .field(\"to\", message.getTo())\n .field(\"from\", message.getFrom())\n .field(\"subject\", message.getSubject())\n .field(\"body\", message.getBody())\n .endObject();\n\n client.prepareIndex(indexName, mappingName, message.getId())\n .setSource(document)\n .execute()\n .actionGet();\n\n } catch (IOException e) {\n System.out.println(e);\n }\n }\n\n public SearchResponse search(String query) {\n return client.prepareSearch(indexName)\n .setTypes(mappingName)\n .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)\n .setQuery(\n QueryBuilders.queryString(query)\n .field(\"_all\")\n )\n .setFrom(0).setSize(10)\n .addHighlightedField(\"to\", 0, 0)\n .addHighlightedField(\"from\", 0, 0)\n .execute()\n .actionGet();\n }\n\n public void cleanup() {\n client.close();\n }\n}\n"},"new_file":{"kind":"string","value":"src/main/java/com/bcoe/enronsearch/ElasticSearch.java"},"old_contents":{"kind":"string","value":"package com.bcoe.enronsearch;\n\nimport java.io.IOException;\n\nimport org.elasticsearch.client.Client;\n\nimport org.elasticsearch.common.xcontent.XContentBuilder;\nimport org.elasticsearch.common.xcontent.XContentFactory;\n\nimport org.elasticsearch.action.admin.indices.create.*;\nimport org.elasticsearch.action.admin.indices.delete.*;\nimport org.elasticsearch.action.admin.indices.flush.*;\n\nimport org.elasticsearch.action.admin.cluster.health.*;\n\nimport org.elasticsearch.common.settings.*;\nimport org.elasticsearch.common.settings.ImmutableSettings;\n\nimport org.elasticsearch.action.search.SearchResponse;\nimport org.elasticsearch.action.search.SearchType;\nimport org.elasticsearch.index.query.FilterBuilders.*;\nimport org.elasticsearch.index.query.QueryBuilders;\n\nimport org.elasticsearch.client.transport.*;\nimport org.elasticsearch.common.transport.InetSocketTransportAddress;\n\n/*\nWrapper for ElasticSearch, performs\nsearching and indexing tasks.\n*/\npublic class ElasticSearch {\n\n private static String indexName = \"enron-messages\";\n private static String mappingName = \"message\";\n private Client client;\n\n public ElasticSearch() {\n client = new TransportClient()\n .addTransportAddress(new InetSocketTransportAddress(\n System.getenv(\"ES_HOST\"),\n Integer.parseInt( System.getenv(\"ES_PORT\") )\n ));\n }\n\n public void index() {\n deleteIndex();\n createIndex();\n putMapping();\n }\n\n private void deleteIndex() {\n try {\n client.admin()\n .indices()\n .delete(new DeleteIndexRequest(indexName))\n .actionGet();\n } catch (Exception e) {\n System.out.println(e);\n }\n }\n\n private void createIndex() {\n Settings indexSettings = ImmutableSettings.settingsBuilder()\n .put(\"number_of_shards\", 1)\n .put(\"number_of_replicas\", 0)\n .put(\"analysis.analyzer.default.tokenizer\", \"uax_url_email\")\n .build();\n\n CreateIndexRequestBuilder createIndexBuilder = client.admin()\n .indices()\n .prepareCreate(indexName);\n\n createIndexBuilder.setSettings(indexSettings);\n\n CreateIndexResponse createIndexResponse = createIndexBuilder\n .execute()\n .actionGet();\n\n waitForYellow();\n }\n\n private void waitForYellow() {\n ClusterHealthRequestBuilder healthRequest = client.admin()\n .cluster()\n .prepareHealth();\n \n healthRequest.setIndices(indexName);\n healthRequest.setWaitForYellowStatus();\n\n ClusterHealthResponse healthResponse = healthRequest.execute()\n .actionGet();\n }\n\n private void putMapping() {\n try {\n\n XContentBuilder mapping = XContentFactory.jsonBuilder()\n .startObject()\n .startObject(\"message\")\n .startObject(\"properties\")\n .startObject(\"to\")\n .field(\"type\", \"string\")\n .field(\"store\", \"yes\")\n .endObject()\n .startObject(\"from\")\n .field(\"type\", \"string\")\n .field(\"store\", \"yes\")\n .endObject()\n .startObject(\"subject\")\n .field(\"type\", \"string\")\n .field(\"store\", \"yes\")\n .endObject()\n .startObject(\"body\")\n .field(\"type\", \"string\")\n .field(\"store\", \"yes\")\n .endObject()\n .endObject()\n .endObject()\n .endObject();\n\n client.admin()\n .indices() \n .preparePutMapping(indexName) \n .setType(mappingName) \n .setSource(mapping) \n .execute()\n .actionGet(); \n\n flush();\n } catch (IOException e) {\n System.out.println(\"Failed to put mapping: \" + e);\n }\n }\n\n private void flush() {\n client.admin()\n .indices()\n .flush(new FlushRequest(indexName))\n .actionGet();\n }\n\n public void indexMessage(Message message) {\n try {\n XContentBuilder document = XContentFactory.jsonBuilder()\n .startObject()\n .field(\"to\", message.getTo())\n .field(\"from\", message.getFrom())\n .field(\"subject\", message.getSubject())\n .field(\"body\", message.getBody())\n .endObject();\n\n client.prepareIndex(indexName, mappingName, message.getId())\n .setSource(document)\n .execute()\n .actionGet();\n\n } catch (IOException e) {\n System.out.println(e);\n }\n }\n\n public SearchResponse search(String query) {\n return client.prepareSearch(indexName)\n .setTypes(mappingName)\n .setSearchType(SearchType.DFS_QUERY_THEN_FETCH)\n .setQuery(\n QueryBuilders.queryString(query)\n .field(\"_all\")\n )\n .setFrom(0).setSize(30)\n .addHighlightedField(\"to\", 0, 0)\n .addHighlightedField(\"from\", 0, 0)\n .execute()\n .actionGet();\n }\n\n public void cleanup() {\n client.close();\n }\n}\n"},"message":{"kind":"string","value":"reduced result set size.\n"},"old_file":{"kind":"string","value":"src/main/java/com/bcoe/enronsearch/ElasticSearch.java"},"subject":{"kind":"string","value":"reduced result set size."}}},{"rowIdx":1441,"cells":{"lang":{"kind":"string","value":"Java"},"license":{"kind":"string","value":"mit"},"stderr":{"kind":"string","value":""},"commit":{"kind":"string","value":"28099b243cbd93301a54b5726c250c9526af64f7"},"returncode":{"kind":"number","value":0,"string":"0"},"repos":{"kind":"string","value":"arnaudricaud/HPP_Project"},"new_contents":{"kind":"string","value":"package HPP_PROJECT;\n\nimport java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\n\nimport org.joda.time.DateTime;\nimport org.joda.time.format.DateTimeFormat;\nimport org.joda.time.format.DateTimeFormatter;\n\npublic class ReaderPost {\n\t\n\tprivate static BufferedReader br;\n\t\n\tpublic ReaderPost(String fichier) {\n\t\ttry{\n\t\t\tbr = new BufferedReader(new FileReader(fichier));\n\t\t}catch(Exception e){\n \t\te.printStackTrace();\n \t}\n\t}\n\n public static Post ReadPost(){\n \tString line = \"\";\n \t\n \ttry { \t\t \n \t\t line = br.readLine();\n \t}catch(Exception e){\n \t\te.printStackTrace();\n \t}\n \t\n \treturn split(line);\n }\n \n public static Post split(String line)\n {\n \t\n \tString[] list = line.split(\"\\\\|\");\n \tDateTimeFormatter formatter = DateTimeFormat.forPattern(\"yyyy-MM-dd'T'HH:mm:ss.SSSZ\");\n \tDateTime dt = formatter.parseDateTime(list[0]);\n \t\n \treturn new Post(dt, Integer.parseInt(list[1]), Integer.parseInt(list[2]), list[4]);\n }\n \n \n}"},"new_file":{"kind":"string","value":"src/main/java/HPP_PROJECT/ReaderPost.java"},"old_contents":{"kind":"string","value":"package HPP_PROJECT;\n\nimport java.io.BufferedReader;\nimport java.io.FileNotFoundException;\nimport java.io.FileReader;\nimport java.io.IOException;\n\nimport org.joda.time.DateTime;\nimport org.joda.time.format.DateTimeFormat;\nimport org.joda.time.format.DateTimeFormatter;\n\npublic class ReaderPost {\n\n public static Post ReadPost(String fichier){\n \tString line = \"\";\n \tBufferedReader br;\n \t\n \ttry {\n \t\t br = new BufferedReader(new FileReader(fichier)); \n \t\t line = br.readLine();\n \t}catch(Exception e){\n \t\te.printStackTrace();\n \t}\n \t\n \treturn split(line);\n }\n \n public static Post split(String line)\n {\n \t\n \tString[] list = line.split(\"\\\\|\");\n \tDateTimeFormatter formatter = DateTimeFormat.forPattern(\"yyyy-MM-dd'T'HH:mm:ss.SSSZ\");\n \tDateTime dt = formatter.parseDateTime(list[0]);\n \t\n \treturn new Post(dt, Integer.parseInt(list[1]), Integer.parseInt(list[2]), list[4]);\n }\n \n \n}"},"message":{"kind":"string","value":"Amelioration readpost\n\nAmelioration constructeur + attribut static\n"},"old_file":{"kind":"string","value":"src/main/java/HPP_PROJECT/ReaderPost.java"},"subject":{"kind":"string","value":"Amelioration readpost"}}},{"rowIdx":1442,"cells":{"lang":{"kind":"string","value":"Java"},"license":{"kind":"string","value":"mit"},"stderr":{"kind":"string","value":""},"commit":{"kind":"string","value":"3a1c025652f9cba2de2e06822d88d7d1a1267f4d"},"returncode":{"kind":"number","value":0,"string":"0"},"repos":{"kind":"string","value":"JOML-CI/JOML,JOML-CI/JOML,JOML-CI/JOML"},"new_contents":{"kind":"string","value":"/*\r\n * (C) Copyright 2015-2016 Richard Greenlees\r\n\r\n Permission is hereby granted, free of charge, to any person obtaining a copy\r\n of this software and associated documentation files (the \"Software\"), to deal\r\n in the Software without restriction, including without limitation the rights\r\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n copies of the Software, and to permit persons to whom the Software is\r\n furnished to do so, subject to the following conditions:\r\n\r\n The above copyright notice and this permission notice shall be included in\r\n all copies or substantial portions of the Software.\r\n\r\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r\n THE SOFTWARE.\r\n\r\n */\r\npackage org.joml;\r\n\r\nimport java.io.Externalizable;\r\nimport java.io.IOException;\r\nimport java.io.ObjectInput;\r\nimport java.io.ObjectOutput;\r\nimport java.nio.Buffer;\r\nimport java.nio.ByteBuffer;\r\nimport java.nio.FloatBuffer;\r\nimport java.text.DecimalFormat;\r\nimport java.text.NumberFormat;\r\n\r\n/**\r\n * Contains the definition of a 4x4 Matrix of floats, and associated functions to transform\r\n * it. The matrix is column-major to match OpenGL's interpretation, and it looks like this:\r\n *
\r\n * m00 m10 m20 m30
\r\n * m01 m11 m21 m31
\r\n * m02 m12 m22 m32
\r\n * m03 m13 m23 m33
\r\n * \r\n * @author Richard Greenlees\r\n * @author Kai Burjack\r\n */\r\npublic class Matrix4f implements Externalizable {\r\n\r\n private static final long serialVersionUID = 1L;\r\n\r\n /**\r\n * Argument to the first parameter of {@link #frustumPlane(int, Vector4f)}\r\n * identifying the plane with equation x=-1 when using the identity matrix. \r\n */\r\n public static final int PLANE_NX = 0;\r\n /**\r\n * Argument to the first parameter of {@link #frustumPlane(int, Vector4f)}\r\n * identifying the plane with equation x=1 when using the identity matrix. \r\n */\r\n public static final int PLANE_PX = 1;\r\n /**\r\n * Argument to the first parameter of {@link #frustumPlane(int, Vector4f)}\r\n * identifying the plane with equation y=-1 when using the identity matrix. \r\n */\r\n public static final int PLANE_NY= 2;\r\n /**\r\n * Argument to the first parameter of {@link #frustumPlane(int, Vector4f)}\r\n * identifying the plane with equation y=1 when using the identity matrix. \r\n */\r\n public static final int PLANE_PY = 3;\r\n /**\r\n * Argument to the first parameter of {@link #frustumPlane(int, Vector4f)}\r\n * identifying the plane with equation z=-1 when using the identity matrix. \r\n */\r\n public static final int PLANE_NZ = 4;\r\n /**\r\n * Argument to the first parameter of {@link #frustumPlane(int, Vector4f)}\r\n * identifying the plane with equation z=1 when using the identity matrix. \r\n */\r\n public static final int PLANE_PZ = 5;\r\n\r\n /**\r\n * Argument to the first parameter of {@link #frustumCorner(int, Vector3f)}\r\n * identifying the corner (-1, -1, -1) when using the identity matrix.\r\n */\r\n public static final int CORNER_NXNYNZ = 0;\r\n /**\r\n * Argument to the first parameter of {@link #frustumCorner(int, Vector3f)}\r\n * identifying the corner (1, -1, -1) when using the identity matrix.\r\n */\r\n public static final int CORNER_PXNYNZ = 1;\r\n /**\r\n * Argument to the first parameter of {@link #frustumCorner(int, Vector3f)}\r\n * identifying the corner (1, 1, -1) when using the identity matrix.\r\n */\r\n public static final int CORNER_PXPYNZ = 2;\r\n /**\r\n * Argument to the first parameter of {@link #frustumCorner(int, Vector3f)}\r\n * identifying the corner (-1, 1, -1) when using the identity matrix.\r\n */\r\n public static final int CORNER_NXPYNZ = 3;\r\n /**\r\n * Argument to the first parameter of {@link #frustumCorner(int, Vector3f)}\r\n * identifying the corner (1, -1, 1) when using the identity matrix.\r\n */\r\n public static final int CORNER_PXNYPZ = 4;\r\n /**\r\n * Argument to the first parameter of {@link #frustumCorner(int, Vector3f)}\r\n * identifying the corner (-1, -1, 1) when using the identity matrix.\r\n */\r\n public static final int CORNER_NXNYPZ = 5;\r\n /**\r\n * Argument to the first parameter of {@link #frustumCorner(int, Vector3f)}\r\n * identifying the corner (-1, 1, 1) when using the identity matrix.\r\n */\r\n public static final int CORNER_NXPYPZ = 6;\r\n /**\r\n * Argument to the first parameter of {@link #frustumCorner(int, Vector3f)}\r\n * identifying the corner (1, 1, 1) when using the identity matrix.\r\n */\r\n public static final int CORNER_PXPYPZ = 7;\r\n\r\n public float m00, m10, m20, m30;\r\n public float m01, m11, m21, m31;\r\n public float m02, m12, m22, m32;\r\n public float m03, m13, m23, m33;\r\n\r\n /**\r\n * Create a new {@link Matrix4f} and set it to {@link #identity() identity}.\r\n */\r\n public Matrix4f() {\r\n m00 = 1.0f;\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = 1.0f;\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = 0.0f;\r\n m22 = 1.0f;\r\n m23 = 0.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n }\r\n\r\n /**\r\n * Create a new {@link Matrix4f} by setting its uppper left 3x3 submatrix to the values of the given {@link Matrix3f}\r\n * and the rest to identity.\r\n * \r\n * @param mat\r\n * the {@link Matrix3f}\r\n */\r\n public Matrix4f(Matrix3f mat) {\r\n m00 = mat.m00;\r\n m01 = mat.m01;\r\n m02 = mat.m02;\r\n m10 = mat.m10;\r\n m11 = mat.m11;\r\n m12 = mat.m12;\r\n m20 = mat.m20;\r\n m21 = mat.m21;\r\n m22 = mat.m22;\r\n m33 = 1.0f;\r\n }\r\n\r\n /**\r\n * Create a new {@link Matrix4f} and make it a copy of the given matrix.\r\n * \r\n * @param mat\r\n * the {@link Matrix4f} to copy the values from\r\n */\r\n public Matrix4f(Matrix4f mat) {\r\n m00 = mat.m00;\r\n m01 = mat.m01;\r\n m02 = mat.m02;\r\n m03 = mat.m03;\r\n m10 = mat.m10;\r\n m11 = mat.m11;\r\n m12 = mat.m12;\r\n m13 = mat.m13;\r\n m20 = mat.m20;\r\n m21 = mat.m21;\r\n m22 = mat.m22;\r\n m23 = mat.m23;\r\n m30 = mat.m30;\r\n m31 = mat.m31;\r\n m32 = mat.m32;\r\n m33 = mat.m33;\r\n }\r\n\r\n /**\r\n * Create a new {@link Matrix4f} and make it a copy of the given matrix.\r\n *
\r\n * Note that due to the given {@link Matrix4d} storing values in double-precision and the constructed {@link Matrix4f} storing them\r\n * in single-precision, there is the possibility of losing precision.\r\n * \r\n * @param mat\r\n * the {@link Matrix4d} to copy the values from\r\n */\r\n public Matrix4f(Matrix4d mat) {\r\n m00 = (float) mat.m00;\r\n m01 = (float) mat.m01;\r\n m02 = (float) mat.m02;\r\n m03 = (float) mat.m03;\r\n m10 = (float) mat.m10;\r\n m11 = (float) mat.m11;\r\n m12 = (float) mat.m12;\r\n m13 = (float) mat.m13;\r\n m20 = (float) mat.m20;\r\n m21 = (float) mat.m21;\r\n m22 = (float) mat.m22;\r\n m23 = (float) mat.m23;\r\n m30 = (float) mat.m30;\r\n m31 = (float) mat.m31;\r\n m32 = (float) mat.m32;\r\n m33 = (float) mat.m33;\r\n }\r\n\r\n /**\r\n * Create a new 4x4 matrix using the supplied float values.\r\n * \r\n * @param m00\r\n * the value of m00\r\n * @param m01\r\n * the value of m01\r\n * @param m02\r\n * the value of m02\r\n * @param m03\r\n * the value of m03\r\n * @param m10\r\n * the value of m10\r\n * @param m11\r\n * the value of m11\r\n * @param m12\r\n * the value of m12\r\n * @param m13\r\n * the value of m13\r\n * @param m20\r\n * the value of m20\r\n * @param m21\r\n * the value of m21\r\n * @param m22\r\n * the value of m22\r\n * @param m23\r\n * the value of m23\r\n * @param m30\r\n * the value of m30\r\n * @param m31\r\n * the value of m31\r\n * @param m32\r\n * the value of m32\r\n * @param m33\r\n * the value of m33\r\n */\r\n public Matrix4f(float m00, float m01, float m02, float m03, \r\n float m10, float m11, float m12, float m13, \r\n float m20, float m21, float m22, float m23,\r\n float m30, float m31, float m32, float m33) {\r\n this.m00 = m00;\r\n this.m01 = m01;\r\n this.m02 = m02;\r\n this.m03 = m03;\r\n this.m10 = m10;\r\n this.m11 = m11;\r\n this.m12 = m12;\r\n this.m13 = m13;\r\n this.m20 = m20;\r\n this.m21 = m21;\r\n this.m22 = m22;\r\n this.m23 = m23;\r\n this.m30 = m30;\r\n this.m31 = m31;\r\n this.m32 = m32;\r\n this.m33 = m33;\r\n }\r\n\r\n /**\r\n * Create a new {@link Matrix4f} by reading its 16 float components from the given {@link FloatBuffer}\r\n * at the buffer's current position.\r\n *
\r\n * That FloatBuffer is expected to hold the values in column-major order.\r\n *
\r\n * The buffer's position will not be changed by this method.\r\n * \r\n * @param buffer\r\n * the {@link FloatBuffer} to read the matrix values from\r\n */\r\n public Matrix4f(FloatBuffer buffer) {\r\n MemUtil.INSTANCE.get(this, buffer.position(), buffer);\r\n }\r\n\r\n /**\r\n * Return the value of the matrix element at column 0 and row 0.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m00() {\r\n return m00;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 0 and row 1.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m01() {\r\n return m01;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 0 and row 2.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m02() {\r\n return m02;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 0 and row 3.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m03() {\r\n return m03;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 1 and row 0.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m10() {\r\n return m10;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 1 and row 1.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m11() {\r\n return m11;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 1 and row 2.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m12() {\r\n return m12;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 1 and row 3.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m13() {\r\n return m13;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 2 and row 0.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m20() {\r\n return m20;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 2 and row 1.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m21() {\r\n return m21;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 2 and row 2.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m22() {\r\n return m22;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 2 and row 3.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m23() {\r\n return m23;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 3 and row 0.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m30() {\r\n return m30;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 3 and row 1.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m31() {\r\n return m31;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 3 and row 2.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m32() {\r\n return m32;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 3 and row 3.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m33() {\r\n return m33;\r\n }\r\n\r\n /**\r\n * Set the value of the matrix element at column 0 and row 0\r\n * \r\n * @param m00\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m00(float m00) {\r\n this.m00 = m00;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 0 and row 1\r\n * \r\n * @param m01\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m01(float m01) {\r\n this.m01 = m01;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 0 and row 2\r\n * \r\n * @param m02\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m02(float m02) {\r\n this.m02 = m02;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 0 and row 3\r\n * \r\n * @param m03\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m03(float m03) {\r\n this.m03 = m03;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 1 and row 0\r\n * \r\n * @param m10\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m10(float m10) {\r\n this.m10 = m10;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 1 and row 1\r\n * \r\n * @param m11\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m11(float m11) {\r\n this.m11 = m11;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 1 and row 2\r\n * \r\n * @param m12\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m12(float m12) {\r\n this.m12 = m12;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 1 and row 3\r\n * \r\n * @param m13\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m13(float m13) {\r\n this.m13 = m13;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 2 and row 0\r\n * \r\n * @param m20\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m20(float m20) {\r\n this.m20 = m20;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 2 and row 1\r\n * \r\n * @param m21\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m21(float m21) {\r\n this.m21 = m21;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 2 and row 2\r\n * \r\n * @param m22\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m22(float m22) {\r\n this.m22 = m22;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 2 and row 3\r\n * \r\n * @param m23\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m23(float m23) {\r\n this.m23 = m23;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 3 and row 0\r\n * \r\n * @param m30\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m30(float m30) {\r\n this.m30 = m30;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 3 and row 1\r\n * \r\n * @param m31\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m31(float m31) {\r\n this.m31 = m31;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 3 and row 2\r\n * \r\n * @param m32\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m32(float m32) {\r\n this.m32 = m32;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 3 and row 3\r\n * \r\n * @param m33\r\n * the new value\r\n * @return this\r\n */\r\n public Matrix4f m33(float m33) {\r\n this.m33 = m33;\r\n return this;\r\n }\r\n\r\n /**\r\n * Reset this matrix to the identity.\r\n *
\r\n * Please note that if a call to {@link #identity()} is immediately followed by a call to:\r\n * {@link #translate(float, float, float) translate}, \r\n * {@link #rotate(float, float, float, float) rotate},\r\n * {@link #scale(float, float, float) scale},\r\n * {@link #perspective(float, float, float, float) perspective},\r\n * {@link #frustum(float, float, float, float, float, float) frustum},\r\n * {@link #ortho(float, float, float, float, float, float) ortho},\r\n * {@link #ortho2D(float, float, float, float) ortho2D},\r\n * {@link #lookAt(float, float, float, float, float, float, float, float, float) lookAt},\r\n * {@link #lookAlong(float, float, float, float, float, float) lookAlong},\r\n * or any of their overloads, then the call to {@link #identity()} can be omitted and the subsequent call replaced with:\r\n * {@link #translation(float, float, float) translation},\r\n * {@link #rotation(float, float, float, float) rotation},\r\n * {@link #scaling(float, float, float) scaling},\r\n * {@link #setPerspective(float, float, float, float) setPerspective},\r\n * {@link #setFrustum(float, float, float, float, float, float) setFrustum},\r\n * {@link #setOrtho(float, float, float, float, float, float) setOrtho},\r\n * {@link #setOrtho2D(float, float, float, float) setOrtho2D},\r\n * {@link #setLookAt(float, float, float, float, float, float, float, float, float) setLookAt},\r\n * {@link #setLookAlong(float, float, float, float, float, float) setLookAlong},\r\n * or any of their overloads.\r\n * \r\n * @return this\r\n */\r\n public Matrix4f identity() {\r\n m00 = 1.0f;\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = 1.0f;\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = 0.0f;\r\n m22 = 1.0f;\r\n m23 = 0.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Store the values of the given matrix m
into this
matrix.\r\n * \r\n * @see #Matrix4f(Matrix4f)\r\n * @see #get(Matrix4f)\r\n * \r\n * @param m\r\n * the matrix to copy the values from\r\n * @return this\r\n */\r\n public Matrix4f set(Matrix4f m) {\r\n m00 = m.m00;\r\n m01 = m.m01;\r\n m02 = m.m02;\r\n m03 = m.m03;\r\n m10 = m.m10;\r\n m11 = m.m11;\r\n m12 = m.m12;\r\n m13 = m.m13;\r\n m20 = m.m20;\r\n m21 = m.m21;\r\n m22 = m.m22;\r\n m23 = m.m23;\r\n m30 = m.m30;\r\n m31 = m.m31;\r\n m32 = m.m32;\r\n m33 = m.m33;\r\n return this;\r\n }\r\n\r\n /**\r\n * Store the values of the given matrix m
into this
matrix.\r\n *
\r\n * Note that due to the given matrix m
storing values in double-precision and this
matrix storing\r\n * them in single-precision, there is the possibility to lose precision.\r\n * \r\n * @see #Matrix4f(Matrix4d)\r\n * @see #get(Matrix4d)\r\n * \r\n * @param m\r\n * the matrix to copy the values from\r\n * @return this\r\n */\r\n public Matrix4f set(Matrix4d m) {\r\n m00 = (float) m.m00;\r\n m01 = (float) m.m01;\r\n m02 = (float) m.m02;\r\n m03 = (float) m.m03;\r\n m10 = (float) m.m10;\r\n m11 = (float) m.m11;\r\n m12 = (float) m.m12;\r\n m13 = (float) m.m13;\r\n m20 = (float) m.m20;\r\n m21 = (float) m.m21;\r\n m22 = (float) m.m22;\r\n m23 = (float) m.m23;\r\n m30 = (float) m.m30;\r\n m31 = (float) m.m31;\r\n m32 = (float) m.m32;\r\n m33 = (float) m.m33;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the upper left 3x3 submatrix of this {@link Matrix4f} to the given {@link Matrix3f} \r\n * and the rest to identity.\r\n * \r\n * @see #Matrix4f(Matrix3f)\r\n * \r\n * @param mat\r\n * the {@link Matrix3f}\r\n * @return this\r\n */\r\n public Matrix4f set(Matrix3f mat) {\r\n m00 = mat.m00;\r\n m01 = mat.m01;\r\n m02 = mat.m02;\r\n m03 = 0.0f;\r\n m10 = mat.m10;\r\n m11 = mat.m11;\r\n m12 = mat.m12;\r\n m13 = 0.0f;\r\n m20 = mat.m20;\r\n m21 = mat.m21;\r\n m22 = mat.m22;\r\n m23 = 0.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be equivalent to the rotation specified by the given {@link AxisAngle4f}.\r\n * \r\n * @param axisAngle\r\n * the {@link AxisAngle4f}\r\n * @return this\r\n */\r\n public Matrix4f set(AxisAngle4f axisAngle) {\r\n float x = axisAngle.x;\r\n float y = axisAngle.y;\r\n float z = axisAngle.z;\r\n double angle = axisAngle.angle;\r\n double n = Math.sqrt(x*x + y*y + z*z);\r\n n = 1/n;\r\n x *= n;\r\n y *= n;\r\n z *= n;\r\n double c = Math.cos(angle);\r\n double s = Math.sin(angle);\r\n double omc = 1.0 - c;\r\n m00 = (float)(c + x*x*omc);\r\n m11 = (float)(c + y*y*omc);\r\n m22 = (float)(c + z*z*omc);\r\n double tmp1 = x*y*omc;\r\n double tmp2 = z*s;\r\n m10 = (float)(tmp1 - tmp2);\r\n m01 = (float)(tmp1 + tmp2);\r\n tmp1 = x*z*omc;\r\n tmp2 = y*s;\r\n m20 = (float)(tmp1 + tmp2);\r\n m02 = (float)(tmp1 - tmp2);\r\n tmp1 = y*z*omc;\r\n tmp2 = x*s;\r\n m21 = (float)(tmp1 - tmp2);\r\n m12 = (float)(tmp1 + tmp2);\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be equivalent to the rotation specified by the given {@link AxisAngle4d}.\r\n * \r\n * @param axisAngle\r\n * the {@link AxisAngle4d}\r\n * @return this\r\n */\r\n public Matrix4f set(AxisAngle4d axisAngle) {\r\n double x = axisAngle.x;\r\n double y = axisAngle.y;\r\n double z = axisAngle.z;\r\n double angle = axisAngle.angle;\r\n double n = Math.sqrt(x*x + y*y + z*z);\r\n n = 1/n;\r\n x *= n;\r\n y *= n;\r\n z *= n;\r\n double c = Math.cos(angle);\r\n double s = Math.sin(angle);\r\n double omc = 1.0 - c;\r\n m00 = (float)(c + x*x*omc);\r\n m11 = (float)(c + y*y*omc);\r\n m22 = (float)(c + z*z*omc);\r\n double tmp1 = x*y*omc;\r\n double tmp2 = z*s;\r\n m10 = (float)(tmp1 - tmp2);\r\n m01 = (float)(tmp1 + tmp2);\r\n tmp1 = x*z*omc;\r\n tmp2 = y*s;\r\n m20 = (float)(tmp1 + tmp2);\r\n m02 = (float)(tmp1 - tmp2);\r\n tmp1 = y*z*omc;\r\n tmp2 = x*s;\r\n m21 = (float)(tmp1 - tmp2);\r\n m12 = (float)(tmp1 + tmp2);\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be equivalent to the rotation specified by the given {@link Quaternionf}.\r\n * \r\n * @see Quaternionf#get(Matrix4f)\r\n * \r\n * @param q\r\n * the {@link Quaternionf}\r\n * @return this\r\n */\r\n public Matrix4f set(Quaternionf q) {\r\n q.get(this);\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be equivalent to the rotation specified by the given {@link Quaterniond}.\r\n * \r\n * @see Quaterniond#get(Matrix4f)\r\n * \r\n * @param q\r\n * the {@link Quaterniond}\r\n * @return this\r\n */\r\n public Matrix4f set(Quaterniond q) {\r\n q.get(this);\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the upper left 3x3 submatrix of this {@link Matrix4f} to that of the given {@link Matrix4f} \r\n * and don't change the other elements.\r\n * \r\n * @param mat\r\n * the {@link Matrix4f}\r\n * @return this\r\n */\r\n public Matrix4f set3x3(Matrix4f mat) {\r\n m00 = mat.m00;\r\n m01 = mat.m01;\r\n m02 = mat.m02;\r\n m10 = mat.m10;\r\n m11 = mat.m11;\r\n m12 = mat.m12;\r\n m20 = mat.m20;\r\n m21 = mat.m21;\r\n m22 = mat.m22;\r\n return this;\r\n }\r\n\r\n /**\r\n * Multiply this matrix by the supplied right
matrix and store the result in this
.\r\n *
\r\n * If M
is this
matrix and R
the right
matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * transformation of the right matrix will be applied first!\r\n *\r\n * @param right\r\n * the right operand of the matrix multiplication\r\n * @return this\r\n */\r\n public Matrix4f mul(Matrix4f right) {\r\n return mul(right, this);\r\n }\r\n\r\n /**\r\n * Multiply this matrix by the supplied right
matrix and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and R
the right
matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * transformation of the right matrix will be applied first!\r\n *\r\n * @param right\r\n * the right operand of the matrix multiplication\r\n * @param dest\r\n * the destination matrix, which will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f mul(Matrix4f right, Matrix4f dest) {\r\n float nm00 = m00 * right.m00 + m10 * right.m01 + m20 * right.m02 + m30 * right.m03;\r\n float nm01 = m01 * right.m00 + m11 * right.m01 + m21 * right.m02 + m31 * right.m03;\r\n float nm02 = m02 * right.m00 + m12 * right.m01 + m22 * right.m02 + m32 * right.m03;\r\n float nm03 = m03 * right.m00 + m13 * right.m01 + m23 * right.m02 + m33 * right.m03;\r\n float nm10 = m00 * right.m10 + m10 * right.m11 + m20 * right.m12 + m30 * right.m13;\r\n float nm11 = m01 * right.m10 + m11 * right.m11 + m21 * right.m12 + m31 * right.m13;\r\n float nm12 = m02 * right.m10 + m12 * right.m11 + m22 * right.m12 + m32 * right.m13;\r\n float nm13 = m03 * right.m10 + m13 * right.m11 + m23 * right.m12 + m33 * right.m13;\r\n float nm20 = m00 * right.m20 + m10 * right.m21 + m20 * right.m22 + m30 * right.m23;\r\n float nm21 = m01 * right.m20 + m11 * right.m21 + m21 * right.m22 + m31 * right.m23;\r\n float nm22 = m02 * right.m20 + m12 * right.m21 + m22 * right.m22 + m32 * right.m23;\r\n float nm23 = m03 * right.m20 + m13 * right.m21 + m23 * right.m22 + m33 * right.m23;\r\n float nm30 = m00 * right.m30 + m10 * right.m31 + m20 * right.m32 + m30 * right.m33;\r\n float nm31 = m01 * right.m30 + m11 * right.m31 + m21 * right.m32 + m31 * right.m33;\r\n float nm32 = m02 * right.m30 + m12 * right.m31 + m22 * right.m32 + m32 * right.m33;\r\n float nm33 = m03 * right.m30 + m13 * right.m31 + m23 * right.m32 + m33 * right.m33;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Multiply this
symmetric perspective projection matrix by the supplied {@link #isAffine() affine} view
matrix.\r\n *
\r\n * If P
is this
matrix and V
the view
matrix,\r\n * then the new matrix will be P * V
. So when transforming a\r\n * vector v
with the new matrix by using P * V * v
, the\r\n * transformation of the view
matrix will be applied first!\r\n *\r\n * @param view\r\n * the {@link #isAffine() affine} matrix to multiply this
symmetric perspective projection matrix by\r\n * @return dest\r\n */\r\n public Matrix4f mulPerspectiveAffine(Matrix4f view) {\r\n return mulPerspectiveAffine(view, this);\r\n }\r\n\r\n /**\r\n * Multiply this
symmetric perspective projection matrix by the supplied {@link #isAffine() affine} view
matrix and store the result in dest
.\r\n *
\r\n * If P
is this
matrix and V
the view
matrix,\r\n * then the new matrix will be P * V
. So when transforming a\r\n * vector v
with the new matrix by using P * V * v
, the\r\n * transformation of the view
matrix will be applied first!\r\n *\r\n * @param view\r\n * the {@link #isAffine() affine} matrix to multiply this
symmetric perspective projection matrix by\r\n * @param dest\r\n * the destination matrix, which will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f mulPerspectiveAffine(Matrix4f view, Matrix4f dest) {\r\n float nm00 = m00 * view.m00;\r\n float nm01 = m11 * view.m01;\r\n float nm02 = m22 * view.m02;\r\n float nm03 = m23 * view.m02;\r\n float nm10 = m00 * view.m10;\r\n float nm11 = m11 * view.m11;\r\n float nm12 = m22 * view.m12;\r\n float nm13 = m23 * view.m12;\r\n float nm20 = m00 * view.m20;\r\n float nm21 = m11 * view.m21;\r\n float nm22 = m22 * view.m22;\r\n float nm23 = m23 * view.m22;\r\n float nm30 = m00 * view.m30;\r\n float nm31 = m11 * view.m31;\r\n float nm32 = m22 * view.m32 + m32;\r\n float nm33 = m23 * view.m32;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Multiply this matrix by the supplied right
matrix, which is assumed to be {@link #isAffine() affine}, and store the result in this
.\r\n *
\r\n * This method assumes that the given right
matrix represents an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and can be used to speed up matrix multiplication if the matrix only represents affine transformations, such as translation, rotation, scaling and shearing (in any combination).\r\n *
\r\n * If M
is this
matrix and R
the right
matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * transformation of the right matrix will be applied first!\r\n *\r\n * @param right\r\n * the right operand of the matrix multiplication (the last row is assumed to be (0, 0, 0, 1))\r\n * @return this\r\n */\r\n public Matrix4f mulAffineR(Matrix4f right) {\r\n return mulAffineR(right, this);\r\n }\r\n\r\n /**\r\n * Multiply this matrix by the supplied right
matrix, which is assumed to be {@link #isAffine() affine}, and store the result in dest
.\r\n *
\r\n * This method assumes that the given right
matrix represents an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and can be used to speed up matrix multiplication if the matrix only represents affine transformations, such as translation, rotation, scaling and shearing (in any combination).\r\n *
\r\n * If M
is this
matrix and R
the right
matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * transformation of the right matrix will be applied first!\r\n *\r\n * @param right\r\n * the right operand of the matrix multiplication (the last row is assumed to be (0, 0, 0, 1))\r\n * @param dest\r\n * the destination matrix, which will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f mulAffineR(Matrix4f right, Matrix4f dest) {\r\n float nm00 = m00 * right.m00 + m10 * right.m01 + m20 * right.m02;\r\n float nm01 = m01 * right.m00 + m11 * right.m01 + m21 * right.m02;\r\n float nm02 = m02 * right.m00 + m12 * right.m01 + m22 * right.m02;\r\n float nm03 = m03 * right.m00 + m13 * right.m01 + m23 * right.m02;\r\n float nm10 = m00 * right.m10 + m10 * right.m11 + m20 * right.m12;\r\n float nm11 = m01 * right.m10 + m11 * right.m11 + m21 * right.m12;\r\n float nm12 = m02 * right.m10 + m12 * right.m11 + m22 * right.m12;\r\n float nm13 = m03 * right.m10 + m13 * right.m11 + m23 * right.m12;\r\n float nm20 = m00 * right.m20 + m10 * right.m21 + m20 * right.m22;\r\n float nm21 = m01 * right.m20 + m11 * right.m21 + m21 * right.m22;\r\n float nm22 = m02 * right.m20 + m12 * right.m21 + m22 * right.m22;\r\n float nm23 = m03 * right.m20 + m13 * right.m21 + m23 * right.m22;\r\n float nm30 = m00 * right.m30 + m10 * right.m31 + m20 * right.m32 + m30;\r\n float nm31 = m01 * right.m30 + m11 * right.m31 + m21 * right.m32 + m31;\r\n float nm32 = m02 * right.m30 + m12 * right.m31 + m22 * right.m32 + m32;\r\n float nm33 = m03 * right.m30 + m13 * right.m31 + m23 * right.m32 + m33;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Multiply this matrix by the supplied right
matrix, both of which are assumed to be {@link #isAffine() affine}, and store the result in this
.\r\n *
\r\n * This method assumes that this
matrix and the given right
matrix both represent an {@link #isAffine() affine} transformation\r\n * (i.e. their last rows are equal to (0, 0, 0, 1))\r\n * and can be used to speed up matrix multiplication if the matrices only represent affine transformations, such as translation, rotation, scaling and shearing (in any combination).\r\n *
\r\n * This method will not modify either the last row of this
or the last row of right
.\r\n *
\r\n * If M
is this
matrix and R
the right
matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * transformation of the right matrix will be applied first!\r\n *\r\n * @param right\r\n * the right operand of the matrix multiplication (the last row is assumed to be (0, 0, 0, 1))\r\n * @return this\r\n */\r\n public Matrix4f mulAffine(Matrix4f right) {\r\n return mulAffine(right, this);\r\n }\r\n\r\n /**\r\n * Multiply this matrix by the supplied right
matrix, both of which are assumed to be {@link #isAffine() affine}, and store the result in dest
.\r\n *
\r\n * This method assumes that this
matrix and the given right
matrix both represent an {@link #isAffine() affine} transformation\r\n * (i.e. their last rows are equal to (0, 0, 0, 1))\r\n * and can be used to speed up matrix multiplication if the matrices only represent affine transformations, such as translation, rotation, scaling and shearing (in any combination).\r\n *
\r\n * This method will not modify either the last row of this
or the last row of right
.\r\n *
\r\n * If M
is this
matrix and R
the right
matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * transformation of the right matrix will be applied first!\r\n *\r\n * @param right\r\n * the right operand of the matrix multiplication (the last row is assumed to be (0, 0, 0, 1))\r\n * @param dest\r\n * the destination matrix, which will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f mulAffine(Matrix4f right, Matrix4f dest) {\r\n float nm00 = m00 * right.m00 + m10 * right.m01 + m20 * right.m02;\r\n float nm01 = m01 * right.m00 + m11 * right.m01 + m21 * right.m02;\r\n float nm02 = m02 * right.m00 + m12 * right.m01 + m22 * right.m02;\r\n float nm03 = m03;\r\n float nm10 = m00 * right.m10 + m10 * right.m11 + m20 * right.m12;\r\n float nm11 = m01 * right.m10 + m11 * right.m11 + m21 * right.m12;\r\n float nm12 = m02 * right.m10 + m12 * right.m11 + m22 * right.m12;\r\n float nm13 = m13;\r\n float nm20 = m00 * right.m20 + m10 * right.m21 + m20 * right.m22;\r\n float nm21 = m01 * right.m20 + m11 * right.m21 + m21 * right.m22;\r\n float nm22 = m02 * right.m20 + m12 * right.m21 + m22 * right.m22;\r\n float nm23 = m23;\r\n float nm30 = m00 * right.m30 + m10 * right.m31 + m20 * right.m32 + m30;\r\n float nm31 = m01 * right.m30 + m11 * right.m31 + m21 * right.m32 + m31;\r\n float nm32 = m02 * right.m30 + m12 * right.m31 + m22 * right.m32 + m32;\r\n float nm33 = m33;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Multiply this
orthographic projection matrix by the supplied {@link #isAffine() affine} view
matrix.\r\n *
\r\n * If M
is this
matrix and V
the view
matrix,\r\n * then the new matrix will be M * V
. So when transforming a\r\n * vector v
with the new matrix by using M * V * v
, the\r\n * transformation of the view
matrix will be applied first!\r\n *\r\n * @param view\r\n * the affine matrix which to multiply this
with\r\n * @return dest\r\n */\r\n public Matrix4f mulOrthoAffine(Matrix4f view) {\r\n return mulOrthoAffine(view, this);\r\n }\r\n\r\n /**\r\n * Multiply this
orthographic projection matrix by the supplied {@link #isAffine() affine} view
matrix\r\n * and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and V
the view
matrix,\r\n * then the new matrix will be M * V
. So when transforming a\r\n * vector v
with the new matrix by using M * V * v
, the\r\n * transformation of the view
matrix will be applied first!\r\n *\r\n * @param view\r\n * the affine matrix which to multiply this
with\r\n * @param dest\r\n * the destination matrix, which will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f mulOrthoAffine(Matrix4f view, Matrix4f dest) {\r\n float nm00 = m00 * view.m00;\r\n float nm01 = m11 * view.m01;\r\n float nm02 = m22 * view.m02;\r\n float nm03 = 0.0f;\r\n float nm10 = m00 * view.m10;\r\n float nm11 = m11 * view.m11;\r\n float nm12 = m22 * view.m12;\r\n float nm13 = 0.0f;\r\n float nm20 = m00 * view.m20;\r\n float nm21 = m11 * view.m21;\r\n float nm22 = m22 * view.m22;\r\n float nm23 = 0.0f;\r\n float nm30 = m00 * view.m30 + m30;\r\n float nm31 = m11 * view.m31 + m31;\r\n float nm32 = m22 * view.m32 + m32;\r\n float nm33 = 1.0f;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Component-wise add the upper 4x3 submatrices of this
and other
\r\n * by first multiplying each component of other
's 4x3 submatrix by otherFactor
and\r\n * adding that result to this
.\r\n *
\r\n * The matrix other
will not be changed.\r\n * \r\n * @param other\r\n * the other matrix \r\n * @param otherFactor\r\n * the factor to multiply each of the other matrix's 4x3 components\r\n * @return this\r\n */\r\n public Matrix4f fma4x3(Matrix4f other, float otherFactor) {\r\n return fma4x3(other, otherFactor, this);\r\n }\r\n\r\n /**\r\n * Component-wise add the upper 4x3 submatrices of this
and other
\r\n * by first multiplying each component of other
's 4x3 submatrix by otherFactor
,\r\n * adding that to this
and storing the final result in dest
.\r\n *
\r\n * The other components of dest
will be set to the ones of this
.\r\n *
\r\n * The matrices this
and other
will not be changed.\r\n * \r\n * @param other\r\n * the other matrix \r\n * @param otherFactor\r\n * the factor to multiply each of the other matrix's 4x3 components\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f fma4x3(Matrix4f other, float otherFactor, Matrix4f dest) {\r\n dest.m00 = m00 + other.m00 * otherFactor;\r\n dest.m01 = m01 + other.m01 * otherFactor;\r\n dest.m02 = m02 + other.m02 * otherFactor;\r\n dest.m03 = m03;\r\n dest.m10 = m10 + other.m10 * otherFactor;\r\n dest.m11 = m11 + other.m11 * otherFactor;\r\n dest.m12 = m12 + other.m12 * otherFactor;\r\n dest.m13 = m13;\r\n dest.m20 = m20 + other.m20 * otherFactor;\r\n dest.m21 = m21 + other.m21 * otherFactor;\r\n dest.m22 = m22 + other.m22 * otherFactor;\r\n dest.m23 = m23;\r\n dest.m30 = m30 + other.m30 * otherFactor;\r\n dest.m31 = m31 + other.m31 * otherFactor;\r\n dest.m32 = m32 + other.m32 * otherFactor;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Component-wise add this
and other
.\r\n * \r\n * @param other\r\n * the other addend \r\n * @return this\r\n */\r\n public Matrix4f add(Matrix4f other) {\r\n return add(other, this);\r\n }\r\n\r\n /**\r\n * Component-wise add this
and other
and store the result in dest
.\r\n * \r\n * @param other\r\n * the other addend \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f add(Matrix4f other, Matrix4f dest) {\r\n dest.m00 = m00 + other.m00;\r\n dest.m01 = m01 + other.m01;\r\n dest.m02 = m02 + other.m02;\r\n dest.m03 = m03 + other.m03;\r\n dest.m10 = m10 + other.m10;\r\n dest.m11 = m11 + other.m11;\r\n dest.m12 = m12 + other.m12;\r\n dest.m13 = m13 + other.m13;\r\n dest.m20 = m20 + other.m20;\r\n dest.m21 = m21 + other.m21;\r\n dest.m22 = m22 + other.m22;\r\n dest.m23 = m23 + other.m23;\r\n dest.m30 = m30 + other.m30;\r\n dest.m31 = m31 + other.m31;\r\n dest.m32 = m32 + other.m32;\r\n dest.m33 = m33 + other.m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Component-wise subtract subtrahend
from this
.\r\n * \r\n * @param subtrahend\r\n * the subtrahend\r\n * @return this\r\n */\r\n public Matrix4f sub(Matrix4f subtrahend) {\r\n return sub(subtrahend, this);\r\n }\r\n\r\n /**\r\n * Component-wise subtract subtrahend
from this
and store the result in dest
.\r\n * \r\n * @param subtrahend\r\n * the subtrahend \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f sub(Matrix4f subtrahend, Matrix4f dest) {\r\n dest.m00 = m00 - subtrahend.m00;\r\n dest.m01 = m01 - subtrahend.m01;\r\n dest.m02 = m02 - subtrahend.m02;\r\n dest.m03 = m03 - subtrahend.m03;\r\n dest.m10 = m10 - subtrahend.m10;\r\n dest.m11 = m11 - subtrahend.m11;\r\n dest.m12 = m12 - subtrahend.m12;\r\n dest.m13 = m13 - subtrahend.m13;\r\n dest.m20 = m20 - subtrahend.m20;\r\n dest.m21 = m21 - subtrahend.m21;\r\n dest.m22 = m22 - subtrahend.m22;\r\n dest.m23 = m23 - subtrahend.m23;\r\n dest.m30 = m30 - subtrahend.m30;\r\n dest.m31 = m31 - subtrahend.m31;\r\n dest.m32 = m32 - subtrahend.m32;\r\n dest.m33 = m33 - subtrahend.m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Component-wise multiply this
by other
.\r\n * \r\n * @param other\r\n * the other matrix\r\n * @return this\r\n */\r\n public Matrix4f mulComponentWise(Matrix4f other) {\r\n return mulComponentWise(other, this);\r\n }\r\n\r\n /**\r\n * Component-wise multiply this
by other
and store the result in dest
.\r\n * \r\n * @param other\r\n * the other matrix\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f mulComponentWise(Matrix4f other, Matrix4f dest) {\r\n dest.m00 = m00 * other.m00;\r\n dest.m01 = m01 * other.m01;\r\n dest.m02 = m02 * other.m02;\r\n dest.m03 = m03 * other.m03;\r\n dest.m10 = m10 * other.m10;\r\n dest.m11 = m11 * other.m11;\r\n dest.m12 = m12 * other.m12;\r\n dest.m13 = m13 * other.m13;\r\n dest.m20 = m20 * other.m20;\r\n dest.m21 = m21 * other.m21;\r\n dest.m22 = m22 * other.m22;\r\n dest.m23 = m23 * other.m23;\r\n dest.m30 = m30 * other.m30;\r\n dest.m31 = m31 * other.m31;\r\n dest.m32 = m32 * other.m32;\r\n dest.m33 = m33 * other.m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Component-wise add the upper 4x3 submatrices of this
and other
.\r\n * \r\n * @param other\r\n * the other addend \r\n * @return this\r\n */\r\n public Matrix4f add4x3(Matrix4f other) {\r\n return add4x3(other, this);\r\n }\r\n\r\n /**\r\n * Component-wise add the upper 4x3 submatrices of this
and other
\r\n * and store the result in dest
.\r\n *
\r\n * The other components of dest
will be set to the ones of this
.\r\n * \r\n * @param other\r\n * the other addend\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f add4x3(Matrix4f other, Matrix4f dest) {\r\n dest.m00 = m00 + other.m00;\r\n dest.m01 = m01 + other.m01;\r\n dest.m02 = m02 + other.m02;\r\n dest.m03 = m03;\r\n dest.m10 = m10 + other.m10;\r\n dest.m11 = m11 + other.m11;\r\n dest.m12 = m12 + other.m12;\r\n dest.m13 = m13;\r\n dest.m20 = m20 + other.m20;\r\n dest.m21 = m21 + other.m21;\r\n dest.m22 = m22 + other.m22;\r\n dest.m23 = m23;\r\n dest.m30 = m30 + other.m30;\r\n dest.m31 = m31 + other.m31;\r\n dest.m32 = m32 + other.m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Component-wise subtract the upper 4x3 submatrices of subtrahend
from this
.\r\n * \r\n * @param subtrahend\r\n * the subtrahend\r\n * @return this\r\n */\r\n public Matrix4f sub4x3(Matrix4f subtrahend) {\r\n return sub4x3(subtrahend, this);\r\n }\r\n\r\n /**\r\n * Component-wise subtract the upper 4x3 submatrices of subtrahend
from this
\r\n * and store the result in dest
.\r\n *
\r\n * The other components of dest
will be set to the ones of this
.\r\n * \r\n * @param subtrahend\r\n * the subtrahend\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f sub4x3(Matrix4f subtrahend, Matrix4f dest) {\r\n dest.m00 = m00 - subtrahend.m00;\r\n dest.m01 = m01 - subtrahend.m01;\r\n dest.m02 = m02 - subtrahend.m02;\r\n dest.m03 = m03;\r\n dest.m10 = m10 - subtrahend.m10;\r\n dest.m11 = m11 - subtrahend.m11;\r\n dest.m12 = m12 - subtrahend.m12;\r\n dest.m13 = m13;\r\n dest.m20 = m20 - subtrahend.m20;\r\n dest.m21 = m21 - subtrahend.m21;\r\n dest.m22 = m22 - subtrahend.m22;\r\n dest.m23 = m23;\r\n dest.m30 = m30 - subtrahend.m30;\r\n dest.m31 = m31 - subtrahend.m31;\r\n dest.m32 = m32 - subtrahend.m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Component-wise multiply the upper 4x3 submatrices of this
by other
.\r\n * \r\n * @param other\r\n * the other matrix\r\n * @return this\r\n */\r\n public Matrix4f mul4x3ComponentWise(Matrix4f other) {\r\n return mul4x3ComponentWise(other, this);\r\n }\r\n\r\n /**\r\n * Component-wise multiply the upper 4x3 submatrices of this
by other
\r\n * and store the result in dest
.\r\n *
\r\n * The other components of dest
will be set to the ones of this
.\r\n * \r\n * @param other\r\n * the other matrix\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f mul4x3ComponentWise(Matrix4f other, Matrix4f dest) {\r\n dest.m00 = m00 * other.m00;\r\n dest.m01 = m01 * other.m01;\r\n dest.m02 = m02 * other.m02;\r\n dest.m03 = m03;\r\n dest.m10 = m10 * other.m10;\r\n dest.m11 = m11 * other.m11;\r\n dest.m12 = m12 * other.m12;\r\n dest.m13 = m13;\r\n dest.m20 = m20 * other.m20;\r\n dest.m21 = m21 * other.m21;\r\n dest.m22 = m22 * other.m22;\r\n dest.m23 = m23;\r\n dest.m30 = m30 * other.m30;\r\n dest.m31 = m31 * other.m31;\r\n dest.m32 = m32 * other.m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Set the values within this matrix to the supplied float values. The matrix will look like this:
\r\n *\r\n * m00, m10, m20, m30
\r\n * m01, m11, m21, m31
\r\n * m02, m12, m22, m32
\r\n * m03, m13, m23, m33\r\n * \r\n * @param m00\r\n * the new value of m00\r\n * @param m01\r\n * the new value of m01\r\n * @param m02\r\n * the new value of m02\r\n * @param m03\r\n * the new value of m03\r\n * @param m10\r\n * the new value of m10\r\n * @param m11\r\n * the new value of m11\r\n * @param m12\r\n * the new value of m12\r\n * @param m13\r\n * the new value of m13\r\n * @param m20\r\n * the new value of m20\r\n * @param m21\r\n * the new value of m21\r\n * @param m22\r\n * the new value of m22\r\n * @param m23\r\n * the new value of m23\r\n * @param m30\r\n * the new value of m30\r\n * @param m31\r\n * the new value of m31\r\n * @param m32\r\n * the new value of m32\r\n * @param m33\r\n * the new value of m33\r\n * @return this\r\n */\r\n public Matrix4f set(float m00, float m01, float m02, float m03,\r\n float m10, float m11, float m12, float m13,\r\n float m20, float m21, float m22, float m23, \r\n float m30, float m31, float m32, float m33) {\r\n this.m00 = m00;\r\n this.m01 = m01;\r\n this.m02 = m02;\r\n this.m03 = m03;\r\n this.m10 = m10;\r\n this.m11 = m11;\r\n this.m12 = m12;\r\n this.m13 = m13;\r\n this.m20 = m20;\r\n this.m21 = m21;\r\n this.m22 = m22;\r\n this.m23 = m23;\r\n this.m30 = m30;\r\n this.m31 = m31;\r\n this.m32 = m32;\r\n this.m33 = m33;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the values in the matrix using a float array that contains the matrix elements in column-major order.\r\n *
\r\n * The results will look like this:
\r\n * \r\n * 0, 4, 8, 12
\r\n * 1, 5, 9, 13
\r\n * 2, 6, 10, 14
\r\n * 3, 7, 11, 15
\r\n * \r\n * @see #set(float[])\r\n * \r\n * @param m\r\n * the array to read the matrix values from\r\n * @param off\r\n * the offset into the array\r\n * @return this\r\n */\r\n public Matrix4f set(float m[], int off) {\r\n m00 = m[off+0];\r\n m01 = m[off+1];\r\n m02 = m[off+2];\r\n m03 = m[off+3];\r\n m10 = m[off+4];\r\n m11 = m[off+5];\r\n m12 = m[off+6];\r\n m13 = m[off+7];\r\n m20 = m[off+8];\r\n m21 = m[off+9];\r\n m22 = m[off+10];\r\n m23 = m[off+11];\r\n m30 = m[off+12];\r\n m31 = m[off+13];\r\n m32 = m[off+14];\r\n m33 = m[off+15];\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the values in the matrix using a float array that contains the matrix elements in column-major order.\r\n *
\r\n * The results will look like this:
\r\n * \r\n * 0, 4, 8, 12
\r\n * 1, 5, 9, 13
\r\n * 2, 6, 10, 14
\r\n * 3, 7, 11, 15
\r\n * \r\n * @see #set(float[], int)\r\n * \r\n * @param m\r\n * the array to read the matrix values from\r\n * @return this\r\n */\r\n public Matrix4f set(float m[]) {\r\n return set(m, 0);\r\n }\r\n\r\n /**\r\n * Set the values of this matrix by reading 16 float values from the given {@link FloatBuffer} in column-major order,\r\n * starting at its current position.\r\n *
\r\n * The FloatBuffer is expected to contain the values in column-major order.\r\n *
\r\n * The position of the FloatBuffer will not be changed by this method.\r\n * \r\n * @param buffer\r\n * the FloatBuffer to read the matrix values from in column-major order\r\n * @return this\r\n */\r\n public Matrix4f set(FloatBuffer buffer) {\r\n MemUtil.INSTANCE.get(this, buffer.position(), buffer);\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the values of this matrix by reading 16 float values from the given {@link ByteBuffer} in column-major order,\r\n * starting at its current position.\r\n *
\r\n * The ByteBuffer is expected to contain the values in column-major order.\r\n *
\r\n * The position of the ByteBuffer will not be changed by this method.\r\n * \r\n * @param buffer\r\n * the ByteBuffer to read the matrix values from in column-major order\r\n * @return this\r\n */\r\n public Matrix4f set(ByteBuffer buffer) {\r\n MemUtil.INSTANCE.get(this, buffer.position(), buffer);\r\n return this;\r\n }\r\n\r\n /**\r\n * Return the determinant of this matrix.\r\n *
\r\n * If this
matrix represents an {@link #isAffine() affine} transformation, such as translation, rotation, scaling and shearing,\r\n * and thus its last row is equal to (0, 0, 0, 1), then {@link #determinantAffine()} can be used instead of this method.\r\n * \r\n * @see #determinantAffine()\r\n * \r\n * @return the determinant\r\n */\r\n public float determinant() {\r\n return (m00 * m11 - m01 * m10) * (m22 * m33 - m23 * m32)\r\n + (m02 * m10 - m00 * m12) * (m21 * m33 - m23 * m31)\r\n + (m00 * m13 - m03 * m10) * (m21 * m32 - m22 * m31)\r\n + (m01 * m12 - m02 * m11) * (m20 * m33 - m23 * m30)\r\n + (m03 * m11 - m01 * m13) * (m20 * m32 - m22 * m30)\r\n + (m02 * m13 - m03 * m12) * (m20 * m31 - m21 * m30);\r\n }\r\n\r\n /**\r\n * Return the determinant of the upper left 3x3 submatrix of this matrix.\r\n * \r\n * @return the determinant\r\n */\r\n public float determinant3x3() {\r\n return (m00 * m11 - m01 * m10) * m22\r\n + (m02 * m10 - m00 * m12) * m21\r\n + (m01 * m12 - m02 * m11) * m20;\r\n }\r\n\r\n /**\r\n * Return the determinant of this matrix by assuming that it represents an {@link #isAffine() affine} transformation and thus\r\n * its last row is equal to (0, 0, 0, 1).\r\n * \r\n * @return the determinant\r\n */\r\n public float determinantAffine() {\r\n return (m00 * m11 - m01 * m10) * m22\r\n + (m02 * m10 - m00 * m12) * m21\r\n + (m01 * m12 - m02 * m11) * m20;\r\n }\r\n\r\n /**\r\n * Invert this matrix and write the result into dest
.\r\n *
\r\n * If this
matrix represents an {@link #isAffine() affine} transformation, such as translation, rotation, scaling and shearing,\r\n * and thus its last row is equal to (0, 0, 0, 1), then {@link #invertAffine(Matrix4f)} can be used instead of this method.\r\n * \r\n * @see #invertAffine(Matrix4f)\r\n * \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f invert(Matrix4f dest) {\r\n float a = m00 * m11 - m01 * m10;\r\n float b = m00 * m12 - m02 * m10;\r\n float c = m00 * m13 - m03 * m10;\r\n float d = m01 * m12 - m02 * m11;\r\n float e = m01 * m13 - m03 * m11;\r\n float f = m02 * m13 - m03 * m12;\r\n float g = m20 * m31 - m21 * m30;\r\n float h = m20 * m32 - m22 * m30;\r\n float i = m20 * m33 - m23 * m30;\r\n float j = m21 * m32 - m22 * m31;\r\n float k = m21 * m33 - m23 * m31;\r\n float l = m22 * m33 - m23 * m32;\r\n float det = a * l - b * k + c * j + d * i - e * h + f * g;\r\n det = 1.0f / det;\r\n float nm00 = ( m11 * l - m12 * k + m13 * j) * det;\r\n float nm01 = (-m01 * l + m02 * k - m03 * j) * det;\r\n float nm02 = ( m31 * f - m32 * e + m33 * d) * det;\r\n float nm03 = (-m21 * f + m22 * e - m23 * d) * det;\r\n float nm10 = (-m10 * l + m12 * i - m13 * h) * det;\r\n float nm11 = ( m00 * l - m02 * i + m03 * h) * det;\r\n float nm12 = (-m30 * f + m32 * c - m33 * b) * det;\r\n float nm13 = ( m20 * f - m22 * c + m23 * b) * det;\r\n float nm20 = ( m10 * k - m11 * i + m13 * g) * det;\r\n float nm21 = (-m00 * k + m01 * i - m03 * g) * det;\r\n float nm22 = ( m30 * e - m31 * c + m33 * a) * det;\r\n float nm23 = (-m20 * e + m21 * c - m23 * a) * det;\r\n float nm30 = (-m10 * j + m11 * h - m12 * g) * det;\r\n float nm31 = ( m00 * j - m01 * h + m02 * g) * det;\r\n float nm32 = (-m30 * d + m31 * b - m32 * a) * det;\r\n float nm33 = ( m20 * d - m21 * b + m22 * a) * det;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Invert this matrix.\r\n *
\r\n * If this
matrix represents an {@link #isAffine() affine} transformation, such as translation, rotation, scaling and shearing,\r\n * and thus its last row is equal to (0, 0, 0, 1), then {@link #invertAffine()} can be used instead of this method.\r\n * \r\n * @see #invertAffine()\r\n * \r\n * @return this\r\n */\r\n public Matrix4f invert() {\r\n return invert(this);\r\n }\r\n\r\n /**\r\n * If this
is a perspective projection matrix obtained via one of the {@link #perspective(float, float, float, float) perspective()} methods\r\n * or via {@link #setPerspective(float, float, float, float) setPerspective()}, that is, if this
is a symmetrical perspective frustum transformation,\r\n * then this method builds the inverse of this
and stores it into the given dest
.\r\n *
\r\n * This method can be used to quickly obtain the inverse of a perspective projection matrix when being obtained via {@link #perspective(float, float, float, float) perspective()}.\r\n * \r\n * @see #perspective(float, float, float, float)\r\n * \r\n * @param dest\r\n * will hold the inverse of this
\r\n * @return dest\r\n */\r\n public Matrix4f invertPerspective(Matrix4f dest) {\r\n float a = 1.0f / (m00 * m11);\r\n float l = -1.0f / (m23 * m32);\r\n dest.set(m11 * a, 0, 0, 0,\r\n 0, m00 * a, 0, 0,\r\n 0, 0, 0, -m23 * l,\r\n 0, 0, -m32 * l, m22 * l);\r\n return dest;\r\n }\r\n\r\n /**\r\n * If this
is a perspective projection matrix obtained via one of the {@link #perspective(float, float, float, float) perspective()} methods\r\n * or via {@link #setPerspective(float, float, float, float) setPerspective()}, that is, if this
is a symmetrical perspective frustum transformation,\r\n * then this method builds the inverse of this
.\r\n *
\r\n * This method can be used to quickly obtain the inverse of a perspective projection matrix when being obtained via {@link #perspective(float, float, float, float) perspective()}.\r\n * \r\n * @see #perspective(float, float, float, float)\r\n * \r\n * @return this\r\n */\r\n public Matrix4f invertPerspective() {\r\n return invertPerspective(this);\r\n }\r\n\r\n /**\r\n * If this
is an arbitrary perspective projection matrix obtained via one of the {@link #frustum(float, float, float, float, float, float) frustum()} methods\r\n * or via {@link #setFrustum(float, float, float, float, float, float) setFrustum()},\r\n * then this method builds the inverse of this
and stores it into the given dest
.\r\n *
\r\n * This method can be used to quickly obtain the inverse of a perspective projection matrix.\r\n *
\r\n * If this matrix represents a symmetric perspective frustum transformation, as obtained via {@link #perspective(float, float, float, float) perspective()}, then\r\n * {@link #invertPerspective(Matrix4f)} should be used instead.\r\n * \r\n * @see #frustum(float, float, float, float, float, float)\r\n * @see #invertPerspective(Matrix4f)\r\n * \r\n * @param dest\r\n * will hold the inverse of this
\r\n * @return dest\r\n */\r\n public Matrix4f invertFrustum(Matrix4f dest) {\r\n float invM00 = 1.0f / m00;\r\n float invM11 = 1.0f / m11;\r\n float invM23 = 1.0f / m23;\r\n float invM32 = 1.0f / m32;\r\n dest.set(invM00, 0, 0, 0,\r\n 0, invM11, 0, 0,\r\n 0, 0, 0, invM32,\r\n -m20 * invM00 * invM23, -m21 * invM11 * invM23, invM23, -m22 * invM23 * invM32);\r\n return dest;\r\n }\r\n\r\n /**\r\n * If this
is an arbitrary perspective projection matrix obtained via one of the {@link #frustum(float, float, float, float, float, float) frustum()} methods\r\n * or via {@link #setFrustum(float, float, float, float, float, float) setFrustum()},\r\n * then this method builds the inverse of this
.\r\n *
\r\n * This method can be used to quickly obtain the inverse of a perspective projection matrix.\r\n *
\r\n * If this matrix represents a symmetric perspective frustum transformation, as obtained via {@link #perspective(float, float, float, float) perspective()}, then\r\n * {@link #invertPerspective()} should be used instead.\r\n * \r\n * @see #frustum(float, float, float, float, float, float)\r\n * @see #invertPerspective()\r\n * \r\n * @return this\r\n */\r\n public Matrix4f invertFrustum() {\r\n return invertFrustum(this);\r\n }\r\n\r\n /**\r\n * Invert this
orthographic projection matrix and store the result into the given dest
.\r\n *
\r\n * This method can be used to quickly obtain the inverse of an orthographic projection matrix.\r\n * \r\n * @param dest\r\n * will hold the inverse of this
\r\n * @return dest\r\n */\r\n public Matrix4f invertOrtho(Matrix4f dest) {\r\n float invM00 = 1.0f / m00;\r\n float invM11 = 1.0f / m11;\r\n float invM22 = 1.0f / m22;\r\n dest.set(invM00, 0, 0, 0,\r\n 0, invM11, 0, 0,\r\n 0, 0, invM22, 0,\r\n -m30 * invM00, -m31 * invM11, -m32 * invM22, 1);\r\n return dest;\r\n }\r\n\r\n /**\r\n * Invert this
orthographic projection matrix.\r\n *
\r\n * This method can be used to quickly obtain the inverse of an orthographic projection matrix.\r\n * \r\n * @return this\r\n */\r\n public Matrix4f invertOrtho() {\r\n return invertOrtho(this);\r\n }\r\n\r\n /**\r\n * If this
is a perspective projection matrix obtained via one of the {@link #perspective(float, float, float, float) perspective()} methods\r\n * or via {@link #setPerspective(float, float, float, float) setPerspective()}, that is, if this
is a symmetrical perspective frustum transformation\r\n * and the given view
matrix is {@link #isAffine() affine} and has unit scaling (for example by being obtained via {@link #lookAt(float, float, float, float, float, float, float, float, float) lookAt()}),\r\n * then this method builds the inverse of this * view and stores it into the given dest
.\r\n *
\r\n * This method can be used to quickly obtain the inverse of the combination of the view and projection matrices, when both were obtained\r\n * via the common methods {@link #perspective(float, float, float, float) perspective()} and {@link #lookAt(float, float, float, float, float, float, float, float, float) lookAt()} or\r\n * other methods, that build affine matrices, such as {@link #translate(float, float, float) translate} and {@link #rotate(float, float, float, float)}, except for {@link #scale(float, float, float) scale()}.\r\n *
\r\n * For the special cases of the matrices this
and view
mentioned above this method, this method is equivalent to the following code:\r\n *
\r\n * dest.set(this).mul(view).invert();\r\n *
\r\n * \r\n * @param view\r\n * the view transformation (must be {@link #isAffine() affine} and have unit scaling)\r\n * @param dest\r\n * will hold the inverse of this * view\r\n * @return dest\r\n */\r\n public Matrix4f invertPerspectiveView(Matrix4f view, Matrix4f dest) {\r\n float a = 1.0f / (m00 * m11);\r\n float l = -1.0f / (m23 * m32);\r\n float pm00 = m11 * a;\r\n float pm11 = m00 * a;\r\n float pm23 = -m23 * l;\r\n float pm32 = -m32 * l;\r\n float pm33 = m22 * l;\r\n float vm30 = -view.m00 * view.m30 - view.m01 * view.m31 - view.m02 * view.m32;\r\n float vm31 = -view.m10 * view.m30 - view.m11 * view.m31 - view.m12 * view.m32;\r\n float vm32 = -view.m20 * view.m30 - view.m21 * view.m31 - view.m22 * view.m32;\r\n dest.set(view.m00 * pm00, view.m10 * pm00, view.m20 * pm00, 0.0f,\r\n view.m01 * pm11, view.m11 * pm11, view.m21 * pm11, 0.0f,\r\n vm30 * pm23, vm31 * pm23, vm32 * pm23, pm23,\r\n view.m02 * pm32 + vm30 * pm33, view.m12 * pm32 + vm31 * pm33, view.m22 * pm32 + vm32 * pm33, pm33);\r\n return dest;\r\n }\r\n\r\n /**\r\n * Invert this matrix by assuming that it is an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and write the result into dest
.\r\n * \r\n * Note that if this
matrix also has unit scaling, then the method {@link #invertAffineUnitScale(Matrix4f)} should be used instead.\r\n * \r\n * @see #invertAffineUnitScale(Matrix4f)\r\n * \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f invertAffine(Matrix4f dest) {\r\n float s = determinantAffine();\r\n s = 1.0f / s;\r\n float m10m22 = m10 * m22;\r\n float m10m21 = m10 * m21;\r\n float m10m02 = m10 * m02;\r\n float m10m01 = m10 * m01;\r\n float m11m22 = m11 * m22;\r\n float m11m20 = m11 * m20;\r\n float m11m02 = m11 * m02;\r\n float m11m00 = m11 * m00;\r\n float m12m21 = m12 * m21;\r\n float m12m20 = m12 * m20;\r\n float m12m01 = m12 * m01;\r\n float m12m00 = m12 * m00;\r\n float m20m02 = m20 * m02;\r\n float m20m01 = m20 * m01;\r\n float m21m02 = m21 * m02;\r\n float m21m00 = m21 * m00;\r\n float m22m01 = m22 * m01;\r\n float m22m00 = m22 * m00;\r\n float nm00 = (m11m22 - m12m21) * s;\r\n float nm01 = (m21m02 - m22m01) * s;\r\n float nm02 = (m12m01 - m11m02) * s;\r\n float nm03 = 0.0f;\r\n float nm10 = (m12m20 - m10m22) * s;\r\n float nm11 = (m22m00 - m20m02) * s;\r\n float nm12 = (m10m02 - m12m00) * s;\r\n float nm13 = 0.0f;\r\n float nm20 = (m10m21 - m11m20) * s;\r\n float nm21 = (m20m01 - m21m00) * s;\r\n float nm22 = (m11m00 - m10m01) * s;\r\n float nm23 = 0.0f;\r\n float nm30 = (m10m22 * m31 - m10m21 * m32 + m11m20 * m32 - m11m22 * m30 + m12m21 * m30 - m12m20 * m31) * s;\r\n float nm31 = (m20m02 * m31 - m20m01 * m32 + m21m00 * m32 - m21m02 * m30 + m22m01 * m30 - m22m00 * m31) * s;\r\n float nm32 = (m11m02 * m30 - m12m01 * m30 + m12m00 * m31 - m10m02 * m31 + m10m01 * m32 - m11m00 * m32) * s;\r\n float nm33 = 1.0f;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Invert this matrix by assuming that it is an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1)).\r\n *
\r\n * Note that if this
matrix also has unit scaling, then the method {@link #invertAffineUnitScale()} should be used instead.\r\n * \r\n * @see #invertAffineUnitScale()\r\n * \r\n * @return this\r\n */\r\n public Matrix4f invertAffine() {\r\n return invertAffine(this);\r\n }\r\n\r\n /**\r\n * Invert this matrix by assuming that it is an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and has unit scaling (i.e. {@link #transformDirection(Vector3f) transformDirection} does not change the {@link Vector3f#length() length} of the vector)\r\n * and write the result into dest
.\r\n *
\r\n * Reference: http://www.gamedev.net/\r\n * \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f invertAffineUnitScale(Matrix4f dest) {\r\n dest.set(m00, m10, m20, 0.0f,\r\n m01, m11, m21, 0.0f,\r\n m02, m12, m22, 0.0f,\r\n -m00 * m30 - m01 * m31 - m02 * m32,\r\n -m10 * m30 - m11 * m31 - m12 * m32,\r\n -m20 * m30 - m21 * m31 - m22 * m32,\r\n 1.0f);\r\n return dest;\r\n }\r\n\r\n /**\r\n * Invert this matrix by assuming that it is an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and has unit scaling (i.e. {@link #transformDirection(Vector3f) transformDirection} does not change the {@link Vector3f#length() length} of the vector).\r\n *
\r\n * Reference: http://www.gamedev.net/\r\n * \r\n * @return this\r\n */\r\n public Matrix4f invertAffineUnitScale() {\r\n return invertAffineUnitScale(this);\r\n }\r\n\r\n /**\r\n * Invert this matrix by assuming that it is an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and has unit scaling (i.e. {@link #transformDirection(Vector3f) transformDirection} does not change the {@link Vector3f#length() length} of the vector),\r\n * as is the case for matrices built via {@link #lookAt(Vector3f, Vector3f, Vector3f)} and their overloads, and write the result into dest
.\r\n *
\r\n * This method is equivalent to calling {@link #invertAffineUnitScale(Matrix4f)}\r\n *
\r\n * Reference: http://www.gamedev.net/\r\n * \r\n * @see #invertAffineUnitScale(Matrix4f)\r\n * \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f invertLookAt(Matrix4f dest) {\r\n return invertAffineUnitScale(dest);\r\n }\r\n\r\n /**\r\n * Invert this matrix by assuming that it is an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and has unit scaling (i.e. {@link #transformDirection(Vector3f) transformDirection} does not change the {@link Vector3f#length() length} of the vector),\r\n * as is the case for matrices built via {@link #lookAt(Vector3f, Vector3f, Vector3f)} and their overloads.\r\n *
\r\n * This method is equivalent to calling {@link #invertAffineUnitScale()}\r\n *
\r\n * Reference: http://www.gamedev.net/\r\n * \r\n * @see #invertAffineUnitScale()\r\n * \r\n * @return this\r\n */\r\n public Matrix4f invertLookAt() {\r\n return invertAffineUnitScale(this);\r\n }\r\n\r\n /**\r\n * Transpose this matrix and store the result in dest
.\r\n * \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f transpose(Matrix4f dest) {\r\n float nm00 = m00;\r\n float nm01 = m10;\r\n float nm02 = m20;\r\n float nm03 = m30;\r\n float nm10 = m01;\r\n float nm11 = m11;\r\n float nm12 = m21;\r\n float nm13 = m31;\r\n float nm20 = m02;\r\n float nm21 = m12;\r\n float nm22 = m22;\r\n float nm23 = m32;\r\n float nm30 = m03;\r\n float nm31 = m13;\r\n float nm32 = m23;\r\n float nm33 = m33;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Transpose only the upper left 3x3 submatrix of this matrix and set the rest of the matrix elements to identity.\r\n * \r\n * @return this\r\n */\r\n public Matrix4f transpose3x3() {\r\n return transpose3x3(this);\r\n }\r\n\r\n /**\r\n * Transpose only the upper left 3x3 submatrix of this matrix and store the result in dest
.\r\n *
\r\n * All other matrix elements of dest
will be set to identity.\r\n * \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f transpose3x3(Matrix4f dest) {\r\n float nm00 = m00;\r\n float nm01 = m10;\r\n float nm02 = m20;\r\n float nm03 = 0.0f;\r\n float nm10 = m01;\r\n float nm11 = m11;\r\n float nm12 = m21;\r\n float nm13 = 0.0f;\r\n float nm20 = m02;\r\n float nm21 = m12;\r\n float nm22 = m22;\r\n float nm23 = 0.0f;\r\n float nm30 = 0.0f;\r\n float nm31 = 0.0f;\r\n float nm32 = 0.0f;\r\n float nm33 = 1.0f;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Transpose only the upper left 3x3 submatrix of this matrix and store the result in dest
.\r\n * \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix3f transpose3x3(Matrix3f dest) {\r\n dest.m00 = m00;\r\n dest.m01 = m10;\r\n dest.m02 = m20;\r\n dest.m10 = m01;\r\n dest.m11 = m11;\r\n dest.m12 = m21;\r\n dest.m20 = m02;\r\n dest.m21 = m12;\r\n dest.m22 = m22;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Transpose this matrix.\r\n * \r\n * @return this\r\n */\r\n public Matrix4f transpose() {\r\n return transpose(this);\r\n }\r\n\r\n /**\r\n * Set this matrix to be a simple translation matrix.\r\n *
\r\n * The resulting matrix can be multiplied against another transformation\r\n * matrix to obtain an additional translation.\r\n *
\r\n * In order to post-multiply a translation transformation directly to a\r\n * matrix, use {@link #translate(float, float, float) translate()} instead.\r\n * \r\n * @see #translate(float, float, float)\r\n * \r\n * @param x\r\n * the offset to translate in x\r\n * @param y\r\n * the offset to translate in y\r\n * @param z\r\n * the offset to translate in z\r\n * @return this\r\n */\r\n public Matrix4f translation(float x, float y, float z) {\r\n m00 = 1.0f;\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = 1.0f;\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = 0.0f;\r\n m22 = 1.0f;\r\n m23 = 0.0f;\r\n m30 = x;\r\n m31 = y;\r\n m32 = z;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be a simple translation matrix.\r\n *
\r\n * The resulting matrix can be multiplied against another transformation\r\n * matrix to obtain an additional translation.\r\n *
\r\n * In order to post-multiply a translation transformation directly to a\r\n * matrix, use {@link #translate(Vector3f) translate()} instead.\r\n * \r\n * @see #translate(float, float, float)\r\n * \r\n * @param offset\r\n * the offsets in x, y and z to translate\r\n * @return this\r\n */\r\n public Matrix4f translation(Vector3f offset) {\r\n return translation(offset.x, offset.y, offset.z);\r\n }\r\n\r\n /**\r\n * Set only the translation components (m30, m31, m32) of this matrix to the given values (x, y, z).\r\n *
\r\n * Note that this will only work properly for orthogonal matrices (without any perspective).\r\n *
\r\n * To build a translation matrix instead, use {@link #translation(float, float, float)}.\r\n * To apply a translation to another matrix, use {@link #translate(float, float, float)}.\r\n * \r\n * @see #translation(float, float, float)\r\n * @see #translate(float, float, float)\r\n * \r\n * @param x\r\n * the offset to translate in x\r\n * @param y\r\n * the offset to translate in y\r\n * @param z\r\n * the offset to translate in z\r\n * @return this\r\n */\r\n public Matrix4f setTranslation(float x, float y, float z) {\r\n m30 = x;\r\n m31 = y;\r\n m32 = z;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set only the translation components (m30, m31, m32) of this matrix to the values (xyz.x, xyz.y, xyz.z).\r\n *
\r\n * Note that this will only work properly for orthogonal matrices (without any perspective).\r\n *
\r\n * To build a translation matrix instead, use {@link #translation(Vector3f)}.\r\n * To apply a translation to another matrix, use {@link #translate(Vector3f)}.\r\n * \r\n * @see #translation(Vector3f)\r\n * @see #translate(Vector3f)\r\n * \r\n * @param xyz\r\n * the units to translate in (x, y, z)\r\n * @return this\r\n */\r\n public Matrix4f setTranslation(Vector3f xyz) {\r\n m30 = xyz.x;\r\n m31 = xyz.y;\r\n m32 = xyz.z;\r\n return this;\r\n }\r\n\r\n /**\r\n * Get only the translation components (m30, m31, m32) of this matrix and store them in the given vector xyz
.\r\n * \r\n * @param dest\r\n * will hold the translation components of this matrix\r\n * @return dest\r\n */\r\n public Vector3f getTranslation(Vector3f dest) {\r\n dest.x = m30;\r\n dest.y = m31;\r\n dest.z = m32;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Get the scaling factors of this
matrix for the three base axes.\r\n * \r\n * @param dest\r\n * will hold the scaling factors for x, y and z\r\n * @return dest\r\n */\r\n public Vector3f getScale(Vector3f dest) {\r\n dest.x = (float) Math.sqrt(m00 * m00 + m01 * m01 + m02 * m02);\r\n dest.y = (float) Math.sqrt(m10 * m10 + m11 * m11 + m12 * m12);\r\n dest.z = (float) Math.sqrt(m20 * m20 + m21 * m21 + m22 * m22);\r\n return dest;\r\n }\r\n\r\n /**\r\n * Return a string representation of this matrix.\r\n *
\r\n * This method creates a new {@link DecimalFormat} on every invocation with the format string \" 0.000E0; -\".\r\n * \r\n * @return the string representation\r\n */\r\n public String toString() {\r\n DecimalFormat formatter = new DecimalFormat(\" 0.000E0; -\"); //$NON-NLS-1$\r\n return toString(formatter).replaceAll(\"E(\\\\d+)\", \"E+$1\"); //$NON-NLS-1$ //$NON-NLS-2$\r\n }\r\n\r\n /**\r\n * Return a string representation of this matrix by formatting the matrix elements with the given {@link NumberFormat}.\r\n * \r\n * @param formatter\r\n * the {@link NumberFormat} used to format the matrix values with\r\n * @return the string representation\r\n */\r\n public String toString(NumberFormat formatter) {\r\n return formatter.format(m00) + formatter.format(m10) + formatter.format(m20) + formatter.format(m30) + \"\\n\" //$NON-NLS-1$\r\n + formatter.format(m01) + formatter.format(m11) + formatter.format(m21) + formatter.format(m31) + \"\\n\" //$NON-NLS-1$\r\n + formatter.format(m02) + formatter.format(m12) + formatter.format(m22) + formatter.format(m32) + \"\\n\" //$NON-NLS-1$\r\n + formatter.format(m03) + formatter.format(m13) + formatter.format(m23) + formatter.format(m33) + \"\\n\"; //$NON-NLS-1$\r\n }\r\n\r\n /**\r\n * Get the current values of this
matrix and store them into\r\n * dest
.\r\n *
\r\n * This is the reverse method of {@link #set(Matrix4f)} and allows to obtain\r\n * intermediate calculation results when chaining multiple transformations.\r\n * \r\n * @see #set(Matrix4f)\r\n * \r\n * @param dest\r\n * the destination matrix\r\n * @return the passed in destination\r\n */\r\n public Matrix4f get(Matrix4f dest) {\r\n return dest.set(this);\r\n }\r\n\r\n /**\r\n * Get the current values of this
matrix and store them into\r\n * dest
.\r\n *
\r\n * This is the reverse method of {@link #set(Matrix4d)} and allows to obtain\r\n * intermediate calculation results when chaining multiple transformations.\r\n * \r\n * @see #set(Matrix4d)\r\n * \r\n * @param dest\r\n * the destination matrix\r\n * @return the passed in destination\r\n */\r\n public Matrix4d get(Matrix4d dest) {\r\n return dest.set(this);\r\n }\r\n\r\n /**\r\n * Get the current values of the upper left 3x3 submatrix of this
matrix and store them into\r\n * dest
.\r\n * \r\n * @param dest\r\n * the destination matrix\r\n * @return the passed in destination\r\n */\r\n public Matrix3f get3x3(Matrix3f dest) {\r\n return dest.set(this);\r\n }\r\n\r\n /**\r\n * Get the current values of the upper left 3x3 submatrix of this
matrix and store them into\r\n * dest
.\r\n * \r\n * @param dest\r\n * the destination matrix\r\n * @return the passed in destination\r\n */\r\n public Matrix3d get3x3(Matrix3d dest) {\r\n return dest.set(this);\r\n }\r\n\r\n /**\r\n * Get the rotational component of this
matrix and store the represented rotation\r\n * into the given {@link AxisAngle4f}.\r\n * \r\n * @see AxisAngle4f#set(Matrix4f)\r\n * \r\n * @param dest\r\n * the destination {@link AxisAngle4f}\r\n * @return the passed in destination\r\n */\r\n public AxisAngle4f getRotation(AxisAngle4f dest) {\r\n return dest.set(this);\r\n }\r\n\r\n /**\r\n * Get the rotational component of this
matrix and store the represented rotation\r\n * into the given {@link AxisAngle4d}.\r\n * \r\n * @see AxisAngle4f#set(Matrix4f)\r\n * \r\n * @param dest\r\n * the destination {@link AxisAngle4d}\r\n * @return the passed in destination\r\n */\r\n public AxisAngle4d getRotation(AxisAngle4d dest) {\r\n return dest.set(this);\r\n }\r\n\r\n /**\r\n * Get the current values of this
matrix and store the represented rotation\r\n * into the given {@link Quaternionf}.\r\n *
\r\n * This method assumes that the first three column vectors of the upper left 3x3 submatrix are not normalized and\r\n * thus allows to ignore any additional scaling factor that is applied to the matrix.\r\n * \r\n * @see Quaternionf#setFromUnnormalized(Matrix4f)\r\n * \r\n * @param dest\r\n * the destination {@link Quaternionf}\r\n * @return the passed in destination\r\n */\r\n public Quaternionf getUnnormalizedRotation(Quaternionf dest) {\r\n return dest.setFromUnnormalized(this);\r\n }\r\n\r\n /**\r\n * Get the current values of this
matrix and store the represented rotation\r\n * into the given {@link Quaternionf}.\r\n *
\r\n * This method assumes that the first three column vectors of the upper left 3x3 submatrix are normalized.\r\n * \r\n * @see Quaternionf#setFromNormalized(Matrix4f)\r\n * \r\n * @param dest\r\n * the destination {@link Quaternionf}\r\n * @return the passed in destination\r\n */\r\n public Quaternionf getNormalizedRotation(Quaternionf dest) {\r\n return dest.setFromNormalized(this);\r\n }\r\n\r\n /**\r\n * Get the current values of this
matrix and store the represented rotation\r\n * into the given {@link Quaterniond}.\r\n *
\r\n * This method assumes that the first three column vectors of the upper left 3x3 submatrix are not normalized and\r\n * thus allows to ignore any additional scaling factor that is applied to the matrix.\r\n * \r\n * @see Quaterniond#setFromUnnormalized(Matrix4f)\r\n * \r\n * @param dest\r\n * the destination {@link Quaterniond}\r\n * @return the passed in destination\r\n */\r\n public Quaterniond getUnnormalizedRotation(Quaterniond dest) {\r\n return dest.setFromUnnormalized(this);\r\n }\r\n\r\n /**\r\n * Get the current values of this
matrix and store the represented rotation\r\n * into the given {@link Quaterniond}.\r\n *
\r\n * This method assumes that the first three column vectors of the upper left 3x3 submatrix are normalized.\r\n * \r\n * @see Quaterniond#setFromNormalized(Matrix4f)\r\n * \r\n * @param dest\r\n * the destination {@link Quaterniond}\r\n * @return the passed in destination\r\n */\r\n public Quaterniond getNormalizedRotation(Quaterniond dest) {\r\n return dest.setFromNormalized(this);\r\n }\r\n\r\n /**\r\n * Store this matrix in column-major order into the supplied {@link FloatBuffer} at the current\r\n * buffer {@link FloatBuffer#position() position}.\r\n *
\r\n * This method will not increment the position of the given FloatBuffer.\r\n *
\r\n * In order to specify the offset into the FloatBuffer at which\r\n * the matrix is stored, use {@link #get(int, FloatBuffer)}, taking\r\n * the absolute position as parameter.\r\n * \r\n * @see #get(int, FloatBuffer)\r\n * \r\n * @param buffer\r\n * will receive the values of this matrix in column-major order at its current position\r\n * @return the passed in buffer\r\n */\r\n public FloatBuffer get(FloatBuffer buffer) {\r\n return get(buffer.position(), buffer);\r\n }\r\n\r\n /**\r\n * Store this matrix in column-major order into the supplied {@link FloatBuffer} starting at the specified\r\n * absolute buffer position/index.\r\n *
\r\n * This method will not increment the position of the given FloatBuffer.\r\n * \r\n * @param index\r\n * the absolute position into the FloatBuffer\r\n * @param buffer\r\n * will receive the values of this matrix in column-major order\r\n * @return the passed in buffer\r\n */\r\n public FloatBuffer get(int index, FloatBuffer buffer) {\r\n MemUtil.INSTANCE.put(this, index, buffer);\r\n return buffer;\r\n }\r\n\r\n /**\r\n * Store this matrix in column-major order into the supplied {@link ByteBuffer} at the current\r\n * buffer {@link ByteBuffer#position() position}.\r\n *
\r\n * This method will not increment the position of the given ByteBuffer.\r\n *
\r\n * In order to specify the offset into the ByteBuffer at which\r\n * the matrix is stored, use {@link #get(int, ByteBuffer)}, taking\r\n * the absolute position as parameter.\r\n * \r\n * @see #get(int, ByteBuffer)\r\n * \r\n * @param buffer\r\n * will receive the values of this matrix in column-major order at its current position\r\n * @return the passed in buffer\r\n */\r\n public ByteBuffer get(ByteBuffer buffer) {\r\n return get(buffer.position(), buffer);\r\n }\r\n\r\n /**\r\n * Store this matrix in column-major order into the supplied {@link ByteBuffer} starting at the specified\r\n * absolute buffer position/index.\r\n *
\r\n * This method will not increment the position of the given ByteBuffer.\r\n * \r\n * @param index\r\n * the absolute position into the ByteBuffer\r\n * @param buffer\r\n * will receive the values of this matrix in column-major order\r\n * @return the passed in buffer\r\n */\r\n public ByteBuffer get(int index, ByteBuffer buffer) {\r\n MemUtil.INSTANCE.put(this, index, buffer);\r\n return buffer;\r\n }\r\n\r\n /**\r\n * Store the transpose of this matrix in column-major order into the supplied {@link FloatBuffer} at the current\r\n * buffer {@link FloatBuffer#position() position}.\r\n *
\r\n * This method will not increment the position of the given FloatBuffer.\r\n *
\r\n * In order to specify the offset into the FloatBuffer at which\r\n * the matrix is stored, use {@link #getTransposed(int, FloatBuffer)}, taking\r\n * the absolute position as parameter.\r\n * \r\n * @see #getTransposed(int, FloatBuffer)\r\n * \r\n * @param buffer\r\n * will receive the values of this matrix in column-major order at its current position\r\n * @return the passed in buffer\r\n */\r\n public FloatBuffer getTransposed(FloatBuffer buffer) {\r\n return getTransposed(buffer.position(), buffer);\r\n }\r\n\r\n /**\r\n * Store the transpose of this matrix in column-major order into the supplied {@link FloatBuffer} starting at the specified\r\n * absolute buffer position/index.\r\n *
\r\n * This method will not increment the position of the given FloatBuffer.\r\n * \r\n * @param index\r\n * the absolute position into the FloatBuffer\r\n * @param buffer\r\n * will receive the values of this matrix in column-major order\r\n * @return the passed in buffer\r\n */\r\n public FloatBuffer getTransposed(int index, FloatBuffer buffer) {\r\n MemUtil.INSTANCE.putTransposed(this, index, buffer);\r\n return buffer;\r\n }\r\n\r\n /**\r\n * Store the transpose of this matrix in column-major order into the supplied {@link ByteBuffer} at the current\r\n * buffer {@link ByteBuffer#position() position}.\r\n *
\r\n * This method will not increment the position of the given ByteBuffer.\r\n *
\r\n * In order to specify the offset into the ByteBuffer at which\r\n * the matrix is stored, use {@link #getTransposed(int, ByteBuffer)}, taking\r\n * the absolute position as parameter.\r\n * \r\n * @see #getTransposed(int, ByteBuffer)\r\n * \r\n * @param buffer\r\n * will receive the values of this matrix in column-major order at its current position\r\n * @return the passed in buffer\r\n */\r\n public ByteBuffer getTransposed(ByteBuffer buffer) {\r\n return getTransposed(buffer.position(), buffer);\r\n }\r\n\r\n /**\r\n * Store the transpose of this matrix in column-major order into the supplied {@link ByteBuffer} starting at the specified\r\n * absolute buffer position/index.\r\n *
\r\n * This method will not increment the position of the given ByteBuffer.\r\n * \r\n * @param index\r\n * the absolute position into the ByteBuffer\r\n * @param buffer\r\n * will receive the values of this matrix in column-major order\r\n * @return the passed in buffer\r\n */\r\n public ByteBuffer getTransposed(int index, ByteBuffer buffer) {\r\n MemUtil.INSTANCE.putTransposed(this, index, buffer);\r\n return buffer;\r\n }\r\n\r\n /**\r\n * Store this matrix into the supplied float array in column-major order at the given offset.\r\n * \r\n * @param arr\r\n * the array to write the matrix values into\r\n * @param offset\r\n * the offset into the array\r\n * @return the passed in array\r\n */\r\n public float[] get(float[] arr, int offset) {\r\n arr[offset+0] = m00;\r\n arr[offset+1] = m01;\r\n arr[offset+2] = m02;\r\n arr[offset+3] = m03;\r\n arr[offset+4] = m10;\r\n arr[offset+5] = m11;\r\n arr[offset+6] = m12;\r\n arr[offset+7] = m13;\r\n arr[offset+8] = m20;\r\n arr[offset+9] = m21;\r\n arr[offset+10] = m22;\r\n arr[offset+11] = m23;\r\n arr[offset+12] = m30;\r\n arr[offset+13] = m31;\r\n arr[offset+14] = m32;\r\n arr[offset+15] = m33;\r\n return arr;\r\n }\r\n\r\n /**\r\n * Store this matrix into the supplied float array in column-major order.\r\n *
\r\n * In order to specify an explicit offset into the array, use the method {@link #get(float[], int)}.\r\n * \r\n * @see #get(float[], int)\r\n * \r\n * @param arr\r\n * the array to write the matrix values into\r\n * @return the passed in array\r\n */\r\n public float[] get(float[] arr) {\r\n return get(arr, 0);\r\n }\r\n\r\n /**\r\n * Set all the values within this matrix to 0
.\r\n * \r\n * @return this\r\n */\r\n public Matrix4f zero() {\r\n m00 = 0.0f;\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = 0.0f;\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = 0.0f;\r\n m22 = 0.0f;\r\n m23 = 0.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 0.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be a simple scale matrix, which scales all axes uniformly by the given factor.\r\n *
\r\n * The resulting matrix can be multiplied against another transformation\r\n * matrix to obtain an additional scaling.\r\n *
\r\n * In order to post-multiply a scaling transformation directly to a\r\n * matrix, use {@link #scale(float) scale()} instead.\r\n * \r\n * @see #scale(float)\r\n * \r\n * @param factor\r\n * the scale factor in x, y and z\r\n * @return this\r\n */\r\n public Matrix4f scaling(float factor) {\r\n m00 = factor;\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = factor;\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = 0.0f;\r\n m22 = factor;\r\n m23 = 0.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be a simple scale matrix.\r\n *
\r\n * The resulting matrix can be multiplied against another transformation\r\n * matrix to obtain an additional scaling.\r\n *
\r\n * In order to post-multiply a scaling transformation directly to a\r\n * matrix, use {@link #scale(float, float, float) scale()} instead.\r\n * \r\n * @see #scale(float, float, float)\r\n * \r\n * @param x\r\n * the scale in x\r\n * @param y\r\n * the scale in y\r\n * @param z\r\n * the scale in z\r\n * @return this\r\n */\r\n public Matrix4f scaling(float x, float y, float z) {\r\n m00 = x;\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = y;\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = 0.0f;\r\n m22 = z;\r\n m23 = 0.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n \r\n /**\r\n * Set this matrix to be a simple scale matrix which scales the base axes by xyz.x, xyz.y and xyz.z respectively.\r\n *
\r\n * The resulting matrix can be multiplied against another transformation\r\n * matrix to obtain an additional scaling.\r\n *
\r\n * In order to post-multiply a scaling transformation directly to a\r\n * matrix use {@link #scale(Vector3f) scale()} instead.\r\n * \r\n * @see #scale(Vector3f)\r\n * \r\n * @param xyz\r\n * the scale in x, y and z respectively\r\n * @return this\r\n */\r\n public Matrix4f scaling(Vector3f xyz) {\r\n return scaling(xyz.x, xyz.y, xyz.z);\r\n }\r\n\r\n /**\r\n * Set this matrix to a rotation matrix which rotates the given radians about a given axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * The resulting matrix can be multiplied against another transformation\r\n * matrix to obtain an additional rotation.\r\n *
\r\n * In order to post-multiply a rotation transformation directly to a\r\n * matrix, use {@link #rotate(float, Vector3f) rotate()} instead.\r\n * \r\n * @see #rotate(float, Vector3f)\r\n * \r\n * @param angle\r\n * the angle in radians\r\n * @param axis\r\n * the axis to rotate about (needs to be {@link Vector3f#normalize() normalized})\r\n * @return this\r\n */\r\n public Matrix4f rotation(float angle, Vector3f axis) {\r\n return rotation(angle, axis.x, axis.y, axis.z);\r\n }\r\n\r\n /**\r\n * Set this matrix to a rotation transformation using the given {@link AxisAngle4f}.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * The resulting matrix can be multiplied against another transformation\r\n * matrix to obtain an additional rotation.\r\n *
\r\n * In order to apply the rotation transformation to an existing transformation,\r\n * use {@link #rotate(AxisAngle4f) rotate()} instead.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n *\r\n * @see #rotate(AxisAngle4f)\r\n * \r\n * @param axisAngle\r\n * the {@link AxisAngle4f} (needs to be {@link AxisAngle4f#normalize() normalized})\r\n * @return this\r\n */\r\n public Matrix4f rotation(AxisAngle4f axisAngle) {\r\n return rotation(axisAngle.angle, axisAngle.x, axisAngle.y, axisAngle.z);\r\n }\r\n\r\n /**\r\n * Set this matrix to a rotation matrix which rotates the given radians about a given axis.\r\n *
\r\n * The axis described by the three components needs to be a unit vector.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * The resulting matrix can be multiplied against another transformation\r\n * matrix to obtain an additional rotation.\r\n *
\r\n * In order to apply the rotation transformation to an existing transformation,\r\n * use {@link #rotate(float, float, float, float) rotate()} instead.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotate(float, float, float, float)\r\n * \r\n * @param angle\r\n * the angle in radians\r\n * @param x\r\n * the x-component of the rotation axis\r\n * @param y\r\n * the y-component of the rotation axis\r\n * @param z\r\n * the z-component of the rotation axis\r\n * @return this\r\n */\r\n public Matrix4f rotation(float angle, float x, float y, float z) {\r\n float cos = (float) Math.cos(angle);\r\n float sin = (float) Math.sin(angle);\r\n float C = 1.0f - cos;\r\n float xy = x * y, xz = x * z, yz = y * z;\r\n m00 = cos + x * x * C;\r\n m10 = xy * C - z * sin;\r\n m20 = xz * C + y * sin;\r\n m30 = 0.0f;\r\n m01 = xy * C + z * sin;\r\n m11 = cos + y * y * C;\r\n m21 = yz * C - x * sin;\r\n m31 = 0.0f;\r\n m02 = xz * C - y * sin;\r\n m12 = yz * C + x * sin;\r\n m22 = cos + z * z * C;\r\n m32 = 0.0f;\r\n m03 = 0.0f;\r\n m13 = 0.0f;\r\n m23 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to a rotation transformation about the X axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @return this\r\n */\r\n public Matrix4f rotationX(float ang) {\r\n float sin, cos;\r\n if (ang == (float) Math.PI || ang == -(float) Math.PI) {\r\n cos = -1.0f;\r\n sin = 0.0f;\r\n } else if (ang == (float) Math.PI * 0.5f || ang == -(float) Math.PI * 1.5f) {\r\n cos = 0.0f;\r\n sin = 1.0f;\r\n } else if (ang == (float) -Math.PI * 0.5f || ang == (float) Math.PI * 1.5f) {\r\n cos = 0.0f;\r\n sin = -1.0f;\r\n } else {\r\n cos = (float) Math.cos(ang);\r\n sin = (float) Math.sin(ang);\r\n }\r\n m00 = 1.0f;\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = cos;\r\n m12 = sin;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = -sin;\r\n m22 = cos;\r\n m23 = 0.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to a rotation transformation about the Y axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @return this\r\n */\r\n public Matrix4f rotationY(float ang) {\r\n float sin, cos;\r\n if (ang == (float) Math.PI || ang == -(float) Math.PI) {\r\n cos = -1.0f;\r\n sin = 0.0f;\r\n } else if (ang == (float) Math.PI * 0.5f || ang == -(float) Math.PI * 1.5f) {\r\n cos = 0.0f;\r\n sin = 1.0f;\r\n } else if (ang == (float) -Math.PI * 0.5f || ang == (float) Math.PI * 1.5f) {\r\n cos = 0.0f;\r\n sin = -1.0f;\r\n } else {\r\n cos = (float) Math.cos(ang);\r\n sin = (float) Math.sin(ang);\r\n }\r\n m00 = cos;\r\n m01 = 0.0f;\r\n m02 = -sin;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = 1.0f;\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = sin;\r\n m21 = 0.0f;\r\n m22 = cos;\r\n m23 = 0.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to a rotation transformation about the Z axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @return this\r\n */\r\n public Matrix4f rotationZ(float ang) {\r\n float sin, cos;\r\n if (ang == (float) Math.PI || ang == -(float) Math.PI) {\r\n cos = -1.0f;\r\n sin = 0.0f;\r\n } else if (ang == (float) Math.PI * 0.5f || ang == -(float) Math.PI * 1.5f) {\r\n cos = 0.0f;\r\n sin = 1.0f;\r\n } else if (ang == (float) -Math.PI * 0.5f || ang == (float) Math.PI * 1.5f) {\r\n cos = 0.0f;\r\n sin = -1.0f;\r\n } else {\r\n cos = (float) Math.cos(ang);\r\n sin = (float) Math.sin(ang);\r\n }\r\n m00 = cos;\r\n m01 = sin;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = -sin;\r\n m11 = cos;\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = 0.0f;\r\n m22 = 1.0f;\r\n m23 = 0.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to a rotation of angleX
radians about the X axis, followed by a rotation\r\n * of angleY
radians about the Y axis and followed by a rotation of angleZ
radians about the Z axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method is equivalent to calling: rotationX(angleX).rotateY(angleY).rotateZ(angleZ)\r\n * \r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @return this\r\n */\r\n public Matrix4f rotationXYZ(float angleX, float angleY, float angleZ) {\r\n float cosX = (float) Math.cos(angleX);\r\n float sinX = (float) Math.sin(angleX);\r\n float cosY = (float) Math.cos(angleY);\r\n float sinY = (float) Math.sin(angleY);\r\n float cosZ = (float) Math.cos(angleZ);\r\n float sinZ = (float) Math.sin(angleZ);\r\n float m_sinX = -sinX;\r\n float m_sinY = -sinY;\r\n float m_sinZ = -sinZ;\r\n\r\n // rotateX\r\n float nm11 = cosX;\r\n float nm12 = sinX;\r\n float nm21 = m_sinX;\r\n float nm22 = cosX;\r\n // rotateY\r\n float nm00 = cosY;\r\n float nm01 = nm21 * m_sinY;\r\n float nm02 = nm22 * m_sinY;\r\n m20 = sinY;\r\n m21 = nm21 * cosY;\r\n m22 = nm22 * cosY;\r\n m23 = 0.0f;\r\n // rotateZ\r\n m00 = nm00 * cosZ;\r\n m01 = nm01 * cosZ + nm11 * sinZ;\r\n m02 = nm02 * cosZ + nm12 * sinZ;\r\n m03 = 0.0f;\r\n m10 = nm00 * m_sinZ;\r\n m11 = nm01 * m_sinZ + nm11 * cosZ;\r\n m12 = nm02 * m_sinZ + nm12 * cosZ;\r\n m13 = 0.0f;\r\n // set last column to identity\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to a rotation of angleZ
radians about the Z axis, followed by a rotation\r\n * of angleY
radians about the Y axis and followed by a rotation of angleX
radians about the X axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method is equivalent to calling: rotationZ(angleZ).rotateY(angleY).rotateX(angleX)\r\n * \r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleX\r\n * the angle to rotate about X\r\n * @return this\r\n */\r\n public Matrix4f rotationZYX(float angleZ, float angleY, float angleX) {\r\n float cosZ = (float) Math.cos(angleZ);\r\n float sinZ = (float) Math.sin(angleZ);\r\n float cosY = (float) Math.cos(angleY);\r\n float sinY = (float) Math.sin(angleY);\r\n float cosX = (float) Math.cos(angleX);\r\n float sinX = (float) Math.sin(angleX);\r\n float m_sinZ = -sinZ;\r\n float m_sinY = -sinY;\r\n float m_sinX = -sinX;\r\n\r\n // rotateZ\r\n float nm00 = cosZ;\r\n float nm01 = sinZ;\r\n float nm10 = m_sinZ;\r\n float nm11 = cosZ;\r\n // rotateY\r\n float nm20 = nm00 * sinY;\r\n float nm21 = nm01 * sinY;\r\n float nm22 = cosY;\r\n m00 = nm00 * cosY;\r\n m01 = nm01 * cosY;\r\n m02 = m_sinY;\r\n m03 = 0.0f;\r\n // rotateX\r\n m10 = nm10 * cosX + nm20 * sinX;\r\n m11 = nm11 * cosX + nm21 * sinX;\r\n m12 = nm22 * sinX;\r\n m13 = 0.0f;\r\n m20 = nm10 * m_sinX + nm20 * cosX;\r\n m21 = nm11 * m_sinX + nm21 * cosX;\r\n m22 = nm22 * cosX;\r\n m23 = 0.0f;\r\n // set last column to identity\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to a rotation of angleY
radians about the Y axis, followed by a rotation\r\n * of angleX
radians about the X axis and followed by a rotation of angleZ
radians about the Z axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method is equivalent to calling: rotationY(angleY).rotateX(angleX).rotateZ(angleZ)\r\n * \r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @return this\r\n */\r\n public Matrix4f rotationYXZ(float angleY, float angleX, float angleZ) {\r\n float cosY = (float) Math.cos(angleY);\r\n float sinY = (float) Math.sin(angleY);\r\n float cosX = (float) Math.cos(angleX);\r\n float sinX = (float) Math.sin(angleX);\r\n float cosZ = (float) Math.cos(angleZ);\r\n float sinZ = (float) Math.sin(angleZ);\r\n float m_sinY = -sinY;\r\n float m_sinX = -sinX;\r\n float m_sinZ = -sinZ;\r\n\r\n // rotateY\r\n float nm00 = cosY;\r\n float nm02 = m_sinY;\r\n float nm20 = sinY;\r\n float nm22 = cosY;\r\n // rotateX\r\n float nm10 = nm20 * sinX;\r\n float nm11 = cosX;\r\n float nm12 = nm22 * sinX;\r\n m20 = nm20 * cosX;\r\n m21 = m_sinX;\r\n m22 = nm22 * cosX;\r\n m23 = 0.0f;\r\n // rotateZ\r\n m00 = nm00 * cosZ + nm10 * sinZ;\r\n m01 = nm11 * sinZ;\r\n m02 = nm02 * cosZ + nm12 * sinZ;\r\n m03 = 0.0f;\r\n m10 = nm00 * m_sinZ + nm10 * cosZ;\r\n m11 = nm11 * cosZ;\r\n m12 = nm02 * m_sinZ + nm12 * cosZ;\r\n m13 = 0.0f;\r\n // set last column to identity\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set only the upper left 3x3 submatrix of this matrix to a rotation of angleX
radians about the X axis, followed by a rotation\r\n * of angleY
radians about the Y axis and followed by a rotation of angleZ
radians about the Z axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n * \r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @return this\r\n */\r\n public Matrix4f setRotationXYZ(float angleX, float angleY, float angleZ) {\r\n float cosX = (float) Math.cos(angleX);\r\n float sinX = (float) Math.sin(angleX);\r\n float cosY = (float) Math.cos(angleY);\r\n float sinY = (float) Math.sin(angleY);\r\n float cosZ = (float) Math.cos(angleZ);\r\n float sinZ = (float) Math.sin(angleZ);\r\n float m_sinX = -sinX;\r\n float m_sinY = -sinY;\r\n float m_sinZ = -sinZ;\r\n\r\n // rotateX\r\n float nm11 = cosX;\r\n float nm12 = sinX;\r\n float nm21 = m_sinX;\r\n float nm22 = cosX;\r\n // rotateY\r\n float nm00 = cosY;\r\n float nm01 = nm21 * m_sinY;\r\n float nm02 = nm22 * m_sinY;\r\n m20 = sinY;\r\n m21 = nm21 * cosY;\r\n m22 = nm22 * cosY;\r\n // rotateZ\r\n m00 = nm00 * cosZ;\r\n m01 = nm01 * cosZ + nm11 * sinZ;\r\n m02 = nm02 * cosZ + nm12 * sinZ;\r\n m10 = nm00 * m_sinZ;\r\n m11 = nm01 * m_sinZ + nm11 * cosZ;\r\n m12 = nm02 * m_sinZ + nm12 * cosZ;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set only the upper left 3x3 submatrix of this matrix to a rotation of angleZ
radians about the Z axis, followed by a rotation\r\n * of angleY
radians about the Y axis and followed by a rotation of angleX
radians about the X axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n * \r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleX\r\n * the angle to rotate about X\r\n * @return this\r\n */\r\n public Matrix4f setRotationZYX(float angleZ, float angleY, float angleX) {\r\n float cosZ = (float) Math.cos(angleZ);\r\n float sinZ = (float) Math.sin(angleZ);\r\n float cosY = (float) Math.cos(angleY);\r\n float sinY = (float) Math.sin(angleY);\r\n float cosX = (float) Math.cos(angleX);\r\n float sinX = (float) Math.sin(angleX);\r\n float m_sinZ = -sinZ;\r\n float m_sinY = -sinY;\r\n float m_sinX = -sinX;\r\n\r\n // rotateZ\r\n float nm00 = cosZ;\r\n float nm01 = sinZ;\r\n float nm10 = m_sinZ;\r\n float nm11 = cosZ;\r\n // rotateY\r\n float nm20 = nm00 * sinY;\r\n float nm21 = nm01 * sinY;\r\n float nm22 = cosY;\r\n m00 = nm00 * cosY;\r\n m01 = nm01 * cosY;\r\n m02 = m_sinY;\r\n // rotateX\r\n m10 = nm10 * cosX + nm20 * sinX;\r\n m11 = nm11 * cosX + nm21 * sinX;\r\n m12 = nm22 * sinX;\r\n m20 = nm10 * m_sinX + nm20 * cosX;\r\n m21 = nm11 * m_sinX + nm21 * cosX;\r\n m22 = nm22 * cosX;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set only the upper left 3x3 submatrix of this matrix to a rotation of angleY
radians about the Y axis, followed by a rotation\r\n * of angleX
radians about the X axis and followed by a rotation of angleZ
radians about the Z axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n * \r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @return this\r\n */\r\n public Matrix4f setRotationYXZ(float angleY, float angleX, float angleZ) {\r\n float cosY = (float) Math.cos(angleY);\r\n float sinY = (float) Math.sin(angleY);\r\n float cosX = (float) Math.cos(angleX);\r\n float sinX = (float) Math.sin(angleX);\r\n float cosZ = (float) Math.cos(angleZ);\r\n float sinZ = (float) Math.sin(angleZ);\r\n float m_sinY = -sinY;\r\n float m_sinX = -sinX;\r\n float m_sinZ = -sinZ;\r\n\r\n // rotateY\r\n float nm00 = cosY;\r\n float nm02 = m_sinY;\r\n float nm20 = sinY;\r\n float nm22 = cosY;\r\n // rotateX\r\n float nm10 = nm20 * sinX;\r\n float nm11 = cosX;\r\n float nm12 = nm22 * sinX;\r\n m20 = nm20 * cosX;\r\n m21 = m_sinX;\r\n m22 = nm22 * cosX;\r\n // rotateZ\r\n m00 = nm00 * cosZ + nm10 * sinZ;\r\n m01 = nm11 * sinZ;\r\n m02 = nm02 * cosZ + nm12 * sinZ;\r\n m10 = nm00 * m_sinZ + nm10 * cosZ;\r\n m11 = nm11 * cosZ;\r\n m12 = nm02 * m_sinZ + nm12 * cosZ;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to the rotation transformation of the given {@link Quaternionf}.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * The resulting matrix can be multiplied against another transformation\r\n * matrix to obtain an additional rotation.\r\n *
\r\n * In order to apply the rotation transformation to an existing transformation,\r\n * use {@link #rotate(Quaternionf) rotate()} instead.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotate(Quaternionf)\r\n * \r\n * @param quat\r\n * the {@link Quaternionf}\r\n * @return this\r\n */\r\n public Matrix4f rotation(Quaternionf quat) {\r\n float dqx = quat.x + quat.x;\r\n float dqy = quat.y + quat.y;\r\n float dqz = quat.z + quat.z;\r\n float q00 = dqx * quat.x;\r\n float q11 = dqy * quat.y;\r\n float q22 = dqz * quat.z;\r\n float q01 = dqx * quat.y;\r\n float q02 = dqx * quat.z;\r\n float q03 = dqx * quat.w;\r\n float q12 = dqy * quat.z;\r\n float q13 = dqy * quat.w;\r\n float q23 = dqz * quat.w;\r\n\r\n m00 = 1.0f - q11 - q22;\r\n m01 = q01 + q23;\r\n m02 = q02 - q13;\r\n m03 = 0.0f;\r\n m10 = q01 - q23;\r\n m11 = 1.0f - q22 - q00;\r\n m12 = q12 + q03;\r\n m13 = 0.0f;\r\n m20 = q02 + q13;\r\n m21 = q12 - q03;\r\n m22 = 1.0f - q11 - q00;\r\n m23 = 0.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this
matrix to T * R * S, where T is a translation by the given (tx, ty, tz),\r\n * R is a rotation transformation specified by the quaternion (qx, qy, qz, qw), and S is a scaling transformation\r\n * which scales the three axes x, y and z by (sx, sy, sz).\r\n *
\r\n * When transforming a vector by the resulting matrix the scaling transformation will be applied first, then the rotation and\r\n * at last the translation.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method is equivalent to calling: translation(tx, ty, tz).rotate(quat).scale(sx, sy, sz)\r\n * \r\n * @see #translation(float, float, float)\r\n * @see #rotate(Quaternionf)\r\n * @see #scale(float, float, float)\r\n * \r\n * @param tx\r\n * the number of units by which to translate the x-component\r\n * @param ty\r\n * the number of units by which to translate the y-component\r\n * @param tz\r\n * the number of units by which to translate the z-component\r\n * @param qx\r\n * the x-coordinate of the vector part of the quaternion\r\n * @param qy\r\n * the y-coordinate of the vector part of the quaternion\r\n * @param qz\r\n * the z-coordinate of the vector part of the quaternion\r\n * @param qw\r\n * the scalar part of the quaternion\r\n * @param sx\r\n * the scaling factor for the x-axis\r\n * @param sy\r\n * the scaling factor for the y-axis\r\n * @param sz\r\n * the scaling factor for the z-axis\r\n * @return this\r\n */\r\n public Matrix4f translationRotateScale(float tx, float ty, float tz, \r\n float qx, float qy, float qz, float qw, \r\n float sx, float sy, float sz) {\r\n float dqx = qx + qx;\r\n float dqy = qy + qy;\r\n float dqz = qz + qz;\r\n float q00 = dqx * qx;\r\n float q11 = dqy * qy;\r\n float q22 = dqz * qz;\r\n float q01 = dqx * qy;\r\n float q02 = dqx * qz;\r\n float q03 = dqx * qw;\r\n float q12 = dqy * qz;\r\n float q13 = dqy * qw;\r\n float q23 = dqz * qw;\r\n m00 = sx - (q11 + q22) * sx;\r\n m01 = (q01 + q23) * sx;\r\n m02 = (q02 - q13) * sx;\r\n m03 = 0.0f;\r\n m10 = (q01 - q23) * sy;\r\n m11 = sy - (q22 + q00) * sy;\r\n m12 = (q12 + q03) * sy;\r\n m13 = 0.0f;\r\n m20 = (q02 + q13) * sz;\r\n m21 = (q12 - q03) * sz;\r\n m22 = sz - (q11 + q00) * sz;\r\n m23 = 0.0f;\r\n m30 = tx;\r\n m31 = ty;\r\n m32 = tz;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this
matrix to T * R * S, where T is the given translation
,\r\n * R is a rotation transformation specified by the given quaternion, and S is a scaling transformation\r\n * which scales the axes by scale
.\r\n *
\r\n * When transforming a vector by the resulting matrix the scaling transformation will be applied first, then the rotation and\r\n * at last the translation.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method is equivalent to calling: translation(translation).rotate(quat).scale(scale)\r\n * \r\n * @see #translation(Vector3f)\r\n * @see #rotate(Quaternionf)\r\n * \r\n * @param translation\r\n * the translation\r\n * @param quat\r\n * the quaternion representing a rotation\r\n * @param scale\r\n * the scaling factors\r\n * @return this\r\n */\r\n public Matrix4f translationRotateScale(Vector3f translation, \r\n Quaternionf quat, \r\n Vector3f scale) {\r\n return translationRotateScale(translation.x, translation.y, translation.z, quat.x, quat.y, quat.z, quat.w, scale.x, scale.y, scale.z);\r\n }\r\n\r\n /**\r\n * Set this
matrix to T * R * S * M, where T is a translation by the given (tx, ty, tz),\r\n * R is a rotation transformation specified by the quaternion (qx, qy, qz, qw), S is a scaling transformation\r\n * which scales the three axes x, y and z by (sx, sy, sz) and M
is an {@link #isAffine() affine} matrix.\r\n *
\r\n * When transforming a vector by the resulting matrix the transformation described by M
will be applied first, then the scaling, then rotation and\r\n * at last the translation.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method is equivalent to calling: translation(tx, ty, tz).rotate(quat).scale(sx, sy, sz).mulAffine(m)\r\n * \r\n * @see #translation(float, float, float)\r\n * @see #rotate(Quaternionf)\r\n * @see #scale(float, float, float)\r\n * @see #mulAffine(Matrix4f)\r\n * \r\n * @param tx\r\n * the number of units by which to translate the x-component\r\n * @param ty\r\n * the number of units by which to translate the y-component\r\n * @param tz\r\n * the number of units by which to translate the z-component\r\n * @param qx\r\n * the x-coordinate of the vector part of the quaternion\r\n * @param qy\r\n * the y-coordinate of the vector part of the quaternion\r\n * @param qz\r\n * the z-coordinate of the vector part of the quaternion\r\n * @param qw\r\n * the scalar part of the quaternion\r\n * @param sx\r\n * the scaling factor for the x-axis\r\n * @param sy\r\n * the scaling factor for the y-axis\r\n * @param sz\r\n * the scaling factor for the z-axis\r\n * @param m\r\n * the {@link #isAffine() affine} matrix to multiply by\r\n * @return this\r\n */\r\n public Matrix4f translationRotateScaleMulAffine(float tx, float ty, float tz, \r\n float qx, float qy, float qz, float qw, \r\n float sx, float sy, float sz,\r\n Matrix4f m) {\r\n float dqx = qx + qx;\r\n float dqy = qy + qy;\r\n float dqz = qz + qz;\r\n float q00 = dqx * qx;\r\n float q11 = dqy * qy;\r\n float q22 = dqz * qz;\r\n float q01 = dqx * qy;\r\n float q02 = dqx * qz;\r\n float q03 = dqx * qw;\r\n float q12 = dqy * qz;\r\n float q13 = dqy * qw;\r\n float q23 = dqz * qw;\r\n float nm00 = sx - (q11 + q22) * sx;\r\n float nm01 = (q01 + q23) * sx;\r\n float nm02 = (q02 - q13) * sx;\r\n float nm10 = (q01 - q23) * sy;\r\n float nm11 = sy - (q22 + q00) * sy;\r\n float nm12 = (q12 + q03) * sy;\r\n float nm20 = (q02 + q13) * sz;\r\n float nm21 = (q12 - q03) * sz;\r\n float nm22 = sz - (q11 + q00) * sz;\r\n float m00 = nm00 * m.m00 + nm10 * m.m01 + nm20 * m.m02;\r\n float m01 = nm01 * m.m00 + nm11 * m.m01 + nm21 * m.m02;\r\n m02 = nm02 * m.m00 + nm12 * m.m01 + nm22 * m.m02;\r\n this.m00 = m00;\r\n this.m01 = m01;\r\n m03 = 0.0f;\r\n float m10 = nm00 * m.m10 + nm10 * m.m11 + nm20 * m.m12;\r\n float m11 = nm01 * m.m10 + nm11 * m.m11 + nm21 * m.m12;\r\n m12 = nm02 * m.m10 + nm12 * m.m11 + nm22 * m.m12;\r\n this.m10 = m10;\r\n this.m11 = m11;\r\n m13 = 0.0f;\r\n float m20 = nm00 * m.m20 + nm10 * m.m21 + nm20 * m.m22;\r\n float m21 = nm01 * m.m20 + nm11 * m.m21 + nm21 * m.m22;\r\n m22 = nm02 * m.m20 + nm12 * m.m21 + nm22 * m.m22;\r\n this.m20 = m20;\r\n this.m21 = m21;\r\n m23 = 0.0f;\r\n float m30 = nm00 * m.m30 + nm10 * m.m31 + nm20 * m.m32 + tx;\r\n float m31 = nm01 * m.m30 + nm11 * m.m31 + nm21 * m.m32 + ty;\r\n m32 = nm02 * m.m30 + nm12 * m.m31 + nm22 * m.m32 + tz;\r\n this.m30 = m30;\r\n this.m31 = m31;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this
matrix to T * R * S * M, where T is the given translation
,\r\n * R is a rotation transformation specified by the given quaternion, S is a scaling transformation\r\n * which scales the axes by scale
and M
is an {@link #isAffine() affine} matrix.\r\n *
\r\n * When transforming a vector by the resulting matrix the transformation described by M
will be applied first, then the scaling, then rotation and\r\n * at last the translation.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method is equivalent to calling: translation(translation).rotate(quat).scale(scale).mulAffine(m)\r\n * \r\n * @see #translation(Vector3f)\r\n * @see #rotate(Quaternionf)\r\n * @see #mulAffine(Matrix4f)\r\n * \r\n * @param translation\r\n * the translation\r\n * @param quat\r\n * the quaternion representing a rotation\r\n * @param scale\r\n * the scaling factors\r\n * @param m\r\n * the {@link #isAffine() affine} matrix to multiply by\r\n * @return this\r\n */\r\n public Matrix4f translationRotateScaleMulAffine(Vector3f translation, \r\n Quaternionf quat, \r\n Vector3f scale,\r\n Matrix4f m) {\r\n return translationRotateScaleMulAffine(translation.x, translation.y, translation.z, quat.x, quat.y, quat.z, quat.w, scale.x, scale.y, scale.z, m);\r\n }\r\n\r\n /**\r\n * Set this
matrix to T * R, where T is a translation by the given (tx, ty, tz) and\r\n * R is a rotation transformation specified by the given quaternion.\r\n *
\r\n * When transforming a vector by the resulting matrix the rotation transformation will be applied first and then the translation.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method is equivalent to calling: translation(tx, ty, tz).rotate(quat)\r\n * \r\n * @see #translation(float, float, float)\r\n * @see #rotate(Quaternionf)\r\n * \r\n * @param tx\r\n * the number of units by which to translate the x-component\r\n * @param ty\r\n * the number of units by which to translate the y-component\r\n * @param tz\r\n * the number of units by which to translate the z-component\r\n * @param quat\r\n * the quaternion representing a rotation\r\n * @return this\r\n */\r\n public Matrix4f translationRotate(float tx, float ty, float tz, Quaternionf quat) {\r\n float dqx = quat.x + quat.x;\r\n float dqy = quat.y + quat.y;\r\n float dqz = quat.z + quat.z;\r\n float q00 = dqx * quat.x;\r\n float q11 = dqy * quat.y;\r\n float q22 = dqz * quat.z;\r\n float q01 = dqx * quat.y;\r\n float q02 = dqx * quat.z;\r\n float q03 = dqx * quat.w;\r\n float q12 = dqy * quat.z;\r\n float q13 = dqy * quat.w;\r\n float q23 = dqz * quat.w;\r\n m00 = 1.0f - (q11 + q22);\r\n m01 = q01 + q23;\r\n m02 = q02 - q13;\r\n m03 = 0.0f;\r\n m10 = q01 - q23;\r\n m11 = 1.0f - (q22 + q00);\r\n m12 = q12 + q03;\r\n m13 = 0.0f;\r\n m20 = q02 + q13;\r\n m21 = q12 - q03;\r\n m22 = 1.0f - (q11 + q00);\r\n m23 = 0.0f;\r\n m30 = tx;\r\n m31 = ty;\r\n m32 = tz;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the upper left 3x3 submatrix of this {@link Matrix4f} to the given {@link Matrix3f} and don't change the other elements..\r\n * \r\n * @param mat\r\n * the 3x3 matrix\r\n * @return this\r\n */\r\n public Matrix4f set3x3(Matrix3f mat) {\r\n m00 = mat.m00;\r\n m01 = mat.m01;\r\n m02 = mat.m02;\r\n m10 = mat.m10;\r\n m11 = mat.m11;\r\n m12 = mat.m12;\r\n m20 = mat.m20;\r\n m21 = mat.m21;\r\n m22 = mat.m22;\r\n return this;\r\n }\r\n\r\n /**\r\n * Transform/multiply the given vector by this matrix and store the result in that vector.\r\n * \r\n * @see Vector4f#mul(Matrix4f)\r\n * \r\n * @param v\r\n * the vector to transform and to hold the final result\r\n * @return v\r\n */\r\n public Vector4f transform(Vector4f v) {\r\n return v.mul(this);\r\n }\r\n\r\n /**\r\n * Transform/multiply the given vector by this matrix and store the result in dest
.\r\n * \r\n * @see Vector4f#mul(Matrix4f, Vector4f)\r\n * \r\n * @param v\r\n * the vector to transform\r\n * @param dest\r\n * will contain the result\r\n * @return dest\r\n */\r\n public Vector4f transform(Vector4f v, Vector4f dest) {\r\n return v.mul(this, dest);\r\n }\r\n\r\n /**\r\n * Transform/multiply the given vector by this matrix, perform perspective divide and store the result in that vector.\r\n * \r\n * @see Vector4f#mulProject(Matrix4f)\r\n * \r\n * @param v\r\n * the vector to transform and to hold the final result\r\n * @return v\r\n */\r\n public Vector4f transformProject(Vector4f v) {\r\n return v.mulProject(this);\r\n }\r\n\r\n /**\r\n * Transform/multiply the given vector by this matrix, perform perspective divide and store the result in dest
.\r\n * \r\n * @see Vector4f#mulProject(Matrix4f, Vector4f)\r\n * \r\n * @param v\r\n * the vector to transform\r\n * @param dest\r\n * will contain the result\r\n * @return dest\r\n */\r\n public Vector4f transformProject(Vector4f v, Vector4f dest) {\r\n return v.mulProject(this, dest);\r\n }\r\n\r\n /**\r\n * Transform/multiply the given vector by this matrix, perform perspective divide and store the result in that vector.\r\n *
\r\n * This method uses w=1.0 as the fourth vector component.\r\n * \r\n * @see Vector3f#mulProject(Matrix4f)\r\n * \r\n * @param v\r\n * the vector to transform and to hold the final result\r\n * @return v\r\n */\r\n public Vector3f transformProject(Vector3f v) {\r\n return v.mulProject(this);\r\n }\r\n\r\n /**\r\n * Transform/multiply the given vector by this matrix, perform perspective divide and store the result in dest
.\r\n *
\r\n * This method uses w=1.0 as the fourth vector component.\r\n * \r\n * @see Vector3f#mulProject(Matrix4f, Vector3f)\r\n * \r\n * @param v\r\n * the vector to transform\r\n * @param dest\r\n * will contain the result\r\n * @return dest\r\n */\r\n public Vector3f transformProject(Vector3f v, Vector3f dest) {\r\n return v.mulProject(this, dest);\r\n }\r\n\r\n /**\r\n * Transform/multiply the given 3D-vector, as if it was a 4D-vector with w=1, by\r\n * this matrix and store the result in that vector.\r\n *
\r\n * The given 3D-vector is treated as a 4D-vector with its w-component being 1.0, so it\r\n * will represent a position/location in 3D-space rather than a direction. This method is therefore\r\n * not suited for perspective projection transformations as it will not save the\r\n * w component of the transformed vector.\r\n * For perspective projection use {@link #transform(Vector4f)} or {@link #transformProject(Vector3f)}\r\n * when perspective divide should be applied, too.\r\n *
\r\n * In order to store the result in another vector, use {@link #transformPosition(Vector3f, Vector3f)}.\r\n * \r\n * @see #transformPosition(Vector3f, Vector3f)\r\n * @see #transform(Vector4f)\r\n * @see #transformProject(Vector3f)\r\n * \r\n * @param v\r\n * the vector to transform and to hold the final result\r\n * @return v\r\n */\r\n public Vector3f transformPosition(Vector3f v) {\r\n v.set(m00 * v.x + m10 * v.y + m20 * v.z + m30,\r\n m01 * v.x + m11 * v.y + m21 * v.z + m31,\r\n m02 * v.x + m12 * v.y + m22 * v.z + m32);\r\n return v;\r\n }\r\n\r\n /**\r\n * Transform/multiply the given 3D-vector, as if it was a 4D-vector with w=1, by\r\n * this matrix and store the result in dest
.\r\n *
\r\n * The given 3D-vector is treated as a 4D-vector with its w-component being 1.0, so it\r\n * will represent a position/location in 3D-space rather than a direction. This method is therefore\r\n * not suited for perspective projection transformations as it will not save the\r\n * w component of the transformed vector.\r\n * For perspective projection use {@link #transform(Vector4f, Vector4f)} or\r\n * {@link #transformProject(Vector3f, Vector3f)} when perspective divide should be applied, too.\r\n *
\r\n * In order to store the result in the same vector, use {@link #transformPosition(Vector3f)}.\r\n * \r\n * @see #transformPosition(Vector3f)\r\n * @see #transform(Vector4f, Vector4f)\r\n * @see #transformProject(Vector3f, Vector3f)\r\n * \r\n * @param v\r\n * the vector to transform\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Vector3f transformPosition(Vector3f v, Vector3f dest) {\r\n dest.set(m00 * v.x + m10 * v.y + m20 * v.z + m30,\r\n m01 * v.x + m11 * v.y + m21 * v.z + m31,\r\n m02 * v.x + m12 * v.y + m22 * v.z + m32);\r\n return dest;\r\n }\r\n\r\n /**\r\n * Transform/multiply the given 3D-vector, as if it was a 4D-vector with w=0, by\r\n * this matrix and store the result in that vector.\r\n *
\r\n * The given 3D-vector is treated as a 4D-vector with its w-component being 0.0, so it\r\n * will represent a direction in 3D-space rather than a position. This method will therefore\r\n * not take the translation part of the matrix into account.\r\n *
\r\n * In order to store the result in another vector, use {@link #transformDirection(Vector3f, Vector3f)}.\r\n * \r\n * @see #transformDirection(Vector3f, Vector3f)\r\n * \r\n * @param v\r\n * the vector to transform and to hold the final result\r\n * @return v\r\n */\r\n public Vector3f transformDirection(Vector3f v) {\r\n v.set(m00 * v.x + m10 * v.y + m20 * v.z,\r\n m01 * v.x + m11 * v.y + m21 * v.z,\r\n m02 * v.x + m12 * v.y + m22 * v.z);\r\n return v;\r\n }\r\n\r\n /**\r\n * Transform/multiply the given 3D-vector, as if it was a 4D-vector with w=0, by\r\n * this matrix and store the result in dest
.\r\n *
\r\n * The given 3D-vector is treated as a 4D-vector with its w-component being 0.0, so it\r\n * will represent a direction in 3D-space rather than a position. This method will therefore\r\n * not take the translation part of the matrix into account.\r\n *
\r\n * In order to store the result in the same vector, use {@link #transformDirection(Vector3f)}.\r\n * \r\n * @see #transformDirection(Vector3f)\r\n * \r\n * @param v\r\n * the vector to transform and to hold the final result\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Vector3f transformDirection(Vector3f v, Vector3f dest) {\r\n dest.set(m00 * v.x + m10 * v.y + m20 * v.z,\r\n m01 * v.x + m11 * v.y + m21 * v.z,\r\n m02 * v.x + m12 * v.y + m22 * v.z);\r\n return dest;\r\n }\r\n\r\n /**\r\n * Transform/multiply the given 4D-vector by assuming that this
matrix represents an {@link #isAffine() affine} transformation\r\n * (i.e. its last row is equal to (0, 0, 0, 1)).\r\n *
\r\n * In order to store the result in another vector, use {@link #transformAffine(Vector4f, Vector4f)}.\r\n * \r\n * @see #transformAffine(Vector4f, Vector4f)\r\n * \r\n * @param v\r\n * the vector to transform and to hold the final result\r\n * @return v\r\n */\r\n public Vector4f transformAffine(Vector4f v) {\r\n v.set(m00 * v.x + m10 * v.y + m20 * v.z + m30 * v.w,\r\n m01 * v.x + m11 * v.y + m21 * v.z + m31 * v.w,\r\n m02 * v.x + m12 * v.y + m22 * v.z + m32 * v.w,\r\n v.w);\r\n return v;\r\n }\r\n\r\n /**\r\n * Transform/multiply the given 4D-vector by assuming that this
matrix represents an {@link #isAffine() affine} transformation\r\n * (i.e. its last row is equal to (0, 0, 0, 1)) and store the result in dest
.\r\n *
\r\n * In order to store the result in the same vector, use {@link #transformAffine(Vector4f)}.\r\n * \r\n * @see #transformAffine(Vector4f)\r\n * \r\n * @param v\r\n * the vector to transform and to hold the final result\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Vector4f transformAffine(Vector4f v, Vector4f dest) {\r\n dest.set(m00 * v.x + m10 * v.y + m20 * v.z + m30 * v.w,\r\n m01 * v.x + m11 * v.y + m21 * v.z + m31 * v.w,\r\n m02 * v.x + m12 * v.y + m22 * v.z + m32 * v.w,\r\n v.w);\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply scaling to the this matrix by scaling the base axes by the given xyz.x,\r\n * xyz.y and xyz.z factors, respectively and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and S
the scaling matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
\r\n * , the scaling will be applied first!\r\n * \r\n * @param xyz\r\n * the factors of the x, y and z component, respectively\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f scale(Vector3f xyz, Matrix4f dest) {\r\n return scale(xyz.x, xyz.y, xyz.z, dest);\r\n }\r\n\r\n /**\r\n * Apply scaling to this matrix by scaling the base axes by the given xyz.x,\r\n * xyz.y and xyz.z factors, respectively.\r\n *
\r\n * If M
is this
matrix and S
the scaling matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
, the\r\n * scaling will be applied first!\r\n * \r\n * @param xyz\r\n * the factors of the x, y and z component, respectively\r\n * @return this\r\n */\r\n public Matrix4f scale(Vector3f xyz) {\r\n return scale(xyz.x, xyz.y, xyz.z, this);\r\n }\r\n\r\n /**\r\n * Apply scaling to this matrix by uniformly scaling all base axes by the given xyz
factor\r\n * and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and S
the scaling matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
, the\r\n * scaling will be applied first!\r\n *
\r\n * Individual scaling of all three axes can be applied using {@link #scale(float, float, float, Matrix4f)}. \r\n * \r\n * @see #scale(float, float, float, Matrix4f)\r\n * \r\n * @param xyz\r\n * the factor for all components\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f scale(float xyz, Matrix4f dest) {\r\n return scale(xyz, xyz, xyz, dest);\r\n }\r\n\r\n /**\r\n * Apply scaling to this matrix by uniformly scaling all base axes by the given xyz
factor.\r\n *
\r\n * If M
is this
matrix and S
the scaling matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
, the\r\n * scaling will be applied first!\r\n *
\r\n * Individual scaling of all three axes can be applied using {@link #scale(float, float, float)}. \r\n * \r\n * @see #scale(float, float, float)\r\n * \r\n * @param xyz\r\n * the factor for all components\r\n * @return this\r\n */\r\n public Matrix4f scale(float xyz) {\r\n return scale(xyz, xyz, xyz);\r\n }\r\n\r\n /**\r\n * Apply scaling to the this matrix by scaling the base axes by the given x,\r\n * y and z factors and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and S
the scaling matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
\r\n * , the scaling will be applied first!\r\n * \r\n * @param x\r\n * the factor of the x component\r\n * @param y\r\n * the factor of the y component\r\n * @param z\r\n * the factor of the z component\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f scale(float x, float y, float z, Matrix4f dest) {\r\n // scale matrix elements:\r\n // m00 = x, m11 = y, m22 = z\r\n // m33 = 1\r\n // all others = 0\r\n dest.m00 = m00 * x;\r\n dest.m01 = m01 * x;\r\n dest.m02 = m02 * x;\r\n dest.m03 = m03 * x;\r\n dest.m10 = m10 * y;\r\n dest.m11 = m11 * y;\r\n dest.m12 = m12 * y;\r\n dest.m13 = m13 * y;\r\n dest.m20 = m20 * z;\r\n dest.m21 = m21 * z;\r\n dest.m22 = m22 * z;\r\n dest.m23 = m23 * z;\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply scaling to this matrix by scaling the base axes by the given x,\r\n * y and z factors.\r\n *
\r\n * If M
is this
matrix and S
the scaling matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
, the\r\n * scaling will be applied first!\r\n * \r\n * @param x\r\n * the factor of the x component\r\n * @param y\r\n * the factor of the y component\r\n * @param z\r\n * the factor of the z component\r\n * @return this\r\n */\r\n public Matrix4f scale(float x, float y, float z) {\r\n return scale(x, y, z, this);\r\n }\r\n\r\n /**\r\n * Pre-multiply scaling to the this matrix by scaling the base axes by the given x,\r\n * y and z factors and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and S
the scaling matrix,\r\n * then the new matrix will be S * M
. So when transforming a\r\n * vector v
with the new matrix by using S * M * v
\r\n * , the scaling will be applied last!\r\n * \r\n * @param x\r\n * the factor of the x component\r\n * @param y\r\n * the factor of the y component\r\n * @param z\r\n * the factor of the z component\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f scaleLocal(float x, float y, float z, Matrix4f dest) {\r\n float nm00 = x * m00;\r\n float nm01 = y * m01;\r\n float nm02 = z * m02;\r\n float nm03 = m03;\r\n float nm10 = x * m10;\r\n float nm11 = y * m11;\r\n float nm12 = z * m12;\r\n float nm13 = m13;\r\n float nm20 = x * m20;\r\n float nm21 = y * m21;\r\n float nm22 = z * m22;\r\n float nm23 = m23;\r\n float nm30 = x * m30;\r\n float nm31 = y * m31;\r\n float nm32 = z * m32;\r\n float nm33 = m33;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Pre-multiply scaling to this matrix by scaling the base axes by the given x,\r\n * y and z factors.\r\n *
\r\n * If M
is this
matrix and S
the scaling matrix,\r\n * then the new matrix will be S * M
. So when transforming a\r\n * vector v
with the new matrix by using S * M * v
, the\r\n * scaling will be applied last!\r\n * \r\n * @param x\r\n * the factor of the x component\r\n * @param y\r\n * the factor of the y component\r\n * @param z\r\n * the factor of the z component\r\n * @return this\r\n */\r\n public Matrix4f scaleLocal(float x, float y, float z) {\r\n return scaleLocal(x, y, z, this);\r\n }\r\n\r\n /**\r\n * Apply rotation about the X axis to this matrix by rotating the given amount of radians \r\n * and store the result in dest
.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise. \r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateX(float ang, Matrix4f dest) {\r\n float sin, cos;\r\n if (ang == (float) Math.PI || ang == -(float) Math.PI) {\r\n cos = -1.0f;\r\n sin = 0.0f;\r\n } else if (ang == (float) Math.PI * 0.5f || ang == -(float) Math.PI * 1.5f) {\r\n cos = 0.0f;\r\n sin = 1.0f;\r\n } else if (ang == (float) -Math.PI * 0.5f || ang == (float) Math.PI * 1.5f) {\r\n cos = 0.0f;\r\n sin = -1.0f;\r\n } else {\r\n cos = (float) Math.cos(ang);\r\n sin = (float) Math.sin(ang);\r\n }\r\n float rm11 = cos;\r\n float rm12 = sin;\r\n float rm21 = -sin;\r\n float rm22 = cos;\r\n\r\n // add temporaries for dependent values\r\n float nm10 = m10 * rm11 + m20 * rm12;\r\n float nm11 = m11 * rm11 + m21 * rm12;\r\n float nm12 = m12 * rm11 + m22 * rm12;\r\n float nm13 = m13 * rm11 + m23 * rm12;\r\n // set non-dependent values directly\r\n dest.m20 = m10 * rm21 + m20 * rm22;\r\n dest.m21 = m11 * rm21 + m21 * rm22;\r\n dest.m22 = m12 * rm21 + m22 * rm22;\r\n dest.m23 = m13 * rm21 + m23 * rm22;\r\n // set other values\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m00 = m00;\r\n dest.m01 = m01;\r\n dest.m02 = m02;\r\n dest.m03 = m03;\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply rotation about the X axis to this matrix by rotating the given amount of radians.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @return this\r\n */\r\n public Matrix4f rotateX(float ang) {\r\n return rotateX(ang, this);\r\n }\r\n\r\n /**\r\n * Apply rotation about the Y axis to this matrix by rotating the given amount of radians \r\n * and store the result in dest
.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateY(float ang, Matrix4f dest) {\r\n float cos, sin;\r\n if (ang == (float) Math.PI || ang == -(float) Math.PI) {\r\n cos = -1.0f;\r\n sin = 0.0f;\r\n } else if (ang == (float) Math.PI * 0.5f || ang == -(float) Math.PI * 1.5f) {\r\n cos = 0.0f;\r\n sin = 1.0f;\r\n } else if (ang == (float) -Math.PI * 0.5f || ang == (float) Math.PI * 1.5f) {\r\n cos = 0.0f;\r\n sin = -1.0f;\r\n } else {\r\n cos = (float) Math.cos(ang);\r\n sin = (float) Math.sin(ang);\r\n }\r\n float rm00 = cos;\r\n float rm02 = -sin;\r\n float rm20 = sin;\r\n float rm22 = cos;\r\n\r\n // add temporaries for dependent values\r\n float nm00 = m00 * rm00 + m20 * rm02;\r\n float nm01 = m01 * rm00 + m21 * rm02;\r\n float nm02 = m02 * rm00 + m22 * rm02;\r\n float nm03 = m03 * rm00 + m23 * rm02;\r\n // set non-dependent values directly\r\n dest.m20 = m00 * rm20 + m20 * rm22;\r\n dest.m21 = m01 * rm20 + m21 * rm22;\r\n dest.m22 = m02 * rm20 + m22 * rm22;\r\n dest.m23 = m03 * rm20 + m23 * rm22;\r\n // set other values\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = m10;\r\n dest.m11 = m11;\r\n dest.m12 = m12;\r\n dest.m13 = m13;\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply rotation about the Y axis to this matrix by rotating the given amount of radians.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @return this\r\n */\r\n public Matrix4f rotateY(float ang) {\r\n return rotateY(ang, this);\r\n }\r\n\r\n /**\r\n * Apply rotation about the Z axis to this matrix by rotating the given amount of radians \r\n * and store the result in dest
.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateZ(float ang, Matrix4f dest) {\r\n float sin, cos;\r\n if (ang == (float) Math.PI || ang == -(float) Math.PI) {\r\n cos = -1.0f;\r\n sin = 0.0f;\r\n } else if (ang == (float) Math.PI * 0.5f || ang == -(float) Math.PI * 1.5f) {\r\n cos = 0.0f;\r\n sin = 1.0f;\r\n } else if (ang == (float) -Math.PI * 0.5f || ang == (float) Math.PI * 1.5f) {\r\n cos = 0.0f;\r\n sin = -1.0f;\r\n } else {\r\n cos = (float) Math.cos(ang);\r\n sin = (float) Math.sin(ang);\r\n }\r\n float rm00 = cos;\r\n float rm01 = sin;\r\n float rm10 = -sin;\r\n float rm11 = cos;\r\n\r\n // add temporaries for dependent values\r\n float nm00 = m00 * rm00 + m10 * rm01;\r\n float nm01 = m01 * rm00 + m11 * rm01;\r\n float nm02 = m02 * rm00 + m12 * rm01;\r\n float nm03 = m03 * rm00 + m13 * rm01;\r\n // set non-dependent values directly\r\n dest.m10 = m00 * rm10 + m10 * rm11;\r\n dest.m11 = m01 * rm10 + m11 * rm11;\r\n dest.m12 = m02 * rm10 + m12 * rm11;\r\n dest.m13 = m03 * rm10 + m13 * rm11;\r\n // set other values\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m20 = m20;\r\n dest.m21 = m21;\r\n dest.m22 = m22;\r\n dest.m23 = m23;\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply rotation about the Z axis to this matrix by rotating the given amount of radians.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @return this\r\n */\r\n public Matrix4f rotateZ(float ang) {\r\n return rotateZ(ang, this);\r\n }\r\n\r\n /**\r\n * Apply rotation of angleX
radians about the X axis, followed by a rotation of angleY
radians about the Y axis and\r\n * followed by a rotation of angleZ
radians about the Z axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * This method is equivalent to calling: rotateX(angleX).rotateY(angleY).rotateZ(angleZ)\r\n * \r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @return this\r\n */\r\n public Matrix4f rotateXYZ(float angleX, float angleY, float angleZ) {\r\n return rotateXYZ(angleX, angleY, angleZ, this);\r\n }\r\n\r\n /**\r\n * Apply rotation of angleX
radians about the X axis, followed by a rotation of angleY
radians about the Y axis and\r\n * followed by a rotation of angleZ
radians about the Z axis and store the result in dest
.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * This method is equivalent to calling: rotateX(angleX, dest).rotateY(angleY).rotateZ(angleZ)\r\n * \r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateXYZ(float angleX, float angleY, float angleZ, Matrix4f dest) {\r\n float cosX = (float) Math.cos(angleX);\r\n float sinX = (float) Math.sin(angleX);\r\n float cosY = (float) Math.cos(angleY);\r\n float sinY = (float) Math.sin(angleY);\r\n float cosZ = (float) Math.cos(angleZ);\r\n float sinZ = (float) Math.sin(angleZ);\r\n float m_sinX = -sinX;\r\n float m_sinY = -sinY;\r\n float m_sinZ = -sinZ;\r\n\r\n // rotateX\r\n float nm10 = m10 * cosX + m20 * sinX;\r\n float nm11 = m11 * cosX + m21 * sinX;\r\n float nm12 = m12 * cosX + m22 * sinX;\r\n float nm13 = m13 * cosX + m23 * sinX;\r\n float nm20 = m10 * m_sinX + m20 * cosX;\r\n float nm21 = m11 * m_sinX + m21 * cosX;\r\n float nm22 = m12 * m_sinX + m22 * cosX;\r\n float nm23 = m13 * m_sinX + m23 * cosX;\r\n // rotateY\r\n float nm00 = m00 * cosY + nm20 * m_sinY;\r\n float nm01 = m01 * cosY + nm21 * m_sinY;\r\n float nm02 = m02 * cosY + nm22 * m_sinY;\r\n float nm03 = m03 * cosY + nm23 * m_sinY;\r\n dest.m20 = m00 * sinY + nm20 * cosY;\r\n dest.m21 = m01 * sinY + nm21 * cosY;\r\n dest.m22 = m02 * sinY + nm22 * cosY;\r\n dest.m23 = m03 * sinY + nm23 * cosY;\r\n // rotateZ\r\n dest.m00 = nm00 * cosZ + nm10 * sinZ;\r\n dest.m01 = nm01 * cosZ + nm11 * sinZ;\r\n dest.m02 = nm02 * cosZ + nm12 * sinZ;\r\n dest.m03 = nm03 * cosZ + nm13 * sinZ;\r\n dest.m10 = nm00 * m_sinZ + nm10 * cosZ;\r\n dest.m11 = nm01 * m_sinZ + nm11 * cosZ;\r\n dest.m12 = nm02 * m_sinZ + nm12 * cosZ;\r\n dest.m13 = nm03 * m_sinZ + nm13 * cosZ;\r\n // copy last column from 'this'\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply rotation of angleX
radians about the X axis, followed by a rotation of angleY
radians about the Y axis and\r\n * followed by a rotation of angleZ
radians about the Z axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method assumes that this
matrix represents an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and can be used to speed up matrix multiplication if the matrix only represents affine transformations, such as translation, rotation, scaling and shearing (in any combination).\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * This method is equivalent to calling: rotateX(angleX).rotateY(angleY).rotateZ(angleZ)\r\n * \r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @return this\r\n */\r\n public Matrix4f rotateAffineXYZ(float angleX, float angleY, float angleZ) {\r\n return rotateAffineXYZ(angleX, angleY, angleZ, this);\r\n }\r\n\r\n /**\r\n * Apply rotation of angleX
radians about the X axis, followed by a rotation of angleY
radians about the Y axis and\r\n * followed by a rotation of angleZ
radians about the Z axis and store the result in dest
.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method assumes that this
matrix represents an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and can be used to speed up matrix multiplication if the matrix only represents affine transformations, such as translation, rotation, scaling and shearing (in any combination).\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n * \r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateAffineXYZ(float angleX, float angleY, float angleZ, Matrix4f dest) {\r\n float cosX = (float) Math.cos(angleX);\r\n float sinX = (float) Math.sin(angleX);\r\n float cosY = (float) Math.cos(angleY);\r\n float sinY = (float) Math.sin(angleY);\r\n float cosZ = (float) Math.cos(angleZ);\r\n float sinZ = (float) Math.sin(angleZ);\r\n float m_sinX = -sinX;\r\n float m_sinY = -sinY;\r\n float m_sinZ = -sinZ;\r\n\r\n // rotateX\r\n float nm10 = m10 * cosX + m20 * sinX;\r\n float nm11 = m11 * cosX + m21 * sinX;\r\n float nm12 = m12 * cosX + m22 * sinX;\r\n float nm20 = m10 * m_sinX + m20 * cosX;\r\n float nm21 = m11 * m_sinX + m21 * cosX;\r\n float nm22 = m12 * m_sinX + m22 * cosX;\r\n // rotateY\r\n float nm00 = m00 * cosY + nm20 * m_sinY;\r\n float nm01 = m01 * cosY + nm21 * m_sinY;\r\n float nm02 = m02 * cosY + nm22 * m_sinY;\r\n dest.m20 = m00 * sinY + nm20 * cosY;\r\n dest.m21 = m01 * sinY + nm21 * cosY;\r\n dest.m22 = m02 * sinY + nm22 * cosY;\r\n dest.m23 = 0.0f;\r\n // rotateZ\r\n dest.m00 = nm00 * cosZ + nm10 * sinZ;\r\n dest.m01 = nm01 * cosZ + nm11 * sinZ;\r\n dest.m02 = nm02 * cosZ + nm12 * sinZ;\r\n dest.m03 = 0.0f;\r\n dest.m10 = nm00 * m_sinZ + nm10 * cosZ;\r\n dest.m11 = nm01 * m_sinZ + nm11 * cosZ;\r\n dest.m12 = nm02 * m_sinZ + nm12 * cosZ;\r\n dest.m13 = 0.0f;\r\n // copy last column from 'this'\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply rotation of angleZ
radians about the Z axis, followed by a rotation of angleY
radians about the Y axis and\r\n * followed by a rotation of angleX
radians about the X axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * This method is equivalent to calling: rotateZ(angleZ).rotateY(angleY).rotateX(angleX)\r\n * \r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleX\r\n * the angle to rotate about X\r\n * @return this\r\n */\r\n public Matrix4f rotateZYX(float angleZ, float angleY, float angleX) {\r\n return rotateZYX(angleZ, angleY, angleX, this);\r\n }\r\n\r\n /**\r\n * Apply rotation of angleZ
radians about the Z axis, followed by a rotation of angleY
radians about the Y axis and\r\n * followed by a rotation of angleX
radians about the X axis and store the result in dest
.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * This method is equivalent to calling: rotateZ(angleZ, dest).rotateY(angleY).rotateX(angleX)\r\n * \r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateZYX(float angleZ, float angleY, float angleX, Matrix4f dest) {\r\n float cosZ = (float) Math.cos(angleZ);\r\n float sinZ = (float) Math.sin(angleZ);\r\n float cosY = (float) Math.cos(angleY);\r\n float sinY = (float) Math.sin(angleY);\r\n float cosX = (float) Math.cos(angleX);\r\n float sinX = (float) Math.sin(angleX);\r\n float m_sinZ = -sinZ;\r\n float m_sinY = -sinY;\r\n float m_sinX = -sinX;\r\n\r\n // rotateZ\r\n float nm00 = m00 * cosZ + m10 * sinZ;\r\n float nm01 = m01 * cosZ + m11 * sinZ;\r\n float nm02 = m02 * cosZ + m12 * sinZ;\r\n float nm03 = m03 * cosZ + m13 * sinZ;\r\n float nm10 = m00 * m_sinZ + m10 * cosZ;\r\n float nm11 = m01 * m_sinZ + m11 * cosZ;\r\n float nm12 = m02 * m_sinZ + m12 * cosZ;\r\n float nm13 = m03 * m_sinZ + m13 * cosZ;\r\n // rotateY\r\n float nm20 = nm00 * sinY + m20 * cosY;\r\n float nm21 = nm01 * sinY + m21 * cosY;\r\n float nm22 = nm02 * sinY + m22 * cosY;\r\n float nm23 = nm03 * sinY + m23 * cosY;\r\n dest.m00 = nm00 * cosY + m20 * m_sinY;\r\n dest.m01 = nm01 * cosY + m21 * m_sinY;\r\n dest.m02 = nm02 * cosY + m22 * m_sinY;\r\n dest.m03 = nm03 * cosY + m23 * m_sinY;\r\n // rotateX\r\n dest.m10 = nm10 * cosX + nm20 * sinX;\r\n dest.m11 = nm11 * cosX + nm21 * sinX;\r\n dest.m12 = nm12 * cosX + nm22 * sinX;\r\n dest.m13 = nm13 * cosX + nm23 * sinX;\r\n dest.m20 = nm10 * m_sinX + nm20 * cosX;\r\n dest.m21 = nm11 * m_sinX + nm21 * cosX;\r\n dest.m22 = nm12 * m_sinX + nm22 * cosX;\r\n dest.m23 = nm13 * m_sinX + nm23 * cosX;\r\n // copy last column from 'this'\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply rotation of angleZ
radians about the Z axis, followed by a rotation of angleY
radians about the Y axis and\r\n * followed by a rotation of angleX
radians about the X axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method assumes that this
matrix represents an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and can be used to speed up matrix multiplication if the matrix only represents affine transformations, such as translation, rotation, scaling and shearing (in any combination).\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n * \r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleX\r\n * the angle to rotate about X\r\n * @return this\r\n */\r\n public Matrix4f rotateAffineZYX(float angleZ, float angleY, float angleX) {\r\n return rotateAffineZYX(angleZ, angleY, angleX, this);\r\n }\r\n\r\n /**\r\n * Apply rotation of angleZ
radians about the Z axis, followed by a rotation of angleY
radians about the Y axis and\r\n * followed by a rotation of angleX
radians about the X axis and store the result in dest
.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method assumes that this
matrix represents an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and can be used to speed up matrix multiplication if the matrix only represents affine transformations, such as translation, rotation, scaling and shearing (in any combination).\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n * \r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateAffineZYX(float angleZ, float angleY, float angleX, Matrix4f dest) {\r\n float cosZ = (float) Math.cos(angleZ);\r\n float sinZ = (float) Math.sin(angleZ);\r\n float cosY = (float) Math.cos(angleY);\r\n float sinY = (float) Math.sin(angleY);\r\n float cosX = (float) Math.cos(angleX);\r\n float sinX = (float) Math.sin(angleX);\r\n float m_sinZ = -sinZ;\r\n float m_sinY = -sinY;\r\n float m_sinX = -sinX;\r\n\r\n // rotateZ\r\n float nm00 = m00 * cosZ + m10 * sinZ;\r\n float nm01 = m01 * cosZ + m11 * sinZ;\r\n float nm02 = m02 * cosZ + m12 * sinZ;\r\n float nm10 = m00 * m_sinZ + m10 * cosZ;\r\n float nm11 = m01 * m_sinZ + m11 * cosZ;\r\n float nm12 = m02 * m_sinZ + m12 * cosZ;\r\n // rotateY\r\n float nm20 = nm00 * sinY + m20 * cosY;\r\n float nm21 = nm01 * sinY + m21 * cosY;\r\n float nm22 = nm02 * sinY + m22 * cosY;\r\n dest.m00 = nm00 * cosY + m20 * m_sinY;\r\n dest.m01 = nm01 * cosY + m21 * m_sinY;\r\n dest.m02 = nm02 * cosY + m22 * m_sinY;\r\n dest.m03 = 0.0f;\r\n // rotateX\r\n dest.m10 = nm10 * cosX + nm20 * sinX;\r\n dest.m11 = nm11 * cosX + nm21 * sinX;\r\n dest.m12 = nm12 * cosX + nm22 * sinX;\r\n dest.m13 = 0.0f;\r\n dest.m20 = nm10 * m_sinX + nm20 * cosX;\r\n dest.m21 = nm11 * m_sinX + nm21 * cosX;\r\n dest.m22 = nm12 * m_sinX + nm22 * cosX;\r\n dest.m23 = 0.0f;\r\n // copy last column from 'this'\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply rotation of angleY
radians about the Y axis, followed by a rotation of angleX
radians about the X axis and\r\n * followed by a rotation of angleZ
radians about the Z axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * This method is equivalent to calling: rotateY(angleY).rotateX(angleX).rotateZ(angleZ)\r\n * \r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @return this\r\n */\r\n public Matrix4f rotateYXZ(float angleY, float angleX, float angleZ) {\r\n return rotateYXZ(angleY, angleX, angleZ, this);\r\n }\r\n\r\n /**\r\n * Apply rotation of angleY
radians about the Y axis, followed by a rotation of angleX
radians about the X axis and\r\n * followed by a rotation of angleZ
radians about the Z axis and store the result in dest
.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * This method is equivalent to calling: rotateY(angleY, dest).rotateX(angleX).rotateZ(angleZ)\r\n * \r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateYXZ(float angleY, float angleX, float angleZ, Matrix4f dest) {\r\n float cosY = (float) Math.cos(angleY);\r\n float sinY = (float) Math.sin(angleY);\r\n float cosX = (float) Math.cos(angleX);\r\n float sinX = (float) Math.sin(angleX);\r\n float cosZ = (float) Math.cos(angleZ);\r\n float sinZ = (float) Math.sin(angleZ);\r\n float m_sinY = -sinY;\r\n float m_sinX = -sinX;\r\n float m_sinZ = -sinZ;\r\n\r\n // rotateY\r\n float nm20 = m00 * sinY + m20 * cosY;\r\n float nm21 = m01 * sinY + m21 * cosY;\r\n float nm22 = m02 * sinY + m22 * cosY;\r\n float nm23 = m03 * sinY + m23 * cosY;\r\n float nm00 = m00 * cosY + m20 * m_sinY;\r\n float nm01 = m01 * cosY + m21 * m_sinY;\r\n float nm02 = m02 * cosY + m22 * m_sinY;\r\n float nm03 = m03 * cosY + m23 * m_sinY;\r\n // rotateX\r\n float nm10 = m10 * cosX + nm20 * sinX;\r\n float nm11 = m11 * cosX + nm21 * sinX;\r\n float nm12 = m12 * cosX + nm22 * sinX;\r\n float nm13 = m13 * cosX + nm23 * sinX;\r\n dest.m20 = m10 * m_sinX + nm20 * cosX;\r\n dest.m21 = m11 * m_sinX + nm21 * cosX;\r\n dest.m22 = m12 * m_sinX + nm22 * cosX;\r\n dest.m23 = m13 * m_sinX + nm23 * cosX;\r\n // rotateZ\r\n dest.m00 = nm00 * cosZ + nm10 * sinZ;\r\n dest.m01 = nm01 * cosZ + nm11 * sinZ;\r\n dest.m02 = nm02 * cosZ + nm12 * sinZ;\r\n dest.m03 = nm03 * cosZ + nm13 * sinZ;\r\n dest.m10 = nm00 * m_sinZ + nm10 * cosZ;\r\n dest.m11 = nm01 * m_sinZ + nm11 * cosZ;\r\n dest.m12 = nm02 * m_sinZ + nm12 * cosZ;\r\n dest.m13 = nm03 * m_sinZ + nm13 * cosZ;\r\n // copy last column from 'this'\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply rotation of angleY
radians about the Y axis, followed by a rotation of angleX
radians about the X axis and\r\n * followed by a rotation of angleZ
radians about the Z axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method assumes that this
matrix represents an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and can be used to speed up matrix multiplication if the matrix only represents affine transformations, such as translation, rotation, scaling and shearing (in any combination).\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n * \r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @return this\r\n */\r\n public Matrix4f rotateAffineYXZ(float angleY, float angleX, float angleZ) {\r\n return rotateAffineYXZ(angleY, angleX, angleZ, this);\r\n }\r\n\r\n /**\r\n * Apply rotation of angleY
radians about the Y axis, followed by a rotation of angleX
radians about the X axis and\r\n * followed by a rotation of angleZ
radians about the Z axis and store the result in dest
.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method assumes that this
matrix represents an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and can be used to speed up matrix multiplication if the matrix only represents affine transformations, such as translation, rotation, scaling and shearing (in any combination).\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n * \r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateAffineYXZ(float angleY, float angleX, float angleZ, Matrix4f dest) {\r\n float cosY = (float) Math.cos(angleY);\r\n float sinY = (float) Math.sin(angleY);\r\n float cosX = (float) Math.cos(angleX);\r\n float sinX = (float) Math.sin(angleX);\r\n float cosZ = (float) Math.cos(angleZ);\r\n float sinZ = (float) Math.sin(angleZ);\r\n float m_sinY = -sinY;\r\n float m_sinX = -sinX;\r\n float m_sinZ = -sinZ;\r\n\r\n // rotateY\r\n float nm20 = m00 * sinY + m20 * cosY;\r\n float nm21 = m01 * sinY + m21 * cosY;\r\n float nm22 = m02 * sinY + m22 * cosY;\r\n float nm00 = m00 * cosY + m20 * m_sinY;\r\n float nm01 = m01 * cosY + m21 * m_sinY;\r\n float nm02 = m02 * cosY + m22 * m_sinY;\r\n // rotateX\r\n float nm10 = m10 * cosX + nm20 * sinX;\r\n float nm11 = m11 * cosX + nm21 * sinX;\r\n float nm12 = m12 * cosX + nm22 * sinX;\r\n dest.m20 = m10 * m_sinX + nm20 * cosX;\r\n dest.m21 = m11 * m_sinX + nm21 * cosX;\r\n dest.m22 = m12 * m_sinX + nm22 * cosX;\r\n dest.m23 = 0.0f;\r\n // rotateZ\r\n dest.m00 = nm00 * cosZ + nm10 * sinZ;\r\n dest.m01 = nm01 * cosZ + nm11 * sinZ;\r\n dest.m02 = nm02 * cosZ + nm12 * sinZ;\r\n dest.m03 = 0.0f;\r\n dest.m10 = nm00 * m_sinZ + nm10 * cosZ;\r\n dest.m11 = nm01 * m_sinZ + nm11 * cosZ;\r\n dest.m12 = nm02 * m_sinZ + nm12 * cosZ;\r\n dest.m13 = 0.0f;\r\n // copy last column from 'this'\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply rotation to this matrix by rotating the given amount of radians\r\n * about the specified (x, y, z) axis and store the result in dest
.\r\n *
\r\n * The axis described by the three components needs to be a unit vector.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * In order to set the matrix to a rotation matrix without post-multiplying the rotation\r\n * transformation, use {@link #rotation(float, float, float, float) rotation()}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotation(float, float, float, float)\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @param x\r\n * the x component of the axis\r\n * @param y\r\n * the y component of the axis\r\n * @param z\r\n * the z component of the axis\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotate(float ang, float x, float y, float z, Matrix4f dest) {\r\n float s = (float) Math.sin(ang);\r\n float c = (float) Math.cos(ang);\r\n float C = 1.0f - c;\r\n\r\n // rotation matrix elements:\r\n // m30, m31, m32, m03, m13, m23 = 0\r\n // m33 = 1\r\n float xx = x * x, xy = x * y, xz = x * z;\r\n float yy = y * y, yz = y * z;\r\n float zz = z * z;\r\n float rm00 = xx * C + c;\r\n float rm01 = xy * C + z * s;\r\n float rm02 = xz * C - y * s;\r\n float rm10 = xy * C - z * s;\r\n float rm11 = yy * C + c;\r\n float rm12 = yz * C + x * s;\r\n float rm20 = xz * C + y * s;\r\n float rm21 = yz * C - x * s;\r\n float rm22 = zz * C + c;\r\n\r\n // add temporaries for dependent values\r\n float nm00 = m00 * rm00 + m10 * rm01 + m20 * rm02;\r\n float nm01 = m01 * rm00 + m11 * rm01 + m21 * rm02;\r\n float nm02 = m02 * rm00 + m12 * rm01 + m22 * rm02;\r\n float nm03 = m03 * rm00 + m13 * rm01 + m23 * rm02;\r\n float nm10 = m00 * rm10 + m10 * rm11 + m20 * rm12;\r\n float nm11 = m01 * rm10 + m11 * rm11 + m21 * rm12;\r\n float nm12 = m02 * rm10 + m12 * rm11 + m22 * rm12;\r\n float nm13 = m03 * rm10 + m13 * rm11 + m23 * rm12;\r\n // set non-dependent values directly\r\n dest.m20 = m00 * rm20 + m10 * rm21 + m20 * rm22;\r\n dest.m21 = m01 * rm20 + m11 * rm21 + m21 * rm22;\r\n dest.m22 = m02 * rm20 + m12 * rm21 + m22 * rm22;\r\n dest.m23 = m03 * rm20 + m13 * rm21 + m23 * rm22;\r\n // set other values\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply rotation to this matrix by rotating the given amount of radians\r\n * about the specified (x, y, z) axis.\r\n *
\r\n * The axis described by the three components needs to be a unit vector.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * In order to set the matrix to a rotation matrix without post-multiplying the rotation\r\n * transformation, use {@link #rotation(float, float, float, float) rotation()}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotation(float, float, float, float)\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @param x\r\n * the x component of the axis\r\n * @param y\r\n * the y component of the axis\r\n * @param z\r\n * the z component of the axis\r\n * @return this\r\n */\r\n public Matrix4f rotate(float ang, float x, float y, float z) {\r\n return rotate(ang, x, y, z, this);\r\n }\r\n\r\n /**\r\n * Apply rotation to this {@link #isAffine() affine} matrix by rotating the given amount of radians\r\n * about the specified (x, y, z) axis and store the result in dest
.\r\n *
\r\n * This method assumes this
to be {@link #isAffine() affine}.\r\n *
\r\n * The axis described by the three components needs to be a unit vector.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * In order to set the matrix to a rotation matrix without post-multiplying the rotation\r\n * transformation, use {@link #rotation(float, float, float, float) rotation()}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotation(float, float, float, float)\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @param x\r\n * the x component of the axis\r\n * @param y\r\n * the y component of the axis\r\n * @param z\r\n * the z component of the axis\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateAffine(float ang, float x, float y, float z, Matrix4f dest) {\r\n float s = (float) Math.sin(ang);\r\n float c = (float) Math.cos(ang);\r\n float C = 1.0f - c;\r\n float xx = x * x, xy = x * y, xz = x * z;\r\n float yy = y * y, yz = y * z;\r\n float zz = z * z;\r\n float rm00 = xx * C + c;\r\n float rm01 = xy * C + z * s;\r\n float rm02 = xz * C - y * s;\r\n float rm10 = xy * C - z * s;\r\n float rm11 = yy * C + c;\r\n float rm12 = yz * C + x * s;\r\n float rm20 = xz * C + y * s;\r\n float rm21 = yz * C - x * s;\r\n float rm22 = zz * C + c;\r\n // add temporaries for dependent values\r\n float nm00 = m00 * rm00 + m10 * rm01 + m20 * rm02;\r\n float nm01 = m01 * rm00 + m11 * rm01 + m21 * rm02;\r\n float nm02 = m02 * rm00 + m12 * rm01 + m22 * rm02;\r\n float nm10 = m00 * rm10 + m10 * rm11 + m20 * rm12;\r\n float nm11 = m01 * rm10 + m11 * rm11 + m21 * rm12;\r\n float nm12 = m02 * rm10 + m12 * rm11 + m22 * rm12;\r\n // set non-dependent values directly\r\n dest.m20 = m00 * rm20 + m10 * rm21 + m20 * rm22;\r\n dest.m21 = m01 * rm20 + m11 * rm21 + m21 * rm22;\r\n dest.m22 = m02 * rm20 + m12 * rm21 + m22 * rm22;\r\n dest.m23 = 0.0f;\r\n // set other values\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = 0.0f;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = 0.0f;\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply rotation to this {@link #isAffine() affine} matrix by rotating the given amount of radians\r\n * about the specified (x, y, z) axis.\r\n *
\r\n * This method assumes this
to be {@link #isAffine() affine}.\r\n *
\r\n * The axis described by the three components needs to be a unit vector.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * In order to set the matrix to a rotation matrix without post-multiplying the rotation\r\n * transformation, use {@link #rotation(float, float, float, float) rotation()}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotation(float, float, float, float)\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @param x\r\n * the x component of the axis\r\n * @param y\r\n * the y component of the axis\r\n * @param z\r\n * the z component of the axis\r\n * @return this\r\n */\r\n public Matrix4f rotateAffine(float ang, float x, float y, float z) {\r\n return rotateAffine(ang, x, y, z, this);\r\n }\r\n\r\n /**\r\n * Pre-multiply a rotation to this {@link #isAffine() affine} matrix by rotating the given amount of radians\r\n * about the specified (x, y, z) axis and store the result in dest
.\r\n *
\r\n * This method assumes this
to be {@link #isAffine() affine}.\r\n *
\r\n * The axis described by the three components needs to be a unit vector.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be R * M
. So when transforming a\r\n * vector v
with the new matrix by using R * M * v
, the\r\n * rotation will be applied last!\r\n *
\r\n * In order to set the matrix to a rotation matrix without pre-multiplying the rotation\r\n * transformation, use {@link #rotation(float, float, float, float) rotation()}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotation(float, float, float, float)\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @param x\r\n * the x component of the axis\r\n * @param y\r\n * the y component of the axis\r\n * @param z\r\n * the z component of the axis\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateAffineLocal(float ang, float x, float y, float z, Matrix4f dest) {\r\n float s = (float) Math.sin(ang);\r\n float c = (float) Math.cos(ang);\r\n float C = 1.0f - c;\r\n float xx = x * x, xy = x * y, xz = x * z;\r\n float yy = y * y, yz = y * z;\r\n float zz = z * z;\r\n float lm00 = xx * C + c;\r\n float lm01 = xy * C + z * s;\r\n float lm02 = xz * C - y * s;\r\n float lm10 = xy * C - z * s;\r\n float lm11 = yy * C + c;\r\n float lm12 = yz * C + x * s;\r\n float lm20 = xz * C + y * s;\r\n float lm21 = yz * C - x * s;\r\n float lm22 = zz * C + c;\r\n float nm00 = lm00 * m00 + lm10 * m01 + lm20 * m02;\r\n float nm01 = lm01 * m00 + lm11 * m01 + lm21 * m02;\r\n float nm02 = lm02 * m00 + lm12 * m01 + lm22 * m02;\r\n float nm03 = 0.0f;\r\n float nm10 = lm00 * m10 + lm10 * m11 + lm20 * m12;\r\n float nm11 = lm01 * m10 + lm11 * m11 + lm21 * m12;\r\n float nm12 = lm02 * m10 + lm12 * m11 + lm22 * m12;\r\n float nm13 = 0.0f;\r\n float nm20 = lm00 * m20 + lm10 * m21 + lm20 * m22;\r\n float nm21 = lm01 * m20 + lm11 * m21 + lm21 * m22;\r\n float nm22 = lm02 * m20 + lm12 * m21 + lm22 * m22;\r\n float nm23 = 0.0f;\r\n float nm30 = lm00 * m30 + lm10 * m31 + lm20 * m32;\r\n float nm31 = lm01 * m30 + lm11 * m31 + lm21 * m32;\r\n float nm32 = lm02 * m30 + lm12 * m31 + lm22 * m32;\r\n float nm33 = 1.0f;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Pre-multiply a rotation to this {@link #isAffine() affine} matrix by rotating the given amount of radians\r\n * about the specified (x, y, z) axis.\r\n *
\r\n * This method assumes this
to be {@link #isAffine() affine}.\r\n *
\r\n * The axis described by the three components needs to be a unit vector.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be R * M
. So when transforming a\r\n * vector v
with the new matrix by using R * M * v
, the\r\n * rotation will be applied last!\r\n *
\r\n * In order to set the matrix to a rotation matrix without pre-multiplying the rotation\r\n * transformation, use {@link #rotation(float, float, float, float) rotation()}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotation(float, float, float, float)\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @param x\r\n * the x component of the axis\r\n * @param y\r\n * the y component of the axis\r\n * @param z\r\n * the z component of the axis\r\n * @return this\r\n */\r\n public Matrix4f rotateAffineLocal(float ang, float x, float y, float z) {\r\n return rotateAffineLocal(ang, x, y, z, this);\r\n }\r\n\r\n /**\r\n * Apply a translation to this matrix by translating by the given number of\r\n * units in x, y and z.\r\n *
\r\n * If M
is this
matrix and T
the translation\r\n * matrix, then the new matrix will be M * T
. So when\r\n * transforming a vector v
with the new matrix by using\r\n * M * T * v
, the translation will be applied first!\r\n *
\r\n * In order to set the matrix to a translation transformation without post-multiplying\r\n * it, use {@link #translation(Vector3f)}.\r\n * \r\n * @see #translation(Vector3f)\r\n * \r\n * @param offset\r\n * the number of units in x, y and z by which to translate\r\n * @return this\r\n */\r\n public Matrix4f translate(Vector3f offset) {\r\n return translate(offset.x, offset.y, offset.z);\r\n }\r\n\r\n /**\r\n * Apply a translation to this matrix by translating by the given number of\r\n * units in x, y and z and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and T
the translation\r\n * matrix, then the new matrix will be M * T
. So when\r\n * transforming a vector v
with the new matrix by using\r\n * M * T * v
, the translation will be applied first!\r\n *
\r\n * In order to set the matrix to a translation transformation without post-multiplying\r\n * it, use {@link #translation(Vector3f)}.\r\n * \r\n * @see #translation(Vector3f)\r\n * \r\n * @param offset\r\n * the number of units in x, y and z by which to translate\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f translate(Vector3f offset, Matrix4f dest) {\r\n return translate(offset.x, offset.y, offset.z, dest);\r\n }\r\n\r\n /**\r\n * Apply a translation to this matrix by translating by the given number of\r\n * units in x, y and z and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and T
the translation\r\n * matrix, then the new matrix will be M * T
. So when\r\n * transforming a vector v
with the new matrix by using\r\n * M * T * v
, the translation will be applied first!\r\n *
\r\n * In order to set the matrix to a translation transformation without post-multiplying\r\n * it, use {@link #translation(float, float, float)}.\r\n * \r\n * @see #translation(float, float, float)\r\n * \r\n * @param x\r\n * the offset to translate in x\r\n * @param y\r\n * the offset to translate in y\r\n * @param z\r\n * the offset to translate in z\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f translate(float x, float y, float z, Matrix4f dest) {\r\n // translation matrix elements:\r\n // m00, m11, m22, m33 = 1\r\n // m30 = x, m31 = y, m32 = z\r\n // all others = 0\r\n dest.m00 = m00;\r\n dest.m01 = m01;\r\n dest.m02 = m02;\r\n dest.m03 = m03;\r\n dest.m10 = m10;\r\n dest.m11 = m11;\r\n dest.m12 = m12;\r\n dest.m13 = m13;\r\n dest.m20 = m20;\r\n dest.m21 = m21;\r\n dest.m22 = m22;\r\n dest.m23 = m23;\r\n dest.m30 = m00 * x + m10 * y + m20 * z + m30;\r\n dest.m31 = m01 * x + m11 * y + m21 * z + m31;\r\n dest.m32 = m02 * x + m12 * y + m22 * z + m32;\r\n dest.m33 = m03 * x + m13 * y + m23 * z + m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply a translation to this matrix by translating by the given number of\r\n * units in x, y and z.\r\n *
\r\n * If M
is this
matrix and T
the translation\r\n * matrix, then the new matrix will be M * T
. So when\r\n * transforming a vector v
with the new matrix by using\r\n * M * T * v
, the translation will be applied first!\r\n *
\r\n * In order to set the matrix to a translation transformation without post-multiplying\r\n * it, use {@link #translation(float, float, float)}.\r\n * \r\n * @see #translation(float, float, float)\r\n * \r\n * @param x\r\n * the offset to translate in x\r\n * @param y\r\n * the offset to translate in y\r\n * @param z\r\n * the offset to translate in z\r\n * @return this\r\n */\r\n public Matrix4f translate(float x, float y, float z) {\r\n Matrix4f c = this;\r\n // translation matrix elements:\r\n // m00, m11, m22, m33 = 1\r\n // m30 = x, m31 = y, m32 = z\r\n // all others = 0\r\n c.m30 = c.m00 * x + c.m10 * y + c.m20 * z + c.m30;\r\n c.m31 = c.m01 * x + c.m11 * y + c.m21 * z + c.m31;\r\n c.m32 = c.m02 * x + c.m12 * y + c.m22 * z + c.m32;\r\n c.m33 = c.m03 * x + c.m13 * y + c.m23 * z + c.m33;\r\n return this;\r\n }\r\n\r\n /**\r\n * Pre-multiply a translation to this matrix by translating by the given number of\r\n * units in x, y and z.\r\n *
\r\n * If M
is this
matrix and T
the translation\r\n * matrix, then the new matrix will be T * M
. So when\r\n * transforming a vector v
with the new matrix by using\r\n * T * M * v
, the translation will be applied last!\r\n *
\r\n * In order to set the matrix to a translation transformation without pre-multiplying\r\n * it, use {@link #translation(Vector3f)}.\r\n * \r\n * @see #translation(Vector3f)\r\n * \r\n * @param offset\r\n * the number of units in x, y and z by which to translate\r\n * @return this\r\n */\r\n public Matrix4f translateLocal(Vector3f offset) {\r\n return translateLocal(offset.x, offset.y, offset.z);\r\n }\r\n\r\n /**\r\n * Pre-multiply a translation to this matrix by translating by the given number of\r\n * units in x, y and z and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and T
the translation\r\n * matrix, then the new matrix will be T * M
. So when\r\n * transforming a vector v
with the new matrix by using\r\n * T * M * v
, the translation will be applied last!\r\n *
\r\n * In order to set the matrix to a translation transformation without pre-multiplying\r\n * it, use {@link #translation(Vector3f)}.\r\n * \r\n * @see #translation(Vector3f)\r\n * \r\n * @param offset\r\n * the number of units in x, y and z by which to translate\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f translateLocal(Vector3f offset, Matrix4f dest) {\r\n return translateLocal(offset.x, offset.y, offset.z, dest);\r\n }\r\n\r\n /**\r\n * Pre-multiply a translation to this matrix by translating by the given number of\r\n * units in x, y and z and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and T
the translation\r\n * matrix, then the new matrix will be T * M
. So when\r\n * transforming a vector v
with the new matrix by using\r\n * T * M * v
, the translation will be applied last!\r\n *
\r\n * In order to set the matrix to a translation transformation without pre-multiplying\r\n * it, use {@link #translation(float, float, float)}.\r\n * \r\n * @see #translation(float, float, float)\r\n * \r\n * @param x\r\n * the offset to translate in x\r\n * @param y\r\n * the offset to translate in y\r\n * @param z\r\n * the offset to translate in z\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f translateLocal(float x, float y, float z, Matrix4f dest) {\r\n float nm00 = m00 + x * m03;\r\n float nm01 = m01 + y * m03;\r\n float nm02 = m02 + z * m03;\r\n float nm03 = m03;\r\n float nm10 = m10 + x * m13;\r\n float nm11 = m11 + y * m13;\r\n float nm12 = m12 + z * m13;\r\n float nm13 = m13;\r\n float nm20 = m20 + x * m23;\r\n float nm21 = m21 + y * m23;\r\n float nm22 = m22 + z * m23;\r\n float nm23 = m23;\r\n float nm30 = m30 + x * m33;\r\n float nm31 = m31 + y * m33;\r\n float nm32 = m32 + z * m33;\r\n float nm33 = m33;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Pre-multiply a translation to this matrix by translating by the given number of\r\n * units in x, y and z.\r\n *
\r\n * If M
is this
matrix and T
the translation\r\n * matrix, then the new matrix will be T * M
. So when\r\n * transforming a vector v
with the new matrix by using\r\n * T * M * v
, the translation will be applied last!\r\n *
\r\n * In order to set the matrix to a translation transformation without pre-multiplying\r\n * it, use {@link #translation(float, float, float)}.\r\n * \r\n * @see #translation(float, float, float)\r\n * \r\n * @param x\r\n * the offset to translate in x\r\n * @param y\r\n * the offset to translate in y\r\n * @param z\r\n * the offset to translate in z\r\n * @return this\r\n */\r\n public Matrix4f translateLocal(float x, float y, float z) {\r\n return translateLocal(x, y, z, this);\r\n }\r\n\r\n public void writeExternal(ObjectOutput out) throws IOException {\r\n out.writeFloat(m00);\r\n out.writeFloat(m01);\r\n out.writeFloat(m02);\r\n out.writeFloat(m03);\r\n out.writeFloat(m10);\r\n out.writeFloat(m11);\r\n out.writeFloat(m12);\r\n out.writeFloat(m13);\r\n out.writeFloat(m20);\r\n out.writeFloat(m21);\r\n out.writeFloat(m22);\r\n out.writeFloat(m23);\r\n out.writeFloat(m30);\r\n out.writeFloat(m31);\r\n out.writeFloat(m32);\r\n out.writeFloat(m33);\r\n }\r\n\r\n public void readExternal(ObjectInput in) throws IOException,\r\n ClassNotFoundException {\r\n m00 = in.readFloat();\r\n m01 = in.readFloat();\r\n m02 = in.readFloat();\r\n m03 = in.readFloat();\r\n m10 = in.readFloat();\r\n m11 = in.readFloat();\r\n m12 = in.readFloat();\r\n m13 = in.readFloat();\r\n m20 = in.readFloat();\r\n m21 = in.readFloat();\r\n m22 = in.readFloat();\r\n m23 = in.readFloat();\r\n m30 = in.readFloat();\r\n m31 = in.readFloat();\r\n m32 = in.readFloat();\r\n m33 = in.readFloat();\r\n }\r\n\r\n /**\r\n * Apply an orthographic projection transformation using the given NDC z range to this matrix and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and O
the orthographic projection matrix,\r\n * then the new matrix will be M * O
. So when transforming a\r\n * vector v
with the new matrix by using M * O * v
, the\r\n * orthographic projection transformation will be applied first!\r\n *
\r\n * In order to set the matrix to an orthographic projection without post-multiplying it,\r\n * use {@link #setOrtho(float, float, float, float, float, float, boolean) setOrtho()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setOrtho(float, float, float, float, float, float, boolean)\r\n * \r\n * @param left\r\n * the distance from the center to the left frustum edge\r\n * @param right\r\n * the distance from the center to the right frustum edge\r\n * @param bottom\r\n * the distance from the center to the bottom frustum edge\r\n * @param top\r\n * the distance from the center to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance\r\n * @param zFar\r\n * far clipping plane distance\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f ortho(float left, float right, float bottom, float top, float zNear, float zFar, boolean zZeroToOne, Matrix4f dest) {\r\n // calculate right matrix elements\r\n float rm00 = 2.0f / (right - left);\r\n float rm11 = 2.0f / (top - bottom);\r\n float rm22 = (zZeroToOne ? 1.0f : 2.0f) / (zNear - zFar);\r\n float rm30 = (left + right) / (left - right);\r\n float rm31 = (top + bottom) / (bottom - top);\r\n float rm32 = (zZeroToOne ? zNear : (zFar + zNear)) / (zNear - zFar);\r\n\r\n // perform optimized multiplication\r\n // compute the last column first, because other columns do not depend on it\r\n dest.m30 = m00 * rm30 + m10 * rm31 + m20 * rm32 + m30;\r\n dest.m31 = m01 * rm30 + m11 * rm31 + m21 * rm32 + m31;\r\n dest.m32 = m02 * rm30 + m12 * rm31 + m22 * rm32 + m32;\r\n dest.m33 = m03 * rm30 + m13 * rm31 + m23 * rm32 + m33;\r\n dest.m00 = m00 * rm00;\r\n dest.m01 = m01 * rm00;\r\n dest.m02 = m02 * rm00;\r\n dest.m03 = m03 * rm00;\r\n dest.m10 = m10 * rm11;\r\n dest.m11 = m11 * rm11;\r\n dest.m12 = m12 * rm11;\r\n dest.m13 = m13 * rm11;\r\n dest.m20 = m20 * rm22;\r\n dest.m21 = m21 * rm22;\r\n dest.m22 = m22 * rm22;\r\n dest.m23 = m23 * rm22;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply an orthographic projection transformation using OpenGL's NDC z range of [-1..+1] to this matrix and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and O
the orthographic projection matrix,\r\n * then the new matrix will be M * O
. So when transforming a\r\n * vector v
with the new matrix by using M * O * v
, the\r\n * orthographic projection transformation will be applied first!\r\n *
\r\n * In order to set the matrix to an orthographic projection without post-multiplying it,\r\n * use {@link #setOrtho(float, float, float, float, float, float) setOrtho()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setOrtho(float, float, float, float, float, float)\r\n * \r\n * @param left\r\n * the distance from the center to the left frustum edge\r\n * @param right\r\n * the distance from the center to the right frustum edge\r\n * @param bottom\r\n * the distance from the center to the bottom frustum edge\r\n * @param top\r\n * the distance from the center to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance\r\n * @param zFar\r\n * far clipping plane distance\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f ortho(float left, float right, float bottom, float top, float zNear, float zFar, Matrix4f dest) {\r\n return ortho(left, right, bottom, top, zNear, zFar, false, dest);\r\n }\r\n\r\n /**\r\n * Apply an orthographic projection transformation using the given NDC z range to this matrix.\r\n *
\r\n * If M
is this
matrix and O
the orthographic projection matrix,\r\n * then the new matrix will be M * O
. So when transforming a\r\n * vector v
with the new matrix by using M * O * v
, the\r\n * orthographic projection transformation will be applied first!\r\n *
\r\n * In order to set the matrix to an orthographic projection without post-multiplying it,\r\n * use {@link #setOrtho(float, float, float, float, float, float, boolean) setOrtho()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setOrtho(float, float, float, float, float, float, boolean)\r\n * \r\n * @param left\r\n * the distance from the center to the left frustum edge\r\n * @param right\r\n * the distance from the center to the right frustum edge\r\n * @param bottom\r\n * the distance from the center to the bottom frustum edge\r\n * @param top\r\n * the distance from the center to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance\r\n * @param zFar\r\n * far clipping plane distance\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return this\r\n */\r\n public Matrix4f ortho(float left, float right, float bottom, float top, float zNear, float zFar, boolean zZeroToOne) {\r\n return ortho(left, right, bottom, top, zNear, zFar, zZeroToOne, this);\r\n }\r\n\r\n /**\r\n * Apply an orthographic projection transformation using OpenGL's NDC z range of [-1..+1] to this matrix.\r\n *
\r\n * If M
is this
matrix and O
the orthographic projection matrix,\r\n * then the new matrix will be M * O
. So when transforming a\r\n * vector v
with the new matrix by using M * O * v
, the\r\n * orthographic projection transformation will be applied first!\r\n *
\r\n * In order to set the matrix to an orthographic projection without post-multiplying it,\r\n * use {@link #setOrtho(float, float, float, float, float, float) setOrtho()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setOrtho(float, float, float, float, float, float)\r\n * \r\n * @param left\r\n * the distance from the center to the left frustum edge\r\n * @param right\r\n * the distance from the center to the right frustum edge\r\n * @param bottom\r\n * the distance from the center to the bottom frustum edge\r\n * @param top\r\n * the distance from the center to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance\r\n * @param zFar\r\n * far clipping plane distance\r\n * @return this\r\n */\r\n public Matrix4f ortho(float left, float right, float bottom, float top, float zNear, float zFar) {\r\n return ortho(left, right, bottom, top, zNear, zFar, false);\r\n }\r\n\r\n /**\r\n * Set this matrix to be an orthographic projection transformation using the given NDC z range.\r\n *
\r\n * In order to apply the orthographic projection to an already existing transformation,\r\n * use {@link #ortho(float, float, float, float, float, float, boolean) ortho()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #ortho(float, float, float, float, float, float, boolean)\r\n * \r\n * @param left\r\n * the distance from the center to the left frustum edge\r\n * @param right\r\n * the distance from the center to the right frustum edge\r\n * @param bottom\r\n * the distance from the center to the bottom frustum edge\r\n * @param top\r\n * the distance from the center to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance\r\n * @param zFar\r\n * far clipping plane distance\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return this\r\n */\r\n public Matrix4f setOrtho(float left, float right, float bottom, float top, float zNear, float zFar, boolean zZeroToOne) {\r\n m00 = 2.0f / (right - left);\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = 2.0f / (top - bottom);\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = 0.0f;\r\n m22 = (zZeroToOne ? 1.0f : 2.0f) / (zNear - zFar);\r\n m23 = 0.0f;\r\n m30 = (right + left) / (left - right);\r\n m31 = (top + bottom) / (bottom - top);\r\n m32 = (zZeroToOne ? zNear : (zFar + zNear)) / (zNear - zFar);\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be an orthographic projection transformation using OpenGL's NDC z range of [-1..+1].\r\n *
\r\n * In order to apply the orthographic projection to an already existing transformation,\r\n * use {@link #ortho(float, float, float, float, float, float) ortho()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #ortho(float, float, float, float, float, float)\r\n * \r\n * @param left\r\n * the distance from the center to the left frustum edge\r\n * @param right\r\n * the distance from the center to the right frustum edge\r\n * @param bottom\r\n * the distance from the center to the bottom frustum edge\r\n * @param top\r\n * the distance from the center to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance\r\n * @param zFar\r\n * far clipping plane distance\r\n * @return this\r\n */\r\n public Matrix4f setOrtho(float left, float right, float bottom, float top, float zNear, float zFar) {\r\n return setOrtho(left, right, bottom, top, zNear, zFar, false);\r\n }\r\n\r\n /**\r\n * Apply a symmetric orthographic projection transformation using the given NDC z range to this matrix and store the result in dest
.\r\n *
\r\n * This method is equivalent to calling {@link #ortho(float, float, float, float, float, float, boolean, Matrix4f) ortho()} with\r\n * left=-width/2
, right=+width/2
, bottom=-height/2
and top=+height/2
.\r\n *
\r\n * If M
is this
matrix and O
the orthographic projection matrix,\r\n * then the new matrix will be M * O
. So when transforming a\r\n * vector v
with the new matrix by using M * O * v
, the\r\n * orthographic projection transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a symmetric orthographic projection without post-multiplying it,\r\n * use {@link #setOrthoSymmetric(float, float, float, float, boolean) setOrthoSymmetric()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setOrthoSymmetric(float, float, float, float, boolean)\r\n * \r\n * @param width\r\n * the distance between the right and left frustum edges\r\n * @param height\r\n * the distance between the top and bottom frustum edges\r\n * @param zNear\r\n * near clipping plane distance\r\n * @param zFar\r\n * far clipping plane distance\r\n * @param dest\r\n * will hold the result\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return dest\r\n */\r\n public Matrix4f orthoSymmetric(float width, float height, float zNear, float zFar, boolean zZeroToOne, Matrix4f dest) {\r\n // calculate right matrix elements\r\n float rm00 = 2.0f / width;\r\n float rm11 = 2.0f / height;\r\n float rm22 = (zZeroToOne ? 1.0f : 2.0f) / (zNear - zFar);\r\n float rm32 = (zZeroToOne ? zNear : (zFar + zNear)) / (zNear - zFar);\r\n\r\n // perform optimized multiplication\r\n // compute the last column first, because other columns do not depend on it\r\n dest.m30 = m20 * rm32 + m30;\r\n dest.m31 = m21 * rm32 + m31;\r\n dest.m32 = m22 * rm32 + m32;\r\n dest.m33 = m23 * rm32 + m33;\r\n dest.m00 = m00 * rm00;\r\n dest.m01 = m01 * rm00;\r\n dest.m02 = m02 * rm00;\r\n dest.m03 = m03 * rm00;\r\n dest.m10 = m10 * rm11;\r\n dest.m11 = m11 * rm11;\r\n dest.m12 = m12 * rm11;\r\n dest.m13 = m13 * rm11;\r\n dest.m20 = m20 * rm22;\r\n dest.m21 = m21 * rm22;\r\n dest.m22 = m22 * rm22;\r\n dest.m23 = m23 * rm22;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply a symmetric orthographic projection transformation using OpenGL's NDC z range of [-1..+1] to this matrix and store the result in dest
.\r\n *
\r\n * This method is equivalent to calling {@link #ortho(float, float, float, float, float, float, Matrix4f) ortho()} with\r\n * left=-width/2
, right=+width/2
, bottom=-height/2
and top=+height/2
.\r\n *
\r\n * If M
is this
matrix and O
the orthographic projection matrix,\r\n * then the new matrix will be M * O
. So when transforming a\r\n * vector v
with the new matrix by using M * O * v
, the\r\n * orthographic projection transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a symmetric orthographic projection without post-multiplying it,\r\n * use {@link #setOrthoSymmetric(float, float, float, float) setOrthoSymmetric()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setOrthoSymmetric(float, float, float, float)\r\n * \r\n * @param width\r\n * the distance between the right and left frustum edges\r\n * @param height\r\n * the distance between the top and bottom frustum edges\r\n * @param zNear\r\n * near clipping plane distance\r\n * @param zFar\r\n * far clipping plane distance\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f orthoSymmetric(float width, float height, float zNear, float zFar, Matrix4f dest) {\r\n return orthoSymmetric(width, height, zNear, zFar, false, dest);\r\n }\r\n\r\n /**\r\n * Apply a symmetric orthographic projection transformation using the given NDC z range to this matrix.\r\n *
\r\n * This method is equivalent to calling {@link #ortho(float, float, float, float, float, float, boolean) ortho()} with\r\n * left=-width/2
, right=+width/2
, bottom=-height/2
and top=+height/2
.\r\n *
\r\n * If M
is this
matrix and O
the orthographic projection matrix,\r\n * then the new matrix will be M * O
. So when transforming a\r\n * vector v
with the new matrix by using M * O * v
, the\r\n * orthographic projection transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a symmetric orthographic projection without post-multiplying it,\r\n * use {@link #setOrthoSymmetric(float, float, float, float, boolean) setOrthoSymmetric()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setOrthoSymmetric(float, float, float, float, boolean)\r\n * \r\n * @param width\r\n * the distance between the right and left frustum edges\r\n * @param height\r\n * the distance between the top and bottom frustum edges\r\n * @param zNear\r\n * near clipping plane distance\r\n * @param zFar\r\n * far clipping plane distance\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return this\r\n */\r\n public Matrix4f orthoSymmetric(float width, float height, float zNear, float zFar, boolean zZeroToOne) {\r\n return orthoSymmetric(width, height, zNear, zFar, zZeroToOne, this);\r\n }\r\n\r\n /**\r\n * Apply a symmetric orthographic projection transformation using OpenGL's NDC z range of [-1..+1] to this matrix.\r\n *
\r\n * This method is equivalent to calling {@link #ortho(float, float, float, float, float, float) ortho()} with\r\n * left=-width/2
, right=+width/2
, bottom=-height/2
and top=+height/2
.\r\n *
\r\n * If M
is this
matrix and O
the orthographic projection matrix,\r\n * then the new matrix will be M * O
. So when transforming a\r\n * vector v
with the new matrix by using M * O * v
, the\r\n * orthographic projection transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a symmetric orthographic projection without post-multiplying it,\r\n * use {@link #setOrthoSymmetric(float, float, float, float) setOrthoSymmetric()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setOrthoSymmetric(float, float, float, float)\r\n * \r\n * @param width\r\n * the distance between the right and left frustum edges\r\n * @param height\r\n * the distance between the top and bottom frustum edges\r\n * @param zNear\r\n * near clipping plane distance\r\n * @param zFar\r\n * far clipping plane distance\r\n * @return this\r\n */\r\n public Matrix4f orthoSymmetric(float width, float height, float zNear, float zFar) {\r\n return orthoSymmetric(width, height, zNear, zFar, false, this);\r\n }\r\n\r\n /**\r\n * Set this matrix to be a symmetric orthographic projection transformation using the given NDC z range.\r\n *
\r\n * This method is equivalent to calling {@link #setOrtho(float, float, float, float, float, float, boolean) setOrtho()} with\r\n * left=-width/2
, right=+width/2
, bottom=-height/2
and top=+height/2
.\r\n *
\r\n * In order to apply the symmetric orthographic projection to an already existing transformation,\r\n * use {@link #orthoSymmetric(float, float, float, float, boolean) orthoSymmetric()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #orthoSymmetric(float, float, float, float, boolean)\r\n * \r\n * @param width\r\n * the distance between the right and left frustum edges\r\n * @param height\r\n * the distance between the top and bottom frustum edges\r\n * @param zNear\r\n * near clipping plane distance\r\n * @param zFar\r\n * far clipping plane distance\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return this\r\n */\r\n public Matrix4f setOrthoSymmetric(float width, float height, float zNear, float zFar, boolean zZeroToOne) {\r\n m00 = 2.0f / width;\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = 2.0f / height;\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = 0.0f;\r\n m22 = (zZeroToOne ? 1.0f : 2.0f) / (zNear - zFar);\r\n m23 = 0.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = (zZeroToOne ? zNear : (zFar + zNear)) / (zNear - zFar);\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be a symmetric orthographic projection transformation using OpenGL's NDC z range of [-1..+1].\r\n *
\r\n * This method is equivalent to calling {@link #setOrtho(float, float, float, float, float, float) setOrtho()} with\r\n * left=-width/2
, right=+width/2
, bottom=-height/2
and top=+height/2
.\r\n *
\r\n * In order to apply the symmetric orthographic projection to an already existing transformation,\r\n * use {@link #orthoSymmetric(float, float, float, float) orthoSymmetric()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #orthoSymmetric(float, float, float, float)\r\n * \r\n * @param width\r\n * the distance between the right and left frustum edges\r\n * @param height\r\n * the distance between the top and bottom frustum edges\r\n * @param zNear\r\n * near clipping plane distance\r\n * @param zFar\r\n * far clipping plane distance\r\n * @return this\r\n */\r\n public Matrix4f setOrthoSymmetric(float width, float height, float zNear, float zFar) {\r\n return setOrthoSymmetric(width, height, zNear, zFar, false);\r\n }\r\n\r\n /**\r\n * Apply an orthographic projection transformation to this matrix and store the result in dest
.\r\n *
\r\n * This method is equivalent to calling {@link #ortho(float, float, float, float, float, float, Matrix4f) ortho()} with\r\n * zNear=-1
and zFar=+1
.\r\n *
\r\n * If M
is this
matrix and O
the orthographic projection matrix,\r\n * then the new matrix will be M * O
. So when transforming a\r\n * vector v
with the new matrix by using M * O * v
, the\r\n * orthographic projection transformation will be applied first!\r\n *
\r\n * In order to set the matrix to an orthographic projection without post-multiplying it,\r\n * use {@link #setOrtho2D(float, float, float, float) setOrtho()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #ortho(float, float, float, float, float, float, Matrix4f)\r\n * @see #setOrtho2D(float, float, float, float)\r\n * \r\n * @param left\r\n * the distance from the center to the left frustum edge\r\n * @param right\r\n * the distance from the center to the right frustum edge\r\n * @param bottom\r\n * the distance from the center to the bottom frustum edge\r\n * @param top\r\n * the distance from the center to the top frustum edge\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f ortho2D(float left, float right, float bottom, float top, Matrix4f dest) {\r\n // calculate right matrix elements\r\n float rm00 = 2.0f / (right - left);\r\n float rm11 = 2.0f / (top - bottom);\r\n float rm30 = -(right + left) / (right - left);\r\n float rm31 = -(top + bottom) / (top - bottom);\r\n\r\n // perform optimized multiplication\r\n // compute the last column first, because other columns do not depend on it\r\n dest.m30 = m00 * rm30 + m10 * rm31 + m30;\r\n dest.m31 = m01 * rm30 + m11 * rm31 + m31;\r\n dest.m32 = m02 * rm30 + m12 * rm31 + m32;\r\n dest.m33 = m03 * rm30 + m13 * rm31 + m33;\r\n dest.m00 = m00 * rm00;\r\n dest.m01 = m01 * rm00;\r\n dest.m02 = m02 * rm00;\r\n dest.m03 = m03 * rm00;\r\n dest.m10 = m10 * rm11;\r\n dest.m11 = m11 * rm11;\r\n dest.m12 = m12 * rm11;\r\n dest.m13 = m13 * rm11;\r\n dest.m20 = -m20;\r\n dest.m21 = -m21;\r\n dest.m22 = -m22;\r\n dest.m23 = -m23;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply an orthographic projection transformation to this matrix.\r\n *
\r\n * This method is equivalent to calling {@link #ortho(float, float, float, float, float, float) ortho()} with\r\n * zNear=-1
and zFar=+1
.\r\n *
\r\n * If M
is this
matrix and O
the orthographic projection matrix,\r\n * then the new matrix will be M * O
. So when transforming a\r\n * vector v
with the new matrix by using M * O * v
, the\r\n * orthographic projection transformation will be applied first!\r\n *
\r\n * In order to set the matrix to an orthographic projection without post-multiplying it,\r\n * use {@link #setOrtho2D(float, float, float, float) setOrtho2D()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #ortho(float, float, float, float, float, float)\r\n * @see #setOrtho2D(float, float, float, float)\r\n * \r\n * @param left\r\n * the distance from the center to the left frustum edge\r\n * @param right\r\n * the distance from the center to the right frustum edge\r\n * @param bottom\r\n * the distance from the center to the bottom frustum edge\r\n * @param top\r\n * the distance from the center to the top frustum edge\r\n * @return this\r\n */\r\n public Matrix4f ortho2D(float left, float right, float bottom, float top) {\r\n return ortho2D(left, right, bottom, top, this);\r\n }\r\n\r\n /**\r\n * Set this matrix to be an orthographic projection transformation.\r\n *
\r\n * This method is equivalent to calling {@link #setOrtho(float, float, float, float, float, float) setOrtho()} with\r\n * zNear=-1
and zFar=+1
.\r\n *
\r\n * In order to apply the orthographic projection to an already existing transformation,\r\n * use {@link #ortho2D(float, float, float, float) ortho2D()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setOrtho(float, float, float, float, float, float)\r\n * @see #ortho2D(float, float, float, float)\r\n * \r\n * @param left\r\n * the distance from the center to the left frustum edge\r\n * @param right\r\n * the distance from the center to the right frustum edge\r\n * @param bottom\r\n * the distance from the center to the bottom frustum edge\r\n * @param top\r\n * the distance from the center to the top frustum edge\r\n * @return this\r\n */\r\n public Matrix4f setOrtho2D(float left, float right, float bottom, float top) {\r\n m00 = 2.0f / (right - left);\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = 2.0f / (top - bottom);\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = 0.0f;\r\n m22 = -1.0f;\r\n m23 = 0.0f;\r\n m30 = -(right + left) / (right - left);\r\n m31 = -(top + bottom) / (top - bottom);\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Apply a rotation transformation to this matrix to make -z
point along dir
. \r\n *
\r\n * If M
is this
matrix and L
the lookalong rotation matrix,\r\n * then the new matrix will be M * L
. So when transforming a\r\n * vector v
with the new matrix by using M * L * v
, the\r\n * lookalong rotation transformation will be applied first!\r\n *
\r\n * This is equivalent to calling\r\n * {@link #lookAt(Vector3f, Vector3f, Vector3f) lookAt}\r\n * with eye = (0, 0, 0)
and center = dir
.\r\n *
\r\n * In order to set the matrix to a lookalong transformation without post-multiplying it,\r\n * use {@link #setLookAlong(Vector3f, Vector3f) setLookAlong()}.\r\n * \r\n * @see #lookAlong(float, float, float, float, float, float)\r\n * @see #lookAt(Vector3f, Vector3f, Vector3f)\r\n * @see #setLookAlong(Vector3f, Vector3f)\r\n * \r\n * @param dir\r\n * the direction in space to look along\r\n * @param up\r\n * the direction of 'up'\r\n * @return this\r\n */\r\n public Matrix4f lookAlong(Vector3f dir, Vector3f up) {\r\n return lookAlong(dir.x, dir.y, dir.z, up.x, up.y, up.z, this);\r\n }\r\n\r\n /**\r\n * Apply a rotation transformation to this matrix to make -z
point along dir
\r\n * and store the result in dest
. \r\n *
\r\n * If M
is this
matrix and L
the lookalong rotation matrix,\r\n * then the new matrix will be M * L
. So when transforming a\r\n * vector v
with the new matrix by using M * L * v
, the\r\n * lookalong rotation transformation will be applied first!\r\n *
\r\n * This is equivalent to calling\r\n * {@link #lookAt(Vector3f, Vector3f, Vector3f) lookAt}\r\n * with eye = (0, 0, 0)
and center = dir
.\r\n *
\r\n * In order to set the matrix to a lookalong transformation without post-multiplying it,\r\n * use {@link #setLookAlong(Vector3f, Vector3f) setLookAlong()}.\r\n * \r\n * @see #lookAlong(float, float, float, float, float, float)\r\n * @see #lookAt(Vector3f, Vector3f, Vector3f)\r\n * @see #setLookAlong(Vector3f, Vector3f)\r\n * \r\n * @param dir\r\n * the direction in space to look along\r\n * @param up\r\n * the direction of 'up'\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f lookAlong(Vector3f dir, Vector3f up, Matrix4f dest) {\r\n return lookAlong(dir.x, dir.y, dir.z, up.x, up.y, up.z, dest);\r\n }\r\n\r\n /**\r\n * Apply a rotation transformation to this matrix to make -z
point along dir
\r\n * and store the result in dest
. \r\n *
\r\n * If M
is this
matrix and L
the lookalong rotation matrix,\r\n * then the new matrix will be M * L
. So when transforming a\r\n * vector v
with the new matrix by using M * L * v
, the\r\n * lookalong rotation transformation will be applied first!\r\n *
\r\n * This is equivalent to calling\r\n * {@link #lookAt(float, float, float, float, float, float, float, float, float) lookAt()}\r\n * with eye = (0, 0, 0)
and center = dir
.\r\n *
\r\n * In order to set the matrix to a lookalong transformation without post-multiplying it,\r\n * use {@link #setLookAlong(float, float, float, float, float, float) setLookAlong()}\r\n * \r\n * @see #lookAt(float, float, float, float, float, float, float, float, float)\r\n * @see #setLookAlong(float, float, float, float, float, float)\r\n * \r\n * @param dirX\r\n * the x-coordinate of the direction to look along\r\n * @param dirY\r\n * the y-coordinate of the direction to look along\r\n * @param dirZ\r\n * the z-coordinate of the direction to look along\r\n * @param upX\r\n * the x-coordinate of the up vector\r\n * @param upY\r\n * the y-coordinate of the up vector\r\n * @param upZ\r\n * the z-coordinate of the up vector\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f lookAlong(float dirX, float dirY, float dirZ,\r\n float upX, float upY, float upZ, Matrix4f dest) {\r\n // Normalize direction\r\n float invDirLength = 1.0f / (float) Math.sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);\r\n float dirnX = dirX * invDirLength;\r\n float dirnY = dirY * invDirLength;\r\n float dirnZ = dirZ * invDirLength;\r\n // right = direction x up\r\n float rightX, rightY, rightZ;\r\n rightX = dirnY * upZ - dirnZ * upY;\r\n rightY = dirnZ * upX - dirnX * upZ;\r\n rightZ = dirnX * upY - dirnY * upX;\r\n // normalize right\r\n float invRightLength = 1.0f / (float) Math.sqrt(rightX * rightX + rightY * rightY + rightZ * rightZ);\r\n rightX *= invRightLength;\r\n rightY *= invRightLength;\r\n rightZ *= invRightLength;\r\n // up = right x direction\r\n float upnX = rightY * dirnZ - rightZ * dirnY;\r\n float upnY = rightZ * dirnX - rightX * dirnZ;\r\n float upnZ = rightX * dirnY - rightY * dirnX;\r\n\r\n // calculate right matrix elements\r\n float rm00 = rightX;\r\n float rm01 = upnX;\r\n float rm02 = -dirnX;\r\n float rm10 = rightY;\r\n float rm11 = upnY;\r\n float rm12 = -dirnY;\r\n float rm20 = rightZ;\r\n float rm21 = upnZ;\r\n float rm22 = -dirnZ;\r\n\r\n // perform optimized matrix multiplication\r\n // introduce temporaries for dependent results\r\n float nm00 = m00 * rm00 + m10 * rm01 + m20 * rm02;\r\n float nm01 = m01 * rm00 + m11 * rm01 + m21 * rm02;\r\n float nm02 = m02 * rm00 + m12 * rm01 + m22 * rm02;\r\n float nm03 = m03 * rm00 + m13 * rm01 + m23 * rm02;\r\n float nm10 = m00 * rm10 + m10 * rm11 + m20 * rm12;\r\n float nm11 = m01 * rm10 + m11 * rm11 + m21 * rm12;\r\n float nm12 = m02 * rm10 + m12 * rm11 + m22 * rm12;\r\n float nm13 = m03 * rm10 + m13 * rm11 + m23 * rm12;\r\n dest.m20 = m00 * rm20 + m10 * rm21 + m20 * rm22;\r\n dest.m21 = m01 * rm20 + m11 * rm21 + m21 * rm22;\r\n dest.m22 = m02 * rm20 + m12 * rm21 + m22 * rm22;\r\n dest.m23 = m03 * rm20 + m13 * rm21 + m23 * rm22;\r\n // set the rest of the matrix elements\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply a rotation transformation to this matrix to make -z
point along dir
. \r\n *
\r\n * If M
is this
matrix and L
the lookalong rotation matrix,\r\n * then the new matrix will be M * L
. So when transforming a\r\n * vector v
with the new matrix by using M * L * v
, the\r\n * lookalong rotation transformation will be applied first!\r\n *
\r\n * This is equivalent to calling\r\n * {@link #lookAt(float, float, float, float, float, float, float, float, float) lookAt()}\r\n * with eye = (0, 0, 0)
and center = dir
.\r\n *
\r\n * In order to set the matrix to a lookalong transformation without post-multiplying it,\r\n * use {@link #setLookAlong(float, float, float, float, float, float) setLookAlong()}\r\n * \r\n * @see #lookAt(float, float, float, float, float, float, float, float, float)\r\n * @see #setLookAlong(float, float, float, float, float, float)\r\n * \r\n * @param dirX\r\n * the x-coordinate of the direction to look along\r\n * @param dirY\r\n * the y-coordinate of the direction to look along\r\n * @param dirZ\r\n * the z-coordinate of the direction to look along\r\n * @param upX\r\n * the x-coordinate of the up vector\r\n * @param upY\r\n * the y-coordinate of the up vector\r\n * @param upZ\r\n * the z-coordinate of the up vector\r\n * @return this\r\n */\r\n public Matrix4f lookAlong(float dirX, float dirY, float dirZ,\r\n float upX, float upY, float upZ) {\r\n return lookAlong(dirX, dirY, dirZ, upX, upY, upZ, this);\r\n }\r\n\r\n /**\r\n * Set this matrix to a rotation transformation to make -z
\r\n * point along dir
.\r\n *
\r\n * This is equivalent to calling\r\n * {@link #setLookAt(Vector3f, Vector3f, Vector3f) setLookAt()} \r\n * with eye = (0, 0, 0)
and center = dir
.\r\n *
\r\n * In order to apply the lookalong transformation to any previous existing transformation,\r\n * use {@link #lookAlong(Vector3f, Vector3f)}.\r\n * \r\n * @see #setLookAlong(Vector3f, Vector3f)\r\n * @see #lookAlong(Vector3f, Vector3f)\r\n * \r\n * @param dir\r\n * the direction in space to look along\r\n * @param up\r\n * the direction of 'up'\r\n * @return this\r\n */\r\n public Matrix4f setLookAlong(Vector3f dir, Vector3f up) {\r\n return setLookAlong(dir.x, dir.y, dir.z, up.x, up.y, up.z);\r\n }\r\n\r\n /**\r\n * Set this matrix to a rotation transformation to make -z
\r\n * point along dir
.\r\n *
\r\n * This is equivalent to calling\r\n * {@link #setLookAt(float, float, float, float, float, float, float, float, float)\r\n * setLookAt()} with eye = (0, 0, 0)
and center = dir
.\r\n *
\r\n * In order to apply the lookalong transformation to any previous existing transformation,\r\n * use {@link #lookAlong(float, float, float, float, float, float) lookAlong()}\r\n * \r\n * @see #setLookAlong(float, float, float, float, float, float)\r\n * @see #lookAlong(float, float, float, float, float, float)\r\n * \r\n * @param dirX\r\n * the x-coordinate of the direction to look along\r\n * @param dirY\r\n * the y-coordinate of the direction to look along\r\n * @param dirZ\r\n * the z-coordinate of the direction to look along\r\n * @param upX\r\n * the x-coordinate of the up vector\r\n * @param upY\r\n * the y-coordinate of the up vector\r\n * @param upZ\r\n * the z-coordinate of the up vector\r\n * @return this\r\n */\r\n public Matrix4f setLookAlong(float dirX, float dirY, float dirZ,\r\n float upX, float upY, float upZ) {\r\n // Normalize direction\r\n float invDirLength = 1.0f / (float) Math.sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);\r\n float dirnX = dirX * invDirLength;\r\n float dirnY = dirY * invDirLength;\r\n float dirnZ = dirZ * invDirLength;\r\n // right = direction x up\r\n float rightX, rightY, rightZ;\r\n rightX = dirnY * upZ - dirnZ * upY;\r\n rightY = dirnZ * upX - dirnX * upZ;\r\n rightZ = dirnX * upY - dirnY * upX;\r\n // normalize right\r\n float invRightLength = 1.0f / (float) Math.sqrt(rightX * rightX + rightY * rightY + rightZ * rightZ);\r\n rightX *= invRightLength;\r\n rightY *= invRightLength;\r\n rightZ *= invRightLength;\r\n // up = right x direction\r\n float upnX = rightY * dirnZ - rightZ * dirnY;\r\n float upnY = rightZ * dirnX - rightX * dirnZ;\r\n float upnZ = rightX * dirnY - rightY * dirnX;\r\n\r\n m00 = rightX;\r\n m01 = upnX;\r\n m02 = -dirnX;\r\n m03 = 0.0f;\r\n m10 = rightY;\r\n m11 = upnY;\r\n m12 = -dirnY;\r\n m13 = 0.0f;\r\n m20 = rightZ;\r\n m21 = upnZ;\r\n m22 = -dirnZ;\r\n m23 = 0.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be a \"lookat\" transformation for a right-handed coordinate system, that aligns\r\n * -z
with center - eye
.\r\n *
\r\n * In order to not make use of vectors to specify eye
, center
and up
but use primitives,\r\n * like in the GLU function, use {@link #setLookAt(float, float, float, float, float, float, float, float, float) setLookAt()}\r\n * instead.\r\n *
\r\n * In order to apply the lookat transformation to a previous existing transformation,\r\n * use {@link #lookAt(Vector3f, Vector3f, Vector3f) lookAt()}.\r\n * \r\n * @see #setLookAt(float, float, float, float, float, float, float, float, float)\r\n * @see #lookAt(Vector3f, Vector3f, Vector3f)\r\n * \r\n * @param eye\r\n * the position of the camera\r\n * @param center\r\n * the point in space to look at\r\n * @param up\r\n * the direction of 'up'\r\n * @return this\r\n */\r\n public Matrix4f setLookAt(Vector3f eye, Vector3f center, Vector3f up) {\r\n return setLookAt(eye.x, eye.y, eye.z, center.x, center.y, center.z, up.x, up.y, up.z);\r\n }\r\n\r\n /**\r\n * Set this matrix to be a \"lookat\" transformation for a right-handed coordinate system, \r\n * that aligns -z
with center - eye
.\r\n *
\r\n * In order to apply the lookat transformation to a previous existing transformation,\r\n * use {@link #lookAt(float, float, float, float, float, float, float, float, float) lookAt}.\r\n * \r\n * @see #setLookAt(Vector3f, Vector3f, Vector3f)\r\n * @see #lookAt(float, float, float, float, float, float, float, float, float)\r\n * \r\n * @param eyeX\r\n * the x-coordinate of the eye/camera location\r\n * @param eyeY\r\n * the y-coordinate of the eye/camera location\r\n * @param eyeZ\r\n * the z-coordinate of the eye/camera location\r\n * @param centerX\r\n * the x-coordinate of the point to look at\r\n * @param centerY\r\n * the y-coordinate of the point to look at\r\n * @param centerZ\r\n * the z-coordinate of the point to look at\r\n * @param upX\r\n * the x-coordinate of the up vector\r\n * @param upY\r\n * the y-coordinate of the up vector\r\n * @param upZ\r\n * the z-coordinate of the up vector\r\n * @return this\r\n */\r\n public Matrix4f setLookAt(float eyeX, float eyeY, float eyeZ,\r\n float centerX, float centerY, float centerZ,\r\n float upX, float upY, float upZ) {\r\n // Compute direction from position to lookAt\r\n float dirX, dirY, dirZ;\r\n dirX = eyeX - centerX;\r\n dirY = eyeY - centerY;\r\n dirZ = eyeZ - centerZ;\r\n // Normalize direction\r\n float invDirLength = 1.0f / (float) Math.sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);\r\n dirX *= invDirLength;\r\n dirY *= invDirLength;\r\n dirZ *= invDirLength;\r\n // left = up x direction\r\n float leftX, leftY, leftZ;\r\n leftX = upY * dirZ - upZ * dirY;\r\n leftY = upZ * dirX - upX * dirZ;\r\n leftZ = upX * dirY - upY * dirX;\r\n // normalize left\r\n float invLeftLength = 1.0f / (float) Math.sqrt(leftX * leftX + leftY * leftY + leftZ * leftZ);\r\n leftX *= invLeftLength;\r\n leftY *= invLeftLength;\r\n leftZ *= invLeftLength;\r\n // up = direction x left\r\n float upnX = dirY * leftZ - dirZ * leftY;\r\n float upnY = dirZ * leftX - dirX * leftZ;\r\n float upnZ = dirX * leftY - dirY * leftX;\r\n\r\n m00 = leftX;\r\n m01 = upnX;\r\n m02 = dirX;\r\n m03 = 0.0f;\r\n m10 = leftY;\r\n m11 = upnY;\r\n m12 = dirY;\r\n m13 = 0.0f;\r\n m20 = leftZ;\r\n m21 = upnZ;\r\n m22 = dirZ;\r\n m23 = 0.0f;\r\n m30 = -(leftX * eyeX + leftY * eyeY + leftZ * eyeZ);\r\n m31 = -(upnX * eyeX + upnY * eyeY + upnZ * eyeZ);\r\n m32 = -(dirX * eyeX + dirY * eyeY + dirZ * eyeZ);\r\n m33 = 1.0f;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Apply a \"lookat\" transformation to this matrix for a right-handed coordinate system, \r\n * that aligns -z
with center - eye
and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and L
the lookat matrix,\r\n * then the new matrix will be M * L
. So when transforming a\r\n * vector v
with the new matrix by using M * L * v
,\r\n * the lookat transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a lookat transformation without post-multiplying it,\r\n * use {@link #setLookAt(Vector3f, Vector3f, Vector3f)}.\r\n * \r\n * @see #lookAt(float, float, float, float, float, float, float, float, float)\r\n * @see #setLookAlong(Vector3f, Vector3f)\r\n * \r\n * @param eye\r\n * the position of the camera\r\n * @param center\r\n * the point in space to look at\r\n * @param up\r\n * the direction of 'up'\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f lookAt(Vector3f eye, Vector3f center, Vector3f up, Matrix4f dest) {\r\n return lookAt(eye.x, eye.y, eye.z, center.x, center.y, center.z, up.x, up.y, up.z, dest);\r\n }\r\n\r\n /**\r\n * Apply a \"lookat\" transformation to this matrix for a right-handed coordinate system, \r\n * that aligns -z
with center - eye
.\r\n *
\r\n * If M
is this
matrix and L
the lookat matrix,\r\n * then the new matrix will be M * L
. So when transforming a\r\n * vector v
with the new matrix by using M * L * v
,\r\n * the lookat transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a lookat transformation without post-multiplying it,\r\n * use {@link #setLookAt(Vector3f, Vector3f, Vector3f)}.\r\n * \r\n * @see #lookAt(float, float, float, float, float, float, float, float, float)\r\n * @see #setLookAlong(Vector3f, Vector3f)\r\n * \r\n * @param eye\r\n * the position of the camera\r\n * @param center\r\n * the point in space to look at\r\n * @param up\r\n * the direction of 'up'\r\n * @return this\r\n */\r\n public Matrix4f lookAt(Vector3f eye, Vector3f center, Vector3f up) {\r\n return lookAt(eye.x, eye.y, eye.z, center.x, center.y, center.z, up.x, up.y, up.z, this);\r\n }\r\n\r\n /**\r\n * Apply a \"lookat\" transformation to this matrix for a right-handed coordinate system, \r\n * that aligns -z
with center - eye
and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and L
the lookat matrix,\r\n * then the new matrix will be M * L
. So when transforming a\r\n * vector v
with the new matrix by using M * L * v
,\r\n * the lookat transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a lookat transformation without post-multiplying it,\r\n * use {@link #setLookAt(float, float, float, float, float, float, float, float, float) setLookAt()}.\r\n * \r\n * @see #lookAt(Vector3f, Vector3f, Vector3f)\r\n * @see #setLookAt(float, float, float, float, float, float, float, float, float)\r\n * \r\n * @param eyeX\r\n * the x-coordinate of the eye/camera location\r\n * @param eyeY\r\n * the y-coordinate of the eye/camera location\r\n * @param eyeZ\r\n * the z-coordinate of the eye/camera location\r\n * @param centerX\r\n * the x-coordinate of the point to look at\r\n * @param centerY\r\n * the y-coordinate of the point to look at\r\n * @param centerZ\r\n * the z-coordinate of the point to look at\r\n * @param upX\r\n * the x-coordinate of the up vector\r\n * @param upY\r\n * the y-coordinate of the up vector\r\n * @param upZ\r\n * the z-coordinate of the up vector\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f lookAt(float eyeX, float eyeY, float eyeZ,\r\n float centerX, float centerY, float centerZ,\r\n float upX, float upY, float upZ, Matrix4f dest) {\r\n // Compute direction from position to lookAt\r\n float dirX, dirY, dirZ;\r\n dirX = eyeX - centerX;\r\n dirY = eyeY - centerY;\r\n dirZ = eyeZ - centerZ;\r\n // Normalize direction\r\n float invDirLength = 1.0f / (float) Math.sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);\r\n dirX *= invDirLength;\r\n dirY *= invDirLength;\r\n dirZ *= invDirLength;\r\n // left = up x direction\r\n float leftX, leftY, leftZ;\r\n leftX = upY * dirZ - upZ * dirY;\r\n leftY = upZ * dirX - upX * dirZ;\r\n leftZ = upX * dirY - upY * dirX;\r\n // normalize left\r\n float invLeftLength = 1.0f / (float) Math.sqrt(leftX * leftX + leftY * leftY + leftZ * leftZ);\r\n leftX *= invLeftLength;\r\n leftY *= invLeftLength;\r\n leftZ *= invLeftLength;\r\n // up = direction x left\r\n float upnX = dirY * leftZ - dirZ * leftY;\r\n float upnY = dirZ * leftX - dirX * leftZ;\r\n float upnZ = dirX * leftY - dirY * leftX;\r\n\r\n // calculate right matrix elements\r\n float rm00 = leftX;\r\n float rm01 = upnX;\r\n float rm02 = dirX;\r\n float rm10 = leftY;\r\n float rm11 = upnY;\r\n float rm12 = dirY;\r\n float rm20 = leftZ;\r\n float rm21 = upnZ;\r\n float rm22 = dirZ;\r\n float rm30 = -(leftX * eyeX + leftY * eyeY + leftZ * eyeZ);\r\n float rm31 = -(upnX * eyeX + upnY * eyeY + upnZ * eyeZ);\r\n float rm32 = -(dirX * eyeX + dirY * eyeY + dirZ * eyeZ);\r\n\r\n // perform optimized matrix multiplication\r\n // compute last column first, because others do not depend on it\r\n dest.m30 = m00 * rm30 + m10 * rm31 + m20 * rm32 + m30;\r\n dest.m31 = m01 * rm30 + m11 * rm31 + m21 * rm32 + m31;\r\n dest.m32 = m02 * rm30 + m12 * rm31 + m22 * rm32 + m32;\r\n dest.m33 = m03 * rm30 + m13 * rm31 + m23 * rm32 + m33;\r\n // introduce temporaries for dependent results\r\n float nm00 = m00 * rm00 + m10 * rm01 + m20 * rm02;\r\n float nm01 = m01 * rm00 + m11 * rm01 + m21 * rm02;\r\n float nm02 = m02 * rm00 + m12 * rm01 + m22 * rm02;\r\n float nm03 = m03 * rm00 + m13 * rm01 + m23 * rm02;\r\n float nm10 = m00 * rm10 + m10 * rm11 + m20 * rm12;\r\n float nm11 = m01 * rm10 + m11 * rm11 + m21 * rm12;\r\n float nm12 = m02 * rm10 + m12 * rm11 + m22 * rm12;\r\n float nm13 = m03 * rm10 + m13 * rm11 + m23 * rm12;\r\n dest.m20 = m00 * rm20 + m10 * rm21 + m20 * rm22;\r\n dest.m21 = m01 * rm20 + m11 * rm21 + m21 * rm22;\r\n dest.m22 = m02 * rm20 + m12 * rm21 + m22 * rm22;\r\n dest.m23 = m03 * rm20 + m13 * rm21 + m23 * rm22;\r\n // set the rest of the matrix elements\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply a \"lookat\" transformation to this matrix for a right-handed coordinate system, \r\n * that aligns -z
with center - eye
.\r\n *
\r\n * If M
is this
matrix and L
the lookat matrix,\r\n * then the new matrix will be M * L
. So when transforming a\r\n * vector v
with the new matrix by using M * L * v
,\r\n * the lookat transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a lookat transformation without post-multiplying it,\r\n * use {@link #setLookAt(float, float, float, float, float, float, float, float, float) setLookAt()}.\r\n * \r\n * @see #lookAt(Vector3f, Vector3f, Vector3f)\r\n * @see #setLookAt(float, float, float, float, float, float, float, float, float)\r\n * \r\n * @param eyeX\r\n * the x-coordinate of the eye/camera location\r\n * @param eyeY\r\n * the y-coordinate of the eye/camera location\r\n * @param eyeZ\r\n * the z-coordinate of the eye/camera location\r\n * @param centerX\r\n * the x-coordinate of the point to look at\r\n * @param centerY\r\n * the y-coordinate of the point to look at\r\n * @param centerZ\r\n * the z-coordinate of the point to look at\r\n * @param upX\r\n * the x-coordinate of the up vector\r\n * @param upY\r\n * the y-coordinate of the up vector\r\n * @param upZ\r\n * the z-coordinate of the up vector\r\n * @return this\r\n */\r\n public Matrix4f lookAt(float eyeX, float eyeY, float eyeZ,\r\n float centerX, float centerY, float centerZ,\r\n float upX, float upY, float upZ) {\r\n return lookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ, this);\r\n }\r\n\r\n /**\r\n * Set this matrix to be a \"lookat\" transformation for a left-handed coordinate system, that aligns\r\n * +z
with center - eye
.\r\n *
\r\n * In order to not make use of vectors to specify eye
, center
and up
but use primitives,\r\n * like in the GLU function, use {@link #setLookAtLH(float, float, float, float, float, float, float, float, float) setLookAtLH()}\r\n * instead.\r\n *
\r\n * In order to apply the lookat transformation to a previous existing transformation,\r\n * use {@link #lookAtLH(Vector3f, Vector3f, Vector3f) lookAt()}.\r\n * \r\n * @see #setLookAtLH(float, float, float, float, float, float, float, float, float)\r\n * @see #lookAtLH(Vector3f, Vector3f, Vector3f)\r\n * \r\n * @param eye\r\n * the position of the camera\r\n * @param center\r\n * the point in space to look at\r\n * @param up\r\n * the direction of 'up'\r\n * @return this\r\n */\r\n public Matrix4f setLookAtLH(Vector3f eye, Vector3f center, Vector3f up) {\r\n return setLookAtLH(eye.x, eye.y, eye.z, center.x, center.y, center.z, up.x, up.y, up.z);\r\n }\r\n\r\n /**\r\n * Set this matrix to be a \"lookat\" transformation for a left-handed coordinate system, \r\n * that aligns +z
with center - eye
.\r\n *
\r\n * In order to apply the lookat transformation to a previous existing transformation,\r\n * use {@link #lookAtLH(float, float, float, float, float, float, float, float, float) lookAtLH}.\r\n * \r\n * @see #setLookAtLH(Vector3f, Vector3f, Vector3f)\r\n * @see #lookAtLH(float, float, float, float, float, float, float, float, float)\r\n * \r\n * @param eyeX\r\n * the x-coordinate of the eye/camera location\r\n * @param eyeY\r\n * the y-coordinate of the eye/camera location\r\n * @param eyeZ\r\n * the z-coordinate of the eye/camera location\r\n * @param centerX\r\n * the x-coordinate of the point to look at\r\n * @param centerY\r\n * the y-coordinate of the point to look at\r\n * @param centerZ\r\n * the z-coordinate of the point to look at\r\n * @param upX\r\n * the x-coordinate of the up vector\r\n * @param upY\r\n * the y-coordinate of the up vector\r\n * @param upZ\r\n * the z-coordinate of the up vector\r\n * @return this\r\n */\r\n public Matrix4f setLookAtLH(float eyeX, float eyeY, float eyeZ,\r\n float centerX, float centerY, float centerZ,\r\n float upX, float upY, float upZ) {\r\n // Compute direction from position to lookAt\r\n float dirX, dirY, dirZ;\r\n dirX = centerX - eyeX;\r\n dirY = centerY - eyeY;\r\n dirZ = centerZ - eyeZ;\r\n // Normalize direction\r\n float invDirLength = 1.0f / (float) Math.sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);\r\n dirX *= invDirLength;\r\n dirY *= invDirLength;\r\n dirZ *= invDirLength;\r\n // left = up x direction\r\n float leftX, leftY, leftZ;\r\n leftX = upY * dirZ - upZ * dirY;\r\n leftY = upZ * dirX - upX * dirZ;\r\n leftZ = upX * dirY - upY * dirX;\r\n // normalize left\r\n float invLeftLength = 1.0f / (float) Math.sqrt(leftX * leftX + leftY * leftY + leftZ * leftZ);\r\n leftX *= invLeftLength;\r\n leftY *= invLeftLength;\r\n leftZ *= invLeftLength;\r\n // up = direction x left\r\n float upnX = dirY * leftZ - dirZ * leftY;\r\n float upnY = dirZ * leftX - dirX * leftZ;\r\n float upnZ = dirX * leftY - dirY * leftX;\r\n\r\n m00 = leftX;\r\n m01 = upnX;\r\n m02 = dirX;\r\n m03 = 0.0f;\r\n m10 = leftY;\r\n m11 = upnY;\r\n m12 = dirY;\r\n m13 = 0.0f;\r\n m20 = leftZ;\r\n m21 = upnZ;\r\n m22 = dirZ;\r\n m23 = 0.0f;\r\n m30 = -(leftX * eyeX + leftY * eyeY + leftZ * eyeZ);\r\n m31 = -(upnX * eyeX + upnY * eyeY + upnZ * eyeZ);\r\n m32 = -(dirX * eyeX + dirY * eyeY + dirZ * eyeZ);\r\n m33 = 1.0f;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Apply a \"lookat\" transformation to this matrix for a left-handed coordinate system, \r\n * that aligns +z
with center - eye
and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and L
the lookat matrix,\r\n * then the new matrix will be M * L
. So when transforming a\r\n * vector v
with the new matrix by using M * L * v
,\r\n * the lookat transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a lookat transformation without post-multiplying it,\r\n * use {@link #setLookAtLH(Vector3f, Vector3f, Vector3f)}.\r\n * \r\n * @see #lookAtLH(float, float, float, float, float, float, float, float, float)\r\n * \r\n * @param eye\r\n * the position of the camera\r\n * @param center\r\n * the point in space to look at\r\n * @param up\r\n * the direction of 'up'\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f lookAtLH(Vector3f eye, Vector3f center, Vector3f up, Matrix4f dest) {\r\n return lookAtLH(eye.x, eye.y, eye.z, center.x, center.y, center.z, up.x, up.y, up.z, dest);\r\n }\r\n\r\n /**\r\n * Apply a \"lookat\" transformation to this matrix for a left-handed coordinate system, \r\n * that aligns +z
with center - eye
.\r\n *
\r\n * If M
is this
matrix and L
the lookat matrix,\r\n * then the new matrix will be M * L
. So when transforming a\r\n * vector v
with the new matrix by using M * L * v
,\r\n * the lookat transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a lookat transformation without post-multiplying it,\r\n * use {@link #setLookAtLH(Vector3f, Vector3f, Vector3f)}.\r\n * \r\n * @see #lookAtLH(float, float, float, float, float, float, float, float, float)\r\n * \r\n * @param eye\r\n * the position of the camera\r\n * @param center\r\n * the point in space to look at\r\n * @param up\r\n * the direction of 'up'\r\n * @return this\r\n */\r\n public Matrix4f lookAtLH(Vector3f eye, Vector3f center, Vector3f up) {\r\n return lookAtLH(eye.x, eye.y, eye.z, center.x, center.y, center.z, up.x, up.y, up.z, this);\r\n }\r\n\r\n /**\r\n * Apply a \"lookat\" transformation to this matrix for a left-handed coordinate system, \r\n * that aligns +z
with center - eye
and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and L
the lookat matrix,\r\n * then the new matrix will be M * L
. So when transforming a\r\n * vector v
with the new matrix by using M * L * v
,\r\n * the lookat transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a lookat transformation without post-multiplying it,\r\n * use {@link #setLookAtLH(float, float, float, float, float, float, float, float, float) setLookAtLH()}.\r\n * \r\n * @see #lookAtLH(Vector3f, Vector3f, Vector3f)\r\n * @see #setLookAtLH(float, float, float, float, float, float, float, float, float)\r\n * \r\n * @param eyeX\r\n * the x-coordinate of the eye/camera location\r\n * @param eyeY\r\n * the y-coordinate of the eye/camera location\r\n * @param eyeZ\r\n * the z-coordinate of the eye/camera location\r\n * @param centerX\r\n * the x-coordinate of the point to look at\r\n * @param centerY\r\n * the y-coordinate of the point to look at\r\n * @param centerZ\r\n * the z-coordinate of the point to look at\r\n * @param upX\r\n * the x-coordinate of the up vector\r\n * @param upY\r\n * the y-coordinate of the up vector\r\n * @param upZ\r\n * the z-coordinate of the up vector\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f lookAtLH(float eyeX, float eyeY, float eyeZ,\r\n float centerX, float centerY, float centerZ,\r\n float upX, float upY, float upZ, Matrix4f dest) {\r\n // Compute direction from position to lookAt\r\n float dirX, dirY, dirZ;\r\n dirX = centerX - eyeX;\r\n dirY = centerY - eyeY;\r\n dirZ = centerZ - eyeZ;\r\n // Normalize direction\r\n float invDirLength = 1.0f / (float) Math.sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);\r\n dirX *= invDirLength;\r\n dirY *= invDirLength;\r\n dirZ *= invDirLength;\r\n // left = up x direction\r\n float leftX, leftY, leftZ;\r\n leftX = upY * dirZ - upZ * dirY;\r\n leftY = upZ * dirX - upX * dirZ;\r\n leftZ = upX * dirY - upY * dirX;\r\n // normalize left\r\n float invLeftLength = 1.0f / (float) Math.sqrt(leftX * leftX + leftY * leftY + leftZ * leftZ);\r\n leftX *= invLeftLength;\r\n leftY *= invLeftLength;\r\n leftZ *= invLeftLength;\r\n // up = direction x left\r\n float upnX = dirY * leftZ - dirZ * leftY;\r\n float upnY = dirZ * leftX - dirX * leftZ;\r\n float upnZ = dirX * leftY - dirY * leftX;\r\n\r\n // calculate right matrix elements\r\n float rm00 = leftX;\r\n float rm01 = upnX;\r\n float rm02 = dirX;\r\n float rm10 = leftY;\r\n float rm11 = upnY;\r\n float rm12 = dirY;\r\n float rm20 = leftZ;\r\n float rm21 = upnZ;\r\n float rm22 = dirZ;\r\n float rm30 = -(leftX * eyeX + leftY * eyeY + leftZ * eyeZ);\r\n float rm31 = -(upnX * eyeX + upnY * eyeY + upnZ * eyeZ);\r\n float rm32 = -(dirX * eyeX + dirY * eyeY + dirZ * eyeZ);\r\n\r\n // perform optimized matrix multiplication\r\n // compute last column first, because others do not depend on it\r\n dest.m30 = m00 * rm30 + m10 * rm31 + m20 * rm32 + m30;\r\n dest.m31 = m01 * rm30 + m11 * rm31 + m21 * rm32 + m31;\r\n dest.m32 = m02 * rm30 + m12 * rm31 + m22 * rm32 + m32;\r\n dest.m33 = m03 * rm30 + m13 * rm31 + m23 * rm32 + m33;\r\n // introduce temporaries for dependent results\r\n float nm00 = m00 * rm00 + m10 * rm01 + m20 * rm02;\r\n float nm01 = m01 * rm00 + m11 * rm01 + m21 * rm02;\r\n float nm02 = m02 * rm00 + m12 * rm01 + m22 * rm02;\r\n float nm03 = m03 * rm00 + m13 * rm01 + m23 * rm02;\r\n float nm10 = m00 * rm10 + m10 * rm11 + m20 * rm12;\r\n float nm11 = m01 * rm10 + m11 * rm11 + m21 * rm12;\r\n float nm12 = m02 * rm10 + m12 * rm11 + m22 * rm12;\r\n float nm13 = m03 * rm10 + m13 * rm11 + m23 * rm12;\r\n dest.m20 = m00 * rm20 + m10 * rm21 + m20 * rm22;\r\n dest.m21 = m01 * rm20 + m11 * rm21 + m21 * rm22;\r\n dest.m22 = m02 * rm20 + m12 * rm21 + m22 * rm22;\r\n dest.m23 = m03 * rm20 + m13 * rm21 + m23 * rm22;\r\n // set the rest of the matrix elements\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply a \"lookat\" transformation to this matrix for a left-handed coordinate system, \r\n * that aligns +z
with center - eye
.\r\n *
\r\n * If M
is this
matrix and L
the lookat matrix,\r\n * then the new matrix will be M * L
. So when transforming a\r\n * vector v
with the new matrix by using M * L * v
,\r\n * the lookat transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a lookat transformation without post-multiplying it,\r\n * use {@link #setLookAtLH(float, float, float, float, float, float, float, float, float) setLookAtLH()}.\r\n * \r\n * @see #lookAtLH(Vector3f, Vector3f, Vector3f)\r\n * @see #setLookAtLH(float, float, float, float, float, float, float, float, float)\r\n * \r\n * @param eyeX\r\n * the x-coordinate of the eye/camera location\r\n * @param eyeY\r\n * the y-coordinate of the eye/camera location\r\n * @param eyeZ\r\n * the z-coordinate of the eye/camera location\r\n * @param centerX\r\n * the x-coordinate of the point to look at\r\n * @param centerY\r\n * the y-coordinate of the point to look at\r\n * @param centerZ\r\n * the z-coordinate of the point to look at\r\n * @param upX\r\n * the x-coordinate of the up vector\r\n * @param upY\r\n * the y-coordinate of the up vector\r\n * @param upZ\r\n * the z-coordinate of the up vector\r\n * @return this\r\n */\r\n public Matrix4f lookAtLH(float eyeX, float eyeY, float eyeZ,\r\n float centerX, float centerY, float centerZ,\r\n float upX, float upY, float upZ) {\r\n return lookAtLH(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ, this);\r\n }\r\n\r\n /**\r\n * Apply a symmetric perspective projection frustum transformation for a right-handed coordinate system\r\n * using the given NDC z range to this matrix and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and P
the perspective projection matrix,\r\n * then the new matrix will be M * P
. So when transforming a\r\n * vector v
with the new matrix by using M * P * v
,\r\n * the perspective projection will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setPerspective(float, float, float, float, boolean) setPerspective}.\r\n * \r\n * @see #setPerspective(float, float, float, float, boolean)\r\n * \r\n * @param fovy\r\n * the vertical field of view in radians (must be greater than zero and less than {@link Math#PI PI})\r\n * @param aspect\r\n * the aspect ratio (i.e. width / height; must be greater than zero)\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param dest\r\n * will hold the result\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return dest\r\n */\r\n public Matrix4f perspective(float fovy, float aspect, float zNear, float zFar, boolean zZeroToOne, Matrix4f dest) {\r\n float h = (float) Math.tan(fovy * 0.5f);\r\n\r\n // calculate right matrix elements\r\n float rm00 = 1.0f / (h * aspect);\r\n float rm11 = 1.0f / h;\r\n float rm22;\r\n float rm32;\r\n boolean farInf = zFar > 0 && Float.isInfinite(zFar);\r\n boolean nearInf = zNear > 0 && Float.isInfinite(zNear);\r\n if (farInf) {\r\n // See: \"Infinite Projection Matrix\" (http://www.terathon.com/gdc07_lengyel.pdf)\r\n float e = 1E-6f;\r\n rm22 = e - 1.0f;\r\n rm32 = (e - (zZeroToOne ? 1.0f : 2.0f)) * zNear;\r\n } else if (nearInf) {\r\n float e = 1E-6f;\r\n rm22 = (zZeroToOne ? 0.0f : 1.0f) - e;\r\n rm32 = ((zZeroToOne ? 1.0f : 2.0f) - e) * zFar;\r\n } else {\r\n rm22 = (zZeroToOne ? zFar : zFar + zNear) / (zNear - zFar);\r\n rm32 = (zZeroToOne ? zFar : zFar + zFar) * zNear / (zNear - zFar);\r\n }\r\n // perform optimized matrix multiplication\r\n float nm20 = m20 * rm22 - m30;\r\n float nm21 = m21 * rm22 - m31;\r\n float nm22 = m22 * rm22 - m32;\r\n float nm23 = m23 * rm22 - m33;\r\n dest.m00 = m00 * rm00;\r\n dest.m01 = m01 * rm00;\r\n dest.m02 = m02 * rm00;\r\n dest.m03 = m03 * rm00;\r\n dest.m10 = m10 * rm11;\r\n dest.m11 = m11 * rm11;\r\n dest.m12 = m12 * rm11;\r\n dest.m13 = m13 * rm11;\r\n dest.m30 = m20 * rm32;\r\n dest.m31 = m21 * rm32;\r\n dest.m32 = m22 * rm32;\r\n dest.m33 = m23 * rm32;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply a symmetric perspective projection frustum transformation for a right-handed coordinate system\r\n * using OpenGL's NDC z range of [-1..+1] to this matrix and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and P
the perspective projection matrix,\r\n * then the new matrix will be M * P
. So when transforming a\r\n * vector v
with the new matrix by using M * P * v
,\r\n * the perspective projection will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setPerspective(float, float, float, float) setPerspective}.\r\n * \r\n * @see #setPerspective(float, float, float, float)\r\n * \r\n * @param fovy\r\n * the vertical field of view in radians (must be greater than zero and less than {@link Math#PI PI})\r\n * @param aspect\r\n * the aspect ratio (i.e. width / height; must be greater than zero)\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f perspective(float fovy, float aspect, float zNear, float zFar, Matrix4f dest) {\r\n return perspective(fovy, aspect, zNear, zFar, false, dest);\r\n }\r\n\r\n /**\r\n * Apply a symmetric perspective projection frustum transformation using for a right-handed coordinate system\r\n * the given NDC z range to this matrix.\r\n *
\r\n * If M
is this
matrix and P
the perspective projection matrix,\r\n * then the new matrix will be M * P
. So when transforming a\r\n * vector v
with the new matrix by using M * P * v
,\r\n * the perspective projection will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setPerspective(float, float, float, float, boolean) setPerspective}.\r\n * \r\n * @see #setPerspective(float, float, float, float, boolean)\r\n * \r\n * @param fovy\r\n * the vertical field of view in radians (must be greater than zero and less than {@link Math#PI PI})\r\n * @param aspect\r\n * the aspect ratio (i.e. width / height; must be greater than zero)\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return this\r\n */\r\n public Matrix4f perspective(float fovy, float aspect, float zNear, float zFar, boolean zZeroToOne) {\r\n return perspective(fovy, aspect, zNear, zFar, zZeroToOne, this);\r\n }\r\n\r\n /**\r\n * Apply a symmetric perspective projection frustum transformation for a right-handed coordinate system\r\n * using OpenGL's NDC z range of [-1..+1] to this matrix.\r\n *
\r\n * If M
is this
matrix and P
the perspective projection matrix,\r\n * then the new matrix will be M * P
. So when transforming a\r\n * vector v
with the new matrix by using M * P * v
,\r\n * the perspective projection will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setPerspective(float, float, float, float) setPerspective}.\r\n * \r\n * @see #setPerspective(float, float, float, float)\r\n * \r\n * @param fovy\r\n * the vertical field of view in radians (must be greater than zero and less than {@link Math#PI PI})\r\n * @param aspect\r\n * the aspect ratio (i.e. width / height; must be greater than zero)\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @return this\r\n */\r\n public Matrix4f perspective(float fovy, float aspect, float zNear, float zFar) {\r\n return perspective(fovy, aspect, zNear, zFar, this);\r\n }\r\n\r\n /**\r\n * Set this matrix to be a symmetric perspective projection frustum transformation for a right-handed coordinate system\r\n * using the given NDC z range.\r\n *
\r\n * In order to apply the perspective projection transformation to an existing transformation,\r\n * use {@link #perspective(float, float, float, float, boolean) perspective()}.\r\n * \r\n * @see #perspective(float, float, float, float, boolean)\r\n * \r\n * @param fovy\r\n * the vertical field of view in radians (must be greater than zero and less than {@link Math#PI PI})\r\n * @param aspect\r\n * the aspect ratio (i.e. width / height; must be greater than zero)\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return this\r\n */\r\n public Matrix4f setPerspective(float fovy, float aspect, float zNear, float zFar, boolean zZeroToOne) {\r\n float h = (float) Math.tan(fovy * 0.5f);\r\n m00 = 1.0f / (h * aspect);\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = 1.0f / h;\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = 0.0f;\r\n boolean farInf = zFar > 0 && Float.isInfinite(zFar);\r\n boolean nearInf = zNear > 0 && Float.isInfinite(zNear);\r\n if (farInf) {\r\n // See: \"Infinite Projection Matrix\" (http://www.terathon.com/gdc07_lengyel.pdf)\r\n float e = 1E-6f;\r\n m22 = e - 1.0f;\r\n m32 = (e - (zZeroToOne ? 1.0f : 2.0f)) * zNear;\r\n } else if (nearInf) {\r\n float e = 1E-6f;\r\n m22 = (zZeroToOne ? 0.0f : 1.0f) - e;\r\n m32 = ((zZeroToOne ? 1.0f : 2.0f) - e) * zFar;\r\n } else {\r\n m22 = (zZeroToOne ? zFar : zFar + zNear) / (zNear - zFar);\r\n m32 = (zZeroToOne ? zFar : zFar + zFar) * zNear / (zNear - zFar);\r\n }\r\n m23 = -1.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m33 = 0.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be a symmetric perspective projection frustum transformation for a right-handed coordinate system\r\n * using OpenGL's NDC z range of [-1..+1].\r\n *
\r\n * In order to apply the perspective projection transformation to an existing transformation,\r\n * use {@link #perspective(float, float, float, float) perspective()}.\r\n * \r\n * @see #perspective(float, float, float, float)\r\n * \r\n * @param fovy\r\n * the vertical field of view in radians (must be greater than zero and less than {@link Math#PI PI})\r\n * @param aspect\r\n * the aspect ratio (i.e. width / height; must be greater than zero)\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @return this\r\n */\r\n public Matrix4f setPerspective(float fovy, float aspect, float zNear, float zFar) {\r\n return setPerspective(fovy, aspect, zNear, zFar, false);\r\n }\r\n\r\n /**\r\n * Apply a symmetric perspective projection frustum transformation for a left-handed coordinate system\r\n * using the given NDC z range to this matrix and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and P
the perspective projection matrix,\r\n * then the new matrix will be M * P
. So when transforming a\r\n * vector v
with the new matrix by using M * P * v
,\r\n * the perspective projection will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setPerspectiveLH(float, float, float, float, boolean) setPerspectiveLH}.\r\n * \r\n * @see #setPerspectiveLH(float, float, float, float, boolean)\r\n * \r\n * @param fovy\r\n * the vertical field of view in radians (must be greater than zero and less than {@link Math#PI PI})\r\n * @param aspect\r\n * the aspect ratio (i.e. width / height; must be greater than zero)\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f perspectiveLH(float fovy, float aspect, float zNear, float zFar, boolean zZeroToOne, Matrix4f dest) {\r\n float h = (float) Math.tan(fovy * 0.5f);\r\n // calculate right matrix elements\r\n float rm00 = 1.0f / (h * aspect);\r\n float rm11 = 1.0f / h;\r\n float rm22;\r\n float rm32;\r\n boolean farInf = zFar > 0 && Float.isInfinite(zFar);\r\n boolean nearInf = zNear > 0 && Float.isInfinite(zNear);\r\n if (farInf) {\r\n // See: \"Infinite Projection Matrix\" (http://www.terathon.com/gdc07_lengyel.pdf)\r\n float e = 1E-6f;\r\n rm22 = 1.0f - e;\r\n rm32 = (e - (zZeroToOne ? 1.0f : 2.0f)) * zNear;\r\n } else if (nearInf) {\r\n float e = 1E-6f;\r\n rm22 = (zZeroToOne ? 0.0f : 1.0f) - e;\r\n rm32 = ((zZeroToOne ? 1.0f : 2.0f) - e) * zFar;\r\n } else {\r\n rm22 = (zZeroToOne ? zFar : zFar + zNear) / (zFar - zNear);\r\n rm32 = (zZeroToOne ? zFar : zFar + zFar) * zNear / (zNear - zFar);\r\n }\r\n // perform optimized matrix multiplication\r\n float nm20 = m20 * rm22 + m30;\r\n float nm21 = m21 * rm22 + m31;\r\n float nm22 = m22 * rm22 + m32;\r\n float nm23 = m23 * rm22 + m33;\r\n dest.m00 = m00 * rm00;\r\n dest.m01 = m01 * rm00;\r\n dest.m02 = m02 * rm00;\r\n dest.m03 = m03 * rm00;\r\n dest.m10 = m10 * rm11;\r\n dest.m11 = m11 * rm11;\r\n dest.m12 = m12 * rm11;\r\n dest.m13 = m13 * rm11;\r\n dest.m30 = m20 * rm32;\r\n dest.m31 = m21 * rm32;\r\n dest.m32 = m22 * rm32;\r\n dest.m33 = m23 * rm32;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply a symmetric perspective projection frustum transformation for a left-handed coordinate system\r\n * using the given NDC z range to this matrix.\r\n *
\r\n * If M
is this
matrix and P
the perspective projection matrix,\r\n * then the new matrix will be M * P
. So when transforming a\r\n * vector v
with the new matrix by using M * P * v
,\r\n * the perspective projection will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setPerspectiveLH(float, float, float, float, boolean) setPerspectiveLH}.\r\n * \r\n * @see #setPerspectiveLH(float, float, float, float, boolean)\r\n * \r\n * @param fovy\r\n * the vertical field of view in radians (must be greater than zero and less than {@link Math#PI PI})\r\n * @param aspect\r\n * the aspect ratio (i.e. width / height; must be greater than zero)\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return this\r\n */\r\n public Matrix4f perspectiveLH(float fovy, float aspect, float zNear, float zFar, boolean zZeroToOne) {\r\n return perspectiveLH(fovy, aspect, zNear, zFar, zZeroToOne, this);\r\n }\r\n\r\n /**\r\n * Apply a symmetric perspective projection frustum transformation for a left-handed coordinate system\r\n * using OpenGL's NDC z range of [-1..+1] to this matrix and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and P
the perspective projection matrix,\r\n * then the new matrix will be M * P
. So when transforming a\r\n * vector v
with the new matrix by using M * P * v
,\r\n * the perspective projection will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setPerspectiveLH(float, float, float, float) setPerspectiveLH}.\r\n * \r\n * @see #setPerspectiveLH(float, float, float, float)\r\n * \r\n * @param fovy\r\n * the vertical field of view in radians (must be greater than zero and less than {@link Math#PI PI})\r\n * @param aspect\r\n * the aspect ratio (i.e. width / height; must be greater than zero)\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f perspectiveLH(float fovy, float aspect, float zNear, float zFar, Matrix4f dest) {\r\n return perspectiveLH(fovy, aspect, zNear, zFar, false, dest);\r\n }\r\n\r\n /**\r\n * Apply a symmetric perspective projection frustum transformation for a left-handed coordinate system\r\n * using OpenGL's NDC z range of [-1..+1] to this matrix.\r\n *
\r\n * If M
is this
matrix and P
the perspective projection matrix,\r\n * then the new matrix will be M * P
. So when transforming a\r\n * vector v
with the new matrix by using M * P * v
,\r\n * the perspective projection will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setPerspectiveLH(float, float, float, float) setPerspectiveLH}.\r\n * \r\n * @see #setPerspectiveLH(float, float, float, float)\r\n * \r\n * @param fovy\r\n * the vertical field of view in radians (must be greater than zero and less than {@link Math#PI PI})\r\n * @param aspect\r\n * the aspect ratio (i.e. width / height; must be greater than zero)\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @return this\r\n */\r\n public Matrix4f perspectiveLH(float fovy, float aspect, float zNear, float zFar) {\r\n return perspectiveLH(fovy, aspect, zNear, zFar, this);\r\n }\r\n\r\n /**\r\n * Set this matrix to be a symmetric perspective projection frustum transformation for a left-handed coordinate system\r\n * using the given NDC z range of [-1..+1].\r\n *
\r\n * In order to apply the perspective projection transformation to an existing transformation,\r\n * use {@link #perspectiveLH(float, float, float, float, boolean) perspectiveLH()}.\r\n * \r\n * @see #perspectiveLH(float, float, float, float, boolean)\r\n * \r\n * @param fovy\r\n * the vertical field of view in radians (must be greater than zero and less than {@link Math#PI PI})\r\n * @param aspect\r\n * the aspect ratio (i.e. width / height; must be greater than zero)\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return this\r\n */\r\n public Matrix4f setPerspectiveLH(float fovy, float aspect, float zNear, float zFar, boolean zZeroToOne) {\r\n float h = (float) Math.tan(fovy * 0.5f);\r\n m00 = 1.0f / (h * aspect);\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = 1.0f / h;\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = 0.0f;\r\n boolean farInf = zFar > 0 && Float.isInfinite(zFar);\r\n boolean nearInf = zNear > 0 && Float.isInfinite(zNear);\r\n if (farInf) {\r\n // See: \"Infinite Projection Matrix\" (http://www.terathon.com/gdc07_lengyel.pdf)\r\n float e = 1E-6f;\r\n m22 = 1.0f - e;\r\n m32 = (e - (zZeroToOne ? 1.0f : 2.0f)) * zNear;\r\n } else if (nearInf) {\r\n float e = 1E-6f;\r\n m22 = (zZeroToOne ? 0.0f : 1.0f) - e;\r\n m32 = ((zZeroToOne ? 1.0f : 2.0f) - e) * zFar;\r\n } else {\r\n m22 = (zZeroToOne ? zFar : zFar + zNear) / (zFar - zNear);\r\n m32 = (zZeroToOne ? zFar : zFar + zFar) * zNear / (zNear - zFar);\r\n }\r\n m23 = 1.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m33 = 0.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be a symmetric perspective projection frustum transformation for a left-handed coordinate system\r\n * using OpenGL's NDC z range of [-1..+1].\r\n *
\r\n * In order to apply the perspective projection transformation to an existing transformation,\r\n * use {@link #perspectiveLH(float, float, float, float) perspectiveLH()}.\r\n * \r\n * @see #perspectiveLH(float, float, float, float)\r\n * \r\n * @param fovy\r\n * the vertical field of view in radians (must be greater than zero and less than {@link Math#PI PI})\r\n * @param aspect\r\n * the aspect ratio (i.e. width / height; must be greater than zero)\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @return this\r\n */\r\n public Matrix4f setPerspectiveLH(float fovy, float aspect, float zNear, float zFar) {\r\n return setPerspectiveLH(fovy, aspect, zNear, zFar, false);\r\n }\r\n\r\n /**\r\n * Apply an arbitrary perspective projection frustum transformation for a right-handed coordinate system\r\n * using the given NDC z range to this matrix and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and F
the frustum matrix,\r\n * then the new matrix will be M * F
. So when transforming a\r\n * vector v
with the new matrix by using M * F * v
,\r\n * the frustum transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setFrustum(float, float, float, float, float, float, boolean) setFrustum()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setFrustum(float, float, float, float, float, float, boolean)\r\n * \r\n * @param left\r\n * the distance along the x-axis to the left frustum edge\r\n * @param right\r\n * the distance along the x-axis to the right frustum edge\r\n * @param bottom\r\n * the distance along the y-axis to the bottom frustum edge\r\n * @param top\r\n * the distance along the y-axis to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f frustum(float left, float right, float bottom, float top, float zNear, float zFar, boolean zZeroToOne, Matrix4f dest) {\r\n // calculate right matrix elements\r\n float rm00 = (zNear + zNear) / (right - left);\r\n float rm11 = (zNear + zNear) / (top - bottom);\r\n float rm20 = (right + left) / (right - left);\r\n float rm21 = (top + bottom) / (top - bottom);\r\n float rm22;\r\n float rm32;\r\n boolean farInf = zFar > 0 && Float.isInfinite(zFar);\r\n boolean nearInf = zNear > 0 && Float.isInfinite(zNear);\r\n if (farInf) {\r\n // See: \"Infinite Projection Matrix\" (http://www.terathon.com/gdc07_lengyel.pdf)\r\n float e = 1E-6f;\r\n rm22 = e - 1.0f;\r\n rm32 = (e - (zZeroToOne ? 1.0f : 2.0f)) * zNear;\r\n } else if (nearInf) {\r\n float e = 1E-6f;\r\n rm22 = (zZeroToOne ? 0.0f : 1.0f) - e;\r\n rm32 = ((zZeroToOne ? 1.0f : 2.0f) - e) * zFar;\r\n } else {\r\n rm22 = (zZeroToOne ? zFar : zFar + zNear) / (zNear - zFar);\r\n rm32 = (zZeroToOne ? zFar : zFar + zFar) * zNear / (zNear - zFar);\r\n }\r\n // perform optimized matrix multiplication\r\n float nm20 = m00 * rm20 + m10 * rm21 + m20 * rm22 - m30;\r\n float nm21 = m01 * rm20 + m11 * rm21 + m21 * rm22 - m31;\r\n float nm22 = m02 * rm20 + m12 * rm21 + m22 * rm22 - m32;\r\n float nm23 = m03 * rm20 + m13 * rm21 + m23 * rm22 - m33;\r\n dest.m00 = m00 * rm00;\r\n dest.m01 = m01 * rm00;\r\n dest.m02 = m02 * rm00;\r\n dest.m03 = m03 * rm00;\r\n dest.m10 = m10 * rm11;\r\n dest.m11 = m11 * rm11;\r\n dest.m12 = m12 * rm11;\r\n dest.m13 = m13 * rm11;\r\n dest.m30 = m20 * rm32;\r\n dest.m31 = m21 * rm32;\r\n dest.m32 = m22 * rm32;\r\n dest.m33 = m23 * rm32;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply an arbitrary perspective projection frustum transformation for a right-handed coordinate system\r\n * using OpenGL's NDC z range of [-1..+1] to this matrix and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and F
the frustum matrix,\r\n * then the new matrix will be M * F
. So when transforming a\r\n * vector v
with the new matrix by using M * F * v
,\r\n * the frustum transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setFrustum(float, float, float, float, float, float) setFrustum()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setFrustum(float, float, float, float, float, float)\r\n * \r\n * @param left\r\n * the distance along the x-axis to the left frustum edge\r\n * @param right\r\n * the distance along the x-axis to the right frustum edge\r\n * @param bottom\r\n * the distance along the y-axis to the bottom frustum edge\r\n * @param top\r\n * the distance along the y-axis to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f frustum(float left, float right, float bottom, float top, float zNear, float zFar, Matrix4f dest) {\r\n return frustum(left, right, bottom, top, zNear, zFar, false, dest);\r\n }\r\n\r\n /**\r\n * Apply an arbitrary perspective projection frustum transformation for a right-handed coordinate system\r\n * using the given NDC z range to this matrix.\r\n *
\r\n * If M
is this
matrix and F
the frustum matrix,\r\n * then the new matrix will be M * F
. So when transforming a\r\n * vector v
with the new matrix by using M * F * v
,\r\n * the frustum transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setFrustum(float, float, float, float, float, float, boolean) setFrustum()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setFrustum(float, float, float, float, float, float, boolean)\r\n * \r\n * @param left\r\n * the distance along the x-axis to the left frustum edge\r\n * @param right\r\n * the distance along the x-axis to the right frustum edge\r\n * @param bottom\r\n * the distance along the y-axis to the bottom frustum edge\r\n * @param top\r\n * the distance along the y-axis to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return this\r\n */\r\n public Matrix4f frustum(float left, float right, float bottom, float top, float zNear, float zFar, boolean zZeroToOne) {\r\n return frustum(left, right, bottom, top, zNear, zFar, zZeroToOne, this);\r\n }\r\n\r\n /**\r\n * Apply an arbitrary perspective projection frustum transformation for a right-handed coordinate system\r\n * using OpenGL's NDC z range of [-1..+1] to this matrix.\r\n *
\r\n * If M
is this
matrix and F
the frustum matrix,\r\n * then the new matrix will be M * F
. So when transforming a\r\n * vector v
with the new matrix by using M * F * v
,\r\n * the frustum transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setFrustum(float, float, float, float, float, float) setFrustum()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setFrustum(float, float, float, float, float, float)\r\n * \r\n * @param left\r\n * the distance along the x-axis to the left frustum edge\r\n * @param right\r\n * the distance along the x-axis to the right frustum edge\r\n * @param bottom\r\n * the distance along the y-axis to the bottom frustum edge\r\n * @param top\r\n * the distance along the y-axis to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @return this\r\n */\r\n public Matrix4f frustum(float left, float right, float bottom, float top, float zNear, float zFar) {\r\n return frustum(left, right, bottom, top, zNear, zFar, this);\r\n }\r\n\r\n /**\r\n * Set this matrix to be an arbitrary perspective projection frustum transformation for a right-handed coordinate system\r\n * using the given NDC z range.\r\n *
\r\n * In order to apply the perspective frustum transformation to an existing transformation,\r\n * use {@link #frustum(float, float, float, float, float, float, boolean) frustum()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #frustum(float, float, float, float, float, float, boolean)\r\n * \r\n * @param left\r\n * the distance along the x-axis to the left frustum edge\r\n * @param right\r\n * the distance along the x-axis to the right frustum edge\r\n * @param bottom\r\n * the distance along the y-axis to the bottom frustum edge\r\n * @param top\r\n * the distance along the y-axis to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return this\r\n */\r\n public Matrix4f setFrustum(float left, float right, float bottom, float top, float zNear, float zFar, boolean zZeroToOne) {\r\n m00 = (zNear + zNear) / (right - left);\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = (zNear + zNear) / (top - bottom);\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = (right + left) / (right - left);\r\n m21 = (top + bottom) / (top - bottom);\r\n boolean farInf = zFar > 0 && Float.isInfinite(zFar);\r\n boolean nearInf = zNear > 0 && Float.isInfinite(zNear);\r\n if (farInf) {\r\n // See: \"Infinite Projection Matrix\" (http://www.terathon.com/gdc07_lengyel.pdf)\r\n float e = 1E-6f;\r\n m22 = e - 1.0f;\r\n m32 = (e - (zZeroToOne ? 1.0f : 2.0f)) * zNear;\r\n } else if (nearInf) {\r\n float e = 1E-6f;\r\n m22 = (zZeroToOne ? 0.0f : 1.0f) - e;\r\n m32 = ((zZeroToOne ? 1.0f : 2.0f) - e) * zFar;\r\n } else {\r\n m22 = (zZeroToOne ? zFar : zFar + zNear) / (zNear - zFar);\r\n m32 = (zZeroToOne ? zFar : zFar + zFar) * zNear / (zNear - zFar);\r\n }\r\n m23 = -1.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m33 = 0.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be an arbitrary perspective projection frustum transformation for a right-handed coordinate system\r\n * using OpenGL's NDC z range of [-1..+1].\r\n *
\r\n * In order to apply the perspective frustum transformation to an existing transformation,\r\n * use {@link #frustum(float, float, float, float, float, float) frustum()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #frustum(float, float, float, float, float, float)\r\n * \r\n * @param left\r\n * the distance along the x-axis to the left frustum edge\r\n * @param right\r\n * the distance along the x-axis to the right frustum edge\r\n * @param bottom\r\n * the distance along the y-axis to the bottom frustum edge\r\n * @param top\r\n * the distance along the y-axis to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @return this\r\n */\r\n public Matrix4f setFrustum(float left, float right, float bottom, float top, float zNear, float zFar) {\r\n return setFrustum(left, right, bottom, top, zNear, zFar, false);\r\n }\r\n\r\n /**\r\n * Apply an arbitrary perspective projection frustum transformation for a left-handed coordinate system\r\n * using the given NDC z range to this matrix and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and F
the frustum matrix,\r\n * then the new matrix will be M * F
. So when transforming a\r\n * vector v
with the new matrix by using M * F * v
,\r\n * the frustum transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setFrustumLH(float, float, float, float, float, float, boolean) setFrustumLH()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setFrustumLH(float, float, float, float, float, float, boolean)\r\n * \r\n * @param left\r\n * the distance along the x-axis to the left frustum edge\r\n * @param right\r\n * the distance along the x-axis to the right frustum edge\r\n * @param bottom\r\n * the distance along the y-axis to the bottom frustum edge\r\n * @param top\r\n * the distance along the y-axis to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f frustumLH(float left, float right, float bottom, float top, float zNear, float zFar, boolean zZeroToOne, Matrix4f dest) {\r\n // calculate right matrix elements\r\n float rm00 = (zNear + zNear) / (right - left);\r\n float rm11 = (zNear + zNear) / (top - bottom);\r\n float rm20 = (right + left) / (right - left);\r\n float rm21 = (top + bottom) / (top - bottom);\r\n float rm22;\r\n float rm32;\r\n boolean farInf = zFar > 0 && Float.isInfinite(zFar);\r\n boolean nearInf = zNear > 0 && Float.isInfinite(zNear);\r\n if (farInf) {\r\n // See: \"Infinite Projection Matrix\" (http://www.terathon.com/gdc07_lengyel.pdf)\r\n float e = 1E-6f;\r\n rm22 = 1.0f - e;\r\n rm32 = (e - (zZeroToOne ? 1.0f : 2.0f)) * zNear;\r\n } else if (nearInf) {\r\n float e = 1E-6f;\r\n rm22 = (zZeroToOne ? 0.0f : 1.0f) - e;\r\n rm32 = ((zZeroToOne ? 1.0f : 2.0f) - e) * zFar;\r\n } else {\r\n rm22 = (zZeroToOne ? zFar : zFar + zNear) / (zFar - zNear);\r\n rm32 = (zZeroToOne ? zFar : zFar + zFar) * zNear / (zNear - zFar);\r\n }\r\n // perform optimized matrix multiplication\r\n float nm20 = m00 * rm20 + m10 * rm21 + m20 * rm22 + m30;\r\n float nm21 = m01 * rm20 + m11 * rm21 + m21 * rm22 + m31;\r\n float nm22 = m02 * rm20 + m12 * rm21 + m22 * rm22 + m32;\r\n float nm23 = m03 * rm20 + m13 * rm21 + m23 * rm22 + m33;\r\n dest.m00 = m00 * rm00;\r\n dest.m01 = m01 * rm00;\r\n dest.m02 = m02 * rm00;\r\n dest.m03 = m03 * rm00;\r\n dest.m10 = m10 * rm11;\r\n dest.m11 = m11 * rm11;\r\n dest.m12 = m12 * rm11;\r\n dest.m13 = m13 * rm11;\r\n dest.m30 = m20 * rm32;\r\n dest.m31 = m21 * rm32;\r\n dest.m32 = m22 * rm32;\r\n dest.m33 = m23 * rm32;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply an arbitrary perspective projection frustum transformation for a left-handed coordinate system\r\n * using the given NDC z range to this matrix.\r\n *
\r\n * If M
is this
matrix and F
the frustum matrix,\r\n * then the new matrix will be M * F
. So when transforming a\r\n * vector v
with the new matrix by using M * F * v
,\r\n * the frustum transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setFrustumLH(float, float, float, float, float, float, boolean) setFrustumLH()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setFrustumLH(float, float, float, float, float, float, boolean)\r\n * \r\n * @param left\r\n * the distance along the x-axis to the left frustum edge\r\n * @param right\r\n * the distance along the x-axis to the right frustum edge\r\n * @param bottom\r\n * the distance along the y-axis to the bottom frustum edge\r\n * @param top\r\n * the distance along the y-axis to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return this\r\n */\r\n public Matrix4f frustumLH(float left, float right, float bottom, float top, float zNear, float zFar, boolean zZeroToOne) {\r\n return frustumLH(left, right, bottom, top, zNear, zFar, zZeroToOne, this);\r\n }\r\n\r\n /**\r\n * Apply an arbitrary perspective projection frustum transformation for a left-handed coordinate system\r\n * using OpenGL's NDC z range of [-1..+1] to this matrix and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and F
the frustum matrix,\r\n * then the new matrix will be M * F
. So when transforming a\r\n * vector v
with the new matrix by using M * F * v
,\r\n * the frustum transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setFrustumLH(float, float, float, float, float, float) setFrustumLH()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setFrustumLH(float, float, float, float, float, float)\r\n * \r\n * @param left\r\n * the distance along the x-axis to the left frustum edge\r\n * @param right\r\n * the distance along the x-axis to the right frustum edge\r\n * @param bottom\r\n * the distance along the y-axis to the bottom frustum edge\r\n * @param top\r\n * the distance along the y-axis to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f frustumLH(float left, float right, float bottom, float top, float zNear, float zFar, Matrix4f dest) {\r\n return frustumLH(left, right, bottom, top, zNear, zFar, false, dest);\r\n }\r\n\r\n /**\r\n * Apply an arbitrary perspective projection frustum transformation for a left-handed coordinate system\r\n * using the given NDC z range to this matrix.\r\n *
\r\n * If M
is this
matrix and F
the frustum matrix,\r\n * then the new matrix will be M * F
. So when transforming a\r\n * vector v
with the new matrix by using M * F * v
,\r\n * the frustum transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setFrustumLH(float, float, float, float, float, float) setFrustumLH()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setFrustumLH(float, float, float, float, float, float)\r\n * \r\n * @param left\r\n * the distance along the x-axis to the left frustum edge\r\n * @param right\r\n * the distance along the x-axis to the right frustum edge\r\n * @param bottom\r\n * the distance along the y-axis to the bottom frustum edge\r\n * @param top\r\n * the distance along the y-axis to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @return this\r\n */\r\n public Matrix4f frustumLH(float left, float right, float bottom, float top, float zNear, float zFar) {\r\n return frustumLH(left, right, bottom, top, zNear, zFar, this);\r\n }\r\n\r\n /**\r\n * Set this matrix to be an arbitrary perspective projection frustum transformation for a left-handed coordinate system\r\n * using OpenGL's NDC z range of [-1..+1].\r\n *
\r\n * In order to apply the perspective frustum transformation to an existing transformation,\r\n * use {@link #frustumLH(float, float, float, float, float, float, boolean) frustumLH()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #frustumLH(float, float, float, float, float, float, boolean)\r\n * \r\n * @param left\r\n * the distance along the x-axis to the left frustum edge\r\n * @param right\r\n * the distance along the x-axis to the right frustum edge\r\n * @param bottom\r\n * the distance along the y-axis to the bottom frustum edge\r\n * @param top\r\n * the distance along the y-axis to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return this\r\n */\r\n public Matrix4f setFrustumLH(float left, float right, float bottom, float top, float zNear, float zFar, boolean zZeroToOne) {\r\n m00 = (zNear + zNear) / (right - left);\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = (zNear + zNear) / (top - bottom);\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = (right + left) / (right - left);\r\n m21 = (top + bottom) / (top - bottom);\r\n boolean farInf = zFar > 0 && Float.isInfinite(zFar);\r\n boolean nearInf = zNear > 0 && Float.isInfinite(zNear);\r\n if (farInf) {\r\n // See: \"Infinite Projection Matrix\" (http://www.terathon.com/gdc07_lengyel.pdf)\r\n float e = 1E-6f;\r\n m22 = 1.0f - e;\r\n m32 = (e - (zZeroToOne ? 1.0f : 2.0f)) * zNear;\r\n } else if (nearInf) {\r\n float e = 1E-6f;\r\n m22 = (zZeroToOne ? 0.0f : 1.0f) - e;\r\n m32 = ((zZeroToOne ? 1.0f : 2.0f) - e) * zFar;\r\n } else {\r\n m22 = (zZeroToOne ? zFar : zFar + zNear) / (zFar - zNear);\r\n m32 = (zZeroToOne ? zFar : zFar + zFar) * zNear / (zNear - zFar);\r\n }\r\n m23 = 1.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m33 = 0.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be an arbitrary perspective projection frustum transformation for a left-handed coordinate system\r\n * using OpenGL's NDC z range of [-1..+1].\r\n *
\r\n * In order to apply the perspective frustum transformation to an existing transformation,\r\n * use {@link #frustumLH(float, float, float, float, float, float) frustumLH()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #frustumLH(float, float, float, float, float, float)\r\n * \r\n * @param left\r\n * the distance along the x-axis to the left frustum edge\r\n * @param right\r\n * the distance along the x-axis to the right frustum edge\r\n * @param bottom\r\n * the distance along the y-axis to the bottom frustum edge\r\n * @param top\r\n * the distance along the y-axis to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @return this\r\n */\r\n public Matrix4f setFrustumLH(float left, float right, float bottom, float top, float zNear, float zFar) {\r\n return setFrustumLH(left, right, bottom, top, zNear, zFar, false);\r\n }\r\n\r\n /**\r\n * Apply the rotation transformation of the given {@link Quaternionf} to this matrix and store\r\n * the result in dest
.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and Q
the rotation matrix obtained from the given quaternion,\r\n * then the new matrix will be M * Q
. So when transforming a\r\n * vector v
with the new matrix by using M * Q * v
,\r\n * the quaternion rotation will be applied first!\r\n *
\r\n * In order to set the matrix to a rotation transformation without post-multiplying,\r\n * use {@link #rotation(Quaternionf)}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotation(Quaternionf)\r\n * \r\n * @param quat\r\n * the {@link Quaternionf}\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotate(Quaternionf quat, Matrix4f dest) {\r\n float dqx = quat.x + quat.x;\r\n float dqy = quat.y + quat.y;\r\n float dqz = quat.z + quat.z;\r\n float q00 = dqx * quat.x;\r\n float q11 = dqy * quat.y;\r\n float q22 = dqz * quat.z;\r\n float q01 = dqx * quat.y;\r\n float q02 = dqx * quat.z;\r\n float q03 = dqx * quat.w;\r\n float q12 = dqy * quat.z;\r\n float q13 = dqy * quat.w;\r\n float q23 = dqz * quat.w;\r\n\r\n float rm00 = 1.0f - q11 - q22;\r\n float rm01 = q01 + q23;\r\n float rm02 = q02 - q13;\r\n float rm10 = q01 - q23;\r\n float rm11 = 1.0f - q22 - q00;\r\n float rm12 = q12 + q03;\r\n float rm20 = q02 + q13;\r\n float rm21 = q12 - q03;\r\n float rm22 = 1.0f - q11 - q00;\r\n\r\n float nm00 = m00 * rm00 + m10 * rm01 + m20 * rm02;\r\n float nm01 = m01 * rm00 + m11 * rm01 + m21 * rm02;\r\n float nm02 = m02 * rm00 + m12 * rm01 + m22 * rm02;\r\n float nm03 = m03 * rm00 + m13 * rm01 + m23 * rm02;\r\n float nm10 = m00 * rm10 + m10 * rm11 + m20 * rm12;\r\n float nm11 = m01 * rm10 + m11 * rm11 + m21 * rm12;\r\n float nm12 = m02 * rm10 + m12 * rm11 + m22 * rm12;\r\n float nm13 = m03 * rm10 + m13 * rm11 + m23 * rm12;\r\n dest.m20 = m00 * rm20 + m10 * rm21 + m20 * rm22;\r\n dest.m21 = m01 * rm20 + m11 * rm21 + m21 * rm22;\r\n dest.m22 = m02 * rm20 + m12 * rm21 + m22 * rm22;\r\n dest.m23 = m03 * rm20 + m13 * rm21 + m23 * rm22;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply the rotation transformation of the given {@link Quaternionf} to this matrix.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and Q
the rotation matrix obtained from the given quaternion,\r\n * then the new matrix will be M * Q
. So when transforming a\r\n * vector v
with the new matrix by using M * Q * v
,\r\n * the quaternion rotation will be applied first!\r\n *
\r\n * In order to set the matrix to a rotation transformation without post-multiplying,\r\n * use {@link #rotation(Quaternionf)}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotation(Quaternionf)\r\n * \r\n * @param quat\r\n * the {@link Quaternionf}\r\n * @return this\r\n */\r\n public Matrix4f rotate(Quaternionf quat) {\r\n return rotate(quat, this);\r\n }\r\n\r\n /**\r\n * Apply the rotation transformation of the given {@link Quaternionf} to this {@link #isAffine() affine} matrix and store\r\n * the result in dest
.\r\n *
\r\n * This method assumes this
to be {@link #isAffine() affine}.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and Q
the rotation matrix obtained from the given quaternion,\r\n * then the new matrix will be M * Q
. So when transforming a\r\n * vector v
with the new matrix by using M * Q * v
,\r\n * the quaternion rotation will be applied first!\r\n *
\r\n * In order to set the matrix to a rotation transformation without post-multiplying,\r\n * use {@link #rotation(Quaternionf)}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotation(Quaternionf)\r\n * \r\n * @param quat\r\n * the {@link Quaternionf}\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateAffine(Quaternionf quat, Matrix4f dest) {\r\n float dqx = quat.x + quat.x;\r\n float dqy = quat.y + quat.y;\r\n float dqz = quat.z + quat.z;\r\n float q00 = dqx * quat.x;\r\n float q11 = dqy * quat.y;\r\n float q22 = dqz * quat.z;\r\n float q01 = dqx * quat.y;\r\n float q02 = dqx * quat.z;\r\n float q03 = dqx * quat.w;\r\n float q12 = dqy * quat.z;\r\n float q13 = dqy * quat.w;\r\n float q23 = dqz * quat.w;\r\n\r\n float rm00 = 1.0f - q11 - q22;\r\n float rm01 = q01 + q23;\r\n float rm02 = q02 - q13;\r\n float rm10 = q01 - q23;\r\n float rm11 = 1.0f - q22 - q00;\r\n float rm12 = q12 + q03;\r\n float rm20 = q02 + q13;\r\n float rm21 = q12 - q03;\r\n float rm22 = 1.0f - q11 - q00;\r\n\r\n float nm00 = m00 * rm00 + m10 * rm01 + m20 * rm02;\r\n float nm01 = m01 * rm00 + m11 * rm01 + m21 * rm02;\r\n float nm02 = m02 * rm00 + m12 * rm01 + m22 * rm02;\r\n float nm10 = m00 * rm10 + m10 * rm11 + m20 * rm12;\r\n float nm11 = m01 * rm10 + m11 * rm11 + m21 * rm12;\r\n float nm12 = m02 * rm10 + m12 * rm11 + m22 * rm12;\r\n dest.m20 = m00 * rm20 + m10 * rm21 + m20 * rm22;\r\n dest.m21 = m01 * rm20 + m11 * rm21 + m21 * rm22;\r\n dest.m22 = m02 * rm20 + m12 * rm21 + m22 * rm22;\r\n dest.m23 = 0.0f;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = 0.0f;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = 0.0f;\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply the rotation transformation of the given {@link Quaternionf} to this matrix.\r\n *
\r\n * This method assumes this
to be {@link #isAffine() affine}.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and Q
the rotation matrix obtained from the given quaternion,\r\n * then the new matrix will be M * Q
. So when transforming a\r\n * vector v
with the new matrix by using M * Q * v
,\r\n * the quaternion rotation will be applied first!\r\n *
\r\n * In order to set the matrix to a rotation transformation without post-multiplying,\r\n * use {@link #rotation(Quaternionf)}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotation(Quaternionf)\r\n * \r\n * @param quat\r\n * the {@link Quaternionf}\r\n * @return this\r\n */\r\n public Matrix4f rotateAffine(Quaternionf quat) {\r\n return rotateAffine(quat, this);\r\n }\r\n\r\n /**\r\n * Pre-multiply the rotation transformation of the given {@link Quaternionf} to this {@link #isAffine() affine} matrix and store\r\n * the result in dest
.\r\n *
\r\n * This method assumes this
to be {@link #isAffine() affine}.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and Q
the rotation matrix obtained from the given quaternion,\r\n * then the new matrix will be Q * M
. So when transforming a\r\n * vector v
with the new matrix by using Q * M * v
,\r\n * the quaternion rotation will be applied last!\r\n *
\r\n * In order to set the matrix to a rotation transformation without pre-multiplying,\r\n * use {@link #rotation(Quaternionf)}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotation(Quaternionf)\r\n * \r\n * @param quat\r\n * the {@link Quaternionf}\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateAffineLocal(Quaternionf quat, Matrix4f dest) {\r\n float dqx = quat.x + quat.x;\r\n float dqy = quat.y + quat.y;\r\n float dqz = quat.z + quat.z;\r\n float q00 = dqx * quat.x;\r\n float q11 = dqy * quat.y;\r\n float q22 = dqz * quat.z;\r\n float q01 = dqx * quat.y;\r\n float q02 = dqx * quat.z;\r\n float q03 = dqx * quat.w;\r\n float q12 = dqy * quat.z;\r\n float q13 = dqy * quat.w;\r\n float q23 = dqz * quat.w;\r\n float lm00 = 1.0f - q11 - q22;\r\n float lm01 = q01 + q23;\r\n float lm02 = q02 - q13;\r\n float lm10 = q01 - q23;\r\n float lm11 = 1.0f - q22 - q00;\r\n float lm12 = q12 + q03;\r\n float lm20 = q02 + q13;\r\n float lm21 = q12 - q03;\r\n float lm22 = 1.0f - q11 - q00;\r\n float nm00 = lm00 * m00 + lm10 * m01 + lm20 * m02;\r\n float nm01 = lm01 * m00 + lm11 * m01 + lm21 * m02;\r\n float nm02 = lm02 * m00 + lm12 * m01 + lm22 * m02;\r\n float nm03 = 0.0f;\r\n float nm10 = lm00 * m10 + lm10 * m11 + lm20 * m12;\r\n float nm11 = lm01 * m10 + lm11 * m11 + lm21 * m12;\r\n float nm12 = lm02 * m10 + lm12 * m11 + lm22 * m12;\r\n float nm13 = 0.0f;\r\n float nm20 = lm00 * m20 + lm10 * m21 + lm20 * m22;\r\n float nm21 = lm01 * m20 + lm11 * m21 + lm21 * m22;\r\n float nm22 = lm02 * m20 + lm12 * m21 + lm22 * m22;\r\n float nm23 = 0.0f;\r\n float nm30 = lm00 * m30 + lm10 * m31 + lm20 * m32;\r\n float nm31 = lm01 * m30 + lm11 * m31 + lm21 * m32;\r\n float nm32 = lm02 * m30 + lm12 * m31 + lm22 * m32;\r\n float nm33 = 1.0f;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Pre-multiply the rotation transformation of the given {@link Quaternionf} to this matrix.\r\n *
\r\n * This method assumes this
to be {@link #isAffine() affine}.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and Q
the rotation matrix obtained from the given quaternion,\r\n * then the new matrix will be Q * M
. So when transforming a\r\n * vector v
with the new matrix by using Q * M * v
,\r\n * the quaternion rotation will be applied last!\r\n *
\r\n * In order to set the matrix to a rotation transformation without pre-multiplying,\r\n * use {@link #rotation(Quaternionf)}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotation(Quaternionf)\r\n * \r\n * @param quat\r\n * the {@link Quaternionf}\r\n * @return this\r\n */\r\n public Matrix4f rotateAffineLocal(Quaternionf quat) {\r\n return rotateAffineLocal(quat, this);\r\n }\r\n\r\n /**\r\n * Apply a rotation transformation, rotating about the given {@link AxisAngle4f}, to this matrix.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and A
the rotation matrix obtained from the given {@link AxisAngle4f},\r\n * then the new matrix will be M * A
. So when transforming a\r\n * vector v
with the new matrix by using M * A * v
,\r\n * the {@link AxisAngle4f} rotation will be applied first!\r\n *
\r\n * In order to set the matrix to a rotation transformation without post-multiplying,\r\n * use {@link #rotation(AxisAngle4f)}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotate(float, float, float, float)\r\n * @see #rotation(AxisAngle4f)\r\n * \r\n * @param axisAngle\r\n * the {@link AxisAngle4f} (needs to be {@link AxisAngle4f#normalize() normalized})\r\n * @return this\r\n */\r\n public Matrix4f rotate(AxisAngle4f axisAngle) {\r\n return rotate(axisAngle.angle, axisAngle.x, axisAngle.y, axisAngle.z);\r\n }\r\n\r\n /**\r\n * Apply a rotation transformation, rotating about the given {@link AxisAngle4f} and store the result in dest
.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and A
the rotation matrix obtained from the given {@link AxisAngle4f},\r\n * then the new matrix will be M * A
. So when transforming a\r\n * vector v
with the new matrix by using M * A * v
,\r\n * the {@link AxisAngle4f} rotation will be applied first!\r\n *
\r\n * In order to set the matrix to a rotation transformation without post-multiplying,\r\n * use {@link #rotation(AxisAngle4f)}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotate(float, float, float, float)\r\n * @see #rotation(AxisAngle4f)\r\n * \r\n * @param axisAngle\r\n * the {@link AxisAngle4f} (needs to be {@link AxisAngle4f#normalize() normalized})\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotate(AxisAngle4f axisAngle, Matrix4f dest) {\r\n return rotate(axisAngle.angle, axisAngle.x, axisAngle.y, axisAngle.z, dest);\r\n }\r\n\r\n /**\r\n * Apply a rotation transformation, rotating the given radians about the specified axis, to this matrix.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and A
the rotation matrix obtained from the given axis-angle,\r\n * then the new matrix will be M * A
. So when transforming a\r\n * vector v
with the new matrix by using M * A * v
,\r\n * the axis-angle rotation will be applied first!\r\n *
\r\n * In order to set the matrix to a rotation transformation without post-multiplying,\r\n * use {@link #rotation(float, Vector3f)}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotate(float, float, float, float)\r\n * @see #rotation(float, Vector3f)\r\n * \r\n * @param angle\r\n * the angle in radians\r\n * @param axis\r\n * the rotation axis (needs to be {@link Vector3f#normalize() normalized})\r\n * @return this\r\n */\r\n public Matrix4f rotate(float angle, Vector3f axis) {\r\n return rotate(angle, axis.x, axis.y, axis.z);\r\n }\r\n\r\n /**\r\n * Apply a rotation transformation, rotating the given radians about the specified axis and store the result in dest
.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and A
the rotation matrix obtained from the given axis-angle,\r\n * then the new matrix will be M * A
. So when transforming a\r\n * vector v
with the new matrix by using M * A * v
,\r\n * the axis-angle rotation will be applied first!\r\n *
\r\n * In order to set the matrix to a rotation transformation without post-multiplying,\r\n * use {@link #rotation(float, Vector3f)}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotate(float, float, float, float)\r\n * @see #rotation(float, Vector3f)\r\n * \r\n * @param angle\r\n * the angle in radians\r\n * @param axis\r\n * the rotation axis (needs to be {@link Vector3f#normalize() normalized})\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotate(float angle, Vector3f axis, Matrix4f dest) {\r\n return rotate(angle, axis.x, axis.y, axis.z, dest);\r\n }\r\n\r\n /**\r\n * Unproject the given window coordinates (winX, winY, winZ) by this
matrix using the specified viewport.\r\n *
\r\n * This method first converts the given window coordinates to normalized device coordinates in the range [-1..1]\r\n * and then transforms those NDC coordinates by the inverse of this
matrix. \r\n *
\r\n * The depth range of winZ is assumed to be [0..1], which is also the OpenGL default.\r\n *
\r\n * As a necessary computation step for unprojecting, this method computes the inverse of this
matrix.\r\n * In order to avoid computing the matrix inverse with every invocation, the inverse of this
matrix can be built\r\n * once outside using {@link #invert(Matrix4f)} and then the method {@link #unprojectInv(float, float, float, int[], Vector4f) unprojectInv()} can be invoked on it.\r\n * \r\n * @see #unprojectInv(float, float, float, int[], Vector4f)\r\n * @see #invert(Matrix4f)\r\n * \r\n * @param winX\r\n * the x-coordinate in window coordinates (pixels)\r\n * @param winY\r\n * the y-coordinate in window coordinates (pixels)\r\n * @param winZ\r\n * the z-coordinate, which is the depth value in [0..1]\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param dest\r\n * will hold the unprojected position\r\n * @return dest\r\n */\r\n public Vector4f unproject(float winX, float winY, float winZ, int[] viewport, Vector4f dest) {\r\n float a = m00 * m11 - m01 * m10;\r\n float b = m00 * m12 - m02 * m10;\r\n float c = m00 * m13 - m03 * m10;\r\n float d = m01 * m12 - m02 * m11;\r\n float e = m01 * m13 - m03 * m11;\r\n float f = m02 * m13 - m03 * m12;\r\n float g = m20 * m31 - m21 * m30;\r\n float h = m20 * m32 - m22 * m30;\r\n float i = m20 * m33 - m23 * m30;\r\n float j = m21 * m32 - m22 * m31;\r\n float k = m21 * m33 - m23 * m31;\r\n float l = m22 * m33 - m23 * m32;\r\n float det = a * l - b * k + c * j + d * i - e * h + f * g;\r\n det = 1.0f / det;\r\n float im00 = ( m11 * l - m12 * k + m13 * j) * det;\r\n float im01 = (-m01 * l + m02 * k - m03 * j) * det;\r\n float im02 = ( m31 * f - m32 * e + m33 * d) * det;\r\n float im03 = (-m21 * f + m22 * e - m23 * d) * det;\r\n float im10 = (-m10 * l + m12 * i - m13 * h) * det;\r\n float im11 = ( m00 * l - m02 * i + m03 * h) * det;\r\n float im12 = (-m30 * f + m32 * c - m33 * b) * det;\r\n float im13 = ( m20 * f - m22 * c + m23 * b) * det;\r\n float im20 = ( m10 * k - m11 * i + m13 * g) * det;\r\n float im21 = (-m00 * k + m01 * i - m03 * g) * det;\r\n float im22 = ( m30 * e - m31 * c + m33 * a) * det;\r\n float im23 = (-m20 * e + m21 * c - m23 * a) * det;\r\n float im30 = (-m10 * j + m11 * h - m12 * g) * det;\r\n float im31 = ( m00 * j - m01 * h + m02 * g) * det;\r\n float im32 = (-m30 * d + m31 * b - m32 * a) * det;\r\n float im33 = ( m20 * d - m21 * b + m22 * a) * det;\r\n float ndcX = (winX-viewport[0])/viewport[2]*2.0f-1.0f;\r\n float ndcY = (winY-viewport[1])/viewport[3]*2.0f-1.0f;\r\n float ndcZ = winZ+winZ-1.0f;\r\n dest.x = im00 * ndcX + im10 * ndcY + im20 * ndcZ + im30;\r\n dest.y = im01 * ndcX + im11 * ndcY + im21 * ndcZ + im31;\r\n dest.z = im02 * ndcX + im12 * ndcY + im22 * ndcZ + im32;\r\n dest.w = im03 * ndcX + im13 * ndcY + im23 * ndcZ + im33;\r\n dest.div(dest.w);\r\n return dest;\r\n }\r\n\r\n /**\r\n * Unproject the given window coordinates (winX, winY, winZ) by this
matrix using the specified viewport.\r\n *
\r\n * This method first converts the given window coordinates to normalized device coordinates in the range [-1..1]\r\n * and then transforms those NDC coordinates by the inverse of this
matrix. \r\n *
\r\n * The depth range of winZ is assumed to be [0..1], which is also the OpenGL default.\r\n *
\r\n * As a necessary computation step for unprojecting, this method computes the inverse of this
matrix.\r\n * In order to avoid computing the matrix inverse with every invocation, the inverse of this
matrix can be built\r\n * once outside using {@link #invert(Matrix4f)} and then the method {@link #unprojectInv(float, float, float, int[], Vector4f) unprojectInv()} can be invoked on it.\r\n * \r\n * @see #unprojectInv(float, float, float, int[], Vector3f)\r\n * @see #invert(Matrix4f)\r\n * \r\n * @param winX\r\n * the x-coordinate in window coordinates (pixels)\r\n * @param winY\r\n * the y-coordinate in window coordinates (pixels)\r\n * @param winZ\r\n * the z-coordinate, which is the depth value in [0..1]\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param dest\r\n * will hold the unprojected position\r\n * @return dest\r\n */\r\n public Vector3f unproject(float winX, float winY, float winZ, int[] viewport, Vector3f dest) {\r\n float a = m00 * m11 - m01 * m10;\r\n float b = m00 * m12 - m02 * m10;\r\n float c = m00 * m13 - m03 * m10;\r\n float d = m01 * m12 - m02 * m11;\r\n float e = m01 * m13 - m03 * m11;\r\n float f = m02 * m13 - m03 * m12;\r\n float g = m20 * m31 - m21 * m30;\r\n float h = m20 * m32 - m22 * m30;\r\n float i = m20 * m33 - m23 * m30;\r\n float j = m21 * m32 - m22 * m31;\r\n float k = m21 * m33 - m23 * m31;\r\n float l = m22 * m33 - m23 * m32;\r\n float det = a * l - b * k + c * j + d * i - e * h + f * g;\r\n det = 1.0f / det;\r\n float im00 = ( m11 * l - m12 * k + m13 * j) * det;\r\n float im01 = (-m01 * l + m02 * k - m03 * j) * det;\r\n float im02 = ( m31 * f - m32 * e + m33 * d) * det;\r\n float im03 = (-m21 * f + m22 * e - m23 * d) * det;\r\n float im10 = (-m10 * l + m12 * i - m13 * h) * det;\r\n float im11 = ( m00 * l - m02 * i + m03 * h) * det;\r\n float im12 = (-m30 * f + m32 * c - m33 * b) * det;\r\n float im13 = ( m20 * f - m22 * c + m23 * b) * det;\r\n float im20 = ( m10 * k - m11 * i + m13 * g) * det;\r\n float im21 = (-m00 * k + m01 * i - m03 * g) * det;\r\n float im22 = ( m30 * e - m31 * c + m33 * a) * det;\r\n float im23 = (-m20 * e + m21 * c - m23 * a) * det;\r\n float im30 = (-m10 * j + m11 * h - m12 * g) * det;\r\n float im31 = ( m00 * j - m01 * h + m02 * g) * det;\r\n float im32 = (-m30 * d + m31 * b - m32 * a) * det;\r\n float im33 = ( m20 * d - m21 * b + m22 * a) * det;\r\n float ndcX = (winX-viewport[0])/viewport[2]*2.0f-1.0f;\r\n float ndcY = (winY-viewport[1])/viewport[3]*2.0f-1.0f;\r\n float ndcZ = winZ+winZ-1.0f;\r\n dest.x = im00 * ndcX + im10 * ndcY + im20 * ndcZ + im30;\r\n dest.y = im01 * ndcX + im11 * ndcY + im21 * ndcZ + im31;\r\n dest.z = im02 * ndcX + im12 * ndcY + im22 * ndcZ + im32;\r\n float w = im03 * ndcX + im13 * ndcY + im23 * ndcZ + im33;\r\n dest.div(w);\r\n return dest;\r\n }\r\n\r\n /**\r\n * Unproject the given window coordinates winCoords
by this
matrix using the specified viewport.\r\n *
\r\n * This method first converts the given window coordinates to normalized device coordinates in the range [-1..1]\r\n * and then transforms those NDC coordinates by the inverse of this
matrix. \r\n *
\r\n * The depth range of winCoords.z is assumed to be [0..1], which is also the OpenGL default.\r\n *
\r\n * As a necessary computation step for unprojecting, this method computes the inverse of this
matrix.\r\n * In order to avoid computing the matrix inverse with every invocation, the inverse of this
matrix can be built\r\n * once outside using {@link #invert(Matrix4f)} and then the method {@link #unprojectInv(float, float, float, int[], Vector4f) unprojectInv()} can be invoked on it.\r\n * \r\n * @see #unprojectInv(float, float, float, int[], Vector4f)\r\n * @see #unproject(float, float, float, int[], Vector4f)\r\n * @see #invert(Matrix4f)\r\n * \r\n * @param winCoords\r\n * the window coordinates to unproject\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param dest\r\n * will hold the unprojected position\r\n * @return dest\r\n */\r\n public Vector4f unproject(Vector3f winCoords, int[] viewport, Vector4f dest) {\r\n return unproject(winCoords.x, winCoords.y, winCoords.z, viewport, dest);\r\n }\r\n\r\n /**\r\n * Unproject the given window coordinates winCoords
by this
matrix using the specified viewport.\r\n *
\r\n * This method first converts the given window coordinates to normalized device coordinates in the range [-1..1]\r\n * and then transforms those NDC coordinates by the inverse of this
matrix. \r\n *
\r\n * The depth range of winCoords.z is assumed to be [0..1], which is also the OpenGL default.\r\n *
\r\n * As a necessary computation step for unprojecting, this method computes the inverse of this
matrix.\r\n * In order to avoid computing the matrix inverse with every invocation, the inverse of this
matrix can be built\r\n * once outside using {@link #invert(Matrix4f)} and then the method {@link #unprojectInv(float, float, float, int[], Vector3f) unprojectInv()} can be invoked on it.\r\n * \r\n * @see #unprojectInv(float, float, float, int[], Vector3f)\r\n * @see #unproject(float, float, float, int[], Vector3f)\r\n * @see #invert(Matrix4f)\r\n * \r\n * @param winCoords\r\n * the window coordinates to unproject\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param dest\r\n * will hold the unprojected position\r\n * @return dest\r\n */\r\n public Vector3f unproject(Vector3f winCoords, int[] viewport, Vector3f dest) {\r\n return unproject(winCoords.x, winCoords.y, winCoords.z, viewport, dest);\r\n }\r\n\r\n /**\r\n * Unproject the given window coordinates winCoords
by this
matrix using the specified viewport.\r\n *
\r\n * This method differs from {@link #unproject(Vector3f, int[], Vector4f) unproject()} \r\n * in that it assumes that this
is already the inverse matrix of the original projection matrix.\r\n * It exists to avoid recomputing the matrix inverse with every invocation.\r\n *
\r\n * The depth range of winCoords.z is assumed to be [0..1], which is also the OpenGL default.\r\n *
\r\n * This method reads the four viewport parameters from the current int[]'s {@link Buffer#position() position}\r\n * and does not modify the buffer's position.\r\n * \r\n * @see #unproject(Vector3f, int[], Vector4f)\r\n * \r\n * @param winCoords\r\n * the window coordinates to unproject\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param dest\r\n * will hold the unprojected position\r\n * @return dest\r\n */\r\n public Vector4f unprojectInv(Vector3f winCoords, int[] viewport, Vector4f dest) {\r\n return unprojectInv(winCoords.x, winCoords.y, winCoords.z, viewport, dest);\r\n }\r\n\r\n /**\r\n * Unproject the given window coordinates (winX, winY, winZ) by this
matrix using the specified viewport.\r\n *
\r\n * This method differs from {@link #unproject(float, float, float, int[], Vector4f) unproject()} \r\n * in that it assumes that this
is already the inverse matrix of the original projection matrix.\r\n * It exists to avoid recomputing the matrix inverse with every invocation.\r\n *
\r\n * The depth range of winZ is assumed to be [0..1], which is also the OpenGL default.\r\n * \r\n * @see #unproject(float, float, float, int[], Vector4f)\r\n * \r\n * @param winX\r\n * the x-coordinate in window coordinates (pixels)\r\n * @param winY\r\n * the y-coordinate in window coordinates (pixels)\r\n * @param winZ\r\n * the z-coordinate, which is the depth value in [0..1]\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param dest\r\n * will hold the unprojected position\r\n * @return dest\r\n */\r\n public Vector4f unprojectInv(float winX, float winY, float winZ, int[] viewport, Vector4f dest) {\r\n float ndcX = (winX-viewport[0])/viewport[2]*2.0f-1.0f;\r\n float ndcY = (winY-viewport[1])/viewport[3]*2.0f-1.0f;\r\n float ndcZ = winZ+winZ-1.0f;\r\n dest.x = m00 * ndcX + m10 * ndcY + m20 * ndcZ + m30;\r\n dest.y = m01 * ndcX + m11 * ndcY + m21 * ndcZ + m31;\r\n dest.z = m02 * ndcX + m12 * ndcY + m22 * ndcZ + m32;\r\n dest.w = m03 * ndcX + m13 * ndcY + m23 * ndcZ + m33;\r\n dest.div(dest.w);\r\n return dest;\r\n }\r\n\r\n /**\r\n * Unproject the given window coordinates winCoords
by this
matrix using the specified viewport.\r\n *
\r\n * This method differs from {@link #unproject(Vector3f, int[], Vector3f) unproject()} \r\n * in that it assumes that this
is already the inverse matrix of the original projection matrix.\r\n * It exists to avoid recomputing the matrix inverse with every invocation.\r\n *
\r\n * The depth range of winCoords.z is assumed to be [0..1], which is also the OpenGL default.\r\n * \r\n * @see #unproject(Vector3f, int[], Vector3f)\r\n * \r\n * @param winCoords\r\n * the window coordinates to unproject\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param dest\r\n * will hold the unprojected position\r\n * @return dest\r\n */\r\n public Vector3f unprojectInv(Vector3f winCoords, int[] viewport, Vector3f dest) {\r\n return unprojectInv(winCoords.x, winCoords.y, winCoords.z, viewport, dest);\r\n }\r\n\r\n /**\r\n * Unproject the given window coordinates (winX, winY, winZ) by this
matrix using the specified viewport.\r\n *
\r\n * This method differs from {@link #unproject(float, float, float, int[], Vector3f) unproject()} \r\n * in that it assumes that this
is already the inverse matrix of the original projection matrix.\r\n * It exists to avoid recomputing the matrix inverse with every invocation.\r\n *
\r\n * The depth range of winZ is assumed to be [0..1], which is also the OpenGL default.\r\n * \r\n * @see #unproject(float, float, float, int[], Vector3f)\r\n * \r\n * @param winX\r\n * the x-coordinate in window coordinates (pixels)\r\n * @param winY\r\n * the y-coordinate in window coordinates (pixels)\r\n * @param winZ\r\n * the z-coordinate, which is the depth value in [0..1]\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param dest\r\n * will hold the unprojected position\r\n * @return dest\r\n */\r\n public Vector3f unprojectInv(float winX, float winY, float winZ, int[] viewport, Vector3f dest) {\r\n float ndcX = (winX-viewport[0])/viewport[2]*2.0f-1.0f;\r\n float ndcY = (winY-viewport[1])/viewport[3]*2.0f-1.0f;\r\n float ndcZ = winZ+winZ-1.0f;\r\n dest.x = m00 * ndcX + m10 * ndcY + m20 * ndcZ + m30;\r\n dest.y = m01 * ndcX + m11 * ndcY + m21 * ndcZ + m31;\r\n dest.z = m02 * ndcX + m12 * ndcY + m22 * ndcZ + m32;\r\n float w = m03 * ndcX + m13 * ndcY + m23 * ndcZ + m33;\r\n dest.div(w);\r\n return dest;\r\n }\r\n\r\n /**\r\n * Project the given (x, y, z) position via this
matrix using the specified viewport\r\n * and store the resulting window coordinates in winCoordsDest
.\r\n *
\r\n * This method transforms the given coordinates by this
matrix including perspective division to \r\n * obtain normalized device coordinates, and then translates these into window coordinates by using the\r\n * given viewport
settings [x, y, width, height].\r\n *
\r\n * The depth range of the returned winCoordsDest.z
will be [0..1], which is also the OpenGL default. \r\n * \r\n * @param x\r\n * the x-coordinate of the position to project\r\n * @param y\r\n * the y-coordinate of the position to project\r\n * @param z\r\n * the z-coordinate of the position to project\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param winCoordsDest\r\n * will hold the projected window coordinates\r\n * @return winCoordsDest\r\n */\r\n public Vector4f project(float x, float y, float z, int[] viewport, Vector4f winCoordsDest) {\r\n winCoordsDest.x = m00 * x + m10 * y + m20 * z + m30;\r\n winCoordsDest.y = m01 * x + m11 * y + m21 * z + m31;\r\n winCoordsDest.z = m02 * x + m12 * y + m22 * z + m32;\r\n winCoordsDest.w = m03 * x + m13 * y + m23 * z + m33;\r\n winCoordsDest.div(winCoordsDest.w);\r\n winCoordsDest.x = (winCoordsDest.x*0.5f+0.5f) * viewport[2] + viewport[0];\r\n winCoordsDest.y = (winCoordsDest.y*0.5f+0.5f) * viewport[3] + viewport[1];\r\n winCoordsDest.z = (1.0f+winCoordsDest.z)*0.5f;\r\n return winCoordsDest;\r\n }\r\n\r\n /**\r\n * Project the given (x, y, z) position via this
matrix using the specified viewport\r\n * and store the resulting window coordinates in winCoordsDest
.\r\n *
\r\n * This method transforms the given coordinates by this
matrix including perspective division to \r\n * obtain normalized device coordinates, and then translates these into window coordinates by using the\r\n * given viewport
settings [x, y, width, height].\r\n *
\r\n * The depth range of the returned winCoordsDest.z
will be [0..1], which is also the OpenGL default. \r\n * \r\n * @param x\r\n * the x-coordinate of the position to project\r\n * @param y\r\n * the y-coordinate of the position to project\r\n * @param z\r\n * the z-coordinate of the position to project\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param winCoordsDest\r\n * will hold the projected window coordinates\r\n * @return winCoordsDest\r\n */\r\n public Vector3f project(float x, float y, float z, int[] viewport, Vector3f winCoordsDest) {\r\n winCoordsDest.x = m00 * x + m10 * y + m20 * z + m30;\r\n winCoordsDest.y = m01 * x + m11 * y + m21 * z + m31;\r\n winCoordsDest.z = m02 * x + m12 * y + m22 * z + m32;\r\n float w = m03 * x + m13 * y + m23 * z + m33;\r\n winCoordsDest.div(w);\r\n winCoordsDest.x = (winCoordsDest.x*0.5f+0.5f) * viewport[2] + viewport[0];\r\n winCoordsDest.y = (winCoordsDest.y*0.5f+0.5f) * viewport[3] + viewport[1];\r\n winCoordsDest.z = (1.0f+winCoordsDest.z)*0.5f;\r\n return winCoordsDest;\r\n }\r\n\r\n /**\r\n * Project the given position
via this
matrix using the specified viewport\r\n * and store the resulting window coordinates in winCoordsDest
.\r\n *
\r\n * This method transforms the given coordinates by this
matrix including perspective division to \r\n * obtain normalized device coordinates, and then translates these into window coordinates by using the\r\n * given viewport
settings [x, y, width, height].\r\n *
\r\n * The depth range of the returned winCoordsDest.z
will be [0..1], which is also the OpenGL default. \r\n * \r\n * @see #project(float, float, float, int[], Vector4f)\r\n * \r\n * @param position\r\n * the position to project into window coordinates\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param winCoordsDest\r\n * will hold the projected window coordinates\r\n * @return winCoordsDest\r\n */\r\n public Vector4f project(Vector3f position, int[] viewport, Vector4f winCoordsDest) {\r\n return project(position.x, position.y, position.z, viewport, winCoordsDest);\r\n }\r\n\r\n /**\r\n * Project the given position
via this
matrix using the specified viewport\r\n * and store the resulting window coordinates in winCoordsDest
.\r\n *
\r\n * This method transforms the given coordinates by this
matrix including perspective division to \r\n * obtain normalized device coordinates, and then translates these into window coordinates by using the\r\n * given viewport
settings [x, y, width, height].\r\n *
\r\n * The depth range of the returned winCoordsDest.z
will be [0..1], which is also the OpenGL default. \r\n * \r\n * @see #project(float, float, float, int[], Vector4f)\r\n * \r\n * @param position\r\n * the position to project into window coordinates\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param winCoordsDest\r\n * will hold the projected window coordinates\r\n * @return winCoordsDest\r\n */\r\n public Vector3f project(Vector3f position, int[] viewport, Vector3f winCoordsDest) {\r\n return project(position.x, position.y, position.z, viewport, winCoordsDest);\r\n }\r\n\r\n /**\r\n * Apply a mirror/reflection transformation to this matrix that reflects about the given plane\r\n * specified via the equation x*a + y*b + z*c + d = 0 and store the result in dest
.\r\n *
\r\n * The vector (a, b, c) must be a unit vector.\r\n *
\r\n * If M
is this
matrix and R
the reflection matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * reflection will be applied first!\r\n *
\r\n * Reference: msdn.microsoft.com\r\n * \r\n * @param a\r\n * the x factor in the plane equation\r\n * @param b\r\n * the y factor in the plane equation\r\n * @param c\r\n * the z factor in the plane equation\r\n * @param d\r\n * the constant in the plane equation\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f reflect(float a, float b, float c, float d, Matrix4f dest) {\r\n float da = a + a, db = b + b, dc = c + c, dd = d + d;\r\n float rm00 = 1.0f - da * a;\r\n float rm01 = -da * b;\r\n float rm02 = -da * c;\r\n float rm10 = -db * a;\r\n float rm11 = 1.0f - db * b;\r\n float rm12 = -db * c;\r\n float rm20 = -dc * a;\r\n float rm21 = -dc * b;\r\n float rm22 = 1.0f - dc * c;\r\n float rm30 = -dd * a;\r\n float rm31 = -dd * b;\r\n float rm32 = -dd * c;\r\n\r\n // matrix multiplication\r\n dest.m30 = m00 * rm30 + m10 * rm31 + m20 * rm32 + m30;\r\n dest.m31 = m01 * rm30 + m11 * rm31 + m21 * rm32 + m31;\r\n dest.m32 = m02 * rm30 + m12 * rm31 + m22 * rm32 + m32;\r\n dest.m33 = m03 * rm30 + m13 * rm31 + m23 * rm32 + m33;\r\n float nm00 = m00 * rm00 + m10 * rm01 + m20 * rm02;\r\n float nm01 = m01 * rm00 + m11 * rm01 + m21 * rm02;\r\n float nm02 = m02 * rm00 + m12 * rm01 + m22 * rm02;\r\n float nm03 = m03 * rm00 + m13 * rm01 + m23 * rm02;\r\n float nm10 = m00 * rm10 + m10 * rm11 + m20 * rm12;\r\n float nm11 = m01 * rm10 + m11 * rm11 + m21 * rm12;\r\n float nm12 = m02 * rm10 + m12 * rm11 + m22 * rm12;\r\n float nm13 = m03 * rm10 + m13 * rm11 + m23 * rm12;\r\n dest.m20 = m00 * rm20 + m10 * rm21 + m20 * rm22;\r\n dest.m21 = m01 * rm20 + m11 * rm21 + m21 * rm22;\r\n dest.m22 = m02 * rm20 + m12 * rm21 + m22 * rm22;\r\n dest.m23 = m03 * rm20 + m13 * rm21 + m23 * rm22;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply a mirror/reflection transformation to this matrix that reflects about the given plane\r\n * specified via the equation x*a + y*b + z*c + d = 0.\r\n *
\r\n * The vector (a, b, c) must be a unit vector.\r\n *
\r\n * If M
is this
matrix and R
the reflection matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * reflection will be applied first!\r\n *
\r\n * Reference: msdn.microsoft.com\r\n * \r\n * @param a\r\n * the x factor in the plane equation\r\n * @param b\r\n * the y factor in the plane equation\r\n * @param c\r\n * the z factor in the plane equation\r\n * @param d\r\n * the constant in the plane equation\r\n * @return this\r\n */\r\n public Matrix4f reflect(float a, float b, float c, float d) {\r\n return reflect(a, b, c, d, this);\r\n }\r\n\r\n /**\r\n * Apply a mirror/reflection transformation to this matrix that reflects about the given plane\r\n * specified via the plane normal and a point on the plane.\r\n *
\r\n * If M
is this
matrix and R
the reflection matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * reflection will be applied first!\r\n * \r\n * @param nx\r\n * the x-coordinate of the plane normal\r\n * @param ny\r\n * the y-coordinate of the plane normal\r\n * @param nz\r\n * the z-coordinate of the plane normal\r\n * @param px\r\n * the x-coordinate of a point on the plane\r\n * @param py\r\n * the y-coordinate of a point on the plane\r\n * @param pz\r\n * the z-coordinate of a point on the plane\r\n * @return this\r\n */\r\n public Matrix4f reflect(float nx, float ny, float nz, float px, float py, float pz) {\r\n return reflect(nx, ny, nz, px, py, pz, this);\r\n }\r\n\r\n /**\r\n * Apply a mirror/reflection transformation to this matrix that reflects about the given plane\r\n * specified via the plane normal and a point on the plane, and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and R
the reflection matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * reflection will be applied first!\r\n * \r\n * @param nx\r\n * the x-coordinate of the plane normal\r\n * @param ny\r\n * the y-coordinate of the plane normal\r\n * @param nz\r\n * the z-coordinate of the plane normal\r\n * @param px\r\n * the x-coordinate of a point on the plane\r\n * @param py\r\n * the y-coordinate of a point on the plane\r\n * @param pz\r\n * the z-coordinate of a point on the plane\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f reflect(float nx, float ny, float nz, float px, float py, float pz, Matrix4f dest) {\r\n float invLength = 1.0f / (float) Math.sqrt(nx * nx + ny * ny + nz * nz);\r\n float nnx = nx * invLength;\r\n float nny = ny * invLength;\r\n float nnz = nz * invLength;\r\n /* See: http://mathworld.wolfram.com/Plane.html */\r\n return reflect(nnx, nny, nnz, -nnx * px - nny * py - nnz * pz, dest);\r\n }\r\n\r\n /**\r\n * Apply a mirror/reflection transformation to this matrix that reflects about the given plane\r\n * specified via the plane normal and a point on the plane.\r\n *
\r\n * If M
is this
matrix and R
the reflection matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * reflection will be applied first!\r\n * \r\n * @param normal\r\n * the plane normal\r\n * @param point\r\n * a point on the plane\r\n * @return this\r\n */\r\n public Matrix4f reflect(Vector3f normal, Vector3f point) {\r\n return reflect(normal.x, normal.y, normal.z, point.x, point.y, point.z);\r\n }\r\n\r\n /**\r\n * Apply a mirror/reflection transformation to this matrix that reflects about a plane\r\n * specified via the plane orientation and a point on the plane.\r\n *
\r\n * This method can be used to build a reflection transformation based on the orientation of a mirror object in the scene.\r\n * It is assumed that the default mirror plane's normal is (0, 0, 1). So, if the given {@link Quaternionf} is\r\n * the identity (does not apply any additional rotation), the reflection plane will be z=0, offset by the given point
.\r\n *
\r\n * If M
is this
matrix and R
the reflection matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * reflection will be applied first!\r\n * \r\n * @param orientation\r\n * the plane orientation\r\n * @param point\r\n * a point on the plane\r\n * @return this\r\n */\r\n public Matrix4f reflect(Quaternionf orientation, Vector3f point) {\r\n return reflect(orientation, point, this);\r\n }\r\n\r\n /**\r\n * Apply a mirror/reflection transformation to this matrix that reflects about a plane\r\n * specified via the plane orientation and a point on the plane, and store the result in dest
.\r\n *
\r\n * This method can be used to build a reflection transformation based on the orientation of a mirror object in the scene.\r\n * It is assumed that the default mirror plane's normal is (0, 0, 1). So, if the given {@link Quaternionf} is\r\n * the identity (does not apply any additional rotation), the reflection plane will be z=0, offset by the given point
.\r\n *
\r\n * If M
is this
matrix and R
the reflection matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * reflection will be applied first!\r\n * \r\n * @param orientation\r\n * the plane orientation relative to an implied normal vector of (0, 0, 1)\r\n * @param point\r\n * a point on the plane\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f reflect(Quaternionf orientation, Vector3f point, Matrix4f dest) {\r\n double num1 = orientation.x + orientation.x;\r\n double num2 = orientation.y + orientation.y;\r\n double num3 = orientation.z + orientation.z;\r\n float normalX = (float) (orientation.x * num3 + orientation.w * num2);\r\n float normalY = (float) (orientation.y * num3 - orientation.w * num1);\r\n float normalZ = (float) (1.0 - (orientation.x * num1 + orientation.y * num2));\r\n return reflect(normalX, normalY, normalZ, point.x, point.y, point.z, dest);\r\n }\r\n\r\n /**\r\n * Apply a mirror/reflection transformation to this matrix that reflects about the given plane\r\n * specified via the plane normal and a point on the plane, and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and R
the reflection matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * reflection will be applied first!\r\n * \r\n * @param normal\r\n * the plane normal\r\n * @param point\r\n * a point on the plane\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f reflect(Vector3f normal, Vector3f point, Matrix4f dest) {\r\n return reflect(normal.x, normal.y, normal.z, point.x, point.y, point.z, dest);\r\n }\r\n\r\n /**\r\n * Set this matrix to a mirror/reflection transformation that reflects about the given plane\r\n * specified via the equation x*a + y*b + z*c + d = 0.\r\n *
\r\n * The vector (a, b, c) must be a unit vector.\r\n *
\r\n * Reference: msdn.microsoft.com\r\n * \r\n * @param a\r\n * the x factor in the plane equation\r\n * @param b\r\n * the y factor in the plane equation\r\n * @param c\r\n * the z factor in the plane equation\r\n * @param d\r\n * the constant in the plane equation\r\n * @return this\r\n */\r\n public Matrix4f reflection(float a, float b, float c, float d) {\r\n float da = a + a, db = b + b, dc = c + c, dd = d + d;\r\n m00 = 1.0f - da * a;\r\n m01 = -da * b;\r\n m02 = -da * c;\r\n m03 = 0.0f;\r\n m10 = -db * a;\r\n m11 = 1.0f - db * b;\r\n m12 = -db * c;\r\n m13 = 0.0f;\r\n m20 = -dc * a;\r\n m21 = -dc * b;\r\n m22 = 1.0f - dc * c;\r\n m23 = 0.0f;\r\n m30 = -dd * a;\r\n m31 = -dd * b;\r\n m32 = -dd * c;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to a mirror/reflection transformation that reflects about the given plane\r\n * specified via the plane normal and a point on the plane.\r\n * \r\n * @param nx\r\n * the x-coordinate of the plane normal\r\n * @param ny\r\n * the y-coordinate of the plane normal\r\n * @param nz\r\n * the z-coordinate of the plane normal\r\n * @param px\r\n * the x-coordinate of a point on the plane\r\n * @param py\r\n * the y-coordinate of a point on the plane\r\n * @param pz\r\n * the z-coordinate of a point on the plane\r\n * @return this\r\n */\r\n public Matrix4f reflection(float nx, float ny, float nz, float px, float py, float pz) {\r\n float invLength = 1.0f / (float) Math.sqrt(nx * nx + ny * ny + nz * nz);\r\n float nnx = nx * invLength;\r\n float nny = ny * invLength;\r\n float nnz = nz * invLength;\r\n /* See: http://mathworld.wolfram.com/Plane.html */\r\n return reflection(nnx, nny, nnz, -nnx * px - nny * py - nnz * pz);\r\n }\r\n\r\n /**\r\n * Set this matrix to a mirror/reflection transformation that reflects about the given plane\r\n * specified via the plane normal and a point on the plane.\r\n * \r\n * @param normal\r\n * the plane normal\r\n * @param point\r\n * a point on the plane\r\n * @return this\r\n */\r\n public Matrix4f reflection(Vector3f normal, Vector3f point) {\r\n return reflection(normal.x, normal.y, normal.z, point.x, point.y, point.z);\r\n }\r\n\r\n /**\r\n * Set this matrix to a mirror/reflection transformation that reflects about a plane\r\n * specified via the plane orientation and a point on the plane.\r\n *
\r\n * This method can be used to build a reflection transformation based on the orientation of a mirror object in the scene.\r\n * It is assumed that the default mirror plane's normal is (0, 0, 1). So, if the given {@link Quaternionf} is\r\n * the identity (does not apply any additional rotation), the reflection plane will be z=0, offset by the given point
.\r\n * \r\n * @param orientation\r\n * the plane orientation\r\n * @param point\r\n * a point on the plane\r\n * @return this\r\n */\r\n public Matrix4f reflection(Quaternionf orientation, Vector3f point) {\r\n double num1 = orientation.x + orientation.x;\r\n double num2 = orientation.y + orientation.y;\r\n double num3 = orientation.z + orientation.z;\r\n float normalX = (float) (orientation.x * num3 + orientation.w * num2);\r\n float normalY = (float) (orientation.y * num3 - orientation.w * num1);\r\n float normalZ = (float) (1.0 - (orientation.x * num1 + orientation.y * num2));\r\n return reflection(normalX, normalY, normalZ, point.x, point.y, point.z);\r\n }\r\n\r\n /**\r\n * Get the row at the given row
index, starting with 0
.\r\n * \r\n * @param row\r\n * the row index in [0..3]\r\n * @param dest\r\n * will hold the row components\r\n * @return the passed in destination\r\n * @throws IndexOutOfBoundsException if row
is not in [0..3]\r\n */\r\n public Vector4f getRow(int row, Vector4f dest) throws IndexOutOfBoundsException {\r\n switch (row) {\r\n case 0:\r\n dest.x = m00;\r\n dest.y = m10;\r\n dest.z = m20;\r\n dest.w = m30;\r\n break;\r\n case 1:\r\n dest.x = m01;\r\n dest.y = m11;\r\n dest.z = m21;\r\n dest.w = m31;\r\n break;\r\n case 2:\r\n dest.x = m02;\r\n dest.y = m12;\r\n dest.z = m22;\r\n dest.w = m32;\r\n break;\r\n case 3:\r\n dest.x = m03;\r\n dest.y = m13;\r\n dest.z = m23;\r\n dest.w = m33;\r\n break;\r\n default:\r\n throw new IndexOutOfBoundsException();\r\n }\r\n return dest;\r\n }\r\n\r\n /**\r\n * Get the column at the given column
index, starting with 0
.\r\n * \r\n * @param column\r\n * the column index in [0..3]\r\n * @param dest\r\n * will hold the column components\r\n * @return the passed in destination\r\n * @throws IndexOutOfBoundsException if column
is not in [0..3]\r\n */\r\n public Vector4f getColumn(int column, Vector4f dest) throws IndexOutOfBoundsException {\r\n switch (column) {\r\n case 0:\r\n dest.x = m00;\r\n dest.y = m01;\r\n dest.z = m02;\r\n dest.w = m03;\r\n break;\r\n case 1:\r\n dest.x = m10;\r\n dest.y = m11;\r\n dest.z = m12;\r\n dest.w = m13;\r\n break;\r\n case 2:\r\n dest.x = m20;\r\n dest.y = m21;\r\n dest.z = m22;\r\n dest.w = m23;\r\n break;\r\n case 3:\r\n dest.x = m30;\r\n dest.y = m31;\r\n dest.z = m32;\r\n dest.w = m32;\r\n break;\r\n default:\r\n throw new IndexOutOfBoundsException();\r\n }\r\n return dest;\r\n }\r\n\r\n /**\r\n * Compute a normal matrix from the upper left 3x3 submatrix of this
\r\n * and store it into the upper left 3x3 submatrix of this
.\r\n * All other values of this
will be set to {@link #identity() identity}.\r\n *
\r\n * The normal matrix of m is the transpose of the inverse of m.\r\n *
\r\n * Please note that, if this
is an orthogonal matrix or a matrix whose columns are orthogonal vectors, \r\n * then this method need not be invoked, since in that case this
itself is its normal matrix.\r\n * In that case, use {@link #set3x3(Matrix4f)} to set a given Matrix4f to only the upper left 3x3 submatrix\r\n * of this matrix.\r\n * \r\n * @see #set3x3(Matrix4f)\r\n * \r\n * @return this\r\n */\r\n public Matrix4f normal() {\r\n return normal(this);\r\n }\r\n\r\n /**\r\n * Compute a normal matrix from the upper left 3x3 submatrix of this
\r\n * and store it into the upper left 3x3 submatrix of dest
.\r\n * All other values of dest
will be set to {@link #identity() identity}.\r\n *
\r\n * The normal matrix of m is the transpose of the inverse of m.\r\n *
\r\n * Please note that, if this
is an orthogonal matrix or a matrix whose columns are orthogonal vectors, \r\n * then this method need not be invoked, since in that case this
itself is its normal matrix.\r\n * In that case, use {@link #set3x3(Matrix4f)} to set a given Matrix4f to only the upper left 3x3 submatrix\r\n * of this matrix.\r\n * \r\n * @see #set3x3(Matrix4f)\r\n * \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f normal(Matrix4f dest) {\r\n float det = determinant3x3();\r\n float s = 1.0f / det;\r\n /* Invert and transpose in one go */\r\n float nm00 = (m11 * m22 - m21 * m12) * s;\r\n float nm01 = (m20 * m12 - m10 * m22) * s;\r\n float nm02 = (m10 * m21 - m20 * m11) * s;\r\n float nm03 = 0.0f;\r\n float nm10 = (m21 * m02 - m01 * m22) * s;\r\n float nm11 = (m00 * m22 - m20 * m02) * s;\r\n float nm12 = (m20 * m01 - m00 * m21) * s;\r\n float nm13 = 0.0f;\r\n float nm20 = (m01 * m12 - m11 * m02) * s;\r\n float nm21 = (m10 * m02 - m00 * m12) * s;\r\n float nm22 = (m00 * m11 - m10 * m01) * s;\r\n float nm23 = 0.0f;\r\n float nm30 = 0.0f;\r\n float nm31 = 0.0f;\r\n float nm32 = 0.0f;\r\n float nm33 = 1.0f;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Compute a normal matrix from the upper left 3x3 submatrix of this
\r\n * and store it into dest
.\r\n *
\r\n * The normal matrix of m is the transpose of the inverse of m.\r\n *
\r\n * Please note that, if this
is an orthogonal matrix or a matrix whose columns are orthogonal vectors, \r\n * then this method need not be invoked, since in that case this
itself is its normal matrix.\r\n * In that case, use {@link Matrix3f#set(Matrix4f)} to set a given Matrix3f to only the upper left 3x3 submatrix\r\n * of this matrix.\r\n * \r\n * @see Matrix3f#set(Matrix4f)\r\n * @see #get3x3(Matrix3f)\r\n * \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix3f normal(Matrix3f dest) {\r\n float det = determinant3x3();\r\n float s = 1.0f / det;\r\n /* Invert and transpose in one go */\r\n dest.m00 = (m11 * m22 - m21 * m12) * s;\r\n dest.m01 = (m20 * m12 - m10 * m22) * s;\r\n dest.m02 = (m10 * m21 - m20 * m11) * s;\r\n dest.m10 = (m21 * m02 - m01 * m22) * s;\r\n dest.m11 = (m00 * m22 - m20 * m02) * s;\r\n dest.m12 = (m20 * m01 - m00 * m21) * s;\r\n dest.m20 = (m01 * m12 - m11 * m02) * s;\r\n dest.m21 = (m10 * m02 - m00 * m12) * s;\r\n dest.m22 = (m00 * m11 - m10 * m01) * s;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Normalize the upper left 3x3 submatrix of this matrix.\r\n *
\r\n * The resulting matrix will map unit vectors to unit vectors, though a pair of orthogonal input unit\r\n * vectors need not be mapped to a pair of orthogonal output vectors if the original matrix was not orthogonal itself\r\n * (i.e. had skewing).\r\n * \r\n * @return this\r\n */\r\n public Matrix4f normalize3x3() {\r\n return normalize3x3(this);\r\n }\r\n\r\n /**\r\n * Normalize the upper left 3x3 submatrix of this matrix and store the result in dest
.\r\n *
\r\n * The resulting matrix will map unit vectors to unit vectors, though a pair of orthogonal input unit\r\n * vectors need not be mapped to a pair of orthogonal output vectors if the original matrix was not orthogonal itself\r\n * (i.e. had skewing).\r\n * \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f normalize3x3(Matrix4f dest) {\r\n float invXlen = (float) (1.0 / Math.sqrt(m00 * m00 + m01 * m01 + m02 * m02));\r\n float invYlen = (float) (1.0 / Math.sqrt(m10 * m10 + m11 * m11 + m12 * m12));\r\n float invZlen = (float) (1.0 / Math.sqrt(m20 * m20 + m21 * m21 + m22 * m22));\r\n dest.m00 = m00 * invXlen; dest.m01 = m01 * invXlen; dest.m02 = m02 * invXlen;\r\n dest.m10 = m10 * invYlen; dest.m11 = m11 * invYlen; dest.m12 = m12 * invYlen;\r\n dest.m20 = m20 * invZlen; dest.m21 = m21 * invZlen; dest.m22 = m22 * invZlen;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Normalize the upper left 3x3 submatrix of this matrix and store the result in dest
.\r\n *
\r\n * The resulting matrix will map unit vectors to unit vectors, though a pair of orthogonal input unit\r\n * vectors need not be mapped to a pair of orthogonal output vectors if the original matrix was not orthogonal itself\r\n * (i.e. had skewing).\r\n * \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix3f normalize3x3(Matrix3f dest) {\r\n float invXlen = (float) (1.0 / Math.sqrt(m00 * m00 + m01 * m01 + m02 * m02));\r\n float invYlen = (float) (1.0 / Math.sqrt(m10 * m10 + m11 * m11 + m12 * m12));\r\n float invZlen = (float) (1.0 / Math.sqrt(m20 * m20 + m21 * m21 + m22 * m22));\r\n dest.m00 = m00 * invXlen; dest.m01 = m01 * invXlen; dest.m02 = m02 * invXlen;\r\n dest.m10 = m10 * invYlen; dest.m11 = m11 * invYlen; dest.m12 = m12 * invYlen;\r\n dest.m20 = m20 * invZlen; dest.m21 = m21 * invZlen; dest.m22 = m22 * invZlen;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Calculate a frustum plane of this
matrix, which\r\n * can be a projection matrix or a combined modelview-projection matrix, and store the result\r\n * in the given planeEquation
.\r\n *
\r\n * Generally, this method computes the frustum plane in the local frame of\r\n * any coordinate system that existed before this
\r\n * transformation was applied to it in order to yield homogeneous clipping space.\r\n *
\r\n * The frustum plane will be given in the form of a general plane equation:\r\n * a*x + b*y + c*z + d = 0, where the given {@link Vector4f} components will\r\n * hold the (a, b, c, d) values of the equation.\r\n *
\r\n * The plane normal, which is (a, b, c), is directed \"inwards\" of the frustum.\r\n * Any plane/point test using a*x + b*y + c*z + d therefore will yield a result greater than zero\r\n * if the point is within the frustum (i.e. at the positive side of the frustum plane).\r\n *
\r\n * Reference: \r\n * Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix\r\n *\r\n * @param plane\r\n * one of the six possible planes, given as numeric constants\r\n * {@link #PLANE_NX}, {@link #PLANE_PX},\r\n * {@link #PLANE_NY}, {@link #PLANE_PY},\r\n * {@link #PLANE_NZ} and {@link #PLANE_PZ}\r\n * @param planeEquation\r\n * will hold the computed plane equation.\r\n * The plane equation will be normalized, meaning that (a, b, c) will be a unit vector\r\n * @return planeEquation\r\n */\r\n public Vector4f frustumPlane(int plane, Vector4f planeEquation) {\r\n switch (plane) {\r\n case PLANE_NX:\r\n planeEquation.set(m03 + m00, m13 + m10, m23 + m20, m33 + m30).normalize3();\r\n break;\r\n case PLANE_PX:\r\n planeEquation.set(m03 - m00, m13 - m10, m23 - m20, m33 - m30).normalize3();\r\n break;\r\n case PLANE_NY:\r\n planeEquation.set(m03 + m01, m13 + m11, m23 + m21, m33 + m31).normalize3();\r\n break;\r\n case PLANE_PY:\r\n planeEquation.set(m03 - m01, m13 - m11, m23 - m21, m33 - m31).normalize3();\r\n break;\r\n case PLANE_NZ:\r\n planeEquation.set(m03 + m02, m13 + m12, m23 + m22, m33 + m32).normalize3();\r\n break;\r\n case PLANE_PZ:\r\n planeEquation.set(m03 - m02, m13 - m12, m23 - m22, m33 - m32).normalize3();\r\n break;\r\n default:\r\n throw new IllegalArgumentException(\"plane\"); //$NON-NLS-1$\r\n }\r\n return planeEquation;\r\n }\r\n\r\n /**\r\n * Compute the corner coordinates of the frustum defined by this
matrix, which\r\n * can be a projection matrix or a combined modelview-projection matrix, and store the result\r\n * in the given point
.\r\n *
\r\n * Generally, this method computes the frustum corners in the local frame of\r\n * any coordinate system that existed before this
\r\n * transformation was applied to it in order to yield homogeneous clipping space.\r\n *
\r\n * Reference: http://geomalgorithms.com\r\n *
\r\n * Reference: \r\n * Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix\r\n * \r\n * @param corner\r\n * one of the eight possible corners, given as numeric constants\r\n * {@link #CORNER_NXNYNZ}, {@link #CORNER_PXNYNZ}, {@link #CORNER_PXPYNZ}, {@link #CORNER_NXPYNZ},\r\n * {@link #CORNER_PXNYPZ}, {@link #CORNER_NXNYPZ}, {@link #CORNER_NXPYPZ}, {@link #CORNER_PXPYPZ}\r\n * @param point\r\n * will hold the resulting corner point coordinates\r\n * @return point\r\n */\r\n public Vector3f frustumCorner(int corner, Vector3f point) {\r\n float d1, d2, d3;\r\n float n1x, n1y, n1z, n2x, n2y, n2z, n3x, n3y, n3z;\r\n switch (corner) {\r\n case CORNER_NXNYNZ: // left, bottom, near\r\n n1x = m03 + m00; n1y = m13 + m10; n1z = m23 + m20; d1 = m33 + m30; // left\r\n n2x = m03 + m01; n2y = m13 + m11; n2z = m23 + m21; d2 = m33 + m31; // bottom\r\n n3x = m03 + m02; n3y = m13 + m12; n3z = m23 + m22; d3 = m33 + m32; // near\r\n break;\r\n case CORNER_PXNYNZ: // right, bottom, near\r\n n1x = m03 - m00; n1y = m13 - m10; n1z = m23 - m20; d1 = m33 - m30; // right\r\n n2x = m03 + m01; n2y = m13 + m11; n2z = m23 + m21; d2 = m33 + m31; // bottom\r\n n3x = m03 + m02; n3y = m13 + m12; n3z = m23 + m22; d3 = m33 + m32; // near\r\n break;\r\n case CORNER_PXPYNZ: // right, top, near\r\n n1x = m03 - m00; n1y = m13 - m10; n1z = m23 - m20; d1 = m33 - m30; // right\r\n n2x = m03 - m01; n2y = m13 - m11; n2z = m23 - m21; d2 = m33 - m31; // top\r\n n3x = m03 + m02; n3y = m13 + m12; n3z = m23 + m22; d3 = m33 + m32; // near\r\n break;\r\n case CORNER_NXPYNZ: // left, top, near\r\n n1x = m03 + m00; n1y = m13 + m10; n1z = m23 + m20; d1 = m33 + m30; // left\r\n n2x = m03 - m01; n2y = m13 - m11; n2z = m23 - m21; d2 = m33 - m31; // top\r\n n3x = m03 + m02; n3y = m13 + m12; n3z = m23 + m22; d3 = m33 + m32; // near\r\n break;\r\n case CORNER_PXNYPZ: // right, bottom, far\r\n n1x = m03 - m00; n1y = m13 - m10; n1z = m23 - m20; d1 = m33 - m30; // right\r\n n2x = m03 + m01; n2y = m13 + m11; n2z = m23 + m21; d2 = m33 + m31; // bottom\r\n n3x = m03 - m02; n3y = m13 - m12; n3z = m23 - m22; d3 = m33 - m32; // far\r\n break;\r\n case CORNER_NXNYPZ: // left, bottom, far\r\n n1x = m03 + m00; n1y = m13 + m10; n1z = m23 + m20; d1 = m33 + m30; // left\r\n n2x = m03 + m01; n2y = m13 + m11; n2z = m23 + m21; d2 = m33 + m31; // bottom\r\n n3x = m03 - m02; n3y = m13 - m12; n3z = m23 - m22; d3 = m33 - m32; // far\r\n break;\r\n case CORNER_NXPYPZ: // left, top, far\r\n n1x = m03 + m00; n1y = m13 + m10; n1z = m23 + m20; d1 = m33 + m30; // left\r\n n2x = m03 - m01; n2y = m13 - m11; n2z = m23 - m21; d2 = m33 - m31; // top\r\n n3x = m03 - m02; n3y = m13 - m12; n3z = m23 - m22; d3 = m33 - m32; // far\r\n break;\r\n case CORNER_PXPYPZ: // right, top, far\r\n n1x = m03 - m00; n1y = m13 - m10; n1z = m23 - m20; d1 = m33 - m30; // right\r\n n2x = m03 - m01; n2y = m13 - m11; n2z = m23 - m21; d2 = m33 - m31; // top\r\n n3x = m03 - m02; n3y = m13 - m12; n3z = m23 - m22; d3 = m33 - m32; // far\r\n break;\r\n default:\r\n throw new IllegalArgumentException(\"corner\"); //$NON-NLS-1$\r\n }\r\n float c23x, c23y, c23z;\r\n c23x = n2y * n3z - n2z * n3y;\r\n c23y = n2z * n3x - n2x * n3z;\r\n c23z = n2x * n3y - n2y * n3x;\r\n float c31x, c31y, c31z;\r\n c31x = n3y * n1z - n3z * n1y;\r\n c31y = n3z * n1x - n3x * n1z;\r\n c31z = n3x * n1y - n3y * n1x;\r\n float c12x, c12y, c12z;\r\n c12x = n1y * n2z - n1z * n2y;\r\n c12y = n1z * n2x - n1x * n2z;\r\n c12z = n1x * n2y - n1y * n2x;\r\n float invDot = 1.0f / (n1x * c23x + n1y * c23y + n1z * c23z);\r\n point.x = (-c23x * d1 - c31x * d2 - c12x * d3) * invDot;\r\n point.y = (-c23y * d1 - c31y * d2 - c12y * d3) * invDot;\r\n point.z = (-c23z * d1 - c31z * d2 - c12z * d3) * invDot;\r\n return point;\r\n }\r\n\r\n /**\r\n * Compute the eye/origin of the perspective frustum transformation defined by this
matrix, \r\n * which can be a projection matrix or a combined modelview-projection matrix, and store the result\r\n * in the given origin
.\r\n *
\r\n * Note that this method will only work using perspective projections obtained via one of the\r\n * perspective methods, such as {@link #perspective(float, float, float, float) perspective()}\r\n * or {@link #frustum(float, float, float, float, float, float) frustum()}.\r\n *
\r\n * Generally, this method computes the origin in the local frame of\r\n * any coordinate system that existed before this
\r\n * transformation was applied to it in order to yield homogeneous clipping space.\r\n *
\r\n * Reference: http://geomalgorithms.com\r\n *
\r\n * Reference: \r\n * Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix\r\n * \r\n * @param origin\r\n * will hold the origin of the coordinate system before applying this
\r\n * perspective projection transformation\r\n * @return origin\r\n */\r\n public Vector3f perspectiveOrigin(Vector3f origin) {\r\n /*\r\n * Simply compute the intersection point of the left, right and top frustum plane.\r\n */\r\n float d1, d2, d3;\r\n float n1x, n1y, n1z, n2x, n2y, n2z, n3x, n3y, n3z;\r\n n1x = m03 + m00; n1y = m13 + m10; n1z = m23 + m20; d1 = m33 + m30; // left\r\n n2x = m03 - m00; n2y = m13 - m10; n2z = m23 - m20; d2 = m33 - m30; // right\r\n n3x = m03 - m01; n3y = m13 - m11; n3z = m23 - m21; d3 = m33 - m31; // top\r\n float c23x, c23y, c23z;\r\n c23x = n2y * n3z - n2z * n3y;\r\n c23y = n2z * n3x - n2x * n3z;\r\n c23z = n2x * n3y - n2y * n3x;\r\n float c31x, c31y, c31z;\r\n c31x = n3y * n1z - n3z * n1y;\r\n c31y = n3z * n1x - n3x * n1z;\r\n c31z = n3x * n1y - n3y * n1x;\r\n float c12x, c12y, c12z;\r\n c12x = n1y * n2z - n1z * n2y;\r\n c12y = n1z * n2x - n1x * n2z;\r\n c12z = n1x * n2y - n1y * n2x;\r\n float invDot = 1.0f / (n1x * c23x + n1y * c23y + n1z * c23z);\r\n origin.x = (-c23x * d1 - c31x * d2 - c12x * d3) * invDot;\r\n origin.y = (-c23y * d1 - c31y * d2 - c12y * d3) * invDot;\r\n origin.z = (-c23z * d1 - c31z * d2 - c12z * d3) * invDot;\r\n return origin;\r\n }\r\n\r\n /**\r\n * Return the vertical field-of-view angle in radians of this perspective transformation matrix.\r\n *
\r\n * Note that this method will only work using perspective projections obtained via one of the\r\n * perspective methods, such as {@link #perspective(float, float, float, float) perspective()}\r\n * or {@link #frustum(float, float, float, float, float, float) frustum()}.\r\n *
\r\n * For orthogonal transformations this method will return 0.0.\r\n *
\r\n * Reference: \r\n * Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix\r\n * \r\n * @return the vertical field-of-view angle in radians\r\n */\r\n public float perspectiveFov() {\r\n /*\r\n * Compute the angle between the bottom and top frustum plane normals.\r\n */\r\n float n1x, n1y, n1z, n2x, n2y, n2z;\r\n n1x = m03 + m01; n1y = m13 + m11; n1z = m23 + m21; // bottom\r\n n2x = m01 - m03; n2y = m11 - m13; n2z = m21 - m23; // top\r\n float n1len = (float) Math.sqrt(n1x * n1x + n1y * n1y + n1z * n1z);\r\n float n2len = (float) Math.sqrt(n2x * n2x + n2y * n2y + n2z * n2z);\r\n return (float) Math.acos((n1x * n2x + n1y * n2y + n1z * n2z) / (n1len * n2len));\r\n }\r\n\r\n /**\r\n * Extract the near clip plane distance from this
perspective projection matrix.\r\n *
\r\n * This method only works if this
is a perspective projection matrix, for example obtained via {@link #perspective(float, float, float, float)}.\r\n * \r\n * @return the near clip plane distance\r\n */\r\n public float perspectiveNear() {\r\n return m32 / (m23 + m22);\r\n }\r\n\r\n /**\r\n * Extract the far clip plane distance from this
perspective projection matrix.\r\n *
\r\n * This method only works if this
is a perspective projection matrix, for example obtained via {@link #perspective(float, float, float, float)}.\r\n * \r\n * @return the far clip plane distance\r\n */\r\n public float perspectiveFar() {\r\n return m32 / (m22 - m23);\r\n }\r\n\r\n /**\r\n * Obtain the direction of a ray starting at the center of the coordinate system and going \r\n * through the near frustum plane.\r\n *
\r\n * This method computes the dir
vector in the local frame of\r\n * any coordinate system that existed before this
\r\n * transformation was applied to it in order to yield homogeneous clipping space.\r\n *
\r\n * The parameters x
and y
are used to interpolate the generated ray direction\r\n * from the bottom-left to the top-right frustum corners.\r\n *
\r\n * For optimal efficiency when building many ray directions over the whole frustum,\r\n * it is recommended to use this method only in order to compute the four corner rays at\r\n * (0, 0), (1, 0), (0, 1) and (1, 1)\r\n * and then bilinearly interpolating between them; or to use the {@link FrustumRayBuilder}.\r\n *
\r\n * Reference: \r\n * Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix\r\n * \r\n * @param x\r\n * the interpolation factor along the left-to-right frustum planes, within [0..1]\r\n * @param y\r\n * the interpolation factor along the bottom-to-top frustum planes, within [0..1]\r\n * @param dir\r\n * will hold the normalized ray direction in the local frame of the coordinate system before \r\n * transforming to homogeneous clipping space using this
matrix\r\n * @return dir\r\n */\r\n public Vector3f frustumRayDir(float x, float y, Vector3f dir) {\r\n /*\r\n * This method works by first obtaining the frustum plane normals,\r\n * then building the cross product to obtain the corner rays,\r\n * and finally bilinearly interpolating to obtain the desired direction.\r\n * The code below uses a condense form of doing all this making use \r\n * of some mathematical identities to simplify the overall expression.\r\n */\r\n float a = m10 * m23, b = m13 * m21, c = m10 * m21, d = m11 * m23, e = m13 * m20, f = m11 * m20;\r\n float g = m03 * m20, h = m01 * m23, i = m01 * m20, j = m03 * m21, k = m00 * m23, l = m00 * m21;\r\n float m = m00 * m13, n = m03 * m11, o = m00 * m11, p = m01 * m13, q = m03 * m10, r = m01 * m10;\r\n float m1x, m1y, m1z;\r\n m1x = (d + e + f - a - b - c) * (1.0f - y) + (a - b - c + d - e + f) * y;\r\n m1y = (j + k + l - g - h - i) * (1.0f - y) + (g - h - i + j - k + l) * y;\r\n m1z = (p + q + r - m - n - o) * (1.0f - y) + (m - n - o + p - q + r) * y;\r\n float m2x, m2y, m2z;\r\n m2x = (b - c - d + e + f - a) * (1.0f - y) + (a + b - c - d - e + f) * y;\r\n m2y = (h - i - j + k + l - g) * (1.0f - y) + (g + h - i - j - k + l) * y;\r\n m2z = (n - o - p + q + r - m) * (1.0f - y) + (m + n - o - p - q + r) * y;\r\n dir.x = m1x + (m2x - m1x) * x;\r\n dir.y = m1y + (m2y - m1y) * x;\r\n dir.z = m1z + (m2z - m1z) * x;\r\n dir.normalize();\r\n return dir;\r\n }\r\n\r\n /**\r\n * Obtain the direction of +Z before the transformation represented by this
matrix is applied.\r\n *
\r\n * This method uses the rotation component of the upper left 3x3 submatrix to obtain the direction \r\n * that is transformed to +Z by this
matrix.\r\n *
\r\n * This method is equivalent to the following code:\r\n *
\r\n * Matrix4f inv = new Matrix4f(this).invert();\r\n * inv.transformDirection(dir.set(0, 0, 1)).normalize();\r\n *
\r\n * If this
is already an orthogonal matrix, then consider using {@link #normalizedPositiveZ(Vector3f)} instead.\r\n * \r\n * Reference: http://www.euclideanspace.com\r\n * \r\n * @param dir\r\n * will hold the direction of +Z\r\n * @return dir\r\n */\r\n public Vector3f positiveZ(Vector3f dir) {\r\n dir.x = m10 * m21 - m11 * m20;\r\n dir.y = m20 * m01 - m21 * m00;\r\n dir.z = m00 * m11 - m01 * m10;\r\n dir.normalize();\r\n return dir;\r\n }\r\n\r\n /**\r\n * Obtain the direction of +Z before the transformation represented by this
orthogonal matrix is applied.\r\n * This method only produces correct results if this
is an orthogonal matrix.\r\n *
\r\n * This method uses the rotation component of the upper left 3x3 submatrix to obtain the direction \r\n * that is transformed to +Z by this
matrix.\r\n *
\r\n * This method is equivalent to the following code:\r\n *
\r\n * Matrix4f inv = new Matrix4f(this).transpose();\r\n * inv.transformDirection(dir.set(0, 0, 1)).normalize();\r\n *
\r\n * \r\n * Reference: http://www.euclideanspace.com\r\n * \r\n * @param dir\r\n * will hold the direction of +Z\r\n * @return dir\r\n */\r\n public Vector3f normalizedPositiveZ(Vector3f dir) {\r\n dir.x = m02;\r\n dir.y = m12;\r\n dir.z = m22;\r\n return dir;\r\n }\r\n\r\n /**\r\n * Obtain the direction of +X before the transformation represented by this
matrix is applied.\r\n *
\r\n * This method uses the rotation component of the upper left 3x3 submatrix to obtain the direction \r\n * that is transformed to +X by this
matrix.\r\n *
\r\n * This method is equivalent to the following code:\r\n *
\r\n * Matrix4f inv = new Matrix4f(this).invert();\r\n * inv.transformDirection(dir.set(1, 0, 0)).normalize();\r\n *
\r\n * If this
is already an orthogonal matrix, then consider using {@link #normalizedPositiveX(Vector3f)} instead.\r\n * \r\n * Reference: http://www.euclideanspace.com\r\n * \r\n * @param dir\r\n * will hold the direction of +X\r\n * @return dir\r\n */\r\n public Vector3f positiveX(Vector3f dir) {\r\n dir.x = m11 * m22 - m12 * m21;\r\n dir.y = m02 * m21 - m01 * m22;\r\n dir.z = m01 * m12 - m02 * m11;\r\n dir.normalize();\r\n return dir;\r\n }\r\n\r\n /**\r\n * Obtain the direction of +X before the transformation represented by this
orthogonal matrix is applied.\r\n * This method only produces correct results if this
is an orthogonal matrix.\r\n *
\r\n * This method uses the rotation component of the upper left 3x3 submatrix to obtain the direction \r\n * that is transformed to +X by this
matrix.\r\n *
\r\n * This method is equivalent to the following code:\r\n *
\r\n * Matrix4f inv = new Matrix4f(this).transpose();\r\n * inv.transformDirection(dir.set(1, 0, 0)).normalize();\r\n *
\r\n * \r\n * Reference: http://www.euclideanspace.com\r\n * \r\n * @param dir\r\n * will hold the direction of +X\r\n * @return dir\r\n */\r\n public Vector3f normalizedPositiveX(Vector3f dir) {\r\n dir.x = m00;\r\n dir.y = m10;\r\n dir.z = m20;\r\n return dir;\r\n }\r\n\r\n /**\r\n * Obtain the direction of +Y before the transformation represented by this
matrix is applied.\r\n *
\r\n * This method uses the rotation component of the upper left 3x3 submatrix to obtain the direction \r\n * that is transformed to +Y by this
matrix.\r\n *
\r\n * This method is equivalent to the following code:\r\n *
\r\n * Matrix4f inv = new Matrix4f(this).invert();\r\n * inv.transformDirection(dir.set(0, 1, 0)).normalize();\r\n *
\r\n * If this
is already an orthogonal matrix, then consider using {@link #normalizedPositiveY(Vector3f)} instead.\r\n * \r\n * Reference: http://www.euclideanspace.com\r\n * \r\n * @param dir\r\n * will hold the direction of +Y\r\n * @return dir\r\n */\r\n public Vector3f positiveY(Vector3f dir) {\r\n dir.x = m12 * m20 - m10 * m22;\r\n dir.y = m00 * m22 - m02 * m20;\r\n dir.z = m02 * m10 - m00 * m12;\r\n dir.normalize();\r\n return dir;\r\n }\r\n\r\n /**\r\n * Obtain the direction of +Y before the transformation represented by this
orthogonal matrix is applied.\r\n * This method only produces correct results if this
is an orthogonal matrix.\r\n *
\r\n * This method uses the rotation component of the upper left 3x3 submatrix to obtain the direction \r\n * that is transformed to +Y by this
matrix.\r\n *
\r\n * This method is equivalent to the following code:\r\n *
\r\n * Matrix4f inv = new Matrix4f(this).transpose();\r\n * inv.transformDirection(dir.set(0, 1, 0)).normalize();\r\n *
\r\n * \r\n * Reference: http://www.euclideanspace.com\r\n * \r\n * @param dir\r\n * will hold the direction of +Y\r\n * @return dir\r\n */\r\n public Vector3f normalizedPositiveY(Vector3f dir) {\r\n dir.x = m01;\r\n dir.y = m11;\r\n dir.z = m21;\r\n return dir;\r\n }\r\n\r\n /**\r\n * Obtain the position that gets transformed to the origin by this
{@link #isAffine() affine} matrix.\r\n * This can be used to get the position of the \"camera\" from a given view transformation matrix.\r\n *
\r\n * This method only works with {@link #isAffine() affine} matrices.\r\n *
\r\n * This method is equivalent to the following code:\r\n *
\r\n * Matrix4f inv = new Matrix4f(this).invertAffine();\r\n * inv.transformPosition(origin.set(0, 0, 0));\r\n *
\r\n * \r\n * @param origin\r\n * will hold the position transformed to the origin\r\n * @return origin\r\n */\r\n public Vector3f originAffine(Vector3f origin) {\r\n float a = m00 * m11 - m01 * m10;\r\n float b = m00 * m12 - m02 * m10;\r\n float d = m01 * m12 - m02 * m11;\r\n float g = m20 * m31 - m21 * m30;\r\n float h = m20 * m32 - m22 * m30;\r\n float j = m21 * m32 - m22 * m31;\r\n origin.x = -m10 * j + m11 * h - m12 * g;\r\n origin.y = m00 * j - m01 * h + m02 * g;\r\n origin.z = -m30 * d + m31 * b - m32 * a;\r\n return origin;\r\n }\r\n\r\n /**\r\n * Obtain the position that gets transformed to the origin by this
matrix.\r\n * This can be used to get the position of the \"camera\" from a given view/projection transformation matrix.\r\n * \r\n * This method is equivalent to the following code:\r\n *
\r\n * Matrix4f inv = new Matrix4f(this).invert();\r\n * inv.transformPosition(origin.set(0, 0, 0));\r\n *
\r\n * \r\n * @param origin\r\n * will hold the position transformed to the origin\r\n * @return origin\r\n */\r\n public Vector3f origin(Vector3f origin) {\r\n float a = m00 * m11 - m01 * m10;\r\n float b = m00 * m12 - m02 * m10;\r\n float c = m00 * m13 - m03 * m10;\r\n float d = m01 * m12 - m02 * m11;\r\n float e = m01 * m13 - m03 * m11;\r\n float f = m02 * m13 - m03 * m12;\r\n float g = m20 * m31 - m21 * m30;\r\n float h = m20 * m32 - m22 * m30;\r\n float i = m20 * m33 - m23 * m30;\r\n float j = m21 * m32 - m22 * m31;\r\n float k = m21 * m33 - m23 * m31;\r\n float l = m22 * m33 - m23 * m32;\r\n float det = a * l - b * k + c * j + d * i - e * h + f * g;\r\n float invDet = 1.0f / det;\r\n float nm30 = (-m10 * j + m11 * h - m12 * g) * invDet;\r\n float nm31 = ( m00 * j - m01 * h + m02 * g) * invDet;\r\n float nm32 = (-m30 * d + m31 * b - m32 * a) * invDet;\r\n float nm33 = det / ( m20 * d - m21 * b + m22 * a);\r\n float x = nm30 * nm33;\r\n float y = nm31 * nm33;\r\n float z = nm32 * nm33;\r\n return origin.set(x, y, z);\r\n }\r\n\r\n /**\r\n * Apply a projection transformation to this matrix that projects onto the plane specified via the general plane equation\r\n * x*a + y*b + z*c + d = 0 as if casting a shadow from a given light position/direction light
.\r\n * \r\n * If light.w is 0.0 the light is being treated as a directional light; if it is 1.0 it is a point light.\r\n *
\r\n * If M
is this
matrix and S
the shadow matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
, the\r\n * reflection will be applied first!\r\n *
\r\n * Reference: ftp.sgi.com\r\n * \r\n * @param light\r\n * the light's vector\r\n * @param a\r\n * the x factor in the plane equation\r\n * @param b\r\n * the y factor in the plane equation\r\n * @param c\r\n * the z factor in the plane equation\r\n * @param d\r\n * the constant in the plane equation\r\n * @return this\r\n */\r\n public Matrix4f shadow(Vector4f light, float a, float b, float c, float d) {\r\n return shadow(light.x, light.y, light.z, light.w, a, b, c, d, this);\r\n }\r\n\r\n /**\r\n * Apply a projection transformation to this matrix that projects onto the plane specified via the general plane equation\r\n * x*a + y*b + z*c + d = 0 as if casting a shadow from a given light position/direction light
\r\n * and store the result in dest
.\r\n *
\r\n * If light.w is 0.0 the light is being treated as a directional light; if it is 1.0 it is a point light.\r\n *
\r\n * If M
is this
matrix and S
the shadow matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
, the\r\n * reflection will be applied first!\r\n *
\r\n * Reference: ftp.sgi.com\r\n * \r\n * @param light\r\n * the light's vector\r\n * @param a\r\n * the x factor in the plane equation\r\n * @param b\r\n * the y factor in the plane equation\r\n * @param c\r\n * the z factor in the plane equation\r\n * @param d\r\n * the constant in the plane equation\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f shadow(Vector4f light, float a, float b, float c, float d, Matrix4f dest) {\r\n return shadow(light.x, light.y, light.z, light.w, a, b, c, d, dest);\r\n }\r\n\r\n /**\r\n * Apply a projection transformation to this matrix that projects onto the plane specified via the general plane equation\r\n * x*a + y*b + z*c + d = 0 as if casting a shadow from a given light position/direction (lightX, lightY, lightZ, lightW).\r\n *
\r\n * If lightW
is 0.0 the light is being treated as a directional light; if it is 1.0 it is a point light.\r\n *
\r\n * If M
is this
matrix and S
the shadow matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
, the\r\n * reflection will be applied first!\r\n *
\r\n * Reference: ftp.sgi.com\r\n * \r\n * @param lightX\r\n * the x-component of the light's vector\r\n * @param lightY\r\n * the y-component of the light's vector\r\n * @param lightZ\r\n * the z-component of the light's vector\r\n * @param lightW\r\n * the w-component of the light's vector\r\n * @param a\r\n * the x factor in the plane equation\r\n * @param b\r\n * the y factor in the plane equation\r\n * @param c\r\n * the z factor in the plane equation\r\n * @param d\r\n * the constant in the plane equation\r\n * @return this\r\n */\r\n public Matrix4f shadow(float lightX, float lightY, float lightZ, float lightW, float a, float b, float c, float d) {\r\n return shadow(lightX, lightY, lightZ, lightW, a, b, c, d, this);\r\n }\r\n\r\n /**\r\n * Apply a projection transformation to this matrix that projects onto the plane specified via the general plane equation\r\n * x*a + y*b + z*c + d = 0 as if casting a shadow from a given light position/direction (lightX, lightY, lightZ, lightW)\r\n * and store the result in dest
.\r\n *
\r\n * If lightW
is 0.0 the light is being treated as a directional light; if it is 1.0 it is a point light.\r\n *
\r\n * If M
is this
matrix and S
the shadow matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
, the\r\n * reflection will be applied first!\r\n *
\r\n * Reference: ftp.sgi.com\r\n * \r\n * @param lightX\r\n * the x-component of the light's vector\r\n * @param lightY\r\n * the y-component of the light's vector\r\n * @param lightZ\r\n * the z-component of the light's vector\r\n * @param lightW\r\n * the w-component of the light's vector\r\n * @param a\r\n * the x factor in the plane equation\r\n * @param b\r\n * the y factor in the plane equation\r\n * @param c\r\n * the z factor in the plane equation\r\n * @param d\r\n * the constant in the plane equation\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f shadow(float lightX, float lightY, float lightZ, float lightW, float a, float b, float c, float d, Matrix4f dest) {\r\n // normalize plane\r\n float invPlaneLen = (float) (1.0 / Math.sqrt(a*a + b*b + c*c));\r\n float an = a * invPlaneLen;\r\n float bn = b * invPlaneLen;\r\n float cn = c * invPlaneLen;\r\n float dn = d * invPlaneLen;\r\n\r\n float dot = an * lightX + bn * lightY + cn * lightZ + dn * lightW;\r\n\r\n // compute right matrix elements\r\n float rm00 = dot - an * lightX;\r\n float rm01 = -an * lightY;\r\n float rm02 = -an * lightZ;\r\n float rm03 = -an * lightW;\r\n float rm10 = -bn * lightX;\r\n float rm11 = dot - bn * lightY;\r\n float rm12 = -bn * lightZ;\r\n float rm13 = -bn * lightW;\r\n float rm20 = -cn * lightX;\r\n float rm21 = -cn * lightY;\r\n float rm22 = dot - cn * lightZ;\r\n float rm23 = -cn * lightW;\r\n float rm30 = -dn * lightX;\r\n float rm31 = -dn * lightY;\r\n float rm32 = -dn * lightZ;\r\n float rm33 = dot - dn * lightW;\r\n\r\n // matrix multiplication\r\n float nm00 = m00 * rm00 + m10 * rm01 + m20 * rm02 + m30 * rm03;\r\n float nm01 = m01 * rm00 + m11 * rm01 + m21 * rm02 + m31 * rm03;\r\n float nm02 = m02 * rm00 + m12 * rm01 + m22 * rm02 + m32 * rm03;\r\n float nm03 = m03 * rm00 + m13 * rm01 + m23 * rm02 + m33 * rm03;\r\n float nm10 = m00 * rm10 + m10 * rm11 + m20 * rm12 + m30 * rm13;\r\n float nm11 = m01 * rm10 + m11 * rm11 + m21 * rm12 + m31 * rm13;\r\n float nm12 = m02 * rm10 + m12 * rm11 + m22 * rm12 + m32 * rm13;\r\n float nm13 = m03 * rm10 + m13 * rm11 + m23 * rm12 + m33 * rm13;\r\n float nm20 = m00 * rm20 + m10 * rm21 + m20 * rm22 + m30 * rm23;\r\n float nm21 = m01 * rm20 + m11 * rm21 + m21 * rm22 + m31 * rm23;\r\n float nm22 = m02 * rm20 + m12 * rm21 + m22 * rm22 + m32 * rm23;\r\n float nm23 = m03 * rm20 + m13 * rm21 + m23 * rm22 + m33 * rm23;\r\n dest.m30 = m00 * rm30 + m10 * rm31 + m20 * rm32 + m30 * rm33;\r\n dest.m31 = m01 * rm30 + m11 * rm31 + m21 * rm32 + m31 * rm33;\r\n dest.m32 = m02 * rm30 + m12 * rm31 + m22 * rm32 + m32 * rm33;\r\n dest.m33 = m03 * rm30 + m13 * rm31 + m23 * rm32 + m33 * rm33;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply a projection transformation to this matrix that projects onto the plane with the general plane equation\r\n * y = 0 as if casting a shadow from a given light position/direction light
\r\n * and store the result in dest
.\r\n *
\r\n * Before the shadow projection is applied, the plane is transformed via the specified planeTransformation
.\r\n *
\r\n * If light.w is 0.0 the light is being treated as a directional light; if it is 1.0 it is a point light.\r\n *
\r\n * If M
is this
matrix and S
the shadow matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
, the\r\n * reflection will be applied first!\r\n * \r\n * @param light\r\n * the light's vector\r\n * @param planeTransform\r\n * the transformation to transform the implied plane y = 0 before applying the projection\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f shadow(Vector4f light, Matrix4f planeTransform, Matrix4f dest) {\r\n // compute plane equation by transforming (y = 0)\r\n float a = planeTransform.m10;\r\n float b = planeTransform.m11;\r\n float c = planeTransform.m12;\r\n float d = -a * planeTransform.m30 - b * planeTransform.m31 - c * planeTransform.m32;\r\n return shadow(light.x, light.y, light.z, light.w, a, b, c, d, dest);\r\n }\r\n\r\n /**\r\n * Apply a projection transformation to this matrix that projects onto the plane with the general plane equation\r\n * y = 0 as if casting a shadow from a given light position/direction light
.\r\n *
\r\n * Before the shadow projection is applied, the plane is transformed via the specified planeTransformation
.\r\n *
\r\n * If light.w is 0.0 the light is being treated as a directional light; if it is 1.0 it is a point light.\r\n *
\r\n * If M
is this
matrix and S
the shadow matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
, the\r\n * reflection will be applied first!\r\n * \r\n * @param light\r\n * the light's vector\r\n * @param planeTransform\r\n * the transformation to transform the implied plane y = 0 before applying the projection\r\n * @return this\r\n */\r\n public Matrix4f shadow(Vector4f light, Matrix4f planeTransform) {\r\n return shadow(light, planeTransform, this);\r\n }\r\n\r\n /**\r\n * Apply a projection transformation to this matrix that projects onto the plane with the general plane equation\r\n * y = 0 as if casting a shadow from a given light position/direction (lightX, lightY, lightZ, lightW)\r\n * and store the result in dest
.\r\n *
\r\n * Before the shadow projection is applied, the plane is transformed via the specified planeTransformation
.\r\n *
\r\n * If lightW
is 0.0 the light is being treated as a directional light; if it is 1.0 it is a point light.\r\n *
\r\n * If M
is this
matrix and S
the shadow matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
, the\r\n * reflection will be applied first!\r\n * \r\n * @param lightX\r\n * the x-component of the light vector\r\n * @param lightY\r\n * the y-component of the light vector\r\n * @param lightZ\r\n * the z-component of the light vector\r\n * @param lightW\r\n * the w-component of the light vector\r\n * @param planeTransform\r\n * the transformation to transform the implied plane y = 0 before applying the projection\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f shadow(float lightX, float lightY, float lightZ, float lightW, Matrix4f planeTransform, Matrix4f dest) {\r\n // compute plane equation by transforming (y = 0)\r\n float a = planeTransform.m10;\r\n float b = planeTransform.m11;\r\n float c = planeTransform.m12;\r\n float d = -a * planeTransform.m30 - b * planeTransform.m31 - c * planeTransform.m32;\r\n return shadow(lightX, lightY, lightZ, lightW, a, b, c, d, dest);\r\n }\r\n\r\n /**\r\n * Apply a projection transformation to this matrix that projects onto the plane with the general plane equation\r\n * y = 0 as if casting a shadow from a given light position/direction (lightX, lightY, lightZ, lightW).\r\n *
\r\n * Before the shadow projection is applied, the plane is transformed via the specified planeTransformation
.\r\n *
\r\n * If lightW
is 0.0 the light is being treated as a directional light; if it is 1.0 it is a point light.\r\n *
\r\n * If M
is this
matrix and S
the shadow matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
, the\r\n * reflection will be applied first!\r\n * \r\n * @param lightX\r\n * the x-component of the light vector\r\n * @param lightY\r\n * the y-component of the light vector\r\n * @param lightZ\r\n * the z-component of the light vector\r\n * @param lightW\r\n * the w-component of the light vector\r\n * @param planeTransform\r\n * the transformation to transform the implied plane y = 0 before applying the projection\r\n * @return this\r\n */\r\n public Matrix4f shadow(float lightX, float lightY, float lightZ, float lightW, Matrix4f planeTransform) {\r\n return shadow(lightX, lightY, lightZ, lightW, planeTransform, this);\r\n }\r\n\r\n /**\r\n * Set this matrix to a cylindrical billboard transformation that rotates the local +Z axis of a given object with position objPos
towards\r\n * a target position at targetPos
while constraining a cylindrical rotation around the given up
vector.\r\n *
\r\n * This method can be used to create the complete model transformation for a given object, including the translation of the object to\r\n * its position objPos
.\r\n * \r\n * @param objPos\r\n * the position of the object to rotate towards targetPos
\r\n * @param targetPos\r\n * the position of the target (for example the camera) towards which to rotate the object\r\n * @param up\r\n * the rotation axis (must be {@link Vector3f#normalize() normalized})\r\n * @return this\r\n */\r\n public Matrix4f billboardCylindrical(Vector3f objPos, Vector3f targetPos, Vector3f up) {\r\n float dirX = targetPos.x - objPos.x;\r\n float dirY = targetPos.y - objPos.y;\r\n float dirZ = targetPos.z - objPos.z;\r\n // left = up x dir\r\n float leftX = up.y * dirZ - up.z * dirY;\r\n float leftY = up.z * dirX - up.x * dirZ;\r\n float leftZ = up.x * dirY - up.y * dirX;\r\n // normalize left\r\n float invLeftLen = 1.0f / (float) Math.sqrt(leftX * leftX + leftY * leftY + leftZ * leftZ);\r\n leftX *= invLeftLen;\r\n leftY *= invLeftLen;\r\n leftZ *= invLeftLen;\r\n // recompute dir by constraining rotation around 'up'\r\n // dir = left x up\r\n dirX = leftY * up.z - leftZ * up.y;\r\n dirY = leftZ * up.x - leftX * up.z;\r\n dirZ = leftX * up.y - leftY * up.x;\r\n // normalize dir\r\n float invDirLen = 1.0f / (float) Math.sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);\r\n dirX *= invDirLen;\r\n dirY *= invDirLen;\r\n dirZ *= invDirLen;\r\n // set matrix elements\r\n m00 = leftX;\r\n m01 = leftY;\r\n m02 = leftZ;\r\n m03 = 0.0f;\r\n m10 = up.x;\r\n m11 = up.y;\r\n m12 = up.z;\r\n m13 = 0.0f;\r\n m20 = dirX;\r\n m21 = dirY;\r\n m22 = dirZ;\r\n m23 = 0.0f;\r\n m30 = objPos.x;\r\n m31 = objPos.y;\r\n m32 = objPos.z;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to a spherical billboard transformation that rotates the local +Z axis of a given object with position objPos
towards\r\n * a target position at targetPos
.\r\n *
\r\n * This method can be used to create the complete model transformation for a given object, including the translation of the object to\r\n * its position objPos
.\r\n *
\r\n * If preserving an up vector is not necessary when rotating the +Z axis, then a shortest arc rotation can be obtained \r\n * using {@link #billboardSpherical(Vector3f, Vector3f)}.\r\n * \r\n * @see #billboardSpherical(Vector3f, Vector3f)\r\n * \r\n * @param objPos\r\n * the position of the object to rotate towards targetPos
\r\n * @param targetPos\r\n * the position of the target (for example the camera) towards which to rotate the object\r\n * @param up\r\n * the up axis used to orient the object\r\n * @return this\r\n */\r\n public Matrix4f billboardSpherical(Vector3f objPos, Vector3f targetPos, Vector3f up) {\r\n float dirX = targetPos.x - objPos.x;\r\n float dirY = targetPos.y - objPos.y;\r\n float dirZ = targetPos.z - objPos.z;\r\n // normalize dir\r\n float invDirLen = 1.0f / (float) Math.sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);\r\n dirX *= invDirLen;\r\n dirY *= invDirLen;\r\n dirZ *= invDirLen;\r\n // left = up x dir\r\n float leftX = up.y * dirZ - up.z * dirY;\r\n float leftY = up.z * dirX - up.x * dirZ;\r\n float leftZ = up.x * dirY - up.y * dirX;\r\n // normalize left\r\n float invLeftLen = 1.0f / (float) Math.sqrt(leftX * leftX + leftY * leftY + leftZ * leftZ);\r\n leftX *= invLeftLen;\r\n leftY *= invLeftLen;\r\n leftZ *= invLeftLen;\r\n // up = dir x left\r\n float upX = dirY * leftZ - dirZ * leftY;\r\n float upY = dirZ * leftX - dirX * leftZ;\r\n float upZ = dirX * leftY - dirY * leftX;\r\n // set matrix elements\r\n m00 = leftX;\r\n m01 = leftY;\r\n m02 = leftZ;\r\n m03 = 0.0f;\r\n m10 = upX;\r\n m11 = upY;\r\n m12 = upZ;\r\n m13 = 0.0f;\r\n m20 = dirX;\r\n m21 = dirY;\r\n m22 = dirZ;\r\n m23 = 0.0f;\r\n m30 = objPos.x;\r\n m31 = objPos.y;\r\n m32 = objPos.z;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to a spherical billboard transformation that rotates the local +Z axis of a given object with position objPos
towards\r\n * a target position at targetPos
using a shortest arc rotation by not preserving any up vector of the object.\r\n *
\r\n * This method can be used to create the complete model transformation for a given object, including the translation of the object to\r\n * its position objPos
.\r\n *
\r\n * In order to specify an up vector which needs to be maintained when rotating the +Z axis of the object,\r\n * use {@link #billboardSpherical(Vector3f, Vector3f, Vector3f)}.\r\n * \r\n * @see #billboardSpherical(Vector3f, Vector3f, Vector3f)\r\n * \r\n * @param objPos\r\n * the position of the object to rotate towards targetPos
\r\n * @param targetPos\r\n * the position of the target (for example the camera) towards which to rotate the object\r\n * @return this\r\n */\r\n public Matrix4f billboardSpherical(Vector3f objPos, Vector3f targetPos) {\r\n float toDirX = targetPos.x - objPos.x;\r\n float toDirY = targetPos.y - objPos.y;\r\n float toDirZ = targetPos.z - objPos.z;\r\n float x = -toDirY;\r\n float y = toDirX;\r\n float w = (float) Math.sqrt(toDirX * toDirX + toDirY * toDirY + toDirZ * toDirZ) + toDirZ;\r\n float invNorm = (float) (1.0 / Math.sqrt(x * x + y * y + w * w));\r\n x *= invNorm;\r\n y *= invNorm;\r\n w *= invNorm;\r\n float q00 = (x + x) * x;\r\n float q11 = (y + y) * y;\r\n float q01 = (x + x) * y;\r\n float q03 = (x + x) * w;\r\n float q13 = (y + y) * w;\r\n m00 = 1.0f - q11;\r\n m01 = q01;\r\n m02 = -q13;\r\n m03 = 0.0f;\r\n m10 = q01;\r\n m11 = 1.0f - q00;\r\n m12 = q03;\r\n m13 = 0.0f;\r\n m20 = q13;\r\n m21 = -q03;\r\n m22 = 1.0f - q11 - q00;\r\n m23 = 0.0f;\r\n m30 = objPos.x;\r\n m31 = objPos.y;\r\n m32 = objPos.z;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n public int hashCode() {\r\n final int prime = 31;\r\n int result = 1;\r\n result = prime * result + Float.floatToIntBits(m00);\r\n result = prime * result + Float.floatToIntBits(m01);\r\n result = prime * result + Float.floatToIntBits(m02);\r\n result = prime * result + Float.floatToIntBits(m03);\r\n result = prime * result + Float.floatToIntBits(m10);\r\n result = prime * result + Float.floatToIntBits(m11);\r\n result = prime * result + Float.floatToIntBits(m12);\r\n result = prime * result + Float.floatToIntBits(m13);\r\n result = prime * result + Float.floatToIntBits(m20);\r\n result = prime * result + Float.floatToIntBits(m21);\r\n result = prime * result + Float.floatToIntBits(m22);\r\n result = prime * result + Float.floatToIntBits(m23);\r\n result = prime * result + Float.floatToIntBits(m30);\r\n result = prime * result + Float.floatToIntBits(m31);\r\n result = prime * result + Float.floatToIntBits(m32);\r\n result = prime * result + Float.floatToIntBits(m33);\r\n return result;\r\n }\r\n\r\n public boolean equals(Object obj) {\r\n if (this == obj)\r\n return true;\r\n if (obj == null)\r\n return false;\r\n if (!(obj instanceof Matrix4f))\r\n return false;\r\n Matrix4f other = (Matrix4f) obj;\r\n if (Float.floatToIntBits(m00) != Float.floatToIntBits(other.m00))\r\n return false;\r\n if (Float.floatToIntBits(m01) != Float.floatToIntBits(other.m01))\r\n return false;\r\n if (Float.floatToIntBits(m02) != Float.floatToIntBits(other.m02))\r\n return false;\r\n if (Float.floatToIntBits(m03) != Float.floatToIntBits(other.m03))\r\n return false;\r\n if (Float.floatToIntBits(m10) != Float.floatToIntBits(other.m10))\r\n return false;\r\n if (Float.floatToIntBits(m11) != Float.floatToIntBits(other.m11))\r\n return false;\r\n if (Float.floatToIntBits(m12) != Float.floatToIntBits(other.m12))\r\n return false;\r\n if (Float.floatToIntBits(m13) != Float.floatToIntBits(other.m13))\r\n return false;\r\n if (Float.floatToIntBits(m20) != Float.floatToIntBits(other.m20))\r\n return false;\r\n if (Float.floatToIntBits(m21) != Float.floatToIntBits(other.m21))\r\n return false;\r\n if (Float.floatToIntBits(m22) != Float.floatToIntBits(other.m22))\r\n return false;\r\n if (Float.floatToIntBits(m23) != Float.floatToIntBits(other.m23))\r\n return false;\r\n if (Float.floatToIntBits(m30) != Float.floatToIntBits(other.m30))\r\n return false;\r\n if (Float.floatToIntBits(m31) != Float.floatToIntBits(other.m31))\r\n return false;\r\n if (Float.floatToIntBits(m32) != Float.floatToIntBits(other.m32))\r\n return false;\r\n if (Float.floatToIntBits(m33) != Float.floatToIntBits(other.m33))\r\n return false;\r\n return true;\r\n }\r\n\r\n /**\r\n * Apply a picking transformation to this matrix using the given window coordinates (x, y) as the pick center\r\n * and the given (width, height) as the size of the picking region in window coordinates, and store the result\r\n * in dest
.\r\n * \r\n * @param x\r\n * the x coordinate of the picking region center in window coordinates\r\n * @param y\r\n * the y coordinate of the picking region center in window coordinates\r\n * @param width\r\n * the width of the picking region in window coordinates\r\n * @param height\r\n * the height of the picking region in window coordinates\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param dest\r\n * the destination matrix, which will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f pick(float x, float y, float width, float height, int[] viewport, Matrix4f dest) {\r\n float sx = viewport[2] / width;\r\n float sy = viewport[3] / height;\r\n float tx = (viewport[2] + 2.0f * (viewport[0] - x)) / width;\r\n float ty = (viewport[3] + 2.0f * (viewport[1] - y)) / height;\r\n dest.m30 = m00 * tx + m10 * ty + m30;\r\n dest.m31 = m01 * tx + m11 * ty + m31;\r\n dest.m32 = m02 * tx + m12 * ty + m32;\r\n dest.m33 = m03 * tx + m13 * ty + m33;\r\n dest.m00 = m00 * sx;\r\n dest.m01 = m01 * sx;\r\n dest.m02 = m02 * sx;\r\n dest.m03 = m03 * sx;\r\n dest.m10 = m10 * sy;\r\n dest.m11 = m11 * sy;\r\n dest.m12 = m12 * sy;\r\n dest.m13 = m13 * sy;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply a picking transformation to this matrix using the given window coordinates (x, y) as the pick center\r\n * and the given (width, height) as the size of the picking region in window coordinates.\r\n * \r\n * @param x\r\n * the x coordinate of the picking region center in window coordinates\r\n * @param y\r\n * the y coordinate of the picking region center in window coordinates\r\n * @param width\r\n * the width of the picking region in window coordinates\r\n * @param height\r\n * the height of the picking region in window coordinates\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @return this\r\n */\r\n public Matrix4f pick(float x, float y, float width, float height, int[] viewport) {\r\n return pick(x, y, width, height, viewport, this);\r\n }\r\n\r\n /**\r\n * Determine whether this matrix describes an affine transformation. This is the case iff its last row is equal to (0, 0, 0, 1).\r\n * \r\n * @return true
iff this matrix is affine; false
otherwise\r\n */\r\n public boolean isAffine() {\r\n return m03 == 0.0f && m13 == 0.0f && m23 == 0.0f && m33 == 1.0f;\r\n }\r\n\r\n /**\r\n * Exchange the values of this
matrix with the given other
matrix.\r\n * \r\n * @param other\r\n * the other matrix to exchange the values with\r\n * @return this\r\n */\r\n public Matrix4f swap(Matrix4f other) {\r\n float tmp;\r\n tmp = m00; m00 = other.m00; other.m00 = tmp;\r\n tmp = m01; m01 = other.m01; other.m01 = tmp;\r\n tmp = m02; m02 = other.m02; other.m02 = tmp;\r\n tmp = m03; m03 = other.m03; other.m03 = tmp;\r\n tmp = m10; m10 = other.m10; other.m10 = tmp;\r\n tmp = m11; m11 = other.m11; other.m11 = tmp;\r\n tmp = m12; m12 = other.m12; other.m12 = tmp;\r\n tmp = m13; m13 = other.m13; other.m13 = tmp;\r\n tmp = m20; m20 = other.m20; other.m20 = tmp;\r\n tmp = m21; m21 = other.m21; other.m21 = tmp;\r\n tmp = m22; m22 = other.m22; other.m22 = tmp;\r\n tmp = m23; m23 = other.m23; other.m23 = tmp;\r\n tmp = m30; m30 = other.m30; other.m30 = tmp;\r\n tmp = m31; m31 = other.m31; other.m31 = tmp;\r\n tmp = m32; m32 = other.m32; other.m32 = tmp;\r\n tmp = m33; m33 = other.m33; other.m33 = tmp;\r\n return this;\r\n }\r\n\r\n /**\r\n * Apply an arcball view transformation to this matrix with the given radius
and center (centerX, centerY, centerZ)\r\n * position of the arcball and the specified X and Y rotation angles, and store the result in dest
.\r\n *
\r\n * This method is equivalent to calling: translate(0, 0, -radius).rotateX(angleX).rotateY(angleY).translate(-centerX, -centerY, -centerZ)\r\n * \r\n * @param radius\r\n * the arcball radius\r\n * @param centerX\r\n * the x coordinate of the center position of the arcball\r\n * @param centerY\r\n * the y coordinate of the center position of the arcball\r\n * @param centerZ\r\n * the z coordinate of the center position of the arcball\r\n * @param angleX\r\n * the rotation angle around the X axis in radians\r\n * @param angleY\r\n * the rotation angle around the Y axis in radians\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f arcball(float radius, float centerX, float centerY, float centerZ, float angleX, float angleY, Matrix4f dest) {\r\n float m30 = m20 * -radius + this.m30;\r\n float m31 = m21 * -radius + this.m31;\r\n float m32 = m22 * -radius + this.m32;\r\n float m33 = m23 * -radius + this.m33;\r\n float cos = (float) Math.cos(angleX);\r\n float sin = (float) Math.sin(angleX);\r\n float nm10 = m10 * cos + m20 * sin;\r\n float nm11 = m11 * cos + m21 * sin;\r\n float nm12 = m12 * cos + m22 * sin;\r\n float nm13 = m13 * cos + m23 * sin;\r\n float m20 = this.m20 * cos - m10 * sin;\r\n float m21 = this.m21 * cos - m11 * sin;\r\n float m22 = this.m22 * cos - m12 * sin;\r\n float m23 = this.m23 * cos - m13 * sin;\r\n cos = (float) Math.cos(angleY);\r\n sin = (float) Math.sin(angleY);\r\n float nm00 = m00 * cos - m20 * sin;\r\n float nm01 = m01 * cos - m21 * sin;\r\n float nm02 = m02 * cos - m22 * sin;\r\n float nm03 = m03 * cos - m23 * sin;\r\n float nm20 = m00 * sin + m20 * cos;\r\n float nm21 = m01 * sin + m21 * cos;\r\n float nm22 = m02 * sin + m22 * cos;\r\n float nm23 = m03 * sin + m23 * cos;\r\n dest.m30 = -nm00 * centerX - nm10 * centerY - nm20 * centerZ + m30;\r\n dest.m31 = -nm01 * centerX - nm11 * centerY - nm21 * centerZ + m31;\r\n dest.m32 = -nm02 * centerX - nm12 * centerY - nm22 * centerZ + m32;\r\n dest.m33 = -nm03 * centerX - nm13 * centerY - nm23 * centerZ + m33;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply an arcball view transformation to this matrix with the given radius
and center
\r\n * position of the arcball and the specified X and Y rotation angles, and store the result in dest
.\r\n *
\r\n * This method is equivalent to calling: translate(0, 0, -radius).rotateX(angleX).rotateY(angleY).translate(-center.x, -center.y, -center.z)\r\n * \r\n * @param radius\r\n * the arcball radius\r\n * @param center\r\n * the center position of the arcball\r\n * @param angleX\r\n * the rotation angle around the X axis in radians\r\n * @param angleY\r\n * the rotation angle around the Y axis in radians\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f arcball(float radius, Vector3f center, float angleX, float angleY, Matrix4f dest) {\r\n return arcball(radius, center.x, center.y, center.z, angleX, angleY, dest);\r\n }\r\n\r\n /**\r\n * Apply an arcball view transformation to this matrix with the given radius
and center (centerX, centerY, centerZ)\r\n * position of the arcball and the specified X and Y rotation angles.\r\n *
\r\n * This method is equivalent to calling: translate(0, 0, -radius).rotateX(angleX).rotateY(angleY).translate(-centerX, -centerY, -centerZ)\r\n * \r\n * @param radius\r\n * the arcball radius\r\n * @param centerX\r\n * the x coordinate of the center position of the arcball\r\n * @param centerY\r\n * the y coordinate of the center position of the arcball\r\n * @param centerZ\r\n * the z coordinate of the center position of the arcball\r\n * @param angleX\r\n * the rotation angle around the X axis in radians\r\n * @param angleY\r\n * the rotation angle around the Y axis in radians\r\n * @return dest\r\n */\r\n public Matrix4f arcball(float radius, float centerX, float centerY, float centerZ, float angleX, float angleY) {\r\n return arcball(radius, centerX, centerY, centerZ, angleX, angleY, this);\r\n }\r\n\r\n /**\r\n * Apply an arcball view transformation to this matrix with the given radius
and center
\r\n * position of the arcball and the specified X and Y rotation angles.\r\n *
\r\n * This method is equivalent to calling: translate(0, 0, -radius).rotateX(angleX).rotateY(angleY).translate(-center.x, -center.y, -center.z)\r\n * \r\n * @param radius\r\n * the arcball radius\r\n * @param center\r\n * the center position of the arcball\r\n * @param angleX\r\n * the rotation angle around the X axis in radians\r\n * @param angleY\r\n * the rotation angle around the Y axis in radians\r\n * @return this\r\n */\r\n public Matrix4f arcball(float radius, Vector3f center, float angleX, float angleY) {\r\n return arcball(radius, center.x, center.y, center.z, angleX, angleY, this);\r\n }\r\n\r\n /**\r\n * Compute the axis-aligned bounding box of the frustum described by this
matrix and store the minimum corner\r\n * coordinates in the given min
and the maximum corner coordinates in the given max
vector.\r\n *
\r\n * The matrix this
is assumed to be the {@link #invert() inverse} of the origial view-projection matrix\r\n * for which to compute the axis-aligned bounding box in world-space.\r\n *
\r\n * The axis-aligned bounding box of the unit frustum is (-1, -1, -1), (1, 1, 1).\r\n * \r\n * @param min\r\n * will hold the minimum corner coordinates of the axis-aligned bounding box\r\n * @param max\r\n * will hold the maximum corner coordinates of the axis-aligned bounding box\r\n * @return this\r\n */\r\n public Matrix4f frustumAabb(Vector3f min, Vector3f max) {\r\n float minX = Float.MAX_VALUE;\r\n float minY = Float.MAX_VALUE;\r\n float minZ = Float.MAX_VALUE;\r\n float maxX = -Float.MAX_VALUE;\r\n float maxY = -Float.MAX_VALUE;\r\n float maxZ = -Float.MAX_VALUE;\r\n for (int t = 0; t < 8; t++) {\r\n float x = ((t & 1) << 1) - 1.0f;\r\n float y = (((t >>> 1) & 1) << 1) - 1.0f;\r\n float z = (((t >>> 2) & 1) << 1) - 1.0f;\r\n float invW = 1.0f / (m03 * x + m13 * y + m23 * z + m33);\r\n float nx = (m00 * x + m10 * y + m20 * z + m30) * invW;\r\n float ny = (m01 * x + m11 * y + m21 * z + m31) * invW;\r\n float nz = (m02 * x + m12 * y + m22 * z + m32) * invW;\r\n minX = minX < nx ? minX : nx;\r\n minY = minY < ny ? minY : ny;\r\n minZ = minZ < nz ? minZ : nz;\r\n maxX = maxX > nx ? maxX : nx;\r\n maxY = maxY > ny ? maxY : ny;\r\n maxZ = maxZ > nz ? maxZ : nz;\r\n }\r\n min.x = minX;\r\n min.y = minY;\r\n min.z = minZ;\r\n max.x = maxX;\r\n max.y = maxY;\r\n max.z = maxZ;\r\n return this;\r\n }\r\n\r\n /**\r\n * Compute the range matrix for the Projected Grid transformation as described in chapter \"2.4.2 Creating the range conversion matrix\"\r\n * of the paper Real-time water rendering - Introducing the projected grid concept\r\n * based on the inverse of the view-projection matrix which is assumed to be this
, and store that range matrix into dest
.\r\n *
\r\n * If the projected grid will not be visible then this method returns null
.\r\n *
\r\n * This method uses the y = 0 plane for the projection.\r\n * \r\n * @param projector\r\n * the projector view-projection transformation\r\n * @param sLower\r\n * the lower (smallest) Y-coordinate which any transformed vertex might have while still being visible on the projected grid\r\n * @param sUpper\r\n * the upper (highest) Y-coordinate which any transformed vertex might have while still being visible on the projected grid\r\n * @param dest\r\n * will hold the resulting range matrix\r\n * @return the computed range matrix; or null
if the projected grid will not be visible\r\n */\r\n public Matrix4f projectedGridRange(Matrix4f projector, float sLower, float sUpper, Matrix4f dest) {\r\n // Compute intersection with frustum edges and plane\r\n float minX = Float.MAX_VALUE, minY = Float.MAX_VALUE;\r\n float maxX = -Float.MAX_VALUE, maxY = -Float.MAX_VALUE;\r\n boolean intersection = false;\r\n for (int t = 0; t < 3 * 4; t++) {\r\n float c0X, c0Y, c0Z;\r\n float c1X, c1Y, c1Z;\r\n if (t < 4) {\r\n // all x edges\r\n c0X = -1; c1X = +1;\r\n c0Y = c1Y = ((t & 1) << 1) - 1.0f;\r\n c0Z = c1Z = (((t >>> 1) & 1) << 1) - 1.0f;\r\n } else if (t < 8) {\r\n // all y edges\r\n c0Y = -1; c1Y = +1;\r\n c0X = c1X = ((t & 1) << 1) - 1.0f;\r\n c0Z = c1Z = (((t >>> 1) & 1) << 1) - 1.0f;\r\n } else {\r\n // all z edges\r\n c0Z = -1; c1Z = +1;\r\n c0X = c1X = ((t & 1) << 1) - 1.0f;\r\n c0Y = c1Y = (((t >>> 1) & 1) << 1) - 1.0f;\r\n }\r\n // unproject corners\r\n float invW = 1.0f / (m03 * c0X + m13 * c0Y + m23 * c0Z + m33);\r\n float p0x = (m00 * c0X + m10 * c0Y + m20 * c0Z + m30) * invW;\r\n float p0y = (m01 * c0X + m11 * c0Y + m21 * c0Z + m31) * invW;\r\n float p0z = (m02 * c0X + m12 * c0Y + m22 * c0Z + m32) * invW;\r\n invW = 1.0f / (m03 * c1X + m13 * c1Y + m23 * c1Z + m33);\r\n float p1x = (m00 * c1X + m10 * c1Y + m20 * c1Z + m30) * invW;\r\n float p1y = (m01 * c1X + m11 * c1Y + m21 * c1Z + m31) * invW;\r\n float p1z = (m02 * c1X + m12 * c1Y + m22 * c1Z + m32) * invW;\r\n float dirX = p1x - p0x;\r\n float dirY = p1y - p0y;\r\n float dirZ = p1z - p0z;\r\n float invDenom = 1.0f / dirY;\r\n // test for intersection\r\n for (int s = 0; s < 2; s++) {\r\n float isectT = -(p0y + (s == 0 ? sLower : sUpper)) * invDenom;\r\n if (isectT >= 0.0f && isectT <= 1.0f) {\r\n intersection = true;\r\n // project with projector matrix\r\n float ix = p0x + isectT * dirX;\r\n float iz = p0z + isectT * dirZ;\r\n invW = 1.0f / (projector.m03 * ix + projector.m23 * iz + projector.m33);\r\n float px = (projector.m00 * ix + projector.m20 * iz + projector.m30) * invW;\r\n float py = (projector.m01 * ix + projector.m21 * iz + projector.m31) * invW;\r\n minX = minX < px ? minX : px;\r\n minY = minY < py ? minY : py;\r\n maxX = maxX > px ? maxX : px;\r\n maxY = maxY > py ? maxY : py;\r\n }\r\n }\r\n }\r\n if (!intersection)\r\n return null; // <- projected grid is not visible\r\n return dest.set(maxX - minX, 0, 0, 0, 0, maxY - minY, 0, 0, 0, 0, 1, 0, minX, minY, 0, 1);\r\n }\r\n\r\n /**\r\n * Change the near and far clip plane distances of this
perspective frustum transformation matrix\r\n * and store the result in dest
.\r\n *
\r\n * This method only works if this
is a perspective projection frustum transformation, for example obtained\r\n * via {@link #perspective(float, float, float, float) perspective()} or {@link #frustum(float, float, float, float, float, float) frustum()}.\r\n * \r\n * @see #perspective(float, float, float, float)\r\n * @see #frustum(float, float, float, float, float, float)\r\n * \r\n * @param near\r\n * the new near clip plane distance\r\n * @param far\r\n * the new far clip plane distance\r\n * @param dest\r\n * will hold the resulting matrix\r\n * @return dest\r\n */\r\n public Matrix4f perspectiveFrustumSlice(float near, float far, Matrix4f dest) {\r\n float invOldNear = (m23 + m22) / m32;\r\n float invNearFar = 1.0f / (near - far);\r\n dest.m00 = m00 * invOldNear * near;\r\n dest.m01 = m01;\r\n dest.m02 = m02;\r\n dest.m03 = m03;\r\n dest.m10 = m10;\r\n dest.m11 = m11 * invOldNear * near;\r\n dest.m12 = m12;\r\n dest.m13 = m13;\r\n dest.m20 = m20;\r\n dest.m21 = m21;\r\n dest.m22 = (far + near) * invNearFar;\r\n dest.m23 = m23;\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = (far + far) * near * invNearFar;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Build an ortographic projection transformation that fits the view-projection transformation represented by this
\r\n * into the given affine view
transformation.\r\n *
\r\n * The transformation represented by this
must be given as the {@link #invert() inverse} of a typical combined camera view-projection\r\n * transformation, whose projection can be either orthographic or perspective.\r\n *
\r\n * The view
must be an {@link #isAffine() affine} transformation which in the application of Cascaded Shadow Maps is usually the light view transformation.\r\n * It be obtained via any affine transformation or for example via {@link #lookAt(float, float, float, float, float, float, float, float, float) lookAt()}.\r\n *
\r\n * Reference: OpenGL SDK - Cascaded Shadow Maps\r\n * \r\n * @param view\r\n * the view transformation to build a corresponding orthographic projection to fit the frustum of this
\r\n * @param dest\r\n * will hold the crop projection transformation\r\n * @return dest\r\n */\r\n public Matrix4f orthoCrop(Matrix4f view, Matrix4f dest) {\r\n // determine min/max world z and min/max orthographically view-projected x/y\r\n float minX = Float.MAX_VALUE, maxX = -Float.MAX_VALUE;\r\n float minY = Float.MAX_VALUE, maxY = -Float.MAX_VALUE;\r\n float minZ = Float.MAX_VALUE, maxZ = -Float.MAX_VALUE;\r\n for (int t = 0; t < 8; t++) {\r\n float x = ((t & 1) << 1) - 1.0f;\r\n float y = (((t >>> 1) & 1) << 1) - 1.0f;\r\n float z = (((t >>> 2) & 1) << 1) - 1.0f;\r\n float invW = 1.0f / (m03 * x + m13 * y + m23 * z + m33);\r\n float wx = (m00 * x + m10 * y + m20 * z + m30) * invW;\r\n float wy = (m01 * x + m11 * y + m21 * z + m31) * invW;\r\n float wz = (m02 * x + m12 * y + m22 * z + m32) * invW;\r\n invW = 1.0f / (view.m03 * wx + view.m13 * wy + view.m23 * wz + view.m33);\r\n float vx = view.m00 * wx + view.m10 * wy + view.m20 * wz + view.m30;\r\n float vy = view.m01 * wx + view.m11 * wy + view.m21 * wz + view.m31;\r\n float vz = (view.m02 * wx + view.m12 * wy + view.m22 * wz + view.m32) * invW;\r\n minX = minX < vx ? minX : vx;\r\n maxX = maxX > vx ? maxX : vx;\r\n minY = minY < vy ? minY : vy;\r\n maxY = maxY > vy ? maxY : vy;\r\n minZ = minZ < vz ? minZ : vz;\r\n maxZ = maxZ > vz ? maxZ : vz;\r\n }\r\n // build crop projection matrix to fit 'this' frustum into view\r\n return dest.setOrtho(minX, maxX, minY, maxY, -maxZ, -minZ);\r\n }\r\n\r\n /**\r\n * Set this
matrix to a perspective transformation that maps the trapezoid spanned by the four corner coordinates\r\n * (p0x, p0y)
, (p1x, p1y)
, (p2x, p2y)
and (p3x, p3y)
to the unit square [(-1, -1)..(+1, +1)].\r\n *
\r\n * The corner coordinates are given in counter-clockwise order starting from the left corner on the smaller parallel side of the trapezoid\r\n * seen when looking at the trapezoid oriented with its shorter parallel edge at the bottom and its longer parallel edge at the top.\r\n *
\r\n * Reference: Notes On Implementation Of Trapezoidal Shadow Maps\r\n * \r\n * @param p0x\r\n * the x coordinate of the left corner at the shorter edge of the trapezoid\r\n * @param p0y\r\n * the y coordinate of the left corner at the shorter edge of the trapezoid\r\n * @param p1x\r\n * the x coordinate of the right corner at the shorter edge of the trapezoid\r\n * @param p1y\r\n * the y coordinate of the right corner at the shorter edge of the trapezoid\r\n * @param p2x\r\n * the x coordinate of the right corner at the longer edge of the trapezoid\r\n * @param p2y\r\n * the y coordinate of the right corner at the longer edge of the trapezoid\r\n * @param p3x\r\n * the x coordinate of the left corner at the longer edge of the trapezoid\r\n * @param p3y\r\n * the y coordinate of the left corner at the longer edge of the trapezoid\r\n * @return this\r\n */\r\n public Matrix4f trapezoidCrop(float p0x, float p0y, float p1x, float p1y, float p2x, float p2y, float p3x, float p3y) {\r\n float aX = p1y - p0y, aY = p0x - p1x;\r\n float m00 = aY;\r\n float m10 = -aX;\r\n float m30 = aX * p0y - aY * p0x;\r\n float m01 = aX;\r\n float m11 = aY;\r\n float m31 = -(aX * p0x + aY * p0y);\r\n float c3x = m00 * p3x + m10 * p3y + m30;\r\n float c3y = m01 * p3x + m11 * p3y + m31;\r\n float s = -c3x / c3y;\r\n m00 += s * m01;\r\n m10 += s * m11;\r\n m30 += s * m31;\r\n float d1x = m00 * p1x + m10 * p1y + m30;\r\n float d2x = m00 * p2x + m10 * p2y + m30;\r\n float d = d1x * c3y / (d2x - d1x);\r\n m31 += d;\r\n float sx = 2.0f / d2x;\r\n float sy = 1.0f / (c3y + d);\r\n float u = (sy + sy) * d / (1.0f - sy * d);\r\n float m03 = m01 * sy;\r\n float m13 = m11 * sy;\r\n float m33 = m31 * sy;\r\n m01 = (u + 1.0f) * m03;\r\n m11 = (u + 1.0f) * m13;\r\n m31 = (u + 1.0f) * m33 - u;\r\n m00 = sx * m00 - m03;\r\n m10 = sx * m10 - m13;\r\n m30 = sx * m30 - m33;\r\n return set(m00, m01, 0, m03,\r\n m10, m11, 0, m13,\r\n 0, 0, 1, 0,\r\n m30, m31, 0, m33);\r\n }\r\n\r\n /**\r\n * Transform the axis-aligned box given as the minimum corner (minX, minY, minZ) and maximum corner (maxX, maxY, maxZ)\r\n * by this
{@link #isAffine() affine} matrix and compute the axis-aligned box of the result whose minimum corner is stored in outMin
\r\n * and maximum corner stored in outMax
.\r\n *
\r\n * Reference: http://dev.theomader.com\r\n * \r\n * @param minX\r\n * the x coordinate of the minimum corner of the axis-aligned box\r\n * @param minY\r\n * the y coordinate of the minimum corner of the axis-aligned box\r\n * @param minZ\r\n * the z coordinate of the minimum corner of the axis-aligned box\r\n * @param maxX\r\n * the x coordinate of the maximum corner of the axis-aligned box\r\n * @param maxY\r\n * the y coordinate of the maximum corner of the axis-aligned box\r\n * @param maxZ\r\n * the y coordinate of the maximum corner of the axis-aligned box\r\n * @param outMin\r\n * will hold the minimum corner of the resulting axis-aligned box\r\n * @param outMax\r\n * will hold the maximum corner of the resulting axis-aligned box\r\n * @return this\r\n */\r\n public Matrix4f transformAab(float minX, float minY, float minZ, float maxX, float maxY, float maxZ, Vector3f outMin, Vector3f outMax) {\r\n float xax = m00 * minX, xay = m01 * minX, xaz = m02 * minX;\r\n float xbx = m00 * maxX, xby = m01 * maxX, xbz = m02 * maxX;\r\n float yax = m10 * minY, yay = m11 * minY, yaz = m12 * minY;\r\n float ybx = m10 * maxY, yby = m11 * maxY, ybz = m12 * maxY;\r\n float zax = m20 * minZ, zay = m21 * minZ, zaz = m22 * minZ;\r\n float zbx = m20 * maxZ, zby = m21 * maxZ, zbz = m22 * maxZ;\r\n float xminx, xminy, xminz, yminx, yminy, yminz, zminx, zminy, zminz;\r\n float xmaxx, xmaxy, xmaxz, ymaxx, ymaxy, ymaxz, zmaxx, zmaxy, zmaxz;\r\n if (xax < xbx) {\r\n xminx = xax;\r\n xmaxx = xbx;\r\n } else {\r\n xminx = xbx;\r\n xmaxx = xax;\r\n }\r\n if (xay < xby) {\r\n xminy = xay;\r\n xmaxy = xby;\r\n } else {\r\n xminy = xby;\r\n xmaxy = xay;\r\n }\r\n if (xaz < xbz) {\r\n xminz = xaz;\r\n xmaxz = xbz;\r\n } else {\r\n xminz = xbz;\r\n xmaxz = xaz;\r\n }\r\n if (yax < ybx) {\r\n yminx = yax;\r\n ymaxx = ybx;\r\n } else {\r\n yminx = ybx;\r\n ymaxx = yax;\r\n }\r\n if (yay < yby) {\r\n yminy = yay;\r\n ymaxy = yby;\r\n } else {\r\n yminy = yby;\r\n ymaxy = yay;\r\n }\r\n if (yaz < ybz) {\r\n yminz = yaz;\r\n ymaxz = ybz;\r\n } else {\r\n yminz = ybz;\r\n ymaxz = yaz;\r\n }\r\n if (zax < zbx) {\r\n zminx = zax;\r\n zmaxx = zbx;\r\n } else {\r\n zminx = zbx;\r\n zmaxx = zax;\r\n }\r\n if (zay < zby) {\r\n zminy = zay;\r\n zmaxy = zby;\r\n } else {\r\n zminy = zby;\r\n zmaxy = zay;\r\n }\r\n if (zaz < zbz) {\r\n zminz = zaz;\r\n zmaxz = zbz;\r\n } else {\r\n zminz = zbz;\r\n zmaxz = zaz;\r\n }\r\n outMin.x = xminx + yminx + zminx + m30;\r\n outMin.y = xminy + yminy + zminy + m31;\r\n outMin.z = xminz + yminz + zminz + m32;\r\n outMax.x = xmaxx + ymaxx + zmaxx + m30;\r\n outMax.y = xmaxy + ymaxy + zmaxy + m31;\r\n outMax.z = xmaxz + ymaxz + zmaxz + m32;\r\n return this;\r\n }\r\n\r\n /**\r\n * Transform the axis-aligned box given as the minimum corner min
and maximum corner max
\r\n * by this
{@link #isAffine() affine} matrix and compute the axis-aligned box of the result whose minimum corner is stored in outMin
\r\n * and maximum corner stored in outMax
.\r\n * \r\n * @param min\r\n * the minimum corner of the axis-aligned box\r\n * @param max\r\n * the maximum corner of the axis-aligned box\r\n * @param outMin\r\n * will hold the minimum corner of the resulting axis-aligned box\r\n * @param outMax\r\n * will hold the maximum corner of the resulting axis-aligned box\r\n * @return this\r\n */\r\n public Matrix4f transformAab(Vector3f min, Vector3f max, Vector3f outMin, Vector3f outMax) {\r\n return transformAab(min.x, min.y, min.z, max.x, max.y, max.z, outMin, outMax);\r\n }\r\n\r\n}\r\n"},"new_file":{"kind":"string","value":"src/org/joml/Matrix4f.java"},"old_contents":{"kind":"string","value":"/*\r\n * (C) Copyright 2015-2016 Richard Greenlees\r\n\r\n Permission is hereby granted, free of charge, to any person obtaining a copy\r\n of this software and associated documentation files (the \"Software\"), to deal\r\n in the Software without restriction, including without limitation the rights\r\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n copies of the Software, and to permit persons to whom the Software is\r\n furnished to do so, subject to the following conditions:\r\n\r\n The above copyright notice and this permission notice shall be included in\r\n all copies or substantial portions of the Software.\r\n\r\n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r\n THE SOFTWARE.\r\n\r\n */\r\npackage org.joml;\r\n\r\nimport java.io.Externalizable;\r\nimport java.io.IOException;\r\nimport java.io.ObjectInput;\r\nimport java.io.ObjectOutput;\r\nimport java.nio.Buffer;\r\nimport java.nio.ByteBuffer;\r\nimport java.nio.FloatBuffer;\r\nimport java.text.DecimalFormat;\r\nimport java.text.NumberFormat;\r\n\r\n/**\r\n * Contains the definition of a 4x4 Matrix of floats, and associated functions to transform\r\n * it. The matrix is column-major to match OpenGL's interpretation, and it looks like this:\r\n *
\r\n * m00 m10 m20 m30
\r\n * m01 m11 m21 m31
\r\n * m02 m12 m22 m32
\r\n * m03 m13 m23 m33
\r\n * \r\n * @author Richard Greenlees\r\n * @author Kai Burjack\r\n */\r\npublic class Matrix4f implements Externalizable {\r\n\r\n private static final long serialVersionUID = 1L;\r\n\r\n /**\r\n * Argument to the first parameter of {@link #frustumPlane(int, Vector4f)}\r\n * identifying the plane with equation x=-1 when using the identity matrix. \r\n */\r\n public static final int PLANE_NX = 0;\r\n /**\r\n * Argument to the first parameter of {@link #frustumPlane(int, Vector4f)}\r\n * identifying the plane with equation x=1 when using the identity matrix. \r\n */\r\n public static final int PLANE_PX = 1;\r\n /**\r\n * Argument to the first parameter of {@link #frustumPlane(int, Vector4f)}\r\n * identifying the plane with equation y=-1 when using the identity matrix. \r\n */\r\n public static final int PLANE_NY= 2;\r\n /**\r\n * Argument to the first parameter of {@link #frustumPlane(int, Vector4f)}\r\n * identifying the plane with equation y=1 when using the identity matrix. \r\n */\r\n public static final int PLANE_PY = 3;\r\n /**\r\n * Argument to the first parameter of {@link #frustumPlane(int, Vector4f)}\r\n * identifying the plane with equation z=-1 when using the identity matrix. \r\n */\r\n public static final int PLANE_NZ = 4;\r\n /**\r\n * Argument to the first parameter of {@link #frustumPlane(int, Vector4f)}\r\n * identifying the plane with equation z=1 when using the identity matrix. \r\n */\r\n public static final int PLANE_PZ = 5;\r\n\r\n /**\r\n * Argument to the first parameter of {@link #frustumCorner(int, Vector3f)}\r\n * identifying the corner (-1, -1, -1) when using the identity matrix.\r\n */\r\n public static final int CORNER_NXNYNZ = 0;\r\n /**\r\n * Argument to the first parameter of {@link #frustumCorner(int, Vector3f)}\r\n * identifying the corner (1, -1, -1) when using the identity matrix.\r\n */\r\n public static final int CORNER_PXNYNZ = 1;\r\n /**\r\n * Argument to the first parameter of {@link #frustumCorner(int, Vector3f)}\r\n * identifying the corner (1, 1, -1) when using the identity matrix.\r\n */\r\n public static final int CORNER_PXPYNZ = 2;\r\n /**\r\n * Argument to the first parameter of {@link #frustumCorner(int, Vector3f)}\r\n * identifying the corner (-1, 1, -1) when using the identity matrix.\r\n */\r\n public static final int CORNER_NXPYNZ = 3;\r\n /**\r\n * Argument to the first parameter of {@link #frustumCorner(int, Vector3f)}\r\n * identifying the corner (1, -1, 1) when using the identity matrix.\r\n */\r\n public static final int CORNER_PXNYPZ = 4;\r\n /**\r\n * Argument to the first parameter of {@link #frustumCorner(int, Vector3f)}\r\n * identifying the corner (-1, -1, 1) when using the identity matrix.\r\n */\r\n public static final int CORNER_NXNYPZ = 5;\r\n /**\r\n * Argument to the first parameter of {@link #frustumCorner(int, Vector3f)}\r\n * identifying the corner (-1, 1, 1) when using the identity matrix.\r\n */\r\n public static final int CORNER_NXPYPZ = 6;\r\n /**\r\n * Argument to the first parameter of {@link #frustumCorner(int, Vector3f)}\r\n * identifying the corner (1, 1, 1) when using the identity matrix.\r\n */\r\n public static final int CORNER_PXPYPZ = 7;\r\n\r\n public float m00, m10, m20, m30;\r\n public float m01, m11, m21, m31;\r\n public float m02, m12, m22, m32;\r\n public float m03, m13, m23, m33;\r\n\r\n /**\r\n * Create a new {@link Matrix4f} and set it to {@link #identity() identity}.\r\n */\r\n public Matrix4f() {\r\n m00 = 1.0f;\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = 1.0f;\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = 0.0f;\r\n m22 = 1.0f;\r\n m23 = 0.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n }\r\n\r\n /**\r\n * Create a new {@link Matrix4f} by setting its uppper left 3x3 submatrix to the values of the given {@link Matrix3f}\r\n * and the rest to identity.\r\n * \r\n * @param mat\r\n * the {@link Matrix3f}\r\n */\r\n public Matrix4f(Matrix3f mat) {\r\n m00 = mat.m00;\r\n m01 = mat.m01;\r\n m02 = mat.m02;\r\n m10 = mat.m10;\r\n m11 = mat.m11;\r\n m12 = mat.m12;\r\n m20 = mat.m20;\r\n m21 = mat.m21;\r\n m22 = mat.m22;\r\n m33 = 1.0f;\r\n }\r\n\r\n /**\r\n * Create a new {@link Matrix4f} and make it a copy of the given matrix.\r\n * \r\n * @param mat\r\n * the {@link Matrix4f} to copy the values from\r\n */\r\n public Matrix4f(Matrix4f mat) {\r\n m00 = mat.m00;\r\n m01 = mat.m01;\r\n m02 = mat.m02;\r\n m03 = mat.m03;\r\n m10 = mat.m10;\r\n m11 = mat.m11;\r\n m12 = mat.m12;\r\n m13 = mat.m13;\r\n m20 = mat.m20;\r\n m21 = mat.m21;\r\n m22 = mat.m22;\r\n m23 = mat.m23;\r\n m30 = mat.m30;\r\n m31 = mat.m31;\r\n m32 = mat.m32;\r\n m33 = mat.m33;\r\n }\r\n\r\n /**\r\n * Create a new {@link Matrix4f} and make it a copy of the given matrix.\r\n *
\r\n * Note that due to the given {@link Matrix4d} storing values in double-precision and the constructed {@link Matrix4f} storing them\r\n * in single-precision, there is the possibility of losing precision.\r\n * \r\n * @param mat\r\n * the {@link Matrix4d} to copy the values from\r\n */\r\n public Matrix4f(Matrix4d mat) {\r\n m00 = (float) mat.m00;\r\n m01 = (float) mat.m01;\r\n m02 = (float) mat.m02;\r\n m03 = (float) mat.m03;\r\n m10 = (float) mat.m10;\r\n m11 = (float) mat.m11;\r\n m12 = (float) mat.m12;\r\n m13 = (float) mat.m13;\r\n m20 = (float) mat.m20;\r\n m21 = (float) mat.m21;\r\n m22 = (float) mat.m22;\r\n m23 = (float) mat.m23;\r\n m30 = (float) mat.m30;\r\n m31 = (float) mat.m31;\r\n m32 = (float) mat.m32;\r\n m33 = (float) mat.m33;\r\n }\r\n\r\n /**\r\n * Create a new 4x4 matrix using the supplied float values.\r\n * \r\n * @param m00\r\n * the value of m00\r\n * @param m01\r\n * the value of m01\r\n * @param m02\r\n * the value of m02\r\n * @param m03\r\n * the value of m03\r\n * @param m10\r\n * the value of m10\r\n * @param m11\r\n * the value of m11\r\n * @param m12\r\n * the value of m12\r\n * @param m13\r\n * the value of m13\r\n * @param m20\r\n * the value of m20\r\n * @param m21\r\n * the value of m21\r\n * @param m22\r\n * the value of m22\r\n * @param m23\r\n * the value of m23\r\n * @param m30\r\n * the value of m30\r\n * @param m31\r\n * the value of m31\r\n * @param m32\r\n * the value of m32\r\n * @param m33\r\n * the value of m33\r\n */\r\n public Matrix4f(float m00, float m01, float m02, float m03, \r\n float m10, float m11, float m12, float m13, \r\n float m20, float m21, float m22, float m23,\r\n float m30, float m31, float m32, float m33) {\r\n this.m00 = m00;\r\n this.m01 = m01;\r\n this.m02 = m02;\r\n this.m03 = m03;\r\n this.m10 = m10;\r\n this.m11 = m11;\r\n this.m12 = m12;\r\n this.m13 = m13;\r\n this.m20 = m20;\r\n this.m21 = m21;\r\n this.m22 = m22;\r\n this.m23 = m23;\r\n this.m30 = m30;\r\n this.m31 = m31;\r\n this.m32 = m32;\r\n this.m33 = m33;\r\n }\r\n\r\n /**\r\n * Create a new {@link Matrix4f} by reading its 16 float components from the given {@link FloatBuffer}\r\n * at the buffer's current position.\r\n *
\r\n * That FloatBuffer is expected to hold the values in column-major order.\r\n *
\r\n * The buffer's position will not be changed by this method.\r\n * \r\n * @param buffer\r\n * the {@link FloatBuffer} to read the matrix values from\r\n */\r\n public Matrix4f(FloatBuffer buffer) {\r\n MemUtil.INSTANCE.get(this, buffer.position(), buffer);\r\n }\r\n\r\n /**\r\n * Return the value of the matrix element at column 0 and row 0.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m00() {\r\n return m00;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 0 and row 1.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m01() {\r\n return m01;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 0 and row 2.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m02() {\r\n return m02;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 0 and row 3.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m03() {\r\n return m03;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 1 and row 0.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m10() {\r\n return m10;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 1 and row 1.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m11() {\r\n return m11;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 1 and row 2.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m12() {\r\n return m12;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 1 and row 3.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m13() {\r\n return m13;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 2 and row 0.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m20() {\r\n return m20;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 2 and row 1.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m21() {\r\n return m21;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 2 and row 2.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m22() {\r\n return m22;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 2 and row 3.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m23() {\r\n return m23;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 3 and row 0.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m30() {\r\n return m30;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 3 and row 1.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m31() {\r\n return m31;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 3 and row 2.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m32() {\r\n return m32;\r\n }\r\n /**\r\n * Return the value of the matrix element at column 3 and row 3.\r\n * \r\n * @return the value of the matrix element\r\n */\r\n public float m33() {\r\n return m33;\r\n }\r\n\r\n /**\r\n * Set the value of the matrix element at column 0 and row 0\r\n * \r\n * @param m00\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m00(float m00) {\r\n this.m00 = m00;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 0 and row 1\r\n * \r\n * @param m01\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m01(float m01) {\r\n this.m01 = m01;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 0 and row 2\r\n * \r\n * @param m02\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m02(float m02) {\r\n this.m02 = m02;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 0 and row 3\r\n * \r\n * @param m03\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m03(float m03) {\r\n this.m03 = m03;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 1 and row 0\r\n * \r\n * @param m10\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m10(float m10) {\r\n this.m10 = m10;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 1 and row 1\r\n * \r\n * @param m11\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m11(float m11) {\r\n this.m11 = m11;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 1 and row 2\r\n * \r\n * @param m12\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m12(float m12) {\r\n this.m12 = m12;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 1 and row 3\r\n * \r\n * @param m13\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m13(float m13) {\r\n this.m13 = m13;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 2 and row 0\r\n * \r\n * @param m20\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m20(float m20) {\r\n this.m20 = m20;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 2 and row 1\r\n * \r\n * @param m21\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m21(float m21) {\r\n this.m21 = m21;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 2 and row 2\r\n * \r\n * @param m22\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m22(float m22) {\r\n this.m22 = m22;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 2 and row 3\r\n * \r\n * @param m23\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m23(float m23) {\r\n this.m23 = m23;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 3 and row 0\r\n * \r\n * @param m30\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m30(float m30) {\r\n this.m30 = m30;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 3 and row 1\r\n * \r\n * @param m31\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m31(float m31) {\r\n this.m31 = m31;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 3 and row 2\r\n * \r\n * @param m32\r\n * the new value\r\n * @return the value of the matrix element\r\n */\r\n public Matrix4f m32(float m32) {\r\n this.m32 = m32;\r\n return this;\r\n }\r\n /**\r\n * Set the value of the matrix element at column 3 and row 3\r\n * \r\n * @param m33\r\n * the new value\r\n * @return this\r\n */\r\n public Matrix4f m33(float m33) {\r\n this.m33 = m33;\r\n return this;\r\n }\r\n\r\n /**\r\n * Reset this matrix to the identity.\r\n *
\r\n * Please note that if a call to {@link #identity()} is immediately followed by a call to:\r\n * {@link #translate(float, float, float) translate}, \r\n * {@link #rotate(float, float, float, float) rotate},\r\n * {@link #scale(float, float, float) scale},\r\n * {@link #perspective(float, float, float, float) perspective},\r\n * {@link #frustum(float, float, float, float, float, float) frustum},\r\n * {@link #ortho(float, float, float, float, float, float) ortho},\r\n * {@link #ortho2D(float, float, float, float) ortho2D},\r\n * {@link #lookAt(float, float, float, float, float, float, float, float, float) lookAt},\r\n * {@link #lookAlong(float, float, float, float, float, float) lookAlong},\r\n * or any of their overloads, then the call to {@link #identity()} can be omitted and the subsequent call replaced with:\r\n * {@link #translation(float, float, float) translation},\r\n * {@link #rotation(float, float, float, float) rotation},\r\n * {@link #scaling(float, float, float) scaling},\r\n * {@link #setPerspective(float, float, float, float) setPerspective},\r\n * {@link #setFrustum(float, float, float, float, float, float) setFrustum},\r\n * {@link #setOrtho(float, float, float, float, float, float) setOrtho},\r\n * {@link #setOrtho2D(float, float, float, float) setOrtho2D},\r\n * {@link #setLookAt(float, float, float, float, float, float, float, float, float) setLookAt},\r\n * {@link #setLookAlong(float, float, float, float, float, float) setLookAlong},\r\n * or any of their overloads.\r\n * \r\n * @return this\r\n */\r\n public Matrix4f identity() {\r\n m00 = 1.0f;\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = 1.0f;\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = 0.0f;\r\n m22 = 1.0f;\r\n m23 = 0.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Store the values of the given matrix m
into this
matrix.\r\n * \r\n * @see #Matrix4f(Matrix4f)\r\n * @see #get(Matrix4f)\r\n * \r\n * @param m\r\n * the matrix to copy the values from\r\n * @return this\r\n */\r\n public Matrix4f set(Matrix4f m) {\r\n m00 = m.m00;\r\n m01 = m.m01;\r\n m02 = m.m02;\r\n m03 = m.m03;\r\n m10 = m.m10;\r\n m11 = m.m11;\r\n m12 = m.m12;\r\n m13 = m.m13;\r\n m20 = m.m20;\r\n m21 = m.m21;\r\n m22 = m.m22;\r\n m23 = m.m23;\r\n m30 = m.m30;\r\n m31 = m.m31;\r\n m32 = m.m32;\r\n m33 = m.m33;\r\n return this;\r\n }\r\n\r\n /**\r\n * Store the values of the given matrix m
into this
matrix.\r\n *
\r\n * Note that due to the given matrix m
storing values in double-precision and this
matrix storing\r\n * them in single-precision, there is the possibility to lose precision.\r\n * \r\n * @see #Matrix4f(Matrix4d)\r\n * @see #get(Matrix4d)\r\n * \r\n * @param m\r\n * the matrix to copy the values from\r\n * @return this\r\n */\r\n public Matrix4f set(Matrix4d m) {\r\n m00 = (float) m.m00;\r\n m01 = (float) m.m01;\r\n m02 = (float) m.m02;\r\n m03 = (float) m.m03;\r\n m10 = (float) m.m10;\r\n m11 = (float) m.m11;\r\n m12 = (float) m.m12;\r\n m13 = (float) m.m13;\r\n m20 = (float) m.m20;\r\n m21 = (float) m.m21;\r\n m22 = (float) m.m22;\r\n m23 = (float) m.m23;\r\n m30 = (float) m.m30;\r\n m31 = (float) m.m31;\r\n m32 = (float) m.m32;\r\n m33 = (float) m.m33;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the upper left 3x3 submatrix of this {@link Matrix4f} to the given {@link Matrix3f} \r\n * and the rest to identity.\r\n * \r\n * @see #Matrix4f(Matrix3f)\r\n * \r\n * @param mat\r\n * the {@link Matrix3f}\r\n * @return this\r\n */\r\n public Matrix4f set(Matrix3f mat) {\r\n m00 = mat.m00;\r\n m01 = mat.m01;\r\n m02 = mat.m02;\r\n m03 = 0.0f;\r\n m10 = mat.m10;\r\n m11 = mat.m11;\r\n m12 = mat.m12;\r\n m13 = 0.0f;\r\n m20 = mat.m20;\r\n m21 = mat.m21;\r\n m22 = mat.m22;\r\n m23 = 0.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be equivalent to the rotation specified by the given {@link AxisAngle4f}.\r\n * \r\n * @param axisAngle\r\n * the {@link AxisAngle4f}\r\n * @return this\r\n */\r\n public Matrix4f set(AxisAngle4f axisAngle) {\r\n float x = axisAngle.x;\r\n float y = axisAngle.y;\r\n float z = axisAngle.z;\r\n double angle = axisAngle.angle;\r\n double n = Math.sqrt(x*x + y*y + z*z);\r\n n = 1/n;\r\n x *= n;\r\n y *= n;\r\n z *= n;\r\n double c = Math.cos(angle);\r\n double s = Math.sin(angle);\r\n double omc = 1.0 - c;\r\n m00 = (float)(c + x*x*omc);\r\n m11 = (float)(c + y*y*omc);\r\n m22 = (float)(c + z*z*omc);\r\n double tmp1 = x*y*omc;\r\n double tmp2 = z*s;\r\n m10 = (float)(tmp1 - tmp2);\r\n m01 = (float)(tmp1 + tmp2);\r\n tmp1 = x*z*omc;\r\n tmp2 = y*s;\r\n m20 = (float)(tmp1 + tmp2);\r\n m02 = (float)(tmp1 - tmp2);\r\n tmp1 = y*z*omc;\r\n tmp2 = x*s;\r\n m21 = (float)(tmp1 - tmp2);\r\n m12 = (float)(tmp1 + tmp2);\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be equivalent to the rotation specified by the given {@link AxisAngle4d}.\r\n * \r\n * @param axisAngle\r\n * the {@link AxisAngle4d}\r\n * @return this\r\n */\r\n public Matrix4f set(AxisAngle4d axisAngle) {\r\n double x = axisAngle.x;\r\n double y = axisAngle.y;\r\n double z = axisAngle.z;\r\n double angle = axisAngle.angle;\r\n double n = Math.sqrt(x*x + y*y + z*z);\r\n n = 1/n;\r\n x *= n;\r\n y *= n;\r\n z *= n;\r\n double c = Math.cos(angle);\r\n double s = Math.sin(angle);\r\n double omc = 1.0 - c;\r\n m00 = (float)(c + x*x*omc);\r\n m11 = (float)(c + y*y*omc);\r\n m22 = (float)(c + z*z*omc);\r\n double tmp1 = x*y*omc;\r\n double tmp2 = z*s;\r\n m10 = (float)(tmp1 - tmp2);\r\n m01 = (float)(tmp1 + tmp2);\r\n tmp1 = x*z*omc;\r\n tmp2 = y*s;\r\n m20 = (float)(tmp1 + tmp2);\r\n m02 = (float)(tmp1 - tmp2);\r\n tmp1 = y*z*omc;\r\n tmp2 = x*s;\r\n m21 = (float)(tmp1 - tmp2);\r\n m12 = (float)(tmp1 + tmp2);\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be equivalent to the rotation specified by the given {@link Quaternionf}.\r\n * \r\n * @see Quaternionf#get(Matrix4f)\r\n * \r\n * @param q\r\n * the {@link Quaternionf}\r\n * @return this\r\n */\r\n public Matrix4f set(Quaternionf q) {\r\n q.get(this);\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be equivalent to the rotation specified by the given {@link Quaterniond}.\r\n * \r\n * @see Quaterniond#get(Matrix4f)\r\n * \r\n * @param q\r\n * the {@link Quaterniond}\r\n * @return this\r\n */\r\n public Matrix4f set(Quaterniond q) {\r\n q.get(this);\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the upper left 3x3 submatrix of this {@link Matrix4f} to that of the given {@link Matrix4f} \r\n * and don't change the other elements.\r\n * \r\n * @param mat\r\n * the {@link Matrix4f}\r\n * @return this\r\n */\r\n public Matrix4f set3x3(Matrix4f mat) {\r\n m00 = mat.m00;\r\n m01 = mat.m01;\r\n m02 = mat.m02;\r\n m10 = mat.m10;\r\n m11 = mat.m11;\r\n m12 = mat.m12;\r\n m20 = mat.m20;\r\n m21 = mat.m21;\r\n m22 = mat.m22;\r\n return this;\r\n }\r\n\r\n /**\r\n * Multiply this matrix by the supplied right
matrix and store the result in this
.\r\n *
\r\n * If M
is this
matrix and R
the right
matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * transformation of the right matrix will be applied first!\r\n *\r\n * @param right\r\n * the right operand of the matrix multiplication\r\n * @return this\r\n */\r\n public Matrix4f mul(Matrix4f right) {\r\n return mul(right, this);\r\n }\r\n\r\n /**\r\n * Multiply this matrix by the supplied right
matrix and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and R
the right
matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * transformation of the right matrix will be applied first!\r\n *\r\n * @param right\r\n * the right operand of the matrix multiplication\r\n * @param dest\r\n * the destination matrix, which will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f mul(Matrix4f right, Matrix4f dest) {\r\n float nm00 = m00 * right.m00 + m10 * right.m01 + m20 * right.m02 + m30 * right.m03;\r\n float nm01 = m01 * right.m00 + m11 * right.m01 + m21 * right.m02 + m31 * right.m03;\r\n float nm02 = m02 * right.m00 + m12 * right.m01 + m22 * right.m02 + m32 * right.m03;\r\n float nm03 = m03 * right.m00 + m13 * right.m01 + m23 * right.m02 + m33 * right.m03;\r\n float nm10 = m00 * right.m10 + m10 * right.m11 + m20 * right.m12 + m30 * right.m13;\r\n float nm11 = m01 * right.m10 + m11 * right.m11 + m21 * right.m12 + m31 * right.m13;\r\n float nm12 = m02 * right.m10 + m12 * right.m11 + m22 * right.m12 + m32 * right.m13;\r\n float nm13 = m03 * right.m10 + m13 * right.m11 + m23 * right.m12 + m33 * right.m13;\r\n float nm20 = m00 * right.m20 + m10 * right.m21 + m20 * right.m22 + m30 * right.m23;\r\n float nm21 = m01 * right.m20 + m11 * right.m21 + m21 * right.m22 + m31 * right.m23;\r\n float nm22 = m02 * right.m20 + m12 * right.m21 + m22 * right.m22 + m32 * right.m23;\r\n float nm23 = m03 * right.m20 + m13 * right.m21 + m23 * right.m22 + m33 * right.m23;\r\n float nm30 = m00 * right.m30 + m10 * right.m31 + m20 * right.m32 + m30 * right.m33;\r\n float nm31 = m01 * right.m30 + m11 * right.m31 + m21 * right.m32 + m31 * right.m33;\r\n float nm32 = m02 * right.m30 + m12 * right.m31 + m22 * right.m32 + m32 * right.m33;\r\n float nm33 = m03 * right.m30 + m13 * right.m31 + m23 * right.m32 + m33 * right.m33;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Multiply this
symmetric perspective projection matrix by the supplied {@link #isAffine() affine} view
matrix.\r\n *
\r\n * If P
is this
matrix and V
the view
matrix,\r\n * then the new matrix will be P * V
. So when transforming a\r\n * vector v
with the new matrix by using P * V * v
, the\r\n * transformation of the view
matrix will be applied first!\r\n *\r\n * @param view\r\n * the {@link #isAffine() affine} matrix to multiply this
symmetric perspective projection matrix by\r\n * @return dest\r\n */\r\n public Matrix4f mulPerspectiveAffine(Matrix4f view) {\r\n return mulPerspectiveAffine(view, this);\r\n }\r\n\r\n /**\r\n * Multiply this
symmetric perspective projection matrix by the supplied {@link #isAffine() affine} view
matrix and store the result in dest
.\r\n *
\r\n * If P
is this
matrix and V
the view
matrix,\r\n * then the new matrix will be P * V
. So when transforming a\r\n * vector v
with the new matrix by using P * V * v
, the\r\n * transformation of the view
matrix will be applied first!\r\n *\r\n * @param view\r\n * the {@link #isAffine() affine} matrix to multiply this
symmetric perspective projection matrix by\r\n * @param dest\r\n * the destination matrix, which will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f mulPerspectiveAffine(Matrix4f view, Matrix4f dest) {\r\n float nm00 = m00 * view.m00;\r\n float nm01 = m11 * view.m01;\r\n float nm02 = m22 * view.m02;\r\n float nm03 = m23 * view.m02;\r\n float nm10 = m00 * view.m10;\r\n float nm11 = m11 * view.m11;\r\n float nm12 = m22 * view.m12;\r\n float nm13 = m23 * view.m12;\r\n float nm20 = m00 * view.m20;\r\n float nm21 = m11 * view.m21;\r\n float nm22 = m22 * view.m22;\r\n float nm23 = m23 * view.m22;\r\n float nm30 = m00 * view.m30;\r\n float nm31 = m11 * view.m31;\r\n float nm32 = m22 * view.m32 + m32;\r\n float nm33 = m23 * view.m32;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Multiply this matrix by the supplied right
matrix, which is assumed to be {@link #isAffine() affine}, and store the result in this
.\r\n *
\r\n * This method assumes that the given right
matrix represents an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and can be used to speed up matrix multiplication if the matrix only represents affine transformations, such as translation, rotation, scaling and shearing (in any combination).\r\n *
\r\n * If M
is this
matrix and R
the right
matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * transformation of the right matrix will be applied first!\r\n *\r\n * @param right\r\n * the right operand of the matrix multiplication (the last row is assumed to be (0, 0, 0, 1))\r\n * @return this\r\n */\r\n public Matrix4f mulAffineR(Matrix4f right) {\r\n return mulAffineR(right, this);\r\n }\r\n\r\n /**\r\n * Multiply this matrix by the supplied right
matrix, which is assumed to be {@link #isAffine() affine}, and store the result in dest
.\r\n *
\r\n * This method assumes that the given right
matrix represents an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and can be used to speed up matrix multiplication if the matrix only represents affine transformations, such as translation, rotation, scaling and shearing (in any combination).\r\n *
\r\n * If M
is this
matrix and R
the right
matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * transformation of the right matrix will be applied first!\r\n *\r\n * @param right\r\n * the right operand of the matrix multiplication (the last row is assumed to be (0, 0, 0, 1))\r\n * @param dest\r\n * the destination matrix, which will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f mulAffineR(Matrix4f right, Matrix4f dest) {\r\n float nm00 = m00 * right.m00 + m10 * right.m01 + m20 * right.m02;\r\n float nm01 = m01 * right.m00 + m11 * right.m01 + m21 * right.m02;\r\n float nm02 = m02 * right.m00 + m12 * right.m01 + m22 * right.m02;\r\n float nm03 = m03 * right.m00 + m13 * right.m01 + m23 * right.m02;\r\n float nm10 = m00 * right.m10 + m10 * right.m11 + m20 * right.m12;\r\n float nm11 = m01 * right.m10 + m11 * right.m11 + m21 * right.m12;\r\n float nm12 = m02 * right.m10 + m12 * right.m11 + m22 * right.m12;\r\n float nm13 = m03 * right.m10 + m13 * right.m11 + m23 * right.m12;\r\n float nm20 = m00 * right.m20 + m10 * right.m21 + m20 * right.m22;\r\n float nm21 = m01 * right.m20 + m11 * right.m21 + m21 * right.m22;\r\n float nm22 = m02 * right.m20 + m12 * right.m21 + m22 * right.m22;\r\n float nm23 = m03 * right.m20 + m13 * right.m21 + m23 * right.m22;\r\n float nm30 = m00 * right.m30 + m10 * right.m31 + m20 * right.m32 + m30;\r\n float nm31 = m01 * right.m30 + m11 * right.m31 + m21 * right.m32 + m31;\r\n float nm32 = m02 * right.m30 + m12 * right.m31 + m22 * right.m32 + m32;\r\n float nm33 = m03 * right.m30 + m13 * right.m31 + m23 * right.m32 + m33;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Multiply this matrix by the supplied right
matrix, both of which are assumed to be {@link #isAffine() affine}, and store the result in this
.\r\n *
\r\n * This method assumes that this
matrix and the given right
matrix both represent an {@link #isAffine() affine} transformation\r\n * (i.e. their last rows are equal to (0, 0, 0, 1))\r\n * and can be used to speed up matrix multiplication if the matrices only represent affine transformations, such as translation, rotation, scaling and shearing (in any combination).\r\n *
\r\n * This method will not modify either the last row of this
or the last row of right
.\r\n *
\r\n * If M
is this
matrix and R
the right
matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * transformation of the right matrix will be applied first!\r\n *\r\n * @param right\r\n * the right operand of the matrix multiplication (the last row is assumed to be (0, 0, 0, 1))\r\n * @return this\r\n */\r\n public Matrix4f mulAffine(Matrix4f right) {\r\n return mulAffine(right, this);\r\n }\r\n\r\n /**\r\n * Multiply this matrix by the supplied right
matrix, both of which are assumed to be {@link #isAffine() affine}, and store the result in dest
.\r\n *
\r\n * This method assumes that this
matrix and the given right
matrix both represent an {@link #isAffine() affine} transformation\r\n * (i.e. their last rows are equal to (0, 0, 0, 1))\r\n * and can be used to speed up matrix multiplication if the matrices only represent affine transformations, such as translation, rotation, scaling and shearing (in any combination).\r\n *
\r\n * This method will not modify either the last row of this
or the last row of right
.\r\n *
\r\n * If M
is this
matrix and R
the right
matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * transformation of the right matrix will be applied first!\r\n *\r\n * @param right\r\n * the right operand of the matrix multiplication (the last row is assumed to be (0, 0, 0, 1))\r\n * @param dest\r\n * the destination matrix, which will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f mulAffine(Matrix4f right, Matrix4f dest) {\r\n float nm00 = m00 * right.m00 + m10 * right.m01 + m20 * right.m02;\r\n float nm01 = m01 * right.m00 + m11 * right.m01 + m21 * right.m02;\r\n float nm02 = m02 * right.m00 + m12 * right.m01 + m22 * right.m02;\r\n float nm03 = m03;\r\n float nm10 = m00 * right.m10 + m10 * right.m11 + m20 * right.m12;\r\n float nm11 = m01 * right.m10 + m11 * right.m11 + m21 * right.m12;\r\n float nm12 = m02 * right.m10 + m12 * right.m11 + m22 * right.m12;\r\n float nm13 = m13;\r\n float nm20 = m00 * right.m20 + m10 * right.m21 + m20 * right.m22;\r\n float nm21 = m01 * right.m20 + m11 * right.m21 + m21 * right.m22;\r\n float nm22 = m02 * right.m20 + m12 * right.m21 + m22 * right.m22;\r\n float nm23 = m23;\r\n float nm30 = m00 * right.m30 + m10 * right.m31 + m20 * right.m32 + m30;\r\n float nm31 = m01 * right.m30 + m11 * right.m31 + m21 * right.m32 + m31;\r\n float nm32 = m02 * right.m30 + m12 * right.m31 + m22 * right.m32 + m32;\r\n float nm33 = m33;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Multiply this
orthographic projection matrix by the supplied {@link #isAffine() affine} view
matrix.\r\n *
\r\n * If M
is this
matrix and V
the view
matrix,\r\n * then the new matrix will be M * V
. So when transforming a\r\n * vector v
with the new matrix by using M * V * v
, the\r\n * transformation of the view
matrix will be applied first!\r\n *\r\n * @param view\r\n * the affine matrix which to multiply this
with\r\n * @return dest\r\n */\r\n public Matrix4f mulOrthoAffine(Matrix4f view) {\r\n return mulOrthoAffine(view, this);\r\n }\r\n\r\n /**\r\n * Multiply this
orthographic projection matrix by the supplied {@link #isAffine() affine} view
matrix\r\n * and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and V
the view
matrix,\r\n * then the new matrix will be M * V
. So when transforming a\r\n * vector v
with the new matrix by using M * V * v
, the\r\n * transformation of the view
matrix will be applied first!\r\n *\r\n * @param view\r\n * the affine matrix which to multiply this
with\r\n * @param dest\r\n * the destination matrix, which will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f mulOrthoAffine(Matrix4f view, Matrix4f dest) {\r\n float nm00 = m00 * view.m00;\r\n float nm01 = m11 * view.m01;\r\n float nm02 = m22 * view.m02;\r\n float nm03 = 0.0f;\r\n float nm10 = m00 * view.m10;\r\n float nm11 = m11 * view.m11;\r\n float nm12 = m22 * view.m12;\r\n float nm13 = 0.0f;\r\n float nm20 = m00 * view.m20;\r\n float nm21 = m11 * view.m21;\r\n float nm22 = m22 * view.m22;\r\n float nm23 = 0.0f;\r\n float nm30 = m00 * view.m30 + m30;\r\n float nm31 = m11 * view.m31 + m31;\r\n float nm32 = m22 * view.m32 + m32;\r\n float nm33 = 1.0f;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Component-wise add the upper 4x3 submatrices of this
and other
\r\n * by first multiplying each component of other
's 4x3 submatrix by otherFactor
and\r\n * adding that result to this
.\r\n *
\r\n * The matrix other
will not be changed.\r\n * \r\n * @param other\r\n * the other matrix \r\n * @param otherFactor\r\n * the factor to multiply each of the other matrix's 4x3 components\r\n * @return this\r\n */\r\n public Matrix4f fma4x3(Matrix4f other, float otherFactor) {\r\n return fma4x3(other, otherFactor, this);\r\n }\r\n\r\n /**\r\n * Component-wise add the upper 4x3 submatrices of this
and other
\r\n * by first multiplying each component of other
's 4x3 submatrix by otherFactor
,\r\n * adding that to this
and storing the final result in dest
.\r\n *
\r\n * The other components of dest
will be set to the ones of this
.\r\n *
\r\n * The matrices this
and other
will not be changed.\r\n * \r\n * @param other\r\n * the other matrix \r\n * @param otherFactor\r\n * the factor to multiply each of the other matrix's 4x3 components\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f fma4x3(Matrix4f other, float otherFactor, Matrix4f dest) {\r\n dest.m00 = m00 + other.m00 * otherFactor;\r\n dest.m01 = m01 + other.m01 * otherFactor;\r\n dest.m02 = m02 + other.m02 * otherFactor;\r\n dest.m03 = m03;\r\n dest.m10 = m10 + other.m10 * otherFactor;\r\n dest.m11 = m11 + other.m11 * otherFactor;\r\n dest.m12 = m12 + other.m12 * otherFactor;\r\n dest.m13 = m13;\r\n dest.m20 = m20 + other.m20 * otherFactor;\r\n dest.m21 = m21 + other.m21 * otherFactor;\r\n dest.m22 = m22 + other.m22 * otherFactor;\r\n dest.m23 = m23;\r\n dest.m30 = m30 + other.m30 * otherFactor;\r\n dest.m31 = m31 + other.m31 * otherFactor;\r\n dest.m32 = m32 + other.m32 * otherFactor;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Component-wise add this
and other
.\r\n * \r\n * @param other\r\n * the other addend \r\n * @return this\r\n */\r\n public Matrix4f add(Matrix4f other) {\r\n return add(other, this);\r\n }\r\n\r\n /**\r\n * Component-wise add this
and other
and store the result in dest
.\r\n * \r\n * @param other\r\n * the other addend \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f add(Matrix4f other, Matrix4f dest) {\r\n dest.m00 = m00 + other.m00;\r\n dest.m01 = m01 + other.m01;\r\n dest.m02 = m02 + other.m02;\r\n dest.m03 = m03 + other.m03;\r\n dest.m10 = m10 + other.m10;\r\n dest.m11 = m11 + other.m11;\r\n dest.m12 = m12 + other.m12;\r\n dest.m13 = m13 + other.m13;\r\n dest.m20 = m20 + other.m20;\r\n dest.m21 = m21 + other.m21;\r\n dest.m22 = m22 + other.m22;\r\n dest.m23 = m23 + other.m23;\r\n dest.m30 = m30 + other.m30;\r\n dest.m31 = m31 + other.m31;\r\n dest.m32 = m32 + other.m32;\r\n dest.m33 = m33 + other.m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Component-wise subtract subtrahend
from this
.\r\n * \r\n * @param subtrahend\r\n * the subtrahend\r\n * @return this\r\n */\r\n public Matrix4f sub(Matrix4f subtrahend) {\r\n return sub(subtrahend, this);\r\n }\r\n\r\n /**\r\n * Component-wise subtract subtrahend
from this
and store the result in dest
.\r\n * \r\n * @param subtrahend\r\n * the subtrahend \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f sub(Matrix4f subtrahend, Matrix4f dest) {\r\n dest.m00 = m00 - subtrahend.m00;\r\n dest.m01 = m01 - subtrahend.m01;\r\n dest.m02 = m02 - subtrahend.m02;\r\n dest.m03 = m03 - subtrahend.m03;\r\n dest.m10 = m10 - subtrahend.m10;\r\n dest.m11 = m11 - subtrahend.m11;\r\n dest.m12 = m12 - subtrahend.m12;\r\n dest.m13 = m13 - subtrahend.m13;\r\n dest.m20 = m20 - subtrahend.m20;\r\n dest.m21 = m21 - subtrahend.m21;\r\n dest.m22 = m22 - subtrahend.m22;\r\n dest.m23 = m23 - subtrahend.m23;\r\n dest.m30 = m30 - subtrahend.m30;\r\n dest.m31 = m31 - subtrahend.m31;\r\n dest.m32 = m32 - subtrahend.m32;\r\n dest.m33 = m33 - subtrahend.m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Component-wise multiply this
by other
.\r\n * \r\n * @param other\r\n * the other matrix\r\n * @return this\r\n */\r\n public Matrix4f mulComponentWise(Matrix4f other) {\r\n return mulComponentWise(other, this);\r\n }\r\n\r\n /**\r\n * Component-wise multiply this
by other
and store the result in dest
.\r\n * \r\n * @param other\r\n * the other matrix\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f mulComponentWise(Matrix4f other, Matrix4f dest) {\r\n dest.m00 = m00 * other.m00;\r\n dest.m01 = m01 * other.m01;\r\n dest.m02 = m02 * other.m02;\r\n dest.m03 = m03 * other.m03;\r\n dest.m10 = m10 * other.m10;\r\n dest.m11 = m11 * other.m11;\r\n dest.m12 = m12 * other.m12;\r\n dest.m13 = m13 * other.m13;\r\n dest.m20 = m20 * other.m20;\r\n dest.m21 = m21 * other.m21;\r\n dest.m22 = m22 * other.m22;\r\n dest.m23 = m23 * other.m23;\r\n dest.m30 = m30 * other.m30;\r\n dest.m31 = m31 * other.m31;\r\n dest.m32 = m32 * other.m32;\r\n dest.m33 = m33 * other.m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Component-wise add the upper 4x3 submatrices of this
and other
.\r\n * \r\n * @param other\r\n * the other addend \r\n * @return this\r\n */\r\n public Matrix4f add4x3(Matrix4f other) {\r\n return add4x3(other, this);\r\n }\r\n\r\n /**\r\n * Component-wise add the upper 4x3 submatrices of this
and other
\r\n * and store the result in dest
.\r\n *
\r\n * The other components of dest
will be set to the ones of this
.\r\n * \r\n * @param other\r\n * the other addend\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f add4x3(Matrix4f other, Matrix4f dest) {\r\n dest.m00 = m00 + other.m00;\r\n dest.m01 = m01 + other.m01;\r\n dest.m02 = m02 + other.m02;\r\n dest.m03 = m03;\r\n dest.m10 = m10 + other.m10;\r\n dest.m11 = m11 + other.m11;\r\n dest.m12 = m12 + other.m12;\r\n dest.m13 = m13;\r\n dest.m20 = m20 + other.m20;\r\n dest.m21 = m21 + other.m21;\r\n dest.m22 = m22 + other.m22;\r\n dest.m23 = m23;\r\n dest.m30 = m30 + other.m30;\r\n dest.m31 = m31 + other.m31;\r\n dest.m32 = m32 + other.m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Component-wise subtract the upper 4x3 submatrices of subtrahend
from this
.\r\n * \r\n * @param subtrahend\r\n * the subtrahend\r\n * @return this\r\n */\r\n public Matrix4f sub4x3(Matrix4f subtrahend) {\r\n return sub4x3(subtrahend, this);\r\n }\r\n\r\n /**\r\n * Component-wise subtract the upper 4x3 submatrices of subtrahend
from this
\r\n * and store the result in dest
.\r\n *
\r\n * The other components of dest
will be set to the ones of this
.\r\n * \r\n * @param subtrahend\r\n * the subtrahend\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f sub4x3(Matrix4f subtrahend, Matrix4f dest) {\r\n dest.m00 = m00 - subtrahend.m00;\r\n dest.m01 = m01 - subtrahend.m01;\r\n dest.m02 = m02 - subtrahend.m02;\r\n dest.m03 = m03;\r\n dest.m10 = m10 - subtrahend.m10;\r\n dest.m11 = m11 - subtrahend.m11;\r\n dest.m12 = m12 - subtrahend.m12;\r\n dest.m13 = m13;\r\n dest.m20 = m20 - subtrahend.m20;\r\n dest.m21 = m21 - subtrahend.m21;\r\n dest.m22 = m22 - subtrahend.m22;\r\n dest.m23 = m23;\r\n dest.m30 = m30 - subtrahend.m30;\r\n dest.m31 = m31 - subtrahend.m31;\r\n dest.m32 = m32 - subtrahend.m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Component-wise multiply the upper 4x3 submatrices of this
by other
.\r\n * \r\n * @param other\r\n * the other matrix\r\n * @return this\r\n */\r\n public Matrix4f mul4x3ComponentWise(Matrix4f other) {\r\n return mul4x3ComponentWise(other, this);\r\n }\r\n\r\n /**\r\n * Component-wise multiply the upper 4x3 submatrices of this
by other
\r\n * and store the result in dest
.\r\n *
\r\n * The other components of dest
will be set to the ones of this
.\r\n * \r\n * @param other\r\n * the other matrix\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f mul4x3ComponentWise(Matrix4f other, Matrix4f dest) {\r\n dest.m00 = m00 * other.m00;\r\n dest.m01 = m01 * other.m01;\r\n dest.m02 = m02 * other.m02;\r\n dest.m03 = m03;\r\n dest.m10 = m10 * other.m10;\r\n dest.m11 = m11 * other.m11;\r\n dest.m12 = m12 * other.m12;\r\n dest.m13 = m13;\r\n dest.m20 = m20 * other.m20;\r\n dest.m21 = m21 * other.m21;\r\n dest.m22 = m22 * other.m22;\r\n dest.m23 = m23;\r\n dest.m30 = m30 * other.m30;\r\n dest.m31 = m31 * other.m31;\r\n dest.m32 = m32 * other.m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Set the values within this matrix to the supplied float values. The matrix will look like this:
\r\n *\r\n * m00, m10, m20, m30
\r\n * m01, m11, m21, m31
\r\n * m02, m12, m22, m32
\r\n * m03, m13, m23, m33\r\n * \r\n * @param m00\r\n * the new value of m00\r\n * @param m01\r\n * the new value of m01\r\n * @param m02\r\n * the new value of m02\r\n * @param m03\r\n * the new value of m03\r\n * @param m10\r\n * the new value of m10\r\n * @param m11\r\n * the new value of m11\r\n * @param m12\r\n * the new value of m12\r\n * @param m13\r\n * the new value of m13\r\n * @param m20\r\n * the new value of m20\r\n * @param m21\r\n * the new value of m21\r\n * @param m22\r\n * the new value of m22\r\n * @param m23\r\n * the new value of m23\r\n * @param m30\r\n * the new value of m30\r\n * @param m31\r\n * the new value of m31\r\n * @param m32\r\n * the new value of m32\r\n * @param m33\r\n * the new value of m33\r\n * @return this\r\n */\r\n public Matrix4f set(float m00, float m01, float m02, float m03,\r\n float m10, float m11, float m12, float m13,\r\n float m20, float m21, float m22, float m23, \r\n float m30, float m31, float m32, float m33) {\r\n this.m00 = m00;\r\n this.m01 = m01;\r\n this.m02 = m02;\r\n this.m03 = m03;\r\n this.m10 = m10;\r\n this.m11 = m11;\r\n this.m12 = m12;\r\n this.m13 = m13;\r\n this.m20 = m20;\r\n this.m21 = m21;\r\n this.m22 = m22;\r\n this.m23 = m23;\r\n this.m30 = m30;\r\n this.m31 = m31;\r\n this.m32 = m32;\r\n this.m33 = m33;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the values in the matrix using a float array that contains the matrix elements in column-major order.\r\n *
\r\n * The results will look like this:
\r\n * \r\n * 0, 4, 8, 12
\r\n * 1, 5, 9, 13
\r\n * 2, 6, 10, 14
\r\n * 3, 7, 11, 15
\r\n * \r\n * @see #set(float[])\r\n * \r\n * @param m\r\n * the array to read the matrix values from\r\n * @param off\r\n * the offset into the array\r\n * @return this\r\n */\r\n public Matrix4f set(float m[], int off) {\r\n m00 = m[off+0];\r\n m01 = m[off+1];\r\n m02 = m[off+2];\r\n m03 = m[off+3];\r\n m10 = m[off+4];\r\n m11 = m[off+5];\r\n m12 = m[off+6];\r\n m13 = m[off+7];\r\n m20 = m[off+8];\r\n m21 = m[off+9];\r\n m22 = m[off+10];\r\n m23 = m[off+11];\r\n m30 = m[off+12];\r\n m31 = m[off+13];\r\n m32 = m[off+14];\r\n m33 = m[off+15];\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the values in the matrix using a float array that contains the matrix elements in column-major order.\r\n *
\r\n * The results will look like this:
\r\n * \r\n * 0, 4, 8, 12
\r\n * 1, 5, 9, 13
\r\n * 2, 6, 10, 14
\r\n * 3, 7, 11, 15
\r\n * \r\n * @see #set(float[], int)\r\n * \r\n * @param m\r\n * the array to read the matrix values from\r\n * @return this\r\n */\r\n public Matrix4f set(float m[]) {\r\n return set(m, 0);\r\n }\r\n\r\n /**\r\n * Set the values of this matrix by reading 16 float values from the given {@link FloatBuffer} in column-major order,\r\n * starting at its current position.\r\n *
\r\n * The FloatBuffer is expected to contain the values in column-major order.\r\n *
\r\n * The position of the FloatBuffer will not be changed by this method.\r\n * \r\n * @param buffer\r\n * the FloatBuffer to read the matrix values from in column-major order\r\n * @return this\r\n */\r\n public Matrix4f set(FloatBuffer buffer) {\r\n MemUtil.INSTANCE.get(this, buffer.position(), buffer);\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the values of this matrix by reading 16 float values from the given {@link ByteBuffer} in column-major order,\r\n * starting at its current position.\r\n *
\r\n * The ByteBuffer is expected to contain the values in column-major order.\r\n *
\r\n * The position of the ByteBuffer will not be changed by this method.\r\n * \r\n * @param buffer\r\n * the ByteBuffer to read the matrix values from in column-major order\r\n * @return this\r\n */\r\n public Matrix4f set(ByteBuffer buffer) {\r\n MemUtil.INSTANCE.get(this, buffer.position(), buffer);\r\n return this;\r\n }\r\n\r\n /**\r\n * Return the determinant of this matrix.\r\n *
\r\n * If this
matrix represents an {@link #isAffine() affine} transformation, such as translation, rotation, scaling and shearing,\r\n * and thus its last row is equal to (0, 0, 0, 1), then {@link #determinantAffine()} can be used instead of this method.\r\n * \r\n * @see #determinantAffine()\r\n * \r\n * @return the determinant\r\n */\r\n public float determinant() {\r\n return (m00 * m11 - m01 * m10) * (m22 * m33 - m23 * m32)\r\n + (m02 * m10 - m00 * m12) * (m21 * m33 - m23 * m31)\r\n + (m00 * m13 - m03 * m10) * (m21 * m32 - m22 * m31)\r\n + (m01 * m12 - m02 * m11) * (m20 * m33 - m23 * m30)\r\n + (m03 * m11 - m01 * m13) * (m20 * m32 - m22 * m30)\r\n + (m02 * m13 - m03 * m12) * (m20 * m31 - m21 * m30);\r\n }\r\n\r\n /**\r\n * Return the determinant of the upper left 3x3 submatrix of this matrix.\r\n * \r\n * @return the determinant\r\n */\r\n public float determinant3x3() {\r\n return (m00 * m11 - m01 * m10) * m22\r\n + (m02 * m10 - m00 * m12) * m21\r\n + (m01 * m12 - m02 * m11) * m20;\r\n }\r\n\r\n /**\r\n * Return the determinant of this matrix by assuming that it represents an {@link #isAffine() affine} transformation and thus\r\n * its last row is equal to (0, 0, 0, 1).\r\n * \r\n * @return the determinant\r\n */\r\n public float determinantAffine() {\r\n return (m00 * m11 - m01 * m10) * m22\r\n + (m02 * m10 - m00 * m12) * m21\r\n + (m01 * m12 - m02 * m11) * m20;\r\n }\r\n\r\n /**\r\n * Invert this matrix and write the result into dest
.\r\n *
\r\n * If this
matrix represents an {@link #isAffine() affine} transformation, such as translation, rotation, scaling and shearing,\r\n * and thus its last row is equal to (0, 0, 0, 1), then {@link #invertAffine(Matrix4f)} can be used instead of this method.\r\n * \r\n * @see #invertAffine(Matrix4f)\r\n * \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f invert(Matrix4f dest) {\r\n float a = m00 * m11 - m01 * m10;\r\n float b = m00 * m12 - m02 * m10;\r\n float c = m00 * m13 - m03 * m10;\r\n float d = m01 * m12 - m02 * m11;\r\n float e = m01 * m13 - m03 * m11;\r\n float f = m02 * m13 - m03 * m12;\r\n float g = m20 * m31 - m21 * m30;\r\n float h = m20 * m32 - m22 * m30;\r\n float i = m20 * m33 - m23 * m30;\r\n float j = m21 * m32 - m22 * m31;\r\n float k = m21 * m33 - m23 * m31;\r\n float l = m22 * m33 - m23 * m32;\r\n float det = a * l - b * k + c * j + d * i - e * h + f * g;\r\n det = 1.0f / det;\r\n float nm00 = ( m11 * l - m12 * k + m13 * j) * det;\r\n float nm01 = (-m01 * l + m02 * k - m03 * j) * det;\r\n float nm02 = ( m31 * f - m32 * e + m33 * d) * det;\r\n float nm03 = (-m21 * f + m22 * e - m23 * d) * det;\r\n float nm10 = (-m10 * l + m12 * i - m13 * h) * det;\r\n float nm11 = ( m00 * l - m02 * i + m03 * h) * det;\r\n float nm12 = (-m30 * f + m32 * c - m33 * b) * det;\r\n float nm13 = ( m20 * f - m22 * c + m23 * b) * det;\r\n float nm20 = ( m10 * k - m11 * i + m13 * g) * det;\r\n float nm21 = (-m00 * k + m01 * i - m03 * g) * det;\r\n float nm22 = ( m30 * e - m31 * c + m33 * a) * det;\r\n float nm23 = (-m20 * e + m21 * c - m23 * a) * det;\r\n float nm30 = (-m10 * j + m11 * h - m12 * g) * det;\r\n float nm31 = ( m00 * j - m01 * h + m02 * g) * det;\r\n float nm32 = (-m30 * d + m31 * b - m32 * a) * det;\r\n float nm33 = ( m20 * d - m21 * b + m22 * a) * det;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Invert this matrix.\r\n *
\r\n * If this
matrix represents an {@link #isAffine() affine} transformation, such as translation, rotation, scaling and shearing,\r\n * and thus its last row is equal to (0, 0, 0, 1), then {@link #invertAffine()} can be used instead of this method.\r\n * \r\n * @see #invertAffine()\r\n * \r\n * @return this\r\n */\r\n public Matrix4f invert() {\r\n return invert(this);\r\n }\r\n\r\n /**\r\n * If this
is a perspective projection matrix obtained via one of the {@link #perspective(float, float, float, float) perspective()} methods\r\n * or via {@link #setPerspective(float, float, float, float) setPerspective()}, that is, if this
is a symmetrical perspective frustum transformation,\r\n * then this method builds the inverse of this
and stores it into the given dest
.\r\n *
\r\n * This method can be used to quickly obtain the inverse of a perspective projection matrix when being obtained via {@link #perspective(float, float, float, float) perspective()}.\r\n * \r\n * @see #perspective(float, float, float, float)\r\n * \r\n * @param dest\r\n * will hold the inverse of this
\r\n * @return dest\r\n */\r\n public Matrix4f invertPerspective(Matrix4f dest) {\r\n float a = 1.0f / (m00 * m11);\r\n float l = -1.0f / (m23 * m32);\r\n dest.set(m11 * a, 0, 0, 0,\r\n 0, m00 * a, 0, 0,\r\n 0, 0, 0, -m23 * l,\r\n 0, 0, -m32 * l, m22 * l);\r\n return dest;\r\n }\r\n\r\n /**\r\n * If this
is a perspective projection matrix obtained via one of the {@link #perspective(float, float, float, float) perspective()} methods\r\n * or via {@link #setPerspective(float, float, float, float) setPerspective()}, that is, if this
is a symmetrical perspective frustum transformation,\r\n * then this method builds the inverse of this
.\r\n *
\r\n * This method can be used to quickly obtain the inverse of a perspective projection matrix when being obtained via {@link #perspective(float, float, float, float) perspective()}.\r\n * \r\n * @see #perspective(float, float, float, float)\r\n * \r\n * @return this\r\n */\r\n public Matrix4f invertPerspective() {\r\n return invertPerspective(this);\r\n }\r\n\r\n /**\r\n * If this
is an arbitrary perspective projection matrix obtained via one of the {@link #frustum(float, float, float, float, float, float) frustum()} methods\r\n * or via {@link #setFrustum(float, float, float, float, float, float) setFrustum()},\r\n * then this method builds the inverse of this
and stores it into the given dest
.\r\n *
\r\n * This method can be used to quickly obtain the inverse of a perspective projection matrix.\r\n *
\r\n * If this matrix represents a symmetric perspective frustum transformation, as obtained via {@link #perspective(float, float, float, float) perspective()}, then\r\n * {@link #invertPerspective(Matrix4f)} should be used instead.\r\n * \r\n * @see #frustum(float, float, float, float, float, float)\r\n * @see #invertPerspective(Matrix4f)\r\n * \r\n * @param dest\r\n * will hold the inverse of this
\r\n * @return dest\r\n */\r\n public Matrix4f invertFrustum(Matrix4f dest) {\r\n float invM00 = 1.0f / m00;\r\n float invM11 = 1.0f / m11;\r\n float invM23 = 1.0f / m23;\r\n float invM32 = 1.0f / m32;\r\n dest.set(invM00, 0, 0, 0,\r\n 0, invM11, 0, 0,\r\n 0, 0, 0, invM32,\r\n -m20 * invM00 * invM23, -m21 * invM11 * invM23, invM23, -m22 * invM23 * invM32);\r\n return dest;\r\n }\r\n\r\n /**\r\n * If this
is an arbitrary perspective projection matrix obtained via one of the {@link #frustum(float, float, float, float, float, float) frustum()} methods\r\n * or via {@link #setFrustum(float, float, float, float, float, float) setFrustum()},\r\n * then this method builds the inverse of this
.\r\n *
\r\n * This method can be used to quickly obtain the inverse of a perspective projection matrix.\r\n *
\r\n * If this matrix represents a symmetric perspective frustum transformation, as obtained via {@link #perspective(float, float, float, float) perspective()}, then\r\n * {@link #invertPerspective()} should be used instead.\r\n * \r\n * @see #frustum(float, float, float, float, float, float)\r\n * @see #invertPerspective()\r\n * \r\n * @return this\r\n */\r\n public Matrix4f invertFrustum() {\r\n return invertFrustum(this);\r\n }\r\n\r\n /**\r\n * Invert this
orthographic projection matrix and store the result into the given dest
.\r\n *
\r\n * This method can be used to quickly obtain the inverse of an orthographic projection matrix.\r\n * \r\n * @param dest\r\n * will hold the inverse of this
\r\n * @return dest\r\n */\r\n public Matrix4f invertOrtho(Matrix4f dest) {\r\n float invM00 = 1.0f / m00;\r\n float invM11 = 1.0f / m11;\r\n float invM22 = 1.0f / m22;\r\n dest.set(invM00, 0, 0, 0,\r\n 0, invM11, 0, 0,\r\n 0, 0, invM22, 0,\r\n -m30 * invM00, -m31 * invM11, -m32 * invM22, 1);\r\n return dest;\r\n }\r\n\r\n /**\r\n * Invert this
orthographic projection matrix.\r\n *
\r\n * This method can be used to quickly obtain the inverse of an orthographic projection matrix.\r\n * \r\n * @return this\r\n */\r\n public Matrix4f invertOrtho() {\r\n return invertOrtho(this);\r\n }\r\n\r\n /**\r\n * If this
is a perspective projection matrix obtained via one of the {@link #perspective(float, float, float, float) perspective()} methods\r\n * or via {@link #setPerspective(float, float, float, float) setPerspective()}, that is, if this
is a symmetrical perspective frustum transformation\r\n * and the given view
matrix is {@link #isAffine() affine} and has unit scaling (for example by being obtained via {@link #lookAt(float, float, float, float, float, float, float, float, float) lookAt()}),\r\n * then this method builds the inverse of this * view and stores it into the given dest
.\r\n *
\r\n * This method can be used to quickly obtain the inverse of the combination of the view and projection matrices, when both were obtained\r\n * via the common methods {@link #perspective(float, float, float, float) perspective()} and {@link #lookAt(float, float, float, float, float, float, float, float, float) lookAt()} or\r\n * other methods, that build affine matrices, such as {@link #translate(float, float, float) translate} and {@link #rotate(float, float, float, float)}, except for {@link #scale(float, float, float) scale()}.\r\n *
\r\n * For the special cases of the matrices this
and view
mentioned above this method, this method is equivalent to the following code:\r\n *
\r\n * dest.set(this).mul(view).invert();\r\n *
\r\n * \r\n * @param view\r\n * the view transformation (must be {@link #isAffine() affine} and have unit scaling)\r\n * @param dest\r\n * will hold the inverse of this * view\r\n * @return dest\r\n */\r\n public Matrix4f invertPerspectiveView(Matrix4f view, Matrix4f dest) {\r\n float a = 1.0f / (m00 * m11);\r\n float l = -1.0f / (m23 * m32);\r\n float pm00 = m11 * a;\r\n float pm11 = m00 * a;\r\n float pm23 = -m23 * l;\r\n float pm32 = -m32 * l;\r\n float pm33 = m22 * l;\r\n float vm30 = -view.m00 * view.m30 - view.m01 * view.m31 - view.m02 * view.m32;\r\n float vm31 = -view.m10 * view.m30 - view.m11 * view.m31 - view.m12 * view.m32;\r\n float vm32 = -view.m20 * view.m30 - view.m21 * view.m31 - view.m22 * view.m32;\r\n dest.set(view.m00 * pm00, view.m10 * pm00, view.m20 * pm00, 0.0f,\r\n view.m01 * pm11, view.m11 * pm11, view.m21 * pm11, 0.0f,\r\n vm30 * pm23, vm31 * pm23, vm32 * pm23, pm23,\r\n view.m02 * pm32 + vm30 * pm33, view.m12 * pm32 + vm31 * pm33, view.m22 * pm32 + vm32 * pm33, pm33);\r\n return dest;\r\n }\r\n\r\n /**\r\n * Invert this matrix by assuming that it is an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and write the result into dest
.\r\n * \r\n * Note that if this
matrix also has unit scaling, then the method {@link #invertAffineUnitScale(Matrix4f)} should be used instead.\r\n * \r\n * @see #invertAffineUnitScale(Matrix4f)\r\n * \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f invertAffine(Matrix4f dest) {\r\n float s = determinantAffine();\r\n s = 1.0f / s;\r\n float m10m22 = m10 * m22;\r\n float m10m21 = m10 * m21;\r\n float m10m02 = m10 * m02;\r\n float m10m01 = m10 * m01;\r\n float m11m22 = m11 * m22;\r\n float m11m20 = m11 * m20;\r\n float m11m02 = m11 * m02;\r\n float m11m00 = m11 * m00;\r\n float m12m21 = m12 * m21;\r\n float m12m20 = m12 * m20;\r\n float m12m01 = m12 * m01;\r\n float m12m00 = m12 * m00;\r\n float m20m02 = m20 * m02;\r\n float m20m01 = m20 * m01;\r\n float m21m02 = m21 * m02;\r\n float m21m00 = m21 * m00;\r\n float m22m01 = m22 * m01;\r\n float m22m00 = m22 * m00;\r\n float nm00 = (m11m22 - m12m21) * s;\r\n float nm01 = (m21m02 - m22m01) * s;\r\n float nm02 = (m12m01 - m11m02) * s;\r\n float nm03 = 0.0f;\r\n float nm10 = (m12m20 - m10m22) * s;\r\n float nm11 = (m22m00 - m20m02) * s;\r\n float nm12 = (m10m02 - m12m00) * s;\r\n float nm13 = 0.0f;\r\n float nm20 = (m10m21 - m11m20) * s;\r\n float nm21 = (m20m01 - m21m00) * s;\r\n float nm22 = (m11m00 - m10m01) * s;\r\n float nm23 = 0.0f;\r\n float nm30 = (m10m22 * m31 - m10m21 * m32 + m11m20 * m32 - m11m22 * m30 + m12m21 * m30 - m12m20 * m31) * s;\r\n float nm31 = (m20m02 * m31 - m20m01 * m32 + m21m00 * m32 - m21m02 * m30 + m22m01 * m30 - m22m00 * m31) * s;\r\n float nm32 = (m11m02 * m30 - m12m01 * m30 + m12m00 * m31 - m10m02 * m31 + m10m01 * m32 - m11m00 * m32) * s;\r\n float nm33 = 1.0f;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Invert this matrix by assuming that it is an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1)).\r\n *
\r\n * Note that if this
matrix also has unit scaling, then the method {@link #invertAffineUnitScale()} should be used instead.\r\n * \r\n * @see #invertAffineUnitScale()\r\n * \r\n * @return this\r\n */\r\n public Matrix4f invertAffine() {\r\n return invertAffine(this);\r\n }\r\n\r\n /**\r\n * Invert this matrix by assuming that it is an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and has unit scaling (i.e. {@link #transformDirection(Vector3f) transformDirection} does not change the {@link Vector3f#length() length} of the vector)\r\n * and write the result into dest
.\r\n *
\r\n * Reference: http://www.gamedev.net/\r\n * \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f invertAffineUnitScale(Matrix4f dest) {\r\n dest.set(m00, m10, m20, 0.0f,\r\n m01, m11, m21, 0.0f,\r\n m02, m12, m22, 0.0f,\r\n -m00 * m30 - m01 * m31 - m02 * m32,\r\n -m10 * m30 - m11 * m31 - m12 * m32,\r\n -m20 * m30 - m21 * m31 - m22 * m32,\r\n 1.0f);\r\n return dest;\r\n }\r\n\r\n /**\r\n * Invert this matrix by assuming that it is an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and has unit scaling (i.e. {@link #transformDirection(Vector3f) transformDirection} does not change the {@link Vector3f#length() length} of the vector).\r\n *
\r\n * Reference: http://www.gamedev.net/\r\n * \r\n * @return this\r\n */\r\n public Matrix4f invertAffineUnitScale() {\r\n return invertAffineUnitScale(this);\r\n }\r\n\r\n /**\r\n * Invert this matrix by assuming that it is an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and has unit scaling (i.e. {@link #transformDirection(Vector3f) transformDirection} does not change the {@link Vector3f#length() length} of the vector),\r\n * as is the case for matrices built via {@link #lookAt(Vector3f, Vector3f, Vector3f)} and their overloads, and write the result into dest
.\r\n *
\r\n * This method is equivalent to calling {@link #invertAffineUnitScale(Matrix4f)}\r\n *
\r\n * Reference: http://www.gamedev.net/\r\n * \r\n * @see #invertAffineUnitScale(Matrix4f)\r\n * \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f invertLookAt(Matrix4f dest) {\r\n return invertAffineUnitScale(dest);\r\n }\r\n\r\n /**\r\n * Invert this matrix by assuming that it is an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and has unit scaling (i.e. {@link #transformDirection(Vector3f) transformDirection} does not change the {@link Vector3f#length() length} of the vector),\r\n * as is the case for matrices built via {@link #lookAt(Vector3f, Vector3f, Vector3f)} and their overloads.\r\n *
\r\n * This method is equivalent to calling {@link #invertAffineUnitScale()}\r\n *
\r\n * Reference: http://www.gamedev.net/\r\n * \r\n * @see #invertAffineUnitScale()\r\n * \r\n * @return this\r\n */\r\n public Matrix4f invertLookAt() {\r\n return invertAffineUnitScale(this);\r\n }\r\n\r\n /**\r\n * Transpose this matrix and store the result in dest
.\r\n * \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f transpose(Matrix4f dest) {\r\n float nm00 = m00;\r\n float nm01 = m10;\r\n float nm02 = m20;\r\n float nm03 = m30;\r\n float nm10 = m01;\r\n float nm11 = m11;\r\n float nm12 = m21;\r\n float nm13 = m31;\r\n float nm20 = m02;\r\n float nm21 = m12;\r\n float nm22 = m22;\r\n float nm23 = m32;\r\n float nm30 = m03;\r\n float nm31 = m13;\r\n float nm32 = m23;\r\n float nm33 = m33;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Transpose only the upper left 3x3 submatrix of this matrix and set the rest of the matrix elements to identity.\r\n * \r\n * @return this\r\n */\r\n public Matrix4f transpose3x3() {\r\n return transpose3x3(this);\r\n }\r\n\r\n /**\r\n * Transpose only the upper left 3x3 submatrix of this matrix and store the result in dest
.\r\n *
\r\n * All other matrix elements of dest
will be set to identity.\r\n * \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f transpose3x3(Matrix4f dest) {\r\n float nm00 = m00;\r\n float nm01 = m10;\r\n float nm02 = m20;\r\n float nm03 = 0.0f;\r\n float nm10 = m01;\r\n float nm11 = m11;\r\n float nm12 = m21;\r\n float nm13 = 0.0f;\r\n float nm20 = m02;\r\n float nm21 = m12;\r\n float nm22 = m22;\r\n float nm23 = 0.0f;\r\n float nm30 = 0.0f;\r\n float nm31 = 0.0f;\r\n float nm32 = 0.0f;\r\n float nm33 = 1.0f;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Transpose only the upper left 3x3 submatrix of this matrix and store the result in dest
.\r\n * \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix3f transpose3x3(Matrix3f dest) {\r\n dest.m00 = m00;\r\n dest.m01 = m10;\r\n dest.m02 = m20;\r\n dest.m10 = m01;\r\n dest.m11 = m11;\r\n dest.m12 = m21;\r\n dest.m20 = m02;\r\n dest.m21 = m12;\r\n dest.m22 = m22;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Transpose this matrix.\r\n * \r\n * @return this\r\n */\r\n public Matrix4f transpose() {\r\n return transpose(this);\r\n }\r\n\r\n /**\r\n * Set this matrix to be a simple translation matrix.\r\n *
\r\n * The resulting matrix can be multiplied against another transformation\r\n * matrix to obtain an additional translation.\r\n *
\r\n * In order to post-multiply a translation transformation directly to a\r\n * matrix, use {@link #translate(float, float, float) translate()} instead.\r\n * \r\n * @see #translate(float, float, float)\r\n * \r\n * @param x\r\n * the offset to translate in x\r\n * @param y\r\n * the offset to translate in y\r\n * @param z\r\n * the offset to translate in z\r\n * @return this\r\n */\r\n public Matrix4f translation(float x, float y, float z) {\r\n m00 = 1.0f;\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = 1.0f;\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = 0.0f;\r\n m22 = 1.0f;\r\n m23 = 0.0f;\r\n m30 = x;\r\n m31 = y;\r\n m32 = z;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be a simple translation matrix.\r\n *
\r\n * The resulting matrix can be multiplied against another transformation\r\n * matrix to obtain an additional translation.\r\n *
\r\n * In order to post-multiply a translation transformation directly to a\r\n * matrix, use {@link #translate(Vector3f) translate()} instead.\r\n * \r\n * @see #translate(float, float, float)\r\n * \r\n * @param offset\r\n * the offsets in x, y and z to translate\r\n * @return this\r\n */\r\n public Matrix4f translation(Vector3f offset) {\r\n return translation(offset.x, offset.y, offset.z);\r\n }\r\n\r\n /**\r\n * Set only the translation components (m30, m31, m32) of this matrix to the given values (x, y, z).\r\n *
\r\n * Note that this will only work properly for orthogonal matrices (without any perspective).\r\n *
\r\n * To build a translation matrix instead, use {@link #translation(float, float, float)}.\r\n * To apply a translation to another matrix, use {@link #translate(float, float, float)}.\r\n * \r\n * @see #translation(float, float, float)\r\n * @see #translate(float, float, float)\r\n * \r\n * @param x\r\n * the offset to translate in x\r\n * @param y\r\n * the offset to translate in y\r\n * @param z\r\n * the offset to translate in z\r\n * @return this\r\n */\r\n public Matrix4f setTranslation(float x, float y, float z) {\r\n m30 = x;\r\n m31 = y;\r\n m32 = z;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set only the translation components (m30, m31, m32) of this matrix to the values (xyz.x, xyz.y, xyz.z).\r\n *
\r\n * Note that this will only work properly for orthogonal matrices (without any perspective).\r\n *
\r\n * To build a translation matrix instead, use {@link #translation(Vector3f)}.\r\n * To apply a translation to another matrix, use {@link #translate(Vector3f)}.\r\n * \r\n * @see #translation(Vector3f)\r\n * @see #translate(Vector3f)\r\n * \r\n * @param xyz\r\n * the units to translate in (x, y, z)\r\n * @return this\r\n */\r\n public Matrix4f setTranslation(Vector3f xyz) {\r\n m30 = xyz.x;\r\n m31 = xyz.y;\r\n m32 = xyz.z;\r\n return this;\r\n }\r\n\r\n /**\r\n * Get only the translation components (m30, m31, m32) of this matrix and store them in the given vector xyz
.\r\n * \r\n * @param dest\r\n * will hold the translation components of this matrix\r\n * @return dest\r\n */\r\n public Vector3f getTranslation(Vector3f dest) {\r\n dest.x = m30;\r\n dest.y = m31;\r\n dest.z = m32;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Get the scaling factors of this
matrix for the three base axes.\r\n * \r\n * @param dest\r\n * will hold the scaling factors for x, y and z\r\n * @return dest\r\n */\r\n public Vector3f getScale(Vector3f dest) {\r\n dest.x = (float) Math.sqrt(m00 * m00 + m01 * m01 + m02 * m02);\r\n dest.y = (float) Math.sqrt(m10 * m10 + m11 * m11 + m12 * m12);\r\n dest.z = (float) Math.sqrt(m20 * m20 + m21 * m21 + m22 * m22);\r\n return dest;\r\n }\r\n\r\n /**\r\n * Return a string representation of this matrix.\r\n *
\r\n * This method creates a new {@link DecimalFormat} on every invocation with the format string \" 0.000E0; -\".\r\n * \r\n * @return the string representation\r\n */\r\n public String toString() {\r\n DecimalFormat formatter = new DecimalFormat(\" 0.000E0; -\"); //$NON-NLS-1$\r\n return toString(formatter).replaceAll(\"E(\\\\d+)\", \"E+$1\"); //$NON-NLS-1$ //$NON-NLS-2$\r\n }\r\n\r\n /**\r\n * Return a string representation of this matrix by formatting the matrix elements with the given {@link NumberFormat}.\r\n * \r\n * @param formatter\r\n * the {@link NumberFormat} used to format the matrix values with\r\n * @return the string representation\r\n */\r\n public String toString(NumberFormat formatter) {\r\n return formatter.format(m00) + formatter.format(m10) + formatter.format(m20) + formatter.format(m30) + \"\\n\" //$NON-NLS-1$\r\n + formatter.format(m01) + formatter.format(m11) + formatter.format(m21) + formatter.format(m31) + \"\\n\" //$NON-NLS-1$\r\n + formatter.format(m02) + formatter.format(m12) + formatter.format(m22) + formatter.format(m32) + \"\\n\" //$NON-NLS-1$\r\n + formatter.format(m03) + formatter.format(m13) + formatter.format(m23) + formatter.format(m33) + \"\\n\"; //$NON-NLS-1$\r\n }\r\n\r\n /**\r\n * Get the current values of this
matrix and store them into\r\n * dest
.\r\n *
\r\n * This is the reverse method of {@link #set(Matrix4f)} and allows to obtain\r\n * intermediate calculation results when chaining multiple transformations.\r\n * \r\n * @see #set(Matrix4f)\r\n * \r\n * @param dest\r\n * the destination matrix\r\n * @return the passed in destination\r\n */\r\n public Matrix4f get(Matrix4f dest) {\r\n return dest.set(this);\r\n }\r\n\r\n /**\r\n * Get the current values of this
matrix and store them into\r\n * dest
.\r\n *
\r\n * This is the reverse method of {@link #set(Matrix4d)} and allows to obtain\r\n * intermediate calculation results when chaining multiple transformations.\r\n * \r\n * @see #set(Matrix4d)\r\n * \r\n * @param dest\r\n * the destination matrix\r\n * @return the passed in destination\r\n */\r\n public Matrix4d get(Matrix4d dest) {\r\n return dest.set(this);\r\n }\r\n\r\n /**\r\n * Get the current values of the upper left 3x3 submatrix of this
matrix and store them into\r\n * dest
.\r\n * \r\n * @param dest\r\n * the destination matrix\r\n * @return the passed in destination\r\n */\r\n public Matrix3f get3x3(Matrix3f dest) {\r\n return dest.set(this);\r\n }\r\n\r\n /**\r\n * Get the current values of the upper left 3x3 submatrix of this
matrix and store them into\r\n * dest
.\r\n * \r\n * @param dest\r\n * the destination matrix\r\n * @return the passed in destination\r\n */\r\n public Matrix3d get3x3(Matrix3d dest) {\r\n return dest.set(this);\r\n }\r\n\r\n /**\r\n * Get the rotational component of this
matrix and store the represented rotation\r\n * into the given {@link AxisAngle4f}.\r\n * \r\n * @see AxisAngle4f#set(Matrix4f)\r\n * \r\n * @param dest\r\n * the destination {@link AxisAngle4f}\r\n * @return the passed in destination\r\n */\r\n public AxisAngle4f getRotation(AxisAngle4f dest) {\r\n return dest.set(this);\r\n }\r\n\r\n /**\r\n * Get the rotational component of this
matrix and store the represented rotation\r\n * into the given {@link AxisAngle4d}.\r\n * \r\n * @see AxisAngle4f#set(Matrix4f)\r\n * \r\n * @param dest\r\n * the destination {@link AxisAngle4d}\r\n * @return the passed in destination\r\n */\r\n public AxisAngle4d getRotation(AxisAngle4d dest) {\r\n return dest.set(this);\r\n }\r\n\r\n /**\r\n * Get the current values of this
matrix and store the represented rotation\r\n * into the given {@link Quaternionf}.\r\n *
\r\n * This method assumes that the first three column vectors of the upper left 3x3 submatrix are not normalized and\r\n * thus allows to ignore any additional scaling factor that is applied to the matrix.\r\n * \r\n * @see Quaternionf#setFromUnnormalized(Matrix4f)\r\n * \r\n * @param dest\r\n * the destination {@link Quaternionf}\r\n * @return the passed in destination\r\n */\r\n public Quaternionf getUnnormalizedRotation(Quaternionf dest) {\r\n return dest.setFromUnnormalized(this);\r\n }\r\n\r\n /**\r\n * Get the current values of this
matrix and store the represented rotation\r\n * into the given {@link Quaternionf}.\r\n *
\r\n * This method assumes that the first three column vectors of the upper left 3x3 submatrix are normalized.\r\n * \r\n * @see Quaternionf#setFromNormalized(Matrix4f)\r\n * \r\n * @param dest\r\n * the destination {@link Quaternionf}\r\n * @return the passed in destination\r\n */\r\n public Quaternionf getNormalizedRotation(Quaternionf dest) {\r\n return dest.setFromNormalized(this);\r\n }\r\n\r\n /**\r\n * Get the current values of this
matrix and store the represented rotation\r\n * into the given {@link Quaterniond}.\r\n *
\r\n * This method assumes that the first three column vectors of the upper left 3x3 submatrix are not normalized and\r\n * thus allows to ignore any additional scaling factor that is applied to the matrix.\r\n * \r\n * @see Quaterniond#setFromUnnormalized(Matrix4f)\r\n * \r\n * @param dest\r\n * the destination {@link Quaterniond}\r\n * @return the passed in destination\r\n */\r\n public Quaterniond getUnnormalizedRotation(Quaterniond dest) {\r\n return dest.setFromUnnormalized(this);\r\n }\r\n\r\n /**\r\n * Get the current values of this
matrix and store the represented rotation\r\n * into the given {@link Quaterniond}.\r\n *
\r\n * This method assumes that the first three column vectors of the upper left 3x3 submatrix are normalized.\r\n * \r\n * @see Quaterniond#setFromNormalized(Matrix4f)\r\n * \r\n * @param dest\r\n * the destination {@link Quaterniond}\r\n * @return the passed in destination\r\n */\r\n public Quaterniond getNormalizedRotation(Quaterniond dest) {\r\n return dest.setFromNormalized(this);\r\n }\r\n\r\n /**\r\n * Store this matrix in column-major order into the supplied {@link FloatBuffer} at the current\r\n * buffer {@link FloatBuffer#position() position}.\r\n *
\r\n * This method will not increment the position of the given FloatBuffer.\r\n *
\r\n * In order to specify the offset into the FloatBuffer at which\r\n * the matrix is stored, use {@link #get(int, FloatBuffer)}, taking\r\n * the absolute position as parameter.\r\n * \r\n * @see #get(int, FloatBuffer)\r\n * \r\n * @param buffer\r\n * will receive the values of this matrix in column-major order at its current position\r\n * @return the passed in buffer\r\n */\r\n public FloatBuffer get(FloatBuffer buffer) {\r\n return get(buffer.position(), buffer);\r\n }\r\n\r\n /**\r\n * Store this matrix in column-major order into the supplied {@link FloatBuffer} starting at the specified\r\n * absolute buffer position/index.\r\n *
\r\n * This method will not increment the position of the given FloatBuffer.\r\n * \r\n * @param index\r\n * the absolute position into the FloatBuffer\r\n * @param buffer\r\n * will receive the values of this matrix in column-major order\r\n * @return the passed in buffer\r\n */\r\n public FloatBuffer get(int index, FloatBuffer buffer) {\r\n MemUtil.INSTANCE.put(this, index, buffer);\r\n return buffer;\r\n }\r\n\r\n /**\r\n * Store this matrix in column-major order into the supplied {@link ByteBuffer} at the current\r\n * buffer {@link ByteBuffer#position() position}.\r\n *
\r\n * This method will not increment the position of the given ByteBuffer.\r\n *
\r\n * In order to specify the offset into the ByteBuffer at which\r\n * the matrix is stored, use {@link #get(int, ByteBuffer)}, taking\r\n * the absolute position as parameter.\r\n * \r\n * @see #get(int, ByteBuffer)\r\n * \r\n * @param buffer\r\n * will receive the values of this matrix in column-major order at its current position\r\n * @return the passed in buffer\r\n */\r\n public ByteBuffer get(ByteBuffer buffer) {\r\n return get(buffer.position(), buffer);\r\n }\r\n\r\n /**\r\n * Store this matrix in column-major order into the supplied {@link ByteBuffer} starting at the specified\r\n * absolute buffer position/index.\r\n *
\r\n * This method will not increment the position of the given ByteBuffer.\r\n * \r\n * @param index\r\n * the absolute position into the ByteBuffer\r\n * @param buffer\r\n * will receive the values of this matrix in column-major order\r\n * @return the passed in buffer\r\n */\r\n public ByteBuffer get(int index, ByteBuffer buffer) {\r\n MemUtil.INSTANCE.put(this, index, buffer);\r\n return buffer;\r\n }\r\n\r\n /**\r\n * Store the transpose of this matrix in column-major order into the supplied {@link FloatBuffer} at the current\r\n * buffer {@link FloatBuffer#position() position}.\r\n *
\r\n * This method will not increment the position of the given FloatBuffer.\r\n *
\r\n * In order to specify the offset into the FloatBuffer at which\r\n * the matrix is stored, use {@link #getTransposed(int, FloatBuffer)}, taking\r\n * the absolute position as parameter.\r\n * \r\n * @see #getTransposed(int, FloatBuffer)\r\n * \r\n * @param buffer\r\n * will receive the values of this matrix in column-major order at its current position\r\n * @return the passed in buffer\r\n */\r\n public FloatBuffer getTransposed(FloatBuffer buffer) {\r\n return getTransposed(buffer.position(), buffer);\r\n }\r\n\r\n /**\r\n * Store the transpose of this matrix in column-major order into the supplied {@link FloatBuffer} starting at the specified\r\n * absolute buffer position/index.\r\n *
\r\n * This method will not increment the position of the given FloatBuffer.\r\n * \r\n * @param index\r\n * the absolute position into the FloatBuffer\r\n * @param buffer\r\n * will receive the values of this matrix in column-major order\r\n * @return the passed in buffer\r\n */\r\n public FloatBuffer getTransposed(int index, FloatBuffer buffer) {\r\n MemUtil.INSTANCE.putTransposed(this, index, buffer);\r\n return buffer;\r\n }\r\n\r\n /**\r\n * Store the transpose of this matrix in column-major order into the supplied {@link ByteBuffer} at the current\r\n * buffer {@link ByteBuffer#position() position}.\r\n *
\r\n * This method will not increment the position of the given ByteBuffer.\r\n *
\r\n * In order to specify the offset into the ByteBuffer at which\r\n * the matrix is stored, use {@link #getTransposed(int, ByteBuffer)}, taking\r\n * the absolute position as parameter.\r\n * \r\n * @see #getTransposed(int, ByteBuffer)\r\n * \r\n * @param buffer\r\n * will receive the values of this matrix in column-major order at its current position\r\n * @return the passed in buffer\r\n */\r\n public ByteBuffer getTransposed(ByteBuffer buffer) {\r\n return getTransposed(buffer.position(), buffer);\r\n }\r\n\r\n /**\r\n * Store the transpose of this matrix in column-major order into the supplied {@link ByteBuffer} starting at the specified\r\n * absolute buffer position/index.\r\n *
\r\n * This method will not increment the position of the given ByteBuffer.\r\n * \r\n * @param index\r\n * the absolute position into the ByteBuffer\r\n * @param buffer\r\n * will receive the values of this matrix in column-major order\r\n * @return the passed in buffer\r\n */\r\n public ByteBuffer getTransposed(int index, ByteBuffer buffer) {\r\n MemUtil.INSTANCE.putTransposed(this, index, buffer);\r\n return buffer;\r\n }\r\n\r\n /**\r\n * Store this matrix into the supplied float array in column-major order at the given offset.\r\n * \r\n * @param arr\r\n * the array to write the matrix values into\r\n * @param offset\r\n * the offset into the array\r\n * @return the passed in array\r\n */\r\n public float[] get(float[] arr, int offset) {\r\n arr[offset+0] = m00;\r\n arr[offset+1] = m01;\r\n arr[offset+2] = m02;\r\n arr[offset+3] = m03;\r\n arr[offset+4] = m10;\r\n arr[offset+5] = m11;\r\n arr[offset+6] = m12;\r\n arr[offset+7] = m13;\r\n arr[offset+8] = m20;\r\n arr[offset+9] = m21;\r\n arr[offset+10] = m22;\r\n arr[offset+11] = m23;\r\n arr[offset+12] = m30;\r\n arr[offset+13] = m31;\r\n arr[offset+14] = m32;\r\n arr[offset+15] = m33;\r\n return arr;\r\n }\r\n\r\n /**\r\n * Store this matrix into the supplied float array in column-major order.\r\n *
\r\n * In order to specify an explicit offset into the array, use the method {@link #get(float[], int)}.\r\n * \r\n * @see #get(float[], int)\r\n * \r\n * @param arr\r\n * the array to write the matrix values into\r\n * @return the passed in array\r\n */\r\n public float[] get(float[] arr) {\r\n return get(arr, 0);\r\n }\r\n\r\n /**\r\n * Set all the values within this matrix to 0
.\r\n * \r\n * @return this\r\n */\r\n public Matrix4f zero() {\r\n m00 = 0.0f;\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = 0.0f;\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = 0.0f;\r\n m22 = 0.0f;\r\n m23 = 0.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 0.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be a simple scale matrix, which scales all axes uniformly by the given factor.\r\n *
\r\n * The resulting matrix can be multiplied against another transformation\r\n * matrix to obtain an additional scaling.\r\n *
\r\n * In order to post-multiply a scaling transformation directly to a\r\n * matrix, use {@link #scale(float) scale()} instead.\r\n * \r\n * @see #scale(float)\r\n * \r\n * @param factor\r\n * the scale factor in x, y and z\r\n * @return this\r\n */\r\n public Matrix4f scaling(float factor) {\r\n m00 = factor;\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = factor;\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = 0.0f;\r\n m22 = factor;\r\n m23 = 0.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be a simple scale matrix.\r\n *
\r\n * The resulting matrix can be multiplied against another transformation\r\n * matrix to obtain an additional scaling.\r\n *
\r\n * In order to post-multiply a scaling transformation directly to a\r\n * matrix, use {@link #scale(float, float, float) scale()} instead.\r\n * \r\n * @see #scale(float, float, float)\r\n * \r\n * @param x\r\n * the scale in x\r\n * @param y\r\n * the scale in y\r\n * @param z\r\n * the scale in z\r\n * @return this\r\n */\r\n public Matrix4f scaling(float x, float y, float z) {\r\n m00 = x;\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = y;\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = 0.0f;\r\n m22 = z;\r\n m23 = 0.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n \r\n /**\r\n * Set this matrix to be a simple scale matrix which scales the base axes by xyz.x, xyz.y and xyz.z respectively.\r\n *
\r\n * The resulting matrix can be multiplied against another transformation\r\n * matrix to obtain an additional scaling.\r\n *
\r\n * In order to post-multiply a scaling transformation directly to a\r\n * matrix use {@link #scale(Vector3f) scale()} instead.\r\n * \r\n * @see #scale(Vector3f)\r\n * \r\n * @param xyz\r\n * the scale in x, y and z respectively\r\n * @return this\r\n */\r\n public Matrix4f scaling(Vector3f xyz) {\r\n return scaling(xyz.x, xyz.y, xyz.z);\r\n }\r\n\r\n /**\r\n * Set this matrix to a rotation matrix which rotates the given radians about a given axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * The resulting matrix can be multiplied against another transformation\r\n * matrix to obtain an additional rotation.\r\n *
\r\n * In order to post-multiply a rotation transformation directly to a\r\n * matrix, use {@link #rotate(float, Vector3f) rotate()} instead.\r\n * \r\n * @see #rotate(float, Vector3f)\r\n * \r\n * @param angle\r\n * the angle in radians\r\n * @param axis\r\n * the axis to rotate about (needs to be {@link Vector3f#normalize() normalized})\r\n * @return this\r\n */\r\n public Matrix4f rotation(float angle, Vector3f axis) {\r\n return rotation(angle, axis.x, axis.y, axis.z);\r\n }\r\n\r\n /**\r\n * Set this matrix to a rotation transformation using the given {@link AxisAngle4f}.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * The resulting matrix can be multiplied against another transformation\r\n * matrix to obtain an additional rotation.\r\n *
\r\n * In order to apply the rotation transformation to an existing transformation,\r\n * use {@link #rotate(AxisAngle4f) rotate()} instead.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n *\r\n * @see #rotate(AxisAngle4f)\r\n * \r\n * @param axisAngle\r\n * the {@link AxisAngle4f} (needs to be {@link AxisAngle4f#normalize() normalized})\r\n * @return this\r\n */\r\n public Matrix4f rotation(AxisAngle4f axisAngle) {\r\n return rotation(axisAngle.angle, axisAngle.x, axisAngle.y, axisAngle.z);\r\n }\r\n\r\n /**\r\n * Set this matrix to a rotation matrix which rotates the given radians about a given axis.\r\n *
\r\n * The axis described by the three components needs to be a unit vector.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * The resulting matrix can be multiplied against another transformation\r\n * matrix to obtain an additional rotation.\r\n *
\r\n * In order to apply the rotation transformation to an existing transformation,\r\n * use {@link #rotate(float, float, float, float) rotate()} instead.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotate(float, float, float, float)\r\n * \r\n * @param angle\r\n * the angle in radians\r\n * @param x\r\n * the x-component of the rotation axis\r\n * @param y\r\n * the y-component of the rotation axis\r\n * @param z\r\n * the z-component of the rotation axis\r\n * @return this\r\n */\r\n public Matrix4f rotation(float angle, float x, float y, float z) {\r\n float cos = (float) Math.cos(angle);\r\n float sin = (float) Math.sin(angle);\r\n float C = 1.0f - cos;\r\n float xy = x * y, xz = x * z, yz = y * z;\r\n m00 = cos + x * x * C;\r\n m10 = xy * C - z * sin;\r\n m20 = xz * C + y * sin;\r\n m30 = 0.0f;\r\n m01 = xy * C + z * sin;\r\n m11 = cos + y * y * C;\r\n m21 = yz * C - x * sin;\r\n m31 = 0.0f;\r\n m02 = xz * C - y * sin;\r\n m12 = yz * C + x * sin;\r\n m22 = cos + z * z * C;\r\n m32 = 0.0f;\r\n m03 = 0.0f;\r\n m13 = 0.0f;\r\n m23 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to a rotation transformation about the X axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @return this\r\n */\r\n public Matrix4f rotationX(float ang) {\r\n float sin, cos;\r\n if (ang == (float) Math.PI || ang == -(float) Math.PI) {\r\n cos = -1.0f;\r\n sin = 0.0f;\r\n } else if (ang == (float) Math.PI * 0.5f || ang == -(float) Math.PI * 1.5f) {\r\n cos = 0.0f;\r\n sin = 1.0f;\r\n } else if (ang == (float) -Math.PI * 0.5f || ang == (float) Math.PI * 1.5f) {\r\n cos = 0.0f;\r\n sin = -1.0f;\r\n } else {\r\n cos = (float) Math.cos(ang);\r\n sin = (float) Math.sin(ang);\r\n }\r\n m00 = 1.0f;\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = cos;\r\n m12 = sin;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = -sin;\r\n m22 = cos;\r\n m23 = 0.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to a rotation transformation about the Y axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @return this\r\n */\r\n public Matrix4f rotationY(float ang) {\r\n float sin, cos;\r\n if (ang == (float) Math.PI || ang == -(float) Math.PI) {\r\n cos = -1.0f;\r\n sin = 0.0f;\r\n } else if (ang == (float) Math.PI * 0.5f || ang == -(float) Math.PI * 1.5f) {\r\n cos = 0.0f;\r\n sin = 1.0f;\r\n } else if (ang == (float) -Math.PI * 0.5f || ang == (float) Math.PI * 1.5f) {\r\n cos = 0.0f;\r\n sin = -1.0f;\r\n } else {\r\n cos = (float) Math.cos(ang);\r\n sin = (float) Math.sin(ang);\r\n }\r\n m00 = cos;\r\n m01 = 0.0f;\r\n m02 = -sin;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = 1.0f;\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = sin;\r\n m21 = 0.0f;\r\n m22 = cos;\r\n m23 = 0.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to a rotation transformation about the Z axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @return this\r\n */\r\n public Matrix4f rotationZ(float ang) {\r\n float sin, cos;\r\n if (ang == (float) Math.PI || ang == -(float) Math.PI) {\r\n cos = -1.0f;\r\n sin = 0.0f;\r\n } else if (ang == (float) Math.PI * 0.5f || ang == -(float) Math.PI * 1.5f) {\r\n cos = 0.0f;\r\n sin = 1.0f;\r\n } else if (ang == (float) -Math.PI * 0.5f || ang == (float) Math.PI * 1.5f) {\r\n cos = 0.0f;\r\n sin = -1.0f;\r\n } else {\r\n cos = (float) Math.cos(ang);\r\n sin = (float) Math.sin(ang);\r\n }\r\n m00 = cos;\r\n m01 = sin;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = -sin;\r\n m11 = cos;\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = 0.0f;\r\n m22 = 1.0f;\r\n m23 = 0.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to a rotation of angleX
radians about the X axis, followed by a rotation\r\n * of angleY
radians about the Y axis and followed by a rotation of angleZ
radians about the Z axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method is equivalent to calling: rotationX(angleX).rotateY(angleY).rotateZ(angleZ)\r\n * \r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @return this\r\n */\r\n public Matrix4f rotationXYZ(float angleX, float angleY, float angleZ) {\r\n float cosX = (float) Math.cos(angleX);\r\n float sinX = (float) Math.sin(angleX);\r\n float cosY = (float) Math.cos(angleY);\r\n float sinY = (float) Math.sin(angleY);\r\n float cosZ = (float) Math.cos(angleZ);\r\n float sinZ = (float) Math.sin(angleZ);\r\n float m_sinX = -sinX;\r\n float m_sinY = -sinY;\r\n float m_sinZ = -sinZ;\r\n\r\n // rotateX\r\n float nm11 = cosX;\r\n float nm12 = sinX;\r\n float nm21 = m_sinX;\r\n float nm22 = cosX;\r\n // rotateY\r\n float nm00 = cosY;\r\n float nm01 = nm21 * m_sinY;\r\n float nm02 = nm22 * m_sinY;\r\n m20 = sinY;\r\n m21 = nm21 * cosY;\r\n m22 = nm22 * cosY;\r\n m23 = 0.0f;\r\n // rotateZ\r\n m00 = nm00 * cosZ;\r\n m01 = nm01 * cosZ + nm11 * sinZ;\r\n m02 = nm02 * cosZ + nm12 * sinZ;\r\n m03 = 0.0f;\r\n m10 = nm00 * m_sinZ;\r\n m11 = nm01 * m_sinZ + nm11 * cosZ;\r\n m12 = nm02 * m_sinZ + nm12 * cosZ;\r\n m13 = 0.0f;\r\n // set last column to identity\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to a rotation of angleZ
radians about the Z axis, followed by a rotation\r\n * of angleY
radians about the Y axis and followed by a rotation of angleX
radians about the X axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method is equivalent to calling: rotationZ(angleZ).rotateY(angleY).rotateX(angleX)\r\n * \r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleX\r\n * the angle to rotate about X\r\n * @return this\r\n */\r\n public Matrix4f rotationZYX(float angleZ, float angleY, float angleX) {\r\n float cosZ = (float) Math.cos(angleZ);\r\n float sinZ = (float) Math.sin(angleZ);\r\n float cosY = (float) Math.cos(angleY);\r\n float sinY = (float) Math.sin(angleY);\r\n float cosX = (float) Math.cos(angleX);\r\n float sinX = (float) Math.sin(angleX);\r\n float m_sinZ = -sinZ;\r\n float m_sinY = -sinY;\r\n float m_sinX = -sinX;\r\n\r\n // rotateZ\r\n float nm00 = cosZ;\r\n float nm01 = sinZ;\r\n float nm10 = m_sinZ;\r\n float nm11 = cosZ;\r\n // rotateY\r\n float nm20 = nm00 * sinY;\r\n float nm21 = nm01 * sinY;\r\n float nm22 = cosY;\r\n m00 = nm00 * cosY;\r\n m01 = nm01 * cosY;\r\n m02 = m_sinY;\r\n m03 = 0.0f;\r\n // rotateX\r\n m10 = nm10 * cosX + nm20 * sinX;\r\n m11 = nm11 * cosX + nm21 * sinX;\r\n m12 = nm22 * sinX;\r\n m13 = 0.0f;\r\n m20 = nm10 * m_sinX + nm20 * cosX;\r\n m21 = nm11 * m_sinX + nm21 * cosX;\r\n m22 = nm22 * cosX;\r\n m23 = 0.0f;\r\n // set last column to identity\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to a rotation of angleY
radians about the Y axis, followed by a rotation\r\n * of angleX
radians about the X axis and followed by a rotation of angleZ
radians about the Z axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method is equivalent to calling: rotationY(angleY).rotateX(angleX).rotateZ(angleZ)\r\n * \r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @return this\r\n */\r\n public Matrix4f rotationYXZ(float angleY, float angleX, float angleZ) {\r\n float cosY = (float) Math.cos(angleY);\r\n float sinY = (float) Math.sin(angleY);\r\n float cosX = (float) Math.cos(angleX);\r\n float sinX = (float) Math.sin(angleX);\r\n float cosZ = (float) Math.cos(angleZ);\r\n float sinZ = (float) Math.sin(angleZ);\r\n float m_sinY = -sinY;\r\n float m_sinX = -sinX;\r\n float m_sinZ = -sinZ;\r\n\r\n // rotateY\r\n float nm00 = cosY;\r\n float nm02 = m_sinY;\r\n float nm20 = sinY;\r\n float nm22 = cosY;\r\n // rotateX\r\n float nm10 = nm20 * sinX;\r\n float nm11 = cosX;\r\n float nm12 = nm22 * sinX;\r\n m20 = nm20 * cosX;\r\n m21 = m_sinX;\r\n m22 = nm22 * cosX;\r\n m23 = 0.0f;\r\n // rotateZ\r\n m00 = nm00 * cosZ + nm10 * sinZ;\r\n m01 = nm11 * sinZ;\r\n m02 = nm02 * cosZ + nm12 * sinZ;\r\n m03 = 0.0f;\r\n m10 = nm00 * m_sinZ + nm10 * cosZ;\r\n m11 = nm11 * cosZ;\r\n m12 = nm02 * m_sinZ + nm12 * cosZ;\r\n m13 = 0.0f;\r\n // set last column to identity\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set only the upper left 3x3 submatrix of this matrix to a rotation of angleX
radians about the X axis, followed by a rotation\r\n * of angleY
radians about the Y axis and followed by a rotation of angleZ
radians about the Z axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n * \r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @return this\r\n */\r\n public Matrix4f setRotationXYZ(float angleX, float angleY, float angleZ) {\r\n float cosX = (float) Math.cos(angleX);\r\n float sinX = (float) Math.sin(angleX);\r\n float cosY = (float) Math.cos(angleY);\r\n float sinY = (float) Math.sin(angleY);\r\n float cosZ = (float) Math.cos(angleZ);\r\n float sinZ = (float) Math.sin(angleZ);\r\n float m_sinX = -sinX;\r\n float m_sinY = -sinY;\r\n float m_sinZ = -sinZ;\r\n\r\n // rotateX\r\n float nm11 = cosX;\r\n float nm12 = sinX;\r\n float nm21 = m_sinX;\r\n float nm22 = cosX;\r\n // rotateY\r\n float nm00 = cosY;\r\n float nm01 = nm21 * m_sinY;\r\n float nm02 = nm22 * m_sinY;\r\n m20 = sinY;\r\n m21 = nm21 * cosY;\r\n m22 = nm22 * cosY;\r\n // rotateZ\r\n m00 = nm00 * cosZ;\r\n m01 = nm01 * cosZ + nm11 * sinZ;\r\n m02 = nm02 * cosZ + nm12 * sinZ;\r\n m10 = nm00 * m_sinZ;\r\n m11 = nm01 * m_sinZ + nm11 * cosZ;\r\n m12 = nm02 * m_sinZ + nm12 * cosZ;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set only the upper left 3x3 submatrix of this matrix to a rotation of angleZ
radians about the Z axis, followed by a rotation\r\n * of angleY
radians about the Y axis and followed by a rotation of angleX
radians about the X axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n * \r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleX\r\n * the angle to rotate about X\r\n * @return this\r\n */\r\n public Matrix4f setRotationZYX(float angleZ, float angleY, float angleX) {\r\n float cosZ = (float) Math.cos(angleZ);\r\n float sinZ = (float) Math.sin(angleZ);\r\n float cosY = (float) Math.cos(angleY);\r\n float sinY = (float) Math.sin(angleY);\r\n float cosX = (float) Math.cos(angleX);\r\n float sinX = (float) Math.sin(angleX);\r\n float m_sinZ = -sinZ;\r\n float m_sinY = -sinY;\r\n float m_sinX = -sinX;\r\n\r\n // rotateZ\r\n float nm00 = cosZ;\r\n float nm01 = sinZ;\r\n float nm10 = m_sinZ;\r\n float nm11 = cosZ;\r\n // rotateY\r\n float nm20 = nm00 * sinY;\r\n float nm21 = nm01 * sinY;\r\n float nm22 = cosY;\r\n m00 = nm00 * cosY;\r\n m01 = nm01 * cosY;\r\n m02 = m_sinY;\r\n // rotateX\r\n m10 = nm10 * cosX + nm20 * sinX;\r\n m11 = nm11 * cosX + nm21 * sinX;\r\n m12 = nm22 * sinX;\r\n m20 = nm10 * m_sinX + nm20 * cosX;\r\n m21 = nm11 * m_sinX + nm21 * cosX;\r\n m22 = nm22 * cosX;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set only the upper left 3x3 submatrix of this matrix to a rotation of angleY
radians about the Y axis, followed by a rotation\r\n * of angleX
radians about the X axis and followed by a rotation of angleZ
radians about the Z axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n * \r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @return this\r\n */\r\n public Matrix4f setRotationYXZ(float angleY, float angleX, float angleZ) {\r\n float cosY = (float) Math.cos(angleY);\r\n float sinY = (float) Math.sin(angleY);\r\n float cosX = (float) Math.cos(angleX);\r\n float sinX = (float) Math.sin(angleX);\r\n float cosZ = (float) Math.cos(angleZ);\r\n float sinZ = (float) Math.sin(angleZ);\r\n float m_sinY = -sinY;\r\n float m_sinX = -sinX;\r\n float m_sinZ = -sinZ;\r\n\r\n // rotateY\r\n float nm00 = cosY;\r\n float nm02 = m_sinY;\r\n float nm20 = sinY;\r\n float nm22 = cosY;\r\n // rotateX\r\n float nm10 = nm20 * sinX;\r\n float nm11 = cosX;\r\n float nm12 = nm22 * sinX;\r\n m20 = nm20 * cosX;\r\n m21 = m_sinX;\r\n m22 = nm22 * cosX;\r\n // rotateZ\r\n m00 = nm00 * cosZ + nm10 * sinZ;\r\n m01 = nm11 * sinZ;\r\n m02 = nm02 * cosZ + nm12 * sinZ;\r\n m10 = nm00 * m_sinZ + nm10 * cosZ;\r\n m11 = nm11 * cosZ;\r\n m12 = nm02 * m_sinZ + nm12 * cosZ;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to the rotation transformation of the given {@link Quaternionf}.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * The resulting matrix can be multiplied against another transformation\r\n * matrix to obtain an additional rotation.\r\n *
\r\n * In order to apply the rotation transformation to an existing transformation,\r\n * use {@link #rotate(Quaternionf) rotate()} instead.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotate(Quaternionf)\r\n * \r\n * @param quat\r\n * the {@link Quaternionf}\r\n * @return this\r\n */\r\n public Matrix4f rotation(Quaternionf quat) {\r\n float dqx = quat.x + quat.x;\r\n float dqy = quat.y + quat.y;\r\n float dqz = quat.z + quat.z;\r\n float q00 = dqx * quat.x;\r\n float q11 = dqy * quat.y;\r\n float q22 = dqz * quat.z;\r\n float q01 = dqx * quat.y;\r\n float q02 = dqx * quat.z;\r\n float q03 = dqx * quat.w;\r\n float q12 = dqy * quat.z;\r\n float q13 = dqy * quat.w;\r\n float q23 = dqz * quat.w;\r\n\r\n m00 = 1.0f - q11 - q22;\r\n m01 = q01 + q23;\r\n m02 = q02 - q13;\r\n m03 = 0.0f;\r\n m10 = q01 - q23;\r\n m11 = 1.0f - q22 - q00;\r\n m12 = q12 + q03;\r\n m13 = 0.0f;\r\n m20 = q02 + q13;\r\n m21 = q12 - q03;\r\n m22 = 1.0f - q11 - q00;\r\n m23 = 0.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this
matrix to T * R * S, where T is a translation by the given (tx, ty, tz),\r\n * R is a rotation transformation specified by the quaternion (qx, qy, qz, qw), and S is a scaling transformation\r\n * which scales the three axes x, y and z by (sx, sy, sz).\r\n *
\r\n * When transforming a vector by the resulting matrix the scaling transformation will be applied first, then the rotation and\r\n * at last the translation.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method is equivalent to calling: translation(tx, ty, tz).rotate(quat).scale(sx, sy, sz)\r\n * \r\n * @see #translation(float, float, float)\r\n * @see #rotate(Quaternionf)\r\n * @see #scale(float, float, float)\r\n * \r\n * @param tx\r\n * the number of units by which to translate the x-component\r\n * @param ty\r\n * the number of units by which to translate the y-component\r\n * @param tz\r\n * the number of units by which to translate the z-component\r\n * @param qx\r\n * the x-coordinate of the vector part of the quaternion\r\n * @param qy\r\n * the y-coordinate of the vector part of the quaternion\r\n * @param qz\r\n * the z-coordinate of the vector part of the quaternion\r\n * @param qw\r\n * the scalar part of the quaternion\r\n * @param sx\r\n * the scaling factor for the x-axis\r\n * @param sy\r\n * the scaling factor for the y-axis\r\n * @param sz\r\n * the scaling factor for the z-axis\r\n * @return this\r\n */\r\n public Matrix4f translationRotateScale(float tx, float ty, float tz, \r\n float qx, float qy, float qz, float qw, \r\n float sx, float sy, float sz) {\r\n float dqx = qx + qx;\r\n float dqy = qy + qy;\r\n float dqz = qz + qz;\r\n float q00 = dqx * qx;\r\n float q11 = dqy * qy;\r\n float q22 = dqz * qz;\r\n float q01 = dqx * qy;\r\n float q02 = dqx * qz;\r\n float q03 = dqx * qw;\r\n float q12 = dqy * qz;\r\n float q13 = dqy * qw;\r\n float q23 = dqz * qw;\r\n m00 = sx - (q11 + q22) * sx;\r\n m01 = (q01 + q23) * sx;\r\n m02 = (q02 - q13) * sx;\r\n m03 = 0.0f;\r\n m10 = (q01 - q23) * sy;\r\n m11 = sy - (q22 + q00) * sy;\r\n m12 = (q12 + q03) * sy;\r\n m13 = 0.0f;\r\n m20 = (q02 + q13) * sz;\r\n m21 = (q12 - q03) * sz;\r\n m22 = sz - (q11 + q00) * sz;\r\n m23 = 0.0f;\r\n m30 = tx;\r\n m31 = ty;\r\n m32 = tz;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this
matrix to T * R * S, where T is the given translation
,\r\n * R is a rotation transformation specified by the given quaternion, and S is a scaling transformation\r\n * which scales the axes by scale
.\r\n *
\r\n * When transforming a vector by the resulting matrix the scaling transformation will be applied first, then the rotation and\r\n * at last the translation.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method is equivalent to calling: translation(translation).rotate(quat).scale(scale)\r\n * \r\n * @see #translation(Vector3f)\r\n * @see #rotate(Quaternionf)\r\n * \r\n * @param translation\r\n * the translation\r\n * @param quat\r\n * the quaternion representing a rotation\r\n * @param scale\r\n * the scaling factors\r\n * @return this\r\n */\r\n public Matrix4f translationRotateScale(Vector3f translation, \r\n Quaternionf quat, \r\n Vector3f scale) {\r\n return translationRotateScale(translation.x, translation.y, translation.z, quat.x, quat.y, quat.z, quat.w, scale.x, scale.y, scale.z);\r\n }\r\n\r\n /**\r\n * Set this
matrix to T * R * S * M, where T is a translation by the given (tx, ty, tz),\r\n * R is a rotation transformation specified by the quaternion (qx, qy, qz, qw), S is a scaling transformation\r\n * which scales the three axes x, y and z by (sx, sy, sz) and M
is an {@link #isAffine() affine} matrix.\r\n *
\r\n * When transforming a vector by the resulting matrix the transformation described by M
will be applied first, then the scaling, then rotation and\r\n * at last the translation.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method is equivalent to calling: translation(tx, ty, tz).rotate(quat).scale(sx, sy, sz).mulAffine(m)\r\n * \r\n * @see #translation(float, float, float)\r\n * @see #rotate(Quaternionf)\r\n * @see #scale(float, float, float)\r\n * @see #mulAffine(Matrix4f)\r\n * \r\n * @param tx\r\n * the number of units by which to translate the x-component\r\n * @param ty\r\n * the number of units by which to translate the y-component\r\n * @param tz\r\n * the number of units by which to translate the z-component\r\n * @param qx\r\n * the x-coordinate of the vector part of the quaternion\r\n * @param qy\r\n * the y-coordinate of the vector part of the quaternion\r\n * @param qz\r\n * the z-coordinate of the vector part of the quaternion\r\n * @param qw\r\n * the scalar part of the quaternion\r\n * @param sx\r\n * the scaling factor for the x-axis\r\n * @param sy\r\n * the scaling factor for the y-axis\r\n * @param sz\r\n * the scaling factor for the z-axis\r\n * @param m\r\n * the {@link #isAffine() affine} matrix to multiply by\r\n * @return this\r\n */\r\n public Matrix4f translationRotateScaleMulAffine(float tx, float ty, float tz, \r\n float qx, float qy, float qz, float qw, \r\n float sx, float sy, float sz,\r\n Matrix4f m) {\r\n float dqx = qx + qx;\r\n float dqy = qy + qy;\r\n float dqz = qz + qz;\r\n float q00 = dqx * qx;\r\n float q11 = dqy * qy;\r\n float q22 = dqz * qz;\r\n float q01 = dqx * qy;\r\n float q02 = dqx * qz;\r\n float q03 = dqx * qw;\r\n float q12 = dqy * qz;\r\n float q13 = dqy * qw;\r\n float q23 = dqz * qw;\r\n float nm00 = sx - (q11 + q22) * sx;\r\n float nm01 = (q01 + q23) * sx;\r\n float nm02 = (q02 - q13) * sx;\r\n float nm10 = (q01 - q23) * sy;\r\n float nm11 = sy - (q22 + q00) * sy;\r\n float nm12 = (q12 + q03) * sy;\r\n float nm20 = (q02 + q13) * sz;\r\n float nm21 = (q12 - q03) * sz;\r\n float nm22 = sz - (q11 + q00) * sz;\r\n float m00 = nm00 * m.m00 + nm10 * m.m01 + nm20 * m.m02;\r\n float m01 = nm01 * m.m00 + nm11 * m.m01 + nm21 * m.m02;\r\n m02 = nm02 * m.m00 + nm12 * m.m01 + nm22 * m.m02;\r\n this.m00 = m00;\r\n this.m01 = m01;\r\n m03 = 0.0f;\r\n float m10 = nm00 * m.m10 + nm10 * m.m11 + nm20 * m.m12;\r\n float m11 = nm01 * m.m10 + nm11 * m.m11 + nm21 * m.m12;\r\n m12 = nm02 * m.m10 + nm12 * m.m11 + nm22 * m.m12;\r\n this.m10 = m10;\r\n this.m11 = m11;\r\n m13 = 0.0f;\r\n float m20 = nm00 * m.m20 + nm10 * m.m21 + nm20 * m.m22;\r\n float m21 = nm01 * m.m20 + nm11 * m.m21 + nm21 * m.m22;\r\n m22 = nm02 * m.m20 + nm12 * m.m21 + nm22 * m.m22;\r\n this.m20 = m20;\r\n this.m21 = m21;\r\n m23 = 0.0f;\r\n float m30 = nm00 * m.m30 + nm10 * m.m31 + nm20 * m.m32 + tx;\r\n float m31 = nm01 * m.m30 + nm11 * m.m31 + nm21 * m.m32 + ty;\r\n m32 = nm02 * m.m30 + nm12 * m.m31 + nm22 * m.m32 + tz;\r\n this.m30 = m30;\r\n this.m31 = m31;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this
matrix to T * R * S * M, where T is the given translation
,\r\n * R is a rotation transformation specified by the given quaternion, S is a scaling transformation\r\n * which scales the axes by scale
and M
is an {@link #isAffine() affine} matrix.\r\n *
\r\n * When transforming a vector by the resulting matrix the transformation described by M
will be applied first, then the scaling, then rotation and\r\n * at last the translation.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method is equivalent to calling: translation(translation).rotate(quat).scale(scale).mulAffine(m)\r\n * \r\n * @see #translation(Vector3f)\r\n * @see #rotate(Quaternionf)\r\n * @see #mulAffine(Matrix4f)\r\n * \r\n * @param translation\r\n * the translation\r\n * @param quat\r\n * the quaternion representing a rotation\r\n * @param scale\r\n * the scaling factors\r\n * @param m\r\n * the {@link #isAffine() affine} matrix to multiply by\r\n * @return this\r\n */\r\n public Matrix4f translationRotateScaleMulAffine(Vector3f translation, \r\n Quaternionf quat, \r\n Vector3f scale,\r\n Matrix4f m) {\r\n return translationRotateScaleMulAffine(translation.x, translation.y, translation.z, quat.x, quat.y, quat.z, quat.w, scale.x, scale.y, scale.z, m);\r\n }\r\n\r\n /**\r\n * Set this
matrix to T * R, where T is a translation by the given (tx, ty, tz) and\r\n * R is a rotation transformation specified by the given quaternion.\r\n *
\r\n * When transforming a vector by the resulting matrix the rotation transformation will be applied first and then the translation.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method is equivalent to calling: translation(tx, ty, tz).rotate(quat)\r\n * \r\n * @see #translation(float, float, float)\r\n * @see #rotate(Quaternionf)\r\n * \r\n * @param tx\r\n * the number of units by which to translate the x-component\r\n * @param ty\r\n * the number of units by which to translate the y-component\r\n * @param tz\r\n * the number of units by which to translate the z-component\r\n * @param quat\r\n * the quaternion representing a rotation\r\n * @return this\r\n */\r\n public Matrix4f translationRotate(float tx, float ty, float tz, Quaternionf quat) {\r\n float dqx = quat.x + quat.x;\r\n float dqy = quat.y + quat.y;\r\n float dqz = quat.z + quat.z;\r\n float q00 = dqx * quat.x;\r\n float q11 = dqy * quat.y;\r\n float q22 = dqz * quat.z;\r\n float q01 = dqx * quat.y;\r\n float q02 = dqx * quat.z;\r\n float q03 = dqx * quat.w;\r\n float q12 = dqy * quat.z;\r\n float q13 = dqy * quat.w;\r\n float q23 = dqz * quat.w;\r\n m00 = 1.0f - (q11 + q22);\r\n m01 = q01 + q23;\r\n m02 = q02 - q13;\r\n m03 = 0.0f;\r\n m10 = q01 - q23;\r\n m11 = 1.0f - (q22 + q00);\r\n m12 = q12 + q03;\r\n m13 = 0.0f;\r\n m20 = q02 + q13;\r\n m21 = q12 - q03;\r\n m22 = 1.0f - (q11 + q00);\r\n m23 = 0.0f;\r\n m30 = tx;\r\n m31 = ty;\r\n m32 = tz;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set the upper left 3x3 submatrix of this {@link Matrix4f} to the given {@link Matrix3f} and don't change the other elements..\r\n * \r\n * @param mat\r\n * the 3x3 matrix\r\n * @return this\r\n */\r\n public Matrix4f set3x3(Matrix3f mat) {\r\n m00 = mat.m00;\r\n m01 = mat.m01;\r\n m02 = mat.m02;\r\n m10 = mat.m10;\r\n m11 = mat.m11;\r\n m12 = mat.m12;\r\n m20 = mat.m20;\r\n m21 = mat.m21;\r\n m22 = mat.m22;\r\n return this;\r\n }\r\n\r\n /**\r\n * Transform/multiply the given vector by this matrix and store the result in that vector.\r\n * \r\n * @see Vector4f#mul(Matrix4f)\r\n * \r\n * @param v\r\n * the vector to transform and to hold the final result\r\n * @return v\r\n */\r\n public Vector4f transform(Vector4f v) {\r\n return v.mul(this);\r\n }\r\n\r\n /**\r\n * Transform/multiply the given vector by this matrix and store the result in dest
.\r\n * \r\n * @see Vector4f#mul(Matrix4f, Vector4f)\r\n * \r\n * @param v\r\n * the vector to transform\r\n * @param dest\r\n * will contain the result\r\n * @return dest\r\n */\r\n public Vector4f transform(Vector4f v, Vector4f dest) {\r\n return v.mul(this, dest);\r\n }\r\n\r\n /**\r\n * Transform/multiply the given vector by this matrix, perform perspective divide and store the result in that vector.\r\n * \r\n * @see Vector4f#mulProject(Matrix4f)\r\n * \r\n * @param v\r\n * the vector to transform and to hold the final result\r\n * @return v\r\n */\r\n public Vector4f transformProject(Vector4f v) {\r\n return v.mulProject(this);\r\n }\r\n\r\n /**\r\n * Transform/multiply the given vector by this matrix, perform perspective divide and store the result in dest
.\r\n * \r\n * @see Vector4f#mulProject(Matrix4f, Vector4f)\r\n * \r\n * @param v\r\n * the vector to transform\r\n * @param dest\r\n * will contain the result\r\n * @return dest\r\n */\r\n public Vector4f transformProject(Vector4f v, Vector4f dest) {\r\n return v.mulProject(this, dest);\r\n }\r\n\r\n /**\r\n * Transform/multiply the given vector by this matrix, perform perspective divide and store the result in that vector.\r\n *
\r\n * This method uses w=1.0 as the fourth vector component.\r\n * \r\n * @see Vector3f#mulProject(Matrix4f)\r\n * \r\n * @param v\r\n * the vector to transform and to hold the final result\r\n * @return v\r\n */\r\n public Vector3f transformProject(Vector3f v) {\r\n return v.mulProject(this);\r\n }\r\n\r\n /**\r\n * Transform/multiply the given vector by this matrix, perform perspective divide and store the result in dest
.\r\n *
\r\n * This method uses w=1.0 as the fourth vector component.\r\n * \r\n * @see Vector3f#mulProject(Matrix4f, Vector3f)\r\n * \r\n * @param v\r\n * the vector to transform\r\n * @param dest\r\n * will contain the result\r\n * @return dest\r\n */\r\n public Vector3f transformProject(Vector3f v, Vector3f dest) {\r\n return v.mulProject(this, dest);\r\n }\r\n\r\n /**\r\n * Transform/multiply the given 3D-vector, as if it was a 4D-vector with w=1, by\r\n * this matrix and store the result in that vector.\r\n *
\r\n * The given 3D-vector is treated as a 4D-vector with its w-component being 1.0, so it\r\n * will represent a position/location in 3D-space rather than a direction. This method is therefore\r\n * not suited for perspective projection transformations as it will not save the\r\n * w component of the transformed vector.\r\n * For perspective projection use {@link #transform(Vector4f)} or {@link #transformProject(Vector3f)}\r\n * when perspective divide should be applied, too.\r\n *
\r\n * In order to store the result in another vector, use {@link #transformPosition(Vector3f, Vector3f)}.\r\n * \r\n * @see #transformPosition(Vector3f, Vector3f)\r\n * @see #transform(Vector4f)\r\n * @see #transformProject(Vector3f)\r\n * \r\n * @param v\r\n * the vector to transform and to hold the final result\r\n * @return v\r\n */\r\n public Vector3f transformPosition(Vector3f v) {\r\n v.set(m00 * v.x + m10 * v.y + m20 * v.z + m30,\r\n m01 * v.x + m11 * v.y + m21 * v.z + m31,\r\n m02 * v.x + m12 * v.y + m22 * v.z + m32);\r\n return v;\r\n }\r\n\r\n /**\r\n * Transform/multiply the given 3D-vector, as if it was a 4D-vector with w=1, by\r\n * this matrix and store the result in dest
.\r\n *
\r\n * The given 3D-vector is treated as a 4D-vector with its w-component being 1.0, so it\r\n * will represent a position/location in 3D-space rather than a direction. This method is therefore\r\n * not suited for perspective projection transformations as it will not save the\r\n * w component of the transformed vector.\r\n * For perspective projection use {@link #transform(Vector4f, Vector4f)} or\r\n * {@link #transformProject(Vector3f, Vector3f)} when perspective divide should be applied, too.\r\n *
\r\n * In order to store the result in the same vector, use {@link #transformPosition(Vector3f)}.\r\n * \r\n * @see #transformPosition(Vector3f)\r\n * @see #transform(Vector4f, Vector4f)\r\n * @see #transformProject(Vector3f, Vector3f)\r\n * \r\n * @param v\r\n * the vector to transform\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Vector3f transformPosition(Vector3f v, Vector3f dest) {\r\n dest.set(m00 * v.x + m10 * v.y + m20 * v.z + m30,\r\n m01 * v.x + m11 * v.y + m21 * v.z + m31,\r\n m02 * v.x + m12 * v.y + m22 * v.z + m32);\r\n return dest;\r\n }\r\n\r\n /**\r\n * Transform/multiply the given 3D-vector, as if it was a 4D-vector with w=0, by\r\n * this matrix and store the result in that vector.\r\n *
\r\n * The given 3D-vector is treated as a 4D-vector with its w-component being 0.0, so it\r\n * will represent a direction in 3D-space rather than a position. This method will therefore\r\n * not take the translation part of the matrix into account.\r\n *
\r\n * In order to store the result in another vector, use {@link #transformDirection(Vector3f, Vector3f)}.\r\n * \r\n * @see #transformDirection(Vector3f, Vector3f)\r\n * \r\n * @param v\r\n * the vector to transform and to hold the final result\r\n * @return v\r\n */\r\n public Vector3f transformDirection(Vector3f v) {\r\n v.set(m00 * v.x + m10 * v.y + m20 * v.z,\r\n m01 * v.x + m11 * v.y + m21 * v.z,\r\n m02 * v.x + m12 * v.y + m22 * v.z);\r\n return v;\r\n }\r\n\r\n /**\r\n * Transform/multiply the given 3D-vector, as if it was a 4D-vector with w=0, by\r\n * this matrix and store the result in dest
.\r\n *
\r\n * The given 3D-vector is treated as a 4D-vector with its w-component being 0.0, so it\r\n * will represent a direction in 3D-space rather than a position. This method will therefore\r\n * not take the translation part of the matrix into account.\r\n *
\r\n * In order to store the result in the same vector, use {@link #transformDirection(Vector3f)}.\r\n * \r\n * @see #transformDirection(Vector3f)\r\n * \r\n * @param v\r\n * the vector to transform and to hold the final result\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Vector3f transformDirection(Vector3f v, Vector3f dest) {\r\n dest.set(m00 * v.x + m10 * v.y + m20 * v.z,\r\n m01 * v.x + m11 * v.y + m21 * v.z,\r\n m02 * v.x + m12 * v.y + m22 * v.z);\r\n return dest;\r\n }\r\n\r\n /**\r\n * Transform/multiply the given 4D-vector by assuming that this
matrix represents an {@link #isAffine() affine} transformation\r\n * (i.e. its last row is equal to (0, 0, 0, 1)).\r\n *
\r\n * In order to store the result in another vector, use {@link #transformAffine(Vector4f, Vector4f)}.\r\n * \r\n * @see #transformAffine(Vector4f, Vector4f)\r\n * \r\n * @param v\r\n * the vector to transform and to hold the final result\r\n * @return v\r\n */\r\n public Vector4f transformAffine(Vector4f v) {\r\n v.set(m00 * v.x + m10 * v.y + m20 * v.z + m30 * v.w,\r\n m01 * v.x + m11 * v.y + m21 * v.z + m31 * v.w,\r\n m02 * v.x + m12 * v.y + m22 * v.z + m32 * v.w,\r\n v.w);\r\n return v;\r\n }\r\n\r\n /**\r\n * Transform/multiply the given 4D-vector by assuming that this
matrix represents an {@link #isAffine() affine} transformation\r\n * (i.e. its last row is equal to (0, 0, 0, 1)) and store the result in dest
.\r\n *
\r\n * In order to store the result in the same vector, use {@link #transformAffine(Vector4f)}.\r\n * \r\n * @see #transformAffine(Vector4f)\r\n * \r\n * @param v\r\n * the vector to transform and to hold the final result\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Vector4f transformAffine(Vector4f v, Vector4f dest) {\r\n dest.set(m00 * v.x + m10 * v.y + m20 * v.z + m30 * v.w,\r\n m01 * v.x + m11 * v.y + m21 * v.z + m31 * v.w,\r\n m02 * v.x + m12 * v.y + m22 * v.z + m32 * v.w,\r\n v.w);\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply scaling to the this matrix by scaling the base axes by the given xyz.x,\r\n * xyz.y and xyz.z factors, respectively and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and S
the scaling matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
\r\n * , the scaling will be applied first!\r\n * \r\n * @param xyz\r\n * the factors of the x, y and z component, respectively\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f scale(Vector3f xyz, Matrix4f dest) {\r\n return scale(xyz.x, xyz.y, xyz.z, dest);\r\n }\r\n\r\n /**\r\n * Apply scaling to this matrix by scaling the base axes by the given xyz.x,\r\n * xyz.y and xyz.z factors, respectively.\r\n *
\r\n * If M
is this
matrix and S
the scaling matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
, the\r\n * scaling will be applied first!\r\n * \r\n * @param xyz\r\n * the factors of the x, y and z component, respectively\r\n * @return this\r\n */\r\n public Matrix4f scale(Vector3f xyz) {\r\n return scale(xyz.x, xyz.y, xyz.z, this);\r\n }\r\n\r\n /**\r\n * Apply scaling to this matrix by uniformly scaling all base axes by the given xyz
factor\r\n * and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and S
the scaling matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
, the\r\n * scaling will be applied first!\r\n *
\r\n * Individual scaling of all three axes can be applied using {@link #scale(float, float, float, Matrix4f)}. \r\n * \r\n * @see #scale(float, float, float, Matrix4f)\r\n * \r\n * @param xyz\r\n * the factor for all components\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f scale(float xyz, Matrix4f dest) {\r\n return scale(xyz, xyz, xyz, dest);\r\n }\r\n\r\n /**\r\n * Apply scaling to this matrix by uniformly scaling all base axes by the given xyz
factor.\r\n *
\r\n * If M
is this
matrix and S
the scaling matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
, the\r\n * scaling will be applied first!\r\n *
\r\n * Individual scaling of all three axes can be applied using {@link #scale(float, float, float)}. \r\n * \r\n * @see #scale(float, float, float)\r\n * \r\n * @param xyz\r\n * the factor for all components\r\n * @return this\r\n */\r\n public Matrix4f scale(float xyz) {\r\n return scale(xyz, xyz, xyz);\r\n }\r\n\r\n /**\r\n * Apply scaling to the this matrix by scaling the base axes by the given x,\r\n * y and z factors and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and S
the scaling matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
\r\n * , the scaling will be applied first!\r\n * \r\n * @param x\r\n * the factor of the x component\r\n * @param y\r\n * the factor of the y component\r\n * @param z\r\n * the factor of the z component\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f scale(float x, float y, float z, Matrix4f dest) {\r\n // scale matrix elements:\r\n // m00 = x, m11 = y, m22 = z\r\n // m33 = 1\r\n // all others = 0\r\n dest.m00 = m00 * x;\r\n dest.m01 = m01 * x;\r\n dest.m02 = m02 * x;\r\n dest.m03 = m03 * x;\r\n dest.m10 = m10 * y;\r\n dest.m11 = m11 * y;\r\n dest.m12 = m12 * y;\r\n dest.m13 = m13 * y;\r\n dest.m20 = m20 * z;\r\n dest.m21 = m21 * z;\r\n dest.m22 = m22 * z;\r\n dest.m23 = m23 * z;\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply scaling to this matrix by scaling the base axes by the given x,\r\n * y and z factors.\r\n *
\r\n * If M
is this
matrix and S
the scaling matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
, the\r\n * scaling will be applied first!\r\n * \r\n * @param x\r\n * the factor of the x component\r\n * @param y\r\n * the factor of the y component\r\n * @param z\r\n * the factor of the z component\r\n * @return this\r\n */\r\n public Matrix4f scale(float x, float y, float z) {\r\n return scale(x, y, z, this);\r\n }\r\n\r\n /**\r\n * Apply rotation about the X axis to this matrix by rotating the given amount of radians \r\n * and store the result in dest
.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise. \r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateX(float ang, Matrix4f dest) {\r\n float sin, cos;\r\n if (ang == (float) Math.PI || ang == -(float) Math.PI) {\r\n cos = -1.0f;\r\n sin = 0.0f;\r\n } else if (ang == (float) Math.PI * 0.5f || ang == -(float) Math.PI * 1.5f) {\r\n cos = 0.0f;\r\n sin = 1.0f;\r\n } else if (ang == (float) -Math.PI * 0.5f || ang == (float) Math.PI * 1.5f) {\r\n cos = 0.0f;\r\n sin = -1.0f;\r\n } else {\r\n cos = (float) Math.cos(ang);\r\n sin = (float) Math.sin(ang);\r\n }\r\n float rm11 = cos;\r\n float rm12 = sin;\r\n float rm21 = -sin;\r\n float rm22 = cos;\r\n\r\n // add temporaries for dependent values\r\n float nm10 = m10 * rm11 + m20 * rm12;\r\n float nm11 = m11 * rm11 + m21 * rm12;\r\n float nm12 = m12 * rm11 + m22 * rm12;\r\n float nm13 = m13 * rm11 + m23 * rm12;\r\n // set non-dependent values directly\r\n dest.m20 = m10 * rm21 + m20 * rm22;\r\n dest.m21 = m11 * rm21 + m21 * rm22;\r\n dest.m22 = m12 * rm21 + m22 * rm22;\r\n dest.m23 = m13 * rm21 + m23 * rm22;\r\n // set other values\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m00 = m00;\r\n dest.m01 = m01;\r\n dest.m02 = m02;\r\n dest.m03 = m03;\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply rotation about the X axis to this matrix by rotating the given amount of radians.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @return this\r\n */\r\n public Matrix4f rotateX(float ang) {\r\n return rotateX(ang, this);\r\n }\r\n\r\n /**\r\n * Apply rotation about the Y axis to this matrix by rotating the given amount of radians \r\n * and store the result in dest
.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateY(float ang, Matrix4f dest) {\r\n float cos, sin;\r\n if (ang == (float) Math.PI || ang == -(float) Math.PI) {\r\n cos = -1.0f;\r\n sin = 0.0f;\r\n } else if (ang == (float) Math.PI * 0.5f || ang == -(float) Math.PI * 1.5f) {\r\n cos = 0.0f;\r\n sin = 1.0f;\r\n } else if (ang == (float) -Math.PI * 0.5f || ang == (float) Math.PI * 1.5f) {\r\n cos = 0.0f;\r\n sin = -1.0f;\r\n } else {\r\n cos = (float) Math.cos(ang);\r\n sin = (float) Math.sin(ang);\r\n }\r\n float rm00 = cos;\r\n float rm02 = -sin;\r\n float rm20 = sin;\r\n float rm22 = cos;\r\n\r\n // add temporaries for dependent values\r\n float nm00 = m00 * rm00 + m20 * rm02;\r\n float nm01 = m01 * rm00 + m21 * rm02;\r\n float nm02 = m02 * rm00 + m22 * rm02;\r\n float nm03 = m03 * rm00 + m23 * rm02;\r\n // set non-dependent values directly\r\n dest.m20 = m00 * rm20 + m20 * rm22;\r\n dest.m21 = m01 * rm20 + m21 * rm22;\r\n dest.m22 = m02 * rm20 + m22 * rm22;\r\n dest.m23 = m03 * rm20 + m23 * rm22;\r\n // set other values\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = m10;\r\n dest.m11 = m11;\r\n dest.m12 = m12;\r\n dest.m13 = m13;\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply rotation about the Y axis to this matrix by rotating the given amount of radians.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @return this\r\n */\r\n public Matrix4f rotateY(float ang) {\r\n return rotateY(ang, this);\r\n }\r\n\r\n /**\r\n * Apply rotation about the Z axis to this matrix by rotating the given amount of radians \r\n * and store the result in dest
.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateZ(float ang, Matrix4f dest) {\r\n float sin, cos;\r\n if (ang == (float) Math.PI || ang == -(float) Math.PI) {\r\n cos = -1.0f;\r\n sin = 0.0f;\r\n } else if (ang == (float) Math.PI * 0.5f || ang == -(float) Math.PI * 1.5f) {\r\n cos = 0.0f;\r\n sin = 1.0f;\r\n } else if (ang == (float) -Math.PI * 0.5f || ang == (float) Math.PI * 1.5f) {\r\n cos = 0.0f;\r\n sin = -1.0f;\r\n } else {\r\n cos = (float) Math.cos(ang);\r\n sin = (float) Math.sin(ang);\r\n }\r\n float rm00 = cos;\r\n float rm01 = sin;\r\n float rm10 = -sin;\r\n float rm11 = cos;\r\n\r\n // add temporaries for dependent values\r\n float nm00 = m00 * rm00 + m10 * rm01;\r\n float nm01 = m01 * rm00 + m11 * rm01;\r\n float nm02 = m02 * rm00 + m12 * rm01;\r\n float nm03 = m03 * rm00 + m13 * rm01;\r\n // set non-dependent values directly\r\n dest.m10 = m00 * rm10 + m10 * rm11;\r\n dest.m11 = m01 * rm10 + m11 * rm11;\r\n dest.m12 = m02 * rm10 + m12 * rm11;\r\n dest.m13 = m03 * rm10 + m13 * rm11;\r\n // set other values\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m20 = m20;\r\n dest.m21 = m21;\r\n dest.m22 = m22;\r\n dest.m23 = m23;\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply rotation about the Z axis to this matrix by rotating the given amount of radians.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @return this\r\n */\r\n public Matrix4f rotateZ(float ang) {\r\n return rotateZ(ang, this);\r\n }\r\n\r\n /**\r\n * Apply rotation of angleX
radians about the X axis, followed by a rotation of angleY
radians about the Y axis and\r\n * followed by a rotation of angleZ
radians about the Z axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * This method is equivalent to calling: rotateX(angleX).rotateY(angleY).rotateZ(angleZ)\r\n * \r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @return this\r\n */\r\n public Matrix4f rotateXYZ(float angleX, float angleY, float angleZ) {\r\n return rotateXYZ(angleX, angleY, angleZ, this);\r\n }\r\n\r\n /**\r\n * Apply rotation of angleX
radians about the X axis, followed by a rotation of angleY
radians about the Y axis and\r\n * followed by a rotation of angleZ
radians about the Z axis and store the result in dest
.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * This method is equivalent to calling: rotateX(angleX, dest).rotateY(angleY).rotateZ(angleZ)\r\n * \r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateXYZ(float angleX, float angleY, float angleZ, Matrix4f dest) {\r\n float cosX = (float) Math.cos(angleX);\r\n float sinX = (float) Math.sin(angleX);\r\n float cosY = (float) Math.cos(angleY);\r\n float sinY = (float) Math.sin(angleY);\r\n float cosZ = (float) Math.cos(angleZ);\r\n float sinZ = (float) Math.sin(angleZ);\r\n float m_sinX = -sinX;\r\n float m_sinY = -sinY;\r\n float m_sinZ = -sinZ;\r\n\r\n // rotateX\r\n float nm10 = m10 * cosX + m20 * sinX;\r\n float nm11 = m11 * cosX + m21 * sinX;\r\n float nm12 = m12 * cosX + m22 * sinX;\r\n float nm13 = m13 * cosX + m23 * sinX;\r\n float nm20 = m10 * m_sinX + m20 * cosX;\r\n float nm21 = m11 * m_sinX + m21 * cosX;\r\n float nm22 = m12 * m_sinX + m22 * cosX;\r\n float nm23 = m13 * m_sinX + m23 * cosX;\r\n // rotateY\r\n float nm00 = m00 * cosY + nm20 * m_sinY;\r\n float nm01 = m01 * cosY + nm21 * m_sinY;\r\n float nm02 = m02 * cosY + nm22 * m_sinY;\r\n float nm03 = m03 * cosY + nm23 * m_sinY;\r\n dest.m20 = m00 * sinY + nm20 * cosY;\r\n dest.m21 = m01 * sinY + nm21 * cosY;\r\n dest.m22 = m02 * sinY + nm22 * cosY;\r\n dest.m23 = m03 * sinY + nm23 * cosY;\r\n // rotateZ\r\n dest.m00 = nm00 * cosZ + nm10 * sinZ;\r\n dest.m01 = nm01 * cosZ + nm11 * sinZ;\r\n dest.m02 = nm02 * cosZ + nm12 * sinZ;\r\n dest.m03 = nm03 * cosZ + nm13 * sinZ;\r\n dest.m10 = nm00 * m_sinZ + nm10 * cosZ;\r\n dest.m11 = nm01 * m_sinZ + nm11 * cosZ;\r\n dest.m12 = nm02 * m_sinZ + nm12 * cosZ;\r\n dest.m13 = nm03 * m_sinZ + nm13 * cosZ;\r\n // copy last column from 'this'\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply rotation of angleX
radians about the X axis, followed by a rotation of angleY
radians about the Y axis and\r\n * followed by a rotation of angleZ
radians about the Z axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method assumes that this
matrix represents an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and can be used to speed up matrix multiplication if the matrix only represents affine transformations, such as translation, rotation, scaling and shearing (in any combination).\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * This method is equivalent to calling: rotateX(angleX).rotateY(angleY).rotateZ(angleZ)\r\n * \r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @return this\r\n */\r\n public Matrix4f rotateAffineXYZ(float angleX, float angleY, float angleZ) {\r\n return rotateAffineXYZ(angleX, angleY, angleZ, this);\r\n }\r\n\r\n /**\r\n * Apply rotation of angleX
radians about the X axis, followed by a rotation of angleY
radians about the Y axis and\r\n * followed by a rotation of angleZ
radians about the Z axis and store the result in dest
.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method assumes that this
matrix represents an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and can be used to speed up matrix multiplication if the matrix only represents affine transformations, such as translation, rotation, scaling and shearing (in any combination).\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n * \r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateAffineXYZ(float angleX, float angleY, float angleZ, Matrix4f dest) {\r\n float cosX = (float) Math.cos(angleX);\r\n float sinX = (float) Math.sin(angleX);\r\n float cosY = (float) Math.cos(angleY);\r\n float sinY = (float) Math.sin(angleY);\r\n float cosZ = (float) Math.cos(angleZ);\r\n float sinZ = (float) Math.sin(angleZ);\r\n float m_sinX = -sinX;\r\n float m_sinY = -sinY;\r\n float m_sinZ = -sinZ;\r\n\r\n // rotateX\r\n float nm10 = m10 * cosX + m20 * sinX;\r\n float nm11 = m11 * cosX + m21 * sinX;\r\n float nm12 = m12 * cosX + m22 * sinX;\r\n float nm20 = m10 * m_sinX + m20 * cosX;\r\n float nm21 = m11 * m_sinX + m21 * cosX;\r\n float nm22 = m12 * m_sinX + m22 * cosX;\r\n // rotateY\r\n float nm00 = m00 * cosY + nm20 * m_sinY;\r\n float nm01 = m01 * cosY + nm21 * m_sinY;\r\n float nm02 = m02 * cosY + nm22 * m_sinY;\r\n dest.m20 = m00 * sinY + nm20 * cosY;\r\n dest.m21 = m01 * sinY + nm21 * cosY;\r\n dest.m22 = m02 * sinY + nm22 * cosY;\r\n dest.m23 = 0.0f;\r\n // rotateZ\r\n dest.m00 = nm00 * cosZ + nm10 * sinZ;\r\n dest.m01 = nm01 * cosZ + nm11 * sinZ;\r\n dest.m02 = nm02 * cosZ + nm12 * sinZ;\r\n dest.m03 = 0.0f;\r\n dest.m10 = nm00 * m_sinZ + nm10 * cosZ;\r\n dest.m11 = nm01 * m_sinZ + nm11 * cosZ;\r\n dest.m12 = nm02 * m_sinZ + nm12 * cosZ;\r\n dest.m13 = 0.0f;\r\n // copy last column from 'this'\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply rotation of angleZ
radians about the Z axis, followed by a rotation of angleY
radians about the Y axis and\r\n * followed by a rotation of angleX
radians about the X axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * This method is equivalent to calling: rotateZ(angleZ).rotateY(angleY).rotateX(angleX)\r\n * \r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleX\r\n * the angle to rotate about X\r\n * @return this\r\n */\r\n public Matrix4f rotateZYX(float angleZ, float angleY, float angleX) {\r\n return rotateZYX(angleZ, angleY, angleX, this);\r\n }\r\n\r\n /**\r\n * Apply rotation of angleZ
radians about the Z axis, followed by a rotation of angleY
radians about the Y axis and\r\n * followed by a rotation of angleX
radians about the X axis and store the result in dest
.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * This method is equivalent to calling: rotateZ(angleZ, dest).rotateY(angleY).rotateX(angleX)\r\n * \r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateZYX(float angleZ, float angleY, float angleX, Matrix4f dest) {\r\n float cosZ = (float) Math.cos(angleZ);\r\n float sinZ = (float) Math.sin(angleZ);\r\n float cosY = (float) Math.cos(angleY);\r\n float sinY = (float) Math.sin(angleY);\r\n float cosX = (float) Math.cos(angleX);\r\n float sinX = (float) Math.sin(angleX);\r\n float m_sinZ = -sinZ;\r\n float m_sinY = -sinY;\r\n float m_sinX = -sinX;\r\n\r\n // rotateZ\r\n float nm00 = m00 * cosZ + m10 * sinZ;\r\n float nm01 = m01 * cosZ + m11 * sinZ;\r\n float nm02 = m02 * cosZ + m12 * sinZ;\r\n float nm03 = m03 * cosZ + m13 * sinZ;\r\n float nm10 = m00 * m_sinZ + m10 * cosZ;\r\n float nm11 = m01 * m_sinZ + m11 * cosZ;\r\n float nm12 = m02 * m_sinZ + m12 * cosZ;\r\n float nm13 = m03 * m_sinZ + m13 * cosZ;\r\n // rotateY\r\n float nm20 = nm00 * sinY + m20 * cosY;\r\n float nm21 = nm01 * sinY + m21 * cosY;\r\n float nm22 = nm02 * sinY + m22 * cosY;\r\n float nm23 = nm03 * sinY + m23 * cosY;\r\n dest.m00 = nm00 * cosY + m20 * m_sinY;\r\n dest.m01 = nm01 * cosY + m21 * m_sinY;\r\n dest.m02 = nm02 * cosY + m22 * m_sinY;\r\n dest.m03 = nm03 * cosY + m23 * m_sinY;\r\n // rotateX\r\n dest.m10 = nm10 * cosX + nm20 * sinX;\r\n dest.m11 = nm11 * cosX + nm21 * sinX;\r\n dest.m12 = nm12 * cosX + nm22 * sinX;\r\n dest.m13 = nm13 * cosX + nm23 * sinX;\r\n dest.m20 = nm10 * m_sinX + nm20 * cosX;\r\n dest.m21 = nm11 * m_sinX + nm21 * cosX;\r\n dest.m22 = nm12 * m_sinX + nm22 * cosX;\r\n dest.m23 = nm13 * m_sinX + nm23 * cosX;\r\n // copy last column from 'this'\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply rotation of angleZ
radians about the Z axis, followed by a rotation of angleY
radians about the Y axis and\r\n * followed by a rotation of angleX
radians about the X axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method assumes that this
matrix represents an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and can be used to speed up matrix multiplication if the matrix only represents affine transformations, such as translation, rotation, scaling and shearing (in any combination).\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n * \r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleX\r\n * the angle to rotate about X\r\n * @return this\r\n */\r\n public Matrix4f rotateAffineZYX(float angleZ, float angleY, float angleX) {\r\n return rotateAffineZYX(angleZ, angleY, angleX, this);\r\n }\r\n\r\n /**\r\n * Apply rotation of angleZ
radians about the Z axis, followed by a rotation of angleY
radians about the Y axis and\r\n * followed by a rotation of angleX
radians about the X axis and store the result in dest
.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method assumes that this
matrix represents an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and can be used to speed up matrix multiplication if the matrix only represents affine transformations, such as translation, rotation, scaling and shearing (in any combination).\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n * \r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateAffineZYX(float angleZ, float angleY, float angleX, Matrix4f dest) {\r\n float cosZ = (float) Math.cos(angleZ);\r\n float sinZ = (float) Math.sin(angleZ);\r\n float cosY = (float) Math.cos(angleY);\r\n float sinY = (float) Math.sin(angleY);\r\n float cosX = (float) Math.cos(angleX);\r\n float sinX = (float) Math.sin(angleX);\r\n float m_sinZ = -sinZ;\r\n float m_sinY = -sinY;\r\n float m_sinX = -sinX;\r\n\r\n // rotateZ\r\n float nm00 = m00 * cosZ + m10 * sinZ;\r\n float nm01 = m01 * cosZ + m11 * sinZ;\r\n float nm02 = m02 * cosZ + m12 * sinZ;\r\n float nm10 = m00 * m_sinZ + m10 * cosZ;\r\n float nm11 = m01 * m_sinZ + m11 * cosZ;\r\n float nm12 = m02 * m_sinZ + m12 * cosZ;\r\n // rotateY\r\n float nm20 = nm00 * sinY + m20 * cosY;\r\n float nm21 = nm01 * sinY + m21 * cosY;\r\n float nm22 = nm02 * sinY + m22 * cosY;\r\n dest.m00 = nm00 * cosY + m20 * m_sinY;\r\n dest.m01 = nm01 * cosY + m21 * m_sinY;\r\n dest.m02 = nm02 * cosY + m22 * m_sinY;\r\n dest.m03 = 0.0f;\r\n // rotateX\r\n dest.m10 = nm10 * cosX + nm20 * sinX;\r\n dest.m11 = nm11 * cosX + nm21 * sinX;\r\n dest.m12 = nm12 * cosX + nm22 * sinX;\r\n dest.m13 = 0.0f;\r\n dest.m20 = nm10 * m_sinX + nm20 * cosX;\r\n dest.m21 = nm11 * m_sinX + nm21 * cosX;\r\n dest.m22 = nm12 * m_sinX + nm22 * cosX;\r\n dest.m23 = 0.0f;\r\n // copy last column from 'this'\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply rotation of angleY
radians about the Y axis, followed by a rotation of angleX
radians about the X axis and\r\n * followed by a rotation of angleZ
radians about the Z axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * This method is equivalent to calling: rotateY(angleY).rotateX(angleX).rotateZ(angleZ)\r\n * \r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @return this\r\n */\r\n public Matrix4f rotateYXZ(float angleY, float angleX, float angleZ) {\r\n return rotateYXZ(angleY, angleX, angleZ, this);\r\n }\r\n\r\n /**\r\n * Apply rotation of angleY
radians about the Y axis, followed by a rotation of angleX
radians about the X axis and\r\n * followed by a rotation of angleZ
radians about the Z axis and store the result in dest
.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * This method is equivalent to calling: rotateY(angleY, dest).rotateX(angleX).rotateZ(angleZ)\r\n * \r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateYXZ(float angleY, float angleX, float angleZ, Matrix4f dest) {\r\n float cosY = (float) Math.cos(angleY);\r\n float sinY = (float) Math.sin(angleY);\r\n float cosX = (float) Math.cos(angleX);\r\n float sinX = (float) Math.sin(angleX);\r\n float cosZ = (float) Math.cos(angleZ);\r\n float sinZ = (float) Math.sin(angleZ);\r\n float m_sinY = -sinY;\r\n float m_sinX = -sinX;\r\n float m_sinZ = -sinZ;\r\n\r\n // rotateY\r\n float nm20 = m00 * sinY + m20 * cosY;\r\n float nm21 = m01 * sinY + m21 * cosY;\r\n float nm22 = m02 * sinY + m22 * cosY;\r\n float nm23 = m03 * sinY + m23 * cosY;\r\n float nm00 = m00 * cosY + m20 * m_sinY;\r\n float nm01 = m01 * cosY + m21 * m_sinY;\r\n float nm02 = m02 * cosY + m22 * m_sinY;\r\n float nm03 = m03 * cosY + m23 * m_sinY;\r\n // rotateX\r\n float nm10 = m10 * cosX + nm20 * sinX;\r\n float nm11 = m11 * cosX + nm21 * sinX;\r\n float nm12 = m12 * cosX + nm22 * sinX;\r\n float nm13 = m13 * cosX + nm23 * sinX;\r\n dest.m20 = m10 * m_sinX + nm20 * cosX;\r\n dest.m21 = m11 * m_sinX + nm21 * cosX;\r\n dest.m22 = m12 * m_sinX + nm22 * cosX;\r\n dest.m23 = m13 * m_sinX + nm23 * cosX;\r\n // rotateZ\r\n dest.m00 = nm00 * cosZ + nm10 * sinZ;\r\n dest.m01 = nm01 * cosZ + nm11 * sinZ;\r\n dest.m02 = nm02 * cosZ + nm12 * sinZ;\r\n dest.m03 = nm03 * cosZ + nm13 * sinZ;\r\n dest.m10 = nm00 * m_sinZ + nm10 * cosZ;\r\n dest.m11 = nm01 * m_sinZ + nm11 * cosZ;\r\n dest.m12 = nm02 * m_sinZ + nm12 * cosZ;\r\n dest.m13 = nm03 * m_sinZ + nm13 * cosZ;\r\n // copy last column from 'this'\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply rotation of angleY
radians about the Y axis, followed by a rotation of angleX
radians about the X axis and\r\n * followed by a rotation of angleZ
radians about the Z axis.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method assumes that this
matrix represents an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and can be used to speed up matrix multiplication if the matrix only represents affine transformations, such as translation, rotation, scaling and shearing (in any combination).\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n * \r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @return this\r\n */\r\n public Matrix4f rotateAffineYXZ(float angleY, float angleX, float angleZ) {\r\n return rotateAffineYXZ(angleY, angleX, angleZ, this);\r\n }\r\n\r\n /**\r\n * Apply rotation of angleY
radians about the Y axis, followed by a rotation of angleX
radians about the X axis and\r\n * followed by a rotation of angleZ
radians about the Z axis and store the result in dest
.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * This method assumes that this
matrix represents an {@link #isAffine() affine} transformation (i.e. its last row is equal to (0, 0, 0, 1))\r\n * and can be used to speed up matrix multiplication if the matrix only represents affine transformations, such as translation, rotation, scaling and shearing (in any combination).\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n * \r\n * @param angleY\r\n * the angle to rotate about Y\r\n * @param angleX\r\n * the angle to rotate about X\r\n * @param angleZ\r\n * the angle to rotate about Z\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateAffineYXZ(float angleY, float angleX, float angleZ, Matrix4f dest) {\r\n float cosY = (float) Math.cos(angleY);\r\n float sinY = (float) Math.sin(angleY);\r\n float cosX = (float) Math.cos(angleX);\r\n float sinX = (float) Math.sin(angleX);\r\n float cosZ = (float) Math.cos(angleZ);\r\n float sinZ = (float) Math.sin(angleZ);\r\n float m_sinY = -sinY;\r\n float m_sinX = -sinX;\r\n float m_sinZ = -sinZ;\r\n\r\n // rotateY\r\n float nm20 = m00 * sinY + m20 * cosY;\r\n float nm21 = m01 * sinY + m21 * cosY;\r\n float nm22 = m02 * sinY + m22 * cosY;\r\n float nm00 = m00 * cosY + m20 * m_sinY;\r\n float nm01 = m01 * cosY + m21 * m_sinY;\r\n float nm02 = m02 * cosY + m22 * m_sinY;\r\n // rotateX\r\n float nm10 = m10 * cosX + nm20 * sinX;\r\n float nm11 = m11 * cosX + nm21 * sinX;\r\n float nm12 = m12 * cosX + nm22 * sinX;\r\n dest.m20 = m10 * m_sinX + nm20 * cosX;\r\n dest.m21 = m11 * m_sinX + nm21 * cosX;\r\n dest.m22 = m12 * m_sinX + nm22 * cosX;\r\n dest.m23 = 0.0f;\r\n // rotateZ\r\n dest.m00 = nm00 * cosZ + nm10 * sinZ;\r\n dest.m01 = nm01 * cosZ + nm11 * sinZ;\r\n dest.m02 = nm02 * cosZ + nm12 * sinZ;\r\n dest.m03 = 0.0f;\r\n dest.m10 = nm00 * m_sinZ + nm10 * cosZ;\r\n dest.m11 = nm01 * m_sinZ + nm11 * cosZ;\r\n dest.m12 = nm02 * m_sinZ + nm12 * cosZ;\r\n dest.m13 = 0.0f;\r\n // copy last column from 'this'\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply rotation to this matrix by rotating the given amount of radians\r\n * about the specified (x, y, z) axis and store the result in dest
.\r\n *
\r\n * The axis described by the three components needs to be a unit vector.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * In order to set the matrix to a rotation matrix without post-multiplying the rotation\r\n * transformation, use {@link #rotation(float, float, float, float) rotation()}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotation(float, float, float, float)\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @param x\r\n * the x component of the axis\r\n * @param y\r\n * the y component of the axis\r\n * @param z\r\n * the z component of the axis\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotate(float ang, float x, float y, float z, Matrix4f dest) {\r\n float s = (float) Math.sin(ang);\r\n float c = (float) Math.cos(ang);\r\n float C = 1.0f - c;\r\n\r\n // rotation matrix elements:\r\n // m30, m31, m32, m03, m13, m23 = 0\r\n // m33 = 1\r\n float xx = x * x, xy = x * y, xz = x * z;\r\n float yy = y * y, yz = y * z;\r\n float zz = z * z;\r\n float rm00 = xx * C + c;\r\n float rm01 = xy * C + z * s;\r\n float rm02 = xz * C - y * s;\r\n float rm10 = xy * C - z * s;\r\n float rm11 = yy * C + c;\r\n float rm12 = yz * C + x * s;\r\n float rm20 = xz * C + y * s;\r\n float rm21 = yz * C - x * s;\r\n float rm22 = zz * C + c;\r\n\r\n // add temporaries for dependent values\r\n float nm00 = m00 * rm00 + m10 * rm01 + m20 * rm02;\r\n float nm01 = m01 * rm00 + m11 * rm01 + m21 * rm02;\r\n float nm02 = m02 * rm00 + m12 * rm01 + m22 * rm02;\r\n float nm03 = m03 * rm00 + m13 * rm01 + m23 * rm02;\r\n float nm10 = m00 * rm10 + m10 * rm11 + m20 * rm12;\r\n float nm11 = m01 * rm10 + m11 * rm11 + m21 * rm12;\r\n float nm12 = m02 * rm10 + m12 * rm11 + m22 * rm12;\r\n float nm13 = m03 * rm10 + m13 * rm11 + m23 * rm12;\r\n // set non-dependent values directly\r\n dest.m20 = m00 * rm20 + m10 * rm21 + m20 * rm22;\r\n dest.m21 = m01 * rm20 + m11 * rm21 + m21 * rm22;\r\n dest.m22 = m02 * rm20 + m12 * rm21 + m22 * rm22;\r\n dest.m23 = m03 * rm20 + m13 * rm21 + m23 * rm22;\r\n // set other values\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply rotation to this matrix by rotating the given amount of radians\r\n * about the specified (x, y, z) axis.\r\n *
\r\n * The axis described by the three components needs to be a unit vector.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * In order to set the matrix to a rotation matrix without post-multiplying the rotation\r\n * transformation, use {@link #rotation(float, float, float, float) rotation()}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotation(float, float, float, float)\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @param x\r\n * the x component of the axis\r\n * @param y\r\n * the y component of the axis\r\n * @param z\r\n * the z component of the axis\r\n * @return this\r\n */\r\n public Matrix4f rotate(float ang, float x, float y, float z) {\r\n return rotate(ang, x, y, z, this);\r\n }\r\n\r\n /**\r\n * Apply rotation to this {@link #isAffine() affine} matrix by rotating the given amount of radians\r\n * about the specified (x, y, z) axis and store the result in dest
.\r\n *
\r\n * This method assumes this
to be {@link #isAffine() affine}.\r\n *
\r\n * The axis described by the three components needs to be a unit vector.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * In order to set the matrix to a rotation matrix without post-multiplying the rotation\r\n * transformation, use {@link #rotation(float, float, float, float) rotation()}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotation(float, float, float, float)\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @param x\r\n * the x component of the axis\r\n * @param y\r\n * the y component of the axis\r\n * @param z\r\n * the z component of the axis\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateAffine(float ang, float x, float y, float z, Matrix4f dest) {\r\n float s = (float) Math.sin(ang);\r\n float c = (float) Math.cos(ang);\r\n float C = 1.0f - c;\r\n float xx = x * x, xy = x * y, xz = x * z;\r\n float yy = y * y, yz = y * z;\r\n float zz = z * z;\r\n float rm00 = xx * C + c;\r\n float rm01 = xy * C + z * s;\r\n float rm02 = xz * C - y * s;\r\n float rm10 = xy * C - z * s;\r\n float rm11 = yy * C + c;\r\n float rm12 = yz * C + x * s;\r\n float rm20 = xz * C + y * s;\r\n float rm21 = yz * C - x * s;\r\n float rm22 = zz * C + c;\r\n // add temporaries for dependent values\r\n float nm00 = m00 * rm00 + m10 * rm01 + m20 * rm02;\r\n float nm01 = m01 * rm00 + m11 * rm01 + m21 * rm02;\r\n float nm02 = m02 * rm00 + m12 * rm01 + m22 * rm02;\r\n float nm10 = m00 * rm10 + m10 * rm11 + m20 * rm12;\r\n float nm11 = m01 * rm10 + m11 * rm11 + m21 * rm12;\r\n float nm12 = m02 * rm10 + m12 * rm11 + m22 * rm12;\r\n // set non-dependent values directly\r\n dest.m20 = m00 * rm20 + m10 * rm21 + m20 * rm22;\r\n dest.m21 = m01 * rm20 + m11 * rm21 + m21 * rm22;\r\n dest.m22 = m02 * rm20 + m12 * rm21 + m22 * rm22;\r\n dest.m23 = 0.0f;\r\n // set other values\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = 0.0f;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = 0.0f;\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply rotation to this {@link #isAffine() affine} matrix by rotating the given amount of radians\r\n * about the specified (x, y, z) axis.\r\n *
\r\n * This method assumes this
to be {@link #isAffine() affine}.\r\n *
\r\n * The axis described by the three components needs to be a unit vector.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * rotation will be applied first!\r\n *
\r\n * In order to set the matrix to a rotation matrix without post-multiplying the rotation\r\n * transformation, use {@link #rotation(float, float, float, float) rotation()}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotation(float, float, float, float)\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @param x\r\n * the x component of the axis\r\n * @param y\r\n * the y component of the axis\r\n * @param z\r\n * the z component of the axis\r\n * @return this\r\n */\r\n public Matrix4f rotateAffine(float ang, float x, float y, float z) {\r\n return rotateAffine(ang, x, y, z, this);\r\n }\r\n\r\n /**\r\n * Pre-multiply a rotation to this {@link #isAffine() affine} matrix by rotating the given amount of radians\r\n * about the specified (x, y, z) axis and store the result in dest
.\r\n *
\r\n * This method assumes this
to be {@link #isAffine() affine}.\r\n *
\r\n * The axis described by the three components needs to be a unit vector.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be R * M
. So when transforming a\r\n * vector v
with the new matrix by using R * M * v
, the\r\n * rotation will be applied last!\r\n *
\r\n * In order to set the matrix to a rotation matrix without pre-multiplying the rotation\r\n * transformation, use {@link #rotation(float, float, float, float) rotation()}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotation(float, float, float, float)\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @param x\r\n * the x component of the axis\r\n * @param y\r\n * the y component of the axis\r\n * @param z\r\n * the z component of the axis\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateAffineLocal(float ang, float x, float y, float z, Matrix4f dest) {\r\n float s = (float) Math.sin(ang);\r\n float c = (float) Math.cos(ang);\r\n float C = 1.0f - c;\r\n float xx = x * x, xy = x * y, xz = x * z;\r\n float yy = y * y, yz = y * z;\r\n float zz = z * z;\r\n float lm00 = xx * C + c;\r\n float lm01 = xy * C + z * s;\r\n float lm02 = xz * C - y * s;\r\n float lm10 = xy * C - z * s;\r\n float lm11 = yy * C + c;\r\n float lm12 = yz * C + x * s;\r\n float lm20 = xz * C + y * s;\r\n float lm21 = yz * C - x * s;\r\n float lm22 = zz * C + c;\r\n float nm00 = lm00 * m00 + lm10 * m01 + lm20 * m02;\r\n float nm01 = lm01 * m00 + lm11 * m01 + lm21 * m02;\r\n float nm02 = lm02 * m00 + lm12 * m01 + lm22 * m02;\r\n float nm03 = 0.0f;\r\n float nm10 = lm00 * m10 + lm10 * m11 + lm20 * m12;\r\n float nm11 = lm01 * m10 + lm11 * m11 + lm21 * m12;\r\n float nm12 = lm02 * m10 + lm12 * m11 + lm22 * m12;\r\n float nm13 = 0.0f;\r\n float nm20 = lm00 * m20 + lm10 * m21 + lm20 * m22;\r\n float nm21 = lm01 * m20 + lm11 * m21 + lm21 * m22;\r\n float nm22 = lm02 * m20 + lm12 * m21 + lm22 * m22;\r\n float nm23 = 0.0f;\r\n float nm30 = lm00 * m30 + lm10 * m31 + lm20 * m32;\r\n float nm31 = lm01 * m30 + lm11 * m31 + lm21 * m32;\r\n float nm32 = lm02 * m30 + lm12 * m31 + lm22 * m32;\r\n float nm33 = 1.0f;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Pre-multiply a rotation to this {@link #isAffine() affine} matrix by rotating the given amount of radians\r\n * about the specified (x, y, z) axis.\r\n *
\r\n * This method assumes this
to be {@link #isAffine() affine}.\r\n *
\r\n * The axis described by the three components needs to be a unit vector.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and R
the rotation matrix,\r\n * then the new matrix will be R * M
. So when transforming a\r\n * vector v
with the new matrix by using R * M * v
, the\r\n * rotation will be applied last!\r\n *
\r\n * In order to set the matrix to a rotation matrix without pre-multiplying the rotation\r\n * transformation, use {@link #rotation(float, float, float, float) rotation()}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotation(float, float, float, float)\r\n * \r\n * @param ang\r\n * the angle in radians\r\n * @param x\r\n * the x component of the axis\r\n * @param y\r\n * the y component of the axis\r\n * @param z\r\n * the z component of the axis\r\n * @return this\r\n */\r\n public Matrix4f rotateAffineLocal(float ang, float x, float y, float z) {\r\n return rotateAffineLocal(ang, x, y, z, this);\r\n }\r\n\r\n /**\r\n * Apply a translation to this matrix by translating by the given number of\r\n * units in x, y and z.\r\n *
\r\n * If M
is this
matrix and T
the translation\r\n * matrix, then the new matrix will be M * T
. So when\r\n * transforming a vector v
with the new matrix by using\r\n * M * T * v
, the translation will be applied first!\r\n *
\r\n * In order to set the matrix to a translation transformation without post-multiplying\r\n * it, use {@link #translation(Vector3f)}.\r\n * \r\n * @see #translation(Vector3f)\r\n * \r\n * @param offset\r\n * the number of units in x, y and z by which to translate\r\n * @return this\r\n */\r\n public Matrix4f translate(Vector3f offset) {\r\n return translate(offset.x, offset.y, offset.z);\r\n }\r\n\r\n /**\r\n * Apply a translation to this matrix by translating by the given number of\r\n * units in x, y and z and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and T
the translation\r\n * matrix, then the new matrix will be M * T
. So when\r\n * transforming a vector v
with the new matrix by using\r\n * M * T * v
, the translation will be applied first!\r\n *
\r\n * In order to set the matrix to a translation transformation without post-multiplying\r\n * it, use {@link #translation(Vector3f)}.\r\n * \r\n * @see #translation(Vector3f)\r\n * \r\n * @param offset\r\n * the number of units in x, y and z by which to translate\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f translate(Vector3f offset, Matrix4f dest) {\r\n return translate(offset.x, offset.y, offset.z, dest);\r\n }\r\n\r\n /**\r\n * Apply a translation to this matrix by translating by the given number of\r\n * units in x, y and z and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and T
the translation\r\n * matrix, then the new matrix will be M * T
. So when\r\n * transforming a vector v
with the new matrix by using\r\n * M * T * v
, the translation will be applied first!\r\n *
\r\n * In order to set the matrix to a translation transformation without post-multiplying\r\n * it, use {@link #translation(float, float, float)}.\r\n * \r\n * @see #translation(float, float, float)\r\n * \r\n * @param x\r\n * the offset to translate in x\r\n * @param y\r\n * the offset to translate in y\r\n * @param z\r\n * the offset to translate in z\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f translate(float x, float y, float z, Matrix4f dest) {\r\n // translation matrix elements:\r\n // m00, m11, m22, m33 = 1\r\n // m30 = x, m31 = y, m32 = z\r\n // all others = 0\r\n dest.m00 = m00;\r\n dest.m01 = m01;\r\n dest.m02 = m02;\r\n dest.m03 = m03;\r\n dest.m10 = m10;\r\n dest.m11 = m11;\r\n dest.m12 = m12;\r\n dest.m13 = m13;\r\n dest.m20 = m20;\r\n dest.m21 = m21;\r\n dest.m22 = m22;\r\n dest.m23 = m23;\r\n dest.m30 = m00 * x + m10 * y + m20 * z + m30;\r\n dest.m31 = m01 * x + m11 * y + m21 * z + m31;\r\n dest.m32 = m02 * x + m12 * y + m22 * z + m32;\r\n dest.m33 = m03 * x + m13 * y + m23 * z + m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply a translation to this matrix by translating by the given number of\r\n * units in x, y and z.\r\n *
\r\n * If M
is this
matrix and T
the translation\r\n * matrix, then the new matrix will be M * T
. So when\r\n * transforming a vector v
with the new matrix by using\r\n * M * T * v
, the translation will be applied first!\r\n *
\r\n * In order to set the matrix to a translation transformation without post-multiplying\r\n * it, use {@link #translation(float, float, float)}.\r\n * \r\n * @see #translation(float, float, float)\r\n * \r\n * @param x\r\n * the offset to translate in x\r\n * @param y\r\n * the offset to translate in y\r\n * @param z\r\n * the offset to translate in z\r\n * @return this\r\n */\r\n public Matrix4f translate(float x, float y, float z) {\r\n Matrix4f c = this;\r\n // translation matrix elements:\r\n // m00, m11, m22, m33 = 1\r\n // m30 = x, m31 = y, m32 = z\r\n // all others = 0\r\n c.m30 = c.m00 * x + c.m10 * y + c.m20 * z + c.m30;\r\n c.m31 = c.m01 * x + c.m11 * y + c.m21 * z + c.m31;\r\n c.m32 = c.m02 * x + c.m12 * y + c.m22 * z + c.m32;\r\n c.m33 = c.m03 * x + c.m13 * y + c.m23 * z + c.m33;\r\n return this;\r\n }\r\n\r\n /**\r\n * Pre-multiply a translation to this matrix by translating by the given number of\r\n * units in x, y and z.\r\n *
\r\n * If M
is this
matrix and T
the translation\r\n * matrix, then the new matrix will be T * M
. So when\r\n * transforming a vector v
with the new matrix by using\r\n * T * M * v
, the translation will be applied last!\r\n *
\r\n * In order to set the matrix to a translation transformation without pre-multiplying\r\n * it, use {@link #translation(Vector3f)}.\r\n * \r\n * @see #translation(Vector3f)\r\n * \r\n * @param offset\r\n * the number of units in x, y and z by which to translate\r\n * @return this\r\n */\r\n public Matrix4f translateLocal(Vector3f offset) {\r\n return translateLocal(offset.x, offset.y, offset.z);\r\n }\r\n\r\n /**\r\n * Pre-multiply a translation to this matrix by translating by the given number of\r\n * units in x, y and z and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and T
the translation\r\n * matrix, then the new matrix will be T * M
. So when\r\n * transforming a vector v
with the new matrix by using\r\n * T * M * v
, the translation will be applied last!\r\n *
\r\n * In order to set the matrix to a translation transformation without pre-multiplying\r\n * it, use {@link #translation(Vector3f)}.\r\n * \r\n * @see #translation(Vector3f)\r\n * \r\n * @param offset\r\n * the number of units in x, y and z by which to translate\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f translateLocal(Vector3f offset, Matrix4f dest) {\r\n return translateLocal(offset.x, offset.y, offset.z, dest);\r\n }\r\n\r\n /**\r\n * Pre-multiply a translation to this matrix by translating by the given number of\r\n * units in x, y and z and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and T
the translation\r\n * matrix, then the new matrix will be T * M
. So when\r\n * transforming a vector v
with the new matrix by using\r\n * T * M * v
, the translation will be applied last!\r\n *
\r\n * In order to set the matrix to a translation transformation without pre-multiplying\r\n * it, use {@link #translation(float, float, float)}.\r\n * \r\n * @see #translation(float, float, float)\r\n * \r\n * @param x\r\n * the offset to translate in x\r\n * @param y\r\n * the offset to translate in y\r\n * @param z\r\n * the offset to translate in z\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f translateLocal(float x, float y, float z, Matrix4f dest) {\r\n float nm00 = m00 + x * m03;\r\n float nm01 = m01 + y * m03;\r\n float nm02 = m02 + z * m03;\r\n float nm03 = m03;\r\n float nm10 = m10 + x * m13;\r\n float nm11 = m11 + y * m13;\r\n float nm12 = m12 + z * m13;\r\n float nm13 = m13;\r\n float nm20 = m20 + x * m23;\r\n float nm21 = m21 + y * m23;\r\n float nm22 = m22 + z * m23;\r\n float nm23 = m23;\r\n float nm30 = m30 + x * m33;\r\n float nm31 = m31 + y * m33;\r\n float nm32 = m32 + z * m33;\r\n float nm33 = m33;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Pre-multiply a translation to this matrix by translating by the given number of\r\n * units in x, y and z.\r\n *
\r\n * If M
is this
matrix and T
the translation\r\n * matrix, then the new matrix will be T * M
. So when\r\n * transforming a vector v
with the new matrix by using\r\n * T * M * v
, the translation will be applied last!\r\n *
\r\n * In order to set the matrix to a translation transformation without pre-multiplying\r\n * it, use {@link #translation(float, float, float)}.\r\n * \r\n * @see #translation(float, float, float)\r\n * \r\n * @param x\r\n * the offset to translate in x\r\n * @param y\r\n * the offset to translate in y\r\n * @param z\r\n * the offset to translate in z\r\n * @return this\r\n */\r\n public Matrix4f translateLocal(float x, float y, float z) {\r\n return translateLocal(x, y, z, this);\r\n }\r\n\r\n public void writeExternal(ObjectOutput out) throws IOException {\r\n out.writeFloat(m00);\r\n out.writeFloat(m01);\r\n out.writeFloat(m02);\r\n out.writeFloat(m03);\r\n out.writeFloat(m10);\r\n out.writeFloat(m11);\r\n out.writeFloat(m12);\r\n out.writeFloat(m13);\r\n out.writeFloat(m20);\r\n out.writeFloat(m21);\r\n out.writeFloat(m22);\r\n out.writeFloat(m23);\r\n out.writeFloat(m30);\r\n out.writeFloat(m31);\r\n out.writeFloat(m32);\r\n out.writeFloat(m33);\r\n }\r\n\r\n public void readExternal(ObjectInput in) throws IOException,\r\n ClassNotFoundException {\r\n m00 = in.readFloat();\r\n m01 = in.readFloat();\r\n m02 = in.readFloat();\r\n m03 = in.readFloat();\r\n m10 = in.readFloat();\r\n m11 = in.readFloat();\r\n m12 = in.readFloat();\r\n m13 = in.readFloat();\r\n m20 = in.readFloat();\r\n m21 = in.readFloat();\r\n m22 = in.readFloat();\r\n m23 = in.readFloat();\r\n m30 = in.readFloat();\r\n m31 = in.readFloat();\r\n m32 = in.readFloat();\r\n m33 = in.readFloat();\r\n }\r\n\r\n /**\r\n * Apply an orthographic projection transformation using the given NDC z range to this matrix and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and O
the orthographic projection matrix,\r\n * then the new matrix will be M * O
. So when transforming a\r\n * vector v
with the new matrix by using M * O * v
, the\r\n * orthographic projection transformation will be applied first!\r\n *
\r\n * In order to set the matrix to an orthographic projection without post-multiplying it,\r\n * use {@link #setOrtho(float, float, float, float, float, float, boolean) setOrtho()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setOrtho(float, float, float, float, float, float, boolean)\r\n * \r\n * @param left\r\n * the distance from the center to the left frustum edge\r\n * @param right\r\n * the distance from the center to the right frustum edge\r\n * @param bottom\r\n * the distance from the center to the bottom frustum edge\r\n * @param top\r\n * the distance from the center to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance\r\n * @param zFar\r\n * far clipping plane distance\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f ortho(float left, float right, float bottom, float top, float zNear, float zFar, boolean zZeroToOne, Matrix4f dest) {\r\n // calculate right matrix elements\r\n float rm00 = 2.0f / (right - left);\r\n float rm11 = 2.0f / (top - bottom);\r\n float rm22 = (zZeroToOne ? 1.0f : 2.0f) / (zNear - zFar);\r\n float rm30 = (left + right) / (left - right);\r\n float rm31 = (top + bottom) / (bottom - top);\r\n float rm32 = (zZeroToOne ? zNear : (zFar + zNear)) / (zNear - zFar);\r\n\r\n // perform optimized multiplication\r\n // compute the last column first, because other columns do not depend on it\r\n dest.m30 = m00 * rm30 + m10 * rm31 + m20 * rm32 + m30;\r\n dest.m31 = m01 * rm30 + m11 * rm31 + m21 * rm32 + m31;\r\n dest.m32 = m02 * rm30 + m12 * rm31 + m22 * rm32 + m32;\r\n dest.m33 = m03 * rm30 + m13 * rm31 + m23 * rm32 + m33;\r\n dest.m00 = m00 * rm00;\r\n dest.m01 = m01 * rm00;\r\n dest.m02 = m02 * rm00;\r\n dest.m03 = m03 * rm00;\r\n dest.m10 = m10 * rm11;\r\n dest.m11 = m11 * rm11;\r\n dest.m12 = m12 * rm11;\r\n dest.m13 = m13 * rm11;\r\n dest.m20 = m20 * rm22;\r\n dest.m21 = m21 * rm22;\r\n dest.m22 = m22 * rm22;\r\n dest.m23 = m23 * rm22;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply an orthographic projection transformation using OpenGL's NDC z range of [-1..+1] to this matrix and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and O
the orthographic projection matrix,\r\n * then the new matrix will be M * O
. So when transforming a\r\n * vector v
with the new matrix by using M * O * v
, the\r\n * orthographic projection transformation will be applied first!\r\n *
\r\n * In order to set the matrix to an orthographic projection without post-multiplying it,\r\n * use {@link #setOrtho(float, float, float, float, float, float) setOrtho()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setOrtho(float, float, float, float, float, float)\r\n * \r\n * @param left\r\n * the distance from the center to the left frustum edge\r\n * @param right\r\n * the distance from the center to the right frustum edge\r\n * @param bottom\r\n * the distance from the center to the bottom frustum edge\r\n * @param top\r\n * the distance from the center to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance\r\n * @param zFar\r\n * far clipping plane distance\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f ortho(float left, float right, float bottom, float top, float zNear, float zFar, Matrix4f dest) {\r\n return ortho(left, right, bottom, top, zNear, zFar, false, dest);\r\n }\r\n\r\n /**\r\n * Apply an orthographic projection transformation using the given NDC z range to this matrix.\r\n *
\r\n * If M
is this
matrix and O
the orthographic projection matrix,\r\n * then the new matrix will be M * O
. So when transforming a\r\n * vector v
with the new matrix by using M * O * v
, the\r\n * orthographic projection transformation will be applied first!\r\n *
\r\n * In order to set the matrix to an orthographic projection without post-multiplying it,\r\n * use {@link #setOrtho(float, float, float, float, float, float, boolean) setOrtho()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setOrtho(float, float, float, float, float, float, boolean)\r\n * \r\n * @param left\r\n * the distance from the center to the left frustum edge\r\n * @param right\r\n * the distance from the center to the right frustum edge\r\n * @param bottom\r\n * the distance from the center to the bottom frustum edge\r\n * @param top\r\n * the distance from the center to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance\r\n * @param zFar\r\n * far clipping plane distance\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return this\r\n */\r\n public Matrix4f ortho(float left, float right, float bottom, float top, float zNear, float zFar, boolean zZeroToOne) {\r\n return ortho(left, right, bottom, top, zNear, zFar, zZeroToOne, this);\r\n }\r\n\r\n /**\r\n * Apply an orthographic projection transformation using OpenGL's NDC z range of [-1..+1] to this matrix.\r\n *
\r\n * If M
is this
matrix and O
the orthographic projection matrix,\r\n * then the new matrix will be M * O
. So when transforming a\r\n * vector v
with the new matrix by using M * O * v
, the\r\n * orthographic projection transformation will be applied first!\r\n *
\r\n * In order to set the matrix to an orthographic projection without post-multiplying it,\r\n * use {@link #setOrtho(float, float, float, float, float, float) setOrtho()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setOrtho(float, float, float, float, float, float)\r\n * \r\n * @param left\r\n * the distance from the center to the left frustum edge\r\n * @param right\r\n * the distance from the center to the right frustum edge\r\n * @param bottom\r\n * the distance from the center to the bottom frustum edge\r\n * @param top\r\n * the distance from the center to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance\r\n * @param zFar\r\n * far clipping plane distance\r\n * @return this\r\n */\r\n public Matrix4f ortho(float left, float right, float bottom, float top, float zNear, float zFar) {\r\n return ortho(left, right, bottom, top, zNear, zFar, false);\r\n }\r\n\r\n /**\r\n * Set this matrix to be an orthographic projection transformation using the given NDC z range.\r\n *
\r\n * In order to apply the orthographic projection to an already existing transformation,\r\n * use {@link #ortho(float, float, float, float, float, float, boolean) ortho()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #ortho(float, float, float, float, float, float, boolean)\r\n * \r\n * @param left\r\n * the distance from the center to the left frustum edge\r\n * @param right\r\n * the distance from the center to the right frustum edge\r\n * @param bottom\r\n * the distance from the center to the bottom frustum edge\r\n * @param top\r\n * the distance from the center to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance\r\n * @param zFar\r\n * far clipping plane distance\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return this\r\n */\r\n public Matrix4f setOrtho(float left, float right, float bottom, float top, float zNear, float zFar, boolean zZeroToOne) {\r\n m00 = 2.0f / (right - left);\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = 2.0f / (top - bottom);\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = 0.0f;\r\n m22 = (zZeroToOne ? 1.0f : 2.0f) / (zNear - zFar);\r\n m23 = 0.0f;\r\n m30 = (right + left) / (left - right);\r\n m31 = (top + bottom) / (bottom - top);\r\n m32 = (zZeroToOne ? zNear : (zFar + zNear)) / (zNear - zFar);\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be an orthographic projection transformation using OpenGL's NDC z range of [-1..+1].\r\n *
\r\n * In order to apply the orthographic projection to an already existing transformation,\r\n * use {@link #ortho(float, float, float, float, float, float) ortho()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #ortho(float, float, float, float, float, float)\r\n * \r\n * @param left\r\n * the distance from the center to the left frustum edge\r\n * @param right\r\n * the distance from the center to the right frustum edge\r\n * @param bottom\r\n * the distance from the center to the bottom frustum edge\r\n * @param top\r\n * the distance from the center to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance\r\n * @param zFar\r\n * far clipping plane distance\r\n * @return this\r\n */\r\n public Matrix4f setOrtho(float left, float right, float bottom, float top, float zNear, float zFar) {\r\n return setOrtho(left, right, bottom, top, zNear, zFar, false);\r\n }\r\n\r\n /**\r\n * Apply a symmetric orthographic projection transformation using the given NDC z range to this matrix and store the result in dest
.\r\n *
\r\n * This method is equivalent to calling {@link #ortho(float, float, float, float, float, float, boolean, Matrix4f) ortho()} with\r\n * left=-width/2
, right=+width/2
, bottom=-height/2
and top=+height/2
.\r\n *
\r\n * If M
is this
matrix and O
the orthographic projection matrix,\r\n * then the new matrix will be M * O
. So when transforming a\r\n * vector v
with the new matrix by using M * O * v
, the\r\n * orthographic projection transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a symmetric orthographic projection without post-multiplying it,\r\n * use {@link #setOrthoSymmetric(float, float, float, float, boolean) setOrthoSymmetric()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setOrthoSymmetric(float, float, float, float, boolean)\r\n * \r\n * @param width\r\n * the distance between the right and left frustum edges\r\n * @param height\r\n * the distance between the top and bottom frustum edges\r\n * @param zNear\r\n * near clipping plane distance\r\n * @param zFar\r\n * far clipping plane distance\r\n * @param dest\r\n * will hold the result\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return dest\r\n */\r\n public Matrix4f orthoSymmetric(float width, float height, float zNear, float zFar, boolean zZeroToOne, Matrix4f dest) {\r\n // calculate right matrix elements\r\n float rm00 = 2.0f / width;\r\n float rm11 = 2.0f / height;\r\n float rm22 = (zZeroToOne ? 1.0f : 2.0f) / (zNear - zFar);\r\n float rm32 = (zZeroToOne ? zNear : (zFar + zNear)) / (zNear - zFar);\r\n\r\n // perform optimized multiplication\r\n // compute the last column first, because other columns do not depend on it\r\n dest.m30 = m20 * rm32 + m30;\r\n dest.m31 = m21 * rm32 + m31;\r\n dest.m32 = m22 * rm32 + m32;\r\n dest.m33 = m23 * rm32 + m33;\r\n dest.m00 = m00 * rm00;\r\n dest.m01 = m01 * rm00;\r\n dest.m02 = m02 * rm00;\r\n dest.m03 = m03 * rm00;\r\n dest.m10 = m10 * rm11;\r\n dest.m11 = m11 * rm11;\r\n dest.m12 = m12 * rm11;\r\n dest.m13 = m13 * rm11;\r\n dest.m20 = m20 * rm22;\r\n dest.m21 = m21 * rm22;\r\n dest.m22 = m22 * rm22;\r\n dest.m23 = m23 * rm22;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply a symmetric orthographic projection transformation using OpenGL's NDC z range of [-1..+1] to this matrix and store the result in dest
.\r\n *
\r\n * This method is equivalent to calling {@link #ortho(float, float, float, float, float, float, Matrix4f) ortho()} with\r\n * left=-width/2
, right=+width/2
, bottom=-height/2
and top=+height/2
.\r\n *
\r\n * If M
is this
matrix and O
the orthographic projection matrix,\r\n * then the new matrix will be M * O
. So when transforming a\r\n * vector v
with the new matrix by using M * O * v
, the\r\n * orthographic projection transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a symmetric orthographic projection without post-multiplying it,\r\n * use {@link #setOrthoSymmetric(float, float, float, float) setOrthoSymmetric()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setOrthoSymmetric(float, float, float, float)\r\n * \r\n * @param width\r\n * the distance between the right and left frustum edges\r\n * @param height\r\n * the distance between the top and bottom frustum edges\r\n * @param zNear\r\n * near clipping plane distance\r\n * @param zFar\r\n * far clipping plane distance\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f orthoSymmetric(float width, float height, float zNear, float zFar, Matrix4f dest) {\r\n return orthoSymmetric(width, height, zNear, zFar, false, dest);\r\n }\r\n\r\n /**\r\n * Apply a symmetric orthographic projection transformation using the given NDC z range to this matrix.\r\n *
\r\n * This method is equivalent to calling {@link #ortho(float, float, float, float, float, float, boolean) ortho()} with\r\n * left=-width/2
, right=+width/2
, bottom=-height/2
and top=+height/2
.\r\n *
\r\n * If M
is this
matrix and O
the orthographic projection matrix,\r\n * then the new matrix will be M * O
. So when transforming a\r\n * vector v
with the new matrix by using M * O * v
, the\r\n * orthographic projection transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a symmetric orthographic projection without post-multiplying it,\r\n * use {@link #setOrthoSymmetric(float, float, float, float, boolean) setOrthoSymmetric()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setOrthoSymmetric(float, float, float, float, boolean)\r\n * \r\n * @param width\r\n * the distance between the right and left frustum edges\r\n * @param height\r\n * the distance between the top and bottom frustum edges\r\n * @param zNear\r\n * near clipping plane distance\r\n * @param zFar\r\n * far clipping plane distance\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return this\r\n */\r\n public Matrix4f orthoSymmetric(float width, float height, float zNear, float zFar, boolean zZeroToOne) {\r\n return orthoSymmetric(width, height, zNear, zFar, zZeroToOne, this);\r\n }\r\n\r\n /**\r\n * Apply a symmetric orthographic projection transformation using OpenGL's NDC z range of [-1..+1] to this matrix.\r\n *
\r\n * This method is equivalent to calling {@link #ortho(float, float, float, float, float, float) ortho()} with\r\n * left=-width/2
, right=+width/2
, bottom=-height/2
and top=+height/2
.\r\n *
\r\n * If M
is this
matrix and O
the orthographic projection matrix,\r\n * then the new matrix will be M * O
. So when transforming a\r\n * vector v
with the new matrix by using M * O * v
, the\r\n * orthographic projection transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a symmetric orthographic projection without post-multiplying it,\r\n * use {@link #setOrthoSymmetric(float, float, float, float) setOrthoSymmetric()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setOrthoSymmetric(float, float, float, float)\r\n * \r\n * @param width\r\n * the distance between the right and left frustum edges\r\n * @param height\r\n * the distance between the top and bottom frustum edges\r\n * @param zNear\r\n * near clipping plane distance\r\n * @param zFar\r\n * far clipping plane distance\r\n * @return this\r\n */\r\n public Matrix4f orthoSymmetric(float width, float height, float zNear, float zFar) {\r\n return orthoSymmetric(width, height, zNear, zFar, false, this);\r\n }\r\n\r\n /**\r\n * Set this matrix to be a symmetric orthographic projection transformation using the given NDC z range.\r\n *
\r\n * This method is equivalent to calling {@link #setOrtho(float, float, float, float, float, float, boolean) setOrtho()} with\r\n * left=-width/2
, right=+width/2
, bottom=-height/2
and top=+height/2
.\r\n *
\r\n * In order to apply the symmetric orthographic projection to an already existing transformation,\r\n * use {@link #orthoSymmetric(float, float, float, float, boolean) orthoSymmetric()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #orthoSymmetric(float, float, float, float, boolean)\r\n * \r\n * @param width\r\n * the distance between the right and left frustum edges\r\n * @param height\r\n * the distance between the top and bottom frustum edges\r\n * @param zNear\r\n * near clipping plane distance\r\n * @param zFar\r\n * far clipping plane distance\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return this\r\n */\r\n public Matrix4f setOrthoSymmetric(float width, float height, float zNear, float zFar, boolean zZeroToOne) {\r\n m00 = 2.0f / width;\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = 2.0f / height;\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = 0.0f;\r\n m22 = (zZeroToOne ? 1.0f : 2.0f) / (zNear - zFar);\r\n m23 = 0.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = (zZeroToOne ? zNear : (zFar + zNear)) / (zNear - zFar);\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be a symmetric orthographic projection transformation using OpenGL's NDC z range of [-1..+1].\r\n *
\r\n * This method is equivalent to calling {@link #setOrtho(float, float, float, float, float, float) setOrtho()} with\r\n * left=-width/2
, right=+width/2
, bottom=-height/2
and top=+height/2
.\r\n *
\r\n * In order to apply the symmetric orthographic projection to an already existing transformation,\r\n * use {@link #orthoSymmetric(float, float, float, float) orthoSymmetric()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #orthoSymmetric(float, float, float, float)\r\n * \r\n * @param width\r\n * the distance between the right and left frustum edges\r\n * @param height\r\n * the distance between the top and bottom frustum edges\r\n * @param zNear\r\n * near clipping plane distance\r\n * @param zFar\r\n * far clipping plane distance\r\n * @return this\r\n */\r\n public Matrix4f setOrthoSymmetric(float width, float height, float zNear, float zFar) {\r\n return setOrthoSymmetric(width, height, zNear, zFar, false);\r\n }\r\n\r\n /**\r\n * Apply an orthographic projection transformation to this matrix and store the result in dest
.\r\n *
\r\n * This method is equivalent to calling {@link #ortho(float, float, float, float, float, float, Matrix4f) ortho()} with\r\n * zNear=-1
and zFar=+1
.\r\n *
\r\n * If M
is this
matrix and O
the orthographic projection matrix,\r\n * then the new matrix will be M * O
. So when transforming a\r\n * vector v
with the new matrix by using M * O * v
, the\r\n * orthographic projection transformation will be applied first!\r\n *
\r\n * In order to set the matrix to an orthographic projection without post-multiplying it,\r\n * use {@link #setOrtho2D(float, float, float, float) setOrtho()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #ortho(float, float, float, float, float, float, Matrix4f)\r\n * @see #setOrtho2D(float, float, float, float)\r\n * \r\n * @param left\r\n * the distance from the center to the left frustum edge\r\n * @param right\r\n * the distance from the center to the right frustum edge\r\n * @param bottom\r\n * the distance from the center to the bottom frustum edge\r\n * @param top\r\n * the distance from the center to the top frustum edge\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f ortho2D(float left, float right, float bottom, float top, Matrix4f dest) {\r\n // calculate right matrix elements\r\n float rm00 = 2.0f / (right - left);\r\n float rm11 = 2.0f / (top - bottom);\r\n float rm30 = -(right + left) / (right - left);\r\n float rm31 = -(top + bottom) / (top - bottom);\r\n\r\n // perform optimized multiplication\r\n // compute the last column first, because other columns do not depend on it\r\n dest.m30 = m00 * rm30 + m10 * rm31 + m30;\r\n dest.m31 = m01 * rm30 + m11 * rm31 + m31;\r\n dest.m32 = m02 * rm30 + m12 * rm31 + m32;\r\n dest.m33 = m03 * rm30 + m13 * rm31 + m33;\r\n dest.m00 = m00 * rm00;\r\n dest.m01 = m01 * rm00;\r\n dest.m02 = m02 * rm00;\r\n dest.m03 = m03 * rm00;\r\n dest.m10 = m10 * rm11;\r\n dest.m11 = m11 * rm11;\r\n dest.m12 = m12 * rm11;\r\n dest.m13 = m13 * rm11;\r\n dest.m20 = -m20;\r\n dest.m21 = -m21;\r\n dest.m22 = -m22;\r\n dest.m23 = -m23;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply an orthographic projection transformation to this matrix.\r\n *
\r\n * This method is equivalent to calling {@link #ortho(float, float, float, float, float, float) ortho()} with\r\n * zNear=-1
and zFar=+1
.\r\n *
\r\n * If M
is this
matrix and O
the orthographic projection matrix,\r\n * then the new matrix will be M * O
. So when transforming a\r\n * vector v
with the new matrix by using M * O * v
, the\r\n * orthographic projection transformation will be applied first!\r\n *
\r\n * In order to set the matrix to an orthographic projection without post-multiplying it,\r\n * use {@link #setOrtho2D(float, float, float, float) setOrtho2D()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #ortho(float, float, float, float, float, float)\r\n * @see #setOrtho2D(float, float, float, float)\r\n * \r\n * @param left\r\n * the distance from the center to the left frustum edge\r\n * @param right\r\n * the distance from the center to the right frustum edge\r\n * @param bottom\r\n * the distance from the center to the bottom frustum edge\r\n * @param top\r\n * the distance from the center to the top frustum edge\r\n * @return this\r\n */\r\n public Matrix4f ortho2D(float left, float right, float bottom, float top) {\r\n return ortho2D(left, right, bottom, top, this);\r\n }\r\n\r\n /**\r\n * Set this matrix to be an orthographic projection transformation.\r\n *
\r\n * This method is equivalent to calling {@link #setOrtho(float, float, float, float, float, float) setOrtho()} with\r\n * zNear=-1
and zFar=+1
.\r\n *
\r\n * In order to apply the orthographic projection to an already existing transformation,\r\n * use {@link #ortho2D(float, float, float, float) ortho2D()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setOrtho(float, float, float, float, float, float)\r\n * @see #ortho2D(float, float, float, float)\r\n * \r\n * @param left\r\n * the distance from the center to the left frustum edge\r\n * @param right\r\n * the distance from the center to the right frustum edge\r\n * @param bottom\r\n * the distance from the center to the bottom frustum edge\r\n * @param top\r\n * the distance from the center to the top frustum edge\r\n * @return this\r\n */\r\n public Matrix4f setOrtho2D(float left, float right, float bottom, float top) {\r\n m00 = 2.0f / (right - left);\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = 2.0f / (top - bottom);\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = 0.0f;\r\n m22 = -1.0f;\r\n m23 = 0.0f;\r\n m30 = -(right + left) / (right - left);\r\n m31 = -(top + bottom) / (top - bottom);\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Apply a rotation transformation to this matrix to make -z
point along dir
. \r\n *
\r\n * If M
is this
matrix and L
the lookalong rotation matrix,\r\n * then the new matrix will be M * L
. So when transforming a\r\n * vector v
with the new matrix by using M * L * v
, the\r\n * lookalong rotation transformation will be applied first!\r\n *
\r\n * This is equivalent to calling\r\n * {@link #lookAt(Vector3f, Vector3f, Vector3f) lookAt}\r\n * with eye = (0, 0, 0)
and center = dir
.\r\n *
\r\n * In order to set the matrix to a lookalong transformation without post-multiplying it,\r\n * use {@link #setLookAlong(Vector3f, Vector3f) setLookAlong()}.\r\n * \r\n * @see #lookAlong(float, float, float, float, float, float)\r\n * @see #lookAt(Vector3f, Vector3f, Vector3f)\r\n * @see #setLookAlong(Vector3f, Vector3f)\r\n * \r\n * @param dir\r\n * the direction in space to look along\r\n * @param up\r\n * the direction of 'up'\r\n * @return this\r\n */\r\n public Matrix4f lookAlong(Vector3f dir, Vector3f up) {\r\n return lookAlong(dir.x, dir.y, dir.z, up.x, up.y, up.z, this);\r\n }\r\n\r\n /**\r\n * Apply a rotation transformation to this matrix to make -z
point along dir
\r\n * and store the result in dest
. \r\n *
\r\n * If M
is this
matrix and L
the lookalong rotation matrix,\r\n * then the new matrix will be M * L
. So when transforming a\r\n * vector v
with the new matrix by using M * L * v
, the\r\n * lookalong rotation transformation will be applied first!\r\n *
\r\n * This is equivalent to calling\r\n * {@link #lookAt(Vector3f, Vector3f, Vector3f) lookAt}\r\n * with eye = (0, 0, 0)
and center = dir
.\r\n *
\r\n * In order to set the matrix to a lookalong transformation without post-multiplying it,\r\n * use {@link #setLookAlong(Vector3f, Vector3f) setLookAlong()}.\r\n * \r\n * @see #lookAlong(float, float, float, float, float, float)\r\n * @see #lookAt(Vector3f, Vector3f, Vector3f)\r\n * @see #setLookAlong(Vector3f, Vector3f)\r\n * \r\n * @param dir\r\n * the direction in space to look along\r\n * @param up\r\n * the direction of 'up'\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f lookAlong(Vector3f dir, Vector3f up, Matrix4f dest) {\r\n return lookAlong(dir.x, dir.y, dir.z, up.x, up.y, up.z, dest);\r\n }\r\n\r\n /**\r\n * Apply a rotation transformation to this matrix to make -z
point along dir
\r\n * and store the result in dest
. \r\n *
\r\n * If M
is this
matrix and L
the lookalong rotation matrix,\r\n * then the new matrix will be M * L
. So when transforming a\r\n * vector v
with the new matrix by using M * L * v
, the\r\n * lookalong rotation transformation will be applied first!\r\n *
\r\n * This is equivalent to calling\r\n * {@link #lookAt(float, float, float, float, float, float, float, float, float) lookAt()}\r\n * with eye = (0, 0, 0)
and center = dir
.\r\n *
\r\n * In order to set the matrix to a lookalong transformation without post-multiplying it,\r\n * use {@link #setLookAlong(float, float, float, float, float, float) setLookAlong()}\r\n * \r\n * @see #lookAt(float, float, float, float, float, float, float, float, float)\r\n * @see #setLookAlong(float, float, float, float, float, float)\r\n * \r\n * @param dirX\r\n * the x-coordinate of the direction to look along\r\n * @param dirY\r\n * the y-coordinate of the direction to look along\r\n * @param dirZ\r\n * the z-coordinate of the direction to look along\r\n * @param upX\r\n * the x-coordinate of the up vector\r\n * @param upY\r\n * the y-coordinate of the up vector\r\n * @param upZ\r\n * the z-coordinate of the up vector\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f lookAlong(float dirX, float dirY, float dirZ,\r\n float upX, float upY, float upZ, Matrix4f dest) {\r\n // Normalize direction\r\n float invDirLength = 1.0f / (float) Math.sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);\r\n float dirnX = dirX * invDirLength;\r\n float dirnY = dirY * invDirLength;\r\n float dirnZ = dirZ * invDirLength;\r\n // right = direction x up\r\n float rightX, rightY, rightZ;\r\n rightX = dirnY * upZ - dirnZ * upY;\r\n rightY = dirnZ * upX - dirnX * upZ;\r\n rightZ = dirnX * upY - dirnY * upX;\r\n // normalize right\r\n float invRightLength = 1.0f / (float) Math.sqrt(rightX * rightX + rightY * rightY + rightZ * rightZ);\r\n rightX *= invRightLength;\r\n rightY *= invRightLength;\r\n rightZ *= invRightLength;\r\n // up = right x direction\r\n float upnX = rightY * dirnZ - rightZ * dirnY;\r\n float upnY = rightZ * dirnX - rightX * dirnZ;\r\n float upnZ = rightX * dirnY - rightY * dirnX;\r\n\r\n // calculate right matrix elements\r\n float rm00 = rightX;\r\n float rm01 = upnX;\r\n float rm02 = -dirnX;\r\n float rm10 = rightY;\r\n float rm11 = upnY;\r\n float rm12 = -dirnY;\r\n float rm20 = rightZ;\r\n float rm21 = upnZ;\r\n float rm22 = -dirnZ;\r\n\r\n // perform optimized matrix multiplication\r\n // introduce temporaries for dependent results\r\n float nm00 = m00 * rm00 + m10 * rm01 + m20 * rm02;\r\n float nm01 = m01 * rm00 + m11 * rm01 + m21 * rm02;\r\n float nm02 = m02 * rm00 + m12 * rm01 + m22 * rm02;\r\n float nm03 = m03 * rm00 + m13 * rm01 + m23 * rm02;\r\n float nm10 = m00 * rm10 + m10 * rm11 + m20 * rm12;\r\n float nm11 = m01 * rm10 + m11 * rm11 + m21 * rm12;\r\n float nm12 = m02 * rm10 + m12 * rm11 + m22 * rm12;\r\n float nm13 = m03 * rm10 + m13 * rm11 + m23 * rm12;\r\n dest.m20 = m00 * rm20 + m10 * rm21 + m20 * rm22;\r\n dest.m21 = m01 * rm20 + m11 * rm21 + m21 * rm22;\r\n dest.m22 = m02 * rm20 + m12 * rm21 + m22 * rm22;\r\n dest.m23 = m03 * rm20 + m13 * rm21 + m23 * rm22;\r\n // set the rest of the matrix elements\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply a rotation transformation to this matrix to make -z
point along dir
. \r\n *
\r\n * If M
is this
matrix and L
the lookalong rotation matrix,\r\n * then the new matrix will be M * L
. So when transforming a\r\n * vector v
with the new matrix by using M * L * v
, the\r\n * lookalong rotation transformation will be applied first!\r\n *
\r\n * This is equivalent to calling\r\n * {@link #lookAt(float, float, float, float, float, float, float, float, float) lookAt()}\r\n * with eye = (0, 0, 0)
and center = dir
.\r\n *
\r\n * In order to set the matrix to a lookalong transformation without post-multiplying it,\r\n * use {@link #setLookAlong(float, float, float, float, float, float) setLookAlong()}\r\n * \r\n * @see #lookAt(float, float, float, float, float, float, float, float, float)\r\n * @see #setLookAlong(float, float, float, float, float, float)\r\n * \r\n * @param dirX\r\n * the x-coordinate of the direction to look along\r\n * @param dirY\r\n * the y-coordinate of the direction to look along\r\n * @param dirZ\r\n * the z-coordinate of the direction to look along\r\n * @param upX\r\n * the x-coordinate of the up vector\r\n * @param upY\r\n * the y-coordinate of the up vector\r\n * @param upZ\r\n * the z-coordinate of the up vector\r\n * @return this\r\n */\r\n public Matrix4f lookAlong(float dirX, float dirY, float dirZ,\r\n float upX, float upY, float upZ) {\r\n return lookAlong(dirX, dirY, dirZ, upX, upY, upZ, this);\r\n }\r\n\r\n /**\r\n * Set this matrix to a rotation transformation to make -z
\r\n * point along dir
.\r\n *
\r\n * This is equivalent to calling\r\n * {@link #setLookAt(Vector3f, Vector3f, Vector3f) setLookAt()} \r\n * with eye = (0, 0, 0)
and center = dir
.\r\n *
\r\n * In order to apply the lookalong transformation to any previous existing transformation,\r\n * use {@link #lookAlong(Vector3f, Vector3f)}.\r\n * \r\n * @see #setLookAlong(Vector3f, Vector3f)\r\n * @see #lookAlong(Vector3f, Vector3f)\r\n * \r\n * @param dir\r\n * the direction in space to look along\r\n * @param up\r\n * the direction of 'up'\r\n * @return this\r\n */\r\n public Matrix4f setLookAlong(Vector3f dir, Vector3f up) {\r\n return setLookAlong(dir.x, dir.y, dir.z, up.x, up.y, up.z);\r\n }\r\n\r\n /**\r\n * Set this matrix to a rotation transformation to make -z
\r\n * point along dir
.\r\n *
\r\n * This is equivalent to calling\r\n * {@link #setLookAt(float, float, float, float, float, float, float, float, float)\r\n * setLookAt()} with eye = (0, 0, 0)
and center = dir
.\r\n *
\r\n * In order to apply the lookalong transformation to any previous existing transformation,\r\n * use {@link #lookAlong(float, float, float, float, float, float) lookAlong()}\r\n * \r\n * @see #setLookAlong(float, float, float, float, float, float)\r\n * @see #lookAlong(float, float, float, float, float, float)\r\n * \r\n * @param dirX\r\n * the x-coordinate of the direction to look along\r\n * @param dirY\r\n * the y-coordinate of the direction to look along\r\n * @param dirZ\r\n * the z-coordinate of the direction to look along\r\n * @param upX\r\n * the x-coordinate of the up vector\r\n * @param upY\r\n * the y-coordinate of the up vector\r\n * @param upZ\r\n * the z-coordinate of the up vector\r\n * @return this\r\n */\r\n public Matrix4f setLookAlong(float dirX, float dirY, float dirZ,\r\n float upX, float upY, float upZ) {\r\n // Normalize direction\r\n float invDirLength = 1.0f / (float) Math.sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);\r\n float dirnX = dirX * invDirLength;\r\n float dirnY = dirY * invDirLength;\r\n float dirnZ = dirZ * invDirLength;\r\n // right = direction x up\r\n float rightX, rightY, rightZ;\r\n rightX = dirnY * upZ - dirnZ * upY;\r\n rightY = dirnZ * upX - dirnX * upZ;\r\n rightZ = dirnX * upY - dirnY * upX;\r\n // normalize right\r\n float invRightLength = 1.0f / (float) Math.sqrt(rightX * rightX + rightY * rightY + rightZ * rightZ);\r\n rightX *= invRightLength;\r\n rightY *= invRightLength;\r\n rightZ *= invRightLength;\r\n // up = right x direction\r\n float upnX = rightY * dirnZ - rightZ * dirnY;\r\n float upnY = rightZ * dirnX - rightX * dirnZ;\r\n float upnZ = rightX * dirnY - rightY * dirnX;\r\n\r\n m00 = rightX;\r\n m01 = upnX;\r\n m02 = -dirnX;\r\n m03 = 0.0f;\r\n m10 = rightY;\r\n m11 = upnY;\r\n m12 = -dirnY;\r\n m13 = 0.0f;\r\n m20 = rightZ;\r\n m21 = upnZ;\r\n m22 = -dirnZ;\r\n m23 = 0.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m32 = 0.0f;\r\n m33 = 1.0f;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be a \"lookat\" transformation for a right-handed coordinate system, that aligns\r\n * -z
with center - eye
.\r\n *
\r\n * In order to not make use of vectors to specify eye
, center
and up
but use primitives,\r\n * like in the GLU function, use {@link #setLookAt(float, float, float, float, float, float, float, float, float) setLookAt()}\r\n * instead.\r\n *
\r\n * In order to apply the lookat transformation to a previous existing transformation,\r\n * use {@link #lookAt(Vector3f, Vector3f, Vector3f) lookAt()}.\r\n * \r\n * @see #setLookAt(float, float, float, float, float, float, float, float, float)\r\n * @see #lookAt(Vector3f, Vector3f, Vector3f)\r\n * \r\n * @param eye\r\n * the position of the camera\r\n * @param center\r\n * the point in space to look at\r\n * @param up\r\n * the direction of 'up'\r\n * @return this\r\n */\r\n public Matrix4f setLookAt(Vector3f eye, Vector3f center, Vector3f up) {\r\n return setLookAt(eye.x, eye.y, eye.z, center.x, center.y, center.z, up.x, up.y, up.z);\r\n }\r\n\r\n /**\r\n * Set this matrix to be a \"lookat\" transformation for a right-handed coordinate system, \r\n * that aligns -z
with center - eye
.\r\n *
\r\n * In order to apply the lookat transformation to a previous existing transformation,\r\n * use {@link #lookAt(float, float, float, float, float, float, float, float, float) lookAt}.\r\n * \r\n * @see #setLookAt(Vector3f, Vector3f, Vector3f)\r\n * @see #lookAt(float, float, float, float, float, float, float, float, float)\r\n * \r\n * @param eyeX\r\n * the x-coordinate of the eye/camera location\r\n * @param eyeY\r\n * the y-coordinate of the eye/camera location\r\n * @param eyeZ\r\n * the z-coordinate of the eye/camera location\r\n * @param centerX\r\n * the x-coordinate of the point to look at\r\n * @param centerY\r\n * the y-coordinate of the point to look at\r\n * @param centerZ\r\n * the z-coordinate of the point to look at\r\n * @param upX\r\n * the x-coordinate of the up vector\r\n * @param upY\r\n * the y-coordinate of the up vector\r\n * @param upZ\r\n * the z-coordinate of the up vector\r\n * @return this\r\n */\r\n public Matrix4f setLookAt(float eyeX, float eyeY, float eyeZ,\r\n float centerX, float centerY, float centerZ,\r\n float upX, float upY, float upZ) {\r\n // Compute direction from position to lookAt\r\n float dirX, dirY, dirZ;\r\n dirX = eyeX - centerX;\r\n dirY = eyeY - centerY;\r\n dirZ = eyeZ - centerZ;\r\n // Normalize direction\r\n float invDirLength = 1.0f / (float) Math.sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);\r\n dirX *= invDirLength;\r\n dirY *= invDirLength;\r\n dirZ *= invDirLength;\r\n // left = up x direction\r\n float leftX, leftY, leftZ;\r\n leftX = upY * dirZ - upZ * dirY;\r\n leftY = upZ * dirX - upX * dirZ;\r\n leftZ = upX * dirY - upY * dirX;\r\n // normalize left\r\n float invLeftLength = 1.0f / (float) Math.sqrt(leftX * leftX + leftY * leftY + leftZ * leftZ);\r\n leftX *= invLeftLength;\r\n leftY *= invLeftLength;\r\n leftZ *= invLeftLength;\r\n // up = direction x left\r\n float upnX = dirY * leftZ - dirZ * leftY;\r\n float upnY = dirZ * leftX - dirX * leftZ;\r\n float upnZ = dirX * leftY - dirY * leftX;\r\n\r\n m00 = leftX;\r\n m01 = upnX;\r\n m02 = dirX;\r\n m03 = 0.0f;\r\n m10 = leftY;\r\n m11 = upnY;\r\n m12 = dirY;\r\n m13 = 0.0f;\r\n m20 = leftZ;\r\n m21 = upnZ;\r\n m22 = dirZ;\r\n m23 = 0.0f;\r\n m30 = -(leftX * eyeX + leftY * eyeY + leftZ * eyeZ);\r\n m31 = -(upnX * eyeX + upnY * eyeY + upnZ * eyeZ);\r\n m32 = -(dirX * eyeX + dirY * eyeY + dirZ * eyeZ);\r\n m33 = 1.0f;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Apply a \"lookat\" transformation to this matrix for a right-handed coordinate system, \r\n * that aligns -z
with center - eye
and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and L
the lookat matrix,\r\n * then the new matrix will be M * L
. So when transforming a\r\n * vector v
with the new matrix by using M * L * v
,\r\n * the lookat transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a lookat transformation without post-multiplying it,\r\n * use {@link #setLookAt(Vector3f, Vector3f, Vector3f)}.\r\n * \r\n * @see #lookAt(float, float, float, float, float, float, float, float, float)\r\n * @see #setLookAlong(Vector3f, Vector3f)\r\n * \r\n * @param eye\r\n * the position of the camera\r\n * @param center\r\n * the point in space to look at\r\n * @param up\r\n * the direction of 'up'\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f lookAt(Vector3f eye, Vector3f center, Vector3f up, Matrix4f dest) {\r\n return lookAt(eye.x, eye.y, eye.z, center.x, center.y, center.z, up.x, up.y, up.z, dest);\r\n }\r\n\r\n /**\r\n * Apply a \"lookat\" transformation to this matrix for a right-handed coordinate system, \r\n * that aligns -z
with center - eye
.\r\n *
\r\n * If M
is this
matrix and L
the lookat matrix,\r\n * then the new matrix will be M * L
. So when transforming a\r\n * vector v
with the new matrix by using M * L * v
,\r\n * the lookat transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a lookat transformation without post-multiplying it,\r\n * use {@link #setLookAt(Vector3f, Vector3f, Vector3f)}.\r\n * \r\n * @see #lookAt(float, float, float, float, float, float, float, float, float)\r\n * @see #setLookAlong(Vector3f, Vector3f)\r\n * \r\n * @param eye\r\n * the position of the camera\r\n * @param center\r\n * the point in space to look at\r\n * @param up\r\n * the direction of 'up'\r\n * @return this\r\n */\r\n public Matrix4f lookAt(Vector3f eye, Vector3f center, Vector3f up) {\r\n return lookAt(eye.x, eye.y, eye.z, center.x, center.y, center.z, up.x, up.y, up.z, this);\r\n }\r\n\r\n /**\r\n * Apply a \"lookat\" transformation to this matrix for a right-handed coordinate system, \r\n * that aligns -z
with center - eye
and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and L
the lookat matrix,\r\n * then the new matrix will be M * L
. So when transforming a\r\n * vector v
with the new matrix by using M * L * v
,\r\n * the lookat transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a lookat transformation without post-multiplying it,\r\n * use {@link #setLookAt(float, float, float, float, float, float, float, float, float) setLookAt()}.\r\n * \r\n * @see #lookAt(Vector3f, Vector3f, Vector3f)\r\n * @see #setLookAt(float, float, float, float, float, float, float, float, float)\r\n * \r\n * @param eyeX\r\n * the x-coordinate of the eye/camera location\r\n * @param eyeY\r\n * the y-coordinate of the eye/camera location\r\n * @param eyeZ\r\n * the z-coordinate of the eye/camera location\r\n * @param centerX\r\n * the x-coordinate of the point to look at\r\n * @param centerY\r\n * the y-coordinate of the point to look at\r\n * @param centerZ\r\n * the z-coordinate of the point to look at\r\n * @param upX\r\n * the x-coordinate of the up vector\r\n * @param upY\r\n * the y-coordinate of the up vector\r\n * @param upZ\r\n * the z-coordinate of the up vector\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f lookAt(float eyeX, float eyeY, float eyeZ,\r\n float centerX, float centerY, float centerZ,\r\n float upX, float upY, float upZ, Matrix4f dest) {\r\n // Compute direction from position to lookAt\r\n float dirX, dirY, dirZ;\r\n dirX = eyeX - centerX;\r\n dirY = eyeY - centerY;\r\n dirZ = eyeZ - centerZ;\r\n // Normalize direction\r\n float invDirLength = 1.0f / (float) Math.sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);\r\n dirX *= invDirLength;\r\n dirY *= invDirLength;\r\n dirZ *= invDirLength;\r\n // left = up x direction\r\n float leftX, leftY, leftZ;\r\n leftX = upY * dirZ - upZ * dirY;\r\n leftY = upZ * dirX - upX * dirZ;\r\n leftZ = upX * dirY - upY * dirX;\r\n // normalize left\r\n float invLeftLength = 1.0f / (float) Math.sqrt(leftX * leftX + leftY * leftY + leftZ * leftZ);\r\n leftX *= invLeftLength;\r\n leftY *= invLeftLength;\r\n leftZ *= invLeftLength;\r\n // up = direction x left\r\n float upnX = dirY * leftZ - dirZ * leftY;\r\n float upnY = dirZ * leftX - dirX * leftZ;\r\n float upnZ = dirX * leftY - dirY * leftX;\r\n\r\n // calculate right matrix elements\r\n float rm00 = leftX;\r\n float rm01 = upnX;\r\n float rm02 = dirX;\r\n float rm10 = leftY;\r\n float rm11 = upnY;\r\n float rm12 = dirY;\r\n float rm20 = leftZ;\r\n float rm21 = upnZ;\r\n float rm22 = dirZ;\r\n float rm30 = -(leftX * eyeX + leftY * eyeY + leftZ * eyeZ);\r\n float rm31 = -(upnX * eyeX + upnY * eyeY + upnZ * eyeZ);\r\n float rm32 = -(dirX * eyeX + dirY * eyeY + dirZ * eyeZ);\r\n\r\n // perform optimized matrix multiplication\r\n // compute last column first, because others do not depend on it\r\n dest.m30 = m00 * rm30 + m10 * rm31 + m20 * rm32 + m30;\r\n dest.m31 = m01 * rm30 + m11 * rm31 + m21 * rm32 + m31;\r\n dest.m32 = m02 * rm30 + m12 * rm31 + m22 * rm32 + m32;\r\n dest.m33 = m03 * rm30 + m13 * rm31 + m23 * rm32 + m33;\r\n // introduce temporaries for dependent results\r\n float nm00 = m00 * rm00 + m10 * rm01 + m20 * rm02;\r\n float nm01 = m01 * rm00 + m11 * rm01 + m21 * rm02;\r\n float nm02 = m02 * rm00 + m12 * rm01 + m22 * rm02;\r\n float nm03 = m03 * rm00 + m13 * rm01 + m23 * rm02;\r\n float nm10 = m00 * rm10 + m10 * rm11 + m20 * rm12;\r\n float nm11 = m01 * rm10 + m11 * rm11 + m21 * rm12;\r\n float nm12 = m02 * rm10 + m12 * rm11 + m22 * rm12;\r\n float nm13 = m03 * rm10 + m13 * rm11 + m23 * rm12;\r\n dest.m20 = m00 * rm20 + m10 * rm21 + m20 * rm22;\r\n dest.m21 = m01 * rm20 + m11 * rm21 + m21 * rm22;\r\n dest.m22 = m02 * rm20 + m12 * rm21 + m22 * rm22;\r\n dest.m23 = m03 * rm20 + m13 * rm21 + m23 * rm22;\r\n // set the rest of the matrix elements\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply a \"lookat\" transformation to this matrix for a right-handed coordinate system, \r\n * that aligns -z
with center - eye
.\r\n *
\r\n * If M
is this
matrix and L
the lookat matrix,\r\n * then the new matrix will be M * L
. So when transforming a\r\n * vector v
with the new matrix by using M * L * v
,\r\n * the lookat transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a lookat transformation without post-multiplying it,\r\n * use {@link #setLookAt(float, float, float, float, float, float, float, float, float) setLookAt()}.\r\n * \r\n * @see #lookAt(Vector3f, Vector3f, Vector3f)\r\n * @see #setLookAt(float, float, float, float, float, float, float, float, float)\r\n * \r\n * @param eyeX\r\n * the x-coordinate of the eye/camera location\r\n * @param eyeY\r\n * the y-coordinate of the eye/camera location\r\n * @param eyeZ\r\n * the z-coordinate of the eye/camera location\r\n * @param centerX\r\n * the x-coordinate of the point to look at\r\n * @param centerY\r\n * the y-coordinate of the point to look at\r\n * @param centerZ\r\n * the z-coordinate of the point to look at\r\n * @param upX\r\n * the x-coordinate of the up vector\r\n * @param upY\r\n * the y-coordinate of the up vector\r\n * @param upZ\r\n * the z-coordinate of the up vector\r\n * @return this\r\n */\r\n public Matrix4f lookAt(float eyeX, float eyeY, float eyeZ,\r\n float centerX, float centerY, float centerZ,\r\n float upX, float upY, float upZ) {\r\n return lookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ, this);\r\n }\r\n\r\n /**\r\n * Set this matrix to be a \"lookat\" transformation for a left-handed coordinate system, that aligns\r\n * +z
with center - eye
.\r\n *
\r\n * In order to not make use of vectors to specify eye
, center
and up
but use primitives,\r\n * like in the GLU function, use {@link #setLookAtLH(float, float, float, float, float, float, float, float, float) setLookAtLH()}\r\n * instead.\r\n *
\r\n * In order to apply the lookat transformation to a previous existing transformation,\r\n * use {@link #lookAtLH(Vector3f, Vector3f, Vector3f) lookAt()}.\r\n * \r\n * @see #setLookAtLH(float, float, float, float, float, float, float, float, float)\r\n * @see #lookAtLH(Vector3f, Vector3f, Vector3f)\r\n * \r\n * @param eye\r\n * the position of the camera\r\n * @param center\r\n * the point in space to look at\r\n * @param up\r\n * the direction of 'up'\r\n * @return this\r\n */\r\n public Matrix4f setLookAtLH(Vector3f eye, Vector3f center, Vector3f up) {\r\n return setLookAtLH(eye.x, eye.y, eye.z, center.x, center.y, center.z, up.x, up.y, up.z);\r\n }\r\n\r\n /**\r\n * Set this matrix to be a \"lookat\" transformation for a left-handed coordinate system, \r\n * that aligns +z
with center - eye
.\r\n *
\r\n * In order to apply the lookat transformation to a previous existing transformation,\r\n * use {@link #lookAtLH(float, float, float, float, float, float, float, float, float) lookAtLH}.\r\n * \r\n * @see #setLookAtLH(Vector3f, Vector3f, Vector3f)\r\n * @see #lookAtLH(float, float, float, float, float, float, float, float, float)\r\n * \r\n * @param eyeX\r\n * the x-coordinate of the eye/camera location\r\n * @param eyeY\r\n * the y-coordinate of the eye/camera location\r\n * @param eyeZ\r\n * the z-coordinate of the eye/camera location\r\n * @param centerX\r\n * the x-coordinate of the point to look at\r\n * @param centerY\r\n * the y-coordinate of the point to look at\r\n * @param centerZ\r\n * the z-coordinate of the point to look at\r\n * @param upX\r\n * the x-coordinate of the up vector\r\n * @param upY\r\n * the y-coordinate of the up vector\r\n * @param upZ\r\n * the z-coordinate of the up vector\r\n * @return this\r\n */\r\n public Matrix4f setLookAtLH(float eyeX, float eyeY, float eyeZ,\r\n float centerX, float centerY, float centerZ,\r\n float upX, float upY, float upZ) {\r\n // Compute direction from position to lookAt\r\n float dirX, dirY, dirZ;\r\n dirX = centerX - eyeX;\r\n dirY = centerY - eyeY;\r\n dirZ = centerZ - eyeZ;\r\n // Normalize direction\r\n float invDirLength = 1.0f / (float) Math.sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);\r\n dirX *= invDirLength;\r\n dirY *= invDirLength;\r\n dirZ *= invDirLength;\r\n // left = up x direction\r\n float leftX, leftY, leftZ;\r\n leftX = upY * dirZ - upZ * dirY;\r\n leftY = upZ * dirX - upX * dirZ;\r\n leftZ = upX * dirY - upY * dirX;\r\n // normalize left\r\n float invLeftLength = 1.0f / (float) Math.sqrt(leftX * leftX + leftY * leftY + leftZ * leftZ);\r\n leftX *= invLeftLength;\r\n leftY *= invLeftLength;\r\n leftZ *= invLeftLength;\r\n // up = direction x left\r\n float upnX = dirY * leftZ - dirZ * leftY;\r\n float upnY = dirZ * leftX - dirX * leftZ;\r\n float upnZ = dirX * leftY - dirY * leftX;\r\n\r\n m00 = leftX;\r\n m01 = upnX;\r\n m02 = dirX;\r\n m03 = 0.0f;\r\n m10 = leftY;\r\n m11 = upnY;\r\n m12 = dirY;\r\n m13 = 0.0f;\r\n m20 = leftZ;\r\n m21 = upnZ;\r\n m22 = dirZ;\r\n m23 = 0.0f;\r\n m30 = -(leftX * eyeX + leftY * eyeY + leftZ * eyeZ);\r\n m31 = -(upnX * eyeX + upnY * eyeY + upnZ * eyeZ);\r\n m32 = -(dirX * eyeX + dirY * eyeY + dirZ * eyeZ);\r\n m33 = 1.0f;\r\n\r\n return this;\r\n }\r\n\r\n /**\r\n * Apply a \"lookat\" transformation to this matrix for a left-handed coordinate system, \r\n * that aligns +z
with center - eye
and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and L
the lookat matrix,\r\n * then the new matrix will be M * L
. So when transforming a\r\n * vector v
with the new matrix by using M * L * v
,\r\n * the lookat transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a lookat transformation without post-multiplying it,\r\n * use {@link #setLookAtLH(Vector3f, Vector3f, Vector3f)}.\r\n * \r\n * @see #lookAtLH(float, float, float, float, float, float, float, float, float)\r\n * \r\n * @param eye\r\n * the position of the camera\r\n * @param center\r\n * the point in space to look at\r\n * @param up\r\n * the direction of 'up'\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f lookAtLH(Vector3f eye, Vector3f center, Vector3f up, Matrix4f dest) {\r\n return lookAtLH(eye.x, eye.y, eye.z, center.x, center.y, center.z, up.x, up.y, up.z, dest);\r\n }\r\n\r\n /**\r\n * Apply a \"lookat\" transformation to this matrix for a left-handed coordinate system, \r\n * that aligns +z
with center - eye
.\r\n *
\r\n * If M
is this
matrix and L
the lookat matrix,\r\n * then the new matrix will be M * L
. So when transforming a\r\n * vector v
with the new matrix by using M * L * v
,\r\n * the lookat transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a lookat transformation without post-multiplying it,\r\n * use {@link #setLookAtLH(Vector3f, Vector3f, Vector3f)}.\r\n * \r\n * @see #lookAtLH(float, float, float, float, float, float, float, float, float)\r\n * \r\n * @param eye\r\n * the position of the camera\r\n * @param center\r\n * the point in space to look at\r\n * @param up\r\n * the direction of 'up'\r\n * @return this\r\n */\r\n public Matrix4f lookAtLH(Vector3f eye, Vector3f center, Vector3f up) {\r\n return lookAtLH(eye.x, eye.y, eye.z, center.x, center.y, center.z, up.x, up.y, up.z, this);\r\n }\r\n\r\n /**\r\n * Apply a \"lookat\" transformation to this matrix for a left-handed coordinate system, \r\n * that aligns +z
with center - eye
and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and L
the lookat matrix,\r\n * then the new matrix will be M * L
. So when transforming a\r\n * vector v
with the new matrix by using M * L * v
,\r\n * the lookat transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a lookat transformation without post-multiplying it,\r\n * use {@link #setLookAtLH(float, float, float, float, float, float, float, float, float) setLookAtLH()}.\r\n * \r\n * @see #lookAtLH(Vector3f, Vector3f, Vector3f)\r\n * @see #setLookAtLH(float, float, float, float, float, float, float, float, float)\r\n * \r\n * @param eyeX\r\n * the x-coordinate of the eye/camera location\r\n * @param eyeY\r\n * the y-coordinate of the eye/camera location\r\n * @param eyeZ\r\n * the z-coordinate of the eye/camera location\r\n * @param centerX\r\n * the x-coordinate of the point to look at\r\n * @param centerY\r\n * the y-coordinate of the point to look at\r\n * @param centerZ\r\n * the z-coordinate of the point to look at\r\n * @param upX\r\n * the x-coordinate of the up vector\r\n * @param upY\r\n * the y-coordinate of the up vector\r\n * @param upZ\r\n * the z-coordinate of the up vector\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f lookAtLH(float eyeX, float eyeY, float eyeZ,\r\n float centerX, float centerY, float centerZ,\r\n float upX, float upY, float upZ, Matrix4f dest) {\r\n // Compute direction from position to lookAt\r\n float dirX, dirY, dirZ;\r\n dirX = centerX - eyeX;\r\n dirY = centerY - eyeY;\r\n dirZ = centerZ - eyeZ;\r\n // Normalize direction\r\n float invDirLength = 1.0f / (float) Math.sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);\r\n dirX *= invDirLength;\r\n dirY *= invDirLength;\r\n dirZ *= invDirLength;\r\n // left = up x direction\r\n float leftX, leftY, leftZ;\r\n leftX = upY * dirZ - upZ * dirY;\r\n leftY = upZ * dirX - upX * dirZ;\r\n leftZ = upX * dirY - upY * dirX;\r\n // normalize left\r\n float invLeftLength = 1.0f / (float) Math.sqrt(leftX * leftX + leftY * leftY + leftZ * leftZ);\r\n leftX *= invLeftLength;\r\n leftY *= invLeftLength;\r\n leftZ *= invLeftLength;\r\n // up = direction x left\r\n float upnX = dirY * leftZ - dirZ * leftY;\r\n float upnY = dirZ * leftX - dirX * leftZ;\r\n float upnZ = dirX * leftY - dirY * leftX;\r\n\r\n // calculate right matrix elements\r\n float rm00 = leftX;\r\n float rm01 = upnX;\r\n float rm02 = dirX;\r\n float rm10 = leftY;\r\n float rm11 = upnY;\r\n float rm12 = dirY;\r\n float rm20 = leftZ;\r\n float rm21 = upnZ;\r\n float rm22 = dirZ;\r\n float rm30 = -(leftX * eyeX + leftY * eyeY + leftZ * eyeZ);\r\n float rm31 = -(upnX * eyeX + upnY * eyeY + upnZ * eyeZ);\r\n float rm32 = -(dirX * eyeX + dirY * eyeY + dirZ * eyeZ);\r\n\r\n // perform optimized matrix multiplication\r\n // compute last column first, because others do not depend on it\r\n dest.m30 = m00 * rm30 + m10 * rm31 + m20 * rm32 + m30;\r\n dest.m31 = m01 * rm30 + m11 * rm31 + m21 * rm32 + m31;\r\n dest.m32 = m02 * rm30 + m12 * rm31 + m22 * rm32 + m32;\r\n dest.m33 = m03 * rm30 + m13 * rm31 + m23 * rm32 + m33;\r\n // introduce temporaries for dependent results\r\n float nm00 = m00 * rm00 + m10 * rm01 + m20 * rm02;\r\n float nm01 = m01 * rm00 + m11 * rm01 + m21 * rm02;\r\n float nm02 = m02 * rm00 + m12 * rm01 + m22 * rm02;\r\n float nm03 = m03 * rm00 + m13 * rm01 + m23 * rm02;\r\n float nm10 = m00 * rm10 + m10 * rm11 + m20 * rm12;\r\n float nm11 = m01 * rm10 + m11 * rm11 + m21 * rm12;\r\n float nm12 = m02 * rm10 + m12 * rm11 + m22 * rm12;\r\n float nm13 = m03 * rm10 + m13 * rm11 + m23 * rm12;\r\n dest.m20 = m00 * rm20 + m10 * rm21 + m20 * rm22;\r\n dest.m21 = m01 * rm20 + m11 * rm21 + m21 * rm22;\r\n dest.m22 = m02 * rm20 + m12 * rm21 + m22 * rm22;\r\n dest.m23 = m03 * rm20 + m13 * rm21 + m23 * rm22;\r\n // set the rest of the matrix elements\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply a \"lookat\" transformation to this matrix for a left-handed coordinate system, \r\n * that aligns +z
with center - eye
.\r\n *
\r\n * If M
is this
matrix and L
the lookat matrix,\r\n * then the new matrix will be M * L
. So when transforming a\r\n * vector v
with the new matrix by using M * L * v
,\r\n * the lookat transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a lookat transformation without post-multiplying it,\r\n * use {@link #setLookAtLH(float, float, float, float, float, float, float, float, float) setLookAtLH()}.\r\n * \r\n * @see #lookAtLH(Vector3f, Vector3f, Vector3f)\r\n * @see #setLookAtLH(float, float, float, float, float, float, float, float, float)\r\n * \r\n * @param eyeX\r\n * the x-coordinate of the eye/camera location\r\n * @param eyeY\r\n * the y-coordinate of the eye/camera location\r\n * @param eyeZ\r\n * the z-coordinate of the eye/camera location\r\n * @param centerX\r\n * the x-coordinate of the point to look at\r\n * @param centerY\r\n * the y-coordinate of the point to look at\r\n * @param centerZ\r\n * the z-coordinate of the point to look at\r\n * @param upX\r\n * the x-coordinate of the up vector\r\n * @param upY\r\n * the y-coordinate of the up vector\r\n * @param upZ\r\n * the z-coordinate of the up vector\r\n * @return this\r\n */\r\n public Matrix4f lookAtLH(float eyeX, float eyeY, float eyeZ,\r\n float centerX, float centerY, float centerZ,\r\n float upX, float upY, float upZ) {\r\n return lookAtLH(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ, this);\r\n }\r\n\r\n /**\r\n * Apply a symmetric perspective projection frustum transformation for a right-handed coordinate system\r\n * using the given NDC z range to this matrix and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and P
the perspective projection matrix,\r\n * then the new matrix will be M * P
. So when transforming a\r\n * vector v
with the new matrix by using M * P * v
,\r\n * the perspective projection will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setPerspective(float, float, float, float, boolean) setPerspective}.\r\n * \r\n * @see #setPerspective(float, float, float, float, boolean)\r\n * \r\n * @param fovy\r\n * the vertical field of view in radians (must be greater than zero and less than {@link Math#PI PI})\r\n * @param aspect\r\n * the aspect ratio (i.e. width / height; must be greater than zero)\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param dest\r\n * will hold the result\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return dest\r\n */\r\n public Matrix4f perspective(float fovy, float aspect, float zNear, float zFar, boolean zZeroToOne, Matrix4f dest) {\r\n float h = (float) Math.tan(fovy * 0.5f);\r\n\r\n // calculate right matrix elements\r\n float rm00 = 1.0f / (h * aspect);\r\n float rm11 = 1.0f / h;\r\n float rm22;\r\n float rm32;\r\n boolean farInf = zFar > 0 && Float.isInfinite(zFar);\r\n boolean nearInf = zNear > 0 && Float.isInfinite(zNear);\r\n if (farInf) {\r\n // See: \"Infinite Projection Matrix\" (http://www.terathon.com/gdc07_lengyel.pdf)\r\n float e = 1E-6f;\r\n rm22 = e - 1.0f;\r\n rm32 = (e - (zZeroToOne ? 1.0f : 2.0f)) * zNear;\r\n } else if (nearInf) {\r\n float e = 1E-6f;\r\n rm22 = (zZeroToOne ? 0.0f : 1.0f) - e;\r\n rm32 = ((zZeroToOne ? 1.0f : 2.0f) - e) * zFar;\r\n } else {\r\n rm22 = (zZeroToOne ? zFar : zFar + zNear) / (zNear - zFar);\r\n rm32 = (zZeroToOne ? zFar : zFar + zFar) * zNear / (zNear - zFar);\r\n }\r\n // perform optimized matrix multiplication\r\n float nm20 = m20 * rm22 - m30;\r\n float nm21 = m21 * rm22 - m31;\r\n float nm22 = m22 * rm22 - m32;\r\n float nm23 = m23 * rm22 - m33;\r\n dest.m00 = m00 * rm00;\r\n dest.m01 = m01 * rm00;\r\n dest.m02 = m02 * rm00;\r\n dest.m03 = m03 * rm00;\r\n dest.m10 = m10 * rm11;\r\n dest.m11 = m11 * rm11;\r\n dest.m12 = m12 * rm11;\r\n dest.m13 = m13 * rm11;\r\n dest.m30 = m20 * rm32;\r\n dest.m31 = m21 * rm32;\r\n dest.m32 = m22 * rm32;\r\n dest.m33 = m23 * rm32;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply a symmetric perspective projection frustum transformation for a right-handed coordinate system\r\n * using OpenGL's NDC z range of [-1..+1] to this matrix and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and P
the perspective projection matrix,\r\n * then the new matrix will be M * P
. So when transforming a\r\n * vector v
with the new matrix by using M * P * v
,\r\n * the perspective projection will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setPerspective(float, float, float, float) setPerspective}.\r\n * \r\n * @see #setPerspective(float, float, float, float)\r\n * \r\n * @param fovy\r\n * the vertical field of view in radians (must be greater than zero and less than {@link Math#PI PI})\r\n * @param aspect\r\n * the aspect ratio (i.e. width / height; must be greater than zero)\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f perspective(float fovy, float aspect, float zNear, float zFar, Matrix4f dest) {\r\n return perspective(fovy, aspect, zNear, zFar, false, dest);\r\n }\r\n\r\n /**\r\n * Apply a symmetric perspective projection frustum transformation using for a right-handed coordinate system\r\n * the given NDC z range to this matrix.\r\n *
\r\n * If M
is this
matrix and P
the perspective projection matrix,\r\n * then the new matrix will be M * P
. So when transforming a\r\n * vector v
with the new matrix by using M * P * v
,\r\n * the perspective projection will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setPerspective(float, float, float, float, boolean) setPerspective}.\r\n * \r\n * @see #setPerspective(float, float, float, float, boolean)\r\n * \r\n * @param fovy\r\n * the vertical field of view in radians (must be greater than zero and less than {@link Math#PI PI})\r\n * @param aspect\r\n * the aspect ratio (i.e. width / height; must be greater than zero)\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return this\r\n */\r\n public Matrix4f perspective(float fovy, float aspect, float zNear, float zFar, boolean zZeroToOne) {\r\n return perspective(fovy, aspect, zNear, zFar, zZeroToOne, this);\r\n }\r\n\r\n /**\r\n * Apply a symmetric perspective projection frustum transformation for a right-handed coordinate system\r\n * using OpenGL's NDC z range of [-1..+1] to this matrix.\r\n *
\r\n * If M
is this
matrix and P
the perspective projection matrix,\r\n * then the new matrix will be M * P
. So when transforming a\r\n * vector v
with the new matrix by using M * P * v
,\r\n * the perspective projection will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setPerspective(float, float, float, float) setPerspective}.\r\n * \r\n * @see #setPerspective(float, float, float, float)\r\n * \r\n * @param fovy\r\n * the vertical field of view in radians (must be greater than zero and less than {@link Math#PI PI})\r\n * @param aspect\r\n * the aspect ratio (i.e. width / height; must be greater than zero)\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @return this\r\n */\r\n public Matrix4f perspective(float fovy, float aspect, float zNear, float zFar) {\r\n return perspective(fovy, aspect, zNear, zFar, this);\r\n }\r\n\r\n /**\r\n * Set this matrix to be a symmetric perspective projection frustum transformation for a right-handed coordinate system\r\n * using the given NDC z range.\r\n *
\r\n * In order to apply the perspective projection transformation to an existing transformation,\r\n * use {@link #perspective(float, float, float, float, boolean) perspective()}.\r\n * \r\n * @see #perspective(float, float, float, float, boolean)\r\n * \r\n * @param fovy\r\n * the vertical field of view in radians (must be greater than zero and less than {@link Math#PI PI})\r\n * @param aspect\r\n * the aspect ratio (i.e. width / height; must be greater than zero)\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return this\r\n */\r\n public Matrix4f setPerspective(float fovy, float aspect, float zNear, float zFar, boolean zZeroToOne) {\r\n float h = (float) Math.tan(fovy * 0.5f);\r\n m00 = 1.0f / (h * aspect);\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = 1.0f / h;\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = 0.0f;\r\n boolean farInf = zFar > 0 && Float.isInfinite(zFar);\r\n boolean nearInf = zNear > 0 && Float.isInfinite(zNear);\r\n if (farInf) {\r\n // See: \"Infinite Projection Matrix\" (http://www.terathon.com/gdc07_lengyel.pdf)\r\n float e = 1E-6f;\r\n m22 = e - 1.0f;\r\n m32 = (e - (zZeroToOne ? 1.0f : 2.0f)) * zNear;\r\n } else if (nearInf) {\r\n float e = 1E-6f;\r\n m22 = (zZeroToOne ? 0.0f : 1.0f) - e;\r\n m32 = ((zZeroToOne ? 1.0f : 2.0f) - e) * zFar;\r\n } else {\r\n m22 = (zZeroToOne ? zFar : zFar + zNear) / (zNear - zFar);\r\n m32 = (zZeroToOne ? zFar : zFar + zFar) * zNear / (zNear - zFar);\r\n }\r\n m23 = -1.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m33 = 0.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be a symmetric perspective projection frustum transformation for a right-handed coordinate system\r\n * using OpenGL's NDC z range of [-1..+1].\r\n *
\r\n * In order to apply the perspective projection transformation to an existing transformation,\r\n * use {@link #perspective(float, float, float, float) perspective()}.\r\n * \r\n * @see #perspective(float, float, float, float)\r\n * \r\n * @param fovy\r\n * the vertical field of view in radians (must be greater than zero and less than {@link Math#PI PI})\r\n * @param aspect\r\n * the aspect ratio (i.e. width / height; must be greater than zero)\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @return this\r\n */\r\n public Matrix4f setPerspective(float fovy, float aspect, float zNear, float zFar) {\r\n return setPerspective(fovy, aspect, zNear, zFar, false);\r\n }\r\n\r\n /**\r\n * Apply a symmetric perspective projection frustum transformation for a left-handed coordinate system\r\n * using the given NDC z range to this matrix and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and P
the perspective projection matrix,\r\n * then the new matrix will be M * P
. So when transforming a\r\n * vector v
with the new matrix by using M * P * v
,\r\n * the perspective projection will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setPerspectiveLH(float, float, float, float, boolean) setPerspectiveLH}.\r\n * \r\n * @see #setPerspectiveLH(float, float, float, float, boolean)\r\n * \r\n * @param fovy\r\n * the vertical field of view in radians (must be greater than zero and less than {@link Math#PI PI})\r\n * @param aspect\r\n * the aspect ratio (i.e. width / height; must be greater than zero)\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f perspectiveLH(float fovy, float aspect, float zNear, float zFar, boolean zZeroToOne, Matrix4f dest) {\r\n float h = (float) Math.tan(fovy * 0.5f);\r\n // calculate right matrix elements\r\n float rm00 = 1.0f / (h * aspect);\r\n float rm11 = 1.0f / h;\r\n float rm22;\r\n float rm32;\r\n boolean farInf = zFar > 0 && Float.isInfinite(zFar);\r\n boolean nearInf = zNear > 0 && Float.isInfinite(zNear);\r\n if (farInf) {\r\n // See: \"Infinite Projection Matrix\" (http://www.terathon.com/gdc07_lengyel.pdf)\r\n float e = 1E-6f;\r\n rm22 = 1.0f - e;\r\n rm32 = (e - (zZeroToOne ? 1.0f : 2.0f)) * zNear;\r\n } else if (nearInf) {\r\n float e = 1E-6f;\r\n rm22 = (zZeroToOne ? 0.0f : 1.0f) - e;\r\n rm32 = ((zZeroToOne ? 1.0f : 2.0f) - e) * zFar;\r\n } else {\r\n rm22 = (zZeroToOne ? zFar : zFar + zNear) / (zFar - zNear);\r\n rm32 = (zZeroToOne ? zFar : zFar + zFar) * zNear / (zNear - zFar);\r\n }\r\n // perform optimized matrix multiplication\r\n float nm20 = m20 * rm22 + m30;\r\n float nm21 = m21 * rm22 + m31;\r\n float nm22 = m22 * rm22 + m32;\r\n float nm23 = m23 * rm22 + m33;\r\n dest.m00 = m00 * rm00;\r\n dest.m01 = m01 * rm00;\r\n dest.m02 = m02 * rm00;\r\n dest.m03 = m03 * rm00;\r\n dest.m10 = m10 * rm11;\r\n dest.m11 = m11 * rm11;\r\n dest.m12 = m12 * rm11;\r\n dest.m13 = m13 * rm11;\r\n dest.m30 = m20 * rm32;\r\n dest.m31 = m21 * rm32;\r\n dest.m32 = m22 * rm32;\r\n dest.m33 = m23 * rm32;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply a symmetric perspective projection frustum transformation for a left-handed coordinate system\r\n * using the given NDC z range to this matrix.\r\n *
\r\n * If M
is this
matrix and P
the perspective projection matrix,\r\n * then the new matrix will be M * P
. So when transforming a\r\n * vector v
with the new matrix by using M * P * v
,\r\n * the perspective projection will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setPerspectiveLH(float, float, float, float, boolean) setPerspectiveLH}.\r\n * \r\n * @see #setPerspectiveLH(float, float, float, float, boolean)\r\n * \r\n * @param fovy\r\n * the vertical field of view in radians (must be greater than zero and less than {@link Math#PI PI})\r\n * @param aspect\r\n * the aspect ratio (i.e. width / height; must be greater than zero)\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return this\r\n */\r\n public Matrix4f perspectiveLH(float fovy, float aspect, float zNear, float zFar, boolean zZeroToOne) {\r\n return perspectiveLH(fovy, aspect, zNear, zFar, zZeroToOne, this);\r\n }\r\n\r\n /**\r\n * Apply a symmetric perspective projection frustum transformation for a left-handed coordinate system\r\n * using OpenGL's NDC z range of [-1..+1] to this matrix and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and P
the perspective projection matrix,\r\n * then the new matrix will be M * P
. So when transforming a\r\n * vector v
with the new matrix by using M * P * v
,\r\n * the perspective projection will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setPerspectiveLH(float, float, float, float) setPerspectiveLH}.\r\n * \r\n * @see #setPerspectiveLH(float, float, float, float)\r\n * \r\n * @param fovy\r\n * the vertical field of view in radians (must be greater than zero and less than {@link Math#PI PI})\r\n * @param aspect\r\n * the aspect ratio (i.e. width / height; must be greater than zero)\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f perspectiveLH(float fovy, float aspect, float zNear, float zFar, Matrix4f dest) {\r\n return perspectiveLH(fovy, aspect, zNear, zFar, false, dest);\r\n }\r\n\r\n /**\r\n * Apply a symmetric perspective projection frustum transformation for a left-handed coordinate system\r\n * using OpenGL's NDC z range of [-1..+1] to this matrix.\r\n *
\r\n * If M
is this
matrix and P
the perspective projection matrix,\r\n * then the new matrix will be M * P
. So when transforming a\r\n * vector v
with the new matrix by using M * P * v
,\r\n * the perspective projection will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setPerspectiveLH(float, float, float, float) setPerspectiveLH}.\r\n * \r\n * @see #setPerspectiveLH(float, float, float, float)\r\n * \r\n * @param fovy\r\n * the vertical field of view in radians (must be greater than zero and less than {@link Math#PI PI})\r\n * @param aspect\r\n * the aspect ratio (i.e. width / height; must be greater than zero)\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @return this\r\n */\r\n public Matrix4f perspectiveLH(float fovy, float aspect, float zNear, float zFar) {\r\n return perspectiveLH(fovy, aspect, zNear, zFar, this);\r\n }\r\n\r\n /**\r\n * Set this matrix to be a symmetric perspective projection frustum transformation for a left-handed coordinate system\r\n * using the given NDC z range of [-1..+1].\r\n *
\r\n * In order to apply the perspective projection transformation to an existing transformation,\r\n * use {@link #perspectiveLH(float, float, float, float, boolean) perspectiveLH()}.\r\n * \r\n * @see #perspectiveLH(float, float, float, float, boolean)\r\n * \r\n * @param fovy\r\n * the vertical field of view in radians (must be greater than zero and less than {@link Math#PI PI})\r\n * @param aspect\r\n * the aspect ratio (i.e. width / height; must be greater than zero)\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return this\r\n */\r\n public Matrix4f setPerspectiveLH(float fovy, float aspect, float zNear, float zFar, boolean zZeroToOne) {\r\n float h = (float) Math.tan(fovy * 0.5f);\r\n m00 = 1.0f / (h * aspect);\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = 1.0f / h;\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = 0.0f;\r\n m21 = 0.0f;\r\n boolean farInf = zFar > 0 && Float.isInfinite(zFar);\r\n boolean nearInf = zNear > 0 && Float.isInfinite(zNear);\r\n if (farInf) {\r\n // See: \"Infinite Projection Matrix\" (http://www.terathon.com/gdc07_lengyel.pdf)\r\n float e = 1E-6f;\r\n m22 = 1.0f - e;\r\n m32 = (e - (zZeroToOne ? 1.0f : 2.0f)) * zNear;\r\n } else if (nearInf) {\r\n float e = 1E-6f;\r\n m22 = (zZeroToOne ? 0.0f : 1.0f) - e;\r\n m32 = ((zZeroToOne ? 1.0f : 2.0f) - e) * zFar;\r\n } else {\r\n m22 = (zZeroToOne ? zFar : zFar + zNear) / (zFar - zNear);\r\n m32 = (zZeroToOne ? zFar : zFar + zFar) * zNear / (zNear - zFar);\r\n }\r\n m23 = 1.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m33 = 0.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be a symmetric perspective projection frustum transformation for a left-handed coordinate system\r\n * using OpenGL's NDC z range of [-1..+1].\r\n *
\r\n * In order to apply the perspective projection transformation to an existing transformation,\r\n * use {@link #perspectiveLH(float, float, float, float) perspectiveLH()}.\r\n * \r\n * @see #perspectiveLH(float, float, float, float)\r\n * \r\n * @param fovy\r\n * the vertical field of view in radians (must be greater than zero and less than {@link Math#PI PI})\r\n * @param aspect\r\n * the aspect ratio (i.e. width / height; must be greater than zero)\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @return this\r\n */\r\n public Matrix4f setPerspectiveLH(float fovy, float aspect, float zNear, float zFar) {\r\n return setPerspectiveLH(fovy, aspect, zNear, zFar, false);\r\n }\r\n\r\n /**\r\n * Apply an arbitrary perspective projection frustum transformation for a right-handed coordinate system\r\n * using the given NDC z range to this matrix and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and F
the frustum matrix,\r\n * then the new matrix will be M * F
. So when transforming a\r\n * vector v
with the new matrix by using M * F * v
,\r\n * the frustum transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setFrustum(float, float, float, float, float, float, boolean) setFrustum()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setFrustum(float, float, float, float, float, float, boolean)\r\n * \r\n * @param left\r\n * the distance along the x-axis to the left frustum edge\r\n * @param right\r\n * the distance along the x-axis to the right frustum edge\r\n * @param bottom\r\n * the distance along the y-axis to the bottom frustum edge\r\n * @param top\r\n * the distance along the y-axis to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f frustum(float left, float right, float bottom, float top, float zNear, float zFar, boolean zZeroToOne, Matrix4f dest) {\r\n // calculate right matrix elements\r\n float rm00 = (zNear + zNear) / (right - left);\r\n float rm11 = (zNear + zNear) / (top - bottom);\r\n float rm20 = (right + left) / (right - left);\r\n float rm21 = (top + bottom) / (top - bottom);\r\n float rm22;\r\n float rm32;\r\n boolean farInf = zFar > 0 && Float.isInfinite(zFar);\r\n boolean nearInf = zNear > 0 && Float.isInfinite(zNear);\r\n if (farInf) {\r\n // See: \"Infinite Projection Matrix\" (http://www.terathon.com/gdc07_lengyel.pdf)\r\n float e = 1E-6f;\r\n rm22 = e - 1.0f;\r\n rm32 = (e - (zZeroToOne ? 1.0f : 2.0f)) * zNear;\r\n } else if (nearInf) {\r\n float e = 1E-6f;\r\n rm22 = (zZeroToOne ? 0.0f : 1.0f) - e;\r\n rm32 = ((zZeroToOne ? 1.0f : 2.0f) - e) * zFar;\r\n } else {\r\n rm22 = (zZeroToOne ? zFar : zFar + zNear) / (zNear - zFar);\r\n rm32 = (zZeroToOne ? zFar : zFar + zFar) * zNear / (zNear - zFar);\r\n }\r\n // perform optimized matrix multiplication\r\n float nm20 = m00 * rm20 + m10 * rm21 + m20 * rm22 - m30;\r\n float nm21 = m01 * rm20 + m11 * rm21 + m21 * rm22 - m31;\r\n float nm22 = m02 * rm20 + m12 * rm21 + m22 * rm22 - m32;\r\n float nm23 = m03 * rm20 + m13 * rm21 + m23 * rm22 - m33;\r\n dest.m00 = m00 * rm00;\r\n dest.m01 = m01 * rm00;\r\n dest.m02 = m02 * rm00;\r\n dest.m03 = m03 * rm00;\r\n dest.m10 = m10 * rm11;\r\n dest.m11 = m11 * rm11;\r\n dest.m12 = m12 * rm11;\r\n dest.m13 = m13 * rm11;\r\n dest.m30 = m20 * rm32;\r\n dest.m31 = m21 * rm32;\r\n dest.m32 = m22 * rm32;\r\n dest.m33 = m23 * rm32;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply an arbitrary perspective projection frustum transformation for a right-handed coordinate system\r\n * using OpenGL's NDC z range of [-1..+1] to this matrix and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and F
the frustum matrix,\r\n * then the new matrix will be M * F
. So when transforming a\r\n * vector v
with the new matrix by using M * F * v
,\r\n * the frustum transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setFrustum(float, float, float, float, float, float) setFrustum()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setFrustum(float, float, float, float, float, float)\r\n * \r\n * @param left\r\n * the distance along the x-axis to the left frustum edge\r\n * @param right\r\n * the distance along the x-axis to the right frustum edge\r\n * @param bottom\r\n * the distance along the y-axis to the bottom frustum edge\r\n * @param top\r\n * the distance along the y-axis to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f frustum(float left, float right, float bottom, float top, float zNear, float zFar, Matrix4f dest) {\r\n return frustum(left, right, bottom, top, zNear, zFar, false, dest);\r\n }\r\n\r\n /**\r\n * Apply an arbitrary perspective projection frustum transformation for a right-handed coordinate system\r\n * using the given NDC z range to this matrix.\r\n *
\r\n * If M
is this
matrix and F
the frustum matrix,\r\n * then the new matrix will be M * F
. So when transforming a\r\n * vector v
with the new matrix by using M * F * v
,\r\n * the frustum transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setFrustum(float, float, float, float, float, float, boolean) setFrustum()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setFrustum(float, float, float, float, float, float, boolean)\r\n * \r\n * @param left\r\n * the distance along the x-axis to the left frustum edge\r\n * @param right\r\n * the distance along the x-axis to the right frustum edge\r\n * @param bottom\r\n * the distance along the y-axis to the bottom frustum edge\r\n * @param top\r\n * the distance along the y-axis to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return this\r\n */\r\n public Matrix4f frustum(float left, float right, float bottom, float top, float zNear, float zFar, boolean zZeroToOne) {\r\n return frustum(left, right, bottom, top, zNear, zFar, zZeroToOne, this);\r\n }\r\n\r\n /**\r\n * Apply an arbitrary perspective projection frustum transformation for a right-handed coordinate system\r\n * using OpenGL's NDC z range of [-1..+1] to this matrix.\r\n *
\r\n * If M
is this
matrix and F
the frustum matrix,\r\n * then the new matrix will be M * F
. So when transforming a\r\n * vector v
with the new matrix by using M * F * v
,\r\n * the frustum transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setFrustum(float, float, float, float, float, float) setFrustum()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setFrustum(float, float, float, float, float, float)\r\n * \r\n * @param left\r\n * the distance along the x-axis to the left frustum edge\r\n * @param right\r\n * the distance along the x-axis to the right frustum edge\r\n * @param bottom\r\n * the distance along the y-axis to the bottom frustum edge\r\n * @param top\r\n * the distance along the y-axis to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @return this\r\n */\r\n public Matrix4f frustum(float left, float right, float bottom, float top, float zNear, float zFar) {\r\n return frustum(left, right, bottom, top, zNear, zFar, this);\r\n }\r\n\r\n /**\r\n * Set this matrix to be an arbitrary perspective projection frustum transformation for a right-handed coordinate system\r\n * using the given NDC z range.\r\n *
\r\n * In order to apply the perspective frustum transformation to an existing transformation,\r\n * use {@link #frustum(float, float, float, float, float, float, boolean) frustum()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #frustum(float, float, float, float, float, float, boolean)\r\n * \r\n * @param left\r\n * the distance along the x-axis to the left frustum edge\r\n * @param right\r\n * the distance along the x-axis to the right frustum edge\r\n * @param bottom\r\n * the distance along the y-axis to the bottom frustum edge\r\n * @param top\r\n * the distance along the y-axis to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return this\r\n */\r\n public Matrix4f setFrustum(float left, float right, float bottom, float top, float zNear, float zFar, boolean zZeroToOne) {\r\n m00 = (zNear + zNear) / (right - left);\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = (zNear + zNear) / (top - bottom);\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = (right + left) / (right - left);\r\n m21 = (top + bottom) / (top - bottom);\r\n boolean farInf = zFar > 0 && Float.isInfinite(zFar);\r\n boolean nearInf = zNear > 0 && Float.isInfinite(zNear);\r\n if (farInf) {\r\n // See: \"Infinite Projection Matrix\" (http://www.terathon.com/gdc07_lengyel.pdf)\r\n float e = 1E-6f;\r\n m22 = e - 1.0f;\r\n m32 = (e - (zZeroToOne ? 1.0f : 2.0f)) * zNear;\r\n } else if (nearInf) {\r\n float e = 1E-6f;\r\n m22 = (zZeroToOne ? 0.0f : 1.0f) - e;\r\n m32 = ((zZeroToOne ? 1.0f : 2.0f) - e) * zFar;\r\n } else {\r\n m22 = (zZeroToOne ? zFar : zFar + zNear) / (zNear - zFar);\r\n m32 = (zZeroToOne ? zFar : zFar + zFar) * zNear / (zNear - zFar);\r\n }\r\n m23 = -1.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m33 = 0.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be an arbitrary perspective projection frustum transformation for a right-handed coordinate system\r\n * using OpenGL's NDC z range of [-1..+1].\r\n *
\r\n * In order to apply the perspective frustum transformation to an existing transformation,\r\n * use {@link #frustum(float, float, float, float, float, float) frustum()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #frustum(float, float, float, float, float, float)\r\n * \r\n * @param left\r\n * the distance along the x-axis to the left frustum edge\r\n * @param right\r\n * the distance along the x-axis to the right frustum edge\r\n * @param bottom\r\n * the distance along the y-axis to the bottom frustum edge\r\n * @param top\r\n * the distance along the y-axis to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @return this\r\n */\r\n public Matrix4f setFrustum(float left, float right, float bottom, float top, float zNear, float zFar) {\r\n return setFrustum(left, right, bottom, top, zNear, zFar, false);\r\n }\r\n\r\n /**\r\n * Apply an arbitrary perspective projection frustum transformation for a left-handed coordinate system\r\n * using the given NDC z range to this matrix and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and F
the frustum matrix,\r\n * then the new matrix will be M * F
. So when transforming a\r\n * vector v
with the new matrix by using M * F * v
,\r\n * the frustum transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setFrustumLH(float, float, float, float, float, float, boolean) setFrustumLH()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setFrustumLH(float, float, float, float, float, float, boolean)\r\n * \r\n * @param left\r\n * the distance along the x-axis to the left frustum edge\r\n * @param right\r\n * the distance along the x-axis to the right frustum edge\r\n * @param bottom\r\n * the distance along the y-axis to the bottom frustum edge\r\n * @param top\r\n * the distance along the y-axis to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f frustumLH(float left, float right, float bottom, float top, float zNear, float zFar, boolean zZeroToOne, Matrix4f dest) {\r\n // calculate right matrix elements\r\n float rm00 = (zNear + zNear) / (right - left);\r\n float rm11 = (zNear + zNear) / (top - bottom);\r\n float rm20 = (right + left) / (right - left);\r\n float rm21 = (top + bottom) / (top - bottom);\r\n float rm22;\r\n float rm32;\r\n boolean farInf = zFar > 0 && Float.isInfinite(zFar);\r\n boolean nearInf = zNear > 0 && Float.isInfinite(zNear);\r\n if (farInf) {\r\n // See: \"Infinite Projection Matrix\" (http://www.terathon.com/gdc07_lengyel.pdf)\r\n float e = 1E-6f;\r\n rm22 = 1.0f - e;\r\n rm32 = (e - (zZeroToOne ? 1.0f : 2.0f)) * zNear;\r\n } else if (nearInf) {\r\n float e = 1E-6f;\r\n rm22 = (zZeroToOne ? 0.0f : 1.0f) - e;\r\n rm32 = ((zZeroToOne ? 1.0f : 2.0f) - e) * zFar;\r\n } else {\r\n rm22 = (zZeroToOne ? zFar : zFar + zNear) / (zFar - zNear);\r\n rm32 = (zZeroToOne ? zFar : zFar + zFar) * zNear / (zNear - zFar);\r\n }\r\n // perform optimized matrix multiplication\r\n float nm20 = m00 * rm20 + m10 * rm21 + m20 * rm22 + m30;\r\n float nm21 = m01 * rm20 + m11 * rm21 + m21 * rm22 + m31;\r\n float nm22 = m02 * rm20 + m12 * rm21 + m22 * rm22 + m32;\r\n float nm23 = m03 * rm20 + m13 * rm21 + m23 * rm22 + m33;\r\n dest.m00 = m00 * rm00;\r\n dest.m01 = m01 * rm00;\r\n dest.m02 = m02 * rm00;\r\n dest.m03 = m03 * rm00;\r\n dest.m10 = m10 * rm11;\r\n dest.m11 = m11 * rm11;\r\n dest.m12 = m12 * rm11;\r\n dest.m13 = m13 * rm11;\r\n dest.m30 = m20 * rm32;\r\n dest.m31 = m21 * rm32;\r\n dest.m32 = m22 * rm32;\r\n dest.m33 = m23 * rm32;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply an arbitrary perspective projection frustum transformation for a left-handed coordinate system\r\n * using the given NDC z range to this matrix.\r\n *
\r\n * If M
is this
matrix and F
the frustum matrix,\r\n * then the new matrix will be M * F
. So when transforming a\r\n * vector v
with the new matrix by using M * F * v
,\r\n * the frustum transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setFrustumLH(float, float, float, float, float, float, boolean) setFrustumLH()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setFrustumLH(float, float, float, float, float, float, boolean)\r\n * \r\n * @param left\r\n * the distance along the x-axis to the left frustum edge\r\n * @param right\r\n * the distance along the x-axis to the right frustum edge\r\n * @param bottom\r\n * the distance along the y-axis to the bottom frustum edge\r\n * @param top\r\n * the distance along the y-axis to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return this\r\n */\r\n public Matrix4f frustumLH(float left, float right, float bottom, float top, float zNear, float zFar, boolean zZeroToOne) {\r\n return frustumLH(left, right, bottom, top, zNear, zFar, zZeroToOne, this);\r\n }\r\n\r\n /**\r\n * Apply an arbitrary perspective projection frustum transformation for a left-handed coordinate system\r\n * using OpenGL's NDC z range of [-1..+1] to this matrix and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and F
the frustum matrix,\r\n * then the new matrix will be M * F
. So when transforming a\r\n * vector v
with the new matrix by using M * F * v
,\r\n * the frustum transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setFrustumLH(float, float, float, float, float, float) setFrustumLH()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setFrustumLH(float, float, float, float, float, float)\r\n * \r\n * @param left\r\n * the distance along the x-axis to the left frustum edge\r\n * @param right\r\n * the distance along the x-axis to the right frustum edge\r\n * @param bottom\r\n * the distance along the y-axis to the bottom frustum edge\r\n * @param top\r\n * the distance along the y-axis to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f frustumLH(float left, float right, float bottom, float top, float zNear, float zFar, Matrix4f dest) {\r\n return frustumLH(left, right, bottom, top, zNear, zFar, false, dest);\r\n }\r\n\r\n /**\r\n * Apply an arbitrary perspective projection frustum transformation for a left-handed coordinate system\r\n * using the given NDC z range to this matrix.\r\n *
\r\n * If M
is this
matrix and F
the frustum matrix,\r\n * then the new matrix will be M * F
. So when transforming a\r\n * vector v
with the new matrix by using M * F * v
,\r\n * the frustum transformation will be applied first!\r\n *
\r\n * In order to set the matrix to a perspective frustum transformation without post-multiplying,\r\n * use {@link #setFrustumLH(float, float, float, float, float, float) setFrustumLH()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #setFrustumLH(float, float, float, float, float, float)\r\n * \r\n * @param left\r\n * the distance along the x-axis to the left frustum edge\r\n * @param right\r\n * the distance along the x-axis to the right frustum edge\r\n * @param bottom\r\n * the distance along the y-axis to the bottom frustum edge\r\n * @param top\r\n * the distance along the y-axis to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @return this\r\n */\r\n public Matrix4f frustumLH(float left, float right, float bottom, float top, float zNear, float zFar) {\r\n return frustumLH(left, right, bottom, top, zNear, zFar, this);\r\n }\r\n\r\n /**\r\n * Set this matrix to be an arbitrary perspective projection frustum transformation for a left-handed coordinate system\r\n * using OpenGL's NDC z range of [-1..+1].\r\n *
\r\n * In order to apply the perspective frustum transformation to an existing transformation,\r\n * use {@link #frustumLH(float, float, float, float, float, float, boolean) frustumLH()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #frustumLH(float, float, float, float, float, float, boolean)\r\n * \r\n * @param left\r\n * the distance along the x-axis to the left frustum edge\r\n * @param right\r\n * the distance along the x-axis to the right frustum edge\r\n * @param bottom\r\n * the distance along the y-axis to the bottom frustum edge\r\n * @param top\r\n * the distance along the y-axis to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zZeroToOne\r\n * whether to use Vulkan's and Direct3D's NDC z range of [0..+1] when true
\r\n * or whether to use OpenGL's NDC z range of [-1..+1] when false
\r\n * @return this\r\n */\r\n public Matrix4f setFrustumLH(float left, float right, float bottom, float top, float zNear, float zFar, boolean zZeroToOne) {\r\n m00 = (zNear + zNear) / (right - left);\r\n m01 = 0.0f;\r\n m02 = 0.0f;\r\n m03 = 0.0f;\r\n m10 = 0.0f;\r\n m11 = (zNear + zNear) / (top - bottom);\r\n m12 = 0.0f;\r\n m13 = 0.0f;\r\n m20 = (right + left) / (right - left);\r\n m21 = (top + bottom) / (top - bottom);\r\n boolean farInf = zFar > 0 && Float.isInfinite(zFar);\r\n boolean nearInf = zNear > 0 && Float.isInfinite(zNear);\r\n if (farInf) {\r\n // See: \"Infinite Projection Matrix\" (http://www.terathon.com/gdc07_lengyel.pdf)\r\n float e = 1E-6f;\r\n m22 = 1.0f - e;\r\n m32 = (e - (zZeroToOne ? 1.0f : 2.0f)) * zNear;\r\n } else if (nearInf) {\r\n float e = 1E-6f;\r\n m22 = (zZeroToOne ? 0.0f : 1.0f) - e;\r\n m32 = ((zZeroToOne ? 1.0f : 2.0f) - e) * zFar;\r\n } else {\r\n m22 = (zZeroToOne ? zFar : zFar + zNear) / (zFar - zNear);\r\n m32 = (zZeroToOne ? zFar : zFar + zFar) * zNear / (zNear - zFar);\r\n }\r\n m23 = 1.0f;\r\n m30 = 0.0f;\r\n m31 = 0.0f;\r\n m33 = 0.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to be an arbitrary perspective projection frustum transformation for a left-handed coordinate system\r\n * using OpenGL's NDC z range of [-1..+1].\r\n *
\r\n * In order to apply the perspective frustum transformation to an existing transformation,\r\n * use {@link #frustumLH(float, float, float, float, float, float) frustumLH()}.\r\n *
\r\n * Reference: http://www.songho.ca\r\n * \r\n * @see #frustumLH(float, float, float, float, float, float)\r\n * \r\n * @param left\r\n * the distance along the x-axis to the left frustum edge\r\n * @param right\r\n * the distance along the x-axis to the right frustum edge\r\n * @param bottom\r\n * the distance along the y-axis to the bottom frustum edge\r\n * @param top\r\n * the distance along the y-axis to the top frustum edge\r\n * @param zNear\r\n * near clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the near clipping plane will be at positive infinity.\r\n * In that case, zFar
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @param zFar\r\n * far clipping plane distance. If the special value {@link Float#POSITIVE_INFINITY} is used, the far clipping plane will be at positive infinity.\r\n * In that case, zNear
may not also be {@link Float#POSITIVE_INFINITY}.\r\n * @return this\r\n */\r\n public Matrix4f setFrustumLH(float left, float right, float bottom, float top, float zNear, float zFar) {\r\n return setFrustumLH(left, right, bottom, top, zNear, zFar, false);\r\n }\r\n\r\n /**\r\n * Apply the rotation transformation of the given {@link Quaternionf} to this matrix and store\r\n * the result in dest
.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and Q
the rotation matrix obtained from the given quaternion,\r\n * then the new matrix will be M * Q
. So when transforming a\r\n * vector v
with the new matrix by using M * Q * v
,\r\n * the quaternion rotation will be applied first!\r\n *
\r\n * In order to set the matrix to a rotation transformation without post-multiplying,\r\n * use {@link #rotation(Quaternionf)}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotation(Quaternionf)\r\n * \r\n * @param quat\r\n * the {@link Quaternionf}\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotate(Quaternionf quat, Matrix4f dest) {\r\n float dqx = quat.x + quat.x;\r\n float dqy = quat.y + quat.y;\r\n float dqz = quat.z + quat.z;\r\n float q00 = dqx * quat.x;\r\n float q11 = dqy * quat.y;\r\n float q22 = dqz * quat.z;\r\n float q01 = dqx * quat.y;\r\n float q02 = dqx * quat.z;\r\n float q03 = dqx * quat.w;\r\n float q12 = dqy * quat.z;\r\n float q13 = dqy * quat.w;\r\n float q23 = dqz * quat.w;\r\n\r\n float rm00 = 1.0f - q11 - q22;\r\n float rm01 = q01 + q23;\r\n float rm02 = q02 - q13;\r\n float rm10 = q01 - q23;\r\n float rm11 = 1.0f - q22 - q00;\r\n float rm12 = q12 + q03;\r\n float rm20 = q02 + q13;\r\n float rm21 = q12 - q03;\r\n float rm22 = 1.0f - q11 - q00;\r\n\r\n float nm00 = m00 * rm00 + m10 * rm01 + m20 * rm02;\r\n float nm01 = m01 * rm00 + m11 * rm01 + m21 * rm02;\r\n float nm02 = m02 * rm00 + m12 * rm01 + m22 * rm02;\r\n float nm03 = m03 * rm00 + m13 * rm01 + m23 * rm02;\r\n float nm10 = m00 * rm10 + m10 * rm11 + m20 * rm12;\r\n float nm11 = m01 * rm10 + m11 * rm11 + m21 * rm12;\r\n float nm12 = m02 * rm10 + m12 * rm11 + m22 * rm12;\r\n float nm13 = m03 * rm10 + m13 * rm11 + m23 * rm12;\r\n dest.m20 = m00 * rm20 + m10 * rm21 + m20 * rm22;\r\n dest.m21 = m01 * rm20 + m11 * rm21 + m21 * rm22;\r\n dest.m22 = m02 * rm20 + m12 * rm21 + m22 * rm22;\r\n dest.m23 = m03 * rm20 + m13 * rm21 + m23 * rm22;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply the rotation transformation of the given {@link Quaternionf} to this matrix.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and Q
the rotation matrix obtained from the given quaternion,\r\n * then the new matrix will be M * Q
. So when transforming a\r\n * vector v
with the new matrix by using M * Q * v
,\r\n * the quaternion rotation will be applied first!\r\n *
\r\n * In order to set the matrix to a rotation transformation without post-multiplying,\r\n * use {@link #rotation(Quaternionf)}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotation(Quaternionf)\r\n * \r\n * @param quat\r\n * the {@link Quaternionf}\r\n * @return this\r\n */\r\n public Matrix4f rotate(Quaternionf quat) {\r\n return rotate(quat, this);\r\n }\r\n\r\n /**\r\n * Apply the rotation transformation of the given {@link Quaternionf} to this {@link #isAffine() affine} matrix and store\r\n * the result in dest
.\r\n *
\r\n * This method assumes this
to be {@link #isAffine() affine}.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and Q
the rotation matrix obtained from the given quaternion,\r\n * then the new matrix will be M * Q
. So when transforming a\r\n * vector v
with the new matrix by using M * Q * v
,\r\n * the quaternion rotation will be applied first!\r\n *
\r\n * In order to set the matrix to a rotation transformation without post-multiplying,\r\n * use {@link #rotation(Quaternionf)}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotation(Quaternionf)\r\n * \r\n * @param quat\r\n * the {@link Quaternionf}\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateAffine(Quaternionf quat, Matrix4f dest) {\r\n float dqx = quat.x + quat.x;\r\n float dqy = quat.y + quat.y;\r\n float dqz = quat.z + quat.z;\r\n float q00 = dqx * quat.x;\r\n float q11 = dqy * quat.y;\r\n float q22 = dqz * quat.z;\r\n float q01 = dqx * quat.y;\r\n float q02 = dqx * quat.z;\r\n float q03 = dqx * quat.w;\r\n float q12 = dqy * quat.z;\r\n float q13 = dqy * quat.w;\r\n float q23 = dqz * quat.w;\r\n\r\n float rm00 = 1.0f - q11 - q22;\r\n float rm01 = q01 + q23;\r\n float rm02 = q02 - q13;\r\n float rm10 = q01 - q23;\r\n float rm11 = 1.0f - q22 - q00;\r\n float rm12 = q12 + q03;\r\n float rm20 = q02 + q13;\r\n float rm21 = q12 - q03;\r\n float rm22 = 1.0f - q11 - q00;\r\n\r\n float nm00 = m00 * rm00 + m10 * rm01 + m20 * rm02;\r\n float nm01 = m01 * rm00 + m11 * rm01 + m21 * rm02;\r\n float nm02 = m02 * rm00 + m12 * rm01 + m22 * rm02;\r\n float nm10 = m00 * rm10 + m10 * rm11 + m20 * rm12;\r\n float nm11 = m01 * rm10 + m11 * rm11 + m21 * rm12;\r\n float nm12 = m02 * rm10 + m12 * rm11 + m22 * rm12;\r\n dest.m20 = m00 * rm20 + m10 * rm21 + m20 * rm22;\r\n dest.m21 = m01 * rm20 + m11 * rm21 + m21 * rm22;\r\n dest.m22 = m02 * rm20 + m12 * rm21 + m22 * rm22;\r\n dest.m23 = 0.0f;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = 0.0f;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = 0.0f;\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = m32;\r\n dest.m33 = m33;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply the rotation transformation of the given {@link Quaternionf} to this matrix.\r\n *
\r\n * This method assumes this
to be {@link #isAffine() affine}.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and Q
the rotation matrix obtained from the given quaternion,\r\n * then the new matrix will be M * Q
. So when transforming a\r\n * vector v
with the new matrix by using M * Q * v
,\r\n * the quaternion rotation will be applied first!\r\n *
\r\n * In order to set the matrix to a rotation transformation without post-multiplying,\r\n * use {@link #rotation(Quaternionf)}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotation(Quaternionf)\r\n * \r\n * @param quat\r\n * the {@link Quaternionf}\r\n * @return this\r\n */\r\n public Matrix4f rotateAffine(Quaternionf quat) {\r\n return rotateAffine(quat, this);\r\n }\r\n\r\n /**\r\n * Pre-multiply the rotation transformation of the given {@link Quaternionf} to this {@link #isAffine() affine} matrix and store\r\n * the result in dest
.\r\n *
\r\n * This method assumes this
to be {@link #isAffine() affine}.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and Q
the rotation matrix obtained from the given quaternion,\r\n * then the new matrix will be Q * M
. So when transforming a\r\n * vector v
with the new matrix by using Q * M * v
,\r\n * the quaternion rotation will be applied last!\r\n *
\r\n * In order to set the matrix to a rotation transformation without pre-multiplying,\r\n * use {@link #rotation(Quaternionf)}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotation(Quaternionf)\r\n * \r\n * @param quat\r\n * the {@link Quaternionf}\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotateAffineLocal(Quaternionf quat, Matrix4f dest) {\r\n float dqx = quat.x + quat.x;\r\n float dqy = quat.y + quat.y;\r\n float dqz = quat.z + quat.z;\r\n float q00 = dqx * quat.x;\r\n float q11 = dqy * quat.y;\r\n float q22 = dqz * quat.z;\r\n float q01 = dqx * quat.y;\r\n float q02 = dqx * quat.z;\r\n float q03 = dqx * quat.w;\r\n float q12 = dqy * quat.z;\r\n float q13 = dqy * quat.w;\r\n float q23 = dqz * quat.w;\r\n float lm00 = 1.0f - q11 - q22;\r\n float lm01 = q01 + q23;\r\n float lm02 = q02 - q13;\r\n float lm10 = q01 - q23;\r\n float lm11 = 1.0f - q22 - q00;\r\n float lm12 = q12 + q03;\r\n float lm20 = q02 + q13;\r\n float lm21 = q12 - q03;\r\n float lm22 = 1.0f - q11 - q00;\r\n float nm00 = lm00 * m00 + lm10 * m01 + lm20 * m02;\r\n float nm01 = lm01 * m00 + lm11 * m01 + lm21 * m02;\r\n float nm02 = lm02 * m00 + lm12 * m01 + lm22 * m02;\r\n float nm03 = 0.0f;\r\n float nm10 = lm00 * m10 + lm10 * m11 + lm20 * m12;\r\n float nm11 = lm01 * m10 + lm11 * m11 + lm21 * m12;\r\n float nm12 = lm02 * m10 + lm12 * m11 + lm22 * m12;\r\n float nm13 = 0.0f;\r\n float nm20 = lm00 * m20 + lm10 * m21 + lm20 * m22;\r\n float nm21 = lm01 * m20 + lm11 * m21 + lm21 * m22;\r\n float nm22 = lm02 * m20 + lm12 * m21 + lm22 * m22;\r\n float nm23 = 0.0f;\r\n float nm30 = lm00 * m30 + lm10 * m31 + lm20 * m32;\r\n float nm31 = lm01 * m30 + lm11 * m31 + lm21 * m32;\r\n float nm32 = lm02 * m30 + lm12 * m31 + lm22 * m32;\r\n float nm33 = 1.0f;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Pre-multiply the rotation transformation of the given {@link Quaternionf} to this matrix.\r\n *
\r\n * This method assumes this
to be {@link #isAffine() affine}.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and Q
the rotation matrix obtained from the given quaternion,\r\n * then the new matrix will be Q * M
. So when transforming a\r\n * vector v
with the new matrix by using Q * M * v
,\r\n * the quaternion rotation will be applied last!\r\n *
\r\n * In order to set the matrix to a rotation transformation without pre-multiplying,\r\n * use {@link #rotation(Quaternionf)}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotation(Quaternionf)\r\n * \r\n * @param quat\r\n * the {@link Quaternionf}\r\n * @return this\r\n */\r\n public Matrix4f rotateAffineLocal(Quaternionf quat) {\r\n return rotateAffineLocal(quat, this);\r\n }\r\n\r\n /**\r\n * Apply a rotation transformation, rotating about the given {@link AxisAngle4f}, to this matrix.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and A
the rotation matrix obtained from the given {@link AxisAngle4f},\r\n * then the new matrix will be M * A
. So when transforming a\r\n * vector v
with the new matrix by using M * A * v
,\r\n * the {@link AxisAngle4f} rotation will be applied first!\r\n *
\r\n * In order to set the matrix to a rotation transformation without post-multiplying,\r\n * use {@link #rotation(AxisAngle4f)}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotate(float, float, float, float)\r\n * @see #rotation(AxisAngle4f)\r\n * \r\n * @param axisAngle\r\n * the {@link AxisAngle4f} (needs to be {@link AxisAngle4f#normalize() normalized})\r\n * @return this\r\n */\r\n public Matrix4f rotate(AxisAngle4f axisAngle) {\r\n return rotate(axisAngle.angle, axisAngle.x, axisAngle.y, axisAngle.z);\r\n }\r\n\r\n /**\r\n * Apply a rotation transformation, rotating about the given {@link AxisAngle4f} and store the result in dest
.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and A
the rotation matrix obtained from the given {@link AxisAngle4f},\r\n * then the new matrix will be M * A
. So when transforming a\r\n * vector v
with the new matrix by using M * A * v
,\r\n * the {@link AxisAngle4f} rotation will be applied first!\r\n *
\r\n * In order to set the matrix to a rotation transformation without post-multiplying,\r\n * use {@link #rotation(AxisAngle4f)}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotate(float, float, float, float)\r\n * @see #rotation(AxisAngle4f)\r\n * \r\n * @param axisAngle\r\n * the {@link AxisAngle4f} (needs to be {@link AxisAngle4f#normalize() normalized})\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotate(AxisAngle4f axisAngle, Matrix4f dest) {\r\n return rotate(axisAngle.angle, axisAngle.x, axisAngle.y, axisAngle.z, dest);\r\n }\r\n\r\n /**\r\n * Apply a rotation transformation, rotating the given radians about the specified axis, to this matrix.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and A
the rotation matrix obtained from the given axis-angle,\r\n * then the new matrix will be M * A
. So when transforming a\r\n * vector v
with the new matrix by using M * A * v
,\r\n * the axis-angle rotation will be applied first!\r\n *
\r\n * In order to set the matrix to a rotation transformation without post-multiplying,\r\n * use {@link #rotation(float, Vector3f)}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotate(float, float, float, float)\r\n * @see #rotation(float, Vector3f)\r\n * \r\n * @param angle\r\n * the angle in radians\r\n * @param axis\r\n * the rotation axis (needs to be {@link Vector3f#normalize() normalized})\r\n * @return this\r\n */\r\n public Matrix4f rotate(float angle, Vector3f axis) {\r\n return rotate(angle, axis.x, axis.y, axis.z);\r\n }\r\n\r\n /**\r\n * Apply a rotation transformation, rotating the given radians about the specified axis and store the result in dest
.\r\n *
\r\n * When used with a right-handed coordinate system, the produced rotation will rotate vector \r\n * counter-clockwise around the rotation axis, when viewing along the negative axis direction towards the origin.\r\n * When used with a left-handed coordinate system, the rotation is clockwise.\r\n *
\r\n * If M
is this
matrix and A
the rotation matrix obtained from the given axis-angle,\r\n * then the new matrix will be M * A
. So when transforming a\r\n * vector v
with the new matrix by using M * A * v
,\r\n * the axis-angle rotation will be applied first!\r\n *
\r\n * In order to set the matrix to a rotation transformation without post-multiplying,\r\n * use {@link #rotation(float, Vector3f)}.\r\n *
\r\n * Reference: http://en.wikipedia.org\r\n * \r\n * @see #rotate(float, float, float, float)\r\n * @see #rotation(float, Vector3f)\r\n * \r\n * @param angle\r\n * the angle in radians\r\n * @param axis\r\n * the rotation axis (needs to be {@link Vector3f#normalize() normalized})\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f rotate(float angle, Vector3f axis, Matrix4f dest) {\r\n return rotate(angle, axis.x, axis.y, axis.z, dest);\r\n }\r\n\r\n /**\r\n * Unproject the given window coordinates (winX, winY, winZ) by this
matrix using the specified viewport.\r\n *
\r\n * This method first converts the given window coordinates to normalized device coordinates in the range [-1..1]\r\n * and then transforms those NDC coordinates by the inverse of this
matrix. \r\n *
\r\n * The depth range of winZ is assumed to be [0..1], which is also the OpenGL default.\r\n *
\r\n * As a necessary computation step for unprojecting, this method computes the inverse of this
matrix.\r\n * In order to avoid computing the matrix inverse with every invocation, the inverse of this
matrix can be built\r\n * once outside using {@link #invert(Matrix4f)} and then the method {@link #unprojectInv(float, float, float, int[], Vector4f) unprojectInv()} can be invoked on it.\r\n * \r\n * @see #unprojectInv(float, float, float, int[], Vector4f)\r\n * @see #invert(Matrix4f)\r\n * \r\n * @param winX\r\n * the x-coordinate in window coordinates (pixels)\r\n * @param winY\r\n * the y-coordinate in window coordinates (pixels)\r\n * @param winZ\r\n * the z-coordinate, which is the depth value in [0..1]\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param dest\r\n * will hold the unprojected position\r\n * @return dest\r\n */\r\n public Vector4f unproject(float winX, float winY, float winZ, int[] viewport, Vector4f dest) {\r\n float a = m00 * m11 - m01 * m10;\r\n float b = m00 * m12 - m02 * m10;\r\n float c = m00 * m13 - m03 * m10;\r\n float d = m01 * m12 - m02 * m11;\r\n float e = m01 * m13 - m03 * m11;\r\n float f = m02 * m13 - m03 * m12;\r\n float g = m20 * m31 - m21 * m30;\r\n float h = m20 * m32 - m22 * m30;\r\n float i = m20 * m33 - m23 * m30;\r\n float j = m21 * m32 - m22 * m31;\r\n float k = m21 * m33 - m23 * m31;\r\n float l = m22 * m33 - m23 * m32;\r\n float det = a * l - b * k + c * j + d * i - e * h + f * g;\r\n det = 1.0f / det;\r\n float im00 = ( m11 * l - m12 * k + m13 * j) * det;\r\n float im01 = (-m01 * l + m02 * k - m03 * j) * det;\r\n float im02 = ( m31 * f - m32 * e + m33 * d) * det;\r\n float im03 = (-m21 * f + m22 * e - m23 * d) * det;\r\n float im10 = (-m10 * l + m12 * i - m13 * h) * det;\r\n float im11 = ( m00 * l - m02 * i + m03 * h) * det;\r\n float im12 = (-m30 * f + m32 * c - m33 * b) * det;\r\n float im13 = ( m20 * f - m22 * c + m23 * b) * det;\r\n float im20 = ( m10 * k - m11 * i + m13 * g) * det;\r\n float im21 = (-m00 * k + m01 * i - m03 * g) * det;\r\n float im22 = ( m30 * e - m31 * c + m33 * a) * det;\r\n float im23 = (-m20 * e + m21 * c - m23 * a) * det;\r\n float im30 = (-m10 * j + m11 * h - m12 * g) * det;\r\n float im31 = ( m00 * j - m01 * h + m02 * g) * det;\r\n float im32 = (-m30 * d + m31 * b - m32 * a) * det;\r\n float im33 = ( m20 * d - m21 * b + m22 * a) * det;\r\n float ndcX = (winX-viewport[0])/viewport[2]*2.0f-1.0f;\r\n float ndcY = (winY-viewport[1])/viewport[3]*2.0f-1.0f;\r\n float ndcZ = winZ+winZ-1.0f;\r\n dest.x = im00 * ndcX + im10 * ndcY + im20 * ndcZ + im30;\r\n dest.y = im01 * ndcX + im11 * ndcY + im21 * ndcZ + im31;\r\n dest.z = im02 * ndcX + im12 * ndcY + im22 * ndcZ + im32;\r\n dest.w = im03 * ndcX + im13 * ndcY + im23 * ndcZ + im33;\r\n dest.div(dest.w);\r\n return dest;\r\n }\r\n\r\n /**\r\n * Unproject the given window coordinates (winX, winY, winZ) by this
matrix using the specified viewport.\r\n *
\r\n * This method first converts the given window coordinates to normalized device coordinates in the range [-1..1]\r\n * and then transforms those NDC coordinates by the inverse of this
matrix. \r\n *
\r\n * The depth range of winZ is assumed to be [0..1], which is also the OpenGL default.\r\n *
\r\n * As a necessary computation step for unprojecting, this method computes the inverse of this
matrix.\r\n * In order to avoid computing the matrix inverse with every invocation, the inverse of this
matrix can be built\r\n * once outside using {@link #invert(Matrix4f)} and then the method {@link #unprojectInv(float, float, float, int[], Vector4f) unprojectInv()} can be invoked on it.\r\n * \r\n * @see #unprojectInv(float, float, float, int[], Vector3f)\r\n * @see #invert(Matrix4f)\r\n * \r\n * @param winX\r\n * the x-coordinate in window coordinates (pixels)\r\n * @param winY\r\n * the y-coordinate in window coordinates (pixels)\r\n * @param winZ\r\n * the z-coordinate, which is the depth value in [0..1]\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param dest\r\n * will hold the unprojected position\r\n * @return dest\r\n */\r\n public Vector3f unproject(float winX, float winY, float winZ, int[] viewport, Vector3f dest) {\r\n float a = m00 * m11 - m01 * m10;\r\n float b = m00 * m12 - m02 * m10;\r\n float c = m00 * m13 - m03 * m10;\r\n float d = m01 * m12 - m02 * m11;\r\n float e = m01 * m13 - m03 * m11;\r\n float f = m02 * m13 - m03 * m12;\r\n float g = m20 * m31 - m21 * m30;\r\n float h = m20 * m32 - m22 * m30;\r\n float i = m20 * m33 - m23 * m30;\r\n float j = m21 * m32 - m22 * m31;\r\n float k = m21 * m33 - m23 * m31;\r\n float l = m22 * m33 - m23 * m32;\r\n float det = a * l - b * k + c * j + d * i - e * h + f * g;\r\n det = 1.0f / det;\r\n float im00 = ( m11 * l - m12 * k + m13 * j) * det;\r\n float im01 = (-m01 * l + m02 * k - m03 * j) * det;\r\n float im02 = ( m31 * f - m32 * e + m33 * d) * det;\r\n float im03 = (-m21 * f + m22 * e - m23 * d) * det;\r\n float im10 = (-m10 * l + m12 * i - m13 * h) * det;\r\n float im11 = ( m00 * l - m02 * i + m03 * h) * det;\r\n float im12 = (-m30 * f + m32 * c - m33 * b) * det;\r\n float im13 = ( m20 * f - m22 * c + m23 * b) * det;\r\n float im20 = ( m10 * k - m11 * i + m13 * g) * det;\r\n float im21 = (-m00 * k + m01 * i - m03 * g) * det;\r\n float im22 = ( m30 * e - m31 * c + m33 * a) * det;\r\n float im23 = (-m20 * e + m21 * c - m23 * a) * det;\r\n float im30 = (-m10 * j + m11 * h - m12 * g) * det;\r\n float im31 = ( m00 * j - m01 * h + m02 * g) * det;\r\n float im32 = (-m30 * d + m31 * b - m32 * a) * det;\r\n float im33 = ( m20 * d - m21 * b + m22 * a) * det;\r\n float ndcX = (winX-viewport[0])/viewport[2]*2.0f-1.0f;\r\n float ndcY = (winY-viewport[1])/viewport[3]*2.0f-1.0f;\r\n float ndcZ = winZ+winZ-1.0f;\r\n dest.x = im00 * ndcX + im10 * ndcY + im20 * ndcZ + im30;\r\n dest.y = im01 * ndcX + im11 * ndcY + im21 * ndcZ + im31;\r\n dest.z = im02 * ndcX + im12 * ndcY + im22 * ndcZ + im32;\r\n float w = im03 * ndcX + im13 * ndcY + im23 * ndcZ + im33;\r\n dest.div(w);\r\n return dest;\r\n }\r\n\r\n /**\r\n * Unproject the given window coordinates winCoords
by this
matrix using the specified viewport.\r\n *
\r\n * This method first converts the given window coordinates to normalized device coordinates in the range [-1..1]\r\n * and then transforms those NDC coordinates by the inverse of this
matrix. \r\n *
\r\n * The depth range of winCoords.z is assumed to be [0..1], which is also the OpenGL default.\r\n *
\r\n * As a necessary computation step for unprojecting, this method computes the inverse of this
matrix.\r\n * In order to avoid computing the matrix inverse with every invocation, the inverse of this
matrix can be built\r\n * once outside using {@link #invert(Matrix4f)} and then the method {@link #unprojectInv(float, float, float, int[], Vector4f) unprojectInv()} can be invoked on it.\r\n * \r\n * @see #unprojectInv(float, float, float, int[], Vector4f)\r\n * @see #unproject(float, float, float, int[], Vector4f)\r\n * @see #invert(Matrix4f)\r\n * \r\n * @param winCoords\r\n * the window coordinates to unproject\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param dest\r\n * will hold the unprojected position\r\n * @return dest\r\n */\r\n public Vector4f unproject(Vector3f winCoords, int[] viewport, Vector4f dest) {\r\n return unproject(winCoords.x, winCoords.y, winCoords.z, viewport, dest);\r\n }\r\n\r\n /**\r\n * Unproject the given window coordinates winCoords
by this
matrix using the specified viewport.\r\n *
\r\n * This method first converts the given window coordinates to normalized device coordinates in the range [-1..1]\r\n * and then transforms those NDC coordinates by the inverse of this
matrix. \r\n *
\r\n * The depth range of winCoords.z is assumed to be [0..1], which is also the OpenGL default.\r\n *
\r\n * As a necessary computation step for unprojecting, this method computes the inverse of this
matrix.\r\n * In order to avoid computing the matrix inverse with every invocation, the inverse of this
matrix can be built\r\n * once outside using {@link #invert(Matrix4f)} and then the method {@link #unprojectInv(float, float, float, int[], Vector3f) unprojectInv()} can be invoked on it.\r\n * \r\n * @see #unprojectInv(float, float, float, int[], Vector3f)\r\n * @see #unproject(float, float, float, int[], Vector3f)\r\n * @see #invert(Matrix4f)\r\n * \r\n * @param winCoords\r\n * the window coordinates to unproject\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param dest\r\n * will hold the unprojected position\r\n * @return dest\r\n */\r\n public Vector3f unproject(Vector3f winCoords, int[] viewport, Vector3f dest) {\r\n return unproject(winCoords.x, winCoords.y, winCoords.z, viewport, dest);\r\n }\r\n\r\n /**\r\n * Unproject the given window coordinates winCoords
by this
matrix using the specified viewport.\r\n *
\r\n * This method differs from {@link #unproject(Vector3f, int[], Vector4f) unproject()} \r\n * in that it assumes that this
is already the inverse matrix of the original projection matrix.\r\n * It exists to avoid recomputing the matrix inverse with every invocation.\r\n *
\r\n * The depth range of winCoords.z is assumed to be [0..1], which is also the OpenGL default.\r\n *
\r\n * This method reads the four viewport parameters from the current int[]'s {@link Buffer#position() position}\r\n * and does not modify the buffer's position.\r\n * \r\n * @see #unproject(Vector3f, int[], Vector4f)\r\n * \r\n * @param winCoords\r\n * the window coordinates to unproject\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param dest\r\n * will hold the unprojected position\r\n * @return dest\r\n */\r\n public Vector4f unprojectInv(Vector3f winCoords, int[] viewport, Vector4f dest) {\r\n return unprojectInv(winCoords.x, winCoords.y, winCoords.z, viewport, dest);\r\n }\r\n\r\n /**\r\n * Unproject the given window coordinates (winX, winY, winZ) by this
matrix using the specified viewport.\r\n *
\r\n * This method differs from {@link #unproject(float, float, float, int[], Vector4f) unproject()} \r\n * in that it assumes that this
is already the inverse matrix of the original projection matrix.\r\n * It exists to avoid recomputing the matrix inverse with every invocation.\r\n *
\r\n * The depth range of winZ is assumed to be [0..1], which is also the OpenGL default.\r\n * \r\n * @see #unproject(float, float, float, int[], Vector4f)\r\n * \r\n * @param winX\r\n * the x-coordinate in window coordinates (pixels)\r\n * @param winY\r\n * the y-coordinate in window coordinates (pixels)\r\n * @param winZ\r\n * the z-coordinate, which is the depth value in [0..1]\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param dest\r\n * will hold the unprojected position\r\n * @return dest\r\n */\r\n public Vector4f unprojectInv(float winX, float winY, float winZ, int[] viewport, Vector4f dest) {\r\n float ndcX = (winX-viewport[0])/viewport[2]*2.0f-1.0f;\r\n float ndcY = (winY-viewport[1])/viewport[3]*2.0f-1.0f;\r\n float ndcZ = winZ+winZ-1.0f;\r\n dest.x = m00 * ndcX + m10 * ndcY + m20 * ndcZ + m30;\r\n dest.y = m01 * ndcX + m11 * ndcY + m21 * ndcZ + m31;\r\n dest.z = m02 * ndcX + m12 * ndcY + m22 * ndcZ + m32;\r\n dest.w = m03 * ndcX + m13 * ndcY + m23 * ndcZ + m33;\r\n dest.div(dest.w);\r\n return dest;\r\n }\r\n\r\n /**\r\n * Unproject the given window coordinates winCoords
by this
matrix using the specified viewport.\r\n *
\r\n * This method differs from {@link #unproject(Vector3f, int[], Vector3f) unproject()} \r\n * in that it assumes that this
is already the inverse matrix of the original projection matrix.\r\n * It exists to avoid recomputing the matrix inverse with every invocation.\r\n *
\r\n * The depth range of winCoords.z is assumed to be [0..1], which is also the OpenGL default.\r\n * \r\n * @see #unproject(Vector3f, int[], Vector3f)\r\n * \r\n * @param winCoords\r\n * the window coordinates to unproject\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param dest\r\n * will hold the unprojected position\r\n * @return dest\r\n */\r\n public Vector3f unprojectInv(Vector3f winCoords, int[] viewport, Vector3f dest) {\r\n return unprojectInv(winCoords.x, winCoords.y, winCoords.z, viewport, dest);\r\n }\r\n\r\n /**\r\n * Unproject the given window coordinates (winX, winY, winZ) by this
matrix using the specified viewport.\r\n *
\r\n * This method differs from {@link #unproject(float, float, float, int[], Vector3f) unproject()} \r\n * in that it assumes that this
is already the inverse matrix of the original projection matrix.\r\n * It exists to avoid recomputing the matrix inverse with every invocation.\r\n *
\r\n * The depth range of winZ is assumed to be [0..1], which is also the OpenGL default.\r\n * \r\n * @see #unproject(float, float, float, int[], Vector3f)\r\n * \r\n * @param winX\r\n * the x-coordinate in window coordinates (pixels)\r\n * @param winY\r\n * the y-coordinate in window coordinates (pixels)\r\n * @param winZ\r\n * the z-coordinate, which is the depth value in [0..1]\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param dest\r\n * will hold the unprojected position\r\n * @return dest\r\n */\r\n public Vector3f unprojectInv(float winX, float winY, float winZ, int[] viewport, Vector3f dest) {\r\n float ndcX = (winX-viewport[0])/viewport[2]*2.0f-1.0f;\r\n float ndcY = (winY-viewport[1])/viewport[3]*2.0f-1.0f;\r\n float ndcZ = winZ+winZ-1.0f;\r\n dest.x = m00 * ndcX + m10 * ndcY + m20 * ndcZ + m30;\r\n dest.y = m01 * ndcX + m11 * ndcY + m21 * ndcZ + m31;\r\n dest.z = m02 * ndcX + m12 * ndcY + m22 * ndcZ + m32;\r\n float w = m03 * ndcX + m13 * ndcY + m23 * ndcZ + m33;\r\n dest.div(w);\r\n return dest;\r\n }\r\n\r\n /**\r\n * Project the given (x, y, z) position via this
matrix using the specified viewport\r\n * and store the resulting window coordinates in winCoordsDest
.\r\n *
\r\n * This method transforms the given coordinates by this
matrix including perspective division to \r\n * obtain normalized device coordinates, and then translates these into window coordinates by using the\r\n * given viewport
settings [x, y, width, height].\r\n *
\r\n * The depth range of the returned winCoordsDest.z
will be [0..1], which is also the OpenGL default. \r\n * \r\n * @param x\r\n * the x-coordinate of the position to project\r\n * @param y\r\n * the y-coordinate of the position to project\r\n * @param z\r\n * the z-coordinate of the position to project\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param winCoordsDest\r\n * will hold the projected window coordinates\r\n * @return winCoordsDest\r\n */\r\n public Vector4f project(float x, float y, float z, int[] viewport, Vector4f winCoordsDest) {\r\n winCoordsDest.x = m00 * x + m10 * y + m20 * z + m30;\r\n winCoordsDest.y = m01 * x + m11 * y + m21 * z + m31;\r\n winCoordsDest.z = m02 * x + m12 * y + m22 * z + m32;\r\n winCoordsDest.w = m03 * x + m13 * y + m23 * z + m33;\r\n winCoordsDest.div(winCoordsDest.w);\r\n winCoordsDest.x = (winCoordsDest.x*0.5f+0.5f) * viewport[2] + viewport[0];\r\n winCoordsDest.y = (winCoordsDest.y*0.5f+0.5f) * viewport[3] + viewport[1];\r\n winCoordsDest.z = (1.0f+winCoordsDest.z)*0.5f;\r\n return winCoordsDest;\r\n }\r\n\r\n /**\r\n * Project the given (x, y, z) position via this
matrix using the specified viewport\r\n * and store the resulting window coordinates in winCoordsDest
.\r\n *
\r\n * This method transforms the given coordinates by this
matrix including perspective division to \r\n * obtain normalized device coordinates, and then translates these into window coordinates by using the\r\n * given viewport
settings [x, y, width, height].\r\n *
\r\n * The depth range of the returned winCoordsDest.z
will be [0..1], which is also the OpenGL default. \r\n * \r\n * @param x\r\n * the x-coordinate of the position to project\r\n * @param y\r\n * the y-coordinate of the position to project\r\n * @param z\r\n * the z-coordinate of the position to project\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param winCoordsDest\r\n * will hold the projected window coordinates\r\n * @return winCoordsDest\r\n */\r\n public Vector3f project(float x, float y, float z, int[] viewport, Vector3f winCoordsDest) {\r\n winCoordsDest.x = m00 * x + m10 * y + m20 * z + m30;\r\n winCoordsDest.y = m01 * x + m11 * y + m21 * z + m31;\r\n winCoordsDest.z = m02 * x + m12 * y + m22 * z + m32;\r\n float w = m03 * x + m13 * y + m23 * z + m33;\r\n winCoordsDest.div(w);\r\n winCoordsDest.x = (winCoordsDest.x*0.5f+0.5f) * viewport[2] + viewport[0];\r\n winCoordsDest.y = (winCoordsDest.y*0.5f+0.5f) * viewport[3] + viewport[1];\r\n winCoordsDest.z = (1.0f+winCoordsDest.z)*0.5f;\r\n return winCoordsDest;\r\n }\r\n\r\n /**\r\n * Project the given position
via this
matrix using the specified viewport\r\n * and store the resulting window coordinates in winCoordsDest
.\r\n *
\r\n * This method transforms the given coordinates by this
matrix including perspective division to \r\n * obtain normalized device coordinates, and then translates these into window coordinates by using the\r\n * given viewport
settings [x, y, width, height].\r\n *
\r\n * The depth range of the returned winCoordsDest.z
will be [0..1], which is also the OpenGL default. \r\n * \r\n * @see #project(float, float, float, int[], Vector4f)\r\n * \r\n * @param position\r\n * the position to project into window coordinates\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param winCoordsDest\r\n * will hold the projected window coordinates\r\n * @return winCoordsDest\r\n */\r\n public Vector4f project(Vector3f position, int[] viewport, Vector4f winCoordsDest) {\r\n return project(position.x, position.y, position.z, viewport, winCoordsDest);\r\n }\r\n\r\n /**\r\n * Project the given position
via this
matrix using the specified viewport\r\n * and store the resulting window coordinates in winCoordsDest
.\r\n *
\r\n * This method transforms the given coordinates by this
matrix including perspective division to \r\n * obtain normalized device coordinates, and then translates these into window coordinates by using the\r\n * given viewport
settings [x, y, width, height].\r\n *
\r\n * The depth range of the returned winCoordsDest.z
will be [0..1], which is also the OpenGL default. \r\n * \r\n * @see #project(float, float, float, int[], Vector4f)\r\n * \r\n * @param position\r\n * the position to project into window coordinates\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param winCoordsDest\r\n * will hold the projected window coordinates\r\n * @return winCoordsDest\r\n */\r\n public Vector3f project(Vector3f position, int[] viewport, Vector3f winCoordsDest) {\r\n return project(position.x, position.y, position.z, viewport, winCoordsDest);\r\n }\r\n\r\n /**\r\n * Apply a mirror/reflection transformation to this matrix that reflects about the given plane\r\n * specified via the equation x*a + y*b + z*c + d = 0 and store the result in dest
.\r\n *
\r\n * The vector (a, b, c) must be a unit vector.\r\n *
\r\n * If M
is this
matrix and R
the reflection matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * reflection will be applied first!\r\n *
\r\n * Reference: msdn.microsoft.com\r\n * \r\n * @param a\r\n * the x factor in the plane equation\r\n * @param b\r\n * the y factor in the plane equation\r\n * @param c\r\n * the z factor in the plane equation\r\n * @param d\r\n * the constant in the plane equation\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f reflect(float a, float b, float c, float d, Matrix4f dest) {\r\n float da = a + a, db = b + b, dc = c + c, dd = d + d;\r\n float rm00 = 1.0f - da * a;\r\n float rm01 = -da * b;\r\n float rm02 = -da * c;\r\n float rm10 = -db * a;\r\n float rm11 = 1.0f - db * b;\r\n float rm12 = -db * c;\r\n float rm20 = -dc * a;\r\n float rm21 = -dc * b;\r\n float rm22 = 1.0f - dc * c;\r\n float rm30 = -dd * a;\r\n float rm31 = -dd * b;\r\n float rm32 = -dd * c;\r\n\r\n // matrix multiplication\r\n dest.m30 = m00 * rm30 + m10 * rm31 + m20 * rm32 + m30;\r\n dest.m31 = m01 * rm30 + m11 * rm31 + m21 * rm32 + m31;\r\n dest.m32 = m02 * rm30 + m12 * rm31 + m22 * rm32 + m32;\r\n dest.m33 = m03 * rm30 + m13 * rm31 + m23 * rm32 + m33;\r\n float nm00 = m00 * rm00 + m10 * rm01 + m20 * rm02;\r\n float nm01 = m01 * rm00 + m11 * rm01 + m21 * rm02;\r\n float nm02 = m02 * rm00 + m12 * rm01 + m22 * rm02;\r\n float nm03 = m03 * rm00 + m13 * rm01 + m23 * rm02;\r\n float nm10 = m00 * rm10 + m10 * rm11 + m20 * rm12;\r\n float nm11 = m01 * rm10 + m11 * rm11 + m21 * rm12;\r\n float nm12 = m02 * rm10 + m12 * rm11 + m22 * rm12;\r\n float nm13 = m03 * rm10 + m13 * rm11 + m23 * rm12;\r\n dest.m20 = m00 * rm20 + m10 * rm21 + m20 * rm22;\r\n dest.m21 = m01 * rm20 + m11 * rm21 + m21 * rm22;\r\n dest.m22 = m02 * rm20 + m12 * rm21 + m22 * rm22;\r\n dest.m23 = m03 * rm20 + m13 * rm21 + m23 * rm22;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply a mirror/reflection transformation to this matrix that reflects about the given plane\r\n * specified via the equation x*a + y*b + z*c + d = 0.\r\n *
\r\n * The vector (a, b, c) must be a unit vector.\r\n *
\r\n * If M
is this
matrix and R
the reflection matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * reflection will be applied first!\r\n *
\r\n * Reference: msdn.microsoft.com\r\n * \r\n * @param a\r\n * the x factor in the plane equation\r\n * @param b\r\n * the y factor in the plane equation\r\n * @param c\r\n * the z factor in the plane equation\r\n * @param d\r\n * the constant in the plane equation\r\n * @return this\r\n */\r\n public Matrix4f reflect(float a, float b, float c, float d) {\r\n return reflect(a, b, c, d, this);\r\n }\r\n\r\n /**\r\n * Apply a mirror/reflection transformation to this matrix that reflects about the given plane\r\n * specified via the plane normal and a point on the plane.\r\n *
\r\n * If M
is this
matrix and R
the reflection matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * reflection will be applied first!\r\n * \r\n * @param nx\r\n * the x-coordinate of the plane normal\r\n * @param ny\r\n * the y-coordinate of the plane normal\r\n * @param nz\r\n * the z-coordinate of the plane normal\r\n * @param px\r\n * the x-coordinate of a point on the plane\r\n * @param py\r\n * the y-coordinate of a point on the plane\r\n * @param pz\r\n * the z-coordinate of a point on the plane\r\n * @return this\r\n */\r\n public Matrix4f reflect(float nx, float ny, float nz, float px, float py, float pz) {\r\n return reflect(nx, ny, nz, px, py, pz, this);\r\n }\r\n\r\n /**\r\n * Apply a mirror/reflection transformation to this matrix that reflects about the given plane\r\n * specified via the plane normal and a point on the plane, and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and R
the reflection matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * reflection will be applied first!\r\n * \r\n * @param nx\r\n * the x-coordinate of the plane normal\r\n * @param ny\r\n * the y-coordinate of the plane normal\r\n * @param nz\r\n * the z-coordinate of the plane normal\r\n * @param px\r\n * the x-coordinate of a point on the plane\r\n * @param py\r\n * the y-coordinate of a point on the plane\r\n * @param pz\r\n * the z-coordinate of a point on the plane\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f reflect(float nx, float ny, float nz, float px, float py, float pz, Matrix4f dest) {\r\n float invLength = 1.0f / (float) Math.sqrt(nx * nx + ny * ny + nz * nz);\r\n float nnx = nx * invLength;\r\n float nny = ny * invLength;\r\n float nnz = nz * invLength;\r\n /* See: http://mathworld.wolfram.com/Plane.html */\r\n return reflect(nnx, nny, nnz, -nnx * px - nny * py - nnz * pz, dest);\r\n }\r\n\r\n /**\r\n * Apply a mirror/reflection transformation to this matrix that reflects about the given plane\r\n * specified via the plane normal and a point on the plane.\r\n *
\r\n * If M
is this
matrix and R
the reflection matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * reflection will be applied first!\r\n * \r\n * @param normal\r\n * the plane normal\r\n * @param point\r\n * a point on the plane\r\n * @return this\r\n */\r\n public Matrix4f reflect(Vector3f normal, Vector3f point) {\r\n return reflect(normal.x, normal.y, normal.z, point.x, point.y, point.z);\r\n }\r\n\r\n /**\r\n * Apply a mirror/reflection transformation to this matrix that reflects about a plane\r\n * specified via the plane orientation and a point on the plane.\r\n *
\r\n * This method can be used to build a reflection transformation based on the orientation of a mirror object in the scene.\r\n * It is assumed that the default mirror plane's normal is (0, 0, 1). So, if the given {@link Quaternionf} is\r\n * the identity (does not apply any additional rotation), the reflection plane will be z=0, offset by the given point
.\r\n *
\r\n * If M
is this
matrix and R
the reflection matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * reflection will be applied first!\r\n * \r\n * @param orientation\r\n * the plane orientation\r\n * @param point\r\n * a point on the plane\r\n * @return this\r\n */\r\n public Matrix4f reflect(Quaternionf orientation, Vector3f point) {\r\n return reflect(orientation, point, this);\r\n }\r\n\r\n /**\r\n * Apply a mirror/reflection transformation to this matrix that reflects about a plane\r\n * specified via the plane orientation and a point on the plane, and store the result in dest
.\r\n *
\r\n * This method can be used to build a reflection transformation based on the orientation of a mirror object in the scene.\r\n * It is assumed that the default mirror plane's normal is (0, 0, 1). So, if the given {@link Quaternionf} is\r\n * the identity (does not apply any additional rotation), the reflection plane will be z=0, offset by the given point
.\r\n *
\r\n * If M
is this
matrix and R
the reflection matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * reflection will be applied first!\r\n * \r\n * @param orientation\r\n * the plane orientation relative to an implied normal vector of (0, 0, 1)\r\n * @param point\r\n * a point on the plane\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f reflect(Quaternionf orientation, Vector3f point, Matrix4f dest) {\r\n double num1 = orientation.x + orientation.x;\r\n double num2 = orientation.y + orientation.y;\r\n double num3 = orientation.z + orientation.z;\r\n float normalX = (float) (orientation.x * num3 + orientation.w * num2);\r\n float normalY = (float) (orientation.y * num3 - orientation.w * num1);\r\n float normalZ = (float) (1.0 - (orientation.x * num1 + orientation.y * num2));\r\n return reflect(normalX, normalY, normalZ, point.x, point.y, point.z, dest);\r\n }\r\n\r\n /**\r\n * Apply a mirror/reflection transformation to this matrix that reflects about the given plane\r\n * specified via the plane normal and a point on the plane, and store the result in dest
.\r\n *
\r\n * If M
is this
matrix and R
the reflection matrix,\r\n * then the new matrix will be M * R
. So when transforming a\r\n * vector v
with the new matrix by using M * R * v
, the\r\n * reflection will be applied first!\r\n * \r\n * @param normal\r\n * the plane normal\r\n * @param point\r\n * a point on the plane\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f reflect(Vector3f normal, Vector3f point, Matrix4f dest) {\r\n return reflect(normal.x, normal.y, normal.z, point.x, point.y, point.z, dest);\r\n }\r\n\r\n /**\r\n * Set this matrix to a mirror/reflection transformation that reflects about the given plane\r\n * specified via the equation x*a + y*b + z*c + d = 0.\r\n *
\r\n * The vector (a, b, c) must be a unit vector.\r\n *
\r\n * Reference: msdn.microsoft.com\r\n * \r\n * @param a\r\n * the x factor in the plane equation\r\n * @param b\r\n * the y factor in the plane equation\r\n * @param c\r\n * the z factor in the plane equation\r\n * @param d\r\n * the constant in the plane equation\r\n * @return this\r\n */\r\n public Matrix4f reflection(float a, float b, float c, float d) {\r\n float da = a + a, db = b + b, dc = c + c, dd = d + d;\r\n m00 = 1.0f - da * a;\r\n m01 = -da * b;\r\n m02 = -da * c;\r\n m03 = 0.0f;\r\n m10 = -db * a;\r\n m11 = 1.0f - db * b;\r\n m12 = -db * c;\r\n m13 = 0.0f;\r\n m20 = -dc * a;\r\n m21 = -dc * b;\r\n m22 = 1.0f - dc * c;\r\n m23 = 0.0f;\r\n m30 = -dd * a;\r\n m31 = -dd * b;\r\n m32 = -dd * c;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to a mirror/reflection transformation that reflects about the given plane\r\n * specified via the plane normal and a point on the plane.\r\n * \r\n * @param nx\r\n * the x-coordinate of the plane normal\r\n * @param ny\r\n * the y-coordinate of the plane normal\r\n * @param nz\r\n * the z-coordinate of the plane normal\r\n * @param px\r\n * the x-coordinate of a point on the plane\r\n * @param py\r\n * the y-coordinate of a point on the plane\r\n * @param pz\r\n * the z-coordinate of a point on the plane\r\n * @return this\r\n */\r\n public Matrix4f reflection(float nx, float ny, float nz, float px, float py, float pz) {\r\n float invLength = 1.0f / (float) Math.sqrt(nx * nx + ny * ny + nz * nz);\r\n float nnx = nx * invLength;\r\n float nny = ny * invLength;\r\n float nnz = nz * invLength;\r\n /* See: http://mathworld.wolfram.com/Plane.html */\r\n return reflection(nnx, nny, nnz, -nnx * px - nny * py - nnz * pz);\r\n }\r\n\r\n /**\r\n * Set this matrix to a mirror/reflection transformation that reflects about the given plane\r\n * specified via the plane normal and a point on the plane.\r\n * \r\n * @param normal\r\n * the plane normal\r\n * @param point\r\n * a point on the plane\r\n * @return this\r\n */\r\n public Matrix4f reflection(Vector3f normal, Vector3f point) {\r\n return reflection(normal.x, normal.y, normal.z, point.x, point.y, point.z);\r\n }\r\n\r\n /**\r\n * Set this matrix to a mirror/reflection transformation that reflects about a plane\r\n * specified via the plane orientation and a point on the plane.\r\n *
\r\n * This method can be used to build a reflection transformation based on the orientation of a mirror object in the scene.\r\n * It is assumed that the default mirror plane's normal is (0, 0, 1). So, if the given {@link Quaternionf} is\r\n * the identity (does not apply any additional rotation), the reflection plane will be z=0, offset by the given point
.\r\n * \r\n * @param orientation\r\n * the plane orientation\r\n * @param point\r\n * a point on the plane\r\n * @return this\r\n */\r\n public Matrix4f reflection(Quaternionf orientation, Vector3f point) {\r\n double num1 = orientation.x + orientation.x;\r\n double num2 = orientation.y + orientation.y;\r\n double num3 = orientation.z + orientation.z;\r\n float normalX = (float) (orientation.x * num3 + orientation.w * num2);\r\n float normalY = (float) (orientation.y * num3 - orientation.w * num1);\r\n float normalZ = (float) (1.0 - (orientation.x * num1 + orientation.y * num2));\r\n return reflection(normalX, normalY, normalZ, point.x, point.y, point.z);\r\n }\r\n\r\n /**\r\n * Get the row at the given row
index, starting with 0
.\r\n * \r\n * @param row\r\n * the row index in [0..3]\r\n * @param dest\r\n * will hold the row components\r\n * @return the passed in destination\r\n * @throws IndexOutOfBoundsException if row
is not in [0..3]\r\n */\r\n public Vector4f getRow(int row, Vector4f dest) throws IndexOutOfBoundsException {\r\n switch (row) {\r\n case 0:\r\n dest.x = m00;\r\n dest.y = m10;\r\n dest.z = m20;\r\n dest.w = m30;\r\n break;\r\n case 1:\r\n dest.x = m01;\r\n dest.y = m11;\r\n dest.z = m21;\r\n dest.w = m31;\r\n break;\r\n case 2:\r\n dest.x = m02;\r\n dest.y = m12;\r\n dest.z = m22;\r\n dest.w = m32;\r\n break;\r\n case 3:\r\n dest.x = m03;\r\n dest.y = m13;\r\n dest.z = m23;\r\n dest.w = m33;\r\n break;\r\n default:\r\n throw new IndexOutOfBoundsException();\r\n }\r\n return dest;\r\n }\r\n\r\n /**\r\n * Get the column at the given column
index, starting with 0
.\r\n * \r\n * @param column\r\n * the column index in [0..3]\r\n * @param dest\r\n * will hold the column components\r\n * @return the passed in destination\r\n * @throws IndexOutOfBoundsException if column
is not in [0..3]\r\n */\r\n public Vector4f getColumn(int column, Vector4f dest) throws IndexOutOfBoundsException {\r\n switch (column) {\r\n case 0:\r\n dest.x = m00;\r\n dest.y = m01;\r\n dest.z = m02;\r\n dest.w = m03;\r\n break;\r\n case 1:\r\n dest.x = m10;\r\n dest.y = m11;\r\n dest.z = m12;\r\n dest.w = m13;\r\n break;\r\n case 2:\r\n dest.x = m20;\r\n dest.y = m21;\r\n dest.z = m22;\r\n dest.w = m23;\r\n break;\r\n case 3:\r\n dest.x = m30;\r\n dest.y = m31;\r\n dest.z = m32;\r\n dest.w = m32;\r\n break;\r\n default:\r\n throw new IndexOutOfBoundsException();\r\n }\r\n return dest;\r\n }\r\n\r\n /**\r\n * Compute a normal matrix from the upper left 3x3 submatrix of this
\r\n * and store it into the upper left 3x3 submatrix of this
.\r\n * All other values of this
will be set to {@link #identity() identity}.\r\n *
\r\n * The normal matrix of m is the transpose of the inverse of m.\r\n *
\r\n * Please note that, if this
is an orthogonal matrix or a matrix whose columns are orthogonal vectors, \r\n * then this method need not be invoked, since in that case this
itself is its normal matrix.\r\n * In that case, use {@link #set3x3(Matrix4f)} to set a given Matrix4f to only the upper left 3x3 submatrix\r\n * of this matrix.\r\n * \r\n * @see #set3x3(Matrix4f)\r\n * \r\n * @return this\r\n */\r\n public Matrix4f normal() {\r\n return normal(this);\r\n }\r\n\r\n /**\r\n * Compute a normal matrix from the upper left 3x3 submatrix of this
\r\n * and store it into the upper left 3x3 submatrix of dest
.\r\n * All other values of dest
will be set to {@link #identity() identity}.\r\n *
\r\n * The normal matrix of m is the transpose of the inverse of m.\r\n *
\r\n * Please note that, if this
is an orthogonal matrix or a matrix whose columns are orthogonal vectors, \r\n * then this method need not be invoked, since in that case this
itself is its normal matrix.\r\n * In that case, use {@link #set3x3(Matrix4f)} to set a given Matrix4f to only the upper left 3x3 submatrix\r\n * of this matrix.\r\n * \r\n * @see #set3x3(Matrix4f)\r\n * \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f normal(Matrix4f dest) {\r\n float det = determinant3x3();\r\n float s = 1.0f / det;\r\n /* Invert and transpose in one go */\r\n float nm00 = (m11 * m22 - m21 * m12) * s;\r\n float nm01 = (m20 * m12 - m10 * m22) * s;\r\n float nm02 = (m10 * m21 - m20 * m11) * s;\r\n float nm03 = 0.0f;\r\n float nm10 = (m21 * m02 - m01 * m22) * s;\r\n float nm11 = (m00 * m22 - m20 * m02) * s;\r\n float nm12 = (m20 * m01 - m00 * m21) * s;\r\n float nm13 = 0.0f;\r\n float nm20 = (m01 * m12 - m11 * m02) * s;\r\n float nm21 = (m10 * m02 - m00 * m12) * s;\r\n float nm22 = (m00 * m11 - m10 * m01) * s;\r\n float nm23 = 0.0f;\r\n float nm30 = 0.0f;\r\n float nm31 = 0.0f;\r\n float nm32 = 0.0f;\r\n float nm33 = 1.0f;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m30 = nm30;\r\n dest.m31 = nm31;\r\n dest.m32 = nm32;\r\n dest.m33 = nm33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Compute a normal matrix from the upper left 3x3 submatrix of this
\r\n * and store it into dest
.\r\n *
\r\n * The normal matrix of m is the transpose of the inverse of m.\r\n *
\r\n * Please note that, if this
is an orthogonal matrix or a matrix whose columns are orthogonal vectors, \r\n * then this method need not be invoked, since in that case this
itself is its normal matrix.\r\n * In that case, use {@link Matrix3f#set(Matrix4f)} to set a given Matrix3f to only the upper left 3x3 submatrix\r\n * of this matrix.\r\n * \r\n * @see Matrix3f#set(Matrix4f)\r\n * @see #get3x3(Matrix3f)\r\n * \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix3f normal(Matrix3f dest) {\r\n float det = determinant3x3();\r\n float s = 1.0f / det;\r\n /* Invert and transpose in one go */\r\n dest.m00 = (m11 * m22 - m21 * m12) * s;\r\n dest.m01 = (m20 * m12 - m10 * m22) * s;\r\n dest.m02 = (m10 * m21 - m20 * m11) * s;\r\n dest.m10 = (m21 * m02 - m01 * m22) * s;\r\n dest.m11 = (m00 * m22 - m20 * m02) * s;\r\n dest.m12 = (m20 * m01 - m00 * m21) * s;\r\n dest.m20 = (m01 * m12 - m11 * m02) * s;\r\n dest.m21 = (m10 * m02 - m00 * m12) * s;\r\n dest.m22 = (m00 * m11 - m10 * m01) * s;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Normalize the upper left 3x3 submatrix of this matrix.\r\n *
\r\n * The resulting matrix will map unit vectors to unit vectors, though a pair of orthogonal input unit\r\n * vectors need not be mapped to a pair of orthogonal output vectors if the original matrix was not orthogonal itself\r\n * (i.e. had skewing).\r\n * \r\n * @return this\r\n */\r\n public Matrix4f normalize3x3() {\r\n return normalize3x3(this);\r\n }\r\n\r\n /**\r\n * Normalize the upper left 3x3 submatrix of this matrix and store the result in dest
.\r\n *
\r\n * The resulting matrix will map unit vectors to unit vectors, though a pair of orthogonal input unit\r\n * vectors need not be mapped to a pair of orthogonal output vectors if the original matrix was not orthogonal itself\r\n * (i.e. had skewing).\r\n * \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f normalize3x3(Matrix4f dest) {\r\n float invXlen = (float) (1.0 / Math.sqrt(m00 * m00 + m01 * m01 + m02 * m02));\r\n float invYlen = (float) (1.0 / Math.sqrt(m10 * m10 + m11 * m11 + m12 * m12));\r\n float invZlen = (float) (1.0 / Math.sqrt(m20 * m20 + m21 * m21 + m22 * m22));\r\n dest.m00 = m00 * invXlen; dest.m01 = m01 * invXlen; dest.m02 = m02 * invXlen;\r\n dest.m10 = m10 * invYlen; dest.m11 = m11 * invYlen; dest.m12 = m12 * invYlen;\r\n dest.m20 = m20 * invZlen; dest.m21 = m21 * invZlen; dest.m22 = m22 * invZlen;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Normalize the upper left 3x3 submatrix of this matrix and store the result in dest
.\r\n *
\r\n * The resulting matrix will map unit vectors to unit vectors, though a pair of orthogonal input unit\r\n * vectors need not be mapped to a pair of orthogonal output vectors if the original matrix was not orthogonal itself\r\n * (i.e. had skewing).\r\n * \r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix3f normalize3x3(Matrix3f dest) {\r\n float invXlen = (float) (1.0 / Math.sqrt(m00 * m00 + m01 * m01 + m02 * m02));\r\n float invYlen = (float) (1.0 / Math.sqrt(m10 * m10 + m11 * m11 + m12 * m12));\r\n float invZlen = (float) (1.0 / Math.sqrt(m20 * m20 + m21 * m21 + m22 * m22));\r\n dest.m00 = m00 * invXlen; dest.m01 = m01 * invXlen; dest.m02 = m02 * invXlen;\r\n dest.m10 = m10 * invYlen; dest.m11 = m11 * invYlen; dest.m12 = m12 * invYlen;\r\n dest.m20 = m20 * invZlen; dest.m21 = m21 * invZlen; dest.m22 = m22 * invZlen;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Calculate a frustum plane of this
matrix, which\r\n * can be a projection matrix or a combined modelview-projection matrix, and store the result\r\n * in the given planeEquation
.\r\n *
\r\n * Generally, this method computes the frustum plane in the local frame of\r\n * any coordinate system that existed before this
\r\n * transformation was applied to it in order to yield homogeneous clipping space.\r\n *
\r\n * The frustum plane will be given in the form of a general plane equation:\r\n * a*x + b*y + c*z + d = 0, where the given {@link Vector4f} components will\r\n * hold the (a, b, c, d) values of the equation.\r\n *
\r\n * The plane normal, which is (a, b, c), is directed \"inwards\" of the frustum.\r\n * Any plane/point test using a*x + b*y + c*z + d therefore will yield a result greater than zero\r\n * if the point is within the frustum (i.e. at the positive side of the frustum plane).\r\n *
\r\n * Reference: \r\n * Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix\r\n *\r\n * @param plane\r\n * one of the six possible planes, given as numeric constants\r\n * {@link #PLANE_NX}, {@link #PLANE_PX},\r\n * {@link #PLANE_NY}, {@link #PLANE_PY},\r\n * {@link #PLANE_NZ} and {@link #PLANE_PZ}\r\n * @param planeEquation\r\n * will hold the computed plane equation.\r\n * The plane equation will be normalized, meaning that (a, b, c) will be a unit vector\r\n * @return planeEquation\r\n */\r\n public Vector4f frustumPlane(int plane, Vector4f planeEquation) {\r\n switch (plane) {\r\n case PLANE_NX:\r\n planeEquation.set(m03 + m00, m13 + m10, m23 + m20, m33 + m30).normalize3();\r\n break;\r\n case PLANE_PX:\r\n planeEquation.set(m03 - m00, m13 - m10, m23 - m20, m33 - m30).normalize3();\r\n break;\r\n case PLANE_NY:\r\n planeEquation.set(m03 + m01, m13 + m11, m23 + m21, m33 + m31).normalize3();\r\n break;\r\n case PLANE_PY:\r\n planeEquation.set(m03 - m01, m13 - m11, m23 - m21, m33 - m31).normalize3();\r\n break;\r\n case PLANE_NZ:\r\n planeEquation.set(m03 + m02, m13 + m12, m23 + m22, m33 + m32).normalize3();\r\n break;\r\n case PLANE_PZ:\r\n planeEquation.set(m03 - m02, m13 - m12, m23 - m22, m33 - m32).normalize3();\r\n break;\r\n default:\r\n throw new IllegalArgumentException(\"plane\"); //$NON-NLS-1$\r\n }\r\n return planeEquation;\r\n }\r\n\r\n /**\r\n * Compute the corner coordinates of the frustum defined by this
matrix, which\r\n * can be a projection matrix or a combined modelview-projection matrix, and store the result\r\n * in the given point
.\r\n *
\r\n * Generally, this method computes the frustum corners in the local frame of\r\n * any coordinate system that existed before this
\r\n * transformation was applied to it in order to yield homogeneous clipping space.\r\n *
\r\n * Reference: http://geomalgorithms.com\r\n *
\r\n * Reference: \r\n * Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix\r\n * \r\n * @param corner\r\n * one of the eight possible corners, given as numeric constants\r\n * {@link #CORNER_NXNYNZ}, {@link #CORNER_PXNYNZ}, {@link #CORNER_PXPYNZ}, {@link #CORNER_NXPYNZ},\r\n * {@link #CORNER_PXNYPZ}, {@link #CORNER_NXNYPZ}, {@link #CORNER_NXPYPZ}, {@link #CORNER_PXPYPZ}\r\n * @param point\r\n * will hold the resulting corner point coordinates\r\n * @return point\r\n */\r\n public Vector3f frustumCorner(int corner, Vector3f point) {\r\n float d1, d2, d3;\r\n float n1x, n1y, n1z, n2x, n2y, n2z, n3x, n3y, n3z;\r\n switch (corner) {\r\n case CORNER_NXNYNZ: // left, bottom, near\r\n n1x = m03 + m00; n1y = m13 + m10; n1z = m23 + m20; d1 = m33 + m30; // left\r\n n2x = m03 + m01; n2y = m13 + m11; n2z = m23 + m21; d2 = m33 + m31; // bottom\r\n n3x = m03 + m02; n3y = m13 + m12; n3z = m23 + m22; d3 = m33 + m32; // near\r\n break;\r\n case CORNER_PXNYNZ: // right, bottom, near\r\n n1x = m03 - m00; n1y = m13 - m10; n1z = m23 - m20; d1 = m33 - m30; // right\r\n n2x = m03 + m01; n2y = m13 + m11; n2z = m23 + m21; d2 = m33 + m31; // bottom\r\n n3x = m03 + m02; n3y = m13 + m12; n3z = m23 + m22; d3 = m33 + m32; // near\r\n break;\r\n case CORNER_PXPYNZ: // right, top, near\r\n n1x = m03 - m00; n1y = m13 - m10; n1z = m23 - m20; d1 = m33 - m30; // right\r\n n2x = m03 - m01; n2y = m13 - m11; n2z = m23 - m21; d2 = m33 - m31; // top\r\n n3x = m03 + m02; n3y = m13 + m12; n3z = m23 + m22; d3 = m33 + m32; // near\r\n break;\r\n case CORNER_NXPYNZ: // left, top, near\r\n n1x = m03 + m00; n1y = m13 + m10; n1z = m23 + m20; d1 = m33 + m30; // left\r\n n2x = m03 - m01; n2y = m13 - m11; n2z = m23 - m21; d2 = m33 - m31; // top\r\n n3x = m03 + m02; n3y = m13 + m12; n3z = m23 + m22; d3 = m33 + m32; // near\r\n break;\r\n case CORNER_PXNYPZ: // right, bottom, far\r\n n1x = m03 - m00; n1y = m13 - m10; n1z = m23 - m20; d1 = m33 - m30; // right\r\n n2x = m03 + m01; n2y = m13 + m11; n2z = m23 + m21; d2 = m33 + m31; // bottom\r\n n3x = m03 - m02; n3y = m13 - m12; n3z = m23 - m22; d3 = m33 - m32; // far\r\n break;\r\n case CORNER_NXNYPZ: // left, bottom, far\r\n n1x = m03 + m00; n1y = m13 + m10; n1z = m23 + m20; d1 = m33 + m30; // left\r\n n2x = m03 + m01; n2y = m13 + m11; n2z = m23 + m21; d2 = m33 + m31; // bottom\r\n n3x = m03 - m02; n3y = m13 - m12; n3z = m23 - m22; d3 = m33 - m32; // far\r\n break;\r\n case CORNER_NXPYPZ: // left, top, far\r\n n1x = m03 + m00; n1y = m13 + m10; n1z = m23 + m20; d1 = m33 + m30; // left\r\n n2x = m03 - m01; n2y = m13 - m11; n2z = m23 - m21; d2 = m33 - m31; // top\r\n n3x = m03 - m02; n3y = m13 - m12; n3z = m23 - m22; d3 = m33 - m32; // far\r\n break;\r\n case CORNER_PXPYPZ: // right, top, far\r\n n1x = m03 - m00; n1y = m13 - m10; n1z = m23 - m20; d1 = m33 - m30; // right\r\n n2x = m03 - m01; n2y = m13 - m11; n2z = m23 - m21; d2 = m33 - m31; // top\r\n n3x = m03 - m02; n3y = m13 - m12; n3z = m23 - m22; d3 = m33 - m32; // far\r\n break;\r\n default:\r\n throw new IllegalArgumentException(\"corner\"); //$NON-NLS-1$\r\n }\r\n float c23x, c23y, c23z;\r\n c23x = n2y * n3z - n2z * n3y;\r\n c23y = n2z * n3x - n2x * n3z;\r\n c23z = n2x * n3y - n2y * n3x;\r\n float c31x, c31y, c31z;\r\n c31x = n3y * n1z - n3z * n1y;\r\n c31y = n3z * n1x - n3x * n1z;\r\n c31z = n3x * n1y - n3y * n1x;\r\n float c12x, c12y, c12z;\r\n c12x = n1y * n2z - n1z * n2y;\r\n c12y = n1z * n2x - n1x * n2z;\r\n c12z = n1x * n2y - n1y * n2x;\r\n float invDot = 1.0f / (n1x * c23x + n1y * c23y + n1z * c23z);\r\n point.x = (-c23x * d1 - c31x * d2 - c12x * d3) * invDot;\r\n point.y = (-c23y * d1 - c31y * d2 - c12y * d3) * invDot;\r\n point.z = (-c23z * d1 - c31z * d2 - c12z * d3) * invDot;\r\n return point;\r\n }\r\n\r\n /**\r\n * Compute the eye/origin of the perspective frustum transformation defined by this
matrix, \r\n * which can be a projection matrix or a combined modelview-projection matrix, and store the result\r\n * in the given origin
.\r\n *
\r\n * Note that this method will only work using perspective projections obtained via one of the\r\n * perspective methods, such as {@link #perspective(float, float, float, float) perspective()}\r\n * or {@link #frustum(float, float, float, float, float, float) frustum()}.\r\n *
\r\n * Generally, this method computes the origin in the local frame of\r\n * any coordinate system that existed before this
\r\n * transformation was applied to it in order to yield homogeneous clipping space.\r\n *
\r\n * Reference: http://geomalgorithms.com\r\n *
\r\n * Reference: \r\n * Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix\r\n * \r\n * @param origin\r\n * will hold the origin of the coordinate system before applying this
\r\n * perspective projection transformation\r\n * @return origin\r\n */\r\n public Vector3f perspectiveOrigin(Vector3f origin) {\r\n /*\r\n * Simply compute the intersection point of the left, right and top frustum plane.\r\n */\r\n float d1, d2, d3;\r\n float n1x, n1y, n1z, n2x, n2y, n2z, n3x, n3y, n3z;\r\n n1x = m03 + m00; n1y = m13 + m10; n1z = m23 + m20; d1 = m33 + m30; // left\r\n n2x = m03 - m00; n2y = m13 - m10; n2z = m23 - m20; d2 = m33 - m30; // right\r\n n3x = m03 - m01; n3y = m13 - m11; n3z = m23 - m21; d3 = m33 - m31; // top\r\n float c23x, c23y, c23z;\r\n c23x = n2y * n3z - n2z * n3y;\r\n c23y = n2z * n3x - n2x * n3z;\r\n c23z = n2x * n3y - n2y * n3x;\r\n float c31x, c31y, c31z;\r\n c31x = n3y * n1z - n3z * n1y;\r\n c31y = n3z * n1x - n3x * n1z;\r\n c31z = n3x * n1y - n3y * n1x;\r\n float c12x, c12y, c12z;\r\n c12x = n1y * n2z - n1z * n2y;\r\n c12y = n1z * n2x - n1x * n2z;\r\n c12z = n1x * n2y - n1y * n2x;\r\n float invDot = 1.0f / (n1x * c23x + n1y * c23y + n1z * c23z);\r\n origin.x = (-c23x * d1 - c31x * d2 - c12x * d3) * invDot;\r\n origin.y = (-c23y * d1 - c31y * d2 - c12y * d3) * invDot;\r\n origin.z = (-c23z * d1 - c31z * d2 - c12z * d3) * invDot;\r\n return origin;\r\n }\r\n\r\n /**\r\n * Return the vertical field-of-view angle in radians of this perspective transformation matrix.\r\n *
\r\n * Note that this method will only work using perspective projections obtained via one of the\r\n * perspective methods, such as {@link #perspective(float, float, float, float) perspective()}\r\n * or {@link #frustum(float, float, float, float, float, float) frustum()}.\r\n *
\r\n * For orthogonal transformations this method will return 0.0.\r\n *
\r\n * Reference: \r\n * Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix\r\n * \r\n * @return the vertical field-of-view angle in radians\r\n */\r\n public float perspectiveFov() {\r\n /*\r\n * Compute the angle between the bottom and top frustum plane normals.\r\n */\r\n float n1x, n1y, n1z, n2x, n2y, n2z;\r\n n1x = m03 + m01; n1y = m13 + m11; n1z = m23 + m21; // bottom\r\n n2x = m01 - m03; n2y = m11 - m13; n2z = m21 - m23; // top\r\n float n1len = (float) Math.sqrt(n1x * n1x + n1y * n1y + n1z * n1z);\r\n float n2len = (float) Math.sqrt(n2x * n2x + n2y * n2y + n2z * n2z);\r\n return (float) Math.acos((n1x * n2x + n1y * n2y + n1z * n2z) / (n1len * n2len));\r\n }\r\n\r\n /**\r\n * Extract the near clip plane distance from this
perspective projection matrix.\r\n *
\r\n * This method only works if this
is a perspective projection matrix, for example obtained via {@link #perspective(float, float, float, float)}.\r\n * \r\n * @return the near clip plane distance\r\n */\r\n public float perspectiveNear() {\r\n return m32 / (m23 + m22);\r\n }\r\n\r\n /**\r\n * Extract the far clip plane distance from this
perspective projection matrix.\r\n *
\r\n * This method only works if this
is a perspective projection matrix, for example obtained via {@link #perspective(float, float, float, float)}.\r\n * \r\n * @return the far clip plane distance\r\n */\r\n public float perspectiveFar() {\r\n return m32 / (m22 - m23);\r\n }\r\n\r\n /**\r\n * Obtain the direction of a ray starting at the center of the coordinate system and going \r\n * through the near frustum plane.\r\n *
\r\n * This method computes the dir
vector in the local frame of\r\n * any coordinate system that existed before this
\r\n * transformation was applied to it in order to yield homogeneous clipping space.\r\n *
\r\n * The parameters x
and y
are used to interpolate the generated ray direction\r\n * from the bottom-left to the top-right frustum corners.\r\n *
\r\n * For optimal efficiency when building many ray directions over the whole frustum,\r\n * it is recommended to use this method only in order to compute the four corner rays at\r\n * (0, 0), (1, 0), (0, 1) and (1, 1)\r\n * and then bilinearly interpolating between them; or to use the {@link FrustumRayBuilder}.\r\n *
\r\n * Reference: \r\n * Fast Extraction of Viewing Frustum Planes from the World-View-Projection Matrix\r\n * \r\n * @param x\r\n * the interpolation factor along the left-to-right frustum planes, within [0..1]\r\n * @param y\r\n * the interpolation factor along the bottom-to-top frustum planes, within [0..1]\r\n * @param dir\r\n * will hold the normalized ray direction in the local frame of the coordinate system before \r\n * transforming to homogeneous clipping space using this
matrix\r\n * @return dir\r\n */\r\n public Vector3f frustumRayDir(float x, float y, Vector3f dir) {\r\n /*\r\n * This method works by first obtaining the frustum plane normals,\r\n * then building the cross product to obtain the corner rays,\r\n * and finally bilinearly interpolating to obtain the desired direction.\r\n * The code below uses a condense form of doing all this making use \r\n * of some mathematical identities to simplify the overall expression.\r\n */\r\n float a = m10 * m23, b = m13 * m21, c = m10 * m21, d = m11 * m23, e = m13 * m20, f = m11 * m20;\r\n float g = m03 * m20, h = m01 * m23, i = m01 * m20, j = m03 * m21, k = m00 * m23, l = m00 * m21;\r\n float m = m00 * m13, n = m03 * m11, o = m00 * m11, p = m01 * m13, q = m03 * m10, r = m01 * m10;\r\n float m1x, m1y, m1z;\r\n m1x = (d + e + f - a - b - c) * (1.0f - y) + (a - b - c + d - e + f) * y;\r\n m1y = (j + k + l - g - h - i) * (1.0f - y) + (g - h - i + j - k + l) * y;\r\n m1z = (p + q + r - m - n - o) * (1.0f - y) + (m - n - o + p - q + r) * y;\r\n float m2x, m2y, m2z;\r\n m2x = (b - c - d + e + f - a) * (1.0f - y) + (a + b - c - d - e + f) * y;\r\n m2y = (h - i - j + k + l - g) * (1.0f - y) + (g + h - i - j - k + l) * y;\r\n m2z = (n - o - p + q + r - m) * (1.0f - y) + (m + n - o - p - q + r) * y;\r\n dir.x = m1x + (m2x - m1x) * x;\r\n dir.y = m1y + (m2y - m1y) * x;\r\n dir.z = m1z + (m2z - m1z) * x;\r\n dir.normalize();\r\n return dir;\r\n }\r\n\r\n /**\r\n * Obtain the direction of +Z before the transformation represented by this
matrix is applied.\r\n *
\r\n * This method uses the rotation component of the upper left 3x3 submatrix to obtain the direction \r\n * that is transformed to +Z by this
matrix.\r\n *
\r\n * This method is equivalent to the following code:\r\n *
\r\n * Matrix4f inv = new Matrix4f(this).invert();\r\n * inv.transformDirection(dir.set(0, 0, 1)).normalize();\r\n *
\r\n * If this
is already an orthogonal matrix, then consider using {@link #normalizedPositiveZ(Vector3f)} instead.\r\n * \r\n * Reference: http://www.euclideanspace.com\r\n * \r\n * @param dir\r\n * will hold the direction of +Z\r\n * @return dir\r\n */\r\n public Vector3f positiveZ(Vector3f dir) {\r\n dir.x = m10 * m21 - m11 * m20;\r\n dir.y = m20 * m01 - m21 * m00;\r\n dir.z = m00 * m11 - m01 * m10;\r\n dir.normalize();\r\n return dir;\r\n }\r\n\r\n /**\r\n * Obtain the direction of +Z before the transformation represented by this
orthogonal matrix is applied.\r\n * This method only produces correct results if this
is an orthogonal matrix.\r\n *
\r\n * This method uses the rotation component of the upper left 3x3 submatrix to obtain the direction \r\n * that is transformed to +Z by this
matrix.\r\n *
\r\n * This method is equivalent to the following code:\r\n *
\r\n * Matrix4f inv = new Matrix4f(this).transpose();\r\n * inv.transformDirection(dir.set(0, 0, 1)).normalize();\r\n *
\r\n * \r\n * Reference: http://www.euclideanspace.com\r\n * \r\n * @param dir\r\n * will hold the direction of +Z\r\n * @return dir\r\n */\r\n public Vector3f normalizedPositiveZ(Vector3f dir) {\r\n dir.x = m02;\r\n dir.y = m12;\r\n dir.z = m22;\r\n return dir;\r\n }\r\n\r\n /**\r\n * Obtain the direction of +X before the transformation represented by this
matrix is applied.\r\n *
\r\n * This method uses the rotation component of the upper left 3x3 submatrix to obtain the direction \r\n * that is transformed to +X by this
matrix.\r\n *
\r\n * This method is equivalent to the following code:\r\n *
\r\n * Matrix4f inv = new Matrix4f(this).invert();\r\n * inv.transformDirection(dir.set(1, 0, 0)).normalize();\r\n *
\r\n * If this
is already an orthogonal matrix, then consider using {@link #normalizedPositiveX(Vector3f)} instead.\r\n * \r\n * Reference: http://www.euclideanspace.com\r\n * \r\n * @param dir\r\n * will hold the direction of +X\r\n * @return dir\r\n */\r\n public Vector3f positiveX(Vector3f dir) {\r\n dir.x = m11 * m22 - m12 * m21;\r\n dir.y = m02 * m21 - m01 * m22;\r\n dir.z = m01 * m12 - m02 * m11;\r\n dir.normalize();\r\n return dir;\r\n }\r\n\r\n /**\r\n * Obtain the direction of +X before the transformation represented by this
orthogonal matrix is applied.\r\n * This method only produces correct results if this
is an orthogonal matrix.\r\n *
\r\n * This method uses the rotation component of the upper left 3x3 submatrix to obtain the direction \r\n * that is transformed to +X by this
matrix.\r\n *
\r\n * This method is equivalent to the following code:\r\n *
\r\n * Matrix4f inv = new Matrix4f(this).transpose();\r\n * inv.transformDirection(dir.set(1, 0, 0)).normalize();\r\n *
\r\n * \r\n * Reference: http://www.euclideanspace.com\r\n * \r\n * @param dir\r\n * will hold the direction of +X\r\n * @return dir\r\n */\r\n public Vector3f normalizedPositiveX(Vector3f dir) {\r\n dir.x = m00;\r\n dir.y = m10;\r\n dir.z = m20;\r\n return dir;\r\n }\r\n\r\n /**\r\n * Obtain the direction of +Y before the transformation represented by this
matrix is applied.\r\n *
\r\n * This method uses the rotation component of the upper left 3x3 submatrix to obtain the direction \r\n * that is transformed to +Y by this
matrix.\r\n *
\r\n * This method is equivalent to the following code:\r\n *
\r\n * Matrix4f inv = new Matrix4f(this).invert();\r\n * inv.transformDirection(dir.set(0, 1, 0)).normalize();\r\n *
\r\n * If this
is already an orthogonal matrix, then consider using {@link #normalizedPositiveY(Vector3f)} instead.\r\n * \r\n * Reference: http://www.euclideanspace.com\r\n * \r\n * @param dir\r\n * will hold the direction of +Y\r\n * @return dir\r\n */\r\n public Vector3f positiveY(Vector3f dir) {\r\n dir.x = m12 * m20 - m10 * m22;\r\n dir.y = m00 * m22 - m02 * m20;\r\n dir.z = m02 * m10 - m00 * m12;\r\n dir.normalize();\r\n return dir;\r\n }\r\n\r\n /**\r\n * Obtain the direction of +Y before the transformation represented by this
orthogonal matrix is applied.\r\n * This method only produces correct results if this
is an orthogonal matrix.\r\n *
\r\n * This method uses the rotation component of the upper left 3x3 submatrix to obtain the direction \r\n * that is transformed to +Y by this
matrix.\r\n *
\r\n * This method is equivalent to the following code:\r\n *
\r\n * Matrix4f inv = new Matrix4f(this).transpose();\r\n * inv.transformDirection(dir.set(0, 1, 0)).normalize();\r\n *
\r\n * \r\n * Reference: http://www.euclideanspace.com\r\n * \r\n * @param dir\r\n * will hold the direction of +Y\r\n * @return dir\r\n */\r\n public Vector3f normalizedPositiveY(Vector3f dir) {\r\n dir.x = m01;\r\n dir.y = m11;\r\n dir.z = m21;\r\n return dir;\r\n }\r\n\r\n /**\r\n * Obtain the position that gets transformed to the origin by this
{@link #isAffine() affine} matrix.\r\n * This can be used to get the position of the \"camera\" from a given view transformation matrix.\r\n *
\r\n * This method only works with {@link #isAffine() affine} matrices.\r\n *
\r\n * This method is equivalent to the following code:\r\n *
\r\n * Matrix4f inv = new Matrix4f(this).invertAffine();\r\n * inv.transformPosition(origin.set(0, 0, 0));\r\n *
\r\n * \r\n * @param origin\r\n * will hold the position transformed to the origin\r\n * @return origin\r\n */\r\n public Vector3f originAffine(Vector3f origin) {\r\n float a = m00 * m11 - m01 * m10;\r\n float b = m00 * m12 - m02 * m10;\r\n float d = m01 * m12 - m02 * m11;\r\n float g = m20 * m31 - m21 * m30;\r\n float h = m20 * m32 - m22 * m30;\r\n float j = m21 * m32 - m22 * m31;\r\n origin.x = -m10 * j + m11 * h - m12 * g;\r\n origin.y = m00 * j - m01 * h + m02 * g;\r\n origin.z = -m30 * d + m31 * b - m32 * a;\r\n return origin;\r\n }\r\n\r\n /**\r\n * Obtain the position that gets transformed to the origin by this
matrix.\r\n * This can be used to get the position of the \"camera\" from a given view/projection transformation matrix.\r\n * \r\n * This method is equivalent to the following code:\r\n *
\r\n * Matrix4f inv = new Matrix4f(this).invert();\r\n * inv.transformPosition(origin.set(0, 0, 0));\r\n *
\r\n * \r\n * @param origin\r\n * will hold the position transformed to the origin\r\n * @return origin\r\n */\r\n public Vector3f origin(Vector3f origin) {\r\n float a = m00 * m11 - m01 * m10;\r\n float b = m00 * m12 - m02 * m10;\r\n float c = m00 * m13 - m03 * m10;\r\n float d = m01 * m12 - m02 * m11;\r\n float e = m01 * m13 - m03 * m11;\r\n float f = m02 * m13 - m03 * m12;\r\n float g = m20 * m31 - m21 * m30;\r\n float h = m20 * m32 - m22 * m30;\r\n float i = m20 * m33 - m23 * m30;\r\n float j = m21 * m32 - m22 * m31;\r\n float k = m21 * m33 - m23 * m31;\r\n float l = m22 * m33 - m23 * m32;\r\n float det = a * l - b * k + c * j + d * i - e * h + f * g;\r\n float invDet = 1.0f / det;\r\n float nm30 = (-m10 * j + m11 * h - m12 * g) * invDet;\r\n float nm31 = ( m00 * j - m01 * h + m02 * g) * invDet;\r\n float nm32 = (-m30 * d + m31 * b - m32 * a) * invDet;\r\n float nm33 = det / ( m20 * d - m21 * b + m22 * a);\r\n float x = nm30 * nm33;\r\n float y = nm31 * nm33;\r\n float z = nm32 * nm33;\r\n return origin.set(x, y, z);\r\n }\r\n\r\n /**\r\n * Apply a projection transformation to this matrix that projects onto the plane specified via the general plane equation\r\n * x*a + y*b + z*c + d = 0 as if casting a shadow from a given light position/direction light
.\r\n * \r\n * If light.w is 0.0 the light is being treated as a directional light; if it is 1.0 it is a point light.\r\n *
\r\n * If M
is this
matrix and S
the shadow matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
, the\r\n * reflection will be applied first!\r\n *
\r\n * Reference: ftp.sgi.com\r\n * \r\n * @param light\r\n * the light's vector\r\n * @param a\r\n * the x factor in the plane equation\r\n * @param b\r\n * the y factor in the plane equation\r\n * @param c\r\n * the z factor in the plane equation\r\n * @param d\r\n * the constant in the plane equation\r\n * @return this\r\n */\r\n public Matrix4f shadow(Vector4f light, float a, float b, float c, float d) {\r\n return shadow(light.x, light.y, light.z, light.w, a, b, c, d, this);\r\n }\r\n\r\n /**\r\n * Apply a projection transformation to this matrix that projects onto the plane specified via the general plane equation\r\n * x*a + y*b + z*c + d = 0 as if casting a shadow from a given light position/direction light
\r\n * and store the result in dest
.\r\n *
\r\n * If light.w is 0.0 the light is being treated as a directional light; if it is 1.0 it is a point light.\r\n *
\r\n * If M
is this
matrix and S
the shadow matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
, the\r\n * reflection will be applied first!\r\n *
\r\n * Reference: ftp.sgi.com\r\n * \r\n * @param light\r\n * the light's vector\r\n * @param a\r\n * the x factor in the plane equation\r\n * @param b\r\n * the y factor in the plane equation\r\n * @param c\r\n * the z factor in the plane equation\r\n * @param d\r\n * the constant in the plane equation\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f shadow(Vector4f light, float a, float b, float c, float d, Matrix4f dest) {\r\n return shadow(light.x, light.y, light.z, light.w, a, b, c, d, dest);\r\n }\r\n\r\n /**\r\n * Apply a projection transformation to this matrix that projects onto the plane specified via the general plane equation\r\n * x*a + y*b + z*c + d = 0 as if casting a shadow from a given light position/direction (lightX, lightY, lightZ, lightW).\r\n *
\r\n * If lightW
is 0.0 the light is being treated as a directional light; if it is 1.0 it is a point light.\r\n *
\r\n * If M
is this
matrix and S
the shadow matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
, the\r\n * reflection will be applied first!\r\n *
\r\n * Reference: ftp.sgi.com\r\n * \r\n * @param lightX\r\n * the x-component of the light's vector\r\n * @param lightY\r\n * the y-component of the light's vector\r\n * @param lightZ\r\n * the z-component of the light's vector\r\n * @param lightW\r\n * the w-component of the light's vector\r\n * @param a\r\n * the x factor in the plane equation\r\n * @param b\r\n * the y factor in the plane equation\r\n * @param c\r\n * the z factor in the plane equation\r\n * @param d\r\n * the constant in the plane equation\r\n * @return this\r\n */\r\n public Matrix4f shadow(float lightX, float lightY, float lightZ, float lightW, float a, float b, float c, float d) {\r\n return shadow(lightX, lightY, lightZ, lightW, a, b, c, d, this);\r\n }\r\n\r\n /**\r\n * Apply a projection transformation to this matrix that projects onto the plane specified via the general plane equation\r\n * x*a + y*b + z*c + d = 0 as if casting a shadow from a given light position/direction (lightX, lightY, lightZ, lightW)\r\n * and store the result in dest
.\r\n *
\r\n * If lightW
is 0.0 the light is being treated as a directional light; if it is 1.0 it is a point light.\r\n *
\r\n * If M
is this
matrix and S
the shadow matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
, the\r\n * reflection will be applied first!\r\n *
\r\n * Reference: ftp.sgi.com\r\n * \r\n * @param lightX\r\n * the x-component of the light's vector\r\n * @param lightY\r\n * the y-component of the light's vector\r\n * @param lightZ\r\n * the z-component of the light's vector\r\n * @param lightW\r\n * the w-component of the light's vector\r\n * @param a\r\n * the x factor in the plane equation\r\n * @param b\r\n * the y factor in the plane equation\r\n * @param c\r\n * the z factor in the plane equation\r\n * @param d\r\n * the constant in the plane equation\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f shadow(float lightX, float lightY, float lightZ, float lightW, float a, float b, float c, float d, Matrix4f dest) {\r\n // normalize plane\r\n float invPlaneLen = (float) (1.0 / Math.sqrt(a*a + b*b + c*c));\r\n float an = a * invPlaneLen;\r\n float bn = b * invPlaneLen;\r\n float cn = c * invPlaneLen;\r\n float dn = d * invPlaneLen;\r\n\r\n float dot = an * lightX + bn * lightY + cn * lightZ + dn * lightW;\r\n\r\n // compute right matrix elements\r\n float rm00 = dot - an * lightX;\r\n float rm01 = -an * lightY;\r\n float rm02 = -an * lightZ;\r\n float rm03 = -an * lightW;\r\n float rm10 = -bn * lightX;\r\n float rm11 = dot - bn * lightY;\r\n float rm12 = -bn * lightZ;\r\n float rm13 = -bn * lightW;\r\n float rm20 = -cn * lightX;\r\n float rm21 = -cn * lightY;\r\n float rm22 = dot - cn * lightZ;\r\n float rm23 = -cn * lightW;\r\n float rm30 = -dn * lightX;\r\n float rm31 = -dn * lightY;\r\n float rm32 = -dn * lightZ;\r\n float rm33 = dot - dn * lightW;\r\n\r\n // matrix multiplication\r\n float nm00 = m00 * rm00 + m10 * rm01 + m20 * rm02 + m30 * rm03;\r\n float nm01 = m01 * rm00 + m11 * rm01 + m21 * rm02 + m31 * rm03;\r\n float nm02 = m02 * rm00 + m12 * rm01 + m22 * rm02 + m32 * rm03;\r\n float nm03 = m03 * rm00 + m13 * rm01 + m23 * rm02 + m33 * rm03;\r\n float nm10 = m00 * rm10 + m10 * rm11 + m20 * rm12 + m30 * rm13;\r\n float nm11 = m01 * rm10 + m11 * rm11 + m21 * rm12 + m31 * rm13;\r\n float nm12 = m02 * rm10 + m12 * rm11 + m22 * rm12 + m32 * rm13;\r\n float nm13 = m03 * rm10 + m13 * rm11 + m23 * rm12 + m33 * rm13;\r\n float nm20 = m00 * rm20 + m10 * rm21 + m20 * rm22 + m30 * rm23;\r\n float nm21 = m01 * rm20 + m11 * rm21 + m21 * rm22 + m31 * rm23;\r\n float nm22 = m02 * rm20 + m12 * rm21 + m22 * rm22 + m32 * rm23;\r\n float nm23 = m03 * rm20 + m13 * rm21 + m23 * rm22 + m33 * rm23;\r\n dest.m30 = m00 * rm30 + m10 * rm31 + m20 * rm32 + m30 * rm33;\r\n dest.m31 = m01 * rm30 + m11 * rm31 + m21 * rm32 + m31 * rm33;\r\n dest.m32 = m02 * rm30 + m12 * rm31 + m22 * rm32 + m32 * rm33;\r\n dest.m33 = m03 * rm30 + m13 * rm31 + m23 * rm32 + m33 * rm33;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply a projection transformation to this matrix that projects onto the plane with the general plane equation\r\n * y = 0 as if casting a shadow from a given light position/direction light
\r\n * and store the result in dest
.\r\n *
\r\n * Before the shadow projection is applied, the plane is transformed via the specified planeTransformation
.\r\n *
\r\n * If light.w is 0.0 the light is being treated as a directional light; if it is 1.0 it is a point light.\r\n *
\r\n * If M
is this
matrix and S
the shadow matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
, the\r\n * reflection will be applied first!\r\n * \r\n * @param light\r\n * the light's vector\r\n * @param planeTransform\r\n * the transformation to transform the implied plane y = 0 before applying the projection\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f shadow(Vector4f light, Matrix4f planeTransform, Matrix4f dest) {\r\n // compute plane equation by transforming (y = 0)\r\n float a = planeTransform.m10;\r\n float b = planeTransform.m11;\r\n float c = planeTransform.m12;\r\n float d = -a * planeTransform.m30 - b * planeTransform.m31 - c * planeTransform.m32;\r\n return shadow(light.x, light.y, light.z, light.w, a, b, c, d, dest);\r\n }\r\n\r\n /**\r\n * Apply a projection transformation to this matrix that projects onto the plane with the general plane equation\r\n * y = 0 as if casting a shadow from a given light position/direction light
.\r\n *
\r\n * Before the shadow projection is applied, the plane is transformed via the specified planeTransformation
.\r\n *
\r\n * If light.w is 0.0 the light is being treated as a directional light; if it is 1.0 it is a point light.\r\n *
\r\n * If M
is this
matrix and S
the shadow matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
, the\r\n * reflection will be applied first!\r\n * \r\n * @param light\r\n * the light's vector\r\n * @param planeTransform\r\n * the transformation to transform the implied plane y = 0 before applying the projection\r\n * @return this\r\n */\r\n public Matrix4f shadow(Vector4f light, Matrix4f planeTransform) {\r\n return shadow(light, planeTransform, this);\r\n }\r\n\r\n /**\r\n * Apply a projection transformation to this matrix that projects onto the plane with the general plane equation\r\n * y = 0 as if casting a shadow from a given light position/direction (lightX, lightY, lightZ, lightW)\r\n * and store the result in dest
.\r\n *
\r\n * Before the shadow projection is applied, the plane is transformed via the specified planeTransformation
.\r\n *
\r\n * If lightW
is 0.0 the light is being treated as a directional light; if it is 1.0 it is a point light.\r\n *
\r\n * If M
is this
matrix and S
the shadow matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
, the\r\n * reflection will be applied first!\r\n * \r\n * @param lightX\r\n * the x-component of the light vector\r\n * @param lightY\r\n * the y-component of the light vector\r\n * @param lightZ\r\n * the z-component of the light vector\r\n * @param lightW\r\n * the w-component of the light vector\r\n * @param planeTransform\r\n * the transformation to transform the implied plane y = 0 before applying the projection\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f shadow(float lightX, float lightY, float lightZ, float lightW, Matrix4f planeTransform, Matrix4f dest) {\r\n // compute plane equation by transforming (y = 0)\r\n float a = planeTransform.m10;\r\n float b = planeTransform.m11;\r\n float c = planeTransform.m12;\r\n float d = -a * planeTransform.m30 - b * planeTransform.m31 - c * planeTransform.m32;\r\n return shadow(lightX, lightY, lightZ, lightW, a, b, c, d, dest);\r\n }\r\n\r\n /**\r\n * Apply a projection transformation to this matrix that projects onto the plane with the general plane equation\r\n * y = 0 as if casting a shadow from a given light position/direction (lightX, lightY, lightZ, lightW).\r\n *
\r\n * Before the shadow projection is applied, the plane is transformed via the specified planeTransformation
.\r\n *
\r\n * If lightW
is 0.0 the light is being treated as a directional light; if it is 1.0 it is a point light.\r\n *
\r\n * If M
is this
matrix and S
the shadow matrix,\r\n * then the new matrix will be M * S
. So when transforming a\r\n * vector v
with the new matrix by using M * S * v
, the\r\n * reflection will be applied first!\r\n * \r\n * @param lightX\r\n * the x-component of the light vector\r\n * @param lightY\r\n * the y-component of the light vector\r\n * @param lightZ\r\n * the z-component of the light vector\r\n * @param lightW\r\n * the w-component of the light vector\r\n * @param planeTransform\r\n * the transformation to transform the implied plane y = 0 before applying the projection\r\n * @return this\r\n */\r\n public Matrix4f shadow(float lightX, float lightY, float lightZ, float lightW, Matrix4f planeTransform) {\r\n return shadow(lightX, lightY, lightZ, lightW, planeTransform, this);\r\n }\r\n\r\n /**\r\n * Set this matrix to a cylindrical billboard transformation that rotates the local +Z axis of a given object with position objPos
towards\r\n * a target position at targetPos
while constraining a cylindrical rotation around the given up
vector.\r\n *
\r\n * This method can be used to create the complete model transformation for a given object, including the translation of the object to\r\n * its position objPos
.\r\n * \r\n * @param objPos\r\n * the position of the object to rotate towards targetPos
\r\n * @param targetPos\r\n * the position of the target (for example the camera) towards which to rotate the object\r\n * @param up\r\n * the rotation axis (must be {@link Vector3f#normalize() normalized})\r\n * @return this\r\n */\r\n public Matrix4f billboardCylindrical(Vector3f objPos, Vector3f targetPos, Vector3f up) {\r\n float dirX = targetPos.x - objPos.x;\r\n float dirY = targetPos.y - objPos.y;\r\n float dirZ = targetPos.z - objPos.z;\r\n // left = up x dir\r\n float leftX = up.y * dirZ - up.z * dirY;\r\n float leftY = up.z * dirX - up.x * dirZ;\r\n float leftZ = up.x * dirY - up.y * dirX;\r\n // normalize left\r\n float invLeftLen = 1.0f / (float) Math.sqrt(leftX * leftX + leftY * leftY + leftZ * leftZ);\r\n leftX *= invLeftLen;\r\n leftY *= invLeftLen;\r\n leftZ *= invLeftLen;\r\n // recompute dir by constraining rotation around 'up'\r\n // dir = left x up\r\n dirX = leftY * up.z - leftZ * up.y;\r\n dirY = leftZ * up.x - leftX * up.z;\r\n dirZ = leftX * up.y - leftY * up.x;\r\n // normalize dir\r\n float invDirLen = 1.0f / (float) Math.sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);\r\n dirX *= invDirLen;\r\n dirY *= invDirLen;\r\n dirZ *= invDirLen;\r\n // set matrix elements\r\n m00 = leftX;\r\n m01 = leftY;\r\n m02 = leftZ;\r\n m03 = 0.0f;\r\n m10 = up.x;\r\n m11 = up.y;\r\n m12 = up.z;\r\n m13 = 0.0f;\r\n m20 = dirX;\r\n m21 = dirY;\r\n m22 = dirZ;\r\n m23 = 0.0f;\r\n m30 = objPos.x;\r\n m31 = objPos.y;\r\n m32 = objPos.z;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to a spherical billboard transformation that rotates the local +Z axis of a given object with position objPos
towards\r\n * a target position at targetPos
.\r\n *
\r\n * This method can be used to create the complete model transformation for a given object, including the translation of the object to\r\n * its position objPos
.\r\n *
\r\n * If preserving an up vector is not necessary when rotating the +Z axis, then a shortest arc rotation can be obtained \r\n * using {@link #billboardSpherical(Vector3f, Vector3f)}.\r\n * \r\n * @see #billboardSpherical(Vector3f, Vector3f)\r\n * \r\n * @param objPos\r\n * the position of the object to rotate towards targetPos
\r\n * @param targetPos\r\n * the position of the target (for example the camera) towards which to rotate the object\r\n * @param up\r\n * the up axis used to orient the object\r\n * @return this\r\n */\r\n public Matrix4f billboardSpherical(Vector3f objPos, Vector3f targetPos, Vector3f up) {\r\n float dirX = targetPos.x - objPos.x;\r\n float dirY = targetPos.y - objPos.y;\r\n float dirZ = targetPos.z - objPos.z;\r\n // normalize dir\r\n float invDirLen = 1.0f / (float) Math.sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);\r\n dirX *= invDirLen;\r\n dirY *= invDirLen;\r\n dirZ *= invDirLen;\r\n // left = up x dir\r\n float leftX = up.y * dirZ - up.z * dirY;\r\n float leftY = up.z * dirX - up.x * dirZ;\r\n float leftZ = up.x * dirY - up.y * dirX;\r\n // normalize left\r\n float invLeftLen = 1.0f / (float) Math.sqrt(leftX * leftX + leftY * leftY + leftZ * leftZ);\r\n leftX *= invLeftLen;\r\n leftY *= invLeftLen;\r\n leftZ *= invLeftLen;\r\n // up = dir x left\r\n float upX = dirY * leftZ - dirZ * leftY;\r\n float upY = dirZ * leftX - dirX * leftZ;\r\n float upZ = dirX * leftY - dirY * leftX;\r\n // set matrix elements\r\n m00 = leftX;\r\n m01 = leftY;\r\n m02 = leftZ;\r\n m03 = 0.0f;\r\n m10 = upX;\r\n m11 = upY;\r\n m12 = upZ;\r\n m13 = 0.0f;\r\n m20 = dirX;\r\n m21 = dirY;\r\n m22 = dirZ;\r\n m23 = 0.0f;\r\n m30 = objPos.x;\r\n m31 = objPos.y;\r\n m32 = objPos.z;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n /**\r\n * Set this matrix to a spherical billboard transformation that rotates the local +Z axis of a given object with position objPos
towards\r\n * a target position at targetPos
using a shortest arc rotation by not preserving any up vector of the object.\r\n *
\r\n * This method can be used to create the complete model transformation for a given object, including the translation of the object to\r\n * its position objPos
.\r\n *
\r\n * In order to specify an up vector which needs to be maintained when rotating the +Z axis of the object,\r\n * use {@link #billboardSpherical(Vector3f, Vector3f, Vector3f)}.\r\n * \r\n * @see #billboardSpherical(Vector3f, Vector3f, Vector3f)\r\n * \r\n * @param objPos\r\n * the position of the object to rotate towards targetPos
\r\n * @param targetPos\r\n * the position of the target (for example the camera) towards which to rotate the object\r\n * @return this\r\n */\r\n public Matrix4f billboardSpherical(Vector3f objPos, Vector3f targetPos) {\r\n float toDirX = targetPos.x - objPos.x;\r\n float toDirY = targetPos.y - objPos.y;\r\n float toDirZ = targetPos.z - objPos.z;\r\n float x = -toDirY;\r\n float y = toDirX;\r\n float w = (float) Math.sqrt(toDirX * toDirX + toDirY * toDirY + toDirZ * toDirZ) + toDirZ;\r\n float invNorm = (float) (1.0 / Math.sqrt(x * x + y * y + w * w));\r\n x *= invNorm;\r\n y *= invNorm;\r\n w *= invNorm;\r\n float q00 = (x + x) * x;\r\n float q11 = (y + y) * y;\r\n float q01 = (x + x) * y;\r\n float q03 = (x + x) * w;\r\n float q13 = (y + y) * w;\r\n m00 = 1.0f - q11;\r\n m01 = q01;\r\n m02 = -q13;\r\n m03 = 0.0f;\r\n m10 = q01;\r\n m11 = 1.0f - q00;\r\n m12 = q03;\r\n m13 = 0.0f;\r\n m20 = q13;\r\n m21 = -q03;\r\n m22 = 1.0f - q11 - q00;\r\n m23 = 0.0f;\r\n m30 = objPos.x;\r\n m31 = objPos.y;\r\n m32 = objPos.z;\r\n m33 = 1.0f;\r\n return this;\r\n }\r\n\r\n public int hashCode() {\r\n final int prime = 31;\r\n int result = 1;\r\n result = prime * result + Float.floatToIntBits(m00);\r\n result = prime * result + Float.floatToIntBits(m01);\r\n result = prime * result + Float.floatToIntBits(m02);\r\n result = prime * result + Float.floatToIntBits(m03);\r\n result = prime * result + Float.floatToIntBits(m10);\r\n result = prime * result + Float.floatToIntBits(m11);\r\n result = prime * result + Float.floatToIntBits(m12);\r\n result = prime * result + Float.floatToIntBits(m13);\r\n result = prime * result + Float.floatToIntBits(m20);\r\n result = prime * result + Float.floatToIntBits(m21);\r\n result = prime * result + Float.floatToIntBits(m22);\r\n result = prime * result + Float.floatToIntBits(m23);\r\n result = prime * result + Float.floatToIntBits(m30);\r\n result = prime * result + Float.floatToIntBits(m31);\r\n result = prime * result + Float.floatToIntBits(m32);\r\n result = prime * result + Float.floatToIntBits(m33);\r\n return result;\r\n }\r\n\r\n public boolean equals(Object obj) {\r\n if (this == obj)\r\n return true;\r\n if (obj == null)\r\n return false;\r\n if (!(obj instanceof Matrix4f))\r\n return false;\r\n Matrix4f other = (Matrix4f) obj;\r\n if (Float.floatToIntBits(m00) != Float.floatToIntBits(other.m00))\r\n return false;\r\n if (Float.floatToIntBits(m01) != Float.floatToIntBits(other.m01))\r\n return false;\r\n if (Float.floatToIntBits(m02) != Float.floatToIntBits(other.m02))\r\n return false;\r\n if (Float.floatToIntBits(m03) != Float.floatToIntBits(other.m03))\r\n return false;\r\n if (Float.floatToIntBits(m10) != Float.floatToIntBits(other.m10))\r\n return false;\r\n if (Float.floatToIntBits(m11) != Float.floatToIntBits(other.m11))\r\n return false;\r\n if (Float.floatToIntBits(m12) != Float.floatToIntBits(other.m12))\r\n return false;\r\n if (Float.floatToIntBits(m13) != Float.floatToIntBits(other.m13))\r\n return false;\r\n if (Float.floatToIntBits(m20) != Float.floatToIntBits(other.m20))\r\n return false;\r\n if (Float.floatToIntBits(m21) != Float.floatToIntBits(other.m21))\r\n return false;\r\n if (Float.floatToIntBits(m22) != Float.floatToIntBits(other.m22))\r\n return false;\r\n if (Float.floatToIntBits(m23) != Float.floatToIntBits(other.m23))\r\n return false;\r\n if (Float.floatToIntBits(m30) != Float.floatToIntBits(other.m30))\r\n return false;\r\n if (Float.floatToIntBits(m31) != Float.floatToIntBits(other.m31))\r\n return false;\r\n if (Float.floatToIntBits(m32) != Float.floatToIntBits(other.m32))\r\n return false;\r\n if (Float.floatToIntBits(m33) != Float.floatToIntBits(other.m33))\r\n return false;\r\n return true;\r\n }\r\n\r\n /**\r\n * Apply a picking transformation to this matrix using the given window coordinates (x, y) as the pick center\r\n * and the given (width, height) as the size of the picking region in window coordinates, and store the result\r\n * in dest
.\r\n * \r\n * @param x\r\n * the x coordinate of the picking region center in window coordinates\r\n * @param y\r\n * the y coordinate of the picking region center in window coordinates\r\n * @param width\r\n * the width of the picking region in window coordinates\r\n * @param height\r\n * the height of the picking region in window coordinates\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @param dest\r\n * the destination matrix, which will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f pick(float x, float y, float width, float height, int[] viewport, Matrix4f dest) {\r\n float sx = viewport[2] / width;\r\n float sy = viewport[3] / height;\r\n float tx = (viewport[2] + 2.0f * (viewport[0] - x)) / width;\r\n float ty = (viewport[3] + 2.0f * (viewport[1] - y)) / height;\r\n dest.m30 = m00 * tx + m10 * ty + m30;\r\n dest.m31 = m01 * tx + m11 * ty + m31;\r\n dest.m32 = m02 * tx + m12 * ty + m32;\r\n dest.m33 = m03 * tx + m13 * ty + m33;\r\n dest.m00 = m00 * sx;\r\n dest.m01 = m01 * sx;\r\n dest.m02 = m02 * sx;\r\n dest.m03 = m03 * sx;\r\n dest.m10 = m10 * sy;\r\n dest.m11 = m11 * sy;\r\n dest.m12 = m12 * sy;\r\n dest.m13 = m13 * sy;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply a picking transformation to this matrix using the given window coordinates (x, y) as the pick center\r\n * and the given (width, height) as the size of the picking region in window coordinates.\r\n * \r\n * @param x\r\n * the x coordinate of the picking region center in window coordinates\r\n * @param y\r\n * the y coordinate of the picking region center in window coordinates\r\n * @param width\r\n * the width of the picking region in window coordinates\r\n * @param height\r\n * the height of the picking region in window coordinates\r\n * @param viewport\r\n * the viewport described by [x, y, width, height]\r\n * @return this\r\n */\r\n public Matrix4f pick(float x, float y, float width, float height, int[] viewport) {\r\n return pick(x, y, width, height, viewport, this);\r\n }\r\n\r\n /**\r\n * Determine whether this matrix describes an affine transformation. This is the case iff its last row is equal to (0, 0, 0, 1).\r\n * \r\n * @return true
iff this matrix is affine; false
otherwise\r\n */\r\n public boolean isAffine() {\r\n return m03 == 0.0f && m13 == 0.0f && m23 == 0.0f && m33 == 1.0f;\r\n }\r\n\r\n /**\r\n * Exchange the values of this
matrix with the given other
matrix.\r\n * \r\n * @param other\r\n * the other matrix to exchange the values with\r\n * @return this\r\n */\r\n public Matrix4f swap(Matrix4f other) {\r\n float tmp;\r\n tmp = m00; m00 = other.m00; other.m00 = tmp;\r\n tmp = m01; m01 = other.m01; other.m01 = tmp;\r\n tmp = m02; m02 = other.m02; other.m02 = tmp;\r\n tmp = m03; m03 = other.m03; other.m03 = tmp;\r\n tmp = m10; m10 = other.m10; other.m10 = tmp;\r\n tmp = m11; m11 = other.m11; other.m11 = tmp;\r\n tmp = m12; m12 = other.m12; other.m12 = tmp;\r\n tmp = m13; m13 = other.m13; other.m13 = tmp;\r\n tmp = m20; m20 = other.m20; other.m20 = tmp;\r\n tmp = m21; m21 = other.m21; other.m21 = tmp;\r\n tmp = m22; m22 = other.m22; other.m22 = tmp;\r\n tmp = m23; m23 = other.m23; other.m23 = tmp;\r\n tmp = m30; m30 = other.m30; other.m30 = tmp;\r\n tmp = m31; m31 = other.m31; other.m31 = tmp;\r\n tmp = m32; m32 = other.m32; other.m32 = tmp;\r\n tmp = m33; m33 = other.m33; other.m33 = tmp;\r\n return this;\r\n }\r\n\r\n /**\r\n * Apply an arcball view transformation to this matrix with the given radius
and center (centerX, centerY, centerZ)\r\n * position of the arcball and the specified X and Y rotation angles, and store the result in dest
.\r\n *
\r\n * This method is equivalent to calling: translate(0, 0, -radius).rotateX(angleX).rotateY(angleY).translate(-centerX, -centerY, -centerZ)\r\n * \r\n * @param radius\r\n * the arcball radius\r\n * @param centerX\r\n * the x coordinate of the center position of the arcball\r\n * @param centerY\r\n * the y coordinate of the center position of the arcball\r\n * @param centerZ\r\n * the z coordinate of the center position of the arcball\r\n * @param angleX\r\n * the rotation angle around the X axis in radians\r\n * @param angleY\r\n * the rotation angle around the Y axis in radians\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f arcball(float radius, float centerX, float centerY, float centerZ, float angleX, float angleY, Matrix4f dest) {\r\n float m30 = m20 * -radius + this.m30;\r\n float m31 = m21 * -radius + this.m31;\r\n float m32 = m22 * -radius + this.m32;\r\n float m33 = m23 * -radius + this.m33;\r\n float cos = (float) Math.cos(angleX);\r\n float sin = (float) Math.sin(angleX);\r\n float nm10 = m10 * cos + m20 * sin;\r\n float nm11 = m11 * cos + m21 * sin;\r\n float nm12 = m12 * cos + m22 * sin;\r\n float nm13 = m13 * cos + m23 * sin;\r\n float m20 = this.m20 * cos - m10 * sin;\r\n float m21 = this.m21 * cos - m11 * sin;\r\n float m22 = this.m22 * cos - m12 * sin;\r\n float m23 = this.m23 * cos - m13 * sin;\r\n cos = (float) Math.cos(angleY);\r\n sin = (float) Math.sin(angleY);\r\n float nm00 = m00 * cos - m20 * sin;\r\n float nm01 = m01 * cos - m21 * sin;\r\n float nm02 = m02 * cos - m22 * sin;\r\n float nm03 = m03 * cos - m23 * sin;\r\n float nm20 = m00 * sin + m20 * cos;\r\n float nm21 = m01 * sin + m21 * cos;\r\n float nm22 = m02 * sin + m22 * cos;\r\n float nm23 = m03 * sin + m23 * cos;\r\n dest.m30 = -nm00 * centerX - nm10 * centerY - nm20 * centerZ + m30;\r\n dest.m31 = -nm01 * centerX - nm11 * centerY - nm21 * centerZ + m31;\r\n dest.m32 = -nm02 * centerX - nm12 * centerY - nm22 * centerZ + m32;\r\n dest.m33 = -nm03 * centerX - nm13 * centerY - nm23 * centerZ + m33;\r\n dest.m20 = nm20;\r\n dest.m21 = nm21;\r\n dest.m22 = nm22;\r\n dest.m23 = nm23;\r\n dest.m10 = nm10;\r\n dest.m11 = nm11;\r\n dest.m12 = nm12;\r\n dest.m13 = nm13;\r\n dest.m00 = nm00;\r\n dest.m01 = nm01;\r\n dest.m02 = nm02;\r\n dest.m03 = nm03;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Apply an arcball view transformation to this matrix with the given radius
and center
\r\n * position of the arcball and the specified X and Y rotation angles, and store the result in dest
.\r\n *
\r\n * This method is equivalent to calling: translate(0, 0, -radius).rotateX(angleX).rotateY(angleY).translate(-center.x, -center.y, -center.z)\r\n * \r\n * @param radius\r\n * the arcball radius\r\n * @param center\r\n * the center position of the arcball\r\n * @param angleX\r\n * the rotation angle around the X axis in radians\r\n * @param angleY\r\n * the rotation angle around the Y axis in radians\r\n * @param dest\r\n * will hold the result\r\n * @return dest\r\n */\r\n public Matrix4f arcball(float radius, Vector3f center, float angleX, float angleY, Matrix4f dest) {\r\n return arcball(radius, center.x, center.y, center.z, angleX, angleY, dest);\r\n }\r\n\r\n /**\r\n * Apply an arcball view transformation to this matrix with the given radius
and center (centerX, centerY, centerZ)\r\n * position of the arcball and the specified X and Y rotation angles.\r\n *
\r\n * This method is equivalent to calling: translate(0, 0, -radius).rotateX(angleX).rotateY(angleY).translate(-centerX, -centerY, -centerZ)\r\n * \r\n * @param radius\r\n * the arcball radius\r\n * @param centerX\r\n * the x coordinate of the center position of the arcball\r\n * @param centerY\r\n * the y coordinate of the center position of the arcball\r\n * @param centerZ\r\n * the z coordinate of the center position of the arcball\r\n * @param angleX\r\n * the rotation angle around the X axis in radians\r\n * @param angleY\r\n * the rotation angle around the Y axis in radians\r\n * @return dest\r\n */\r\n public Matrix4f arcball(float radius, float centerX, float centerY, float centerZ, float angleX, float angleY) {\r\n return arcball(radius, centerX, centerY, centerZ, angleX, angleY, this);\r\n }\r\n\r\n /**\r\n * Apply an arcball view transformation to this matrix with the given radius
and center
\r\n * position of the arcball and the specified X and Y rotation angles.\r\n *
\r\n * This method is equivalent to calling: translate(0, 0, -radius).rotateX(angleX).rotateY(angleY).translate(-center.x, -center.y, -center.z)\r\n * \r\n * @param radius\r\n * the arcball radius\r\n * @param center\r\n * the center position of the arcball\r\n * @param angleX\r\n * the rotation angle around the X axis in radians\r\n * @param angleY\r\n * the rotation angle around the Y axis in radians\r\n * @return this\r\n */\r\n public Matrix4f arcball(float radius, Vector3f center, float angleX, float angleY) {\r\n return arcball(radius, center.x, center.y, center.z, angleX, angleY, this);\r\n }\r\n\r\n /**\r\n * Compute the axis-aligned bounding box of the frustum described by this
matrix and store the minimum corner\r\n * coordinates in the given min
and the maximum corner coordinates in the given max
vector.\r\n *
\r\n * The matrix this
is assumed to be the {@link #invert() inverse} of the origial view-projection matrix\r\n * for which to compute the axis-aligned bounding box in world-space.\r\n *
\r\n * The axis-aligned bounding box of the unit frustum is (-1, -1, -1), (1, 1, 1).\r\n * \r\n * @param min\r\n * will hold the minimum corner coordinates of the axis-aligned bounding box\r\n * @param max\r\n * will hold the maximum corner coordinates of the axis-aligned bounding box\r\n * @return this\r\n */\r\n public Matrix4f frustumAabb(Vector3f min, Vector3f max) {\r\n float minX = Float.MAX_VALUE;\r\n float minY = Float.MAX_VALUE;\r\n float minZ = Float.MAX_VALUE;\r\n float maxX = -Float.MAX_VALUE;\r\n float maxY = -Float.MAX_VALUE;\r\n float maxZ = -Float.MAX_VALUE;\r\n for (int t = 0; t < 8; t++) {\r\n float x = ((t & 1) << 1) - 1.0f;\r\n float y = (((t >>> 1) & 1) << 1) - 1.0f;\r\n float z = (((t >>> 2) & 1) << 1) - 1.0f;\r\n float invW = 1.0f / (m03 * x + m13 * y + m23 * z + m33);\r\n float nx = (m00 * x + m10 * y + m20 * z + m30) * invW;\r\n float ny = (m01 * x + m11 * y + m21 * z + m31) * invW;\r\n float nz = (m02 * x + m12 * y + m22 * z + m32) * invW;\r\n minX = minX < nx ? minX : nx;\r\n minY = minY < ny ? minY : ny;\r\n minZ = minZ < nz ? minZ : nz;\r\n maxX = maxX > nx ? maxX : nx;\r\n maxY = maxY > ny ? maxY : ny;\r\n maxZ = maxZ > nz ? maxZ : nz;\r\n }\r\n min.x = minX;\r\n min.y = minY;\r\n min.z = minZ;\r\n max.x = maxX;\r\n max.y = maxY;\r\n max.z = maxZ;\r\n return this;\r\n }\r\n\r\n /**\r\n * Compute the range matrix for the Projected Grid transformation as described in chapter \"2.4.2 Creating the range conversion matrix\"\r\n * of the paper Real-time water rendering - Introducing the projected grid concept\r\n * based on the inverse of the view-projection matrix which is assumed to be this
, and store that range matrix into dest
.\r\n *
\r\n * If the projected grid will not be visible then this method returns null
.\r\n *
\r\n * This method uses the y = 0 plane for the projection.\r\n * \r\n * @param projector\r\n * the projector view-projection transformation\r\n * @param sLower\r\n * the lower (smallest) Y-coordinate which any transformed vertex might have while still being visible on the projected grid\r\n * @param sUpper\r\n * the upper (highest) Y-coordinate which any transformed vertex might have while still being visible on the projected grid\r\n * @param dest\r\n * will hold the resulting range matrix\r\n * @return the computed range matrix; or null
if the projected grid will not be visible\r\n */\r\n public Matrix4f projectedGridRange(Matrix4f projector, float sLower, float sUpper, Matrix4f dest) {\r\n // Compute intersection with frustum edges and plane\r\n float minX = Float.MAX_VALUE, minY = Float.MAX_VALUE;\r\n float maxX = -Float.MAX_VALUE, maxY = -Float.MAX_VALUE;\r\n boolean intersection = false;\r\n for (int t = 0; t < 3 * 4; t++) {\r\n float c0X, c0Y, c0Z;\r\n float c1X, c1Y, c1Z;\r\n if (t < 4) {\r\n // all x edges\r\n c0X = -1; c1X = +1;\r\n c0Y = c1Y = ((t & 1) << 1) - 1.0f;\r\n c0Z = c1Z = (((t >>> 1) & 1) << 1) - 1.0f;\r\n } else if (t < 8) {\r\n // all y edges\r\n c0Y = -1; c1Y = +1;\r\n c0X = c1X = ((t & 1) << 1) - 1.0f;\r\n c0Z = c1Z = (((t >>> 1) & 1) << 1) - 1.0f;\r\n } else {\r\n // all z edges\r\n c0Z = -1; c1Z = +1;\r\n c0X = c1X = ((t & 1) << 1) - 1.0f;\r\n c0Y = c1Y = (((t >>> 1) & 1) << 1) - 1.0f;\r\n }\r\n // unproject corners\r\n float invW = 1.0f / (m03 * c0X + m13 * c0Y + m23 * c0Z + m33);\r\n float p0x = (m00 * c0X + m10 * c0Y + m20 * c0Z + m30) * invW;\r\n float p0y = (m01 * c0X + m11 * c0Y + m21 * c0Z + m31) * invW;\r\n float p0z = (m02 * c0X + m12 * c0Y + m22 * c0Z + m32) * invW;\r\n invW = 1.0f / (m03 * c1X + m13 * c1Y + m23 * c1Z + m33);\r\n float p1x = (m00 * c1X + m10 * c1Y + m20 * c1Z + m30) * invW;\r\n float p1y = (m01 * c1X + m11 * c1Y + m21 * c1Z + m31) * invW;\r\n float p1z = (m02 * c1X + m12 * c1Y + m22 * c1Z + m32) * invW;\r\n float dirX = p1x - p0x;\r\n float dirY = p1y - p0y;\r\n float dirZ = p1z - p0z;\r\n float invDenom = 1.0f / dirY;\r\n // test for intersection\r\n for (int s = 0; s < 2; s++) {\r\n float isectT = -(p0y + (s == 0 ? sLower : sUpper)) * invDenom;\r\n if (isectT >= 0.0f && isectT <= 1.0f) {\r\n intersection = true;\r\n // project with projector matrix\r\n float ix = p0x + isectT * dirX;\r\n float iz = p0z + isectT * dirZ;\r\n invW = 1.0f / (projector.m03 * ix + projector.m23 * iz + projector.m33);\r\n float px = (projector.m00 * ix + projector.m20 * iz + projector.m30) * invW;\r\n float py = (projector.m01 * ix + projector.m21 * iz + projector.m31) * invW;\r\n minX = minX < px ? minX : px;\r\n minY = minY < py ? minY : py;\r\n maxX = maxX > px ? maxX : px;\r\n maxY = maxY > py ? maxY : py;\r\n }\r\n }\r\n }\r\n if (!intersection)\r\n return null; // <- projected grid is not visible\r\n return dest.set(maxX - minX, 0, 0, 0, 0, maxY - minY, 0, 0, 0, 0, 1, 0, minX, minY, 0, 1);\r\n }\r\n\r\n /**\r\n * Change the near and far clip plane distances of this
perspective frustum transformation matrix\r\n * and store the result in dest
.\r\n *
\r\n * This method only works if this
is a perspective projection frustum transformation, for example obtained\r\n * via {@link #perspective(float, float, float, float) perspective()} or {@link #frustum(float, float, float, float, float, float) frustum()}.\r\n * \r\n * @see #perspective(float, float, float, float)\r\n * @see #frustum(float, float, float, float, float, float)\r\n * \r\n * @param near\r\n * the new near clip plane distance\r\n * @param far\r\n * the new far clip plane distance\r\n * @param dest\r\n * will hold the resulting matrix\r\n * @return dest\r\n */\r\n public Matrix4f perspectiveFrustumSlice(float near, float far, Matrix4f dest) {\r\n float invOldNear = (m23 + m22) / m32;\r\n float invNearFar = 1.0f / (near - far);\r\n dest.m00 = m00 * invOldNear * near;\r\n dest.m01 = m01;\r\n dest.m02 = m02;\r\n dest.m03 = m03;\r\n dest.m10 = m10;\r\n dest.m11 = m11 * invOldNear * near;\r\n dest.m12 = m12;\r\n dest.m13 = m13;\r\n dest.m20 = m20;\r\n dest.m21 = m21;\r\n dest.m22 = (far + near) * invNearFar;\r\n dest.m23 = m23;\r\n dest.m30 = m30;\r\n dest.m31 = m31;\r\n dest.m32 = (far + far) * near * invNearFar;\r\n dest.m33 = m33;\r\n return dest;\r\n }\r\n\r\n /**\r\n * Build an ortographic projection transformation that fits the view-projection transformation represented by this
\r\n * into the given affine view
transformation.\r\n *
\r\n * The transformation represented by this
must be given as the {@link #invert() inverse} of a typical combined camera view-projection\r\n * transformation, whose projection can be either orthographic or perspective.\r\n *
\r\n * The view
must be an {@link #isAffine() affine} transformation which in the application of Cascaded Shadow Maps is usually the light view transformation.\r\n * It be obtained via any affine transformation or for example via {@link #lookAt(float, float, float, float, float, float, float, float, float) lookAt()}.\r\n *
\r\n * Reference: OpenGL SDK - Cascaded Shadow Maps\r\n * \r\n * @param view\r\n * the view transformation to build a corresponding orthographic projection to fit the frustum of this
\r\n * @param dest\r\n * will hold the crop projection transformation\r\n * @return dest\r\n */\r\n public Matrix4f orthoCrop(Matrix4f view, Matrix4f dest) {\r\n // determine min/max world z and min/max orthographically view-projected x/y\r\n float minX = Float.MAX_VALUE, maxX = -Float.MAX_VALUE;\r\n float minY = Float.MAX_VALUE, maxY = -Float.MAX_VALUE;\r\n float minZ = Float.MAX_VALUE, maxZ = -Float.MAX_VALUE;\r\n for (int t = 0; t < 8; t++) {\r\n float x = ((t & 1) << 1) - 1.0f;\r\n float y = (((t >>> 1) & 1) << 1) - 1.0f;\r\n float z = (((t >>> 2) & 1) << 1) - 1.0f;\r\n float invW = 1.0f / (m03 * x + m13 * y + m23 * z + m33);\r\n float wx = (m00 * x + m10 * y + m20 * z + m30) * invW;\r\n float wy = (m01 * x + m11 * y + m21 * z + m31) * invW;\r\n float wz = (m02 * x + m12 * y + m22 * z + m32) * invW;\r\n invW = 1.0f / (view.m03 * wx + view.m13 * wy + view.m23 * wz + view.m33);\r\n float vx = view.m00 * wx + view.m10 * wy + view.m20 * wz + view.m30;\r\n float vy = view.m01 * wx + view.m11 * wy + view.m21 * wz + view.m31;\r\n float vz = (view.m02 * wx + view.m12 * wy + view.m22 * wz + view.m32) * invW;\r\n minX = minX < vx ? minX : vx;\r\n maxX = maxX > vx ? maxX : vx;\r\n minY = minY < vy ? minY : vy;\r\n maxY = maxY > vy ? maxY : vy;\r\n minZ = minZ < vz ? minZ : vz;\r\n maxZ = maxZ > vz ? maxZ : vz;\r\n }\r\n // build crop projection matrix to fit 'this' frustum into view\r\n return dest.setOrtho(minX, maxX, minY, maxY, -maxZ, -minZ);\r\n }\r\n\r\n /**\r\n * Set this
matrix to a perspective transformation that maps the trapezoid spanned by the four corner coordinates\r\n * (p0x, p0y)
, (p1x, p1y)
, (p2x, p2y)
and (p3x, p3y)
to the unit square [(-1, -1)..(+1, +1)].\r\n *
\r\n * The corner coordinates are given in counter-clockwise order starting from the left corner on the smaller parallel side of the trapezoid\r\n * seen when looking at the trapezoid oriented with its shorter parallel edge at the bottom and its longer parallel edge at the top.\r\n *
\r\n * Reference: Notes On Implementation Of Trapezoidal Shadow Maps\r\n * \r\n * @param p0x\r\n * the x coordinate of the left corner at the shorter edge of the trapezoid\r\n * @param p0y\r\n * the y coordinate of the left corner at the shorter edge of the trapezoid\r\n * @param p1x\r\n * the x coordinate of the right corner at the shorter edge of the trapezoid\r\n * @param p1y\r\n * the y coordinate of the right corner at the shorter edge of the trapezoid\r\n * @param p2x\r\n * the x coordinate of the right corner at the longer edge of the trapezoid\r\n * @param p2y\r\n * the y coordinate of the right corner at the longer edge of the trapezoid\r\n * @param p3x\r\n * the x coordinate of the left corner at the longer edge of the trapezoid\r\n * @param p3y\r\n * the y coordinate of the left corner at the longer edge of the trapezoid\r\n * @return this\r\n */\r\n public Matrix4f trapezoidCrop(float p0x, float p0y, float p1x, float p1y, float p2x, float p2y, float p3x, float p3y) {\r\n float aX = p1y - p0y, aY = p0x - p1x;\r\n float m00 = aY;\r\n float m10 = -aX;\r\n float m30 = aX * p0y - aY * p0x;\r\n float m01 = aX;\r\n float m11 = aY;\r\n float m31 = -(aX * p0x + aY * p0y);\r\n float c3x = m00 * p3x + m10 * p3y + m30;\r\n float c3y = m01 * p3x + m11 * p3y + m31;\r\n float s = -c3x / c3y;\r\n m00 += s * m01;\r\n m10 += s * m11;\r\n m30 += s * m31;\r\n float d1x = m00 * p1x + m10 * p1y + m30;\r\n float d2x = m00 * p2x + m10 * p2y + m30;\r\n float d = d1x * c3y / (d2x - d1x);\r\n m31 += d;\r\n float sx = 2.0f / d2x;\r\n float sy = 1.0f / (c3y + d);\r\n float u = (sy + sy) * d / (1.0f - sy * d);\r\n float m03 = m01 * sy;\r\n float m13 = m11 * sy;\r\n float m33 = m31 * sy;\r\n m01 = (u + 1.0f) * m03;\r\n m11 = (u + 1.0f) * m13;\r\n m31 = (u + 1.0f) * m33 - u;\r\n m00 = sx * m00 - m03;\r\n m10 = sx * m10 - m13;\r\n m30 = sx * m30 - m33;\r\n return set(m00, m01, 0, m03,\r\n m10, m11, 0, m13,\r\n 0, 0, 1, 0,\r\n m30, m31, 0, m33);\r\n }\r\n\r\n /**\r\n * Transform the axis-aligned box given as the minimum corner (minX, minY, minZ) and maximum corner (maxX, maxY, maxZ)\r\n * by this
{@link #isAffine() affine} matrix and compute the axis-aligned box of the result whose minimum corner is stored in outMin
\r\n * and maximum corner stored in outMax
.\r\n *
\r\n * Reference: http://dev.theomader.com\r\n * \r\n * @param minX\r\n * the x coordinate of the minimum corner of the axis-aligned box\r\n * @param minY\r\n * the y coordinate of the minimum corner of the axis-aligned box\r\n * @param minZ\r\n * the z coordinate of the minimum corner of the axis-aligned box\r\n * @param maxX\r\n * the x coordinate of the maximum corner of the axis-aligned box\r\n * @param maxY\r\n * the y coordinate of the maximum corner of the axis-aligned box\r\n * @param maxZ\r\n * the y coordinate of the maximum corner of the axis-aligned box\r\n * @param outMin\r\n * will hold the minimum corner of the resulting axis-aligned box\r\n * @param outMax\r\n * will hold the maximum corner of the resulting axis-aligned box\r\n * @return this\r\n */\r\n public Matrix4f transformAab(float minX, float minY, float minZ, float maxX, float maxY, float maxZ, Vector3f outMin, Vector3f outMax) {\r\n float xax = m00 * minX, xay = m01 * minX, xaz = m02 * minX;\r\n float xbx = m00 * maxX, xby = m01 * maxX, xbz = m02 * maxX;\r\n float yax = m10 * minY, yay = m11 * minY, yaz = m12 * minY;\r\n float ybx = m10 * maxY, yby = m11 * maxY, ybz = m12 * maxY;\r\n float zax = m20 * minZ, zay = m21 * minZ, zaz = m22 * minZ;\r\n float zbx = m20 * maxZ, zby = m21 * maxZ, zbz = m22 * maxZ;\r\n float xminx, xminy, xminz, yminx, yminy, yminz, zminx, zminy, zminz;\r\n float xmaxx, xmaxy, xmaxz, ymaxx, ymaxy, ymaxz, zmaxx, zmaxy, zmaxz;\r\n if (xax < xbx) {\r\n xminx = xax;\r\n xmaxx = xbx;\r\n } else {\r\n xminx = xbx;\r\n xmaxx = xax;\r\n }\r\n if (xay < xby) {\r\n xminy = xay;\r\n xmaxy = xby;\r\n } else {\r\n xminy = xby;\r\n xmaxy = xay;\r\n }\r\n if (xaz < xbz) {\r\n xminz = xaz;\r\n xmaxz = xbz;\r\n } else {\r\n xminz = xbz;\r\n xmaxz = xaz;\r\n }\r\n if (yax < ybx) {\r\n yminx = yax;\r\n ymaxx = ybx;\r\n } else {\r\n yminx = ybx;\r\n ymaxx = yax;\r\n }\r\n if (yay < yby) {\r\n yminy = yay;\r\n ymaxy = yby;\r\n } else {\r\n yminy = yby;\r\n ymaxy = yay;\r\n }\r\n if (yaz < ybz) {\r\n yminz = yaz;\r\n ymaxz = ybz;\r\n } else {\r\n yminz = ybz;\r\n ymaxz = yaz;\r\n }\r\n if (zax < zbx) {\r\n zminx = zax;\r\n zmaxx = zbx;\r\n } else {\r\n zminx = zbx;\r\n zmaxx = zax;\r\n }\r\n if (zay < zby) {\r\n zminy = zay;\r\n zmaxy = zby;\r\n } else {\r\n zminy = zby;\r\n zmaxy = zay;\r\n }\r\n if (zaz < zbz) {\r\n zminz = zaz;\r\n zmaxz = zbz;\r\n } else {\r\n zminz = zbz;\r\n zmaxz = zaz;\r\n }\r\n outMin.x = xminx + yminx + zminx + m30;\r\n outMin.y = xminy + yminy + zminy + m31;\r\n outMin.z = xminz + yminz + zminz + m32;\r\n outMax.x = xmaxx + ymaxx + zmaxx + m30;\r\n outMax.y = xmaxy + ymaxy + zmaxy + m31;\r\n outMax.z = xmaxz + ymaxz + zmaxz + m32;\r\n return this;\r\n }\r\n\r\n /**\r\n * Transform the axis-aligned box given as the minimum corner min
and maximum corner max
\r\n * by this
{@link #isAffine() affine} matrix and compute the axis-aligned box of the result whose minimum corner is stored in outMin
\r\n * and maximum corner stored in outMax
.\r\n * \r\n * @param min\r\n * the minimum corner of the axis-aligned box\r\n * @param max\r\n * the maximum corner of the axis-aligned box\r\n * @param outMin\r\n * will hold the minimum corner of the resulting axis-aligned box\r\n * @param outMax\r\n * will hold the maximum corner of the resulting axis-aligned box\r\n * @return this\r\n */\r\n public Matrix4f transformAab(Vector3f min, Vector3f max, Vector3f outMin, Vector3f outMax) {\r\n return transformAab(min.x, min.y, min.z, max.x, max.y, max.z, outMin, outMax);\r\n }\r\n\r\n}\r\n"},"message":{"kind":"string","value":"Add Matrix4f.scaleLocal()"},"old_file":{"kind":"string","value":"src/org/joml/Matrix4f.java"},"subject":{"kind":"string","value":"Add Matrix4f.scaleLocal()"}}},{"rowIdx":1443,"cells":{"lang":{"kind":"string","value":"Java"},"license":{"kind":"string","value":"mit"},"stderr":{"kind":"string","value":""},"commit":{"kind":"string","value":"397c5257c54e4eeedb5b5bbd4a51c1d7e83d96b2"},"returncode":{"kind":"number","value":0,"string":"0"},"repos":{"kind":"string","value":"smblott-github/intent_radio,smblott-github/intent_radio,smblott-github/intent_radio"},"new_contents":{"kind":"string","value":"package org.smblott.intentradio;\n\nimport java.io.File;\nimport java.io.FileOutputStream;\n\nimport java.util.Date;\nimport java.text.DateFormat;\nimport java.text.SimpleDateFormat;\n\nimport android.content.Context;\nimport android.widget.Toast;\nimport android.util.Log;\n\npublic class Logger\n{\n private static Context context = null;\n private static boolean debugging = false;\n\n private static String name = null;\n private static FileOutputStream file = null;\n\n private static DateFormat format = null;\n\n /* ********************************************************************\n * Initialisation...\n */\n\n public static void init(Context acontext)\n {\n context = acontext;\n name = context.getString(R.string.app_name);\n }\n\n /* ********************************************************************\n * Enable/disable...\n */\n\n public static void state(String how)\n {\n if ( how.equals(\"debug\") || how.equals(\"yes\") || how.equals(\"on\") || how.equals(\"start\") )\n { start(); return; }\n\n if ( how.equals(\"nodebug\") || how.equals(\"no\") || how.equals(\"off\") || how.equals(\"stop\") )\n { stop(); return; }\n\n Log.d(name, \"Logger: invalid state: \" + how);\n }\n\n /* ********************************************************************\n * State changes...\n */\n\n private static void start()\n {\n if ( debugging )\n return;\n\n if ( format == null )\n format = new SimpleDateFormat(\"HH:mm:ss \");\n\n debugging = true;\n\n try\n {\n File log_file = new File(context.getExternalFilesDir(null), context.getString(R.string.intent_log_file));\n file = new FileOutputStream(log_file);\n }\n catch (Exception e)\n { file = null; }\n\n log(\"Logger: -> on\");\n }\n\n private static void stop()\n {\n log(\"Logger: -> off\");\n\n if ( file != null )\n {\n try { file.close(); }\n catch (Exception e) { }\n file = null;\n }\n\n debugging = false;\n }\n\n /* ********************************************************************\n * Logging methods...\n */\n\n public static void log(String msg)\n {\n if ( ! debugging || msg == null )\n return;\n\n msg = format.format(new Date()) + msg;\n\n Log.d(name, msg);\n log_file(msg);\n }\n\n public static void toast(String msg)\n {\n if ( msg == null )\n return;\n\n Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();\n log(msg);\n }\n\n private static void log_file(String msg)\n {\n if ( file != null )\n try\n {\n file.write((msg+\"\\n\").getBytes());\n file.flush();\n } catch (Exception e) {}\n }\n\n}\n"},"new_file":{"kind":"string","value":"src/org/smblott/intentradio/Logger.java"},"old_contents":{"kind":"string","value":"package org.smblott.intentradio;\n\nimport java.io.File;\nimport java.io.FileOutputStream;\n\nimport java.util.Date;\nimport java.text.DateFormat;\nimport java.text.SimpleDateFormat;\n\nimport android.content.Context;\nimport android.widget.Toast;\nimport android.util.Log;\n\npublic class Logger\n{\n private static Context context = null;\n private static boolean debugging = false;\n\n private static String name = null;\n private static FileOutputStream file = null;\n\n private static DateFormat format = null;\n\n /* ********************************************************************\n * Initialisation...\n */\n\n public static void init(Context acontext)\n {\n context = acontext;\n name = context.getString(R.string.app_name);\n }\n\n /* ********************************************************************\n * Enable/disable...\n */\n\n public static void state(String how)\n {\n if ( how.equals(\"debug\") || how.equals(\"yes\") || how.equals(\"on\") || how.equals(\"start\") )\n { start(); return; }\n\n if ( how.equals(\"nodebug\") || how.equals(\"no\") || how.equals(\"off\") || how.equals(\"stop\") )\n { stop(); return; }\n\n Log.d(name, \"Logger: invalid state: \" + how);\n }\n\n /* ********************************************************************\n * State changes...\n */\n\n private static void start()\n {\n if ( debugging )\n return;\n\n debugging = true;\n format = new SimpleDateFormat(\"HH:mm:ss \");\n\n try\n {\n File log_file = new File(context.getExternalFilesDir(null), context.getString(R.string.intent_log_file));\n file = new FileOutputStream(log_file);\n }\n catch (Exception e)\n { file = null; }\n\n log(\"Logger: -> on\");\n }\n\n private static void stop()\n {\n log(\"Logger: -> off\");\n\n if ( file != null )\n {\n try { file.close(); }\n catch (Exception e) { }\n file = null;\n }\n\n debugging = false;\n }\n\n /* ********************************************************************\n * Logging methods...\n */\n\n public static void log(String msg)\n {\n if ( ! debugging || msg == null )\n return;\n\n Log.d(name, msg);\n log_file(msg);\n }\n\n public static void toast(String msg)\n {\n if ( msg == null )\n return;\n\n Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();\n log(msg);\n }\n\n private static void log_file(String msg)\n {\n if ( file == null )\n return;\n\n String stamp = format.format(new Date());\n\n try\n {\n file.write((stamp+msg+\"\\n\").getBytes());\n file.flush();\n } catch (Exception e) {}\n }\n\n}\n"},"message":{"kind":"string","value":"Logger timestamps.\n"},"old_file":{"kind":"string","value":"src/org/smblott/intentradio/Logger.java"},"subject":{"kind":"string","value":"Logger timestamps."}}},{"rowIdx":1444,"cells":{"lang":{"kind":"string","value":"Java"},"license":{"kind":"string","value":"mit"},"stderr":{"kind":"string","value":""},"commit":{"kind":"string","value":"6698a79f23b55598cfeabbd1cfa8c5cb254273c0"},"returncode":{"kind":"number","value":0,"string":"0"},"repos":{"kind":"string","value":"Bouowmx/APCS"},"new_contents":{"kind":"string","value":"import static java.lang.System.out;\nimport java.util.ArrayDeque;\nimport java.util.Scanner;\n\npublic class RPNCalculator {\n\tprivate static ArrayDeque stack = new ArrayDeque();\n\t\n\tprivate RPNCalculator() {}\n\t\n\tpublic static Long evaluate(String expression) {\n\t\tif (!(expression.matches(\"[ 0-9+\\\\-\\\\*/%]*\")) || (expression.contains(\".\"))) {\n\t\t\tout.println(\"Invalid expression: only digits 0-9 and operators +, -, *, /, % allowed.\");\n\t\t\treturn null;\n\t\t}\n\t\tScanner parser = new Scanner(expression).useDelimiter(\" \");\n\t\twhile (parser.hasNext()) {\n\t\t\tString next = parser.next();\n\t\t\tif ((next.length() == 1) && (next.matches(\"[+\\\\-\\\\*/%]\"))) {\n\t\t\t\tif (stack.size() < 2) {\n\t\t\t\t\tout.println(\"Invalid expression: too many operators.\");\n\t\t\t\t\tstack.clear();\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t\tlong second = stack.pop().longValue();\n\t\t\t\tlong first = stack.pop().longValue();\n\t\t\t\tif (next.equals(\"+\")) {stack.push(first + second);}\n\t\t\t\tif (next.equals(\"-\")) {stack.push(first - second);}\n\t\t\t\tif (next.equals(\"*\")) {stack.push(first * second);}\n\t\t\t\tif (next.equals(\"/\")) {stack.push(first / second);}\n\t\t\t\tif (next.equals(\"%\")) {stack.push(first % second);}\n\t\t\t}\n\t\t\telse {\n<<<<<<< HEAD\n\t\t\t\tif (next.matches(\"[+\\\\-\\\\*/%]+\")) {\n\t\t\t\t\tout.println(\"Invalid expression: separate values and operators with spaces.\");\n\t\t\t\t\treturn null;\n\t\t\t\t}\n=======\n\t\t\t\tif ((next.contains(\"+\")) || (next.contains(\"-\")) || (next.contains(\"*\")) || (next.contains(\"/\")) || (next.contains(\"%\"))) { //I couldn't get a regular expression to work.\n\t\t\t\tout.println(\"Invalid expression: separate values and operators with spaces.\");\n\t\t\t\tstack.clear();\n\t\t\t\treturn null;\n\t\t\t}\n>>>>>>> 23f55099f5810898e0b5ac2cf58196cab733c79b\n\t\t\t\tstack.push(new Long(next));\n\t\t\t}\n\t\t}\n\t\tif (stack.size() > 1) {\n\t\t\tout.println(\"Invalid expression: too many values.\");\n\t\t\tstack.clear();\n\t\t\treturn null;\n\t\t}\n\t\treturn stack.pop();\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tout.println(\"RPN Calculator. Type in an expression, with values and operators separated by spaces, in reverse Polish or postfix notation and press Enter to print the result. Integers (between -2^63 and 2^63 - 1) only because Java is finicky with types. Press q or Ctrl + C to quit.\");\n\t\tout.print(\">> \");\n\t\tScanner scanner = new Scanner(System.in);\n\t\tfor (;;) {\n\t\t\tString next = \"\";\n\t\t\tfor (;;) {\n\t\t\t\tnext = scanner.nextLine().trim();\n\t\t\t\tif (next.equals(\"\")) {out.print(\">> \");}\n\t\t\t\telse {break;}\n\t\t\t}\n\t\t\tif (next.equals(\"q\")) {return;}\n\t\t\tLong nextEvaluate = evaluate(next);\n\t\t\tif (nextEvaluate != null) {out.println(nextEvaluate);}\n\t\t\tout.print(\">> \");\n\t\t}\n\t}\n}\n<<<<<<< HEAD\n=======\n\n>>>>>>> 23f55099f5810898e0b5ac2cf58196cab733c79b\n"},"new_file":{"kind":"string","value":"13-RPNCalculator/RPNCalculator.java"},"old_contents":{"kind":"string","value":"import static java.lang.System.out;\nimport java.util.ArrayDeque;\nimport java.util.Scanner;\n\npublic class RPNCalculator {\n\tprivate static ArrayDeque stack = new ArrayDeque();\n\t\n\tprivate RPNCalculator() {}\n\t\n\tpublic static Long evaluate(String expression) {\n\t\tif (!(expression.matches(\"[ 0-9+\\\\-\\\\*/%]*\")) || (expression.contains(\".\"))) {\n\t\t\tout.println(\"Invalid expression: only digits 0-9 and operators +, -, *, /, % allowed.\");\n\t\t\treturn null;\n\t\t}\n\t\tScanner parser = new Scanner(expression).useDelimiter(\" \");\n\t\twhile (parser.hasNext()) {\n\t\t\tString next = parser.next();\n\t\t\tif ((next.length() == 1) && (next.matches(\"[+\\\\-\\\\*/%]\"))) {\n\t\t\t\tif (stack.size() < 2) {\n\t\t\t\t\tout.println(\"Invalid expression: too many operators.\");\n\t\t\t\t\tstack.clear();\n\t\t\t\t\treturn null;\n\t\t\t\t}\n\t\t\t\tlong second = stack.pop().longValue();\n\t\t\t\tlong first = stack.pop().longValue();\n\t\t\t\tif (next.equals(\"+\")) {stack.push(first + second);}\n\t\t\t\tif (next.equals(\"-\")) {stack.push(first - second);}\n\t\t\t\tif (next.equals(\"*\")) {stack.push(first * second);}\n\t\t\t\tif (next.equals(\"/\")) {stack.push(first / second);}\n\t\t\t\tif (next.equals(\"%\")) {stack.push(first % second);}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif ((next.contains(\"+\")) || (next.contains(\"-\")) || (next.contains(\"*\")) || (next.contains(\"/\")) || (next.contains(\"%\"))) { //I couldn't get a regular expression to work.\n\t\t\t\tout.println(\"Invalid expression: separate values and operators with spaces.\");\n\t\t\t\tstack.clear();\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\t\tstack.push(new Long(next));\n\t\t\t}\n\t\t}\n\t\tif (stack.size() > 1) {\n\t\t\tout.println(\"Invalid expression: too many values.\");\n\t\t\tstack.clear();\n\t\t\treturn null;\n\t\t}\n\t\treturn stack.pop();\n\t}\n\t\n\tpublic static void main(String[] args) {\n\t\tout.println(\"RPN Calculator. Type in an expression in reverse Polish or postfix notation and press Enter to print the result. Integers only because Java is finicky with types. Press q or Ctrl + C to quit.\");\n\t\tout.print(\">> \");\n\t\tScanner scanner = new Scanner(System.in);\n\t\tfor (;;) {\n\t\t\tString next = \"\";\n\t\t\tfor (;;) {\n\t\t\t\tnext = scanner.nextLine().trim();\n\t\t\t\tif (!(next.equals(\"\"))) {break;}\n\t\t\t}\n\t\t\tif (next.equals(\"q\")) {return;}\n\t\t\tLong nextEvaluate = evaluate(next);\n\t\t\tif (nextEvaluate != null) {out.println(nextEvaluate);}\n\t\t\tout.print(\">> \");\n\t\t}\n\t}\n}\n\n"},"message":{"kind":"string","value":"RPNCalculator: Git misbehaves\n"},"old_file":{"kind":"string","value":"13-RPNCalculator/RPNCalculator.java"},"subject":{"kind":"string","value":"RPNCalculator: Git misbehaves"}}},{"rowIdx":1445,"cells":{"lang":{"kind":"string","value":"Java"},"license":{"kind":"string","value":"mit"},"stderr":{"kind":"string","value":""},"commit":{"kind":"string","value":"1c79cbee45573ca958d7149bc7e1a0d34c3936d2"},"returncode":{"kind":"number","value":0,"string":"0"},"repos":{"kind":"string","value":"tripu/validator,sammuelyee/validator,YOTOV-LIMITED/validator,tripu/validator,validator/validator,tripu/validator,sammuelyee/validator,sammuelyee/validator,YOTOV-LIMITED/validator,validator/validator,sammuelyee/validator,YOTOV-LIMITED/validator,YOTOV-LIMITED/validator,validator/validator,validator/validator,sammuelyee/validator,takenspc/validator,takenspc/validator,takenspc/validator,tripu/validator,validator/validator,takenspc/validator,takenspc/validator,YOTOV-LIMITED/validator,tripu/validator"},"new_contents":{"kind":"string","value":"/*\n * This file is part of the RELAX NG schemas far (X)HTML5. \n * Please see the file named LICENSE in the relaxng directory for \n * license details.\n */\n\npackage org.whattf.syntax;\n\nimport java.io.File;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.net.MalformedURLException;\nimport java.util.ArrayList;\nimport java.util.List;\n\nimport nu.validator.validation.SimpleDocumentValidator;\nimport nu.validator.xml.SystemErrErrorHandler;\n\nimport org.xml.sax.SAXException;\n\nimport com.thaiopensource.xml.sax.CountingErrorHandler;\n\n/**\n * \n * @version $Id$\n * @author hsivonen\n */\npublic class Driver {\n\n private SimpleDocumentValidator validator;\n\n private static final String PATH = \"syntax/relaxng/tests/\";\n\n private PrintWriter err;\n\n private PrintWriter out;\n\n private SystemErrErrorHandler errorHandler;\n\n private CountingErrorHandler countingErrorHandler;\n\n private boolean failed = false;\n\n private boolean verbose;\n\n /**\n * @param basePath\n */\n public Driver(boolean verbose) throws IOException {\n this.errorHandler = new SystemErrErrorHandler();\n this.countingErrorHandler = new CountingErrorHandler();\n this.verbose = verbose;\n validator = new SimpleDocumentValidator();\n try {\n this.err = new PrintWriter(new OutputStreamWriter(System.err,\n \"UTF-8\"));\n this.out = new PrintWriter(new OutputStreamWriter(System.out,\n \"UTF-8\"));\n } catch (Exception e) {\n // If this happens, the JDK is too broken anyway\n throw new RuntimeException(e);\n }\n }\n\n private void checkHtmlFile(File file) throws IOException, SAXException {\n if (!file.exists()) {\n if (verbose) {\n out.println(String.format(\"\\\"%s\\\": warning: File not found.\",\n file.toURI().toURL().toString()));\n out.flush();\n }\n return;\n }\n if (verbose) {\n out.println(file);\n out.flush();\n }\n if (isHtml(file)) {\n validator.checkHtmlFile(file, true);\n } else if (isXhtml(file)) {\n validator.checkXmlFile(file);\n } else {\n if (verbose) {\n out.println(String.format(\n \"\\\"%s\\\": warning: File was not checked.\"\n + \" Files must have a .html, .xhtml, .htm,\"\n + \" or .xht extension.\",\n file.toURI().toURL().toString()));\n out.flush();\n }\n }\n }\n\n private boolean isXhtml(File file) {\n String name = file.getName();\n return name.endsWith(\".xhtml\") || name.endsWith(\".xht\");\n }\n\n private boolean isHtml(File file) {\n String name = file.getName();\n return name.endsWith(\".html\") || name.endsWith(\".htm\");\n }\n\n private boolean isCheckableFile(File file) {\n return file.isFile() && (isHtml(file) || isXhtml(file));\n }\n\n private void recurseDirectory(File directory) throws SAXException,\n IOException {\n File[] files = directory.listFiles();\n for (int i = 0; i < files.length; i++) {\n File file = files[i];\n if (file.isDirectory()) {\n recurseDirectory(file);\n } else {\n checkHtmlFile(file);\n }\n }\n }\n\n private void checkFiles(List files) {\n for (File file : files) {\n errorHandler.reset();\n try {\n if (file.isDirectory()) {\n recurseDirectory(file);\n } else {\n checkHtmlFile(file);\n }\n } catch (IOException e) {\n } catch (SAXException e) {\n }\n if (errorHandler.isInError()) {\n failed = true;\n }\n }\n }\n\n private void checkInvalidFiles(List files) {\n for (File file : files) {\n countingErrorHandler.reset();\n try {\n if (file.isDirectory()) {\n recurseDirectory(file);\n } else {\n checkHtmlFile(file);\n }\n } catch (IOException e) {\n } catch (SAXException e) {\n }\n if (!countingErrorHandler.getHadErrorOrFatalError()) {\n failed = true;\n try {\n err.println(String.format(\n \"\\\"%s\\\": error: Document was supposed to be\"\n + \" invalid but was not.\",\n file.toURI().toURL().toString()));\n err.flush();\n } catch (MalformedURLException e) {\n throw new RuntimeException(e);\n }\n }\n }\n }\n\n private enum State {\n EXPECTING_INVALID_FILES, EXPECTING_VALID_FILES, EXPECTING_ANYTHING\n }\n\n private void checkTestDirectoryAgainstSchema(File directory,\n String schemaUrl) throws SAXException, Exception {\n validator.setUpMainSchema(schemaUrl, errorHandler);\n checkTestFiles(directory, State.EXPECTING_ANYTHING);\n }\n\n private void checkTestFiles(File directory, State state)\n throws SAXException {\n File[] files = directory.listFiles();\n List validFiles = new ArrayList();\n List invalidFiles = new ArrayList();\n if (files == null) {\n if (verbose) {\n try {\n out.println(String.format(\n \"\\\"%s\\\": warning: No files found in directory.\",\n directory.toURI().toURL().toString()));\n out.flush();\n } catch (MalformedURLException mue) {\n throw new RuntimeException(mue);\n }\n }\n return;\n }\n for (int i = 0; i < files.length; i++) {\n File file = files[i];\n if (file.isDirectory()) {\n if (state != State.EXPECTING_ANYTHING) {\n checkTestFiles(file, state);\n } else if (\"invalid\".equals(file.getName())) {\n checkTestFiles(file, State.EXPECTING_INVALID_FILES);\n } else if (\"valid\".equals(file.getName())) {\n checkTestFiles(file, State.EXPECTING_VALID_FILES);\n } else {\n checkTestFiles(file, State.EXPECTING_ANYTHING);\n }\n } else if (isCheckableFile(file)) {\n if (state == State.EXPECTING_INVALID_FILES) {\n invalidFiles.add(file);\n } else if (state == State.EXPECTING_VALID_FILES) {\n validFiles.add(file);\n } else if (file.getPath().indexOf(\"notvalid\") > 0) {\n invalidFiles.add(file);\n } else {\n validFiles.add(file);\n }\n }\n }\n if (validFiles.size() > 0) {\n validator.setUpValidatorAndParsers(errorHandler, false);\n checkFiles(validFiles);\n }\n if (invalidFiles.size() > 0) {\n validator.setUpValidatorAndParsers(countingErrorHandler, false);\n checkInvalidFiles(invalidFiles);\n }\n }\n\n public boolean runTestSuite() throws SAXException, Exception {\n checkTestDirectoryAgainstSchema(new File(PATH\n + \"html5core-plus-web-forms2/\"),\n \"http://s.validator.nu/html5/xhtml5core-plus-web-forms2.rnc\");\n checkTestDirectoryAgainstSchema(new File(PATH + \"html/\"),\n \"http://s.validator.nu/html5-all.rnc\");\n checkTestDirectoryAgainstSchema(new File(PATH + \"xhtml/\"),\n \"http://s.validator.nu/xhtml5-all.rnc\");\n checkTestDirectoryAgainstSchema(new File(PATH + \"html-its/\"),\n \"http://s.validator.nu/html5-all.rnc\");\n checkTestDirectoryAgainstSchema(new File(PATH + \"html-rdfa/\"),\n \"http://s.validator.nu/html5-all.rnc\");\n checkTestDirectoryAgainstSchema(new File(PATH + \"html-rdfalite/\"),\n \"http://s.validator.nu/html5-rdfalite.rnc\");\n\n if (verbose) {\n if (failed) {\n out.println(\"Failure!\");\n out.flush();\n } else {\n out.println(\"Success!\");\n out.flush();\n }\n }\n return !failed;\n }\n\n /**\n * @param args\n * @throws SAXException\n */\n public static void main(String[] args) throws SAXException, Exception {\n boolean verbose = ((args.length == 1) && \"-v\".equals(args[0]));\n Driver d = new Driver(verbose);\n if (d.runTestSuite()) {\n System.exit(0);\n } else {\n System.exit(-1);\n }\n }\n}\n"},"new_file":{"kind":"string","value":"src/nu/validator/client/Driver.java"},"old_contents":{"kind":"string","value":"/*\n * This file is part of the RELAX NG schemas far (X)HTML5. \n * Please see the file named LICENSE in the relaxng directory for \n * license details.\n */\n\npackage org.whattf.syntax;\n\nimport java.io.File;\nimport java.io.IOException;\nimport java.io.OutputStreamWriter;\nimport java.io.PrintWriter;\nimport java.net.MalformedURLException;\nimport java.util.ArrayList;\nimport java.util.List;\n\nimport nu.validator.validation.SimpleValidator;\nimport nu.validator.xml.SystemErrErrorHandler;\n\nimport org.xml.sax.SAXException;\n\nimport com.thaiopensource.xml.sax.CountingErrorHandler;\n\n/**\n * \n * @version $Id$\n * @author hsivonen\n */\npublic class Driver {\n\n private SimpleValidator validator;\n\n private static final String PATH = \"syntax/relaxng/tests/\";\n\n private PrintWriter err;\n\n private PrintWriter out;\n\n private SystemErrErrorHandler errorHandler;\n\n private CountingErrorHandler countingErrorHandler;\n\n private boolean failed = false;\n\n private boolean verbose;\n\n /**\n * @param basePath\n */\n public Driver(boolean verbose) throws IOException {\n this.errorHandler = new SystemErrErrorHandler();\n this.countingErrorHandler = new CountingErrorHandler();\n this.verbose = verbose;\n validator = new SimpleValidator();\n try {\n this.err = new PrintWriter(new OutputStreamWriter(System.err,\n \"UTF-8\"));\n this.out = new PrintWriter(new OutputStreamWriter(System.out,\n \"UTF-8\"));\n } catch (Exception e) {\n // If this happens, the JDK is too broken anyway\n throw new RuntimeException(e);\n }\n }\n\n private void checkHtmlFile(File file) throws IOException, SAXException {\n if (!file.exists()) {\n if (verbose) {\n out.println(String.format(\"\\\"%s\\\": warning: File not found.\",\n file.toURI().toURL().toString()));\n out.flush();\n }\n return;\n }\n if (verbose) {\n out.println(file);\n out.flush();\n }\n if (isHtml(file)) {\n validator.checkHtmlFile(file, true);\n } else if (isXhtml(file)) {\n validator.checkXmlFile(file);\n } else {\n if (verbose) {\n out.println(String.format(\n \"\\\"%s\\\": warning: File was not checked.\"\n + \" Files must have a .html, .xhtml, .htm,\"\n + \" or .xht extension.\",\n file.toURI().toURL().toString()));\n out.flush();\n }\n }\n }\n\n private boolean isXhtml(File file) {\n String name = file.getName();\n return name.endsWith(\".xhtml\") || name.endsWith(\".xht\");\n }\n\n private boolean isHtml(File file) {\n String name = file.getName();\n return name.endsWith(\".html\") || name.endsWith(\".htm\");\n }\n\n private boolean isCheckableFile(File file) {\n return file.isFile() && (isHtml(file) || isXhtml(file));\n }\n\n private void recurseDirectory(File directory) throws SAXException,\n IOException {\n File[] files = directory.listFiles();\n for (int i = 0; i < files.length; i++) {\n File file = files[i];\n if (file.isDirectory()) {\n recurseDirectory(file);\n } else {\n checkHtmlFile(file);\n }\n }\n }\n\n private void checkFiles(List files) {\n for (File file : files) {\n errorHandler.reset();\n try {\n if (file.isDirectory()) {\n recurseDirectory(file);\n } else {\n checkHtmlFile(file);\n }\n } catch (IOException e) {\n } catch (SAXException e) {\n }\n if (errorHandler.isInError()) {\n failed = true;\n }\n }\n }\n\n private void checkInvalidFiles(List files) {\n for (File file : files) {\n countingErrorHandler.reset();\n try {\n if (file.isDirectory()) {\n recurseDirectory(file);\n } else {\n checkHtmlFile(file);\n }\n } catch (IOException e) {\n } catch (SAXException e) {\n }\n if (!countingErrorHandler.getHadErrorOrFatalError()) {\n failed = true;\n try {\n err.println(String.format(\n \"\\\"%s\\\": error: Document was supposed to be\"\n + \" invalid but was not.\",\n file.toURI().toURL().toString()));\n err.flush();\n } catch (MalformedURLException e) {\n throw new RuntimeException(e);\n }\n }\n }\n }\n\n private enum State {\n EXPECTING_INVALID_FILES, EXPECTING_VALID_FILES, EXPECTING_ANYTHING\n }\n\n private void checkTestDirectoryAgainstSchema(File directory,\n String schemaUrl) throws SAXException, Exception {\n validator.setUpMainSchema(schemaUrl, errorHandler);\n checkTestFiles(directory, State.EXPECTING_ANYTHING);\n }\n\n private void checkTestFiles(File directory, State state)\n throws SAXException {\n File[] files = directory.listFiles();\n List validFiles = new ArrayList();\n List invalidFiles = new ArrayList();\n if (files == null) {\n if (verbose) {\n try {\n out.println(String.format(\n \"\\\"%s\\\": warning: No files found in directory.\",\n directory.toURI().toURL().toString()));\n out.flush();\n } catch (MalformedURLException mue) {\n throw new RuntimeException(mue);\n }\n }\n return;\n }\n for (int i = 0; i < files.length; i++) {\n File file = files[i];\n if (file.isDirectory()) {\n if (state != State.EXPECTING_ANYTHING) {\n checkTestFiles(file, state);\n } else if (\"invalid\".equals(file.getName())) {\n checkTestFiles(file, State.EXPECTING_INVALID_FILES);\n } else if (\"valid\".equals(file.getName())) {\n checkTestFiles(file, State.EXPECTING_VALID_FILES);\n } else {\n checkTestFiles(file, State.EXPECTING_ANYTHING);\n }\n } else if (isCheckableFile(file)) {\n if (state == State.EXPECTING_INVALID_FILES) {\n invalidFiles.add(file);\n } else if (state == State.EXPECTING_VALID_FILES) {\n validFiles.add(file);\n } else if (file.getPath().indexOf(\"notvalid\") > 0) {\n invalidFiles.add(file);\n } else {\n validFiles.add(file);\n }\n }\n }\n if (validFiles.size() > 0) {\n validator.setUpValidatorAndParsers(errorHandler, false);\n checkFiles(validFiles);\n }\n if (invalidFiles.size() > 0) {\n validator.setUpValidatorAndParsers(countingErrorHandler, false);\n checkInvalidFiles(invalidFiles);\n }\n }\n\n public boolean runTestSuite() throws SAXException, Exception {\n checkTestDirectoryAgainstSchema(new File(PATH\n + \"html5core-plus-web-forms2/\"),\n \"http://s.validator.nu/html5/xhtml5core-plus-web-forms2.rnc\");\n checkTestDirectoryAgainstSchema(new File(PATH + \"html/\"),\n \"http://s.validator.nu/html5-all.rnc\");\n checkTestDirectoryAgainstSchema(new File(PATH + \"xhtml/\"),\n \"http://s.validator.nu/xhtml5-all.rnc\");\n checkTestDirectoryAgainstSchema(new File(PATH + \"html-its/\"),\n \"http://s.validator.nu/html5-all.rnc\");\n checkTestDirectoryAgainstSchema(new File(PATH + \"html-rdfa/\"),\n \"http://s.validator.nu/html5-all.rnc\");\n checkTestDirectoryAgainstSchema(new File(PATH + \"html-rdfalite/\"),\n \"http://s.validator.nu/html5-rdfalite.rnc\");\n\n if (verbose) {\n if (failed) {\n out.println(\"Failure!\");\n out.flush();\n } else {\n out.println(\"Success!\");\n out.flush();\n }\n }\n return !failed;\n }\n\n /**\n * @param args\n * @throws SAXException\n */\n public static void main(String[] args) throws SAXException, Exception {\n boolean verbose = ((args.length == 1) && \"-v\".equals(args[0]));\n Driver d = new Driver(verbose);\n if (d.runTestSuite()) {\n System.exit(0);\n } else {\n System.exit(-1);\n }\n }\n}\n"},"message":{"kind":"string","value":"SimpleValidator is now SimpleDocumentValidator.\n\n--HG--\nextra : transplant_source : N%B5%D8%82%E5f%E1%23%94%23%FD%D5cV%E7%85%F3o%0E%81\n"},"old_file":{"kind":"string","value":"src/nu/validator/client/Driver.java"},"subject":{"kind":"string","value":"SimpleValidator is now SimpleDocumentValidator."}}},{"rowIdx":1446,"cells":{"lang":{"kind":"string","value":"Java"},"license":{"kind":"string","value":"mit"},"stderr":{"kind":"string","value":""},"commit":{"kind":"string","value":"9757c42d6fd43246a5f8d3902e6716b6d9c4c397"},"returncode":{"kind":"number","value":0,"string":"0"},"repos":{"kind":"string","value":"kapadiamush/Eve-s-Adventure"},"new_contents":{"kind":"string","value":"package controllers;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.Random;\r\n\r\nimport javafx.event.ActionEvent;\r\nimport javafx.event.EventHandler;\r\nimport javafx.scene.Scene;\r\nimport javafx.scene.control.Button;\r\nimport javafx.scene.layout.VBox;\r\nimport javafx.scene.text.Text;\r\nimport javafx.stage.Modality;\r\nimport javafx.stage.Stage;\r\nimport models.Coordinate;\r\nimport models.campaign.KarelCode;\r\nimport models.campaign.World;\r\nimport models.gridobjects.creatures.Creature;\r\nimport models.gridobjects.items.Bamboo;\r\nimport models.gridobjects.items.Item;\r\nimport models.gridobjects.items.Shrub;\r\nimport models.gridobjects.items.Tree;\r\nimport views.MainApp;\r\nimport views.grid.GridWorld;\r\nimport views.karel.KarelTable;\r\nimport views.scenes.LoadMenuScene;\r\nimport views.scenes.LoadSessionScene;\r\nimport views.scenes.MainMenuScene;\r\nimport views.scenes.SandboxScene;\r\nimport views.tabs.GameTabs;\r\n\r\n/**\r\n * \r\n * @author Anthony Wong\r\n * @author Megan Murray\r\n *\r\n */\r\npublic final class ButtonHandlers {\r\n\r\n\tpublic static final void SANDBOX_MODE_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"SANDBOX_MODE_BUTTON_HANDLER CALLED\");\r\n\t\tMainApp.changeScenes(LoadMenuScene.getInstance());\r\n\t}\r\n\r\n\tpublic static final void ADVENTURE_MODE_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"ADVENTURE_MODE_BUTTON_HANDLER CALLED\");\r\n\t\tMainApp.changeScenes(LoadMenuScene.getInstance());\r\n\t}\r\n\r\n\tpublic static final void LOAD_SESSION_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"LOAD_SESSION_BUTTON_HANDLER CALLED\");\r\n\t\tMainApp.changeScenes(LoadSessionScene.getInstance());\r\n\t}\r\n\r\n\tpublic static final void NEW_SESSION_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"NEW_SESSION_BUTTON_HANDLER CALLED\");\r\n\t\tMainApp.changeScenes(SandboxScene.getInstance());\r\n\t}\r\n\r\n\tpublic static final void CANCEL_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"CANCEL_BUTTON_HANDLER CALLED\");\r\n\t\tMainApp.changeScenes(LoadMenuScene.getInstance());\r\n\t}\r\n\r\n\tpublic static final void BACK_HOMESCREEN_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"BACK_HOMESCREEN_BUTTON_HANDLER CALLED\");\r\n\t\tMainApp.changeScenes(MainMenuScene.getInstance());\r\n\t}\r\n\r\n\t/**\r\n\t * InstuctionsTab.java\r\n\t */\r\n\tpublic static final void IF_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tKarelTable.getInstance().addInstructionsCode(KarelCode.IFSTATEMENT);\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.IFSTATEMENT);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.INSTRUCTIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().switchTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t}\r\n\r\n\tpublic static final void END_IF_BUTTON_HANDLER(ActionEvent e) {\r\n\t}\r\n\r\n\tpublic static final void ELSE_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tKarelTable.getInstance().addInstructionsCode(KarelCode.ELSESTATEMENT);\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\t// TODO\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.ELSESTATEMENT);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.INSTRUCTIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().switchTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t}\r\n\r\n\tpublic static final void END_ELSE_BUTTON_HANDLER(ActionEvent e) {\r\n\t}\r\n\r\n\tpublic static final void WHILE_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tKarelTable.getInstance().addInstructionsCode(KarelCode.WHILESTATEMENT);\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.WHILESTATEMENT);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.INSTRUCTIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().switchTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t}\r\n\r\n\tpublic static final void END_WHILE_BUTTON_HANDLER(ActionEvent e) {\r\n\t}\r\n\r\n\tpublic static final void TASK_BUTTON_HANDLER(ActionEvent e) {\r\n\t}\r\n\r\n\tpublic static final void LOOP_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tKarelTable.getInstance().addInstructionsCode(KarelCode.LOOPSTATEMENT);\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.INSTRUCTIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.NUMBERS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().switchTab(GameTabs.NUMBERS_TAB_VALUE);\r\n\t}\r\n\r\n\tpublic static final void END_LOOP_BUTTON_HANDLER(ActionEvent e) {\r\n\t}\r\n\r\n\t/**\r\n\t * ConditionalsTab.java\r\n\t */\r\n\tpublic static final void FRONT_IS_CLEAR_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"FRONT_IS_CLEAR_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.FRONTISCLEAR);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.FRONTISCLEAR);\r\n\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.INSTRUCTIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().switchTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t}\r\n\r\n\tpublic static final void NEXT_TO_A_FRIEND_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"NEXT_TO_A_FRIEND_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.NEXTTOAFRIEND);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.NEXTTOAFRIEND);\r\n\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.INSTRUCTIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().switchTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t}\r\n\r\n\tpublic static final void FACING_NORTH_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"FACING_NORTH_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.FACINGNORTH);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.FACINGNORTH);\r\n\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.INSTRUCTIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().switchTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t}\r\n\r\n\tpublic static final void FACING_SOUTH_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"FACING_SOUTH_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.FACINGSOUTH);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.FACINGSOUTH);\r\n\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.INSTRUCTIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().switchTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t}\r\n\r\n\tpublic static final void FACING_EAST_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"FACING_EAST_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.FACINGEAST);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.FACINGEAST);\r\n\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.INSTRUCTIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().switchTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t}\r\n\r\n\tpublic static final void FACING_WEST_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"FACING_WEST_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.FACINGWEST);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.FACINGWEST);\r\n\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.INSTRUCTIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().switchTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t}\r\n\r\n\tpublic static final void BAG_IS_EMPTY_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"BAG_IS_EMPTY_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.BAGISEMPTY);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.BAGISEMPTY);\r\n\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.INSTRUCTIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().switchTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t}\r\n\r\n\t/**\r\n\t * OperationsTab.java\r\n\t */\r\n\tpublic static final void MOVE_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"MOVE_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.MOVE);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.MOVE);\r\n\t}\r\n\r\n\tpublic static final void SLEEP_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"SLEEP_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.SLEEP);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.SLEEP);\r\n\t}\r\n\r\n\tpublic static final void WAKE_UP_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"WAKE_UP_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.WAKEUP);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.WAKEUP);\r\n\t}\r\n\t\r\n\tpublic static final void TURN_RIGHT_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"TURN_RIGHT_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.TURNRIGHT);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.TURNRIGHT);\r\n\t}\r\n\r\n\tpublic static final void PICK_UP_BAMBOO_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"PICK_UP_BAMBOO_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.PICKBAMBOO);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.PICKBAMBOO);\r\n\t}\r\n\r\n\tpublic static final void PUT_BAMBOO_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"PUT_BAMBOO_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.PUTBAMBOO);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.PUTBAMBOO);\r\n\t}\r\n\r\n\tpublic static final void NUMBERS_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"NUMBERS_BUTTON_HANDLER\");\r\n\t\tString value = ((Button) e.getSource()).getText();\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(value);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(value);\r\n\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.NUMBERS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.INSTRUCTIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().switchTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t}\r\n\t\r\n\t\r\n\t/**\r\n\t * Popup for if a grid space is not empty\r\n\t * Asks to replace object or just cancel\r\n\t * \r\n\t * @newObject the object the user is trying to put into the square\r\n\t */\r\n\tpublic static void popup(String newObject){\r\n\tString oldObject = GridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].getText();\r\n\tfinal Stage dialog = new Stage();\r\n dialog.initModality(Modality.APPLICATION_MODAL);\r\n VBox dialogVbox = new VBox(20);\r\n dialogVbox.getChildren().add(new Text(\"There is already an object in this space. \\nReplace \" + \r\n \t\t\t\t\t\t\t\t\t\toldObject + \r\n \t\t\t\t\t\t\t\t\t\t\" with \" + newObject + \"?\"));\r\n Scene dialogScene = new Scene(dialogVbox, 300, 200);\r\n final Button REPLACE = new Button(\"Replace\");\r\n REPLACE.setMaxWidth(100);\r\n final Button CANCEL = new Button(\"Cancel\");\r\n REPLACE.setMaxWidth(100);\r\n dialogVbox.getChildren().addAll(REPLACE, CANCEL);\r\n dialog.setScene(dialogScene);\r\n dialog.show();\r\n \r\n CANCEL.setOnAction(\r\n \t\tnew EventHandler(){\r\n \t\t\tpublic void handle(ActionEvent e){\r\n \t\t\t\tdialog.close();\r\n \t\t\t}\r\n \t}\r\n\t);\r\n REPLACE.setOnAction(\r\n \t\tnew EventHandler(){\r\n \t\t\tpublic void handle(ActionEvent e){\r\n \t\t\t\tdialog.close();\r\n \t\t\t\tif (oldObject.equals(\"Tree\") || oldObject.equals(\"Shrub\") || oldObject.equals(\"Bamboo\"))\r\n \t\t\t\t\tRMITEM_BUTTON_HANDLER(null);\r\n \t\t\t\t\t\r\n \t\t\t\tif (oldObject.equals(\"Friend\"))\r\n \t\t\t\t\tRMCREATURE_BUTTON_HANDLER(null);\r\n \t\t\t\t\r\n \t\t\t\tGridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].setText(newObject);\r\n \t\t\t\tswitch(newObject){\r\n \t\t\t\tcase \"Tree\":\r\n \t\t\t\t\tTree tree = new Tree(4);\r\n \t\t\t\t\ttree.setCoordinates(new Coordinate(GridWorld.getXCoordinate(), GridWorld.getYCoordinate()));\r\n \t\t\t\t\tif(GridWorld.getInstance().getWorld() == null) System.out.println(\"Uninitalized world\");\r\n \t\t\t\t\tGridWorld.getInstance().getWorld().addItem(tree); \r\n \t\t\t\t\tGridWorld.getInstance().getWorld().printWorld();\r\n \t\t\t\t\tbreak;\r\n \t\t\t\tcase \"Shrub\":\r\n \t\t\t\t\tShrub shrub = new Shrub(4, false);\r\n \t\t\t\t\tshrub.setCoordinates(new Coordinate(GridWorld.getXCoordinate(), GridWorld.getYCoordinate()));\r\n \t\t\t\t\tif(GridWorld.getInstance().getWorld() == null) System.out.println(\"Uninitalized world\");\r\n \t\t\t\t\tGridWorld.getInstance().getWorld().addItem(shrub); \r\n \t\t\t\t\tGridWorld.getInstance().getWorld().printWorld();\r\n \t\t\t\t\tbreak; \r\n \t\t\t\tcase \"Bamboo\":\r\n \t\t\t\t\tBamboo bamboo = new Bamboo(4);\r\n \t\t\t\t\tbamboo.setCoordinates(new Coordinate(GridWorld.getXCoordinate(), GridWorld.getYCoordinate()));\r\n \t\t\t\t\tif(GridWorld.getInstance().getWorld() == null) System.out.println(\"Uninitalized world\");\r\n \t\t\t\t\tGridWorld.getInstance().getWorld().addItem(bamboo); \r\n \t\t\t\t\tGridWorld.getInstance().getWorld().printWorld();\r\n \t\t\t\tcase \"Friend\":\r\n \t\t\t\t\tCoordinate cords = new Coordinate(GridWorld.getXCoordinate(),GridWorld.getYCoordinate());\r\n \t\t\t\t\tCreature Friend = new Creature(\"Friend\", cords);\r\n \t\t\t\t\tFriend.setCoordinates(new Coordinate(GridWorld.getXCoordinate(), GridWorld.getYCoordinate()));\r\n \t\t\t\t\tif(GridWorld.getInstance().getWorld() == null) System.out.println(\"Uninitalized world\");\r\n \t\t\t\t\tGridWorld.getInstance().getWorld().addCreature(Friend); \r\n \t\t\t\t\tGridWorld.getInstance().getWorld().printWorld();\r\n \t\t\t\tdefault: \r\n \t\t\t\t\tbreak; \r\n \t\t\t\t}\r\n \t\t\t}\r\n \t}\r\n\t);\r\n \r\n}\r\n\t/**\r\n\t * Popup if they try to put something where Eve is\r\n\t * @newObject the object the user is trying to put into the square\r\n\t */\r\n\tpublic static void EvePop(){\r\n\tfinal Stage dialog = new Stage();\r\n dialog.initModality(Modality.APPLICATION_MODAL);\r\n VBox dialogVbox = new VBox(20);\r\n dialogVbox.getChildren().add(new Text(\"This space is already full. \\nYou can't put an Object here.\"));\r\n Scene dialogScene = new Scene(dialogVbox, 300, 200);\r\n final Button OKAY = new Button(\"Okay\");\r\n dialogVbox.getChildren().add(OKAY);\r\n dialog.setScene(dialogScene);\r\n dialog.show();\r\n OKAY.setOnAction(\r\n \t\tnew EventHandler(){\r\n \t\t\tpublic void handle(ActionEvent e){\r\n \t\t\t\tdialog.close();\r\n \t\t\t}\r\n \t}\r\n\t);\r\n}\r\n\t\r\n\t\r\n\t\r\n\t\r\n\t/**\r\n\t * Popup if they try delete the wrong thing\r\n\t * @newObject the object the user is trying to put into the square\r\n\t */\r\n\tpublic static void DeletePop(){\r\n\tString oldObject = GridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].getText();\r\n\tfinal Stage dialog = new Stage();\r\n dialog.initModality(Modality.APPLICATION_MODAL);\r\n VBox dialogVbox = new VBox(20);\r\n dialogVbox.getChildren().add(new Text(\"This space is a(n) \"+ oldObject +\". \\nUse the Remove\"+oldObject+\" button.\"));\r\n Scene dialogScene = new Scene(dialogVbox, 300, 200);\r\n final Button OKAY = new Button(\"Okay\");\r\n dialogVbox.getChildren().add(OKAY);\r\n dialog.setScene(dialogScene);\r\n dialog.show();\r\n OKAY.setOnAction(\r\n \t\tnew EventHandler(){\r\n \t\t\tpublic void handle(ActionEvent e){\r\n \t\t\t\tdialog.close();\r\n \t\t\t}\r\n \t}\r\n\t);\r\n}\r\n\t \r\n\t/**\r\n\t * ItemsTab.java\r\n\t */\r\n\tpublic static final void RMITEM_BUTTON_HANDLER(ActionEvent e){\r\n\t\tSystem.out.println(\"RMITEM_BUTTON_HANDLER\");\r\n\t\tString oldObject = GridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].getText();\r\n\t\tswitch(oldObject){\r\n\t\tcase \"Tree\":\r\n\t\t\tGridWorld.getInstance().getWorld().removeItem(new Coordinate(GridWorld.getXCoordinate(),GridWorld.getYCoordinate()));\r\n\t\t\tGridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].setText(\"\");\r\n\t\t\tbreak;\r\n\t\tcase \"Shrub\":\r\n\t\t\tGridWorld.getInstance().getWorld().removeItem(new Coordinate(GridWorld.getXCoordinate(),GridWorld.getYCoordinate()));\r\n\t\t\tGridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].setText(\"\");\r\n\t\t\tbreak; \r\n\t\tcase \"Bamboo\":\r\n\t\t\tGridWorld.getInstance().getWorld().removeItem(new Coordinate(GridWorld.getXCoordinate(),GridWorld.getYCoordinate()));\r\n\t\t\tGridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].setText(\"\");\t\t\t\r\n\t\tdefault: \r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\tpublic static final void SHRUB_BUTTON_HANDLER(ActionEvent e){\r\n\t\tSystem.out.println(\"SHRUB_BUTTON_HANDLER\");\r\n\t\tString oldObject = GridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].getText();\r\n\t\tif (oldObject.equals(\"Eve!\"))\r\n\t\t\tEvePop();\r\n\t\t\t\r\n\t\telse if (oldObject.equals(\"Tree\") || oldObject.equals(\"Shrub\") || oldObject.equals(\"Bamboo\") || oldObject.equals(\"Friend\")){\r\n\t\t\tpopup(\"Shrub\");\r\n\t\t}\r\n else\r\n\t\t\tGridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].setText(\"Shrub\");\r\n\t\t\tShrub shrub = new Shrub(4, false);\r\n\t\t\tshrub.setCoordinates(new Coordinate(GridWorld.getXCoordinate(), GridWorld.getYCoordinate()));\r\n\t\t\tif(GridWorld.getInstance().getWorld() == null) System.out.println(\"Uninitalized world\");\r\n\t\t\tGridWorld.getInstance().getWorld().addItem(shrub); \r\n\t\t\tGridWorld.getInstance().getWorld().printWorld();\r\n\t}\r\n\t\t\r\n\t\r\n\tpublic static final void TREE_BUTTON_HANDLER(ActionEvent e){\r\n\t\tString oldObject = GridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].getText();\r\n\t\tif (oldObject.equals(\"Eve!\"))\r\n\t\t\tEvePop();\r\n\t\t\t\r\n\t\telse if (oldObject.equals(\"Tree\") || oldObject.equals(\"Shrub\") || oldObject.equals(\"Bamboo\") || oldObject.equals(\"Friend\")){\r\n\t\t\tpopup(\"Tree\");\r\n\t\t\r\n\t\t}\r\n else{\r\n\t\t\tGridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].setText(\"Tree\");\r\n\t\t\tTree tree = new Tree(4);\r\n\t\t\ttree.setCoordinates(new Coordinate(GridWorld.getXCoordinate(), GridWorld.getYCoordinate()));\r\n\t\t\tif(GridWorld.getInstance().getWorld() == null) System.out.println(\"Uninitalized world\");\r\n\t\t\tGridWorld.getInstance().getWorld().addItem(tree); \r\n\t\t\tGridWorld.getInstance().getWorld().printWorld();\r\n }\t\r\n\t}\r\n\t\r\n\tpublic static final void BAMBOO_BUTTON_HANDLER(ActionEvent e){\r\n\t\tSystem.out.println(\"BAMBOO_BUTTON_HANDLER\");\r\n\t\tString oldObject = GridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].getText();\r\n\t\tif (oldObject.equals(\"Eve!\"))\r\n\t\t\tEvePop();\r\n\t\t\t\r\n\t\telse if (oldObject.equals(\"Tree\") || oldObject.equals(\"Shrub\") || oldObject.equals(\"Bamboo\") || oldObject.equals(\"Friend\")){\r\n\t\t\tpopup(\"Bamboo\");\r\n\t\t}\r\n else{\r\n\t\t\tGridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].setText(\"Bamboo\");\r\n\t\t\tBamboo bamboo = new Bamboo(4);\r\n\t\t\tbamboo.setCoordinates(new Coordinate(GridWorld.getXCoordinate(), GridWorld.getYCoordinate()));\r\n\t\t\tif(GridWorld.getInstance().getWorld() == null) System.out.println(\"Uninitalized world\");\r\n\t\t\tGridWorld.getInstance().getWorld().addItem(bamboo); \r\n\t\t\tGridWorld.getInstance().getWorld().printWorld();\r\n }\r\n\t}\t\r\n\t\r\n\t/**\r\n\t * CreaturesTab.java\r\n\t */\r\n\tpublic static final void RMCREATURE_BUTTON_HANDLER(ActionEvent e){\r\n\t\tString oldObject = GridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].getText();\r\n\t\t\tif (oldObject.equals(\"Tree\") || oldObject.equals(\"Shrub\") || oldObject.equals(\"Bamboo\") || oldObject.equals(\"Friend\")){\r\n\t\t\t\t\r\n\t\t\t}\r\n\t\tSystem.out.println(\"RMCREATURE_BUTTON_HANDLER\");\r\n\t\tGridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].setText(\"\");\r\n\t\tGridWorld.getInstance().getWorld().removeCreature(new Coordinate(GridWorld.getXCoordinate(),GridWorld.getYCoordinate()));\r\n\t}\r\n\tpublic static final void EVE_BUTTON_HANDLER(ActionEvent e){\r\n\t\tSystem.out.println(\"EVE_BUTTON_HANDLER\");\r\n\t\tString oldObject = GridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].getText();\r\n\t\t\r\n\t\tfor(int y=0; y < GridWorld.gridButtons.length; y++){\r\n\t\t\tfor(int x=0; x < GridWorld.gridButtons[y].length; x++){\r\n\t\t\t\tif (GridWorld.gridButtons[y][x].getText().equals(\"Eve!\")){\r\n\t\t\t\t\t//frontend move\n\t\t\t\t\tGridWorld.gridButtons[y][x].setText(\" \");\n\t\t\t\t\t\r\n\t\t\t\t\t//backend move\r\n\t\t\t\t\tSystem.out.println(\"X: \" + x + \"Y: \" + y); \r\n\t\t\t\t\tCreature eve = GridWorld.getInstance().getWorld().removeCreature(new Coordinate(y,x)); \r\n\t\t\t\t\teve.setCoordinates(new Coordinate(GridWorld.getXCoordinate(), GridWorld.getYCoordinate()));\r\n\t\t\t\t\teve.setDirection(Coordinate.DOWN);\r\n\t\t\t\t\tGridWorld.getInstance().getWorld().addCreature(eve);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tif (oldObject.equals(\"Tree\") || oldObject.equals(\"Shrub\") || oldObject.equals(\"Bamboo\") || oldObject.equals(\"Friend\")){\r\n\t\t\tEvePop();\r\n\t\t}\r\n\t\t\r\n else{\r\n\t\t\tGridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].setText(\"Eve!\");\r\n\t\t\tCoordinate cords = new Coordinate(GridWorld.getXCoordinate(),GridWorld.getYCoordinate());\r\n\t\t\tCreature Eve = new Creature(\"Eve!\", cords);\r\n\t\t\tEve.setCoordinates(new Coordinate(GridWorld.getXCoordinate(), GridWorld.getYCoordinate()));\r\n\t\t\tif(GridWorld.getInstance().getWorld() == null) System.out.println(\"Uninitalized world\");\r\n\t\t\tGridWorld.getInstance().getWorld().addCreature(Eve); \r\n\t\t\tGridWorld.getInstance().getWorld().printWorld();\r\n }\r\n\t}\r\n\t\r\n\t\r\n\tpublic static final void FRIENDS_BUTTON_HANDLER(ActionEvent e){\r\n\t\tSystem.out.println(\"FRIENDS_BUTTON_HANDLER\");\r\n\t\tString oldObject = GridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].getText();\r\n\t\t\t\r\n\t\tif (oldObject.equals(\"Tree\") || oldObject.equals(\"Shrub\") || oldObject.equals(\"Bamboo\") || oldObject.equals(\"Eve!\")){\r\n\t\t\tpopup(\"Friend\");\r\n\t\t}\r\n else\r\n\t\t\tGridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].setText(\"Friend\");\r\n\t\t\tCoordinate cords = new Coordinate(GridWorld.getXCoordinate(),GridWorld.getYCoordinate());\r\n\t\t\tCreature Friend = new Creature(\"Friend\", cords);\r\n\t\t\tFriend.setCoordinates(new Coordinate(GridWorld.getXCoordinate(), GridWorld.getYCoordinate()));\r\n\t\t\tif(GridWorld.getInstance().getWorld() == null) System.out.println(\"Uninitalized world\");\r\n\t\t\tGridWorld.getInstance().getWorld().addCreature(Friend); \r\n\t\t\tGridWorld.getInstance().getWorld().printWorld();\r\n\t}\r\n\t\r\n\t\r\n\t\r\n\t\t\r\n\t\t\r\n\t\t\r\n\t\r\n\tpublic static final void GridWorld_BUTTON_HANDLER(ActionEvent e){\r\n\t}\r\n\t\r\n\tpublic static final void BACK_BUTTON_HANDLER(ActionEvent e){\r\n\t\tSystem.out.println(\"BACK_BUTTON_HANDLER CALLED\");\r\n\t}\r\n\t\r\n\tpublic static final void FORWARD_BUTTON_HANDLER(ActionEvent e){\r\n\t\tSystem.out.println(\"FORWARD_BUTTON_HANDLER CALLED\");\r\n\t}\r\n\t\r\n\tpublic static final void PLAY_BUTTON_HANDLER(ActionEvent e){\r\n\t\tSystem.out.println(\"PLAY_BUTTON_HANDLER CALLED\");\r\n\t\tArrayList karelCode = KarelTable.getInstance().getKarelCode(); \r\n\t\tif(karelCode.isEmpty()){\r\n\t\t\tSystem.out.println(\"karelCode is empty!\");\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tWorld world = SandboxScene.getWorld(); \r\n\t\tSystem.out.println(KarelTable.getInstance().getKarelCode());\r\n\t\tInterpreter interpreter = new Interpreter(karelCode, world);\r\n\t\tworld.printWorld();\r\n\t\tinterpreter.start(); //starts the code\r\n\t\tworld.printWorld();\r\n\t}\r\n\r\n\tpublic static final void RESET_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"RESET_BUTTON_HANDLER CALLED\");\r\n\t}\r\n\r\n\tpublic static final void REPLACE_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"REPLACE_BUTTON_HANDLER CALLED\");\r\n\t}\r\n\r\n\tpublic static final void QUIT_MENU_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"Quit sandbox mode. Returned to home screen.\");\r\n\t\tMainApp.changeScenes(MainMenuScene.getInstance());\r\n\t}\r\n\r\n\tpublic static final void SAVE_MENU_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"Saved!\");\r\n\t}\r\n}\r\n"},"new_file":{"kind":"string","value":"src/controllers/ButtonHandlers.java"},"old_contents":{"kind":"string","value":"package controllers;\r\n\r\nimport java.util.ArrayList;\r\nimport java.util.Random;\r\n\r\nimport javafx.event.ActionEvent;\r\nimport javafx.event.EventHandler;\r\nimport javafx.scene.Scene;\r\nimport javafx.scene.control.Button;\r\nimport javafx.scene.layout.VBox;\r\nimport javafx.scene.text.Text;\r\nimport javafx.stage.Modality;\r\nimport javafx.stage.Stage;\r\nimport models.Coordinate;\r\nimport models.campaign.KarelCode;\r\nimport models.campaign.World;\r\nimport models.gridobjects.creatures.Creature;\r\nimport models.gridobjects.items.Bamboo;\r\nimport models.gridobjects.items.Item;\r\nimport models.gridobjects.items.Shrub;\r\nimport models.gridobjects.items.Tree;\r\nimport views.MainApp;\r\nimport views.grid.GridWorld;\r\nimport views.karel.KarelTable;\r\nimport views.scenes.LoadMenuScene;\r\nimport views.scenes.LoadSessionScene;\r\nimport views.scenes.MainMenuScene;\r\nimport views.scenes.SandboxScene;\r\nimport views.tabs.GameTabs;\r\n\r\n/**\r\n * \r\n * @author Anthony Wong\r\n * @author Megan Murray\r\n *\r\n */\r\npublic final class ButtonHandlers {\r\n\r\n\tpublic static final void SANDBOX_MODE_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"SANDBOX_MODE_BUTTON_HANDLER CALLED\");\r\n\t\tMainApp.changeScenes(LoadMenuScene.getInstance());\r\n\t}\r\n\r\n\tpublic static final void ADVENTURE_MODE_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"ADVENTURE_MODE_BUTTON_HANDLER CALLED\");\r\n\t\tMainApp.changeScenes(LoadMenuScene.getInstance());\r\n\t}\r\n\r\n\tpublic static final void LOAD_SESSION_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"LOAD_SESSION_BUTTON_HANDLER CALLED\");\r\n\t\tMainApp.changeScenes(LoadSessionScene.getInstance());\r\n\t}\r\n\r\n\tpublic static final void NEW_SESSION_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"NEW_SESSION_BUTTON_HANDLER CALLED\");\r\n\t\tMainApp.changeScenes(SandboxScene.getInstance());\r\n\t}\r\n\r\n\tpublic static final void CANCEL_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"CANCEL_BUTTON_HANDLER CALLED\");\r\n\t\tMainApp.changeScenes(LoadMenuScene.getInstance());\r\n\t}\r\n\r\n\tpublic static final void BACK_HOMESCREEN_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"BACK_HOMESCREEN_BUTTON_HANDLER CALLED\");\r\n\t\tMainApp.changeScenes(MainMenuScene.getInstance());\r\n\t}\r\n\r\n\t/**\r\n\t * InstuctionsTab.java\r\n\t */\r\n\tpublic static final void IF_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tKarelTable.getInstance().addInstructionsCode(KarelCode.IFSTATEMENT);\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.IFSTATEMENT);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.INSTRUCTIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().switchTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t}\r\n\r\n\tpublic static final void END_IF_BUTTON_HANDLER(ActionEvent e) {\r\n\t}\r\n\r\n\tpublic static final void ELSE_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tKarelTable.getInstance().addInstructionsCode(KarelCode.ELSESTATEMENT);\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\t// TODO\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.ELSESTATEMENT);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.INSTRUCTIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().switchTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t}\r\n\r\n\tpublic static final void END_ELSE_BUTTON_HANDLER(ActionEvent e) {\r\n\t}\r\n\r\n\tpublic static final void WHILE_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tKarelTable.getInstance().addInstructionsCode(KarelCode.WHILESTATEMENT);\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.WHILESTATEMENT);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.INSTRUCTIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().switchTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t}\r\n\r\n\tpublic static final void END_WHILE_BUTTON_HANDLER(ActionEvent e) {\r\n\t}\r\n\r\n\tpublic static final void TASK_BUTTON_HANDLER(ActionEvent e) {\r\n\t}\r\n\r\n\tpublic static final void LOOP_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tKarelTable.getInstance().addInstructionsCode(KarelCode.LOOPSTATEMENT);\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.INSTRUCTIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.NUMBERS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().switchTab(GameTabs.NUMBERS_TAB_VALUE);\r\n\t}\r\n\r\n\tpublic static final void END_LOOP_BUTTON_HANDLER(ActionEvent e) {\r\n\t}\r\n\r\n\t/**\r\n\t * ConditionalsTab.java\r\n\t */\r\n\tpublic static final void FRONT_IS_CLEAR_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"FRONT_IS_CLEAR_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.FRONTISCLEAR);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.FRONTISCLEAR);\r\n\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.INSTRUCTIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().switchTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t}\r\n\r\n\tpublic static final void NEXT_TO_A_FRIEND_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"NEXT_TO_A_FRIEND_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.NEXTTOAFRIEND);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.NEXTTOAFRIEND);\r\n\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.INSTRUCTIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().switchTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t}\r\n\r\n\tpublic static final void FACING_NORTH_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"FACING_NORTH_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.FACINGNORTH);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.FACINGNORTH);\r\n\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.INSTRUCTIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().switchTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t}\r\n\r\n\tpublic static final void FACING_SOUTH_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"FACING_SOUTH_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.FACINGSOUTH);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.FACINGSOUTH);\r\n\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.INSTRUCTIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().switchTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t}\r\n\r\n\tpublic static final void FACING_EAST_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"FACING_EAST_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.FACINGEAST);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.FACINGEAST);\r\n\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.INSTRUCTIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().switchTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t}\r\n\r\n\tpublic static final void FACING_WEST_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"FACING_WEST_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.FACINGWEST);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.FACINGWEST);\r\n\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.INSTRUCTIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().switchTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t}\r\n\r\n\tpublic static final void BAG_IS_EMPTY_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"BAG_IS_EMPTY_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.BAGISEMPTY);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.BAGISEMPTY);\r\n\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.CONDITIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.INSTRUCTIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().switchTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t}\r\n\r\n\t/**\r\n\t * OperationsTab.java\r\n\t */\r\n\tpublic static final void MOVE_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"MOVE_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.MOVE);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.MOVE);\r\n\t}\r\n\r\n\tpublic static final void SLEEP_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"SLEEP_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.SLEEP);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.SLEEP);\r\n\t}\r\n\r\n\tpublic static final void WAKE_UP_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"WAKE_UP_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.WAKEUP);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.WAKEUP);\r\n\t}\r\n\t\r\n\tpublic static final void TURN_RIGHT_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"TURN_RIGHT_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.TURNRIGHT);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.TURNRIGHT);\r\n\t}\r\n\r\n\tpublic static final void PICK_UP_BAMBOO_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"PICK_UP_BAMBOO_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.PICKBAMBOO);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.PICKBAMBOO);\r\n\t}\r\n\r\n\tpublic static final void PUT_BAMBOO_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"PUT_BAMBOO_BUTTON_HANDLER\");\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(KarelCode.PUTBAMBOO);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(KarelCode.PUTBAMBOO);\r\n\t}\r\n\r\n\tpublic static final void NUMBERS_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"NUMBERS_BUTTON_HANDLER\");\r\n\t\tString value = ((Button) e.getSource()).getText();\r\n\t\tif (KarelTable.getInstance().isREPLACE_BUTTON_ON()) {\r\n\t\t\tKarelTable.getInstance().replaceCode(value);\r\n\t\t\treturn;\r\n\t\t}\r\n\t\tKarelTable.getInstance().addCode(value);\r\n\r\n\t\tGameTabs.getInstance().disableTab(GameTabs.NUMBERS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.INSTRUCTIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().enableTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t\tGameTabs.getInstance().switchTab(GameTabs.OPERATIONS_TAB_VALUE);\r\n\t}\r\n\t\r\n\t\r\n\t/**\r\n\t * Popup for if a grid space is not empty\r\n\t * Asks to replace object or just cancel\r\n\t * \r\n\t * @newObject the object the user is trying to put into the square\r\n\t */\r\n\tpublic static void popup(String newObject){\r\n\tString oldObject = GridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].getText();\r\n\tfinal Stage dialog = new Stage();\r\n dialog.initModality(Modality.APPLICATION_MODAL);\r\n VBox dialogVbox = new VBox(20);\r\n dialogVbox.getChildren().add(new Text(\"There is already an object in this space. \\nReplace \" + \r\n \t\t\t\t\t\t\t\t\t\toldObject + \r\n \t\t\t\t\t\t\t\t\t\t\" with \" + newObject + \"?\"));\r\n Scene dialogScene = new Scene(dialogVbox, 300, 200);\r\n final Button REPLACE = new Button(\"Replace\");\r\n REPLACE.setMaxWidth(100);\r\n final Button CANCEL = new Button(\"Cancel\");\r\n REPLACE.setMaxWidth(100);\r\n dialogVbox.getChildren().addAll(REPLACE, CANCEL);\r\n dialog.setScene(dialogScene);\r\n dialog.show();\r\n \r\n CANCEL.setOnAction(\r\n \t\tnew EventHandler(){\r\n \t\t\tpublic void handle(ActionEvent e){\r\n \t\t\t\tdialog.close();\r\n \t\t\t}\r\n \t}\r\n\t);\r\n REPLACE.setOnAction(\r\n \t\tnew EventHandler(){\r\n \t\t\tpublic void handle(ActionEvent e){\r\n \t\t\t\tdialog.close();\r\n \t\t\t\tif (oldObject.equals(\"Tree\") || oldObject.equals(\"Shrub\") || oldObject.equals(\"Bamboo\"))\r\n \t\t\t\t\tRMITEM_BUTTON_HANDLER(null);\r\n \t\t\t\t\t\r\n \t\t\t\tif (oldObject.equals(\"Friend\"))\r\n \t\t\t\t\tRMCREATURE_BUTTON_HANDLER(null);\r\n \t\t\t\t\r\n \t\t\t\tGridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].setText(newObject);\r\n \t\t\t\tswitch(newObject){\r\n \t\t\t\tcase \"Tree\":\r\n \t\t\t\t\tTree tree = new Tree(4);\r\n \t\t\t\t\ttree.setCoordinates(new Coordinate(GridWorld.getXCoordinate(), GridWorld.getYCoordinate()));\r\n \t\t\t\t\tif(GridWorld.getInstance().getWorld() == null) System.out.println(\"Uninitalized world\");\r\n \t\t\t\t\tGridWorld.getInstance().getWorld().addItem(tree); \r\n \t\t\t\t\tGridWorld.getInstance().getWorld().printWorld();\r\n \t\t\t\t\tbreak;\r\n \t\t\t\tcase \"Shrub\":\r\n \t\t\t\t\tShrub shrub = new Shrub(4, false);\r\n \t\t\t\t\tshrub.setCoordinates(new Coordinate(GridWorld.getXCoordinate(), GridWorld.getYCoordinate()));\r\n \t\t\t\t\tif(GridWorld.getInstance().getWorld() == null) System.out.println(\"Uninitalized world\");\r\n \t\t\t\t\tGridWorld.getInstance().getWorld().addItem(shrub); \r\n \t\t\t\t\tGridWorld.getInstance().getWorld().printWorld();\r\n \t\t\t\t\tbreak; \r\n \t\t\t\tcase \"Bamboo\":\r\n \t\t\t\t\tBamboo bamboo = new Bamboo(4);\r\n \t\t\t\t\tbamboo.setCoordinates(new Coordinate(GridWorld.getXCoordinate(), GridWorld.getYCoordinate()));\r\n \t\t\t\t\tif(GridWorld.getInstance().getWorld() == null) System.out.println(\"Uninitalized world\");\r\n \t\t\t\t\tGridWorld.getInstance().getWorld().addItem(bamboo); \r\n \t\t\t\t\tGridWorld.getInstance().getWorld().printWorld();\r\n \t\t\t\tcase \"Friend\":\r\n \t\t\t\t\tCoordinate cords = new Coordinate(GridWorld.getXCoordinate(),GridWorld.getYCoordinate());\r\n \t\t\t\t\tCreature Friend = new Creature(\"Friend\", cords);\r\n \t\t\t\t\tFriend.setCoordinates(new Coordinate(GridWorld.getXCoordinate(), GridWorld.getYCoordinate()));\r\n \t\t\t\t\tif(GridWorld.getInstance().getWorld() == null) System.out.println(\"Uninitalized world\");\r\n \t\t\t\t\tGridWorld.getInstance().getWorld().addCreature(Friend); \r\n \t\t\t\t\tGridWorld.getInstance().getWorld().printWorld();\r\n \t\t\t\tdefault: \r\n \t\t\t\t\tbreak; \r\n \t\t\t\t}\r\n \t\t\t}\r\n \t}\r\n\t);\r\n \r\n}\r\n\t/**\r\n\t * Popup if they try to put something where Eve is\r\n\t * @newObject the object the user is trying to put into the square\r\n\t */\r\n\tpublic static void EvePop(){\r\n\tfinal Stage dialog = new Stage();\r\n dialog.initModality(Modality.APPLICATION_MODAL);\r\n VBox dialogVbox = new VBox(20);\r\n dialogVbox.getChildren().add(new Text(\"This space is already full. \\nYou can't put an Object here.\"));\r\n Scene dialogScene = new Scene(dialogVbox, 300, 200);\r\n final Button OKAY = new Button(\"Okay\");\r\n dialogVbox.getChildren().add(OKAY);\r\n dialog.setScene(dialogScene);\r\n dialog.show();\r\n OKAY.setOnAction(\r\n \t\tnew EventHandler(){\r\n \t\t\tpublic void handle(ActionEvent e){\r\n \t\t\t\tdialog.close();\r\n \t\t\t}\r\n \t}\r\n\t);\r\n}\r\n\t\r\n\t\r\n\t\r\n\t\r\n\t/**\r\n\t * Popup if they try delete the wrong thing\r\n\t * @newObject the object the user is trying to put into the square\r\n\t */\r\n\tpublic static void DeletePop(){\r\n\tString oldObject = GridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].getText();\r\n\tfinal Stage dialog = new Stage();\r\n dialog.initModality(Modality.APPLICATION_MODAL);\r\n VBox dialogVbox = new VBox(20);\r\n dialogVbox.getChildren().add(new Text(\"This space is a(n) \"+ oldObject +\". \\nUse the Remove\"+oldObject+\" button.\"));\r\n Scene dialogScene = new Scene(dialogVbox, 300, 200);\r\n final Button OKAY = new Button(\"Okay\");\r\n dialogVbox.getChildren().add(OKAY);\r\n dialog.setScene(dialogScene);\r\n dialog.show();\r\n OKAY.setOnAction(\r\n \t\tnew EventHandler(){\r\n \t\t\tpublic void handle(ActionEvent e){\r\n \t\t\t\tdialog.close();\r\n \t\t\t}\r\n \t}\r\n\t);\r\n}\r\n\t \r\n\t/**\r\n\t * ItemsTab.java\r\n\t */\r\n\tpublic static final void RMITEM_BUTTON_HANDLER(ActionEvent e){\r\n\t\tSystem.out.println(\"RMITEM_BUTTON_HANDLER\");\r\n\t\tString oldObject = GridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].getText();\r\n\t\tswitch(oldObject){\r\n\t\tcase \"Tree\":\r\n\t\t\tGridWorld.getInstance().getWorld().removeItem(new Coordinate(GridWorld.getXCoordinate(),GridWorld.getYCoordinate()));\r\n\t\t\tGridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].setText(\"\");\r\n\t\t\tbreak;\r\n\t\tcase \"Shrub\":\r\n\t\t\tGridWorld.getInstance().getWorld().removeItem(new Coordinate(GridWorld.getXCoordinate(),GridWorld.getYCoordinate()));\r\n\t\t\tGridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].setText(\"\");\r\n\t\t\tbreak; \r\n\t\tcase \"Bamboo\":\r\n\t\t\tGridWorld.getInstance().getWorld().removeItem(new Coordinate(GridWorld.getXCoordinate(),GridWorld.getYCoordinate()));\r\n\t\t\tGridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].setText(\"\");\t\t\t\r\n\t\tdefault: \r\n\t\t\tbreak;\r\n\t\t}\r\n\t}\r\n\tpublic static final void SHRUB_BUTTON_HANDLER(ActionEvent e){\r\n\t\tSystem.out.println(\"SHRUB_BUTTON_HANDLER\");\r\n\t\tString oldObject = GridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].getText();\r\n\t\tif (oldObject.equals(\"Eve!\"))\r\n\t\t\tEvePop();\r\n\t\t\t\r\n\t\telse if (oldObject.equals(\"Tree\") || oldObject.equals(\"Shrub\") || oldObject.equals(\"Bamboo\") || oldObject.equals(\"Friend\")){\r\n\t\t\tpopup(\"Shrub\");\r\n\t\t}\r\n else\r\n\t\t\tGridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].setText(\"Shrub\");\r\n\t\t\tShrub shrub = new Shrub(4, false);\r\n\t\t\tshrub.setCoordinates(new Coordinate(GridWorld.getXCoordinate(), GridWorld.getYCoordinate()));\r\n\t\t\tif(GridWorld.getInstance().getWorld() == null) System.out.println(\"Uninitalized world\");\r\n\t\t\tGridWorld.getInstance().getWorld().addItem(shrub); \r\n\t\t\tGridWorld.getInstance().getWorld().printWorld();\r\n\t}\r\n\t\t\r\n\t\r\n\tpublic static final void TREE_BUTTON_HANDLER(ActionEvent e){\r\n\t\tString oldObject = GridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].getText();\r\n\t\tif (oldObject.equals(\"Eve!\"))\r\n\t\t\tEvePop();\r\n\t\t\t\r\n\t\telse if (oldObject.equals(\"Tree\") || oldObject.equals(\"Shrub\") || oldObject.equals(\"Bamboo\") || oldObject.equals(\"Friend\")){\r\n\t\t\tpopup(\"Tree\");\r\n\t\t\r\n\t\t}\r\n else{\r\n\t\t\tGridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].setText(\"Tree\");\r\n\t\t\tTree tree = new Tree(4);\r\n\t\t\ttree.setCoordinates(new Coordinate(GridWorld.getXCoordinate(), GridWorld.getYCoordinate()));\r\n\t\t\tif(GridWorld.getInstance().getWorld() == null) System.out.println(\"Uninitalized world\");\r\n\t\t\tGridWorld.getInstance().getWorld().addItem(tree); \r\n\t\t\tGridWorld.getInstance().getWorld().printWorld();\r\n }\t\r\n\t}\r\n\t\r\n\tpublic static final void BAMBOO_BUTTON_HANDLER(ActionEvent e){\r\n\t\tSystem.out.println(\"BAMBOO_BUTTON_HANDLER\");\r\n\t\tString oldObject = GridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].getText();\r\n\t\tif (oldObject.equals(\"Eve!\"))\r\n\t\t\tEvePop();\r\n\t\t\t\r\n\t\telse if (oldObject.equals(\"Tree\") || oldObject.equals(\"Shrub\") || oldObject.equals(\"Bamboo\") || oldObject.equals(\"Friend\")){\r\n\t\t\tpopup(\"Bamboo\");\r\n\t\t}\r\n else{\r\n\t\t\tGridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].setText(\"Bamboo\");\r\n\t\t\tBamboo bamboo = new Bamboo(4);\r\n\t\t\tbamboo.setCoordinates(new Coordinate(GridWorld.getXCoordinate(), GridWorld.getYCoordinate()));\r\n\t\t\tif(GridWorld.getInstance().getWorld() == null) System.out.println(\"Uninitalized world\");\r\n\t\t\tGridWorld.getInstance().getWorld().addItem(bamboo); \r\n\t\t\tGridWorld.getInstance().getWorld().printWorld();\r\n }\r\n\t}\t\r\n\t\r\n\t/**\r\n\t * CreaturesTab.java\r\n\t */\r\n\tpublic static final void RMCREATURE_BUTTON_HANDLER(ActionEvent e){\r\n\t\tString oldObject = GridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].getText();\r\n\t\t\tif (oldObject.equals(\"Tree\") || oldObject.equals(\"Shrub\") || oldObject.equals(\"Bamboo\") || oldObject.equals(\"Friend\")){\r\n\t\t\t\t\r\n\t\t\t}\r\n\t\tSystem.out.println(\"RMCREATURE_BUTTON_HANDLER\");\r\n\t\tGridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].setText(\"\");\r\n\t\tGridWorld.getInstance().getWorld().removeCreature(new Coordinate(GridWorld.getXCoordinate(),GridWorld.getYCoordinate()));\r\n\t}\r\n\tpublic static final void EVE_BUTTON_HANDLER(ActionEvent e){\r\n\t\tSystem.out.println(\"EVE_BUTTON_HANDLER\");\r\n\t\tString oldObject = GridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].getText();\r\n\t\t\r\n\t\tfor(int y=0; y < GridWorld.gridButtons.length; y++){\r\n\t\t\tfor(int x=0; x < GridWorld.gridButtons[y].length; x++){\r\n\t\t\t\tif (GridWorld.gridButtons[y][x].getText().equals(\"Eve!\")){\r\n\t\t\t\t\t//frontend move\n\t\t\t\t\tGridWorld.gridButtons[y][x].setText(\" \");\n\t\t\t\t\t\r\n\t\t\t\t\t//backend move\r\n\t\t\t\t\tSystem.out.println(\"X: \" + x + \"Y: \" + y); \r\n\t\t\t\t\tCreature eve = GridWorld.getInstance().getWorld().removeCreature(new Coordinate(y,x)); \r\n\t\t\t\t\teve.setCoordinates(new Coordinate(GridWorld.getXCoordinate(), GridWorld.getYCoordinate()));\r\n\t\t\t\t\teve.setDirection(Coordinate.DOWN);\r\n\t\t\t\t\tGridWorld.getInstance().getWorld().addCreature(eve);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t\t\r\n\t\tif (oldObject.equals(\"Tree\") || oldObject.equals(\"Shrub\") || oldObject.equals(\"Bamboo\") || oldObject.equals(\"Friend\")){\r\n\t\t\tEvePop();\r\n\t\t}\r\n\t\t\r\n else{\r\n\t\t\tGridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].setText(\"Eve!\");\r\n\t\t\tCoordinate cords = new Coordinate(GridWorld.getXCoordinate(),GridWorld.getYCoordinate());\r\n\t\t\tCreature Eve = new Creature(\"Eve!\", cords);\r\n\t\t\tEve.setCoordinates(new Coordinate(GridWorld.getXCoordinate(), GridWorld.getYCoordinate()));\r\n\t\t\tif(GridWorld.getInstance().getWorld() == null) System.out.println(\"Uninitalized world\");\r\n\t\t\tGridWorld.getInstance().getWorld().addCreature(Eve); \r\n\t\t\tGridWorld.getInstance().getWorld().printWorld();\r\n }\r\n\t}\r\n\t\r\n\t\r\n\tpublic static final void FRIENDS_BUTTON_HANDLER(ActionEvent e){\r\n\t\tSystem.out.println(\"FRIENDS_BUTTON_HANDLER\");\r\n\t\tString oldObject = GridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].getText();\r\n\t\t\t\r\n\t\tif (oldObject.equals(\"Tree\") || oldObject.equals(\"Shrub\") || oldObject.equals(\"Bamboo\") || oldObject.equals(\"Eve!\")){\r\n\t\t\tpopup(\"Friend\");\r\n\t\t}\r\n else\r\n\t\t\tGridWorld.gridButtons[GridWorld.getXCoordinate()][GridWorld.getYCoordinate()].setText(\"Friend\");\r\n\t\t\tCoordinate cords = new Coordinate(GridWorld.getXCoordinate(),GridWorld.getYCoordinate());\r\n\t\t\tCreature Friend = new Creature(\"Friend\", cords);\r\n\t\t\tFriend.setCoordinates(new Coordinate(GridWorld.getXCoordinate(), GridWorld.getYCoordinate()));\r\n\t\t\tif(GridWorld.getInstance().getWorld() == null) System.out.println(\"Uninitalized world\");\r\n\t\t\tGridWorld.getInstance().getWorld().addCreature(Friend); \r\n\t\t\tGridWorld.getInstance().getWorld().printWorld();\r\n\t}\r\n\t\r\n\t\r\n\t\r\n\t\t\r\n\t\t\r\n\t\t\r\n\t\r\n\tpublic static final void GridWorld_BUTTON_HANDLER(ActionEvent e){\r\n\t}\r\n\t\r\n\tpublic static final void BACK_BUTTON_HANDLER(ActionEvent e){\r\n\t\tSystem.out.println(\"BACK_BUTTON_HANDLER CALLED\");\r\n\t}\r\n\t\r\n\tpublic static final void FORWARD_BUTTON_HANDLER(ActionEvent e){\r\n\t\tSystem.out.println(\"FORWARD_BUTTON_HANDLER CALLED\");\r\n\t}\r\n\t\r\n\tpublic static final void PLAY_BUTTON_HANDLER(ActionEvent e){\r\n\t\tSystem.out.println(\"PLAY_BUTTON_HANDLER CALLED\");\r\n\t\tArrayList karelCode = KarelTable.getInstance().getKarelCode(); \r\n\t\tWorld world = SandboxScene.getWorld(); \r\n\t\tSystem.out.println(KarelTable.getInstance().getKarelCode());\r\n\t\tInterpreter interpreter = new Interpreter(karelCode, world);\r\n\t\tworld.printWorld();\r\n\t\tinterpreter.start(); //starts the code\r\n\t\tworld.printWorld();\r\n\t}\r\n\r\n\tpublic static final void RESET_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"RESET_BUTTON_HANDLER CALLED\");\r\n\t}\r\n\r\n\tpublic static final void REPLACE_BUTTON_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"REPLACE_BUTTON_HANDLER CALLED\");\r\n\t}\r\n\r\n\tpublic static final void QUIT_MENU_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"Quit sandbox mode. Returned to home screen.\");\r\n\t\tMainApp.changeScenes(MainMenuScene.getInstance());\r\n\t}\r\n\r\n\tpublic static final void SAVE_MENU_HANDLER(ActionEvent e) {\r\n\t\tSystem.out.println(\"Saved!\");\r\n\t}\r\n}\r\n"},"message":{"kind":"string","value":"Fix the karelCode bug."},"old_file":{"kind":"string","value":"src/controllers/ButtonHandlers.java"},"subject":{"kind":"string","value":"Fix the karelCode bug."}}},{"rowIdx":1447,"cells":{"lang":{"kind":"string","value":"Java"},"license":{"kind":"string","value":"mit"},"stderr":{"kind":"string","value":""},"commit":{"kind":"string","value":"aadd20b15c4c466cfea880fd87f0ac6766ac804b"},"returncode":{"kind":"number","value":0,"string":"0"},"repos":{"kind":"string","value":"cs2103aug2014-t17-1j/main"},"new_contents":{"kind":"string","value":"package taskDo;\n\nimport java.util.ArrayList;\n\nimport Parser.ParsedResult;\nimport commandFactory.CommandType;\nimport commandFactory.Search;\nimport commonClasses.Constants;\nimport commonClasses.SummaryReport;\n\npublic class UpdateSummaryReport {\n\n\n\tpublic static void update(ParsedResult parsedResult){\n\t\tSearch search = new Search();\n\n\t\tupdateDisplayTaskList(search.searchByDate(parsedResult));\n\t\tSummaryReport.sortByDueDate();\n\t\tdetermineFeedbackMsg(parsedResult.getCommandType());\n\t}\n\t\n\tpublic static void updateForDisplay(ParsedResult parsedResult, ArrayList displayList){\n\n\t\tupdateDisplayTaskList(displayList);\n\t\tSummaryReport.sortByDueDate();\n\t\tdetermineFeedbackMsg(parsedResult.getCommandType());\n\t}\n\t\n\tpublic static void updateForSearch(ParsedResult parsedResult, ArrayList displayList){\n\n\t\tupdateDisplayTaskList(displayList);\n\t\tSummaryReport.sortByDueDate();\n\t\tif(displayList.isEmpty()){\n\t\t\tupdateFeedbackMsg(Constants.MESSAGE_FAIL_SEARCH);\n\t\t}else{updateFeedbackMsg(Constants.MESSAGE_SUCCESS_SEARCH);}\n\t}\n\n\tprivate static void updateDisplayTaskList(ArrayList displayList) {\n\t\tSummaryReport.setDisplayList(displayList);\n\t}\n\n\tprivate static void determineFeedbackMsg(CommandType commandType) {\n\t\tswitch(commandType){\n\t\tcase ADD:\n\t\t\tupdateFeedbackMsg(Constants.MESSAGE_SUCCESS_ADD);\t\n\t\t\tbreak;\n\t\tcase DELETE:\n\t\t\tupdateFeedbackMsg(Constants.MESSAGE_SUCCESS_DELETE);\n\t\t\tbreak;\n\t\tcase EDIT:\n\t\t\tupdateFeedbackMsg(Constants.MESSAGE_SUCCESS_EDIT);\n\t\t\tbreak;\n\t\tcase DISPLAY:\n\t\t\tupdateFeedbackMsg(Constants.MESSAGE_DISPLAY);\n\t\t\tbreak;\n\t\tcase UNDO:\n\t\t\tupdateFeedbackMsg(Constants.MESSAGE_SUCCESS_UNDO);\n\t\t\tbreak;\n\t\tcase REDO:\n\t\t\tupdateFeedbackMsg(Constants.MESSAGE_SUCCESS_REDO);\n\t\t\tbreak;\n\t\tcase COMPLETED:\n\t\t\tupdateFeedbackMsg(Constants.MESSAGE_SUCCESS_COMPLETED);\n\t\t\tbreak;\n\t\tcase SEARCH:\n\t\t\tupdateFeedbackMsg(Constants.MESSAGE_SUCCESS_SEARCH);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tprivate static void updateFeedbackMsg(String feedbackMsg) {\n\t\tSummaryReport.setFeedBackMsg(feedbackMsg);\n\t}\n}\n\n"},"new_file":{"kind":"string","value":"src/taskDo/UpdateSummaryReport.java"},"old_contents":{"kind":"string","value":"package taskDo;\n\nimport java.util.ArrayList;\n\nimport org.joda.time.format.DateTimeFormat;\nimport org.joda.time.format.DateTimeFormatter;\n\nimport Parser.ParsedResult;\nimport commandFactory.CommandType;\nimport commandFactory.Search;\nimport commonClasses.Constants;\nimport commonClasses.SummaryReport;\n\npublic class UpdateSummaryReport {\n\n\n\tpublic static void update(ParsedResult parsedResult){\n\t\tSearch search = new Search();\n\t\tupdateHeader(parsedResult.getTaskDetails());\n\t\tupdateDisplayTaskList(search.searchByDate(parsedResult));\n\t\tSummaryReport.sortByDueDate();\n\t\tdetermineFeedbackMsg(parsedResult.getCommandType());\n\t}\n\t\n\tpublic static void updateForDisplay(ParsedResult parsedResult, ArrayList displayList){\n\t\tupdateHeader(parsedResult.getTaskDetails());\n\t\tupdateDisplayTaskList(displayList);\n\t\tSummaryReport.sortByDueDate();\n\t\tdetermineFeedbackMsg(parsedResult.getCommandType());\n\t}\n\t\n\tpublic static void updateForSearch(ParsedResult parsedResult, ArrayList displayList){\n\t\tupdateHeader(parsedResult.getTaskDetails());\n\t\tupdateDisplayTaskList(displayList);\n\t\tSummaryReport.sortByDueDate();\n\t\tif(displayList.isEmpty()){\n\t\t\tupdateFeedbackMsg(Constants.MESSAGE_FAIL_SEARCH);\n\t\t}else{updateFeedbackMsg(Constants.MESSAGE_SUCCESS_SEARCH);}\n\t}\n\n\tprivate static void updateHeader(Task task) {\n\t\tif(isSomeday(task)) {\n\t\t\tSummaryReport.setHeader(Constants.MESSAGE_SOMEDAY);\n\t\t} else {\n\t\t\tDateTimeFormatter dateFormat = DateTimeFormat.forPattern(\"dd-MM-yyyy\");\n\t\t\tString dateDisplay = dateFormat.print(task.getDueDate().toLocalDate());\n\t\t\tSummaryReport.setHeader(dateDisplay);\n\t\t}\n\t}\n\n\tprivate static boolean isSomeday(Task refTask) {\n\t\treturn refTask.getDueDate().toLocalDate().getYear() == Constants.NILL_YEAR;\n\t}\n\n\tprivate static void updateDisplayTaskList(ArrayList displayList) {\n\t\tSummaryReport.setDisplayList(displayList);\n\t}\n\n\tprivate static void determineFeedbackMsg(CommandType commandType) {\n\t\tswitch(commandType){\n\t\tcase ADD:\n\t\t\tupdateFeedbackMsg(Constants.MESSAGE_SUCCESS_ADD);\t\n\t\t\tbreak;\n\t\tcase DELETE:\n\t\t\tupdateFeedbackMsg(Constants.MESSAGE_SUCCESS_DELETE);\n\t\t\tbreak;\n\t\tcase EDIT:\n\t\t\tupdateFeedbackMsg(Constants.MESSAGE_SUCCESS_EDIT);\n\t\t\tbreak;\n\t\tcase DISPLAY:\n\t\t\tupdateFeedbackMsg(Constants.MESSAGE_DISPLAY);\n\t\t\tbreak;\n\t\tcase UNDO:\n\t\t\tupdateFeedbackMsg(Constants.MESSAGE_SUCCESS_UNDO);\n\t\t\tbreak;\n\t\tcase REDO:\n\t\t\tupdateFeedbackMsg(Constants.MESSAGE_SUCCESS_REDO);\n\t\t\tbreak;\n\t\tcase COMPLETED:\n\t\t\tupdateFeedbackMsg(Constants.MESSAGE_SUCCESS_COMPLETED);\n\t\t\tbreak;\n\t\tcase SEARCH:\n\t\t\tupdateFeedbackMsg(Constants.MESSAGE_SUCCESS_SEARCH);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tprivate static void updateFeedbackMsg(String feedbackMsg) {\n\t\tSummaryReport.setFeedBackMsg(feedbackMsg);\n\t}\n}\n\n"},"message":{"kind":"string","value":"cancel display header\n"},"old_file":{"kind":"string","value":"src/taskDo/UpdateSummaryReport.java"},"subject":{"kind":"string","value":"cancel display header"}}},{"rowIdx":1448,"cells":{"lang":{"kind":"string","value":"Java"},"license":{"kind":"string","value":"epl-1.0"},"stderr":{"kind":"string","value":""},"commit":{"kind":"string","value":"17eb511d4498c35eef2c4701d96fc9f60a237768"},"returncode":{"kind":"number","value":0,"string":"0"},"repos":{"kind":"string","value":"inevo/mondrian,inevo/mondrian"},"new_contents":{"kind":"string","value":"/*\n// $Id$\n// This software is subject to the terms of the Eclipse Public License v1.0\n// Agreement, available at the following URL:\n// http://www.eclipse.org/legal/epl-v10.html.\n// Copyright (C) 2003-2009 Julian Hyde\n// All Rights Reserved.\n// You must accept the terms of that agreement to use this software.\n//\n// jhyde, Feb 14, 2003\n*/\npackage mondrian.test;\n\nimport mondrian.olap.*;\nimport mondrian.olap.type.NumericType;\nimport mondrian.olap.type.Type;\nimport mondrian.rolap.RolapConnectionProperties;\nimport mondrian.spi.UserDefinedFunction;\nimport mondrian.spi.Dialect;\nimport mondrian.util.Bug;\nimport mondrian.calc.ResultStyle;\n\nimport java.util.regex.Pattern;\nimport java.util.*;\n\nimport junit.framework.Assert;\n\n/**\n * BasicQueryTest
is a test case which tests simple queries\n * against the FoodMart database.\n *\n * @author jhyde\n * @since Feb 14, 2003\n * @version $Id$\n */\npublic class BasicQueryTest extends FoodMartTestCase {\n static final String EmptyResult =\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"Axis #2:\\n\";\n\n private static final String timeWeekly =\n TestContext.hierarchyName(\"Time\", \"Weekly\");\n\n private MondrianProperties props = MondrianProperties.instance();\n\n public BasicQueryTest() {\n super();\n }\n\n public BasicQueryTest(String name) {\n super(name);\n }\n\n private static final QueryAndResult[] sampleQueries = {\n // 0\n new QueryAndResult(\n \"select {[Measures].[Unit Sales]} on columns\\n\" + \" from Sales\",\n\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Row #0: 266,773\\n\"),\n\n // 1\n new QueryAndResult(\n \"select\\n\"\n + \" {[Measures].[Unit Sales]} on columns,\\n\"\n + \" order(except([Promotion Media].[Media Type].members,{[Promotion Media].[Media Type].[No Media]}),[Measures].[Unit Sales],DESC) on rows\\n\"\n + \"from Sales \",\n\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Promotion Media].[All Media].[Daily Paper, Radio, TV]}\\n\"\n + \"{[Promotion Media].[All Media].[Daily Paper]}\\n\"\n + \"{[Promotion Media].[All Media].[Product Attachment]}\\n\"\n + \"{[Promotion Media].[All Media].[Daily Paper, Radio]}\\n\"\n + \"{[Promotion Media].[All Media].[Cash Register Handout]}\\n\"\n + \"{[Promotion Media].[All Media].[Sunday Paper, Radio]}\\n\"\n + \"{[Promotion Media].[All Media].[Street Handout]}\\n\"\n + \"{[Promotion Media].[All Media].[Sunday Paper]}\\n\"\n + \"{[Promotion Media].[All Media].[Bulk Mail]}\\n\"\n + \"{[Promotion Media].[All Media].[In-Store Coupon]}\\n\"\n + \"{[Promotion Media].[All Media].[TV]}\\n\"\n + \"{[Promotion Media].[All Media].[Sunday Paper, Radio, TV]}\\n\"\n + \"{[Promotion Media].[All Media].[Radio]}\\n\"\n + \"Row #0: 9,513\\n\"\n + \"Row #1: 7,738\\n\"\n + \"Row #2: 7,544\\n\"\n + \"Row #3: 6,891\\n\"\n + \"Row #4: 6,697\\n\"\n + \"Row #5: 5,945\\n\"\n + \"Row #6: 5,753\\n\"\n + \"Row #7: 4,339\\n\"\n + \"Row #8: 4,320\\n\"\n + \"Row #9: 3,798\\n\"\n + \"Row #10: 3,607\\n\"\n + \"Row #11: 2,726\\n\"\n + \"Row #12: 2,454\\n\"),\n\n // 2\n new QueryAndResult(\n \"select\\n\"\n + \" { [Measures].[Units Shipped], [Measures].[Units Ordered] } on columns,\\n\"\n + \" NON EMPTY [Store].[Store Name].members on rows\\n\"\n + \"from Warehouse\",\n\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Units Shipped]}\\n\"\n + \"{[Measures].[Units Ordered]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[Beverly Hills].[Store 6]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[Los Angeles].[Store 7]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[San Diego].[Store 24]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[San Francisco].[Store 14]}\\n\"\n + \"{[Store].[All Stores].[USA].[OR].[Portland].[Store 11]}\\n\"\n + \"{[Store].[All Stores].[USA].[OR].[Salem].[Store 13]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Bellingham].[Store 2]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Bremerton].[Store 3]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Seattle].[Store 15]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Spokane].[Store 16]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Tacoma].[Store 17]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Walla Walla].[Store 22]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Yakima].[Store 23]}\\n\"\n + \"Row #0: 10759.0\\n\"\n + \"Row #0: 11699.0\\n\"\n + \"Row #1: 24587.0\\n\"\n + \"Row #1: 26463.0\\n\"\n + \"Row #2: 23835.0\\n\"\n + \"Row #2: 26270.0\\n\"\n + \"Row #3: 1696.0\\n\"\n + \"Row #3: 1875.0\\n\"\n + \"Row #4: 8515.0\\n\"\n + \"Row #4: 9109.0\\n\"\n + \"Row #5: 32393.0\\n\"\n + \"Row #5: 35797.0\\n\"\n + \"Row #6: 2348.0\\n\"\n + \"Row #6: 2454.0\\n\"\n + \"Row #7: 22734.0\\n\"\n + \"Row #7: 24610.0\\n\"\n + \"Row #8: 24110.0\\n\"\n + \"Row #8: 26703.0\\n\"\n + \"Row #9: 11889.0\\n\"\n + \"Row #9: 12828.0\\n\"\n + \"Row #10: 32411.0\\n\"\n + \"Row #10: 35930.0\\n\"\n + \"Row #11: 1860.0\\n\"\n + \"Row #11: 2074.0\\n\"\n + \"Row #12: 10589.0\\n\"\n + \"Row #12: 11426.0\\n\"),\n\n // 3\n new QueryAndResult(\n \"with member [Measures].[Store Sales Last Period] as \"\n + \" '([Measures].[Store Sales], Time.[Time].PrevMember)',\\n\"\n + \" format='#,###.00'\\n\"\n + \"select\\n\"\n + \" {[Measures].[Store Sales Last Period]} on columns,\\n\"\n + \" {TopCount([Product].[Product Department].members,5, [Measures].[Store Sales Last Period])} on rows\\n\"\n + \"from Sales\\n\"\n + \"where ([Time].[1998])\",\n\n \"Axis #0:\\n\"\n + \"{[Time].[1998]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Store Sales Last Period]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Product].[All Products].[Food].[Produce]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods]}\\n\"\n + \"{[Product].[All Products].[Non-Consumable].[Household]}\\n\"\n + \"{[Product].[All Products].[Food].[Frozen Foods]}\\n\"\n + \"{[Product].[All Products].[Food].[Canned Foods]}\\n\"\n + \"Row #0: 82,248.42\\n\"\n + \"Row #1: 67,609.82\\n\"\n + \"Row #2: 60,469.89\\n\"\n + \"Row #3: 55,207.50\\n\"\n + \"Row #4: 39,774.34\\n\"),\n\n // 4\n new QueryAndResult(\n \"with member [Measures].[Total Store Sales] as 'Sum(YTD(),[Measures].[Store Sales])', format_string='#.00'\\n\"\n + \"select\\n\"\n + \" {[Measures].[Total Store Sales]} on columns,\\n\"\n + \" {TopCount([Product].[Product Department].members,5, [Measures].[Total Store Sales])} on rows\\n\"\n + \"from Sales\\n\"\n + \"where ([Time].[1997].[Q2].[4])\",\n\n \"Axis #0:\\n\"\n + \"{[Time].[1997].[Q2].[4]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Total Store Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Product].[All Products].[Food].[Produce]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods]}\\n\"\n + \"{[Product].[All Products].[Non-Consumable].[Household]}\\n\"\n + \"{[Product].[All Products].[Food].[Frozen Foods]}\\n\"\n + \"{[Product].[All Products].[Food].[Canned Foods]}\\n\"\n + \"Row #0: 26526.67\\n\"\n + \"Row #1: 21897.10\\n\"\n + \"Row #2: 19980.90\\n\"\n + \"Row #3: 17882.63\\n\"\n + \"Row #4: 12963.23\\n\"),\n\n // 5\n new QueryAndResult(\n \"with member [Measures].[Store Profit Rate] as '([Measures].[Store Sales]-[Measures].[Store Cost])/[Measures].[Store Cost]', format = '#.00%'\\n\"\n + \"select\\n\"\n + \" {[Measures].[Store Cost],[Measures].[Store Sales],[Measures].[Store Profit Rate]} on columns,\\n\"\n + \" Order([Product].[Product Department].members, [Measures].[Store Profit Rate], BDESC) on rows\\n\"\n + \"from Sales\\n\"\n + \"where ([Time].[1997])\",\n\n \"Axis #0:\\n\"\n + \"{[Time].[1997]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Store Cost]}\\n\"\n + \"{[Measures].[Store Sales]}\\n\"\n + \"{[Measures].[Store Profit Rate]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Product].[All Products].[Food].[Breakfast Foods]}\\n\"\n + \"{[Product].[All Products].[Non-Consumable].[Carousel]}\\n\"\n + \"{[Product].[All Products].[Food].[Canned Products]}\\n\"\n + \"{[Product].[All Products].[Food].[Baking Goods]}\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages]}\\n\"\n + \"{[Product].[All Products].[Non-Consumable].[Health and Hygiene]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods]}\\n\"\n + \"{[Product].[All Products].[Food].[Baked Goods]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages]}\\n\"\n + \"{[Product].[All Products].[Food].[Frozen Foods]}\\n\"\n + \"{[Product].[All Products].[Non-Consumable].[Periodicals]}\\n\"\n + \"{[Product].[All Products].[Food].[Produce]}\\n\"\n + \"{[Product].[All Products].[Food].[Seafood]}\\n\"\n + \"{[Product].[All Products].[Food].[Deli]}\\n\"\n + \"{[Product].[All Products].[Food].[Meat]}\\n\"\n + \"{[Product].[All Products].[Food].[Canned Foods]}\\n\"\n + \"{[Product].[All Products].[Non-Consumable].[Household]}\\n\"\n + \"{[Product].[All Products].[Food].[Starchy Foods]}\\n\"\n + \"{[Product].[All Products].[Food].[Eggs]}\\n\"\n + \"{[Product].[All Products].[Food].[Snacks]}\\n\"\n + \"{[Product].[All Products].[Food].[Dairy]}\\n\"\n + \"{[Product].[All Products].[Drink].[Dairy]}\\n\"\n + \"{[Product].[All Products].[Non-Consumable].[Checkout]}\\n\"\n + \"Row #0: 2,756.80\\n\"\n + \"Row #0: 6,941.46\\n\"\n + \"Row #0: 151.79%\\n\"\n + \"Row #1: 595.97\\n\"\n + \"Row #1: 1,500.11\\n\"\n + \"Row #1: 151.71%\\n\"\n + \"Row #2: 1,317.13\\n\"\n + \"Row #2: 3,314.52\\n\"\n + \"Row #2: 151.65%\\n\"\n + \"Row #3: 15,370.61\\n\"\n + \"Row #3: 38,670.41\\n\"\n + \"Row #3: 151.59%\\n\"\n + \"Row #4: 5,576.79\\n\"\n + \"Row #4: 14,029.08\\n\"\n + \"Row #4: 151.56%\\n\"\n + \"Row #5: 12,972.99\\n\"\n + \"Row #5: 32,571.86\\n\"\n + \"Row #5: 151.07%\\n\"\n + \"Row #6: 26,963.34\\n\"\n + \"Row #6: 67,609.82\\n\"\n + \"Row #6: 150.75%\\n\"\n + \"Row #7: 6,564.09\\n\"\n + \"Row #7: 16,455.43\\n\"\n + \"Row #7: 150.69%\\n\"\n + \"Row #8: 11,069.53\\n\"\n + \"Row #8: 27,748.53\\n\"\n + \"Row #8: 150.67%\\n\"\n + \"Row #9: 22,030.66\\n\"\n + \"Row #9: 55,207.50\\n\"\n + \"Row #9: 150.59%\\n\"\n + \"Row #10: 3,614.55\\n\"\n + \"Row #10: 9,056.76\\n\"\n + \"Row #10: 150.56%\\n\"\n + \"Row #11: 32,831.33\\n\"\n + \"Row #11: 82,248.42\\n\"\n + \"Row #11: 150.52%\\n\"\n + \"Row #12: 1,520.70\\n\"\n + \"Row #12: 3,809.14\\n\"\n + \"Row #12: 150.49%\\n\"\n + \"Row #13: 10,108.87\\n\"\n + \"Row #13: 25,318.93\\n\"\n + \"Row #13: 150.46%\\n\"\n + \"Row #14: 1,465.42\\n\"\n + \"Row #14: 3,669.89\\n\"\n + \"Row #14: 150.43%\\n\"\n + \"Row #15: 15,894.53\\n\"\n + \"Row #15: 39,774.34\\n\"\n + \"Row #15: 150.24%\\n\"\n + \"Row #16: 24,170.73\\n\"\n + \"Row #16: 60,469.89\\n\"\n + \"Row #16: 150.18%\\n\"\n + \"Row #17: 4,705.91\\n\"\n + \"Row #17: 11,756.07\\n\"\n + \"Row #17: 149.82%\\n\"\n + \"Row #18: 3,684.90\\n\"\n + \"Row #18: 9,200.76\\n\"\n + \"Row #18: 149.69%\\n\"\n + \"Row #19: 5,827.58\\n\"\n + \"Row #19: 14,550.05\\n\"\n + \"Row #19: 149.68%\\n\"\n + \"Row #20: 12,228.85\\n\"\n + \"Row #20: 30,508.85\\n\"\n + \"Row #20: 149.48%\\n\"\n + \"Row #21: 2,830.92\\n\"\n + \"Row #21: 7,058.60\\n\"\n + \"Row #21: 149.34%\\n\"\n + \"Row #22: 1,525.04\\n\"\n + \"Row #22: 3,767.71\\n\"\n + \"Row #22: 147.06%\\n\"),\n\n // 6\n new QueryAndResult(\n \"with\\n\"\n + \" member [Product].[All Products].[Drink].[Percent of Alcoholic Drinks] as '[Product].[All Products].[Drink].[Alcoholic Beverages]/[Product].[All Products].[Drink]',\\n\"\n + \" format_string = '#.00%'\\n\"\n + \"select\\n\"\n + \" { [Product].[All Products].[Drink].[Percent of Alcoholic Drinks] } on columns,\\n\"\n + \" order([Customers].[All Customers].[USA].[WA].Children, [Product].[All Products].[Drink].[Percent of Alcoholic Drinks],BDESC) on rows\\n\"\n + \"from Sales\\n\"\n + \"where ([Measures].[Unit Sales])\",\n\n \"Axis #0:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Product].[All Products].[Drink].[Percent of Alcoholic Drinks]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Seattle]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Kirkland]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Marysville]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Anacortes]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Olympia]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Ballard]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Bremerton]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Puyallup]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Yakima]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Tacoma]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Everett]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Renton]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Issaquah]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Bellingham]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Port Orchard]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Redmond]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Spokane]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Burien]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Lynnwood]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Walla Walla]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Edmonds]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Sedro Woolley]}\\n\"\n + \"Row #0: 44.05%\\n\"\n + \"Row #1: 34.41%\\n\"\n + \"Row #2: 34.20%\\n\"\n + \"Row #3: 32.93%\\n\"\n + \"Row #4: 31.05%\\n\"\n + \"Row #5: 30.84%\\n\"\n + \"Row #6: 30.69%\\n\"\n + \"Row #7: 29.81%\\n\"\n + \"Row #8: 28.82%\\n\"\n + \"Row #9: 28.70%\\n\"\n + \"Row #10: 28.37%\\n\"\n + \"Row #11: 26.67%\\n\"\n + \"Row #12: 26.60%\\n\"\n + \"Row #13: 26.47%\\n\"\n + \"Row #14: 26.42%\\n\"\n + \"Row #15: 26.28%\\n\"\n + \"Row #16: 25.96%\\n\"\n + \"Row #17: 24.70%\\n\"\n + \"Row #18: 21.89%\\n\"\n + \"Row #19: 21.47%\\n\"\n + \"Row #20: 17.47%\\n\"\n + \"Row #21: 13.79%\\n\"),\n\n // 7\n new QueryAndResult(\n \"with member [Measures].[Accumulated Sales] as 'Sum(YTD(),[Measures].[Store Sales])'\\n\"\n + \"select\\n\"\n + \" {[Measures].[Store Sales],[Measures].[Accumulated Sales]} on columns,\\n\"\n + \" {Descendants([Time].[1997],[Time].[Month])} on rows\\n\"\n + \"from Sales\",\n\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Store Sales]}\\n\"\n + \"{[Measures].[Accumulated Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Time].[1997].[Q1].[1]}\\n\"\n + \"{[Time].[1997].[Q1].[2]}\\n\"\n + \"{[Time].[1997].[Q1].[3]}\\n\"\n + \"{[Time].[1997].[Q2].[4]}\\n\"\n + \"{[Time].[1997].[Q2].[5]}\\n\"\n + \"{[Time].[1997].[Q2].[6]}\\n\"\n + \"{[Time].[1997].[Q3].[7]}\\n\"\n + \"{[Time].[1997].[Q3].[8]}\\n\"\n + \"{[Time].[1997].[Q3].[9]}\\n\"\n + \"{[Time].[1997].[Q4].[10]}\\n\"\n + \"{[Time].[1997].[Q4].[11]}\\n\"\n + \"{[Time].[1997].[Q4].[12]}\\n\"\n + \"Row #0: 45,539.69\\n\"\n + \"Row #0: 45,539.69\\n\"\n + \"Row #1: 44,058.79\\n\"\n + \"Row #1: 89,598.48\\n\"\n + \"Row #2: 50,029.87\\n\"\n + \"Row #2: 139,628.35\\n\"\n + \"Row #3: 42,878.25\\n\"\n + \"Row #3: 182,506.60\\n\"\n + \"Row #4: 44,456.29\\n\"\n + \"Row #4: 226,962.89\\n\"\n + \"Row #5: 45,331.73\\n\"\n + \"Row #5: 272,294.62\\n\"\n + \"Row #6: 50,246.88\\n\"\n + \"Row #6: 322,541.50\\n\"\n + \"Row #7: 46,199.04\\n\"\n + \"Row #7: 368,740.54\\n\"\n + \"Row #8: 43,825.97\\n\"\n + \"Row #8: 412,566.51\\n\"\n + \"Row #9: 42,342.27\\n\"\n + \"Row #9: 454,908.78\\n\"\n + \"Row #10: 53,363.71\\n\"\n + \"Row #10: 508,272.49\\n\"\n + \"Row #11: 56,965.64\\n\"\n + \"Row #11: 565,238.13\\n\"),\n\n // 8\n new QueryAndResult(\n \"select {[Measures].[Promotion Sales]} on columns\\n\"\n + \" from Sales\",\n\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Promotion Sales]}\\n\"\n + \"Row #0: 151,211.21\\n\"),\n };\n\n public void testSample0() {\n assertQueryReturns(sampleQueries[0].query, sampleQueries[0].result);\n }\n\n public void testSample1() {\n assertQueryReturns(sampleQueries[1].query, sampleQueries[1].result);\n }\n\n public void testSample2() {\n assertQueryReturns(sampleQueries[2].query, sampleQueries[2].result);\n }\n\n public void testSample3() {\n assertQueryReturns(sampleQueries[3].query, sampleQueries[3].result);\n }\n\n public void testSample4() {\n assertQueryReturns(sampleQueries[4].query, sampleQueries[4].result);\n }\n\n public void testSample5() {\n assertQueryReturns(sampleQueries[5].query, sampleQueries[5].result);\n }\n\n public void testSample6() {\n assertQueryReturns(sampleQueries[6].query, sampleQueries[6].result);\n }\n\n public void testSample7() {\n assertQueryReturns(sampleQueries[7].query, sampleQueries[7].result);\n }\n\n public void testSample8() {\n if (TestContext.instance().getDialect().getDatabaseProduct()\n == Dialect.DatabaseProduct.INFOBRIGHT)\n {\n // Skip this test on Infobright, because [Promotion Sales] is\n // defined wrong.\n return;\n }\n assertQueryReturns(sampleQueries[8].query, sampleQueries[8].result);\n }\n\n public void testGoodComments() {\n assertQueryReturns(\n \"SELECT {} ON ROWS, {} ON COLUMNS FROM [Sales]/* trailing comment*/\",\n EmptyResult);\n\n String[] comments = {\n \"-- a basic comment\\n\",\n\n \"// another basic comment\\n\",\n\n \"/* yet another basic comment */\",\n\n \"-- a more complicated comment test\\n\",\n\n \"-- to make it more intesting, -- we'll nest this comment\\n\",\n\n \"-- also, \\\"we can put a string in the comment\\\"\\n\",\n\n \"-- also, 'even a single quote string'\\n\",\n\n \"---- and, the comment delimiter is looong\\n\",\n\n \"/*\\n\"\n + \" * next, how about a comment block?\\n\"\n + \" * with several lines.\\n\"\n + \" * also, \\\"we can put a string in the comment\\\"\\n\"\n + \" * also, 'even a single quote string'\\n\"\n + \" * also, -- another style comment is happy\\n\"\n + \" */\\n\",\n\n \"/* a simple /* nested */ comment */\",\n\n \"/*\\n\" + \" * a multiline /* nested */ comment\\n\" + \"*/\",\n\n \"/*\\n\"\n + \" * a multiline\\n\"\n + \" * /* multiline\\n\"\n + \" * * nested comment\\n\"\n + \" * */\\n\"\n + \"*/\",\n\n \"/*\\n\"\n + \" * a multiline\\n\"\n + \" * /* multiline\\n\"\n + \" * /* deeply\\n\"\n + \" * /* really /* deeply */\\n\"\n + \" * * nested comment\\n\"\n + \" * */\\n\"\n + \" * */\\n\"\n + \" * */\\n\"\n + \"*/\",\n\n \"-- single-line comment containing /* multiline */ comment\\n\",\n\n \"/* multi-line comment containing -- single-line comment */\",\n };\n\n\n List allCommentList = new ArrayList();\n for (String comment : comments) {\n allCommentList.add(comment);\n if (comment.indexOf(\"\\n\") >= 0) {\n allCommentList.add(comment.replaceAll(\"\\n\", \"\\r\\n\"));\n allCommentList.add(comment.replaceAll(\"\\n\", \"\\n\\r\"));\n allCommentList.add(comment.replaceAll(\"\\n\", \" \\n \\n \"));\n }\n }\n allCommentList.add(\"\");\n final String[] allComments =\n allCommentList.toArray(new String[allCommentList.size()]);\n\n // The last element of the array is the concatenation of all other\n // comments.\n StringBuilder buf = new StringBuilder();\n for (String allComment : allComments) {\n buf.append(allComment);\n }\n allComments[allComments.length - 1] = buf.toString();\n\n // Comment at start of query.\n for (String comment : allComments) {\n assertQueryReturns(\n comment + \"SELECT {} ON ROWS, {} ON COLUMNS FROM [Sales]\",\n EmptyResult);\n }\n\n // Comment after SELECT.\n for (String comment : allComments) {\n assertQueryReturns(\n \"SELECT\" + comment + \"{} ON ROWS, {} ON COLUMNS FROM [Sales]\",\n EmptyResult);\n }\n\n // Comment within braces.\n for (String comment : allComments) {\n assertQueryReturns(\n \"SELECT {\" + comment + \"} ON ROWS, {} ON COLUMNS FROM [Sales]\",\n EmptyResult);\n }\n\n // Comment after axis name.\n for (String comment : allComments) {\n assertQueryReturns(\n \"SELECT {} ON ROWS\" + comment + \", {} ON COLUMNS FROM [Sales]\",\n EmptyResult);\n }\n\n // Comment before slicer.\n for (String comment : allComments) {\n assertQueryReturns(\n \"SELECT {} ON ROWS, {} ON COLUMNS FROM [Sales] WHERE\"\n + comment\n + \"([Gender].[F])\",\n \"Axis #0:\\n\"\n + \"{[Gender].[All Gender].[F]}\\n\"\n + \"Axis #1:\\n\"\n + \"Axis #2:\\n\");\n }\n\n // Comment after query.\n for (String comment : allComments) {\n assertQueryReturns(\n \"SELECT {} ON ROWS, {} ON COLUMNS FROM [Sales]\" + comment,\n EmptyResult);\n }\n\n\n assertQueryReturns(\n \"-- a comment test with carriage returns at the end of the lines\\r\\n\"\n + \"-- first, more than one single-line comment in a row\\r\\n\"\n + \"-- and, to make it more intesting, -- we'll nest this comment\\r\\n\"\n + \"-- also, \\\"we can put a string in the comment\\\"\\r\\n\"\n + \"-- also, 'even a single quote string'\\r\\n\"\n + \"---- and, the comment delimiter is looong\\r\\n\"\n + \"/*\\r\\n\"\n + \" * next, now about a comment block?\\r\\n\"\n + \" * with several lines.\\r\\n\"\n + \" * also, \\\"we can put a string in the comment\\\"\\r\\n\"\n + \" * also, 'even a single quote comment'\\r\\n\"\n + \" * also, -- another style comment is heppy\\r\\n\"\n + \" * also, // another style comment is heppy\\r\\n\"\n + \" */\\r\\n\"\n + \"SELECT {} ON ROWS, {} ON COLUMNS FROM [Sales]\\r\",\n EmptyResult);\n\n assertQueryReturns(\n \"/* a simple /* nested */ comment */\\n\"\n + \"/*\\n\"\n + \" * a multiline /* nested */ comment\\n\"\n + \"*/\\n\"\n + \"/*\\n\"\n + \" * a multiline\\n\"\n + \" * /* multiline\\n\"\n + \" * * nested comment\\n\"\n + \" * */\\n\"\n + \"*/\\n\"\n + \"/*\\n\"\n + \" * a multiline\\n\"\n + \" * /* multiline\\n\"\n + \" * /* deeply\\n\"\n + \" * /* really /* deeply */\\n\"\n + \" * * nested comment\\n\"\n + \" * */\\n\"\n + \" * */\\n\"\n + \" * */\\n\"\n + \"*/\\n\"\n + \"SELECT {} ON ROWS, {} ON COLUMNS FROM [Sales]\",\n EmptyResult);\n\n assertQueryReturns(\n \"-- an entire select statement commented out\\n\"\n + \"-- SELECT {} ON ROWS, {} ON COLUMNS FROM [Sales];\\n\"\n + \"/*SELECT {} ON ROWS, {} ON COLUMNS FROM [Sales];*/\\n\"\n + \"// SELECT {} ON ROWS, {} ON COLUMNS FROM [Sales];\\n\"\n + \"SELECT {} ON ROWS, {} ON COLUMNS FROM [Sales]\",\n EmptyResult);\n\n assertQueryReturns(\n \"// now for some comments in a larger command\\n\"\n + \"with // create calculate measure [Product].[All Products].[Drink].[Percent of Alcoholic Drinks]\\n\"\n + \" member [Product].[All Products].[Drink].[Percent of Alcoholic Drinks]/*the measure name*/as ' // begin the definition of the measure next\\n\"\n + \" [Product]./****this is crazy****/[All Products].[Drink].[Alcoholic Beverages]/[Product].[All Products].[Drink]', // divide number of alcoholic drinks by total # of drinks\\n\"\n + \" format_string = '#.00%' // a custom format for our measure\\n\"\n + \"select\\n\"\n + \" { [Product]/**** still crazy ****/.[All Products].[Drink].[Percent of Alcoholic Drinks] } on columns,\\n\"\n + \" order(/****do not put a comment inside square brackets****/[Customers].[All Customers].[USA].[WA].Children, [Product].[All Products].[Drink].[Percent of Alcoholic Drinks],BDESC) on rows\\n\"\n + \"from Sales\\n\"\n + \"where ([Measures].[Unit Sales] /****,[Time].[1997]****/) -- a comment at the end of the command\",\n\n \"Axis #0:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Product].[All Products].[Drink].[Percent of Alcoholic Drinks]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Seattle]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Kirkland]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Marysville]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Anacortes]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Olympia]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Ballard]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Bremerton]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Puyallup]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Yakima]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Tacoma]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Everett]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Renton]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Issaquah]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Bellingham]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Port Orchard]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Redmond]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Spokane]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Burien]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Lynnwood]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Walla Walla]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Edmonds]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA].[Sedro Woolley]}\\n\"\n + \"Row #0: 44.05%\\n\"\n + \"Row #1: 34.41%\\n\"\n + \"Row #2: 34.20%\\n\"\n + \"Row #3: 32.93%\\n\"\n + \"Row #4: 31.05%\\n\"\n + \"Row #5: 30.84%\\n\"\n + \"Row #6: 30.69%\\n\"\n + \"Row #7: 29.81%\\n\"\n + \"Row #8: 28.82%\\n\"\n + \"Row #9: 28.70%\\n\"\n + \"Row #10: 28.37%\\n\"\n + \"Row #11: 26.67%\\n\"\n + \"Row #12: 26.60%\\n\"\n + \"Row #13: 26.47%\\n\"\n + \"Row #14: 26.42%\\n\"\n + \"Row #15: 26.28%\\n\"\n + \"Row #16: 25.96%\\n\"\n + \"Row #17: 24.70%\\n\"\n + \"Row #18: 21.89%\\n\"\n + \"Row #19: 21.47%\\n\"\n + \"Row #20: 17.47%\\n\"\n + \"Row #21: 13.79%\\n\");\n }\n\n public void testBadComments() {\n // Comments cannot appear inside identifiers.\n assertQueryThrows(\n \"SELECT {[Measures].[Unit Sales]} ON COLUMNS,\\n\"\n + \" {[Gender].MEMBERS} ON ROWS\\n\"\n + \"FROM [Sales]\\n\"\n + \"WHERE {[/***an illegal comment****/Marital Status].[S]}\",\n \"Failed to parse query\");\n\n // Nested comments must be closed.\n assertQueryThrows(\n \"/* a simple /* nested * comment */\\n\"\n + \"SELECT {} ON ROWS, {} ON COLUMNS FROM [Sales]\",\n \"Failed to parse query\");\n\n // We do NOT support \\r as a line-end delimiter. (Too bad, Mac users.)\n assertQueryThrows(\n \"SELECT {} ON COLUMNS -- comment terminated by CR only\\r, {} ON ROWS FROM [Sales]\",\n \"Failed to parse query\");\n }\n\n /**\n * Tests that a query whose axes are empty works; bug\n * MONDRIAN-52.\n */\n public void testBothAxesEmpty() {\n assertQueryReturns(\n \"SELECT {} ON ROWS, {} ON COLUMNS FROM [Sales]\",\n EmptyResult);\n\n // expression which evaluates to empty set\n assertQueryReturns(\n \"SELECT Filter({[Gender].MEMBERS}, 1 = 0) ON COLUMNS, \\n\"\n + \"{} ON ROWS\\n\"\n + \"FROM [Sales]\",\n EmptyResult);\n\n // with slicer\n assertQueryReturns(\n \"SELECT {} ON ROWS, {} ON COLUMNS \\n\"\n + \"FROM [Sales] WHERE ([Gender].[F])\",\n \"Axis #0:\\n\"\n + \"{[Gender].[All Gender].[F]}\\n\"\n + \"Axis #1:\\n\"\n + \"Axis #2:\\n\");\n }\n\n /**\n * Tests that a slicer with multiple values gives an error; bug\n * MONDRIAN-96.\n */\n public void testCompoundSlicerFails() {\n // two tuples\n assertQueryReturns(\n \"SELECT {[Measures].[Unit Sales]} ON COLUMNS,\\n\"\n + \" {[Gender].MEMBERS} ON ROWS\\n\"\n + \"FROM [Sales]\\n\"\n + \"WHERE {([Marital Status].[S]),\\n\"\n + \" ([Marital Status].[M])}\",\n \"Axis #0:\\n\"\n + \"{[Marital Status].[All Marital Status].[S]}\\n\"\n + \"{[Marital Status].[All Marital Status].[M]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Gender].[All Gender]}\\n\"\n + \"{[Gender].[All Gender].[F]}\\n\"\n + \"{[Gender].[All Gender].[M]}\\n\"\n + \"Row #0: 266,773\\n\"\n + \"Row #1: 131,558\\n\"\n + \"Row #2: 135,215\\n\");\n\n // set with incompatible members\n assertQueryThrows(\n \"SELECT {[Measures].[Unit Sales]} ON COLUMNS,\\n\"\n + \" {[Gender].MEMBERS} ON ROWS\\n\"\n + \"FROM [Sales]\\n\"\n + \"WHERE {[Marital Status].[S],\\n\"\n + \" [Product]}\",\n \"All arguments to function '{}' must have same hierarchy.\");\n\n // expression which evaluates to a set with zero members used to be an\n // error - now it's ok; cells are null because they are aggregating over\n // nothing\n assertQueryReturns(\n \"SELECT {[Measures].[Unit Sales]} ON COLUMNS,\\n\"\n + \" {[Gender].MEMBERS} ON ROWS\\n\"\n + \"FROM [Sales]\\n\"\n + \"WHERE Filter({[Marital Status].MEMBERS}, 1 = 0)\",\n \"Axis #0:\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Gender].[All Gender]}\\n\"\n + \"{[Gender].[All Gender].[F]}\\n\"\n + \"{[Gender].[All Gender].[M]}\\n\"\n + \"Row #0: \\n\"\n + \"Row #1: \\n\"\n + \"Row #2: \\n\");\n\n // expression which evaluates to a not-null member is ok\n assertQueryReturns(\n \"SELECT {[Measures].[Unit Sales]} ON COLUMNS,\\n\"\n + \" {[Gender].MEMBERS} ON ROWS\\n\"\n + \"FROM [Sales]\\n\"\n + \"WHERE ({Filter({[Marital Status].MEMBERS}, [Measures].[Unit Sales] = 266773)}.Item(0))\",\n \"Axis #0:\\n\"\n + \"{[Marital Status].[All Marital Status]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Gender].[All Gender]}\\n\"\n + \"{[Gender].[All Gender].[F]}\\n\"\n + \"{[Gender].[All Gender].[M]}\\n\"\n + \"Row #0: 266,773\\n\"\n + \"Row #1: 131,558\\n\"\n + \"Row #2: 135,215\\n\");\n\n // Expression which evaluates to a null member used to be an error; now\n // it is an unsatisfiable condition, so cells come out empty.\n // Confirmed with SSAS 2005.\n assertQueryReturns(\n \"SELECT {[Measures].[Unit Sales]} ON COLUMNS,\\n\"\n + \" {[Gender].MEMBERS} ON ROWS\\n\"\n + \"FROM [Sales]\\n\"\n + \"WHERE [Marital Status].Parent\",\n \"Axis #0:\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Gender].[All Gender]}\\n\"\n + \"{[Gender].[All Gender].[F]}\\n\"\n + \"{[Gender].[All Gender].[M]}\\n\"\n + \"Row #0: \\n\"\n + \"Row #1: \\n\"\n + \"Row #2: \\n\");\n\n // expression which evaluates to a set with one member is ok\n assertQueryReturns(\n \"SELECT {[Measures].[Unit Sales]} ON COLUMNS,\\n\"\n + \" {[Gender].MEMBERS} ON ROWS\\n\"\n + \"FROM [Sales]\\n\"\n + \"WHERE Filter({[Marital Status].MEMBERS}, [Measures].[Unit Sales] = 266773)\",\n \"Axis #0:\\n\"\n + \"{[Marital Status].[All Marital Status]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Gender].[All Gender]}\\n\"\n + \"{[Gender].[All Gender].[F]}\\n\"\n + \"{[Gender].[All Gender].[M]}\\n\"\n + \"Row #0: 266,773\\n\"\n + \"Row #1: 131,558\\n\"\n + \"Row #2: 135,215\\n\");\n\n // slicer expression which evaluates to three tuples is not ok\n assertQueryReturns(\n \"SELECT {[Measures].[Unit Sales]} ON COLUMNS,\\n\"\n + \" {[Gender].MEMBERS} ON ROWS\\n\"\n + \"FROM [Sales]\\n\"\n + \"WHERE Filter({[Marital Status].MEMBERS}, [Measures].[Unit Sales] <= 266773)\",\n \"Axis #0:\\n\"\n + \"{[Marital Status].[All Marital Status]}\\n\"\n + \"{[Marital Status].[All Marital Status].[M]}\\n\"\n + \"{[Marital Status].[All Marital Status].[S]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Gender].[All Gender]}\\n\"\n + \"{[Gender].[All Gender].[F]}\\n\"\n + \"{[Gender].[All Gender].[M]}\\n\"\n + \"Row #0: 266,773\\n\"\n + \"Row #1: 131,558\\n\"\n + \"Row #2: 135,215\\n\");\n\n // set with incompatible members\n assertQueryThrows(\n \"SELECT {[Measures].[Unit Sales]} ON COLUMNS,\\n\"\n + \" {[Gender].MEMBERS} ON ROWS\\n\"\n + \"FROM [Sales]\\n\"\n + \"WHERE {[Marital Status].[S],\\n\"\n + \" [Product]}\",\n \"All arguments to function '{}' must have same hierarchy.\");\n\n // two members of same dimension in columns and rows\n assertQueryThrows(\n \"SELECT CrossJoin(\\n\"\n + \" {[Measures].[Unit Sales]},\\n\"\n + \" {[Gender].[M]}) ON COLUMNS,\\n\"\n + \" {[Gender].MEMBERS} ON ROWS\\n\"\n + \"FROM [Sales]\",\n \"Hierarchy '[Gender]' appears in more than one independent axis.\");\n\n // two members of same dimension in rows and filter\n assertQueryThrows(\n \"SELECT {[Measures].[Unit Sales]} ON COLUMNS,\\n\"\n + \" {[Gender].MEMBERS} ON ROWS\\n\"\n + \"FROM [Sales]\"\n + \"WHERE ([Marital Status].[S], [Gender].[F])\",\n \"Hierarchy '[Gender]' appears in more than one independent axis.\");\n\n // members of different hierarchies of the same dimension in rows and\n // filter\n assertQueryReturns(\n \"SELECT {[Measures].[Unit Sales]} ON COLUMNS,\\n\"\n + \" {[Time].[1997].Children} ON ROWS\\n\"\n + \"FROM [Sales]\"\n + \"WHERE ([Marital Status].[S], \" + timeWeekly + \".[1997].[20])\",\n \"Axis #0:\\n\"\n + \"{[Marital Status].[All Marital Status].[S], [Time].[Weekly].[All Weeklys].[1997].[20]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Time].[1997].[Q1]}\\n\"\n + \"{[Time].[1997].[Q2]}\\n\"\n + \"{[Time].[1997].[Q3]}\\n\"\n + \"{[Time].[1997].[Q4]}\\n\"\n + \"Row #0: \\n\"\n + \"Row #1: 3,523\\n\"\n + \"Row #2: \\n\"\n + \"Row #3: \\n\");\n\n // two members of same dimension in slicer tuple\n assertQueryThrows(\n \"SELECT {[Measures].[Unit Sales]} ON COLUMNS,\\n\"\n + \" {[Gender].MEMBERS} ON ROWS\\n\"\n + \"FROM [Sales]\"\n + \"WHERE ([Marital Status].[S], [Marital Status].[M])\",\n \"Tuple contains more than one member of hierarchy '[Marital Status]'.\");\n\n // two members of different hierarchies of the same dimension in the\n // slicer tuple\n assertQueryReturns(\n \"SELECT {[Measures].[Unit Sales]} ON COLUMNS,\\n\"\n + \" {[Gender].MEMBERS} ON ROWS\\n\"\n + \"FROM [Sales]\"\n + \"WHERE ([Time].[1997].[Q1], \" + timeWeekly + \".[1997].[4])\",\n \"Axis #0:\\n\"\n + \"{[Time].[1997].[Q1], [Time].[Weekly].[All Weeklys].[1997].[4]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Gender].[All Gender]}\\n\"\n + \"{[Gender].[All Gender].[F]}\\n\"\n + \"{[Gender].[All Gender].[M]}\\n\"\n + \"Row #0: 4,908\\n\"\n + \"Row #1: 2,354\\n\"\n + \"Row #2: 2,554\\n\");\n\n // testcase for bug MONDRIAN-68, \"Member appears in slicer and other\n // axis should be illegal\"\n assertQueryThrows(\n \"select\\n\"\n + \"{[Measures].[Unit Sales]} on columns,\\n\"\n + \"{([Product].[All Products], [Time].[1997])} ON rows\\n\"\n + \"from Sales\\n\"\n + \"where ([Time].[1997])\",\n \"Hierarchy '[Time]' appears in more than one independent axis.\");\n\n // different hierarchies of same dimension on slicer and other axis\n assertQueryReturns(\n \"select\\n\"\n + \"{[Measures].[Unit Sales]} on columns,\\n\"\n + \"{([Product].[All Products], \"\n + timeWeekly + \".[1997])} ON rows\\n\"\n + \"from Sales\\n\"\n + \"where ([Time].[1997])\",\n \"Axis #0:\\n\"\n + \"{[Time].[1997]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Product].[All Products], [Time].[Weekly].[All Weeklys].[1997]}\\n\"\n + \"Row #0: 266,773\\n\");\n }\n\n public void testEmptyTupleSlicerFails() {\n assertQueryThrows(\n \"select [Measures].[Unit Sales] on 0,\\n\"\n + \"[Product].Children on 1\\n\"\n + \"from [Warehouse and Sales]\\n\"\n + \"where ()\",\n \"Syntax error at line 4, column 10, token ')'\");\n }\n\n /**\n * Requires the use of a sparse segment, because the product dimension\n * has 6 atttributes, the product of whose cardinalities is ~8M. If we\n * use a dense segment, we run out of memory trying to allocate a huge\n * array.\n */\n public void testBigQuery() {\n Result result = executeQuery(\n \"SELECT {[Measures].[Unit Sales]} on columns,\\n\"\n + \" {[Product].members} on rows\\n\"\n + \"from Sales\");\n final int rowCount = result.getAxes()[1].getPositions().size();\n assertEquals(2256, rowCount);\n assertEquals(\n \"152\",\n result.getCell(\n new int[]{\n 0, rowCount - 1\n }).getFormattedValue());\n }\n\n public void testNonEmpty1() {\n assertSize(\n \"select\\n\"\n + \" NON EMPTY CrossJoin({[Product].[All Products].[Drink].Children},\\n\"\n + \" {[Customers].[All Customers].[USA].[WA].[Bellingham]}) on rows,\\n\"\n + \" CrossJoin(\\n\"\n + \" {[Measures].[Unit Sales], [Measures].[Store Sales]},\\n\"\n + \" { [Promotion Media].[All Media].[Radio],\\n\"\n + \" [Promotion Media].[All Media].[TV],\\n\"\n + \" [Promotion Media].[All Media].[Sunday Paper],\\n\"\n + \" [Promotion Media].[All Media].[Street Handout] }\\n\"\n + \" ) on columns\\n\"\n + \"from Sales\\n\"\n + \"where ([Time].[1997])\",\n 8, 2);\n }\n\n public void testNonEmpty2() {\n assertSize(\n \"select\\n\"\n + \" NON EMPTY CrossJoin(\\n\"\n + \" {[Product].[All Products].Children},\\n\"\n + \" {[Customers].[All Customers].[USA].[WA].[Bellingham]}) on rows,\\n\"\n + \" NON EMPTY CrossJoin(\\n\"\n + \" {[Measures].[Unit Sales]},\\n\"\n + \" { [Promotion Media].[All Media].[Cash Register Handout],\\n\"\n + \" [Promotion Media].[All Media].[Sunday Paper],\\n\"\n + \" [Promotion Media].[All Media].[Street Handout] }\\n\"\n + \" ) on columns\\n\"\n + \"from Sales\\n\"\n + \"where ([Time].[1997])\",\n 2, 2);\n }\n\n public void testOneDimensionalQueryWithTupleAsSlicer() {\n Result result = executeQuery(\n \"select\\n\"\n + \" [Product].[All Products].[Drink].children on columns\\n\"\n + \"from Sales\\n\"\n + \"where ([Measures].[Unit Sales], [Promotion Media].[All Media].[Street Handout], [Time].[1997])\");\n assertTrue(result.getAxes().length == 1);\n assertTrue(result.getAxes()[0].getPositions().size() == 3);\n assertTrue(result.getSlicerAxis().getPositions().size() == 1);\n assertTrue(result.getSlicerAxis().getPositions().get(0).size() == 3);\n }\n\n public void testSlicerIsEvaluatedBeforeAxes() {\n // about 10 products exceeded 20000 units in 1997, only 2 for Q1\n assertSize(\n \"SELECT {[Measures].[Unit Sales]} on columns,\\n\"\n + \" filter({[Product].members}, [Measures].[Unit Sales] > 20000) on rows\\n\"\n + \"FROM Sales\\n\"\n + \"WHERE [Time].[1997].[Q1]\", 1, 2);\n }\n\n public void testSlicerWithCalculatedMembers() {\n assertSize(\n \"WITH MEMBER [Time].[1997].[H1] as ' Aggregate({[Time].[1997].[Q1], [Time].[1997].[Q2]})' \\n\"\n + \" MEMBER [Measures].[Store Margin] as '[Measures].[Store Sales] - [Measures].[Store Cost]'\\n\"\n + \"SELECT {[Gender].children} on columns,\\n\"\n + \" filter({[Product].members}, [Gender].[F] > 10000) on rows\\n\"\n + \"FROM Sales\\n\"\n + \"WHERE ([Time].[1997].[H1], [Measures].[Store Margin])\",\n 2,\n 6);\n }\n\n public void _testEver() {\n assertQueryReturns(\n \"select\\n\"\n + \" {[Measures].[Unit Sales], [Measures].[Ever]} on columns,\\n\"\n + \" [Gender].members on rows\\n\"\n + \"from Sales\", \"xxx\");\n }\n\n public void _testDairy() {\n assertQueryReturns(\n \"with\\n\"\n + \" member [Product].[Non dairy] as '[Product].[All Products] - [Product].[Food].[Dairy]'\\n\"\n + \" member [Measures].[Dairy ever] as 'sum([Time].members, ([Measures].[Unit Sales],[Product].[Food].[Dairy]))'\\n\"\n + \" set [Customers who never bought dairy] as 'filter([Customers].members, [Measures].[Dairy ever] = 0)'\\n\"\n + \"select\\n\"\n + \" {[Measures].[Unit Sales], [Measures].[Dairy ever]} on columns,\\n\"\n + \" [Customers who never bought dairy] on rows\\n\"\n + \"from Sales\", \"xxx\");\n }\n\n public void testSolveOrder() {\n assertQueryReturns(\n \"WITH\\n\"\n + \" MEMBER [Measures].[StoreType] AS \\n\"\n + \" '[Store].CurrentMember.Properties(\\\"Store Type\\\")',\\n\"\n + \" SOLVE_ORDER = 2\\n\"\n + \" MEMBER [Measures].[ProfitPct] AS \\n\"\n + \" '(Measures.[Store Sales] - Measures.[Store Cost]) / Measures.[Store Sales]',\\n\"\n + \" SOLVE_ORDER = 1, FORMAT_STRING = '##.00%'\\n\"\n + \"SELECT\\n\"\n + \" { Descendants([Store].[USA], [Store].[Store Name])} ON COLUMNS,\\n\"\n + \" { [Measures].[Store Sales], [Measures].[Store Cost], [Measures].[StoreType],\\n\"\n + \" [Measures].[ProfitPct] } ON ROWS\\n\"\n + \"FROM Sales\",\n\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[Alameda].[HQ]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[Beverly Hills].[Store 6]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[Los Angeles].[Store 7]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[San Diego].[Store 24]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[San Francisco].[Store 14]}\\n\"\n + \"{[Store].[All Stores].[USA].[OR].[Portland].[Store 11]}\\n\"\n + \"{[Store].[All Stores].[USA].[OR].[Salem].[Store 13]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Bellingham].[Store 2]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Bremerton].[Store 3]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Seattle].[Store 15]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Spokane].[Store 16]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Tacoma].[Store 17]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Walla Walla].[Store 22]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Yakima].[Store 23]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Measures].[Store Sales]}\\n\"\n + \"{[Measures].[Store Cost]}\\n\"\n + \"{[Measures].[StoreType]}\\n\"\n + \"{[Measures].[ProfitPct]}\\n\"\n + \"Row #0: \\n\"\n + \"Row #0: 45,750.24\\n\"\n + \"Row #0: 54,545.28\\n\"\n + \"Row #0: 54,431.14\\n\"\n + \"Row #0: 4,441.18\\n\"\n + \"Row #0: 55,058.79\\n\"\n + \"Row #0: 87,218.28\\n\"\n + \"Row #0: 4,739.23\\n\"\n + \"Row #0: 52,896.30\\n\"\n + \"Row #0: 52,644.07\\n\"\n + \"Row #0: 49,634.46\\n\"\n + \"Row #0: 74,843.96\\n\"\n + \"Row #0: 4,705.97\\n\"\n + \"Row #0: 24,329.23\\n\"\n + \"Row #1: \\n\"\n + \"Row #1: 18,266.44\\n\"\n + \"Row #1: 21,771.54\\n\"\n + \"Row #1: 21,713.53\\n\"\n + \"Row #1: 1,778.92\\n\"\n + \"Row #1: 21,948.94\\n\"\n + \"Row #1: 34,823.56\\n\"\n + \"Row #1: 1,896.62\\n\"\n + \"Row #1: 21,121.96\\n\"\n + \"Row #1: 20,956.80\\n\"\n + \"Row #1: 19,795.49\\n\"\n + \"Row #1: 29,959.28\\n\"\n + \"Row #1: 1,880.34\\n\"\n + \"Row #1: 9,713.81\\n\"\n + \"Row #2: HeadQuarters\\n\"\n + \"Row #2: Gourmet Supermarket\\n\"\n + \"Row #2: Supermarket\\n\"\n + \"Row #2: Supermarket\\n\"\n + \"Row #2: Small Grocery\\n\"\n + \"Row #2: Supermarket\\n\"\n + \"Row #2: Deluxe Supermarket\\n\"\n + \"Row #2: Small Grocery\\n\"\n + \"Row #2: Supermarket\\n\"\n + \"Row #2: Supermarket\\n\"\n + \"Row #2: Supermarket\\n\"\n + \"Row #2: Deluxe Supermarket\\n\"\n + \"Row #2: Small Grocery\\n\"\n + \"Row #2: Mid-Size Grocery\\n\"\n + \"Row #3: \\n\"\n + \"Row #3: 60.07%\\n\"\n + \"Row #3: 60.09%\\n\"\n + \"Row #3: 60.11%\\n\"\n + \"Row #3: 59.94%\\n\"\n + \"Row #3: 60.14%\\n\"\n + \"Row #3: 60.07%\\n\"\n + \"Row #3: 59.98%\\n\"\n + \"Row #3: 60.07%\\n\"\n + \"Row #3: 60.19%\\n\"\n + \"Row #3: 60.12%\\n\"\n + \"Row #3: 59.97%\\n\"\n + \"Row #3: 60.04%\\n\"\n + \"Row #3: 60.07%\\n\");\n }\n\n public void testSolveOrderNonMeasure() {\n assertQueryReturns(\n \"WITH\\n\"\n + \" MEMBER [Product].[ProdCalc] as '1', SOLVE_ORDER=1\\n\"\n + \" MEMBER [Measures].[MeasuresCalc] as '2', SOLVE_ORDER=2\\n\"\n + \" MEMBER [Time].[TimeCalc] as '3', SOLVE_ORDER=3\\n\"\n + \"SELECT\\n\"\n + \" { [Product].[ProdCalc] } ON columns,\\n\"\n + \" {([Time].[TimeCalc], [Measures].[MeasuresCalc])} ON rows\\n\"\n + \"FROM Sales\",\n\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Product].[ProdCalc]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Time].[TimeCalc], [Measures].[MeasuresCalc]}\\n\"\n + \"Row #0: 3\\n\");\n }\n\n public void testSolveOrderNonMeasure2() {\n assertQueryReturns(\n \"WITH\\n\"\n + \" MEMBER [Store].[StoreCalc] as '0', SOLVE_ORDER=0\\n\"\n + \" MEMBER [Product].[ProdCalc] as '1', SOLVE_ORDER=1\\n\"\n + \"SELECT\\n\"\n + \" { [Product].[ProdCalc] } ON columns,\\n\"\n + \" { [Store].[StoreCalc] } ON rows\\n\"\n + \"FROM Sales\",\n\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Product].[ProdCalc]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Store].[StoreCalc]}\\n\"\n + \"Row #0: 1\\n\");\n }\n\n /**\n * Test what happens when the solve orders are the same. According to\n * http://msdn.microsoft.com/library/en-us/olapdmad/agmdxadvanced_6jn7.asp\n * if solve orders are the same then the dimension specified first\n * when defining the cube wins.\n *\n * In the first test, the answer should be 1 because Promotions\n * comes before Customers in the FoodMart.xml schema.\n */\n public void testSolveOrderAmbiguous1() {\n assertQueryReturns(\n \"WITH\\n\"\n + \" MEMBER [Promotions].[Calc] AS '1'\\n\"\n + \" MEMBER [Customers].[Calc] AS '2'\\n\"\n + \"SELECT\\n\"\n + \" { [Promotions].[Calc] } ON COLUMNS,\\n\"\n + \" { [Customers].[Calc] } ON ROWS\\n\"\n + \"FROM Sales\",\n\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Promotions].[Calc]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Customers].[Calc]}\\n\"\n + \"Row #0: 1\\n\");\n }\n\n /**\n * In the second test, the answer should be 2 because Product comes before\n * Promotions in the FoodMart.xml schema.\n */\n public void testSolveOrderAmbiguous2() {\n assertQueryReturns(\n \"WITH\\n\"\n + \" MEMBER [Promotions].[Calc] AS '1'\\n\"\n + \" MEMBER [Product].[Calc] AS '2'\\n\"\n + \"SELECT\\n\"\n + \" { [Promotions].[Calc] } ON COLUMNS,\\n\"\n + \" { [Product].[Calc] } ON ROWS\\n\"\n + \"FROM Sales\",\n\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Promotions].[Calc]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Product].[Calc]}\\n\"\n + \"Row #0: 2\\n\");\n }\n\n public void testCalculatedMemberWhichIsNotAMeasure() {\n assertQueryReturns(\n \"WITH MEMBER [Product].[BigSeller] AS\\n\"\n + \" 'IIf([Product].[Drink].[Alcoholic Beverages].[Beer and Wine] > 100, \\\"Yes\\\",\\\"No\\\")'\\n\"\n + \"SELECT {[Product].[BigSeller],[Product].children} ON COLUMNS,\\n\"\n + \" {[Store].[All Stores].[USA].[CA].children} ON ROWS\\n\"\n + \"FROM Sales\",\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Product].[BigSeller]}\\n\"\n + \"{[Product].[All Products].[Drink]}\\n\"\n + \"{[Product].[All Products].[Food]}\\n\"\n + \"{[Product].[All Products].[Non-Consumable]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[Alameda]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[Beverly Hills]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[Los Angeles]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[San Diego]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[San Francisco]}\\n\"\n + \"Row #0: No\\n\"\n + \"Row #0: \\n\"\n + \"Row #0: \\n\"\n + \"Row #0: \\n\"\n + \"Row #1: Yes\\n\"\n + \"Row #1: 1,945\\n\"\n + \"Row #1: 15,438\\n\"\n + \"Row #1: 3,950\\n\"\n + \"Row #2: Yes\\n\"\n + \"Row #2: 2,422\\n\"\n + \"Row #2: 18,294\\n\"\n + \"Row #2: 4,947\\n\"\n + \"Row #3: Yes\\n\"\n + \"Row #3: 2,560\\n\"\n + \"Row #3: 18,369\\n\"\n + \"Row #3: 4,706\\n\"\n + \"Row #4: No\\n\"\n + \"Row #4: 175\\n\"\n + \"Row #4: 1,555\\n\"\n + \"Row #4: 387\\n\");\n }\n\n public void testMultipleCalculatedMembersWhichAreNotMeasures() {\n assertQueryReturns(\n \"WITH\\n\"\n + \" MEMBER [Store].[x] AS '1'\\n\"\n + \" MEMBER [Product].[x] AS '1'\\n\"\n + \"SELECT {[Store].[x]} ON COLUMNS\\n\"\n + \"FROM Sales\",\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Store].[x]}\\n\"\n + \"Row #0: 1\\n\");\n }\n\n /**\n * There used to be something wrong with non-measure calculated members\n * where the ordering of the WITH MEMBER would determine whether or not\n * the member would be found in the cube. This test would fail but the\n * previous one would work ok. (see sf#1084651)\n */\n public void testMultipleCalculatedMembersWhichAreNotMeasures2() {\n assertQueryReturns(\n \"WITH\\n\"\n + \" MEMBER [Product].[x] AS '1'\\n\"\n + \" MEMBER [Store].[x] AS '1'\\n\"\n + \"SELECT {[Store].[x]} ON COLUMNS\\n\"\n + \"FROM Sales\",\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Store].[x]}\\n\"\n + \"Row #0: 1\\n\");\n }\n\n /**\n * This one had the same problem. It wouldn't find the\n * [Store].[All Stores].[x] member because it has the same leaf\n * name as [Product].[All Products].[x]. (see sf#1084651)\n */\n public void testMultipleCalculatedMembersWhichAreNotMeasures3() {\n assertQueryReturns(\n \"WITH\\n\"\n + \" MEMBER [Product].[All Products].[x] AS '1'\\n\"\n + \" MEMBER [Store].[All Stores].[x] AS '1'\\n\"\n + \"SELECT {[Store].[All Stores].[x]} ON COLUMNS\\n\"\n + \"FROM Sales\",\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Store].[All Stores].[x]}\\n\"\n + \"Row #0: 1\\n\");\n }\n\n public void testConstantString() {\n String s = executeExpr(\" \\\"a string\\\" \");\n assertEquals(\"a string\", s);\n }\n\n public void testConstantNumber() {\n String s = executeExpr(\" 1234 \");\n assertEquals(\"1,234\", s);\n }\n\n public void testCyclicalCalculatedMembers() {\n Util.discard(\n executeQuery(\n \"WITH\\n\"\n + \" MEMBER [Product].[X] AS '[Product].[Y]'\\n\"\n + \" MEMBER [Product].[Y] AS '[Product].[X]'\\n\"\n + \"SELECT\\n\"\n + \" {[Product].[X]} ON COLUMNS,\\n\"\n + \" {Store.[Store Name].Members} ON ROWS\\n\"\n + \"FROM Sales\"));\n }\n\n /**\n * Disabled test. It used throw an 'infinite loop' error (which is what\n * Plato does). But now we revert to the context of the default member when\n * calculating calculated members (we used to stay in the context of the\n * calculated member), and we get a result.\n */\n public void testCycle() {\n if (false) {\n assertExprThrows(\"[Time].[1997].[Q4]\", \"infinite loop\");\n } else {\n String s = executeExpr(\"[Time].[1997].[Q4]\");\n assertEquals(\"72,024\", s);\n }\n }\n\n public void testHalfYears() {\n Util.discard(\n executeQuery(\n \"WITH MEMBER [Measures].[ProfitPercent] AS\\n\"\n + \" '([Measures].[Store Sales]-[Measures].[Store Cost])/([Measures].[Store Cost])',\\n\"\n + \" FORMAT_STRING = '#.00%', SOLVE_ORDER = 1\\n\"\n + \" MEMBER [Time].[First Half 97] AS '[Time].[1997].[Q1] + [Time].[1997].[Q2]'\\n\"\n + \" MEMBER [Time].[Second Half 97] AS '[Time].[1997].[Q3] + [Time].[1997].[Q4]'\\n\"\n + \" SELECT {[Time].[First Half 97],\\n\"\n + \" [Time].[Second Half 97],\\n\"\n + \" [Time].[1997].CHILDREN} ON COLUMNS,\\n\"\n + \" {[Store].[Store Country].[USA].CHILDREN} ON ROWS\\n\"\n + \" FROM [Sales]\\n\"\n + \" WHERE ([Measures].[ProfitPercent])\"));\n }\n\n public void _testHalfYearsTrickyCase() {\n Util.discard(\n executeQuery(\n \"WITH MEMBER MEASURES.ProfitPercent AS\\n\"\n + \" '([Measures].[Store Sales]-[Measures].[Store Cost])/([Measures].[Store Cost])',\\n\"\n + \" FORMAT_STRING = '#.00%', SOLVE_ORDER = 1\\n\"\n + \" MEMBER [Time].[First Half 97] AS '[Time].[1997].[Q1] + [Time].[1997].[Q2]'\\n\"\n + \" MEMBER [Time].[Second Half 97] AS '[Time].[1997].[Q3] + [Time].[1997].[Q4]'\\n\"\n + \" SELECT {[Time].[First Half 97],\\n\"\n + \" [Time].[Second Half 97],\\n\"\n + \" [Time].[1997].CHILDREN} ON COLUMNS,\\n\"\n + \" {[Store].[Store Country].[USA].CHILDREN} ON ROWS\\n\"\n + \" FROM [Sales]\\n\"\n + \" WHERE (MEASURES.ProfitPercent)\"));\n }\n\n public void testAsSample7ButUsingVirtualCube() {\n Util.discard(\n executeQuery(\n \"with member [Measures].[Accumulated Sales] as 'Sum(YTD(),[Measures].[Store Sales])'\\n\"\n + \"select\\n\"\n + \" {[Measures].[Store Sales],[Measures].[Accumulated Sales]} on columns,\\n\"\n + \" {Descendants([Time].[1997],[Time].[Month])} on rows\\n\"\n + \"from [Warehouse and Sales]\"));\n }\n\n public void testVirtualCube() {\n assertQueryReturns(\n // Note that Unit Sales is independent of Warehouse.\n \"select CrossJoin(\\n\"\n + \" {[Warehouse].DefaultMember, [Warehouse].[USA].children},\\n\"\n + \" {[Measures].[Unit Sales], [Measures].[Store Sales], [Measures].[Units Shipped]}) on columns,\\n\"\n + \" [Time].[Time].children on rows\\n\"\n + \"from [Warehouse and Sales]\",\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Warehouse].[All Warehouses], [Measures].[Unit Sales]}\\n\"\n + \"{[Warehouse].[All Warehouses], [Measures].[Store Sales]}\\n\"\n + \"{[Warehouse].[All Warehouses], [Measures].[Units Shipped]}\\n\"\n + \"{[Warehouse].[All Warehouses].[USA].[CA], [Measures].[Unit Sales]}\\n\"\n + \"{[Warehouse].[All Warehouses].[USA].[CA], [Measures].[Store Sales]}\\n\"\n + \"{[Warehouse].[All Warehouses].[USA].[CA], [Measures].[Units Shipped]}\\n\"\n + \"{[Warehouse].[All Warehouses].[USA].[OR], [Measures].[Unit Sales]}\\n\"\n + \"{[Warehouse].[All Warehouses].[USA].[OR], [Measures].[Store Sales]}\\n\"\n + \"{[Warehouse].[All Warehouses].[USA].[OR], [Measures].[Units Shipped]}\\n\"\n + \"{[Warehouse].[All Warehouses].[USA].[WA], [Measures].[Unit Sales]}\\n\"\n + \"{[Warehouse].[All Warehouses].[USA].[WA], [Measures].[Store Sales]}\\n\"\n + \"{[Warehouse].[All Warehouses].[USA].[WA], [Measures].[Units Shipped]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Time].[1997].[Q1]}\\n\"\n + \"{[Time].[1997].[Q2]}\\n\"\n + \"{[Time].[1997].[Q3]}\\n\"\n + \"{[Time].[1997].[Q4]}\\n\"\n + \"Row #0: 66,291\\n\"\n + \"Row #0: 139,628.35\\n\"\n + \"Row #0: 50951.0\\n\"\n + \"Row #0: \\n\"\n + \"Row #0: \\n\"\n + \"Row #0: 8539.0\\n\"\n + \"Row #0: \\n\"\n + \"Row #0: \\n\"\n + \"Row #0: 7994.0\\n\"\n + \"Row #0: \\n\"\n + \"Row #0: \\n\"\n + \"Row #0: 34418.0\\n\"\n + \"Row #1: 62,610\\n\"\n + \"Row #1: 132,666.27\\n\"\n + \"Row #1: 49187.0\\n\"\n + \"Row #1: \\n\"\n + \"Row #1: \\n\"\n + \"Row #1: 15726.0\\n\"\n + \"Row #1: \\n\"\n + \"Row #1: \\n\"\n + \"Row #1: 7575.0\\n\"\n + \"Row #1: \\n\"\n + \"Row #1: \\n\"\n + \"Row #1: 25886.0\\n\"\n + \"Row #2: 65,848\\n\"\n + \"Row #2: 140,271.89\\n\"\n + \"Row #2: 57789.0\\n\"\n + \"Row #2: \\n\"\n + \"Row #2: \\n\"\n + \"Row #2: 20821.0\\n\"\n + \"Row #2: \\n\"\n + \"Row #2: \\n\"\n + \"Row #2: 8673.0\\n\"\n + \"Row #2: \\n\"\n + \"Row #2: \\n\"\n + \"Row #2: 28295.0\\n\"\n + \"Row #3: 72,024\\n\"\n + \"Row #3: 152,671.62\\n\"\n + \"Row #3: 49799.0\\n\"\n + \"Row #3: \\n\"\n + \"Row #3: \\n\"\n + \"Row #3: 15791.0\\n\"\n + \"Row #3: \\n\"\n + \"Row #3: \\n\"\n + \"Row #3: 16666.0\\n\"\n + \"Row #3: \\n\"\n + \"Row #3: \\n\"\n + \"Row #3: 17342.0\\n\");\n }\n\n public void testUseDimensionAsShorthandForMember() {\n Util.discard(\n executeQuery(\n \"select {[Measures].[Unit Sales]} on columns,\\n\"\n + \" {[Store], [Store].children} on rows\\n\"\n + \"from [Sales]\"));\n }\n\n public void _testMembersFunction() {\n Util.discard(\n executeQuery(\n \"select {[Measures].[Unit Sales]} on columns,\\n\"\n + \" {[Customers].members(0)} on rows\\n\"\n + \"from [Sales]\"));\n }\n\n public void _testProduct2() {\n final Axis axis = getTestContext().executeAxis(\"{[Product2].members}\");\n System.out.println(TestContext.toString(axis.getPositions()));\n }\n\n private static final List taglibQueries = Arrays.asList(\n // 0\n new QueryAndResult(\n \"select\\n\"\n + \" {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} on columns,\\n\"\n + \" CrossJoin(\\n\"\n + \" { [Promotion Media].[All Media].[Radio],\\n\"\n + \" [Promotion Media].[All Media].[TV],\\n\"\n + \" [Promotion Media].[All Media].[Sunday Paper],\\n\"\n + \" [Promotion Media].[All Media].[Street Handout] },\\n\"\n + \" [Product].[All Products].[Drink].children) on rows\\n\"\n + \"from Sales\\n\"\n + \"where ([Time].[1997])\",\n\n \"Axis #0:\\n\"\n + \"{[Time].[1997]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"{[Measures].[Store Cost]}\\n\"\n + \"{[Measures].[Store Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Promotion Media].[All Media].[Radio], [Product].[All Products].[Drink].[Alcoholic Beverages]}\\n\"\n + \"{[Promotion Media].[All Media].[Radio], [Product].[All Products].[Drink].[Beverages]}\\n\"\n + \"{[Promotion Media].[All Media].[Radio], [Product].[All Products].[Drink].[Dairy]}\\n\"\n + \"{[Promotion Media].[All Media].[TV], [Product].[All Products].[Drink].[Alcoholic Beverages]}\\n\"\n + \"{[Promotion Media].[All Media].[TV], [Product].[All Products].[Drink].[Beverages]}\\n\"\n + \"{[Promotion Media].[All Media].[TV], [Product].[All Products].[Drink].[Dairy]}\\n\"\n + \"{[Promotion Media].[All Media].[Sunday Paper], [Product].[All Products].[Drink].[Alcoholic Beverages]}\\n\"\n + \"{[Promotion Media].[All Media].[Sunday Paper], [Product].[All Products].[Drink].[Beverages]}\\n\"\n + \"{[Promotion Media].[All Media].[Sunday Paper], [Product].[All Products].[Drink].[Dairy]}\\n\"\n + \"{[Promotion Media].[All Media].[Street Handout], [Product].[All Products].[Drink].[Alcoholic Beverages]}\\n\"\n + \"{[Promotion Media].[All Media].[Street Handout], [Product].[All Products].[Drink].[Beverages]}\\n\"\n + \"{[Promotion Media].[All Media].[Street Handout], [Product].[All Products].[Drink].[Dairy]}\\n\"\n + \"Row #0: 75\\n\"\n + \"Row #0: 70.40\\n\"\n + \"Row #0: 168.62\\n\"\n + \"Row #1: 97\\n\"\n + \"Row #1: 75.70\\n\"\n + \"Row #1: 186.03\\n\"\n + \"Row #2: 54\\n\"\n + \"Row #2: 36.75\\n\"\n + \"Row #2: 89.03\\n\"\n + \"Row #3: 76\\n\"\n + \"Row #3: 70.99\\n\"\n + \"Row #3: 182.38\\n\"\n + \"Row #4: 188\\n\"\n + \"Row #4: 167.00\\n\"\n + \"Row #4: 419.14\\n\"\n + \"Row #5: 68\\n\"\n + \"Row #5: 45.19\\n\"\n + \"Row #5: 119.55\\n\"\n + \"Row #6: 148\\n\"\n + \"Row #6: 128.97\\n\"\n + \"Row #6: 316.88\\n\"\n + \"Row #7: 197\\n\"\n + \"Row #7: 161.81\\n\"\n + \"Row #7: 399.58\\n\"\n + \"Row #8: 85\\n\"\n + \"Row #8: 54.75\\n\"\n + \"Row #8: 140.27\\n\"\n + \"Row #9: 158\\n\"\n + \"Row #9: 121.14\\n\"\n + \"Row #9: 294.55\\n\"\n + \"Row #10: 270\\n\"\n + \"Row #10: 201.28\\n\"\n + \"Row #10: 520.55\\n\"\n + \"Row #11: 84\\n\"\n + \"Row #11: 50.26\\n\"\n + \"Row #11: 128.32\\n\"),\n\n // 1\n new QueryAndResult(\n \"select\\n\"\n + \" [Product].[All Products].[Drink].children on rows,\\n\"\n + \" CrossJoin(\\n\"\n + \" {[Measures].[Unit Sales], [Measures].[Store Sales]},\\n\"\n + \" { [Promotion Media].[All Media].[Radio],\\n\"\n + \" [Promotion Media].[All Media].[TV],\\n\"\n + \" [Promotion Media].[All Media].[Sunday Paper],\\n\"\n + \" [Promotion Media].[All Media].[Street Handout] }\\n\"\n + \" ) on columns\\n\"\n + \"from Sales\\n\"\n + \"where ([Time].[1997])\",\n\n \"Axis #0:\\n\"\n + \"{[Time].[1997]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales], [Promotion Media].[All Media].[Radio]}\\n\"\n + \"{[Measures].[Unit Sales], [Promotion Media].[All Media].[TV]}\\n\"\n + \"{[Measures].[Unit Sales], [Promotion Media].[All Media].[Sunday Paper]}\\n\"\n + \"{[Measures].[Unit Sales], [Promotion Media].[All Media].[Street Handout]}\\n\"\n + \"{[Measures].[Store Sales], [Promotion Media].[All Media].[Radio]}\\n\"\n + \"{[Measures].[Store Sales], [Promotion Media].[All Media].[TV]}\\n\"\n + \"{[Measures].[Store Sales], [Promotion Media].[All Media].[Sunday Paper]}\\n\"\n + \"{[Measures].[Store Sales], [Promotion Media].[All Media].[Street Handout]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages]}\\n\"\n + \"{[Product].[All Products].[Drink].[Dairy]}\\n\"\n + \"Row #0: 75\\n\"\n + \"Row #0: 76\\n\"\n + \"Row #0: 148\\n\"\n + \"Row #0: 158\\n\"\n + \"Row #0: 168.62\\n\"\n + \"Row #0: 182.38\\n\"\n + \"Row #0: 316.88\\n\"\n + \"Row #0: 294.55\\n\"\n + \"Row #1: 97\\n\"\n + \"Row #1: 188\\n\"\n + \"Row #1: 197\\n\"\n + \"Row #1: 270\\n\"\n + \"Row #1: 186.03\\n\"\n + \"Row #1: 419.14\\n\"\n + \"Row #1: 399.58\\n\"\n + \"Row #1: 520.55\\n\"\n + \"Row #2: 54\\n\"\n + \"Row #2: 68\\n\"\n + \"Row #2: 85\\n\"\n + \"Row #2: 84\\n\"\n + \"Row #2: 89.03\\n\"\n + \"Row #2: 119.55\\n\"\n + \"Row #2: 140.27\\n\"\n + \"Row #2: 128.32\\n\"),\n\n // 2\n new QueryAndResult(\n \"select\\n\"\n + \" {[Measures].[Unit Sales], [Measures].[Store Sales]} on columns,\\n\"\n + \" Order([Product].[Product Department].members, [Measures].[Store Sales], DESC) on rows\\n\"\n + \"from Sales\",\n\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"{[Measures].[Store Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Product].[All Products].[Food].[Produce]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods]}\\n\"\n + \"{[Product].[All Products].[Food].[Frozen Foods]}\\n\"\n + \"{[Product].[All Products].[Food].[Canned Foods]}\\n\"\n + \"{[Product].[All Products].[Food].[Baking Goods]}\\n\"\n + \"{[Product].[All Products].[Food].[Dairy]}\\n\"\n + \"{[Product].[All Products].[Food].[Deli]}\\n\"\n + \"{[Product].[All Products].[Food].[Baked Goods]}\\n\"\n + \"{[Product].[All Products].[Food].[Snacks]}\\n\"\n + \"{[Product].[All Products].[Food].[Starchy Foods]}\\n\"\n + \"{[Product].[All Products].[Food].[Eggs]}\\n\"\n + \"{[Product].[All Products].[Food].[Breakfast Foods]}\\n\"\n + \"{[Product].[All Products].[Food].[Seafood]}\\n\"\n + \"{[Product].[All Products].[Food].[Meat]}\\n\"\n + \"{[Product].[All Products].[Food].[Canned Products]}\\n\"\n + \"{[Product].[All Products].[Non-Consumable].[Household]}\\n\"\n + \"{[Product].[All Products].[Non-Consumable].[Health and Hygiene]}\\n\"\n + \"{[Product].[All Products].[Non-Consumable].[Periodicals]}\\n\"\n + \"{[Product].[All Products].[Non-Consumable].[Checkout]}\\n\"\n + \"{[Product].[All Products].[Non-Consumable].[Carousel]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages]}\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages]}\\n\"\n + \"{[Product].[All Products].[Drink].[Dairy]}\\n\"\n + \"Row #0: 37,792\\n\"\n + \"Row #0: 82,248.42\\n\"\n + \"Row #1: 30,545\\n\"\n + \"Row #1: 67,609.82\\n\"\n + \"Row #2: 26,655\\n\"\n + \"Row #2: 55,207.50\\n\"\n + \"Row #3: 19,026\\n\"\n + \"Row #3: 39,774.34\\n\"\n + \"Row #4: 20,245\\n\"\n + \"Row #4: 38,670.41\\n\"\n + \"Row #5: 12,885\\n\"\n + \"Row #5: 30,508.85\\n\"\n + \"Row #6: 12,037\\n\"\n + \"Row #6: 25,318.93\\n\"\n + \"Row #7: 7,870\\n\"\n + \"Row #7: 16,455.43\\n\"\n + \"Row #8: 6,884\\n\"\n + \"Row #8: 14,550.05\\n\"\n + \"Row #9: 5,262\\n\"\n + \"Row #9: 11,756.07\\n\"\n + \"Row #10: 4,132\\n\"\n + \"Row #10: 9,200.76\\n\"\n + \"Row #11: 3,317\\n\"\n + \"Row #11: 6,941.46\\n\"\n + \"Row #12: 1,764\\n\"\n + \"Row #12: 3,809.14\\n\"\n + \"Row #13: 1,714\\n\"\n + \"Row #13: 3,669.89\\n\"\n + \"Row #14: 1,812\\n\"\n + \"Row #14: 3,314.52\\n\"\n + \"Row #15: 27,038\\n\"\n + \"Row #15: 60,469.89\\n\"\n + \"Row #16: 16,284\\n\"\n + \"Row #16: 32,571.86\\n\"\n + \"Row #17: 4,294\\n\"\n + \"Row #17: 9,056.76\\n\"\n + \"Row #18: 1,779\\n\"\n + \"Row #18: 3,767.71\\n\"\n + \"Row #19: 841\\n\"\n + \"Row #19: 1,500.11\\n\"\n + \"Row #20: 13,573\\n\"\n + \"Row #20: 27,748.53\\n\"\n + \"Row #21: 6,838\\n\"\n + \"Row #21: 14,029.08\\n\"\n + \"Row #22: 4,186\\n\"\n + \"Row #22: 7,058.60\\n\"),\n\n // 3\n new QueryAndResult(\n \"select\\n\"\n + \" [Product].[All Products].[Drink].children on columns\\n\"\n + \"from Sales\\n\"\n + \"where ([Measures].[Unit Sales], [Promotion Media].[All Media].[Street Handout], [Time].[1997])\",\n\n \"Axis #0:\\n\"\n + \"{[Measures].[Unit Sales], [Promotion Media].[All Media].[Street Handout], [Time].[1997]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages]}\\n\"\n + \"{[Product].[All Products].[Drink].[Dairy]}\\n\"\n + \"Row #0: 158\\n\"\n + \"Row #0: 270\\n\"\n + \"Row #0: 84\\n\"),\n\n // 4\n new QueryAndResult(\n \"select\\n\"\n + \" NON EMPTY CrossJoin([Product].[All Products].[Drink].children, [Customers].[All Customers].[USA].[WA].Children) on rows,\\n\"\n + \" CrossJoin(\\n\"\n + \" {[Measures].[Unit Sales], [Measures].[Store Sales]},\\n\"\n + \" { [Promotion Media].[All Media].[Radio],\\n\"\n + \" [Promotion Media].[All Media].[TV],\\n\"\n + \" [Promotion Media].[All Media].[Sunday Paper],\\n\"\n + \" [Promotion Media].[All Media].[Street Handout] }\\n\"\n + \" ) on columns\\n\"\n + \"from Sales\\n\"\n + \"where ([Time].[1997])\",\n\n \"Axis #0:\\n\"\n + \"{[Time].[1997]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales], [Promotion Media].[All Media].[Radio]}\\n\"\n + \"{[Measures].[Unit Sales], [Promotion Media].[All Media].[TV]}\\n\"\n + \"{[Measures].[Unit Sales], [Promotion Media].[All Media].[Sunday Paper]}\\n\"\n + \"{[Measures].[Unit Sales], [Promotion Media].[All Media].[Street Handout]}\\n\"\n + \"{[Measures].[Store Sales], [Promotion Media].[All Media].[Radio]}\\n\"\n + \"{[Measures].[Store Sales], [Promotion Media].[All Media].[TV]}\\n\"\n + \"{[Measures].[Store Sales], [Promotion Media].[All Media].[Sunday Paper]}\\n\"\n + \"{[Measures].[Store Sales], [Promotion Media].[All Media].[Street Handout]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages], [Customers].[All Customers].[USA].[WA].[Anacortes]}\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages], [Customers].[All Customers].[USA].[WA].[Ballard]}\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages], [Customers].[All Customers].[USA].[WA].[Bellingham]}\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages], [Customers].[All Customers].[USA].[WA].[Bremerton]}\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages], [Customers].[All Customers].[USA].[WA].[Burien]}\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages], [Customers].[All Customers].[USA].[WA].[Everett]}\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages], [Customers].[All Customers].[USA].[WA].[Issaquah]}\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages], [Customers].[All Customers].[USA].[WA].[Kirkland]}\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages], [Customers].[All Customers].[USA].[WA].[Lynnwood]}\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages], [Customers].[All Customers].[USA].[WA].[Marysville]}\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages], [Customers].[All Customers].[USA].[WA].[Olympia]}\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages], [Customers].[All Customers].[USA].[WA].[Port Orchard]}\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages], [Customers].[All Customers].[USA].[WA].[Puyallup]}\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages], [Customers].[All Customers].[USA].[WA].[Redmond]}\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages], [Customers].[All Customers].[USA].[WA].[Renton]}\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages], [Customers].[All Customers].[USA].[WA].[Seattle]}\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages], [Customers].[All Customers].[USA].[WA].[Spokane]}\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages], [Customers].[All Customers].[USA].[WA].[Tacoma]}\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages], [Customers].[All Customers].[USA].[WA].[Yakima]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages], [Customers].[All Customers].[USA].[WA].[Anacortes]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages], [Customers].[All Customers].[USA].[WA].[Ballard]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages], [Customers].[All Customers].[USA].[WA].[Bremerton]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages], [Customers].[All Customers].[USA].[WA].[Burien]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages], [Customers].[All Customers].[USA].[WA].[Edmonds]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages], [Customers].[All Customers].[USA].[WA].[Everett]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages], [Customers].[All Customers].[USA].[WA].[Issaquah]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages], [Customers].[All Customers].[USA].[WA].[Kirkland]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages], [Customers].[All Customers].[USA].[WA].[Lynnwood]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages], [Customers].[All Customers].[USA].[WA].[Marysville]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages], [Customers].[All Customers].[USA].[WA].[Olympia]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages], [Customers].[All Customers].[USA].[WA].[Port Orchard]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages], [Customers].[All Customers].[USA].[WA].[Puyallup]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages], [Customers].[All Customers].[USA].[WA].[Redmond]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages], [Customers].[All Customers].[USA].[WA].[Seattle]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages], [Customers].[All Customers].[USA].[WA].[Sedro Woolley]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages], [Customers].[All Customers].[USA].[WA].[Spokane]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages], [Customers].[All Customers].[USA].[WA].[Tacoma]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages], [Customers].[All Customers].[USA].[WA].[Walla Walla]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages], [Customers].[All Customers].[USA].[WA].[Yakima]}\\n\"\n + \"{[Product].[All Products].[Drink].[Dairy], [Customers].[All Customers].[USA].[WA].[Ballard]}\\n\"\n + \"{[Product].[All Products].[Drink].[Dairy], [Customers].[All Customers].[USA].[WA].[Bellingham]}\\n\"\n + \"{[Product].[All Products].[Drink].[Dairy], [Customers].[All Customers].[USA].[WA].[Bremerton]}\\n\"\n + \"{[Product].[All Products].[Drink].[Dairy], [Customers].[All Customers].[USA].[WA].[Burien]}\\n\"\n + \"{[Product].[All Products].[Drink].[Dairy], [Customers].[All Customers].[USA].[WA].[Everett]}\\n\"\n + \"{[Product].[All Products].[Drink].[Dairy], [Customers].[All Customers].[USA].[WA].[Issaquah]}\\n\"\n + \"{[Product].[All Products].[Drink].[Dairy], [Customers].[All Customers].[USA].[WA].[Kirkland]}\\n\"\n + \"{[Product].[All Products].[Drink].[Dairy], [Customers].[All Customers].[USA].[WA].[Lynnwood]}\\n\"\n + \"{[Product].[All Products].[Drink].[Dairy], [Customers].[All Customers].[USA].[WA].[Marysville]}\\n\"\n + \"{[Product].[All Products].[Drink].[Dairy], [Customers].[All Customers].[USA].[WA].[Olympia]}\\n\"\n + \"{[Product].[All Products].[Drink].[Dairy], [Customers].[All Customers].[USA].[WA].[Port Orchard]}\\n\"\n + \"{[Product].[All Products].[Drink].[Dairy], [Customers].[All Customers].[USA].[WA].[Puyallup]}\\n\"\n + \"{[Product].[All Products].[Drink].[Dairy], [Customers].[All Customers].[USA].[WA].[Redmond]}\\n\"\n + \"{[Product].[All Products].[Drink].[Dairy], [Customers].[All Customers].[USA].[WA].[Renton]}\\n\"\n + \"{[Product].[All Products].[Drink].[Dairy], [Customers].[All Customers].[USA].[WA].[Seattle]}\\n\"\n + \"{[Product].[All Products].[Drink].[Dairy], [Customers].[All Customers].[USA].[WA].[Spokane]}\\n\"\n + \"{[Product].[All Products].[Drink].[Dairy], [Customers].[All Customers].[USA].[WA].[Tacoma]}\\n\"\n + \"{[Product].[All Products].[Drink].[Dairy], [Customers].[All Customers].[USA].[WA].[Yakima]}\\n\"\n + \"Row #0: \\n\"\n + \"Row #0: 2\\n\"\n + \"Row #0: \\n\"\n + \"Row #0: \\n\"\n + \"Row #0: \\n\"\n + \"Row #0: 1.14\\n\"\n + \"Row #0: \\n\"\n + \"Row #0: \\n\"\n + \"Row #1: 4\\n\"\n + \"Row #1: \\n\"\n + \"Row #1: \\n\"\n + \"Row #1: 4\\n\"\n + \"Row #1: 10.40\\n\"\n + \"Row #1: \\n\"\n + \"Row #1: \\n\"\n + \"Row #1: 2.16\\n\"\n + \"Row #2: \\n\"\n + \"Row #2: 1\\n\"\n + \"Row #2: \\n\"\n + \"Row #2: \\n\"\n + \"Row #2: \\n\"\n + \"Row #2: 2.37\\n\"\n + \"Row #2: \\n\"\n + \"Row #2: \\n\"\n + \"Row #3: \\n\"\n + \"Row #3: \\n\"\n + \"Row #3: 24\\n\"\n + \"Row #3: \\n\"\n + \"Row #3: \\n\"\n + \"Row #3: \\n\"\n + \"Row #3: 46.09\\n\"\n + \"Row #3: \\n\"\n + \"Row #4: 3\\n\"\n + \"Row #4: \\n\"\n + \"Row #4: \\n\"\n + \"Row #4: 8\\n\"\n + \"Row #4: 2.10\\n\"\n + \"Row #4: \\n\"\n + \"Row #4: \\n\"\n + \"Row #4: 9.63\\n\"\n + \"Row #5: 6\\n\"\n + \"Row #5: \\n\"\n + \"Row #5: \\n\"\n + \"Row #5: 5\\n\"\n + \"Row #5: 8.06\\n\"\n + \"Row #5: \\n\"\n + \"Row #5: \\n\"\n + \"Row #5: 6.21\\n\"\n + \"Row #6: 3\\n\"\n + \"Row #6: \\n\"\n + \"Row #6: \\n\"\n + \"Row #6: 7\\n\"\n + \"Row #6: 7.80\\n\"\n + \"Row #6: \\n\"\n + \"Row #6: \\n\"\n + \"Row #6: 15.00\\n\"\n + \"Row #7: 14\\n\"\n + \"Row #7: \\n\"\n + \"Row #7: \\n\"\n + \"Row #7: \\n\"\n + \"Row #7: 36.10\\n\"\n + \"Row #7: \\n\"\n + \"Row #7: \\n\"\n + \"Row #7: \\n\"\n + \"Row #8: 3\\n\"\n + \"Row #8: \\n\"\n + \"Row #8: \\n\"\n + \"Row #8: 16\\n\"\n + \"Row #8: 10.29\\n\"\n + \"Row #8: \\n\"\n + \"Row #8: \\n\"\n + \"Row #8: 32.20\\n\"\n + \"Row #9: 3\\n\"\n + \"Row #9: \\n\"\n + \"Row #9: \\n\"\n + \"Row #9: \\n\"\n + \"Row #9: 10.56\\n\"\n + \"Row #9: \\n\"\n + \"Row #9: \\n\"\n + \"Row #9: \\n\"\n + \"Row #10: \\n\"\n + \"Row #10: \\n\"\n + \"Row #10: 15\\n\"\n + \"Row #10: 11\\n\"\n + \"Row #10: \\n\"\n + \"Row #10: \\n\"\n + \"Row #10: 34.79\\n\"\n + \"Row #10: 15.67\\n\"\n + \"Row #11: \\n\"\n + \"Row #11: \\n\"\n + \"Row #11: 7\\n\"\n + \"Row #11: \\n\"\n + \"Row #11: \\n\"\n + \"Row #11: \\n\"\n + \"Row #11: 17.44\\n\"\n + \"Row #11: \\n\"\n + \"Row #12: \\n\"\n + \"Row #12: \\n\"\n + \"Row #12: 22\\n\"\n + \"Row #12: 9\\n\"\n + \"Row #12: \\n\"\n + \"Row #12: \\n\"\n + \"Row #12: 32.35\\n\"\n + \"Row #12: 17.43\\n\"\n + \"Row #13: 7\\n\"\n + \"Row #13: \\n\"\n + \"Row #13: \\n\"\n + \"Row #13: 4\\n\"\n + \"Row #13: 4.77\\n\"\n + \"Row #13: \\n\"\n + \"Row #13: \\n\"\n + \"Row #13: 15.16\\n\"\n + \"Row #14: 4\\n\"\n + \"Row #14: \\n\"\n + \"Row #14: \\n\"\n + \"Row #14: 4\\n\"\n + \"Row #14: 3.64\\n\"\n + \"Row #14: \\n\"\n + \"Row #14: \\n\"\n + \"Row #14: 9.64\\n\"\n + \"Row #15: 2\\n\"\n + \"Row #15: \\n\"\n + \"Row #15: \\n\"\n + \"Row #15: 7\\n\"\n + \"Row #15: 6.86\\n\"\n + \"Row #15: \\n\"\n + \"Row #15: \\n\"\n + \"Row #15: 8.38\\n\"\n + \"Row #16: \\n\"\n + \"Row #16: \\n\"\n + \"Row #16: \\n\"\n + \"Row #16: 28\\n\"\n + \"Row #16: \\n\"\n + \"Row #16: \\n\"\n + \"Row #16: \\n\"\n + \"Row #16: 61.98\\n\"\n + \"Row #17: \\n\"\n + \"Row #17: \\n\"\n + \"Row #17: 3\\n\"\n + \"Row #17: 4\\n\"\n + \"Row #17: \\n\"\n + \"Row #17: \\n\"\n + \"Row #17: 10.56\\n\"\n + \"Row #17: 8.96\\n\"\n + \"Row #18: 6\\n\"\n + \"Row #18: \\n\"\n + \"Row #18: \\n\"\n + \"Row #18: 3\\n\"\n + \"Row #18: 7.16\\n\"\n + \"Row #18: \\n\"\n + \"Row #18: \\n\"\n + \"Row #18: 8.10\\n\"\n + \"Row #19: 7\\n\"\n + \"Row #19: \\n\"\n + \"Row #19: \\n\"\n + \"Row #19: \\n\"\n + \"Row #19: 15.63\\n\"\n + \"Row #19: \\n\"\n + \"Row #19: \\n\"\n + \"Row #19: \\n\"\n + \"Row #20: 3\\n\"\n + \"Row #20: \\n\"\n + \"Row #20: \\n\"\n + \"Row #20: 13\\n\"\n + \"Row #20: 6.96\\n\"\n + \"Row #20: \\n\"\n + \"Row #20: \\n\"\n + \"Row #20: 12.22\\n\"\n + \"Row #21: \\n\"\n + \"Row #21: \\n\"\n + \"Row #21: 16\\n\"\n + \"Row #21: \\n\"\n + \"Row #21: \\n\"\n + \"Row #21: \\n\"\n + \"Row #21: 45.08\\n\"\n + \"Row #21: \\n\"\n + \"Row #22: 3\\n\"\n + \"Row #22: \\n\"\n + \"Row #22: \\n\"\n + \"Row #22: 18\\n\"\n + \"Row #22: 6.39\\n\"\n + \"Row #22: \\n\"\n + \"Row #22: \\n\"\n + \"Row #22: 21.08\\n\"\n + \"Row #23: \\n\"\n + \"Row #23: \\n\"\n + \"Row #23: \\n\"\n + \"Row #23: 21\\n\"\n + \"Row #23: \\n\"\n + \"Row #23: \\n\"\n + \"Row #23: \\n\"\n + \"Row #23: 33.22\\n\"\n + \"Row #24: \\n\"\n + \"Row #24: \\n\"\n + \"Row #24: \\n\"\n + \"Row #24: 9\\n\"\n + \"Row #24: \\n\"\n + \"Row #24: \\n\"\n + \"Row #24: \\n\"\n + \"Row #24: 22.65\\n\"\n + \"Row #25: 2\\n\"\n + \"Row #25: \\n\"\n + \"Row #25: \\n\"\n + \"Row #25: 9\\n\"\n + \"Row #25: 6.80\\n\"\n + \"Row #25: \\n\"\n + \"Row #25: \\n\"\n + \"Row #25: 18.90\\n\"\n + \"Row #26: 3\\n\"\n + \"Row #26: \\n\"\n + \"Row #26: \\n\"\n + \"Row #26: 9\\n\"\n + \"Row #26: 1.50\\n\"\n + \"Row #26: \\n\"\n + \"Row #26: \\n\"\n + \"Row #26: 23.01\\n\"\n + \"Row #27: \\n\"\n + \"Row #27: \\n\"\n + \"Row #27: \\n\"\n + \"Row #27: 22\\n\"\n + \"Row #27: \\n\"\n + \"Row #27: \\n\"\n + \"Row #27: \\n\"\n + \"Row #27: 50.71\\n\"\n + \"Row #28: 4\\n\"\n + \"Row #28: \\n\"\n + \"Row #28: \\n\"\n + \"Row #28: \\n\"\n + \"Row #28: 5.16\\n\"\n + \"Row #28: \\n\"\n + \"Row #28: \\n\"\n + \"Row #28: \\n\"\n + \"Row #29: \\n\"\n + \"Row #29: \\n\"\n + \"Row #29: 20\\n\"\n + \"Row #29: 14\\n\"\n + \"Row #29: \\n\"\n + \"Row #29: \\n\"\n + \"Row #29: 48.02\\n\"\n + \"Row #29: 28.80\\n\"\n + \"Row #30: \\n\"\n + \"Row #30: \\n\"\n + \"Row #30: 14\\n\"\n + \"Row #30: \\n\"\n + \"Row #30: \\n\"\n + \"Row #30: \\n\"\n + \"Row #30: 19.96\\n\"\n + \"Row #30: \\n\"\n + \"Row #31: \\n\"\n + \"Row #31: \\n\"\n + \"Row #31: 10\\n\"\n + \"Row #31: 40\\n\"\n + \"Row #31: \\n\"\n + \"Row #31: \\n\"\n + \"Row #31: 26.36\\n\"\n + \"Row #31: 74.49\\n\"\n + \"Row #32: 6\\n\"\n + \"Row #32: \\n\"\n + \"Row #32: \\n\"\n + \"Row #32: \\n\"\n + \"Row #32: 17.01\\n\"\n + \"Row #32: \\n\"\n + \"Row #32: \\n\"\n + \"Row #32: \\n\"\n + \"Row #33: 4\\n\"\n + \"Row #33: \\n\"\n + \"Row #33: \\n\"\n + \"Row #33: \\n\"\n + \"Row #33: 2.80\\n\"\n + \"Row #33: \\n\"\n + \"Row #33: \\n\"\n + \"Row #33: \\n\"\n + \"Row #34: 4\\n\"\n + \"Row #34: \\n\"\n + \"Row #34: \\n\"\n + \"Row #34: \\n\"\n + \"Row #34: 7.98\\n\"\n + \"Row #34: \\n\"\n + \"Row #34: \\n\"\n + \"Row #34: \\n\"\n + \"Row #35: \\n\"\n + \"Row #35: \\n\"\n + \"Row #35: \\n\"\n + \"Row #35: 46\\n\"\n + \"Row #35: \\n\"\n + \"Row #35: \\n\"\n + \"Row #35: \\n\"\n + \"Row #35: 81.71\\n\"\n + \"Row #36: \\n\"\n + \"Row #36: \\n\"\n + \"Row #36: 21\\n\"\n + \"Row #36: 6\\n\"\n + \"Row #36: \\n\"\n + \"Row #36: \\n\"\n + \"Row #36: 37.93\\n\"\n + \"Row #36: 14.73\\n\"\n + \"Row #37: \\n\"\n + \"Row #37: \\n\"\n + \"Row #37: 3\\n\"\n + \"Row #37: \\n\"\n + \"Row #37: \\n\"\n + \"Row #37: \\n\"\n + \"Row #37: 7.92\\n\"\n + \"Row #37: \\n\"\n + \"Row #38: 25\\n\"\n + \"Row #38: \\n\"\n + \"Row #38: \\n\"\n + \"Row #38: 3\\n\"\n + \"Row #38: 51.65\\n\"\n + \"Row #38: \\n\"\n + \"Row #38: \\n\"\n + \"Row #38: 2.34\\n\"\n + \"Row #39: 3\\n\"\n + \"Row #39: \\n\"\n + \"Row #39: \\n\"\n + \"Row #39: 4\\n\"\n + \"Row #39: 4.47\\n\"\n + \"Row #39: \\n\"\n + \"Row #39: \\n\"\n + \"Row #39: 9.20\\n\"\n + \"Row #40: \\n\"\n + \"Row #40: 1\\n\"\n + \"Row #40: \\n\"\n + \"Row #40: \\n\"\n + \"Row #40: \\n\"\n + \"Row #40: 1.47\\n\"\n + \"Row #40: \\n\"\n + \"Row #40: \\n\"\n + \"Row #41: \\n\"\n + \"Row #41: \\n\"\n + \"Row #41: 15\\n\"\n + \"Row #41: \\n\"\n + \"Row #41: \\n\"\n + \"Row #41: \\n\"\n + \"Row #41: 18.88\\n\"\n + \"Row #41: \\n\"\n + \"Row #42: \\n\"\n + \"Row #42: \\n\"\n + \"Row #42: \\n\"\n + \"Row #42: 3\\n\"\n + \"Row #42: \\n\"\n + \"Row #42: \\n\"\n + \"Row #42: \\n\"\n + \"Row #42: 3.75\\n\"\n + \"Row #43: 9\\n\"\n + \"Row #43: \\n\"\n + \"Row #43: \\n\"\n + \"Row #43: 10\\n\"\n + \"Row #43: 31.41\\n\"\n + \"Row #43: \\n\"\n + \"Row #43: \\n\"\n + \"Row #43: 15.12\\n\"\n + \"Row #44: 3\\n\"\n + \"Row #44: \\n\"\n + \"Row #44: \\n\"\n + \"Row #44: 3\\n\"\n + \"Row #44: 7.41\\n\"\n + \"Row #44: \\n\"\n + \"Row #44: \\n\"\n + \"Row #44: 2.55\\n\"\n + \"Row #45: 3\\n\"\n + \"Row #45: \\n\"\n + \"Row #45: \\n\"\n + \"Row #45: \\n\"\n + \"Row #45: 1.71\\n\"\n + \"Row #45: \\n\"\n + \"Row #45: \\n\"\n + \"Row #45: \\n\"\n + \"Row #46: \\n\"\n + \"Row #46: \\n\"\n + \"Row #46: \\n\"\n + \"Row #46: 7\\n\"\n + \"Row #46: \\n\"\n + \"Row #46: \\n\"\n + \"Row #46: \\n\"\n + \"Row #46: 11.86\\n\"\n + \"Row #47: \\n\"\n + \"Row #47: \\n\"\n + \"Row #47: \\n\"\n + \"Row #47: 3\\n\"\n + \"Row #47: \\n\"\n + \"Row #47: \\n\"\n + \"Row #47: \\n\"\n + \"Row #47: 2.76\\n\"\n + \"Row #48: \\n\"\n + \"Row #48: \\n\"\n + \"Row #48: 4\\n\"\n + \"Row #48: 5\\n\"\n + \"Row #48: \\n\"\n + \"Row #48: \\n\"\n + \"Row #48: 4.50\\n\"\n + \"Row #48: 7.27\\n\"\n + \"Row #49: \\n\"\n + \"Row #49: \\n\"\n + \"Row #49: 7\\n\"\n + \"Row #49: \\n\"\n + \"Row #49: \\n\"\n + \"Row #49: \\n\"\n + \"Row #49: 10.01\\n\"\n + \"Row #49: \\n\"\n + \"Row #50: \\n\"\n + \"Row #50: \\n\"\n + \"Row #50: 5\\n\"\n + \"Row #50: 4\\n\"\n + \"Row #50: \\n\"\n + \"Row #50: \\n\"\n + \"Row #50: 12.88\\n\"\n + \"Row #50: 5.28\\n\"\n + \"Row #51: 2\\n\"\n + \"Row #51: \\n\"\n + \"Row #51: \\n\"\n + \"Row #51: \\n\"\n + \"Row #51: 2.64\\n\"\n + \"Row #51: \\n\"\n + \"Row #51: \\n\"\n + \"Row #51: \\n\"\n + \"Row #52: \\n\"\n + \"Row #52: \\n\"\n + \"Row #52: \\n\"\n + \"Row #52: 5\\n\"\n + \"Row #52: \\n\"\n + \"Row #52: \\n\"\n + \"Row #52: \\n\"\n + \"Row #52: 12.34\\n\"\n + \"Row #53: \\n\"\n + \"Row #53: \\n\"\n + \"Row #53: \\n\"\n + \"Row #53: 5\\n\"\n + \"Row #53: \\n\"\n + \"Row #53: \\n\"\n + \"Row #53: \\n\"\n + \"Row #53: 3.41\\n\"\n + \"Row #54: \\n\"\n + \"Row #54: \\n\"\n + \"Row #54: \\n\"\n + \"Row #54: 4\\n\"\n + \"Row #54: \\n\"\n + \"Row #54: \\n\"\n + \"Row #54: \\n\"\n + \"Row #54: 2.44\\n\"\n + \"Row #55: \\n\"\n + \"Row #55: \\n\"\n + \"Row #55: 2\\n\"\n + \"Row #55: \\n\"\n + \"Row #55: \\n\"\n + \"Row #55: \\n\"\n + \"Row #55: 6.92\\n\"\n + \"Row #55: \\n\"\n + \"Row #56: 13\\n\"\n + \"Row #56: \\n\"\n + \"Row #56: \\n\"\n + \"Row #56: 7\\n\"\n + \"Row #56: 23.69\\n\"\n + \"Row #56: \\n\"\n + \"Row #56: \\n\"\n + \"Row #56: 7.07\\n\"),\n\n // 5\n new QueryAndResult(\n \"select from Sales\\n\"\n + \"where ([Measures].[Store Sales], [Time].[1997], [Promotion Media].[All Media].[TV])\",\n\n \"Axis #0:\\n\"\n + \"{[Measures].[Store Sales], [Time].[1997], [Promotion Media].[All Media].[TV]}\\n\"\n + \"7,786.21\"));\n\n public void testTaglib0() {\n assertQueryReturns(\n taglibQueries.get(0).query, taglibQueries.get(0).result);\n }\n\n public void testTaglib1() {\n assertQueryReturns(\n taglibQueries.get(1).query, taglibQueries.get(1).result);\n }\n\n public void testTaglib2() {\n assertQueryReturns(\n taglibQueries.get(2).query, taglibQueries.get(2).result);\n }\n\n public void testTaglib3() {\n assertQueryReturns(\n taglibQueries.get(3).query, taglibQueries.get(3).result);\n }\n\n public void testTaglib4() {\n assertQueryReturns(\n taglibQueries.get(4).query, taglibQueries.get(4).result);\n }\n\n public void testTaglib5() {\n assertQueryReturns(\n taglibQueries.get(5).query, taglibQueries.get(5).result);\n }\n\n public void testCellValue() {\n Result result = executeQuery(\n \"select {[Measures].[Unit Sales],[Measures].[Store Sales]} on columns,\\n\"\n + \" {[Gender].[M]} on rows\\n\"\n + \"from Sales\");\n Cell cell = result.getCell(new int[]{0, 0});\n Object value = cell.getValue();\n assertTrue(value instanceof Number);\n assertEquals(135215, ((Number) value).intValue());\n cell = result.getCell(new int[]{1, 0});\n value = cell.getValue();\n assertTrue(value instanceof Number);\n // Plato give 285011.12, Oracle gives 285011, MySQL gives 285964 (bug!)\n assertEquals(285011, ((Number) value).intValue());\n }\n\n public void testDynamicFormat() {\n assertQueryReturns(\n \"with member [Measures].[USales] as [Measures].[Unit Sales],\\n\"\n + \" format_string = iif([Measures].[Unit Sales] > 50000, \\\"\\\\#.00\\\\<\\\\/b\\\\>\\\", \\\"\\\\#.00\\\\<\\\\/i\\\\>\\\")\\n\"\n + \"select \\n\"\n + \" {[Measures].[USales]} on columns,\\n\"\n + \" {[Store Type].members} on rows\\n\"\n + \"from Sales\",\n\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[USales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Store Type].[All Store Types]}\\n\"\n + \"{[Store Type].[All Store Types].[Deluxe Supermarket]}\\n\"\n + \"{[Store Type].[All Store Types].[Gourmet Supermarket]}\\n\"\n + \"{[Store Type].[All Store Types].[HeadQuarters]}\\n\"\n + \"{[Store Type].[All Store Types].[Mid-Size Grocery]}\\n\"\n + \"{[Store Type].[All Store Types].[Small Grocery]}\\n\"\n + \"{[Store Type].[All Store Types].[Supermarket]}\\n\"\n + \"Row #0: 266773.00\\n\"\n + \"Row #1: 76837.00\\n\"\n + \"Row #2: 21333.00\\n\"\n + \"Row #3: \\n\"\n + \"Row #4: 11491.00\\n\"\n + \"Row #5: 6557.00\\n\"\n + \"Row #6: 150555.00\\n\");\n }\n\n public void testFormatOfNulls() {\n assertQueryReturns(\n \"with member [Measures].[Foo] as '([Measures].[Store Sales])',\\n\"\n + \" format_string = '$#,##0.00;($#,##0.00);ZERO;NULL;Nil'\\n\"\n + \"select\\n\"\n + \" {[Measures].[Foo]} on columns,\\n\"\n + \" {[Customers].[Country].members} on rows\\n\"\n + \"from Sales\",\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Foo]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Customers].[All Customers].[Canada]}\\n\"\n + \"{[Customers].[All Customers].[Mexico]}\\n\"\n + \"{[Customers].[All Customers].[USA]}\\n\"\n + \"Row #0: NULL\\n\"\n + \"Row #1: NULL\\n\"\n + \"Row #2: $565,238.13\\n\");\n }\n\n /**\n * If a measure (in this case, [Measures].[Sales Count]
)\n * occurs only within a format expression, bug\n * MONDRIAN-14.\n * causes an internal\n * error (\"value not found\") when the cell's formatted value is retrieved.\n */\n public void testBugMondrian14() {\n assertQueryReturns(\n \"with member [Measures].[USales] as '[Measures].[Unit Sales]',\\n\"\n + \" format_string = iif([Measures].[Sales Count] > 30, \\\"#.00 good\\\",\\\"#.00 bad\\\")\\n\"\n + \"select {[Measures].[USales], [Measures].[Store Cost], [Measures].[Store Sales]} ON columns,\\n\"\n + \" Crossjoin({[Promotion Media].[All Media].[Radio], [Promotion Media].[All Media].[TV], [Promotion Media]. [All Media].[Sunday Paper], [Promotion Media].[All Media].[Street Handout]}, [Product].[All Products].[Drink].Children) ON rows\\n\"\n + \"from [Sales] where ([Time].[1997])\",\n\n \"Axis #0:\\n\"\n + \"{[Time].[1997]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[USales]}\\n\"\n + \"{[Measures].[Store Cost]}\\n\"\n + \"{[Measures].[Store Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Promotion Media].[All Media].[Radio], [Product].[All Products].[Drink].[Alcoholic Beverages]}\\n\"\n + \"{[Promotion Media].[All Media].[Radio], [Product].[All Products].[Drink].[Beverages]}\\n\"\n + \"{[Promotion Media].[All Media].[Radio], [Product].[All Products].[Drink].[Dairy]}\\n\"\n + \"{[Promotion Media].[All Media].[TV], [Product].[All Products].[Drink].[Alcoholic Beverages]}\\n\"\n + \"{[Promotion Media].[All Media].[TV], [Product].[All Products].[Drink].[Beverages]}\\n\"\n + \"{[Promotion Media].[All Media].[TV], [Product].[All Products].[Drink].[Dairy]}\\n\"\n + \"{[Promotion Media].[All Media].[Sunday Paper], [Product].[All Products].[Drink].[Alcoholic Beverages]}\\n\"\n + \"{[Promotion Media].[All Media].[Sunday Paper], [Product].[All Products].[Drink].[Beverages]}\\n\"\n + \"{[Promotion Media].[All Media].[Sunday Paper], [Product].[All Products].[Drink].[Dairy]}\\n\"\n + \"{[Promotion Media].[All Media].[Street Handout], [Product].[All Products].[Drink].[Alcoholic Beverages]}\\n\"\n + \"{[Promotion Media].[All Media].[Street Handout], [Product].[All Products].[Drink].[Beverages]}\\n\"\n + \"{[Promotion Media].[All Media].[Street Handout], [Product].[All Products].[Drink].[Dairy]}\\n\"\n + \"Row #0: 75.00 bad\\n\"\n + \"Row #0: 70.40\\n\"\n + \"Row #0: 168.62\\n\"\n + \"Row #1: 97.00 good\\n\"\n + \"Row #1: 75.70\\n\"\n + \"Row #1: 186.03\\n\"\n + \"Row #2: 54.00 bad\\n\"\n + \"Row #2: 36.75\\n\"\n + \"Row #2: 89.03\\n\"\n + \"Row #3: 76.00 bad\\n\"\n + \"Row #3: 70.99\\n\"\n + \"Row #3: 182.38\\n\"\n + \"Row #4: 188.00 good\\n\"\n + \"Row #4: 167.00\\n\"\n + \"Row #4: 419.14\\n\"\n + \"Row #5: 68.00 bad\\n\"\n + \"Row #5: 45.19\\n\"\n + \"Row #5: 119.55\\n\"\n + \"Row #6: 148.00 good\\n\"\n + \"Row #6: 128.97\\n\"\n + \"Row #6: 316.88\\n\"\n + \"Row #7: 197.00 good\\n\"\n + \"Row #7: 161.81\\n\"\n + \"Row #7: 399.58\\n\"\n + \"Row #8: 85.00 bad\\n\"\n + \"Row #8: 54.75\\n\"\n + \"Row #8: 140.27\\n\"\n + \"Row #9: 158.00 good\\n\"\n + \"Row #9: 121.14\\n\"\n + \"Row #9: 294.55\\n\"\n + \"Row #10: 270.00 good\\n\"\n + \"Row #10: 201.28\\n\"\n + \"Row #10: 520.55\\n\"\n + \"Row #11: 84.00 bad\\n\"\n + \"Row #11: 50.26\\n\"\n + \"Row #11: 128.32\\n\");\n }\n\n /**\n * This bug causes all of the format strings to be the same, because the\n * required expression [Measures].[Unit Sales] is not in the cache; bug\n * MONDRIAN-34.\n */\n public void testBugMondrian34() {\n assertQueryReturns(\n \"with member [Measures].[xxx] as '[Measures].[Store Sales]',\\n\"\n + \" format_string = IIf([Measures].[Unit Sales] > 100000, \\\"AAA######.00\\\",\\\"BBB###.00\\\")\\n\"\n + \"select {[Measures].[xxx]} ON columns,\\n\"\n + \" {[Product].[All Products].children} ON rows\\n\"\n + \"from [Sales] where [Time].[1997]\",\n\n \"Axis #0:\\n\"\n + \"{[Time].[1997]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[xxx]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Product].[All Products].[Drink]}\\n\"\n + \"{[Product].[All Products].[Food]}\\n\"\n + \"{[Product].[All Products].[Non-Consumable]}\\n\"\n + \"Row #0: BBB48836.21\\n\"\n + \"Row #1: AAA409035.59\\n\"\n + \"Row #2: BBB107366.33\\n\");\n }\n\n /**\n * Tuple as slicer causes {@link ClassCastException}; bug\n * MONDRIAN-36.\n */\n public void testBugMondrian36() {\n assertQueryReturns(\n \"select {[Measures].[Unit Sales]} ON columns,\\n\"\n + \" {[Gender].Children} ON rows\\n\"\n + \"from [Sales]\\n\"\n + \"where ([Time].[1997], [Customers])\",\n \"Axis #0:\\n\"\n + \"{[Time].[1997], [Customers].[All Customers]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Gender].[All Gender].[F]}\\n\"\n + \"{[Gender].[All Gender].[M]}\\n\"\n + \"Row #0: 131,558\\n\"\n + \"Row #1: 135,215\\n\");\n }\n\n /**\n * Query with distinct-count measure and no other measures gives\n * {@link ArrayIndexOutOfBoundsException};\n * MONDRIAN-46.\n */\n public void testBugMondrian46() {\n getConnection().getCacheControl(null).flushSchemaCache();\n assertQueryReturns(\n \"select {[Measures].[Customer Count]} ON columns,\\n\"\n + \" {([Promotion Media].[All Media], [Product].[All Products])} ON rows\\n\"\n + \"from [Sales]\\n\"\n + \"where [Time].[1997]\",\n \"Axis #0:\\n\"\n + \"{[Time].[1997]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Customer Count]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Promotion Media].[All Media], [Product].[All Products]}\\n\"\n + \"Row #0: 5,581\\n\");\n }\n\n /** Make sure that the \"Store\" cube is working. */\n public void testStoreCube() {\n assertQueryReturns(\n \"select {[Measures].members} on columns,\\n\"\n + \" {[Store Type].members} on rows\\n\"\n + \"from [Store]\"\n + \"where [Store].[USA].[CA]\",\n\n \"Axis #0:\\n\"\n + \"{[Store].[All Stores].[USA].[CA]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Store Sqft]}\\n\"\n + \"{[Measures].[Grocery Sqft]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Store Type].[All Store Types]}\\n\"\n + \"{[Store Type].[All Store Types].[Deluxe Supermarket]}\\n\"\n + \"{[Store Type].[All Store Types].[Gourmet Supermarket]}\\n\"\n + \"{[Store Type].[All Store Types].[HeadQuarters]}\\n\"\n + \"{[Store Type].[All Store Types].[Mid-Size Grocery]}\\n\"\n + \"{[Store Type].[All Store Types].[Small Grocery]}\\n\"\n + \"{[Store Type].[All Store Types].[Supermarket]}\\n\"\n + \"Row #0: 69,764\\n\"\n + \"Row #0: 44,868\\n\"\n + \"Row #1: \\n\"\n + \"Row #1: \\n\"\n + \"Row #2: 23,688\\n\"\n + \"Row #2: 15,337\\n\"\n + \"Row #3: \\n\"\n + \"Row #3: \\n\"\n + \"Row #4: \\n\"\n + \"Row #4: \\n\"\n + \"Row #5: 22,478\\n\"\n + \"Row #5: 15,321\\n\"\n + \"Row #6: 23,598\\n\"\n + \"Row #6: 14,210\\n\");\n }\n\n public void testSchemaLevelTableIsBad() {\n // todo: \n }\n\n public void testSchemaLevelTableInAnotherHierarchy() {\n // todo:\n // \n // \n // \n // \n // \n // \n // \n }\n\n public void testSchemaLevelWithViewSpecifiesTable() {\n // todo:\n // \n // select * from emp\n // \n // \n // Should get error that tablename is not allowed\n }\n\n public void testSchemaLevelOrdinalInOtherTable() {\n // todo:\n // Hierarchy is based upon a join.\n // Level's name expression is in a different table than its ordinal.\n }\n\n public void testSchemaTopLevelNotUnique() {\n // todo:\n // Should get error if the top level of a hierarchy does not have\n // uniqueNames=\"true\"\n }\n\n /**\n * Bug 645744 happens when getting the children of a member crosses a table\n * boundary. The symptom\n */\n public void testBug645744() {\n // minimal test case\n assertQueryReturns(\n \"select {[Measures].[Unit Sales]} ON columns,\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages].[Drinks].[Flavored Drinks].children} ON rows\\n\"\n + \"from [Sales]\",\n\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages].[Drinks].[Flavored Drinks].[Excellent]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages].[Drinks].[Flavored Drinks].[Fabulous]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages].[Drinks].[Flavored Drinks].[Skinner]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages].[Drinks].[Flavored Drinks].[Token]}\\n\"\n + \"{[Product].[All Products].[Drink].[Beverages].[Drinks].[Flavored Drinks].[Washington]}\\n\"\n + \"Row #0: 468\\n\"\n + \"Row #1: 469\\n\"\n + \"Row #2: 506\\n\"\n + \"Row #3: 466\\n\"\n + \"Row #4: 560\\n\");\n\n // shorter test case\n executeQuery(\n \"select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} ON columns,\"\n + \"ToggleDrillState({\"\n + \"([Promotion Media].[All Media].[Radio], [Product].[All Products].[Drink].[Beverages].[Drinks].[Flavored Drinks])\"\n + \"}, {[Product].[All Products].[Drink].[Beverages].[Drinks].[Flavored Drinks]}) ON rows \"\n + \"from [Sales] where ([Time].[1997])\");\n }\n\n /**\n * The bug happened when a cell which was in cache was compared with a cell\n * which was not in cache. The compare method could not deal with the\n * {@link RuntimeException} which indicates that the cell is not in cache.\n */\n public void testBug636687() {\n executeQuery(\n \"select {[Measures].[Unit Sales], [Measures].[Store Cost],[Measures].[Store Sales]} ON columns, \"\n + \"Order(\"\n + \"{([Store].[All Stores].[USA].[CA], [Product].[All Products].[Drink].[Alcoholic Beverages]), \"\n + \"([Store].[All Stores].[USA].[CA], [Product].[All Products].[Drink].[Beverages]), \"\n + \"Crossjoin({[Store].[All Stores].[USA].[CA].Children}, {[Product].[All Products].[Drink].[Beverages]}), \"\n + \"([Store].[All Stores].[USA].[CA], [Product].[All Products].[Drink].[Dairy]), \"\n + \"([Store].[All Stores].[USA].[OR], [Product].[All Products].[Drink].[Alcoholic Beverages]), \"\n + \"([Store].[All Stores].[USA].[OR], [Product].[All Products].[Drink].[Beverages]), \"\n + \"([Store].[All Stores].[USA].[OR], [Product].[All Products].[Drink].[Dairy]), \"\n + \"([Store].[All Stores].[USA].[WA], [Product].[All Products].[Drink].[Alcoholic Beverages]), \"\n + \"([Store].[All Stores].[USA].[WA], [Product].[All Products].[Drink].[Beverages]), \"\n + \"([Store].[All Stores].[USA].[WA], [Product].[All Products].[Drink].[Dairy])}, \"\n + \"[Measures].[Store Cost], BDESC) ON rows \"\n + \"from [Sales] \"\n + \"where ([Time].[1997])\");\n executeQuery(\n \"select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} ON columns, \"\n + \"Order(\"\n + \"{([Store].[All Stores].[USA].[WA], [Product].[All Products].[Drink].[Beverages]), \"\n + \"([Store].[All Stores].[USA].[CA], [Product].[All Products].[Drink].[Beverages]), \"\n + \"([Store].[All Stores].[USA].[OR], [Product].[All Products].[Drink].[Beverages]), \"\n + \"([Store].[All Stores].[USA].[WA], [Product].[All Products].[Drink].[Alcoholic Beverages]), \"\n + \"([Store].[All Stores].[USA].[CA], [Product].[All Products].[Drink].[Alcoholic Beverages]), \"\n + \"([Store].[All Stores].[USA].[OR], [Product].[All Products].[Drink].[Alcoholic Beverages]), \"\n + \"([Store].[All Stores].[USA].[WA], [Product].[All Products].[Drink].[Dairy]), \"\n + \"([Store].[All Stores].[USA].[CA].[San Diego], [Product].[All Products].[Drink].[Beverages]), \"\n + \"([Store].[All Stores].[USA].[CA].[Los Angeles], [Product].[All Products].[Drink].[Beverages]), \"\n + \"Crossjoin({[Store].[All Stores].[USA].[CA].[Los Angeles]}, {[Product].[All Products].[Drink].[Beverages].Children}), \"\n + \"([Store].[All Stores].[USA].[CA].[Beverly Hills], [Product].[All Products].[Drink].[Beverages]), \"\n + \"([Store].[All Stores].[USA].[CA], [Product].[All Products].[Drink].[Dairy]), \"\n + \"([Store].[All Stores].[USA].[OR], [Product].[All Products].[Drink].[Dairy]), \"\n + \"([Store].[All Stores].[USA].[CA].[San Francisco], [Product].[All Products].[Drink].[Beverages])}, \"\n + \"[Measures].[Store Cost], BDESC) ON rows \"\n + \"from [Sales] \"\n + \"where ([Time].[1997])\");\n }\n\n /**\n * Bug 769114: Internal error (\"not found\") when executing\n * Order(TopCount).\n */\n public void testBug769114() {\n assertQueryReturns(\n \"select {[Measures].[Unit Sales], [Measures].[Store Cost], [Measures].[Store Sales]} ON columns,\\n\"\n + \" Order(TopCount({[Product].[Product Category].Members}, 10.0, [Measures].[Unit Sales]), [Measures].[Store Sales], ASC) ON rows\\n\"\n + \"from [Sales]\\n\"\n + \"where [Time].[1997]\",\n \"Axis #0:\\n\"\n + \"{[Time].[1997]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"{[Measures].[Store Cost]}\\n\"\n + \"{[Measures].[Store Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Product].[All Products].[Food].[Baked Goods].[Bread]}\\n\"\n + \"{[Product].[All Products].[Food].[Deli].[Meat]}\\n\"\n + \"{[Product].[All Products].[Food].[Dairy].[Dairy]}\\n\"\n + \"{[Product].[All Products].[Food].[Baking Goods].[Baking Goods]}\\n\"\n + \"{[Product].[All Products].[Food].[Baking Goods].[Jams and Jellies]}\\n\"\n + \"{[Product].[All Products].[Food].[Canned Foods].[Canned Soup]}\\n\"\n + \"{[Product].[All Products].[Food].[Frozen Foods].[Vegetables]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods].[Snack Foods]}\\n\"\n + \"{[Product].[All Products].[Food].[Produce].[Fruit]}\\n\"\n + \"{[Product].[All Products].[Food].[Produce].[Vegetables]}\\n\"\n + \"Row #0: 7,870\\n\"\n + \"Row #0: 6,564.09\\n\"\n + \"Row #0: 16,455.43\\n\"\n + \"Row #1: 9,433\\n\"\n + \"Row #1: 8,215.81\\n\"\n + \"Row #1: 20,616.29\\n\"\n + \"Row #2: 12,885\\n\"\n + \"Row #2: 12,228.85\\n\"\n + \"Row #2: 30,508.85\\n\"\n + \"Row #3: 8,357\\n\"\n + \"Row #3: 6,123.32\\n\"\n + \"Row #3: 15,446.69\\n\"\n + \"Row #4: 11,888\\n\"\n + \"Row #4: 9,247.29\\n\"\n + \"Row #4: 23,223.72\\n\"\n + \"Row #5: 8,006\\n\"\n + \"Row #5: 6,408.29\\n\"\n + \"Row #5: 15,966.10\\n\"\n + \"Row #6: 6,984\\n\"\n + \"Row #6: 5,885.05\\n\"\n + \"Row #6: 14,769.82\\n\"\n + \"Row #7: 30,545\\n\"\n + \"Row #7: 26,963.34\\n\"\n + \"Row #7: 67,609.82\\n\"\n + \"Row #8: 11,767\\n\"\n + \"Row #8: 10,312.77\\n\"\n + \"Row #8: 25,816.13\\n\"\n + \"Row #9: 20,739\\n\"\n + \"Row #9: 18,048.81\\n\"\n + \"Row #9: 45,185.41\\n\");\n }\n\n /**\n * Bug 793616: Deeply nested UNION function takes forever to validate.\n * (Problem was that each argument of a function was validated twice, hence\n * the validation time was O(2 ^ depth)
.)\n */\n public void _testBug793616() {\n if (props.TestExpDependencies.get() > 0) {\n // Don't run this test if dependency-checking is enabled.\n // Dependency checking will hugely slow down evaluation, and give\n // the false impression that the validation performance bug has\n // returned.\n return;\n }\n final long start = System.currentTimeMillis();\n Connection connection = getTestContext().getFoodMartConnection();\n final String queryString =\n \"select {[Measures].[Unit Sales],\\n\"\n + \" [Measures].[Store Cost],\\n\"\n + \" [Measures].[Store Sales]} ON columns,\\n\"\n + \"Hierarchize(Union(Union(Union(Union(Union(Union(Union(Union(Union(Union(Union(Union(Union(Union(Union(Union(Union(Union(Union(Union\\n\"\n + \"({([Gender].[All Gender],\\n\"\n + \" [Marital Status].[All Marital Status],\\n\"\n + \" [Customers].[All Customers],\\n\"\n + \" [Product].[All Products])},\\n\"\n + \" Crossjoin ([Gender].[All Gender].Children,\\n\"\n + \" {([Marital Status].[All Marital Status],\\n\"\n + \" [Customers].[All Customers],\\n\"\n + \" [Product].[All Products])})),\\n\"\n + \" Crossjoin(Crossjoin({[Gender].[All Gender].[F]},\\n\"\n + \" [Marital Status].[All Marital Status].Children),\\n\"\n + \" {([Customers].[All Customers],\\n\"\n + \" [Product].[All Products])})),\\n\"\n + \" Crossjoin(Crossjoin({([Gender].[All Gender].[F],\\n\"\n + \" [Marital Status].[All Marital Status].[M])},\\n\"\n + \" [Customers].[All Customers].Children),\\n\"\n + \" {[Product].[All Products]})),\\n\"\n + \" Crossjoin(Crossjoin({([Gender].[All Gender].[F],\\n\"\n + \" [Marital Status].[All Marital Status].[M])},\\n\"\n + \" [Customers].[All Customers].[USA].Children),\\n\"\n + \" {[Product].[All Products]})),\\n\"\n + \" Crossjoin ({([Gender].[All Gender].[F], [Marital Status].[All Marital Status].[M], [Customers].[All Customers].[USA].[CA])},\\n\"\n + \" [Product].[All Products].Children)),\\n\"\n + \" Crossjoin({([Gender].[All Gender].[F], [Marital Status].[All Marital Status].[M], [Customers].[All Customers].[USA].[OR])},\\n\"\n + \" [Product].[All Products].Children)),\\n\"\n + \" Crossjoin({([Gender].[All Gender].[F], [Marital Status].[All Marital Status].[M], [Customers].[All Customers].[USA].[WA])},\\n\"\n + \" [Product].[All Products].Children)),\\n\"\n + \" Crossjoin ({([Gender].[All Gender].[F], [Marital Status].[All Marital Status].[M], [Customers].[All Customers].[USA])},\\n\"\n + \" [Product].[All Products].Children)),\\n\"\n + \" Crossjoin(\\n\"\n + \" Crossjoin({([Gender].[All Gender].[F], [Marital Status].[All Marital Status].[S])}, [Customers].[All Customers].Children),\\n\"\n + \" {[Product].[All Products]})),\\n\"\n + \" Crossjoin(Crossjoin({([Gender].[All Gender].[F],\\n\"\n + \" [Marital Status].[All Marital Status].[S])},\\n\"\n + \" [Customers].[All Customers].[USA].Children),\\n\"\n + \" {[Product].[All Products]})),\\n\"\n + \" Crossjoin ({([Gender].[All Gender].[F],\\n\"\n + \" [Marital Status].[All Marital Status].[S],\\n\"\n + \" [Customers].[All Customers].[USA].[CA])},\\n\"\n + \" [Product].[All Products].Children)),\\n\"\n + \" Crossjoin({([Gender].[All Gender].[F],\\n\"\n + \" [Marital Status].[All Marital Status].[S],\\n\"\n + \" [Customers].[All Customers].[USA].[OR])},\\n\"\n + \" [Product].[All Products].Children)),\\n\"\n + \" Crossjoin({([Gender].[All Gender].[F],\\n\"\n + \" [Marital Status].[All Marital Status].[S],\\n\"\n + \" [Customers].[All Customers].[USA].[WA])},\\n\"\n + \" [Product].[All Products].Children)),\\n\"\n + \" Crossjoin ({([Gender].[All Gender].[F],\\n\"\n + \" [Marital Status].[All Marital Status].[S],\\n\"\n + \" [Customers].[All Customers].[USA])},\\n\"\n + \" [Product].[All Products].Children)),\\n\"\n + \" Crossjoin(Crossjoin({([Gender].[All Gender].[F],\\n\"\n + \" [Marital Status].[All Marital Status])},\\n\"\n + \" [Customers].[All Customers].Children),\\n\"\n + \" {[Product].[All Products]})),\\n\"\n + \" Crossjoin(Crossjoin({([Gender].[All Gender].[F],\\n\"\n + \" [Marital Status].[All Marital Status])},\\n\"\n + \" [Customers].[All Customers].[USA].Children),\\n\"\n + \" {[Product].[All Products]})),\\n\"\n + \" Crossjoin ({([Gender].[All Gender].[F],\\n\"\n + \" [Marital Status].[All Marital Status],\\n\"\n + \" [Customers].[All Customers].[USA].[CA])},\\n\"\n + \" [Product].[All Products].Children)),\\n\"\n + \" Crossjoin({([Gender].[All Gender].[F],\\n\"\n + \" [Marital Status].[All Marital Status],\\n\"\n + \" [Customers].[All Customers].[USA].[OR])},\\n\"\n + \" [Product].[All Products].Children)),\\n\"\n + \" Crossjoin({([Gender].[All Gender].[F],\\n\"\n + \" [Marital Status].[All Marital Status],\\n\"\n + \" [Customers].[All Customers].[USA].[WA])},\\n\"\n + \" [Product].[All Products].Children)),\\n\"\n + \" Crossjoin ({([Gender].[All Gender].[F],\\n\"\n + \" [Marital Status].[All Marital Status],\\n\"\n + \" [Customers].[All Customers].[USA])},\\n\"\n + \" [Product].[All Products].Children))) ON rows from [Sales] where [Time].[1997]\";\n Query query = connection.parseQuery(queryString);\n // If this call took longer than 10 seconds, the performance bug has\n // probably resurfaced again.\n final long afterParseMillis = System.currentTimeMillis();\n final long afterParseNonDbMillis =\n afterParseMillis - Util.dbTimeMillis();\n final long parseMillis = afterParseMillis - start;\n assertTrue(\n \"performance problem: parse took \" + parseMillis + \" milliseconds\",\n parseMillis <= 10000);\n\n Result result = connection.execute(query);\n assertEquals(59, result.getAxes()[1].getPositions().size());\n\n // If this call took longer than 10 seconds,\n // or 2 seconds exclusing db access,\n // the performance bug has\n // probably resurfaced again.\n final long afterExecMillis = System.currentTimeMillis();\n final long afterExecNonDbMillis = afterExecMillis - Util.dbTimeMillis();\n final long execNonDbMillis =\n afterExecNonDbMillis - afterParseNonDbMillis;\n final long execMillis = (afterExecMillis - afterParseMillis);\n assertTrue(\n \"performance problem: execute took \"\n + execMillis\n + \" milliseconds, \"\n + execNonDbMillis\n + \" milliseconds excluding db\",\n execNonDbMillis <= 2000 && execMillis <= 30000);\n }\n\n public void testCatalogHierarchyBasedOnView() {\n // Don't run this test if aggregates are enabled: two levels mapped to\n // the \"gender\" column confuse the agg engine.\n if (props.ReadAggregates.get()) {\n return;\n }\n TestContext testContext = TestContext.createSubstitutingCube(\n \"Sales\",\n \"\\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \"\",\n null);\n if (!testContext.getDialect().allowsFromQuery()) {\n return;\n }\n testContext.assertAxisReturns(\n \"[Gender2].members\",\n \"[Gender2].[All Gender]\\n\"\n + \"[Gender2].[All Gender].[F]\\n\"\n + \"[Gender2].[All Gender].[M]\");\n }\n\n /**\n * Run a query against a large hierarchy, to make sure that we can generate\n * joins correctly. This probably won't work in MySQL.\n */\n public void testCatalogHierarchyBasedOnView2() {\n // Don't run this test if aggregates are enabled: two levels mapped to\n // the \"gender\" column confuse the agg engine.\n if (props.ReadAggregates.get()) {\n return;\n }\n if (getTestContext().getDialect().allowsFromQuery()) {\n return;\n }\n TestContext testContext = TestContext.createSubstitutingCube(\n \"Sales\",\n \"\\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \"\");\n testContext.assertQueryReturns(\n \"select {[Measures].[Unit Sales]} on columns,\\n\"\n + \" {[ProductView].[Drink].[Beverages].children} on rows\\n\"\n + \"from Sales\",\n\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[ProductView].[All ProductViews].[Drink].[Beverages].[Carbonated Beverages]}\\n\"\n + \"{[ProductView].[All ProductViews].[Drink].[Beverages].[Drinks]}\\n\"\n + \"{[ProductView].[All ProductViews].[Drink].[Beverages].[Hot Beverages]}\\n\"\n + \"{[ProductView].[All ProductViews].[Drink].[Beverages].[Pure Juice Beverages]}\\n\"\n + \"Row #0: 3,407\\n\"\n + \"Row #1: 2,469\\n\"\n + \"Row #2: 4,301\\n\"\n + \"Row #3: 3,396\\n\");\n }\n\n public void testCountDistinct() {\n assertQueryReturns(\n \"select {[Measures].[Unit Sales], [Measures].[Customer Count]} on columns,\\n\"\n + \" {[Gender].members} on rows\\n\"\n + \"from Sales\",\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"{[Measures].[Customer Count]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Gender].[All Gender]}\\n\"\n + \"{[Gender].[All Gender].[F]}\\n\"\n + \"{[Gender].[All Gender].[M]}\\n\"\n + \"Row #0: 266,773\\n\"\n + \"Row #0: 5,581\\n\"\n + \"Row #1: 131,558\\n\"\n + \"Row #1: 2,755\\n\"\n + \"Row #2: 135,215\\n\"\n + \"Row #2: 2,826\\n\");\n }\n\n /**\n * Turn off aggregate caching and run query with both use of aggregate\n * tables on and off - should result in the same answer.\n * Note that if the \"mondrian.rolap.aggregates.Read\" property is not true,\n * then no aggregate tables is be read in any event.\n */\n public void testCountDistinctAgg() {\n boolean use_agg_orig = props.UseAggregates.get();\n boolean do_caching_orig = props.DisableCaching.get();\n\n // turn off caching\n props.DisableCaching.setString(\"true\");\n\n assertQueryReturns(\n \"select {[Measures].[Unit Sales], [Measures].[Customer Count]} on rows,\\n\"\n + \"NON EMPTY {[Time].[1997].[Q1].[1]} ON COLUMNS\\n\"\n + \"from Sales\",\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Time].[1997].[Q1].[1]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"{[Measures].[Customer Count]}\\n\"\n + \"Row #0: 21,628\\n\"\n + \"Row #1: 1,396\\n\");\n\n if (use_agg_orig) {\n props.UseAggregates.setString(\"false\");\n } else {\n props.UseAggregates.setString(\"true\");\n }\n\n assertQueryReturns(\n \"select {[Measures].[Unit Sales], [Measures].[Customer Count]} on rows,\\n\"\n + \"NON EMPTY {[Time].[1997].[Q1].[1]} ON COLUMNS\\n\"\n + \"from Sales\",\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Time].[1997].[Q1].[1]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"{[Measures].[Customer Count]}\\n\"\n + \"Row #0: 21,628\\n\"\n + \"Row #1: 1,396\\n\");\n\n if (use_agg_orig) {\n props.UseAggregates.setString(\"true\");\n } else {\n props.UseAggregates.setString(\"false\");\n }\n if (do_caching_orig) {\n props.DisableCaching.setString(\"true\");\n } else {\n props.DisableCaching.setString(\"false\");\n }\n }\n\n /**\n *\n * There are cross database order issues in this test.\n *\n * MySQL and Access show the rows as:\n *\n * [Store Size in SQFT].[All Store Size in SQFTs]\n * [Store Size in SQFT].[All Store Size in SQFTs].[null]\n * [Store Size in SQFT].[All Store Size in SQFTs].[]\n *\n * Postgres shows:\n *\n * [Store Size in SQFT].[All Store Size in SQFTs]\n * [Store Size in SQFT].[All Store Size in SQFTs].[]\n * [Store Size in SQFT].[All Store Size in SQFTs].[null]\n *\n * The test failure is due to some inherent differences in the way\n * Postgres orders NULLs in a result set,\n * compared with MySQL and Access.\n *\n * From the MySQL 4.X manual:\n *\n * When doing an ORDER BY, NULL values are presented first if you do\n * ORDER BY ... ASC and last if you do ORDER BY ... DESC.\n *\n * From the Postgres 8.0 manual:\n *\n * The null value sorts higher than any other value. In other words,\n * with ascending sort order, null values sort at the end, and with\n * descending sort order, null values sort at the beginning.\n *\n * Oracle also sorts nulls high by default.\n *\n * So, this test has expected results that vary depending on whether\n * the database is being used sorts nulls high or low.\n *\n */\n public void testMemberWithNullKey() {\n if (!isDefaultNullMemberRepresentation()) {\n return;\n }\n Result result = executeQuery(\n \"select {[Measures].[Unit Sales]} on columns,\\n\"\n + \"{[Store Size in SQFT].members} on rows\\n\"\n + \"from Sales\");\n String resultString = TestContext.toString(result);\n resultString =\n Pattern.compile(\"\\\\.0\\\\]\").matcher(resultString).replaceAll(\"]\");\n\n // The members function hierarchizes its results, so nulls should\n // sort high, regardless of DBMS. Note that Oracle's driver says that\n // NULLs sort low, but it's lying.\n final boolean nullsSortHigh = false;\n int row = 0;\n\n final String expected =\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs]}\\n\"\n\n // null is at the start in order under DBMSs that sort null low\n + (!nullsSortHigh\n ? \"{[Store Size in SQFT].[All Store Size in SQFTs].[#null]}\\n\"\n : \"\")\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[20319]}\\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[21215]}\\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[22478]}\\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[23112]}\\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[23593]}\\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[23598]}\\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[23688]}\\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[23759]}\\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[24597]}\\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[27694]}\\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[28206]}\\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[30268]}\\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[30584]}\\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[30797]}\\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[33858]}\\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[34452]}\\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[34791]}\\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[36509]}\\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[38382]}\\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[39696]}\\n\"\n\n // null is at the end in order for DBMSs that sort nulls high\n + (nullsSortHigh\n ? \"{[Store Size in SQFT].[All Store Size in SQFTs].[#null]}\\n\"\n : \"\")\n + \"Row #\" + row++ + \": 266,773\\n\"\n + (!nullsSortHigh ? \"Row #\" + row++ + \": 39,329\\n\" : \"\")\n + \"Row #\" + row++ + \": 26,079\\n\"\n + \"Row #\" + row++ + \": 25,011\\n\"\n + \"Row #\" + row++ + \": 2,117\\n\"\n + \"Row #\" + row++ + \": \\n\"\n + \"Row #\" + row++ + \": \\n\"\n + \"Row #\" + row++ + \": 25,663\\n\"\n + \"Row #\" + row++ + \": 21,333\\n\"\n + \"Row #\" + row++ + \": \\n\"\n + \"Row #\" + row++ + \": \\n\"\n + \"Row #\" + row++ + \": 41,580\\n\"\n + \"Row #\" + row++ + \": 2,237\\n\"\n + \"Row #\" + row++ + \": 23,591\\n\"\n + \"Row #\" + row++ + \": \\n\"\n + \"Row #\" + row++ + \": \\n\"\n + \"Row #\" + row++ + \": 35,257\\n\"\n + \"Row #\" + row++ + \": \\n\"\n + \"Row #\" + row++ + \": \\n\"\n + \"Row #\" + row++ + \": \\n\"\n + \"Row #\" + row++ + \": \\n\"\n + \"Row #\" + row++ + \": 24,576\\n\"\n + (nullsSortHigh ? \"Row #\" + row++ + \": 39,329\\n\" : \"\");\n TestContext.assertEqualsVerbose(expected, resultString);\n }\n\n /**\n * Slicer contains [Promotion Media].[Daily Paper]
, but\n * filter expression is in terms of [Promotion Media].[Radio]
.\n */\n public void testSlicerOverride() {\n assertQueryReturns(\n \"with member [Measures].[Radio Unit Sales] as \\n\"\n + \" '([Measures].[Unit Sales], [Promotion Media].[Radio])'\\n\"\n + \"select {[Measures].[Unit Sales], [Measures].[Radio Unit Sales]} on columns,\\n\"\n + \" filter([Product].[Product Department].members, [Promotion Media].[Radio] > 50) on rows\\n\"\n + \"from Sales\\n\"\n + \"where ([Promotion Media].[Daily Paper], [Time].[1997].[Q1])\",\n \"Axis #0:\\n\"\n + \"{[Promotion Media].[All Media].[Daily Paper], [Time].[1997].[Q1]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"{[Measures].[Radio Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Product].[All Products].[Food].[Produce]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods]}\\n\"\n + \"Row #0: 692\\n\"\n + \"Row #0: 87\\n\"\n + \"Row #1: 447\\n\"\n + \"Row #1: 63\\n\");\n }\n\n public void testMembersOfLargeDimensionTheHardWay() {\n // Avoid this test if memory is scarce.\n if (Bug.avoidMemoryOverflow(TestContext.instance().getDialect())) {\n return;\n }\n\n final Connection connection =\n TestContext.instance().getFoodMartConnection();\n String queryString =\n \"select {[Measures].[Unit Sales]} on columns,\\n\"\n + \"{[Customers].members} on rows\\n\"\n + \"from Sales\";\n Query query = connection.parseQuery(queryString);\n Result result = connection.execute(query);\n assertEquals(10407, result.getAxes()[1].getPositions().size());\n }\n\n public void testUnparse() {\n Connection connection = getConnection();\n Query query = connection.parseQuery(\n \"with member [Measures].[Rendite] as \\n\"\n + \" '(([Measures].[Store Sales] - [Measures].[Store Cost])) / [Measures].[Store Cost]',\\n\"\n + \" format_string = iif(([Measures].[Store Sales] - [Measures].[Store Cost]) / [Measures].[Store Cost] * 100 > \\n\"\n + \" Parameter (\\\"UpperLimit\\\", NUMERIC, 151, \\\"Obere Grenze\\\"), \\n\"\n + \" \\\"|#.00%|arrow='up'\\\",\\n\"\n + \" iif(([Measures].[Store Sales] - [Measures].[Store Cost]) / [Measures].[Store Cost] * 100 < \\n\"\n + \" Parameter(\\\"LowerLimit\\\", NUMERIC, 150, \\\"Untere Grenze\\\"),\\n\"\n + \" \\\"|#.00%|arrow='down'\\\",\\n\"\n + \" \\\"|#.00%|arrow='right'\\\"))\\n\"\n + \"select {[Measures].members} on columns\\n\"\n + \"from Sales\");\n final String s = Util.unparse(query);\n // Parentheses are added to reflect operator precedence, but that's ok.\n // Note that the doubled parentheses in line #2 of the query have been\n // reduced to a single level.\n TestContext.assertEqualsVerbose(\n \"with member [Measures].[Rendite] as '(([Measures].[Store Sales] - [Measures].[Store Cost]) / [Measures].[Store Cost])', \"\n + \"format_string = IIf((((([Measures].[Store Sales] - [Measures].[Store Cost]) / [Measures].[Store Cost]) * 100.0) > Parameter(\\\"UpperLimit\\\", NUMERIC, 151.0, \\\"Obere Grenze\\\")), \"\n + \"\\\"|#.00%|arrow='up'\\\", \"\n + \"IIf((((([Measures].[Store Sales] - [Measures].[Store Cost]) / [Measures].[Store Cost]) * 100.0) < Parameter(\\\"LowerLimit\\\", NUMERIC, 150.0, \\\"Untere Grenze\\\")), \"\n + \"\\\"|#.00%|arrow='down'\\\", \\\"|#.00%|arrow='right'\\\"))\\n\"\n + \"select {[Measures].Members} ON COLUMNS\\n\"\n + \"from [Sales]\\n\",\n s);\n }\n\n public void testUnparse2() {\n Connection connection = getConnection();\n Query query = connection.parseQuery(\n \"with member [Measures].[Foo] as '1', \"\n + \"format_string='##0.00', \"\n + \"funny=IIf(1=1,\\\"x\\\"\\\"y\\\",\\\"foo\\\") \"\n + \"select {[Measures].[Foo]} on columns from Sales\");\n final String s = query.toString();\n // The \"format_string\" property, a string literal, is now delimited by\n // double-quotes. This won't work in MSOLAP, but for Mondrian it's\n // consistent with the fact that property values are expressions,\n // not enclosed in single-quotes.\n TestContext.assertEqualsVerbose(\n \"with member [Measures].[Foo] as '1.0', \"\n + \"format_string = \\\"##0.00\\\", \"\n + \"funny = IIf((1.0 = 1.0), \\\"x\\\"\\\"y\\\", \\\"foo\\\")\\n\"\n + \"select {[Measures].[Foo]} ON COLUMNS\\n\"\n + \"from [Sales]\\n\",\n s);\n }\n\n /**\n * Basically, the LookupCube function can evaluate a single MDX statement\n * against a cube other than the cube currently indicated by query context\n * to retrieve a single string or numeric result.\n *\n * For example, the Budget cube in the FoodMart 2000 database contains\n * budget information that can be displayed by store. The Sales cube in the\n * FoodMart 2000 database contains sales information that can be displayed\n * by store. Since no virtual cube exists in the FoodMart 2000 database that\n * joins the Sales and Budget cubes together, comparing the two sets of\n * figures would be difficult at best.\n *\n *
Note In many situations a virtual cube can be used to integrate\n * data from multiple cubes, which will often provide a simpler and more\n * efficient solution than the LookupCube function. This example uses the\n * LookupCube function for purposes of illustration.\n *\n *
The following MDX query, however, uses the LookupCube function to\n * retrieve unit sales information for each store from the Sales cube,\n * presenting it side by side with the budget information from the Budget\n * cube.\n */\n public void _testLookupCube() {\n assertQueryReturns(\n \"WITH MEMBER Measures.[Store Unit Sales] AS \\n\"\n + \" 'LookupCube(\\\"Sales\\\", \\\"(\\\" + MemberToStr(Store.CurrentMember) + \\\", Measures.[Unit Sales])\\\")'\\n\"\n + \"SELECT\\n\"\n + \" {Measures.Amount, Measures.[Store Unit Sales]} ON COLUMNS,\\n\"\n + \" Store.CA.CHILDREN ON ROWS\\n\"\n + \"FROM Budget\", \"\");\n }\n\n /**\n *
Basket analysis is a topic better suited to data mining discussions,\n * but some basic forms of basket analysis can be handled through the use of\n * MDX queries.\n *\n *
For example, one method of basket analysis groups customers based on\n * qualification. In the following example, a qualified customer is one who\n * has more than $10,000 in store sales or more than 10 unit sales. The\n * following table illustrates such a report, run against the Sales cube in\n * FoodMart 2000 with qualified customers grouped by the Country and State\n * Province levels of the Customers dimension. The count and store sales\n * total of qualified customers is represented by the Qualified Count and\n * Qualified Sales columns, respectively.\n *\n *
To accomplish this basic form of basket analysis, the following MDX\n * query constructs two calculated members. The first calculated member uses\n * the MDX Count, Filter, and Descendants functions to create the Qualified\n * Count column, while the second calculated member uses the MDX Sum,\n * Filter, and Descendants functions to create the Qualified Sales column.\n *\n *
The key to this MDX query is the use of Filter and Descendants\n * together to screen out non-qualified customers. Once screened out, the\n * Sum and Count MDX functions can then be used to provide aggregation data\n * only on qualified customers.\n */\n public void testBasketAnalysis() {\n assertQueryReturns(\n \"WITH MEMBER [Measures].[Qualified Count] AS\\n\"\n + \" 'COUNT(FILTER(DESCENDANTS(Customers.CURRENTMEMBER, [Customers].[Name]),\\n\"\n + \" ([Measures].[Store Sales]) > 10000 OR ([Measures].[Unit Sales]) > 10))'\\n\"\n + \"MEMBER [Measures].[Qualified Sales] AS\\n\"\n + \" 'SUM(FILTER(DESCENDANTS(Customers.CURRENTMEMBER, [Customers].[Name]),\\n\"\n + \" ([Measures].[Store Sales]) > 10000 OR ([Measures].[Unit Sales]) > 10),\\n\"\n + \" ([Measures].[Store Sales]))'\\n\"\n + \"SELECT {[Measures].[Qualified Count], [Measures].[Qualified Sales]} ON COLUMNS,\\n\"\n + \" DESCENDANTS([Customers].[All Customers], [State Province], SELF_AND_BEFORE) ON ROWS\\n\"\n + \"FROM Sales\",\n\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Qualified Count]}\\n\"\n + \"{[Measures].[Qualified Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Customers].[All Customers]}\\n\"\n + \"{[Customers].[All Customers].[Canada]}\\n\"\n + \"{[Customers].[All Customers].[Canada].[BC]}\\n\"\n + \"{[Customers].[All Customers].[Mexico]}\\n\"\n + \"{[Customers].[All Customers].[Mexico].[DF]}\\n\"\n + \"{[Customers].[All Customers].[Mexico].[Guerrero]}\\n\"\n + \"{[Customers].[All Customers].[Mexico].[Jalisco]}\\n\"\n + \"{[Customers].[All Customers].[Mexico].[Mexico]}\\n\"\n + \"{[Customers].[All Customers].[Mexico].[Oaxaca]}\\n\"\n + \"{[Customers].[All Customers].[Mexico].[Sinaloa]}\\n\"\n + \"{[Customers].[All Customers].[Mexico].[Veracruz]}\\n\"\n + \"{[Customers].[All Customers].[Mexico].[Yucatan]}\\n\"\n + \"{[Customers].[All Customers].[Mexico].[Zacatecas]}\\n\"\n + \"{[Customers].[All Customers].[USA]}\\n\"\n + \"{[Customers].[All Customers].[USA].[CA]}\\n\"\n + \"{[Customers].[All Customers].[USA].[OR]}\\n\"\n + \"{[Customers].[All Customers].[USA].[WA]}\\n\"\n + \"Row #0: 4,719.00\\n\"\n + \"Row #0: 553,587.77\\n\"\n + \"Row #1: .00\\n\"\n + \"Row #1: \\n\"\n + \"Row #2: .00\\n\"\n + \"Row #2: \\n\"\n + \"Row #3: .00\\n\"\n + \"Row #3: \\n\"\n + \"Row #4: .00\\n\"\n + \"Row #4: \\n\"\n + \"Row #5: .00\\n\"\n + \"Row #5: \\n\"\n + \"Row #6: .00\\n\"\n + \"Row #6: \\n\"\n + \"Row #7: .00\\n\"\n + \"Row #7: \\n\"\n + \"Row #8: .00\\n\"\n + \"Row #8: \\n\"\n + \"Row #9: .00\\n\"\n + \"Row #9: \\n\"\n + \"Row #10: .00\\n\"\n + \"Row #10: \\n\"\n + \"Row #11: .00\\n\"\n + \"Row #11: \\n\"\n + \"Row #12: .00\\n\"\n + \"Row #12: \\n\"\n + \"Row #13: 4,719.00\\n\"\n + \"Row #13: 553,587.77\\n\"\n + \"Row #14: 2,149.00\\n\"\n + \"Row #14: 151,509.69\\n\"\n + \"Row #15: 1,008.00\\n\"\n + \"Row #15: 141,899.84\\n\"\n + \"Row #16: 1,562.00\\n\"\n + \"Row #16: 260,178.24\\n\");\n }\n\n /**\n * Flushes the cache then runs {@link #testBasketAnalysis}, because this\n * test has been known to fail when run standalone.\n */\n public void testBasketAnalysisAfterFlush() {\n getConnection().getCacheControl(null).flushSchemaCache();\n testBasketAnalysis();\n }\n\n /**\n * How Can I Perform Complex String Comparisons?\n *\n *
MDX can handle basic string comparisons, but does not include complex\n * string comparison and manipulation functions, for example, for finding\n * substrings in strings or for supporting case-insensitive string\n * comparisons. However, since MDX can take advantage of external function\n * libraries, this question is easily resolved using string manipulation\n * and comparison functions from the Microsoft Visual Basic for\n * Applications (VBA) external function library.\n *\n *
For example, you want to report the unit sales of all fruit-based\n * products -- not only the sales of fruit, but canned fruit, fruit snacks,\n * fruit juices, and so on. By using the LCase and InStr VBA functions, the\n * following results are easily accomplished in a single MDX query, without\n * complex set construction or explicit member names within the query.\n *\n *
The following MDX query demonstrates how to achieve the results\n * displayed in the previous table. For each member in the Product\n * dimension, the name of the member is converted to lowercase using the\n * LCase VBA function. Then, the InStr VBA function is used to discover\n * whether or not the name contains the word \"fruit\". This information is\n * used to then construct a set, using the Filter MDX function, from only\n * those members from the Product dimension that contain the substring\n * \"fruit\" in their names.\n */\n public void testStringComparisons() {\n assertQueryReturns(\n \"SELECT {Measures.[Unit Sales]} ON COLUMNS,\\n\"\n + \" FILTER([Product].[Product Name].MEMBERS,\\n\"\n + \" INSTR(LCASE([Product].CURRENTMEMBER.NAME), \\\"fruit\\\") <> 0) ON ROWS \\n\"\n + \"FROM Sales\",\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Product].[All Products].[Food].[Canned Products].[Fruit].[Canned Fruit].[Applause].[Applause Canned Mixed Fruit]}\\n\"\n + \"{[Product].[All Products].[Food].[Canned Products].[Fruit].[Canned Fruit].[Big City].[Big City Canned Mixed Fruit]}\\n\"\n + \"{[Product].[All Products].[Food].[Canned Products].[Fruit].[Canned Fruit].[Green Ribbon].[Green Ribbon Canned Mixed Fruit]}\\n\"\n + \"{[Product].[All Products].[Food].[Canned Products].[Fruit].[Canned Fruit].[Swell].[Swell Canned Mixed Fruit]}\\n\"\n + \"{[Product].[All Products].[Food].[Canned Products].[Fruit].[Canned Fruit].[Toucan].[Toucan Canned Mixed Fruit]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods].[Snack Foods].[Dried Fruit].[Best Choice].[Best Choice Apple Fruit Roll]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods].[Snack Foods].[Dried Fruit].[Best Choice].[Best Choice Grape Fruit Roll]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods].[Snack Foods].[Dried Fruit].[Best Choice].[Best Choice Raspberry Fruit Roll]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods].[Snack Foods].[Dried Fruit].[Best Choice].[Best Choice Strawberry Fruit Roll]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods].[Snack Foods].[Dried Fruit].[Fast].[Fast Apple Fruit Roll]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods].[Snack Foods].[Dried Fruit].[Fast].[Fast Grape Fruit Roll]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods].[Snack Foods].[Dried Fruit].[Fast].[Fast Raspberry Fruit Roll]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods].[Snack Foods].[Dried Fruit].[Fast].[Fast Strawberry Fruit Roll]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods].[Snack Foods].[Dried Fruit].[Fort West].[Fort West Apple Fruit Roll]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods].[Snack Foods].[Dried Fruit].[Fort West].[Fort West Grape Fruit Roll]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods].[Snack Foods].[Dried Fruit].[Fort West].[Fort West Raspberry Fruit Roll]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods].[Snack Foods].[Dried Fruit].[Fort West].[Fort West Strawberry Fruit Roll]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods].[Snack Foods].[Dried Fruit].[Horatio].[Horatio Apple Fruit Roll]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods].[Snack Foods].[Dried Fruit].[Horatio].[Horatio Grape Fruit Roll]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods].[Snack Foods].[Dried Fruit].[Horatio].[Horatio Raspberry Fruit Roll]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods].[Snack Foods].[Dried Fruit].[Horatio].[Horatio Strawberry Fruit Roll]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods].[Snack Foods].[Dried Fruit].[Nationeel].[Nationeel Apple Fruit Roll]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods].[Snack Foods].[Dried Fruit].[Nationeel].[Nationeel Grape Fruit Roll]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods].[Snack Foods].[Dried Fruit].[Nationeel].[Nationeel Raspberry Fruit Roll]}\\n\"\n + \"{[Product].[All Products].[Food].[Snack Foods].[Snack Foods].[Dried Fruit].[Nationeel].[Nationeel Strawberry Fruit Roll]}\\n\"\n + \"Row #0: 205\\n\"\n + \"Row #1: 204\\n\"\n + \"Row #2: 142\\n\"\n + \"Row #3: 204\\n\"\n + \"Row #4: 187\\n\"\n + \"Row #5: 174\\n\"\n + \"Row #6: 114\\n\"\n + \"Row #7: 110\\n\"\n + \"Row #8: 150\\n\"\n + \"Row #9: 149\\n\"\n + \"Row #10: 173\\n\"\n + \"Row #11: 163\\n\"\n + \"Row #12: 154\\n\"\n + \"Row #13: 181\\n\"\n + \"Row #14: 178\\n\"\n + \"Row #15: 210\\n\"\n + \"Row #16: 189\\n\"\n + \"Row #17: 177\\n\"\n + \"Row #18: 191\\n\"\n + \"Row #19: 149\\n\"\n + \"Row #20: 169\\n\"\n + \"Row #21: 185\\n\"\n + \"Row #22: 216\\n\"\n + \"Row #23: 167\\n\"\n + \"Row #24: 138\\n\");\n }\n\n /**\n * Test case for\n * MONDRIAN-539,\n * \"Problem with the MID function getting last character in a string.\".\n */\n public void testMid() {\n assertQueryReturns(\n \"with\\n\"\n + \"member measures.x as 'Mid(\\\"yahoo\\\",5, 1)'\\n\"\n + \"select {measures.x} ON COLUMNS from [Sales] \",\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[x]}\\n\"\n + \"Row #0: o\\n\");\n }\n\n /**\n * How Can I Show Percentages as Measures?\n *\n *
Another common business question easily answered through MDX is the\n * display of percent values created as available measures.\n *\n *
For example, the Sales cube in the FoodMart 2000 database contains\n * unit sales for each store in a given city, state, and country, organized\n * along the Sales dimension. A report is requested to show, for\n * California, the percentage of total unit sales attained by each city\n * with a store. The results are illustrated in the following table.\n *\n *
Because the parent of a member is typically another, aggregated\n * member in a regular dimension, this is easily achieved by the\n * construction of a calculated member, as demonstrated in the following MDX\n * query, using the CurrentMember and Parent MDX functions.\n */\n public void testPercentagesAsMeasures() {\n assertQueryReturns(\n // todo: \"Store.[USA].[CA]\" should be \"Store.CA\"\n \"WITH MEMBER Measures.[Unit Sales Percent] AS\\n\"\n + \" '((Store.CURRENTMEMBER, Measures.[Unit Sales]) /\\n\"\n + \" (Store.CURRENTMEMBER.PARENT, Measures.[Unit Sales])) ',\\n\"\n + \" FORMAT_STRING = 'Percent'\\n\"\n + \"SELECT {Measures.[Unit Sales], Measures.[Unit Sales Percent]} ON COLUMNS,\\n\"\n + \" ORDER(DESCENDANTS(Store.[USA].[CA], Store.[Store City], SELF), \\n\"\n + \" [Measures].[Unit Sales], ASC) ON ROWS\\n\"\n + \"FROM Sales\",\n\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"{[Measures].[Unit Sales Percent]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[Alameda]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[San Francisco]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[Beverly Hills]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[San Diego]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[Los Angeles]}\\n\"\n + \"Row #0: \\n\"\n + \"Row #0: \\n\"\n + \"Row #1: 2,117\\n\"\n + \"Row #1: 2.83%\\n\"\n + \"Row #2: 21,333\\n\"\n + \"Row #2: 28.54%\\n\"\n + \"Row #3: 25,635\\n\"\n + \"Row #3: 34.30%\\n\"\n + \"Row #4: 25,663\\n\"\n + \"Row #4: 34.33%\\n\");\n }\n\n /**\n * How Can I Show Cumulative Sums as Measures?\n *\n *
Another common business request, cumulative sums, is useful for\n * business reporting purposes. However, since aggregations are handled in a\n * hierarchical fashion, cumulative sums present some unique challenges in\n * Analysis Services.\n *\n *
The best way to create a cumulative sum is as a calculated measure in\n * MDX, using the Rank, Head, Order, and Sum MDX functions together.\n *\n *
For example, the following table illustrates a report that shows two\n * views of employee count in all stores and cities in California, sorted\n * by employee count. The first column shows the aggregated counts for each\n * store and city, while the second column shows aggregated counts for each\n * store, but cumulative counts for each city.\n *\n *
The cumulative number of employees for San Diego represents the value\n * of both Los Angeles and San Diego, the value for Beverly Hills represents\n * the cumulative total of Los Angeles, San Diego, and Beverly Hills, and so\n * on.\n *\n *
Since the members within the state of California have been ordered\n * from highest to lowest number of employees, this form of cumulative sum\n * measure provides a form of pareto analysis within each state.\n *\n *
To support this, the Order function is first used to reorder members\n * accordingly for both the Rank and Head functions. Once reordered, the\n * Rank function is used to supply the ranking of each tuple within the\n * reordered set of members, progressing as each member in the Store\n * dimension is examined. The value is then used to determine the number of\n * tuples to retrieve from the set of reordered members using the Head\n * function. Finally, the retrieved members are then added together using\n * the Sum function to obtain a cumulative sum. The following MDX query\n * demonstrates how all of this works in concert to provide cumulative\n * sums.\n *\n *
As an aside, a named set cannot be used in this situation to replace\n * the duplicate Order function calls. Named sets are evaluated once, when\n * a query is parsed -- since the set can change based on the fact that the\n * set can be different for each store member because the set is evaluated\n * for the children of multiple parents, the set does not change with\n * respect to its use in the Sum function. Since the named set is only\n * evaluated once, it would not satisfy the needs of this query.\n */\n public void _testCumlativeSums() {\n assertQueryReturns(\n // todo: \"[Store].[USA].[CA]\" should be \"Store.CA\"; implement \"AS\"\n \"WITH MEMBER Measures.[Cumulative No of Employees] AS\\n\"\n + \" 'SUM(HEAD(ORDER({[Store].Siblings}, [Measures].[Number of Employees], BDESC) AS OrderedSiblings,\\n\"\n + \" RANK([Store], OrderedSiblings)),\\n\"\n + \" [Measures].[Number of Employees])'\\n\"\n + \"SELECT {[Measures].[Number of Employees], [Measures].[Cumulative No of Employees]} ON COLUMNS,\\n\"\n + \" ORDER(DESCENDANTS([Store].[USA].[CA], [Store State], AFTER), \\n\"\n + \" [Measures].[Number of Employees], BDESC) ON ROWS\\n\"\n + \"FROM HR\",\n \"\");\n }\n\n /**\n * How Can I Implement a Logical AND or OR Condition in a WHERE\n * Clause?\n *\n *
For SQL users, the use of AND and OR logical operators in the WHERE\n * clause of a SQL statement is an essential tool for constructing business\n * queries. However, the WHERE clause of an MDX statement serves a\n * slightly different purpose, and understanding how the WHERE clause is\n * used in MDX can assist in constructing such business queries.\n *\n *
The WHERE clause in MDX is used to further restrict the results of\n * an MDX query, in effect providing another dimension on which the results\n * of the query are further sliced. As such, only expressions that resolve\n * to a single tuple are allowed. The WHERE clause implicitly supports a\n * logical AND operation involving members across different dimensions, by\n * including the members as part of a tuple. To support logical AND\n * operations involving members within a single dimensions, as well as\n * logical OR operations, a calculated member needs to be defined in\n * addition to the use of the WHERE clause.\n *\n *
For example, the following MDX query illustrates the use of a\n * calculated member to support a logical OR. The query returns unit sales\n * by quarter and year for all food and drink related products sold in 1997,\n * run against the Sales cube in the FoodMart 2000 database.\n *\n *
The calculated member simply adds the values of the Unit Sales\n * measure for the Food and the Drink levels of the Product dimension\n * together. The WHERE clause is then used to restrict return of\n * information only to the calculated member, effectively implementing a\n * logical OR to return information for all time periods that contain unit\n * sales values for either food, drink, or both types of products.\n *\n *
You can use the Aggregate function in similar situations where all\n * measures are not aggregated by summing. To return the same results in the\n * above example using the Aggregate function, replace the definition for\n * the calculated member with this definition:\n *\n *
\n * 'Aggregate({[Product].[Food], [Product].[Drink]})'
\n *
\n */\n public void testLogicalOps() {\n assertQueryReturns(\n \"WITH MEMBER [Product].[Food OR Drink] AS\\n\"\n + \" '([Product].[Food], Measures.[Unit Sales]) + ([Product].[Drink], Measures.[Unit Sales])'\\n\"\n + \"SELECT {Measures.[Unit Sales]} ON COLUMNS,\\n\"\n + \" DESCENDANTS(Time.[1997], [Quarter], SELF_AND_BEFORE) ON ROWS\\n\"\n + \"FROM Sales\\n\"\n + \"WHERE [Product].[Food OR Drink]\",\n\n \"Axis #0:\\n\"\n + \"{[Product].[Food OR Drink]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Time].[1997]}\\n\"\n + \"{[Time].[1997].[Q1]}\\n\"\n + \"{[Time].[1997].[Q2]}\\n\"\n + \"{[Time].[1997].[Q3]}\\n\"\n + \"{[Time].[1997].[Q4]}\\n\"\n + \"Row #0: 216,537\\n\"\n + \"Row #1: 53,785\\n\"\n + \"Row #2: 50,720\\n\"\n + \"Row #3: 53,505\\n\"\n + \"Row #4: 58,527\\n\");\n }\n\n /**\n * A logical AND, by contrast, can be supported by using two different\n * techniques. If the members used to construct the logical AND reside on\n * different dimensions, all that is required is a WHERE clause that uses\n * a tuple representing all involved members. The following MDX query uses a\n * WHERE clause that effectively restricts the query to retrieve unit\n * sales for drink products in the USA, shown by quarter and year for 1997.\n */\n public void testLogicalAnd() {\n assertQueryReturns(\n \"SELECT {Measures.[Unit Sales]} ON COLUMNS,\\n\"\n + \" DESCENDANTS([Time].[1997], [Quarter], SELF_AND_BEFORE) ON ROWS\\n\"\n + \"FROM Sales\\n\"\n + \"WHERE ([Product].[Drink], [Store].USA)\",\n\n \"Axis #0:\\n\"\n + \"{[Product].[All Products].[Drink], [Store].[All Stores].[USA]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Time].[1997]}\\n\"\n + \"{[Time].[1997].[Q1]}\\n\"\n + \"{[Time].[1997].[Q2]}\\n\"\n + \"{[Time].[1997].[Q3]}\\n\"\n + \"{[Time].[1997].[Q4]}\\n\"\n + \"Row #0: 24,597\\n\"\n + \"Row #1: 5,976\\n\"\n + \"Row #2: 5,895\\n\"\n + \"Row #3: 6,065\\n\"\n + \"Row #4: 6,661\\n\");\n }\n\n /**\n *
The WHERE clause in the previous MDX query effectively provides a\n * logical AND operator, in which all unit sales for 1997 are returned only\n * for drink products and only for those sold in stores in the USA.\n *\n *
If the members used to construct the logical AND condition reside on\n * the same dimension, you can use a calculated member or a named set to\n * filter out the unwanted members, as demonstrated in the following MDX\n * query.\n *\n *
The named set, [Good AND Pearl Stores], restricts the displayed unit\n * sales totals only to those stores that have sold both Good products and\n * Pearl products.\n */\n public void _testSet() {\n assertQueryReturns(\n \"WITH SET [Good AND Pearl Stores] AS\\n\"\n + \" 'FILTER(Store.Members,\\n\"\n + \" ([Product].[Good], Measures.[Unit Sales]) > 0 AND \\n\"\n + \" ([Product].[Pearl], Measures.[Unit Sales]) > 0)'\\n\"\n + \"SELECT DESCENDANTS([Time].[1997], [Quarter], SELF_AND_BEFORE) ON COLUMNS,\\n\"\n + \" [Good AND Pearl Stores] ON ROWS\\n\"\n + \"FROM Sales\",\n \"\");\n }\n\n /**\n * How Can I Use Custom Member Properties in MDX?\n *\n *
Member properties are a good way of adding secondary business\n * information to members in a dimension. However, getting that information\n * out can be confusing -- member properties are not readily apparent in a\n * typical MDX query.\n *\n *
Member properties can be retrieved in one of two ways. The easiest\n * and most used method of retrieving member properties is to use the\n * DIMENSION PROPERTIES MDX statement when constructing an axis in an MDX\n * query.\n *\n *
For example, a member property in the Store dimension in the FoodMart\n * 2000 database details the total square feet for each store. The following\n * MDX query can retrieve this member property as part of the returned\n * cellset.\n */\n public void testCustomMemberProperties() {\n assertQueryReturns(\n \"SELECT {[Measures].[Units Shipped], [Measures].[Units Ordered]} ON COLUMNS,\\n\"\n + \" NON EMPTY [Store].[Store Name].MEMBERS\\n\"\n + \" DIMENSION PROPERTIES [Store].[Store Name].[Store Sqft] ON ROWS\\n\"\n + \"FROM Warehouse\",\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Units Shipped]}\\n\"\n + \"{[Measures].[Units Ordered]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[Beverly Hills].[Store 6]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[Los Angeles].[Store 7]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[San Diego].[Store 24]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[San Francisco].[Store 14]}\\n\"\n + \"{[Store].[All Stores].[USA].[OR].[Portland].[Store 11]}\\n\"\n + \"{[Store].[All Stores].[USA].[OR].[Salem].[Store 13]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Bellingham].[Store 2]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Bremerton].[Store 3]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Seattle].[Store 15]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Spokane].[Store 16]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Tacoma].[Store 17]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Walla Walla].[Store 22]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Yakima].[Store 23]}\\n\"\n + \"Row #0: 10759.0\\n\"\n + \"Row #0: 11699.0\\n\"\n + \"Row #1: 24587.0\\n\"\n + \"Row #1: 26463.0\\n\"\n + \"Row #2: 23835.0\\n\"\n + \"Row #2: 26270.0\\n\"\n + \"Row #3: 1696.0\\n\"\n + \"Row #3: 1875.0\\n\"\n + \"Row #4: 8515.0\\n\"\n + \"Row #4: 9109.0\\n\"\n + \"Row #5: 32393.0\\n\"\n + \"Row #5: 35797.0\\n\"\n + \"Row #6: 2348.0\\n\"\n + \"Row #6: 2454.0\\n\"\n + \"Row #7: 22734.0\\n\"\n + \"Row #7: 24610.0\\n\"\n + \"Row #8: 24110.0\\n\"\n + \"Row #8: 26703.0\\n\"\n + \"Row #9: 11889.0\\n\"\n + \"Row #9: 12828.0\\n\"\n + \"Row #10: 32411.0\\n\"\n + \"Row #10: 35930.0\\n\"\n + \"Row #11: 1860.0\\n\"\n + \"Row #11: 2074.0\\n\"\n + \"Row #12: 10589.0\\n\"\n + \"Row #12: 11426.0\\n\");\n }\n\n /**\n *
The drawback to using the DIMENSION PROPERTIES statement is that,\n * for most client applications, the member property is not readily\n * apparent. If the previous MDX query is executed in the MDX sample\n * application shipped with SQL Server 2000 Analysis Services, for example,\n * you must double-click the name of the member in the grid to open the\n * Member Properties dialog box, which displays all of the member properties\n * shipped as part of the cellset, including the [Store].[Store Name].[Store\n * Sqft] member property.\n *\n *
The other method of retrieving member properties involves the creation\n * of a calculated member based on the member property. The following MDX\n * query brings back the total square feet for each store as a measure,\n * included in the COLUMNS axis.\n *\n *
The [Store SqFt] measure is constructed with the Properties MDX\n * function to retrieve the [Store SQFT] member property for each member in\n * the Store dimension. The benefit to this technique is that the calculated\n * member is readily apparent and easily accessible in client applications\n * that do not support member properties.\n */\n public void _testMemberPropertyAsCalcMember() {\n assertQueryReturns(\n // todo: implement .PROPERTIES\n \"WITH MEMBER Measures.[Store SqFt] AS '[Store].CURRENTMEMBER.PROPERTIES(\\\"Store SQFT\\\")'\\n\"\n + \"SELECT { [Measures].[Store SQFT], [Measures].[Units Shipped], [Measures].[Units Ordered] } ON COLUMNS,\\n\"\n + \" [Store].[Store Name].MEMBERS ON ROWS\\n\"\n + \"FROM Warehouse\",\n \"\");\n }\n\n /**\n * How Can I Drill Down More Than One Level Deep, or Skip Levels When\n * Drilling Down?\n *\n * Drilling down is an essential ability for most OLAP products, and\n * Analysis Services is no exception. Several functions exist that support\n * drilling up and down the hierarchy of dimensions within a cube.\n * Typically, drilling up and down the hierarchy is done one level at a\n * time; think of this functionality as a zoom feature for OLAP data.\n *\n *
There are times, though, when the need to drill down more than one\n * level at the same time, or even skip levels when displaying information\n * about multiple levels, exists for a business scenario.\n *\n *
For example, you would like to show report results from a query of\n * the Sales cube in the FoodMart 2000 sample database showing sales totals\n * for individual cities and the subtotals for each country, as shown in the\n * following table.\n *\n *
The Customers dimension, however, has Country, State Province, and\n * City levels. In order to show the above report, you would have to show\n * the Country level and then drill down two levels to show the City\n * level, skipping the State Province level entirely.\n *\n *
However, the MDX ToggleDrillState and DrillDownMember functions\n * provide drill down functionality only one level below a specified set. To\n * drill down more than one level below a specified set, you need to use a\n * combination of MDX functions, including Descendants, Generate, and\n * Except. This technique essentially constructs a large set that includes\n * all levels between both upper and lower desired levels, then uses a\n * smaller set representing the undesired level or levels to remove the\n * appropriate members from the larger set.\n *\n *
The MDX Descendants function is used to construct a set consisting of\n * the descendants of each member in the Customers dimension. The\n * descendants are determined using the MDX Descendants function, with the\n * descendants of the City level and the level above, the State Province\n * level, for each member of the Customers dimension being added to the\n * set.\n *\n *
The MDX Generate function now creates a set consisting of all members\n * at the Country level as well as the members of the set generated by the\n * MDX Descendants function. Then, the MDX Except function is used to\n * exclude all members at the State Province level, so the returned set\n * contains members at the Country and City levels.\n *\n *
Note, however, that the previous MDX query will still order the\n * members according to their hierarchy. Although the returned set contains\n * members at the Country and City levels, the Country, State Province,\n * and City levels determine the order of the members.\n */\n public void _testDrillingDownMoreThanOneLevel() {\n assertQueryReturns(\n // todo: implement \"GENERATE\"\n \"SELECT {[Measures].[Unit Sales]} ON COLUMNS,\\n\"\n + \" EXCEPT(GENERATE([Customers].[Country].MEMBERS,\\n\"\n + \" {DESCENDANTS([Customers].CURRENTMEMBER, [Customers].[City], SELF_AND_BEFORE)}),\\n\"\n + \" {[Customers].[State Province].MEMBERS}) ON ROWS\\n\"\n + \"FROM Sales\", \"\");\n }\n\n /**\n * How Do I Get the Topmost Members of a Level Broken Out by an Ancestor\n * Level?\n *\n *
This type of MDX query is common when only the facts for the lowest\n * level of a dimension within a cube are needed, but information about\n * other levels within the same dimension may also be required to satisfy a\n * specific business scenario.\n *\n *
For example, a report that shows the unit sales for the store with\n * the highest unit sales from each country is needed for marketing\n * purposes. The following table provides an example of this report, run\n * against the Sales cube in the FoodMart 2000 sample database.\n *\n *
This looks simple enough, but the Country Name column provides\n * unexpected difficulty. The values for the Store Country column are taken\n * from the Store Country level of the Store dimension, so the Store\n * Country column is constructed as a calculated member as part of the MDX\n * query, using the MDX Ancestor and Name functions to return the country\n * names for each store.\n *\n *
A combination of the MDX Generate, TopCount, and Descendants\n * functions are used to create a set containing the top stores in unit\n * sales for each country.\n */\n public void _testTopmost() {\n assertQueryReturns(\n // todo: implement \"GENERATE\"\n \"WITH MEMBER Measures.[Country Name] AS \\n\"\n + \" 'Ancestor(Store.CurrentMember, [Store Country]).Name'\\n\"\n + \"SELECT {Measures.[Country Name], Measures.[Unit Sales]} ON COLUMNS,\\n\"\n + \" GENERATE([Store Country].MEMBERS, \\n\"\n + \" TOPCOUNT(DESCENDANTS([Store].CURRENTMEMBER, [Store].[Store Name]),\\n\"\n + \" 1, [Measures].[Unit Sales])) ON ROWS\\n\"\n + \"FROM Sales\",\n \"\");\n }\n\n /**\n *
The MDX Descendants function is used to construct a set consisting of\n * only those members at the Store Name level in the Store dimension. Then,\n * the MDX TopCount function is used to return only the topmost store based\n * on the Unit Sales measure. The MDX Generate function then constructs a\n * set based on the topmost stores, following the hierarchy of the Store\n * dimension.\n *\n *
Alternate techniques, such as using the MDX Crossjoin function, may\n * not provide the desired results because non-related joins can occur.\n * Since the Store Country and Store Name levels are within the same\n * dimension, they cannot be cross-joined. Another dimension that provides\n * the same regional hierarchy structure, such as the Customers dimension,\n * can be employed with the Crossjoin function. But, using this technique\n * can cause non-related joins and return unexpected results.\n *\n *
For example, the following MDX query uses the Crossjoin function to\n * attempt to return the same desired results.\n *\n *
However, some unexpected surprises occur because the topmost member\n * in the Store dimension is cross-joined with all of the children of the\n * Customers dimension, as shown in the following table.\n *\n *
In this instance, the use of a calculated member to provide store\n * country names is easier to understand and debug than attempting to\n * cross-join across unrelated members\n */\n public void testTopmost2() {\n assertQueryReturns(\n \"SELECT {Measures.[Unit Sales]} ON COLUMNS,\\n\"\n + \" CROSSJOIN(Customers.CHILDREN,\\n\"\n + \" TOPCOUNT(DESCENDANTS([Store].CURRENTMEMBER, [Store].[Store Name]),\\n\"\n + \" 1, [Measures].[Unit Sales])) ON ROWS\\n\"\n + \"FROM Sales\",\n\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Customers].[All Customers].[Canada], [Store].[All Stores].[USA].[OR].[Salem].[Store 13]}\\n\"\n + \"{[Customers].[All Customers].[Mexico], [Store].[All Stores].[USA].[OR].[Salem].[Store 13]}\\n\"\n + \"{[Customers].[All Customers].[USA], [Store].[All Stores].[USA].[OR].[Salem].[Store 13]}\\n\"\n + \"Row #0: \\n\"\n + \"Row #1: \\n\"\n + \"Row #2: 41,580\\n\");\n }\n\n /**\n * How Can I Rank or Reorder Members?\n *\n *
One of the issues commonly encountered in business scenarios is the\n * need to rank the members of a dimension according to their corresponding\n * measure values. The Order MDX function allows you to order a set based on\n * a string or numeric expression evaluated against the members of a set.\n * Combined with other MDX functions, the Order function can support\n * several different types of ranking.\n *\n *
For example, the Sales cube in the FoodMart 2000 database can be used\n * to show unit sales for each store. However, the business scenario\n * requires a report that ranks the stores from highest to lowest unit\n * sales, individually, of nonconsumable products.\n *\n *
Because of the requirement that stores be sorted individually, the\n * hierarchy must be broken (in other words, ignored) for the purpose of\n * ranking the stores. The Order function is capable of sorting within the\n * hierarchy, based on the topmost level represented in the set to be\n * sorted, or, by breaking the hierarchy, sorting all of the members of the\n * set as if they existed on the same level, with the same parent.\n *\n *
The following MDX query illustrates the use of the Order function to\n * rank the members according to unit sales.\n */\n public void testRank() {\n assertQueryReturns(\n \"SELECT {[Measures].[Unit Sales]} ON COLUMNS, \\n\"\n + \" ORDER([Store].[Store Name].MEMBERS, (Measures.[Unit Sales]), BDESC) ON ROWS\\n\"\n + \"FROM Sales\\n\"\n + \"WHERE [Product].[Non-Consumable]\",\n \"Axis #0:\\n\"\n + \"{[Product].[All Products].[Non-Consumable]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Store].[All Stores].[USA].[OR].[Salem].[Store 13]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Tacoma].[Store 17]}\\n\"\n + \"{[Store].[All Stores].[USA].[OR].[Portland].[Store 11]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[Los Angeles].[Store 7]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[San Diego].[Store 24]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Seattle].[Store 15]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Bremerton].[Store 3]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Spokane].[Store 16]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[Beverly Hills].[Store 6]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Yakima].[Store 23]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Bellingham].[Store 2]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Walla Walla].[Store 22]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[San Francisco].[Store 14]}\\n\"\n + \"{[Store].[All Stores].[Canada].[BC].[Vancouver].[Store 19]}\\n\"\n + \"{[Store].[All Stores].[Canada].[BC].[Victoria].[Store 20]}\\n\"\n + \"{[Store].[All Stores].[Mexico].[DF].[Mexico City].[Store 9]}\\n\"\n + \"{[Store].[All Stores].[Mexico].[DF].[San Andres].[Store 21]}\\n\"\n + \"{[Store].[All Stores].[Mexico].[Guerrero].[Acapulco].[Store 1]}\\n\"\n + \"{[Store].[All Stores].[Mexico].[Jalisco].[Guadalajara].[Store 5]}\\n\"\n + \"{[Store].[All Stores].[Mexico].[Veracruz].[Orizaba].[Store 10]}\\n\"\n + \"{[Store].[All Stores].[Mexico].[Yucatan].[Merida].[Store 8]}\\n\"\n + \"{[Store].[All Stores].[Mexico].[Zacatecas].[Camacho].[Store 4]}\\n\"\n + \"{[Store].[All Stores].[Mexico].[Zacatecas].[Hidalgo].[Store 12]}\\n\"\n + \"{[Store].[All Stores].[Mexico].[Zacatecas].[Hidalgo].[Store 18]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA].[Alameda].[HQ]}\\n\"\n + \"Row #0: 7,940\\n\"\n + \"Row #1: 6,712\\n\"\n + \"Row #2: 5,076\\n\"\n + \"Row #3: 4,947\\n\"\n + \"Row #4: 4,706\\n\"\n + \"Row #5: 4,639\\n\"\n + \"Row #6: 4,479\\n\"\n + \"Row #7: 4,428\\n\"\n + \"Row #8: 3,950\\n\"\n + \"Row #9: 2,140\\n\"\n + \"Row #10: 442\\n\"\n + \"Row #11: 390\\n\"\n + \"Row #12: 387\\n\"\n + \"Row #13: \\n\"\n + \"Row #14: \\n\"\n + \"Row #15: \\n\"\n + \"Row #16: \\n\"\n + \"Row #17: \\n\"\n + \"Row #18: \\n\"\n + \"Row #19: \\n\"\n + \"Row #20: \\n\"\n + \"Row #21: \\n\"\n + \"Row #22: \\n\"\n + \"Row #23: \\n\"\n + \"Row #24: \\n\");\n }\n\n /**\n * How Can I Use Different Calculations for Different Levels in a\n * Dimension?\n *\n *
This type of MDX query frequently occurs when different aggregations\n * are needed at different levels in a dimension. One easy way to support\n * such functionality is through the use of a calculated measure, created as\n * part of the query, which uses the MDX Descendants function in conjunction\n * with one of the MDX aggregation functions to provide results.\n *\n *
For example, the Warehouse cube in the FoodMart 2000 database\n * supplies the [Units Ordered] measure, aggregated through the Sum\n * function. But, you would also like to see the average number of units\n * ordered per store. The following table demonstrates the desired results.\n *\n *
By using the following MDX query, the desired results can be\n * achieved. The calculated measure, [Average Units Ordered], supplies the\n * average number of ordered units per store by using the Avg,\n * CurrentMember, and Descendants MDX functions.\n */\n public void testDifferentCalculationsForDifferentLevels() {\n assertQueryReturns(\n \"WITH MEMBER Measures.[Average Units Ordered] AS\\n\"\n + \" 'AVG(DESCENDANTS([Store].CURRENTMEMBER, [Store].[Store Name]), [Measures].[Units Ordered])',\\n\"\n + \" FORMAT_STRING='#.00'\\n\"\n + \"SELECT {[Measures].[Units ordered], Measures.[Average Units Ordered]} ON COLUMNS,\\n\"\n + \" [Store].[Store State].MEMBERS ON ROWS\\n\"\n + \"FROM Warehouse\",\n\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Units Ordered]}\\n\"\n + \"{[Measures].[Average Units Ordered]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Store].[All Stores].[Canada].[BC]}\\n\"\n + \"{[Store].[All Stores].[Mexico].[DF]}\\n\"\n + \"{[Store].[All Stores].[Mexico].[Guerrero]}\\n\"\n + \"{[Store].[All Stores].[Mexico].[Jalisco]}\\n\"\n + \"{[Store].[All Stores].[Mexico].[Veracruz]}\\n\"\n + \"{[Store].[All Stores].[Mexico].[Yucatan]}\\n\"\n + \"{[Store].[All Stores].[Mexico].[Zacatecas]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA]}\\n\"\n + \"{[Store].[All Stores].[USA].[OR]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA]}\\n\"\n + \"Row #0: \\n\"\n + \"Row #0: \\n\"\n + \"Row #1: \\n\"\n + \"Row #1: \\n\"\n + \"Row #2: \\n\"\n + \"Row #2: \\n\"\n + \"Row #3: \\n\"\n + \"Row #3: \\n\"\n + \"Row #4: \\n\"\n + \"Row #4: \\n\"\n + \"Row #5: \\n\"\n + \"Row #5: \\n\"\n + \"Row #6: \\n\"\n + \"Row #6: \\n\"\n + \"Row #7: 66307.0\\n\"\n + \"Row #7: 16576.75\\n\"\n + \"Row #8: 44906.0\\n\"\n + \"Row #8: 22453.00\\n\"\n + \"Row #9: 116025.0\\n\"\n + \"Row #9: 16575.00\\n\");\n }\n\n /**\n *
This calculated measure is more powerful than it seems; if, for\n * example, you then want to see the average number of units ordered for\n * beer products in all of the stores in the California area, the following\n * MDX query can be executed with the same calculated measure.\n */\n public void testDifferentCalculations2() {\n assertQueryReturns(\n // todo: \"[Store].[USA].[CA]\" should be \"[Store].CA\",\n // \"[Product].[Drink].[Alcoholic Beverages].[Beer and Wine].[Beer]\"\n // should be \"[Product].[Beer]\"\n \"WITH MEMBER Measures.[Average Units Ordered] AS\\n\"\n + \" 'AVG(DESCENDANTS([Store].CURRENTMEMBER, [Store].[Store Name]), [Measures].[Units Ordered])'\\n\"\n + \"SELECT {[Measures].[Units ordered], Measures.[Average Units Ordered]} ON COLUMNS,\\n\"\n + \" [Product].[Drink].[Alcoholic Beverages].[Beer and Wine].[Beer].CHILDREN ON ROWS\\n\"\n + \"FROM Warehouse\\n\"\n + \"WHERE [Store].[USA].[CA]\",\n\n \"Axis #0:\\n\"\n + \"{[Store].[All Stores].[USA].[CA]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Units Ordered]}\\n\"\n + \"{[Measures].[Average Units Ordered]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages].[Beer and Wine].[Beer].[Good]}\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages].[Beer and Wine].[Beer].[Pearl]}\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages].[Beer and Wine].[Beer].[Portsmouth]}\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages].[Beer and Wine].[Beer].[Top Measure]}\\n\"\n + \"{[Product].[All Products].[Drink].[Alcoholic Beverages].[Beer and Wine].[Beer].[Walrus]}\\n\"\n + \"Row #0: \\n\"\n + \"Row #0: \\n\"\n + \"Row #1: 151.0\\n\"\n + \"Row #1: 75.5\\n\"\n + \"Row #2: 95.0\\n\"\n + \"Row #2: 95.0\\n\"\n + \"Row #3: \\n\"\n + \"Row #3: \\n\"\n + \"Row #4: 211.0\\n\"\n + \"Row #4: 105.5\\n\");\n }\n\n /**\n * How Can I Use Different Calculations for Different Dimensions?\n *\n *
Each measure in a cube uses the same aggregation function across all\n * dimensions. However, there are times where a different aggregation\n * function may be needed to represent a measure for reporting purposes. Two\n * basic cases involve aggregating a single dimension using a different\n * aggregation function than the one used for other dimensions.
\n *\n * - Aggregating minimums, maximums, or averages along a time\n * dimension
\n *\n * - Aggregating opening and closing period values along a time\n * dimension
\n *\n * The first case involves some knowledge of the behavior of the time\n * dimension specified in the cube. For instance, to create a calculated\n * measure that contains the average, along a time dimension, of measures\n * aggregated as sums along other dimensions, the average of the aggregated\n * measures must be taken over the set of averaging time periods,\n * constructed through the use of the Descendants MDX function. Minimum and\n * maximum values are more easily calculated through the use of the Min and\n * Max MDX functions, also combined with the Descendants function.\n *\n *
For example, the Warehouse cube in the FoodMart 2000 database\n * contains information on ordered and shipped inventory; from it, a report\n * is requested to show the average number of units shipped, by product, to\n * each store. Information on units shipped is added on a monthly basis, so\n * the aggregated measure [Units Shipped] is divided by the count of\n * descendants, at the Month level, of the current member in the Time\n * dimension. This calculation provides a measure representing the average\n * number of units shipped per month, as demonstrated in the following MDX\n * query.\n */\n public void _testDifferentCalculationsForDifferentDimensions() {\n assertQueryReturns(\n // todo: implement \"NONEMPTYCROSSJOIN\"\n \"WITH MEMBER [Measures].[Avg Units Shipped] AS\\n\"\n + \" '[Measures].[Units Shipped] / \\n\"\n + \" COUNT(DESCENDANTS([Time].CURRENTMEMBER, [Time].[Month], SELF))'\\n\"\n + \"SELECT {Measures.[Units Shipped], Measures.[Avg Units Shipped]} ON COLUMNS,\\n\"\n + \"NONEMPTYCROSSJOIN(Store.CA.Children, Product.MEMBERS) ON ROWS\\n\"\n + \"FROM Warehouse\",\n \"\");\n }\n\n /**\n *
The second case is easier to resolve, because MDX provides the\n * OpeningPeriod and ClosingPeriod MDX functions specifically to support\n * opening and closing period values.\n *\n *
For example, the Warehouse cube in the FoodMart 2000 database\n * contains information on ordered and shipped inventory; from it, a report\n * is requested to show on-hand inventory at the end of every month. Because\n * the inventory on hand should equal ordered inventory minus shipped\n * inventory, the ClosingPeriod MDX function can be used to create a\n * calculated measure to supply the value of inventory on hand, as\n * demonstrated in the following MDX query.\n */\n public void _testDifferentCalculationsForDifferentDimensions2() {\n assertQueryReturns(\n \"WITH MEMBER Measures.[Closing Balance] AS\\n\"\n + \" '([Measures].[Units Ordered], \\n\"\n + \" CLOSINGPERIOD([Time].[Month], [Time].CURRENTMEMBER)) -\\n\"\n + \" ([Measures].[Units Shipped], \\n\"\n + \" CLOSINGPERIOD([Time].[Month], [Time].CURRENTMEMBER))'\\n\"\n + \"SELECT {[Measures].[Closing Balance]} ON COLUMNS,\\n\"\n + \" Product.MEMBERS ON ROWS\\n\"\n + \"FROM Warehouse\",\n \"\");\n }\n\n /**\n * How Can I Use Date Ranges in MDX?\n *\n *
Date ranges are a frequently encountered problem. Business questions\n * use ranges of dates, but OLAP objects provide aggregated information in\n * date levels.\n *\n *
Using the technique described here, you can establish date ranges in\n * MDX queries at the level of granularity provided by a time dimension.\n * Date ranges cannot be established below the granularity of the dimension\n * without additional information. For example, if the lowest level of a\n * time dimension represents months, you will not be able to establish a\n * two-week date range without other information. Member properties can be\n * added to supply specific dates for members; using such member properties,\n * you can take advantage of the date and time functions provided by VBA and\n * Excel external function libraries to establish date ranges.\n *\n *
The easiest way to specify a static date range is by using the colon\n * (:) operator. This operator creates a naturally ordered set, using the\n * members specified on either side of the operator as the endpoints for the\n * ordered set. For example, to specify the first six months of 1998 from\n * the Time dimension in FoodMart 2000, the MDX syntax would resemble:\n *\n *
[Time].[1998].[1]:[Time].[1998].[6]
\n *\n * For example, the Sales cube uses a time dimension that supports Year,\n * Quarter, and Month levels. To add a six-month and nine-month total, two\n * calculated members are created in the following MDX query.\n */\n public void _testDateRange() {\n assertQueryReturns(\n // todo: implement \"AddCalculatedMembers\"\n \"WITH MEMBER [Time].[1997].[Six Month] AS\\n\"\n + \" 'SUM([Time].[1]:[Time].[6])'\\n\"\n + \"MEMBER [Time].[1997].[Nine Month] AS\\n\"\n + \" 'SUM([Time].[1]:[Time].[9])'\\n\"\n + \"SELECT AddCalculatedMembers([Time].[1997].Children) ON COLUMNS,\\n\"\n + \" [Product].Children ON ROWS\\n\"\n + \"FROM Sales\",\n \"\");\n }\n\n /**\n * How Can I Use Rolling Date Ranges in MDX?\n *\n *
There are several techniques that can be used in MDX to support\n * rolling date ranges. All of these techniques tend to fall into two\n * groups. The first group involves the use of relative hierarchical\n * functions to construct named sets or calculated members, and the second\n * group involves the use of absolute date functions from external function\n * libraries to construct named sets or calculated members. Both groups are\n * applicable in different business scenarios.\n *\n *
In the first group of techniques, typically a named set is\n * constructed which contains a number of periods from a time dimension. For\n * example, the following table illustrates a 12-month rolling period, in\n * which the figures for unit sales of the previous 12 months are shown.\n *\n *
The following MDX query accomplishes this by using a number of MDX\n * functions, including LastPeriods, Tail, Filter, Members, and Item, to\n * construct a named set containing only those members across all other\n * dimensions that share data with the time dimension at the Month level.\n * The example assumes that there is at least one measure, such as [Unit\n * Sales], with a value greater than zero in the current period. The Filter\n * function creates a set of months with unit sales greater than zero, while\n * the Tail function returns the last month in this set, the current month.\n * The LastPeriods function, finally, is then used to retrieve the last 12\n * periods at this level, including the current period.\n */\n public void _testRolling() {\n assertQueryReturns(\n \"WITH SET Rolling12 AS\\n\"\n + \" 'LASTPERIODS(12, TAIL(FILTER([Time].[Month].MEMBERS, \\n\"\n + \" ([Customers].[All Customers], \\n\"\n + \" [Education Level].[All Education Level],\\n\"\n + \" [Gender].[All Gender],\\n\"\n + \" [Marital Status].[All Marital Status],\\n\"\n + \" [Product].[All Products], \\n\"\n + \" [Promotion Media].[All Media],\\n\"\n + \" [Promotions].[All Promotions],\\n\"\n + \" [Store].[All Stores],\\n\"\n + \" [Store Size in SQFT].[All Store Size in SQFT],\\n\"\n + \" [Store Type].[All Store Type],\\n\"\n + \" [Yearly Income].[All Yearly Income],\\n\"\n + \" Measures.[Unit Sales]) >0),\\n\"\n + \" 1).ITEM(0).ITEM(0))'\\n\"\n + \"SELECT {[Measures].[Unit Sales]} ON COLUMNS, \\n\"\n + \" Rolling12 ON ROWS\\n\"\n + \"FROM Sales\",\n \"\");\n }\n\n /**\n * How Can I Use Different Calculations for Different Time Periods?\n *\n *
A few techniques can be used, depending on the structure of the cube\n * being queried, to support different calculations for members depending\n * on the time period. The following example includes the MDX IIf function,\n * and is easy to use but difficult to maintain. This example works well for\n * ad hoc queries, but is not the ideal technique for client applications in\n * a production environment.\n *\n *
For example, the following table illustrates a standard and dynamic\n * forecast of warehouse sales, from the Warehouse cube in the FoodMart 2000\n * database, for drink products. The standard forecast is double the\n * warehouse sales of the previous year, while the dynamic forecast varies\n * from month to month -- the forecast for January is 120 percent of\n * previous sales, while the forecast for July is 260 percent of previous\n * sales.\n *\n *
The most flexible way of handling this type of report is the use of\n * nested MDX IIf functions to return a multiplier to be used on the members\n * of the Products dimension, at the Drinks level. The following MDX query\n * demonstrates this technique.\n */\n public void testDifferentCalcsForDifferentTimePeriods() {\n assertQueryReturns(\n // note: \"[Product].[Drink Forecast - Standard]\"\n // was \"[Drink Forecast - Standard]\"\n \"WITH MEMBER [Product].[Drink Forecast - Standard] AS\\n\"\n + \" '[Product].[All Products].[Drink] * 2'\\n\"\n + \"MEMBER [Product].[Drink Forecast - Dynamic] AS \\n\"\n + \" '[Product].[All Products].[Drink] * \\n\"\n + \" IIF([Time].[Time].CurrentMember.Name = \\\"1\\\", 1.2,\\n\"\n + \" IIF([Time].[Time].CurrentMember.Name = \\\"2\\\", 1.3,\\n\"\n + \" IIF([Time].[Time].CurrentMember.Name = \\\"3\\\", 1.4,\\n\"\n + \" IIF([Time].[Time].CurrentMember.Name = \\\"4\\\", 1.6,\\n\"\n + \" IIF([Time].[Time].CurrentMember.Name = \\\"5\\\", 2.1,\\n\"\n + \" IIF([Time].[Time].CurrentMember.Name = \\\"6\\\", 2.4,\\n\"\n + \" IIF([Time].[Time].CurrentMember.Name = \\\"7\\\", 2.6,\\n\"\n + \" IIF([Time].[Time].CurrentMember.Name = \\\"8\\\", 2.3,\\n\"\n + \" IIF([Time].[Time].CurrentMember.Name = \\\"9\\\", 1.9,\\n\"\n + \" IIF([Time].[Time].CurrentMember.Name = \\\"10\\\", 1.5,\\n\"\n + \" IIF([Time].[Time].CurrentMember.Name = \\\"11\\\", 1.4,\\n\"\n + \" IIF([Time].[Time].CurrentMember.Name = \\\"12\\\", 1.2, 1.0))))))))))))'\\n\"\n + \"SELECT DESCENDANTS(Time.[1997], [Month], SELF) ON COLUMNS, \\n\"\n + \" {[Product].CHILDREN, [Product].[Drink Forecast - Standard], [Product].[Drink Forecast - Dynamic]} ON ROWS\\n\"\n + \"FROM Warehouse\",\n\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Time].[1997].[Q1].[1]}\\n\"\n + \"{[Time].[1997].[Q1].[2]}\\n\"\n + \"{[Time].[1997].[Q1].[3]}\\n\"\n + \"{[Time].[1997].[Q2].[4]}\\n\"\n + \"{[Time].[1997].[Q2].[5]}\\n\"\n + \"{[Time].[1997].[Q2].[6]}\\n\"\n + \"{[Time].[1997].[Q3].[7]}\\n\"\n + \"{[Time].[1997].[Q3].[8]}\\n\"\n + \"{[Time].[1997].[Q3].[9]}\\n\"\n + \"{[Time].[1997].[Q4].[10]}\\n\"\n + \"{[Time].[1997].[Q4].[11]}\\n\"\n + \"{[Time].[1997].[Q4].[12]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Product].[All Products].[Drink]}\\n\"\n + \"{[Product].[All Products].[Food]}\\n\"\n + \"{[Product].[All Products].[Non-Consumable]}\\n\"\n + \"{[Product].[Drink Forecast - Standard]}\\n\"\n + \"{[Product].[Drink Forecast - Dynamic]}\\n\"\n + \"Row #0: 881.847\\n\"\n + \"Row #0: 579.051\\n\"\n + \"Row #0: 476.292\\n\"\n + \"Row #0: 618.722\\n\"\n + \"Row #0: 778.886\\n\"\n + \"Row #0: 636.935\\n\"\n + \"Row #0: 937.842\\n\"\n + \"Row #0: 767.332\\n\"\n + \"Row #0: 920.707\\n\"\n + \"Row #0: 1,007.764\\n\"\n + \"Row #0: 820.808\\n\"\n + \"Row #0: 792.167\\n\"\n + \"Row #1: 8,383.446\\n\"\n + \"Row #1: 4,851.406\\n\"\n + \"Row #1: 5,353.188\\n\"\n + \"Row #1: 6,061.829\\n\"\n + \"Row #1: 6,039.282\\n\"\n + \"Row #1: 5,259.242\\n\"\n + \"Row #1: 6,902.01\\n\"\n + \"Row #1: 5,790.772\\n\"\n + \"Row #1: 8,167.053\\n\"\n + \"Row #1: 6,188.732\\n\"\n + \"Row #1: 5,344.845\\n\"\n + \"Row #1: 5,025.744\\n\"\n + \"Row #2: 2,040.396\\n\"\n + \"Row #2: 1,269.816\\n\"\n + \"Row #2: 1,460.686\\n\"\n + \"Row #2: 1,696.757\\n\"\n + \"Row #2: 1,397.035\\n\"\n + \"Row #2: 1,578.136\\n\"\n + \"Row #2: 1,671.046\\n\"\n + \"Row #2: 1,609.447\\n\"\n + \"Row #2: 2,059.617\\n\"\n + \"Row #2: 1,617.493\\n\"\n + \"Row #2: 1,909.713\\n\"\n + \"Row #2: 1,382.364\\n\"\n + \"Row #3: 1,763.693\\n\"\n + \"Row #3: 1,158.102\\n\"\n + \"Row #3: 952.584\\n\"\n + \"Row #3: 1,237.444\\n\"\n + \"Row #3: 1,557.773\\n\"\n + \"Row #3: 1,273.87\\n\"\n + \"Row #3: 1,875.685\\n\"\n + \"Row #3: 1,534.665\\n\"\n + \"Row #3: 1,841.414\\n\"\n + \"Row #3: 2,015.528\\n\"\n + \"Row #3: 1,641.615\\n\"\n + \"Row #3: 1,584.334\\n\"\n + \"Row #4: 1,058.216\\n\"\n + \"Row #4: 752.766\\n\"\n + \"Row #4: 666.809\\n\"\n + \"Row #4: 989.955\\n\"\n + \"Row #4: 1,635.661\\n\"\n + \"Row #4: 1,528.644\\n\"\n + \"Row #4: 2,438.39\\n\"\n + \"Row #4: 1,764.865\\n\"\n + \"Row #4: 1,749.343\\n\"\n + \"Row #4: 1,511.646\\n\"\n + \"Row #4: 1,149.13\\n\"\n + \"Row #4: 950.601\\n\");\n }\n\n /**\n *
Other techniques, such as the addition of member properties to the\n * Time or Product dimensions to support such calculations, are not as\n * flexible but are much more efficient. The primary drawback to using such\n * techniques is that the calculations are not easily altered for\n * speculative analysis purposes. For client applications, however, where\n * the calculations are static or slowly changing, using a member property\n * is an excellent way of supplying such functionality to clients while\n * keeping maintenance of calculation variables at the server level. The\n * same MDX query, for example, could be rewritten to use a member property\n * named [Dynamic Forecast Multiplier] as shown in the following MDX query.\n */\n public void _testDc4dtp2() {\n assertQueryReturns(\n \"WITH MEMBER [Product].[Drink Forecast - Standard] AS\\n\"\n + \" '[Product].[All Products].[Drink] * 2'\\n\"\n + \"MEMBER [Product].[Drink Forecast - Dynamic] AS \\n\"\n + \" '[Product].[All Products].[Drink] * \\n\"\n + \" [Time].CURRENTMEMBER.PROPERTIES(\\\"Dynamic Forecast Multiplier\\\")'\\n\"\n + \"SELECT DESCENDANTS(Time.[1997], [Month], SELF) ON COLUMNS, \\n\"\n + \" {[Product].CHILDREN, [Drink Forecast - Standard], [Drink Forecast - Dynamic]} ON ROWS\\n\"\n + \"FROM Warehouse\",\n \"\");\n }\n\n public void _testWarehouseProfit() {\n assertQueryReturns(\n \"select \\n\"\n + \"{[Measures].[Warehouse Cost], [Measures].[Warehouse Sales], [Measures].[Warehouse Profit]}\\n\"\n + \" ON COLUMNS from [Warehouse]\",\n \"\");\n }\n\n /**\n * How Can I Compare Time Periods in MDX?\n *\n *
To answer such a common business question, MDX provides a number of\n * functions specifically designed to navigate and aggregate information\n * across time periods. For example, year-to-date (YTD) totals are directly\n * supported through the YTD function in MDX. In combination with the MDX\n * ParallelPeriod function, you can create calculated members to support\n * direct comparison of totals across time periods.\n *\n *
For example, the following table represents a comparison of YTD unit\n * sales between 1997 and 1998, run against the Sales cube in the FoodMart\n * 2000 database.\n *\n *
The following MDX query uses three calculated members to illustrate\n * how to use the YTD and ParallelPeriod functions in combination to compare\n * time periods.\n */\n public void _testYtdGrowth() {\n assertQueryReturns(\n // todo: implement \"ParallelPeriod\"\n \"WITH MEMBER [Measures].[YTD Unit Sales] AS\\n\"\n + \" 'COALESCEEMPTY(SUM(YTD(), [Measures].[Unit Sales]), 0)'\\n\"\n + \"MEMBER [Measures].[Previous YTD Unit Sales] AS\\n\"\n + \" '(Measures.[YTD Unit Sales], PARALLELPERIOD([Time].[Year]))'\\n\"\n + \"MEMBER [Measures].[YTD Growth] AS\\n\"\n + \" '[Measures].[YTD Unit Sales] - ([Measures].[Previous YTD Unit Sales])'\\n\"\n + \"SELECT {[Time].[1998]} ON COLUMNS,\\n\"\n + \" {[Measures].[YTD Unit Sales], [Measures].[Previous YTD Unit Sales], [Measures].[YTD Growth]} ON ROWS\\n\"\n + \"FROM Sales \", \"\");\n }\n\n\n /*\n * takes quite long\n */\n public void dont_testParallelMutliple() {\n for (int i = 0; i < 5; i++) {\n runParallelQueries(1, 1, false);\n runParallelQueries(3, 2, false);\n runParallelQueries(4, 6, true);\n runParallelQueries(6, 10, false);\n }\n }\n\n public void dont_testParallelNot() {\n runParallelQueries(1, 1, false);\n }\n\n public void dont_testParallelSomewhat() {\n runParallelQueries(3, 2, false);\n }\n\n public void dont_testParallelFlushCache() {\n runParallelQueries(4, 6, true);\n }\n\n public void dont_testParallelVery() {\n runParallelQueries(6, 10, false);\n }\n\n private void runParallelQueries(\n final int threadCount,\n final int iterationCount,\n final boolean flush)\n {\n // 10 minute per query\n long timeoutMs = (long) threadCount * iterationCount * 600 * 1000;\n final int[] executeCount = new int[] {0};\n final List queries = new ArrayList();\n queries.addAll(Arrays.asList(sampleQueries));\n queries.addAll(taglibQueries);\n TestCaseForker threaded =\n new TestCaseForker(\n this, timeoutMs, threadCount,\n new ChooseRunnable() {\n public void run(int i) {\n for (int j = 0; j < iterationCount; j++) {\n int queryIndex = (i * 2 + j) % queries.size();\n try {\n QueryAndResult query = queries.get(queryIndex);\n assertQueryReturns(query.query, query.result);\n if (flush && i == 0) {\n getConnection().getCacheControl(null)\n .flushSchemaCache();\n }\n synchronized (executeCount) {\n executeCount[0]++;\n }\n } catch (Throwable e) {\n e.printStackTrace();\n throw Util.newInternal(\n e,\n \"Thread #\"\n + i\n + \" failed while executing query #\"\n + queryIndex);\n }\n }\n }\n });\n threaded.run();\n assertEquals(\n \"number of executions\",\n threadCount * iterationCount,\n executeCount[0]);\n }\n\n /**\n * Makes sure that the expression \n *\n * [Measures].[Unit Sales] / ([Measures].[Unit Sales], [Product].[All\n * Products])\n *\n *
depends on the current member of the Product dimension, although\n * [Product].[All Products] is referenced from the expression.\n */\n public void testDependsOn() {\n assertQueryReturns(\n \"with member [Customers].[my] as \\n\"\n + \" 'Aggregate(Filter([Customers].[City].Members, (([Measures].[Unit Sales] / ([Measures].[Unit Sales], [Product].[All Products])) > 0.1)))' \\n\"\n + \"select \\n\"\n + \" {[Measures].[Unit Sales]} ON columns, \\n\"\n + \" {[Product].[All Products].[Food].[Deli], [Product].[All Products].[Food].[Frozen Foods]} ON rows \\n\"\n + \"from [Sales] \\n\"\n + \"where ([Customers].[my], [Time].[1997])\\n\",\n\n \"Axis #0:\\n\"\n + \"{[Customers].[my], [Time].[1997]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Product].[All Products].[Food].[Deli]}\\n\"\n + \"{[Product].[All Products].[Food].[Frozen Foods]}\\n\"\n + \"Row #0: 13\\n\"\n + \"Row #1: 15,111\\n\");\n }\n\n /**\n * Testcase for bug 1755778, \"CrossJoin / Filter query returns null row in\n * result set\"\n *\n * @throws Exception on error\n */\n public void testFilterWithCrossJoin() throws Exception {\n String queryWithFilter =\n \"WITH SET [#DataSet#] AS 'Filter(Crossjoin({[Store].[All Stores]}, {[Customers].[All Customers]}), \"\n + \"[Measures].[Unit Sales] > 5)' \"\n + \"MEMBER [Customers].[#GT#] as 'Aggregate({[#DataSet#]})' \"\n + \"MEMBER [Store].[#GT#] as 'Aggregate({[#DataSet#]})' \"\n + \"SET [#GrandTotalSet#] as 'Crossjoin({[Store].[#GT#]}, {[Customers].[#GT#]})' \"\n + \"SELECT {[Measures].[Unit Sales]} \"\n + \"on columns, Union([#GrandTotalSet#], Hierarchize({[#DataSet#]})) on rows FROM [Sales]\";\n\n String queryWithoutFilter =\n \"WITH SET [#DataSet#] AS 'Crossjoin({[Store].[All Stores]}, {[Customers].[All Customers]})' \"\n + \"SET [#GrandTotalSet#] as 'Crossjoin({[Store].[All Stores]}, {[Customers].[All Customers]})' \"\n + \"SELECT {[Measures].[Unit Sales]} on columns, Union([#GrandTotalSet#], Hierarchize({[#DataSet#]})) \"\n + \"on rows FROM [Sales]\";\n\n\n String wrongResultWithFilter =\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Store].[#GT#], [Customers].[#GT#]}\\n\"\n + \"Row #0: \\n\";\n\n String expectedResultWithFilter =\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Store].[#GT#], [Customers].[#GT#]}\\n\"\n + \"{[Store].[All Stores], [Customers].[All Customers]}\\n\"\n + \"Row #0: 266,773\\n\"\n + \"Row #1: 266,773\\n\";\n\n String expectedResultWithoutFilter =\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Store].[All Stores], [Customers].[All Customers]}\\n\"\n + \"Row #0: 266,773\\n\";\n\n // With bug 1755778, the following test below fails because it returns\n // only row that have a null value (see \"wrongResultWithFilter\").\n // It should return the \"expectedResultWithFilter\" value.\n assertQueryReturns(queryWithFilter, expectedResultWithFilter);\n\n // To see the test case return the correct result comment out the line\n // above and uncomment out the lines below following. If a similar\n // query without the filter is executed (queryWithoutFilter) prior to\n // running the query with the filter then the correct result set is\n // returned\n assertQueryReturns(\n queryWithoutFilter, expectedResultWithoutFilter);\n assertQueryReturns(\n queryWithFilter, expectedResultWithFilter);\n }\n\n /**\n * This resulted in {@link OutOfMemoryError} when the\n * BatchingCellReader did not know the values for the tuples that\n * were used in filters.\n */\n public void testFilteredCrossJoin() {\n getConnection().getCacheControl(null).flushSchemaCache();\n Result result = executeQuery(\n \"select {[Measures].[Store Sales]} on columns,\\n\"\n + \" NON EMPTY Crossjoin(\\n\"\n + \" Filter([Customers].[Name].Members,\\n\"\n + \" (([Measures].[Store Sales],\\n\"\n + \" [Store].[All Stores].[USA].[CA].[San Francisco].[Store 14],\\n\"\n + \" [Time].[1997].[Q1].[1]) > 5.0)),\\n\"\n + \" Filter([Product].[Product Name].Members,\\n\"\n + \" (([Measures].[Store Sales],\\n\"\n + \" [Store].[All Stores].[USA].[CA].[San Francisco].[Store 14],\\n\"\n + \" [Time].[1997].[Q1].[1]) > 5.0))\\n\"\n + \" ) ON rows\\n\"\n + \"from [Sales]\\n\"\n + \"where (\\n\"\n + \" [Store].[All Stores].[USA].[CA].[San Francisco].[Store 14],\\n\"\n + \" [Time].[1997].[Q1].[1]\\n\"\n + \")\\n\");\n // ok if no OutOfMemoryError occurs\n Axis a = result.getAxes()[1];\n assertEquals(12, a.getPositions().size());\n }\n\n /**\n * Tests a query with a CrossJoin so large that we run out of memory unless\n * we can push down evaluation to SQL.\n */\n public void testNonEmptyCrossJoin() {\n if (!props.EnableNativeCrossJoin.get()) {\n // If we try to evaluate the crossjoin in memory we run out of\n // memory.\n return;\n }\n getConnection().getCacheControl(null).flushSchemaCache();\n Result result = executeQuery(\n \"select {[Measures].[Store Sales]} on columns,\\n\"\n + \" NON EMPTY Crossjoin(\\n\"\n + \" [Customers].[Name].Members,\\n\"\n + \" [Product].[Product Name].Members\\n\"\n + \" ) ON rows\\n\"\n + \"from [Sales]\\n\"\n + \"where (\\n\"\n + \" [Store].[All Stores].[USA].[CA].[San Francisco].[Store 14],\\n\"\n + \" [Time].[1997].[Q1].[1]\\n\"\n + \")\\n\");\n // ok if no OutOfMemoryError occurs\n Axis a = result.getAxes()[1];\n assertEquals(67, a.getPositions().size());\n }\n\n /**\n * NonEmptyCrossJoin() is not the same as NON EMPTY CrossJoin()\n * because it's evaluated independently of the other axes.\n * (see http://blogs.msdn.com/bi_systems/articles/162841.aspx)\n */\n public void testNonEmptyNonEmptyCrossJoin1() {\n getConnection().getCacheControl(null).flushSchemaCache();\n Result result = executeQuery(\n \"select {[Education Level].[All Education Levels].[Graduate Degree]} on columns,\\n\"\n + \" CrossJoin(\\n\"\n + \" {[Store Type].[Store Type].members},\\n\"\n + \" {[Promotions].[Promotion Name].members})\\n\"\n + \" on rows\\n\"\n + \"from Sales\\n\"\n + \"where ([Customers].[All Customers].[USA].[WA].[Anacortes])\\n\");\n Axis a = result.getAxes()[1];\n assertEquals(306, a.getPositions().size());\n }\n\n public void testNonEmptyNonEmptyCrossJoin2() {\n getConnection().getCacheControl(null).flushSchemaCache();\n Result result = executeQuery(\n \"select {[Education Level].[All Education Levels].[Graduate Degree]} on columns,\\n\"\n + \" NonEmptyCrossJoin(\\n\"\n + \" {[Store Type].[Store Type].members},\\n\"\n + \" {[Promotions].[Promotion Name].members})\\n\"\n + \" on rows\\n\"\n + \"from Sales\\n\"\n + \"where ([Customers].[All Customers].[USA].[WA].[Anacortes])\\n\");\n Axis a = result.getAxes()[1];\n assertEquals(10, a.getPositions().size());\n }\n\n public void testNonEmptyNonEmptyCrossJoin3() {\n getConnection().getCacheControl(null).flushSchemaCache();\n Result result = executeQuery(\n \"select {[Education Level].[All Education Levels].[Graduate Degree]} on columns,\\n\"\n + \" Non Empty CrossJoin(\\n\"\n + \" {[Store Type].[Store Type].members},\\n\"\n + \" {[Promotions].[Promotion Name].members})\\n\"\n + \" on rows\\n\"\n + \"from Sales\\n\"\n + \"where ([Customers].[All Customers].[USA].[WA].[Anacortes])\\n\");\n Axis a = result.getAxes()[1];\n assertEquals(1, a.getPositions().size());\n }\n\n public void testNonEmptyNonEmptyCrossJoin4() {\n getConnection().getCacheControl(null).flushSchemaCache();\n Result result = executeQuery(\n \"select {[Education Level].[All Education Levels].[Graduate Degree]} on columns,\\n\"\n + \" Non Empty NonEmptyCrossJoin(\\n\"\n + \" {[Store Type].[Store Type].members},\\n\"\n + \" {[Promotions].[Promotion Name].members})\\n\"\n + \" on rows\\n\"\n + \"from Sales\\n\"\n + \"where ([Customers].[All Customers].[USA].[WA].[Anacortes])\\n\");\n Axis a = result.getAxes()[1];\n assertEquals(1, a.getPositions().size());\n }\n\n /**\n * description of this testcase:\n * A calculated member is created on the time.month level.\n * On Hierarchize this member is compared to a month.\n * The month has a numeric key, while the calculated members\n * key type is string.\n * No exeception must be thrown.\n */\n public void testHierDifferentKeyClass() {\n Result result = executeQuery(\n \"with member [Time].[1997].[Q1].[xxx] as\\n\"\n + \"'Aggregate({[Time].[1997].[Q1].[1], [Time].[1997].[Q1].[2]})'\\n\"\n + \"select {[Measures].[Unit Sales], [Measures].[Store Cost],\\n\"\n + \"[Measures].[Store Sales]} ON columns,\\n\"\n + \"Hierarchize(Union(Union({[Time].[1997], [Time].[1998],\\n\"\n + \"[Time].[1997].[Q1].[xxx]}, [Time].[1997].Children),\\n\"\n + \"[Time].[1997].[Q1].Children)) ON rows from [Sales]\");\n Axis a = result.getAxes()[1];\n assertEquals(10, a.getPositions().size());\n }\n\n\n /**\n * Bug #1005995 - many totals of various dimensions\n */\n public void testOverlappingCalculatedMembers() {\n assertQueryReturns(\n \"WITH MEMBER [Store].[Total] AS 'SUM([Store].[Store Country].MEMBERS)' \"\n + \"MEMBER [Store Type].[Total] AS 'SUM([Store Type].[Store Type].MEMBERS)' \"\n + \"MEMBER [Gender].[Total] AS 'SUM([Gender].[Gender].MEMBERS)' \"\n + \"MEMBER [Measures].[x] AS '[Measures].[Store Sales]' \"\n + \"SELECT {[Measures].[x]} ON COLUMNS , \"\n + \"{ ([Store].[Total], [Store Type].[Total], [Gender].[Total]) } ON ROWS \"\n + \"FROM Sales\",\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[x]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Store].[Total], [Store Type].[Total], [Gender].[Total]}\\n\"\n + \"Row #0: 565,238.13\\n\");\n }\n\n /**\n * the following query raised a classcast exception because\n * an empty property evaluated as \"NullMember\"\n * note: Store \"HQ\" does not have a \"Store Manager\"\n */\n public void testEmptyProperty() {\n assertQueryReturns(\n \"select {[Measures].[Unit Sales]} on columns, \"\n + \"filter([Store].[Store Name].members,\"\n + \"[Store].currentmember.properties(\\\"Store Manager\\\")=\\\"Smith\\\") on rows\"\n + \" from Sales\",\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Store].[All Stores].[USA].[WA].[Bellingham].[Store 2]}\\n\"\n + \"Row #0: 2,237\\n\");\n }\n\n /**\n * This test modifies the Sales cube to contain both the regular usage\n * of the [Store] shared dimension, and another usage called [Other Store]\n * which is connected to the [Unit Sales] column\n */\n public void _testCubeWhichUsesSameSharedDimTwice() {\n // Create a second usage of the \"Store\" shared dimension called \"Other\n // Store\". Attach it to the \"unit_sales\" column (which has values [1,\n // 6] whereas store has values [1, 24].\n TestContext testContext = TestContext.createSubstitutingCube(\n \"Sales\",\n \"\");\n Axis axis = testContext.executeAxis(\"[Other Store].members\");\n assertEquals(63, axis.getPositions().size());\n\n axis = testContext.executeAxis(\"[Store].members\");\n assertEquals(63, axis.getPositions().size());\n\n final String q1 =\n \"select {[Measures].[Unit Sales]} on columns,\\n\"\n + \" NON EMPTY {[Other Store].members} on rows\\n\"\n + \"from [Sales]\";\n testContext.assertQueryReturns(\n q1,\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Other Store].[All Other Stores]}\\n\"\n + \"{[Other Store].[All Other Stores].[Mexico]}\\n\"\n + \"{[Other Store].[All Other Stores].[USA]}\\n\"\n + \"{[Other Store].[All Other Stores].[Mexico].[Guerrero]}\\n\"\n + \"{[Other Store].[All Other Stores].[Mexico].[Jalisco]}\\n\"\n + \"{[Other Store].[All Other Stores].[Mexico].[Zacatecas]}\\n\"\n + \"{[Other Store].[All Other Stores].[USA].[CA]}\\n\"\n + \"{[Other Store].[All Other Stores].[USA].[WA]}\\n\"\n + \"{[Other Store].[All Other Stores].[Mexico].[Guerrero].[Acapulco]}\\n\"\n + \"{[Other Store].[All Other Stores].[Mexico].[Jalisco].[Guadalajara]}\\n\"\n + \"{[Other Store].[All Other Stores].[Mexico].[Zacatecas].[Camacho]}\\n\"\n + \"{[Other Store].[All Other Stores].[USA].[CA].[Beverly Hills]}\\n\"\n + \"{[Other Store].[All Other Stores].[USA].[WA].[Bellingham]}\\n\"\n + \"{[Other Store].[All Other Stores].[USA].[WA].[Bremerton]}\\n\"\n + \"{[Other Store].[All Other Stores].[Mexico].[Guerrero].[Acapulco].[Store 1]}\\n\"\n + \"{[Other Store].[All Other Stores].[Mexico].[Jalisco].[Guadalajara].[Store 5]}\\n\"\n + \"{[Other Store].[All Other Stores].[Mexico].[Zacatecas].[Camacho].[Store 4]}\\n\"\n + \"{[Other Store].[All Other Stores].[USA].[CA].[Beverly Hills].[Store 6]}\\n\"\n + \"{[Other Store].[All Other Stores].[USA].[WA].[Bellingham].[Store 2]}\\n\"\n + \"{[Other Store].[All Other Stores].[USA].[WA].[Bremerton].[Store 3]}\\n\"\n + \"Row #0: 266,773\\n\"\n + \"Row #1: 110,822\\n\"\n + \"Row #2: 155,951\\n\"\n + \"Row #3: 1,827\\n\"\n + \"Row #4: 14,915\\n\"\n + \"Row #5: 94,080\\n\"\n + \"Row #6: 222\\n\"\n + \"Row #7: 155,729\\n\"\n + \"Row #8: 1,827\\n\"\n + \"Row #9: 14,915\\n\"\n + \"Row #10: 94,080\\n\"\n + \"Row #11: 222\\n\"\n + \"Row #12: 39,362\\n\"\n + \"Row #13: 116,367\\n\"\n + \"Row #14: 1,827\\n\"\n + \"Row #15: 14,915\\n\"\n + \"Row #16: 94,080\\n\"\n + \"Row #17: 222\\n\"\n + \"Row #18: 39,362\\n\"\n + \"Row #19: 116,367\\n\");\n\n final String q2 =\n \"select {[Measures].[Unit Sales]} on columns,\\n\"\n + \" CrossJoin(\\n\"\n + \" {[Store].[USA], [Store].[USA].[CA], [Store].[USA].[OR].[Portland]}, \\n\"\n + \" {[Other Store].[USA], [Other Store].[USA].[CA], [Other Store].[USA].[OR].[Portland]}) on rows\\n\"\n + \"from [Sales]\";\n testContext.assertQueryReturns(\n q2,\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Unit Sales]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Store].[All Stores].[USA], [Other Store].[All Other Stores].[USA]}\\n\"\n + \"{[Store].[All Stores].[USA], [Other Store].[All Other Stores].[USA].[CA]}\\n\"\n + \"{[Store].[All Stores].[USA], [Other Store].[All Other Stores].[USA].[OR].[Portland]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA], [Other Store].[All Other Stores].[USA]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA], [Other Store].[All Other Stores].[USA].[CA]}\\n\"\n + \"{[Store].[All Stores].[USA].[CA], [Other Store].[All Other Stores].[USA].[OR].[Portland]}\\n\"\n + \"{[Store].[All Stores].[USA].[OR].[Portland], [Other Store].[All Other Stores].[USA]}\\n\"\n + \"{[Store].[All Stores].[USA].[OR].[Portland], [Other Store].[All Other Stores].[USA].[CA]}\\n\"\n + \"{[Store].[All Stores].[USA].[OR].[Portland], [Other Store].[All Other Stores].[USA].[OR].[Portland]}\\n\"\n + \"Row #0: 155,951\\n\"\n + \"Row #1: 222\\n\"\n + \"Row #2: \\n\"\n + \"Row #3: 43,730\\n\"\n + \"Row #4: 66\\n\"\n + \"Row #5: \\n\"\n + \"Row #6: 15,134\\n\"\n + \"Row #7: 24\\n\"\n + \"Row #8: \\n\");\n\n Result result = executeQuery(q2);\n final Cell cell = result.getCell(new int[] {0, 0});\n String sql = cell.getDrillThroughSQL(false);\n // the following replacement is for databases in ANSI mode\n // using '\"' to quote identifiers\n sql = sql.replace('\"', '`');\n\n String tableQualifier = \"as \";\n final Dialect dialect = getTestContext().getDialect();\n if (dialect.getDatabaseProduct() == Dialect.DatabaseProduct.ORACLE) {\n // \" + tableQualifier + \"\n tableQualifier = \"\";\n }\n assertEquals(\n \"select `store`.`store_country` as `Store Country`,\"\n + \" `time_by_day`.`the_year` as `Year`,\"\n + \" `store_1`.`store_country` as `x0`,\"\n + \" `sales_fact_1997`.`unit_sales` as `Unit Sales` \"\n + \"from `store` \" + tableQualifier + \"`store`,\"\n + \" `sales_fact_1997` \" + tableQualifier + \"`sales_fact_1997`,\"\n + \" `time_by_day` \" + tableQualifier + \"`time_by_day`,\"\n + \" `store` \" + tableQualifier + \"`store_1` \"\n + \"where `sales_fact_1997`.`store_id` = `store`.`store_id`\"\n + \" and `store`.`store_country` = 'USA'\"\n + \" and `sales_fact_1997`.`time_id` = `time_by_day`.`time_id`\"\n + \" and `time_by_day`.`the_year` = 1997\"\n + \" and `sales_fact_1997`.`unit_sales` = `store_1`.`store_id`\"\n + \" and `store_1`.`store_country` = 'USA'\",\n sql);\n }\n\n public void testMemberVisibility() {\n String cubeName = \"Sales_MemberVis\";\n TestContext testContext = TestContext.create(\n null,\n \"\\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \"\", null, null, null, null);\n SchemaReader scr = testContext.getConnection().getSchema().lookupCube(\n cubeName, true).getSchemaReader(null);\n Member member = scr.getMemberByUniqueName(\n Id.Segment.toList(\n \"Measures\", \"Unit Sales\"), true);\n Object visible = member.getPropertyValue(Property.VISIBLE.name);\n assertEquals(Boolean.FALSE, visible);\n\n member = scr.getMemberByUniqueName(\n Id.Segment.toList(\n \"Measures\", \"Store Cost\"), true);\n visible = member.getPropertyValue(Property.VISIBLE.name);\n assertEquals(Boolean.TRUE, visible);\n\n member = scr.getMemberByUniqueName(\n Id.Segment.toList(\n \"Measures\", \"Profit\"), true);\n visible = member.getPropertyValue(Property.VISIBLE.name);\n assertEquals(Boolean.FALSE, visible);\n }\n\n public void testAllMemberCaption() {\n TestContext testContext = TestContext.createSubstitutingCube(\n \"Sales\",\n \"\\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \"\");\n String mdx = \"select {[Gender3].[All Gender]} on columns from Sales\";\n Result result = testContext.executeQuery(mdx);\n Axis axis0 = result.getAxes()[0];\n Position pos0 = axis0.getPositions().get(0);\n Member allGender = pos0.get(0);\n String caption = allGender.getCaption();\n Assert.assertEquals(caption, \"Frauen und Maenner\");\n }\n\n public void testAllLevelName() {\n TestContext testContext = TestContext.createSubstitutingCube(\n \"Sales\",\n \"\\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \"\");\n String mdx = \"select {[Gender4].[All Gender]} on columns from Sales\";\n Result result = testContext.executeQuery(mdx);\n Axis axis0 = result.getAxes()[0];\n Position pos0 = axis0.getPositions().get(0);\n Member allGender = pos0.get(0);\n String caption = allGender.getLevel().getName();\n Assert.assertEquals(caption, \"GenderLevel\");\n }\n\n /**\n * Bug 1250080 caused a dimension with no 'all' member to be constrained\n * twice.\n */\n public void testDimWithoutAll() {\n // Create a test context with a new \"\"Sales_DimWithoutAll\" cube, and\n // which evaluates expressions against that cube.\n TestContext testContext = new TestContext() {\n public Util.PropertyList getFoodMartConnectionProperties() {\n final String schema = getFoodMartSchema(\n null,\n \"\\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \"\n + \" \\n\"\n + \" \\n\"\n + \"\",\n null,\n null,\n null,\n null);\n Util.PropertyList properties =\n super.getFoodMartConnectionProperties();\n properties.put(\n RolapConnectionProperties.CatalogContent.name(), schema);\n return properties;\n }\n\n public String getDefaultCubeName() {\n return \"Sales_DimWithoutAll\";\n }\n };\n // the default member of the Gender dimension is the first member\n testContext.assertExprReturns(\"[Gender].CurrentMember.Name\", \"F\");\n testContext.assertExprReturns(\"[Product].CurrentMember.Name\", \"Drink\");\n // There is no all member.\n testContext.assertExprThrows(\n \"([Gender].[All Gender], [Measures].[Unit Sales])\",\n \"MDX object '[Gender].[All Gender]' not found in cube 'Sales_DimWithoutAll'\");\n testContext.assertExprThrows(\n \"([Gender].[All Genders], [Measures].[Unit Sales])\",\n \"MDX object '[Gender].[All Genders]' not found in cube 'Sales_DimWithoutAll'\");\n // evaluated in the default context: [Product].[Drink], [Gender].[F]\n testContext.assertExprReturns(\"[Measures].[Unit Sales]\", \"12,202\");\n // evaluated in the same context: [Product].[Drink], [Gender].[F]\n testContext.assertExprReturns(\n \"([Gender].[F], [Measures].[Unit Sales])\", \"12,202\");\n // evaluated at in the context: [Product].[Drink], [Gender].[M]\n testContext.assertExprReturns(\n \"([Gender].[M], [Measures].[Unit Sales])\", \"12,395\");\n // evaluated in the context:\n // [Product].[Food].[Canned Foods], [Gender].[F]\n testContext.assertExprReturns(\n \"([Product].[Food].[Canned Foods], [Measures].[Unit Sales])\",\n \"9,407\");\n testContext.assertExprReturns(\n \"([Product].[Food].[Dairy], [Measures].[Unit Sales])\", \"6,513\");\n testContext.assertExprReturns(\n \"([Product].[Drink].[Dairy], [Measures].[Unit Sales])\", \"1,987\");\n }\n\n /**\n * If an axis expression is a member, implicitly convert it to a set.\n */\n public void testMemberOnAxis() {\n assertQueryReturns(\n \"select [Measures].[Sales Count] on 0, non empty [Store].[Store State].members on 1 from [Sales]\",\n \"Axis #0:\\n\"\n + \"{}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Sales Count]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Store].[All Stores].[USA].[CA]}\\n\"\n + \"{[Store].[All Stores].[USA].[OR]}\\n\"\n + \"{[Store].[All Stores].[USA].[WA]}\\n\"\n + \"Row #0: 24,442\\n\"\n + \"Row #1: 21,611\\n\"\n + \"Row #2: 40,784\\n\");\n }\n\n public void testScalarOnAxisFails() {\n assertQueryThrows(\n \"select [Measures].[Sales Count] + 1 on 0, non empty [Store].[Store State].members on 1 from [Sales]\",\n \"Axis 'COLUMNS' expression is not a set\");\n }\n\n /**\n * It is illegal for a query to have the same dimension on more than\n * one axis.\n */\n public void testSameDimOnTwoAxesFails() {\n assertQueryThrows(\n \"select {[Measures].[Unit Sales]} on columns,\\n\"\n + \" {[Measures].[Store Sales]} on rows\\n\"\n + \"from [Sales]\",\n \"Hierarchy '[Measures]' appears in more than one independent axis\");\n\n // as part of a crossjoin\n assertQueryThrows(\n \"select {[Measures].[Unit Sales]} on columns,\\n\"\n + \" CrossJoin({[Product].members},\"\n + \" {[Measures].[Store Sales]}) on rows\\n\"\n + \"from [Sales]\",\n \"Hierarchy '[Measures]' appears in more than one independent axis\");\n\n // as part of a tuple\n assertQueryThrows(\n \"select CrossJoin(\\n\"\n + \" {[Product].children},\\n\"\n + \" {[Measures].[Unit Sales]}) on columns,\\n\"\n + \" {([Product],\\n\"\n + \" [Store].CurrentMember)} on rows\\n\"\n + \"from [Sales]\",\n \"Hierarchy '[Product]' appears in more than one independent axis\");\n\n // clash between columns and slicer\n assertQueryThrows(\n \"select {[Measures].[Unit Sales]} on columns,\\n\"\n + \" {[Store].Members} on rows\\n\"\n + \"from [Sales]\\n\"\n + \"where ([Time].[1997].[Q1], [Measures].[Store Sales])\",\n \"Hierarchy '[Measures]' appears in more than one independent axis\");\n\n // within aggregate is OK\n executeQuery(\n \"with member [Measures].[West Coast Total] as \"\n + \" ' Aggregate({[Store].[USA].[CA], [Store].[USA].[OR], [Store].[USA].[WA]}) ' \\n\"\n + \"select \"\n + \" {[Measures].[Store Sales], \\n\"\n + \" [Measures].[Unit Sales]} on Columns,\\n\"\n + \" CrossJoin(\\n\"\n + \" {[Product].children},\\n\"\n + \" {[Store].children}) on Rows\\n\"\n + \"from [Sales]\");\n }\n\n public void _testSetArgToTupleFails() {\n assertQueryThrows(\n \"select CrossJoin(\\n\"\n + \" {[Product].children},\\n\"\n + \" {[Measures].[Unit Sales]}) on columns,\\n\"\n + \" {([Product],\\n\"\n + \" [Store].members)} on rows\\n\"\n + \"from [Sales]\",\n \"Dimension '[Product]' appears in more than one independent axis\");\n }\n\n public void _badArgsToTupleFails() {\n // clash within slicer\n assertQueryThrows(\n \"select {[Measures].[Unit Sales]} on columns,\\n\"\n + \" {[Store].Members} on rows\\n\"\n + \"from [Sales]\\n\"\n + \"where ([Time].[1997].[Q1], [Product], [Time].[1997].[Q2])\",\n \"Dimension '[Time]' more than once in same tuple\");\n\n // ditto\n assertQueryThrows(\n \"select {[Measures].[Unit Sales]} on columns,\\n\"\n + \" CrossJoin({[Time].[1997].[Q1],\\n\"\n + \" {[Product]},\\n\"\n + \" {[Time].[1997].[Q2]}) on rows\\n\"\n + \"from [Sales]\",\n \"Dimension '[Time]' more than once in same tuple\");\n }\n\n public void testNullMember() {\n if (isDefaultNullMemberRepresentation()) {\n assertQueryReturns(\n \"SELECT \\n\"\n + \"{[Measures].[Store Cost]} ON columns, \\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[#null]} ON rows \\n\"\n + \"FROM [Sales] \\n\"\n + \"WHERE [Time].[1997]\",\n \"Axis #0:\\n\"\n + \"{[Time].[1997]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Store Cost]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[#null]}\\n\"\n + \"Row #0: 33,307.69\\n\");\n }\n }\n\n public void testNullMemberWithOneNonNull() {\n if (isDefaultNullMemberRepresentation()) {\n assertQueryReturns(\n \"SELECT \\n\"\n + \"{[Measures].[Store Cost]} ON columns, \\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[#null],\"\n + \"[Store Size in SQFT].[ALL Store Size in SQFTs].[39696]} ON rows \\n\"\n + \"FROM [Sales] \\n\"\n + \"WHERE [Time].[1997]\",\n \"Axis #0:\\n\"\n + \"{[Time].[1997]}\\n\"\n + \"Axis #1:\\n\"\n + \"{[Measures].[Store Cost]}\\n\"\n + \"Axis #2:\\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[#null]}\\n\"\n + \"{[Store Size in SQFT].[All Store Size in SQFTs].[39696]}\\n\"\n + \"Row #0: 33,307.69\\n\"\n + \"Row #1: 21,121.96\\n\");\n }\n }\n\n /**\n * Tests whether the agg mgr behaves correctly if a cell request causes\n * a column to be constrained multiple times. This happens if two levels\n * map to the same column via the same join-path. If the constraints are\n * inconsistent, no data will be returned.\n */\n public void testMultipleConstraintsOnSameColumn() {\n final String cubeName = \"Sales_withCities\";\n TestContext testContext = TestContext.create(\n null,\n \"\\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \" \\n\"\n + \"