Adobe ATMOSPHERE User Manual page 308

Table of Contents

Advertisement

296
APPENDIX E
// Make the box spin when it is clicked on
box.physicalModel.applyAngularImpulse(Vector(1,0,0));
}
removeAnimator(this);
}
}
addAnimator(box);
applyImpulse(Vector impulse, Vector position)
This function increments the linear momentum of the physical model by a specifi ed amount, and also updates
the angular momentum, in a way that is consistent with the impulse being applied to a given position within the
physical model. The direction of the impulse vector defi nes the direction of applied force, and the magnitude
of the vector determines the amount of linear momentum applied. A linear impulse may be thought of as a
large force applied for a short time, with the magnitude of the force being multiplied by the duration to get the
amount of linear momentum change. A classic use of an impulse is to simulate the effect of a bullet hitting an
object at a specifi ed location. Since the impulse is not calculated to be at the center of mass, the object might
start to spin as well.
Lastly, An impulse is measured in units of force times time, or "momentum". So, to get an object from rest up to
a velocity of 1 foot per second, you would need to apply an impulse equal to the mass of the object.
box = SceneGroup("./box.aer").add();
box.timestep = function()
{
if(this.loaded)
{
this.physicalModel = this.createPhysicalModel(10);
this.physicalModel.collide = true;
this.root = this.getSolidObject(0).rootPrimitive;
this.root.onClick = function()
{
mouseX
mouseY
camera
rayOrigin = camera.position;
rayDir
distance
intersection = Vector(rayOrigin.x + rayDir.x * distance,
impulse
// Push the box at the point where it is clicked on
box.physicalModel.applyImpulse(impulse, intersection);
= application.getView(0).mouseX;
= application.getView(0).mouseY;
= application.getView(0).getCamera(0);
= camera.getRayDirectionFromPixelCoords(mouseX, mouseY);
= stageModel.rayIntersectionDistance(rayOrigin, rayDir);
rayOrigin.y + rayDir.y * distance,
rayOrigin.z + rayDir.z * distance);
= rayDir.scale(10);

Advertisement

Table of Contents
loading

Table of Contents