| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184 |
- //-----------------------------------------------------------------------------
- // Copyright (c) 2013 GarageGames, LLC
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //-----------------------------------------------------------------------------
- ConsoleFunction( getGlobalSceneCount, S32, 1, 1, "() - Gets the system-wide scene count.\n"
- "@return The system-wide scene count." )
- {
- return Scene::getGlobalSceneCount();
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setGravity, void, 3, 4, "(forceX / forceY) The gravity force to apply to all objects in the scene.\n"
- "@param forceX/forceY The direction and magnitude of the force in each direction. Formatted as either (\"forceX forceY\") or (forceX, forceY)\n"
- "@return No return value.\n")
- {
- // The force.
- Vector2 force;
- // Grab the element count.
- U32 elementCount = Utility::mGetStringElementCount(argv[2]);
- // ("forceX forceY")
- if (elementCount == 1)
- {
- force = Vector2(dAtof(argv[2]), dAtof(argv[3]));
- }
- else if (elementCount == 2)
- {
- force = Utility::mGetStringElementVector(argv[2]);
- }
- // Invalid
- else
- {
- Con::warnf("SceneObject::setGravity() - Invalid number of parameters!");
- return;
- }
- // Set gravity.
- object->setGravity(force);
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getGravity, const char*, 2, 2, "() Gets the gravity force applied to all objects in the scene.\n"
- "@return The gravity force applied to all objects in the scene." )
- {
- return Vector2(object->getGravity()).scriptThis();
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setVelocityIterations, void, 3, 3, "(int iterations) Sets the number of velocity iterations the physics solver uses.\n"
- "@return No return value.")
- {
- object->setVelocityIterations( dAtoi(argv[2]) );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getVelocityIterations, S32, 2, 2, "() Gets the number of velocity iterations the physics solver uses.\n"
- "(@return The number of velocity iterations the physics solver uses." )
- {
- return object->getVelocityIterations();
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setPositionIterations, void, 3, 3, "(int iterations) Sets the number of position iterations the physics solver uses.\n"
- "@return No return value.")
- {
- object->setPositionIterations( dAtoi(argv[2]) );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getPositionIterations, S32, 2, 2, "() Gets the number of position iterations the physics solver uses.\n"
- "(@return The number of position iterations the physics solver uses." )
- {
- return object->getPositionIterations();
- }
- //-----------------------------------------------------------------------------
- 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."
- "@param red The red value.\n"
- "@param green The green value.\n"
- "@param blue The blue value.\n"
- "@param alpha The alpha value.\n"
- "@return No return Value.")
- {
- // The colors.
- F32 red;
- F32 green;
- F32 blue;
- F32 alpha = 1.0f;
- // Space separated.
- if (argc == 3)
- {
- // Grab the element count.
- const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
- // Has a single argument been specified?
- if ( elementCount == 1 )
- {
- object->setDataField( StringTable->insert("BackgroundColor"), NULL, argv[2] );
- return;
- }
- // ("R G B [A]")
- if ((elementCount == 3) || (elementCount == 4))
- {
- // Extract the color.
- red = dAtof(Utility::mGetStringElement(argv[2], 0));
- green = dAtof(Utility::mGetStringElement(argv[2], 1));
- blue = dAtof(Utility::mGetStringElement(argv[2], 2));
- // Grab the alpha if it's there.
- if (elementCount > 3)
- alpha = dAtof(Utility::mGetStringElement(argv[2], 3));
- }
- // Invalid.
- else
- {
- Con::warnf("Scene::setBackgroundColor() - Invalid Number of parameters!");
- return;
- }
- }
- // (R, G, B)
- else if (argc >= 5)
- {
- red = dAtof(argv[2]);
- green = dAtof(argv[3]);
- blue = dAtof(argv[4]);
- // Grab the alpha if it's there.
- if (argc > 5)
- alpha = dAtof(argv[5]);
- }
- // Invalid.
- else
- {
- Con::warnf("Scene::setBackgroundColor() - Invalid Number of parameters!");
- return;
- }
- // Set background color.
- object->setBackgroundColor(ColorF(red, green, blue, alpha) );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getBackgroundColor, const char*, 2, 2, "Gets the background color for the scene.\n"
- "@return (float red / float green / float blue / float alpha) The background color for the scene.")
- {
- // Get the background color.
- const ColorF& color = object->getBackgroundColor();
- // Fetch color name.
- StringTableEntry colorName = StockColor::name( color );
- // Return the color name if it's valid.
- if ( colorName != StringTable->EmptyString )
- return colorName;
- // Create Returnable Buffer.
- char* pBuffer = Con::getReturnBuffer(64);
- // Format Buffer.
- dSprintf(pBuffer, 64, "%g %g %g %g", color.red, color.green, color.blue, color.alpha );
- // Return buffer.
- return pBuffer;
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setUseBackgroundColor, void, 3, 3, "Sets whether to use the scene background color or not.\n"
- "@param useBackgroundColor Whether to use the scene background color or not.\n"
- "@return No return value." )
- {
- // Fetch flag.
- const bool useBackgroundColor = dAtob(argv[2]);
- // Set the flag.
- object->setUseBackgroundColor( useBackgroundColor );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getUseBackgroundColor, bool, 2, 2, "Gets whether the scene background color is in use or not.\n"
- "@return Whether the scene background color is in use or not." )
- {
- // Get the flag.
- return object->getUseBackgroundColor();
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, add, void, 3, 3, "(sceneObject) Add the SceneObject to the scene.\n"
- "@param sceneObject The SceneObject to add to the scene.\n"
- "@return No return value.")
- {
- // Find the specified object.
- SceneObject* pSceneObject = dynamic_cast<SceneObject*>(Sim::findObject(argv[2]));
- // Did we find the object?
- if ( !pSceneObject )
- {
- // No, so warn.
- Con::warnf("Scene::addToScene() - Could not find the specified object '%s'.", argv[2]);
- return;
- }
- // Add to Scene.
- object->addToScene( pSceneObject );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, remove, void, 3, 3, "(sceneObject) Remove the SceneObject from the scene.\n"
- "@param sceneObject The SceneObject to remove from the scene.\n"
- "@return No return value.")
- {
- // Find the specified object.
- SceneObject* pSceneObject = dynamic_cast<SceneObject*>(Sim::findObject(argv[2]));
- // Did we find the object?
- if ( !pSceneObject )
- {
- // No, so warn.
- Con::warnf("Scene::removeFromScene() - Could not find the specified object '%s'.", argv[2]);
- return;
- }
- // Remove from Scene.
- object->removeFromScene( pSceneObject );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, clear, void, 2, 3, "([deleteObjects]) Clear the scene of all scene objects.\n"
- "@param deleteObjects A boolean flag that sets whether to delete the objects as well as remove them from the scene (default is true).\n"
- "@return No return value.")
- {
- // Calculate 'Delete Objects' flag.
- bool deleteObjects;
- if ( argc >= 3 )
- deleteObjects = dAtob( argv[2] );
- else
- deleteObjects = true;
- // Clear Scene.
- object->clearScene( deleteObjects );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getCount, S32, 2, 2, "() Gets the count of scene objects in the scnee.\n"
- "@return Returns the number of scene objects in current scene as an integer.")
- {
- // Get Scene Object-Count.
- return object->getSceneObjectCount();
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getObject, S32, 3, 3, "(sceneObjectIndex) Gets the scene object at the selected index.\n"
- "@param sceneObjectIndex The index of the desired object\n"
- "@return The scene object at the specified index.")
- {
- // Fetch Object Index.
- const U32 objectIndex = dAtoi(argv[2]);
- // Fetch scene object count.
- const U32 sceneObjectCount = object->getSceneObjectCount();
- // Sanity!
- if ( objectIndex >= sceneObjectCount )
- {
- // Error so warn.
- Con::warnf("Scene::getObject() - Cannot retrieve specified object index (%d) as there are only (%d) object(s) in the scene!", objectIndex, sceneObjectCount );
- // Return no object.
- return 0;
- }
- // Fetch Scene Object.
- const SceneObject* pSceneObject = object->getSceneObject( objectIndex );
- // Check Object.
- if ( pSceneObject != NULL )
- {
- // No error so return object id.
- return pSceneObject->getId();
- }
- else
- {
- // Error so warn.
- Con::warnf("Scene::getObject() - Cannot retrieve specified object index (%d)!", objectIndex);
- // Return no object.
- return 0;
- }
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getSceneObjectList, const char*, 2, 2, "() Gets the Scene Object-List.\n"
- "@return Returns a string with a list of object IDs")
- {
- // Scene Object-List.
- Vector<SceneObject*> objList;
- // Finish here if there are no scene objects.
- U32 objCount = object->getSceneObjects( objList );
- if( objCount == 0 )
- return NULL;
- // Our return buffer will be 6 times the size of our object list (4 for Id (+1 for future size?) + 1 for space).
- U32 maxBufferSize = objCount * 12;
- // Create Returnable Buffer.
- char *pBuffer = Con::getReturnBuffer( maxBufferSize );
- // Set Buffer Counter.
- U32 bufferCount = 0;
- // Iterate through the list and generate an id string list to return
- for ( S32 n = 0; n < objList.size(); n++ )
- {
- // Output Object ID.
- bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", objList[n]->getId() );
- // Finish early if we run out of buffer space.
- if ( bufferCount >= maxBufferSize )
- {
- // Warn.
- Con::warnf("Scene::getSceneObjectList() - Not enough space to return all %d objects!", objList.size());
- break;
- }
- }
- // Return buffer.
- return pBuffer;
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, mergeScene, void, 3, 3, "(scene) Merges the specified scene into this scene by cloning the scenes contents.")
- {
- // Find the specified scene.
- Scene* pScene = Sim::findObject<Scene>( argv[2] );
- // Did we find the scene?
- if ( pScene == NULL )
- {
- // No, so warn.
- Con::warnf( "Scene::mergeScene() - Could not find the specified scene '%s'.", argv[2] );
- return;
- }
- object->mergeScene( pScene );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getControllers, const char*, 2, 2, "() Gets the Scene Controllers.\n"
- "@return Gets the scene controllers.")
- {
- // Fetch the scene controllers.
- SimSet* pControllerSet = object->getControllers();
- return ( pControllerSet == NULL ) ? StringTable->EmptyString : pControllerSet->getIdString();
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getSceneTime, F32, 2, 2, "() Gets the Scene Time.\n"
- "@return Returns the time as a floating point number\n")
- {
- // Get Scene Time.
- return object->getSceneTime();
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setScenePause, void, 3, 3, "(status) Sets scene pause status.\n"
- "@return No return value.")
- {
- // Set Scene Pause.
- object->setScenePause( dAtob(argv[2]) );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getScenePause, bool, 2, 2, "() Gets scene pause status.\n"
- "@return Returns a boolean value. True if pause status, false otherwise.")
- {
- // Get Scene Pause.
- return object->getScenePause();
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getJointCount, S32, 2, 2, "() Gets the joint count.\n"
- "@return Returns no value")
- {
- return object->getJointCount();
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, isJoint, bool, 3, 3, "(int jointId) Gets whether the joint Id is valid or not.\n"
- "@param jointId The Id of the joint.\n"
- "@return whether the joint Id is valid or not." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi( argv[2] );
- return object->findJoint( jointId ) != NULL;
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getJointType, const char*, 3, 3, "(int jointId) Gets the joint type of the specified joint Id.\n"
- "@param jointId The Id of the joint.\n"
- "@return The type of joint of the specified joint Id." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi( argv[2] );
- // Fetch joint type.
- const b2JointType jointType = object->getJointType( jointId );
- // Ignore if invalid joint.
- if ( jointType == e_unknownJoint )
- return StringTable->EmptyString;
- return Scene::getJointTypeDescription( jointType );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, deleteJoint, bool, 3, 3, "(int jointId) Deletes the specified joint Id.\n"
- "@param jointId The Id of the joint.\n"
- "@return Whether the joint was successfully deleted or not." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi( argv[2] );
- return object->deleteJoint( jointId );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, createDistanceJoint, S32, 4, 12, "(sceneObjectA, sceneObjectB, [localAnchorA X/Y], [localAnchorB X/Y], [distance], [frequency], [dampingRatio], [collideConnected]) Creates a distance joint.\n"
- "@param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
- "@param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
- "@param localAnchorA The local point of the first scene object where the joint connects.\n"
- "@param localAnchorB The local point of the second scene object where the joint connects.\n"
- "@param distance The distance the joint should maintain between scene objects. The default is the distance currently between the scene objects.\n"
- "@param frequency The mass-spring-damper frequency in Hertz. A value of 0 disables softness (default).\n"
- "@param dampingRatio The damping ratio. 0 = no damping (default), 1 = critical damping.\n"
- "@param collideConnected Whether the scene objects can collide with each other while connected with this joint.\n"
- "@return The joint Id (-1 if error).")
- {
- // Fetch scene object references.
- const char* sceneObjectA = argv[2];
- const char* sceneObjectB = argv[3];
- SceneObject* pSceneObjectA = NULL;
- SceneObject* pSceneObjectB = NULL;
- // Fetch scene object.
- if ( *sceneObjectA != 0 )
- {
- pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
- if ( !pSceneObjectA )
- Con::warnf("Scene::createDistanceJoint() - Could not find scene object %d.", sceneObjectA);
- }
- // Fetch scene object.
- if (*sceneObjectB != 0 )
- {
- pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
- if ( !pSceneObjectB )
- Con::warnf("Scene::createDistanceJoint() - Could not find scene object %d.", sceneObjectB);
- }
- if ( argc == 4 )
- {
- return object->createDistanceJoint( pSceneObjectA, pSceneObjectB );
- }
- // Local anchor A.
- const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
- b2Vec2 localAnchorA;
- S32 nextArg = 5;
- if ( anchorAElementCount == 1 && argc > 5 )
- {
- localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
- nextArg = 6;
- }
- else if ( anchorAElementCount == 2 )
- {
- localAnchorA = Utility::mGetStringElementVector(argv[4]);
- }
- // Invalid
- else
- {
- Con::warnf("Scene::createDistanceJoint() - Invalid number of parameters!");
- return -1;
- }
- if ( argc <= nextArg )
- {
- return object->createDistanceJoint( pSceneObjectA, pSceneObjectB, localAnchorA );
- }
- // Local anchor B.
- const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
- b2Vec2 localAnchorB;
- if ( anchorBElementCount == 1 && argc > (nextArg+1) )
- {
- localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
- nextArg += 2;
- }
- else if ( anchorBElementCount == 2 )
- {
- localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
- }
- // Invalid
- else
- {
- Con::warnf("Scene::createDistanceJoint() - Invalid number of parameters!");
- return -1;
- }
- if ( argc <= nextArg )
- {
- return object->createDistanceJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB );
- }
- // Fetch length.
- const F32 length = dAtof(argv[nextArg++]);
- if ( argc <= nextArg )
- {
- return object->createDistanceJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, length );
- }
- // Fetch frequency (Hertz).
- const F32 frequency = dAtof(argv[nextArg++]);
- if ( argc <= nextArg )
- {
- return object->createDistanceJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, length, frequency );
- }
- // Fetch damping ratio.
- const F32 dampingRatio = dAtof(argv[nextArg++]);
- if ( argc <= nextArg )
- {
- return object->createDistanceJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, length, frequency, dampingRatio );
- }
- // Fetch collide connected.
- const bool collideConnected = dAtob(argv[nextArg++]);
- return object->createDistanceJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, length, frequency, dampingRatio, collideConnected );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setDistanceJointLength, void, 4, 4, "(jointId, length) Sets the distance the joint should maintain between scene objects.\n"
- "@param jointId The Id of the joint to use.\n"
- "@param length The length the joint should maintain between scene objects.\n"
- "@return Returns no value." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Fetch args.
- const F32 length = dAtof(argv[3]);
- // Access joint.
- object->setDistanceJointLength( jointId, length );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getDistanceJointLength, F32, 3, 3, "(jointId) Gets the distance the joint should maintain between scene objects.\n"
- "@param jointId The Id of the joint to use.\n"
- "@return Returns the distance the joint should maintain between scene objects (-1 indicates error)." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Access joint.
- return object->getDistanceJointLength( jointId );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setDistanceJointFrequency, void, 4, 4, "(jointId, frequency) Sets the mass-spring-damper frequency in Hertz.\n"
- "@param jointId The Id of the joint to use.\n"
- "@param frequency The mass-spring-damper frequency in Hertz. A value of 0 disables softness.\n"
- "@return Returns no value." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Fetch args.
- const F32 frequency = dAtof(argv[3]);
- // Access joint.
- object->setDistanceJointFrequency( jointId, frequency );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getDistanceJointFrequency, F32, 3, 3, "(jointId) Gets the mass-spring-damper frequency in Hertz.\n"
- "@param jointId The Id of the joint to use.\n"
- "@return Returns the mass-spring-damper frequency in Hertz (-1 indicates error)." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Access joint.
- return object->getDistanceJointFrequency( jointId );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setDistanceJointDampingRatio, void, 4, 4, "(jointId, dampingRatio) Sets the damping ratio.\n"
- "@param jointId The Id of the joint to use.\n"
- "@param dampingRatio The damping ratio. 0 = no damping, 1 = critical damping.\n"
- "@return Returns no value." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Fetch args.
- const F32 dampingRatio = dAtof(argv[3]);
- // Access joint.
- object->setDistanceJointDampingRatio( jointId, dampingRatio );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getDistanceJointDampingRatio, F32, 3, 3, "(jointId) Gets the damping ratio.\n"
- "@param jointId The Id of the joint to use.\n"
- "@return Returns the damping ratio (-1 indicates error)." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Access joint.
- return object->getDistanceJointDampingRatio( jointId );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, createRopeJoint, S32, 4, 10, "(sceneObjectA, sceneObjectB, [localAnchorA X/Y], [localAnchorB X/Y], [maxLength], [collideConnected]) Creates a rope joint.\n"
- "@param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
- "@param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
- "@param localAnchorA The local point of the first scene object where the joint connects.\n"
- "@param localAnchorB The local point of the second scene object where the joint connects.\n"
- "@param maxLength The maximum rigid length of the rope.\n"
- "@param collideConnected Whether the scene objects can collide with each other while connected with this joint.\n"
- "@return The joint Id (-1 if error).")
- {
- // Fetch scene object references.
- const char* sceneObjectA = argv[2];
- const char* sceneObjectB = argv[3];
- SceneObject* pSceneObjectA = NULL;
- SceneObject* pSceneObjectB = NULL;
- // Fetch scene object.
- if ( *sceneObjectA != 0 )
- {
- pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
- if ( !pSceneObjectA )
- Con::warnf("Scene::createRopeJoint() - Could not find scene object %d.", sceneObjectA);
- }
- // Fetch scene object.
- if (*sceneObjectB != 0 )
- {
- pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
- if ( !pSceneObjectB )
- Con::warnf("Scene::createRopeJoint() - Could not find scene object %d.", sceneObjectB);
- }
- if ( argc == 4 )
- {
- return object->createRopeJoint( pSceneObjectA, pSceneObjectB );
- }
- // Local anchor A.
- const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
- b2Vec2 localAnchorA;
- S32 nextArg = 5;
- if ( anchorAElementCount == 1 && argc > 5 )
- {
- localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
- nextArg = 6;
- }
- else if ( anchorAElementCount == 2 )
- {
- localAnchorA = Utility::mGetStringElementVector(argv[4]);
- }
- // Invalid
- else
- {
- Con::warnf("Scene::createRopeJoint() - Invalid number of parameters!");
- return -1;
- }
- if ( argc <= nextArg )
- {
- return object->createRopeJoint( pSceneObjectA, pSceneObjectB, localAnchorA );
- }
- // Local anchor B.
- const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
- b2Vec2 localAnchorB;
- if ( anchorBElementCount == 1 && argc > (nextArg+1) )
- {
- localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
- nextArg += 2;
- }
- else if ( anchorBElementCount == 2 )
- {
- localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
- }
- // Invalid
- else
- {
- Con::warnf("Scene::createRopeJoint() - Invalid number of parameters!");
- return -1;
- }
- if ( argc <= nextArg )
- {
- return object->createRopeJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB );
- }
- // Fetch maximum length.
- const F32 maxLength = dAtof(argv[nextArg++]);
- if ( argc <= nextArg )
- {
- return object->createRopeJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, maxLength );
- }
- // Fetch collide connected.
- const bool collideConnected = dAtob(argv[nextArg++]);
- return object->createRopeJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, maxLength, collideConnected );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setRopeJointMaxLength, void, 4, 4, "(jointId, maxLength) Sets the maximum rigid length of the rope.\n"
- "@param jointId The Id of the joint to use.\n"
- "@param maxLength The maximum rigid length of the rope.\n"
- "@return Returns no value." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Fetch args.
- const F32 maxLength = dAtof(argv[3]);
- // Access joint.
- object->setRopeJointMaxLength( jointId, maxLength );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getRopeJointMaxLength, F32, 3, 3, "(jointId) Gets the maximum rigid length of the rope.\n"
- "@param jointId The Id of the joint to use.\n"
- "@return Returns the maximum rigid length of the rope (-1 indicates error)." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Access joint.
- return object->getRopeJointMaxLength( jointId );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, createRevoluteJoint, S32, 4, 9, "(sceneObjectA, sceneObjectB, [localAnchorA X/Y], [localAnchorB X/Y], [collideConnected]) Creates a revolute joint.\n"
- "@param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
- "@param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
- "@param localAnchorA The local point of the first scene object where the joint connects.\n"
- "@param localAnchorB The local point of the second scene object where the joint connects.\n"
- "@param collideConnected Whether the scene objects can collide with each other while connected with this joint.\n"
- "@return The joint Id (-1 if error).")
- {
- // Fetch scene object references.
- const char* sceneObjectA = argv[2];
- const char* sceneObjectB = argv[3];
- SceneObject* pSceneObjectA = NULL;
- SceneObject* pSceneObjectB = NULL;
- // Fetch scene object.
- if ( *sceneObjectA != 0 )
- {
- pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
- if ( !pSceneObjectA )
- Con::warnf("Scene::createRevoluteJoint() - Could not find scene object %d.", sceneObjectA);
- }
- // Fetch scene object.
- if ( *sceneObjectB != 0 )
- {
- pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
- if ( !pSceneObjectB )
- Con::warnf("Scene::createRevoluteJoint() - Could not find scene object %d.", sceneObjectB);
- }
- if ( argc == 4 )
- {
- return object->createRevoluteJoint( pSceneObjectA, pSceneObjectB );
- }
- // Local anchor A.
- const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
- b2Vec2 localAnchorA;
- S32 nextArg = 5;
- if ( anchorAElementCount == 1 && argc > 5 )
- {
- localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
- nextArg = 6;
- }
- else if ( anchorAElementCount == 2 )
- {
- localAnchorA = Utility::mGetStringElementVector(argv[4]);
- }
- // Invalid
- else
- {
- Con::warnf("Scene::createRevoluteJoint() - Invalid number of parameters!");
- return -1;
- }
- if ( argc <= nextArg )
- {
- return object->createRevoluteJoint( pSceneObjectA, pSceneObjectB, localAnchorA );
- }
- // Local anchor B.
- const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
- b2Vec2 localAnchorB;
- if ( anchorBElementCount == 1 && argc > (nextArg+1) )
- {
- localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
- nextArg += 2;
- }
- else if ( anchorBElementCount == 2 )
- {
- localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
- }
- // Invalid
- else
- {
- Con::warnf("Scene::createRevoluteJoint() - Invalid number of parameters!");
- return -1;
- }
- if ( argc <= nextArg )
- {
- return object->createRevoluteJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB );
- }
- // Fetch collide connected.
- const bool collideConnected = dAtob(argv[nextArg++]);
- return object->createRevoluteJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, collideConnected );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setRevoluteJointLimit, void, 4, 6, "(jointId, enableLimit, [lowerAngle], [upperAngle]) Sets whether the joint has angular limits or not and the limits themselves.\n"
- "@param jointId The Id of the joint to use.\n"
- "@param enableLimit Whether the joint has angular limits or not.\n"
- "@param lowerAngle The lower angle of the angular limit.\n"
- "@param upperAngle The upper angle of the angular limit.\n"
- "@return Returns no value." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Fetch args.
- const bool enableLimit = dAtob(argv[3]);
- const F32 lowerAngle = argc > 4 ? mDegToRad( dAtof(argv[4]) ) : 0.0f;
- const F32 upperAngle = argc > 5 ? mDegToRad( dAtof(argv[5]) ) : lowerAngle;
- // Access joint.
- object->setRevoluteJointLimit( jointId, enableLimit, lowerAngle, upperAngle );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getRevoluteJointLimit, const char*, 3, 3, "(jointId) Gets whether the joint has angular limits or not and the limits themselves.\n"
- "@param jointId The Id of the joint to use.\n"
- "@return Returns whether the joint has angular limits or not and the limits themselves (empty string indicates error)." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Args.
- bool enableLimit;
- F32 lowerAngle;
- F32 upperAngle;
- // Access joint.
- if ( !object->getRevoluteJointLimit( jointId, enableLimit, lowerAngle, upperAngle ) )
- {
- return NULL;
- }
- // Format output.
- char* pBuffer = Con::getReturnBuffer(64);
- dSprintf( pBuffer, 64, "%d %g %g", enableLimit, mRadToDeg(lowerAngle), mRadToDeg(upperAngle) );
- return pBuffer;
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setRevoluteJointMotor, void, 4, 6, "(jointId, enableMotor, [motorSpeed], [maxMotorTorque]) Sets whether the joint has a motor or not and the motor settings.\n"
- "@param jointId The Id of the joint to use.\n"
- "@param enableMotor Whether the joint has a motor or not.\n"
- "@param motorSpeed The motor speed (degrees per/sec).\n"
- "@param maxMotorTorque The maximum motor torque used to achieve the specified motor speed (N-m).\n"
- "@return Returns no value." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Fetch args.
- const bool enableMotor = dAtob(argv[3]);
- const F32 motorSpeed = argc > 4 ? mDegToRad( dAtof(argv[4]) ) : 0.0f;
- const F32 maxMotorTorque = argc > 5 ? dAtof(argv[5]) : 0.0f;
- // Access joint.
- object->setRevoluteJointMotor( jointId, enableMotor, motorSpeed, maxMotorTorque );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getRevoluteJointMotor, const char*, 3, 3, "(jointId) Gets whether the joint has a motor or not and the motor settings.\n"
- "@param jointId The Id of the joint to use.\n"
- "@return Returns whether the joint has a motor or not and the motor settings (empty string indicates error)." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Args.
- bool enableMotor;
- F32 motorSpeed;
- F32 maxMotorTorque;
- // Access joint.
- if ( !object->getRevoluteJointLimit( jointId, enableMotor, motorSpeed, maxMotorTorque ) )
- {
- return NULL;
- }
- // Format output.
- char* pBuffer = Con::getReturnBuffer(64);
- dSprintf( pBuffer, 64, "%d %g %g", enableMotor, mRadToDeg(motorSpeed), maxMotorTorque );
- return pBuffer;
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, createWeldJoint, S32, 4, 11, "(sceneObjectA, sceneObjectB, [localAnchorA X/Y], [localAnchorB X/Y], [frequency], [dampingRatio], [collideConnected]) Creates a weld joint.\n"
- "@param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
- "@param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
- "@param localAnchorA The local point of the first scene object where the joint connects.\n"
- "@param localAnchorB The local point of the second scene object where the joint connects.\n"
- "@param frequency The mass-spring-damper frequency in Hertz. A value of 0 disables softness (default).\n"
- "@param dampingRatio The damping ratio. 0 = no damping (default), 1 = critical damping.\n"
- "@param collideConnected Whether the scene objects can collide with each other while connected with this joint.\n"
- "@return The joint Id (-1 if error).")
- {
- // Fetch scene object references.
- const char* sceneObjectA = argv[2];
- const char* sceneObjectB = argv[3];
- SceneObject* pSceneObjectA = NULL;
- SceneObject* pSceneObjectB = NULL;
- // Fetch scene object.
- if ( *sceneObjectA != 0 )
- {
- pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
- if ( !pSceneObjectA )
- Con::warnf("Scene::createWeldJoint() - Could not find scene object %d.", sceneObjectA);
- }
- // Fetch scene object.
- if ( *sceneObjectB != 0 )
- {
- pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
- if ( !pSceneObjectB )
- Con::warnf("Scene::createWeldJoint() - Could not find scene object %d.", sceneObjectB);
- }
- if ( argc == 4 )
- {
- return object->createWeldJoint( pSceneObjectA, pSceneObjectB );
- }
- // Local anchor A.
- const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
- b2Vec2 localAnchorA;
- S32 nextArg = 5;
- if ( anchorAElementCount == 1 && argc > 5 )
- {
- localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
- nextArg = 6;
- }
- else if ( anchorAElementCount == 2 )
- {
- localAnchorA = Utility::mGetStringElementVector(argv[4]);
- }
- // Invalid
- else
- {
- Con::warnf("Scene::createWeldJoint() - Invalid number of parameters!");
- return -1;
- }
- if ( argc <= nextArg )
- {
- return object->createWeldJoint( pSceneObjectA, pSceneObjectB, localAnchorA );
- }
- // Local anchor B.
- const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
- b2Vec2 localAnchorB;
- if ( anchorBElementCount == 1 && argc > (nextArg+1) )
- {
- localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
- nextArg += 2;
- }
- else if ( anchorBElementCount == 2 )
- {
- localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
- }
- // Invalid
- else
- {
- Con::warnf("Scene::createWeldJoint() - Invalid number of parameters!");
- return -1;
- }
- if ( argc <= nextArg )
- {
- return object->createWeldJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB );
- }
- // Fetch frequency (Hertz).
- const F32 frequency = dAtof(argv[nextArg++]);
- if ( argc <= nextArg )
- {
- return object->createWeldJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, frequency );
- }
- // Fetch damping ratio.
- const F32 dampingRatio = dAtof(argv[nextArg++]);
- if ( argc <= nextArg )
- {
- return object->createWeldJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, frequency, dampingRatio );
- }
- // Fetch collide connected.
- const bool collideConnected = dAtob(argv[nextArg++]);
- return object->createWeldJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, frequency, dampingRatio, collideConnected );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setWeldJointFrequency, void, 4, 4, "(jointId, frequency) Sets the mass-spring-damper frequency in Hertz.\n"
- "@param jointId The Id of the joint to use.\n"
- "@param frequency The mass-spring-damper frequency in Hertz. A value of 0 disables softness.\n"
- "@return Returns no value." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Fetch args.
- const F32 frequency = dAtof(argv[3]);
- // Access joint.
- object->setWeldJointFrequency( jointId, frequency );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getWeldJointFrequency, F32, 3, 3, "(jointId) Gets the mass-spring-damper frequency in Hertz.\n"
- "@param jointId The Id of the joint to use.\n"
- "@return Returns the mass-spring-damper frequency in Hertz (-1 indicates error)." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Access joint.
- return object->getWeldJointFrequency( jointId );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setWeldJointDampingRatio, void, 4, 4, "(jointId, dampingRatio) Sets the damping ratio.\n"
- "@param jointId The Id of the joint to use.\n"
- "@param dampingRatio The damping ratio. 0 = no damping, 1 = critical damping.\n"
- "@return Returns no value." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Fetch args.
- const F32 dampingRatio = dAtof(argv[3]);
- // Access joint.
- object->setWeldJointDampingRatio( jointId, dampingRatio );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getWeldJointDampingRatio, F32, 3, 3, "(jointId) Gets the damping ratio.\n"
- "@param jointId The Id of the joint to use.\n"
- "@return Returns the damping ratio (-1 indicates error)." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Access joint.
- return object->getWeldJointDampingRatio( jointId );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, createWheelJoint, S32, 7, 11, "(sceneObjectA, sceneObjectB, localAnchorA X/Y, localAnchorB X/Y, worldAxis X/Y, [collideConnected]) Creates a wheel joint.\n"
- "@param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
- "@param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
- "@param localAnchorA The local point of the first scene object where the joint connects.\n"
- "@param localAnchorB The local point of the second scene object where the joint connects.\n"
- "@param worldAxis The world axis of the wheel suspension spring.\n"
- "@param collideConnected Whether the scene objects can collide with each other while connected with this joint.\n"
- "@return The joint Id (-1 if error).")
- {
- // Fetch scene object references.
- const char* sceneObjectA = argv[2];
- const char* sceneObjectB = argv[3];
- SceneObject* pSceneObjectA = NULL;
- SceneObject* pSceneObjectB = NULL;
- // Fetch scene object.
- if ( *sceneObjectA != 0 )
- {
- pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
- if ( !pSceneObjectA )
- Con::warnf("Scene::createWheelJoint() - Could not find scene object %d.", sceneObjectA);
- }
- // Fetch scene object.
- if ( *sceneObjectB != 0 )
- {
- pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
- if ( !pSceneObjectB )
- Con::warnf("Scene::createWheelJoint() - Could not find scene object %d.", sceneObjectB);
- }
- // Local anchor A.
- const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
- b2Vec2 localAnchorA;
- S32 nextArg = 5;
- if ( anchorAElementCount == 1 && argc > 5 )
- {
- localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
- nextArg = 6;
- }
- else if ( anchorAElementCount == 2 )
- {
- localAnchorA = Utility::mGetStringElementVector(argv[4]);
- }
- // Invalid
- else
- {
- Con::warnf("Scene::createWheelJoint() - Invalid number of parameters!");
- return -1;
- }
- // Local anchor B.
- const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
- b2Vec2 localAnchorB;
- if ( anchorBElementCount == 1 && argc > (nextArg+1) )
- {
- localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
- nextArg += 2;
- }
- else if ( anchorBElementCount == 2 )
- {
- localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
- }
- // Invalid
- else
- {
- Con::warnf("Scene::createWheelJoint() - Invalid number of parameters!");
- return -1;
- }
- // World axis.
- const U32 worldAxisElementCount = Utility::mGetStringElementCount(argv[nextArg]);
- b2Vec2 worldAxis;
- if ( worldAxisElementCount == 1 && argc > (nextArg+1) )
- {
- worldAxis.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
- nextArg += 2;
- }
- else if ( worldAxisElementCount == 2 )
- {
- worldAxis = Utility::mGetStringElementVector(argv[nextArg++]);
- }
- // Invalid
- else
- {
- Con::warnf("Scene::createWheelJoint() - Invalid number of parameters!");
- return -1;
- }
- if ( argc <= nextArg )
- {
- return object->createWheelJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, worldAxis );
- }
- // Fetch collide connected.
- const bool collideConnected = dAtob(argv[nextArg++]);
- return object->createWheelJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, worldAxis, collideConnected );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setWheelJointMotor, void, 4, 6, "(jointId, enableMotor, [motorSpeed], [maxMotorTorque]) Sets whether the joint has a motor or not and the motor settings.\n"
- "@param jointId The Id of the joint to use.\n"
- "@param enableMotor Whether the joint has a motor or not.\n"
- "@param motorSpeed The motor speed (degrees per/sec).\n"
- "@param maxMotorTorque The maximum motor torque used to achieve the specified motor speed (N-m).\n"
- "@return Returns no value." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Fetch args.
- const bool enableMotor = dAtob(argv[3]);
- const F32 motorSpeed = argc > 4 ? mDegToRad( dAtof(argv[4]) ) : 0.0f;
- const F32 maxMotorTorque = argc > 5 ? dAtof(argv[5]) : 0.0f;
- // Access joint.
- object->setWheelJointMotor( jointId, enableMotor, motorSpeed, maxMotorTorque );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getWheelJointMotor, const char*, 3, 3, "(jointId) Gets whether the joint has a motor or not and the motor settings.\n"
- "@param jointId The Id of the joint to use.\n"
- "@return Returns whether the joint has a motor or not and the motor settings (empty string indicates error)." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Args.
- bool enableMotor;
- F32 motorSpeed;
- F32 maxMotorTorque;
- // Access joint.
- if ( !object->getWheelJointMotor( jointId, enableMotor, motorSpeed, maxMotorTorque ) )
- {
- return NULL;
- }
- // Format output.
- char* pBuffer = Con::getReturnBuffer(64);
- dSprintf( pBuffer, 64, "%d %g %g", enableMotor, mRadToDeg(motorSpeed), maxMotorTorque );
- return pBuffer;
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setWheelJointFrequency, void, 4, 4, "(jointId, frequency) Sets the mass-spring-damper frequency in Hertz.\n"
- "@param jointId The Id of the joint to use.\n"
- "@param frequency The mass-spring-damper frequency in Hertz. A value of 0 disables softness.\n"
- "@return Returns no value." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Fetch args.
- const F32 frequency = dAtof(argv[3]);
- // Access joint.
- object->setWheelJointFrequency( jointId, frequency );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getWheelJointFrequency, F32, 3, 3, "(jointId) Gets the mass-spring-damper frequency in Hertz.\n"
- "@param jointId The Id of the joint to use.\n"
- "@return Returns the mass-spring-damper frequency in Hertz (-1 indicates error)." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Access joint.
- return object->getWheelJointFrequency( jointId );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setWheelJointDampingRatio, void, 4, 4, "(jointId, dampingRatio) Sets the damping ratio.\n"
- "@param jointId The Id of the joint to use.\n"
- "@param dampingRatio The damping ratio. 0 = no damping, 1 = critical damping.\n"
- "@return Returns no value." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Fetch args.
- const F32 dampingRatio = dAtof(argv[3]);
- // Access joint.
- object->setWheelJointDampingRatio( jointId, dampingRatio );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getWheelJointDampingRatio, F32, 3, 3, "(jointId) Gets the damping ratio.\n"
- "@param jointId The Id of the joint to use.\n"
- "@return Returns the damping ratio (-1 indicates error)." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Access joint.
- return object->getWheelJointDampingRatio( jointId );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, createFrictionJoint, S32, 4, 11, "(sceneObjectA, sceneObjectB, [localAnchorA X/Y], [localAnchorB X/Y], [maxForce], [maxTorque], [collideConnected]) Creates a friction joint.\n"
- "@param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
- "@param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
- "@param localAnchorA The local point of the first scene object where the joint connects.\n"
- "@param localAnchorB The local point of the second scene object where the joint connects.\n"
- "@param maxForce The maximum friction force (N).\n"
- "@param maxTorque The maximum torque force (N-m).\n"
- "@param collideConnected Whether the scene objects can collide with each other while connected with this joint.\n"
- "@return The joint Id (-1 if error).")
- {
- // Fetch scene object references.
- const char* sceneObjectA = argv[2];
- const char* sceneObjectB = argv[3];
- SceneObject* pSceneObjectA = NULL;
- SceneObject* pSceneObjectB = NULL;
- // Fetch scene object.
- if ( *sceneObjectA != 0 )
- {
- pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
- if ( !pSceneObjectA )
- Con::warnf("Scene::createFrictionJoint() - Could not find scene object %d.", sceneObjectA);
- }
- // Fetch scene object.
- if ( *sceneObjectB != 0 )
- {
- pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
- if ( !pSceneObjectB )
- Con::warnf("Scene::createFrictionJoint() - Could not find scene object %d.", sceneObjectB);
- }
- if ( argc == 4 )
- {
- return object->createFrictionJoint( pSceneObjectA, pSceneObjectB );
- }
- // Local anchor A.
- const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
- b2Vec2 localAnchorA;
- S32 nextArg = 5;
- if ( anchorAElementCount == 1 && argc > 5 )
- {
- localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
- nextArg = 6;
- }
- else if ( anchorAElementCount == 2 )
- {
- localAnchorA = Utility::mGetStringElementVector(argv[4]);
- }
- // Invalid
- else
- {
- Con::warnf("Scene::createFrictionJoint() - Invalid number of parameters!");
- return -1;
- }
- if ( argc <= nextArg )
- {
- return object->createFrictionJoint( pSceneObjectA, pSceneObjectB, localAnchorA );
- }
- // Local anchor B.
- const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
- b2Vec2 localAnchorB;
- if ( anchorBElementCount == 1 && argc > (nextArg+1) )
- {
- localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
- nextArg += 2;
- }
- else if ( anchorBElementCount == 2 )
- {
- localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
- }
- // Invalid
- else
- {
- Con::warnf("Scene::createFrictionJoint() - Invalid number of parameters!");
- return -1;
- }
- // Fetch maximum force.
- const F32 maxForce = dAtof(argv[nextArg++]);
- if ( argc <= nextArg )
- {
- return object->createFrictionJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, maxForce );
- }
- // Fetch maximum torque.
- const F32 maxTorque = dAtof(argv[nextArg++]);
- if ( argc <= nextArg )
- {
- return object->createFrictionJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, maxForce, maxTorque );
- }
- // Fetch collide connected.
- const bool collideConnected = dAtob(argv[nextArg++]);
- return object->createFrictionJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, maxForce, maxTorque, collideConnected );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setFrictionJointMaxForce, void, 4, 4, "(jointId, maxForce) Sets the maximum friction force.\n"
- "@param jointId The Id of the joint to use.\n"
- "@param maxForce The maximum friction force (N).\n"
- "@return Returns no value." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Fetch args.
- const F32 maxForce = dAtof(argv[3]);
- // Access joint.
- object->setFrictionJointMaxForce( jointId, maxForce );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getFrictionJointMaxForce, F32, 3, 3, "(jointId) Sets the maximum friction force.\n"
- "@param jointId The Id of the joint to use.\n"
- "@return Returns the maximum friction force (-1 indicates error)." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Access joint.
- return object->getFrictionJointMaxForce( jointId );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setFrictionJointMaxTorque, void, 4, 4, "(jointId, maxTorque) Sets the maximum torque force.\n"
- "@param jointId The Id of the joint to use.\n"
- "@param maxTorque The maximum torque force (N).\n"
- "@return Returns no value." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Fetch args.
- const F32 maxTorque = dAtof(argv[3]);
- // Access joint.
- object->setFrictionJointMaxTorque( jointId, maxTorque );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getFrictionJointMaxTorque, F32, 3, 3, "(jointId) Gets the maximum torque force.\n"
- "@param jointId The Id of the joint to use.\n"
- "@return Returns the maximum torque force (-1 indicates error)." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Access joint.
- return object->getFrictionJointMaxTorque( jointId );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, createPrismaticJoint, S32, 7, 11, "(sceneObjectA, sceneObjectB, localAnchorA X/Y, localAnchorB X/Y, worldAxis X/Y, [collideConnected]) Creates a prismatic joint.\n"
- "@param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
- "@param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
- "@param localAnchorA The local point of the first scene object where the joint connects.\n"
- "@param localAnchorB The local point of the second scene object where the joint connects.\n"
- "@param worldAxis The world axis defining the translational degree of freedom.\n"
- "@param collideConnected Whether the scene objects can collide with each other while connected with this joint.\n"
- "@return The joint Id (-1 if error).")
- {
- // Fetch scene object references.
- const char* sceneObjectA = argv[2];
- const char* sceneObjectB = argv[3];
- SceneObject* pSceneObjectA = NULL;
- SceneObject* pSceneObjectB = NULL;
- // Fetch scene object.
- if ( *sceneObjectA != 0 )
- {
- pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
- if ( !pSceneObjectA )
- Con::warnf("Scene::createPrismaticJoint() - Could not find scene object %d.", sceneObjectA);
- }
- // Fetch scene object.
- if ( *sceneObjectB != 0 )
- {
- pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
- if ( !pSceneObjectB )
- Con::warnf("Scene::createPrismaticJoint() - Could not find scene object %d.", sceneObjectB);
- }
- // Local anchor A.
- const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
- b2Vec2 localAnchorA;
- S32 nextArg = 5;
- if ( anchorAElementCount == 1 && argc > 5 )
- {
- localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
- nextArg = 6;
- }
- else if ( anchorAElementCount == 2 )
- {
- localAnchorA = Utility::mGetStringElementVector(argv[4]);
- }
- // Invalid
- else
- {
- Con::warnf("Scene::createPrismaticJoint() - Invalid number of parameters!");
- return -1;
- }
- // Local anchor B.
- const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
- b2Vec2 localAnchorB;
- if ( anchorBElementCount == 1 && argc > (nextArg+1) )
- {
- localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
- nextArg += 2;
- }
- else if ( anchorBElementCount == 2 )
- {
- localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
- }
- // Invalid
- else
- {
- Con::warnf("Scene::createPrismaticJoint() - Invalid number of parameters!");
- return -1;
- }
- // World axis.
- const U32 worldAxisElementCount = Utility::mGetStringElementCount(argv[nextArg]);
- b2Vec2 worldAxis;
- if ( worldAxisElementCount == 1 && argc > (nextArg+1) )
- {
- worldAxis.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
- nextArg += 2;
- }
- else if ( worldAxisElementCount == 2 )
- {
- worldAxis = Utility::mGetStringElementVector(argv[nextArg++]);
- }
- // Invalid
- else
- {
- Con::warnf("Scene::createPrismaticJoint() - Invalid number of parameters!");
- return -1;
- }
- if ( argc <= nextArg )
- {
- return object->createPrismaticJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, worldAxis );
- }
- // Fetch collide connected.
- const bool collideConnected = dAtob(argv[nextArg++]);
- return object->createPrismaticJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, worldAxis, collideConnected );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setPrismaticJointLimit, void, 4, 6, "(jointId, enableLimit, [lowerTranslation], [upperTranslation]) Sets whether the joint has translational limits or not and the limits themselves.\n"
- "@param jointId The Id of the joint to use.\n"
- "@param enableLimit Whether the joint has angular limits or not.\n"
- "@param lowerTranslation The lower translation limit.\n"
- "@param upperTranslation The upper translation limit.\n"
- "@return Returns no value." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Fetch args.
- const bool enableLimit = dAtob(argv[3]);
- const F32 lowerTranslation = argc > 4 ? dAtof(argv[4]) : 0.0f;
- const F32 upperTranslation = argc > 5 ? dAtof(argv[5]) : lowerTranslation;
- // Access joint.
- object->setPrismaticJointLimit( jointId, enableLimit, lowerTranslation, upperTranslation );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getPrismaticJointLimit, const char*, 3, 3, "(jointId) Gets whether the joint has translational limits or not and the limits themselves.\n"
- "@return Returns whether the joint has translational limits or not and the limits themselves (empty string indicates error)." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Args.
- bool enableLimit;
- F32 lowerTranslation;
- F32 upperTranslation;
- // Access joint.
- if ( !object->getPrismaticJointLimit( jointId, enableLimit, lowerTranslation, upperTranslation ) )
- {
- return NULL;
- }
- // Format output.
- char* pBuffer = Con::getReturnBuffer(64);
- dSprintf( pBuffer, 64, "%d %g %g", enableLimit, lowerTranslation, upperTranslation );
- return pBuffer;
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setPrismaticJointMotor, void, 4, 6, "(jointId, enableMotor, [motorSpeed], [maxMotorForce]) Sets whether the joint has a motor or not and the motor settings.\n"
- "@param jointId The Id of the joint to use.\n"
- "@param enableMotor Whether the joint has a motor or not.\n"
- "@param motorSpeed The motor speed (degrees per/sec).\n"
- "@param maxMotorForce The maximum motor force used to achieve the specified motor speed (N-m).\n"
- "@return Returns no value." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Fetch args.
- const bool enableMotor = dAtob(argv[3]);
- const F32 motorSpeed = argc > 4 ? mDegToRad( dAtof(argv[4]) ) : 0.0f;
- const F32 maxMotorForce = argc > 5 ? dAtof(argv[5]) : 0.0f;
- // Access joint.
- object->setPrismaticJointMotor( jointId, enableMotor, motorSpeed, maxMotorForce );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getPrismaticJointMotor, const char*, 3, 3, "(jointId) Gets whether the joint has a motor or not and the motor settings.\n"
- "@return Returns whether the joint has a motor or not and the motor settings (empty string indicates error)." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Args.
- bool enableMotor;
- F32 motorSpeed;
- F32 maxMotorForce;
- // Access joint.
- if ( !object->getPrismaticJointMotor( jointId, enableMotor, motorSpeed, maxMotorForce ) )
- {
- return NULL;
- }
- // Format output.
- char* pBuffer = Con::getReturnBuffer(64);
- dSprintf( pBuffer, 64, "%d %g %g", enableMotor, mRadToDeg(motorSpeed), maxMotorForce );
- return pBuffer;
- }
- //-----------------------------------------------------------------------------
- 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"
- "@param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
- "@param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
- "@param localAnchorA The local point of the first scene object where the joint connects.\n"
- "@param localAnchorB The local point of the second scene object where the joint connects.\n"
- "@param worldGroundAnchorA The world point of the first ground anchor. This point never moves.\n"
- "@param worldGroundAnchorB The world point of the second ground anchor. This point never moves.\n"
- "@param ratio The pulley ratio used to simulate a block-and-tackle pulley.\n"
- "@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"
- "@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"
- "@param collideConnected Whether the scene objects can collide with each other while connected with this joint.\n"
- "@return The joint Id (-1 if error).")
- {
- // Fetch scene object references.
- const char* sceneObjectA = argv[2];
- const char* sceneObjectB = argv[3];
- SceneObject* pSceneObjectA = NULL;
- SceneObject* pSceneObjectB = NULL;
- // Fetch scene object.
- if ( *sceneObjectA != 0 )
- {
- pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
- if ( !pSceneObjectA )
- Con::warnf("Scene::createPulleyJoint() - Could not find scene object %d.", sceneObjectA);
- }
- // Fetch scene object.
- if ( *sceneObjectB != 0 )
- {
- pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
- if ( !pSceneObjectB )
- Con::warnf("Scene::createPulleyJoint() - Could not find scene object %d.", sceneObjectB);
- }
- // Local anchor A.
- const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
- b2Vec2 localAnchorA;
- S32 nextArg = 5;
- if ( anchorAElementCount == 1 && argc > 5 )
- {
- localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
- nextArg = 6;
- }
- else if ( anchorAElementCount == 2 )
- {
- localAnchorA = Utility::mGetStringElementVector(argv[4]);
- }
- // Invalid
- else
- {
- Con::warnf("Scene::createPulleyJoint() - Invalid number of parameters!");
- return -1;
- }
- // Local anchor B.
- const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
- b2Vec2 localAnchorB;
- if ( anchorBElementCount == 1 && argc > (nextArg+1) )
- {
- localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
- nextArg += 2;
- }
- else if ( anchorBElementCount == 2 )
- {
- localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
- }
- // Invalid
- else
- {
- Con::warnf("Scene::createPulleyJoint() - Invalid number of parameters!");
- return -1;
- }
- // World ground anchor A.
- const U32 worldGroundAnchorAElementCount = Utility::mGetStringElementCount(argv[nextArg]);
- b2Vec2 worldGroundAnchorA;
- if ( worldGroundAnchorAElementCount == 1 && argc > 5 )
- {
- worldGroundAnchorA.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg++]) );
- nextArg += 2;
- }
- else if ( worldGroundAnchorAElementCount == 2 )
- {
- worldGroundAnchorA = Utility::mGetStringElementVector(argv[nextArg++]);
- }
- // Invalid
- else
- {
- Con::warnf("Scene::createPulleyJoint() - Invalid number of parameters!");
- return -1;
- }
- // World ground anchor B.
- const U32 worldGroundAnchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
- b2Vec2 worldGroundAnchorB;
- if ( worldGroundAnchorBElementCount == 1 && argc > (nextArg+1) )
- {
- worldGroundAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
- nextArg += 2;
- }
- else if ( worldGroundAnchorBElementCount == 2 )
- {
- worldGroundAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
- }
- // Invalid
- else
- {
- Con::warnf("Scene::createPulleyJoint() - Invalid number of parameters!");
- return -1;
- }
- // Fetch maximum ratio.
- const F32 ratio = dAtof(argv[nextArg++]);
- if ( argc <= nextArg )
- {
- return object->createPulleyJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, worldGroundAnchorA, worldGroundAnchorB, ratio );
- }
- // Fetch collide connected.
- const bool collideConnected = dAtob(argv[nextArg++]);
- return object->createPulleyJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, worldGroundAnchorA, worldGroundAnchorB, ratio, collideConnected );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, createTargetJoint, S32, 5, 10, "(sceneObject, worldTarget X/Y, maxForce, [useCenterOfMass?], [frequency], [dampingRatio], [collideConnected]) Creates a target joint.\n"
- "@param sceneObject The scene object to connect to the joint.\n"
- "@param worldTarget The world point target to move the scene object to.\n"
- "@param maxForce The maximum force the joint should use to position the scene object at the target.\n"
- "@param useCenterOfMass Whether to use the center of mass as the point which the joint is attached or not. Defaults to false.\n"
- "@param frequency The mass-spring-damper frequency in Hertz. A value of 0 disables softness (default=0.7).\n"
- "@param dampingRatio The damping ratio. 0 = no damping (default), 1 = critical damping.\n"
- "@param collideConnected Whether the scene objects can collide with each other while connected with this joint.\n"
- "@return The joint Id (-1 if error).")
- {
- // Fetch scene object.
- SceneObject* pSceneObject = Sim::findObject<SceneObject>(argv[2]);
- // Check scene object.
- if ( !pSceneObject )
- {
- Con::warnf("Scene::createTargetJoint() - Could not find scene object %d.", argv[2]);
- return -1;
- }
- // World target.
- const U32 worldTargetElementCount = Utility::mGetStringElementCount(argv[3]);
- b2Vec2 worldTarget;
- S32 nextArg = 4;
- if ( worldTargetElementCount == 1 && argc > 5 )
- {
- worldTarget.Set( dAtof(argv[3]), dAtof(argv[4]) );
- nextArg = 5;
- }
- else if ( worldTargetElementCount == 2 )
- {
- worldTarget = Utility::mGetStringElementVector(argv[3]);
- }
- // Invalid
- else
- {
- Con::warnf("Scene::createTargetJoint() - Invalid number of parameters!");
- return -1;
- }
- // Fetch maximum force.
- const F32 maxForce = dAtof(argv[nextArg++]);
- if ( argc <= nextArg )
- {
- return object->createTargetJoint( pSceneObject, worldTarget, maxForce );
- }
- // Fetch the center-of-mass flag.
- const bool centerOfMass = dAtob(argv[nextArg++]);
- if ( argc <= nextArg )
- {
- return object->createTargetJoint( pSceneObject, worldTarget, maxForce, centerOfMass );
- }
- // Fetch frequency (Hertz).
- const F32 frequency = dAtof(argv[nextArg++]);
- if ( argc <= nextArg )
- {
- return object->createTargetJoint( pSceneObject, worldTarget, maxForce, frequency );
- }
- // Fetch damping ratio.
- const F32 dampingRatio = dAtof(argv[nextArg++]);
- if ( argc <= nextArg )
- {
- return object->createTargetJoint( pSceneObject, worldTarget, maxForce, frequency, dampingRatio );
- }
- // Fetch collide connected.
- const bool collideConnected = dAtob(argv[nextArg++]);
- return object->createTargetJoint( pSceneObject, worldTarget, maxForce, frequency, dampingRatio, collideConnected );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setTargetJointTarget, void, 4, 5, "(jointId, worldTarget X/Y) Sets the target world point for the scene object.\n"
- "@param jointId The Id of the joint to use.\n"
- "@param worldTarget The target world point to move the scene object to.\n"
- "@return Returns no value." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // World target.
- const U32 worldTargetElementCount = Utility::mGetStringElementCount(argv[3]);
- b2Vec2 worldTarget;
- if ( worldTargetElementCount == 1 && argc > 5 )
- {
- worldTarget.Set( dAtof(argv[3]), dAtof(argv[4]) );
- }
- else if ( worldTargetElementCount == 2 )
- {
- worldTarget = Utility::mGetStringElementVector(argv[3]);
- }
- // Invalid
- else
- {
- Con::warnf("Scene::setTargetJointTarget() - Invalid number of parameters!");
- }
- // Access joint.
- object->setTargetJointTarget( jointId, worldTarget );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getTargetJointTarget, const char*, 3, 3, "(jointId) Gets the target world point for the scene object.\n"
- "@param jointId The Id of the joint to use.\n"
- "@return Returns the target world point for the scene object (always 0,0 if error)." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Access joint.
- const Vector2 worldTarget = object->getTargetJointTarget( jointId );
- return worldTarget.scriptThis();
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setTargetJointFrequency, void, 4, 4, "(jointId, frequency) Sets the mass-spring-damper frequency in Hertz.\n"
- "@param jointId The Id of the joint to use.\n"
- "@param frequency The mass-spring-damper frequency in Hertz. A value of 0 disables softness.\n"
- "@return Returns no value." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Fetch args.
- const F32 frequency = dAtof(argv[3]);
- // Access joint.
- object->setTargetJointFrequency( jointId, frequency );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getTargetJointFrequency, F32, 3, 3, "(jointId) Gets the mass-spring-damper frequency in Hertz.\n"
- "@param jointId The Id of the joint to use.\n"
- "@return Returns the mass-spring-damper frequency in Hertz (-1 indicates error)." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Access joint.
- return object->getTargetJointFrequency( jointId );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setTargetJointDampingRatio, void, 4, 4, "(jointId, dampingRatio) Sets the damping ratio.\n"
- "@param jointId The Id of the joint to use.\n"
- "@param dampingRatio The damping ratio. 0 = no damping, 1 = critical damping.\n"
- "@return Returns no value." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Fetch args.
- const F32 dampingRatio = dAtof(argv[3]);
- // Access joint.
- object->setTargetJointDampingRatio( jointId, dampingRatio );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getTargetJointDampingRatio, F32, 3, 3, "(jointId) Sets the damping ratio.\n"
- "@param jointId The Id of the joint to use.\n"
- "@return Returns the damping ratio (-1 indicates error)." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Access joint.
- return object->getTargetJointDampingRatio( jointId );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, createMotorJoint, S32, 4, 11, "(sceneObjectA, sceneObjectB, [linearOffset X/Y], [angularOffset], [maxForce], [maxTorque], [correctionFactor], [collideConnected]) Creates a motor joint.\n"
- "@param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
- "@param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.\n"
- "@param linearOffsetX/Y The linear offset in sceneObjectA space.\n"
- "@param angularOffset The angularOffset between the bodies.\n"
- "@param maxForce The maximum friction force (N).\n"
- "@param maxTorque The maximum torque force (N-m).\n"
- "@param correctionFactor The correction factor (tolerance).\n"
- "@param collideConnected Whether the scene objects can collide with each other while connected with this joint.\n"
- "@return The joint Id (-1 if error).")
- {
- // Fetch scene object references.
- const char* sceneObjectA = argv[2];
- const char* sceneObjectB = argv[3];
- SceneObject* pSceneObjectA = NULL;
- SceneObject* pSceneObjectB = NULL;
- // Fetch scene object.
- if ( *sceneObjectA != 0 )
- {
- pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
- if ( !pSceneObjectA )
- Con::warnf("Scene::createMotorJoint() - Could not find scene object %d.", sceneObjectA);
- }
- // Fetch scene object.
- if ( *sceneObjectB != 0 )
- {
- pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
- if ( !pSceneObjectB )
- Con::warnf("Scene::createMotorJoint() - Could not find scene object %d.", sceneObjectB);
- }
- if ( argc == 4 )
- {
- return object->createMotorJoint( pSceneObjectA, pSceneObjectB );
- }
- // Linear offset.
- const U32 linearOffsetElementCount = Utility::mGetStringElementCount(argv[4]);
- b2Vec2 linearOffset;
- S32 nextArg = 5;
- if ( linearOffsetElementCount == 1 && argc > 5 )
- {
- linearOffset.Set( dAtof(argv[4]), dAtof(argv[5]) );
- nextArg = 6;
- }
- else if ( linearOffsetElementCount == 2 )
- {
- linearOffset = Utility::mGetStringElementVector(argv[4]);
- }
- // Invalid
- else
- {
- Con::warnf("Scene::createMotorJoint() - Invalid number of parameters!");
- return -1;
- }
- if ( argc <= nextArg )
- {
- return object->createMotorJoint( pSceneObjectA, pSceneObjectB, linearOffset );
- }
- // Fetch angular offset.
- const F32 angularOffset = mDegToRad( dAtof(argv[nextArg++]) );
- if ( argc <= nextArg )
- {
- return object->createMotorJoint( pSceneObjectA, pSceneObjectB, linearOffset, angularOffset );
- }
- // Fetch maximum force.
- const F32 maxForce = dAtof(argv[nextArg++]);
- if ( argc <= nextArg )
- {
- return object->createMotorJoint( pSceneObjectA, pSceneObjectB, linearOffset, angularOffset, maxForce );
- }
- // Fetch maximum torque.
- const F32 maxTorque = dAtof(argv[nextArg++]);
- if ( argc <= nextArg )
- {
- return object->createMotorJoint( pSceneObjectA, pSceneObjectB, linearOffset, angularOffset, maxForce, maxTorque );
- }
- // Fetch collide connected.
- const bool collideConnected = dAtob(argv[nextArg++]);
- return object->createMotorJoint( pSceneObjectA, pSceneObjectB, linearOffset, angularOffset, maxForce, maxTorque, collideConnected );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setMotorJointLinearOffset, void, 4, 5, "(jointId, linearOffset X/Y) Sets the linear offset in sceneObjectA space.\n"
- "@param jointId The Id of the joint to use.\n"
- "@param linearOffsetX/Y The linear offset in sceneObjectA space.\n"
- "@return Returns no value." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Linear offset.
- const U32 linearOffsetElementCount = Utility::mGetStringElementCount(argv[3]);
- b2Vec2 linearOffset;
- if ( linearOffsetElementCount == 1 && argc > 5 )
- {
- linearOffset.Set( dAtof(argv[3]), dAtof(argv[4]) );
- }
- else if ( linearOffsetElementCount == 2 )
- {
- linearOffset = Utility::mGetStringElementVector(argv[3]);
- }
- // Invalid
- else
- {
- Con::warnf("Scene::setMotorJointLinearOffset() - Invalid number of parameters!");
- }
- // Access joint.
- object->setMotorJointLinearOffset( jointId, linearOffset );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getMotorJointLinearOffset, const char*, 3, 3, "(jointId) Gets the linear offset in sceneObjectA space.\n"
- "@param jointId The Id of the joint to use.\n"
- "@return Returns the linear offset in sceneObjectA space (always 0,0 if error)." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Access joint.
- const Vector2 linearOffset = object->getMotorJointLinearOffset( jointId );
- return linearOffset.scriptThis();
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setMotorJointAngularOffset, void, 4, 4, "(jointId, angularOffset) Sets the angularOffset between the bodies.\n"
- "@param jointId The Id of the joint to use.\n"
- "@param angularOffset The angularOffset between the bodies.\n"
- "@return Returns no value." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Fetch args.
- const F32 angularOffset = mDegToRad(dAtof(argv[3]));
- // Access joint.
- object->setMotorJointAngularOffset( jointId, angularOffset );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getMotorJointAngularOffset, F32, 3, 3, "(jointId) Gets angularOffset between the bodies.\n"
- "@param jointId The Id of the joint to use.\n"
- "@return Returns the angularOffset between the bodies (-1 indicates error)." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Access joint.
- return mRadToDeg( object->getMotorJointAngularOffset( jointId ) );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setMotorJointMaxForce, void, 4, 4, "(jointId, maxForce) Sets the maximum motor force.\n"
- "@param jointId The Id of the joint to use.\n"
- "@param maxForce The maximum motor force (N).\n"
- "@return Returns no value." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Fetch args.
- const F32 maxForce = dAtof(argv[3]);
- // Access joint.
- object->setMotorJointMaxForce( jointId, maxForce );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getMotorJointMaxForce, F32, 3, 3, "(jointId) Sets the maximum motor force.\n"
- "@param jointId The Id of the joint to use.\n"
- "@return Returns the maximum motor force (-1 indicates error)." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Access joint.
- return object->getMotorJointMaxForce( jointId );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setMotorJointMaxTorque, void, 4, 4, "(jointId, maxTorque) Sets the maximum motor torque force.\n"
- "@param jointId The Id of the joint to use.\n"
- "@param maxTorque The maximum motor torque force (N).\n"
- "@return Returns no value." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Fetch args.
- const F32 maxTorque = dAtof(argv[3]);
- // Access joint.
- object->setMotorJointMaxTorque( jointId, maxTorque );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getMotorJointMaxTorque, F32, 3, 3, "(jointId) Gets the maximum motor torque force.\n"
- "@param jointId The Id of the joint to use.\n"
- "@return Returns the maximum motor torque force (-1 indicates error)." )
- {
- // Fetch joint Id.
- const U32 jointId = dAtoi(argv[2]);
- // Access joint.
- return object->getMotorJointMaxTorque( jointId );
- }
- //-----------------------------------------------------------------------------
- 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"
- "@param startx/y The coordinates of the start point as either (\"x y\") or (x,y)\n"
- "@param endx/y The coordinates of the end point as either (\"x y\") or (x,y)\n"
- "@param sceneGroupMask Optional scene group mask.\n"
- "@param sceneLayerMask Optional scene layer mask.\n"
- "@param pickMode Optional mode 'any', 'size' or 'collision' (default is 'size').\n"
- "@return Returns list of object IDs.")
- {
- // Upper left and lower right bound.
- Vector2 v1, v2;
- // The index of the first optional parameter.
- U32 firstArg;
- // Grab the number of elements in the first two parameters.
- U32 elementCount1 = Utility::mGetStringElementCount(argv[2]);
- U32 elementCount2 = 1;
- if (argc > 3)
- elementCount2 = Utility::mGetStringElementCount(argv[3]);
- // ("x1 y1 x2 y2")
- if ((elementCount1 == 4) && (argc < 9))
- {
- v1 = Utility::mGetStringElementVector(argv[2]);
- v2 = Utility::mGetStringElementVector(argv[2], 2);
- firstArg = 3;
- }
-
- // ("x1 y1", "x2 y2")
- else if ((elementCount1 == 2) && (elementCount2 == 2) && (argc > 3) && (argc < 10))
- {
- v1 = Utility::mGetStringElementVector(argv[2]);
- v2 = Utility::mGetStringElementVector(argv[3]);
- firstArg = 4;
- }
-
- // (x1, y1, x2, y2)
- else if (argc > 5)
- {
- v1 = Vector2(dAtof(argv[2]), dAtof(argv[3]));
- v2 = Vector2(dAtof(argv[4]), dAtof(argv[5]));
- firstArg = 6;
- }
-
- // Invalid
- else
- {
- Con::warnf("Scene::pickArea() - Invalid number of parameters!");
- return NULL;
- }
- // Calculate scene group mask.
- U32 sceneGroupMask = MASK_ALL;
- if ( (U32)argc > firstArg )
- sceneGroupMask = dAtoi(argv[firstArg]);
- // Calculate scene layer mask.
- U32 sceneLayerMask = MASK_ALL;
- if ( (U32)argc > (firstArg + 1) )
- sceneLayerMask = dAtoi(argv[firstArg + 1]);
- // Calculate pick mode.
- Scene::PickMode pickMode = Scene::PICK_SIZE;
- if ( (U32)argc > (firstArg + 2))
- {
- pickMode = Scene::getPickModeEnum(argv[firstArg + 2]);
- }
- if ( pickMode == Scene::PICK_INVALID )
- {
- Con::warnf("Scene::pickArea() - Invalid pick mode of %s", argv[firstArg + 2]);
- pickMode = Scene::PICK_SIZE;
- }
- // Fetch world query and clear results.
- WorldQuery* pWorldQuery = object->getWorldQuery( true );
- // Set filter.
- WorldQueryFilter queryFilter( sceneLayerMask, sceneGroupMask, true, false, true, true );
- pWorldQuery->setQueryFilter( queryFilter );
- // Calculate normalized AABB.
- b2AABB aabb;
- aabb.lowerBound.x = getMin( v1.x, v2.x );
- aabb.lowerBound.y = getMin( v1.y, v2.y );
- aabb.upperBound.x = getMax( v1.x, v2.x );
- aabb.upperBound.y = getMax( v1.y, v2.y );
- // Perform query.
- if ( pickMode == Scene::PICK_ANY )
- {
- pWorldQuery->anyQueryArea( aabb );
- }
- else if ( pickMode == Scene::PICK_SIZE )
- {
- pWorldQuery->renderQueryArea( aabb );
- }
- else if ( pickMode == Scene::PICK_COLLISION )
- {
- pWorldQuery->fixtureQueryArea( aabb );
- }
- else
- {
- AssertFatal( false, "Unsupported pick mode." );
- }
- // Finish if no results.
- if ( pWorldQuery->getQueryResultsCount() == 0 )
- return NULL;
- // Fetch results.
- typeWorldQueryResultVector& queryResults = pWorldQuery->getQueryResults();
- // Set Max Buffer Size.
- const U32 maxBufferSize = 4096;
- // Create Returnable Buffer.
- char* pBuffer = Con::getReturnBuffer(maxBufferSize);
- // Set Buffer Counter.
- U32 bufferCount = 0;
- // Add picked objects.
- for ( U32 n = 0; n < (U32)queryResults.size(); n++ )
- {
- // Output Object ID.
- bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", queryResults[n].mpSceneObject->getId() );
- // Finish early if we run out of buffer space.
- if ( bufferCount >= maxBufferSize )
- {
- // Warn.
- Con::warnf("Scene::pickArea() - Too many items picked to return to scripts!");
- break;
- }
- }
- // Clear world query.
- pWorldQuery->clearQuery();
- // Return buffer.
- return pBuffer;
- }
- //-----------------------------------------------------------------------------
- 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"
- "@param startx/y The coordinates of the start point as either (\"x y\") or (x,y)\n"
- "@param endx/y The coordinates of the end point as either (\"x y\") or (x,y)\n"
- "@param sceneGroupMask Optional scene group mask.\n"
- "@param sceneLayerMask Optional scene layer mask.\n"
- "@param pickMode Optional mode 'any', 'size' or 'collision' (default is 'size').\n"
- "@return Returns list of object IDs.")
- {
- // Upper left and lower right bound.
- Vector2 v1, v2;
- // The index of the first optional parameter.
- U32 firstArg;
- // Grab the number of elements in the first two parameters.
- U32 elementCount1 = Utility::mGetStringElementCount(argv[2]);
- U32 elementCount2 = 1;
- if (argc > 3)
- elementCount2 = Utility::mGetStringElementCount(argv[3]);
- // ("x1 y1 x2 y2")
- if ((elementCount1 == 4) && (argc < 9))
- {
- v1 = Utility::mGetStringElementVector(argv[2]);
- v2 = Utility::mGetStringElementVector(argv[2], 2);
- firstArg = 3;
- }
-
- // ("x1 y1", "x2 y2")
- else if ((elementCount1 == 2) && (elementCount2 == 2) && (argc > 3) && (argc < 10))
- {
- v1 = Utility::mGetStringElementVector(argv[2]);
- v2 = Utility::mGetStringElementVector(argv[3]);
- firstArg = 4;
- }
-
- // (x1, y1, x2, y2)
- else if (argc > 5)
- {
- v1 = Vector2(dAtof(argv[2]), dAtof(argv[3]));
- v2 = Vector2(dAtof(argv[4]), dAtof(argv[5]));
- firstArg = 6;
- }
-
- // Invalid
- else
- {
- Con::warnf("Scene::pickRay() - Invalid number of parameters!");
- return NULL;
- }
- // Calculate scene group mask.
- U32 sceneGroupMask = MASK_ALL;
- if ( (U32)argc > firstArg )
- sceneGroupMask = dAtoi(argv[firstArg]);
- // Calculate scene layer mask.
- U32 sceneLayerMask = MASK_ALL;
- if ( (U32)argc > (firstArg + 1) )
- sceneLayerMask = dAtoi(argv[firstArg + 1]);
- // Calculate pick mode.
- Scene::PickMode pickMode = Scene::PICK_SIZE;
- if ( (U32)argc > (firstArg + 2))
- {
- pickMode = Scene::getPickModeEnum(argv[firstArg + 2]);
- }
- if ( pickMode == Scene::PICK_INVALID )
- {
- Con::warnf("Scene::pickRay() - Invalid pick mode of %s", argv[firstArg + 2]);
- pickMode = Scene::PICK_SIZE;
- }
- // Fetch world query and clear results.
- WorldQuery* pWorldQuery = object->getWorldQuery( true );
- // Set filter.
- WorldQueryFilter queryFilter( sceneLayerMask, sceneGroupMask, true, false, true, true );
- pWorldQuery->setQueryFilter( queryFilter );
- // Perform query.
- if ( pickMode == Scene::PICK_ANY )
- {
- pWorldQuery->anyQueryRay( v1, v2 );
- }
- else if ( pickMode == Scene::PICK_SIZE )
- {
- pWorldQuery->renderQueryRay( v1, v2 );
- }
- else if ( pickMode == Scene::PICK_COLLISION )
- {
- pWorldQuery->fixtureQueryRay( v1, v2 );
- }
- else
- {
- AssertFatal( false, "Unsupported pick mode." );
- }
- // Sanity!
- AssertFatal( pWorldQuery->getIsRaycastQueryResult(), "Invalid non-ray-cast query result returned." );
- // Finish if no results.
- if ( pWorldQuery->getQueryResultsCount() == 0 )
- return NULL;
- // Sort ray-cast result.
- pWorldQuery->sortRaycastQueryResult();
- // Fetch results.
- typeWorldQueryResultVector& queryResults = pWorldQuery->getQueryResults();
- // Set Max Buffer Size.
- const U32 maxBufferSize = 4096;
- // Create Returnable Buffer.
- char* pBuffer = Con::getReturnBuffer(maxBufferSize);
- // Set Buffer Counter.
- U32 bufferCount = 0;
- // Add Picked Objects to List.
- for ( U32 n = 0; n < (U32)queryResults.size(); n++ )
- {
- // Output Object ID.
- bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", queryResults[n].mpSceneObject->getId() );
- // Finish early if we run out of buffer space.
- if ( bufferCount >= maxBufferSize )
- {
- // Warn.
- Con::warnf("Scene::pickRay() - Too many items picked to return to scripts!");
- break;
- }
- }
- // Clear world query.
- pWorldQuery->clearQuery();
- // Return buffer.
- return pBuffer;
- }
- //-----------------------------------------------------------------------------
- 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"
- "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"
- "@param startx/y The coordinates of the start point as either (\"x y\") or (x,y)\n"
- "@param endx/y The coordinates of the end point as either (\"x y\") or (x,y)\n"
- "@param sceneGroupMask Optional scene group mask.\n"
- "@param sceneLayerMask Optional scene layer mask.\n"
- "@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:"
- "<ObjectId PointX PointY NormalX NormalY RayFraction ShapeIndex> <ObjectId PointX PointY NormalX NormalY RayFraction ShapeIndex> <ObjectId PointX PointY NormalX NormalY RayFraction ShapeIndex> etc.\n")
- {
- // Upper left and lower right bound.
- Vector2 v1, v2;
- // The index of the first optional parameter.
- U32 firstArg;
- // Grab the number of elements in the first two parameters.
- U32 elementCount1 = Utility::mGetStringElementCount(argv[2]);
- U32 elementCount2 = 1;
- if (argc > 3)
- elementCount2 = Utility::mGetStringElementCount(argv[3]);
- // ("x1 y1 x2 y2")
- if ((elementCount1 == 4) && (argc < 9))
- {
- v1 = Utility::mGetStringElementVector(argv[2]);
- v2 = Utility::mGetStringElementVector(argv[2], 2);
- firstArg = 3;
- }
-
- // ("x1 y1", "x2 y2")
- else if ((elementCount1 == 2) && (elementCount2 == 2) && (argc > 3) && (argc < 9))
- {
- v1 = Utility::mGetStringElementVector(argv[2]);
- v2 = Utility::mGetStringElementVector(argv[3]);
- firstArg = 4;
- }
-
- // (x1, y1, x2, y2)
- else if (argc > 5)
- {
- v1 = Vector2(dAtof(argv[2]), dAtof(argv[3]));
- v2 = Vector2(dAtof(argv[4]), dAtof(argv[5]));
- firstArg = 6;
- }
-
- // Invalid
- else
- {
- Con::warnf("Scene::pickRayCollision() - Invalid number of parameters!");
- return NULL;
- }
- // Calculate scene group mask.
- U32 sceneGroupMask = MASK_ALL;
- if ( (U32)argc > firstArg )
- sceneGroupMask = dAtoi(argv[firstArg]);
- // Calculate scene layer mask.
- U32 sceneLayerMask = MASK_ALL;
- if ( (U32)argc > (firstArg + 1) )
- sceneLayerMask = dAtoi(argv[firstArg + 1]);
- // Fetch world query and clear results.
- WorldQuery* pWorldQuery = object->getWorldQuery( true );
- // Set filter.
- WorldQueryFilter queryFilter( sceneLayerMask, sceneGroupMask, true, false, true, true );
- pWorldQuery->setQueryFilter( queryFilter );
- // Perform query.
- pWorldQuery->fixtureQueryRay( v1, v2 );
- // Sanity!
- AssertFatal( pWorldQuery->getIsRaycastQueryResult(), "Invalid non-ray-cast query result returned." );
- // Finish if no results.
- const U32 queryResultCount = pWorldQuery->getQueryResultsCount();
- if ( queryResultCount == 0 )
- return NULL;
- // Sort ray-cast result.
- pWorldQuery->sortRaycastQueryResult();
- // Fetch results.
- typeWorldQueryResultVector& queryResults = pWorldQuery->getQueryResults();
- // Set Max Buffer Size.
- const U32 maxBufferSize = 4096;
- // Create Returnable Buffer.
- char* pBuffer = Con::getReturnBuffer(maxBufferSize);
- // Set Buffer Counter.
- U32 bufferCount = 0;
- // Add Picked Objects to List.
- for ( U32 n = 0; n < queryResultCount; n++ )
- {
- // Fetch query result.
- const WorldQueryResult& queryResult = queryResults[n];
- bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d %g %g %g %g %g %d ",
- queryResult.mpSceneObject->getId(),
- queryResult.mPoint.x, queryResult.mPoint.y,
- queryResult.mNormal.x, queryResult.mNormal.y,
- queryResult.mFraction,
- queryResult.mShapeIndex );
- // Finish early if we run out of buffer space.
- if ( bufferCount >= maxBufferSize )
- {
- // Warn.
- Con::warnf("Scene::pickRayCollision() - Too many items picked to return to scripts!");
- break;
- }
- }
- // Clear world query.
- pWorldQuery->clearQuery();
- // Return buffer.
- return pBuffer;
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, pickPoint, const char*, 3, 7, "(x / y, [sceneGroupMask], [sceneLayerMask], [pickMode] ) Picks objects intersecting the specified point with optional group/layer masks.\n"
- "@param x/y The coordinate of the point as either (\"x y\") or (x,y)\n"
- "@param sceneGroupMask Optional scene group mask.\n"
- "@param sceneLayerMask Optional scene layer mask.\n"
- "@param pickMode Optional mode 'any', 'size' or 'collision' (default is 'size').\n"
- "@return Returns list of object IDs.")
- {
- // The point.
- Vector2 point;
- // The index of the first optional parameter.
- U32 firstArg;
- // Grab the number of elements in the first parameter.
- U32 elementCount = Utility::mGetStringElementCount(argv[2]);
- // ("x y")
- if ((elementCount == 2) && (argc < 8))
- {
- point = Utility::mGetStringElementVector(argv[2]);
- firstArg = 3;
- }
-
- // (x, y)
- else if ((elementCount == 1) && (argc > 3))
- {
- point = Vector2(dAtof(argv[2]), dAtof(argv[3]));
- firstArg = 4;
- }
-
- // Invalid
- else
- {
- Con::warnf("Scene::pickPoint() - Invalid number of parameters!");
- return NULL;
- }
- // Calculate scene group mask.
- U32 sceneGroupMask = MASK_ALL;
- if ( (U32)argc > firstArg )
- sceneGroupMask = dAtoi(argv[firstArg]);
- // Calculate scene layer mask.
- U32 sceneLayerMask = MASK_ALL;
- if ( (U32)argc > (firstArg + 1) )
- sceneLayerMask = dAtoi(argv[firstArg + 1]);
- // Calculate pick mode.
- Scene::PickMode pickMode = Scene::PICK_SIZE;
- if ( (U32)argc > (firstArg + 2 ))
- {
- pickMode = Scene::getPickModeEnum(argv[firstArg + 2]);
- }
- if ( pickMode == Scene::PICK_INVALID )
- {
- Con::warnf("Scene::pickPoint() - Invalid pick mode of %s", argv[firstArg + 2]);
- pickMode = Scene::PICK_SIZE;
- }
- // Fetch world query and clear results.
- WorldQuery* pWorldQuery = object->getWorldQuery( true );
- // Set filter.
- WorldQueryFilter queryFilter( sceneLayerMask, sceneGroupMask, true, false, true, true );
- pWorldQuery->setQueryFilter( queryFilter );
- // Perform query.
- if ( pickMode == Scene::PICK_ANY )
- {
- pWorldQuery->anyQueryPoint( point );
- }
- else if ( pickMode == Scene::PICK_SIZE )
- {
- pWorldQuery->renderQueryPoint( point );
- }
- else if ( pickMode == Scene::PICK_COLLISION )
- {
- pWorldQuery->fixtureQueryPoint( point );
- }
- else
- {
- AssertFatal( false, "Unsupported pick mode." );
- }
- // Finish if no results.
- if ( pWorldQuery->getQueryResultsCount() == 0 )
- return NULL;
- // Fetch results.
- typeWorldQueryResultVector& queryResults = pWorldQuery->getQueryResults();
- // Set Max Buffer Size.
- const U32 maxBufferSize = 4096;
- // Create Returnable Buffer.
- char* pBuffer = Con::getReturnBuffer(maxBufferSize);
- // Set Buffer Counter.
- U32 bufferCount = 0;
- // Add Picked Objects to List.
- for ( U32 n = 0; n < (U32)queryResults.size(); n++ )
- {
- // Output Object ID.
- bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", queryResults[n].mpSceneObject->getId() );
- // Finish early if we run out of buffer space.
- if ( bufferCount >= maxBufferSize )
- {
- // Warn.
- Con::warnf("Scene::pickPoint() - Too many items picked to return to scripts!");
- break;
- }
- }
- // Clear world query.
- pWorldQuery->clearQuery();
- // Return buffer.
- return pBuffer;
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setDebugOn, void, 3, 2 + DEBUG_MODE_COUNT, "(debugOptions) Sets Debug option(s) on.\n"
- "@param debugOptions Either a list of debug modes (comma-separated), or a string with the modes (space-separated)\n"
- "@return No return value.")
- {
- // Reset the mask.
- U32 mask = 0;
- // Grab the element count of the first parameter.
- const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
- // Make sure we get at least one number.
- if (elementCount < 1)
- {
- Con::warnf( "Scene::setDebugOn() - Invalid number of parameters!" );
- return;
- }
- // Space-separated list.
- if (argc == 3)
- {
- // Convert the string to a mask.
- for (U32 i = 0; i < elementCount; i++)
- {
- // Fetch the debug option.
- const char* pDebugOption = Utility::mGetStringElement( argv[2], i );
- Scene::DebugOption debugOption = Scene::getDebugOptionEnum( pDebugOption );
-
- // Is the option valid?
- if ( debugOption == Scene::SCENE_DEBUG_INVALID )
- {
- // No, so warn.
- Con::warnf( "Scene::setDebugOn() - Invalid debug option '%s' specified.", pDebugOption );
- continue;
- }
-
- // Merge into mask.
- mask |= debugOption;
- }
- }
- // Comma-separated list.
- else
- {
- // Convert the list to a mask.
- for (U32 i = 2; i < (U32)argc; i++)
- {
- // Fetch the debug option.
- const char* pDebugOption = argv[i];
- Scene::DebugOption debugOption = Scene::getDebugOptionEnum( argv[i] );
- // Is the option valid?
- if ( debugOption == Scene::SCENE_DEBUG_INVALID )
- {
- // No, so warn.
- Con::warnf( "Scene::setDebugOn() - Invalid debug option '%s' specified.", pDebugOption );
- continue;
- }
- // Merge into mask.
- mask |= debugOption;
- }
- }
- // Set debug mask.
- object->setDebugOn(mask);
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setDebugOff, void, 3, 2 + DEBUG_MODE_COUNT, "(debugOptions) Sets Debug options(s) off.\n"
- "@param debugOptions Either a list of debug modes to turn off (comma-separated) or a string (space-separated)\n"
- "@return No return value.")
- {
- // Reset the mask.
- U32 mask = 0;
- // Grab the element count of the first parameter.
- const U32 elementCount = Utility::mGetStringElementCount(argv[2]);
- // Make sure we get at least one number.
- if (elementCount < 1)
- {
- Con::warnf( "Scene::setDebugOff() - Invalid number of parameters!" );
- return;
- }
- // Space-separated list.
- if (argc == 3)
- {
- // Convert the string to a mask.
- for (U32 i = 0; i < elementCount; i++)
- {
- // Fetch the debug option.
- const char* pDebugOption = Utility::mGetStringElement( argv[2], i );
- Scene::DebugOption debugOption = Scene::getDebugOptionEnum( pDebugOption );
-
- // Is the option valid?
- if ( debugOption == Scene::SCENE_DEBUG_INVALID )
- {
- // No, so warn.
- Con::warnf( "Scene::setDebugOff() - Invalid debug option '%s' specified.", pDebugOption );
- continue;
- }
-
- // Merge into mask.
- mask |= debugOption;
- }
- }
- // Comma-separated list.
- else
- {
- // Convert the list to a mask.
- for (U32 i = 2; i < (U32)argc; i++)
- {
- // Fetch the debug option.
- const char* pDebugOption = argv[i];
- Scene::DebugOption debugOption = Scene::getDebugOptionEnum( argv[i] );
- // Is the option valid?
- if ( debugOption == Scene::SCENE_DEBUG_INVALID )
- {
- // No, so warn.
- Con::warnf( "Scene::setDebugOff() - Invalid debug option '%s' specified.", pDebugOption );
- continue;
- }
- // Merge into mask.
- mask |= debugOption;
- }
- }
- // Set debug mask.
- object->setDebugOff(mask);
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getDebugOn, bool, 3, 3, "(debugMode) Gets the state of the debug mode.\n"
- "@param The specific debug mode to check active state of.\n"
- "@return Returns true if active, false if not.")
- {
- const U32 mask = 1 << dAtoi(argv[2]);
- return object->getDebugMask() & mask;
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setDebugSceneObject, void, 3, 3, "(sceneObject) Sets the scene object to monitor in the debug metrics.\n"
- "@param SceneObject The scene object to monitor in the debug metrics.\n"
- "@return No return value.\n")
- {
- // Fetch scene object Id.
- const SimObjectId sceneObjectId = dAtoi(argv[2]);
- // Find scene object.
- SceneObject* pSceneObject = dynamic_cast<SceneObject*>( Sim::findObject(sceneObjectId) );
- // Sanity!
- if ( !pSceneObject )
- {
- Con::warnf("Scene::setDebugSceneObject() - Could not find scene object %d.", sceneObjectId);
- return;
- }
- // Set debug object.
- object->setDebugSceneObject( pSceneObject );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getDebugSceneObject, S32, 2, 2, "( Gets the scene object being monitored in the debug metrics.\n"
- "@return The scene object being monitored in the debug metrics (zero if none being monitored).\n")
- {
- // Fetch scene object.
- SceneObject* pSceneObject = object->getDebugSceneObject();
- if ( pSceneObject == NULL )
- return 0;
- return pSceneObject->getId();
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setLayerSortMode, void, 4, 4, "(layer, sortMode) Sets the layer to use the specified render sort mode.\n"
- "@param layer The layer to modify.\n"
- "@param sortMode The sort mode to use on the specified layer.\n"
- "@return No return value." )
- {
- // Fetch the layer.
- const U32 layer = dAtoi(argv[2]);
- // Fetch the sort mode.
- const SceneRenderQueue::RenderSort sortMode = SceneRenderQueue::getRenderSortEnum( argv[3] );
- object->setLayerSortMode( layer, sortMode );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getLayerSortMode, const char*, 3, 3, "(layer) Gets the render sort mode for the specified layer.\n"
- "@param layer The layer to retrieve.\n"
- "@return The render sort mode for the specified layer." )
- {
- // Fetch the layer.
- const U32 layer = dAtoi(argv[2]);
- // Fetch the sort mode.
- return SceneRenderQueue::getRenderSortDescription( object->getLayerSortMode( layer ) );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, resetDebugStats, void, 2, 2, "() Resets the debug statistics.\n"
- "@return No return value." )
- {
- object->resetDebugStats();
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getFPS, F32, 2, 2, "() Gets the current average frames-per-second.\n"
- "@return The current average frames-per-second.")
- {
- return object->getDebugStats().fps;
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getMinFPS, F32, 2, 2, "() Gets the minimum average frames-per-second.\n"
- "@return The minimum Faverage frames-per-second.")
- {
- return object->getDebugStats().minFPS;
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getMaxFPS, F32, 2, 2, "() Gets the maximum average frames-per-second.\n"
- "@return The average frames-per-second.")
- {
- return object->getDebugStats().maxFPS;
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getFrameCount, S32, 2, 2, "() Gets the current rendered frame count.\n"
- "@return The current rendered frame count.")
- {
- return (S32)object->getDebugStats().frameCount;
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setBatchingEnabled, void, 3, 3, "( bool enabled ) Sets whether render batching is enabled or not.\n"
- "@param enabled Whether render batching is enabled or not.\n"
- "return No return value.\n" )
- {
- // Fetch args.
- const bool enabled = dAtob(argv[2]);
- // Sets batching enabled.
- object->setBatchingEnabled( enabled );
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, getBatchingEnabled, bool, 2, 2, "() Gets whether render batching is enabled or not.\n"
- "return Whether render batching is enabled or not.\n" )
- {
- // Gets batching enabled.
- return object->getBatchingEnabled();
- }
- //-----------------------------------------------------------------------------
- ConsoleMethod(Scene, setIsEditorScene, void, 3, 3, "() Sets whether this is an editor scene\n"
- "@return No return value.")
- {
- object->setIsEditorScene(dAtob(argv[2]));
- }
|