├── .gitignore ├── .gitmodules ├── Collision ├── Sources │ ├── Main.hx │ └── Project.hx └── khafile.js ├── Forces ├── Sources │ ├── Main.hx │ └── Project.hx └── khafile.js ├── LICENSE ├── PolygonCollision ├── Sources │ ├── Main.hx │ └── Project.hx └── khafile.js ├── README.md ├── Shapes ├── Sources │ ├── Main.hx │ └── Project.hx └── khafile.js └── updateSubmodules.bat /.gitignore: -------------------------------------------------------------------------------- 1 | Shapes/build/ 2 | Collision/build/ 3 | PolygonCollision/build/ 4 | Forces/build/ 5 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Shapes/Libraries/verlet"] 2 | path = Shapes/Libraries/verlet 3 | url = https://github.com/Devination/VerletKha.git 4 | [submodule "Collision/Libraries/verlet"] 5 | path = Collision/Libraries/verlet 6 | url = https://github.com/Devination/VerletKha.git 7 | [submodule "PolgonCollision/Libraries/verlet"] 8 | path = PolgonCollision/Libraries/verlet 9 | url = https://github.com/Devination/VerletKha.git 10 | [submodule "PolygonCollision/Libraries/verlet"] 11 | path = PolygonCollision/Libraries/verlet 12 | url = https://github.com/Devination/VerletKha.git 13 | [submodule "Forces/Libraries/verlet"] 14 | path = Forces/Libraries/verlet 15 | url = https://github.com/Devination/VerletKha.git 16 | -------------------------------------------------------------------------------- /Collision/Sources/Main.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import kha.System; 4 | 5 | class Main { 6 | public static function main() { 7 | System.init({title: "Project", width: 800, height: 600}, function() { 8 | new Project(); 9 | }); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Collision/Sources/Project.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import kha.Framebuffer; 4 | import kha.Scheduler; 5 | import kha.System; 6 | import kha.math.Vector2; 7 | import verlet.Objects.Tire; 8 | import verlet.Verlet; 9 | import verlet.Renderer; 10 | import verlet.collision.Colliders; 11 | 12 | class Project { 13 | public function new() { 14 | System.notifyOnRender(render); 15 | Scheduler.addTimeTask(update, 0, 1 / 60); 16 | new Verlet(800, 600); 17 | 18 | // Entities 19 | new Tire(new Vector2(500,32), 64, 32, .05, .5); 20 | 21 | // Colliders 22 | new Circle(new Vector2(222, 200), 256); 23 | new Circle(new Vector2(666, 300), 128); 24 | new Circle(new Vector2(400, 600), 128); 25 | new Box(new Vector2(200, 200), 256, 80); 26 | } 27 | 28 | function update(): Void { 29 | Verlet._instance.update(10); 30 | } 31 | 32 | function render(framebuffer: Framebuffer): Void { 33 | var graphics = framebuffer.g2; 34 | graphics.begin(); 35 | Renderer._instance.renderAll(graphics); 36 | graphics.end(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Collision/khafile.js: -------------------------------------------------------------------------------- 1 | var project = new Project('New Project'); 2 | project.addAssets('Assets/**'); 3 | project.addSources('Sources'); 4 | project.addLibrary('verlet'); 5 | return project; 6 | -------------------------------------------------------------------------------- /Forces/Sources/Main.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import kha.System; 4 | 5 | class Main { 6 | public static function main() { 7 | System.init({title: "Project", width: 800, height: 600}, function() { 8 | new Project(); 9 | }); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Forces/Sources/Project.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import kha.Framebuffer; 4 | import kha.Scheduler; 5 | import kha.System; 6 | import kha.math.Vector2; 7 | import verlet.Objects.Tire; 8 | import verlet.Verlet; 9 | import verlet.Renderer; 10 | import verlet.collision.Colliders; 11 | import kha.Color; 12 | 13 | class Project { 14 | public function new() { 15 | System.notifyOnRender(render); 16 | Scheduler.addTimeTask(update, 0, 1 / 60); 17 | // Verlet World 18 | new Verlet(800, 600, true); 19 | Verlet._instance.gravity.y = 0; 20 | 21 | // Entities 22 | new Tire(new Vector2(100,128), 32, 7, .1, .3); 23 | 24 | // Colliders 25 | //small planet 26 | var circle = new Circle(new Vector2(100, 250), 50); 27 | circle = new Circle(new Vector2(100, 250), 250); 28 | circle.strength = -0.0001; 29 | circle.colliderColor = Color.fromBytes(118, 138, 183); 30 | //big planet 31 | circle = new Circle(new Vector2(800, 50), 100); 32 | circle = new Circle(new Vector2(800, 50), 450); 33 | circle.strength = -0.00015; 34 | circle.colliderColor = Color.fromBytes(118, 138, 183); 35 | //repulsor box 36 | var box = new Box(new Vector2(0, 500), 800, 200); 37 | box.strength = 0.001; 38 | box.colliderColor = Color.fromBytes(215, 105, 110); 39 | //repulsor poly 40 | var poly = new Polygon(new Vector2(0,0), [new Vector2(0,0),new Vector2(150,-200),new Vector2(300,0)]); 41 | poly.pos.x = 250; 42 | poly.pos.y = 500; 43 | poly.strength = 0.05; 44 | poly.colliderColor = Color.fromBytes(215, 105, 110); 45 | } 46 | 47 | function update(): Void { 48 | Verlet._instance.update(10); 49 | } 50 | 51 | var debug = true; 52 | function render(framebuffer: Framebuffer): Void { 53 | var graphics = framebuffer.g2; 54 | graphics.begin(); 55 | Renderer._instance.renderAll(graphics); 56 | graphics.color = Color.Red; 57 | debug = false; 58 | graphics.end(); 59 | } 60 | } -------------------------------------------------------------------------------- /Forces/khafile.js: -------------------------------------------------------------------------------- 1 | var project = new Project('New Project'); 2 | project.addAssets('Assets/**'); 3 | project.addSources('Sources'); 4 | project.addLibrary('verlet'); 5 | return project; 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Devin Curry 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /PolygonCollision/Sources/Main.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import kha.System; 4 | 5 | class Main { 6 | public static function main() { 7 | System.init({title: "Project", width: 800, height: 600}, function() { 8 | new Project(); 9 | }); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /PolygonCollision/Sources/Project.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import kha.Framebuffer; 4 | import kha.Scheduler; 5 | import kha.System; 6 | import kha.math.Vector2; 7 | import verlet.Objects.Tire; 8 | import verlet.Objects.Point; 9 | import verlet.Verlet; 10 | import verlet.Renderer; 11 | import verlet.collision.Colliders; 12 | import kha.Color; 13 | 14 | import kha.graphics2.Graphics; 15 | using kha.graphics2.GraphicsExtension; 16 | 17 | class Project { 18 | public function new() { 19 | System.notifyOnRender(render); 20 | Scheduler.addTimeTask(update, 0, 1 / 60); 21 | new Verlet(800, 600); 22 | 23 | // Entities 24 | var tire:Tire = new Tire(new Vector2(170,-32), 64, 32, .05, .5); 25 | 26 | // Colliders 27 | //Convex 28 | var poly = new Polygon(new Vector2(0, 0), [new Vector2(0, 0),new Vector2(100, -100), new Vector2(200, 0), new Vector2(150, 150), new Vector2(20, 100)]); 29 | poly.pos.x = 20; 30 | poly.pos.y = 300; 31 | //Concave 32 | poly = new Polygon ( 33 | new Vector2(0, 0), 34 | [ 35 | new Vector2(0, 0), 36 | new Vector2(0, -200), 37 | new Vector2(50, -200), 38 | new Vector2(150, -50), 39 | new Vector2(300, -200), 40 | new Vector2(350, -200), 41 | new Vector2(350, 100) 42 | ] 43 | ); 44 | //poly.renderNormals = true; 45 | poly.pos.x = 250; 46 | poly.pos.y = 550; 47 | 48 | } 49 | 50 | function update(): Void { 51 | Verlet._instance.update(10); 52 | } 53 | 54 | var debug = true; 55 | function render(framebuffer: Framebuffer): Void { 56 | var graphics = framebuffer.g2; 57 | graphics.begin(); 58 | Renderer._instance.renderAll(graphics); 59 | graphics.color = Color.Red; 60 | debug = false; 61 | graphics.end(); 62 | } 63 | } -------------------------------------------------------------------------------- /PolygonCollision/khafile.js: -------------------------------------------------------------------------------- 1 | var project = new Project('New Project'); 2 | project.addAssets('Assets/**'); 3 | project.addSources('Sources'); 4 | project.addLibrary('verlet'); 5 | return project; 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VerletKha-Examples 2 | Tech Demos for [VerletKha](https://github.com/Devination/VerletKha). 3 | 4 | ![Tire](https://lh4.googleusercontent.com/-4WirsEC5qfc/VxRRD9JEs0I/AAAAAAAAB0g/gzPgE0SglS0K7cKToBCsDB73RedfQivcwCL0B/w350-h282-no/VerletTire.gif) 5 | 6 | How to use 7 | -------- 8 | 1. Clone this repro 9 | 2. Use [Kode Studio](https://github.com/KTXSoftware/KodeStudio/releases) to open one of the sub-folders (ie Shapes/) 10 | 3. Build with Kode Studio 11 | 4. Play with the code, discover how things work 12 | -------------------------------------------------------------------------------- /Shapes/Sources/Main.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import kha.System; 4 | 5 | class Main { 6 | public static function main() { 7 | System.init({title: "Project", width: 800, height: 600}, function() { 8 | new Project(); 9 | }); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Shapes/Sources/Project.hx: -------------------------------------------------------------------------------- 1 | package; 2 | 3 | import kha.Framebuffer; 4 | import kha.Scheduler; 5 | import kha.System; 6 | import kha.math.Vector2; 7 | import verlet.Objects.Tire; 8 | import verlet.Objects.LineSegments; 9 | import verlet.Verlet; 10 | import verlet.Renderer; 11 | 12 | class Project { 13 | 14 | public function new() { 15 | System.notifyOnRender(render); 16 | Scheduler.addTimeTask(update, 0, 1 / 60); 17 | new Verlet(800, 600); 18 | 19 | // Entities 20 | var segment = new LineSegments([new Vector2(20,10), new Vector2(40,10), new Vector2(60,10), new Vector2(80,10), new Vector2(100,10)], 0.02, [0,4]); 21 | 22 | new Tire(new Vector2(100,128), 64, 7, .1, .3); 23 | new Tire(new Vector2(350,64), 64, 32, .03, .5); 24 | new Tire(new Vector2(600,32), 50, 4, .2, .7); 25 | } 26 | 27 | function update(): Void { 28 | Verlet._instance.update(10); 29 | } 30 | 31 | function render(framebuffer: Framebuffer): Void { 32 | var graphics = framebuffer.g2; 33 | graphics.begin(); 34 | Renderer._instance.renderAll(graphics); 35 | graphics.end(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Shapes/khafile.js: -------------------------------------------------------------------------------- 1 | var project = new Project('New Project'); 2 | project.addAssets('Assets/**'); 3 | project.addSources('Sources'); 4 | project.addLibrary('verlet'); 5 | return project; 6 | -------------------------------------------------------------------------------- /updateSubmodules.bat: -------------------------------------------------------------------------------- 1 | git submodule foreach --recursive git checkout master && git submodule foreach --recursive git pull origin master --------------------------------------------------------------------------------