Different types of rigid-body contact testing

Source: Internet
Author: User

A rigid body in contact with any type of inductive rigid body, preslove and Postslove will ignore execution only. The test code is as follows:

package{ImportBox2D.Common.Math.b2Vec2; ImportBox2D.Dynamics.b2Body; ImportFlash.text.TextField; ImportBox2D.Dynamics.Contacts.b2Contact; ImportBox2D.Collision.b2Manifold; ImportBox2D.Dynamics.b2ContactImpulse; ImportCom.bit101.components.TextArea; ImportCom.bit101.components.PushButton; Importflash.events.MouseEvent;  Public classMainextendsbasemain{ Public functionMain () {Super(NewB2VEC2 (0,0)); }                Private var_box:b2body; Private var_textarea:textarea; Private var_clearbtn:pushbutton; Override protectedfunctionInit ():void{            //Static sensorCreatetxt (60,200,"Static sensor"); varStaticsensorbox:b2body=createbox (100,100,60,200);            Staticsensorbox.settype (B2body.b2_staticbody); Staticsensorbox.setsensor (true); Staticsensorbox.setallowmovement (false); Staticsensorbox.setuserdata ({type:"Static sensor"}); //StaticCreatetxt (60,400,"Static"); varStaticbox:b2body=createbox (100,100,60,400);            Staticbox.settype (B2body.b2_staticbody); Staticbox.setallowmovement (false); Staticbox.setuserdata ({type:"Static"}); //kinematic sensorCreatetxt (300,200,"kinematic sensor"); varKinematicsensorbox:b2body=createbox (100,100,300,200);            Kinematicsensorbox.settype (B2body.b2_kinematicbody); Kinematicsensorbox.setsensor (true); Kinematicsensorbox.setallowmovement (false); Kinematicsensorbox.setuserdata ({type:"kinematic sensor"}); //kinematicCreatetxt (300,400,"Kinematic"); varKinematicbox:b2body=createbox (100,100,300,400);            Kinematicbox.settype (B2body.b2_kinematicbody); Kinematicbox.setallowmovement (false); Kinematicbox.setuserdata ({type:"Kinematic"}); //Dynamic SensorCreatetxt (500,200,"Dynamic Sensor"); varDynamicsensorbox:b2body=createbox (100,100,500,200);            Dynamicsensorbox.settype (B2body.b2_dynamicbody); Dynamicsensorbox.setsensor (true); Dynamicsensorbox.setallowmovement (false); Dynamicsensorbox.setuserdata ({type:"kinematic sensor"}); //DynamicCreatetxt (500,400,"Dynamic"); varDynamicbox:b2body=createbox (100,100,500,400);            Dynamicbox.settype (B2body.b2_dynamicbody); Dynamicbox.setallowmovement (false); Dynamicbox.setuserdata ({type:"Kinematic"}); varBox:b2body=createbox (40,40,300,40); Box.            Setcontactbegincallback (Contactbegin); Box.            Setpresolvecallback (Presolve); Box.            Setpostsolvecallback (Postsolve); Box.            Setcontactendcallback (Contactend); _box=box; _textarea=NewTextArea (NULL, 10, 10,""); Addchildat (_textarea,0); _CLEARBTN=NewPushbutton ( This, 220, 10,"Clear", Clearhandler); _clearbtn.setsize (50,20); }                Private functionContactbegin (contact:b2contact):void{contacthandler (Contact,"Begin"); }        Private functionPresolve (Contact:b2contact,oldmanifold:b2manifold):void{contacthandler (Contact,"Pre"); }        Private functionPostsolve (Contact:b2contact,impulse:b2contactimpulse):void{contacthandler (Contact,"POST"); }        Private functionContactend (contact:b2contact):void{contacthandler (Contact,"End"); }                Private functionContacthandler (contact:b2contact,cbtype:string):void{            varb1:b2body=Contact . Getfixturea ().            GetBody (); varb2:b2body=Contact . Getfixtureb ().            GetBody (); varOb:b2body= (B1==_box)?b2:b1; varotype:string=ob.            Getuserdata (). Type; Print ("BodyType:"+otype,"Cbtype:"+Cbtype); }                Private functionCreatetxt (x: NumberY: Number, text:string):void{            varTxt:textfield=NewTextField (); Txt.htmltext="<font color= ' #ffffff ' size= ' >"+text+"</font>"; Txt.x=x-txt.textwidth*0.5; Txt.y=y-txt.textheight*0.5;        AddChild (TXT); }                Private functionClearhandler (e:mouseevent):void{_textarea.text=""; }                Private functionPrint (.... params):void{            vartext:string="";  for(vari:int=0; i<params.length; i++) text+=params[i]+" "; _textarea.text+=text+"\ n"; }            };}

SOURCE Download: Https://yunpan.cn/cxx6C2BgWAYqY access password a205

Different types of rigid-body contact testing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.