Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qphysicsworld.cpp File Reference
#include "qcapsuleshape_p.h"
#include "qdebugdrawhelper_p.h"
#include "qphysicsworld_p.h"
#include "qabstractphysicsnode_p.h"
#include "qphysicsutils_p.h"
#include "qtriggerbody_p.h"
#include "qrigidbody_p.h"
#include "qplaneshape_p.h"
#include "qphysicscommands_p.h"
#include "PxPhysicsAPI.h"
#include "qcharactercontroller_p.h"
#include "qheightfieldshape_p.h"
#include "cooking/PxCooking.h"
#include "extensions/PxDefaultCpuDispatcher.h"
#include <QtQuick3D/private/qquick3dobject_p.h>
#include <QtQuick3D/private/qquick3dnode_p.h>
#include <QtQuick3D/private/qquick3dmodel_p.h>
#include <QtQuick3D/private/qquick3ddefaultmaterial_p.h>
#include <QtQuick3DUtils/private/qssgutils_p.h>
#include "qphysicsworld.moc"
+ Include dependency graph for qphysicsworld.cpp:

Go to the source code of this file.

Classes

class  SimulationEventCallback
 
class  ControllerCallback
 
struct  StaticPhysXObjects
 
struct  PhysXWorld
 
class  QAbstractPhysXNode
 
class  QPhysXCharacterController
 
class  QPhysXActorBody
 
class  QPhysXRigidBody
 
class  QPhysXStaticBody
 
class  QPhysXDynamicBody
 
class  QPhysXTriggerBody
 
class  QPhysXFactory
 
class  SimulationWorker
 
struct  QWorldManager
 

Macros

#define PHYSX_ENABLE_PVD   0
 
#define PHYSX_RELEASE(x)
 

Enumerations

enum class  DebugDrawBodyType {
  Static = 0 , DynamicAwake = 1 , DynamicSleeping = 2 , Trigger = 3 ,
  Unknown = 4
}
 

Functions

QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY (lcQuick3dPhysics, "qt.quick3d.physics")
 \qmltype PhysicsWorld \inqmlmodule QtQuick3D.Physics
 
static bool fuzzyEquals (const physx::PxTransform &a, const physx::PxTransform &b)
 
static physx::PxTransform getPhysXWorldTransform (const QQuick3DNode *node)
 
static physx::PxTransform getPhysXWorldTransform (const QMatrix4x4 transform)
 
static physx::PxTransform getPhysXLocalTransform (const QQuick3DNode *node)
 
static physx::PxFilterFlags contactReportFilterShader (physx::PxFilterObjectAttributes, physx::PxFilterData, physx::PxFilterObjectAttributes, physx::PxFilterData, physx::PxPairFlags &pairFlags, const void *, physx::PxU32)
 
static physx::PxFilterFlags contactReportFilterShaderCCD (physx::PxFilterObjectAttributes, physx::PxFilterData, physx::PxFilterObjectAttributes, physx::PxFilterData, physx::PxPairFlags &pairFlags, const void *, physx::PxU32)
 
static void processCommandQueue (QQueue< QPhysicsCommand * > &commandQueue, const QDynamicRigidBody &rigidBody, physx::PxRigidBody &body)
 
static QMatrix4x4 calculateKinematicNodeTransform (QQuick3DNode *node, QHash< QQuick3DNode *, QMatrix4x4 > &transformCache)
 
static physx::PxRigidDynamicLockFlags getLockFlags (QDynamicRigidBody *body)
 
static void updatePhysXMaterial (const QPhysicsMaterial *qtMaterial, physx::PxMaterial *physXMaterial)
 

Variables

static const QQuaternion kMinus90YawRotation = QQuaternion::fromEulerAngles(0, -90, 0)
 
StaticPhysXObjects s_physx = StaticPhysXObjects()
 
static QWorldManager worldManager = QWorldManager {}
 

Macro Definition Documentation

◆ PHYSX_ENABLE_PVD

#define PHYSX_ENABLE_PVD   0

Definition at line 29 of file qphysicsworld.cpp.

◆ PHYSX_RELEASE

#define PHYSX_RELEASE (   x)
Value:
if (x != nullptr) { \
x->release(); \
x = nullptr; \
}
GLint GLint GLint GLint GLint x
[0]

Definition at line 390 of file qphysicsworld.cpp.

Enumeration Type Documentation

◆ DebugDrawBodyType

enum class DebugDrawBodyType
strong
Enumerator
Static 
DynamicAwake 
DynamicSleeping 
Trigger 
Unknown 

Definition at line 514 of file qphysicsworld.cpp.

Function Documentation

◆ calculateKinematicNodeTransform()

static QMatrix4x4 calculateKinematicNodeTransform ( QQuick3DNode node,
QHash< QQuick3DNode *, QMatrix4x4 > &  transformCache 
)
static

Definition at line 949 of file qphysicsworld.cpp.

References calculateKinematicNodeTransform(), QSSGRenderNode::calculateTransformMatrix(), QHash< Key, T >::contains(), parent, QQuick3DNode::parentNode(), QQuick3DNode::pivot, QQuick3DNode::position, qWarning, QQuick3DNode::rotation, QQuick3DNode::scale, and sceneTransform().

Referenced by calculateKinematicNodeTransform(), and QPhysXDynamicBody::sync().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ contactReportFilterShader()

static physx::PxFilterFlags contactReportFilterShader ( physx::PxFilterObjectAttributes  ,
physx::PxFilterData  ,
physx::PxFilterObjectAttributes  ,
physx::PxFilterData  ,
physx::PxPairFlags &  pairFlags,
const void ,
physx::PxU32   
)
static

Definition at line 196 of file qphysicsworld.cpp.

Referenced by PhysXWorld::createScene().

+ Here is the caller graph for this function:

◆ contactReportFilterShaderCCD()

static physx::PxFilterFlags contactReportFilterShaderCCD ( physx::PxFilterObjectAttributes  ,
physx::PxFilterData  ,
physx::PxFilterObjectAttributes  ,
physx::PxFilterData  ,
physx::PxPairFlags &  pairFlags,
const void ,
physx::PxU32   
)
static

Definition at line 218 of file qphysicsworld.cpp.

Referenced by PhysXWorld::createScene().

+ Here is the caller graph for this function:

◆ fuzzyEquals()

static bool fuzzyEquals ( const physx::PxTransform &  a,
const physx::PxTransform &  b 
)
inlinestatic

Definition at line 148 of file qphysicsworld.cpp.

References qFuzzyCompare().

Referenced by QPhysXActorBody::markDirtyShapes(), QDynamicRigidBody::setInertiaMatrix(), and QPhysXStaticBody::sync().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getLockFlags()

static physx::PxRigidDynamicLockFlags getLockFlags ( QDynamicRigidBody body)
static

Definition at line 982 of file qphysicsworld.cpp.

References QDynamicRigidBody::angularAxisLock, QDynamicRigidBody::linearAxisLock, QDynamicRigidBody::LockX, QDynamicRigidBody::LockY, and QDynamicRigidBody::LockZ.

Referenced by QPhysXDynamicBody::sync().

+ Here is the caller graph for this function:

◆ getPhysXLocalTransform()

static physx::PxTransform getPhysXLocalTransform ( const QQuick3DNode node)
static

Definition at line 174 of file qphysicsworld.cpp.

References kMinus90YawRotation, QQuick3DNode::position, QQuick3DNode::rotation, QQuick3DNode::sceneScale, and QPhysicsUtils::toPhysXType().

Referenced by QPhysXActorBody::buildShapes(), and QPhysXActorBody::markDirtyShapes().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPhysXWorldTransform() [1/2]

static physx::PxTransform getPhysXWorldTransform ( const QMatrix4x4  transform)
static

Definition at line 163 of file qphysicsworld.cpp.

References QQuaternion::fromRotationMatrix(), mat44::getPosition(), mat44::getUpper3x3(), mat44::normalize(), QQuaternion::normalized(), and QPhysicsUtils::toPhysXType().

+ Here is the call graph for this function:

◆ getPhysXWorldTransform() [2/2]

static physx::PxTransform getPhysXWorldTransform ( const QQuick3DNode node)
static

Definition at line 155 of file qphysicsworld.cpp.

References QQuick3DNode::scenePosition, QQuick3DNode::sceneRotation, and QPhysicsUtils::toPhysXType().

Referenced by QPhysXActorBody::createActor(), QPhysXStaticBody::createActor(), QPhysXStaticBody::sync(), QPhysXDynamicBody::sync(), and QPhysXTriggerBody::sync().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ processCommandQueue()

static void processCommandQueue ( QQueue< QPhysicsCommand * > &  commandQueue,
const QDynamicRigidBody rigidBody,
physx::PxRigidBody &  body 
)
static

Definition at line 938 of file qphysicsworld.cpp.

References QList< T >::clear().

Referenced by QPhysXDynamicBody::sync().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Q_LOGGING_CATEGORY()

QT_BEGIN_NAMESPACE Q_LOGGING_CATEGORY ( lcQuick3dPhysics  ,
"qt.quick3d.physics"   
)

\qmltype PhysicsWorld \inqmlmodule QtQuick3D.Physics

Since
6.4

Controls the physics simulation.

The PhysicsWorld type controls the physics simulation. This node is used to create an instance of the physics world as well as define its properties. There can only be one physics world. All collision nodes in the qml will get added automatically to the physics world.

\qmlproperty vector3d PhysicsWorld::gravity This property defines the gravity vector of the physics world. The default value is (0, -981, 0). Set the value to {Qt.vector3d(0, -9.81, 0)} if your unit of measurement is meters and you are simulating Earth gravity.

\qmlproperty bool PhysicsWorld::running This property starts or stops the physical simulation. The default value is true.

\qmlproperty bool PhysicsWorld::forceDebugDraw This property enables debug drawing of all active shapes in the physics world. The default value is false.

\qmlproperty bool PhysicsWorld::enableCCD This property enables continuous collision detection. This will reduce the risk of bodies going through other bodies at high velocities (also known as tunnelling). The default value is false.

\qmlproperty float PhysicsWorld::typicalLength This property defines the approximate size of objects in the simulation. This is used to estimate certain length-related tolerances. Objects much smaller or much larger than this size may not behave properly. The default value is 100.

Range: {[0, inf]}

\qmlproperty float PhysicsWorld::typicalSpeed This property defines the typical magnitude of velocities of objects in simulation. This is used to estimate whether a contact should be treated as bouncing or resting based on its impact velocity, and a kinetic energy threshold below which the simulation may put objects to sleep.

For normal physical environments, a good choice is the approximate speed of an object falling under gravity for one second. The default value is 1000.

Range: {[0, inf]}

\qmlproperty float PhysicsWorld::defaultDensity This property defines the default density of dynamic objects, measured in kilograms per cubic unit. This is equal to the weight of a cube with side 1.

The default value is 0.001, corresponding to 1 g/cm³: the density of water. If your unit of measurement is meters, a good value would be 1000. Note that only positive values are allowed.

Range: {(0, inf]}

\qmlproperty Node PhysicsWorld::viewport This property defines the viewport where debug components will be drawn if \l{forceDebugDraw} is enabled. If unset the \l{scene} node will be used.

See also
forceDebugDraw, scene

\qmlproperty float PhysicsWorld::minimumTimestep This property defines the minimum simulation timestep in milliseconds. The default value is 16.667 which corresponds to 60 frames per second.

Range: {[0, maximumTimestep]}

\qmlproperty float PhysicsWorld::maximumTimestep This property defines the maximum simulation timestep in milliseconds. The default value is 33.333 which corresponds to 30 frames per second.

Range: {[0, inf]}

\qmlproperty Node PhysicsWorld::scene

This property defines the top-most Node that contains all the nodes of the physical simulation. All physics objects that are an ancestor of this node will be seen as part of this PhysicsWorld.

Note
Using the same scene node for several PhysicsWorld is unsupported.

\qmlsignal PhysicsWorld::frameDone(float timestep)

Since
6.5

This signal is emitted when the physical simulation is done simulating a frame. The timestep parameter is how long in milliseconds the timestep was in the simulation.

◆ updatePhysXMaterial()

static void updatePhysXMaterial ( const QPhysicsMaterial qtMaterial,
physx::PxMaterial *  physXMaterial 
)
static

Definition at line 1007 of file qphysicsworld.cpp.

References QPhysicsMaterial::dynamicFriction, QPhysicsMaterial::restitution, and QPhysicsMaterial::staticFriction.

Referenced by QPhysXActorBody::sync().

+ Here is the caller graph for this function:

Variable Documentation

◆ kMinus90YawRotation

const QQuaternion kMinus90YawRotation = QQuaternion::fromEulerAngles(0, -90, 0)
static

Definition at line 146 of file qphysicsworld.cpp.

Referenced by getPhysXLocalTransform().

◆ s_physx

◆ worldManager