I can think of two ways to implement rolling egg.

1. Use aim constraint to point in the direction of movement and have rolling axis as your up vector. The object can then roll about this up vector. I will implement this approach later.

2. Calculate rolling rotation around the rolling axis using matrix calculations.

!These approaches do not simulate the actual physics.!

I am currently working on 2nd approach. Here are some notes for both the approaches:

# First one will follow a path and will need some work to blend the direction changes so the object orientation does not jump.

# First method is more like driving a car so the object's front/rear side follows the direction of movement, egg however may or may not follow this kind of movement.

# Second method adds the rotation on top of the current rotation, so egg starts rolling in the direction of movement without any jump in it's orientation.

# First one will rely on expression only for small amount of work, hence reliable undo operations.

# Second method depends mainly on expression to avoid cycle and use of getAttr, setAttr is required. This leads to non-user friendly undo.

The main difficulty in 2nd method is in getting the rotation around the rolling axis. I understand the theoretical part of it, but I am having a bit difficult time implementing it. May be I am doing something wrong, but it's hard to debug it at this stage. Here is what I am doing:

- Find the direction of movement

- Find rolling axis using cross product

- Find a matrix difference between so that z-axis of egg rotation matrix matches rolling axis (Diff)

- Do this operation to rotate egg around rolling axis by R

F = Egg * Diff * R * Diff(-1)

- In above equation we first take the current egg rotation and then multiply it by "Diff" matrix to align z-axis with rolling axis. Then apply the rotation amount around z-axis and then just apply inverse of Diff matrix.

And here is the result.

You can see that in the beginning it rolls fine, but when direction changes rotation does not follow the rolling axis.

## No comments:

## Post a Comment