| Force |
Besides joints, you can also define forces between two objects.
This is done by using the Force object. Example:
//use some material
factory.material = Material(1e-6, .2, .9, 0.1);
var A = Box({10,10,10},{0,100,0}); // create two objects
var B = Box({10,10,10}, {0,50,0});
A.color = RGB(255,0,0); // assign some colors
B.color = RGB(255,255,0);
A .static = true; // topmost object is static
// create a force between A and B, it is attached to the local
// origin of both objects
var f = Force(A, {0,0,0}, B , {0,0,0});
// create a function that will calculate the amount of force
// to be applied by 'f'.
function f_func()
{
return norm(A.position - B.position)-70;
};
f.force = f_func; //assign the function to 'f'
// simulate scene
while (simulator.time < 1)
{
WaitFrame();
simulator.run(.01 );
};
Each end of the force object is attached to an object at a local position on
that object. The expressed force is directed along the line between the two
endpoints and has a size equal to the force property of the Force instance.
|