Home
1. Introduction SIO2 SDK Overview
Contents
1. Move the pivar point of our constraint so the that block object 1 that we are draggin will move accordingly Lbtpoint2pointconatraint ssetpivers cam_loc dir normalize pick dat vold touchestndad void _ptr Sto2rouche _sr02touche i when the touche ia released if we have a selection simply J spacity that we want the collision object te be deactivated J whan its velocity become too low Af selection selection gt _sto2objectphyad WANTS _DEACTIVATION J _brnigidsody gt aetactivationstate J Remove our 3D constraint if any remove constraint We now have a full 3D physic picking code up running Build and run your application and start picking and dragging the blocks around in order to test the code Game Logic Since the rules of your game are purely physic based you will now have to handle different collision callbacks in order to handle our game states Let s first handle the game aver state which is really what determine the end of the game and allow us to restart the level For this you first need to create a collision callback that will notify you when a black touch the physic boundary determined by the limit object that you previously set to a static box collision shape so it its very easy for you to be able to determine if a block is falling inside the delimitation Once again locate the init function and paste the following code block at the end just before losing the f
2. For more information about either Blender or Active Python please refer to their respective website for more detail about the installation procedure for your targeted platform Please take note that SIO2 also support Maya and 3d Studio Max for more information about how to use the exporter for theses software visit hitou api sioZinteractive com Now that your game development environment is all set You are now good to go and ready to start creating games using SIO2 MyGame For this tutorial you are going to create a simple 3d casual game Even if the game may look pretty basic at first it touch base with a lot of different notions that you are going to use in your everyday game development Tap the screen to restart The goal of the game is to clear the table by dragging every block using the touch screen out of the red delimitation If there s no more black on the table or if a block fall inside the red area the game is over and the player have to touch the screen to restart the game Creating a New Project For all developers the first step before we start creating our game we need to create a new project For this go in the 1s directory and create a copy of the 00 template folder Then double click on it and either select the iOS or Win32 depending on which platform you are working on and open the associated project file for either XCade or VC For XCode Developers Enter the iOS directory and dou
3. SIO2 SDK v2 x GETTING STARTED MANUAL FOR XCode Eclipse and VC last revision 2011 06 23 1 Introduction Welcome to this getting started tutorial for SIO2 Engine v2 x In this document you will first get an overview of the SIO2 Engine SDK and lear what is required in order for you to get you started right away Then you will lear how to build a simple casual game from scratch that will allow you to touch base with all the basics such as physic lighting instancing how to handle materials and textures as well as game logic and game states 102 SDK Overview In order to get you started you first download the the latest version of the SIO2 Engine SDK available at the following address hitp sioZinteractive com download oho Once you ve downloaded the SIO2 SDK simply un compress the ZIP file in a directory that you have read and write access no other installation process is required The SDK file architecture should look like this proa r a ga fs Box E tive wahie eel amnor Bon 8102_SDK docs Contain an HTML file that will automatically redirect you to http pL siointeractive com where you can find the latest SIO2 API documentation as well as the S102 Exporter manual for Blender Maya and 3D Studio Max available at the top of the left side treeview e 5102_5DK inc This directory contain all the header files required by SIO2 as well as the other extema
4. and features of the engine so you can create your own state of the art 2d or 3d game Please take note that all source files and all 2d and 3d assets along with the original models and texture files are also available to you in order to rebuild from scratch each tutorials Final Requirements Please take note that in addition to the 5102 50K if you are a iOS developer you will also need to download and install the latest iOS SDK you can download it along with XCode at the following address hitp developer apple conv and for Windows developers all you need is Microsoft Visual C the Express free version of the software is available at http microsoft com express Windows For Android developers make sure that you have downloaded and install the Android SDK http developer android com sdidindex himl and NDK http developer android com sdlindk index him Eclipse hito vww eclipse ora downloads with the ADT plugin htip developer android com sdk gclipse adt htmi and to be able to compile directly within Eclipse applications that uses JNI through the NDK download and install the Sequoyah plugin htto www eclipse ora sequoyah documentation native debug php To be able to compile and debug native code In addition for Windows developer you will also need to install the necessary dynamic link libraries DLLs that are required by SIO2 to be able to simulate a GLES mobile development environment on your Microsoft Wind
5. sort the different physic entities sic iz Now move on to the draw_ rane function so you can insert inside the rendering loop the necessary code to step in the physic simulation every frame based on the delta time of your game in order to have a continuous physic simulation synchronized with the rendering Then locate the o22 scurceRenci r function call and add the following block of code on the next line right after the call joickendesFall siazGetinysic hy Now build and run the application Congratulations you have successfully link instances create a physic world and you have integrate the necessary code to run the physic simulation in real time If you have followed the steps above properly you should now obtain the following Lighting Let s now add some light to your scene but first go back to Blender and right click on the Lamp which should be hidden by the table to pick it easily simply switch the rendering mode from Textured to Wireframe then get back to Textured Move the Lamp location using the 3D Transform Tool and place it at the comer of the limit object facing the Camera and give it some offset on the Z axis which should be around the following coordinates Now cick Lamp data button Elio access he Lamp properties and modify te stance value to 600 and the energy t0 2 0 For more information about which Lamp properties are supported by the Ble
6. time and patience you will realize how fast flexible scalable and powerful it is With SIO2 sky is the limit there s no restrictions Hope you enjoy this getting started enjoy your SIO2 Trial
7. GAME_STATE_NEXT_LEVEL i U7 Th we had other Level this would be the Location 7 that we would increment the level and trigger 11 the loading of the next level In cur case we don t 77 have any so we are basically just going to reset 77 the gane like in the GAME_STATE_GANE_OVER condition reset_oamet i i Here s the code AE game state GAME_STATE PLAY And the 1 se condition else i Af game_state GAME_STATE_GAME_OVER The player fail to complete the level we now need 1 to rezet the table teset_aane j else 1f gane_atate i LEVEL x we had other level this would be the location 7 that we wouid increment the level and trigger 7 the loading of the next level In our case we don t have any so we are basically just going to reset 7 the game like in the GAME STATE GAME OVER condition reset_game Time to create a new function called co5e sa just before the toucheseqan declaration void reset_game void i tenp counter unsigned int 4 0s Reset the game state back ta play 7 Put back the sto2sprite to invisible Disablestate prite pflags S102 SPRITE_VISIBLE Reset ite alpha value Loop while we go dnaide our global s102resource tReaource gt n_object Bobject siozGetResource gt srozobject 1 object s You are now ready for another test run So compile and start the game and see h
8. Moved void ptr si toucheatoved n 7 1 touchesgnded void _ptr staztouche _s102touche Report on the Now build and run your App and when the application is loaded simply click move and release your left mouse button over the screen while monitoring the console prompt to receive live feedbacks from the code you ve just added After you gat the confirmation that your event handling code work properly it is now time to implement 3d physic picking code in order for the player to be able to drag and drop the blocks around To do this replace the touchesBegan touchesEnded and touchesMoved function block by simply selecting them and replace their content with the following cade to handle the picking using theses 3 events callback emp variable to hold the picking distance fe it emary r Simply del i renove_constraint JI ts our btPoint2pointconsteaint is different than NULL Af _beroiatzpointconstraine i 1 Remove the constraint from out stO2physic world sia2GetPhysie gt brsoftRigidnynamicawaeld gt removeConstraint bePoint2Paintconstraint Free the memory allocated delete _brPoint2vointconstraint 17 Reset the pointer to NULL void toucheaBagan void _pte sto2touche stogtauehe i tenp variable to hold the location that we pick in 3D as well as the normal vector at this same location vec hit point hit_nornal Create a 3D phy
9. ane and 500 0 for the far plane Renaming The Objects In order to have access within your game to some more friendly and representative names than the one used by default by the Wavefront OBJ importer Rename the objects lke in the table below so 102 will use theses names internally To rename an object simply toggle the object panel by cicking te Bil buton ten rename me unique data block 1D name Old Object Name New Object Name Mesh floor Mesh 003 table Mesh 004 tit Mesh 002 game_over Mesh 001 block Export Time to export the scene your scene for the first time in order to make sure that what you are seeing in Blender is exactly what you are going to get inside the iOS Simulator on your Mac or the iDevice Simulator on Windows in order to do that follow the steps below 1 Since its the first time you are exporting change the Blender Screen Layout to Scripting 2 Then from the Text Editor window click Text gt Open Text Block 3 Next load the the SIO2 Python Exporter Script for Blender v2 57b file sio2_exporter_blender_257b py located under the 5102 SDK tools scripts blender _v2 57b directory then click the Open Text Block button to load it inside the Text Editor Now run the script once to make it part of the Blender File gt Export Menu to run the script simply select from the Text Editor menu Text gt Run Script or simply push ALP P to run the active
10. ansformuorldapace mat 3 1 1 Jy sio2GetCanera gt _st0ztransform uorldapace mat 3 J 2 14 Variable use to calculate the current ray position from our 7 camera location te the current 3D point on screen btvector3 ray tor The direction of our movenent 3D ray final position current 3D point under the touche brvector3 diry JI Get the 3D location under our 2D touche coordinate slo2uaProject _s702touche gt gles x The GLES x position on screen _stoztouche gt glea y The GLES y position on screen Tor Since we are picking in 20 the z is the far plane sle2cetcaners pmat_modelvies The current camera modelview matrix S1o2GetCanera gt mat p eojection The current camera projection matriz slo2Getwindow gt mat_viewport The current Window viewport matrix keure_point x The x position if in 3D of our 2D coordinate kcurr_pointsy The position if in 3D of our 2D coordinate koure_point The 2 position if in 3D of our 2D coordinate caloulate the dicection vector between our current point in 49 and the camera location sio vec3nif seure point ves jasiozcetcanera gt _ kcurr point j J Create the final ray_to position in aD ray_to set cam_loc x curr point 17 zay_to setY cam_loe y curr_point y ray to setz cam_loc 2 curr point calculate the direction vector of our movement dir ray_to cam loc
11. are information about this copyright Lici B S Daniana tiae include tenplat E peta E Default pipra Mainmndowaio amp aneri Ep Uren Bes i macintosh HD B os E time machine Erom B soze sosa eh temalarsce ve For VC Developers On Windows no extra operation needs to be done you are going to later on load the sio2 file in code taking in consideration the relative location of the SIO2 scene file directly in code For Eclipse Developers Copy the Scene sio2 file and paste it within Eclipse inside the assets directory from your project architecture Please take note that this operation have to be done everytime you output a new version of the scene Compile itis now time to have a first test run with the Scene in order to do that you must frst load the S102 from disk then and render it using the SIO2 Engine API Loading and Rendering Now save your Blender file inside the S102_s0K tutorials Chaptert directory using the File gt Save dialog in order to have a backup of this files before modifying other properties Itis now time to start coding Let s open template cpp located on your project solution architecture and locate the nit function which currently contain our basic SIO2 initialization First we need to define where your 02 is located for that we are going to add the following code above the include call Hider s102 wrn32 1 on Windows g
12. bjecti stozobject brRigidrody btcollistonobjecti gt getuserrointer check if the name of one of the 2 objects is called limit I yes 7 it means that one of our block haye touch the limit To2object0 gt same object limit Toobjecti gt nane object limit 1 For now ju print game continue to pre sa the contact point Lets build and run the game again and drop a block by dragging it to make sure it fall down inside the limit Then monitor the console for the game over print As you can see as soon as a block touch the limit object the game over is printed over and over on the command line prompt which is perfectly normal since the collision callback occur many times per second Now lets handle the opposite and handle the logic ifthe player actually clear the table without dropping any of the block inside the red limit For this you are going to implement another type of collision callback function that will act as a sensor that will be activated as long as some blocks are actually colliding with the table To do this add the following line after the ctAddedal back funetion callback assignment Enable proximity calib yete gt _btcal t s bounding box overlap back MyGameNearcallback Please take note that this time we do not need to enable material collision callback this function is global to your 102phy2ic world and will be triggered every
13. ble click the Untied xcodepro to launch the XCode Now its is time to rename your project so that your App bundle name and the executable name can be set to MyGame Using XCode 4 1 Select project navigator then the current project named Untitled 2 Click on the 00 inside the Targets list 3 From the tabs on the top right select Build Settings 4 Make sure that All and Combined is selected 5 Browse the list to find the Product Name entry and change it from 00 to MyGame Se T en ae For VC Developers First double click on MyGame sin to load the project into Visual C Once your project is loaded open the Solution Explorer and select the U sd project target then right click on select Rename from the pop up menu list and update the field to use the name MyGame just like in the figure below Uropa m et a Bulb cutaisors Flees 4 Seem Lali ore wtp Ubasreobet For Eclipse Developers First you have to import the project into the Eclipse workspace In order to do that frst start by licking the button to launch the wizard to create a new Android project Enter MyGame as the project name then select the radio button Create project for existing source The click the browse button and select the 102 SDX tutorials MyGane Android directory Then click the finish button Please take note that if you
14. ed na tne Bound Type You shouid naw hava he sama atinga ah ha falnin verte Now that you have assigned physic data its time to instance the object Object instancing in SIO2 drastically improve the rendering speed what instancing does it share all the mesh data from the master to the children objects and avoid unnecessary machine state switch by rendering the master object first then flush all the childrens without changing any states Please take note that instancing is name based and the exporter will search for the tag inside the object name For more information about instancing please consult the Blender SIO2 Exporter manual For instancing your block object make sure it is selected and that we are in Object Mode then simply hit ALT D in Blender to create a new soft copy of the object in addition please take note that Blender automatically create a new valid SIO2 instance for each duplicated block by adding the 2 tag to the abject name Now use the 3D Transform Manipulator to move the block away from the first one on the Y axis the green arrow filing a first row of blocks on our table object like this When you are moving the block make sure that they don t overlap each other and leave a small distance between each of them If the objects are too close fram each other the physic simulation will not work properly I you want to get fancy an invert a few blocks just to break the linear pattern simply select a bloc
15. eration as you did for the floor but this time for the table and the limit object Once itis done select all the objects in the scene the select File gt Export gt SIO2 Scene sio2 and set that the scene output directory is the same as where you export your scene before basically located inside the 8102_SDK tutorials MyGane folder as you did previously Now before clicking the Export button make sure hatte AE toc so you wrt have to re expr the scene from scratch but simply update it then export Create and Render a Physic World Now get back inside the init function callback inside tompiate cpp then locate the following a z x uzce 1 and add the following code right before calling the function to do that BEFORE we p ET As you might have guess since now you have some objec instances you have to make sure that they are all bind to their respective master before pre calculating their matrices Now insert the following code after the sio2ResourceBindAllMatix function call 2 new physic wo jobally available t physic wor D ai Physic 12 the first sto2world in the stack and make it accessible globally ree gt Si02wor1a 01 py d and pass the current sii ally point to our newly created physic w 7 the gravity value contain in the S102world to aur S102phyaie world U stozcerrh tup sio2Gerha been added
16. fault blend mode of the material to use the ALPHA value of the Jal gt blend 5102_MATERIAL_COLOR _ frame function the block of code between bracket The next step is to locate inside the dra entitled with the following code comment Physic simulation and add the following condition right before the starting bracket of the block tate GAME STATE PLAY case that contain the following code in addition we are also going to add an wi Progressively increase the alpha of the diff S102material Linked to our fullscreen StO2sprite direu window Render the St02sprite on spriteRender ein J meset the s102sprite maci SpriteReset 7 Before going out of the dzaw_ zame function replace the following line prinest with Set the current game state to next Level to be visible Toggle the fullscreen stozsprit Now inside the touchesBegan modify the structure of the function and add an entry condition as in the screenshot below JI Are we running the gana N game state GAME STATE_PLAY tz 17 Wait for the player input to reset the gane or Load the next level if any 17 at this state we nust be either in game over or next level state else fC gane_state GAME STATE GAME OVER J The player fail te complete the Level we now need 77 to reset the table reset_gama p else if gome_state
17. g list box sac Boundrg Bo You should now see the following inside the Blender 3d viewport Fixing The Camera Now its time to adjust the resolution and to place the camera into space in a way that it can now visualize all the scene 4 On tte ight panet select the Render icon ane change he Reson tote 3040 iene faure bln 2 Next select the camera by right clicking on it and push 0 on your keyboard to make it active in order to be able to look at the scene from the camera perspective inside the Blender 3d viewport like in the screenshot below Please take note that the orange line around the visible viewport camera since you have change the resolution above they now perfectly fit the way it will be displayed on your iPhone 3 As you can the default camera position and rotation doesn t match with the bound of the scene To move it to an appropriate location hit Shift F on your keyboard to enter first person view mode Then using WASD on your keyboard move the camera into a location that the whole scene will be displayed But not the game over plane A suitable location and orientation should be obtain by moving the camera around the following values 4 You might have probably notice that when moving the camera the far clipping plane was actually cutting the ground plane To fix this issue simply select the Hall camera data button and modify the Clipping values to be 1 0 for the near pl
18. have been added in s102 pr ite integrate the following block of code right after it prite NULL and J pefinition of our game states typedef enum i J The gane la running The game is over and we are waiting for the player input GaNE_STATE_GAME_OVER The player clear the level and we are waiting to go to the next level if any GaME_STATE_NEXT_LEVEL The current global gane state char game state GAME STATE PLAY Now move on to the MyGameCo11isionCa11back function and replace the line prints sane over n with the following block of code Set the current game state to game over toggle our fullscreen stogapeite to be visible Sie2Enablestate 4 si0Jspritee gt rlags SIO2_5 Next lets get bi id init function and locate the following line aio2enablestate amp st02sprite gt flags S102 SPRITE_ENABLED Assign a material to the stodeprite i Get the game over object ect S1020bject siozResourceGatobject sio2Getkesource obj game _over Get the of the first verteagroup of the game over object and assign it to the sIo2sprite material The material is 1 also linked to the game over texture and our sto2eprite 1 4g fullscreen So we are going to use it to display the 1 qane over texture depending on our current gane state _5102sprite gt _5102material _STO 0bject gt sto2vertexgraup 0 gt sT02material Change the de
19. ic s099 sound fl Py dalani very curd buti aed wl be corsdoed aa an ambient sound seared and eat play and to oop war and over For mote deta about he oar pis a you cae Wh sours plasa Gone fo experiar ra Now export your scene again to overwrite the current sio2 the same way as you did in the Physic and Instancing section where you toggle to update the sio2 and export the vertex normals Now back to template cpp in order to start playing the background music you have to add a few lines of code First jump to the init function and add the following instruction after the function o2tnit Initialize openat LOs Next you have to tell SIO2 to link the sound buffer to the material this is done using the following line k all the sound butte 2 dBuffers aio function call indAl ima and place it right after the sio2Resour The next step is to create the sound source the approach SIO2 is using allow you to have one sound buffer in memory and then share it among multiple sound sources However for this tutorial you only have one so we won t be using this technique but in any case you stil have to bind all the sound buffers and create a new sound source To do this plug the following code right after the so2ResourceGenta function call nique sound source for each sound buffer attached to the sto2obje eninda ist EN And now the final touch to make the sound be streamed from memor
20. ill simply exit don t panic its not a crash check the system console to find more information about what might have cause SIO2 to exit The Scene For this getting started tutorial you will use Blender to build your SIO2 Scene the first step is going to be to re create the 3d Scene for your game as demonstrated in the introduction All assets necessary to re create the scene from scratch for this chapter are available inside the SDK tutorials _MyGame Chapterl e ks es eae mor A a E pe ee ee Now its time to import the scene into Blender 1 Open Blender 2 Select the default cube by right clicking on it Then push X to delete it and confirm the operation 3 From the Blender top menu select File gt Import gt Wavefront OBJ then go select the untitled sbj file located inside the s102_s directory als _MyGame Chapt 4 Then select all the objects by pressing A once or twice on your keyboard while your mouse is over the 3d viewport to select all the objects 5 Then from the Object menu select Transform gt Origin to Geometry this action will reset the pivot point of all the selected meshes to the center of their bounding box Orignta 30 Crcar rign by shit Cr maz Conecto e 6 Now switch to texture view to be able to get a preview of the current scene the way is going to look like in SIO2 by selection Textured from the Viewport Shadin
21. ing First you have to let the player be able to drag each block on screen for this you are going to need to create a full screen 102sprite to handle the global touchesBegan touchesMoved and touchesEnd event callbacks But first what exactly is an 5102sprite Basically it is a 2D quad on screen that represent a region that can respond to event in addition you can also link a material to it and render texture as well This region can also respond to transformation such as location rotation and scale if you desire Now locate the ini function declaration and insert the following variable declaration right above it Next spot the ic2Getwindaw gt 5102x dee located inside the init function and integrate the code below on the next line to create the 702sprite in order to link and respond to touche events ansformipdatesat amp Pointer wi And finally the Set the flag 102 SPRITE ENABLED to our prite to enable event processing ablestate amp SIO sprite gt flags SI TE ENABLED j Then to make sure that your events handling code is working properly let s temporary replace the event function callbacks with the code above and lets have a test run while monitoring the system console prompt to make sure that all events are handled properly id touchessegan void ptr stoztouche Report on th toucheasegan s ole when the touche began id touches
22. ipping plane distance sio2Getcanera acend The end clipping plane distance float Jaio2getmindow gt orientatlon The viewport orientation in degree 1 select the modelview matrix gidatriaveda GL_MODELVIEW I neset it glueaddentity 7 multiply the current modelview matrix with our camera matrix sio2CameraRender sio2Getcamara 1 7 Get the GLES modelview matrix sio2CaneraGerModelviewatrix sie2GetCanera 17 Get the GLES projection natrix siodCaneraGetProjectionMatrix sio2GetCamera suild the camera frustum based on the matrix that we just gather sioCaneraUpdaterrustum sio2cetcamera ose the camera frustum to determine which objects are visible 7 and which one are not siozResourcecull sio2Gethesoi aiadcetcaners s102_CULL_oBJECTS J P Rander all visible aolid objects in our acene and since we 17 are going to use physic we also want to keep track of the current position of the off screen objects siodResourceRender sio2GetResource And finally insert the code to be executed when the application exit by adding the code below to the close _app function void close app void 1 1 Free out global sto2resource aioRascueceUnloadAll sia2GetResa n U Free the sto2window aiozWindowFree sic2cetwindow 1 Shutdown s102 aio2shutdown 2 prince shutdewn e pa Now build and run the program you shou
23. k by right clicking on it then press R then Z and type 180 to rotate the object on the Z axis of 180 degree and create the following pattern Now lets start stacking a few columns to do that hold the shift button on your keyboard and right click on every block one by one to make sure they are all selected Then push ALT D to duplicate the whole row Then once again using the 3D Transform Manipulator offset the newly created instances up on the Z axis and make sure they are not overlapping the objects of the first row On the keyboard type R then Z then 180 to rotate the whole row in order to invert the texture pattem Repeat the steps above to stack about 4 or 5 row high you should now have something similar as the following Since now all your physic blocks are set we need to make sure that they won t just fall down in space since there s nothing that can support them at the moment and if you start the physic simulation the block will just pass right through the table and the floor You naw have to assign the necessary physic property to the floor and the table To do this first select the floor by right clicking on i hen get back to Physics panel by clicking the IBB punon its is not already selected Then from the Physics atributes select tat Ine Physic typo s set to Static toggle the Actor check bos enable to tne Callsion Bounds check box and make sure at Box is selected Ike in the igure below Now repeat the same op
24. l libraries embedded inside the SIO2 Engine core 8102_SDK Lib Contains pre compiled static libraries for OS MacOS Windows and Android used by SIO2 internally along with their respective license s as well as their project file in order for you to be able to re compile them from scratch for your targeted platform if needed In addition for Windows developers this directory contains all the necessary dependencies to mimic an iPhone iPod Touch and iPad game development environment right on your Windows box theses dependencies are required in order to be able to run SIO2 for your specific version of Windows In addition by default all the dependencies are by default available for 32bits system if you are using a 64bits system please make sure that you download the appropriate version for your system 9102_SDK srct In this folder you can find all the source files used by the external SIO2 dependencies associated with the header files contained in the 5102_sDK inc directory e 5102_5DK too1s All the necessary tools that you need to get you started are located inside this directory You can also find other links to optional external tools and other goodies located in sub directories that will help you to develop your games using SIO2 e 8102_SDK tutorials This is the best place to start leaming inside this directory you have access to multiple tutorials that will guide you step by steps through the different functionalities
25. large s JI Increase the number of table hit Let Bullet continue to deal with the near callback call for internal ocessing _btcollsionnispat er defaultNearcallback _btBrosdphasePair apatchertnfo And finaly implement the logic code that will determine if the player clear the level Lets locate e Ful function and replace the call block with the following code Now build and run the game and clear the table by moving every block away from the table and outside the delimitation When you re done you should see level clear printed on the system console As you can see you now have the logic of the game in place now nat much code to plug left before you can make the process loop aver and over and in addition if you had more level make the player go the next level restart it and so on like in a real game scenario bt lets first focus on getting one level work for now This mark then end of this chapter as usual you can find the final result of the source code for this chapter under the S102_SDK tutorials _MyGame Chapters Chapter 4 Game States and Fine Tuning Atthis stage you are ready to integrate your game states in order to finalize the game and to be able to run it as long as the player doesn t quit In addition in this chapter you will also learn how to add a background music stream it and play it on loop Game State Locate the following line that
26. ld now see the following on either your Windows iDevice Simulator or on your Mac iPhone Simulator This conclude Chaptert you can find the all the files that were used or modified in this chapter inside the s MyGane Chapter directory for your reference Compare them with yours to make sure that everything is identical before you moving on to the next chapter 2 Physic Lighting and Instancing Inside the following sections you will learn how to setup the necessary properties to the world as well as your objects to support physic In addition you will add light to the scene and learn how to control the Lamp properties to get realistic results And finally you will discover how to instance objects and save precious rendering time Physic and Instancing Before adding physic properties to you objects first get back to the Default screen layout by selecting it from the Screen Layout list box located on the top bar Then switch the Blender Game from the Rendering Settings list box located on the top bar It is necessary to switch it to game in order to gain access to the physic settings used by SIO2 Blender lender Now select the object named block by right clicking on it the cick the Physics bution Bo acces the physic properties of he object Insido the Physics area select from the Physic Typo lst box Rigid Body Then lek e Collisions Bound check box acted a tne bottom of fhe panel and make zara thst Bt i lac
27. nder SIO2 Exporter please consult the user manual where you can get more information about each and every Lamp property You are now almost ready to export your Scene again in order to test the ligthing settings but before that Im sure you would like to get a preview of how our Scene would look like inside the Blender 3D viewport This step is actually optional and not necessary but can really you to visualize how your Scene s will look like when Lamp s are present For this make sure that the Copy Attributes Menu add on is enabled then select i e the floor object then enter Edit Made by pushing the TAB button select select a face Then click the object data buton Blt get acces to tne properties then move on to the Texture Face panet and ck the Light check box Then invert tne face selgcion by pressing CTRL then cick he Copy Mode bution Repeat the operation for every objects that shouid receive ight basically all of them except he game ovar plane Yau should now obtain the following result insida the Blender 34 viewport In addition before moving forward please take note that the preview in Blender will aways be slightly darker than what you will get in SIO2 this is because Blender is using the lighting model controlled by the GL_SEPARATE_SPECULAR_COLOR extension which is unfortunately not available in GLES Keep that in mind when you are testing your Scene inside the Blender 3D Viewport You are now ready to exp
28. o one directory down to find the sioz define TUTORIAL SCENE Scane sia2 telse on Mac our Scene sio2 is enbedded inside the app and 1 is located at the same level of our executable def ne TUTORIAL SCENE Scene sio2 tendit Then insert the following code right after the SIO2 OpenGLES initialization function c22nstc J Initialize a new S102resource pointer call it default and make it available J globally using the sia2setRescurce function aio2setResource slo Resourcernit default 4 1 1 neclare a counter unsigned int 1 0 Create a dictionary for the stO2resqurce to be able to lead 11 and parse our 20 and 3D asseta pio2Resourcecreatenletionary slo2catResols Open the s o2 file in read only mode pio2keourcepen slo2GetResouxes TUTORIAL SCENE zoop while we have some entry inside our sted wbile 4 stozResourceGatwunEntry sio2cetRasource 1 extract parse and dispatch the stream to the appropriate loader aio2Resourcerstract sio2GetResource MULL 1 negt entry wee W Close the aio resource aiozResourceClose sio2cetResource 1 z nk all the materials to thelr respective objects aio2Resourcesindallateriala sio2Gethesource 1 tink all the images to their respective materials aie2RagourcesindAllinages sio2GetResource J pre calculate the localapace and worldapace matrix for every objects aie2Rag
29. ociated with our S102 selection object and our start position LbrPoint2pointConateaint new btoint2zointcenstraint selection gt 51020bjectphysie gt _btmigidEody select ioue gt _stozobjectphysic gt btRigidsody gt gatCenterofMassTransform inverse at rt pos 2 J Set that we want to calmp the impulse this is necessary JI 4 we want ta achieve smooth drag movements _btPoint2PointConstraint gt m _setting m impulseclanp 1 0f7 n d the constraint to our physte world aio2GetPhysic gt brsoftnigidnynamicaworld paddconstraint _btPoint2vointconatraint 4 J Calculate the vector length magnitude between our camera 3D position J and our start aD coordinate pick det start pos cam loe length specify that we don t want the collision object to be deactivated aa we want to keep it alive as long we are dragging it on screen select Lose gt StOJobjectphyste gt btRigidsody gt setactivationState DISABLE DEACTIVATION n i void touchesMoved void _ptr stoztoucne stotouche i Da we have a constraint alread created Tf yes we must 17 be dragging the block LE _brrosnt2Pointconsteaint JI Temp variable use to calculate the current 3D location of the touche on veo eurr point Get the final camera location in worldspace extracting the xYz location from the world matrix btvector3 eam loe sic2GetCanera gt st02transform warldspace mat 3 1 0 Ty Sio2Getcanera gt _S102tr
30. ort your scene again apply the same procedure as before in order to overwrite the previous Scene sio2 so make sure that the Update sio2 option is toggled In addition this time since you will need to export the normals in order for the ligthing to be able to work properly so make sure you ato cle me AEM nee 10 do so Lighting Code Now back to our C C IDE to add more code to render the Scene with lighting enabled nder call inside ime unction and replace it with the First locate the following der all our solid objects and all t z eRender sio2 Then build and run the application you should now be able to see your Scene fully dynamically lighted and shaded This conclude this chapter you have learned plenty enough to start doing some experimentation before moving on the next and final chapter of this getting started tutorial In order to by sure that you have all the good properties set and the proper source code integrated do nat hesitate to compare your files with the ones located inside the s1 My apter directory 2_SDK tutorial ame Chapter 3 Events and Game Logic At this stage you are basically done with the Blender operations your Scene is not fully set and it is now time to integrate the bits and pieces of code to finish our simple game In this chapter you will earn how to handle events do 3d picking and handle the game logic Handling Events and 3D Pick
31. ourcesindAliMatrix sioZGetResource J Generate ali the openGL VRO and Texture 1D aie2Ragourcetentd siozGetResource 17 J meset the 102 states aiozreaet meset the GLES states maintained by 5102 sio2stateneset sic2cerstate J Get the first camera in our StO2sesource and make it accessible 1 globally using the sio2setcamera function aio2satcaners s102canera elo2GerResource gt _sto2caneral 0 4 Now all you have to do is to include the following rendering code inside the daw frame function void draw_frame void i Clear the depth buffer and the color buffer giclear GL DEPTH SUFFER BIT GL_COLOR_BUSFER BIT I select the projection matrix glatrintiode GL PROJECTION 3 Hinder s102 wmm32 J 1 we are on Mac reset the projection matrix alroadrdentity teise Tor windows user ita impossible to flip the inevice simulator 1 since the os doesn t allow us to do that so the iDevice simulator maintain its own projection matrix based on the orientation set JI at initialization time so we don t need ta reset the projection JI matrix tenait 1 set the perspective of our 3D viewport using the information of 7 our current camera previous set inside cur init function Sio Perspective sic2GetCanera gt fov The field of view in degree siozWindousetAspectRatio sio Getw indow Get the aspect ratio of the viewport sie2Getcamera acatart The start cl
32. ow you have successfully pull it off and now have a simply yet fun casual game running on your device Try to get game over by dropping a block inside the limit and try to clear the table to got the next level even if you only have one but Your game should now look like in the figure below Tap the screen to restart Background Music Time to add a bit of music to the game for this re open your Blender file and select the game_over object by right clicking on it Then click the Texture button LE in order to access the textures properties In order for SIO2 to be able to handle 3d positional or ambient static sound source you have link them like fit was a texture since Blender is not offering any other way to link sounds to a specific material you have to use the texture slot starting from the 3rd one up until the 10th max 8 sound buffer per material is supported by default in 102 So first select the 3rd texture channel then click Add New select the Texture Type to be Image or Movie and click the Open button You should then see the Blender file dialog but before you can select the OGG file that you are going to use for sound you have to toggle OFF the file filtering in Blender as a 99 is not a format that Blender can recogrize to do that simply cick the IE puton at ne top ofthe le alg Then browse o he 3102 S0 tutoriais Mycame Chapter dre and select Ihe mus
33. ows Theses DLLs can be found under the S102_SDK 1ib Win32 directory and require you to install them before you can start developing The cd von Faves Tse Om OD F Dao r X ibe 3 beams a Saron nE E proz Que ovens The tan tr Tee On O 2 D s Em e xO es Sauer Jae paeas eT oe beth irana Bewa Ssoronana E pars 0 Sines Sracce oan TTS aa aa ai To install them simply select them all then drag and drop them to your C Windows System32 or C Windows System folder depending on the Windows version that you are using The next step is to install OpenAL to install it simply double click on oa1 inst exe also located under the 102_SD 1b Win32 folder then simply follow the installation instructions on screen openi AL OUT cha TAON RIED WARRANTIES OF CONDCNS OF ly cmon For all developers you also need to download and install the latest version Blender hito blender org which is by default the 3d software used by the SIO2 SDK since itis free and available on multiple platforms In addition in order to be able to export your Blender scene to the SIO2 file format you are require to have Python installed in order to run the Blender Python SIO2 Exporter If you do not already have Python setup on your machine you can get a free copy by visiting the ActiveState website and download ActivePython htipJAyww activestate com activepython
34. script 5 Now time to export to do this simply click A once or twice to select all the objects in your scene When they are all selected simply use the Blender gt File gt Export gt SIO2 Scene menu to trigger the exporter interface As you can see from the screenshot above the exporter options are available on the left side however do not toggle any of them at the moment what you are trying to do now is to simply export the current scene data to the ST02_SDK tutorials MyCane directory to be able to create the 5102 for your scene and then be able to link it with your project 6 Optionally you can now if you open the S102_SDK tutorials MyGame directory with your file explorer you will notice that a directory name Scene have been created along with a file named scene sio2 This S102 is basically a ZIP file that contain all the data from the Scene directory pean Base a Erom H For XCode Developers Itis now time to link the Scene 02 fle to your project in order to be able to load it at initialization time To do this if you are using XCode simply drag the file from its location in Finder to the Resources folder inside the XCode project tree as demonstrated in the following screenshot fate rca rene yen BB remp ate ce Libraries ye lease take note that s102 Engine is fon find these respective icense your apa icatien conply to ati ar vane m
35. sic picking ray if our touche hit a collision object 1 the sto2ebject pointer of this object will be returned to ua if nothing 7 is picked the function will simply return NULL fection sio2Physicrick siozGetPhysic Our global stO2physie world information sie2getcanera Our global stozcamara with madelview and projection matrix updated sie2Getwindow Our global S102Window which contains the viewport matriz amp _5102touche gt gles Get the openGiES color buffer position of the touche on screen thit_point If we get a hit the 30 location will be assigned to this variable thit_normal If we get a hit the normal vector at the 3D location will be assigned Da we have a valid S1020bject painter If yes it means that I we bit something now simply create a physic constraint to 17 atart dragging aur object on screen Aft selection Get the current camara location base on its worldspace matrix btvector cam loe sic2GetCanera gt s102transform warldapace mat 3 1 0 Ty sio2GetCanera gt _st0ztransform worldapace mat 3 J 1 ie stodGetCanara gt stottransform worldapace nat 3 J 2 t Renove any previously initialized constraint emave_conateaine Set the start position for our drag move start_pos setx hit_point x Start pos setY hit pointy 17 Start pos set hit points 17 J create a new constraint on the fly based on the btRigidsody information 1 aas
36. side this section you can find your SIO2 Engine Key located under the Developer License Status box as demonstrated below Then simply select the whole text box content and copy it to your clipboard DeVELopeR License STATUS Sachin Spoight An eer taste S102 Ene sly copy the s102 Erge Seah in Googie Frame ihe sos We noe Yr Soe A In exonay Speling and Grammar e soz engrana Substitutions id Transformations ig Speech Paragraph Direction inspect Element a Then paste it as the last parameter ofthe s102 17 template cpp fie function which is located inside the In addition make sure that as long as your SIO2 App is in development you are connected on the Internet in order for SIO2 to be able to communicate with the SIO2 Authentication Server in order to validate your SIO2 Engine Key every time you successfull start your App However be re assured that the final version of your game will not effectuate no further check and will automatically authenticate your SIO2 Engine Key locally and print on the device system console your SIO2 Developer information Now compile and run the project If everything went fine you should have a the simulator window up and running displaying a black background which is perfectly Ok since this means that SIO2 is running at full speed in the window from there we will now start adding code to start drawing on the screen If something goes wrong and your App w
37. time the axis aligned bounding box of an object collide with anohter Now Create the iyGametiearCal Lback function and place the following block of code right after the MyGameCollisionCal back function so your 2 type of collision callback functions are near each other for a question of convenience Declare a counter to count how many current hit we got with our table We are later on going te use that fully complete the to determine if the player have auc void MyGameNearCaliback btBroadphasePair btBroadphasePair pe btCollisionDispatehar amp btCollisionbispatcher brDiapatcherinfo 4 broispatcher nfo similar as we did in the myGaneCollisioncallback ex Rigidsody and cast the user pointer back te an StOZebject pointer brRigidBadyo brrigidsody _braroadphasePair n_prroxy0 pn_clientabject sTprnigidpody btrigidsody btaroadphasePair n_prroxyl pn_clicntobject Zobject _sTO20bjeet SIo2objecti 102object _btRigidsodyt gt getuser bject _beRigidnody0 getuserPointer eros Check if one of the two obj table For a question of et name that collides against eaci is called obj jenience we are using the name of the object however in a real game mmended to ct pointer which will drastically improve the ne with many different Ject table p object table gic speed especially 1f we have a
38. unction bracket Since we have our collision object created and added to cur Sto2physie I world simply enable custom collision callback on it aio 0bjectEnablecollistonob ck _sr0Zabject Assign the global collision callback function Every inside of our physic world will be reported in thla fur ontact that happen J collision objects that have been tagged with 2io20bjectEnabiecollisionobjeetCal iback llback MyGamaCollisioncallbacks You have now enable in the code above a global collision callback function itis now time to actually create that function in code Simply copy and paste the code below and insert it right before the init function declaration boal MyGameColliioncallback btwanifoldroint amp bemanifeldpoint nst b ject _btcollisiondbject0 int pO int 10 isiondbject _btcollistonobjecti int pl int ay 1 As you might have notice from the function declaration thia function will parameter 2 collision object For each collision object we will first get back the sto2object pointer associated to them by simply sting the collision object getuserPointer back to an St02object pointer which have automatically been s I sie2Resour by the BindAllPhysie0bjects call when we add our StO2abject to our sto2phyaie world Babject StO2ebjectO s102cbject bERigidsody _btcollisionobject0 gt getuserrointert y _Stoza
39. want to to import other SIO2 Tutorials within your Eclipse Android development environment you ll have to repeat this procedure for each and every one of them Or you can simply use the command like with naic bui 1d to compile and launch your application on your device In addition as a reminder SIO2 and its tutorials CANNOT work properly on the Android simulator due to the lack of proper support for OpenGL ES v1 For XCode Eclipse and VC Developers Expand the tutorial directory located inside the project tree view and double click on tenplete cpp this the source fle that you are going to add the source code necessary to create your first game with S102 As you might have already notice the basic initialization is already created so have a first shot at it and compile the project but before you do so make sure that you enter your SIO2 Engine Key associated to our SIO2 Developer Account by passing it in parameter to the i02Tnit function To find your SIO2 Engine key simply open your web browser and go to hitp sio2interactive com then use the login form the link is located at the top right of page header then log in using your SIO2 Developer Account email and password Once logged in you will automatically be redirected to your Developer Control Panel fram there clock on the Developer section ARE Home FEATURES DOWMLOAD stoRe DEVELOPER CONTROL PANEL Speyer vat Smead your EOE deco T on SS In
40. y and playback using OpenAL you need to tell to the 3 dee function to actually stream the sound butfer and to deal with the quad buffering operations in real time to do this simply replace the so2ResourceRende function call with the following snender slo2cetnesource 1 In order to make sure that you clean the OpenAL state when the game close add the following line before the 02Shutdown function inside the close_app function callback JownAL Now re compile the game for the last time and run and enjoy Conclusion In this getting started tutorial you have lear a lt Now the next step in order to get the most out of S102 is to start digging inside the different tutorials available in the S102_SOK tutorials Read carefully the source code documentation for each of them and pay close attention to every properties set inside their respective b1en file In addition do not hesitate to consult http api sioZinteractive com for more information about the SIO2 APIs as well Exporter Manual for your favorite 3d software in order to learn what is supported by the exporter and what is not If you have a questions regarding the code or the assets or if you simply want more information about SIO2 v2 x or the SDK feel free to post your quesion s online at htto forum sio2interactive com in the appropriate forum thread S102 is quite a large 2d 3d engine and the learning curve might look steep at first but with a bit of
Download Pdf Manuals
Related Search
Related Contents
Manhattan 394130 Samsung AC026FBJDEH Manuel de l'utilisateur LaCie electron19blueIV User`s Manual an interactive system to analyze dietry habits Canon WITE32 User's Manual Todo lo que tienes que saber para empezar. FLA COE, FLB COE, FLC112 Convencional, FLD Convencional Lirio by Philips Spot light 57113/31/LI use Inst Color RIngs Copyright © All rights reserved.
Failed to retrieve file