AppleSCNPhysicsBody - UBogun/Xojo-iosLib GitHub Wiki
Inherits from AppleObject
Memory leak check: not yet done.
Status: complete.
An SCNPhysicsBody object is used to add physics simulation to a node. When SceneKit prepares to render a new frame, it performs physics calculations on physics bodies attached to nodes in the scene. These calculations include gravity, friction, and collisions with other bodies. You can also apply your own forces and impulses to a body. After SceneKit completes these calculations, it updates the positions and orientations of the node objects before rendering the frame.
Constructors
Constructor (Type as SCNPhysicsBodyType, opt. shape as AppleSCNPhysicsShape = nil): Creates a physics body with the specified type and shape. If you pass nil for the shape parameter, SceneKit automatically creates a physics shape for the body when you attach it to a node, based on that node’s geometry property.
The following constructors are available as class (shared) methods:
DynamicBody() As AppleSCNPhysicsBody: Creates a physics body that can be affected by forces and collisions.
KinematicBody() As AppleSCNPhysicsBody: Creates a physics body that is unaffected by forces or collisions but that can cause collisions affecting other bodies when moved.
StaticBody() As AppleSCNPhysicsBody: Creates a physics body that is unaffected by forces or collisions and that cannot move.
SCNPhysicsBodyType | Definition |
---|---|
StaticType | A physics body that is unaffected by forces or collisions and cannot move. Use static bodies to construct fixtures in your scene that other bodies need to collide with but that do not themselves move, such as floors, walls, and terrain. |
DynamicType | A physics body that can be affected by forces and collisions. Use dynamic bodies for the elements of your scene that are moved by the physics simulation. |
KinematicType | A physics body that is unaffected by forces or collisions but that can cause collisions affecting other bodies when moved. Use kinematic bodies for scene elements that you want to control directly directly but whose movement manipulates other elements. For example, to allow the user to push objects around with a finger, you might create a kinematic body and attach it to an invisible node that you move to follow touch events. |
Properties
AffectedByGravity As Boolean: A Boolean value that determines whether the constant gravity of a scene accelerates the body. Available since iOS 9.0. Default True.
AllowsResting As Boolean: A Boolean value that specifies whether SceneKit can automatically mark the physics body at rest. Default True.
AngularDamping As Double: A factor that reduces the body’s angular velocity.
AngularVelocity As SCNVector4: A vector describing both the current rotation axis and rotational speed (in radians per second) of the physics body.
AngularVelocityFactor As SCNVector3: A multiplier affecting how SceneKit applies rotations computed by the physics simulation to the node containing the physics body.
Use this property to constrain or restrict the effect of physics simulation on the node containing the physics body. For example, you can force a body to rotate in only one axis by setting its angular velocity factor to {0.0, 1.0, 0.0}.
CategoryBitMask As Uinteger: A mask that defines which categories the body belongs to.
Charge As Double: The electric charge of the body, in coulombs.
CollisionBitMask As Uinteger: A mask that defines which categories of physics bodies can collide with this physics body.
ContactTestBitMask As Uinteger: A mask that defines which categories of bodies cause intersection notifications with this physics body. Available since iOS 9.0.
For applications running iOS 8, this property’s value matches that of the collisionBitMask property—that is, SceneKit sends contact messages if and only if a collision occurs. For applications running on iOS 9 or later, this property’s value defaults to zero and need not match the collision mask—that is, a pair of bodies generates contact messages whenever the bodies intersect, regardless of whether they collide or pass through one another.
Damping As Double: A factor that reduces the body’s linear velocity.
Friction As Double: The body’s resistance to sliding motion.
Mass As Double: The mass of the body, in kilograms.
MomentOfInertia As SCNVector3: The body’s moment of inertia, expressed in the local coordinate system of the node that contains the body. Available since iOS 9.0.
Using a custom moment of inertia requires setting the usesDefaultMomentOfInertia property to False.
PhysicsShape As AppleSCNPhysicsShape: An object that defines the solid volume of the physics body for use in collision detection.
Resting As Boolean: A Boolean value that indicates whether the physics body is at rest. (read-only)
Restitution As Double: A factor that determines how much kinetic energy the body loses or gains in collisions.
RollingFriction As Double: The body’s resistance to rolling motion.
Type As SCNPhysicsBodyType: A constant that determines how the physics body responds to forces and collisions. See Constructor.
UsesDefaultMomentOfInertia As Boolean: A Boolean value that determines whether SceneKit automatically calculates the body’s moment of inertia or allows setting a custom value. Available since iOS 9.0. Default True.
Velocity As SCNVector3: A vector describing both the current speed (in meters per second) and direction of motion of the physics body.
VelocityFactor As SCNVector3: A multiplier affecting how SceneKit applies translations computed by the physics simulation to the node containing the physics body. Use this property to constrain or restrict the effect of physics simulation on the node containing the physics body. For example, you can force a body to move in only two dimensions by setting its velocity factor to {1.0, 1.0, 0.0}.
Methods
ApplyForce (Force as SCNVector3, instantaneous as Boolean = false): Applies a force or impulse to the body at its center of mass. If instantaneous does so directly, else at the end of the simulation step.
ApplyForce (Force as SCNVector3, Position as SCNVector3, instantaneous as Boolean = false): Applies a force or impulse to the body at a specific point. If instantaneous does so directly, else at the end of the simulation step.
ApplyTorque (Torque as SCNVector4, instantaneous as Boolean = false): Applies a net torque or a change in angular momentum to the body. If instantaneous does so directly, else at the end of the simulation step.
ClearAllForces(): Cancels all continuous forces and torques acting on the physics body during the current simulation step.
ResetTransform(): Updates the position and orientation of a body in the physics simulation to match that of the node to which the body is attached.
If you change the position or orientation of a node with an attached static or dynamic physics body, call this method afterward to ensure that the physics simulation incorporates the change. You need not call this method for kinematic bodies.
Note that dynamic and physics bodies are designed to be moved only by the physics simulation or not at all. You may use this method to move them regardless of this restriction, but at a cost to performance.