use of artisynth.core.util.ScalarRange in project artisynth_core by artisynth.
the class CollisionManager method setPenetrationDepthRange.
public void setPenetrationDepthRange(ScalarRange range) {
ScalarRange newRange = range.clone();
PropertyUtils.updateCompositeProperty(this, "penetrationDepthRange", myPenetrationDepthRange, newRange);
myPenetrationDepthRange = newRange;
}
use of artisynth.core.util.ScalarRange in project artisynth_core by artisynth.
the class CollisionRenderer method createPenetrationRenderObject.
RenderObject createPenetrationRenderObject(CollisionHandler handler, ArrayList<PenetratingPoint> points, ArrayList<PenetrationRegion> regions) {
RenderObject rd = new RenderObject();
HashMap<Vertex3d, Double> depthMap = new HashMap<Vertex3d, Double>();
double maxd = 0;
for (PenetratingPoint pp : points) {
depthMap.put(pp.vertex, pp.distance);
if (pp.distance > maxd) {
maxd = pp.distance;
}
}
ScalarRange range = handler.myBehavior.myPenetrationDepthRange;
range.updateInterval(0, maxd);
float[] rgb = new float[3];
for (int i = 0; i < 256; i++) {
handler.myManager.myColorMap.getRGB(i / 255.0, rgb);
rd.addColor(rgb);
}
Point3d wpnt = new Point3d();
Vector3d wnrm = new Vector3d();
for (PenetrationRegion region : regions) {
for (Face face : region.getFaces()) {
HalfEdge he = face.firstHalfEdge();
Vertex3d v0 = he.getHead();
Vertex3d v1 = he.getNext().getHead();
Vertex3d v2 = he.getTail();
v0.getWorldPoint(wpnt);
int pi0 = rd.addPosition(wpnt);
v1.getWorldPoint(wpnt);
int pi1 = rd.addPosition(wpnt);
v2.getWorldPoint(wpnt);
int pi2 = rd.addPosition(wpnt);
int ci0 = getColorIndex(range, v0, depthMap);
int ci1 = getColorIndex(range, v1, depthMap);
int ci2 = getColorIndex(range, v2, depthMap);
face.getWorldNormal(wnrm);
int ni = rd.addNormal(wnrm);
int v0idx = rd.addVertex(pi0, ni, ci0, -1);
int v1idx = rd.addVertex(pi1, ni, ci1, -1);
int v2idx = rd.addVertex(pi2, ni, ci2, -1);
rd.addTriangle(v0idx, v1idx, v2idx);
}
}
return rd;
}
use of artisynth.core.util.ScalarRange in project artisynth_core by artisynth.
the class PenetrationRender method prerender.
public void prerender(RenderList list) {
// In prerender, we update the color bar labels based on the updated
// penetration range stored in the collision behavior.
//
// Object references are obtained by name using 'findComponent'. This is
// more robust than using class member variables, since the latter will
// be lost if we save and restore this model from a file.
ColorBar cbar = (ColorBar) (renderables().get("colorBar"));
MechModel mech = (MechModel) findComponent("models/mech");
RigidBody body0 = (RigidBody) mech.findComponent("rigidBodies/body0");
RigidBody body1 = (RigidBody) mech.findComponent("rigidBodies/body1");
CollisionBehavior behav = mech.getCollisionBehavior(body0, body1);
ScalarRange range = behav.getPenetrationDepthRange();
cbar.updateLabels(0, 1000 * range.getUpperBound());
// call the regular prerender method
super.prerender(list);
}
Aggregations