Physics - Nadarenost

advertisement
Centar "Bistrić"
Upute za napredne programere
Physics
(see Wikipedia)
Overview
The goal was to add real time realistic physics behavior to Active Worlds,
without the need to wrestle the targeted hardware nor set up esoteric parameters
to get the correct timing for your simulation. You only need to know basic physics
principles to produce realistic physics behavior using a few simple action
commands.
The first step of adding physics to Active Worlds is done by defining colliders.
Colliders are geometries/boundaries that define the outlines of 3D geometries,
also called meshes.
3D meshes may have an arbitrary shape. To reduce load and to increase
calculation speed of physics a good deal, it is wise to use primitives for colliders,
rather than the shape of the native 3D mesh.
Most of the objects can be substituted by a collider box, a sphere or a cone.
Collider primitives
Collider primitives represent the shape of a rendered 3D mesh within the physics
engine.
Box
A standard box primitive. This is the default, using the object's axis aligned
bounding box (AABB). Boxes work for most objects we deal with, for example
walls, floors, panels, small poles, etc.
Command: create collider box
Sphere
Sphere collisions are generalized ellipsoids, it can create many different kind of
objects by just playing with dimensions of the radius. This is a very flexible
primitive shape that uses the dimensions of the AABB for it's radius in all 3 axes.
If all 3 radius' are equal, it makes a perfect sphere. If two radius' are equal, it
makes an ellipse of revolution.
Command: create collider sphere
Page 1
Centar "Bistrić"
Upute za napredne programere
Cone
A cone of given radius and height, it gets from the AABB. The browser takes care
of correct alignment for most common cases. It is aligned with the x axis after
creation. The cone height must be greater than or equal to the diameter of the
cap. If this is not the case, then the height will be clamped to the diameter.
Command: create collider cone
Cylinder
A cylinder of given radius and height, where it uses the AABB for the calculation
of height and radius and takes care of correct alignment with the x axis after
creation. The ground and top plane of the cylinder must be equal circles and must
have the same radius. If the ground and top planes are elipsoids, you are better
using a box or sphere primitive instead.
Command: create collider cylinder
Capsule
A capsule is similar to a cylinder, just that it's bottom and top shapes are rounded.
Command: create collider capsule
Convex Hull
This is the primitive that aims the shape the original geometry the best. Use it with
care and only if really needed, as the 3D mesh can be rather complex and
thereby it can produce heavy load to your computer. It is useful for getting objects
to interact with exterior curved surfaces of the model it is applied to.
Command: create collider hull
Tree Collision
TreeCollision is the preferred method for collision with polygonal meshes of
arbitrary complexity. The mesh must be made of flat non-intersecting polygons,
but they do not explicitly need to be triangles. It is also useful for getting objects to
interact with interior curved surfaces of the model it is applied to. When a
TreeCollision is assigned to a body the mass of the body is ignored in all
dynamics calculations. This makes the body behave as a static body.
Command: create collider tree
Mass
The mass is given as an optional attribute to the collider action command. Only
positive values are possible. If no mass is specified, the volume of the collider
primitive is used to calculate a default mass, which works well for most cases.
Page 2
Centar "Bistrić"
Upute za napredne programere
The mass of an object is important to calculate the impact it has on other bodies
when it hits them.
A mass of zero makes the collider static and its body is ignored in all dynamics
calculations. Other bodies still collide with this body, but this body won't move.
Don't mistake mass for the weight of an object. An object's weight is actually its
mass multiplied to the applied gravity. On earth weight is 9.81 times more than
the mass of a phyiscs body. Resulting that weight is actually the force that pulls a
body down on earth and the mass of the same body is independend of gravity. If
you define a mass of 10 kilograms to a physics body, it actually has a weight of
98.1 Newtons on earth, where as on Moon the same body with 10 kilograms only
has a weight of 1.63 Newtons.
Gravity
The world's gravity is used as a continuous force applied in vertical direction to
bodies with a mass greater than zero. If a body is currently within a zone, the
zone's gravity is applied onto this body. A value of 1.0 for gravity will simulate the
average gravity on earth. A positive value for gravity will pull all bodies within the
physics simulation downwards, and a negative gravity will pull them upwards. A
zero value for gravity will simulate an outer space experience.
The optional nograv statement to the collider action command overrides the
world's gravity setting and forces this particular body to act as it was in outer
space.
Static Objects
A mass of zero makes the collider static and its body is ignored in all dynamics
calculations. Other bodies still collide with this body, but this body won't move.
Tree collisions always act as static bodies, even they have a positive mass
applied.
The optional static statement to the collider action command forces an collider
shape to act as static body.
The terrain acts as static object inworld by default.
Building with Physics
As soon an object is selected for edit, or as soon build mode is activated, the
physics simulation will stop immediately and all objects are reset to their initial
position in world. When all objects are deselected and build mode is off, the
physics simulation will start over.
Page 3
Centar "Bistrić"
Upute za napredne programere
Thus making it easy to build, to reset and to test the physics simulation while
building.
The currently implemented physics specific action commands in build 1123 are
create/activate/bump addforce x y z [pitch yaw roll] [global] [name=abc]
create/activate/bump addtorque pitch yaw roll [global] [name=abc]
create/activate/bump collider box|sphere|... mass=m [static|nogravity]
[avvel] [dampLin=v] [dampAng=v] [global] [name=abc]
create/activate/bump colltag number
create/activate/bump velocity x y z [pitch yaw roll] [ltm] [global]
[name=abc]
Scaling
Scaling, as well as dynamically scaling objects, is supported. Be aware that objects that are
dynamically scaled while in the engine's autosleep mode, will not collide with other objects,
unless either the collider itsself or the other physics object is moving.
Move and Rotate
When the commands move and rotate are used on an object, the object will be
removed from physics considerations. The move and rotate commands do not
follow physics, they are in contradiction to the physics engine's behavior.
Stats
Stats are shown in the lower left corner of the 3D render window when running in 3D
designer video mode. All shown values are and average of the past second and are updated
in a 1 second interval.
Phys.Memory Used shows the total memory used my the physics engine. It includes
all collision geomtries and its internal a cache.
Physics Bodies shows the total count of updated bodies and next to it the total count
of static bodies added to the current physics simulation.
Updated Bodies shows the total count of bodies that are updated to their new position
following physics behavior.
Constraints shows the total count of relations between bodies, either static or
dynamic bodies.
Time shows the time needed to calculates the real time realistic physics simulation.
The delay shows the time the simulation is behind, as a consequence of very low frame
rates.
Page 4
Centar "Bistrić"
Upute za napredne programere
Considerations with Dynamic Objects
Use the correct collider shape. The collider shape should match the shape of the original
object as close as possible to avoid unexpected behavior. E.g. applying a sphere type collider to a
cube shaped objects will look unnaturally in its physics behavior.
Do not overlap objects. Overlapped objects lead to physics reaction looking like explosions.
Avoid inballanced masses. Applying masses to objects may be tricky. If the difference in
masses of two colliding objects is too far off, it will probably lead to unexpected physical behavior.
By default the mass is calculated based on the object's volume, what leads to natural behavior in
most cases.
Avoid to apply the same mass to all objects regardless to their individual size and shape, what
also may lead to odd behavior.
Avoid using small or thin objects, like panels or zero-thickness walls or floors, as supporter of
a stacked build. A card house becomes unstable easily.
Avoid too high forces applied to objects. This may lead to very high speeds of objects when
collisions can not be calcualted precise enough.
Neither the mass nor applied forces are limited at this time. It is up to you to apply the right
forces within your physics simulation.
Physics Feature Notes
An invisible object may act as a collider and a force can be applied on it also.
Scaling applied to an object is also considered with physics, in its represented size and in its
mass calculation.
Objects without collider definition, which is the default, won't interact with physics in any way.
Physics related action commands can not be combined with move or rotate commands.
The physics simulation speed may get delayed when the rendering frame rate drops below 15
Hz.
The physics simulation runs on your local computer and can be optionally synchronized when
it is initiated by an addforce or collider action command with the global statement added.
A physics simulation is restricted within a cube in the size of 1200 by 1200 by 1200 meters. If
physics objects fall outside this cube, they will remain on that last spot until all physics are reset.
Objects that fall outside of visual view range, are removed from the physics simulation also.
Physics can be used within huge worlds. The cube of physics, as mentioned above, moves
with your location in world.
Page 5
Centar "Bistrić"
Upute za napredne programere
DODATAK
Primjer korištenja naredbi za fiziku u svijetu AWTeen na terenima Bistrić
Lokacija : AWTeen 19.98S 3238.99W 0.14a 137
Obratite pozornost:
1. Bačve su definirane kao "collider cylinder" ili "collider capsule"
2. Kosina i zidovi definirani su kao "collider tree", pa tako bačve ne
mogu prolaziti kroz njih nego se kotrljaju i odbijaju.
3. Bačve koje se nalaze iznad kosine (vidi sliku) mogu se gurnuti na
kosinu jednostavnim klikom miša jer se pokreću naredbom
"activate velocity X Y Z" kao i sve bačve koje su se dokotrljale.
4. Osim klikanjem miša bačve se mogu gurati i kotrljati tako da ih vaš
avatar gura - jer su sve definirane kao "collider avvel".
Zbog vježbe pokušajte SVE bačve gurnuti u bazen !
Page 6
Download