├── .gitignore ├── LICENSE ├── Particles ├── .classpath ├── .project ├── AndroidManifest.xml ├── assets │ ├── fireButton.jpg │ ├── fire_pit.png │ ├── particle_transp.jpg │ ├── smokeButton.jpg │ └── steamButton.jpg ├── bin │ ├── AndroidManifest.xml │ ├── Particles.apk │ ├── classes.dex │ ├── classes │ │ └── com │ │ │ └── kennethmaffei │ │ │ └── particles │ │ │ ├── BlackSmoke.class │ │ │ ├── BuildConfig.class │ │ │ ├── Fire.class │ │ │ ├── GLRenderer$PARTICLE_TYPE.class │ │ │ ├── GLRenderer.class │ │ │ ├── GenericParticleSystem.class │ │ │ ├── Globals.class │ │ │ ├── MainActivity$1.class │ │ │ ├── MainActivity$2.class │ │ │ ├── MainActivity$3.class │ │ │ ├── MainActivity.class │ │ │ ├── Particle.class │ │ │ ├── ParticleSystem.class │ │ │ ├── Quad.class │ │ │ ├── R$attr.class │ │ │ ├── R$dimen.class │ │ │ ├── R$drawable.class │ │ │ ├── R$id.class │ │ │ ├── R$layout.class │ │ │ ├── R$menu.class │ │ │ ├── R$string.class │ │ │ ├── R$style.class │ │ │ ├── R.class │ │ │ └── Vector3.class │ ├── dexedLibs │ │ └── android-support-v4-da707b2fdef3e87d425bbbf6146fb35d.jar │ ├── jarlist.cache │ ├── res │ │ └── crunch │ │ │ ├── drawable-hdpi │ │ │ └── ic_launcher.png │ │ │ ├── drawable-mdpi │ │ │ └── ic_launcher.png │ │ │ ├── drawable-xhdpi │ │ │ └── ic_launcher.png │ │ │ └── drawable-xxhdpi │ │ │ └── ic_launcher.png │ └── resources.ap_ ├── gen │ └── com │ │ └── kennethmaffei │ │ └── particles │ │ ├── BuildConfig.java │ │ └── R.java ├── ic_launcher-web.png ├── libs │ └── android-support-v4.jar ├── proguard-project.txt ├── project.properties ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── drawable-xxhdpi │ │ └── ic_launcher.png │ ├── layout │ │ └── activity_main.xml │ ├── menu │ │ └── main.xml │ ├── values-sw600dp │ │ └── dimens.xml │ ├── values-sw720dp-land │ │ └── dimens.xml │ ├── values-v11 │ │ └── styles.xml │ ├── values-v14 │ │ └── styles.xml │ └── values │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml └── src │ └── com │ └── kennethmaffei │ └── particles │ ├── BlackSmoke.java │ ├── Fire.java │ ├── GLRenderer.java │ ├── GenericParticleSystem.java │ ├── Globals.java │ ├── MainActivity.java │ ├── Particle.java │ ├── ParticleSystem.java │ ├── Quad.java │ └── Vector3.java └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | 19 | # Local configuration file (sdk path, etc) 20 | local.properties 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. -------------------------------------------------------------------------------- /Particles/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Particles/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Particles 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /Particles/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Particles/assets/fireButton.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/assets/fireButton.jpg -------------------------------------------------------------------------------- /Particles/assets/fire_pit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/assets/fire_pit.png -------------------------------------------------------------------------------- /Particles/assets/particle_transp.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/assets/particle_transp.jpg -------------------------------------------------------------------------------- /Particles/assets/smokeButton.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/assets/smokeButton.jpg -------------------------------------------------------------------------------- /Particles/assets/steamButton.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/assets/steamButton.jpg -------------------------------------------------------------------------------- /Particles/bin/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 10 | 11 | 16 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Particles/bin/Particles.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/Particles.apk -------------------------------------------------------------------------------- /Particles/bin/classes.dex: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes.dex -------------------------------------------------------------------------------- /Particles/bin/classes/com/kennethmaffei/particles/BlackSmoke.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes/com/kennethmaffei/particles/BlackSmoke.class -------------------------------------------------------------------------------- /Particles/bin/classes/com/kennethmaffei/particles/BuildConfig.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes/com/kennethmaffei/particles/BuildConfig.class -------------------------------------------------------------------------------- /Particles/bin/classes/com/kennethmaffei/particles/Fire.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes/com/kennethmaffei/particles/Fire.class -------------------------------------------------------------------------------- /Particles/bin/classes/com/kennethmaffei/particles/GLRenderer$PARTICLE_TYPE.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes/com/kennethmaffei/particles/GLRenderer$PARTICLE_TYPE.class -------------------------------------------------------------------------------- /Particles/bin/classes/com/kennethmaffei/particles/GLRenderer.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes/com/kennethmaffei/particles/GLRenderer.class -------------------------------------------------------------------------------- /Particles/bin/classes/com/kennethmaffei/particles/GenericParticleSystem.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes/com/kennethmaffei/particles/GenericParticleSystem.class -------------------------------------------------------------------------------- /Particles/bin/classes/com/kennethmaffei/particles/Globals.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes/com/kennethmaffei/particles/Globals.class -------------------------------------------------------------------------------- /Particles/bin/classes/com/kennethmaffei/particles/MainActivity$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes/com/kennethmaffei/particles/MainActivity$1.class -------------------------------------------------------------------------------- /Particles/bin/classes/com/kennethmaffei/particles/MainActivity$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes/com/kennethmaffei/particles/MainActivity$2.class -------------------------------------------------------------------------------- /Particles/bin/classes/com/kennethmaffei/particles/MainActivity$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes/com/kennethmaffei/particles/MainActivity$3.class -------------------------------------------------------------------------------- /Particles/bin/classes/com/kennethmaffei/particles/MainActivity.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes/com/kennethmaffei/particles/MainActivity.class -------------------------------------------------------------------------------- /Particles/bin/classes/com/kennethmaffei/particles/Particle.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes/com/kennethmaffei/particles/Particle.class -------------------------------------------------------------------------------- /Particles/bin/classes/com/kennethmaffei/particles/ParticleSystem.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes/com/kennethmaffei/particles/ParticleSystem.class -------------------------------------------------------------------------------- /Particles/bin/classes/com/kennethmaffei/particles/Quad.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes/com/kennethmaffei/particles/Quad.class -------------------------------------------------------------------------------- /Particles/bin/classes/com/kennethmaffei/particles/R$attr.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes/com/kennethmaffei/particles/R$attr.class -------------------------------------------------------------------------------- /Particles/bin/classes/com/kennethmaffei/particles/R$dimen.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes/com/kennethmaffei/particles/R$dimen.class -------------------------------------------------------------------------------- /Particles/bin/classes/com/kennethmaffei/particles/R$drawable.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes/com/kennethmaffei/particles/R$drawable.class -------------------------------------------------------------------------------- /Particles/bin/classes/com/kennethmaffei/particles/R$id.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes/com/kennethmaffei/particles/R$id.class -------------------------------------------------------------------------------- /Particles/bin/classes/com/kennethmaffei/particles/R$layout.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes/com/kennethmaffei/particles/R$layout.class -------------------------------------------------------------------------------- /Particles/bin/classes/com/kennethmaffei/particles/R$menu.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes/com/kennethmaffei/particles/R$menu.class -------------------------------------------------------------------------------- /Particles/bin/classes/com/kennethmaffei/particles/R$string.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes/com/kennethmaffei/particles/R$string.class -------------------------------------------------------------------------------- /Particles/bin/classes/com/kennethmaffei/particles/R$style.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes/com/kennethmaffei/particles/R$style.class -------------------------------------------------------------------------------- /Particles/bin/classes/com/kennethmaffei/particles/R.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes/com/kennethmaffei/particles/R.class -------------------------------------------------------------------------------- /Particles/bin/classes/com/kennethmaffei/particles/Vector3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/classes/com/kennethmaffei/particles/Vector3.class -------------------------------------------------------------------------------- /Particles/bin/dexedLibs/android-support-v4-da707b2fdef3e87d425bbbf6146fb35d.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/dexedLibs/android-support-v4-da707b2fdef3e87d425bbbf6146fb35d.jar -------------------------------------------------------------------------------- /Particles/bin/jarlist.cache: -------------------------------------------------------------------------------- 1 | # cache for current jar dependency. DO NOT EDIT. 2 | # format is 3 | # Encoding is UTF-8 4 | -------------------------------------------------------------------------------- /Particles/bin/res/crunch/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/res/crunch/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Particles/bin/res/crunch/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/res/crunch/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Particles/bin/res/crunch/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/res/crunch/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Particles/bin/res/crunch/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/res/crunch/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Particles/bin/resources.ap_: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/bin/resources.ap_ -------------------------------------------------------------------------------- /Particles/gen/com/kennethmaffei/particles/BuildConfig.java: -------------------------------------------------------------------------------- 1 | /** Automatically generated file. DO NOT MODIFY */ 2 | package com.kennethmaffei.particles; 3 | 4 | public final class BuildConfig { 5 | public final static boolean DEBUG = true; 6 | } -------------------------------------------------------------------------------- /Particles/gen/com/kennethmaffei/particles/R.java: -------------------------------------------------------------------------------- 1 | /* AUTO-GENERATED FILE. DO NOT MODIFY. 2 | * 3 | * This class was automatically generated by the 4 | * aapt tool from the resource data it found. It 5 | * should not be modified by hand. 6 | */ 7 | 8 | package com.kennethmaffei.particles; 9 | 10 | public final class R { 11 | public static final class attr { 12 | } 13 | public static final class dimen { 14 | /** Default screen margins, per the Android Design guidelines. 15 | 16 | Customize dimensions originally defined in res/values/dimens.xml (such as 17 | screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here. 18 | 19 | */ 20 | public static final int activity_horizontal_margin=0x7f040000; 21 | public static final int activity_vertical_margin=0x7f040001; 22 | } 23 | public static final class drawable { 24 | public static final int ic_launcher=0x7f020000; 25 | } 26 | public static final class id { 27 | public static final int action_settings=0x7f080001; 28 | public static final int text_id=0x7f080000; 29 | } 30 | public static final class layout { 31 | public static final int activity_main=0x7f030000; 32 | } 33 | public static final class menu { 34 | public static final int main=0x7f070000; 35 | } 36 | public static final class string { 37 | public static final int action_settings=0x7f050001; 38 | public static final int app_name=0x7f050000; 39 | public static final int hello_world=0x7f050002; 40 | } 41 | public static final class style { 42 | /** 43 | Base application theme, dependent on API level. This theme is replaced 44 | by AppBaseTheme from res/values-vXX/styles.xml on newer devices. 45 | 46 | 47 | Theme customizations available in newer API levels can go in 48 | res/values-vXX/styles.xml, while customizations related to 49 | backward-compatibility can go here. 50 | 51 | 52 | Base application theme for API 11+. This theme completely replaces 53 | AppBaseTheme from res/values/styles.xml on API 11+ devices. 54 | 55 | API 11 theme customizations can go here. 56 | 57 | Base application theme for API 14+. This theme completely replaces 58 | AppBaseTheme from BOTH res/values/styles.xml and 59 | res/values-v11/styles.xml on API 14+ devices. 60 | 61 | API 14 theme customizations can go here. 62 | */ 63 | public static final int AppBaseTheme=0x7f060000; 64 | /** Application theme. 65 | All customizations that are NOT specific to a particular API-level can go here. 66 | */ 67 | public static final int AppTheme=0x7f060001; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Particles/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/ic_launcher-web.png -------------------------------------------------------------------------------- /Particles/libs/android-support-v4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/libs/android-support-v4.jar -------------------------------------------------------------------------------- /Particles/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /Particles/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-19 15 | -------------------------------------------------------------------------------- /Particles/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /Particles/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /Particles/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Particles/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenmaffei/opengl-particles/60c440c62241c0331b9cd0b8a5b420bc40ea0106/Particles/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /Particles/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 10 | 11 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Particles/res/menu/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Particles/res/values-sw600dp/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Particles/res/values-sw720dp-land/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 128dp 8 | 9 | 10 | -------------------------------------------------------------------------------- /Particles/res/values-v11/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Particles/res/values-v14/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /Particles/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16dp 5 | 16dp 6 | 7 | 8 | -------------------------------------------------------------------------------- /Particles/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Particles 5 | Settings 6 | Hello world! 7 | 8 | 9 | -------------------------------------------------------------------------------- /Particles/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Particles/src/com/kennethmaffei/particles/BlackSmoke.java: -------------------------------------------------------------------------------- 1 | package com.kennethmaffei.particles; 2 | 3 | import javax.microedition.khronos.opengles.GL10; 4 | 5 | import android.opengl.GLES11; 6 | 7 | public class BlackSmoke extends ParticleSystem { 8 | 9 | @Override 10 | void InitializeParticle(int index) { 11 | Particle p = particles.get(index); 12 | p.colorR = p.colorG = p.colorB = p.colorA = 1.0f; 13 | 14 | p.lifeTime = p.life = lifeTime + Globals.random()*lifeTimeVar; 15 | p.deltaColorR = -(p.colorR)/p.life; 16 | p.deltaColorG = -(p.colorG)/p.life; 17 | p.deltaColorB = -(p.colorB)/p.life; 18 | p.deltaColorA = -1.0f/p.life; 19 | 20 | p.position.x = origin.x + (2.0f*Globals.random() - 1.0f)*width/2.0f; 21 | p.position.y = origin.y + (2.0f*Globals.random() - 1.0f)*depth/2.0f; 22 | p.position.z = origin.z + (2.0f*Globals.random() - 1.0f)*height/2.0f; 23 | 24 | p.velocity.x = velocity.x + (2.0f*Globals.random() - 1.0f)*velocityVariation.x; 25 | p.velocity.y = velocity.y + (2.0f*Globals.random() - 1.0f)*velocityVariation.y; 26 | p.velocity.z = velocity.z + (2.0f*Globals.random() - 1.0f)*velocityVariation.z; 27 | 28 | p.acceleration.copy(acceleration); 29 | 30 | p.size.x = startSize.x; 31 | p.size.y = startSize.y; 32 | 33 | p.deltaSize.x = (endSize.x - startSize.x)/p.life; 34 | p.deltaSize.y = (endSize.y - startSize.y)/p.life; 35 | 36 | //Now that the particle attributes are set, initialize the quad 37 | p.initializeQuad(startSize, glTexture[0], facing); 38 | 39 | //Now that the particle attributes are set, initialize the quad 40 | p.initializeQuad(startSize, glTexture[0], facing); 41 | } 42 | 43 | @Override 44 | void update(float elapsedTime) { 45 | if(!started) 46 | return; 47 | 48 | timeBeforeStartTime+= elapsedTime; 49 | if(timeBeforeStartTime < startTime) 50 | return; 51 | 52 | accumulatedTime+= elapsedTime; 53 | 54 | /* Frustum culling (NOT IMPLEMENTED HERE) 55 | * If you are doing frustum culling, then check here. 56 | * For example: 57 | * 58 | * //If the system is outside the frustion, don't draw it. 59 | * //However, depending on what the system is, you may still 60 | * //want to update it. For example, transient systems like 61 | * //an explosion should still be updated, while fixed system 62 | * //like mist or fire would not need to be updated. 63 | * if(!frustum->sphereInFrustum(origin, rEff)) { 64 | * draw = false; 65 | * return; (Optional) 66 | * } 67 | * 68 | */ 69 | 70 | //Iterate over all the particles and update their attributes 71 | for(int i=0; i < numParticles; ) { 72 | Particle p = particles.get(i); 73 | //Update the particle's position based on the elapsed time and velocity 74 | p.position.x+= p.velocity.x * elapsedTime; 75 | p.position.y+= p.velocity.y * elapsedTime; 76 | p.position.z+= p.velocity.z * elapsedTime; 77 | p.velocity.x+= p.acceleration.x * elapsedTime; 78 | p.velocity.y+= p.acceleration.y * elapsedTime; 79 | p.velocity.z+= p.acceleration.z * elapsedTime; 80 | 81 | p.life -= 2*elapsedTime; 82 | 83 | p.size.x+= p.deltaSize.x * 2*elapsedTime; 84 | p.size.y+= p.deltaSize.y * 2*elapsedTime; 85 | 86 | p.colorA+= p.deltaColorA * 2*elapsedTime; 87 | p.colorG+= p.deltaColorG * 2*elapsedTime; 88 | 89 | p.colorR+= p.deltaColorR * 2*elapsedTime; 90 | p.colorB+= p.deltaColorB * 2*elapsedTime; 91 | 92 | //Kill the particle if it's been around long enough 93 | if(p.life <= 0.0) { 94 | //Swap the last particle with the current position, and decrease the count 95 | Particle dead = particles.get(i); 96 | particles.set(i, particles.get(numParticles - 1)); 97 | particles.set(numParticles - 1, dead); 98 | numParticles--; 99 | } 100 | else { 101 | p.updateQuad(); 102 | i++; 103 | } 104 | } 105 | 106 | if(accumulatedTime < duration || fixed) { 107 | float numParticlesThisFrame = elapsedTime*particlesPerSec; 108 | float numNewParticles = numParticlesThisFrame + numParticlesHeldOver; 109 | int numParticlesToEmit = (int) Math.floor(numNewParticles); 110 | numParticlesHeldOver = numNewParticles - numParticlesToEmit; 111 | updateSystem(numParticlesToEmit, elapsedTime); 112 | 113 | return; 114 | } 115 | else 116 | destroying = true; 117 | } 118 | 119 | @Override 120 | void draw(GL10 gl) { 121 | GLES11.glDepthMask(false); 122 | GLES11.glEnable(GLES11.GL_BLEND); 123 | GLES11.glTexEnvi(GLES11.GL_TEXTURE_ENV, GLES11.GL_TEXTURE_ENV_MODE, GLES11.GL_MODULATE); 124 | GLES11.glBlendFunc(GLES11.GL_ZERO, GLES11.GL_ONE_MINUS_SRC_COLOR); //Special blend mode for Black Smoke! 125 | 126 | GLES11.glBindTexture(GLES11.GL_TEXTURE_2D, glTexture[0]); 127 | 128 | GLES11.glPushMatrix(); 129 | //No need for translation, it's done per particle when they are created 130 | //We don't translate an already-emitted particle's origin as the the emitter moves 131 | GLES11.glRotatef(rotate.x, 0, 0, 1); 132 | GLES11.glRotatef(rotate.y, 0, 1, 0); 133 | GLES11.glRotatef(rotate.x, 1, 0, 0); 134 | GLES11.glScalef(scale.x, scale.y, scale.z); 135 | 136 | for(int i=0; isphereInFrustum(origin, rEff)) { 184 | * draw = false; 185 | * return; (Optional) 186 | * } 187 | * 188 | */ 189 | 190 | //Iterate over all the particles and update their attributes 191 | for(int i=0; i < numParticles; ) { 192 | Particle p = particles.get(i); 193 | //Update the particle's position based on the elapsed time and velocity 194 | p.position.x+= p.velocity.x * elapsedTime; 195 | p.position.y+= p.velocity.y * elapsedTime; 196 | p.position.z+= p.velocity.z * elapsedTime; 197 | p.velocity.x+= p.acceleration.x * elapsedTime; 198 | p.velocity.y+= p.acceleration.y * elapsedTime; 199 | p.velocity.z+= p.acceleration.z * elapsedTime; 200 | 201 | if(destroying) //accelerate the particle death a little 202 | p.life-= 3*elapsedTime; 203 | else 204 | p.life -= 2*elapsedTime; 205 | 206 | p.size.x+= p.deltaSize.x * elapsedTime; 207 | p.size.y+= p.deltaSize.y * elapsedTime; 208 | 209 | if(useDefaultColors) { 210 | p.colorA+= p.deltaColorA * elapsedTime; 211 | p.colorG+= p.deltaColorG * elapsedTime; 212 | 213 | p.colorR+= p.deltaColorR * elapsedTime; 214 | p.colorB+= p.deltaColorB * elapsedTime; 215 | } 216 | else { 217 | float percentComplete = (p.lifeTime - p.life)/p.lifeTime; 218 | if(percentComplete < midPercent) 219 | { 220 | percentComplete = percentComplete/midPercent; 221 | p.colorR = startColorR + (midColorR - startColorR)*percentComplete; 222 | p.colorG = startColorG + (midColorG - startColorG)*percentComplete; 223 | p.colorB = startColorB + (midColorB - startColorB)*percentComplete; 224 | p.colorA = startColorA + (midColorA - startColorA)*percentComplete; 225 | } 226 | else 227 | { 228 | percentComplete = (percentComplete - midPercent)/(1.0f - midPercent); 229 | p.colorR = midColorR + (endColorR - midColorR)*percentComplete; 230 | p.colorG = midColorG + (endColorG - midColorG)*percentComplete; 231 | p.colorB = midColorB + (endColorB - midColorB)*percentComplete; 232 | p.colorA = midColorA + (endColorA - midColorA)*percentComplete; 233 | } 234 | } 235 | 236 | //Kill the particle if it's been around long enough 237 | if(p.life <= 0.0) { 238 | //Swap the last particle with the current position, and decrease the count 239 | Particle dead = particles.get(i); 240 | particles.set(i, particles.get(numParticles - 1)); 241 | particles.set(numParticles - 1, dead); 242 | numParticles--; 243 | } 244 | else { 245 | p.updateQuad(); 246 | i++; 247 | } 248 | } 249 | 250 | if(accumulatedTime < duration || fixed) { 251 | float numParticlesThisFrame = elapsedTime*particlesPerSec; 252 | float numNewParticles = numParticlesThisFrame + numParticlesHeldOver; 253 | int numParticlesToEmit = (int) Math.floor(numNewParticles); 254 | numParticlesHeldOver = numNewParticles - numParticlesToEmit; 255 | updateSystem(numParticlesToEmit, elapsedTime); 256 | 257 | return; 258 | } 259 | else 260 | destroying = true; 261 | } 262 | 263 | @Override 264 | void draw(GL10 gl) { 265 | GLES11.glDepthMask(false); 266 | GLES11.glEnable(GLES11.GL_BLEND); 267 | GLES11.glTexEnvi(GLES11.GL_TEXTURE_ENV, GLES11.GL_TEXTURE_ENV_MODE, GLES11.GL_MODULATE); 268 | GLES11.glBlendFunc(GLES11.GL_SRC_ALPHA, GL10.GL_ONE); 269 | 270 | GLES11.glBindTexture(GLES11.GL_TEXTURE_2D, glTexture[0]); 271 | 272 | GLES11.glPushMatrix(); 273 | //No need for translation, it's done per particle when they are created 274 | //We don't translate an already-emitted particle's origin as the the emitter moves 275 | GLES11.glRotatef(rotate.x, 0, 0, 1); 276 | GLES11.glRotatef(rotate.y, 0, 1, 0); 277 | GLES11.glRotatef(rotate.x, 1, 0, 0); 278 | GLES11.glScalef(scale.x, scale.y, scale.z); 279 | 280 | for(int i=0; i -0.9999); 138 | 139 | objToCam.copy(camPos); 140 | objToCam.subtract(fire.origin); 141 | objToCam.normalize(); 142 | 143 | Globals.phi = Vector3.dotProduct(objToCamProj, objToCam); 144 | Globals.phiTest = (Globals.phi < 0.99990) && (Globals.phi > -0.9999); 145 | 146 | Globals.billboardDirectionTest = (objToCam.y < 0); 147 | 148 | switch (particleType) { 149 | case STEAM: 150 | GLES11.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 151 | steam.update(deltaT); 152 | steam.draw(gl); 153 | break; 154 | case BLACK_SMOKE: 155 | GLES11.glClearColor(0.8f, 0.8f, 0.8f, 1.0f); 156 | blackSmoke.update(deltaT); 157 | blackSmoke.draw(gl); 158 | firePit.draw(gl); 159 | break; 160 | case FIRE: 161 | GLES11.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); 162 | fire.update(deltaT); 163 | fire.draw(gl); 164 | firePit.draw(gl); 165 | } 166 | 167 | //Disable the client state before leaving 168 | GLES11.glDisableClientState(GLES11.GL_VERTEX_ARRAY); 169 | GLES11.glDisableClientState(GLES11.GL_TEXTURE_COORD_ARRAY); 170 | } 171 | 172 | /** 173 | * Create the particle systems for the demo 174 | * 175 | * @param gl - the openGl context 176 | */ 177 | void CreateSystems(GL10 gl) { 178 | //Steam system 179 | steam.loadTexture(gl, "particle_transp.jpg"); 180 | steam.setStartColor(0.75f, 0.75f, 0.9f, 0.25f); 181 | steam.setMidColor(0.75f, 0.75f, 0.9f, 0.15f); 182 | steam.setEndColor(0.75f, 0.75f, 0.9f, 0.0f); 183 | steam.setEmitterVolume(10.0f, 1.0f, 10.0f); 184 | PointF startSize = new PointF(); 185 | startSize.x = 100.0f; 186 | startSize.y = 150.0f; 187 | PointF endSize = new PointF(); 188 | endSize.x = 200.0f; 189 | endSize.y = 800.0f; 190 | steam.setParticleSize(startSize, endSize); 191 | steam.setParticleLife(200, 55, 1.0f, 0.5f); 192 | Vector3 velocity = new Vector3(); 193 | velocity.x = 0.0f; 194 | velocity.y = 1000.0f; 195 | velocity.z = 0.0f; 196 | Vector3 velocityVariation = new Vector3(150.0f, 30.0f, 150.0f); 197 | Vector3 acceleration = new Vector3(0.0f, -800.0f, 0.0f); 198 | steam.setMotion(velocity, velocityVariation, acceleration); 199 | Vector3 origin = new Vector3(0.0f, -300.0f, 0.0f); 200 | steam.startSystem(origin, -1.0f); 201 | 202 | //Fire system 203 | fire.loadTexture(gl, "particle_transp.jpg"); 204 | fire.setEmitterVolume(240.0f, 100.0f, 240.0f); 205 | startSize = new PointF(); 206 | startSize.x = 160.0f; 207 | startSize.y = 240.0f; 208 | endSize = new PointF(); 209 | endSize.x = 120.0f; 210 | endSize.y = 600.0f; 211 | fire.setParticleSize(startSize, endSize); 212 | fire.setParticleLife(80, 60.0f, 2.0f, 0.5f); 213 | velocity = new Vector3(0.0f, 500.0f, 0.0f); 214 | velocityVariation = new Vector3(120.0f, 180.0f, 120.0f); 215 | acceleration = new Vector3(); 216 | fire.setMotion(velocity, velocityVariation, acceleration); 217 | origin = new Vector3(0.0f, -300.0f, 0.0f); 218 | fire.startSystem(origin, -1.0f); 219 | 220 | Vector3 firePitPosition = new Vector3(0.0f, -325.0f, 200.0f); 221 | firePit = new Quad(500, 300, firePitPosition); 222 | firePit.isFacingParticle = false; 223 | firePit.isParticle = false; 224 | firePit.loadTexture(gl, "fire_pit.png"); 225 | 226 | //Black smoke system 227 | blackSmoke.loadTexture(gl, "particle_transp.jpg"); 228 | blackSmoke.setEmitterVolume(100.0f, 50.0f, 100.0f); 229 | startSize = new PointF(); 230 | startSize.x = 100.0f; 231 | startSize.y = 180.0f; 232 | endSize = new PointF(); 233 | endSize.x = 500.0f; 234 | endSize.y = 300.0f; 235 | blackSmoke.setParticleSize(startSize, endSize); 236 | blackSmoke.setParticleLife(50, 20.0f, 4.0f, 2.0f); 237 | velocity = new Vector3(0.0f, 250.0f, 0.0f); 238 | velocityVariation = new Vector3(60.0f, 100.0f, 60.0f); 239 | acceleration = new Vector3(); 240 | blackSmoke.setMotion(velocity, velocityVariation, acceleration); 241 | origin = new Vector3(0.0f, -300.0f, 0.0f); 242 | blackSmoke.startSystem(origin, -1.0f); 243 | 244 | graphicsLoaded = true; 245 | currentTime = prevTime = System.currentTimeMillis(); //Reset timers 246 | } 247 | 248 | public void setToSteam() { 249 | particleType = PARTICLE_TYPE.STEAM; 250 | } 251 | 252 | public void setToFire() { 253 | particleType = PARTICLE_TYPE.FIRE; 254 | } 255 | 256 | public void setToBlackSmoke() { 257 | particleType = PARTICLE_TYPE.BLACK_SMOKE; 258 | } 259 | } 260 | -------------------------------------------------------------------------------- /Particles/src/com/kennethmaffei/particles/GenericParticleSystem.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2014 Kenneth Maffei 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | package com.kennethmaffei.particles; 18 | 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | 22 | import javax.microedition.khronos.opengles.GL10; 23 | 24 | import android.graphics.Bitmap; 25 | import android.graphics.BitmapFactory; 26 | import android.opengl.GLES11; 27 | import android.opengl.GLUtils; 28 | 29 | /** 30 | * This system is a general particle system. 31 | * It uses a start color, mid color and end color for particles 32 | * A particle will morph from it's start color to its mid and end colors 33 | * The mid color appears at the midPercent point in it's life cycle 34 | * The colors include an alpha value 35 | * 36 | * @author Kenneth Maffei 37 | * 38 | */ 39 | public class GenericParticleSystem extends ParticleSystem { 40 | 41 | protected float startColorR = 1.0f; //Start red value 42 | protected float startColorG = 1.0f; //Start green value 43 | protected float startColorB = 1.0f; //Start blue value 44 | protected float startColorA = 1.0f; //Start alpha value 45 | protected float midColorR = 1.0f; //Mid red value 46 | protected float midColorG = 1.0f; //Mid green value 47 | protected float midColorB = 1.0f; //Mid blue value 48 | protected float midColorA = 1.0f; //Mid alpha value 49 | protected float endColorR = 1.0f; //Final red value 50 | protected float endColorG = 1.0f; //Final green value 51 | protected float endColorB = 1.0f; //Final blue value 52 | protected float endColorA = 1.0f; //Final alpha value 53 | 54 | protected float midPercent = 0.5f; //At what point in the particles life it reaches the mid color 55 | 56 | /** 57 | * Set the particle start color 58 | * 59 | * @param r - red 60 | * @param g - greed 61 | * @param b - blue 62 | * @param a - alpha 63 | */ 64 | void setStartColor(float r, float g, float b, float a) { 65 | startColorR = r; 66 | startColorG = g; 67 | startColorB = b; 68 | startColorA = a; 69 | } 70 | 71 | /** 72 | * Set the particle mid color 73 | * 74 | * @param r - red 75 | * @param g - greed 76 | * @param b - blue 77 | * @param a - alpha 78 | */ 79 | void setMidColor(float r, float g, float b, float a) { 80 | midColorR = r; 81 | midColorG = g; 82 | midColorB = b; 83 | midColorA = a; 84 | } 85 | 86 | /** 87 | * Set the particle end color 88 | * 89 | * @param r - red 90 | * @param g - greed 91 | * @param b - blue 92 | * @param a - alpha 93 | */ 94 | void setEndColor(float r, float g, float b, float a) { 95 | endColorR = r; 96 | endColorG = g; 97 | endColorB = b; 98 | endColorA = a; 99 | } 100 | 101 | /** 102 | * Sets the midpoint for particle color changes 103 | * 104 | * @param midPercent - the midpoint percentage in the particle's life 105 | */ 106 | void setMidPercent(float midPercent) { 107 | this.midPercent = midPercent/100.0f; 108 | if(midPercent == 0.0f) 109 | midPercent = .001f; 110 | } 111 | 112 | @Override 113 | void InitializeParticle(int index) { 114 | Particle p = particles.get(index); 115 | p.position.x = origin.x + (2.0f*Globals.random() - 1.0f)*width/2.0f; 116 | p.position.y = origin.y + (2.0f*Globals.random() - 1.0f)*depth/2.0f; 117 | p.position.z = origin.z + (2.0f*Globals.random() - 1.0f)*height/2.0f; 118 | 119 | p.size.x = startSize.x; 120 | p.size.y = startSize.y; 121 | 122 | if(radial) { 123 | float vel = velocity.x + (2.0f*Globals.random() - 1.0f)*velocityVariation.x; //This is our radial velocity 124 | p.velocity.x = (2.0f*Globals.random() - 1.0f)*vel; 125 | p.velocity.y = (2.0f*Globals.random() - 1.0f)*vel; 126 | p.velocity.z = (2.0f*Globals.random() - 1.0f)*vel; 127 | p.velocity.normalize(); 128 | p.velocity.x*= vel; 129 | p.velocity.y*= vel; 130 | p.velocity.z*= vel; 131 | } 132 | else { 133 | p.velocity.x = velocity.x + (2.0f*Globals.random() - 1.0f)*velocityVariation.x; 134 | p.velocity.y = velocity.y + (2.0f*Globals.random() - 1.0f)*velocityVariation.y; 135 | p.velocity.z = velocity.z + (2.0f*Globals.random() - 1.0f)*velocityVariation.z; 136 | } 137 | 138 | p.acceleration.copy(acceleration); 139 | p.lifeTime = p.life = lifeTime + Globals.random()*lifeTimeVar; 140 | p.colorR = startColorR; 141 | p.colorG = startColorG; 142 | p.colorB = startColorB; 143 | p.colorA = startColorA; 144 | 145 | p.deltaSize.x = (endSize.x - startSize.x)/p.life; 146 | p.deltaSize.y = (endSize.y - startSize.y)/p.life; 147 | 148 | //Now that the particle attributes are set, initialize the quad 149 | p.initializeQuad(startSize, glTexture[0], facing); 150 | } 151 | 152 | @Override 153 | void update(float elapsedTime) { 154 | if(!started) 155 | return; 156 | 157 | timeBeforeStartTime+= elapsedTime; 158 | if(timeBeforeStartTime < startTime) 159 | return; 160 | 161 | accumulatedTime+= elapsedTime; 162 | 163 | /* Frustum culling (NOT IMPLEMENTED HERE) 164 | * If you are doing frustum culling, then check here. 165 | * For example: 166 | * 167 | * //If the system is outside the frustion, don't draw it. 168 | * //However, depending on what the system is, you may still 169 | * //want to update it. For example, transient systems like 170 | * //an explosion should still be updated, while fixed system 171 | * //like mist or fire would not need to be updated. 172 | * if(!frustum->sphereInFrustum(origin, rEff)) { 173 | * draw = false; 174 | * return; (Optional) 175 | * } 176 | * 177 | */ 178 | 179 | for(int i=0; i < numParticles; ) { 180 | Particle p = particles.get(i); 181 | //Update the particle's position based on the elapsed time and velocity 182 | p.position.x+= p.velocity.x * elapsedTime; 183 | p.position.y+= p.velocity.y * elapsedTime; 184 | p.position.z+= p.velocity.z * elapsedTime; 185 | p.velocity.x+= p.acceleration.x * elapsedTime; 186 | p.velocity.y+= p.acceleration.y * elapsedTime; 187 | p.velocity.z+= p.acceleration.z * elapsedTime; 188 | 189 | p.life-= elapsedTime; 190 | 191 | p.size.x+= p.deltaSize.x * elapsedTime; 192 | p.size.y+= p.deltaSize.y * elapsedTime; 193 | 194 | float percentComplete = (p.lifeTime - p.life)/p.lifeTime; 195 | if(percentComplete < midPercent) { 196 | percentComplete = percentComplete/midPercent; 197 | p.colorR = startColorR + (midColorR - startColorR)*percentComplete; 198 | p.colorG = startColorG + (midColorG - startColorG)*percentComplete; 199 | p.colorB = startColorB + (midColorB - startColorB)*percentComplete; 200 | p.colorA = startColorA + (midColorA - startColorA)*percentComplete; 201 | } 202 | else { 203 | percentComplete = (percentComplete - midPercent)/(1.0f - midPercent); 204 | p.colorR = midColorR + (endColorR - midColorR)*percentComplete; 205 | p.colorG = midColorG + (endColorG - midColorG)*percentComplete; 206 | p.colorB = midColorB + (endColorB - midColorB)*percentComplete; 207 | p.colorA = midColorA + (endColorA - midColorA)*percentComplete; 208 | } 209 | 210 | //Kill the particle if it's been around long enough 211 | if(p.life <= 0.0) { 212 | //Swap the last particle with the current positon, and decrease the count 213 | Particle dead = particles.get(i); 214 | particles.set(i, particles.get(numParticles - 1)); 215 | particles.set(numParticles - 1, dead); 216 | numParticles--; 217 | } 218 | else { 219 | p.updateQuad(); 220 | i++; 221 | } 222 | } 223 | 224 | if(accumulatedTime < duration || fixed) { 225 | float numParticlesThisFrame = elapsedTime*particlesPerSec; 226 | float numNewParticles = numParticlesThisFrame + numParticlesHeldOver; 227 | int numParticlesToEmit = (int) Math.floor(numNewParticles); 228 | numParticlesHeldOver = numNewParticles - numParticlesToEmit; 229 | updateSystem(numParticlesToEmit, elapsedTime); 230 | 231 | return; 232 | } 233 | else 234 | destroying = true; 235 | } 236 | 237 | @Override 238 | void draw(GL10 gl) { 239 | GLES11.glDepthMask(false); 240 | GLES11.glEnable(GLES11.GL_BLEND); 241 | GLES11.glTexEnvi(GLES11.GL_TEXTURE_ENV, GLES11.GL_TEXTURE_ENV_MODE, GLES11.GL_MODULATE); 242 | GLES11.glBlendFunc (GLES11.GL_SRC_ALPHA, GL10.GL_ONE); 243 | 244 | GLES11.glBindTexture(GLES11.GL_TEXTURE_2D, glTexture[0]); 245 | 246 | GLES11.glPushMatrix(); 247 | 248 | //No need for translation, it's done per particle when they are created 249 | //We don't translate an already-emitted particle's origin as the the emitter moves 250 | GLES11.glRotatef(rotate.z, 0, 0, 1); 251 | GLES11.glRotatef(rotate.y, 0, 1, 0); 252 | GLES11.glRotatef(rotate.z, 1, 0, 0); 253 | GLES11.glScalef(scale.x, scale.y, scale.z); 254 | 255 | for(int i=0; i particles = new ArrayList(); 40 | //We don't rely on particles.size() for the number of particles in the system. 41 | //For efficiency, the particles array is always built for maxParticles. 42 | //Particles are swapped in the array at particle death (see the emit() function). 43 | //numParticles keeps track of how many we are rendering at a given time. 44 | protected int numParticles; 45 | int maxParticles; 46 | 47 | protected PointF startSize = new PointF(); //Particle start size 48 | protected PointF endSize = new PointF(); //Particle end size 49 | protected float particlesPerSec; //Particle birth rate 50 | protected Vector3 velocity = new Vector3(); //Particle starting velocity 51 | protected Vector3 velocityVariation = new Vector3(); //Variation in the particle starting velocity 52 | protected Vector3 acceleration = new Vector3(); //Particle staring acceleration 53 | protected Vector3 origin = new Vector3(); //The origin for the system 54 | protected float height, width, depth; //Volume parameters for particle generation 55 | protected float radius; //For radial systems 56 | protected float accumulatedTime; //For transient systems, the time the system has been alive 57 | protected float lifeTime; //Particle lifetime 58 | protected float lifeTimeVar; //Lifetime variation 59 | protected float startTime; //Delay before actually generating any particles 60 | protected float timeBeforeStartTime; //The accumulated time before the start time 61 | protected boolean started; //Indicates that the system has been started 62 | protected boolean fixed; //Fixed system or transient 63 | protected float duration = -1.0f; //Duration of particle system; duration = -1 means keep going once started 64 | protected boolean destroying; //If the system is shutting down. Generally will decrease life for graceful shut down 65 | protected boolean draw; //Whether or not to actually render the system (for transient systems, update can be true, but draw false) 66 | //If elapsedTime is such that numNewParticles is 0 (because of rounding down), 67 | //then hold over this elapsed time and add it to the next until we get some particle production! 68 | protected float timeHeldOver; 69 | protected float numParticlesHeldOver; 70 | 71 | protected Vector3 emitterVelocity = new Vector3(); //Allows the particle emitter to move 72 | protected Vector3 emitterAcceleration = new Vector3(); //Acceleration for the emitter 73 | 74 | protected boolean radial; //Sets this as for radial particle production. Velocity is interpreted as radial velocity. 75 | 76 | protected boolean facing = true; //Particles always face the camera. This is usually the case, but not always. 77 | 78 | protected float rEff; //Effective radius used for frustum culling 79 | 80 | protected Vector3 scale = new Vector3(1.0f, 1.0f, 1.0f);//Scaling of the entire system as a whole 81 | protected Vector3 rotate = new Vector3(); //Rotation of the entire system as a whole 82 | 83 | protected int[] glTexture = new int[1]; 84 | 85 | /** 86 | * Initializes a given particle with all its "start" values 87 | * 88 | * @param index - the index into the particle array 89 | */ 90 | abstract void InitializeParticle(int index); 91 | 92 | /** 93 | * Iterates over the particles and updates their attributes 94 | * This function must also call updateSystem() 95 | * 96 | * @param elapsedTime - the time since the last frame 97 | */ 98 | abstract void update(float elapsedTime); 99 | 100 | /** 101 | * Renders the particle system to the screen 102 | * 103 | * @param gl - the openGL context 104 | */ 105 | abstract void draw(GL10 gl); 106 | 107 | /** 108 | * Load a masking texture for the particle system 109 | * 110 | * @param gl - the openGL context 111 | * @param file - the masking texture file name 112 | * @return - success or failure 113 | */ 114 | boolean loadTexture(GL10 gl, String file) { 115 | try{ 116 | InputStream is = Globals.context.getAssets().open(file); 117 | int size = is.available(); 118 | byte[] buffer = new byte[size]; 119 | is.read(buffer, 0, size); 120 | is.close(); 121 | 122 | //Check if png or jpg 123 | BitmapFactory.Options opt = new BitmapFactory.Options(); 124 | opt.inDither = false; 125 | opt.inPreferredConfig = Bitmap.Config.ARGB_8888; 126 | 127 | Bitmap bitmap = BitmapFactory.decodeByteArray(buffer, 0, size, opt); 128 | 129 | //Generate one texture pointer 130 | GLES11.glGenTextures(1, glTexture, 0); 131 | // ...and bind it to our array 132 | GLES11.glBindTexture(GL10.GL_TEXTURE_2D, glTexture[0]); 133 | 134 | //Create nearest filtered texture 135 | GLES11.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); 136 | GLES11.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); 137 | GLES11.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE); 138 | GLES11.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE); 139 | 140 | //Use Android GLUtils to specify a two-dimensional texture image from our bitmap 141 | GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0); 142 | } 143 | catch(IOException IOerror) { 144 | return false; 145 | } 146 | return true; 147 | } 148 | 149 | /** 150 | * Resets the particle array 151 | */ 152 | public void initializeSystem() { 153 | particles.clear(); 154 | numParticles = 0; 155 | for(int i=0; i endSize.x? startSize.x:endSize.x; 295 | float sizey = startSize.y > endSize.y? startSize.y:endSize.y; 296 | 297 | //Calculate an effective radius for frustum culling 298 | if(radius > 0.0f) 299 | { 300 | rEff = sizex + radius + velocity.x*(lifeTime + lifeTimeVar); 301 | test = sizey + height/2.0f + velocity.z*(lifeTime + lifeTimeVar); 302 | if(test > rEff) 303 | test = rEff; 304 | } 305 | else 306 | { 307 | float size = (sizex > sizey)? sizex:sizey; 308 | float dim = (width > depth)? width:depth; 309 | dim = (dim > height)? dim:height; 310 | //By using the factor of 2.0, it helps to start the system before the camera fully gets around to it. 311 | rEff = 2.0f*(size + dim + velocity.length()*(lifeTime + lifeTimeVar)); 312 | } 313 | 314 | started = draw = true; 315 | if(duration == -1.0f) 316 | fixed = true; 317 | } 318 | 319 | /** 320 | * Moves the system if necessary. 321 | * Adjusts our particle array when emitting particles 322 | * 323 | * @param numParticlesToCreate - how many particles need to be created this frame 324 | * @param deltaTime - time increment since the last frame 325 | * @return 326 | */ 327 | protected void updateSystem(int numParticlesToCreate, float deltaTime) { 328 | //Create new particles 329 | origin.add(emitterVelocity.scaled(deltaTime)); 330 | 331 | emitterVelocity.add(emitterAcceleration.scaled(deltaTime)); 332 | while(numParticlesToCreate > 0 && numParticles < maxParticles) { 333 | InitializeParticle(numParticles++); 334 | --numParticlesToCreate; 335 | } 336 | } 337 | 338 | /** 339 | * Causes an immediate killing and reset of the system 340 | */ 341 | public void killSystem() { 342 | if(numParticles != 0) { 343 | particles.clear(); 344 | numParticles = 0; 345 | } 346 | } 347 | } 348 | -------------------------------------------------------------------------------- /Particles/src/com/kennethmaffei/particles/Quad.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2014 Kenneth Maffei 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | package com.kennethmaffei.particles; 18 | 19 | import java.io.IOException; 20 | import java.io.InputStream; 21 | import java.nio.ByteBuffer; 22 | import java.nio.ByteOrder; 23 | import java.nio.FloatBuffer; 24 | 25 | import javax.microedition.khronos.opengles.GL10; 26 | 27 | import android.graphics.Bitmap; 28 | import android.graphics.BitmapFactory; 29 | import android.opengl.GLES11; 30 | import android.opengl.GLUtils; 31 | 32 | /** 33 | * Representation and rendering of a quad 34 | * 35 | * @author Kenneth Maffei 36 | * 37 | */ 38 | public class Quad { 39 | private ByteBuffer vertexByteBuffer; 40 | private ByteBuffer textureByteBuffer; 41 | private FloatBuffer vertexBuffer; //Buffer holding the vertices 42 | 43 | public float transX; //X translation 44 | public float transY; //Y translation 45 | public float transZ; //Z translation 46 | 47 | public float scaleX = 1.0f; //X scale 48 | public float scaleY = 1.0f; //Y scale 49 | public float scaleZ = 1.0f; //Z scale 50 | 51 | public float rotateX = 0.0f; //X rotation 52 | public float rotateY = 0.0f; //Y rotation 53 | public float rotateZ = 0.0f; //Z rotation 54 | 55 | public float width; //start width 56 | public float height; //start height 57 | 58 | public boolean isParticle; //Are we a particle 59 | public boolean isFacingParticle; //Are we a facing particle, or just a regular quad 60 | 61 | //The current colors for the quad 62 | public float r = 1.0f; 63 | public float g = 1.0f; 64 | public float b = 1.0f; 65 | public float a = 1.0f; 66 | 67 | private float vertices[] = { 68 | 0.0f, 0.0f, 0.0f, // V1 - bottom left 69 | 0.0f, 0.0f, 0.0f, // V2 - top left 70 | 0.0f, 0.0f, 0.0f, // V3 - bottom right 71 | 0.0f, 0.0f, 0.0f // V4 - top right 72 | }; 73 | 74 | 75 | private FloatBuffer textureBuffer; // buffer holding the texture coordinates 76 | private float texture[] = { 77 | // Mapping coordinates for the vertices 78 | 0.0f, 1.0f, // top left (V2) 79 | 0.0f, 0.0f, // bottom left (V1) 80 | 1.0f, 1.0f, // top right (V4) 81 | 1.0f, 0.0f // bottom right (V3) 82 | }; 83 | 84 | 85 | /** The texture pointer */ 86 | public int[] glTexture = new int[1]; 87 | 88 | //Places the square at the center of the screen 89 | public Quad(float width, float height, Vector3 position) { 90 | transX = position.x; 91 | transY = position.y; 92 | transZ = position.z; 93 | 94 | this.width = width; 95 | this.height = height; 96 | 97 | vertices[0] = -width/2.0f; 98 | vertices[1] = -height/2.0f; 99 | vertices[3] = -width/2.0f; 100 | vertices[4] = height/2.0f; 101 | vertices[6] = width/2.0f; 102 | vertices[7] = -height/2.0f; 103 | vertices[9] = width/2.0f; 104 | vertices[10] = height/2.0f; 105 | 106 | vertexByteBuffer = ByteBuffer.allocateDirect(vertices.length * 4); 107 | vertexByteBuffer.order(ByteOrder.nativeOrder()); 108 | vertexBuffer = vertexByteBuffer.asFloatBuffer(); 109 | 110 | vertexBuffer.put(vertices); 111 | vertexBuffer.position(0); 112 | 113 | textureByteBuffer = ByteBuffer.allocateDirect(texture.length * 4); 114 | textureByteBuffer.order(ByteOrder.nativeOrder()); 115 | textureBuffer = textureByteBuffer.asFloatBuffer(); 116 | 117 | textureBuffer.put(texture); 118 | textureBuffer.position(0); 119 | 120 | glTexture[0] = -1; 121 | } 122 | 123 | public void update(float width, float height, Vector3 position) { 124 | transX = position.x; 125 | transY = position.y; 126 | transZ = position.z; 127 | 128 | this.width = width; 129 | this.height = height; 130 | 131 | scaleX = scaleY = 1.0f; 132 | 133 | vertices[0] = -width/2.0f; 134 | vertices[1] = -height/2.0f; 135 | vertices[3] = -width/2.0f; 136 | vertices[4] = height/2.0f; 137 | vertices[6] = width/2.0f; 138 | vertices[7] = -height/2.0f; 139 | vertices[9] = width/2.0f; 140 | vertices[10] = height/2.0f; 141 | 142 | vertexBuffer.put(vertices); 143 | vertexBuffer.position(0); 144 | 145 | textureBuffer.put(texture); 146 | textureBuffer.position(0); 147 | } 148 | 149 | /** 150 | * We will use the glTranslate and glScale during rendering rather than resetting the vertices 151 | * Updating the vertex buffers is too expensive an operation 152 | * 153 | * @param newWidth - updated width 154 | * @param newHeight - updated height 155 | * @param position - updated position; 156 | */ 157 | public void resetSize(float newWidth, float newHeight, Vector3 position) { 158 | transX = position.x; 159 | transY = position.y; 160 | transZ = position.z; 161 | 162 | scaleX = newWidth/width; 163 | scaleY = newHeight/height; 164 | } 165 | 166 | boolean loadTexture(GL10 gl, String file) { 167 | try{ 168 | InputStream is = Globals.context.getAssets().open(file); 169 | int size = is.available(); 170 | byte[] buffer = new byte[size]; 171 | is.read(buffer, 0, size); 172 | is.close(); 173 | 174 | //Check if png or jpg 175 | BitmapFactory.Options opt = new BitmapFactory.Options(); 176 | opt.inDither = false; 177 | if(file.indexOf(".png") > 0) 178 | opt.inPreferredConfig = Bitmap.Config.ARGB_8888; 179 | else 180 | opt.inPreferredConfig = Bitmap.Config.RGB_565; 181 | 182 | Bitmap bitmap = BitmapFactory.decodeByteArray(buffer, 0, size, opt); 183 | 184 | //Generate one texture pointer 185 | GLES11.glGenTextures(1, glTexture, 0); 186 | // ...and bind it to our array 187 | GLES11.glBindTexture(GL10.GL_TEXTURE_2D, glTexture[0]); 188 | 189 | //Create nearest filtered texture 190 | GLES11.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); 191 | GLES11.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); 192 | GLES11.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE); 193 | GLES11.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE); 194 | 195 | //Use Android GLUtils to specify a two-dimensional texture image from our bitmap 196 | GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0); 197 | } 198 | catch(IOException IOerror) { 199 | return false; 200 | } 201 | return true; 202 | } 203 | 204 | /** 205 | * If creating the texture externally, set it here 206 | * 207 | * @param tex 208 | */ 209 | public void setTexture(int tex) { 210 | glTexture[0] = tex; 211 | } 212 | 213 | /** The draw method for the square with the GL context */ 214 | public void draw(GL10 gl) { 215 | 216 | GLES11.glColor4f(r, g, b, a); 217 | 218 | GLES11.glPushMatrix(); 219 | 220 | GLES11.glTranslatef(transX, transY, transZ); 221 | 222 | if(!isParticle) { 223 | GLES11.glEnable(GLES11.GL_BLEND); 224 | GLES11.glTexEnvi(GLES11.GL_TEXTURE_ENV, GLES11.GL_TEXTURE_ENV_MODE, GLES11.GL_MODULATE); 225 | GLES11.glBlendFunc (GLES11.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA); 226 | 227 | GLES11.glBindTexture(GLES11.GL_TEXTURE_2D, glTexture[0]); 228 | } 229 | 230 | //If we are a facing particle, then we have to apply the billboard routine 231 | if(isFacingParticle) { 232 | if (Globals.thetaTest) 233 | GLES11.glRotatef((float)(Math.acos(Globals.theta)*180.0f/3.14f), Globals.upAux.x, Globals.upAux.y, Globals.upAux.z); 234 | 235 | if (Globals.phiTest) { 236 | if(Globals.billboardDirectionTest) 237 | GLES11.glRotatef((float) (Math.acos(Globals.phi)*180.0f/3.14f), 1, 0, 0); 238 | else 239 | GLES11.glRotatef((float) (Math.acos(Globals.phi)*180.0f/3.14f), -1,0, 0); 240 | } 241 | } 242 | else { 243 | GLES11.glRotatef(rotateZ, 0, 0, 1); 244 | GLES11.glRotatef(rotateY, 0, 1, 0); 245 | GLES11.glRotatef(rotateX, 1, 0, 0); 246 | } 247 | 248 | GLES11.glScalef(scaleX, scaleY, scaleZ); 249 | 250 | //Point to our vertex buffer 251 | GLES11.glVertexPointer(3, GLES11.GL_FLOAT, 0, vertexBuffer); 252 | GLES11.glTexCoordPointer(2, GLES11.GL_FLOAT, 0, textureBuffer); 253 | 254 | //Draw the vertices as triangle strip 255 | GLES11.glDrawArrays(GLES11.GL_TRIANGLE_STRIP, 0, vertices.length / 3); 256 | 257 | GLES11.glPopMatrix(); 258 | 259 | if(!isParticle) 260 | GLES11.glDisable(GLES11.GL_LIGHTING); 261 | } 262 | 263 | public void DeleteTexture() { 264 | if(glTexture[0] > -1) 265 | GLES11.glDeleteTextures(1, glTexture, 0); 266 | glTexture[0] = -1; 267 | } 268 | } 269 | -------------------------------------------------------------------------------- /Particles/src/com/kennethmaffei/particles/Vector3.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright 2014 Kenneth Maffei 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | *******************************************************************************/ 16 | 17 | package com.kennethmaffei.particles; 18 | 19 | /** 20 | * Class for a 3-Vector in 3D space 21 | * 22 | * @author Ken 23 | * 24 | */ 25 | public class Vector3 { 26 | public float x; 27 | public float y; 28 | public float z; 29 | 30 | /** 31 | * Constructors 32 | */ 33 | public Vector3() {}; 34 | public Vector3(float a, float b, float c) { 35 | x = a; 36 | y = b; 37 | z = c; 38 | } 39 | 40 | /** 41 | * Copies one Vector3's parameters into this one's 42 | * @param a 43 | */ 44 | public void copy(Vector3 a) { 45 | x = a.x; 46 | y = a.y; 47 | z = a.z; 48 | } 49 | 50 | /** 51 | * Subtract a Vector3 from this one 52 | * 53 | * @param a - the Vector3 to subtract 54 | */ 55 | public void subtract(Vector3 a) { 56 | x-= a.x; 57 | y-= a.y; 58 | z-= a.z; 59 | } 60 | 61 | /** 62 | * Adds a Vector3 to this one 63 | * 64 | * @param a - the Vector3 to add 65 | */ 66 | public void add(Vector3 a) { 67 | x+= a.x; 68 | y+= a.y; 69 | z+= a.z; 70 | } 71 | 72 | /** 73 | * Scales this Vector3 and returns a new scaled Vector3 74 | * 75 | * @param a - the scale factor 76 | * @return - the new vector 77 | */ 78 | public Vector3 scaled(float a) { 79 | Vector3 temp = new Vector3(); 80 | temp.copy(this); 81 | 82 | temp.x*= a; 83 | temp.y*= a; 84 | temp.z*= a; 85 | 86 | return temp; 87 | } 88 | 89 | /** 90 | * Returns the length of this Vector3 91 | * 92 | * @return - the length 93 | */ 94 | public float length() { 95 | return (float) Math.sqrt(x*x + y*y + z*z); 96 | } 97 | 98 | /** 99 | * Normalizes this Vector3 100 | * 101 | * @return - itself 102 | */ 103 | public Vector3 normalize() { 104 | float length = length(); 105 | 106 | if(length < 0.00001f) 107 | length = 1.0f; 108 | 109 | float invLength = 1.0f/length; 110 | 111 | x*= invLength; 112 | y*= invLength; 113 | z*= invLength; 114 | 115 | return this; 116 | } 117 | 118 | /** 119 | * Static function to calculate the dot product between two Vector3s 120 | * 121 | * @param a - the first Vector3 122 | * @param b - the second Vector3 123 | * @return - the dot product 124 | */ 125 | public static float dotProduct(Vector3 a, Vector3 b) { 126 | return (a.x*b.x + a.y*b.y + a.z*b.z); 127 | } 128 | 129 | /** 130 | * Static function to calculate the cross product between two Vector3s 131 | * 132 | * @param a - the first Vector3 133 | * @param b - the second Vector3 134 | * @return - the cross product 135 | */ 136 | public static Vector3 crossProduct(Vector3 a, Vector3 b) { 137 | Vector3 cp = new Vector3(); 138 | cp.x = (a.y*b.z - b.y*a.z); 139 | cp.y = (a.z*b.x - b.z*a.x); 140 | cp.z = (a.x*b.y - b.x*a.y); 141 | return cp; 142 | } 143 | 144 | @Override 145 | public boolean equals(Object obj) { 146 | if (!(obj instanceof Vector3)) 147 | return false; 148 | if (obj == this) 149 | return true; 150 | 151 | Vector3 compare = (Vector3)obj; 152 | if(x == compare.x && y == compare.y && z == compare.z) 153 | return true; 154 | return false; 155 | } 156 | 157 | public int hashCode(Object obj) { 158 | final int prime = 31; 159 | int result = 1; 160 | 161 | Float xf = Float.valueOf(x); 162 | result = prime + xf.hashCode(); 163 | Float yf = Float.valueOf(y); 164 | result = prime*result + yf.hashCode(); 165 | Float zf = Float.valueOf(z); 166 | result = prime*result + zf.hashCode(); 167 | 168 | return result; 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | opengl-particles 2 | ================ 3 | 4 | Android OpenGL Particle System 5 | 6 | This is an additive particle system which I adapted from my Ignition Game Engine (a c++ app for Windows). You can create effects like fire and smoke with this system. Each type of system is extended from the base ParticleSystem class. The demo has three subclasses: Generic, Fire and Black Smoke. The code uses OpenGLES11. At some point I'll update it for OpenGLES2. 7 | 8 | Additive particle systems are very useful, however you must be aware that they exhibit two limitation. The first is that they are not appropriate if constructed over white or very light backgrounds. This is due to the additive blending which will wash out the effect. The second issue is that very dark particle colors will not show up. This is a result of the color blending per particle against the transparency map that is used. You can google to see how some people have tried to ameliorate these problems, however, in most cases you don't need to worry about them too much. Usually you need to specify low values for the alpha components of the colors, since additive blending of large numbers of particles will result in white. 9 | 10 | Given the issue with dark particle colors, the black smoke system uses a different blending mode. The only point here is that the system is strictly black with no option to change it's color. 11 | 12 | Particles are planar objects in 3D space, so if the camera moves around the user will see that they are planes. Therefore a billboarding technique so that the particles always orient themselves towards the camera. You can find the billboarding technique used here: http://www.lighthouse3d.com/opengl/billboarding/ 13 | 14 | Some final notes. The transparency map should not be a 32 bit image with alpha. It should be a 24 bit jpg or other format readable by Android. Also, because of performance, your systems should be limited to a couple hundred particles or less. 15 | --------------------------------------------------------------------------------