锘??xml version="1.0" encoding="utf-8" standalone="yes"?> 棣栧厛錛宨rrlicht鐨勫晢涓氭ф槸寰堟祬鐨勶紝濡傛灉瑕佹兂搴旂敤浜庡晢涓氬寲錛屼笉涓嬩竴緲誨姛澶槸涓嶈鐨勩?姣旇搗鐜板湪婊″ぉ椋炶垶鐨刄INTY3D錛屽氨鏇翠笉鐢ㄨ浜嗐傚氨綆楀拰OGRE姣旓紝涔熷洜涓篒RRLICHT娌℃湁鎻愪緵澶鑺卞摠鐨勭壒鎬э紝鑰屽鑷磋繖涔堝騫存潵ARPU鍊間竴鐩存病鏈塐GRE楂橈紝鐜╁嫻佸け鐜囨槸宸ㄥぇ鐨勩?/p> Niko鑷繁鏁寸殑SupperCuber.灝辨洿涓嶇敤璇翠簡錛屾垜鑷繁涓嬭澆鏉ュ紕浜嗕竴涓嬶紝涔熸病瑙佸緱鏈夊濂戒嬌錛屽弽姝f病鏈夊畼鏂逛粙緇嶅緱閭d箞鐗汢銆?/p> 鍦ㄩ噸鏂板畾浣嶈嚜宸辮娣卞叆鎸栨帢鐨勫紩鎿庝箣鍓嶏紝涔熸浘鍐嶄竴嬈¤OGRE鍚稿紩榪囥?鍘熷洜鏈夊緢澶氱錛?/p> 涓鏄ぉ榫欎唬鐮佺殑娉勬紡錛岄噷闈㈡湁寰堝OGRE妯″瀷錛屽彲浠ョ洿鎺ュ姞杞斤紝鏋勫緩鍦烘櫙銆傚緢蹇熷湴鑾峰緱鍍忔ā鍍忔牱鐨勬垚灝辨劅銆?/p> 浜屾槸錛孫GRE鏈韓鐨凞EMO灝辨彁渚涗簡澶ч噺鐨凷HADER錛屼笉鐢ㄨ嚜宸卞啀杈涜緵鑻﹁嫤鍦板幓涓滄嫾瑗挎壘浜嗐?/p> 涓夋槸錛屾湰鏉ヤ笌涓涓湅鍙嬬浉綰︾敤OGRE鏁碦TS鐨勶紝 鍥犱負鐩墠鍏徃鐨勯」鐩槸RTS錛屾墍浠ヤ竴鏃墮棿錛屽RTS鍏磋叮澶у錛?鐪嬩簡0 A.D. GLEST絳変唬鐮併?涔熸槑鐧戒簡RTS涓紝宸ュ叿涓嶢I錛岃繙榪滃ぇ榪囦簬鐢婚潰鏄劇ず銆?鎵浠ワ紝浣跨敤OGRE錛屾湁鐜版垚鐨凮greCrowd絳夊彲浠ヤ嬌鐢ㄣ?涓嶇敤鍐嶄負鍔ㄦ佸璺壘楹葷儲銆?/p> 鍥涙槸錛孫GRE鐨勬嫑鑱樺拰鎴愮啛鐨勬渚嬭繙榪滃ぇ浜巌rrlicht. 鍏夋槸鎴戠煡閬撶殑 澶╅緳鍏儴錛屾垚鍚夋濇睏錛岀嫭瀛ゆ眰璐ワ紝鏋佸厜涓栫晫錛岀伀鐐箣鍏夌瓑錛屽氨瓚沖璇存槑瀹冪殑濞佸姏銆?/p> 浜旀槸錛孫GRE瀹樻柟鏀寔WIN8,ADDROID,IOS銆傘?/p> 鍘熷洜澶浜嗭紝榪欐槸涓綃囪irrlicht鐨勬枃绔狅紝鑰佹槸澶窸GRE鏄笉閬撳痙鐨勩?/p> 涓嬮潰錛屾垜鏉ヨ璇存垜鐨勫師鍥狅紝涔熶緵鍜屾垜涓鏍風籂緇撶殑鏈嬪弸浣滀竴涓弬鑰冦?/p> 涓銆佹垜鏃墮棿鏈夐檺錛岃櫧鐒朵箣鍓嶇湅榪嘜GRE鐨勪唬鐮侊紝浣嗘槸瀵筄GRE榪樻槸涓嶆暍璇存湁鎺屾彙錛?濡傛灉瑕佺敤OGRE錛屽叾瀹炶繕鏄緱閲嶅ご鍐嶆潵銆?/p> 浜屻両RRLICHT鍥犱負涓滆タ涓嶅錛屾墍浠ヤ互鍓嶅湪澶у鐨勬椂鍊欙紝灝卞鍏跺緢鐔熸倝浜嗭紝鍥炶繃澶存潵涓婃墜錛屼篃鏇村鏄撱?/p> 涓夈佹湁涓鐐圭偣鎺у埗嬈插湪閲岄潰錛屾兂鐪嬬湅IRRLICHT緇忚繃鏀歸犲悗錛屾槸涓嶆槸鐪熺殑姣斾笉涓奜GRE銆?/p> 鍥涖佽渶闂ㄧ殑鎴愬姛錛岃凍澶熻鏄庝竴涓父鎴忕殑鐢婚潰錛屼笉鏄叏閮紝鍙涓嶅獎鍝嶅ぇ灞錛?鏈変竴涓瘮杈冧寒鐐圭殑鎶鏈垨鑰呮晥鏋滐紝灝卞彲浠ョ暀浣忕帺瀹躲?鎴戞兂錛岃渶闂ㄩ噷瑁呭鐨勬祦鍏夋晥鏋滐紝铏界劧灝辨槸緇忚繃緹庢湳綺懼績璁捐鍚庣殑綰圭悊鍔ㄧ敾錛?浣嗗凡緇忚凍澶熶綋鐜伴珮綰ц澶囧拰浣庣駭瑁呭鐨勫樊璺濄?鐜╁涔熻兘鎰熷彈鍒拌嚜宸遍珮綰ц澶囩殑鍗庝附錛?鎵浠ワ紝鎴戞洿鍠滄铚闂ㄧ殑灝忓閥銆?/p> 浜斻佺姱璐憋紝瓚婃槸澶氱殑浜哄枩嬈㈢殑涓滆タ錛岃秺鏄笉鎯蟲暣銆?/p> 鍏佹兂鎱㈡參榪囨浮錛屽厛浣跨敤IRRLICHT錛岀洿鍒癐RRLICHT涓嶅鐢紝灝辨敼錛屾敼瀹屼簡錛屽氨鎶奍RR鎵鏈夌殑涓滆タ鍒犻櫎浜嗭紝鍚嶅瓧鎹簡銆?灝辨槸鑷繁鐨勪簡銆?/p> 涓冦丟AMELOFT鐨勫埡瀹俊鏉$敤鐨勬槸IRRLICHT錛屾墍浠ワ紝鎴戣寰楄繕鏄彲浠ョ殑銆?錛圥S:涓嬭澆鏉ョ帺浜嗕竴涓嬶紝鍦↖PAD涓婏紝涓昏绔欑珛涓嶅姩鐨勬椂鍊欙紝浼氭潵鍥炴姈鍔紝 鎽勭浉鏈虹Щ鍔ㄧ殑鏃跺欙紝涔熶細鎶栧姩錛屽緢璐硅В錛?闅鵑亾鏄誕鐐圭簿搴﹂棶棰橈紵 浣哢NITY3D鍜孋OCOS2D-X絳夋槸娌℃湁榪欓棶棰樼殑鍛錛夈?/p> 鍏跺疄錛屽垪浜嗗緢澶氭潯錛屾渶鍚庝篃鍙戠幇錛孖RRLICHT闄や簡瑕佺畝鍗曠偣浠ュ錛屾槸娌℃湁OGRE閭d箞寮哄ぇ鐨勩?涓嶈繃錛屾垜榪樻槸閫夋嫨浜嗕粠綆錛屾瘯绔熺簿鍔涙湁闄愩?濡傛灉瑕佹妸OGRE鏁村涓滆タ鐞嗚В浜嗭紝鍐嶉愭閲嶅啓錛屾垜浼拌浼氱柉鎺夈?姣曠珶澶ц屽叏鐨勪笢瑗匡紝鍏蜂綋鍦ㄧ敤鐨勬椂鍊欙紝鏄鎶涙帀寰堝涓滆タ鏉ユ崲鍙栨晥鐜囩殑銆?/p> 鏃㈢劧鍒拌繖涓偣浜嗭紝涓嶅緱涓嶈鐐瑰埆鐨勩?/p> 11騫寸殑鏃跺欙紝鍏徃鐮斿彂鐨勫紩鎿庡湪婕旂ず瀹孌EMO鍚庯紝灝卞彨鍋滀簡銆?欏圭洰榪涜浜嗕袱騫村崐錛屾渶鍚庡彧鏈変竴鍫嗕唬鐮佸拰婕旂ず紼嬪簭銆?瀵瑰叕鍙告潵璇達紝鍏跺疄鏄竴瀹氱殑鎹熷け銆?鍚庢潵欏圭洰緇勬垚鍛樿漿鎴榃EB銆?nbsp; 璧板埌榪欎竴姝ワ紝鍏跺疄鍘熸潵鐨勬垚鍛樺彧鍓╁拰鎴戝彟涓涓惌妗d簡銆?/p> 娌℃兂鍒幫紝榪涘叆浜哤EB錛屽氨涓鍘諱笉澶嶈繑浜嗐?騫朵笖錛屽叕鍙哥殑WEB欏圭洰榪涘睍涔熶笉鏄緢欏哄埄銆?nbsp; 閮借姣曚笟鍚庝袱騫存槸涓涓垎姘村箔錛?褰撴椂姝eソ姣曚笟涓ゅ勾銆?浜庢槸鍐沖畾鎹竴涓幆澧冩寫鎴樸?灝辨潵鍒頒簡鐩墠鐨勫叕鍙革紝鍋歊TS娓告垙鏈嶅姟鍣ㄣ?nbsp; 闈㈠鏈煡鐨勪笢瑗匡紝璨屼技鏇磋兘嬋鍙戞垜鐨勫叴瓚o紝濡備粖椹笂鍙堟槸涓騫翠簡銆傛笎娓愬湴錛屽紑濮嬫蹇靛紩鎿庯紝鎬蹇靛浘褰€?鍙互璇碔RRLICHT鐩墠灝辨槸琚垜鐢ㄦ潵琛ㄨ揪鎴戝鍥懼艦鐨勬濆康銆?铏界劧鎴戝浘褰㈡柟闈㈢殑鎶鏈緢闄堟棫錛岃佸湡錛?浣嗗茍涓嶅獎鍝嶆垜璇存垜鍠滄鎼炲浘褰€?/p> 鏂囩珷灝卞埌姝ゅ惂銆備篃涓嶇煡閬撳啀瑕佽浜涗粈涔堜簡銆?/p>
榪欐槸浣跨敤freetype榪涜涓枃鏄劇ず鐨勬晥鏋溿?/p>
irrlicht鐢變簬鏄嬌鐢ㄤ綅鍥懼瓧浣撶殑鏂瑰紡錛屾槸寰堝鏄撴浛鎹㈡帀瀛椾綋鐨勩?鍚屾椂錛屽叾鏈韓涔熸彁渚涗簡Font鎺ュ彛鏇挎崲鐨勫姛鑳姐?/p>
鍏蜂綋鍋氭硶鍜岀綉涓婂ぇ澶氭暟浜烘槸涓鏍風殑銆?/p>
鍦ㄥ仛榪欎釜鐨勬椂鍊欙紝鍙堝紩鍏ヤ簡鍙︿竴涓瘽棰橈紝 gameswf鍜宬font(KlayGE Font)
gameswf鏄竴涓紑婧愮殑C++ FLASH PLAYER銆?/p>
gameloft浠ュ強寰堝縐誨姩搴旂敤鎴栬呮父鎴忛兘鍦ㄤ嬌鐢ㄥ畠銆?/p>
褰撶劧錛屼篃鍖呮嫭ScaleForm. 鍥犱負ScaleForm鏄晢涓氱殑錛屾墍浠ユ瘮gameswf鏇村姞瀹屽杽錛岃櫧鐒惰錛実ameswf鏄疭caleForm鐨勫師鍨嬨?/p>
kfont涓鐩存槸鑷繁鍠滄鐨勪竴縐嶅瓧浣撹В鍐蟲柟妗堬紝鍏舵棤姣旀媺浼哥殑鑳藉姏闈炲父璁ㄤ漢鍠滄銆傚姞涓婄幇鍦ㄥ張鍗曠嫭鎴愬簱浜嗭紝濡傛灉涓嶇敤gameswf鐨勮瘽錛屾垜鎯蟲妸瀹冩暣鍚堣繘irrlicht涓?涓ゅ勾鍓嶅叕鍙革紙鍏堝墠鐨勫叕鍙革級鐨勫紩鎿庡氨鐢ㄤ笂浜嗚繖涓紝閬楁喚瀛椾綋搴撲笉鏄垜寮勮繘鍘葷殑錛屼竴鐩村kfont娌℃湁榪戣窛紱繪帴瑙︺?/p>
緗戜笂涓嬭澆涓嬫潵鐨勪唬鐮?涓嬮潰鍦板潃鍙緵鍙傝冿紝榪欐槸鎴戣寰椾紬澶氭枃绔犱腑錛岃寰楁瘮杈冪粏鐨勪竴涓?/p>
http://blog.csdn.net/lee353086/article/details/5260101
鑷充簬FreeType,澶у鍘誨畼鏂逛笅杞芥潵緙栬瘧灝卞彲浠ヤ簡銆?/p>
BLOOM寮
BLOOM鍏?/p>
鍦↖RRLICHT涓疄鐜癇LOOM錛屽拰鍏跺畠寮曟搸涓病鏈夊お澶氱殑涓嶅悓銆?SHADER榪樻槸閭d釜SHADER銆?/p>
鍏充簬BLOOM鐨勭畻娉曪紝涔熷氨閭f牱浜嗭紝娌℃湁鐗瑰埆涔嬪錛屽喌涓旓紝鎴戣繖BLOOM寰堟毚鍔?/p>
render scene to texture.
1/4 downsample 閫夋嫨鏆村厜鍍忕礌
h_blur 7嬈¢噰鏍?鍜屾潈閲嶆販鍚?
v_blur 7嬈¢噰鏍?鍜屾潈閲嶆販鍚?/p>
compose 涓ゅ浘鍙犲姞
涓嬮潰璇磋鎴戝湪irrlicht涓疄鐜皃ost processing鐨勬柟妗堛?/p>
鍦╥rrlicht涓槸娌℃湁灞忓箷瀵歸綈鍥涜竟褰㈣妭鐐圭殑錛屽鏋滆鐗規畩鎵╁睍錛屽氨鍙兘淇敼浠g爜浜嗐傛垜鏄敖閲忎繚璇佽嚜宸變笉淇敼IRR涓琛屼唬鐮侊紝 闄ら潪鏄湡姝d嬌鐢ㄦ椂錛岃瀵規晥鐜囪繘琛屼紭鍖栥傚墠鐜板疄鐜扮殑GPU钂欑毊錛屾按闈紝闀滈潰絳夛紝閮芥病鏈変慨鏀硅繃涓琛屼唬鐮侊紝 鍥犱負鎴戜笉鎯沖洜涓鴻嚜宸辯殑涓鏃墮渶姹傦紝鑰屾敼鍔ㄤ簡閭d竴鍫嗐?褰撴垜鐪熺殑闇瑕佹敼鍔╥rrlicht鎵嶈兘杈懼埌鐩爣鐨勬椂鍊欙紝琛ㄧずirrlicht涓垜浣跨敤鐨勯儴鍒嗭紝鍙互閫浼戜簡銆?/p>
娓叉煋鍦烘櫙鐨勬椂鍊欙紝鎴戜滑閫氬父鍦ㄤ嬌鐢╝ddXXXXSceneNode鐨勬椂鍊欙紝閮介粯璁や笉浼犵埗鑺傜偣銆傝繖鏍峰氨鏄粯璁ょ殑鍦烘櫙鏍硅妭鐐廣備絾鏄紝褰撴垜浠鍋歱ost process鐨勬椂鍊欙紝灝遍渶瑕佸鍦烘櫙涓殑鐗╀綋榪涜鏄劇ず鐨勫紑鍜屽叧錛?浜庢槸錛屾垜浠負浜嗗緢蹇熷湴鎺у埗錛?浜庢槸灝嗘櫘閫氬満鏅妭鐐瑰鍔犱簡涓涓埗鑺傜偣錛?鑰宲ost processing浣滀負鍦烘櫙鐨勫厔寮熻妭鐐癸紝 榪欐牱鍦ㄦ覆鏌撶殑鏃跺欙紝灝卞彲浠ユ柟渚垮湴榪涜鐩稿叧鎺у埗浜嗐?/p>
澶ф鏄繖鏍風殑
RootSceneNode
PostProcessingNode SceneOjbectsNode
Obj1鈥?Obj2鈥?Obj3鈥?/p>
嫻佺▼錛?/p>
鍏抽棴 PostProcessingNode 錛?娓叉煋 SceneOjbectsNode 涓嬫墍鏈夌殑鐗╀綋鍒癛T涓娿?/p>
鍏抽棴 SceneOjbectsNode錛?鎵撳紑PostProcessingNode錛?榪涜涓緋誨垪鐨勫悗鏈熸晥鏋滃鐞嗐?/p>
鍦╥rrlicht涓槸娌℃湁鎻愪緵灞忓箷瀵歸綈鍥涜竟褰㈢粯鍒剁殑錛?濡傛灉鎵嬪伐鏋勫緩錛屽氨寰堥夯鐑︺?鎵浠ワ紝鎴戦噰鐢ㄧ殑鏄竴縐嶅緢甯歌鐨勬墜娉曪紝 鍗抽氳繃UV鍧愭爣鏉ヨ綆楁渶鏈緇堢殑欏剁偣鍧愭爣鍊箋?/p>
VS鐨勮緭鍑猴紝鏄涓鍖栧潗鏍囩郴錛?鍗砐,Y鏄浜?錛堬紞1錛?錛変箣闂寸殑錛?浜庢槸銆?鎴戜滑鍙渶瑕?pos = (uv-0.5)*2; pos.y = 鈥損os.y;灝卞彲浠ヤ簡銆?/p>
鏈榪戜竴鐩村湪鍔犵彮錛屾病鏃墮棿鏁寸悊鍑轟唬鐮併?鏈夊叴瓚g殑鏈嬪弸鍙互鍔犱笅闈㈢殑緹?/p>
Irrlicht Engine-China
254431855
Posted on May 19, 2011, 11:00 pm, by xp, under Programming.
Just got a new Android phone (a Samsung Vibrant) a month ago, so after flashing a new ROM and installing a bunch of applications, what would I want to do with the new phone? Well, I鈥檇 like to know if the phone is fast enough to play 3D games. From the hardware configuration point of view, it is better equipped than my desktop computer in the 1990s, and since my desktop computer at the time had no problem with 3D games, I would expect it to be fast enough to do the same.
At first, I was considering downloading a 3D game from the market, but 3D games for Android are still rare, then why don鈥檛 I just create a 3D demo game myself?
After looking around which 3D game engines are available for the Android platform, I just settled down with Irrlicht. This is an open source C++ graphic engine, and not really a game engine per se, but it should have enough features to create my demo 3D application. And I like to have realistic physics in my game, so what could be better than the Bullet Physics library? This is the best known open source physics library, also developed in C++. The two libraries together would be an interesting combination.
Although Irrlicht was developed for desktop computers, but luckily enough, someone has already ported Irrlicht to the Android platform, which requires a special device driver for the graphic engine. And guess what? Someone has also created a Bullet wrapper for the Irrlicht engine. All of them in C++, and open source. All we need to do now to pull all these codes together to build a shared library for Android.
In this part, I鈥檒l just describe what needs to compile all the codes for Android. Since we will compile C/C++ codes, you鈥檒l need to download the Android native development kit. Please refer to the documentation on how to install.
We create an Android project, and add a jni folder. Then we put all the C/C++ source codes under the jni folder. I created three sub-folders:
After, all we need to do is to create an Android.mk file, which is quite simple, really. You can read the makefile to see how it is structured. Basically, we just tell the Android NDK build tools that we want to build all the source codes for the Arm platform, and we want to link with the OpenGL ES library, to create a shared library called libirrlichtbullet.so. That鈥檚 about it.
However, there鈥檚 one minor thing to note though. Android does not really support C++ standard template library, but the irrBullet library made use of it. Therefore, in the jni folder, we need to add an Application.mk file, which contains the following line:
APP_STL := stlport_static
And that鈥檚 it. Now, you can run ndk-build to build the shared library. If you have a slow computer, it would take a while. If everything is alright, you should have a shared library in the folder libs/armeabi/. That shared library contains the Bullet Physics, Irrlicht and the irrBullet wrapper libraries. You can now create your 3D games for Android with it. In the next part, we will write a small demo program using this library.
You can download all the source codes and pre-built library here.
Posted on May 20, 2011, 11:30 am, by xp, under Programming.
In the last post, we have built the Bullet Physics, Irrlicht and irrBullet libraries together to create a shared library for the Android platform. In this post, we are going to create a small demo 3D game for Android, using the libraries that we have built earlier.
This demo is not really anything new, I am going to just convert an Irrlicht example to run on Android. In this simple game, we are going to stack up a bunch of crates, and then we will shoot a sphere or a cube, from a distance, to topple the crates. The Irrlicht engine will handle all the 3D graphics, and the Bullet Physics library will take care of rigid body collision detection and all realistic physical kinetics. For example, when we shoot a sphere from the distance, how the sphere follows a curve line when flying over the air, how far it will fly, where it is going to fall on to the ground, how it reacts when it hits the ground, how it reacts when it hits the crates, and how the crates will react when being hit, etc, all these will be taken care of by Bullet Physics, and Irrlicht will render the game world accordingly.
Since it is easier to create Android project in Eclipse, we are going to work with Eclipse here. You will need to following tools to work with:
I鈥檓 assuming you have all these tools installed and configured correctly. And I鈥檓 assuming you have basic knowledge on Android programming too, so I won鈥檛 get into the basic details here.
Let鈥檚 create a project called ca.renzhi.bullet, with an Activity called BulletActivity. The onCreate() method will look something like this:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Lock screen to landscape mode.
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
mGLView = new GLSurfaceView(getApplication());
renderer = new BulletRenderer(this);
mGLView.setRenderer(renderer);
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
width = displayMetrics.widthPixels;
height = displayMetrics.heightPixels;
setContentView(mGLView);
}
This just tells Android that we want an OpenGL surface view. We will create a Renderer class for this, something very simple like the following:
public class BulletRenderer implements Renderer
{
BulletActivity activity;
public BulletRenderer(BulletActivity activity)
{
this.activity = activity;
}
public void onDrawFrame(GL10 arg0)
{
activity.drawIteration();
}
public void onSurfaceChanged(GL10 gl, int width, int height)
{
activity.nativeResize(width, height);
}
public void onSurfaceCreated(GL10 gl, EGLConfig config)
{
activity.nativeInitGL(activity.width, activity.height);
}
}
The renderer class鈥檚 method will be invoked every time a frame needs to be rendered. There鈥檚 nothing special here. When the methods are invoked, we just invoke the native methods in the activity class, which will then call the C native functions through JNI. Since Irrlicht and Bullet are C++ libraries, we will have to write the main part of the game in C/C++. We keep very little logic in Java code.
When the surface is first created, the onSurfaceCreated() method is invoked, and here, we just call nativeInitGL(), which will initialize our game world in Irrlicht. This will initialize the device, the scene manager, create a physical world to manage the rigid bodies and their collision, create a ground floor, and put a stack of crates in the middle point. Then, we create a first-person-shooter (FPS) camera to look at the stack of crates. The player will look at this game world through the FPS camera.
I鈥檓 not going to describe the codes line by line, since you can download the codes to play with it. But when you create the Irrlicht device with the following line of code:
device = createDevice( video::EDT_OGLES1, dimension2d(gWindowWidth, gWindowHeight), 16, false, false, false, 0);
Make sure you select the correct version of OpenGL ES library on your Android device. I have version 1.x on mine. But if you have version 2.x, change to video::EDT_OGLES2 instead.
After the initialization, we would have a scene that looks like this:
When a frame is changed and needs to render, the onDrawFrame() method of the renderer is invoked. And here, we just call the nativeDrawIteration() function and will handle the game logic in C/C++ codes. The code looks like this:
void Java_ca_renzhi_bullet_BulletActivity_nativeDrawIteration(
JNIEnv* env,
jobject thiz,
jint direction,
jfloat markX, jfloat markY)
{
deltaTime = device->getTimer()->getTime() 鈥?timeStamp;
timeStamp = device->getTimer()->getTime();
device->run();
// Step the simulation
world->stepSimulation(deltaTime * 0.001f, 120);
if ((direction != -1) || (markX != -1) || (markY != -1))
handleUserInput(direction, markX, markY);
driver->beginScene(true, true, SColor(0, 200, 200, 200));
smgr->drawAll();
guienv->drawAll();
driver->endScene();
}
As you can see, this is very standard Irrlicht game loop, the only thing added here is a function to handle user input.
User input includes moving left and right, forward and backward, shooting sphere and cube. Irrlicht engine depends on keyboard and mouse for user interaction, which are not available on Android devices. So, we will create a very basic kludge to allow users to move around and shoot. We will use touch and tap to handle user input. Users will move their finger left and right, on the left part of the screen, to move left and right in the game world. Users will move their finger up and down, on the right part of screen, to move forward and backward in the game world. And tap on the screen to shoot. Therefore, the movement direction is translated into a parameter, called direction, and passed to the native code to be handled. We also grab the X and Y coordinates of the shooting mark, and pass them as parameters to native codes as well.
That鈥檚 it. You can now build it, package into an apk, install it on your Android device, and play with it. When you shoot on the stack of crates, you would have a scene that looks like this:
The performance on my Samsung Vibrant is ok, I get about 56 or 57 FPS, which is quite smooth. But if there are too many objects to animate, especially after we have shot many spheres and cubes, we will have a screen that hangs and jumps a bit, or sometimes, it stops to react to user input for a fraction of second. In a real game, we might want to remove objects that have done their work, so that the number of objects to animate is significantly reduced to maintain an acceptable performance.
The other important thing that we want to improve is user interaction and control. The Irrlicht engine is developed for desktop computers, it relies mainly on keyboard and mouse for user interaction. These are not available on mobile devices. The current demo attempted to use touch and tap on screen as user control, but it does not work very well. In a next post, we will try to create virtual controls on screen (e.g. buttons, dials, etc), and we might want to take advantage of the sensor as well, which is a standard feature on mobile devices now.
You can download the source codes of the demo here.
Posted on May 23, 2011, 6:25 pm, by xp, under Programming.
In the last post, we have created a basic 3D demo application with Irrlicht, in which we put a stack of crates, and we topple them by shooting a cube or a sphere.
In this post, we will try to create an on-screen control so that you can move around with it, like using a hardware control. What we want to have is something like this, in the following screenshot:
What we have here is a control knob, sitting on a base. The knob is in the centre of the base. The on-screen control always stays on top of the game scene, and the position should stay still regardless of how you move the camera. However, users can press on the knob, and drag it left and right, and this, in turn, moves the camera left and right accordingly.
Obviously, you can implement movement direction along more than one axis too. And you can also have more than one on-screen control if you want, since it is a device with multi-touch screen. But that鈥檚 left to you as an exercise.
Placing an on-screen control is actually quite easy. All you have to do is to load a picture as texture, then draw it as 2D image on the screen, at the location you want to put the control. But since we want the on-screen control to be always on top, we have to draw the 2D image after the game scene (and all the scene objects) are drawn. If we draw the 2D image first, it will hidden by the game scene. There, in your loop, you would have something like this:
driver->beginScene(true, true, SColor(0, 200, 200, 200));
smgr->drawAll();
guienv->drawAll();
// Draw the on-screen control now
onScreenControl->draw(driver);
driver->endScene();
That鈥檚 the basic idea. Here, we have created an OnScreenControl class, which encloses two objects, one of VirtualControlBase class and the other, of VirtualControlKnob class. The draw() method of the OnScreenControl class looks like this:
void OnScreenControl::draw(IVideoDriver* driver)
{
base->draw(driver);
knob->draw(driver);
}
It just relegates the drawing works to its sub-objects, the control base and the control knob. Note that the knob has to be drawn after the base, otherwise, it will be hidden behind the base, instead of sitting on top of it. The draw() method of the base looks like:
void VirtualControlBase::draw(IVideoDriver* driver)
{
driver->draw2DImage(_texture,
position2d(pos_x, pos_y),
rect(0, 0, width, height),
0,
SColor(255,255,255,255),
true);
}
As you see, it just draws a 2D image with the texture, at the location specified. That鈥檚 it.
After putting the on-screen control in place, we have to handle user touch events on the screen. If users press on the knob (i.e. pressing within the square boundary of the knob image), and move the finger around, we update the position of the knob according to the movement direction. Here, we want to make sure that users can not drag the knob out of the control base boundary (or too far out of the boundary anyway), to make it look and behave like a real control. As users move the knob around, you want to update your camera鈥檚 position accordingly. And when the knob is released, you want to reset its position back to the centre of the control base.
That鈥檚 basically the idea. You can grab the source code here. Ugly codes, I warn you.
The major problem of programming Irrlicht on Android is the separation of Java codes and the C/C++ codes. If you want to limit your program to only Android 2.3 or later, you can probably write the whole program in C/C++, using the native activity class. That way, you don鈥檛 have to move back and forth between Java and C++. But if you want to run your program on older versions of Android, your Activity must be written in Java, and the main game logic written in C/C++. You then have to catch user interaction events in your Java code, pass them through JNI to your C/C++ code. There will be loss of information as you move back and forth, not to mention that there will be quite a bit of code duplication. You can certainly create a full wrapper for the Irrlicht and Bullet libraries, but that will be taxing your mobile device heavily, and will certainly have a negative impact on performance. And creating a full wrapper for these two libraries would be a heck of a job.
The other problem is that, Irrlicht is an engine developed for the desktop, where keyboard and mouse are the main input devices. The Irrlicht port to Android mainly concerns with a display driver for Android, but the port has not really gone deep into this area of user interaction. Therefore, as you write your Irrlicht-based Android program, you would have to hack together user input handling model, event model, etc. In my demo, I haven鈥檛 even touched that, I have just kludged together some primitive event handling codes. In order to have our program fit in those multi-touch based devices, we would have to dig into the Irrlicht scene node animator and event handling mechanisms, and work it out from there. For example, we will have to define our own scene node animator which would be based on touch events instead of keyboard and mouse events, and add it to the scene node that we want to animate. This is something that we are going to look into in our future posts.
鏈榪戝湪鐢╥rrlicht鍋氫竴涓?D璇曡。闂寸殑灝忛」鐩紝涓轟簡緇欓」鐩娣葷偣鑺辨牱錛屼簬鏄兂瀹炵幇涓闈㈤暅瀛愩?/p>
鎴戣寰桪3D榫欎功涓婃湁涓涓嬌鐢ㄦā鏉跨紦鍐插尯瀹炵幇鐨勪緥瀛愩傜綉涓婁篃鏈塐PENGL瀹炵幇鐨勪緥瀛愩?浣嗚繖涓嬈★紝鎴戞兂鐢╥rrlicht鐨凴TT瀹炵幇涓闈㈤暅瀛愭晥鏋溿?/p>
鍏跺疄鍘熺悊鍜屾按闈㈠弽灝勫師鐞嗘槸涓鏍風殑錛?鍙槸娌℃湁鍔犳壈鍔ㄨ屽凡
絎竴姝ワ細娓叉煋鍙嶅皠璐村浘
鍙嶅皠璐村浘鐨勬覆鏌擄紝鍏跺疄灝辨槸灝嗘憚鐩告満閫氳繃闀滈潰闀滃儚鍗沖彲錛宨rrlicht涓垜鎵句簡鍗婂ぉ錛屾病鏈夊彂鐜伴暅鍍忕煩闃電殑綆楁硶錛屽掓槸鍦ㄧ綉涓婃悳鍒頒簡涓涓?寰堟槸涓嶉敊銆?/p>
鍚屾椂錛屼篃緲婚槄浜嗕竴涓嬪厛鍓嶅叕鍙稿紩鎿庨」鐩殑浠g爜錛屽彂鐜板叾瀹炲氨鏄偅涓叕寮忋?鏈夊叴瓚g殑鏈嬪弸鍙互鍙傜湅榪欓噷
http://www.cnblogs.com/glshader/archive/2010/11/02/1866971.html
閫氳繃榪欎釜闀滈潰鍙嶅皠鐭╅樀錛屾垜浠彲浠ュ皢鎽勭浉鏈洪暅鍍忥紝 鐩稿綋浜庢槸浠庨暅瀛愰噷鍚戝鐪嬶紝娓叉煋鍑轟竴涓笘鐣屻?鍦ㄦ覆鏌撶殑鏃跺欙紝瑕佽寰楄緗鍓潰銆?鍦ㄦ垜鐨勬祴璇曚腑鎴戞病鏈夎緗?/p>
絎簩姝ワ細閲嶆柊娓叉煋涓栫晫
閲嶆柊娓叉煋涓栫晫鐨勬椂鍊欙紝闀滃瓙闇瑕佷竴涓壒孌婄殑綰圭悊鏉ヨ繘琛屽弽灝勮創鍥俱傦紙闀滃儚鎽勭浉鏈虹┖闂寸殑鎶曞獎綰圭悊鏄犲皠錛夈?榪欎釜璐村浘鏂瑰紡錛屽氨鏄寚蹇界暐闀滃瓙鐨勭汗鐞嗗潗鏍囷紝鑰岄氳繃
闀滃儚鎽勭浉鏈烘潵璁$畻鍑烘姇褰卞潗鏍囷紝鐒跺悗璐村湪闀滃瓙涓娿傚湪鎴戠殑嫻嬭瘯涓紝鏄敤SHADER鏉ュ疄鐜扮殑銆?涓洪暅瀛愬仛浜嗕竴涓壒孌婄殑綰圭悊銆?/p>
涓嬮潰錛屾垜璐翠竴涓婼HADER錛屽緢綆鍗曪紝濡傛灉瀹炲湪涓嶆竻妤氱殑錛屽彲浠ュ弬鑰冧竴浜涙姇褰辯汗鐞嗙浉鍏崇殑璧勬枡銆?/p>
欏剁偣鐫鑹插櫒浠g爜 HLSL
float4x4 WorldViewProj;
float4x4 MirrorWorldViewProj;
struct VS_OUTPUT
{
float4 position :POSITION;
float3 uv: TEXCOORD0;
};
struct VS_INPUT
{
float4 position : POSITION;
float4 color : COLOR0;
float2 texCoord0 : TEXCOORD0;
};
VS_OUTPUT main(VS_INPUT input)
{
VS_OUTPUT output;
float4 pos = mul(input.position, WorldViewProj);
output.position = pos;
//璁$畻鍙嶅皠綰圭悊鐨勫潗鏍?
pos = mul(input.position,MirrorWorldViewProj);
output.uv.x = 0.5 * (pos.w + pos.x);
output.uv.y = 0.5 * (pos.w - pos.y);
output.uv.z = pos.w;
return output;
}
鍍忕礌鐫鑹插櫒浠g爜 HLSL
sampler2D colorMap;
struct PS_OUTPUT
{
float4 color : COLOR0;
};
struct PS_INPUT
{
float4 position : POSITION;
float3 uv: TEXCOORD0;
};
PS_OUTPUT main( PS_INPUT input )
{
PS_OUTPUT output;
float2 uv = saturate(input.uv.xy / input.uv.z);
output.color = tex2D(colorMap,uv);
return output;
}
RTT鐩稿叧鐨勬搷浣滐紝irrlicht鐨凴enderToTexture宸茬粡寰堟槑鐧戒簡錛屽啀姝や笉鍦ㄦ暦榪般?/p>
涓婂浘錛屾敹宸?/p>
鏈潵璇存槸鍋氶暅瀛愭晥鏋滅殑錛岀粨鏋滄墜宸ヨ綆楃殑闀滈潰鍙嶅皠鐭╅樀搴旂敤鍦╥rrlicht鐩告満涓婄殑鏃跺欙紝濮嬬粓鏃犳硶鍑虹幇鏁堟灉錛屽彧鑳藉幓緗戜笂鎼滅儲
鍦╥rrlicht official wiki涓婂彂鐜頒簡榪欎釜鎵╁睍鐨刉aterNode錛屼笅杞戒笅鏉ワ紝鏀逛簡鐐笲UG錛屾暣鍚堣繘浜員errain Demo閲岋紝 灝辨槸涓婂浘鐨勬晥鏋溿?/p>
鍦ㄦ垜鐨勬満鍣ㄤ笂,HLSL鐗堟湰鏄病鏈夐棶棰樼殑錛孏L鐗堟湰璨屼技RTT鏈夌偣闂銆?/p>
http://supertuxkart.sourceforge.net/
鐢變簬澧欑殑鍘熷洜錛岄渶瑕佸悇浣嶆惌姊瓙銆?/p>
涓婂懆鏈紝鍦ㄥ紕鎹㈣鐨勬椂鍊欙紝鍙戠幇irrlicht寮曟搸鏈韓鏄笉鏀寔紜歡钂欑毊鐨勶紝澶氬皯浠や漢鏈変簺澶辨湜銆?蹇冮噷灝變竴鐩村鎬濈潃鎬庝箞鎵╁睍涓涓嬶紝灝嗗畠寮勫嚭鏉ャ?/p>
鍊煎緱璇存槑鐨勬槸STK瀵筰rrlicht寮曟搸鐨勭敤娉曟槸寰堢畝鍗曠殑錛屽熀鏈笂鍙互璇存槸瑁哥敤錛屽茍鏈湪irrlicht鎺ュ彛涓婂仛淇敼銆?鑰屾槸瀵瑰榪涜浜嗕竴浜涘繀瑕佺殑鎵╁睍銆?/p>
褰撶劧錛孲TK涔熷澶栧紑鏀句簡涓涓猧rrlicht.dll錛岃鏄慨鏀逛簡鍏朵腑鐨凚UG銆?浣嗙洿鎺ヤ嬌鐢╥rrlicht鏄彲浠ョ殑銆?/p>
搴熻瘽涓嶅璇達紝鏉ヨ璇村浣曚笉淇敼irrlicht涓琛屼唬鐮侊紝閫氳繃澶栭儴鎵╁睍鏉ュ疄鐜扮‖浠墮楠煎姩鐢誨惂
棣栧厛錛岃兘澶熶嬌鎴戜滑涓嶄慨鏀筰rrlicht浠g爜鐨勫師鍥狅紝鏄洜涓篒SkinnedMesh鎻愪緵浜嗕竴涓猻etHardwareSkinning鎺ュ彛錛岄粯璁や負false.
铏界劧榪欎釜鎺ュ彛鐨勮鏄庢槸"(This feature is not implemented in irrlicht yet)”錛屼絾騫朵笉浠h〃錛岃緗笌涓嶈緗棤宸埆銆?
鏌ョ湅浠g爜鍙互鍙戠幇錛屽綋浣犺緗簡榪欎釜涓簍rue浠ュ悗錛宨rrlicht灝卞畬鍏ㄤ笉綆′綘鐨勫姩鐢諱簡銆?鎰忔濆氨鏄紝瑕佹槸浣犻潪瑕佽鎴戝共鎴戜笉騫蹭笉浜嗙殑浜嬶紝閭e氨鍙湁鎮ㄥ彟璇烽珮鏄庝簡銆?/p>
irrlicht榪濩PU璁$畻閮戒笉浼氬弬涓庛?榪欐濂借鎴戜滑鏈夋満鍙箻錛屽畬鍏ㄧ敤GPU鎺ョ銆?/p>
鑰岃璁╀竴涓《鐐瑰弬涓庨楠艱綆楋紝閭i楠肩儲寮曞垯鏄皯涓嶄簡鐨勩傛墍浠ワ紝鎴戜滑闇瑕佹兂鍔炴硶璁╅《鐐規暟鎹兘澶熷皢楠ㄩ绱㈠紩浠e叆SHADER涓?/p>
鍦⊿TK涓敤浜嗕竴縐嶅閥濡欑殑鏂規硶錛?灝辨槸浣跨敤浜嗛《鐐圭殑棰滆壊鏁版嵁錛?铏界劧榪欐牱涓鏉ワ紝欏剁偣棰滆壊灝辯敤涓嶄簡浜嗐?浣嗗湪妯″瀷娓叉煋鏃訛紝欏剁偣棰滆壊寰堝皯琚嬌鐢ㄥ埌鐨勩?涔熷氨鏄錛岄《鐐歸鑹插湪STK鐨勫姩鐢繪ā鍨嬩腑錛岃鐢ㄤ綔浜嗛楠肩儲寮曘?/p>
鍒濆鍖栭楠肩儲寮曠殑鏂規硶寰堢畝鍗曪紝鐢ㄤ笅闈㈢殑浠g爜閬嶅巻鍗沖彲銆?/p>
璁撅細鎴戜滑鏈変竴涓楠煎姩鐢繪ā鍨嬫槸 ISkinnedMesh* pSkinnedMesh = …
閭d箞錛氬垵濮嬪寲浠g爜濡備笅
for(u32 i = 0;i < pSkinnedMesh ->getMeshBuffers().size();++i)
{
for(u32 g = 0;g < pSkinnedMesh ->getMeshBuffers()[i]->getVertexCount();++g)
{
pSkinnedMesh ->getMeshBuffers()[i]->getVertex(g)->Color = video::SColor(0,0,0,0);
}
}
//鍒濆鍖栧畬姣曚互鍚庯紝灝辨槸闇瑕佺湡姝g殑绱㈠紩璧嬪間簡錛岄氳繃浠ヤ笅浠g爜鍙互瀹屾垚
const core::array<scene::ISkinnedMesh::SJoint*>& joints = pSkinnedMesh ->getAllJoints();
for(u32 i = 0;i < joints.size();++i)
{
const core::array<scene::ISkinnedMesh::SWeight>& weights = joints[i]->Weights;
for(u32 j = 0;j < weights.size();++j)
{
int buffId = weights[j].buffer_id;
int vertexId = pSkinedMesh->getAllJoints()[i]->Weights[j].vertex_id;
video::SColor* vColor = &pSkinedMesh->getMeshBuffers()[buffId]->getVertex(vertexId)->Color;
if(vColor->getRed() == 0)
vColor->setRed(i + 1);
else if(vColor->getGreen() == 0)
vColor->setGreen(i + 1);
else if(vColor->getBlue() == 0)
vColor->setBlue(i + 1);
else if(vColor->getAlpha() == 0)
vColor->setAlpha(i + 1);
}
}
//緇忚繃浠ヤ笂涓や釜姝ラ錛岄《鐐規暟鎹敼閫犲畬鎴愩?鍊煎緱娉ㄦ剰鐨勬槸錛?鍦ㄨ繖閲岋紝 绱㈠紩 0 鏄璁や負鏄棤鏁堢殑
鐒跺悗錛屾垜浠潵鍒涘緩涓涓猄HADER浣滀負娓叉煋銆?/p>
鍋囪 鎴戜滑灝嗚繖涓猵SkinnedMesh緇戝畾浜嗗埌浜嗕竴涓狪AnimatedSceneNode* node 涓娿?/p>
閭o紝鎴戜滑涓鴻繖涓粨鐐瑰垱寤轟竴涓潗璐?鍦ㄥ垱寤烘潗璐ㄥ墠錛屾垜浠渶瑕佸噯澶囦竴涓猄HADER鍥炶皟銆?SHADER鍥炶皟灝卞儚涓嬮潰涓鏍峰氨鍙互浜嗐?/p>
class HWSkinCallBack:public video::IShaderConstantSetCallBack
{
scene::IAnimatedMeshSceneNode* m_pNode;
public:
HWSkinCallBack(scene::IAnimatedMeshSceneNode* node):m_pNode(node)
{
}
virtual void OnSetConstants(video::IMaterialRendererServices* services,
s32 userData)
{
scene::ISkinnedMesh* mesh = (scene::ISkinnedMesh*)m_pNode->getMesh();
f32 joints_data[55 * 16];
int copyIncrement = 0;
const core::array<scene::ISkinnedMesh::SJoint*> joints = mesh->getAllJoints();
for(u32 i = 0;i < joints.size();++i)
{
core::matrix4 joint_vertex_pull(core::matrix4::EM4CONST_NOTHING);
joint_vertex_pull.setbyproduct(joints[i]->GlobalAnimatedMatrix, joints[i]->GlobalInversedMatrix);
f32* pointer = joints_data + copyIncrement;
for(int i = 0;i < 16;++i)
*pointer++ = joint_vertex_pull[i];
copyIncrement += 16;
}
services->setVertexShaderConstant("JointTransform", joints_data, mesh->getAllJoints().size() * 16);
}
};
濂戒簡錛岀幇鍦ㄦ垜浠潵鍒涘緩涓涓潗璐?/p>
s32 hwskm = gpu->addHighLevelShaderMaterialFromFiles(
"../../skinning.vert","main",video::EVST_VS_2_0,
"","main",video::EPST_PS_2_0,&hwc,video::EMT_SOLID);
//鐢ㄦ柊鍒涘緩鍑烘潵鐨勬潗璐ㄨ祴鍊肩粰榪欎釜緇撶偣
node->setMaterialType((video::E_MATERIAL_TYPE)hwskm );
//鍒版錛岃緗畬姣曘?/p>
//鏈鍚庯紝灝辨槸skinning.vert鏈韓鐨勫唴瀹逛簡銆?璐村嚭鏉ュ嵆鍙紝娌℃湁澶鎶宸э紝灝辨槸涓涓櫘閫氱殑钂欑毊銆?/p>
// skinning.vert
#define MAX_JOINT_NUM 36
#define MAX_LIGHT_NUM 8
uniform mat4 JointTransform[MAX_JOINT_NUM];
void main()
{
int index;
vec4 ecPos;
vec3 normal;
vec3 light_dir;
float n_dot_l;
float dist;
mat4 ModelTransform = gl_ModelViewProjectionMatrix;
index = int(gl_Color.r * 255.99);
mat4 vertTran = JointTransform[index - 1];
index = int(gl_Color.g * 255.99);
if(index > 0)
vertTran += JointTransform[index - 1];
index = int(gl_Color.b * 255.99);
if(index > 0)
vertTran += JointTransform[index - 1];
index = int(gl_Color.a * 255.99);
if(index > 0)
vertTran += JointTransform[index - 1];
ecPos = gl_ModelViewMatrix * vertTran * gl_Vertex;
normal = normalize(gl_NormalMatrix * mat3(vertTran) * gl_Normal);
gl_FrontColor = vec4(0,0,0,0);
for(int i = 0;i < MAX_LIGHT_NUM;i++)
{
light_dir = vec3(gl_LightSource[i].position-ecPos);
n_dot_l = max(dot(normal, normalize(light_dir)), 0.0);
dist = length(light_dir);
n_dot_l *= 1.0 / (gl_LightSource[0].constantAttenuation + gl_LightSource[0].linearAttenuation * dist);
gl_FrontColor += gl_LightSource[i].diffuse * n_dot_l;
}
gl_FrontColor = clamp(gl_FrontColor,0.3,1.0);
ModelTransform *= vertTran;
gl_Position = ModelTransform * gl_Vertex;
gl_TexCoord[0] = gl_MultiTexCoord0;
gl_TexCoord[1] = gl_MultiTexCoord1;
/*
// Reflections.
vec3 r = reflect( ecPos.xyz , normal );
float m = 2.0 * sqrt( r.x*r.x + r.y*r.y + (r.z+1.0)*(r.z+1.0) );
gl_TexCoord[1].s = r.x/m + 0.5;
gl_TexCoord[1].t = r.y/m + 0.5;
*/
}
//娉細榪欐槸GLSL 2.0錛?鍦ㄧ敤IRR鍋氭祴璇曠殑鏃跺欙紝瑕侀塆L椹卞姩鏂瑰紡銆?/p>
榪樻槸涓婁釜鍥懼惂錛屼笉涓婂浘鎰熻娌℃湁鐪熷儚銆?铏界劧鍥劇湅涓嶅嚭鏉ヤ粈涔堝姩浣?/p>
涓轟簡璇存槑瀹冪湡鐨勫湪鍔紝涓嶅緱涓嶄笂絎簩寮犮?
鍦ㄦ錛屽崄鍒嗘劅璋uper Tux Kart. 鎻愪緵浜嗕竴涓涔犲拰鎵╁睍irrlicht鐨勬鏍?
閭e氨浠庝粖澶╄繖涓敤irrlicht鍋氬ぉ榫欏叓閮ㄧ殑妯″瀷鎹㈣璇磋搗鍚с?/p>
涔熶笉鐭ラ亾鏄負浠涔堬紝鏈榪戝張鎹i紦璧蜂簡OGRE鍜宨rrlicht. 騫朵笖錛屾繪兂鐢╥rrlicht瀹炵幇涓浜汷GRE涓殑涓滆タ銆?/p>
褰撶劧錛岃繖涓嶆槸鍟嗕笟欏圭洰錛屼篃娌℃湁鍟嗕笟鐩殑錛岀函灞炶泲鐤艱屽凡銆?/p>
涓鍒囪鍔ㄧ殑鐢辨潵錛岄兘鏉ヨ嚜浜巚czh閭eぉ鏅氫笂鐨勪婦鍔ㄣ?/p>
璁板緱鏈変竴澶╂櫄涓婂湪緹ら噷鑱婂ぉ錛屽ぇ浼欏氨縐拌禐鍚勪綅鑿婅嫞鏄涔堢殑鍘夊銆?/p>
鏈鍚巚c鍙戜簡涓涓嚜宸辯殑妗岄潰鎴浘璇達細璁╀綘浠湅鐪嬭強鑻f槸濡備綍緇冩垚鐨勶紙榪欎笉鏄師璇濓紝鍜岃瘽鐨勫瓧鐪兼湁鍑哄叆錛屽湪姝や笉鎯寵礋浠諱綍璐d換錛屽鏋滅湡鏈夋兂鐪嬬殑錛屽幓緲葷兢鐨勮亰澶╄褰曪級
閭eぉ鏅氫笂錛屾垜鎯充簡寰堜箙銆傛兂鎯寵嚜宸辮嚜浠庤漿鍋氶〉娓鎬互鍚庯紝鏄浣曡櫄娓″厜闃寸殑銆?/p>
緇堜簬蹇嶄笉浣忎簡錛岀炕寮浜嗚嚜宸辯殑縐誨姩紜洏錛岀湅鐪嬭嚜宸辨浘緇忓仛榪囩殑灝忎笢瑗褲?0%鏄緩濂藉伐紼嬪氨娌$悊浜嗐?/p>
榪欐墠鏄庣櫧錛屾垜鑺卞湪鎬濊冧笂鐨勬椂闂磋繙榪滃ぇ浜庝簡琛屽姩銆?浜庢槸錛屾垜鍐沖畾鏀瑰彉鑷繁錛屾壘鍥為偅涓湡鐨勬垜銆?/p>
3D娓告垙鏄垜鐨勭湡鐖憋紝 鐪熺埍鍒板氨綆楃敾闈㈠樊涓鐐癸紝鍙鏄?D錛屾垜涔熶細寰堝枩嬈€?/p>
浜庢槸錛屾垜瑙夊緱鑷繁榪樻槸搴旇鎺ョ潃鍏堝墠鐨勮礬璧頒笅鍘匯?浠涔堟湇鍔″櫒錛屼粈涔?AS3. 閮芥槸嫻簯錛?涓嶅枩嬈㈠氨鏄笉鍠滄銆?/p>
縐佷笅鍙堝紑濮嬬爺絀秈rrlicht浜嗐?/p>
鐚涘湴涓鍙戠幇錛岃嚜宸辨槸澶氫箞鐨勬悶絎戯紝 浠?9騫村埌11騫達紝涓鐩村湪鍋氬紩鎿庡紑鍙戯紝 涔熺炕榪噄rrlicht鍜宱gre鏃犳暟閬嶃?鍗翠粠鏉ュ氨娌℃湁鍐欏畬榪囦竴涓畬鏁寸殑DEMO銆?/p>
榪炲姛鑳芥祴璇曠敤渚嬮兘娌℃湁鍐欒繃銆傜獊鐒惰寰椾箣鍓嶇殑涓浜涜璁′技涔庢湁浜涜劚紱諱簡瀹為檯銆傛病鏈夌湡姝d嬌鐢ㄨ繃錛屽張鎬庣煡濡備綍鏄ソ錛屽浣曟槸鍧忓憿錛?/p>
榪欎竴嬈℃槸鐪熺殑鐜﹊rrlicht浜嗭紝 涓棿涔熺籂緇撹繃鏄笉鏄疧GRE鏇撮傚悎銆?浣嗗湪鐩墠榪欎釜鏃墮棿鏈夐檺鐨勭┖闂翠笅錛屾垜鏇存効鎰忕帺irrlicht.灝忓閥錛岃交渚褲?褰撶劧錛屾剰鍛崇潃鏇村涓滆タ瑕佽嚜宸卞疄鐜般?涓嶈繃瀵逛簬涓涓唬鐮佹帶鏉ヨ錛屼篃鍙嶈屾洿鑷緱鍏朵箰銆?姝eソ鍙互鍦ㄧ煭璺殑鏃跺欙紝鍘誨弬鑰冧竴涓嬪叾瀹冨紩鎿庯紝鐢ㄦ潵鎵╁厖irrlicht.
鎴戣鍋氱殑涓嶆槸鎶奿rrlicht鏁村緱鐗汢錛岃屾槸鎯寵嚜宸卞紕寮勶紝鍔犱笂縐誨姩騫沖彴鐨勫礇璧鳳紝鎴戣寰梚rrlicht鏇村姞閫傚悎鍚с?鎹gameloft涔熸湁浣跨敤錛堜粎鏄嵁璇達級銆?/p>
鍙兘寰堝鍏勫紵浼氳鎴戣繖璁茬殑涓滆タ錛屽叾瀹炲氨鏄竴鍧ㄥ睅浜嗐?涓嶈繃錛屾垜瑙夊緱鍐嶅潖鐨勮瘎璁猴紝涔熻〃紺轟竴縐嶅叧娉ㄣ?鎵硅瘎濂借繃浜庢棤瑙嗗晩~~~~
----------------------------------------------------------涓嬮潰璇磋鎴戦亣涓婄殑綰犵粨------------------------------------------------
綰犵粨1:鎹㈣闇瑕佸満鏅妭鐐歸厤鍚?/strong>
鍦╥rrlicht涓紝騫舵病鏈夋彁渚涙櫘閫氬紩鎿庝腑鐨剆ubmesh鎴栬卋odypart榪欑涓滆タ錛岀敤浜庣洿鎺ユ敮鎸佹崲瑁呫?鍦╥rrlicht涓紝濡傛灉鎯寵鎹㈣錛屾渶鐩存帴鐨勬柟娉曞氨鏄緷璧栦簬鍦烘櫙緇撶偣
姣斿,鍦ㄦ垜鐨勭ず渚嬩腑錛屽彲浠ユ洿鎹㈠ご鍙戯紝甯藉瓙錛岃。鏈嶏紝鎶よ厱錛岄澊瀛愶紝闈㈠銆?閭e氨闇瑕?涓満鏅妭鐐癸紝1涓綔涓烘牴鑺傜偣錛岀敤浜庢帶鍒舵暣涓鑹茬殑涓栫晫鍧愭爣錛屽鉤縐伙紝緙╂斁錛屾棆杞瓑灞炴с傚彟澶?涓満鏅妭鐐瑰垯鍒嗗埆緇戞湁鍚勪釜閮ㄤ歡鐨勬ā鍨?/p>
璐翠竴涓嬫垜鐨勮鑹茬被鐨勪唬鐮侊紝琛屾暟涓嶅
class CCharactor
{
IrrlichtDevice* m_pDevice;
IAnimatedMeshSceneNode* m_pBodyParts[eCBPT_Num];
ISceneNode* m_pRoot;
public:
CCharactor(IrrlichtDevice* pDevice)
:m_pDevice(pDevice)
{
memset(m_pBodyParts,0,sizeof(m_pBodyParts));
m_pRoot = pDevice->getSceneManager()->addEmptySceneNode(NULL,12345);
}
void changeBodyPart(ECharactorBodyPartType ePartType,stringw& meshPath,stringw& metrialPath)
{
ISceneManager* smgr = m_pDevice->getSceneManager();
IAnimatedMeshSceneNode* pBpNode = m_pBodyParts[ePartType];
IAnimatedMesh* pMesh = smgr->getMesh(meshPath.c_str());
if(pMesh==NULL)
return;
if(pBpNode==NULL)
{
pBpNode = smgr->addAnimatedMeshSceneNode(pMesh,m_pRoot);
m_pBodyParts[ePartType] = pBpNode;
}
else
{
pBpNode->setMesh(pMesh);
}
ITexture* pTexture = m_pDevice->getVideoDriver()->getTexture(metrialPath.c_str());
if(pTexture)
pBpNode->setMaterialTexture(0,pTexture);
}
};
//鐒跺悗錛屾垜鐢ㄤ簡涓涓粨鏋勪綋鏉ユ瀯寤洪儴浠朵俊鎭?/p>
struct SBodyPartInfo
{
stringw Desc;
ECharactorBodyPartType Type;
stringw MeshPath;
stringw MeterialPath;
};
綰犵粨2錛氬叡浜楠?/strong>
棣栧厛錛宨rrlicht 1.8涓OGRE妯″瀷鐨勬牸寮忔敮鎸佸湪浠g爜涓紝鏈楂樺彧鐪嬪埌浜?.40鐗堟湰鐨勮В鏋愶紝鏇撮珮鐨勫氨浼氳鏃犺銆?澶╅緳鍏儴鐨勬ā鍨嬫湁鍑犱釜鏄?.30鐨勶紝鑰岀敤浜庢崲瑁呭拰涓昏鐨勶紝閮芥槸1.40鐨勩?鍙兘鏄В鏋愪笉鍏ㄧ殑鍘熷洜錛屽鑷?.40鐨勯楠煎姩鐢繪棤娉曟甯告挱鏀俱?榪欎釜闂鏁翠簡鍑犱釜灝忔椂錛屾病鏈夎В鍐籌紝鏄庡ぉ緇х畫
鍏舵錛屽涓ā鍨嬪叡浜楠煎彧鑳介氳繃鍦烘櫙鑺傜偣鐨剈seAnimationFrom鏉ュ畬鎴愶紝騫朵笖浼犲叆鐨勬槸涓涓狹esh鍙傛暟銆傝繖鐐硅浜鴻泲鐤鹼紝 澶╅緳鍏儴鐨勮鑹插姩浣滄槸鍒嗗紑浜嗙殑錛屼笉鍚岀殑鏀誨嚮鍔ㄤ綔鏄竴涓猻keleton鏂囦歡銆?鎯寵瀹炵幇鍏變韓錛屾湁鐐歸夯鐑︺?/p>
綰犵粨3錛氭ā鍨嬫枃浠舵牸寮?/strong>
irrlicht涓嶅儚OGRE閭f牱鏈変竴涓己澶т笖鎴愮啛鐨勬ā鍨嬫枃浠舵牸寮?铏界劧鎻愪緵浜?irr鏍煎紡錛屼絾浠呮槸鐢ㄤ簬irrEdit鐨勫満鏅俊鎭緭鍑恒傚厛鐪嬩竴寮犲浘
榪欏紶鍥炬槸irrlicht samples涓殑MeshViewer鐨勬彁紺烘鍐呭銆?涓婇潰鍒楀嚭浜嗗彲浠ユ敮鎸佺殑妯″瀷鏂囦歡綾誨瀷銆?澶у鍙互鐪嬬湅錛屽張鏈夊灝戞ā鍨嬫牸寮忔槸鍙互鐩存帴鎷挎潵鏀懼埌欏圭洰涓婄敤鐨勫憿錛?mdl鍜宮s3d鍙互鑰冭檻錛宒ae鐨勮瘽錛屾垜鍦ㄥ紑婧愭父鎴? A.D. 涓鍒頒嬌鐢ㄨ繃銆?鍏跺畠鐨勮瘽錛屽氨瀹屽叏涓嶇啛鎮変簡銆?OGRE鐨?.mesh鏀寔涔熶笉瀹屽叏銆?闅鵑亾鐪熻鑷繁鏁翠竴涓?
鎴戣兘鎯沖埌鐨勶紝灝辨槸閫変竴涓彃浠跺畬鏁村拰妯″瀷鍜屽姩鐢繪牸寮忛兘姣旇緝濂界殑浣滀負涓庣編鏈伐鍏蜂氦浜掔殑鏍煎紡銆?鑷繁鍐嶅啓涓涓伐鍏鳳紝杞崲鎴愯嚜宸辯殑鏍煎紡銆?/p>
綰犵粨4錛氱‖浠惰挋鐨?/strong>
鎴戜互涓哄儚NIKO閭f牱鐨勬妧鏈媯錛屾庝箞浼氭斁鎺夎繖涓涓壒鎬с?寰堥珮鍏村湴鍦ㄥ満鏅妭鐐逛笂鍙戠幇浜嗙‖浠惰挋鐨殑鍑芥暟鎺ュ彛銆備絾涓鐪嬫敞閲婏紝鎶婃垜鍜界潃浜嗐?/p>
//! (This feature is not implemented in irrlicht yet)
virtual bool setHardwareSkinning(bool on);
鍏跺畠鍦版柟錛岃繕娌℃湁鍘繪暣錛屽氨鍏堜笉鍙戣〃璦璁轟簡銆?緇х畫鐫榪欎釜寰堝偦B,寰堝ぉ鐪熺殑鎹i紦涔嬭礬銆?
涓婁釜鍥撅紝綰康涓涓嬫垜鐨刬rrlicht浜х墿銆?/p>
甯冭。
鎹簡韜洈鐢?/p>
鎹簡甯藉瓙鍜岄澊瀛?/p>
PS:澶村彂娌℃湁綰圭悊錛屾墍浠ユ槸鐧界殑銆?/p>