Scene_ScriptBinding.h 125 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. ConsoleFunction( getGlobalSceneCount, S32, 1, 1, "() - Gets the system-wide scene count.\n"
  23. "@return The system-wide scene count." )
  24. {
  25. return Scene::getGlobalSceneCount();
  26. }
  27. //-----------------------------------------------------------------------------
  28. ConsoleMethod(Scene, setGravity, void, 3, 4, "(forceX / forceY) The gravity force to apply to all objects in the scene.\n"
  29. "@param forceX/forceY The direction and magnitude of the force in each direction. Formatted as either (\"forceX forceY\") or (forceX, forceY)\n"
  30. "@return No return value.\n")
  31. {
  32. // The force.
  33. Vector2 force;
  34. // Grab the element count.
  35. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  36. // ("forceX forceY")
  37. if (elementCount == 1)
  38. {
  39. force = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  40. }
  41. else if (elementCount == 2)
  42. {
  43. force = Utility::mGetStringElementVector(argv[2]);
  44. }
  45. // Invalid
  46. else
  47. {
  48. Con::warnf("SceneObject::setGravity() - Invalid number of parameters!");
  49. return;
  50. }
  51. // Set gravity.
  52. object->setGravity(force);
  53. }
  54. //-----------------------------------------------------------------------------
  55. ConsoleMethod(Scene, getGravity, const char*, 2, 2, "() Gets the gravity force applied to all objects in the scene.\n"
  56. "@return The gravity force applied to all objects in the scene." )
  57. {
  58. return Vector2(object->getGravity()).scriptThis();
  59. }
  60. //-----------------------------------------------------------------------------
  61. ConsoleMethod(Scene, setVelocityIterations, void, 3, 3, "(int iterations) Sets the number of velocity iterations the physics solver uses.\n"
  62. "@return No return value.")
  63. {
  64. object->setVelocityIterations( dAtoi(argv[2]) );
  65. }
  66. //-----------------------------------------------------------------------------
  67. ConsoleMethod(Scene, getVelocityIterations, S32, 2, 2, "() Gets the number of velocity iterations the physics solver uses.\n"
  68. "(@return The number of velocity iterations the physics solver uses." )
  69. {
  70. return object->getVelocityIterations();
  71. }
  72. //-----------------------------------------------------------------------------
  73. ConsoleMethod(Scene, setPositionIterations, void, 3, 3, "(int iterations) Sets the number of position iterations the physics solver uses.\n"
  74. "@return No return value.")
  75. {
  76. object->setPositionIterations( dAtoi(argv[2]) );
  77. }
  78. //-----------------------------------------------------------------------------
  79. ConsoleMethod(Scene, getPositionIterations, S32, 2, 2, "() Gets the number of position iterations the physics solver uses.\n"
  80. "(@return The number of position iterations the physics solver uses." )
  81. {
  82. return object->getPositionIterations();
  83. }
  84. //-----------------------------------------------------------------------------
  85. ConsoleMethod(Scene, add, void, 3, 3, "(sceneObject) Add the SceneObject to the scene.\n"
  86. "@param sceneObject The SceneObject to add to the scene.\n"
  87. "@return No return value.")
  88. {
  89. // Find the specified object.
  90. SceneObject* pSceneObject = dynamic_cast<SceneObject*>(Sim::findObject(argv[2]));
  91. // Did we find the object?
  92. if ( !pSceneObject )
  93. {
  94. // No, so warn.
  95. Con::warnf("Scene::addToScene() - Could not find the specified object '%s'.", argv[2]);
  96. return;
  97. }
  98. // Add to Scene.
  99. object->addToScene( pSceneObject );
  100. }
  101. //-----------------------------------------------------------------------------
  102. ConsoleMethod(Scene, remove, void, 3, 3, "(sceneObject) Remove the SceneObject from the scene.\n"
  103. "@param sceneObject The SceneObject to remove from the scene.\n"
  104. "@return No return value.")
  105. {
  106. // Find the specified object.
  107. SceneObject* pSceneObject = dynamic_cast<SceneObject*>(Sim::findObject(argv[2]));
  108. // Did we find the object?
  109. if ( !pSceneObject )
  110. {
  111. // No, so warn.
  112. Con::warnf("Scene::removeFromScene() - Could not find the specified object '%s'.", argv[2]);
  113. return;
  114. }
  115. // Remove from Scene.
  116. object->removeFromScene( pSceneObject );
  117. }
  118. //-----------------------------------------------------------------------------
  119. ConsoleMethod(Scene, clear, void, 2, 3, "([deleteObjects]) Clear the scene of all scene objects.\n"
  120. "@param deleteObjects A boolean flag that sets whether to delete the objects as well as remove them from the scene (default is true).\n"
  121. "@return No return value.")
  122. {
  123. // Calculate 'Delete Objects' flag.
  124. bool deleteObjects;
  125. if ( argc >= 3 )
  126. deleteObjects = dAtob( argv[2] );
  127. else
  128. deleteObjects = true;
  129. // Clear Scene.
  130. object->clearScene( deleteObjects );
  131. }
  132. //-----------------------------------------------------------------------------
  133. ConsoleMethod(Scene, getCount, S32, 2, 2, "() Gets the count of scene objects in the scnee.\n"
  134. "@return Returns the number of scene objects in current scene as an integer.")
  135. {
  136. // Get Scene Object-Count.
  137. return object->getSceneObjectCount();
  138. }
  139. //-----------------------------------------------------------------------------
  140. ConsoleMethod(Scene, getObject, S32, 3, 3, "(sceneObjectIndex) Gets the scene object at the selected index.\n"
  141. "@param sceneObjectIndex The index of the desired object\n"
  142. "@return The scene object at the specified index.")
  143. {
  144. // Fetch Object Index.
  145. const U32 objectIndex = dAtoi(argv[2]);
  146. // Fetch scene object count.
  147. const U32 sceneObjectCount = object->getSceneObjectCount();
  148. // Sanity!
  149. if ( objectIndex >= sceneObjectCount )
  150. {
  151. // Error so warn.
  152. Con::warnf("Scene::getObject() - Cannot retrieve specified object index (%d) as there are only (%d) object(s) in the scene!", objectIndex, sceneObjectCount );
  153. // Return no object.
  154. return 0;
  155. }
  156. // Fetch Scene Object.
  157. const SceneObject* pSceneObject = object->getSceneObject( objectIndex );
  158. // Check Object.
  159. if ( pSceneObject != NULL )
  160. {
  161. // No error so return object id.
  162. return pSceneObject->getId();
  163. }
  164. else
  165. {
  166. // Error so warn.
  167. Con::warnf("Scene::getObject() - Cannot retrieve specified object index (%d)!", objectIndex);
  168. // Return no object.
  169. return 0;
  170. }
  171. }
  172. //-----------------------------------------------------------------------------
  173. ConsoleMethod(Scene, getSceneObjectList, const char*, 2, 2, "() Gets the Scene Object-List.\n"
  174. "@return Returns a string with a list of object IDs")
  175. {
  176. // Scene Object-List.
  177. Vector<SceneObject*> objList;
  178. // Finish here if there are no scene objects.
  179. U32 objCount = object->getSceneObjects( objList );
  180. if( objCount == 0 )
  181. return NULL;
  182. // Our return buffer will be 6 times the size of our object list (4 for Id (+1 for future size?) + 1 for space).
  183. U32 maxBufferSize = objCount * 12;
  184. // Create Returnable Buffer.
  185. char *pBuffer = Con::getReturnBuffer( maxBufferSize );
  186. // Set Buffer Counter.
  187. U32 bufferCount = 0;
  188. // Iterate through the list and generate an id string list to return
  189. for ( S32 n = 0; n < objList.size(); n++ )
  190. {
  191. // Output Object ID.
  192. bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", objList[n]->getId() );
  193. // Finish early if we run out of buffer space.
  194. if ( bufferCount >= maxBufferSize )
  195. {
  196. // Warn.
  197. Con::warnf("Scene::getSceneObjectList() - Not enough space to return all %d objects!", objList.size());
  198. break;
  199. }
  200. }
  201. // Return buffer.
  202. return pBuffer;
  203. }
  204. //-----------------------------------------------------------------------------
  205. ConsoleMethod(Scene, getAssetPreloadCount, S32, 2, 2, "() Gets the number of assets set to preload for this scene.\n"
  206. "@return The number of assets set to preload for this scene.")
  207. {
  208. return object->getAssetPreloadCount();
  209. }
  210. //-----------------------------------------------------------------------------
  211. ConsoleMethod(Scene, getAssetPreload, const char*, 3, 3, "(index) Gets the asset to be preloaded at the specified index.\n"
  212. "@param index The index of the preloaded asset.\n"
  213. "@return The asset to be preloaded at the specified index.")
  214. {
  215. // Fetch preload index.
  216. const S32 index = dAtoi(argv[2]);
  217. // Fetch the asset pointer.
  218. const AssetPtr<AssetBase>* pAssetPtr = object->getAssetPreload( index );
  219. return pAssetPtr == NULL ? NULL : pAssetPtr->getAssetId();
  220. }
  221. //-----------------------------------------------------------------------------
  222. ConsoleMethod(Scene, addAssetPreload, void, 3, 3, "(assetId) Adds the asset Id so that it is preloaded when the scene is loaded.\n"
  223. "The asset loaded immediately by this operation. Duplicate assets are ignored.\n"
  224. "@param assetId The asset Id to be added.\n"
  225. "@return No return value.")
  226. {
  227. // Fetch asset Id.
  228. const char* pAssetId = argv[2];
  229. // Add asset preload.
  230. object->addAssetPreload( pAssetId );
  231. }
  232. //-----------------------------------------------------------------------------
  233. ConsoleMethod(Scene, removeAssetPreload, void, 3, 3, "(assetId) Removes the asset Id from being preloaded when the scene is loaded.\n"
  234. "The asset may be unloaded immediately by this operation if it has no other references.\n"
  235. "@param assetId The asset Id to be removed.\n"
  236. "@return No return value.")
  237. {
  238. // Fetch asset Id.
  239. const char* pAssetId = argv[2];
  240. // Remove asset preload.
  241. object->removeAssetPreload( pAssetId );
  242. }
  243. //-----------------------------------------------------------------------------
  244. ConsoleMethod(Scene, clearAssetPreloads, void, 2, 2, "() Clears all assets added as a preload.\n"
  245. "@return No return value.")
  246. {
  247. // Clear asset preloads.
  248. object->clearAssetPreloads();
  249. }
  250. //-----------------------------------------------------------------------------
  251. ConsoleMethod(Scene, mergeScene, void, 3, 3, "(scene) Merges the specified scene into this scene by cloning the scenes contents.")
  252. {
  253. // Find the specified scene.
  254. Scene* pScene = Sim::findObject<Scene>( argv[2] );
  255. // Did we find the scene?
  256. if ( pScene == NULL )
  257. {
  258. // No, so warn.
  259. Con::warnf( "Scene::mergeScene() - Could not find the specified scene '%s'.", argv[2] );
  260. return;
  261. }
  262. object->mergeScene( pScene );
  263. }
  264. //-----------------------------------------------------------------------------
  265. ConsoleMethod(Scene, getControllers, const char*, 2, 2, "() Gets the Scene Controllers.\n"
  266. "@return Gets the scene controllers.")
  267. {
  268. // Fetch the scene controllers.
  269. SimSet* pControllerSet = object->getControllers();
  270. return ( pControllerSet == NULL ) ? StringTable->EmptyString : pControllerSet->getIdString();
  271. }
  272. //-----------------------------------------------------------------------------
  273. ConsoleMethod(Scene, getSceneTime, F32, 2, 2, "() Gets the Scene Time.\n"
  274. "@return Returns the time as a floating point number\n")
  275. {
  276. // Get Scene Time.
  277. return object->getSceneTime();
  278. }
  279. //-----------------------------------------------------------------------------
  280. ConsoleMethod(Scene, setScenePause, void, 3, 3, "(status) Sets scene pause status.\n"
  281. "@return No return value.")
  282. {
  283. // Set Scene Pause.
  284. object->setScenePause( dAtob(argv[2]) );
  285. }
  286. //-----------------------------------------------------------------------------
  287. ConsoleMethod(Scene, getScenePause, bool, 2, 2, "() Gets scene pause status.\n"
  288. "@return Returns a boolean value. True if pause status, false otherwise.")
  289. {
  290. // Get Scene Pause.
  291. return object->getScenePause();
  292. }
  293. //-----------------------------------------------------------------------------
  294. ConsoleMethod(Scene, getJointCount, S32, 2, 2, "() Gets the joint count.\n"
  295. "@return Returns no value")
  296. {
  297. return object->getJointCount();
  298. }
  299. //-----------------------------------------------------------------------------
  300. ConsoleMethod(Scene, isJoint, bool, 3, 3, "(int jointId) Gets whether the joint Id is valid or not.\n"
  301. "@param jointId The Id of the joint.\n"
  302. "@return whether the joint Id is valid or not." )
  303. {
  304. // Fetch joint Id.
  305. const S32 jointId = dAtoi( argv[2] );
  306. return object->findJoint( jointId ) != NULL;
  307. }
  308. //-----------------------------------------------------------------------------
  309. ConsoleMethod(Scene, getJointType, const char*, 3, 3, "(int jointId) Gets the joint type of the specified joint Id.\n"
  310. "@param jointId The Id of the joint.\n"
  311. "@return The type of joint of the specified joint Id." )
  312. {
  313. // Fetch joint Id.
  314. const S32 jointId = dAtoi( argv[2] );
  315. // Fetch joint type.
  316. const b2JointType jointType = object->getJointType( jointId );
  317. // Ignore if invalid joint.
  318. if ( jointType == e_unknownJoint )
  319. return StringTable->EmptyString;
  320. return Scene::getJointTypeDescription( jointType );
  321. }
  322. //-----------------------------------------------------------------------------
  323. ConsoleMethod(Scene, deleteJoint, bool, 3, 3, "(int jointId) Deletes the specified joint Id.\n"
  324. "@param jointId The Id of the joint.\n"
  325. "@return Whether the joint was successfully deleted or not." )
  326. {
  327. // Fetch joint Id.
  328. const S32 jointId = dAtoi( argv[2] );
  329. return object->deleteJoint( jointId );
  330. }
  331. //-----------------------------------------------------------------------------
  332. ConsoleMethod(Scene, createDistanceJoint, S32, 4, 12, "(sceneObjectA, sceneObjectB, [localAnchorA X/Y], [localAnchorB X/Y], [distance], [frequency], [dampingRatio], [collideConnected]) Creates a distance joint.\n"
  333. "@param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
  334. "@param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
  335. "@param localAnchorA The local point of the first scene object where the joint connects.\n"
  336. "@param localAnchorB The local point of the second scene object where the joint connects.\n"
  337. "@param distance The distance the joint should maintain between scene objects. The default is the distance currently between the scene objects.\n"
  338. "@param frequency The mass-spring-damper frequency in Hertz. A value of 0 disables softness (default).\n"
  339. "@param dampingRatio The damping ratio. 0 = no damping (default), 1 = critical damping.\n"
  340. "@param collideConnected Whether the scene objects can collide with each other while connected with this joint.\n"
  341. "@return The joint Id (-1 if error).")
  342. {
  343. // Fetch scene object references.
  344. const char* sceneObjectA = argv[2];
  345. const char* sceneObjectB = argv[3];
  346. SceneObject* pSceneObjectA = NULL;
  347. SceneObject* pSceneObjectB = NULL;
  348. // Fetch scene object.
  349. if ( *sceneObjectA != 0 )
  350. {
  351. pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
  352. if ( !pSceneObjectA )
  353. Con::warnf("Scene::createDistanceJoint() - Could not find scene object %d.", sceneObjectA);
  354. }
  355. // Fetch scene object.
  356. if (*sceneObjectB != 0 )
  357. {
  358. pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
  359. if ( !pSceneObjectB )
  360. Con::warnf("Scene::createDistanceJoint() - Could not find scene object %d.", sceneObjectB);
  361. }
  362. if ( argc == 4 )
  363. {
  364. return object->createDistanceJoint( pSceneObjectA, pSceneObjectB );
  365. }
  366. // Local anchor A.
  367. const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
  368. b2Vec2 localAnchorA;
  369. S32 nextArg = 5;
  370. if ( anchorAElementCount == 1 && argc > 5 )
  371. {
  372. localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
  373. nextArg = 6;
  374. }
  375. else if ( anchorAElementCount == 2 )
  376. {
  377. localAnchorA = Utility::mGetStringElementVector(argv[4]);
  378. }
  379. // Invalid
  380. else
  381. {
  382. Con::warnf("Scene::createDistanceJoint() - Invalid number of parameters!");
  383. return -1;
  384. }
  385. if ( argc <= nextArg )
  386. {
  387. return object->createDistanceJoint( pSceneObjectA, pSceneObjectB, localAnchorA );
  388. }
  389. // Local anchor B.
  390. const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
  391. b2Vec2 localAnchorB;
  392. if ( anchorBElementCount == 1 && argc > (nextArg+1) )
  393. {
  394. localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
  395. nextArg += 2;
  396. }
  397. else if ( anchorBElementCount == 2 )
  398. {
  399. localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
  400. }
  401. // Invalid
  402. else
  403. {
  404. Con::warnf("Scene::createDistanceJoint() - Invalid number of parameters!");
  405. return -1;
  406. }
  407. if ( argc <= nextArg )
  408. {
  409. return object->createDistanceJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB );
  410. }
  411. // Fetch length.
  412. const F32 length = dAtof(argv[nextArg++]);
  413. if ( argc <= nextArg )
  414. {
  415. return object->createDistanceJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, length );
  416. }
  417. // Fetch frequency (Hertz).
  418. const F32 frequency = dAtof(argv[nextArg++]);
  419. if ( argc <= nextArg )
  420. {
  421. return object->createDistanceJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, length, frequency );
  422. }
  423. // Fetch damping ratio.
  424. const F32 dampingRatio = dAtof(argv[nextArg++]);
  425. if ( argc <= nextArg )
  426. {
  427. return object->createDistanceJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, length, frequency, dampingRatio );
  428. }
  429. // Fetch collide connected.
  430. const bool collideConnected = dAtob(argv[nextArg++]);
  431. return object->createDistanceJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, length, frequency, dampingRatio, collideConnected );
  432. }
  433. //-----------------------------------------------------------------------------
  434. ConsoleMethod(Scene, setDistanceJointLength, void, 4, 4, "(jointId, length) Sets the distance the joint should maintain between scene objects.\n"
  435. "@param jointId The Id of the joint to use.\n"
  436. "@param length The length the joint should maintain between scene objects.\n"
  437. "@return Returns no value." )
  438. {
  439. // Fetch joint Id.
  440. const S32 jointId = dAtoi(argv[2]);
  441. // Fetch args.
  442. const F32 length = dAtof(argv[3]);
  443. // Access joint.
  444. object->setDistanceJointLength( jointId, length );
  445. }
  446. //-----------------------------------------------------------------------------
  447. ConsoleMethod(Scene, getDistanceJointLength, F32, 3, 3, "(jointId) Gets the distance the joint should maintain between scene objects.\n"
  448. "@param jointId The Id of the joint to use.\n"
  449. "@return Returns the distance the joint should maintain between scene objects (-1 indicates error)." )
  450. {
  451. // Fetch joint Id.
  452. const S32 jointId = dAtoi(argv[2]);
  453. // Access joint.
  454. return object->getDistanceJointLength( jointId );
  455. }
  456. //-----------------------------------------------------------------------------
  457. ConsoleMethod(Scene, setDistanceJointFrequency, void, 4, 4, "(jointId, frequency) Sets the mass-spring-damper frequency in Hertz.\n"
  458. "@param jointId The Id of the joint to use.\n"
  459. "@param frequency The mass-spring-damper frequency in Hertz. A value of 0 disables softness.\n"
  460. "@return Returns no value." )
  461. {
  462. // Fetch joint Id.
  463. const S32 jointId = dAtoi(argv[2]);
  464. // Fetch args.
  465. const F32 frequency = dAtof(argv[3]);
  466. // Access joint.
  467. object->setDistanceJointFrequency( jointId, frequency );
  468. }
  469. //-----------------------------------------------------------------------------
  470. ConsoleMethod(Scene, getDistanceJointFrequency, F32, 3, 3, "(jointId) Gets the mass-spring-damper frequency in Hertz.\n"
  471. "@param jointId The Id of the joint to use.\n"
  472. "@return Returns the mass-spring-damper frequency in Hertz (-1 indicates error)." )
  473. {
  474. // Fetch joint Id.
  475. const S32 jointId = dAtoi(argv[2]);
  476. // Access joint.
  477. return object->getDistanceJointFrequency( jointId );
  478. }
  479. //-----------------------------------------------------------------------------
  480. ConsoleMethod(Scene, setDistanceJointDampingRatio, void, 4, 4, "(jointId, dampingRatio) Sets the damping ratio.\n"
  481. "@param jointId The Id of the joint to use.\n"
  482. "@param dampingRatio The damping ratio. 0 = no damping, 1 = critical damping.\n"
  483. "@return Returns no value." )
  484. {
  485. // Fetch joint Id.
  486. const S32 jointId = dAtoi(argv[2]);
  487. // Fetch args.
  488. const F32 dampingRatio = dAtof(argv[3]);
  489. // Access joint.
  490. object->setDistanceJointDampingRatio( jointId, dampingRatio );
  491. }
  492. //-----------------------------------------------------------------------------
  493. ConsoleMethod(Scene, getDistanceJointDampingRatio, F32, 3, 3, "(jointId) Gets the damping ratio.\n"
  494. "@param jointId The Id of the joint to use.\n"
  495. "@return Returns the damping ratio (-1 indicates error)." )
  496. {
  497. // Fetch joint Id.
  498. const S32 jointId = dAtoi(argv[2]);
  499. // Access joint.
  500. return object->getDistanceJointDampingRatio( jointId );
  501. }
  502. //-----------------------------------------------------------------------------
  503. ConsoleMethod(Scene, createRopeJoint, S32, 4, 10, "(sceneObjectA, sceneObjectB, [localAnchorA X/Y], [localAnchorB X/Y], [maxLength], [collideConnected]) Creates a rope joint.\n"
  504. "@param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
  505. "@param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
  506. "@param localAnchorA The local point of the first scene object where the joint connects.\n"
  507. "@param localAnchorB The local point of the second scene object where the joint connects.\n"
  508. "@param maxLength The maximum rigid length of the rope.\n"
  509. "@param collideConnected Whether the scene objects can collide with each other while connected with this joint.\n"
  510. "@return The joint Id (-1 if error).")
  511. {
  512. // Fetch scene object references.
  513. const char* sceneObjectA = argv[2];
  514. const char* sceneObjectB = argv[3];
  515. SceneObject* pSceneObjectA = NULL;
  516. SceneObject* pSceneObjectB = NULL;
  517. // Fetch scene object.
  518. if ( *sceneObjectA != 0 )
  519. {
  520. pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
  521. if ( !pSceneObjectA )
  522. Con::warnf("Scene::createRopeJoint() - Could not find scene object %d.", sceneObjectA);
  523. }
  524. // Fetch scene object.
  525. if (*sceneObjectB != 0 )
  526. {
  527. pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
  528. if ( !pSceneObjectB )
  529. Con::warnf("Scene::createRopeJoint() - Could not find scene object %d.", sceneObjectB);
  530. }
  531. if ( argc == 4 )
  532. {
  533. return object->createRopeJoint( pSceneObjectA, pSceneObjectB );
  534. }
  535. // Local anchor A.
  536. const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
  537. b2Vec2 localAnchorA;
  538. S32 nextArg = 5;
  539. if ( anchorAElementCount == 1 && argc > 5 )
  540. {
  541. localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
  542. nextArg = 6;
  543. }
  544. else if ( anchorAElementCount == 2 )
  545. {
  546. localAnchorA = Utility::mGetStringElementVector(argv[4]);
  547. }
  548. // Invalid
  549. else
  550. {
  551. Con::warnf("Scene::createRopeJoint() - Invalid number of parameters!");
  552. return -1;
  553. }
  554. if ( argc <= nextArg )
  555. {
  556. return object->createRopeJoint( pSceneObjectA, pSceneObjectB, localAnchorA );
  557. }
  558. // Local anchor B.
  559. const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
  560. b2Vec2 localAnchorB;
  561. if ( anchorBElementCount == 1 && argc > (nextArg+1) )
  562. {
  563. localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
  564. nextArg += 2;
  565. }
  566. else if ( anchorBElementCount == 2 )
  567. {
  568. localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
  569. }
  570. // Invalid
  571. else
  572. {
  573. Con::warnf("Scene::createRopeJoint() - Invalid number of parameters!");
  574. return -1;
  575. }
  576. if ( argc <= nextArg )
  577. {
  578. return object->createRopeJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB );
  579. }
  580. // Fetch maximum length.
  581. const F32 maxLength = dAtof(argv[nextArg++]);
  582. if ( argc <= nextArg )
  583. {
  584. return object->createRopeJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, maxLength );
  585. }
  586. // Fetch collide connected.
  587. const bool collideConnected = dAtob(argv[nextArg++]);
  588. return object->createRopeJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, maxLength, collideConnected );
  589. }
  590. //-----------------------------------------------------------------------------
  591. ConsoleMethod(Scene, setRopeJointMaxLength, void, 4, 4, "(jointId, maxLength) Sets the maximum rigid length of the rope.\n"
  592. "@param jointId The Id of the joint to use.\n"
  593. "@param maxLength The maximum rigid length of the rope.\n"
  594. "@return Returns no value." )
  595. {
  596. // Fetch joint Id.
  597. const S32 jointId = dAtoi(argv[2]);
  598. // Fetch args.
  599. const F32 maxLength = dAtof(argv[3]);
  600. // Access joint.
  601. object->setRopeJointMaxLength( jointId, maxLength );
  602. }
  603. //-----------------------------------------------------------------------------
  604. ConsoleMethod(Scene, getRopeJointMaxLength, F32, 3, 3, "(jointId) Gets the maximum rigid length of the rope.\n"
  605. "@param jointId The Id of the joint to use.\n"
  606. "@return Returns the maximum rigid length of the rope (-1 indicates error)." )
  607. {
  608. // Fetch joint Id.
  609. const S32 jointId = dAtoi(argv[2]);
  610. // Access joint.
  611. return object->getRopeJointMaxLength( jointId );
  612. }
  613. //-----------------------------------------------------------------------------
  614. ConsoleMethod(Scene, createRevoluteJoint, S32, 4, 9, "(sceneObjectA, sceneObjectB, [localAnchorA X/Y], [localAnchorB X/Y], [collideConnected]) Creates a revolute joint.\n"
  615. "@param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
  616. "@param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
  617. "@param localAnchorA The local point of the first scene object where the joint connects.\n"
  618. "@param localAnchorB The local point of the second scene object where the joint connects.\n"
  619. "@param collideConnected Whether the scene objects can collide with each other while connected with this joint.\n"
  620. "@return The joint Id (-1 if error).")
  621. {
  622. // Fetch scene object references.
  623. const char* sceneObjectA = argv[2];
  624. const char* sceneObjectB = argv[3];
  625. SceneObject* pSceneObjectA = NULL;
  626. SceneObject* pSceneObjectB = NULL;
  627. // Fetch scene object.
  628. if ( *sceneObjectA != 0 )
  629. {
  630. pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
  631. if ( !pSceneObjectA )
  632. Con::warnf("Scene::createRevoluteJoint() - Could not find scene object %d.", sceneObjectA);
  633. }
  634. // Fetch scene object.
  635. if ( *sceneObjectB != 0 )
  636. {
  637. pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
  638. if ( !pSceneObjectB )
  639. Con::warnf("Scene::createRevoluteJoint() - Could not find scene object %d.", sceneObjectB);
  640. }
  641. if ( argc == 4 )
  642. {
  643. return object->createRevoluteJoint( pSceneObjectA, pSceneObjectB );
  644. }
  645. // Local anchor A.
  646. const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
  647. b2Vec2 localAnchorA;
  648. S32 nextArg = 5;
  649. if ( anchorAElementCount == 1 && argc > 5 )
  650. {
  651. localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
  652. nextArg = 6;
  653. }
  654. else if ( anchorAElementCount == 2 )
  655. {
  656. localAnchorA = Utility::mGetStringElementVector(argv[4]);
  657. }
  658. // Invalid
  659. else
  660. {
  661. Con::warnf("Scene::createRevoluteJoint() - Invalid number of parameters!");
  662. return -1;
  663. }
  664. if ( argc <= nextArg )
  665. {
  666. return object->createRevoluteJoint( pSceneObjectA, pSceneObjectB, localAnchorA );
  667. }
  668. // Local anchor B.
  669. const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
  670. b2Vec2 localAnchorB;
  671. if ( anchorBElementCount == 1 && argc > (nextArg+1) )
  672. {
  673. localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
  674. nextArg += 2;
  675. }
  676. else if ( anchorBElementCount == 2 )
  677. {
  678. localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
  679. }
  680. // Invalid
  681. else
  682. {
  683. Con::warnf("Scene::createRevoluteJoint() - Invalid number of parameters!");
  684. return -1;
  685. }
  686. if ( argc <= nextArg )
  687. {
  688. return object->createRevoluteJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB );
  689. }
  690. // Fetch collide connected.
  691. const bool collideConnected = dAtob(argv[nextArg++]);
  692. return object->createRevoluteJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, collideConnected );
  693. }
  694. //-----------------------------------------------------------------------------
  695. ConsoleMethod(Scene, setRevoluteJointLimit, void, 4, 6, "(jointId, enableLimit, [lowerAngle], [upperAngle]) Sets whether the joint has angular limits or not and the limits themselves.\n"
  696. "@param jointId The Id of the joint to use.\n"
  697. "@param enableLimit Whether the joint has angular limits or not.\n"
  698. "@param lowerAngle The lower angle of the angular limit.\n"
  699. "@param upperAngle The upper angle of the angular limit.\n"
  700. "@return Returns no value." )
  701. {
  702. // Fetch joint Id.
  703. const S32 jointId = dAtoi(argv[2]);
  704. // Fetch args.
  705. const bool enableLimit = dAtob(argv[3]);
  706. const F32 lowerAngle = argc > 4 ? mDegToRad( dAtof(argv[4]) ) : 0.0f;
  707. const F32 upperAngle = argc > 5 ? mDegToRad( dAtof(argv[5]) ) : lowerAngle;
  708. // Access joint.
  709. object->setRevoluteJointLimit( jointId, enableLimit, lowerAngle, upperAngle );
  710. }
  711. //-----------------------------------------------------------------------------
  712. ConsoleMethod(Scene, getRevoluteJointLimit, const char*, 3, 3, "(jointId) Gets whether the joint has angular limits or not and the limits themselves.\n"
  713. "@param jointId The Id of the joint to use.\n"
  714. "@return Returns whether the joint has angular limits or not and the limits themselves (empty string indicates error)." )
  715. {
  716. // Fetch joint Id.
  717. const S32 jointId = dAtoi(argv[2]);
  718. // Args.
  719. bool enableLimit;
  720. F32 lowerAngle;
  721. F32 upperAngle;
  722. // Access joint.
  723. if ( !object->getRevoluteJointLimit( jointId, enableLimit, lowerAngle, upperAngle ) )
  724. {
  725. return NULL;
  726. }
  727. // Format output.
  728. char* pBuffer = Con::getReturnBuffer(64);
  729. dSprintf( pBuffer, 64, "%d %g %g", enableLimit, mRadToDeg(lowerAngle), mRadToDeg(upperAngle) );
  730. return pBuffer;
  731. }
  732. //-----------------------------------------------------------------------------
  733. ConsoleMethod(Scene, setRevoluteJointMotor, void, 4, 6, "(jointId, enableMotor, [motorSpeed], [maxMotorTorque]) Sets whether the joint has a motor or not and the motor settings.\n"
  734. "@param jointId The Id of the joint to use.\n"
  735. "@param enableMotor Whether the joint has a motor or not.\n"
  736. "@param motorSpeed The motor speed (degrees per/sec).\n"
  737. "@param maxMotorTorque The maximum motor torque used to achieve the specified motor speed (N-m).\n"
  738. "@return Returns no value." )
  739. {
  740. // Fetch joint Id.
  741. const S32 jointId = dAtoi(argv[2]);
  742. // Fetch args.
  743. const bool enableMotor = dAtob(argv[3]);
  744. const F32 motorSpeed = argc > 4 ? mDegToRad( dAtof(argv[4]) ) : 0.0f;
  745. const F32 maxMotorTorque = argc > 5 ? dAtof(argv[5]) : 0.0f;
  746. // Access joint.
  747. object->setRevoluteJointMotor( jointId, enableMotor, motorSpeed, maxMotorTorque );
  748. }
  749. //-----------------------------------------------------------------------------
  750. ConsoleMethod(Scene, getRevoluteJointMotor, const char*, 3, 3, "(jointId) Gets whether the joint has a motor or not and the motor settings.\n"
  751. "@param jointId The Id of the joint to use.\n"
  752. "@return Returns whether the joint has a motor or not and the motor settings (empty string indicates error)." )
  753. {
  754. // Fetch joint Id.
  755. const S32 jointId = dAtoi(argv[2]);
  756. // Args.
  757. bool enableMotor;
  758. F32 motorSpeed;
  759. F32 maxMotorTorque;
  760. // Access joint.
  761. if ( !object->getRevoluteJointMotor( jointId, enableMotor, motorSpeed, maxMotorTorque ) )
  762. {
  763. return NULL;
  764. }
  765. // Format output.
  766. char* pBuffer = Con::getReturnBuffer(64);
  767. dSprintf( pBuffer, 64, "%d %g %g", enableMotor, mRadToDeg(motorSpeed), maxMotorTorque );
  768. return pBuffer;
  769. }
  770. //-----------------------------------------------------------------------------
  771. ConsoleMethod(Scene, createWeldJoint, S32, 4, 11, "(sceneObjectA, sceneObjectB, [localAnchorA X/Y], [localAnchorB X/Y], [frequency], [dampingRatio], [collideConnected]) Creates a weld joint.\n"
  772. "@param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
  773. "@param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
  774. "@param localAnchorA The local point of the first scene object where the joint connects.\n"
  775. "@param localAnchorB The local point of the second scene object where the joint connects.\n"
  776. "@param frequency The mass-spring-damper frequency in Hertz. A value of 0 disables softness (default).\n"
  777. "@param dampingRatio The damping ratio. 0 = no damping (default), 1 = critical damping.\n"
  778. "@param collideConnected Whether the scene objects can collide with each other while connected with this joint.\n"
  779. "@return The joint Id (-1 if error).")
  780. {
  781. // Fetch scene object references.
  782. const char* sceneObjectA = argv[2];
  783. const char* sceneObjectB = argv[3];
  784. SceneObject* pSceneObjectA = NULL;
  785. SceneObject* pSceneObjectB = NULL;
  786. // Fetch scene object.
  787. if ( *sceneObjectA != 0 )
  788. {
  789. pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
  790. if ( !pSceneObjectA )
  791. Con::warnf("Scene::createWeldJoint() - Could not find scene object %d.", sceneObjectA);
  792. }
  793. // Fetch scene object.
  794. if ( *sceneObjectB != 0 )
  795. {
  796. pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
  797. if ( !pSceneObjectB )
  798. Con::warnf("Scene::createWeldJoint() - Could not find scene object %d.", sceneObjectB);
  799. }
  800. if ( argc == 4 )
  801. {
  802. return object->createWeldJoint( pSceneObjectA, pSceneObjectB );
  803. }
  804. // Local anchor A.
  805. const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
  806. b2Vec2 localAnchorA;
  807. S32 nextArg = 5;
  808. if ( anchorAElementCount == 1 && argc > 5 )
  809. {
  810. localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
  811. nextArg = 6;
  812. }
  813. else if ( anchorAElementCount == 2 )
  814. {
  815. localAnchorA = Utility::mGetStringElementVector(argv[4]);
  816. }
  817. // Invalid
  818. else
  819. {
  820. Con::warnf("Scene::createWeldJoint() - Invalid number of parameters!");
  821. return -1;
  822. }
  823. if ( argc <= nextArg )
  824. {
  825. return object->createWeldJoint( pSceneObjectA, pSceneObjectB, localAnchorA );
  826. }
  827. // Local anchor B.
  828. const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
  829. b2Vec2 localAnchorB;
  830. if ( anchorBElementCount == 1 && argc > (nextArg+1) )
  831. {
  832. localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
  833. nextArg += 2;
  834. }
  835. else if ( anchorBElementCount == 2 )
  836. {
  837. localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
  838. }
  839. // Invalid
  840. else
  841. {
  842. Con::warnf("Scene::createWeldJoint() - Invalid number of parameters!");
  843. return -1;
  844. }
  845. if ( argc <= nextArg )
  846. {
  847. return object->createWeldJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB );
  848. }
  849. // Fetch frequency (Hertz).
  850. const F32 frequency = dAtof(argv[nextArg++]);
  851. if ( argc <= nextArg )
  852. {
  853. return object->createWeldJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, frequency );
  854. }
  855. // Fetch damping ratio.
  856. const F32 dampingRatio = dAtof(argv[nextArg++]);
  857. if ( argc <= nextArg )
  858. {
  859. return object->createWeldJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, frequency, dampingRatio );
  860. }
  861. // Fetch collide connected.
  862. const bool collideConnected = dAtob(argv[nextArg++]);
  863. return object->createWeldJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, frequency, dampingRatio, collideConnected );
  864. }
  865. //-----------------------------------------------------------------------------
  866. ConsoleMethod(Scene, setWeldJointFrequency, void, 4, 4, "(jointId, frequency) Sets the mass-spring-damper frequency in Hertz.\n"
  867. "@param jointId The Id of the joint to use.\n"
  868. "@param frequency The mass-spring-damper frequency in Hertz. A value of 0 disables softness.\n"
  869. "@return Returns no value." )
  870. {
  871. // Fetch joint Id.
  872. const S32 jointId = dAtoi(argv[2]);
  873. // Fetch args.
  874. const F32 frequency = dAtof(argv[3]);
  875. // Access joint.
  876. object->setWeldJointFrequency( jointId, frequency );
  877. }
  878. //-----------------------------------------------------------------------------
  879. ConsoleMethod(Scene, getWeldJointFrequency, F32, 3, 3, "(jointId) Gets the mass-spring-damper frequency in Hertz.\n"
  880. "@param jointId The Id of the joint to use.\n"
  881. "@return Returns the mass-spring-damper frequency in Hertz (-1 indicates error)." )
  882. {
  883. // Fetch joint Id.
  884. const S32 jointId = dAtoi(argv[2]);
  885. // Access joint.
  886. return object->getWeldJointFrequency( jointId );
  887. }
  888. //-----------------------------------------------------------------------------
  889. ConsoleMethod(Scene, setWeldJointDampingRatio, void, 4, 4, "(jointId, dampingRatio) Sets the damping ratio.\n"
  890. "@param jointId The Id of the joint to use.\n"
  891. "@param dampingRatio The damping ratio. 0 = no damping, 1 = critical damping.\n"
  892. "@return Returns no value." )
  893. {
  894. // Fetch joint Id.
  895. const S32 jointId = dAtoi(argv[2]);
  896. // Fetch args.
  897. const F32 dampingRatio = dAtof(argv[3]);
  898. // Access joint.
  899. object->setWeldJointDampingRatio( jointId, dampingRatio );
  900. }
  901. //-----------------------------------------------------------------------------
  902. ConsoleMethod(Scene, getWeldJointDampingRatio, F32, 3, 3, "(jointId) Gets the damping ratio.\n"
  903. "@param jointId The Id of the joint to use.\n"
  904. "@return Returns the damping ratio (-1 indicates error)." )
  905. {
  906. // Fetch joint Id.
  907. const S32 jointId = dAtoi(argv[2]);
  908. // Access joint.
  909. return object->getWeldJointDampingRatio( jointId );
  910. }
  911. //-----------------------------------------------------------------------------
  912. ConsoleMethod(Scene, createWheelJoint, S32, 7, 11, "(sceneObjectA, sceneObjectB, localAnchorA X/Y, localAnchorB X/Y, worldAxis X/Y, [collideConnected]) Creates a wheel joint.\n"
  913. "@param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
  914. "@param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
  915. "@param localAnchorA The local point of the first scene object where the joint connects.\n"
  916. "@param localAnchorB The local point of the second scene object where the joint connects.\n"
  917. "@param worldAxis The world axis of the wheel suspension spring.\n"
  918. "@param collideConnected Whether the scene objects can collide with each other while connected with this joint.\n"
  919. "@return The joint Id (-1 if error).")
  920. {
  921. // Fetch scene object references.
  922. const char* sceneObjectA = argv[2];
  923. const char* sceneObjectB = argv[3];
  924. SceneObject* pSceneObjectA = NULL;
  925. SceneObject* pSceneObjectB = NULL;
  926. // Fetch scene object.
  927. if ( *sceneObjectA != 0 )
  928. {
  929. pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
  930. if ( !pSceneObjectA )
  931. Con::warnf("Scene::createWheelJoint() - Could not find scene object %d.", sceneObjectA);
  932. }
  933. // Fetch scene object.
  934. if ( *sceneObjectB != 0 )
  935. {
  936. pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
  937. if ( !pSceneObjectB )
  938. Con::warnf("Scene::createWheelJoint() - Could not find scene object %d.", sceneObjectB);
  939. }
  940. // Local anchor A.
  941. const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
  942. b2Vec2 localAnchorA;
  943. S32 nextArg = 5;
  944. if ( anchorAElementCount == 1 && argc > 5 )
  945. {
  946. localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
  947. nextArg = 6;
  948. }
  949. else if ( anchorAElementCount == 2 )
  950. {
  951. localAnchorA = Utility::mGetStringElementVector(argv[4]);
  952. }
  953. // Invalid
  954. else
  955. {
  956. Con::warnf("Scene::createWheelJoint() - Invalid number of parameters!");
  957. return -1;
  958. }
  959. // Local anchor B.
  960. const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
  961. b2Vec2 localAnchorB;
  962. if ( anchorBElementCount == 1 && argc > (nextArg+1) )
  963. {
  964. localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
  965. nextArg += 2;
  966. }
  967. else if ( anchorBElementCount == 2 )
  968. {
  969. localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
  970. }
  971. // Invalid
  972. else
  973. {
  974. Con::warnf("Scene::createWheelJoint() - Invalid number of parameters!");
  975. return -1;
  976. }
  977. // World axis.
  978. const U32 worldAxisElementCount = Utility::mGetStringElementCount(argv[nextArg]);
  979. b2Vec2 worldAxis;
  980. if ( worldAxisElementCount == 1 && argc > (nextArg+1) )
  981. {
  982. worldAxis.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
  983. nextArg += 2;
  984. }
  985. else if ( worldAxisElementCount == 2 )
  986. {
  987. worldAxis = Utility::mGetStringElementVector(argv[nextArg++]);
  988. }
  989. // Invalid
  990. else
  991. {
  992. Con::warnf("Scene::createWheelJoint() - Invalid number of parameters!");
  993. return -1;
  994. }
  995. if ( argc <= nextArg )
  996. {
  997. return object->createWheelJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, worldAxis );
  998. }
  999. // Fetch collide connected.
  1000. const bool collideConnected = dAtob(argv[nextArg++]);
  1001. return object->createWheelJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, worldAxis, collideConnected );
  1002. }
  1003. //-----------------------------------------------------------------------------
  1004. ConsoleMethod(Scene, setWheelJointMotor, void, 4, 6, "(jointId, enableMotor, [motorSpeed], [maxMotorTorque]) Sets whether the joint has a motor or not and the motor settings.\n"
  1005. "@param jointId The Id of the joint to use.\n"
  1006. "@param enableMotor Whether the joint has a motor or not.\n"
  1007. "@param motorSpeed The motor speed (degrees per/sec).\n"
  1008. "@param maxMotorTorque The maximum motor torque used to achieve the specified motor speed (N-m).\n"
  1009. "@return Returns no value." )
  1010. {
  1011. // Fetch joint Id.
  1012. const S32 jointId = dAtoi(argv[2]);
  1013. // Fetch args.
  1014. const bool enableMotor = dAtob(argv[3]);
  1015. const F32 motorSpeed = argc > 4 ? mDegToRad( dAtof(argv[4]) ) : 0.0f;
  1016. const F32 maxMotorTorque = argc > 5 ? dAtof(argv[5]) : 0.0f;
  1017. // Access joint.
  1018. object->setWheelJointMotor( jointId, enableMotor, motorSpeed, maxMotorTorque );
  1019. }
  1020. //-----------------------------------------------------------------------------
  1021. ConsoleMethod(Scene, getWheelJointMotor, const char*, 3, 3, "(jointId) Gets whether the joint has a motor or not and the motor settings.\n"
  1022. "@param jointId The Id of the joint to use.\n"
  1023. "@return Returns whether the joint has a motor or not and the motor settings (empty string indicates error)." )
  1024. {
  1025. // Fetch joint Id.
  1026. const S32 jointId = dAtoi(argv[2]);
  1027. // Args.
  1028. bool enableMotor;
  1029. F32 motorSpeed;
  1030. F32 maxMotorTorque;
  1031. // Access joint.
  1032. if ( !object->getWheelJointMotor( jointId, enableMotor, motorSpeed, maxMotorTorque ) )
  1033. {
  1034. return NULL;
  1035. }
  1036. // Format output.
  1037. char* pBuffer = Con::getReturnBuffer(64);
  1038. dSprintf( pBuffer, 64, "%d %g %g", enableMotor, mRadToDeg(motorSpeed), maxMotorTorque );
  1039. return pBuffer;
  1040. }
  1041. //-----------------------------------------------------------------------------
  1042. ConsoleMethod(Scene, setWheelJointFrequency, void, 4, 4, "(jointId, frequency) Sets the mass-spring-damper frequency in Hertz.\n"
  1043. "@param jointId The Id of the joint to use.\n"
  1044. "@param frequency The mass-spring-damper frequency in Hertz. A value of 0 disables softness.\n"
  1045. "@return Returns no value." )
  1046. {
  1047. // Fetch joint Id.
  1048. const S32 jointId = dAtoi(argv[2]);
  1049. // Fetch args.
  1050. const F32 frequency = dAtof(argv[3]);
  1051. // Access joint.
  1052. object->setWheelJointFrequency( jointId, frequency );
  1053. }
  1054. //-----------------------------------------------------------------------------
  1055. ConsoleMethod(Scene, getWheelJointFrequency, F32, 3, 3, "(jointId) Gets the mass-spring-damper frequency in Hertz.\n"
  1056. "@param jointId The Id of the joint to use.\n"
  1057. "@return Returns the mass-spring-damper frequency in Hertz (-1 indicates error)." )
  1058. {
  1059. // Fetch joint Id.
  1060. const S32 jointId = dAtoi(argv[2]);
  1061. // Access joint.
  1062. return object->getWheelJointFrequency( jointId );
  1063. }
  1064. //-----------------------------------------------------------------------------
  1065. ConsoleMethod(Scene, setWheelJointDampingRatio, void, 4, 4, "(jointId, dampingRatio) Sets the damping ratio.\n"
  1066. "@param jointId The Id of the joint to use.\n"
  1067. "@param dampingRatio The damping ratio. 0 = no damping, 1 = critical damping.\n"
  1068. "@return Returns no value." )
  1069. {
  1070. // Fetch joint Id.
  1071. const S32 jointId = dAtoi(argv[2]);
  1072. // Fetch args.
  1073. const F32 dampingRatio = dAtof(argv[3]);
  1074. // Access joint.
  1075. object->setWheelJointDampingRatio( jointId, dampingRatio );
  1076. }
  1077. //-----------------------------------------------------------------------------
  1078. ConsoleMethod(Scene, getWheelJointDampingRatio, F32, 3, 3, "(jointId) Gets the damping ratio.\n"
  1079. "@param jointId The Id of the joint to use.\n"
  1080. "@return Returns the damping ratio (-1 indicates error)." )
  1081. {
  1082. // Fetch joint Id.
  1083. const S32 jointId = dAtoi(argv[2]);
  1084. // Access joint.
  1085. return object->getWheelJointDampingRatio( jointId );
  1086. }
  1087. //-----------------------------------------------------------------------------
  1088. ConsoleMethod(Scene, createFrictionJoint, S32, 4, 11, "(sceneObjectA, sceneObjectB, [localAnchorA X/Y], [localAnchorB X/Y], [maxForce], [maxTorque], [collideConnected]) Creates a friction joint.\n"
  1089. "@param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
  1090. "@param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
  1091. "@param localAnchorA The local point of the first scene object where the joint connects.\n"
  1092. "@param localAnchorB The local point of the second scene object where the joint connects.\n"
  1093. "@param maxForce The maximum friction force (N).\n"
  1094. "@param maxTorque The maximum torque force (N-m).\n"
  1095. "@param collideConnected Whether the scene objects can collide with each other while connected with this joint.\n"
  1096. "@return The joint Id (-1 if error).")
  1097. {
  1098. // Fetch scene object references.
  1099. const char* sceneObjectA = argv[2];
  1100. const char* sceneObjectB = argv[3];
  1101. SceneObject* pSceneObjectA = NULL;
  1102. SceneObject* pSceneObjectB = NULL;
  1103. // Fetch scene object.
  1104. if ( *sceneObjectA != 0 )
  1105. {
  1106. pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
  1107. if ( !pSceneObjectA )
  1108. Con::warnf("Scene::createFrictionJoint() - Could not find scene object %d.", sceneObjectA);
  1109. }
  1110. // Fetch scene object.
  1111. if ( *sceneObjectB != 0 )
  1112. {
  1113. pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
  1114. if ( !pSceneObjectB )
  1115. Con::warnf("Scene::createFrictionJoint() - Could not find scene object %d.", sceneObjectB);
  1116. }
  1117. if ( argc == 4 )
  1118. {
  1119. return object->createFrictionJoint( pSceneObjectA, pSceneObjectB );
  1120. }
  1121. // Local anchor A.
  1122. const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
  1123. b2Vec2 localAnchorA;
  1124. S32 nextArg = 5;
  1125. if ( anchorAElementCount == 1 && argc > 5 )
  1126. {
  1127. localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
  1128. nextArg = 6;
  1129. }
  1130. else if ( anchorAElementCount == 2 )
  1131. {
  1132. localAnchorA = Utility::mGetStringElementVector(argv[4]);
  1133. }
  1134. // Invalid
  1135. else
  1136. {
  1137. Con::warnf("Scene::createFrictionJoint() - Invalid number of parameters!");
  1138. return -1;
  1139. }
  1140. if ( argc <= nextArg )
  1141. {
  1142. return object->createFrictionJoint( pSceneObjectA, pSceneObjectB, localAnchorA );
  1143. }
  1144. // Local anchor B.
  1145. const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
  1146. b2Vec2 localAnchorB;
  1147. if ( anchorBElementCount == 1 && argc > (nextArg+1) )
  1148. {
  1149. localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
  1150. nextArg += 2;
  1151. }
  1152. else if ( anchorBElementCount == 2 )
  1153. {
  1154. localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
  1155. }
  1156. // Invalid
  1157. else
  1158. {
  1159. Con::warnf("Scene::createFrictionJoint() - Invalid number of parameters!");
  1160. return -1;
  1161. }
  1162. // Fetch maximum force.
  1163. const F32 maxForce = dAtof(argv[nextArg++]);
  1164. if ( argc <= nextArg )
  1165. {
  1166. return object->createFrictionJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, maxForce );
  1167. }
  1168. // Fetch maximum torque.
  1169. const F32 maxTorque = dAtof(argv[nextArg++]);
  1170. if ( argc <= nextArg )
  1171. {
  1172. return object->createFrictionJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, maxForce, maxTorque );
  1173. }
  1174. // Fetch collide connected.
  1175. const bool collideConnected = dAtob(argv[nextArg++]);
  1176. return object->createFrictionJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, maxForce, maxTorque, collideConnected );
  1177. }
  1178. //-----------------------------------------------------------------------------
  1179. ConsoleMethod(Scene, setFrictionJointMaxForce, void, 4, 4, "(jointId, maxForce) Sets the maximum friction force.\n"
  1180. "@param jointId The Id of the joint to use.\n"
  1181. "@param maxForce The maximum friction force (N).\n"
  1182. "@return Returns no value." )
  1183. {
  1184. // Fetch joint Id.
  1185. const S32 jointId = dAtoi(argv[2]);
  1186. // Fetch args.
  1187. const F32 maxForce = dAtof(argv[3]);
  1188. // Access joint.
  1189. object->setFrictionJointMaxForce( jointId, maxForce );
  1190. }
  1191. //-----------------------------------------------------------------------------
  1192. ConsoleMethod(Scene, getFrictionJointMaxForce, F32, 3, 3, "(jointId) Sets the maximum friction force.\n"
  1193. "@param jointId The Id of the joint to use.\n"
  1194. "@return Returns the maximum friction force (-1 indicates error)." )
  1195. {
  1196. // Fetch joint Id.
  1197. const S32 jointId = dAtoi(argv[2]);
  1198. // Access joint.
  1199. return object->getFrictionJointMaxForce( jointId );
  1200. }
  1201. //-----------------------------------------------------------------------------
  1202. ConsoleMethod(Scene, setFrictionJointMaxTorque, void, 4, 4, "(jointId, maxTorque) Sets the maximum torque force.\n"
  1203. "@param jointId The Id of the joint to use.\n"
  1204. "@param maxTorque The maximum torque force (N).\n"
  1205. "@return Returns no value." )
  1206. {
  1207. // Fetch joint Id.
  1208. const S32 jointId = dAtoi(argv[2]);
  1209. // Fetch args.
  1210. const F32 maxTorque = dAtof(argv[3]);
  1211. // Access joint.
  1212. object->setFrictionJointMaxTorque( jointId, maxTorque );
  1213. }
  1214. //-----------------------------------------------------------------------------
  1215. ConsoleMethod(Scene, getFrictionJointMaxTorque, F32, 3, 3, "(jointId) Gets the maximum torque force.\n"
  1216. "@param jointId The Id of the joint to use.\n"
  1217. "@return Returns the maximum torque force (-1 indicates error)." )
  1218. {
  1219. // Fetch joint Id.
  1220. const S32 jointId = dAtoi(argv[2]);
  1221. // Access joint.
  1222. return object->getFrictionJointMaxTorque( jointId );
  1223. }
  1224. //-----------------------------------------------------------------------------
  1225. ConsoleMethod(Scene, createPrismaticJoint, S32, 7, 11, "(sceneObjectA, sceneObjectB, localAnchorA X/Y, localAnchorB X/Y, worldAxis X/Y, [collideConnected]) Creates a prismatic joint.\n"
  1226. "@param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
  1227. "@param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
  1228. "@param localAnchorA The local point of the first scene object where the joint connects.\n"
  1229. "@param localAnchorB The local point of the second scene object where the joint connects.\n"
  1230. "@param worldAxis The world axis defining the translational degree of freedom.\n"
  1231. "@param collideConnected Whether the scene objects can collide with each other while connected with this joint.\n"
  1232. "@return The joint Id (-1 if error).")
  1233. {
  1234. // Fetch scene object references.
  1235. const char* sceneObjectA = argv[2];
  1236. const char* sceneObjectB = argv[3];
  1237. SceneObject* pSceneObjectA = NULL;
  1238. SceneObject* pSceneObjectB = NULL;
  1239. // Fetch scene object.
  1240. if ( *sceneObjectA != 0 )
  1241. {
  1242. pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
  1243. if ( !pSceneObjectA )
  1244. Con::warnf("Scene::createPrismaticJoint() - Could not find scene object %d.", sceneObjectA);
  1245. }
  1246. // Fetch scene object.
  1247. if ( *sceneObjectB != 0 )
  1248. {
  1249. pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
  1250. if ( !pSceneObjectB )
  1251. Con::warnf("Scene::createPrismaticJoint() - Could not find scene object %d.", sceneObjectB);
  1252. }
  1253. // Local anchor A.
  1254. const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
  1255. b2Vec2 localAnchorA;
  1256. S32 nextArg = 5;
  1257. if ( anchorAElementCount == 1 && argc > 5 )
  1258. {
  1259. localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
  1260. nextArg = 6;
  1261. }
  1262. else if ( anchorAElementCount == 2 )
  1263. {
  1264. localAnchorA = Utility::mGetStringElementVector(argv[4]);
  1265. }
  1266. // Invalid
  1267. else
  1268. {
  1269. Con::warnf("Scene::createPrismaticJoint() - Invalid number of parameters!");
  1270. return -1;
  1271. }
  1272. // Local anchor B.
  1273. const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
  1274. b2Vec2 localAnchorB;
  1275. if ( anchorBElementCount == 1 && argc > (nextArg+1) )
  1276. {
  1277. localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
  1278. nextArg += 2;
  1279. }
  1280. else if ( anchorBElementCount == 2 )
  1281. {
  1282. localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
  1283. }
  1284. // Invalid
  1285. else
  1286. {
  1287. Con::warnf("Scene::createPrismaticJoint() - Invalid number of parameters!");
  1288. return -1;
  1289. }
  1290. // World axis.
  1291. const U32 worldAxisElementCount = Utility::mGetStringElementCount(argv[nextArg]);
  1292. b2Vec2 worldAxis;
  1293. if ( worldAxisElementCount == 1 && argc > (nextArg+1) )
  1294. {
  1295. worldAxis.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
  1296. nextArg += 2;
  1297. }
  1298. else if ( worldAxisElementCount == 2 )
  1299. {
  1300. worldAxis = Utility::mGetStringElementVector(argv[nextArg++]);
  1301. }
  1302. // Invalid
  1303. else
  1304. {
  1305. Con::warnf("Scene::createPrismaticJoint() - Invalid number of parameters!");
  1306. return -1;
  1307. }
  1308. if ( argc <= nextArg )
  1309. {
  1310. return object->createPrismaticJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, worldAxis );
  1311. }
  1312. // Fetch collide connected.
  1313. const bool collideConnected = dAtob(argv[nextArg++]);
  1314. return object->createPrismaticJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, worldAxis, collideConnected );
  1315. }
  1316. //-----------------------------------------------------------------------------
  1317. ConsoleMethod(Scene, setPrismaticJointLimit, void, 4, 6, "(jointId, enableLimit, [lowerTranslation], [upperTranslation]) Sets whether the joint has translational limits or not and the limits themselves.\n"
  1318. "@param jointId The Id of the joint to use.\n"
  1319. "@param enableLimit Whether the joint has angular limits or not.\n"
  1320. "@param lowerTranslation The lower translation limit.\n"
  1321. "@param upperTranslation The upper translation limit.\n"
  1322. "@return Returns no value." )
  1323. {
  1324. // Fetch joint Id.
  1325. const S32 jointId = dAtoi(argv[2]);
  1326. // Fetch args.
  1327. const bool enableLimit = dAtob(argv[3]);
  1328. const F32 lowerTranslation = argc > 4 ? dAtof(argv[4]) : 0.0f;
  1329. const F32 upperTranslation = argc > 5 ? dAtof(argv[5]) : lowerTranslation;
  1330. // Access joint.
  1331. object->setPrismaticJointLimit( jointId, enableLimit, lowerTranslation, upperTranslation );
  1332. }
  1333. //-----------------------------------------------------------------------------
  1334. ConsoleMethod(Scene, getPrismaticJointLimit, const char*, 3, 3, "(jointId) Gets whether the joint has translational limits or not and the limits themselves.\n"
  1335. "@return Returns whether the joint has translational limits or not and the limits themselves (empty string indicates error)." )
  1336. {
  1337. // Fetch joint Id.
  1338. const S32 jointId = dAtoi(argv[2]);
  1339. // Args.
  1340. bool enableLimit;
  1341. F32 lowerTranslation;
  1342. F32 upperTranslation;
  1343. // Access joint.
  1344. if ( !object->getPrismaticJointLimit( jointId, enableLimit, lowerTranslation, upperTranslation ) )
  1345. {
  1346. return NULL;
  1347. }
  1348. // Format output.
  1349. char* pBuffer = Con::getReturnBuffer(64);
  1350. dSprintf( pBuffer, 64, "%d %g %g", enableLimit, lowerTranslation, upperTranslation );
  1351. return pBuffer;
  1352. }
  1353. //-----------------------------------------------------------------------------
  1354. ConsoleMethod(Scene, setPrismaticJointMotor, void, 4, 6, "(jointId, enableMotor, [motorSpeed], [maxMotorForce]) Sets whether the joint has a motor or not and the motor settings.\n"
  1355. "@param jointId The Id of the joint to use.\n"
  1356. "@param enableMotor Whether the joint has a motor or not.\n"
  1357. "@param motorSpeed The motor speed (degrees per/sec).\n"
  1358. "@param maxMotorForce The maximum motor force used to achieve the specified motor speed (N-m).\n"
  1359. "@return Returns no value." )
  1360. {
  1361. // Fetch joint Id.
  1362. const S32 jointId = dAtoi(argv[2]);
  1363. // Fetch args.
  1364. const bool enableMotor = dAtob(argv[3]);
  1365. const F32 motorSpeed = argc > 4 ? mDegToRad( dAtof(argv[4]) ) : 0.0f;
  1366. const F32 maxMotorForce = argc > 5 ? dAtof(argv[5]) : 0.0f;
  1367. // Access joint.
  1368. object->setPrismaticJointMotor( jointId, enableMotor, motorSpeed, maxMotorForce );
  1369. }
  1370. //-----------------------------------------------------------------------------
  1371. ConsoleMethod(Scene, getPrismaticJointMotor, const char*, 3, 3, "(jointId) Gets whether the joint has a motor or not and the motor settings.\n"
  1372. "@return Returns whether the joint has a motor or not and the motor settings (empty string indicates error)." )
  1373. {
  1374. // Fetch joint Id.
  1375. const S32 jointId = dAtoi(argv[2]);
  1376. // Args.
  1377. bool enableMotor;
  1378. F32 motorSpeed;
  1379. F32 maxMotorForce;
  1380. // Access joint.
  1381. if ( !object->getPrismaticJointMotor( jointId, enableMotor, motorSpeed, maxMotorForce ) )
  1382. {
  1383. return NULL;
  1384. }
  1385. // Format output.
  1386. char* pBuffer = Con::getReturnBuffer(64);
  1387. dSprintf( pBuffer, 64, "%d %g %g", enableMotor, mRadToDeg(motorSpeed), maxMotorForce );
  1388. return pBuffer;
  1389. }
  1390. //-----------------------------------------------------------------------------
  1391. ConsoleMethod(Scene, createPulleyJoint, S32, 9, 16, "(sceneObjectA, sceneObjectB, localAnchorA X/Y, localAnchorB X/Y, worldGroundAnchorA X/Y, worldGroundAnchorB X/Y, ratio, [lengthA], [lengthB], [collideConnected]) Creates a prismatic joint.\n"
  1392. "@param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
  1393. "@param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
  1394. "@param localAnchorA The local point of the first scene object where the joint connects.\n"
  1395. "@param localAnchorB The local point of the second scene object where the joint connects.\n"
  1396. "@param worldGroundAnchorA The world point of the first ground anchor. This point never moves.\n"
  1397. "@param worldGroundAnchorB The world point of the second ground anchor. This point never moves.\n"
  1398. "@param ratio The pulley ratio used to simulate a block-and-tackle pulley.\n"
  1399. "@param lengthA The reference pulley length for the segment attached to scene object A. Defaults to the distance between the first scene object and the first ground anchor.\n"
  1400. "@param lengthB The reference pulley length for the segment attached to scene object B. Defaults to the distance between the second scene object and the second ground anchor.\n"
  1401. "@param collideConnected Whether the scene objects can collide with each other while connected with this joint.\n"
  1402. "@return The joint Id (-1 if error).")
  1403. {
  1404. // Fetch scene object references.
  1405. const char* sceneObjectA = argv[2];
  1406. const char* sceneObjectB = argv[3];
  1407. SceneObject* pSceneObjectA = NULL;
  1408. SceneObject* pSceneObjectB = NULL;
  1409. // Fetch scene object.
  1410. if ( *sceneObjectA != 0 )
  1411. {
  1412. pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
  1413. if ( !pSceneObjectA )
  1414. Con::warnf("Scene::createPulleyJoint() - Could not find scene object %d.", sceneObjectA);
  1415. }
  1416. // Fetch scene object.
  1417. if ( *sceneObjectB != 0 )
  1418. {
  1419. pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
  1420. if ( !pSceneObjectB )
  1421. Con::warnf("Scene::createPulleyJoint() - Could not find scene object %d.", sceneObjectB);
  1422. }
  1423. // Local anchor A.
  1424. const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
  1425. b2Vec2 localAnchorA;
  1426. S32 nextArg = 5;
  1427. if ( anchorAElementCount == 1 && argc > 5 )
  1428. {
  1429. localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
  1430. nextArg = 6;
  1431. }
  1432. else if ( anchorAElementCount == 2 )
  1433. {
  1434. localAnchorA = Utility::mGetStringElementVector(argv[4]);
  1435. }
  1436. // Invalid
  1437. else
  1438. {
  1439. Con::warnf("Scene::createPulleyJoint() - Invalid number of parameters!");
  1440. return -1;
  1441. }
  1442. // Local anchor B.
  1443. const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
  1444. b2Vec2 localAnchorB;
  1445. if ( anchorBElementCount == 1 && argc > (nextArg+1) )
  1446. {
  1447. localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
  1448. nextArg += 2;
  1449. }
  1450. else if ( anchorBElementCount == 2 )
  1451. {
  1452. localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
  1453. }
  1454. // Invalid
  1455. else
  1456. {
  1457. Con::warnf("Scene::createPulleyJoint() - Invalid number of parameters!");
  1458. return -1;
  1459. }
  1460. // World ground anchor A.
  1461. const U32 worldGroundAnchorAElementCount = Utility::mGetStringElementCount(argv[nextArg]);
  1462. b2Vec2 worldGroundAnchorA;
  1463. if ( worldGroundAnchorAElementCount == 1 && argc > 5 )
  1464. {
  1465. worldGroundAnchorA.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg++]) );
  1466. nextArg += 2;
  1467. }
  1468. else if ( worldGroundAnchorAElementCount == 2 )
  1469. {
  1470. worldGroundAnchorA = Utility::mGetStringElementVector(argv[nextArg++]);
  1471. }
  1472. // Invalid
  1473. else
  1474. {
  1475. Con::warnf("Scene::createPulleyJoint() - Invalid number of parameters!");
  1476. return -1;
  1477. }
  1478. // World ground anchor B.
  1479. const U32 worldGroundAnchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
  1480. b2Vec2 worldGroundAnchorB;
  1481. if ( worldGroundAnchorBElementCount == 1 && argc > (nextArg+1) )
  1482. {
  1483. worldGroundAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
  1484. nextArg += 2;
  1485. }
  1486. else if ( worldGroundAnchorBElementCount == 2 )
  1487. {
  1488. worldGroundAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
  1489. }
  1490. // Invalid
  1491. else
  1492. {
  1493. Con::warnf("Scene::createPulleyJoint() - Invalid number of parameters!");
  1494. return -1;
  1495. }
  1496. // Fetch maximum ratio.
  1497. const F32 ratio = dAtof(argv[nextArg++]);
  1498. if ( argc <= nextArg )
  1499. {
  1500. return object->createPulleyJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, worldGroundAnchorA, worldGroundAnchorB, ratio );
  1501. }
  1502. // Fetch collide connected.
  1503. const bool collideConnected = dAtob(argv[nextArg++]);
  1504. return object->createPulleyJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, worldGroundAnchorA, worldGroundAnchorB, ratio, collideConnected );
  1505. }
  1506. //-----------------------------------------------------------------------------
  1507. ConsoleMethod(Scene, createTargetJoint, S32, 5, 10, "(sceneObject, worldTarget X/Y, maxForce, [useCenterOfMass?], [frequency], [dampingRatio], [collideConnected]) Creates a target joint.\n"
  1508. "@param sceneObject The scene object to connect to the joint.\n"
  1509. "@param worldTarget The world point target to move the scene object to.\n"
  1510. "@param maxForce The maximum force the joint should use to position the scene object at the target.\n"
  1511. "@param useCenterOfMass Whether to use the center of mass as the point which the joint is attached or not. Defaults to false.\n"
  1512. "@param frequency The mass-spring-damper frequency in Hertz. A value of 0 disables softness (default=0.7).\n"
  1513. "@param dampingRatio The damping ratio. 0 = no damping (default), 1 = critical damping.\n"
  1514. "@param collideConnected Whether the scene objects can collide with each other while connected with this joint.\n"
  1515. "@return The joint Id (-1 if error).")
  1516. {
  1517. // Fetch scene object.
  1518. SceneObject* pSceneObject = Sim::findObject<SceneObject>(argv[2]);
  1519. // Check scene object.
  1520. if ( !pSceneObject )
  1521. {
  1522. Con::warnf("Scene::createTargetJoint() - Could not find scene object %d.", argv[2]);
  1523. return -1;
  1524. }
  1525. // World target.
  1526. const U32 worldTargetElementCount = Utility::mGetStringElementCount(argv[3]);
  1527. b2Vec2 worldTarget;
  1528. S32 nextArg = 4;
  1529. if ( worldTargetElementCount == 1 && argc > 5 )
  1530. {
  1531. worldTarget.Set( dAtof(argv[3]), dAtof(argv[4]) );
  1532. nextArg = 5;
  1533. }
  1534. else if ( worldTargetElementCount == 2 )
  1535. {
  1536. worldTarget = Utility::mGetStringElementVector(argv[3]);
  1537. }
  1538. // Invalid
  1539. else
  1540. {
  1541. Con::warnf("Scene::createTargetJoint() - Invalid number of parameters!");
  1542. return -1;
  1543. }
  1544. // Fetch maximum force.
  1545. const F32 maxForce = dAtof(argv[nextArg++]);
  1546. if ( argc <= nextArg )
  1547. {
  1548. return object->createTargetJoint( pSceneObject, worldTarget, maxForce );
  1549. }
  1550. // Fetch the center-of-mass flag.
  1551. const bool centerOfMass = dAtob(argv[nextArg++]);
  1552. if ( argc <= nextArg )
  1553. {
  1554. return object->createTargetJoint( pSceneObject, worldTarget, maxForce, centerOfMass );
  1555. }
  1556. // Fetch frequency (Hertz).
  1557. const F32 frequency = dAtof(argv[nextArg++]);
  1558. if ( argc <= nextArg )
  1559. {
  1560. return object->createTargetJoint( pSceneObject, worldTarget, maxForce, frequency );
  1561. }
  1562. // Fetch damping ratio.
  1563. const F32 dampingRatio = dAtof(argv[nextArg++]);
  1564. if ( argc <= nextArg )
  1565. {
  1566. return object->createTargetJoint( pSceneObject, worldTarget, maxForce, frequency, dampingRatio );
  1567. }
  1568. // Fetch collide connected.
  1569. const bool collideConnected = dAtob(argv[nextArg++]);
  1570. return object->createTargetJoint( pSceneObject, worldTarget, maxForce, frequency, dampingRatio, collideConnected );
  1571. }
  1572. //-----------------------------------------------------------------------------
  1573. ConsoleMethod(Scene, setTargetJointTarget, void, 4, 5, "(jointId, worldTarget X/Y) Sets the target world point for the scene object.\n"
  1574. "@param jointId The Id of the joint to use.\n"
  1575. "@param worldTarget The target world point to move the scene object to.\n"
  1576. "@return Returns no value." )
  1577. {
  1578. // Fetch joint Id.
  1579. const S32 jointId = dAtoi(argv[2]);
  1580. // World target.
  1581. const U32 worldTargetElementCount = Utility::mGetStringElementCount(argv[3]);
  1582. b2Vec2 worldTarget;
  1583. if ( worldTargetElementCount == 1 && argc > 5 )
  1584. {
  1585. worldTarget.Set( dAtof(argv[3]), dAtof(argv[4]) );
  1586. }
  1587. else if ( worldTargetElementCount == 2 )
  1588. {
  1589. worldTarget = Utility::mGetStringElementVector(argv[3]);
  1590. }
  1591. // Invalid
  1592. else
  1593. {
  1594. Con::warnf("Scene::setTargetJointTarget() - Invalid number of parameters!");
  1595. }
  1596. // Access joint.
  1597. object->setTargetJointTarget( jointId, worldTarget );
  1598. }
  1599. //-----------------------------------------------------------------------------
  1600. ConsoleMethod(Scene, getTargetJointTarget, const char*, 3, 3, "(jointId) Gets the target world point for the scene object.\n"
  1601. "@param jointId The Id of the joint to use.\n"
  1602. "@return Returns the target world point for the scene object (always 0,0 if error)." )
  1603. {
  1604. // Fetch joint Id.
  1605. const S32 jointId = dAtoi(argv[2]);
  1606. // Access joint.
  1607. const Vector2 worldTarget = object->getTargetJointTarget( jointId );
  1608. return worldTarget.scriptThis();
  1609. }
  1610. //-----------------------------------------------------------------------------
  1611. ConsoleMethod(Scene, setTargetJointFrequency, void, 4, 4, "(jointId, frequency) Sets the mass-spring-damper frequency in Hertz.\n"
  1612. "@param jointId The Id of the joint to use.\n"
  1613. "@param frequency The mass-spring-damper frequency in Hertz. A value of 0 disables softness.\n"
  1614. "@return Returns no value." )
  1615. {
  1616. // Fetch joint Id.
  1617. const S32 jointId = dAtoi(argv[2]);
  1618. // Fetch args.
  1619. const F32 frequency = dAtof(argv[3]);
  1620. // Access joint.
  1621. object->setTargetJointFrequency( jointId, frequency );
  1622. }
  1623. //-----------------------------------------------------------------------------
  1624. ConsoleMethod(Scene, getTargetJointFrequency, F32, 3, 3, "(jointId) Gets the mass-spring-damper frequency in Hertz.\n"
  1625. "@param jointId The Id of the joint to use.\n"
  1626. "@return Returns the mass-spring-damper frequency in Hertz (-1 indicates error)." )
  1627. {
  1628. // Fetch joint Id.
  1629. const S32 jointId = dAtoi(argv[2]);
  1630. // Access joint.
  1631. return object->getTargetJointFrequency( jointId );
  1632. }
  1633. //-----------------------------------------------------------------------------
  1634. ConsoleMethod(Scene, setTargetJointDampingRatio, void, 4, 4, "(jointId, dampingRatio) Sets the damping ratio.\n"
  1635. "@param jointId The Id of the joint to use.\n"
  1636. "@param dampingRatio The damping ratio. 0 = no damping, 1 = critical damping.\n"
  1637. "@return Returns no value." )
  1638. {
  1639. // Fetch joint Id.
  1640. const S32 jointId = dAtoi(argv[2]);
  1641. // Fetch args.
  1642. const F32 dampingRatio = dAtof(argv[3]);
  1643. // Access joint.
  1644. object->setTargetJointDampingRatio( jointId, dampingRatio );
  1645. }
  1646. //-----------------------------------------------------------------------------
  1647. ConsoleMethod(Scene, getTargetJointDampingRatio, F32, 3, 3, "(jointId) Sets the damping ratio.\n"
  1648. "@param jointId The Id of the joint to use.\n"
  1649. "@return Returns the damping ratio (-1 indicates error)." )
  1650. {
  1651. // Fetch joint Id.
  1652. const S32 jointId = dAtoi(argv[2]);
  1653. // Access joint.
  1654. return object->getTargetJointDampingRatio( jointId );
  1655. }
  1656. //-----------------------------------------------------------------------------
  1657. ConsoleMethod(Scene, createMotorJoint, S32, 4, 11, "(sceneObjectA, sceneObjectB, [linearOffset X/Y], [angularOffset], [maxForce], [maxTorque], [correctionFactor], [collideConnected]) Creates a motor joint.\n"
  1658. "@param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
  1659. "@param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
  1660. "@param linearOffsetX/Y The linear offset in sceneObjectA space.\n"
  1661. "@param angularOffset The angularOffset between the bodies.\n"
  1662. "@param maxForce The maximum friction force (N).\n"
  1663. "@param maxTorque The maximum torque force (N-m).\n"
  1664. "@param correctionFactor The correction factor (tolerance).\n"
  1665. "@param collideConnected Whether the scene objects can collide with each other while connected with this joint.\n"
  1666. "@return The joint Id (-1 if error).")
  1667. {
  1668. // Fetch scene object references.
  1669. const char* sceneObjectA = argv[2];
  1670. const char* sceneObjectB = argv[3];
  1671. SceneObject* pSceneObjectA = NULL;
  1672. SceneObject* pSceneObjectB = NULL;
  1673. // Fetch scene object.
  1674. if ( *sceneObjectA != 0 )
  1675. {
  1676. pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
  1677. if ( !pSceneObjectA )
  1678. Con::warnf("Scene::createMotorJoint() - Could not find scene object %d.", sceneObjectA);
  1679. }
  1680. // Fetch scene object.
  1681. if ( *sceneObjectB != 0 )
  1682. {
  1683. pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
  1684. if ( !pSceneObjectB )
  1685. Con::warnf("Scene::createMotorJoint() - Could not find scene object %d.", sceneObjectB);
  1686. }
  1687. if ( argc == 4 )
  1688. {
  1689. return object->createMotorJoint( pSceneObjectA, pSceneObjectB );
  1690. }
  1691. // Linear offset.
  1692. const U32 linearOffsetElementCount = Utility::mGetStringElementCount(argv[4]);
  1693. b2Vec2 linearOffset;
  1694. S32 nextArg = 5;
  1695. if ( linearOffsetElementCount == 1 && argc > 5 )
  1696. {
  1697. linearOffset.Set( dAtof(argv[4]), dAtof(argv[5]) );
  1698. nextArg = 6;
  1699. }
  1700. else if ( linearOffsetElementCount == 2 )
  1701. {
  1702. linearOffset = Utility::mGetStringElementVector(argv[4]);
  1703. }
  1704. // Invalid
  1705. else
  1706. {
  1707. Con::warnf("Scene::createMotorJoint() - Invalid number of parameters!");
  1708. return -1;
  1709. }
  1710. if ( argc <= nextArg )
  1711. {
  1712. return object->createMotorJoint( pSceneObjectA, pSceneObjectB, linearOffset );
  1713. }
  1714. // Fetch angular offset.
  1715. const F32 angularOffset = mDegToRad( dAtof(argv[nextArg++]) );
  1716. if ( argc <= nextArg )
  1717. {
  1718. return object->createMotorJoint( pSceneObjectA, pSceneObjectB, linearOffset, angularOffset );
  1719. }
  1720. // Fetch maximum force.
  1721. const F32 maxForce = dAtof(argv[nextArg++]);
  1722. if ( argc <= nextArg )
  1723. {
  1724. return object->createMotorJoint( pSceneObjectA, pSceneObjectB, linearOffset, angularOffset, maxForce );
  1725. }
  1726. // Fetch maximum torque.
  1727. const F32 maxTorque = dAtof(argv[nextArg++]);
  1728. if ( argc <= nextArg )
  1729. {
  1730. return object->createMotorJoint( pSceneObjectA, pSceneObjectB, linearOffset, angularOffset, maxForce, maxTorque );
  1731. }
  1732. // Fetch collide connected.
  1733. const bool collideConnected = dAtob(argv[nextArg++]);
  1734. return object->createMotorJoint( pSceneObjectA, pSceneObjectB, linearOffset, angularOffset, maxForce, maxTorque, collideConnected );
  1735. }
  1736. //-----------------------------------------------------------------------------
  1737. ConsoleMethod(Scene, setMotorJointLinearOffset, void, 4, 5, "(jointId, linearOffset X/Y) Sets the linear offset in sceneObjectA space.\n"
  1738. "@param jointId The Id of the joint to use.\n"
  1739. "@param linearOffsetX/Y The linear offset in sceneObjectA space.\n"
  1740. "@return Returns no value." )
  1741. {
  1742. // Fetch joint Id.
  1743. const S32 jointId = dAtoi(argv[2]);
  1744. // Linear offset.
  1745. const U32 linearOffsetElementCount = Utility::mGetStringElementCount(argv[3]);
  1746. b2Vec2 linearOffset;
  1747. if ( linearOffsetElementCount == 1 && argc > 5 )
  1748. {
  1749. linearOffset.Set( dAtof(argv[3]), dAtof(argv[4]) );
  1750. }
  1751. else if ( linearOffsetElementCount == 2 )
  1752. {
  1753. linearOffset = Utility::mGetStringElementVector(argv[3]);
  1754. }
  1755. // Invalid
  1756. else
  1757. {
  1758. Con::warnf("Scene::setMotorJointLinearOffset() - Invalid number of parameters!");
  1759. }
  1760. // Access joint.
  1761. object->setMotorJointLinearOffset( jointId, linearOffset );
  1762. }
  1763. //-----------------------------------------------------------------------------
  1764. ConsoleMethod(Scene, getMotorJointLinearOffset, const char*, 3, 3, "(jointId) Gets the linear offset in sceneObjectA space.\n"
  1765. "@param jointId The Id of the joint to use.\n"
  1766. "@return Returns the linear offset in sceneObjectA space (always 0,0 if error)." )
  1767. {
  1768. // Fetch joint Id.
  1769. const S32 jointId = dAtoi(argv[2]);
  1770. // Access joint.
  1771. const Vector2 linearOffset = object->getMotorJointLinearOffset( jointId );
  1772. return linearOffset.scriptThis();
  1773. }
  1774. //-----------------------------------------------------------------------------
  1775. ConsoleMethod(Scene, setMotorJointAngularOffset, void, 4, 4, "(jointId, angularOffset) Sets the angularOffset between the bodies.\n"
  1776. "@param jointId The Id of the joint to use.\n"
  1777. "@param angularOffset The angularOffset between the bodies.\n"
  1778. "@return Returns no value." )
  1779. {
  1780. // Fetch joint Id.
  1781. const S32 jointId = dAtoi(argv[2]);
  1782. // Fetch args.
  1783. const F32 angularOffset = mDegToRad(dAtof(argv[3]));
  1784. // Access joint.
  1785. object->setMotorJointAngularOffset( jointId, angularOffset );
  1786. }
  1787. //-----------------------------------------------------------------------------
  1788. ConsoleMethod(Scene, getMotorJointAngularOffset, F32, 3, 3, "(jointId) Gets angularOffset between the bodies.\n"
  1789. "@param jointId The Id of the joint to use.\n"
  1790. "@return Returns the angularOffset between the bodies (-1 indicates error)." )
  1791. {
  1792. // Fetch joint Id.
  1793. const S32 jointId = dAtoi(argv[2]);
  1794. // Access joint.
  1795. return mRadToDeg( object->getMotorJointAngularOffset( jointId ) );
  1796. }
  1797. //-----------------------------------------------------------------------------
  1798. ConsoleMethod(Scene, setMotorJointMaxForce, void, 4, 4, "(jointId, maxForce) Sets the maximum motor force.\n"
  1799. "@param jointId The Id of the joint to use.\n"
  1800. "@param maxForce The maximum motor force (N).\n"
  1801. "@return Returns no value." )
  1802. {
  1803. // Fetch joint Id.
  1804. const S32 jointId = dAtoi(argv[2]);
  1805. // Fetch args.
  1806. const F32 maxForce = dAtof(argv[3]);
  1807. // Access joint.
  1808. object->setMotorJointMaxForce( jointId, maxForce );
  1809. }
  1810. //-----------------------------------------------------------------------------
  1811. ConsoleMethod(Scene, getMotorJointMaxForce, F32, 3, 3, "(jointId) Sets the maximum motor force.\n"
  1812. "@param jointId The Id of the joint to use.\n"
  1813. "@return Returns the maximum motor force (-1 indicates error)." )
  1814. {
  1815. // Fetch joint Id.
  1816. const S32 jointId = dAtoi(argv[2]);
  1817. // Access joint.
  1818. return object->getMotorJointMaxForce( jointId );
  1819. }
  1820. //-----------------------------------------------------------------------------
  1821. ConsoleMethod(Scene, setMotorJointMaxTorque, void, 4, 4, "(jointId, maxTorque) Sets the maximum motor torque force.\n"
  1822. "@param jointId The Id of the joint to use.\n"
  1823. "@param maxTorque The maximum motor torque force (N).\n"
  1824. "@return Returns no value." )
  1825. {
  1826. // Fetch joint Id.
  1827. const S32 jointId = dAtoi(argv[2]);
  1828. // Fetch args.
  1829. const F32 maxTorque = dAtof(argv[3]);
  1830. // Access joint.
  1831. object->setMotorJointMaxTorque( jointId, maxTorque );
  1832. }
  1833. //-----------------------------------------------------------------------------
  1834. ConsoleMethod(Scene, getMotorJointMaxTorque, F32, 3, 3, "(jointId) Gets the maximum motor torque force.\n"
  1835. "@param jointId The Id of the joint to use.\n"
  1836. "@return Returns the maximum motor torque force (-1 indicates error)." )
  1837. {
  1838. // Fetch joint Id.
  1839. const S32 jointId = dAtoi(argv[2]);
  1840. // Access joint.
  1841. return object->getMotorJointMaxTorque( jointId );
  1842. }
  1843. //-----------------------------------------------------------------------------
  1844. ConsoleMethod(Scene, pickArea, const char*, 4, 9, "(startx/y, endx/y, [sceneGroupMask], [sceneLayerMask], [pickMode] ) Picks objects intersecting the specified area with optional group/layer masks.\n"
  1845. "@param startx/y The coordinates of the start point as either (\"x y\") or (x,y)\n"
  1846. "@param endx/y The coordinates of the end point as either (\"x y\") or (x,y)\n"
  1847. "@param sceneGroupMask Optional scene group mask.\n"
  1848. "@param sceneLayerMask Optional scene layer mask.\n"
  1849. "@param pickMode Optional mode 'any', 'size' or 'collision' (default is 'size').\n"
  1850. "@return Returns list of object IDs.")
  1851. {
  1852. // Upper left and lower right bound.
  1853. Vector2 v1, v2;
  1854. // The index of the first optional parameter.
  1855. U32 firstArg;
  1856. // Grab the number of elements in the first two parameters.
  1857. U32 elementCount1 = Utility::mGetStringElementCount(argv[2]);
  1858. U32 elementCount2 = 1;
  1859. if (argc > 3)
  1860. elementCount2 = Utility::mGetStringElementCount(argv[3]);
  1861. // ("x1 y1 x2 y2")
  1862. if ((elementCount1 == 4) && (argc < 9))
  1863. {
  1864. v1 = Utility::mGetStringElementVector(argv[2]);
  1865. v2 = Utility::mGetStringElementVector(argv[2], 2);
  1866. firstArg = 3;
  1867. }
  1868. // ("x1 y1", "x2 y2")
  1869. else if ((elementCount1 == 2) && (elementCount2 == 2) && (argc > 3) && (argc < 10))
  1870. {
  1871. v1 = Utility::mGetStringElementVector(argv[2]);
  1872. v2 = Utility::mGetStringElementVector(argv[3]);
  1873. firstArg = 4;
  1874. }
  1875. // (x1, y1, x2, y2)
  1876. else if (argc > 5)
  1877. {
  1878. v1 = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  1879. v2 = Vector2(dAtof(argv[4]), dAtof(argv[5]));
  1880. firstArg = 6;
  1881. }
  1882. // Invalid
  1883. else
  1884. {
  1885. Con::warnf("Scene::pickArea() - Invalid number of parameters!");
  1886. return NULL;
  1887. }
  1888. // Calculate scene group mask.
  1889. U32 sceneGroupMask = MASK_ALL;
  1890. if ( (U32)argc > firstArg )
  1891. sceneGroupMask = dAtoi(argv[firstArg]);
  1892. // Calculate scene layer mask.
  1893. U32 sceneLayerMask = MASK_ALL;
  1894. if ( (U32)argc > (firstArg + 1) )
  1895. sceneLayerMask = dAtoi(argv[firstArg + 1]);
  1896. // Calculate pick mode.
  1897. Scene::PickMode pickMode = Scene::PICK_SIZE;
  1898. if ( (U32)argc > (firstArg + 2))
  1899. {
  1900. pickMode = Scene::getPickModeEnum(argv[firstArg + 2]);
  1901. }
  1902. if ( pickMode == Scene::PICK_INVALID )
  1903. {
  1904. Con::warnf("Scene::pickArea() - Invalid pick mode of %s", argv[firstArg + 2]);
  1905. pickMode = Scene::PICK_SIZE;
  1906. }
  1907. // Fetch world query and clear results.
  1908. WorldQuery* pWorldQuery = object->getWorldQuery( true );
  1909. // Set filter.
  1910. WorldQueryFilter queryFilter( sceneLayerMask, sceneGroupMask, true, false, true, true );
  1911. pWorldQuery->setQueryFilter( queryFilter );
  1912. // Calculate normalized AABB.
  1913. b2AABB aabb;
  1914. aabb.lowerBound.x = getMin( v1.x, v2.x );
  1915. aabb.lowerBound.y = getMin( v1.y, v2.y );
  1916. aabb.upperBound.x = getMax( v1.x, v2.x );
  1917. aabb.upperBound.y = getMax( v1.y, v2.y );
  1918. // Perform query.
  1919. if ( pickMode == Scene::PICK_ANY )
  1920. {
  1921. pWorldQuery->anyQueryArea( aabb );
  1922. }
  1923. else if ( pickMode == Scene::PICK_SIZE )
  1924. {
  1925. pWorldQuery->renderQueryArea( aabb );
  1926. }
  1927. else if ( pickMode == Scene::PICK_COLLISION )
  1928. {
  1929. pWorldQuery->fixtureQueryArea( aabb );
  1930. }
  1931. else
  1932. {
  1933. AssertFatal( false, "Unsupported pick mode." );
  1934. }
  1935. // Fetch result count.
  1936. const U32 resultCount = pWorldQuery->getQueryResultsCount();
  1937. // Finish if no results.
  1938. if ( resultCount == 0 )
  1939. return NULL;
  1940. // Fetch results.
  1941. typeWorldQueryResultVector& queryResults = pWorldQuery->getQueryResults();
  1942. // Set Max Buffer Size.
  1943. const U32 maxBufferSize = 4096;
  1944. // Create Returnable Buffer.
  1945. char* pBuffer = Con::getReturnBuffer(maxBufferSize);
  1946. // Set Buffer Counter.
  1947. U32 bufferCount = 0;
  1948. // Add picked objects.
  1949. for ( U32 n = 0; n < resultCount; n++ )
  1950. {
  1951. // Output Object ID.
  1952. bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", queryResults[n].mpSceneObject->getId() );
  1953. // Finish early if we run out of buffer space.
  1954. if ( bufferCount >= maxBufferSize )
  1955. {
  1956. // Warn.
  1957. Con::warnf("Scene::pickArea() - Too many items picked to return to scripts!");
  1958. break;
  1959. }
  1960. }
  1961. // Clear world query.
  1962. pWorldQuery->clearQuery();
  1963. // Return buffer.
  1964. return pBuffer;
  1965. }
  1966. //-----------------------------------------------------------------------------
  1967. ConsoleMethod(Scene, pickRay, const char*, 4, 9, "(startx/y, endx/y, [sceneGroupMask], [sceneLayerMask], [pickMode] ) Picks objects intersecting the specified ray with optional group/layer masks.\n"
  1968. "@param startx/y The coordinates of the start point as either (\"x y\") or (x,y)\n"
  1969. "@param endx/y The coordinates of the end point as either (\"x y\") or (x,y)\n"
  1970. "@param sceneGroupMask Optional scene group mask.\n"
  1971. "@param sceneLayerMask Optional scene layer mask.\n"
  1972. "@param pickMode Optional mode 'any', 'size' or 'collision' (default is 'size').\n"
  1973. "@return Returns list of object IDs.")
  1974. {
  1975. // Upper left and lower right bound.
  1976. Vector2 v1, v2;
  1977. // The index of the first optional parameter.
  1978. U32 firstArg;
  1979. // Grab the number of elements in the first two parameters.
  1980. U32 elementCount1 = Utility::mGetStringElementCount(argv[2]);
  1981. U32 elementCount2 = 1;
  1982. if (argc > 3)
  1983. elementCount2 = Utility::mGetStringElementCount(argv[3]);
  1984. // ("x1 y1 x2 y2")
  1985. if ((elementCount1 == 4) && (argc < 9))
  1986. {
  1987. v1 = Utility::mGetStringElementVector(argv[2]);
  1988. v2 = Utility::mGetStringElementVector(argv[2], 2);
  1989. firstArg = 3;
  1990. }
  1991. // ("x1 y1", "x2 y2")
  1992. else if ((elementCount1 == 2) && (elementCount2 == 2) && (argc > 3) && (argc < 10))
  1993. {
  1994. v1 = Utility::mGetStringElementVector(argv[2]);
  1995. v2 = Utility::mGetStringElementVector(argv[3]);
  1996. firstArg = 4;
  1997. }
  1998. // (x1, y1, x2, y2)
  1999. else if (argc > 5)
  2000. {
  2001. v1 = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  2002. v2 = Vector2(dAtof(argv[4]), dAtof(argv[5]));
  2003. firstArg = 6;
  2004. }
  2005. // Invalid
  2006. else
  2007. {
  2008. Con::warnf("Scene::pickRay() - Invalid number of parameters!");
  2009. return NULL;
  2010. }
  2011. // Calculate scene group mask.
  2012. U32 sceneGroupMask = MASK_ALL;
  2013. if ( (U32)argc > firstArg )
  2014. sceneGroupMask = dAtoi(argv[firstArg]);
  2015. // Calculate scene layer mask.
  2016. U32 sceneLayerMask = MASK_ALL;
  2017. if ( (U32)argc > (firstArg + 1) )
  2018. sceneLayerMask = dAtoi(argv[firstArg + 1]);
  2019. // Calculate pick mode.
  2020. Scene::PickMode pickMode = Scene::PICK_SIZE;
  2021. if ( (U32)argc > (firstArg + 2))
  2022. {
  2023. pickMode = Scene::getPickModeEnum(argv[firstArg + 2]);
  2024. }
  2025. if ( pickMode == Scene::PICK_INVALID )
  2026. {
  2027. Con::warnf("Scene::pickRay() - Invalid pick mode of %s", argv[firstArg + 2]);
  2028. pickMode = Scene::PICK_SIZE;
  2029. }
  2030. // Fetch world query and clear results.
  2031. WorldQuery* pWorldQuery = object->getWorldQuery( true );
  2032. // Set filter.
  2033. WorldQueryFilter queryFilter( sceneLayerMask, sceneGroupMask, true, false, true, true );
  2034. pWorldQuery->setQueryFilter( queryFilter );
  2035. // Perform query.
  2036. if ( pickMode == Scene::PICK_ANY )
  2037. {
  2038. pWorldQuery->anyQueryRay( v1, v2 );
  2039. }
  2040. else if ( pickMode == Scene::PICK_SIZE )
  2041. {
  2042. pWorldQuery->renderQueryRay( v1, v2 );
  2043. }
  2044. else if ( pickMode == Scene::PICK_COLLISION )
  2045. {
  2046. pWorldQuery->fixtureQueryRay( v1, v2 );
  2047. }
  2048. else
  2049. {
  2050. AssertFatal( false, "Unsupported pick mode." );
  2051. }
  2052. // Sanity!
  2053. AssertFatal( pWorldQuery->getIsRaycastQueryResult(), "Invalid non-ray-cast query result returned." );
  2054. // Fetch result count.
  2055. const U32 resultCount = pWorldQuery->getQueryResultsCount();
  2056. // Finish if no results.
  2057. if ( resultCount == 0 )
  2058. return NULL;
  2059. // Sort ray-cast result.
  2060. pWorldQuery->sortRaycastQueryResult();
  2061. // Fetch results.
  2062. typeWorldQueryResultVector& queryResults = pWorldQuery->getQueryResults();
  2063. // Set Max Buffer Size.
  2064. const U32 maxBufferSize = 4096;
  2065. // Create Returnable Buffer.
  2066. char* pBuffer = Con::getReturnBuffer(maxBufferSize);
  2067. // Set Buffer Counter.
  2068. U32 bufferCount = 0;
  2069. // Add Picked Objects to List.
  2070. for ( U32 n = 0; n < resultCount; n++ )
  2071. {
  2072. // Output Object ID.
  2073. bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", queryResults[n].mpSceneObject->getId() );
  2074. // Finish early if we run out of buffer space.
  2075. if ( bufferCount >= maxBufferSize )
  2076. {
  2077. // Warn.
  2078. Con::warnf("Scene::pickRay() - Too many items picked to return to scripts!");
  2079. break;
  2080. }
  2081. }
  2082. // Clear world query.
  2083. pWorldQuery->clearQuery();
  2084. // Return buffer.
  2085. return pBuffer;
  2086. }
  2087. //-----------------------------------------------------------------------------
  2088. ConsoleMethod(Scene, pickRayCollision, const char*, 4, 8, "(startx/y, endx/y, [sceneGroupMask], [sceneLayerMask] ) Picks objects with collision shapes intersecting the specified ray with optional group/layer masks.\n"
  2089. "Unlike other pick methods, this returns the complete detail for each object encountered, returning the collision point, normal and fraction of the ray intersection.\n"
  2090. "@param startx/y The coordinates of the start point as either (\"x y\") or (x,y)\n"
  2091. "@param endx/y The coordinates of the end point as either (\"x y\") or (x,y)\n"
  2092. "@param sceneGroupMask Optional scene group mask.\n"
  2093. "@param sceneLayerMask Optional scene layer mask.\n"
  2094. "@return Returns a list of objects in blocks of detail items where each block represents a single object and its collision detail in the format:"
  2095. "<ObjectId PointX PointY NormalX NormalY RayFraction ShapeIndex> <ObjectId PointX PointY NormalX NormalY RayFraction ShapeIndex> <ObjectId PointX PointY NormalX NormalY RayFraction ShapeIndex> etc.\n")
  2096. {
  2097. // Upper left and lower right bound.
  2098. Vector2 v1, v2;
  2099. // The index of the first optional parameter.
  2100. U32 firstArg;
  2101. // Grab the number of elements in the first two parameters.
  2102. U32 elementCount1 = Utility::mGetStringElementCount(argv[2]);
  2103. U32 elementCount2 = 1;
  2104. if (argc > 3)
  2105. elementCount2 = Utility::mGetStringElementCount(argv[3]);
  2106. // ("x1 y1 x2 y2")
  2107. if ((elementCount1 == 4) && (argc < 9))
  2108. {
  2109. v1 = Utility::mGetStringElementVector(argv[2]);
  2110. v2 = Utility::mGetStringElementVector(argv[2], 2);
  2111. firstArg = 3;
  2112. }
  2113. // ("x1 y1", "x2 y2")
  2114. else if ((elementCount1 == 2) && (elementCount2 == 2) && (argc > 3) && (argc < 9))
  2115. {
  2116. v1 = Utility::mGetStringElementVector(argv[2]);
  2117. v2 = Utility::mGetStringElementVector(argv[3]);
  2118. firstArg = 4;
  2119. }
  2120. // (x1, y1, x2, y2)
  2121. else if (argc > 5)
  2122. {
  2123. v1 = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  2124. v2 = Vector2(dAtof(argv[4]), dAtof(argv[5]));
  2125. firstArg = 6;
  2126. }
  2127. // Invalid
  2128. else
  2129. {
  2130. Con::warnf("Scene::pickRayCollision() - Invalid number of parameters!");
  2131. return NULL;
  2132. }
  2133. // Calculate scene group mask.
  2134. U32 sceneGroupMask = MASK_ALL;
  2135. if ( (U32)argc > firstArg )
  2136. sceneGroupMask = dAtoi(argv[firstArg]);
  2137. // Calculate scene layer mask.
  2138. U32 sceneLayerMask = MASK_ALL;
  2139. if ( (U32)argc > (firstArg + 1) )
  2140. sceneLayerMask = dAtoi(argv[firstArg + 1]);
  2141. // Fetch world query and clear results.
  2142. WorldQuery* pWorldQuery = object->getWorldQuery( true );
  2143. // Set filter.
  2144. WorldQueryFilter queryFilter( sceneLayerMask, sceneGroupMask, true, false, true, true );
  2145. pWorldQuery->setQueryFilter( queryFilter );
  2146. // Perform query.
  2147. pWorldQuery->fixtureQueryRay( v1, v2 );
  2148. // Sanity!
  2149. AssertFatal( pWorldQuery->getIsRaycastQueryResult(), "Invalid non-ray-cast query result returned." );
  2150. // Fetch result count.
  2151. const U32 resultCount = pWorldQuery->getQueryResultsCount();
  2152. // Finish if no results.
  2153. if ( resultCount == 0 )
  2154. return NULL;
  2155. // Sort ray-cast result.
  2156. pWorldQuery->sortRaycastQueryResult();
  2157. // Fetch results.
  2158. typeWorldQueryResultVector& queryResults = pWorldQuery->getQueryResults();
  2159. // Set Max Buffer Size.
  2160. const U32 maxBufferSize = 4096;
  2161. // Create Returnable Buffer.
  2162. char* pBuffer = Con::getReturnBuffer(maxBufferSize);
  2163. // Set Buffer Counter.
  2164. U32 bufferCount = 0;
  2165. // Add Picked Objects to List.
  2166. for ( U32 n = 0; n < resultCount; n++ )
  2167. {
  2168. // Fetch query result.
  2169. const WorldQueryResult& queryResult = queryResults[n];
  2170. bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d %g %g %g %g %g %d ",
  2171. queryResult.mpSceneObject->getId(),
  2172. queryResult.mPoint.x, queryResult.mPoint.y,
  2173. queryResult.mNormal.x, queryResult.mNormal.y,
  2174. queryResult.mFraction,
  2175. queryResult.mShapeIndex );
  2176. // Finish early if we run out of buffer space.
  2177. if ( bufferCount >= maxBufferSize )
  2178. {
  2179. // Warn.
  2180. Con::warnf("Scene::pickRayCollision() - Too many items picked to return to scripts!");
  2181. break;
  2182. }
  2183. }
  2184. // Clear world query.
  2185. pWorldQuery->clearQuery();
  2186. // Return buffer.
  2187. return pBuffer;
  2188. }
  2189. //-----------------------------------------------------------------------------
  2190. ConsoleMethod(Scene, pickPoint, const char*, 3, 7, "(x / y, [sceneGroupMask], [sceneLayerMask], [pickMode] ) Picks objects intersecting the specified point with optional group/layer masks.\n"
  2191. "@param x/y The coordinate of the point as either (\"x y\") or (x,y)\n"
  2192. "@param sceneGroupMask Optional scene group mask.\n"
  2193. "@param sceneLayerMask Optional scene layer mask.\n"
  2194. "@param pickMode Optional mode 'any', 'size' or 'collision' (default is 'size').\n"
  2195. "@return Returns list of object IDs.")
  2196. {
  2197. // The point.
  2198. Vector2 point;
  2199. // The index of the first optional parameter.
  2200. U32 firstArg;
  2201. // Grab the number of elements in the first parameter.
  2202. U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  2203. // ("x y")
  2204. if ((elementCount == 2) && (argc < 8))
  2205. {
  2206. point = Utility::mGetStringElementVector(argv[2]);
  2207. firstArg = 3;
  2208. }
  2209. // (x, y)
  2210. else if ((elementCount == 1) && (argc > 3))
  2211. {
  2212. point = Vector2(dAtof(argv[2]), dAtof(argv[3]));
  2213. firstArg = 4;
  2214. }
  2215. // Invalid
  2216. else
  2217. {
  2218. Con::warnf("Scene::pickPoint() - Invalid number of parameters!");
  2219. return NULL;
  2220. }
  2221. // Calculate scene group mask.
  2222. U32 sceneGroupMask = MASK_ALL;
  2223. if ( (U32)argc > firstArg )
  2224. sceneGroupMask = dAtoi(argv[firstArg]);
  2225. // Calculate scene layer mask.
  2226. U32 sceneLayerMask = MASK_ALL;
  2227. if ( (U32)argc > (firstArg + 1) )
  2228. sceneLayerMask = dAtoi(argv[firstArg + 1]);
  2229. // Calculate pick mode.
  2230. Scene::PickMode pickMode = Scene::PICK_SIZE;
  2231. if ( (U32)argc > (firstArg + 2 ))
  2232. {
  2233. pickMode = Scene::getPickModeEnum(argv[firstArg + 2]);
  2234. }
  2235. if ( pickMode == Scene::PICK_INVALID )
  2236. {
  2237. Con::warnf("Scene::pickPoint() - Invalid pick mode of %s", argv[firstArg + 2]);
  2238. pickMode = Scene::PICK_SIZE;
  2239. }
  2240. // Fetch world query and clear results.
  2241. WorldQuery* pWorldQuery = object->getWorldQuery( true );
  2242. // Set filter.
  2243. WorldQueryFilter queryFilter( sceneLayerMask, sceneGroupMask, true, false, true, true );
  2244. pWorldQuery->setQueryFilter( queryFilter );
  2245. // Perform query.
  2246. if ( pickMode == Scene::PICK_ANY )
  2247. {
  2248. pWorldQuery->anyQueryPoint( point );
  2249. }
  2250. else if ( pickMode == Scene::PICK_SIZE )
  2251. {
  2252. pWorldQuery->renderQueryPoint( point );
  2253. }
  2254. else if ( pickMode == Scene::PICK_COLLISION )
  2255. {
  2256. pWorldQuery->fixtureQueryPoint( point );
  2257. }
  2258. else
  2259. {
  2260. AssertFatal( false, "Unsupported pick mode." );
  2261. }
  2262. // Fetch result count.
  2263. const U32 resultCount = pWorldQuery->getQueryResultsCount();
  2264. // Finish if no results.
  2265. if ( resultCount == 0 )
  2266. return NULL;
  2267. // Fetch results.
  2268. typeWorldQueryResultVector& queryResults = pWorldQuery->getQueryResults();
  2269. // Set Max Buffer Size.
  2270. const U32 maxBufferSize = 4096;
  2271. // Create Returnable Buffer.
  2272. char* pBuffer = Con::getReturnBuffer(maxBufferSize);
  2273. // Set Buffer Counter.
  2274. U32 bufferCount = 0;
  2275. // Add Picked Objects to List.
  2276. for ( U32 n = 0; n < resultCount; n++ )
  2277. {
  2278. // Output Object ID.
  2279. bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", queryResults[n].mpSceneObject->getId() );
  2280. // Finish early if we run out of buffer space.
  2281. if ( bufferCount >= maxBufferSize )
  2282. {
  2283. // Warn.
  2284. Con::warnf("Scene::pickPoint() - Too many items picked to return to scripts!");
  2285. break;
  2286. }
  2287. }
  2288. // Clear world query.
  2289. pWorldQuery->clearQuery();
  2290. // Return buffer.
  2291. return pBuffer;
  2292. }
  2293. //-----------------------------------------------------------------------------
  2294. ConsoleMethod(Scene, setDebugOn, void, 3, 2 + DEBUG_MODE_COUNT, "(debugOptions) Sets Debug option(s) on.\n"
  2295. "@param debugOptions Either a list of debug modes (comma-separated), or a string with the modes (space-separated)\n"
  2296. "@return No return value.")
  2297. {
  2298. // Reset the mask.
  2299. U32 mask = 0;
  2300. // Grab the element count of the first parameter.
  2301. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  2302. // Make sure we get at least one number.
  2303. if (elementCount < 1)
  2304. {
  2305. Con::warnf( "Scene::setDebugOn() - Invalid number of parameters!" );
  2306. return;
  2307. }
  2308. // Space-separated list.
  2309. if (argc == 3)
  2310. {
  2311. // Convert the string to a mask.
  2312. for (U32 i = 0; i < elementCount; i++)
  2313. {
  2314. // Fetch the debug option.
  2315. const char* pDebugOption = Utility::mGetStringElement( argv[2], i );
  2316. Scene::DebugOption debugOption = Scene::getDebugOptionEnum( pDebugOption );
  2317. // Is the option valid?
  2318. if ( debugOption == Scene::SCENE_DEBUG_INVALID )
  2319. {
  2320. // No, so warn.
  2321. Con::warnf( "Scene::setDebugOn() - Invalid debug option '%s' specified.", pDebugOption );
  2322. continue;
  2323. }
  2324. // Merge into mask.
  2325. mask |= debugOption;
  2326. }
  2327. }
  2328. // Comma-separated list.
  2329. else
  2330. {
  2331. // Convert the list to a mask.
  2332. for (U32 i = 2; i < (U32)argc; i++)
  2333. {
  2334. // Fetch the debug option.
  2335. const char* pDebugOption = argv[i];
  2336. Scene::DebugOption debugOption = Scene::getDebugOptionEnum( argv[i] );
  2337. // Is the option valid?
  2338. if ( debugOption == Scene::SCENE_DEBUG_INVALID )
  2339. {
  2340. // No, so warn.
  2341. Con::warnf( "Scene::setDebugOn() - Invalid debug option '%s' specified.", pDebugOption );
  2342. continue;
  2343. }
  2344. // Merge into mask.
  2345. mask |= debugOption;
  2346. }
  2347. }
  2348. // Set debug mask.
  2349. object->setDebugOn(mask);
  2350. }
  2351. //-----------------------------------------------------------------------------
  2352. ConsoleMethod(Scene, setDebugOff, void, 3, 2 + DEBUG_MODE_COUNT, "(debugOptions) Sets Debug options(s) off.\n"
  2353. "@param debugOptions Either a list of debug modes to turn off (comma-separated) or a string (space-separated)\n"
  2354. "@return No return value.")
  2355. {
  2356. // Reset the mask.
  2357. U32 mask = 0;
  2358. // Grab the element count of the first parameter.
  2359. const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
  2360. // Make sure we get at least one number.
  2361. if (elementCount < 1)
  2362. {
  2363. Con::warnf( "Scene::setDebugOff() - Invalid number of parameters!" );
  2364. return;
  2365. }
  2366. // Space-separated list.
  2367. if (argc == 3)
  2368. {
  2369. // Convert the string to a mask.
  2370. for (U32 i = 0; i < elementCount; i++)
  2371. {
  2372. // Fetch the debug option.
  2373. const char* pDebugOption = Utility::mGetStringElement( argv[2], i );
  2374. Scene::DebugOption debugOption = Scene::getDebugOptionEnum( pDebugOption );
  2375. // Is the option valid?
  2376. if ( debugOption == Scene::SCENE_DEBUG_INVALID )
  2377. {
  2378. // No, so warn.
  2379. Con::warnf( "Scene::setDebugOff() - Invalid debug option '%s' specified.", pDebugOption );
  2380. continue;
  2381. }
  2382. // Merge into mask.
  2383. mask |= debugOption;
  2384. }
  2385. }
  2386. // Comma-separated list.
  2387. else
  2388. {
  2389. // Convert the list to a mask.
  2390. for (U32 i = 2; i < (U32)argc; i++)
  2391. {
  2392. // Fetch the debug option.
  2393. const char* pDebugOption = argv[i];
  2394. Scene::DebugOption debugOption = Scene::getDebugOptionEnum( argv[i] );
  2395. // Is the option valid?
  2396. if ( debugOption == Scene::SCENE_DEBUG_INVALID )
  2397. {
  2398. // No, so warn.
  2399. Con::warnf( "Scene::setDebugOff() - Invalid debug option '%s' specified.", pDebugOption );
  2400. continue;
  2401. }
  2402. // Merge into mask.
  2403. mask |= debugOption;
  2404. }
  2405. }
  2406. // Set debug mask.
  2407. object->setDebugOff(mask);
  2408. }
  2409. //-----------------------------------------------------------------------------
  2410. ConsoleMethod(Scene, getDebugOn, const char*, 2, 2, "() Gets the state of the debug modes.\n"
  2411. "@return Returns a space separated list of debug modes that are active.")
  2412. {
  2413. // Fetch debug mask,.
  2414. const U32 debugMask = object->getDebugMask();
  2415. // Fetch a return buffer.
  2416. S32 bufferSize = 1024;
  2417. char* pReturnBuffer = Con::getReturnBuffer(bufferSize);
  2418. *pReturnBuffer = 0;
  2419. char* pWriteCursor = pReturnBuffer;
  2420. // Iterate debug mask.
  2421. for( U32 bit = 0; bit < 32; ++bit )
  2422. {
  2423. // Calculate debug mask bit.
  2424. const S32 debugBit = 1 << bit;
  2425. if ( (debugMask & debugBit) == 0 )
  2426. continue;
  2427. // Format option.
  2428. const S32 size = dSprintf( pWriteCursor, bufferSize, "%s ", object->getDebugOptionDescription( (Scene::DebugOption)debugBit ) );
  2429. bufferSize -= size;
  2430. pWriteCursor += size;
  2431. }
  2432. return pReturnBuffer;
  2433. }
  2434. //-----------------------------------------------------------------------------
  2435. ConsoleMethod(Scene, setDebugSceneObject, void, 3, 3, "(sceneObject) Sets the scene object to monitor in the debug metrics.\n"
  2436. "@param SceneObject The scene object to monitor in the debug metrics.\n"
  2437. "@return No return value.\n")
  2438. {
  2439. // Fetch scene object Id.
  2440. const SimObjectId sceneObjectId = dAtoi(argv[2]);
  2441. // Find scene object.
  2442. SceneObject* pSceneObject = dynamic_cast<SceneObject*>( Sim::findObject(sceneObjectId) );
  2443. // Sanity!
  2444. if ( !pSceneObject )
  2445. {
  2446. Con::warnf("Scene::setDebugSceneObject() - Could not find scene object %d.", sceneObjectId);
  2447. return;
  2448. }
  2449. // Set debug object.
  2450. object->setDebugSceneObject( pSceneObject );
  2451. }
  2452. //-----------------------------------------------------------------------------
  2453. ConsoleMethod(Scene, getDebugSceneObject, S32, 2, 2, "( Gets the scene object being monitored in the debug metrics.\n"
  2454. "@return The scene object being monitored in the debug metrics (zero if none being monitored).\n")
  2455. {
  2456. // Fetch scene object.
  2457. SceneObject* pSceneObject = object->getDebugSceneObject();
  2458. if ( pSceneObject == NULL )
  2459. return 0;
  2460. return pSceneObject->getId();
  2461. }
  2462. //-----------------------------------------------------------------------------
  2463. ConsoleMethod(Scene, setLayerSortMode, void, 4, 4, "(layer, sortMode) Sets the layer to use the specified render sort mode.\n"
  2464. "@param layer The layer to modify.\n"
  2465. "@param sortMode The sort mode to use on the specified layer.\n"
  2466. "@return No return value." )
  2467. {
  2468. // Fetch the layer.
  2469. const U32 layer = dAtoi(argv[2]);
  2470. // Fetch the sort mode.
  2471. const SceneRenderQueue::RenderSort sortMode = SceneRenderQueue::getRenderSortEnum( argv[3] );
  2472. object->setLayerSortMode( layer, sortMode );
  2473. }
  2474. //-----------------------------------------------------------------------------
  2475. ConsoleMethod(Scene, getLayerSortMode, const char*, 3, 3, "(layer) Gets the render sort mode for the specified layer.\n"
  2476. "@param layer The layer to retrieve.\n"
  2477. "@return The render sort mode for the specified layer." )
  2478. {
  2479. // Fetch the layer.
  2480. const U32 layer = dAtoi(argv[2]);
  2481. // Fetch the sort mode.
  2482. return SceneRenderQueue::getRenderSortDescription( object->getLayerSortMode( layer ) );
  2483. }
  2484. //-----------------------------------------------------------------------------
  2485. ConsoleMethod(Scene, resetDebugStats, void, 2, 2, "() Resets the debug statistics.\n"
  2486. "@return No return value." )
  2487. {
  2488. object->resetDebugStats();
  2489. }
  2490. //-----------------------------------------------------------------------------
  2491. ConsoleMethod(Scene, getFPS, F32, 2, 2, "() Gets the current average frames-per-second.\n"
  2492. "@return The current average frames-per-second.")
  2493. {
  2494. return object->getDebugStats().fps;
  2495. }
  2496. //-----------------------------------------------------------------------------
  2497. ConsoleMethod(Scene, getMinFPS, F32, 2, 2, "() Gets the minimum average frames-per-second.\n"
  2498. "@return The minimum Faverage frames-per-second.")
  2499. {
  2500. return object->getDebugStats().minFPS;
  2501. }
  2502. //-----------------------------------------------------------------------------
  2503. ConsoleMethod(Scene, getMaxFPS, F32, 2, 2, "() Gets the maximum average frames-per-second.\n"
  2504. "@return The average frames-per-second.")
  2505. {
  2506. return object->getDebugStats().maxFPS;
  2507. }
  2508. //-----------------------------------------------------------------------------
  2509. ConsoleMethod(Scene, getFrameCount, S32, 2, 2, "() Gets the current rendered frame count.\n"
  2510. "@return The current rendered frame count.")
  2511. {
  2512. return (S32)object->getDebugStats().frameCount;
  2513. }
  2514. //-----------------------------------------------------------------------------
  2515. ConsoleMethod(Scene, setBatchingEnabled, void, 3, 3, "( bool enabled ) Sets whether render batching is enabled or not.\n"
  2516. "@param enabled Whether render batching is enabled or not.\n"
  2517. "return No return value.\n" )
  2518. {
  2519. // Fetch args.
  2520. const bool enabled = dAtob(argv[2]);
  2521. // Sets batching enabled.
  2522. object->setBatchingEnabled( enabled );
  2523. }
  2524. //-----------------------------------------------------------------------------
  2525. ConsoleMethod(Scene, getBatchingEnabled, bool, 2, 2, "() Gets whether render batching is enabled or not.\n"
  2526. "return Whether render batching is enabled or not.\n" )
  2527. {
  2528. // Gets batching enabled.
  2529. return object->getBatchingEnabled();
  2530. }
  2531. //-----------------------------------------------------------------------------
  2532. ConsoleMethod(Scene, setIsEditorScene, void, 3, 3, "() Sets whether this is an editor scene.\n"
  2533. "@return No return value.")
  2534. {
  2535. object->setIsEditorScene(dAtob(argv[2]));
  2536. }
  2537. //-----------------------------------------------------------------------------
  2538. ConsoleMethod(Scene, create, const char*, 3, 3, "(type) Creates the specified scene-object derived type and adds it to the scene.\n"
  2539. "@return The scene-object or NULL if not created.")
  2540. {
  2541. // Create the scene object.
  2542. SceneObject* pSceneObject = object->create( argv[2] );
  2543. return pSceneObject == NULL ? NULL : pSceneObject->getIdString();
  2544. }