A component holding one or more Joint3D, defining connections between a 3D Physics Body and anchors according to velocity and/or position constraints.
More...
Inherits Quantum.IComponent.
|
void | AddJoint (FrameBase f, ref Joint3D joint) |
| Adds a Joint3D to the component. If the buffer is at full Capacity, a new buffer will be allocated with double the capacity and existing entries are copied over. In that case, the previous buffer is not disposed immediately and cached pointers are still valid, although outdated. More...
|
|
JointsIterator3D | GetIterator (FrameBase f, bool reverseOrder=true) |
| Gets an auxiliary struct to iterate over the joints in this component. See also TryGetJoints and GetJoints to have direct access to the buffer. More...
|
|
Joint3D * | GetJoints (FrameBase f, out Int32 count) |
| Gets the currently allocated buffer for the component joints. See also GetIterator to iterate over the buffer with an auxiliary structure. More...
|
|
void | RemoveAt (FrameBase f, int index) |
| Removes the joint at the specified index of the component's joints buffer, while keeping the order of the remaining objects. If the remaining elements do not need to be kept in order, RemoveAtUnordered is a cheaper option. More...
|
|
void | RemoveAtUnordered (FrameBase f, int index) |
| Removes the joint at the specified index of the component's joints buffer. The order of the elements with indices greater than index is not kept. If the order must be kept, use RemoveAt instead. More...
|
|
bool | RemoveJoints (FrameBase f, int? userTag=null) |
| Removes all joints in the component that have a Joint3D.UserTag field matching the specified userTag . If none is specified, all joints are removed. More...
|
|
bool | TryGetJoints (FrameBase f, out Joint3D *joints, out Int32 count) |
| Gets the currently allocated buffer for the component joints, if it has one. See also GetIterator to iterate over the buffer with an auxiliary structure. More...
|
|
|
UInt16 | Capacity [get] |
| The number of joints the currently allocated buffer can hold before having to be resized. More...
|
|
UInt16 | Count [get] |
| The current amount of joints tracked by the component. More...
|
|
A component holding one or more Joint3D, defining connections between a 3D Physics Body and anchors according to velocity and/or position constraints.
◆ AddJoint()
Adds a Joint3D to the component. If the buffer is at full Capacity, a new buffer will be allocated with double the capacity and existing entries are copied over. In that case, the previous buffer is not disposed immediately and cached pointers are still valid, although outdated.
- Parameters
-
f | The current frame. |
joint | The joint that will be added to the component. |
◆ RemoveJoints()
bool Quantum.PhysicsJoints3D.RemoveJoints |
( |
FrameBase |
f, |
|
|
int? |
userTag = null |
|
) |
| |
|
inline |
Removes all joints in the component that have a Joint3D.UserTag field matching the specified userTag . If none is specified, all joints are removed.
This method does not keep the order of remaining elements in the buffer. To achieve that instead, use GetJoints and RemoveAt while iterating the buffer in reverse order.
- Parameters
-
f | The current frame. |
userTag | A numerical tag that can be used to identify a joint or a group of joints. Any joint in the component that matches the tag will be removed. If none is specified, all joints are removed. |
- Returns
- True if at least one joint has been removed.
const int removeJointsUserTag = 42;
var jointsComponent = f.Unsafe.GetPointer<PhysicsJoints3D>(entity);
if (removeAll) {
jointsComponent->RemoveJoints(f);
} else {
jointsComponent->RemoveJoints(f, removeJointsUserTag);
}
◆ RemoveAt()
void Quantum.PhysicsJoints3D.RemoveAt |
( |
FrameBase |
f, |
|
|
int |
index |
|
) |
| |
|
inline |
Removes the joint at the specified index of the component's joints buffer, while keeping the order of the remaining objects. If the remaining elements do not need to be kept in order, RemoveAtUnordered is a cheaper option.
- Parameters
-
f | The current frame. |
index | The index of the element to be removed. |
- Exceptions
-
NullReferenceException | If the joints buffer is not allocated. |
ArgumentOutOfRangeException | If the index is outside the valid range. |
var jointsComponent = f.Unsafe.GetPointer<PhysicsJoints3D>(entity);
if (jointsComponent->TryGetJoints(f, out var joints, out var count)) {
for (var i = count - 1; i >= 0; i–) {
var current = joints + i;
if (current->Type == Physics3D.JointType3D.DistanceJoint) {
jointsComponent->RemoveAt(f, i);
}
}
}
◆ RemoveAtUnordered()
void Quantum.PhysicsJoints3D.RemoveAtUnordered |
( |
FrameBase |
f, |
|
|
int |
index |
|
) |
| |
|
inline |
Removes the joint at the specified index of the component's joints buffer. The order of the elements with indices greater than index is not kept. If the order must be kept, use RemoveAt instead.
- Parameters
-
f | The current frame. |
index | The index of the element to be removed. |
- Exceptions
-
NullReferenceException | If the joints buffer is not allocated. |
ArgumentOutOfRangeException | If the index is outside the valid range. |
var jointsComponent = f.Unsafe.GetPointer<PhysicsJoints3D>(entity);
if (jointsComponent->TryGetJoints(f, out var joints, out var count)) {
for (var i = count - 1; i >= 0; i–) {
var current = joints + i;
if (current->Type == Physics3D.JointType3D.DistanceJoint) {
jointsComponent->RemoveAtUnordered(f, i);
}
}
}
◆ TryGetJoints()
bool Quantum.PhysicsJoints3D.TryGetJoints |
( |
FrameBase |
f, |
|
|
out Joint3D * |
joints, |
|
|
out Int32 |
count |
|
) |
| |
|
inline |
Gets the currently allocated buffer for the component joints, if it has one. See also GetIterator to iterate over the buffer with an auxiliary structure.
- Parameters
-
f | The current frame. |
joints | The allocated buffer for the component joints. Null if the buffer is not allocated. |
count | The number of elements used in the buffer at the moment this method is called. 0 if the buffer is not allocated. |
- Returns
- True if the buffer is allocated.
var jointsComponent = f.Unsafe.GetPointer<PhysicsJoints3D>(entity);
if (jointsComponent->TryGetJoints(f, out var joints, out var count)) {
for (var i = 0; i < count; i++) {
var current = joints + i;
Log.Info($"Joint Type {i}: {current->Type}");
}
}
◆ GetJoints()
Gets the currently allocated buffer for the component joints. See also GetIterator to iterate over the buffer with an auxiliary structure.
- Parameters
-
f | The current frame. |
count | The number of elements used in the buffer at the moment this method is called. |
- Returns
- The allocated buffer for the component joints.
- Exceptions
-
NullReferenceException | If the buffer is not allocated. |
var jointsComponent = f.Unsafe.GetPointer<PhysicsJoints3D>(entity);
var joints = jointsComponent->GetJoints(f, out var count);
for (var i = 0; i < count; i++) {
var current = joints + i;
Log.Info($"Joint Type {i}: {current->Type}");
}
◆ GetIterator()
Gets an auxiliary struct to iterate over the joints in this component. See also TryGetJoints and GetJoints to have direct access to the buffer.
If new elements are added while iterating and this causes the buffer to be expanded, the iterator will keep iterating over the previous buffer, which is not immediately disposed (see AddJoint). In this case, further changes to elements in the buffer being iterated will not modify the elements on the new buffer. Hence, the addition of elements while iterating is not recommended, unless the access to the elements are read-only.
- Parameters
-
f | The current frame. |
reverseOrder | If the buffer elements should be iterated in reverse order. If true, allows the removal of elements while iterating without it causing some elements to be skipped. |
- Returns
- A JointsIterator3D for the buffer of joints in this component.
var jointsComponent = f.Unsafe.GetPointer<PhysicsJoints3D>(entity);
var jointsIterator = jointsComponent->GetIterator(f);
while (jointsIterator.MoveNext()) {
jointsIterator.CurrentUnsafe->Enabled = true;
var jointCopy = jointsIterator.Current;
Assert.Check(jointCopy.Enabled);
if (jointCopy.Type == Physics3D.JointType3D.None) {
jointsComponent->RemoveAtUnordered(f, jointsIterator.CurrentIndex);
}
}
◆ Count
UInt16 Quantum.PhysicsJoints3D.Count |
|
get |
The current amount of joints tracked by the component.
◆ Capacity
UInt16 Quantum.PhysicsJoints3D.Capacity |
|
get |
The number of joints the currently allocated buffer can hold before having to be resized.