SuperDex Physics C++ API
Loading...
Searching...
No Matches
mochi_constraint.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include "mochi_enums.h"
20#include "mochi_handle.h"
21#include "mochi_scene.h"
22#include "mochi_structs.h"
23
24/********************************************************************************
25 IMPORTANT: PLEASE KEEP HEADER INCLUDES TO A MINIMUM.
26 If you must include a mochi_core header, then please make sure that it only
27 declares the data types (not containing other implementation details).
28*********************************************************************************/
34
35namespace superdex {
36
37class Actor;
38
40 public:
41 [[nodiscard]] virtual ConstraintType GetType() const = 0;
42
43 [[nodiscard]] virtual ConstraintHandle GetHandle() const = 0;
44
45 [[nodiscard]] virtual real GetStiffness() const = 0;
46
47 virtual void SetStiffness(real stiffness, Error& error) = 0;
48
49 [[nodiscard]] virtual real GetDamping() const = 0;
50
51 virtual void SetDamping(real damping, Error& error) = 0;
52
53 [[nodiscard]] virtual real GetSaturation() const = 0;
54
55 virtual void SetSaturation(real saturation, Error& error) = 0;
56
57 [[nodiscard]] virtual DynamicArray<real> GetDeviation() const = 0;
58
59 [[nodiscard]] virtual Span<real const> GetForce(Error& error) const = 0;
60
61 [[nodiscard]] virtual int GetNumActors() const = 0;
62
63 [[nodiscard]] virtual Actor* GetActor(int actorIndex) = 0;
64
65 [[nodiscard]] virtual Actor const* GetActor(int actorIndex) const = 0;
66
67 [[nodiscard]] virtual Span<int const> GetDofIndicesForActor(int actorIndex) const = 0;
68
69 virtual void SetTargetPosition(Real3 const& position, Error& error) = 0;
70
71 virtual void SetTargetRotation(Quaternion const& rotation, Error& error) = 0;
72
73 virtual void SetTargetDof(real target, Error& error) = 0;
74
75 virtual void UpdateOldTarget(Error& error) = 0;
76
78 Quaternion const& rotationA,
79 Quaternion const& rotationB,
80 Error& error) = 0;
81
82 [[nodiscard]] virtual Span<real const> GetLimitMinValues(Error& error) const = 0;
83
84 [[nodiscard]] virtual Span<real const> GetLimitMaxValues(Error& error) const = 0;
85
86 virtual QueryHandle RegisterQuery(QueryType type, Error& error) = 0;
87
88 virtual void CancelQuery(QueryHandle handle) = 0;
89
90 [[nodiscard]] virtual bool IsQuerySupported(QueryType type) const = 0;
91
92 protected:
93 // Don't delete the Constraint pointer. Call Scene::DestroyConstraint.
94 virtual ~Constraint() = default;
95};
96
97} // namespace superdex
Represents a simulated body (actor) in a scene.
Definition mochi_actor.h:51
Represents a constraint that restricts the degrees of freedom of one or more actors.
virtual real GetStiffness() const =0
Get the constraint's stiffness parameter.
virtual void SetRefRelativeRotation(Quaternion const &rotationA, Quaternion const &rotationB, Error &error)=0
Set a relative-rotation target from two rotations expressed in a common frame.
virtual Span< int const > GetDofIndicesForActor(int actorIndex) const =0
Get the degrees of freedom (DoF) indices affected by this constraint on a specific actor.
virtual void SetTargetPosition(Real3 const &position, Error &error)=0
Set the constraint's target position in world frame.
virtual ~Constraint()=default
virtual Span< real const > GetLimitMaxValues(Error &error) const =0
Get the constraint's maximum limit values.
virtual real GetSaturation() const =0
Get the constraint's saturation parameter.
virtual void SetTargetDof(real target, Error &error)=0
Set the constraint's target DoF.
virtual DynamicArray< real > GetDeviation() const =0
Compute the constraint's current deviation from its target, limits, or coupling condition.
virtual void SetStiffness(real stiffness, Error &error)=0
Set the constraint's stiffness parameter.
virtual real GetDamping() const =0
Get the constraint's damping parameter.
virtual bool IsQuerySupported(QueryType type) const =0
Check whether a query type is supported for this constraint.
virtual void SetTargetRotation(Quaternion const &rotation, Error &error)=0
Set the constraint's target rotation.
virtual Span< real const > GetForce(Error &error) const =0
Get the force/torque applied by the constraint.
virtual QueryHandle RegisterQuery(QueryType type, Error &error)=0
Register a query to compute data for this constraint.
virtual void SetDamping(real damping, Error &error)=0
Set the constraint's damping parameter.
virtual ConstraintType GetType() const =0
Get the type of the constraint.
virtual void CancelQuery(QueryHandle handle)=0
Cancel a previously registered query.
virtual void SetSaturation(real saturation, Error &error)=0
Set the constraint's saturation parameter.
virtual Actor const * GetActor(int actorIndex) const =0
Get read-only access to one of the actors affected by this constraint.
virtual int GetNumActors() const =0
Get the number of actors affected by the constraint.
virtual ConstraintHandle GetHandle() const =0
Get the handle associated with this constraint.
virtual Span< real const > GetLimitMinValues(Error &error) const =0
Get the constraint's minimum limit values.
virtual void UpdateOldTarget(Error &error)=0
Update the old target to match the current target.
virtual Actor * GetActor(int actorIndex)=0
Get one of the actors affected by this constraint.
A dynamically resizable array with syntax and behavior similar to std::pmr::vector.
NdArray< real, 3 > Real3
Definition nd_array.h:106
ConstraintType
Type of constraint acting on actors' degrees of freedom.
Definition mochi_enums.h:79
QueryType
Type of query data to compute for an actor or constraint.
Unique identifier for a Constraint within a Scene.
Unique identifier for a query within a Scene.