Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qtquick3dphysics-shapes-bodies.qdoc
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5\page qtquick3dphysics-shapes-bodies.html
6\title Qt Quick 3D Physics Shapes and Bodies
7\brief An overview of Qt Quick 3D Physics objects and their physical shapes
8
9The objects in the simulation are represented by any of the following four types of bodies: \l{StaticRigidBody}, \l{DynamicRigidBody}, \l{CharacterController} and \l{TriggerBody}. The physical shape of a body is represented by subtypes of \l CollisionShape.
10
11\section1 Shapes
12
13A collision shape is used to define the physical shape and extent of an
14object for the purposes of the physics simulation. The collision shape
15will typically be simpler than the object's visual appearance.
16
17There are some predefined shapes built into the engine: \l BoxShape,
18\l CapsuleShape, \l SphereShape, and \l PlaneShape. Handling of these shapes is
19optimized, so simulation using them will typically perform better.
20
21In addition, there are custom shapes that are defined by data: \l ConvexMeshShape,
22\l HeightFieldShape, and \l TriangleMeshShape. These allow more flexibility at the expense
23of performance.
24
25\section1 Bodies
26
27A \l {PhysicsBody}{body} represents a physical object in the simulation. These bodies interact and
28collide with each other. The two main types are \e{static bodies} (\l StaticRigidBody) and \e{dynamic bodies} (\l DynamicRigidBody). The
29physical shape of a body is specified by a list of shapes. The effective shape is the \e union of
30these shapes. The relative position of the shapes is fixed: the bodies are \e rigid.
31
32\section2 Dynamic body
33
34Dynamic bodies are able to move. The \l{DynamicRigidBody::isKinematic}{isKinematic} property
35determines how it moves. When \c isKinematic is \c true, the body is positioned explicitly by
36modifying the \l{DynamicRigidBody::kinematicPosition}{kinematicPosition} and
37\l{DynamicRigidBody::kinematicRotation}{kinematicRotation} properties. When \c isKinematic is \c false, the
38object is controlled by the simulation: it will fall under gravity, and bounce off other objects.
39
40When \isKinematic is \c true, all shapes are allowed. However, non-kinematic bodies are more
41restricted: only \e convex shapes can be used. These are the pre-defined shapes \l BoxShape,
42\l CapsuleShape, and \l SphereShape; and the custom shape \l ConvexMeshShape. This does not mean
43that it is impossible to have a non-convex physical geometry: several convex shapes can be combined
44for a single body. The \l {Qt Quick 3D Physics - Compound Shapes Example}{Compound Shapes Example}
45shows how to form ring-shaped bodies based on convex shapes.
46
47\section2 Static body
48
49Static bodies do not move. They represent the environment in which the other bodies move. Note that it is technically possible to move a static body, but the physical simulation will behave unexpectedly. In particular, a dynamic body that has entered a resting position on a static body will not be awoken if the static body moves. This means the dynamic body will remain in the same position even if the static body is moved.
50
51\section2 Character controller
52
53The \l {CharacterController} type is a special case. It represents a character that moves through
54the environment. One typical use case is a first-person view where the \l {QtQuick3D::Camera}{camera}
55is a child of the character controller, and its movement is controlled by keyboard/mouse or gamepad.
56
57\section2 Trigger body
58
59There is also the \l {TriggerBody} type which is another special case. As opposed to the other bodies it is not a physical body, meaning it does not interact in collision with other bodies. As the name suggests it is only used to trigger actions when another body enters or leaves its volume as defined by its collision shapes. If another body has \l {PhysicsNode::sendTriggerReports} {sendTriggerReports} set to \c true and its collision volume enters a \l {TriggerBody} the \l{TriggerBody::bodyEntered} {bodyEntered} signal is emitted.
60
61The following table shows a summary of the different types of bodies, how they interact and can be used:
62
63\table
64\header
65 \li Body
66 \li Interaction
67 \li Allowed shapes
68\row
69 \li \l {StaticRigidBody}
70 \li Does not move
71 \li All shapes
72\row
73 \li \l {DynamicRigidBody} with \l{DynamicRigidBody::isKinematic}{isKinematic} \c true
74 \li Positioned programatically. Influences dynamic bodies. Stopped by nothing.
75 \li All shapes
76\row
77 \li \l {DynamicRigidBody} with \l{DynamicRigidBody::isKinematic}{isKinematic} \c false
78 \li Fully controlled by simulation
79 \li Limited shapes
80\row
81 \li \l {CharacterController}
82 \li Moved programatically. Influences dynamic bodies. Stopped by static bodies.
83 \li Only a single \l CapsuleShape
84\row
85 \li \l {TriggerBody}
86 \li None
87 \li All shapes
88\endtable
89
90\section1 Physics Materials
91
92The \l PhysicsMaterial type specifies how an object behaves when it collides with another. The
93\l {PhysicsMaterial::dynamicFriction}{dynamicFriction} and \l {PhysicsMaterial::staticFriction}{staticFriction}
94properties determine how slippery the object is, and \l {PhysicsMaterial::restitution}{restitution}
95determines how bouncy it is.
96*/