Scene_ScriptBinding.h 125 KB

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