Search in sources :

Example 6 with CollisionManager

use of artisynth.core.mechmodels.CollisionManager in project artisynth_core by artisynth.

the class PenetrationRendererDemo method build.

public void build(String[] args) {
    // create MechModel and add to RootModel
    MechModel mech = new MechModel("mech");
    addModel(mech);
    // create and add the ball and plate
    RigidBody ball = RigidBody.createIcosahedralSphere("ball", 0.8, 0.1, 1);
    // ball.setPose (new RigidTransform3d (0, 0, 2, 0.4, 0.1, 0.1));
    ball.setPose(new RigidTransform3d(0, 0, 0, 0.4, 0.1, 0.1));
    ball.setDynamic(false);
    mech.addRigidBody(ball);
    RigidBody plate = RigidBody.createBox("plate", 5, 5, 5, 1);
    plate.setPose(new RigidTransform3d(0, 0, 2.94, 1, 0, 0, 0));
    plate.setDynamic(false);
    mech.addRigidBody(plate);
    // turn on collisions
    mech.setDefaultCollisionBehavior(true, 0.20);
    // make ball transparent so that contacts can be seen more clearly
    RenderProps.setFaceStyle(ball, Renderer.FaceStyle.NONE);
    RenderProps.setDrawEdges(ball, true);
    RenderProps.setEdgeColor(ball, Color.WHITE);
    RenderProps.setVisible(plate, false);
    RenderProps.setAlpha(plate, 0.5);
    // enable rendering of contacts normals and contours
    CollisionManager cm = mech.getCollisionManager();
    RenderProps.setVisible(cm, true);
    RenderProps.setLineWidth(cm, 3);
    RenderProps.setLineColor(cm, Color.RED);
    RenderProps.setEdgeWidth(cm, 3);
    RenderProps.setEdgeColor(cm, Color.BLUE);
    cm.setContactNormalLen(0.5);
    cm.setDrawContactNormals(true);
    cm.setDrawIntersectionContours(true);
    cm.setDrawIntersectionFaces(true);
    cm.setDrawIntersectionPoints(true);
    CollisionResponse resp = mech.setCollisionResponse(ball, plate);
    addMonitor(new PenetrationRenderer(resp));
}
Also used : MechModel(artisynth.core.mechmodels.MechModel) RigidTransform3d(maspack.matrix.RigidTransform3d) CollisionManager(artisynth.core.mechmodels.CollisionManager) RigidBody(artisynth.core.mechmodels.RigidBody) CollisionResponse(artisynth.core.mechmodels.CollisionResponse)

Aggregations

CollisionManager (artisynth.core.mechmodels.CollisionManager)6 MechModel (artisynth.core.mechmodels.MechModel)5 RigidBody (artisynth.core.mechmodels.RigidBody)4 RigidTransform3d (maspack.matrix.RigidTransform3d)3 ControlPanel (artisynth.core.gui.ControlPanel)2 IOException (java.io.IOException)2 AffineTransform3d (maspack.matrix.AffineTransform3d)2 AxisAngle (maspack.matrix.AxisAngle)2 Vector3d (maspack.matrix.Vector3d)2 BodyConnector (artisynth.core.mechmodels.BodyConnector)1 CollisionResponse (artisynth.core.mechmodels.CollisionResponse)1 RevoluteJoint (artisynth.core.mechmodels.RevoluteJoint)1 SphericalJoint (artisynth.core.mechmodels.SphericalJoint)1 NumericInputProbe (artisynth.core.probes.NumericInputProbe)1 WayPoint (artisynth.core.probes.WayPoint)1 Color (java.awt.Color)1 File (java.io.File)1 PolygonalMesh (maspack.geometry.PolygonalMesh)1