├── .gitignore ├── LICENSE ├── README.md ├── actions ├── lua │ └── main.lua └── main.cpp ├── billboard ├── assets │ ├── ely_hills │ │ ├── ely_hills.shader │ │ ├── hills_bk.tga │ │ ├── hills_dn.tga │ │ ├── hills_ft.tga │ │ ├── hills_lf.tga │ │ ├── hills_rt.tga │ │ ├── hills_up.tga │ │ └── readme │ ├── ground.png │ └── tree_08_10000.png └── main.cpp ├── car ├── assets │ ├── ely_hills │ │ ├── ely_hills.shader │ │ ├── hills_bk.tga │ │ ├── hills_dn.tga │ │ ├── hills_ft.tga │ │ ├── hills_lf.tga │ │ ├── hills_rt.tga │ │ ├── hills_up.tga │ │ └── readme │ ├── engine.wav │ ├── jeep │ │ ├── Jeep.mtl │ │ ├── Jeep.obj │ │ ├── Jeep_glass_d.tga │ │ ├── Jeep_inside_d.tga │ │ └── Jeep_outside_d.tga │ ├── old-house │ │ ├── old-house.mtl │ │ ├── old-house.obj │ │ └── old-house.png │ └── road.png ├── lua │ └── main.lua └── main.cpp ├── events └── main.cpp ├── lines └── main.cpp ├── mirror ├── assets │ ├── WaterBottle.glb │ ├── ely_hills │ │ ├── ely_hills.shader │ │ ├── hills_bk.tga │ │ ├── hills_dn.tga │ │ ├── hills_ft.tga │ │ ├── hills_lf.tga │ │ ├── hills_rt.tga │ │ ├── hills_up.tga │ │ └── readme │ └── ground.png ├── lua │ └── main.lua └── main.cpp ├── morph_targets ├── assets │ ├── AnimatedMorphCube.bin │ ├── AnimatedMorphCube.gltf │ ├── ely_hills │ │ ├── ely_hills.shader │ │ ├── hills_bk.tga │ │ ├── hills_dn.tga │ │ ├── hills_ft.tga │ │ ├── hills_lf.tga │ │ ├── hills_rt.tga │ │ ├── hills_up.tga │ │ └── readme │ └── ground.png ├── lua │ └── main.lua └── main.cpp ├── offscreen ├── assets │ ├── ely_hills │ │ ├── ely_hills.shader │ │ ├── hills_bk.tga │ │ ├── hills_dn.tga │ │ ├── hills_ft.tga │ │ ├── hills_lf.tga │ │ ├── hills_rt.tga │ │ ├── hills_up.tga │ │ └── readme │ ├── jeep │ │ ├── Jeep.mtl │ │ ├── Jeep.obj │ │ ├── Jeep_glass_d.tga │ │ ├── Jeep_inside_d.tga │ │ └── Jeep_outside_d.tga │ ├── old-house │ │ ├── old-house.mtl │ │ ├── old-house.obj │ │ └── old-house.png │ └── road.png └── main.cpp ├── particles ├── assets │ └── explosion.png ├── lua │ └── main.lua └── main.cpp ├── particles3d_and_instances ├── assets │ ├── CommonTree_1.mtl │ ├── CommonTree_1.obj │ ├── ely_hills │ │ ├── ely_hills.shader │ │ ├── hills_bk.tga │ │ ├── hills_dn.tga │ │ ├── hills_ft.tga │ │ ├── hills_lf.tga │ │ ├── hills_rt.tga │ │ ├── hills_up.tga │ │ └── readme │ ├── ground.png │ └── particle.png └── main.cpp ├── persistence ├── assets │ ├── Button_Disable.png │ ├── Button_Normal.png │ └── Button_Press.png ├── lua │ └── main.lua └── main.cpp ├── physics2d ├── assets │ ├── SoccerBall.png │ └── crate.png └── main.cpp ├── physics3d ├── assets │ ├── block.png │ ├── ely_hills │ │ ├── ely_hills.shader │ │ ├── hills_bk.tga │ │ ├── hills_dn.tga │ │ ├── hills_ft.tga │ │ ├── hills_lf.tga │ │ ├── hills_rt.tga │ │ ├── hills_up.tga │ │ └── readme │ └── ground.png └── main.cpp ├── physics3d_terrain ├── assets │ ├── block.png │ ├── ground.png │ └── heightmap.png └── main.cpp ├── shapes ├── assets │ └── block.png ├── lua │ └── main.lua └── main.cpp ├── simple_triangle ├── lua │ └── main.lua └── main.cpp ├── skeletal_animation ├── assets │ ├── CesiumMan.glb │ ├── ely_hills │ │ ├── ely_hills.shader │ │ ├── hills_bk.tga │ │ ├── hills_dn.tga │ │ ├── hills_ft.tga │ │ ├── hills_lf.tga │ │ ├── hills_rt.tga │ │ ├── hills_up.tga │ │ └── readme │ └── ground.png ├── lua │ └── main.lua └── main.cpp ├── sprites ├── assets │ └── dino.png ├── lua │ └── main.lua └── main.cpp ├── terrain ├── assets │ ├── blendmap.png │ ├── block.png │ ├── ground.png │ └── heightmap.png ├── lua │ └── main.lua └── main.cpp ├── tilemap ├── assets │ ├── bg │ │ └── BG.png │ ├── object │ │ ├── Bush (1).png │ │ ├── Bush (2).png │ │ ├── Bush (3).png │ │ ├── Bush (4).png │ │ ├── Crate.png │ │ ├── Mushroom_1.png │ │ ├── Mushroom_2.png │ │ ├── Sign_1.png │ │ ├── Sign_2.png │ │ ├── Stone.png │ │ ├── Tree_1.png │ │ ├── Tree_2.png │ │ └── Tree_3.png │ └── tiles │ │ ├── tileset1.png │ │ └── tileset2.png ├── lua │ └── main.lua └── main.cpp ├── user_interface ├── assets │ ├── button_disable.png │ ├── button_normal.png │ ├── paper_icon.png │ ├── textedit.png │ ├── tile.png │ └── window.png └── main.cpp └── user_interface_3d ├── assets ├── ely_hills │ ├── ely_hills.shader │ ├── hills_bk.tga │ ├── hills_dn.tga │ ├── hills_ft.tga │ ├── hills_lf.tga │ ├── hills_rt.tga │ ├── hills_up.tga │ └── readme ├── ground.png ├── paper_icon.png └── textedit.png └── main.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # --OSX-- 2 | 3 | *.DS_Store 4 | .AppleDouble 5 | .LSOverride 6 | 7 | # Icon must end with two \r 8 | Icon 9 | 10 | # Visual Studio Code 11 | .vscode 12 | 13 | # Thumbnails 14 | ._* 15 | 16 | # Files that might appear in the root of a volume 17 | .DocumentRevisions-V100 18 | .fseventsd 19 | .Spotlight-V100 20 | .TemporaryItems 21 | .Trashes 22 | .VolumeIcon.icns 23 | .com.apple.timemachine.donotpresent 24 | 25 | # Directories potentially created on remote AFP share 26 | .AppleDB 27 | .AppleDesktop 28 | Network Trash Folder 29 | Temporary Items 30 | .apdisk 31 | 32 | 33 | #--Windows-- 34 | 35 | # Windows image file caches 36 | Thumbs.db 37 | ehthumbs.db 38 | 39 | # Folder config file 40 | Desktop.ini 41 | 42 | # Recycle Bin used on file shares 43 | $RECYCLE.BIN/ 44 | 45 | # Windows Installer files 46 | *.cab 47 | *.msi 48 | *.msm 49 | *.msp 50 | 51 | # Windows shortcuts 52 | *.lnk 53 | 54 | # --LINUNX-- 55 | 56 | 57 | *~ 58 | 59 | # temporary files which can be created if a process still has a handle open of a deleted file 60 | .fuse_hidden* 61 | 62 | # KDE directory preferences 63 | .directory 64 | 65 | # Linux trash folder which might appear on any partition or disk 66 | .Trash-* 67 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2024 Eduardo Doria Lima 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Supernova Engine's samples 2 | 3 | This repository contains samples projects of [Supernova Engine's website](http://supernovaengine.org) 4 | 5 | ## Third-party assets 6 | 7 | * Ely_hills (sky box) by Colin Lowndes - GPLv2 8 | * Jeep (model) by http://www.cadnav.com/3d-models/model-42033.html - Free (Personal and Commercial) 9 | * Old house (model) by https://123free3dmodels.com/old-house-3-9702 - Free Personal Use Only 10 | * Animated Morph Cube by Microsoft (https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/AnimatedMorphCube) - Public Domain 11 | * Cesium Man by Cesium (https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/CesiumMan) - CC 4.0 12 | * Water Bottle (https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/WaterBottle) - Public Domain 13 | * Cute Dino (https://www.gameart2d.com/free-dino-sprites.html) - Public Domain 14 | * Motorcycle engine working (https://mixkit.co/free-sound-effects/engine/) - Mixkit License 15 | * Tiny Texture Pack (https://screamingbrainstudios.itch.io/tiny-texture-pack) - Public Domain 16 | * Tree Collection v2.6 (https://opengameart.org/content/tree-collection-v26-bleeds-game-art) - CC-BY 3.0 17 | * Free platformer game tileset (https://pzuh.itch.io/free-platformer-tileset) - Free without license 18 | * Crate (https://opengameart.org/content/3-crate-textures-w-bump-normal) - Public Domain 19 | * Soccer ball (https://opengameart.org/content/soccer-ball) - Public Domain 20 | * Explosion Particle Sprite - (https://opengameart.org/content/explosion-particles-sprite-atlas) - Public Domain 21 | * CommonTree - (https://quaternius.itch.io/150-lowpoly-nature-models) - CC0 1.0 Universal -------------------------------------------------------------------------------- /actions/lua/main.lua: -------------------------------------------------------------------------------- 1 | scene = Scene() 2 | 3 | text = Text(scene) 4 | 5 | polygon = MeshPolygon(scene) 6 | polygon2 = MeshPolygon(scene) 7 | polygon3 = Polygon(scene) 8 | polygon4 = Polygon(scene) 9 | 10 | positionaction = PositionAction(scene) 11 | rotationaction = RotationAction(scene) 12 | scaleaction = ScaleAction(scene) 13 | coloraction = ColorAction(scene) 14 | alphaaction = AlphaAction(scene) 15 | timedaction = TimedAction(scene) 16 | 17 | 18 | function onActionStep() 19 | angle = math.pi * 2.0 * timedaction:getValue() 20 | polygon4:setPosition(math.cos(angle)*100 + 450, math.sin(angle)*100 + 300, 0); 21 | end 22 | 23 | function onActionStart() 24 | Log.verbose("Rotation action start") 25 | end 26 | 27 | function onTouchStart(pointer, x, y) 28 | positionaction:start() 29 | rotationaction:start() 30 | scaleaction:start() 31 | coloraction:start() 32 | alphaaction:start() 33 | timedaction:start() 34 | end 35 | 36 | 37 | text.text = "Click on screen to start" 38 | text.anchorPreset = AnchorPreset.CENTER_TOP 39 | 40 | polygon:addVertex(0, 0); 41 | polygon:addVertex(100, 0); 42 | polygon:addVertex(0, 100); 43 | polygon:addVertex(100, 100); 44 | polygon:setColor(1.0, 0.3, 0.8, 1.0); 45 | polygon:setPosition(50, 50, 0); 46 | polygon.name = "Polygon1"; 47 | 48 | polygon2:addVertex(0, 0) 49 | polygon2:addVertex(100, 0) 50 | polygon2:addVertex(0, 100) 51 | polygon2:addVertex(100, 100) 52 | polygon2:setColor(1.0, 0.5, 1.0, 1.0) 53 | polygon2:setPosition(450, 50, 0) 54 | polygon2.name = "Polygon2" 55 | 56 | polygon3:addVertex(0, 0) 57 | polygon3:addVertex(100, 0) 58 | polygon3:addVertex(0, 100) 59 | polygon3:addVertex(100, 100) 60 | polygon3:setColor(0.5, 1.0, 1.0, 1.0) 61 | polygon3:setPosition(800, 50, 0) 62 | polygon3.name = "Polygon3" 63 | 64 | polygon4:addVertex(0, 0) 65 | polygon4:addVertex(100, 0) 66 | polygon4:addVertex(0, 100) 67 | polygon4:addVertex(100, 100) 68 | polygon4:setColor(0.5, 1.0, 0.3, 1.0) 69 | polygon4:setPosition(450, 300, 0) 70 | polygon4.name = "Polygon4" 71 | 72 | polygon2:moveToTop(); 73 | 74 | startRot = Quaternion() 75 | endRot = Quaternion() 76 | startRot:fromAngle(Angle.degToDefault(0)) 77 | endRot:fromAngle(Angle.degToDefault(180)) 78 | rotationaction:setAction(startRot, endRot, 5, false) 79 | rotationaction.target = polygon3.entity 80 | rotationaction:getActionComponent().onStart = onActionStart 81 | 82 | scaleaction:setAction(Vector3(1,1,1), Vector3(2,2,2), 10, false) 83 | scaleaction.target = polygon2.entity 84 | 85 | coloraction:setAction(polygon.color, Vector4(0.0, 0.0, 1.0, 1.0), 5, false) 86 | coloraction.target = polygon.entity 87 | 88 | alphaaction:setAction(1.0, 0.3, 5, false) 89 | alphaaction.target = polygon2.entity 90 | 91 | positionaction:setAction(Vector3(20,20,0), Vector3(200,200,0), 5, true) 92 | positionaction.target = polygon.entity 93 | positionaction:setFunctionType(EaseType.ELASTIC_IN_OUT) 94 | positionaction.speed = 1 95 | 96 | timedaction.duration = 10 97 | timedaction:getActionComponent().onStep = onActionStep; 98 | 99 | Engine.setScene(scene) 100 | Engine.setCallTouchInMouseEvent(true) 101 | 102 | Engine.onTouchStart = onTouchStart -------------------------------------------------------------------------------- /actions/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Supernova.h" 2 | using namespace Supernova; 3 | 4 | Scene scene; 5 | 6 | Text text(&scene); 7 | 8 | MeshPolygon polygon(&scene); 9 | MeshPolygon polygon2(&scene); 10 | Polygon polygon3(&scene); 11 | Polygon polygon4(&scene); 12 | 13 | TimedAction timedaction(&scene); 14 | PositionAction positionaction(&scene); 15 | RotationAction rotationaction(&scene); 16 | ScaleAction scaleaction(&scene); 17 | ColorAction coloraction(&scene); 18 | AlphaAction alphaaction(&scene); 19 | 20 | void onActionStep(); 21 | void onActionStart(); 22 | void onTouchStart(int pointer, float x, float y); 23 | 24 | void init(){ 25 | 26 | text.setText("Click on screen to start"); 27 | text.setAnchorPreset(AnchorPreset::CENTER_TOP); 28 | 29 | polygon.addVertex(0, 0); 30 | polygon.addVertex(100, 0); 31 | polygon.addVertex(0, 100); 32 | polygon.addVertex(100, 100); 33 | polygon.setColor(1.0, 0.3, 0.8, 1.0); 34 | polygon.setPosition(50, 50, 0); 35 | polygon.setName("Polygon1"); 36 | 37 | polygon2.addVertex(0, 0); 38 | polygon2.addVertex(100, 0); 39 | polygon2.addVertex(0, 100); 40 | polygon2.addVertex(100, 100); 41 | polygon2.setColor(1.0, 0.5, 1.0, 1.0); 42 | polygon2.setPosition(450, 50, 0); 43 | polygon2.setName("Polygon2"); 44 | 45 | polygon3.addVertex(0, 0); 46 | polygon3.addVertex(100, 0); 47 | polygon3.addVertex(0, 100); 48 | polygon3.addVertex(100, 100); 49 | polygon3.setColor(0.5, 1.0, 1.0, 1.0); 50 | polygon3.setPosition(800, 50, 0); 51 | polygon3.setName("Polygon3"); 52 | 53 | polygon4.addVertex(0, 0); 54 | polygon4.addVertex(100, 0); 55 | polygon4.addVertex(0, 100); 56 | polygon4.addVertex(100, 100); 57 | polygon4.setColor(0.5, 1.0, 0.3, 1.0); 58 | polygon4.setPosition(450, 300, 0); 59 | polygon4.setName("Polygon4"); 60 | 61 | polygon2.moveToTop(); 62 | 63 | Quaternion startRot; 64 | Quaternion endRot; 65 | startRot.fromAngle(Angle::degToDefault(0)); 66 | endRot.fromAngle(Angle::degToDefault(180)); 67 | rotationaction.setAction(startRot, endRot, 5, false); 68 | rotationaction.setTarget(polygon3.getEntity()); 69 | timedaction.getComponent().onStart = onActionStart; 70 | 71 | scaleaction.setAction(Vector3(1,1,1), Vector3(2,2,2), 10, false); 72 | scaleaction.setTarget(polygon2.getEntity()); 73 | 74 | coloraction.setAction(polygon.getColor(), Vector4(0.0, 0.0, 1.0, 1.0), 5, false); 75 | coloraction.setTarget(polygon.getEntity()); 76 | 77 | alphaaction.setAction(1.0, 0.2, 5, false); 78 | alphaaction.setTarget(polygon2.getEntity()); 79 | 80 | positionaction.setAction(Vector3(20,20,0), Vector3(200,200,0), 5, true); 81 | positionaction.setTarget(polygon.getEntity()); 82 | positionaction.setFunctionType(EaseType::ELASTIC_IN_OUT); 83 | positionaction.setSpeed(1); 84 | 85 | timedaction.setDuration(10); 86 | timedaction.getComponent().onStep = onActionStep; 87 | 88 | Engine::setScene(&scene); 89 | Engine::setCallTouchInMouseEvent(true); 90 | 91 | Engine::onTouchStart = onTouchStart; 92 | } 93 | 94 | void onTouchStart(int pointer, float x, float y) { 95 | positionaction.start(); 96 | rotationaction.start(); 97 | scaleaction.start(); 98 | coloraction.start(); 99 | alphaaction.start(); 100 | timedaction.start(); 101 | } 102 | 103 | void onActionStep(){ 104 | float angle = M_PI * 2.0 * timedaction.getValue(); 105 | polygon4.setPosition(cos(angle)*100 + 450, sin(angle)*100 + 300, 0); 106 | } 107 | 108 | void onActionStart(){ 109 | Log::verbose("Rotation action Start"); 110 | } -------------------------------------------------------------------------------- /billboard/assets/ely_hills/ely_hills.shader: -------------------------------------------------------------------------------- 1 | // Direction & elevation checked and adjusted - Speaker 2 | 3 | textures/skies/ely_hills 4 | { 5 | qer_editorimage env/ely_hills/hills_ft.tga 6 | surfaceparm noimpact 7 | surfaceparm nolightmap 8 | q3map_globaltexture 9 | q3map_lightsubdivide 256 10 | surfaceparm sky 11 | q3map_surfacelight 200 12 | q3map_sun 1 1 1 200 25 40 13 | skyparms env/ely_hills/hills - - 14 | } 15 | -------------------------------------------------------------------------------- /billboard/assets/ely_hills/hills_bk.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/billboard/assets/ely_hills/hills_bk.tga -------------------------------------------------------------------------------- /billboard/assets/ely_hills/hills_dn.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/billboard/assets/ely_hills/hills_dn.tga -------------------------------------------------------------------------------- /billboard/assets/ely_hills/hills_ft.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/billboard/assets/ely_hills/hills_ft.tga -------------------------------------------------------------------------------- /billboard/assets/ely_hills/hills_lf.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/billboard/assets/ely_hills/hills_lf.tga -------------------------------------------------------------------------------- /billboard/assets/ely_hills/hills_rt.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/billboard/assets/ely_hills/hills_rt.tga -------------------------------------------------------------------------------- /billboard/assets/ely_hills/hills_up.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/billboard/assets/ely_hills/hills_up.tga -------------------------------------------------------------------------------- /billboard/assets/ely_hills/readme: -------------------------------------------------------------------------------- 1 | These sky boxes have been downloaded from http://www.3delyvisions.com. They were produced by Colin Lowndes using a properly licensed copy of TerraGen. The author granted permission to distribute these sky boxes under the GNU General Public License version 2. Thanks, Colin! 2 | 3 | I (Laszlo Menczel aka Speaker) converted the textures to TGA format and resized the ones not conforming to the power-of-two texture size rule of Quake3. Also renamed the textures to conform to the name conventions of sky boxes in Quake3 (i.e. using the postfixes _bk, _ft, _lf, _rt and _up). The original boxes did not have 'down' textures. I made a 512x512 neutral grey image and added copies of this to each sky box as a fake 'down' texture. 4 | -------------------------------------------------------------------------------- /billboard/assets/ground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/billboard/assets/ground.png -------------------------------------------------------------------------------- /billboard/assets/tree_08_10000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/billboard/assets/tree_08_10000.png -------------------------------------------------------------------------------- /billboard/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Supernova.h" 2 | 3 | using namespace Supernova; 4 | 5 | void onUpdate(); 6 | void onKeyDown(int key, bool repeat, int mods); 7 | void onTouchStart(int pointer, float x, float y); 8 | void onTouchMove(int pointer, float x, float y); 9 | 10 | Vector2 lastTouchPos; 11 | 12 | 13 | Scene scene; 14 | 15 | Camera camera(&scene); 16 | Shape terrain(&scene); 17 | SkyBox sky(&scene); 18 | Light* sun = NULL; 19 | 20 | Sprite tree1(&scene); 21 | Text text1(&scene); 22 | 23 | Sprite tree2(&scene); 24 | Text text2(&scene); 25 | 26 | void init(){ 27 | scene.setGlobalIllumination(0.1); 28 | scene.setCamera(camera.getEntity()); 29 | 30 | camera.setPosition(0, 7, -40); 31 | 32 | terrain.createPlane(200, 200); 33 | terrain.setTexture("ground.png"); 34 | 35 | tree1.setTexture("tree_08_10000.png"); 36 | tree1.setBillboard(true, false, true); 37 | tree1.setScale(0.1); 38 | tree1.setPosition(10,0,0); 39 | tree1.setSize(100,100); 40 | tree1.setPivotPreset(PivotPreset::BOTTOM_CENTER); 41 | tree1.addChild(&text1); 42 | 43 | text1.setText("True billboard"); 44 | text1.setScale(0.5); 45 | text1.setPivotCentered(true); 46 | text1.setPosition(0,100,0); 47 | 48 | tree2.setTexture("tree_08_10000.png"); 49 | tree2.setBillboard(true); 50 | tree2.setCylindricalBillboard(true); 51 | tree2.setScale(0.1); 52 | tree2.setPosition(-10,0,0); 53 | tree2.setSize(100,100); 54 | tree2.setPivotPreset(PivotPreset::BOTTOM_CENTER); 55 | tree2.addChild(&text2); 56 | 57 | text2.setBillboard(true); 58 | text2.setText("Fake billboard"); 59 | text2.setScale(0.5); 60 | text2.setPivotCentered(true); 61 | text2.setPosition(0,100,0); 62 | 63 | sky.setTextureFront("ely_hills/hills_lf.tga"); 64 | sky.setTextureBack("ely_hills/hills_rt.tga"); 65 | sky.setTextureLeft("ely_hills/hills_bk.tga"); 66 | sky.setTextureRight("ely_hills/hills_ft.tga"); 67 | sky.setTextureUp("ely_hills/hills_up.tga"); 68 | sky.setTextureDown("ely_hills/hills_dn.tga"); 69 | 70 | if (!sun) 71 | sun = new Light(&scene); 72 | sun->setType(LightType::DIRECTIONAL); 73 | sun->setDirection(0,-0.7, 0.8); 74 | sun->setIntensity(10); 75 | sun->setShadows(true); 76 | 77 | Engine::setScene(&scene); 78 | Engine::setCallTouchInMouseEvent(true); 79 | 80 | Engine::onUpdate = onUpdate; 81 | Engine::onKeyDown = onKeyDown; 82 | Engine::onTouchStart = onTouchStart; 83 | Engine::onTouchMove = onTouchMove; 84 | } 85 | 86 | void onUpdate(){ 87 | if (Input::isKeyPressed(S_KEY_UP) || Input::isKeyPressed(S_KEY_W)){ 88 | camera.walkForward(1); 89 | }else if (Input::isKeyPressed(S_KEY_DOWN) || Input::isKeyPressed(S_KEY_S)){ 90 | camera.walkForward(-1); 91 | } 92 | 93 | if (Input::isKeyPressed(S_KEY_A)){ 94 | camera.slide(-1); 95 | }else if (Input::isKeyPressed(S_KEY_D)){ 96 | camera.slide(1); 97 | } 98 | 99 | if (Input::isKeyPressed(S_KEY_LEFT)){ 100 | camera.rotateView(2); 101 | }else if (Input::isKeyPressed(S_KEY_RIGHT)){ 102 | camera.rotateView(-2); 103 | } 104 | } 105 | 106 | void onKeyDown(int key, bool repeat, int mods){ 107 | //model.getAnimation(0).start(); 108 | } 109 | 110 | void onTouchMove(int pointer, float x, float y){ 111 | float difX = lastTouchPos.x - x; 112 | float difY = lastTouchPos.y - y; 113 | lastTouchPos = Vector2(x, y); 114 | 115 | camera.rotateView(0.1 * difX); 116 | camera.elevateView(0.1 * difY); 117 | } 118 | 119 | void onTouchStart(int pointer, float x, float y){ 120 | lastTouchPos = Vector2(x, y); 121 | } 122 | -------------------------------------------------------------------------------- /car/assets/ely_hills/ely_hills.shader: -------------------------------------------------------------------------------- 1 | // Direction & elevation checked and adjusted - Speaker 2 | 3 | textures/skies/ely_hills 4 | { 5 | qer_editorimage env/ely_hills/hills_ft.tga 6 | surfaceparm noimpact 7 | surfaceparm nolightmap 8 | q3map_globaltexture 9 | q3map_lightsubdivide 256 10 | surfaceparm sky 11 | q3map_surfacelight 200 12 | q3map_sun 1 1 1 200 25 40 13 | skyparms env/ely_hills/hills - - 14 | } 15 | -------------------------------------------------------------------------------- /car/assets/ely_hills/hills_bk.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/car/assets/ely_hills/hills_bk.tga -------------------------------------------------------------------------------- /car/assets/ely_hills/hills_dn.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/car/assets/ely_hills/hills_dn.tga -------------------------------------------------------------------------------- /car/assets/ely_hills/hills_ft.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/car/assets/ely_hills/hills_ft.tga -------------------------------------------------------------------------------- /car/assets/ely_hills/hills_lf.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/car/assets/ely_hills/hills_lf.tga -------------------------------------------------------------------------------- /car/assets/ely_hills/hills_rt.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/car/assets/ely_hills/hills_rt.tga -------------------------------------------------------------------------------- /car/assets/ely_hills/hills_up.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/car/assets/ely_hills/hills_up.tga -------------------------------------------------------------------------------- /car/assets/ely_hills/readme: -------------------------------------------------------------------------------- 1 | These sky boxes have been downloaded from http://www.3delyvisions.com. They were produced by Colin Lowndes using a properly licensed copy of TerraGen. The author granted permission to distribute these sky boxes under the GNU General Public License version 2. Thanks, Colin! 2 | 3 | I (Laszlo Menczel aka Speaker) converted the textures to TGA format and resized the ones not conforming to the power-of-two texture size rule of Quake3. Also renamed the textures to conform to the name conventions of sky boxes in Quake3 (i.e. using the postfixes _bk, _ft, _lf, _rt and _up). The original boxes did not have 'down' textures. I made a 512x512 neutral grey image and added copies of this to each sky box as a fake 'down' texture. 4 | -------------------------------------------------------------------------------- /car/assets/engine.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/car/assets/engine.wav -------------------------------------------------------------------------------- /car/assets/jeep/Jeep.mtl: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | newmtl Jeep_glass 4 | Ns 96.078431 5 | Ka 0.000000 0.000000 0.000000 6 | Kd 0.640000 0.640000 0.640000 7 | Ks 0.500000 0.500000 0.500000 8 | Ni 1.000000 9 | d 0.000000 10 | illum 2 11 | map_Kd Jeep_glass_d.tga 12 | 13 | 14 | newmtl Jeep_outside 15 | Ns 96.078431 16 | Ka 0.000000 0.000000 0.000000 17 | Kd 0.640000 0.640000 0.640000 18 | Ks 0.000000 0.000000 0.000000 19 | Ni 1.000000 20 | d 1.000000 21 | illum 1 22 | map_Kd Jeep_outside_d.tga 23 | 24 | 25 | newmtl Jeep_inside 26 | Ns 96.078431 27 | Ka 0.000000 0.000000 0.000000 28 | Kd 0.640000 0.640000 0.640000 29 | Ks 0.000000 0.000000 0.000000 30 | Ni 1.000000 31 | d 1.000000 32 | illum 1 33 | map_Kd Jeep_inside_d.tga 34 | 35 | 36 | -------------------------------------------------------------------------------- /car/assets/jeep/Jeep_glass_d.tga: -------------------------------------------------------------------------------- 1 |  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& -------------------------------------------------------------------------------- /car/assets/jeep/Jeep_inside_d.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/car/assets/jeep/Jeep_inside_d.tga -------------------------------------------------------------------------------- /car/assets/jeep/Jeep_outside_d.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/car/assets/jeep/Jeep_outside_d.tga -------------------------------------------------------------------------------- /car/assets/old-house/old-house.mtl: -------------------------------------------------------------------------------- 1 | # 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware 2 | # File Created: 09.04.2016 18:26:18 3 | 4 | newmtl SAN_RUMAHGEN05 5 | Ns 9.999999 6 | Ni 1.500000 7 | d 1.000000 8 | Tr 0.000000 9 | Tf 1.000000 1.000000 1.000000 10 | illum 2 11 | Ka 0.588235 0.588235 0.588235 12 | Kd 0.588235 0.588235 0.588235 13 | Ks 0.000000 0.000000 0.000000 14 | Ke 0.000000 0.000000 0.000000 15 | map_Ka old-house.png 16 | map_Kd old-house.png 17 | -------------------------------------------------------------------------------- /car/assets/old-house/old-house.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/car/assets/old-house/old-house.png -------------------------------------------------------------------------------- /car/assets/road.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/car/assets/road.png -------------------------------------------------------------------------------- /car/lua/main.lua: -------------------------------------------------------------------------------- 1 | scene = Scene() 2 | uiscene = Scene() 3 | 4 | camera = Camera(scene) 5 | terrain = Shape(scene) 6 | car = Model(scene) 7 | house = Model(scene) 8 | sky = SkyBox(scene) 9 | carengine = Audio(scene) 10 | fog = Fog(scene) 11 | 12 | text = Text(uiscene) 13 | 14 | curve = 0 15 | speed = 0 16 | rotation = 0 17 | 18 | up, down, left, right = false 19 | 20 | function onUpdate() 21 | 22 | text.text = tostring(Engine.framerate) 23 | 24 | if (Input.isKeyPressed(Input.KEY_UP)) then 25 | speed = speed + 0.1 26 | elseif (Input.isKeyPressed(Input.KEY_DOWN)) then 27 | speed = speed - 0.1 28 | end 29 | speed = speed * 0.95 30 | 31 | carengine.volume = 1.0 + (math.abs(speed) * 0.5) 32 | carengine.speed = 1.0 + (math.abs(speed) * 0.5) 33 | 34 | if (Input.isKeyPressed(Input.KEY_LEFT)) then 35 | if (curve < 3) then 36 | curve = curve + 0.4 37 | end 38 | elseif (Input.isKeyPressed(Input.KEY_RIGHT)) then 39 | if (curve > -3) then 40 | curve = curve - 0.4 41 | end 42 | else 43 | curve = 0 44 | end 45 | 46 | rotation = rotation + curve 47 | if (rotation > 360) then 48 | rotation = rotation - 360 49 | end 50 | if (rotation < 0) then 51 | rotation = 360 + rotation 52 | end 53 | 54 | vDir = Vector3(math.cos(Angle.degToRad(rotation-90)), 0, -math.sin(Angle.degToRad(rotation-90))) 55 | 56 | car:setRotation(0, rotation, 0); 57 | car.position = car.position + (vDir*speed) 58 | 59 | camera.target = car.position 60 | end 61 | 62 | 63 | scene.camera = camera.entity 64 | 65 | scene.globalIlluminationIntensity = 0.3; 66 | scene:setBackgroundColor(0.8, 0.8, 0.8); 67 | 68 | fog.type = FogType.LINEAR 69 | fog.linearStart = 30 70 | fog.linearEnd = 100 71 | 72 | camera:setPosition(0, 5, 20) 73 | 74 | house:loadModel("old-house/old-house.obj") 75 | house:setRotation(-1,2,0) 76 | house:setRotation(-90,180,0) 77 | house:setPosition(6,0,6) 78 | 79 | terrain:createPlane(200, 200) 80 | terrain:setTexture("road.png") 81 | 82 | car:loadModel("jeep/Jeep.obj") 83 | car:setScale(0.5) 84 | car:addChild(carengine) 85 | 86 | carengine:loadAudio("engine.wav") 87 | carengine.sound3D = true 88 | carengine.lopping = true 89 | carengine.dopplerFactor = 10.0 90 | carengine:setMinMaxDistance(1, 100) 91 | carengine.attenuationModel = AudioAttenuation.LINEAR_DISTANCE 92 | carengine:play() 93 | 94 | sky:setTextureFront("ely_hills/hills_lf.tga") 95 | sky:setTextureBack("ely_hills/hills_rt.tga") 96 | sky:setTextureLeft("ely_hills/hills_bk.tga") 97 | sky:setTextureRight("ely_hills/hills_ft.tga") 98 | sky:setTextureUp("ely_hills/hills_up.tga") 99 | sky:setTextureDown("ely_hills/hills_dn.tga") 100 | sky.alpha = 0.2 101 | 102 | carlight = Light(scene) 103 | carlight.type = LightType.SPOT 104 | carlight:setConeAngle(80, 100) 105 | carlight:setPosition(0, 5, 8) 106 | carlight:setDirection(0, 0, 30) 107 | carlight.intensity = 50 108 | carlight.shadows = true 109 | car:addChild(carlight) 110 | 111 | sun = Light(scene); 112 | sun.type = LightType.DIRECTIONAL 113 | sun:setDirection(0, -0.4, 0.6) 114 | sun.shadows = true 115 | 116 | text:setPosition(100, 100, 0) 117 | 118 | Engine.setScene(scene) 119 | Engine.addSceneLayer(uiscene) 120 | 121 | Engine.onUpdate = onUpdate 122 | -------------------------------------------------------------------------------- /car/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Supernova.h" 2 | 3 | 4 | using namespace Supernova; 5 | 6 | Scene scene; 7 | Scene uiscene; 8 | 9 | Camera camera(&scene); 10 | Shape terrain(&scene); 11 | 12 | Model car(&scene); 13 | 14 | Model house(&scene); 15 | SkyBox sky(&scene); 16 | Audio carengine(&scene); 17 | Fog fog(&scene); 18 | 19 | Light* carlight = NULL; 20 | Light* sun = NULL; 21 | 22 | Text text(&uiscene); 23 | 24 | float curve = 0; 25 | float speed = 0; 26 | float rotation = 0; 27 | 28 | bool up, down, left, right; 29 | 30 | void onUpdate(); 31 | 32 | void init(){ 33 | 34 | scene.setGlobalIllumination(0.3); 35 | scene.setBackgroundColor(0.8, 0.8, 0.8); 36 | 37 | scene.setCamera(camera.getEntity()); 38 | 39 | fog.setType(FogType::LINEAR); 40 | fog.setLinearStart(30); 41 | fog.setLinearEnd(100); 42 | 43 | camera.setPosition(0, 5, 20); 44 | 45 | house.loadModel("old-house/old-house.obj"); 46 | house.setRotation(-1,2,0); 47 | house.setRotation(-90,180,0); 48 | house.setPosition(6,0,6); 49 | 50 | terrain.createPlane(200, 200); 51 | terrain.setTexture("road.png"); 52 | 53 | car.loadModel("jeep/Jeep.obj"); 54 | car.setScale(0.5); 55 | car.addChild(&carengine); 56 | 57 | carengine.loadAudio("engine.wav"); 58 | carengine.setSound3D(true); 59 | carengine.setLopping(true); 60 | carengine.setDopplerFactor(10.0); 61 | carengine.setMinMaxDistance(1, 100); 62 | carengine.setAttenuationModel(AudioAttenuation::LINEAR_DISTANCE); 63 | carengine.play(); 64 | 65 | sky.setTextureFront("ely_hills/hills_lf.tga"); 66 | sky.setTextureBack("ely_hills/hills_rt.tga"); 67 | sky.setTextureLeft("ely_hills/hills_bk.tga"); 68 | sky.setTextureRight("ely_hills/hills_ft.tga"); 69 | sky.setTextureUp("ely_hills/hills_up.tga"); 70 | sky.setTextureDown("ely_hills/hills_dn.tga"); 71 | sky.setAlpha(0.2); 72 | 73 | if (!carlight) 74 | carlight = new Light(&scene); 75 | carlight->setType(LightType::SPOT); 76 | carlight->setConeAngle(80, 100); 77 | carlight->setPosition(0, 5, 8); 78 | carlight->setDirection(0, 0, 30); 79 | carlight->setIntensity(50); 80 | carlight->setShadows(true); 81 | car.addChild(carlight); 82 | 83 | if (!sun) 84 | sun = new Light(&scene); 85 | sun->setType(LightType::DIRECTIONAL); 86 | sun->setDirection(0, -0.4, 0.6); 87 | sun->setShadows(true); 88 | 89 | text.setPosition(100, 100, 0); 90 | 91 | Engine::setScene(&scene); 92 | Engine::addSceneLayer(&uiscene); 93 | 94 | Engine::onUpdate = onUpdate; 95 | } 96 | 97 | void onUpdate(){ 98 | 99 | text.setText(std::to_string(Engine::getFramerate()).c_str()); 100 | 101 | if (Input::isKeyPressed(S_KEY_UP)){ 102 | speed += 0.1; 103 | }else if (Input::isKeyPressed(S_KEY_DOWN)){ 104 | speed -= 0.1; 105 | } 106 | speed *= 0.95; 107 | 108 | carengine.setVolume(1.0 + (abs(speed) * 0.5)); 109 | carengine.setSpeed(1.0 + (abs(speed) * 0.5)); 110 | 111 | if (Input::isKeyPressed(S_KEY_LEFT)){ 112 | if (curve < 3) 113 | curve += 0.4; 114 | }else if (Input::isKeyPressed(S_KEY_RIGHT)){ 115 | if (curve > -3) 116 | curve -= 0.4; 117 | }else{ 118 | curve = 0; 119 | } 120 | 121 | rotation += curve; 122 | if (rotation > 360) 123 | rotation = rotation - 360; 124 | if (rotation < 0) 125 | rotation = 360 + rotation; 126 | 127 | Vector3 vDir(cos(Angle::degToRad(rotation-90)), 0, -sin(Angle::degToRad(rotation-90))); 128 | 129 | car.setRotation(0,rotation,0); 130 | car.setPosition(car.getPosition() + (vDir*speed)); 131 | 132 | camera.setTarget(car.getPosition()); 133 | } 134 | -------------------------------------------------------------------------------- /events/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Supernova.h" 2 | using namespace Supernova; 3 | 4 | void onUpdate(); 5 | void onCharInput(wchar_t); 6 | void onViewLoaded(); 7 | void onKeyDown(int key, bool repeat, int mods); 8 | void onKeyUp(int key, bool repeat, int mods); 9 | void onMouseDown(int button, float x, float y, int mods); 10 | void onMouseUp(int button, float x, float y, int mods); 11 | void onMouseMove(float x, float y, int mods); 12 | void onMouseScroll(float xoffset, float yoffset, int mods); 13 | void onMouseEnter(); 14 | void onMouseLeave(); 15 | void onTouchStart(int pointer, float x, float y); 16 | void onTouchMove(int pointer, float x, float y); 17 | void onTouchEnd(int pointer, float x, float y); 18 | void onTouchCancel(); 19 | 20 | void onButtonPress(); 21 | void onButtonRelease(); 22 | void onButtonMouseMove(); 23 | 24 | Scene scene; 25 | 26 | Text text(&scene); 27 | 28 | void init(){ 29 | 30 | text.setPosition(200, 200, 0); 31 | text.setText("Events example: check output"); 32 | 33 | Engine::setAllowEventsOutCanvas(true); 34 | Engine::setCallMouseInTouchEvent(true); 35 | Engine::setCallTouchInMouseEvent(true); 36 | 37 | Engine::onUpdate = onUpdate; 38 | Engine::onCharInput = onCharInput; 39 | Engine::onViewLoaded = onViewLoaded; 40 | Engine::onKeyDown = onKeyDown; 41 | Engine::onKeyUp = onKeyUp; 42 | Engine::onMouseDown = onMouseDown; 43 | Engine::onMouseUp = onMouseUp; 44 | Engine::onKeyDown = onKeyDown; 45 | Engine::onMouseMove = onMouseMove; 46 | Engine::onMouseScroll = onMouseScroll; 47 | Engine::onMouseEnter = onMouseEnter; 48 | Engine::onMouseLeave = onMouseLeave; 49 | Engine::onTouchStart = onTouchStart; 50 | Engine::onTouchMove = onTouchMove; 51 | Engine::onTouchEnd = onTouchEnd; 52 | Engine::onTouchCancel = onTouchCancel; 53 | 54 | 55 | Engine::setScene(&scene); 56 | } 57 | 58 | void onUpdate(){ 59 | 60 | } 61 | 62 | void onButtonPress(){ 63 | Log::verbose("Button pressed!!"); 64 | } 65 | 66 | void onButtonRelease(){ 67 | Log::verbose("Button released!!"); 68 | } 69 | 70 | void onButtonMouseMove(){ 71 | Log::verbose("Button mouse move!!"); 72 | } 73 | 74 | void onViewLoaded(){ 75 | Log::verbose("View loaded"); 76 | } 77 | 78 | void onTouchStart(int pointer, float x, float y){ 79 | Log::verbose("Touch start %i - %f %f", pointer, x, y); 80 | } 81 | void onTouchMove(int pointer, float x, float y){ 82 | Log::verbose("Touch move %i - %f %f", pointer, x, y); 83 | } 84 | void onTouchEnd(int pointer, float x, float y){ 85 | Log::verbose("Touch end %i - %f %f", pointer, x, y); 86 | } 87 | void onTouchCancel(){ 88 | Log::verbose("Touch cancel"); 89 | } 90 | 91 | void onMouseDown(int button, float x, float y, int mods){ 92 | std::string modifier = ""; 93 | if (mods & S_MODIFIER_SHIFT) 94 | modifier += "shift;"; 95 | if (mods & S_MODIFIER_CONTROL) 96 | modifier += "control;"; 97 | if (mods & S_MODIFIER_ALT) 98 | modifier += "alt;"; 99 | if (mods & S_MODIFIER_SUPER) 100 | modifier += "super;"; 101 | if (mods & S_MODIFIER_CAPS_LOCK) 102 | modifier += "caps;"; 103 | if (mods & S_MODIFIER_NUM_LOCK) 104 | modifier += "num;"; 105 | 106 | std::string bt = ""; 107 | if (button == S_MOUSE_BUTTON_LEFT) 108 | bt = "left"; 109 | if (button == S_MOUSE_BUTTON_RIGHT) 110 | bt = "right"; 111 | if (button == S_MOUSE_BUTTON_MIDDLE) 112 | bt = "middle"; 113 | 114 | 115 | Log::verbose("Mouse down - %s - %s", bt.c_str(), modifier.c_str()); 116 | } 117 | 118 | void onMouseUp(int button, float x, float y, int mods){ 119 | std::string modifier = ""; 120 | if (mods & S_MODIFIER_SHIFT) 121 | modifier += "shift;"; 122 | if (mods & S_MODIFIER_CONTROL) 123 | modifier += "control;"; 124 | if (mods & S_MODIFIER_ALT) 125 | modifier += "alt;"; 126 | if (mods & S_MODIFIER_SUPER) 127 | modifier += "super;"; 128 | if (mods & S_MODIFIER_CAPS_LOCK) 129 | modifier += "caps;"; 130 | if (mods & S_MODIFIER_NUM_LOCK) 131 | modifier += "num;"; 132 | 133 | std::string bt = ""; 134 | if (button == S_MOUSE_BUTTON_LEFT) 135 | bt = "left"; 136 | if (button == S_MOUSE_BUTTON_RIGHT) 137 | bt = "right"; 138 | if (button == S_MOUSE_BUTTON_MIDDLE) 139 | bt = "middle"; 140 | 141 | 142 | Log::verbose("Mouse up - %s - %s", bt.c_str(), modifier.c_str()); 143 | } 144 | 145 | void onMouseMove(float x, float y, int mods){ 146 | Log::verbose("Mouse %f %f", x, y); 147 | } 148 | 149 | void onMouseScroll(float xoffset, float yoffset, int mods){ 150 | if (xoffset != 0 || yoffset != 0) 151 | Log::verbose("Mouse scroll %f %f", xoffset, yoffset); 152 | } 153 | 154 | void onMouseEnter(){ 155 | Log::verbose("Mouse enter"); 156 | } 157 | 158 | void onMouseLeave(){ 159 | Log::verbose("Mouse leave"); 160 | } 161 | 162 | void onCharInput(wchar_t codepoint){ 163 | Log::verbose("%s",StringUtils::toUTF8(codepoint).c_str()); 164 | } 165 | 166 | void onKeyDown(int key, bool repeat, int mods){ 167 | std::string modifier = ""; 168 | if (mods & S_MODIFIER_SHIFT) 169 | modifier += "shift;"; 170 | if (mods & S_MODIFIER_CONTROL) 171 | modifier += "control;"; 172 | if (mods & S_MODIFIER_ALT) 173 | modifier += "alt;"; 174 | if (mods & S_MODIFIER_SUPER) 175 | modifier += "super;"; 176 | if (mods & S_MODIFIER_CAPS_LOCK) 177 | modifier += "caps;"; 178 | if (mods & S_MODIFIER_NUM_LOCK) 179 | modifier += "num;"; 180 | 181 | std::string rstr; 182 | if (repeat) 183 | rstr = "repeated"; 184 | 185 | Log::verbose("KeyDown: %i - %s - %s",key, modifier.c_str(), rstr.c_str()); 186 | } 187 | 188 | void onKeyUp(int key, bool repeat, int mods){ 189 | std::string modifier = ""; 190 | if (mods & S_MODIFIER_SHIFT) 191 | modifier += "shift;"; 192 | if (mods & S_MODIFIER_CONTROL) 193 | modifier += "control;"; 194 | if (mods & S_MODIFIER_ALT) 195 | modifier += "alt;"; 196 | if (mods & S_MODIFIER_SUPER) 197 | modifier += "super;"; 198 | if (mods & S_MODIFIER_CAPS_LOCK) 199 | modifier += "caps;"; 200 | if (mods & S_MODIFIER_NUM_LOCK) 201 | modifier += "num;"; 202 | 203 | std::string rstr; 204 | if (repeat) 205 | rstr = "repeated"; 206 | 207 | Log::verbose("KeyUp: %i - %s - %s",key, modifier.c_str(), rstr.c_str()); 208 | } 209 | -------------------------------------------------------------------------------- /lines/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Supernova.h" 2 | using namespace Supernova; 3 | 4 | Vector2 lastTouchPos; 5 | 6 | Scene scene; 7 | Camera camera(&scene); 8 | Lines lines(&scene); 9 | 10 | void onTouchStart(int pointer, float x, float y); 11 | void onTouchMove(int pointer, float x, float y); 12 | void onMouseScroll(float xoffset, float yoffset, int mods); 13 | 14 | 15 | void init(){ 16 | lastTouchPos = Vector2(0, 0); 17 | 18 | scene.setCamera(camera.getEntity()); 19 | 20 | int gridHeight = 0; 21 | 22 | for (int i = -1000; i <= 1000; i++){ 23 | if (i == 0){ 24 | lines.addLine(Vector3(i, gridHeight, -1000), Vector3(i, gridHeight, 1000), Vector4(1.0, 0.5, 0.5, 1.0)); 25 | }else{ 26 | if (i % 10 == 0){ 27 | lines.addLine(Vector3(i, gridHeight, -1000), Vector3(i, gridHeight, 1000), Vector4(0.5, 0.5, 0.5, 1.0)); 28 | }else{ 29 | lines.addLine(Vector3(i, gridHeight, -1000), Vector3(i, gridHeight, 1000), Vector4(0.5, 0.5, 0.5, 0.5)); 30 | } 31 | } 32 | } 33 | for (int i = -1000; i <= 1000; i++){ 34 | if (i == 0){ 35 | lines.addLine(Vector3(-1000, gridHeight, i), Vector3(1000, gridHeight, i), Vector4(0.5, 1.0, 0.5, 1.0)); 36 | }else{ 37 | if (i % 10 == 0){ 38 | lines.addLine(Vector3(-1000, gridHeight, i), Vector3(1000, gridHeight, i), Vector4(0.5, 0.5, 0.5, 1.0)); 39 | }else{ 40 | lines.addLine(Vector3(-1000, gridHeight, i), Vector3(1000, gridHeight, i), Vector4(0.5, 0.5, 0.5, 0.5)); 41 | } 42 | } 43 | } 44 | 45 | camera.setPosition(0, 7, 20); 46 | camera.setTarget(0, 2, 0); 47 | 48 | Engine::setScalingMode(Scaling::FITWIDTH); 49 | Engine::setScene(&scene); 50 | Engine::setCallTouchInMouseEvent(true); 51 | 52 | Engine::onTouchStart = onTouchStart; 53 | Engine::onTouchMove = onTouchMove; 54 | Engine::onMouseScroll = onMouseScroll; 55 | 56 | } 57 | 58 | void onTouchMove(int pointer, float x, float y){ 59 | float difX = lastTouchPos.x - x; 60 | float difY = lastTouchPos.y - y; 61 | lastTouchPos = Vector2(x, y); 62 | 63 | if (Input::isMousePressed(S_MOUSE_BUTTON_1)){ 64 | camera.walkForward(-0.05 * difY); 65 | camera.slide(0.02 * difX); 66 | }else{ 67 | camera.rotatePosition(0.1 * difX); 68 | camera.elevatePosition(-0.1 * difY); 69 | } 70 | 71 | } 72 | 73 | void onTouchStart(int pointer, float x, float y){ 74 | lastTouchPos = Vector2(x, y); 75 | } 76 | 77 | void onMouseScroll(float xoffset, float yoffset, int mods){ 78 | camera.zoom(1.0 * yoffset); 79 | } -------------------------------------------------------------------------------- /mirror/assets/WaterBottle.glb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/mirror/assets/WaterBottle.glb -------------------------------------------------------------------------------- /mirror/assets/ely_hills/ely_hills.shader: -------------------------------------------------------------------------------- 1 | // Direction & elevation checked and adjusted - Speaker 2 | 3 | textures/skies/ely_hills 4 | { 5 | qer_editorimage env/ely_hills/hills_ft.tga 6 | surfaceparm noimpact 7 | surfaceparm nolightmap 8 | q3map_globaltexture 9 | q3map_lightsubdivide 256 10 | surfaceparm sky 11 | q3map_surfacelight 200 12 | q3map_sun 1 1 1 200 25 40 13 | skyparms env/ely_hills/hills - - 14 | } 15 | -------------------------------------------------------------------------------- /mirror/assets/ely_hills/hills_bk.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/mirror/assets/ely_hills/hills_bk.tga -------------------------------------------------------------------------------- /mirror/assets/ely_hills/hills_dn.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/mirror/assets/ely_hills/hills_dn.tga -------------------------------------------------------------------------------- /mirror/assets/ely_hills/hills_ft.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/mirror/assets/ely_hills/hills_ft.tga -------------------------------------------------------------------------------- /mirror/assets/ely_hills/hills_lf.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/mirror/assets/ely_hills/hills_lf.tga -------------------------------------------------------------------------------- /mirror/assets/ely_hills/hills_rt.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/mirror/assets/ely_hills/hills_rt.tga -------------------------------------------------------------------------------- /mirror/assets/ely_hills/hills_up.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/mirror/assets/ely_hills/hills_up.tga -------------------------------------------------------------------------------- /mirror/assets/ely_hills/readme: -------------------------------------------------------------------------------- 1 | These sky boxes have been downloaded from http://www.3delyvisions.com. They were produced by Colin Lowndes using a properly licensed copy of TerraGen. The author granted permission to distribute these sky boxes under the GNU General Public License version 2. Thanks, Colin! 2 | 3 | I (Laszlo Menczel aka Speaker) converted the textures to TGA format and resized the ones not conforming to the power-of-two texture size rule of Quake3. Also renamed the textures to conform to the name conventions of sky boxes in Quake3 (i.e. using the postfixes _bk, _ft, _lf, _rt and _up). The original boxes did not have 'down' textures. I made a 512x512 neutral grey image and added copies of this to each sky box as a fake 'down' texture. 4 | -------------------------------------------------------------------------------- /mirror/assets/ground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/mirror/assets/ground.png -------------------------------------------------------------------------------- /mirror/lua/main.lua: -------------------------------------------------------------------------------- 1 | --print("lua file") -------------------------------------------------------------------------------- /mirror/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Supernova.h" 2 | 3 | using namespace Supernova; 4 | 5 | void onUpdate(); 6 | void onKeyDown(int key, bool repeat, int mods); 7 | void onTouchStart(int pointer, float x, float y); 8 | void onTouchMove(int pointer, float x, float y); 9 | 10 | Vector2 lastTouchPos; 11 | 12 | Scene scene; 13 | 14 | Model model(&scene); 15 | Camera camera(&scene); 16 | Shape terrain(&scene); 17 | SkyBox sky(&scene); 18 | Light sun(&scene); 19 | 20 | Camera cameramirror(&scene); 21 | Sprite mirror(&scene); 22 | 23 | 24 | void init(){ 25 | scene.setCamera(camera.getEntity()); 26 | scene.setGlobalIllumination(0.5); 27 | 28 | camera.setPosition(0, 7, 40); 29 | camera.setName("camera"); 30 | 31 | sun.setType(LightType::DIRECTIONAL); 32 | sun.setDirection(0, -0.4, -0.6); 33 | 34 | terrain.createPlane(200, 200); 35 | terrain.setTexture("ground.png"); 36 | terrain.setName("terrain"); 37 | 38 | cameramirror.setPosition(0, 5, 0); 39 | cameramirror.setTarget(0, 5, 40); 40 | cameramirror.setRenderToTexture(true); 41 | cameramirror.setName("cameramirror"); 42 | 43 | mirror.setTexture(cameramirror.getFramebuffer()); 44 | mirror.setSize(10,10); 45 | mirror.setPivotPreset(PivotPreset::CENTER); 46 | mirror.setPosition(0,5,0); 47 | mirror.setName("mirror"); 48 | 49 | model.loadModel("WaterBottle.glb"); 50 | model.setScale(20); 51 | model.setPosition(0,3,20); 52 | 53 | sky.setTextureFront("ely_hills/hills_lf.tga"); 54 | sky.setTextureBack("ely_hills/hills_rt.tga"); 55 | sky.setTextureLeft("ely_hills/hills_bk.tga"); 56 | sky.setTextureRight("ely_hills/hills_ft.tga"); 57 | sky.setTextureUp("ely_hills/hills_up.tga"); 58 | sky.setTextureDown("ely_hills/hills_dn.tga"); 59 | 60 | Engine::setScene(&scene); 61 | Engine::setCallTouchInMouseEvent(true); 62 | 63 | Engine::onUpdate = onUpdate; 64 | Engine::onKeyDown = onKeyDown; 65 | Engine::onTouchStart = onTouchStart; 66 | Engine::onTouchMove = onTouchMove; 67 | } 68 | 69 | void onUpdate(){ 70 | 71 | if (Input::isKeyPressed(S_KEY_UP) || Input::isKeyPressed(S_KEY_W)){ 72 | camera.walkForward(1); 73 | }else if (Input::isKeyPressed(S_KEY_DOWN) || Input::isKeyPressed(S_KEY_S)){ 74 | camera.walkForward(-1); 75 | } 76 | 77 | if (Input::isKeyPressed(S_KEY_A)){ 78 | camera.slide(-1); 79 | }else if (Input::isKeyPressed(S_KEY_D)){ 80 | camera.slide(1); 81 | } 82 | 83 | if (Input::isKeyPressed(S_KEY_LEFT)){ 84 | camera.rotateView(2); 85 | }else if (Input::isKeyPressed(S_KEY_RIGHT)){ 86 | camera.rotateView(-2); 87 | } 88 | 89 | // necessary if use camera.getWorldPosition() to update world positions 90 | // scene.getSystem()->updateTransform(camera.getComponent()); 91 | 92 | Vector3 camVec = mirror.getPosition() - camera.getPosition(); 93 | Vector3 reflVec = camVec.reflect(Vector3(0,0,1)); 94 | cameramirror.setTarget(cameramirror.getPosition() + reflVec); 95 | } 96 | 97 | void onKeyDown(int key, bool repeat, int mods){ 98 | 99 | } 100 | 101 | void onTouchMove(int pointer, float x, float y){ 102 | float difX = lastTouchPos.x - x; 103 | float difY = lastTouchPos.y - y; 104 | lastTouchPos = Vector2(x, y); 105 | 106 | camera.rotateView(0.1 * difX); 107 | camera.elevateView(0.1 * difY); 108 | } 109 | 110 | void onTouchStart(int pointer, float x, float y){ 111 | lastTouchPos = Vector2(x, y); 112 | } 113 | -------------------------------------------------------------------------------- /morph_targets/assets/AnimatedMorphCube.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/morph_targets/assets/AnimatedMorphCube.bin -------------------------------------------------------------------------------- /morph_targets/assets/AnimatedMorphCube.gltf: -------------------------------------------------------------------------------- 1 | { 2 | "accessors": [ 3 | { 4 | "bufferView": 0, 5 | "componentType": 5126, 6 | "count": 24, 7 | "type": "VEC3" 8 | }, 9 | { 10 | "bufferView": 1, 11 | "componentType": 5126, 12 | "count": 24, 13 | "type": "VEC4" 14 | }, 15 | { 16 | "bufferView": 2, 17 | "componentType": 5126, 18 | "count": 24, 19 | "type": "VEC3", 20 | "max": [ 21 | 0.0100000035, 22 | 0.0100000035, 23 | 0.01 24 | ], 25 | "min": [ 26 | -0.0100000044, 27 | -0.0100000054, 28 | -0.01 29 | ] 30 | }, 31 | { 32 | "bufferView": 3, 33 | "componentType": 5126, 34 | "count": 24, 35 | "type": "VEC3", 36 | "name": "thin" 37 | }, 38 | { 39 | "bufferView": 4, 40 | "componentType": 5126, 41 | "count": 24, 42 | "type": "VEC3", 43 | "max": [ 44 | 0.0, 45 | 0.01893253, 46 | 0.0 47 | ], 48 | "min": [ 49 | 0.0, 50 | 0.0, 51 | 0.0 52 | ], 53 | "name": "thin" 54 | }, 55 | { 56 | "bufferView": 5, 57 | "componentType": 5126, 58 | "count": 24, 59 | "type": "VEC3", 60 | "name": "thin" 61 | }, 62 | { 63 | "bufferView": 6, 64 | "componentType": 5126, 65 | "count": 24, 66 | "type": "VEC3", 67 | "name": "angle" 68 | }, 69 | { 70 | "bufferView": 7, 71 | "componentType": 5126, 72 | "count": 24, 73 | "type": "VEC3", 74 | "max": [ 75 | 0.0, 76 | 0.0198908355, 77 | 0.0 78 | ], 79 | "min": [ 80 | 0.0, 81 | 0.0, 82 | 0.0 83 | ], 84 | "name": "angle" 85 | }, 86 | { 87 | "bufferView": 8, 88 | "componentType": 5126, 89 | "count": 24, 90 | "type": "VEC3", 91 | "name": "angle" 92 | }, 93 | { 94 | "bufferView": 9, 95 | "componentType": 5123, 96 | "count": 36, 97 | "type": "SCALAR" 98 | }, 99 | { 100 | "bufferView": 10, 101 | "componentType": 5126, 102 | "count": 127, 103 | "type": "SCALAR", 104 | "max": [ 105 | 4.19999743 106 | ], 107 | "min": [ 108 | 0.0 109 | ] 110 | }, 111 | { 112 | "bufferView": 11, 113 | "componentType": 5126, 114 | "count": 254, 115 | "type": "SCALAR" 116 | } 117 | ], 118 | "animations": [ 119 | { 120 | "channels": [ 121 | { 122 | "sampler": 0, 123 | "target": { 124 | "node": 0, 125 | "path": "weights" 126 | } 127 | } 128 | ], 129 | "samplers": [ 130 | { 131 | "input": 10, 132 | "interpolation": "LINEAR", 133 | "output": 11 134 | } 135 | ], 136 | "name": "Square" 137 | } 138 | ], 139 | "asset": { 140 | "generator": "glTF Tools for Unity", 141 | "version": "2.0" 142 | }, 143 | "bufferViews": [ 144 | { 145 | "buffer": 0, 146 | "byteLength": 288 147 | }, 148 | { 149 | "buffer": 0, 150 | "byteOffset": 288, 151 | "byteLength": 384 152 | }, 153 | { 154 | "buffer": 0, 155 | "byteOffset": 672, 156 | "byteLength": 288 157 | }, 158 | { 159 | "buffer": 0, 160 | "byteOffset": 960, 161 | "byteLength": 288 162 | }, 163 | { 164 | "buffer": 0, 165 | "byteOffset": 1248, 166 | "byteLength": 288 167 | }, 168 | { 169 | "buffer": 0, 170 | "byteOffset": 1536, 171 | "byteLength": 288 172 | }, 173 | { 174 | "buffer": 0, 175 | "byteOffset": 1824, 176 | "byteLength": 288 177 | }, 178 | { 179 | "buffer": 0, 180 | "byteOffset": 2112, 181 | "byteLength": 288 182 | }, 183 | { 184 | "buffer": 0, 185 | "byteOffset": 2400, 186 | "byteLength": 288 187 | }, 188 | { 189 | "buffer": 0, 190 | "byteOffset": 2688, 191 | "byteLength": 72 192 | }, 193 | { 194 | "buffer": 0, 195 | "byteOffset": 2760, 196 | "byteLength": 508 197 | }, 198 | { 199 | "buffer": 0, 200 | "byteOffset": 3268, 201 | "byteLength": 1016 202 | } 203 | ], 204 | "buffers": [ 205 | { 206 | "uri": "AnimatedMorphCube.bin", 207 | "byteLength": 4284 208 | } 209 | ], 210 | "meshes": [ 211 | { 212 | "primitives": [ 213 | { 214 | "attributes": { 215 | "NORMAL": 0, 216 | "TANGENT": 1, 217 | "POSITION": 2 218 | }, 219 | "indices": 9, 220 | "material": 0, 221 | "targets": [ 222 | { 223 | "NORMAL": 3, 224 | "POSITION": 4, 225 | "TANGENT": 5 226 | }, 227 | { 228 | "NORMAL": 6, 229 | "POSITION": 7, 230 | "TANGENT": 8 231 | } 232 | ] 233 | } 234 | ], 235 | "weights": [ 236 | 0.0, 237 | 0.0 238 | ], 239 | "name": "Cube" 240 | } 241 | ], 242 | "materials": [ 243 | { 244 | "pbrMetallicRoughness": { 245 | "baseColorFactor": [ 246 | 0.6038274, 247 | 0.6038274, 248 | 0.6038274, 249 | 1.0 250 | ], 251 | "metallicFactor": 0.0, 252 | "roughnessFactor": 0.5 253 | }, 254 | "name": "Material" 255 | } 256 | ], 257 | "nodes": [ 258 | { 259 | "mesh": 0, 260 | "rotation": [ 261 | 0.0, 262 | 0.7071067, 263 | -0.7071068, 264 | 0.0 265 | ], 266 | "scale": [ 267 | 100.0, 268 | 100.0, 269 | 100.0 270 | ], 271 | "name": "AnimatedMorphCube" 272 | } 273 | ], 274 | "scene": 0, 275 | "scenes": [ 276 | { 277 | "nodes": [ 278 | 0 279 | ] 280 | } 281 | ] 282 | } -------------------------------------------------------------------------------- /morph_targets/assets/ely_hills/ely_hills.shader: -------------------------------------------------------------------------------- 1 | // Direction & elevation checked and adjusted - Speaker 2 | 3 | textures/skies/ely_hills 4 | { 5 | qer_editorimage env/ely_hills/hills_ft.tga 6 | surfaceparm noimpact 7 | surfaceparm nolightmap 8 | q3map_globaltexture 9 | q3map_lightsubdivide 256 10 | surfaceparm sky 11 | q3map_surfacelight 200 12 | q3map_sun 1 1 1 200 25 40 13 | skyparms env/ely_hills/hills - - 14 | } 15 | -------------------------------------------------------------------------------- /morph_targets/assets/ely_hills/hills_bk.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/morph_targets/assets/ely_hills/hills_bk.tga -------------------------------------------------------------------------------- /morph_targets/assets/ely_hills/hills_dn.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/morph_targets/assets/ely_hills/hills_dn.tga -------------------------------------------------------------------------------- /morph_targets/assets/ely_hills/hills_ft.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/morph_targets/assets/ely_hills/hills_ft.tga -------------------------------------------------------------------------------- /morph_targets/assets/ely_hills/hills_lf.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/morph_targets/assets/ely_hills/hills_lf.tga -------------------------------------------------------------------------------- /morph_targets/assets/ely_hills/hills_rt.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/morph_targets/assets/ely_hills/hills_rt.tga -------------------------------------------------------------------------------- /morph_targets/assets/ely_hills/hills_up.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/morph_targets/assets/ely_hills/hills_up.tga -------------------------------------------------------------------------------- /morph_targets/assets/ely_hills/readme: -------------------------------------------------------------------------------- 1 | These sky boxes have been downloaded from http://www.3delyvisions.com. They were produced by Colin Lowndes using a properly licensed copy of TerraGen. The author granted permission to distribute these sky boxes under the GNU General Public License version 2. Thanks, Colin! 2 | 3 | I (Laszlo Menczel aka Speaker) converted the textures to TGA format and resized the ones not conforming to the power-of-two texture size rule of Quake3. Also renamed the textures to conform to the name conventions of sky boxes in Quake3 (i.e. using the postfixes _bk, _ft, _lf, _rt and _up). The original boxes did not have 'down' textures. I made a 512x512 neutral grey image and added copies of this to each sky box as a fake 'down' texture. 4 | -------------------------------------------------------------------------------- /morph_targets/assets/ground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/morph_targets/assets/ground.png -------------------------------------------------------------------------------- /morph_targets/lua/main.lua: -------------------------------------------------------------------------------- 1 | lastTouchPos = Vector2(0, 0) 2 | 3 | scene = Scene() 4 | 5 | camera = Camera(scene) 6 | terrain = Shape(scene) 7 | model = Model(scene) 8 | sky = SkyBox(scene) 9 | sun = Light(scene) 10 | 11 | uiscene = Scene() 12 | text = Text(uiscene) 13 | 14 | function onKeyDown(key, rep, mods) 15 | model:getAnimation(0):start() 16 | end 17 | 18 | function onTouchStart(pointer, x, y) 19 | lastTouchPos = Vector2(x, y) 20 | end 21 | 22 | function onTouchMove(pointer, x, y) 23 | difX = lastTouchPos.x - x 24 | difY = lastTouchPos.y - y 25 | lastTouchPos = Vector2(x, y) 26 | 27 | camera:rotatePosition(0.1 * difX) 28 | camera:elevatePosition(-0.1 * difY) 29 | end 30 | 31 | scene.globalIlluminationIntensity = 0.1 32 | scene.camera = camera.entity 33 | 34 | text.text = "Press any key to start" 35 | text.anchorPreset = AnchorPreset.CENTER_TOP 36 | 37 | camera:setPosition(0, 7, -20) 38 | camera:setTarget(0, 2, 0); 39 | 40 | terrain:createPlane(200, 200) 41 | terrain:setTexture("ground.png") 42 | 43 | model:loadModel("AnimatedMorphCube.gltf") 44 | model:setScale(100) 45 | model:setPosition(0,1,0) 46 | model:setRotation(0,90,0) 47 | model:getAnimation(0).loop = true 48 | 49 | sun.type = LightType.DIRECTIONAL 50 | sun:setDirection(0,-0.7, 0.8) 51 | sun:setIntensity(10) 52 | sun:setShadows(true) 53 | 54 | sky:setTextureFront("ely_hills/hills_lf.tga") 55 | sky:setTextureBack("ely_hills/hills_rt.tga") 56 | sky:setTextureLeft("ely_hills/hills_bk.tga") 57 | sky:setTextureRight("ely_hills/hills_ft.tga") 58 | sky:setTextureUp("ely_hills/hills_up.tga") 59 | sky:setTextureDown("ely_hills/hills_dn.tga") 60 | 61 | Engine.scalingMode = Scaling.FITWIDTH 62 | Engine.setCanvasSize(1000, 480) 63 | Engine.setScene(scene) 64 | Engine.addSceneLayer(uiscene) 65 | Engine.callTouchInMouseEvent = true 66 | 67 | Engine.onKeyDown = onKeyDown 68 | Engine.onTouchStart = onTouchStart 69 | Engine.onTouchMove = onTouchMove -------------------------------------------------------------------------------- /morph_targets/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Supernova.h" 2 | using namespace Supernova; 3 | 4 | void onKeyDown(int key, bool repeat, int mods); 5 | void onTouchStart(int pointer, float x, float y); 6 | void onTouchMove(int pointer, float x, float y); 7 | 8 | Vector2 lastTouchPos; 9 | 10 | Scene scene; 11 | 12 | Camera camera(&scene); 13 | Shape terrain(&scene); 14 | Model model(&scene); 15 | SkyBox sky(&scene); 16 | Light* sun = NULL; 17 | 18 | Scene uiscene; 19 | Text text(&uiscene); 20 | 21 | 22 | void init(){ 23 | scene.setGlobalIllumination(0.1); 24 | scene.setCamera(camera.getEntity()); 25 | 26 | text.setText("Press any key to start"); 27 | text.setAnchorPreset(AnchorPreset::CENTER_TOP); 28 | 29 | camera.setPosition(0, 7, -20); 30 | camera.setTarget(0, 2, 0); 31 | 32 | terrain.createPlane(200, 200); 33 | terrain.setTexture("ground.png"); 34 | 35 | model.loadModel("AnimatedMorphCube.gltf"); 36 | model.setScale(100); 37 | model.setPosition(0,1,0); 38 | model.setRotation(0,90,0); 39 | model.getAnimation(0).setLoop(true); 40 | 41 | if (!sun) 42 | sun = new Light(&scene); 43 | sun->setType(LightType::DIRECTIONAL); 44 | sun->setDirection(0,-0.7, 0.8); 45 | sun->setIntensity(10); 46 | sun->setShadows(true); 47 | 48 | sky.setTextureFront("ely_hills/hills_lf.tga"); 49 | sky.setTextureBack("ely_hills/hills_rt.tga"); 50 | sky.setTextureLeft("ely_hills/hills_bk.tga"); 51 | sky.setTextureRight("ely_hills/hills_ft.tga"); 52 | sky.setTextureUp("ely_hills/hills_up.tga"); 53 | sky.setTextureDown("ely_hills/hills_dn.tga"); 54 | 55 | Engine::setScalingMode(Scaling::FITWIDTH); 56 | Engine::setCanvasSize(1000, 480); 57 | Engine::setScene(&scene); 58 | Engine::addSceneLayer(&uiscene); 59 | Engine::setCallTouchInMouseEvent(true); 60 | 61 | Engine::onKeyDown = onKeyDown; 62 | Engine::onTouchStart = onTouchStart; 63 | Engine::onTouchMove = onTouchMove; 64 | } 65 | 66 | void onKeyDown(int key, bool repeat, int mods){ 67 | model.getAnimation(0).start(); 68 | } 69 | 70 | void onTouchMove(int pointer, float x, float y){ 71 | float difX = lastTouchPos.x - x; 72 | float difY = lastTouchPos.y - y; 73 | lastTouchPos = Vector2(x, y); 74 | 75 | camera.rotatePosition(0.1 * difX); 76 | camera.elevatePosition(-0.1 * difY); 77 | } 78 | 79 | void onTouchStart(int pointer, float x, float y){ 80 | lastTouchPos = Vector2(x, y); 81 | } 82 | -------------------------------------------------------------------------------- /offscreen/assets/ely_hills/ely_hills.shader: -------------------------------------------------------------------------------- 1 | // Direction & elevation checked and adjusted - Speaker 2 | 3 | textures/skies/ely_hills 4 | { 5 | qer_editorimage env/ely_hills/hills_ft.tga 6 | surfaceparm noimpact 7 | surfaceparm nolightmap 8 | q3map_globaltexture 9 | q3map_lightsubdivide 256 10 | surfaceparm sky 11 | q3map_surfacelight 200 12 | q3map_sun 1 1 1 200 25 40 13 | skyparms env/ely_hills/hills - - 14 | } 15 | -------------------------------------------------------------------------------- /offscreen/assets/ely_hills/hills_bk.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/offscreen/assets/ely_hills/hills_bk.tga -------------------------------------------------------------------------------- /offscreen/assets/ely_hills/hills_dn.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/offscreen/assets/ely_hills/hills_dn.tga -------------------------------------------------------------------------------- /offscreen/assets/ely_hills/hills_ft.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/offscreen/assets/ely_hills/hills_ft.tga -------------------------------------------------------------------------------- /offscreen/assets/ely_hills/hills_lf.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/offscreen/assets/ely_hills/hills_lf.tga -------------------------------------------------------------------------------- /offscreen/assets/ely_hills/hills_rt.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/offscreen/assets/ely_hills/hills_rt.tga -------------------------------------------------------------------------------- /offscreen/assets/ely_hills/hills_up.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/offscreen/assets/ely_hills/hills_up.tga -------------------------------------------------------------------------------- /offscreen/assets/ely_hills/readme: -------------------------------------------------------------------------------- 1 | These sky boxes have been downloaded from http://www.3delyvisions.com. They were produced by Colin Lowndes using a properly licensed copy of TerraGen. The author granted permission to distribute these sky boxes under the GNU General Public License version 2. Thanks, Colin! 2 | 3 | I (Laszlo Menczel aka Speaker) converted the textures to TGA format and resized the ones not conforming to the power-of-two texture size rule of Quake3. Also renamed the textures to conform to the name conventions of sky boxes in Quake3 (i.e. using the postfixes _bk, _ft, _lf, _rt and _up). The original boxes did not have 'down' textures. I made a 512x512 neutral grey image and added copies of this to each sky box as a fake 'down' texture. 4 | -------------------------------------------------------------------------------- /offscreen/assets/jeep/Jeep.mtl: -------------------------------------------------------------------------------- 1 | # 2 | # 3 | newmtl Jeep_glass 4 | Ns 96.078431 5 | Ka 0.000000 0.000000 0.000000 6 | Kd 0.640000 0.640000 0.640000 7 | Ks 0.500000 0.500000 0.500000 8 | Ni 1.000000 9 | d 0.000000 10 | illum 2 11 | map_Kd Jeep_glass_d.tga 12 | 13 | 14 | newmtl Jeep_outside 15 | Ns 96.078431 16 | Ka 0.000000 0.000000 0.000000 17 | Kd 0.640000 0.640000 0.640000 18 | Ks 0.000000 0.000000 0.000000 19 | Ni 1.000000 20 | d 1.000000 21 | illum 1 22 | map_Kd Jeep_outside_d.tga 23 | 24 | 25 | newmtl Jeep_inside 26 | Ns 96.078431 27 | Ka 0.000000 0.000000 0.000000 28 | Kd 0.640000 0.640000 0.640000 29 | Ks 0.000000 0.000000 0.000000 30 | Ni 1.000000 31 | d 1.000000 32 | illum 1 33 | map_Kd Jeep_inside_d.tga 34 | 35 | 36 | -------------------------------------------------------------------------------- /offscreen/assets/jeep/Jeep_glass_d.tga: -------------------------------------------------------------------------------- 1 |  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& -------------------------------------------------------------------------------- /offscreen/assets/jeep/Jeep_inside_d.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/offscreen/assets/jeep/Jeep_inside_d.tga -------------------------------------------------------------------------------- /offscreen/assets/jeep/Jeep_outside_d.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/offscreen/assets/jeep/Jeep_outside_d.tga -------------------------------------------------------------------------------- /offscreen/assets/old-house/old-house.mtl: -------------------------------------------------------------------------------- 1 | # 3ds Max Wavefront OBJ Exporter v0.97b - (c)2007 guruware 2 | # File Created: 09.04.2016 18:26:18 3 | 4 | newmtl SAN_RUMAHGEN05 5 | Ns 9.999999 6 | Ni 1.500000 7 | d 1.000000 8 | Tr 0.000000 9 | Tf 1.000000 1.000000 1.000000 10 | illum 2 11 | Ka 0.588235 0.588235 0.588235 12 | Kd 0.588235 0.588235 0.588235 13 | Ks 0.000000 0.000000 0.000000 14 | Ke 0.000000 0.000000 0.000000 15 | map_Ka old-house.png 16 | map_Kd old-house.png 17 | -------------------------------------------------------------------------------- /offscreen/assets/old-house/old-house.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/offscreen/assets/old-house/old-house.png -------------------------------------------------------------------------------- /offscreen/assets/road.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/offscreen/assets/road.png -------------------------------------------------------------------------------- /offscreen/main.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "Supernova.h" 3 | using namespace Supernova; 4 | 5 | Scene scene; 6 | Image image(&scene); 7 | Container textcontainer(&scene); 8 | Text text1(&scene); 9 | Text text2(&scene); 10 | 11 | Scene carscene; 12 | Camera* camera; 13 | Shape terrain(&carscene); 14 | Model car(&carscene); 15 | SkyBox sky(&carscene); 16 | 17 | float curve = 0; 18 | float speed = 0; 19 | float rotation = 0; 20 | 21 | void onUpdate(); 22 | void onKeyDown(int key, bool repeat, int mods); 23 | 24 | void init(){ 25 | Engine::setCanvasSize(1000, 480); 26 | Engine::setCallTouchInMouseEvent(true); 27 | 28 | camera = new Camera(&carscene); 29 | 30 | camera->setFramebufferFilter(TextureFilter::NEAREST); 31 | camera->setFramebufferSize(512, 512); 32 | camera->setRenderToTexture(true); 33 | camera->setPosition(0, 5, 20); 34 | carscene.setCamera(camera->getEntity()); 35 | 36 | terrain.createPlane(200, 200); 37 | terrain.setTexture("road.png"); 38 | 39 | car.loadModel("jeep/Jeep.obj"); 40 | car.setScale(0.5); 41 | 42 | sky.setTextureFront("ely_hills/hills_lf.tga"); 43 | sky.setTextureBack("ely_hills/hills_rt.tga"); 44 | sky.setTextureLeft("ely_hills/hills_bk.tga"); 45 | sky.setTextureRight("ely_hills/hills_ft.tga"); 46 | sky.setTextureUp("ely_hills/hills_up.tga"); 47 | sky.setTextureDown("ely_hills/hills_dn.tga"); 48 | 49 | image.setTexture(camera->getFramebuffer()); 50 | image.setPosition(550,100,0); 51 | image.setSize(400, 300); 52 | image.setAnchorPreset(AnchorPreset::CENTER); 53 | 54 | textcontainer.setAnchorPreset(AnchorPreset::CENTER_TOP); 55 | textcontainer.addChild(&text1); 56 | textcontainer.addChild(&text2); 57 | 58 | text1.setText("Press F to fullscreen draw rect"); 59 | text1.setFontSize(20); 60 | text1.setAnchorPreset(AnchorPreset::CENTER); 61 | text2.setText("Press R to change resolution"); 62 | text2.setFontSize(20); 63 | text2.setAnchorPreset(AnchorPreset::CENTER); 64 | 65 | Engine::setScene(&scene); 66 | Engine::addSceneLayer(&carscene); 67 | Engine::setScalingMode(Scaling::NATIVE); 68 | 69 | Engine::onKeyDown = onKeyDown; 70 | Engine::onUpdate = onUpdate; 71 | 72 | } 73 | 74 | void onKeyDown(int key, bool repeat, int mods){ 75 | if (key == S_KEY_F){ 76 | if (image.getAnchorPreset() == AnchorPreset::CENTER){ 77 | image.setAnchorPreset(AnchorPreset::FULL_LAYOUT); 78 | }else{ 79 | image.setSize(400, 300); 80 | image.setAnchorPreset(AnchorPreset::CENTER); 81 | } 82 | } 83 | if (key == S_KEY_R){ 84 | if (camera->getFramebuffer()->getWidth() == 512){ 85 | camera->setFramebufferSize(256, 256); 86 | }else{ 87 | camera->setFramebufferSize(512, 512); 88 | } 89 | } 90 | } 91 | 92 | void onUpdate(){ 93 | if (Input::isKeyPressed(S_KEY_UP)){ 94 | speed += 0.1; 95 | }else if (Input::isKeyPressed(S_KEY_DOWN)){ 96 | speed -= 0.1; 97 | } 98 | speed *= 0.95; 99 | 100 | if (Input::isKeyPressed(S_KEY_LEFT)){ 101 | if (curve < 3) 102 | curve += 0.4; 103 | }else if (Input::isKeyPressed(S_KEY_RIGHT)){ 104 | if (curve > -3) 105 | curve -= 0.4; 106 | }else{ 107 | curve = 0; 108 | } 109 | 110 | rotation += curve; 111 | if (rotation > 360) 112 | rotation = rotation - 360; 113 | if (rotation < 0) 114 | rotation = 360 + rotation; 115 | 116 | Vector3 vDir(cos(Angle::degToRad(rotation-90)), 0, -sin(Angle::degToRad(rotation-90))); 117 | 118 | car.setRotation(0,rotation,0); 119 | car.setPosition(car.getPosition() + (vDir*speed)); 120 | 121 | camera->setTarget(car.getPosition()); 122 | } 123 | -------------------------------------------------------------------------------- /particles/assets/explosion.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/particles/assets/explosion.png -------------------------------------------------------------------------------- /particles/lua/main.lua: -------------------------------------------------------------------------------- 1 | scene = Scene() 2 | 3 | ParticlesType = { 4 | POINTS = 0, 5 | SPRITES = 1 6 | } 7 | 8 | parttext = " particles (press any key to change)" 9 | 10 | text = Text(scene) 11 | 12 | points = Points(scene) 13 | sprite = Sprite(scene) 14 | particles = Particles(scene) 15 | 16 | 17 | function onKeyDown(key, rep, mods) 18 | if type == ParticlesType.SPRITES then 19 | text.text = "Points"..parttext 20 | type = ParticlesType.POINTS 21 | particles.target = points.entity 22 | 23 | sprite:clearInstances() 24 | sprite.visible = false 25 | points.visible = true 26 | else 27 | text.text = "Sprite"..parttext 28 | type = ParticlesType.SPRITES 29 | particles.target = sprite.entity 30 | 31 | points:clearPoints() 32 | points.visible = false 33 | sprite.visible = true 34 | end 35 | end 36 | 37 | 38 | text.anchorPreset = AnchorPreset.CENTER_TOP 39 | 40 | text.text = "Sprite"..parttext 41 | type = ParticlesType.SPRITES 42 | 43 | sprite:setPosition(300, 100, 0); 44 | sprite.pivotPreset = PivotPreset.CENTER; 45 | sprite:setTexture("explosion.png"); 46 | sprite:setSize(50, 50); 47 | for i = 0,3,1 do 48 | for j = 0,3,1 do 49 | sprite:addFrame((i+(j*3)), "", Rect(i * ((1/3.0)), j * ((1/3.0)), (1/3.0), (1/3.0))); 50 | end 51 | end 52 | 53 | points:setPosition(300, 100, 0) 54 | points:setTexture("explosion.png") 55 | for i = 0,3,1 do 56 | for j = 0,3,1 do 57 | points:addSpriteFrame((i+(j*3)), "", Rect(i * ((1/3.0)), j * ((1/3.0)), (1/3.0), (1/3.0))); 58 | end 59 | end 60 | 61 | 62 | particles.target = sprite.entity 63 | 64 | particles:setLifeInitializer(10) 65 | 66 | particles:setPositionInitializer(Vector3(0,0,0), Vector3(300,0,0)) 67 | --particles:setPositionModifier(2,4, Vector3(0,0,0), Vector3(0,300,0)) 68 | 69 | particles:setVelocityInitializer(Vector3(0,10,0), Vector3(0,50,0)) 70 | particles:setVelocityModifier(5, 8, Vector3(0,10,0), Vector3(0,300,0), EaseType.CUBIC_IN_OUT) 71 | 72 | --particles:setAccelerationInitializer(Vector3(0,100,0), Vector3(0,200,0)) 73 | 74 | particles:setColorInitializer(Vector3(0,0,0), Vector3(1,1,1)) 75 | --particles:setColorModifier(2, 5, Vector3(1,1,1), Vector3(1,0,0)) 76 | 77 | --particles:setAlphaInitializer(0, 1) 78 | particles:setAlphaModifier(4, 6, 1, 0.2) 79 | 80 | particles:setSizeInitializer(10, 50) 81 | particles:setScaleInitializer(1.0/5.0, 1.0) 82 | 83 | particles:setSpriteIntializer(0, 2) 84 | particles:setSpriteModifier(1, 8, {0,1,2,3,4,5,6,7,8}) 85 | 86 | --particles:setRotationInitializer(90) 87 | --particles:setRotationModifier(1, 5, 0, 360) 88 | 89 | Engine.setScene(scene) 90 | Engine.onKeyDown = onKeyDown 91 | 92 | particles:start() -------------------------------------------------------------------------------- /particles/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Supernova.h" 2 | using namespace Supernova; 3 | 4 | enum class ParticlesType{ 5 | POINTS, 6 | SPRITES 7 | }; 8 | 9 | std::string parttext(" particles (press any key to change)"); 10 | 11 | Scene scene; 12 | 13 | Text text(&scene); 14 | 15 | Points points(&scene); 16 | Sprite sprite(&scene); 17 | Particles particles(&scene); 18 | 19 | ParticlesType type; 20 | 21 | void onKeyDown(int key, bool repeat, int mods); 22 | 23 | void init(){ 24 | text.setAnchorPreset(AnchorPreset::CENTER_TOP); 25 | 26 | text.setText("Sprite" + parttext); 27 | type = ParticlesType::SPRITES; 28 | 29 | sprite.setPosition(300, 100, 0); 30 | sprite.setPivotPreset(PivotPreset::CENTER); 31 | sprite.setTexture("explosion.png"); 32 | sprite.setSize(50, 50); 33 | for (int i = 0; i < 3; i++){ 34 | for (int j = 0; j < 3; j++){ 35 | sprite.addFrame((i+(j*3)), "", Rect(i * ((1/3.0)), j * ((1/3.0)), (1/3.0), (1/3.0))); 36 | } 37 | } 38 | 39 | points.setPosition(300, 100, 0); 40 | points.setTexture("explosion.png"); 41 | for (int i = 0; i < 3; i++){ 42 | for (int j = 0; j < 3; j++){ 43 | points.addSpriteFrame((i+(j*3)), "", Rect(i * ((1/3.0)), j * ((1/3.0)), (1/3.0), (1/3.0))); 44 | } 45 | } 46 | 47 | //particles.addParticle(Vector3(30, 30, 0), Vector4(1.0, 1.0, 1.0, 1.0), 50, 40); 48 | //particles.addParticle(Vector3(20, 60, 0), Vector4(0.0, 1.0, 0.0, 1.0), 40, 0, Rect(0, 0, 0.5, 0.5)); 49 | 50 | particles.setTarget(&sprite); 51 | 52 | particles.setLifeInitializer(10); 53 | 54 | particles.setPositionInitializer(Vector3(0,0,0), Vector3(300,0,0)); 55 | //particles.setPositionModifier(2,4, Vector3(0,0,0), Vector3(0,300,0)); 56 | 57 | particles.setVelocityInitializer(Vector3(0,10,0), Vector3(0,50,0)); 58 | particles.setVelocityModifier(5, 8, Vector3(0,10,0), Vector3(0,300,0), EaseType::CUBIC_IN_OUT); 59 | 60 | //particles.setAccelerationInitializer(Vector3(0,100,0), Vector3(0,200,0)); 61 | 62 | particles.setColorInitializer(Vector3(0,0,0), Vector3(1,1,1)); 63 | //particles.setColorModifier(2, 5, Vector3(1,1,1), Vector3(1,0,0)); 64 | 65 | //particles.setAlphaInitializer(0, 1); 66 | particles.setAlphaModifier(4, 6, 1, 0.2); 67 | 68 | particles.setSizeInitializer(10, 50); //for points 69 | particles.setScaleInitializer(1.0/5.0, 1.0); 70 | 71 | particles.setSpriteIntializer(0, 2); 72 | particles.setSpriteModifier(1, 8, {0,1,2,3,4,5,6,7,8}); 73 | 74 | //particles.setRotationInitializer(0, 90); 75 | //particles.setRotationModifier(1, 5, 0, 359); 76 | 77 | Engine::setScene(&scene); 78 | Engine::onKeyDown = onKeyDown; 79 | 80 | particles.start(); 81 | } 82 | 83 | void onKeyDown(int key, bool repeat, int mods){ 84 | if (type == ParticlesType::SPRITES){ 85 | text.setText("Points" + parttext); 86 | type = ParticlesType::POINTS; 87 | particles.setTarget(&points); 88 | 89 | sprite.clearInstances(); 90 | sprite.setVisible(false); 91 | points.setVisible(true); 92 | }else{ 93 | text.setText("Sprite" + parttext); 94 | type = ParticlesType::SPRITES; 95 | particles.setTarget(&sprite); 96 | 97 | points.clearPoints(); 98 | points.setVisible(false); 99 | sprite.setVisible(true); 100 | } 101 | } -------------------------------------------------------------------------------- /particles3d_and_instances/assets/CommonTree_1.mtl: -------------------------------------------------------------------------------- 1 | # Blender MTL File: 'CommonTree_1.blend' 2 | # Material Count: 2 3 | 4 | newmtl Green 5 | Ns 96.078431 6 | Ka 1.000000 1.000000 1.000000 7 | Kd 0.069954 0.121857 0.047888 8 | Ks 0.500000 0.500000 0.500000 9 | Ke 0.000000 0.000000 0.000000 10 | Ni 1.000000 11 | d 1.000000 12 | illum 2 13 | 14 | newmtl Wood 15 | Ns 96.078431 16 | Ka 1.000000 1.000000 1.000000 17 | Kd 0.122341 0.056288 0.047609 18 | Ks 0.500000 0.500000 0.500000 19 | Ke 0.000000 0.000000 0.000000 20 | Ni 1.000000 21 | d 1.000000 22 | illum 2 23 | -------------------------------------------------------------------------------- /particles3d_and_instances/assets/ely_hills/ely_hills.shader: -------------------------------------------------------------------------------- 1 | // Direction & elevation checked and adjusted - Speaker 2 | 3 | textures/skies/ely_hills 4 | { 5 | qer_editorimage env/ely_hills/hills_ft.tga 6 | surfaceparm noimpact 7 | surfaceparm nolightmap 8 | q3map_globaltexture 9 | q3map_lightsubdivide 256 10 | surfaceparm sky 11 | q3map_surfacelight 200 12 | q3map_sun 1 1 1 200 25 40 13 | skyparms env/ely_hills/hills - - 14 | } 15 | -------------------------------------------------------------------------------- /particles3d_and_instances/assets/ely_hills/hills_bk.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/particles3d_and_instances/assets/ely_hills/hills_bk.tga -------------------------------------------------------------------------------- /particles3d_and_instances/assets/ely_hills/hills_dn.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/particles3d_and_instances/assets/ely_hills/hills_dn.tga -------------------------------------------------------------------------------- /particles3d_and_instances/assets/ely_hills/hills_ft.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/particles3d_and_instances/assets/ely_hills/hills_ft.tga -------------------------------------------------------------------------------- /particles3d_and_instances/assets/ely_hills/hills_lf.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/particles3d_and_instances/assets/ely_hills/hills_lf.tga -------------------------------------------------------------------------------- /particles3d_and_instances/assets/ely_hills/hills_rt.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/particles3d_and_instances/assets/ely_hills/hills_rt.tga -------------------------------------------------------------------------------- /particles3d_and_instances/assets/ely_hills/hills_up.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/particles3d_and_instances/assets/ely_hills/hills_up.tga -------------------------------------------------------------------------------- /particles3d_and_instances/assets/ely_hills/readme: -------------------------------------------------------------------------------- 1 | These sky boxes have been downloaded from http://www.3delyvisions.com. They were produced by Colin Lowndes using a properly licensed copy of TerraGen. The author granted permission to distribute these sky boxes under the GNU General Public License version 2. Thanks, Colin! 2 | 3 | I (Laszlo Menczel aka Speaker) converted the textures to TGA format and resized the ones not conforming to the power-of-two texture size rule of Quake3. Also renamed the textures to conform to the name conventions of sky boxes in Quake3 (i.e. using the postfixes _bk, _ft, _lf, _rt and _up). The original boxes did not have 'down' textures. I made a 512x512 neutral grey image and added copies of this to each sky box as a fake 'down' texture. 4 | -------------------------------------------------------------------------------- /particles3d_and_instances/assets/ground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/particles3d_and_instances/assets/ground.png -------------------------------------------------------------------------------- /particles3d_and_instances/assets/particle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/particles3d_and_instances/assets/particle.png -------------------------------------------------------------------------------- /particles3d_and_instances/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Supernova.h" 2 | 3 | using namespace Supernova; 4 | 5 | void onUpdate(); 6 | void onKeyDown(int key, bool repeat, int mods); 7 | void onTouchStart(int pointer, float x, float y); 8 | void onTouchMove(int pointer, float x, float y); 9 | 10 | Vector2 lastTouchPos; 11 | 12 | enum class ParticlesType{ 13 | MODEL, 14 | SPRITE 15 | }; 16 | 17 | std::string parttext(" particles (press SPACE to change)"); 18 | 19 | Scene scene; 20 | 21 | Camera camera(&scene); 22 | Shape terrain(&scene); 23 | SkyBox sky(&scene); 24 | Light sun(&scene); 25 | 26 | Particles particles(&scene); 27 | Sprite sprite(&scene); 28 | Shape cube(&scene); 29 | 30 | Model trees(&scene); 31 | 32 | Scene uiscene; 33 | Text text(&uiscene); 34 | 35 | ParticlesType type; 36 | 37 | void init(){ 38 | text.setAnchorPreset(AnchorPreset::CENTER_TOP); 39 | 40 | text.setText("Sprite" + parttext); 41 | type = ParticlesType::SPRITE; 42 | 43 | scene.setGlobalIllumination(0.1); 44 | scene.setCamera(camera.getEntity()); 45 | 46 | camera.setPosition(0, 7, 40); 47 | camera.setTarget(0, 7, 0); 48 | 49 | terrain.createPlane(200, 200); 50 | terrain.setTexture("ground.png"); 51 | 52 | cube.createBox(1,1,1); 53 | cube.setColor(0.2, 0.4, 1.0, 1.0); 54 | cube.setVisible(false); 55 | //cube.setCastShadows(false); 56 | 57 | //sprite.setPosition(0, 7, 0); 58 | sprite.setPivotPreset(PivotPreset::CENTER); 59 | sprite.setTexture("particle.png"); 60 | sprite.setColor(0.2, 0.4, 1.0, 1.0); 61 | //sprite.setBillboard(true, true, false); 62 | sprite.createInstancedMesh(); 63 | sprite.setInstancedBillboard(true); 64 | sprite.setCastShadows(false); 65 | sprite.setReceiveShadows(false); 66 | sprite.setSize(2,2); 67 | 68 | particles.setMaxParticles(100); 69 | particles.setRate(10); 70 | particles.setTarget(&sprite); 71 | particles.setLifeInitializer(5); 72 | particles.setSizeInitializer(4000,4000); 73 | particles.setVelocityInitializer(Vector3(-1,5,-1), Vector3(1,8,1)); 74 | //particles.setVelocityInitializer(Vector3(0,5,3), Vector3(0,8,3)); 75 | particles.setAccelerationInitializer(Vector3(0, -5, 0)); 76 | particles.start(); 77 | 78 | trees.loadModel("CommonTree_1.obj"); 79 | trees.setScale(3); 80 | for (int i = -100; i < 100; i+=20){ 81 | for (int j = -100; j < 100; j+=20){ 82 | if ((i > 10 || i < -10) && (j > 10 || j < -10)) 83 | trees.addInstance(i/3.0, 0.0, j/3.0); 84 | } 85 | } 86 | 87 | sky.setTextureFront("ely_hills/hills_lf.tga"); 88 | sky.setTextureBack("ely_hills/hills_rt.tga"); 89 | sky.setTextureLeft("ely_hills/hills_bk.tga"); 90 | sky.setTextureRight("ely_hills/hills_ft.tga"); 91 | sky.setTextureUp("ely_hills/hills_up.tga"); 92 | sky.setTextureDown("ely_hills/hills_dn.tga"); 93 | 94 | sun.setType(LightType::DIRECTIONAL); 95 | sun.setDirection(0,-0.7, -0.8); 96 | sun.setIntensity(10); 97 | sun.setShadows(true); 98 | 99 | Engine::setScene(&scene); 100 | Engine::addSceneLayer(&uiscene); 101 | Engine::setCallTouchInMouseEvent(true); 102 | 103 | Engine::onUpdate = onUpdate; 104 | Engine::onKeyDown = onKeyDown; 105 | Engine::onTouchStart = onTouchStart; 106 | Engine::onTouchMove = onTouchMove; 107 | } 108 | 109 | void onUpdate(){ 110 | if (Input::isKeyPressed(S_KEY_UP) || Input::isKeyPressed(S_KEY_W)){ 111 | camera.walkForward(1); 112 | }else if (Input::isKeyPressed(S_KEY_DOWN) || Input::isKeyPressed(S_KEY_S)){ 113 | camera.walkForward(-1); 114 | } 115 | 116 | if (Input::isKeyPressed(S_KEY_A)){ 117 | camera.slide(-1); 118 | }else if (Input::isKeyPressed(S_KEY_D)){ 119 | camera.slide(1); 120 | } 121 | 122 | if (Input::isKeyPressed(S_KEY_LEFT)){ 123 | camera.rotateView(2); 124 | }else if (Input::isKeyPressed(S_KEY_RIGHT)){ 125 | camera.rotateView(-2); 126 | } 127 | } 128 | 129 | void onKeyDown(int key, bool repeat, int mods){ 130 | //model.getAnimation(0).start(); 131 | if (key == S_KEY_SPACE){ 132 | if (type == ParticlesType::SPRITE){ 133 | text.setText("Model" + parttext); 134 | type = ParticlesType::MODEL; 135 | particles.setTarget(&cube); 136 | 137 | sprite.clearInstances(); 138 | sprite.setVisible(false); 139 | cube.setVisible(true); 140 | }else{ 141 | text.setText("Sprite" + parttext); 142 | type = ParticlesType::SPRITE; 143 | particles.setTarget(&sprite); 144 | 145 | cube.clearInstances(); 146 | cube.setVisible(false); 147 | sprite.setVisible(true); 148 | } 149 | } 150 | } 151 | 152 | void onTouchMove(int pointer, float x, float y){ 153 | float difX = lastTouchPos.x - x; 154 | float difY = lastTouchPos.y - y; 155 | lastTouchPos = Vector2(x, y); 156 | 157 | camera.rotateView(0.1 * difX); 158 | camera.elevateView(0.1 * difY); 159 | } 160 | 161 | void onTouchStart(int pointer, float x, float y){ 162 | lastTouchPos = Vector2(x, y); 163 | } 164 | -------------------------------------------------------------------------------- /persistence/assets/Button_Disable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/persistence/assets/Button_Disable.png -------------------------------------------------------------------------------- /persistence/assets/Button_Normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/persistence/assets/Button_Normal.png -------------------------------------------------------------------------------- /persistence/assets/Button_Press.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/persistence/assets/Button_Press.png -------------------------------------------------------------------------------- /persistence/lua/main.lua: -------------------------------------------------------------------------------- 1 | scene = Scene() 2 | 3 | button_save = Button(scene) 4 | button_read = Button(scene) 5 | button_storage_save = Button(scene) 6 | button_storage_read = Button(scene) 7 | 8 | 9 | function onButton_save() 10 | Log.verbose("Save file path: " .. FileData.getSystemPath("data://test.txt")) 11 | file = File("data://test.txt", true) 12 | file:writeString("The string has words and keyword\n") 13 | file:writeString("This is a string which is written to a file\n") 14 | file:flush() 15 | end 16 | 17 | function onButton_read() 18 | Log.verbose("Read file path: " .. FileData.getSystemPath("data://test.txt")) 19 | file = File() 20 | if (file:open("data://test.txt") == FileErrors.FILEDATA_OK) then 21 | Log.verbose(file:readString(file:length())) 22 | end 23 | end 24 | 25 | function onButton_storage_save() 26 | Log.verbose("Save key-value"); 27 | 28 | UserSettings.setBoolForKey("key1", true) 29 | UserSettings.setIntegerForKey("key2", 55) 30 | UserSettings.setLongForKey("key3", 545254545) 31 | UserSettings.setFloatForKey("key4", 23.54) 32 | UserSettings.setDoubleForKey("key5", 23434.645454) 33 | UserSettings.setStringForKey("key6", "testing string") 34 | data = Data("data://test.txt") 35 | UserSettings.setDataForKey("key7", data) 36 | end 37 | 38 | function onButton_storage_read() 39 | boolStr = "false" 40 | if (UserSettings.getBoolForKey("key1")) then 41 | boolStr = "true" 42 | end 43 | Log.verbose("Read bool key-value: " .. boolStr) 44 | Log.verbose("Read integer key-value: " .. UserSettings.getIntegerForKey("key2")) 45 | Log.verbose("Read long key-value: " .. UserSettings.getLongForKey("key3")) 46 | Log.verbose("Read float key-value: " .. UserSettings.getFloatForKey("key4")) 47 | Log.verbose("Read double key-value: " .. UserSettings.getDoubleForKey("key5")) 48 | Log.verbose("Read string key-value: " .. UserSettings.getStringForKey("key6")) 49 | 50 | data = UserSettings.getDataForKey("key7"); 51 | Log.verbose("Read data key-value: " .. data:readString()) 52 | 53 | Log.verbose("Deleting key4") 54 | UserSettings.removeKey("key4") 55 | end 56 | 57 | 58 | button_save:setTexture("asset://Button_Normal.png") 59 | button_save:setTexturePressed("/Button_Disable.png") 60 | button_save:setPosition(100, 100, 0) 61 | button_save:setSize(200, 100) 62 | button_save:setPatchMargin(5) 63 | button_save.label = "Save" 64 | button_save.labelFontSize = 40 65 | button_save.labelColor = Vector4(0.2, 0.2, 0.2, 1.0) 66 | button_save:getButtonComponent().onRelease = onButton_save; 67 | 68 | button_read:setTexture("Button_Normal.png") 69 | button_read:setTexturePressed("Button_Disable.png") 70 | button_read:setPosition(500, 100, 0) 71 | button_read:setSize(200, 100) 72 | button_read:setPatchMargin(5) 73 | button_read.label = "Read" 74 | button_read.labelFontSize = 40 75 | button_read.labelColor = Vector4(0.2, 0.2, 0.2, 1.0) 76 | button_read:getButtonComponent().onRelease = onButton_read 77 | 78 | button_storage_save:setTexture("Button_Normal.png") 79 | button_storage_save:setTexturePressed("Button_Disable.png") 80 | button_storage_save:setPosition(100, 300, 0) 81 | button_storage_save:setSize(300, 100) 82 | button_storage_save:setPatchMargin(5) 83 | button_storage_save.label = "Save user setting" 84 | button_storage_save.labelFontSize = 40 85 | button_storage_save.labelColor = Vector4(0.2, 0.2, 0.2, 1.0) 86 | button_storage_save:getButtonComponent().onRelease = onButton_storage_save 87 | 88 | button_storage_read:setTexture("Button_Normal.png") 89 | button_storage_read:setTexturePressed("Button_Disable.png") 90 | button_storage_read:setPosition(500, 300, 0) 91 | button_storage_read:setSize(300, 100) 92 | button_storage_read:setPatchMargin(5) 93 | button_storage_read.label = "Read user setting" 94 | button_storage_read.labelFontSize = 40 95 | button_storage_read.labelColor = Vector4(0.2, 0.2, 0.2, 1.0) 96 | button_storage_read:getButtonComponent().onRelease = onButton_storage_read 97 | 98 | Engine.setCanvasSize(1000,480) 99 | Engine.setScene(scene) -------------------------------------------------------------------------------- /persistence/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Supernova.h" 2 | using namespace Supernova; 3 | 4 | Scene scene; 5 | 6 | Button button_save(&scene); 7 | Button button_read(&scene); 8 | Button button_storage_save(&scene); 9 | Button button_storage_read(&scene); 10 | 11 | 12 | void onButton_save(){ 13 | Log::verbose("Save file path: %s", FileData::getSystemPath("data://test.txt").c_str()); 14 | File* file = new File("data://test.txt", true); 15 | file->writeString("The string has words and keyword\n"); 16 | file->writeString("This is a string which is written to a file\n"); 17 | delete file; 18 | } 19 | 20 | void onButton_read(){ 21 | Log::verbose("Read file path: %s", FileData::getSystemPath("data://test.txt").c_str()); 22 | File* file = new File(); 23 | if (file->open("data://test.txt")==FileErrors::FILEDATA_OK) { 24 | Log::verbose("%s", file->readString().c_str()); 25 | } 26 | delete file; 27 | } 28 | 29 | void onButton_storage_save(){ 30 | Log::verbose("Save key-value"); 31 | 32 | UserSettings::setBoolForKey("key1", true); 33 | UserSettings::setIntegerForKey("key2", 55); 34 | UserSettings::setLongForKey("key3", (long)5454545454545454545); 35 | UserSettings::setFloatForKey("key4", 23.54f); 36 | UserSettings::setDoubleForKey("key5", 23434.645454); 37 | UserSettings::setStringForKey("key6", "testing string"); 38 | Data data("data://test.txt"); 39 | UserSettings::setDataForKey("key7", data); 40 | } 41 | 42 | void onButton_storage_read(){ 43 | std::string boolStr = "false"; 44 | if (UserSettings::getBoolForKey("key1")) { 45 | boolStr = "true"; 46 | } 47 | Log::verbose("Read bool key-value: %s", boolStr.c_str()); 48 | Log::verbose("Read integer key-value: %i", UserSettings::getIntegerForKey("key2")); 49 | Log::verbose("Read long key-value: %ld", UserSettings::getLongForKey("key3")); 50 | Log::verbose("Read float key-value: %f", UserSettings::getFloatForKey("key4")); 51 | Log::verbose("Read double key-value: %f", UserSettings::getDoubleForKey("key5")); 52 | Log::verbose("Read string key-value: %s", UserSettings::getStringForKey("key6").c_str()); 53 | 54 | Data data = UserSettings::getDataForKey("key7"); 55 | Log::verbose("Read data key-value: %s", data.readString().c_str()); 56 | 57 | Log::verbose("Deleting key4"); 58 | UserSettings::removeKey("key4"); 59 | } 60 | 61 | void init(){ 62 | button_save.setTexture("asset://Button_Normal.png"); 63 | button_save.setTexturePressed("/Button_Disable.png"); 64 | button_save.setPosition(100, 100, 0); 65 | button_save.setSize(200, 100); 66 | button_save.setPatchMargin(5); 67 | button_save.setLabel("Save"); 68 | button_save.setLabelFontSize(40); 69 | button_save.setLabelColor(Vector4(0.2, 0.2, 0.2, 1.0)); 70 | button_save.getComponent().onRelease = onButton_save; 71 | 72 | button_read.setTexture("Button_Normal.png"); 73 | button_read.setTexturePressed("Button_Disable.png"); 74 | button_read.setPosition(500, 100, 0); 75 | button_read.setSize(200, 100); 76 | button_read.setPatchMargin(5); 77 | button_read.setLabel("Read"); 78 | button_read.setLabelFontSize(40); 79 | button_read.setLabelColor(Vector4(0.2, 0.2, 0.2, 1.0)); 80 | button_read.getComponent().onRelease = onButton_read; 81 | 82 | button_storage_save.setTexture("Button_Normal.png"); 83 | button_storage_save.setTexturePressed("Button_Disable.png"); 84 | button_storage_save.setPosition(100, 300, 0); 85 | button_storage_save.setSize(300, 100); 86 | button_storage_save.setPatchMargin(5); 87 | button_storage_save.setLabel("Save user setting"); 88 | button_storage_save.setLabelFontSize(40); 89 | button_storage_save.setLabelColor(Vector4(0.2, 0.2, 0.2, 1.0)); 90 | button_storage_save.getComponent().onRelease = onButton_storage_save; 91 | 92 | button_storage_read.setTexture("Button_Normal.png"); 93 | button_storage_read.setTexturePressed("Button_Disable.png"); 94 | button_storage_read.setPosition(500, 300, 0); 95 | button_storage_read.setSize(300, 100); 96 | button_storage_read.setPatchMargin(5); 97 | button_storage_read.setLabel("Read user setting"); 98 | button_storage_read.setLabelFontSize(40); 99 | button_storage_read.setLabelColor(Vector4(0.2, 0.2, 0.2, 1.0)); 100 | button_storage_read.getComponent().onRelease = onButton_storage_read; 101 | 102 | Engine::setCanvasSize(1000,480); 103 | Engine::setScene(&scene); 104 | } -------------------------------------------------------------------------------- /physics2d/assets/SoccerBall.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/physics2d/assets/SoccerBall.png -------------------------------------------------------------------------------- /physics2d/assets/crate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/physics2d/assets/crate.png -------------------------------------------------------------------------------- /physics2d/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Supernova.h" 2 | using namespace Supernova; 3 | 4 | #define MAXCRATES 4 5 | 6 | Scene scene; 7 | Camera camera(&scene); 8 | Sprite* crates[MAXCRATES]; 9 | Sprite* ball; 10 | Joint2D joint(&scene); 11 | 12 | Lines lines(&scene); 13 | Points points(&scene); 14 | 15 | Scene uiscene; 16 | Text text(&uiscene); 17 | 18 | void onUpdate(); 19 | void onKeyDown(int key, bool repeat, int mods); 20 | 21 | 22 | bool shouldCollide(Body2D bA, size_t sA, Body2D bB, size_t sB){ 23 | printf("Should collide %s %lu %s %lu\n", bA.getAttachedObject().getName().c_str(), sA, bB.getAttachedObject().getName().c_str(), sB); 24 | return true; 25 | } 26 | 27 | void beginContact2D(Body2D bA, size_t sA, Body2D bB, size_t sB){ 28 | printf("beginContact2D %s %lu %s %lu\n", bA.getAttachedObject().getName().c_str(), sA, bB.getAttachedObject().getName().c_str(), sB); 29 | } 30 | 31 | void endContact2D(Body2D bA, size_t sA, Body2D bB, size_t sB){ 32 | printf("endContact2D %s %lu %s %lu\n", bA.getAttachedObject().getName().c_str(), sA, bB.getAttachedObject().getName().c_str(), sB); 33 | } 34 | 35 | void hitContact2D(Body2D bA, size_t sA, Body2D bB, size_t sB, Vector2 point, Vector2 normal, float approachSpeed){ 36 | printf("hitContact2D %s %lu %s %lu (%f %f) (%f %f) %f\n", 37 | bA.getAttachedObject().getName().c_str(), sA, 38 | bB.getAttachedObject().getName().c_str(), sB, 39 | point.x, point.y, normal.x, normal.y, approachSpeed); 40 | } 41 | 42 | bool preSolve2D(Body2D bA, size_t sA, Body2D bB, size_t sB, Manifold2D manifold){ 43 | printf("preSolve2D %s %lu %s %lu\n", bA.getAttachedObject().getName().c_str(), sA, bB.getAttachedObject().getName().c_str(), sB); 44 | return true; 45 | } 46 | 47 | void startPositions(){ 48 | crates[0]->setPosition(170, 600); 49 | //crates[0]->setRotation(0, 0, 0); 50 | crates[0]->getBody2D().setLinearVelocity(Vector2(0, 0)); 51 | crates[0]->getBody2D().setAngularVelocity(0); 52 | crates[0]->getBody2D().setLinearDamping(0); 53 | crates[0]->getBody2D().setAngularDamping(0); 54 | crates[0]->getBody2D().applyMassFromShapes(); 55 | 56 | crates[1]->setPosition(110, 100); 57 | crates[1]->getBody2D().setLinearVelocity(Vector2(0, 0)); 58 | 59 | crates[2]->setPosition(500, 300); 60 | crates[2]->getBody2D().setLinearVelocity(Vector2(0, 0)); 61 | 62 | crates[3]->setPosition(700, 300); 63 | crates[3]->getBody2D().setLinearVelocity(Vector2(0, 0)); 64 | 65 | ball->setPosition(130, 450); 66 | ball->getBody2D().setLinearVelocity(Vector2(0, 0)); 67 | } 68 | 69 | 70 | void init(){ 71 | 72 | text.setText("Press any key to reset"); 73 | text.setAnchorPreset(AnchorPreset::CENTER_TOP); 74 | 75 | for (int i = 0; i < MAXCRATES; i++){ 76 | crates[i] = new Sprite(&scene); 77 | } 78 | ball = new Sprite(&scene); 79 | 80 | camera.setType(CameraType::CAMERA_ORTHO); 81 | scene.setCamera(camera.getEntity()); 82 | scene.setBackgroundColor(0.6, 0.6, 0.6); 83 | 84 | 85 | crates[0]->setTexture("crate.png"); 86 | crates[0]->setName("crate0"); 87 | crates[0]->setSize(100, 100); 88 | crates[0]->setPivotPreset(PivotPreset::CENTER); 89 | 90 | Body2D body = crates[0]->getBody2D(); 91 | body.createCenteredBoxShape(100, 100, Vector2(0,0), 0); 92 | body.setShapeDensity(1.0); 93 | body.setType(BodyType::DYNAMIC); 94 | body.load(); 95 | 96 | 97 | crates[1]->setTexture("crate.png"); 98 | crates[1]->setName("crate1"); 99 | crates[1]->setSize(100, 100); 100 | crates[1]->setPivotPreset(PivotPreset::CENTER); 101 | 102 | Body2D body1 = crates[1]->getBody2D(); 103 | body1.createCenteredBoxShape(100, 100); 104 | body1.setShapeDensity(1.0); 105 | body1.setShapeEnableHitEvents(true); 106 | body1.setShapePreSolveEvents(true); 107 | body1.load(); 108 | 109 | 110 | crates[2]->setTexture("crate.png"); 111 | crates[2]->setName("crate2"); 112 | crates[2]->setSize(100, 100); 113 | crates[2]->setPivotPreset(PivotPreset::CENTER); 114 | 115 | Body2D body2 = crates[2]->getBody2D(); 116 | body2.createCenteredBoxShape(100, 100); 117 | body2.setShapeDensity(1.0); 118 | body2.setType(BodyType::DYNAMIC); 119 | body2.load(); 120 | 121 | 122 | crates[3]->setTexture("crate.png"); 123 | crates[3]->setName("crate3"); 124 | crates[3]->setSize(100, 100); 125 | crates[3]->setPivotPreset(PivotPreset::CENTER); 126 | 127 | Body2D body3 = crates[3]->getBody2D(); 128 | body3.createCenteredBoxShape(100, 100); 129 | body3.setShapeDensity(1.0); 130 | body3.load(); 131 | 132 | 133 | ball->setTexture("SoccerBall.png"); 134 | ball->setName("soccerball"); 135 | ball->setSize(50, 50); 136 | ball->setPivotPreset(PivotPreset::CENTER); 137 | 138 | Body2D bodyball = ball->getBody2D(); 139 | bodyball.createCircleShape(Vector2(0, 0), 25); 140 | bodyball.setShapeDensity(1.0); 141 | bodyball.setType(BodyType::DYNAMIC); 142 | bodyball.load(); 143 | 144 | startPositions(); 145 | 146 | scene.getSystem()->shouldCollide2D = shouldCollide; 147 | scene.getSystem()->beginContact2D = beginContact2D; 148 | scene.getSystem()->endContact2D = endContact2D; 149 | scene.getSystem()->hitContact2D = hitContact2D; 150 | scene.getSystem()->preSolve2D = preSolve2D; 151 | 152 | //scene.getSystem()->setGravity(0,10); 153 | 154 | joint.setDistanceJoint(body2.getEntity(), body3.getEntity(), Vector2(crates[2]->getPosition()), Vector2(crates[3]->getPosition()), false); 155 | 156 | lines.addLine(Vector3(725, 0, 0), Vector3(725, 500, 0)); 157 | 158 | points.addPoint(Vector3(0, 0, 0), Vector4(1, 0, 1, 1), 10); 159 | points.setPointVisible(0, false); 160 | 161 | Engine::setScalingMode(Scaling::FITWIDTH); 162 | Engine::setCanvasSize(1000,480); 163 | Engine::setScene(&scene); 164 | Engine::addSceneLayer(&uiscene); 165 | 166 | Engine::onUpdate = onUpdate; 167 | Engine::onKeyDown = onKeyDown; 168 | } 169 | 170 | void onUpdate(){ 171 | Ray ray(Vector3(725, 0, 0), Vector3(0, 500, 0)); 172 | RayReturn rret = ray.intersects(&scene, RayFilter::BODY_2D); 173 | 174 | if (rret.hit){ 175 | points.updatePoint(0, rret.point); 176 | points.setPointVisible(0, true); 177 | }else{ 178 | points.setPointVisible(0, false); 179 | } 180 | } 181 | 182 | void onKeyDown(int key, bool repeat, int mods){ 183 | startPositions(); 184 | } 185 | -------------------------------------------------------------------------------- /physics3d/assets/block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/physics3d/assets/block.png -------------------------------------------------------------------------------- /physics3d/assets/ely_hills/ely_hills.shader: -------------------------------------------------------------------------------- 1 | // Direction & elevation checked and adjusted - Speaker 2 | 3 | textures/skies/ely_hills 4 | { 5 | qer_editorimage env/ely_hills/hills_ft.tga 6 | surfaceparm noimpact 7 | surfaceparm nolightmap 8 | q3map_globaltexture 9 | q3map_lightsubdivide 256 10 | surfaceparm sky 11 | q3map_surfacelight 200 12 | q3map_sun 1 1 1 200 25 40 13 | skyparms env/ely_hills/hills - - 14 | } 15 | -------------------------------------------------------------------------------- /physics3d/assets/ely_hills/hills_bk.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/physics3d/assets/ely_hills/hills_bk.tga -------------------------------------------------------------------------------- /physics3d/assets/ely_hills/hills_dn.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/physics3d/assets/ely_hills/hills_dn.tga -------------------------------------------------------------------------------- /physics3d/assets/ely_hills/hills_ft.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/physics3d/assets/ely_hills/hills_ft.tga -------------------------------------------------------------------------------- /physics3d/assets/ely_hills/hills_lf.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/physics3d/assets/ely_hills/hills_lf.tga -------------------------------------------------------------------------------- /physics3d/assets/ely_hills/hills_rt.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/physics3d/assets/ely_hills/hills_rt.tga -------------------------------------------------------------------------------- /physics3d/assets/ely_hills/hills_up.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/physics3d/assets/ely_hills/hills_up.tga -------------------------------------------------------------------------------- /physics3d/assets/ely_hills/readme: -------------------------------------------------------------------------------- 1 | These sky boxes have been downloaded from http://www.3delyvisions.com. They were produced by Colin Lowndes using a properly licensed copy of TerraGen. The author granted permission to distribute these sky boxes under the GNU General Public License version 2. Thanks, Colin! 2 | 3 | I (Laszlo Menczel aka Speaker) converted the textures to TGA format and resized the ones not conforming to the power-of-two texture size rule of Quake3. Also renamed the textures to conform to the name conventions of sky boxes in Quake3 (i.e. using the postfixes _bk, _ft, _lf, _rt and _up). The original boxes did not have 'down' textures. I made a 512x512 neutral grey image and added copies of this to each sky box as a fake 'down' texture. 4 | -------------------------------------------------------------------------------- /physics3d/assets/ground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/physics3d/assets/ground.png -------------------------------------------------------------------------------- /physics3d/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Supernova.h" 2 | using namespace Supernova; 3 | 4 | const float cubeSize = 1; 5 | const float sphereSize = 1; 6 | const float terrainSize = 20; 7 | 8 | 9 | Vector2 lastTouchPos; 10 | 11 | Scene scene; 12 | 13 | Camera camera(&scene); 14 | Shape terrain(&scene); 15 | SkyBox sky(&scene); 16 | 17 | 18 | Shape* cubes[4]; 19 | Shape* spheres[4]; 20 | 21 | Shape* cubesjoint[2]; 22 | 23 | Joint3D joint(&scene); 24 | 25 | Scene uiscene; 26 | Text text(&uiscene); 27 | 28 | void onKeyDown(int key, bool repeat, int mods); 29 | void onTouchStart(int pointer, float x, float y); 30 | void onTouchMove(int pointer, float x, float y); 31 | void onMouseScroll(float xoffset, float yoffset, int mods); 32 | 33 | void onContactAdded3D(Body3D bA, Body3D bB, Contact3D inContact){ 34 | printf("onContactAdded3D %s %s\n", bA.getAttachedObject().getName().c_str(), bB.getAttachedObject().getName().c_str()); 35 | } 36 | 37 | void onContactPersisted3D(Body3D bA, Body3D bB, Contact3D inContact){ 38 | //printf("onContactPersisted3D %s %s\n", bA.getAttachedObject().getName().c_str(), bB.getAttachedObject().getName().c_str()); 39 | } 40 | 41 | void onContactRemoved3D(Body3D bA, Body3D bB, unsigned long shapeIndex1, unsigned long shapeIndex2){ 42 | printf("onContactRemoved3D %s %s\n", bA.getAttachedObject().getName().c_str(), bB.getAttachedObject().getName().c_str()); 43 | } 44 | 45 | bool shouldCollide3D(Body3D bA, Body3D bB, Vector3 inBaseOffset, CollideShapeResult3D inCollisionResult){ 46 | //printf("shouldCollide3D %s %s\n", bA.getAttachedObject().getName().c_str(), bB.getAttachedObject().getName().c_str()); 47 | 48 | return true; 49 | } 50 | 51 | void onBodyActivated3D(Body3D bA){ 52 | printf("onBodyActivated3D %s\n", bA.getAttachedObject().getName().c_str()); 53 | } 54 | 55 | void onBodyDeactivated3D(Body3D bA){ 56 | printf("onBodyDeactivated3D %s\n", bA.getAttachedObject().getName().c_str()); 57 | } 58 | 59 | void startPositions(){ 60 | cubesjoint[1]->setPosition(4, 9, 2); 61 | 62 | for (int i = 0; i < 4; i++){ 63 | if (i < 2){ 64 | cubes[i]->setPosition((4*i)-6, 11, -0.5); 65 | }else{ 66 | cubes[i]->setPosition((4*i)-6, 11, 0.5); 67 | } 68 | cubes[i]->getBody3D().setLinearVelocity(Vector3(0, 0, 0)); 69 | 70 | spheres[i]->setPosition((4*i)-5, 7, 0); 71 | spheres[i]->getBody3D().setLinearVelocity(Vector3(0, 0, 0)); 72 | } 73 | } 74 | 75 | 76 | void init(){ 77 | scene.getSystem()->onContactAdded3D = onContactAdded3D; 78 | scene.getSystem()->onContactPersisted3D = onContactPersisted3D; 79 | scene.getSystem()->onContactRemoved3D = onContactRemoved3D; 80 | scene.getSystem()->shouldCollide3D = shouldCollide3D; 81 | scene.getSystem()->onBodyActivated3D = onBodyActivated3D; 82 | scene.getSystem()->onBodyDeactivated3D = onBodyDeactivated3D; 83 | 84 | cubesjoint[0] = new Shape(&scene); 85 | cubesjoint[0]->createBox(cubeSize, cubeSize, cubeSize); 86 | cubesjoint[0]->setTexture("block.png"); 87 | cubesjoint[0]->setName("cubejoint0"); 88 | cubesjoint[0]->getBody3D().createBoxShape(cubeSize, cubeSize, cubeSize); 89 | cubesjoint[0]->getBody3D().load(); 90 | cubesjoint[0]->setPosition(0, 9, 2); 91 | 92 | cubesjoint[1] = new Shape(&scene); 93 | cubesjoint[1]->createBox(cubeSize, cubeSize, cubeSize); 94 | cubesjoint[1]->setTexture("block.png"); 95 | cubesjoint[1]->setName("cubejoint0"); 96 | cubesjoint[1]->getBody3D().setType(BodyType::DYNAMIC); 97 | cubesjoint[1]->getBody3D().createBoxShape(cubeSize, cubeSize, cubeSize); 98 | cubesjoint[1]->getBody3D().load(); 99 | 100 | for (int i = 0; i < 4; i++){ 101 | cubes[i] = new Shape(&scene); 102 | cubes[i]->createBox(cubeSize, cubeSize, cubeSize); 103 | cubes[i]->setTexture("block.png"); 104 | cubes[i]->setName("cube"+std::to_string(i)); 105 | cubes[i]->getBody3D().setType(BodyType::DYNAMIC); 106 | cubes[i]->getBody3D().createBoxShape(cubeSize, cubeSize, cubeSize); 107 | cubes[i]->getBody3D().load(); 108 | 109 | spheres[i] = new Shape(&scene); 110 | spheres[i]->createSphere(sphereSize); 111 | spheres[i]->setTexture("block.png"); 112 | spheres[i]->setName("sphere"+std::to_string(i)); 113 | spheres[i]->getBody3D().setType(BodyType::DYNAMIC); 114 | spheres[i]->getBody3D().createSphereShape(sphereSize); 115 | spheres[i]->getBody3D().load(); 116 | } 117 | startPositions(); 118 | 119 | joint.setDistanceJoint(cubesjoint[0]->getBody3D().getEntity(), cubesjoint[1]->getBody3D().getEntity(), cubesjoint[0]->getPosition(), cubesjoint[1]->getPosition()); 120 | 121 | lastTouchPos = Vector2(0, 0); 122 | 123 | scene.setGlobalIllumination(0.3); 124 | scene.setCamera(camera.getEntity()); 125 | 126 | text.setText("Press any key to reset"); 127 | text.setAnchorPreset(AnchorPreset::CENTER_TOP); 128 | text.setName("text"); 129 | 130 | camera.setPosition(0, 7, -20); 131 | camera.setTarget(0, 2, 0); 132 | 133 | terrain.createPlane(terrainSize, terrainSize); 134 | terrain.setTexture("ground.png"); 135 | terrain.setName("terrain"); 136 | Body3D bodyterrain = terrain.getBody3D(); 137 | bodyterrain.createMeshShape(); 138 | bodyterrain.load(); 139 | 140 | Light* sun = new Light(&scene); 141 | sun->setType(LightType::DIRECTIONAL); 142 | sun->setDirection(0,-0.6, 0.4); 143 | sun->setIntensity(4); 144 | sun->setShadows(true); 145 | 146 | sky.setTextureFront("ely_hills/hills_lf.tga"); 147 | sky.setTextureBack("ely_hills/hills_rt.tga"); 148 | sky.setTextureLeft("ely_hills/hills_bk.tga"); 149 | sky.setTextureRight("ely_hills/hills_ft.tga"); 150 | sky.setTextureUp("ely_hills/hills_up.tga"); 151 | sky.setTextureDown("ely_hills/hills_dn.tga"); 152 | 153 | Engine::setScalingMode(Scaling::FITWIDTH); 154 | Engine::setScene(&scene); 155 | Engine::addSceneLayer(&uiscene); 156 | Engine::setCallTouchInMouseEvent(true); 157 | 158 | Engine::onKeyDown = onKeyDown; 159 | Engine::onTouchStart = onTouchStart; 160 | Engine::onTouchMove = onTouchMove; 161 | Engine::onMouseScroll = onMouseScroll; 162 | } 163 | 164 | void onKeyDown(int key, bool repeat, int mods){ 165 | startPositions(); 166 | } 167 | 168 | void onTouchMove(int pointer, float x, float y){ 169 | float difX = lastTouchPos.x - x; 170 | float difY = lastTouchPos.y - y; 171 | lastTouchPos = Vector2(x, y); 172 | 173 | camera.rotatePosition(0.1 * difX); 174 | camera.elevatePosition(-0.1 * difY); 175 | } 176 | 177 | void onTouchStart(int pointer, float x, float y){ 178 | lastTouchPos = Vector2(x, y); 179 | } 180 | 181 | void onMouseScroll(float xoffset, float yoffset, int mods){ 182 | camera.slideForward(0.5 * yoffset); 183 | camera.setTarget(0, 2, 0); 184 | } -------------------------------------------------------------------------------- /physics3d_terrain/assets/block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/physics3d_terrain/assets/block.png -------------------------------------------------------------------------------- /physics3d_terrain/assets/ground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/physics3d_terrain/assets/ground.png -------------------------------------------------------------------------------- /physics3d_terrain/assets/heightmap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/physics3d_terrain/assets/heightmap.png -------------------------------------------------------------------------------- /physics3d_terrain/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Supernova.h" 2 | using namespace Supernova; 3 | 4 | float lastX; 5 | float lastY; 6 | float lastPressX; 7 | float lastPressY; 8 | 9 | Scene scene; 10 | Scene uiscene; 11 | 12 | Camera camera(&scene); 13 | Terrain terrain(&scene); 14 | Light sun(&scene); 15 | 16 | Text text(&uiscene); 17 | Text text2(&uiscene); 18 | 19 | Shape* cubes[25]; 20 | Shape* spheres[25]; 21 | 22 | void onViewLoaded(); 23 | void onUpdate(); 24 | void onKeyDown(int key, bool repeat, int mods); 25 | void onKeyUp(int key, bool repeat, int mods); 26 | void onTouchStart(int pointer, float x, float y); 27 | void onTouchMove(int pointer, float x, float y); 28 | 29 | void startPositions(){ 30 | for (int i = 0; i < 5; i++){ 31 | for (int j = 0; j < 5; j++){ 32 | cubes[(5*i)+j]->setPosition(10*i - 25, 15, 10*j - 25); 33 | cubes[(5*i)+j]->getBody3D().setLinearVelocity(Vector3(0,0,0)); 34 | 35 | spheres[(5*i)+j]->setPosition(10*i - 20, 15, 10*j - 20); 36 | spheres[(5*i)+j]->getBody3D().setLinearVelocity(Vector3(0,0,0)); 37 | } 38 | } 39 | } 40 | 41 | void init(){ 42 | 43 | for (int i = 0; i < 5; i++){ 44 | for (int j = 0; j < 5; j++){ 45 | cubes[(5*i)+j] = new Shape(&scene); 46 | cubes[(5*i)+j]->createBox(1.0, 1.0, 1.0); 47 | cubes[(5*i)+j]->setTexture("block.png"); 48 | cubes[(5*i)+j]->setName("cube"+std::to_string((4*i)+j)); 49 | cubes[(5*i)+j]->getBody3D().setType(BodyType::DYNAMIC); 50 | cubes[(5*i)+j]->getBody3D().createBoxShape(1, 1, 1); 51 | cubes[(5*i)+j]->getBody3D().load(); 52 | 53 | spheres[(5*i)+j] = new Shape(&scene); 54 | spheres[(5*i)+j]->createSphere(1.0); 55 | spheres[(5*i)+j]->setTexture("block.png"); 56 | spheres[(5*i)+j]->setName("sphere"+std::to_string((4*i)+j)); 57 | spheres[(5*i)+j]->getBody3D().setType(BodyType::DYNAMIC); 58 | spheres[(5*i)+j]->getBody3D().createSphereShape(1); 59 | spheres[(5*i)+j]->getBody3D().load(); 60 | } 61 | } 62 | startPositions(); 63 | 64 | camera.setPosition(0, 15, -50); 65 | scene.setCamera(camera.getEntity()); 66 | 67 | terrain.setName("terrain"); 68 | 69 | terrain.setHeightMap("heightmap.png"); 70 | terrain.setTexture("ground.png"); 71 | 72 | terrain.createTerrain(); 73 | 74 | Body3D bodyterrain = terrain.getBody3D(); 75 | bodyterrain.setType(BodyType::STATIC); 76 | bodyterrain.createHeightFieldShape(); 77 | bodyterrain.load(); 78 | 79 | scene.setGlobalIllumination(0.2); 80 | scene.setBackgroundColor(Vector4(0.5,0.5,0.5,1.0)); 81 | 82 | sun.setType(LightType::DIRECTIONAL); 83 | sun.setDirection(0.0f, -0.3, -0.8); 84 | sun.setShadows(true); 85 | 86 | text.setAnchorPreset(AnchorPreset::TOP_LEFT); 87 | text2.setAnchorPreset(AnchorPreset::CENTER_TOP); 88 | text2.setText("Press space to reset"); 89 | 90 | Engine::setCanvasSize(1000,480); 91 | Engine::setScene(&scene); 92 | Engine::addSceneLayer(&uiscene); 93 | Engine::setCallTouchInMouseEvent(true); 94 | 95 | Engine::onViewLoaded = onViewLoaded; 96 | Engine::onUpdate = onUpdate; 97 | Engine::onKeyDown = onKeyDown; 98 | Engine::onKeyUp = onKeyUp; 99 | Engine::onTouchStart = onTouchStart; 100 | Engine::onTouchMove = onTouchMove; 101 | } 102 | 103 | void onViewLoaded(){ 104 | 105 | 106 | } 107 | 108 | void onUpdate(){ 109 | text.setText(std::string("FPS: ") + std::to_string(Engine::getFramerate()).c_str()); 110 | 111 | if (Input::isKeyPressed(S_KEY_UP) || Input::isKeyPressed(S_KEY_W)){ 112 | camera.walkForward(1); 113 | } 114 | if (Input::isKeyPressed(S_KEY_DOWN) || Input::isKeyPressed(S_KEY_S)){ 115 | camera.walkForward(-1); 116 | } 117 | if (Input::isKeyPressed(S_KEY_LEFT)){ 118 | camera.rotateView(1); 119 | } 120 | if (Input::isKeyPressed(S_KEY_RIGHT)){ 121 | camera.rotateView(-1); 122 | } 123 | if (Input::isKeyPressed(S_KEY_A)){ 124 | camera.slide(-1); 125 | } 126 | if (Input::isKeyPressed(S_KEY_D)){ 127 | camera.slide(1); 128 | } 129 | 130 | } 131 | 132 | void onKeyDown(int key, bool repeat, int mods){ 133 | if (key == S_KEY_X){ 134 | camera.setPosition(camera.getPosition().x, camera.getPosition().y+10, camera.getPosition().z); 135 | camera.setTarget(camera.getTarget().x, camera.getTarget().y+10, camera.getTarget().z); 136 | } 137 | 138 | if (key == S_KEY_Z){ 139 | camera.setPosition(camera.getPosition().x, camera.getPosition().y-10, camera.getPosition().z); 140 | camera.setTarget(camera.getTarget().x, camera.getTarget().y-10, camera.getTarget().z); 141 | } 142 | 143 | if (key == S_KEY_SPACE){ 144 | startPositions(); 145 | } 146 | } 147 | 148 | void onKeyUp(int key, bool repeat, int mods){ 149 | if (key == S_KEY_F){ 150 | if (!System::instance().isFullscreen()) { 151 | System::instance().requestFullscreen(); 152 | }else{ 153 | System::instance().exitFullscreen(); 154 | } 155 | } 156 | } 157 | 158 | void onTouchStart(int pointer, float x, float y) { 159 | lastX = x; 160 | lastY = y; 161 | lastPressX = x; 162 | lastPressY = y; 163 | } 164 | 165 | void onTouchMove(int pointer, float x, float y) { 166 | float difX = lastX - x; 167 | lastX = x; 168 | camera.rotateView(0.1 * difX); 169 | 170 | float difY = lastY - y; 171 | lastY = y; 172 | camera.elevateView(-0.1 * difY); 173 | } -------------------------------------------------------------------------------- /shapes/assets/block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/shapes/assets/block.png -------------------------------------------------------------------------------- /shapes/lua/main.lua: -------------------------------------------------------------------------------- 1 | --print("lua file") -------------------------------------------------------------------------------- /shapes/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Supernova.h" 2 | using namespace Supernova; 3 | 4 | void onActionStep(); 5 | void onKeyDown(int key, bool repeat, int mods); 6 | void onTouchStart(int pointer, float x, float y); 7 | void onTouchMove(int pointer, float x, float y); 8 | 9 | Vector2 lastTouchPos; 10 | 11 | Scene scene; 12 | 13 | Camera camera(&scene); 14 | Shape torus(&scene); 15 | Shape cylinder(&scene); 16 | Shape cube(&scene); 17 | Shape sphere(&scene); 18 | Shape plane(&scene); 19 | Shape capsule(&scene); 20 | 21 | TimedAction timedaction(&scene); 22 | 23 | 24 | void init(){ 25 | scene.setCamera(camera.getEntity()); 26 | 27 | camera.setPosition(0, 30, 30); 28 | camera.setTarget(0, 0, 5); 29 | camera.setName("camera"); 30 | 31 | torus.createTorus(3, 1); 32 | torus.setTexture("block.png"); 33 | torus.setPosition(10,0,10); 34 | 35 | cylinder.createCylinder(1, 3); 36 | cylinder.setTexture("block.png"); 37 | cylinder.setPosition(-10,0,0); 38 | 39 | cube.createBox(4, 4, 4); 40 | cube.setTexture("block.png"); 41 | cube.setPosition(0,0,0); 42 | 43 | sphere.createSphere(3); 44 | sphere.setTexture("block.png"); 45 | sphere.setPosition(0,0,10); 46 | 47 | plane.createPlane(5, 5); 48 | plane.setTexture("block.png"); 49 | plane.setPosition(10,0,0); 50 | plane.setFaceCulling(false); 51 | 52 | capsule.createCapsule(1, 3); 53 | capsule.setTexture("block.png"); 54 | capsule.setPosition(-10,0,10); 55 | 56 | timedaction.setDuration(5); 57 | timedaction.setLoop(true); 58 | timedaction.getComponent().onStep = onActionStep; 59 | timedaction.start(); 60 | 61 | Engine::setScene(&scene); 62 | Engine::setCallTouchInMouseEvent(true); 63 | 64 | Engine::onTouchStart = onTouchStart; 65 | Engine::onTouchMove = onTouchMove; 66 | } 67 | 68 | void onActionStep(){ 69 | float angle = timedaction.getValue() * 360; 70 | 71 | Quaternion rot; 72 | rot.fromAngle(Angle::degToDefault(angle)); 73 | 74 | torus.setRotation(rot); 75 | cylinder.setRotation(rot); 76 | cube.setRotation(rot); 77 | sphere.setRotation(rot); 78 | plane.setRotation(rot); 79 | capsule.setRotation(rot); 80 | } 81 | 82 | void onTouchMove(int pointer, float x, float y){ 83 | float difX = lastTouchPos.x - x; 84 | float difY = lastTouchPos.y - y; 85 | lastTouchPos = Vector2(x, y); 86 | 87 | camera.rotateView(0.1 * difX); 88 | camera.elevateView(0.1 * difY); 89 | } 90 | 91 | void onTouchStart(int pointer, float x, float y){ 92 | lastTouchPos = Vector2(x, y); 93 | } 94 | -------------------------------------------------------------------------------- /simple_triangle/lua/main.lua: -------------------------------------------------------------------------------- 1 | scene = Scene() 2 | triangle = Polygon(scene) 3 | 4 | triangle:addVertex(0, -100) 5 | triangle:addVertex(-50, 50) 6 | triangle:addVertex(Vector3(50, 50,0)) 7 | 8 | triangle.position = Vector3(300,300,0) 9 | triangle:setColor(0.6, 0.2, 0.6, 1) 10 | 11 | Engine.setCanvasSize(1000,480) 12 | Engine.setScene(scene) -------------------------------------------------------------------------------- /simple_triangle/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Supernova.h" 2 | using namespace Supernova; 3 | 4 | Scene scene; 5 | Polygon triangle(&scene); 6 | 7 | void init(){ 8 | triangle.addVertex(0, -100); 9 | triangle.addVertex(-50, 50); 10 | triangle.addVertex(50, 50); 11 | 12 | triangle.setPosition(Vector3(300,300,0)); 13 | triangle.setColor(0.6, 0.2, 0.6, 1); 14 | 15 | Engine::setCanvasSize(1000,480); 16 | Engine::setScene(&scene); 17 | } -------------------------------------------------------------------------------- /skeletal_animation/assets/CesiumMan.glb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/skeletal_animation/assets/CesiumMan.glb -------------------------------------------------------------------------------- /skeletal_animation/assets/ely_hills/ely_hills.shader: -------------------------------------------------------------------------------- 1 | // Direction & elevation checked and adjusted - Speaker 2 | 3 | textures/skies/ely_hills 4 | { 5 | qer_editorimage env/ely_hills/hills_ft.tga 6 | surfaceparm noimpact 7 | surfaceparm nolightmap 8 | q3map_globaltexture 9 | q3map_lightsubdivide 256 10 | surfaceparm sky 11 | q3map_surfacelight 200 12 | q3map_sun 1 1 1 200 25 40 13 | skyparms env/ely_hills/hills - - 14 | } 15 | -------------------------------------------------------------------------------- /skeletal_animation/assets/ely_hills/hills_bk.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/skeletal_animation/assets/ely_hills/hills_bk.tga -------------------------------------------------------------------------------- /skeletal_animation/assets/ely_hills/hills_dn.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/skeletal_animation/assets/ely_hills/hills_dn.tga -------------------------------------------------------------------------------- /skeletal_animation/assets/ely_hills/hills_ft.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/skeletal_animation/assets/ely_hills/hills_ft.tga -------------------------------------------------------------------------------- /skeletal_animation/assets/ely_hills/hills_lf.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/skeletal_animation/assets/ely_hills/hills_lf.tga -------------------------------------------------------------------------------- /skeletal_animation/assets/ely_hills/hills_rt.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/skeletal_animation/assets/ely_hills/hills_rt.tga -------------------------------------------------------------------------------- /skeletal_animation/assets/ely_hills/hills_up.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/skeletal_animation/assets/ely_hills/hills_up.tga -------------------------------------------------------------------------------- /skeletal_animation/assets/ely_hills/readme: -------------------------------------------------------------------------------- 1 | These sky boxes have been downloaded from http://www.3delyvisions.com. They were produced by Colin Lowndes using a properly licensed copy of TerraGen. The author granted permission to distribute these sky boxes under the GNU General Public License version 2. Thanks, Colin! 2 | 3 | I (Laszlo Menczel aka Speaker) converted the textures to TGA format and resized the ones not conforming to the power-of-two texture size rule of Quake3. Also renamed the textures to conform to the name conventions of sky boxes in Quake3 (i.e. using the postfixes _bk, _ft, _lf, _rt and _up). The original boxes did not have 'down' textures. I made a 512x512 neutral grey image and added copies of this to each sky box as a fake 'down' texture. 4 | -------------------------------------------------------------------------------- /skeletal_animation/assets/ground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/skeletal_animation/assets/ground.png -------------------------------------------------------------------------------- /skeletal_animation/lua/main.lua: -------------------------------------------------------------------------------- 1 | lastTouchPos = Vector2(0, 0) 2 | 3 | scene = Scene() 4 | 5 | camera = Camera(scene) 6 | terrain = Shape(scene) 7 | model = Model(scene) 8 | sky = SkyBox(scene) 9 | sun = Light(scene) 10 | 11 | uiscene = Scene() 12 | text = Text(uiscene) 13 | 14 | function onKeyDown(key, rep, mods) 15 | model:getAnimation(0):start() 16 | end 17 | 18 | function onTouchStart(pointer, x, y) 19 | lastTouchPos = Vector2(x, y) 20 | end 21 | 22 | function onTouchMove(pointer, x, y) 23 | difX = lastTouchPos.x - x 24 | difY = lastTouchPos.y - y 25 | lastTouchPos = Vector2(x, y) 26 | 27 | camera:rotatePosition(0.1 * difX) 28 | camera:elevatePosition(-0.1 * difY) 29 | end 30 | 31 | scene.globalIlluminationIntensity = 0.1 32 | scene.camera = camera.entity 33 | 34 | text.text = "Press any key to start" 35 | text.anchorPreset = AnchorPreset.CENTER_TOP 36 | 37 | camera:setPosition(0, 7, -20) 38 | camera:setTarget(0, 2, 0); 39 | 40 | terrain:createPlane(200, 200) 41 | terrain:setTexture("ground.png") 42 | 43 | model:loadModel("CesiumMan.glb") 44 | model:setScale(4) 45 | model:setRotation(-90,0,0) 46 | model:getAnimation(0).loop = true 47 | 48 | sun.type = LightType.DIRECTIONAL 49 | sun:setDirection(0,-0.7, 0.8) 50 | sun:setIntensity(10) 51 | sun:setShadows(true) 52 | 53 | sky:setTextureFront("ely_hills/hills_lf.tga") 54 | sky:setTextureBack("ely_hills/hills_rt.tga") 55 | sky:setTextureLeft("ely_hills/hills_bk.tga") 56 | sky:setTextureRight("ely_hills/hills_ft.tga") 57 | sky:setTextureUp("ely_hills/hills_up.tga") 58 | sky:setTextureDown("ely_hills/hills_dn.tga") 59 | 60 | Engine.scalingMode = Scaling.FITWIDTH 61 | Engine.setCanvasSize(1000, 480) 62 | Engine.setScene(scene) 63 | Engine.addSceneLayer(uiscene) 64 | Engine.callTouchInMouseEvent = true 65 | 66 | Engine.onKeyDown = onKeyDown 67 | Engine.onTouchStart = onTouchStart 68 | Engine.onTouchMove = onTouchMove -------------------------------------------------------------------------------- /skeletal_animation/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Supernova.h" 2 | using namespace Supernova; 3 | 4 | void onKeyDown(int key, bool repeat, int mods); 5 | void onTouchStart(int pointer, float x, float y); 6 | void onTouchMove(int pointer, float x, float y); 7 | 8 | Vector2 lastTouchPos; 9 | 10 | Scene scene; 11 | 12 | Camera camera(&scene); 13 | Shape terrain(&scene); 14 | Model model(&scene); 15 | SkyBox sky(&scene); 16 | Light* sun = NULL; 17 | 18 | Scene uiscene; 19 | Text text(&uiscene); 20 | 21 | 22 | void init(){ 23 | scene.setGlobalIllumination(0.1); 24 | scene.setCamera(camera.getEntity()); 25 | 26 | text.setText("Press any key to start"); 27 | text.setAnchorPreset(AnchorPreset::CENTER_TOP); 28 | 29 | camera.setPosition(0, 7, -20); 30 | camera.setTarget(0, 2, 0); 31 | 32 | terrain.createPlane(200, 200); 33 | terrain.setTexture("ground.png"); 34 | 35 | model.loadModel("CesiumMan.glb"); 36 | model.setScale(4); 37 | model.setRotation(-90,0,0); 38 | model.getAnimation(0).setLoop(true); 39 | 40 | if (!sun) 41 | sun = new Light(&scene); 42 | sun->setType(LightType::DIRECTIONAL); 43 | sun->setDirection(0,-0.7, 0.8); 44 | sun->setIntensity(10); 45 | sun->setShadows(true); 46 | 47 | sky.setTextureFront("ely_hills/hills_lf.tga"); 48 | sky.setTextureBack("ely_hills/hills_rt.tga"); 49 | sky.setTextureLeft("ely_hills/hills_bk.tga"); 50 | sky.setTextureRight("ely_hills/hills_ft.tga"); 51 | sky.setTextureUp("ely_hills/hills_up.tga"); 52 | sky.setTextureDown("ely_hills/hills_dn.tga"); 53 | 54 | Engine::setScalingMode(Scaling::FITWIDTH); 55 | Engine::setCanvasSize(1000, 480); 56 | Engine::setScene(&scene); 57 | Engine::addSceneLayer(&uiscene); 58 | Engine::setCallTouchInMouseEvent(true); 59 | 60 | Engine::onKeyDown = onKeyDown; 61 | Engine::onTouchStart = onTouchStart; 62 | Engine::onTouchMove = onTouchMove; 63 | } 64 | 65 | void onKeyDown(int key, bool repeat, int mods){ 66 | model.getAnimation(0).start(); 67 | } 68 | 69 | void onTouchMove(int pointer, float x, float y){ 70 | float difX = lastTouchPos.x - x; 71 | float difY = lastTouchPos.y - y; 72 | lastTouchPos = Vector2(x, y); 73 | 74 | camera.rotatePosition(0.1 * difX); 75 | camera.elevatePosition(-0.1 * difY); 76 | } 77 | 78 | void onTouchStart(int pointer, float x, float y){ 79 | lastTouchPos = Vector2(x, y); 80 | } 81 | -------------------------------------------------------------------------------- /sprites/assets/dino.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/sprites/assets/dino.png -------------------------------------------------------------------------------- /sprites/lua/main.lua: -------------------------------------------------------------------------------- 1 | scene = Scene() 2 | 3 | camera = Camera(scene); 4 | 5 | sprite = Sprite(scene) 6 | sprite2 = Sprite(scene) 7 | spriteanim = SpriteAnimation(scene) 8 | 9 | 10 | function onActionStart() 11 | Log.verbose("Sprite start"); 12 | end 13 | 14 | function onTouchStart(pointer, x, y) 15 | spriteanim:start() 16 | sprite2:startAnimation(0, 7, 200, true) 17 | end 18 | 19 | 20 | camera.type = CameraType.CAMERA_ORTHO 21 | scene.camera = camera.entity 22 | 23 | sprite:setTexture("dino.png") 24 | for i=0,7 do 25 | sprite:addFrame(i, "", Rect((i+1.0)/8, 0.0, 1.0/8, 1.0)) 26 | end 27 | sprite:setFrame(0) 28 | sprite.name = "Sprite" 29 | sprite:setPosition(100,200,0) 30 | sprite:setSize(200,200) 31 | 32 | spriteanim.target = sprite.entity 33 | spriteanim:setAnimation(0, 7, 100, true) 34 | spriteanim:getActionComponent().onStart = onActionStart 35 | 36 | sprite2:setTexture("dino.png") 37 | for i=0,7 do 38 | sprite2:addFrame(i, "", Rect((i+1.0)/8, 0.0, 1.0/8, 1.0)) 39 | end 40 | sprite2:setFrame(0) 41 | sprite2.name = "Sprite2" 42 | sprite2:setPosition(400,200,0) 43 | sprite2:setSize(200,200) 44 | 45 | Engine.setScene(scene); 46 | Engine.setCallTouchInMouseEvent(true); 47 | 48 | Engine.onTouchStart = onTouchStart -------------------------------------------------------------------------------- /sprites/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Supernova.h" 2 | using namespace Supernova; 3 | 4 | Scene scene; 5 | 6 | Camera camera(&scene); 7 | 8 | Sprite sprite(&scene); 9 | Sprite sprite2(&scene); 10 | SpriteAnimation spriteanim(&scene); 11 | 12 | void onActionStart(); 13 | void onTouchStart(int pointer, float x, float y); 14 | 15 | void init(){ 16 | 17 | camera.setType(CameraType::CAMERA_ORTHO); 18 | scene.setCamera(camera.getEntity()); 19 | 20 | sprite.setTexture("dino.png"); 21 | for (int i = 0; i < 8; i++) 22 | sprite.addFrame(i, "", Rect((i+1.0)/8, 0.0, 1.0/8, 1.0)); 23 | sprite.setFrame(0); 24 | sprite.setName("Sprite"); 25 | sprite.setPosition(100,200,0); 26 | sprite.setSize(200,200); 27 | 28 | spriteanim.setTarget(sprite.getEntity()); 29 | spriteanim.setAnimation(0, 7, 100, true); 30 | spriteanim.getComponent().onStart = onActionStart; 31 | 32 | 33 | sprite2.setTexture("dino.png"); 34 | for (int i = 0; i < 8; i++) 35 | sprite2.addFrame(i, "", Rect((i+1.0)/8, 0.0, 1.0/8, 1.0)); 36 | sprite2.setFrame(0); 37 | sprite.setName("Sprite"); 38 | sprite2.setPosition(400,200,0); 39 | sprite2.setSize(200,200); 40 | 41 | Engine::setScene(&scene); 42 | Engine::setCallTouchInMouseEvent(true); 43 | 44 | Engine::onTouchStart = onTouchStart; 45 | } 46 | 47 | void onTouchStart(int pointer, float x, float y) { 48 | spriteanim.start(); 49 | sprite2.startAnimation(0, 7, 200, true); 50 | } 51 | 52 | void onActionStart(){ 53 | Log::verbose("Sprite start"); 54 | } -------------------------------------------------------------------------------- /terrain/assets/blendmap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/terrain/assets/blendmap.png -------------------------------------------------------------------------------- /terrain/assets/block.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/terrain/assets/block.png -------------------------------------------------------------------------------- /terrain/assets/ground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/terrain/assets/ground.png -------------------------------------------------------------------------------- /terrain/assets/heightmap.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/terrain/assets/heightmap.png -------------------------------------------------------------------------------- /terrain/lua/main.lua: -------------------------------------------------------------------------------- 1 | lastX = 0 2 | lastY = 0 3 | lastPressX = 0 4 | lastPressY = 0 5 | 6 | scene = Scene() 7 | uiscene = Scene() 8 | 9 | camera = Camera(scene) 10 | terrain = Terrain(scene) 11 | sun = Light(scene) 12 | 13 | textcontainer = Container(uiscene) 14 | text = Text(uiscene) 15 | text2 = Text(uiscene) 16 | text3 = Text(uiscene) 17 | text4 = Text(uiscene) 18 | 19 | 20 | function onUpdate() 21 | text.text = "FPS: " .. tostring(Engine.framerate) 22 | text2.text = "Camera X: " .. tostring(camera.position.x) 23 | text3.text = "Camera Y: " .. tostring(camera.position.y) 24 | text4.text = "Camera Z: " .. tostring(camera.position.z) 25 | 26 | if (Input.isKeyPressed(Input.KEY_UP) or Input.isKeyPressed(Input.KEY_W)) then 27 | camera:walkForward(1) 28 | end 29 | if (Input.isKeyPressed(Input.KEY_DOWN) or Input.isKeyPressed(Input.KEY_S)) then 30 | camera:walkForward(-1) 31 | end 32 | if Input.isKeyPressed(Input.KEY_LEFT) then 33 | camera:rotateView(1) 34 | end 35 | if Input.isKeyPressed(Input.KEY_RIGHT) then 36 | camera:rotateView(-1) 37 | end 38 | if Input.isKeyPressed(Input.KEY_A) then 39 | camera:slide(-1) 40 | end 41 | if Input.isKeyPressed(Input.KEY_D) then 42 | camera:slide(1) 43 | end 44 | end 45 | 46 | function onTouchStart(pointer, x, y) 47 | lastX = x 48 | lastY = y 49 | lastPressX = x 50 | lastPressY = y 51 | end 52 | 53 | function onTouchMove(pointer, x, y) 54 | difX = lastX - x 55 | lastX = x 56 | camera:rotateView(0.1 * difX) 57 | 58 | difY = lastY - y 59 | lastY = y 60 | camera:elevateView(-0.1 * difY) 61 | end 62 | 63 | function onKeyDown(key, rep, mods) 64 | if (key == Input.KEY_X) then 65 | camera:setPosition(camera.position.x, camera.position.y+10, camera.position.z); 66 | camera:setTarget(camera.view.x, camera.view.y+10, camera.view.z); 67 | end 68 | 69 | if (key == Input.KEY_Z) then 70 | camera:setPosition(camera.position.x, camera.position.y-10, camera.position.z); 71 | camera:setTarget(camera.view.x, camera.view.y-10, camera.view.z); 72 | end 73 | end 74 | 75 | function onKeyUp(key, rep, mods) 76 | if (key == Input.KEY_F) then 77 | if (not System.isFullscreen()) then 78 | System.requestFullscreen(); 79 | else 80 | System.exitFullscreen(); 81 | end 82 | end 83 | end 84 | 85 | 86 | camera.position = Vector3(0, 15, -60) 87 | 88 | terrain.name = "terrain" 89 | 90 | terrain:setHeightMap("heightmap.png") 91 | terrain:setTexture("ground.png") 92 | terrain:setBlendMap("blendmap.png") 93 | 94 | terrain:setTextureDetailRed("block.png"); 95 | terrain:setTextureDetailGreen("block.png"); 96 | terrain:setTextureDetailBlue("block.png"); 97 | 98 | scene.camera = camera.entity; 99 | 100 | scene.globalIlluminationIntensity = 0.1; 101 | 102 | sun:setType(LightType.DIRECTIONAL) 103 | sun:setDirection(0.0, -0.3, -0.8) 104 | sun:setShadows(true) 105 | 106 | textcontainer.anchorPreset = AnchorPreset.TOP_LEFT 107 | textcontainer:addChild(text) 108 | textcontainer:addChild(text2) 109 | textcontainer:addChild(text3) 110 | textcontainer:addChild(text4) 111 | 112 | Engine.setCanvasSize(1000,480) 113 | Engine.setScene(scene) 114 | Engine.addSceneLayer(uiscene) 115 | Engine.callTouchInMouseEvent = true 116 | 117 | Engine.onUpdate = onUpdate 118 | Engine.onTouchStart = onTouchStart 119 | Engine.onTouchMove = onTouchMove 120 | Engine.onKeyDown = onKeyDown 121 | Engine.onKeyUp = onKeyUp 122 | -------------------------------------------------------------------------------- /terrain/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Supernova.h" 2 | using namespace Supernova; 3 | 4 | float lastX; 5 | float lastY; 6 | float lastPressX; 7 | float lastPressY; 8 | 9 | Scene scene; 10 | Scene uiscene; 11 | 12 | Camera camera(&scene); 13 | Terrain terrain(&scene); 14 | Light sun(&scene); 15 | 16 | Container textcontainer(&uiscene); 17 | Text text(&uiscene); 18 | Text text2(&uiscene); 19 | Text text3(&uiscene); 20 | Text text4(&uiscene); 21 | 22 | void onUpdate(); 23 | void onKeyDown(int key, bool repeat, int mods); 24 | void onKeyUp(int key, bool repeat, int mods); 25 | void onTouchStart(int pointer, float x, float y); 26 | void onTouchMove(int pointer, float x, float y); 27 | 28 | void init(){ 29 | camera.setPosition(0, 15, -60); 30 | 31 | terrain.setName("terrain"); 32 | 33 | terrain.setHeightMap("heightmap.png"); 34 | terrain.setTexture("ground.png"); 35 | terrain.setBlendMap("blendmap.png"); 36 | 37 | terrain.setTextureDetailRed("block.png"); 38 | terrain.setTextureDetailGreen("block.png"); 39 | terrain.setTextureDetailBlue("block.png"); 40 | 41 | scene.setCamera(camera.getEntity()); 42 | 43 | scene.setGlobalIllumination(0.1); 44 | 45 | sun.setType(LightType::DIRECTIONAL); 46 | sun.setDirection(0.0f, -0.3, -0.8); 47 | sun.setShadows(true); 48 | 49 | textcontainer.setAnchorPreset(AnchorPreset::TOP_LEFT); 50 | textcontainer.addChild(&text); 51 | textcontainer.addChild(&text2); 52 | textcontainer.addChild(&text3); 53 | textcontainer.addChild(&text4); 54 | 55 | Engine::setCanvasSize(1000,480); 56 | Engine::setScene(&scene); 57 | Engine::addSceneLayer(&uiscene); 58 | Engine::setCallTouchInMouseEvent(true); 59 | 60 | Engine::onUpdate = onUpdate; 61 | Engine::onKeyDown = onKeyDown; 62 | Engine::onKeyUp = onKeyUp; 63 | Engine::onTouchStart = onTouchStart; 64 | Engine::onTouchMove = onTouchMove; 65 | } 66 | 67 | void onUpdate(){ 68 | text.setText(std::string("FPS: ") + std::to_string(Engine::getFramerate()).c_str()); 69 | text2.setText(std::string("Camera X: ") + std::to_string(camera.getWorldPosition().x)); 70 | text3.setText(std::string("Camera Y: ") + std::to_string(camera.getWorldPosition().y)); 71 | text4.setText(std::string("Camera Z: ") + std::to_string(camera.getWorldPosition().z)); 72 | 73 | if (Input::isKeyPressed(S_KEY_UP) || Input::isKeyPressed(S_KEY_W)){ 74 | camera.walkForward(1); 75 | } 76 | if (Input::isKeyPressed(S_KEY_DOWN) || Input::isKeyPressed(S_KEY_S)){ 77 | camera.walkForward(-1); 78 | } 79 | if (Input::isKeyPressed(S_KEY_LEFT)){ 80 | camera.rotateView(1); 81 | } 82 | if (Input::isKeyPressed(S_KEY_RIGHT)){ 83 | camera.rotateView(-1); 84 | } 85 | if (Input::isKeyPressed(S_KEY_A)){ 86 | camera.slide(-1); 87 | } 88 | if (Input::isKeyPressed(S_KEY_D)){ 89 | camera.slide(1); 90 | } 91 | 92 | } 93 | 94 | void onKeyDown(int key, bool repeat, int mods){ 95 | if (key == S_KEY_X){ 96 | camera.setPosition(camera.getPosition().x, camera.getPosition().y+10, camera.getPosition().z); 97 | camera.setTarget(camera.getTarget().x, camera.getTarget().y+10, camera.getTarget().z); 98 | } 99 | 100 | if (key == S_KEY_Z){ 101 | camera.setPosition(camera.getPosition().x, camera.getPosition().y-10, camera.getPosition().z); 102 | camera.setTarget(camera.getTarget().x, camera.getTarget().y-10, camera.getTarget().z); 103 | } 104 | } 105 | 106 | void onKeyUp(int key, bool repeat, int mods){ 107 | if (key == S_KEY_F){ 108 | if (!System::instance().isFullscreen()) { 109 | System::instance().requestFullscreen(); 110 | }else{ 111 | System::instance().exitFullscreen(); 112 | } 113 | } 114 | } 115 | 116 | void onTouchStart(int pointer, float x, float y) { 117 | lastX = x; 118 | lastY = y; 119 | lastPressX = x; 120 | lastPressY = y; 121 | } 122 | 123 | void onTouchMove(int pointer, float x, float y) { 124 | float difX = lastX - x; 125 | lastX = x; 126 | camera.rotateView(0.1 * difX); 127 | 128 | float difY = lastY - y; 129 | lastY = y; 130 | camera.elevateView(-0.1 * difY); 131 | } -------------------------------------------------------------------------------- /tilemap/assets/bg/BG.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/tilemap/assets/bg/BG.png -------------------------------------------------------------------------------- /tilemap/assets/object/Bush (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/tilemap/assets/object/Bush (1).png -------------------------------------------------------------------------------- /tilemap/assets/object/Bush (2).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/tilemap/assets/object/Bush (2).png -------------------------------------------------------------------------------- /tilemap/assets/object/Bush (3).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/tilemap/assets/object/Bush (3).png -------------------------------------------------------------------------------- /tilemap/assets/object/Bush (4).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/tilemap/assets/object/Bush (4).png -------------------------------------------------------------------------------- /tilemap/assets/object/Crate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/tilemap/assets/object/Crate.png -------------------------------------------------------------------------------- /tilemap/assets/object/Mushroom_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/tilemap/assets/object/Mushroom_1.png -------------------------------------------------------------------------------- /tilemap/assets/object/Mushroom_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/tilemap/assets/object/Mushroom_2.png -------------------------------------------------------------------------------- /tilemap/assets/object/Sign_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/tilemap/assets/object/Sign_1.png -------------------------------------------------------------------------------- /tilemap/assets/object/Sign_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/tilemap/assets/object/Sign_2.png -------------------------------------------------------------------------------- /tilemap/assets/object/Stone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/tilemap/assets/object/Stone.png -------------------------------------------------------------------------------- /tilemap/assets/object/Tree_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/tilemap/assets/object/Tree_1.png -------------------------------------------------------------------------------- /tilemap/assets/object/Tree_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/tilemap/assets/object/Tree_2.png -------------------------------------------------------------------------------- /tilemap/assets/object/Tree_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/tilemap/assets/object/Tree_3.png -------------------------------------------------------------------------------- /tilemap/assets/tiles/tileset1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/tilemap/assets/tiles/tileset1.png -------------------------------------------------------------------------------- /tilemap/assets/tiles/tileset2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/tilemap/assets/tiles/tileset2.png -------------------------------------------------------------------------------- /tilemap/lua/main.lua: -------------------------------------------------------------------------------- 1 | --print("lua file") -------------------------------------------------------------------------------- /tilemap/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Supernova.h" 2 | using namespace Supernova; 3 | 4 | Scene uiscene; 5 | Text text(&uiscene); 6 | 7 | Scene scene; 8 | 9 | Camera camera(&scene); 10 | 11 | std::vector objects; 12 | Sprite bg(&scene); 13 | Object map(&scene); 14 | Tilemap tilemap(&scene); 15 | 16 | const int tilesize = 128; 17 | const int numObjects = 4; 18 | 19 | void onUpdate(); 20 | 21 | 22 | void init(){ 23 | 24 | camera.setType(CameraType::CAMERA_ORTHO); 25 | camera.setTransparentSort(false); 26 | scene.setCamera(camera.getEntity()); 27 | scene.setBackgroundColor(0.867, 0.973, 1.0); 28 | 29 | text.setText("Use left and right arrow to move"); 30 | text.setAnchorPreset(AnchorPreset::CENTER_TOP); 31 | text.setColor(0.3, 0.3, 0.3, 1.0); 32 | 33 | map.setScale(0.6); 34 | map.addChild(&tilemap); 35 | 36 | objects.clear(); 37 | objects.reserve(numObjects); 38 | for (int i = 0; i < numObjects; i++){ 39 | objects.emplace_back(&scene); 40 | map.addChild(&objects[i]); 41 | } 42 | 43 | bg.setTexture("bg/BG.png"); 44 | 45 | objects[0].setTexture("object/Tree_1.png"); 46 | objects[0].setPosition(1*tilesize, 5*tilesize, 0); 47 | objects[0].setTextureScaleFactor(1.0); 48 | objects[1].setTexture("object/Tree_2.png"); 49 | objects[1].setPosition(5*tilesize, 2*tilesize, 0); 50 | objects[1].setTextureScaleFactor(1.0); 51 | objects[2].setTexture("object/Stone.png"); 52 | objects[2].setPosition(7*tilesize, 5*tilesize, 0); 53 | objects[2].setTextureScaleFactor(1.0); 54 | objects[3].setTexture("object/Sign_1.png"); 55 | objects[3].setPosition(11*tilesize, 3*tilesize, 0); 56 | objects[3].setTextureScaleFactor(1.0); 57 | 58 | tilemap.setTextureScaleFactor(1.0); 59 | 60 | for (int i = 0; i < 2; i++){ 61 | tilemap.addRect(i+16, "water"+std::to_string(i), "tiles/tileset2.png", TextureFilter::NEAREST, Rect(tilesize*i,0,tilesize,tilesize)); 62 | } 63 | 64 | for (int i = 0; i < 4; i++){ 65 | for (int j = 0; j < 4; j++){ 66 | tilemap.addRect(4*i + j, "tile"+std::to_string(i)+std::to_string(j), "tiles/tileset1.png", TextureFilter::NEAREST, Rect(tilesize*j,tilesize*i,tilesize,tilesize)); 67 | } 68 | } 69 | 70 | tilemap.addTile(0, Vector2(0*tilesize,4*tilesize), tilesize, tilesize); 71 | tilemap.addTile(1, Vector2(1*tilesize,4*tilesize), tilesize, tilesize); 72 | tilemap.addTile(2, Vector2(2*tilesize,4*tilesize), tilesize, tilesize); 73 | tilemap.addTile(3, Vector2(0*tilesize,3*tilesize), tilesize, tilesize); 74 | tilemap.addTile(4, Vector2(1*tilesize,3*tilesize), tilesize, tilesize); 75 | tilemap.addTile(5, Vector2(2*tilesize,3*tilesize), tilesize, tilesize); 76 | tilemap.addTile(11, Vector2(0*tilesize,2*tilesize), tilesize, tilesize); 77 | tilemap.addTile(8, Vector2(1*tilesize,2*tilesize), tilesize, tilesize); 78 | tilemap.addTile(15, Vector2(2*tilesize,2*tilesize), tilesize, tilesize); 79 | 80 | tilemap.addTile(0, Vector2(4*tilesize,1*tilesize), tilesize, tilesize); 81 | tilemap.addTile(1, Vector2(5*tilesize,1*tilesize), tilesize, tilesize); 82 | tilemap.addTile(2, Vector2(6*tilesize,1*tilesize), tilesize, tilesize); 83 | tilemap.addTile(3, Vector2(4*tilesize,0*tilesize), tilesize, tilesize); 84 | tilemap.addTile(4, Vector2(5*tilesize,0*tilesize), tilesize, tilesize); 85 | tilemap.addTile(5, Vector2(6*tilesize,0*tilesize), tilesize, tilesize); 86 | 87 | tilemap.addTile(12, Vector2(6*tilesize,4*tilesize), tilesize, tilesize); 88 | tilemap.addTile(13, Vector2(7*tilesize,4*tilesize), tilesize, tilesize); 89 | tilemap.addTile(14, Vector2(8*tilesize,4*tilesize), tilesize, tilesize); 90 | 91 | tilemap.addTile(12, Vector2(11*tilesize,2*tilesize), tilesize, tilesize); 92 | tilemap.addTile(14, Vector2(12*tilesize,2*tilesize), tilesize, tilesize); 93 | 94 | //water 95 | for (int i = -10; i < 20; i++){ 96 | tilemap.addTile(17, Vector2(i*tilesize,0*tilesize), tilesize, tilesize); 97 | tilemap.addTile(16, Vector2(i*tilesize,1*tilesize), tilesize, tilesize); 98 | } 99 | 100 | 101 | Engine::setScene(&scene); 102 | Engine::addSceneLayer(&uiscene); 103 | Engine::setCallTouchInMouseEvent(true); 104 | Engine::setAutomaticTransparency(false); 105 | 106 | Engine::onUpdate = onUpdate; 107 | } 108 | 109 | void onUpdate() { 110 | if (Input::isKeyPressed(S_KEY_LEFT)){ 111 | Vector3 oldPos = map.getPosition(); 112 | map.setPosition(oldPos.x+10, oldPos.y, oldPos.z); 113 | }else if (Input::isKeyPressed(S_KEY_RIGHT)){ 114 | Vector3 oldPos = map.getPosition(); 115 | map.setPosition(oldPos.x-10, oldPos.y, oldPos.z); 116 | } 117 | } -------------------------------------------------------------------------------- /user_interface/assets/button_disable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/user_interface/assets/button_disable.png -------------------------------------------------------------------------------- /user_interface/assets/button_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/user_interface/assets/button_normal.png -------------------------------------------------------------------------------- /user_interface/assets/paper_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/user_interface/assets/paper_icon.png -------------------------------------------------------------------------------- /user_interface/assets/textedit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/user_interface/assets/textedit.png -------------------------------------------------------------------------------- /user_interface/assets/tile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/user_interface/assets/tile.png -------------------------------------------------------------------------------- /user_interface/assets/window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/user_interface/assets/window.png -------------------------------------------------------------------------------- /user_interface/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Supernova.h" 2 | using namespace Supernova; 3 | 4 | Scene scene; 5 | 6 | Panel window(&scene); 7 | Container windowcontainer(&scene); 8 | Container iconlist(&scene); 9 | Scrollbar scroll(&scene); 10 | 11 | Panel window2(&scene); 12 | Button button(&scene); 13 | Button button2(&scene); 14 | TextEdit textedit(&scene); 15 | Text text(&scene); 16 | Container vcontainer(&scene); 17 | Container hcontainer(&scene); 18 | 19 | void onWindowResize(int width, int height); 20 | void onChangeScroll(float step); 21 | void onPress(); 22 | void onPress2(); 23 | 24 | void init(){ 25 | Engine::setCanvasSize(1000, 480); 26 | Engine::setCallTouchInMouseEvent(true); 27 | Engine::setScalingMode(Scaling::NATIVE); 28 | 29 | window.setSize(430, 400); 30 | window.setTitle("Files"); 31 | window.setTexture("window.png"); 32 | window.setPatchMargin(10, 10, 50, 10); 33 | window.setPosition(50, 50); 34 | window.addChild(&windowcontainer); 35 | window.setName("window"); 36 | window.getComponent().onResize = onWindowResize; 37 | 38 | windowcontainer.setType(ContainerType::HORIZONTAL); 39 | windowcontainer.setAnchorPreset(AnchorPreset::FULL_LAYOUT); 40 | windowcontainer.addChild(&iconlist); 41 | windowcontainer.addChild(&scroll); 42 | windowcontainer.setName("windowcontainer"); 43 | windowcontainer.setBoxExpand(1, false); 44 | 45 | iconlist.setType(ContainerType::HORIZONTAL_WRAP); 46 | iconlist.setAnchorPreset(AnchorPreset::TOP_WIDE); 47 | iconlist.setName("iconlist"); 48 | 49 | scroll.setSize(20, 20); 50 | scroll.setColor(0.5, 0.5, 0.5); 51 | scroll.setBarSize(0.6); 52 | scroll.setBarColor(0.8, 0.8, 0.8, 1.0); 53 | scroll.setStep(0.0); 54 | scroll.setType(ScrollbarType::VERTICAL); 55 | scroll.setAnchorPreset(AnchorPreset::VERTICAL_CENTER_WIDE); 56 | scroll.getComponent().onChange = onChangeScroll; 57 | scroll.setBarTexture("button_normal.png"); 58 | scroll.setBarPatchMargin(5); 59 | 60 | for (int i = 0; i < 22; i++){ 61 | Container* iconset = new Container(window.getScene()); 62 | Image* iconimage = new Image(window.getScene()); 63 | Text* icontext = new Text(window.getScene()); 64 | 65 | iconlist.addChild(iconset); 66 | 67 | iconset->addChild(iconimage); 68 | iconset->addChild(icontext); 69 | iconset->setName("iconset"); 70 | iconset->setAnchorPreset(AnchorPreset::CENTER); 71 | 72 | iconimage->setTexture("paper_icon.png"); 73 | iconimage->setSize(30, 40); 74 | iconimage->setAnchorPreset(AnchorPreset::CENTER); 75 | iconimage->setName("iconimage"); 76 | icontext->setText("terrain_"+std::to_string(i)+".obj"); 77 | icontext->setColor(0, 0, 0, 1); 78 | icontext->setFontSize(20); 79 | icontext->setAnchorPreset(AnchorPreset::CENTER); 80 | } 81 | 82 | // ============================================== 83 | 84 | vcontainer.addChild(&hcontainer); 85 | vcontainer.addChild(&button2); 86 | vcontainer.addChild(&text); 87 | vcontainer.setBoxExpand(0, true); 88 | vcontainer.setBoxExpand(1, false); 89 | vcontainer.setBoxExpand(2, true); 90 | 91 | hcontainer.addChild(&textedit); 92 | hcontainer.addChild(&button); 93 | hcontainer.setBoxExpand(true); 94 | 95 | //vcontainer.setSize(0,0); 96 | vcontainer.setType(ContainerType::VERTICAL); 97 | vcontainer.setName("vcontainer"); 98 | vcontainer.setAnchorPreset(AnchorPreset::FULL_LAYOUT); 99 | //container.setBoxExpand(0, false); 100 | 101 | hcontainer.setType(ContainerType::HORIZONTAL); 102 | hcontainer.setName("hcontainer"); 103 | hcontainer.setAnchorPreset(AnchorPreset::HORIZONTAL_CENTER_WIDE); 104 | 105 | button.setTexture("button_normal.png"); 106 | button.setTexturePressed("button_disable.png"); 107 | button.setPosition(100, 200, 0); 108 | button.setSize(200, 100); 109 | button.setPatchMargin(5); 110 | //button.setLabelFont("arial.ttf"); 111 | button.setLabel("Insert"); 112 | button.setName("button1"); 113 | button.setLabelFontSize(40); 114 | button.setLabelColor(Vector4(0.2, 0.2, 0.2, 1.0)); 115 | button.getComponent().onPress = onPress; 116 | button.setAnchorPreset(AnchorPreset::CENTER); 117 | 118 | button2.setTexture("button_normal.png"); 119 | button2.setTexturePressed("button_disable.png"); 120 | button2.setPosition(100, 200, 0); 121 | button2.setSize(200, 100); 122 | button2.setPatchMargin(5); 123 | button2.setLabel("Move position"); 124 | button2.setName("button2"); 125 | button2.setLabelFontSize(40); 126 | button2.setLabelColor(Vector4(0.2, 0.2, 0.2, 1.0)); 127 | button2.getComponent().onPress = onPress2; 128 | button2.setAnchorPreset(AnchorPreset::HORIZONTAL_CENTER_WIDE); 129 | //button2.setAnchors(0.5, 0.5, 0.5, 0.5); 130 | //button2.setMargins(-200,-200, 200,200); 131 | 132 | textedit.setPosition(300, 50, 0); 133 | textedit.setTexture("textedit.png"); 134 | textedit.setPatchMargin(5); 135 | textedit.setSize(200, 50); 136 | textedit.setText(""); 137 | textedit.setName("textedit"); 138 | textedit.setAnchorPreset(AnchorPreset::CENTER); 139 | //textedit.getComponent().ignoreScissor = true; 140 | 141 | text.setText("Any text"); 142 | text.setName("textobject"); 143 | text.setColor(Vector4(0.2, 0.2, 0.2, 1.0)); 144 | text.setAnchorPreset(AnchorPreset::CENTER_BOTTOM); 145 | 146 | window2.setTexture("window.png"); 147 | //window.getComponent().texture.setMinFilter(TextureFilter::NEAREST_MIPMAP_NEAREST); 148 | //window.getComponent().texture.setWrapU(TextureWrap::CLAMP_TO_EDGE); 149 | window2.setPosition(300,20,0); 150 | window2.setPatchMargin(10, 10, 50, 10); 151 | window2.setSize(600,400); 152 | window2.setName("window"); 153 | window2.setTitle("Window"); 154 | //window.setAnchorPreset(AnchorPreset::CENTER); 155 | window2.addChild(&vcontainer); 156 | 157 | Engine::setScene(&scene); 158 | } 159 | 160 | void onWindowResize(int width, int height){ 161 | float bar = (float)windowcontainer.getHeight() / (float)iconlist.getHeight(); 162 | 163 | scroll.setBarSize(bar); 164 | 165 | if (bar >= 1){ 166 | scroll.setVisible(false); 167 | }else{ 168 | scroll.setVisible(true); 169 | } 170 | } 171 | 172 | void onChangeScroll(float step){ 173 | int diff = iconlist.getHeight() - windowcontainer.getHeight(); 174 | 175 | iconlist.setPositionOffset(Vector2(0, -step*diff)); 176 | } 177 | 178 | void onPress(){ 179 | text.setText(textedit.getText()); 180 | } 181 | 182 | void onPress2(){ 183 | if (text.getAnchorPreset() == AnchorPreset::CENTER_BOTTOM){ 184 | text.setAnchorPreset(AnchorPreset::CENTER_RIGHT); 185 | }else if (text.getAnchorPreset() == AnchorPreset::CENTER_RIGHT){ 186 | text.setAnchorPreset(AnchorPreset::CENTER_TOP); 187 | }else if (text.getAnchorPreset() == AnchorPreset::CENTER_TOP){ 188 | text.setAnchorPreset(AnchorPreset::CENTER_LEFT); 189 | }else if (text.getAnchorPreset() == AnchorPreset::CENTER_LEFT){ 190 | text.setAnchorPreset(AnchorPreset::CENTER_BOTTOM); 191 | } 192 | } -------------------------------------------------------------------------------- /user_interface_3d/assets/ely_hills/ely_hills.shader: -------------------------------------------------------------------------------- 1 | // Direction & elevation checked and adjusted - Speaker 2 | 3 | textures/skies/ely_hills 4 | { 5 | qer_editorimage env/ely_hills/hills_ft.tga 6 | surfaceparm noimpact 7 | surfaceparm nolightmap 8 | q3map_globaltexture 9 | q3map_lightsubdivide 256 10 | surfaceparm sky 11 | q3map_surfacelight 200 12 | q3map_sun 1 1 1 200 25 40 13 | skyparms env/ely_hills/hills - - 14 | } 15 | -------------------------------------------------------------------------------- /user_interface_3d/assets/ely_hills/hills_bk.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/user_interface_3d/assets/ely_hills/hills_bk.tga -------------------------------------------------------------------------------- /user_interface_3d/assets/ely_hills/hills_dn.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/user_interface_3d/assets/ely_hills/hills_dn.tga -------------------------------------------------------------------------------- /user_interface_3d/assets/ely_hills/hills_ft.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/user_interface_3d/assets/ely_hills/hills_ft.tga -------------------------------------------------------------------------------- /user_interface_3d/assets/ely_hills/hills_lf.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/user_interface_3d/assets/ely_hills/hills_lf.tga -------------------------------------------------------------------------------- /user_interface_3d/assets/ely_hills/hills_rt.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/user_interface_3d/assets/ely_hills/hills_rt.tga -------------------------------------------------------------------------------- /user_interface_3d/assets/ely_hills/hills_up.tga: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/user_interface_3d/assets/ely_hills/hills_up.tga -------------------------------------------------------------------------------- /user_interface_3d/assets/ely_hills/readme: -------------------------------------------------------------------------------- 1 | These sky boxes have been downloaded from http://www.3delyvisions.com. They were produced by Colin Lowndes using a properly licensed copy of TerraGen. The author granted permission to distribute these sky boxes under the GNU General Public License version 2. Thanks, Colin! 2 | 3 | I (Laszlo Menczel aka Speaker) converted the textures to TGA format and resized the ones not conforming to the power-of-two texture size rule of Quake3. Also renamed the textures to conform to the name conventions of sky boxes in Quake3 (i.e. using the postfixes _bk, _ft, _lf, _rt and _up). The original boxes did not have 'down' textures. I made a 512x512 neutral grey image and added copies of this to each sky box as a fake 'down' texture. 4 | -------------------------------------------------------------------------------- /user_interface_3d/assets/ground.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/user_interface_3d/assets/ground.png -------------------------------------------------------------------------------- /user_interface_3d/assets/paper_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/user_interface_3d/assets/paper_icon.png -------------------------------------------------------------------------------- /user_interface_3d/assets/textedit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supernovaengine/supernova-samples/74ede7660a6ac46c5e1a346010ca328385c3b56f/user_interface_3d/assets/textedit.png -------------------------------------------------------------------------------- /user_interface_3d/main.cpp: -------------------------------------------------------------------------------- 1 | #include "Supernova.h" 2 | 3 | using namespace Supernova; 4 | 5 | void onUpdate(); 6 | void onCharInput(wchar_t codepoint); 7 | void onKeyDown(int key, bool repeat, int mods); 8 | void onTouchStart(int pointer, float x, float y); 9 | void onTouchMove(int pointer, float x, float y); 10 | void onTouchEnd(int pointer, float x, float y); 11 | 12 | void onWindowResize(int width, int height); 13 | void onChangeScroll(float step); 14 | void onPress(); 15 | void onPress2(); 16 | 17 | Vector2 lastTouchPos; 18 | 19 | Scene scene; 20 | 21 | Camera camera(&scene); 22 | Shape terrain(&scene); 23 | SkyBox sky(&scene); 24 | Light sun(&scene); 25 | 26 | Sprite wall(&scene); 27 | 28 | 29 | Scene uiscene; 30 | 31 | Panel window(&uiscene); 32 | Container windowcontainer(&uiscene); 33 | Container iconlist(&uiscene); 34 | Scrollbar scroll(&uiscene); 35 | 36 | Panel window2(&uiscene); 37 | Button button(&uiscene); 38 | Button button2(&uiscene); 39 | TextEdit textedit(&uiscene); 40 | Text text(&uiscene); 41 | Container vcontainer(&uiscene); 42 | Container hcontainer(&uiscene); 43 | 44 | 45 | void init(){ 46 | scene.setCamera(camera.getEntity()); 47 | scene.setGlobalIllumination(0.5); 48 | 49 | camera.setPosition(0, 7, 40); 50 | camera.setTarget(0, 15, 0); 51 | camera.setName("camera"); 52 | 53 | //sun.setType(LightType::DIRECTIONAL); 54 | //sun.setDirection(0, -0.4, -0.6); 55 | 56 | terrain.createPlane(200, 200); 57 | terrain.setTexture("ground.png"); 58 | terrain.setName("terrain"); 59 | 60 | Camera* camera2 = new Camera(&uiscene); 61 | 62 | camera2->setType(CameraType::CAMERA_2D); 63 | camera2->setFramebufferSize(1024, 1024); 64 | camera2->setRenderToTexture(true); 65 | uiscene.setEnableUIEvents(false); 66 | uiscene.setBackgroundColor(0.8, 0.8, 0.8, 0.2); 67 | 68 | uiscene.setCamera(camera2->getEntity()); 69 | 70 | //========================================= 71 | 72 | wall.setTexture(camera2->getFramebuffer()); 73 | wall.setSize(10,10); 74 | wall.setRotation(0, 45, 0); 75 | wall.setPosition(-5,5,30); 76 | wall.setName("wall"); 77 | 78 | window.addChild(&windowcontainer); 79 | window.setSize(430, 400); 80 | window.setTitle("Window"); 81 | window.setPatchMargin(10, 10, 50, 10); 82 | window.setPosition(100, 200); 83 | window.setHeaderColor(0.5, 0.5, 0.8, 1.0); 84 | window.getComponent().onResize = onWindowResize; 85 | 86 | windowcontainer.setType(ContainerType::HORIZONTAL); 87 | windowcontainer.setAnchorPreset(AnchorPreset::FULL_LAYOUT); 88 | windowcontainer.addChild(&iconlist); 89 | windowcontainer.addChild(&scroll); 90 | windowcontainer.setName("windowcontainer"); 91 | windowcontainer.setBoxExpand(1, false); 92 | 93 | iconlist.setType(ContainerType::HORIZONTAL_WRAP); 94 | iconlist.setAnchorPreset(AnchorPreset::TOP_WIDE); 95 | iconlist.setName("iconlist"); 96 | 97 | scroll.setSize(20, 20); 98 | scroll.setColor(0.5, 0.5, 0.5); 99 | scroll.setBarSize(0.6); 100 | scroll.setBarColor(0.8, 0.8, 0.8, 1.0); 101 | scroll.setStep(0.0); 102 | scroll.setType(ScrollbarType::VERTICAL); 103 | scroll.setAnchorPreset(AnchorPreset::VERTICAL_CENTER_WIDE); 104 | scroll.getComponent().onChange = onChangeScroll; 105 | scroll.setBarPatchMargin(5); 106 | 107 | for (int i = 0; i < 22; i++){ 108 | Container* iconset = new Container(window.getScene()); 109 | Image* iconimage = new Image(window.getScene()); 110 | Text* icontext = new Text(window.getScene()); 111 | 112 | iconlist.addChild(iconset); 113 | 114 | iconset->addChild(iconimage); 115 | iconset->addChild(icontext); 116 | iconset->setName("iconset"); 117 | iconset->setAnchorPreset(AnchorPreset::CENTER); 118 | 119 | iconimage->setTexture("paper_icon.png"); 120 | iconimage->setSize(30, 40); 121 | iconimage->setAnchorPreset(AnchorPreset::CENTER); 122 | iconimage->setName("iconimage"); 123 | icontext->setText("terrain_"+std::to_string(i)+".obj"); 124 | icontext->setColor(0, 0, 0, 1); 125 | icontext->setFontSize(20); 126 | icontext->setAnchorPreset(AnchorPreset::CENTER); 127 | } 128 | 129 | //========================================= 130 | 131 | window2.setSize(430, 400); 132 | window2.setTitle("Files"); 133 | window2.setPatchMargin(10, 10, 50, 10); 134 | window2.setPosition(400, 400); 135 | window2.setHeaderColor(0.5, 0.5, 0.8, 1.0); 136 | window2.addChild(&vcontainer); 137 | 138 | vcontainer.addChild(&hcontainer); 139 | vcontainer.addChild(&button2); 140 | vcontainer.addChild(&text); 141 | vcontainer.setBoxExpand(0, true); 142 | vcontainer.setBoxExpand(1, false); 143 | vcontainer.setBoxExpand(2, true); 144 | 145 | hcontainer.addChild(&textedit); 146 | hcontainer.addChild(&button); 147 | hcontainer.setBoxExpand(true); 148 | 149 | vcontainer.setType(ContainerType::VERTICAL); 150 | vcontainer.setName("vcontainer"); 151 | vcontainer.setAnchorPreset(AnchorPreset::FULL_LAYOUT); 152 | 153 | hcontainer.setType(ContainerType::HORIZONTAL); 154 | hcontainer.setName("hcontainer"); 155 | hcontainer.setAnchorPreset(AnchorPreset::HORIZONTAL_CENTER_WIDE); 156 | 157 | button.setColor(0.6, 0.6, 0.5, 1.0); 158 | button.setColorPressed(0.6, 0.2, 0.6, 1.0); 159 | button.setColorDisabled(0.2, 0.6, 0.6, 1.0); 160 | button.setPosition(100, 200, 0); 161 | button.setSize(200, 100); 162 | button.setPatchMargin(5); 163 | button.setLabel("Insert"); 164 | button.setName("button1"); 165 | button.setLabelFontSize(40); 166 | button.setLabelColor(Vector4(0.2, 0.2, 0.2, 1.0)); 167 | button.getComponent().onPress = onPress; 168 | button.setAnchorPreset(AnchorPreset::CENTER); 169 | 170 | button2.setColor(0.6, 0.6, 0.5, 1.0); 171 | button2.setColorPressed(0.6, 0.2, 0.6, 1.0); 172 | button2.setColorDisabled(0.2, 0.6, 0.6, 1.0); 173 | button2.setPosition(100, 200, 0); 174 | button2.setSize(200, 100); 175 | button2.setPatchMargin(5); 176 | button2.setLabel("Move position"); 177 | button2.setName("button2"); 178 | button2.setLabelFontSize(40); 179 | button2.setLabelColor(Vector4(0.2, 0.2, 0.2, 1.0)); 180 | button2.getComponent().onPress = onPress2; 181 | button2.setAnchorPreset(AnchorPreset::HORIZONTAL_CENTER_WIDE); 182 | 183 | textedit.setPosition(300, 50, 0); 184 | textedit.setTexture("textedit.png"); 185 | //textedit.setColor(0.3, 0.3, 0.3, 1.0); 186 | textedit.setPatchMargin(5); 187 | textedit.setSize(200, 50); 188 | textedit.setText(""); 189 | textedit.setName("textedit"); 190 | textedit.setAnchorPreset(AnchorPreset::CENTER); 191 | 192 | text.setText("Any text"); 193 | text.setName("textobject"); 194 | text.setColor(Vector4(0.2, 0.2, 0.2, 1.0)); 195 | text.setAnchorPreset(AnchorPreset::CENTER_BOTTOM); 196 | 197 | sky.setTextureFront("ely_hills/hills_lf.tga"); 198 | sky.setTextureBack("ely_hills/hills_rt.tga"); 199 | sky.setTextureLeft("ely_hills/hills_bk.tga"); 200 | sky.setTextureRight("ely_hills/hills_ft.tga"); 201 | sky.setTextureUp("ely_hills/hills_up.tga"); 202 | sky.setTextureDown("ely_hills/hills_dn.tga"); 203 | 204 | Engine::setScene(&scene); 205 | Engine::addSceneLayer(&uiscene); 206 | Engine::setCallTouchInMouseEvent(true); 207 | 208 | Engine::onUpdate = onUpdate; 209 | Engine::onCharInput = onCharInput; 210 | Engine::onKeyDown = onKeyDown; 211 | Engine::onTouchStart = onTouchStart; 212 | Engine::onTouchMove = onTouchMove; 213 | Engine::onTouchEnd = onTouchEnd; 214 | } 215 | 216 | void onUpdate(){ 217 | if (!uiscene.getSystem()->isTextEditFocused()){ 218 | if (Input::isKeyPressed(S_KEY_UP) || Input::isKeyPressed(S_KEY_W)){ 219 | camera.walkForward(1); 220 | }else if (Input::isKeyPressed(S_KEY_DOWN) || Input::isKeyPressed(S_KEY_S)){ 221 | camera.walkForward(-1); 222 | } 223 | 224 | if (Input::isKeyPressed(S_KEY_A)){ 225 | camera.slide(-1); 226 | }else if (Input::isKeyPressed(S_KEY_D)){ 227 | camera.slide(1); 228 | } 229 | 230 | if (Input::isKeyPressed(S_KEY_LEFT)){ 231 | camera.rotateView(2); 232 | }else if (Input::isKeyPressed(S_KEY_RIGHT)){ 233 | camera.rotateView(-2); 234 | } 235 | } 236 | } 237 | 238 | void onCharInput(wchar_t codepoint){ 239 | uiscene.getSystem()->eventOnCharInput(codepoint); 240 | } 241 | 242 | void onKeyDown(int key, bool repeat, int mods){ 243 | 244 | } 245 | 246 | void onTouchMove(int pointer, float x, float y){ 247 | Vector3 normal = ((wall.getModelMatrix() * Vector3(0, 0, 1)) - wall.getWorldPosition()).normalize(); 248 | Plane plane(normal, wall.getWorldPosition()); 249 | RayReturn rretrun = camera.screenToRay(x, y).intersects(plane); 250 | Vector3 point = wall.getModelMatrix().inverse() * rretrun.point; 251 | 252 | if (!uiscene.getSystem()->eventOnPointerMove(point.x * 1024 / 10, (wall.getHeight() - point.y) * 1024 / 10)){ 253 | float difX = lastTouchPos.x - x; 254 | float difY = lastTouchPos.y - y; 255 | lastTouchPos = Vector2(x, y); 256 | 257 | camera.rotateView(0.1 * difX); 258 | camera.elevateView(0.1 * difY); 259 | } 260 | } 261 | 262 | void onTouchStart(int pointer, float x, float y){ 263 | Vector3 normal = ((wall.getModelMatrix() * Vector3(0, 0, 1)) - wall.getWorldPosition()).normalize(); 264 | Plane plane(normal, wall.getWorldPosition()); 265 | RayReturn rretrun = camera.screenToRay(x, y).intersects(plane); 266 | Vector3 point = wall.getModelMatrix().inverse() * rretrun.point; 267 | 268 | if (!uiscene.getSystem()->eventOnPointerDown(point.x * 1024 / 10, (wall.getHeight() - point.y) * 1024 / 10)){ 269 | lastTouchPos = Vector2(x, y); 270 | } 271 | } 272 | 273 | void onTouchEnd(int pointer, float x, float y){ 274 | Vector3 normal = ((wall.getModelMatrix() * Vector3(0, 0, 1)) - wall.getWorldPosition()).normalize(); 275 | Plane plane(normal, wall.getWorldPosition()); 276 | RayReturn rretrun = camera.screenToRay(x, y).intersects(plane); 277 | Vector3 point = wall.getModelMatrix().inverse() * rretrun.point; 278 | 279 | uiscene.getSystem()->eventOnPointerUp(point.x * 1024 / 10, (wall.getHeight() - point.y) * 1024 / 10); 280 | } 281 | 282 | void onWindowResize(int width, int height){ 283 | float bar = (float)windowcontainer.getHeight() / (float)iconlist.getHeight(); 284 | 285 | scroll.setBarSize(bar); 286 | 287 | if (bar >= 1){ 288 | scroll.setVisible(false); 289 | }else{ 290 | scroll.setVisible(true); 291 | } 292 | } 293 | 294 | void onChangeScroll(float step){ 295 | int diff = iconlist.getHeight() - windowcontainer.getHeight(); 296 | 297 | iconlist.setPositionOffset(Vector2(0, -step*diff)); 298 | } 299 | 300 | void onPress(){ 301 | text.setText(textedit.getText()); 302 | } 303 | 304 | void onPress2(){ 305 | if (text.getAnchorPreset() == AnchorPreset::CENTER_BOTTOM){ 306 | text.setAnchorPreset(AnchorPreset::CENTER_RIGHT); 307 | }else if (text.getAnchorPreset() == AnchorPreset::CENTER_RIGHT){ 308 | text.setAnchorPreset(AnchorPreset::CENTER_TOP); 309 | }else if (text.getAnchorPreset() == AnchorPreset::CENTER_TOP){ 310 | text.setAnchorPreset(AnchorPreset::CENTER_LEFT); 311 | }else if (text.getAnchorPreset() == AnchorPreset::CENTER_LEFT){ 312 | text.setAnchorPreset(AnchorPreset::CENTER_BOTTOM); 313 | } 314 | } --------------------------------------------------------------------------------