Archive for November, 2005

Intersection and Penetration Depth

November 28, 2005

So it has been two weeks since I started translating C++ SOLID code into Java code. Over the Thanksgiving weekend I intensely debugged my code such that it now runs reasonablely. One notable bug I have is that within the subroutine I cannot simply reassign the argument variable to a new object.

void test() {
  Vector3d v = new Vector3d();
  foo(v);
  System.out.println(v.x + " " + v.y + " " + v.z); // still (0.0, 0.0, 0.0)
}

void foo(Vector3d v) {
  Vector3d a = new Vector3d(1.0, 2.0, 3.0);
  v = a; // this has no effect on v
}

When checking the results from Penetration.java, it is found that the calculation of penetration depth is soemewhat unstable and slow. My to-do list will just have to expand:

  • To understand the GJK algorithm more deeply.
  • To thoroughly test my current implementation.

I think it is quite reasonable to assume only one contact point when two convex objects contact or intersect/impact. Thus the penetration depth and the impact normal can be conveniently calculated from the GJK subroutines. I implemented this idea by modifying BoxBoxCollider.java today and the test results are satisfactory so far with minor observed intersections. The results certainly look better than the ODE implementation, which I don’t fully understand either. Let’s assume now the convex problems are resolved. Then I still need to investigate the complex/trimesh problems. More items on to-do list:

  • Check SOLID complex package and try to implement a corresponding one for my trimesh. Can RAPID code be integrated here?
  • Try two packaging and delivery methods – applet and web start.

Crank Model Now Works

November 1, 2005

Last Friday I expanded the piston assembly model to a full cranktrain model. The original Smith method worked immediately, but Baraff method did not. Today I finally have the bug fixed 🙂 My confidence in the Baraff method rises as the results match pretty well with those of the Smith method. Now the performace of the Baraff method is still a question mark. I don’t feel the program running any faster using the new method.

The bug fix is within buildTree() in World2.java

  TreeNode buildTree(Body b) {
    // get b = the next enabled, untagged body, and tag it
    if (b.tag!=0 || (b.flags & Body.Disabled)!=0) return null;
    b.tag = 1;

    aux.clear();
    LinkedList stack = new LinkedList();
    // tag all bodies and joints starting from b
    TreeNode root = new TreeNode(b, null);
    TreeNode node = root, childnode;
    stack.addFirst(node);
    while (stack.size() > 0) {
      node = (TreeNode)stack.removeFirst();  // pop body node off stack
      b = node.body;

      // traverse and tag all body's joints,
      // add untagged connected bodies to stack
      Iterator j = b.nodes.iterator();
      while(j.hasNext()) {
        JointNode jn = (JointNode)j.next();
        if(jn.joint.tag==0) {
          jn.joint.tag = 1;
          if(jn.body!=null && jn.body.tag==0) {
            childnode = new TreeNode(jn.joint, node);
            childnode = new TreeNode(jn.body, childnode);
            jn.body.tag = 1;
            stack.addFirst(childnode);
          }
          else
            aux.add(n.joint); // put boundary joints into auxiliary joint list
        }
      }
    }
    return root;
  }