HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SIM_ForceOrbit.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024
3  * Side Effects Software Inc. All rights reserved.
4  *
5  * Redistribution and use of Houdini Development Kit samples in source and
6  * binary forms, with or without modification, are permitted provided that the
7  * following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. The name of Side Effects Software may not be used to endorse or
11  * promote products derived from this software without specific prior
12  * written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17  * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  *----------------------------------------------------------------------------
26  */
27 
28 /// @file SIM_ForceOrbit.h
29 /// This example creates a custom force DOP.
30 ///
31 /// This class will add a new DOP node called Orbit Force. This node will
32 /// attach a SIM_ForceOrbit instance on DOP objects. Solvers will discover
33 /// this instance when iterating over the applied forces and can call one of
34 /// getForce*() methods to find out the applied force and torque values.
35 /// Houdini will also use the createGuideObject() method to display guide
36 /// geometry.
37 
38 #ifndef __SIM_ForceOrbit_h__
39 #define __SIM_ForceOrbit_h__
40 
41 #include <SIM/SIM_Force.h>
42 #include <SIM/SIM_OptionsUser.h>
43 
44 #define SIM_NAME_POINTMASS "pointmass"
45 #define SIM_NAME_POINTPOSITION "pointposition"
46 
47 namespace HDK_Sample {
48 
49 /// This is an implementation of the SIM_Force interface. This
50 /// implementation returns a force value that is proportional to the
51 /// square of the distance from a point in space (as if there were an
52 /// infinitely small massive body at that location).
53 class SIM_ForceOrbit : public SIM_Force,
54  public SIM_OptionsUser
55 {
56 public:
57  /// Controls the position of the point we are orbiting.
59  /// Controls the mass of the point we are orbiting.
61 
62 protected:
63  /// Declare a protected constructor to ensure the data factory is used to
64  /// create new instances of SIM_ForceOrbit.
65  explicit SIM_ForceOrbit(const SIM_DataFactory *factory);
66  ~SIM_ForceOrbit() override;
67 
68  /// Override this to return a SIM_GuideShared as the guide geometry looks
69  /// the same for all objects.
70  SIM_Guide *createGuideObjectSubclass() const override;
71 
72  /// We override this method to create the attractor geometry.
74  const SIM_Options &options,
75  const GU_DetailHandle &gdh,
76  UT_DMatrix4 *xform,
77  const SIM_Time &t
78  ) const override;
79 
80  /// Calculates the force on a point. The force depends only on the
81  /// mass of the point.
82  void getForceSubclass(const SIM_Object &object,
83  const UT_Vector3 &position,
84  const UT_Vector3 &velocity,
85  const UT_Vector3 &angvel,
86  const fpreal mass,
88  UT_Vector3 &torque) const override;
89  /// Calculates the force on a surface. The force depends only
90  /// on the mass, so this function simply calls getForceSubclass(),
91  /// ignoring the circle parameters.
92  void getForceOnCircleSubclass(const SIM_Object &object,
93  const UT_Vector3 &position,
94  const UT_Vector3 &normal,
95  const fpreal radius,
96  const UT_Vector3 &velocity,
97  const UT_Vector3 &angvel,
98  const fpreal mass,
99  UT_Vector3 &force,
100  UT_Vector3 &torque) const override;
101  /// Calculates the force on a volume. The force depends only
102  /// on the mass, so this function simply calls getForceSubclass(),
103  /// ignoring the sphere parameters.
104  void getForceOnSphereSubclass(const SIM_Object &object,
105  const UT_Vector3 &position,
106  const fpreal radius,
107  const UT_Vector3 &velocity,
108  const UT_Vector3 &angvel,
109  const fpreal mass,
110  UT_Vector3 &force,
111  UT_Vector3 &torque) const override;
112 
113 private:
114  /// Get the SIM_DopDescription for creating an orbit force.
115  static const SIM_DopDescription *getForceOrbitDopDescription();
116 
117  /// This macro adds the standard getCastToType() method needed by
118  /// DECLARE_DATAFACTORY()
119  DECLARE_STANDARD_GETCASTTOTYPE();
120  /// This macro defines all the static functions needed to declare a
121  /// SIM_DataFactory for SIM_ForceOrbit.
122  DECLARE_DATAFACTORY(SIM_ForceOrbit,
123  SIM_Force,
124  "Orbit Force",
125  getForceOrbitDopDescription());
126 };
127 
128 } // End HDK_Sample namespace
129 
130 #endif
131 
SIM_Guide * createGuideObjectSubclass() const override
void getForceOnSphereSubclass(const SIM_Object &object, const UT_Vector3 &position, const fpreal radius, const UT_Vector3 &velocity, const UT_Vector3 &angvel, const fpreal mass, UT_Vector3 &force, UT_Vector3 &torque) const override
void getForceOnCircleSubclass(const SIM_Object &object, const UT_Vector3 &position, const UT_Vector3 &normal, const fpreal radius, const UT_Vector3 &velocity, const UT_Vector3 &angvel, const fpreal mass, UT_Vector3 &force, UT_Vector3 &torque) const override
GETSET_DATA_FUNCS_F(SIM_NAME_POINTMASS, PointMass)
Controls the mass of the point we are orbiting.
SIM_API const UT_StringHolder torque
void getForceSubclass(const SIM_Object &object, const UT_Vector3 &position, const UT_Vector3 &velocity, const UT_Vector3 &angvel, const fpreal mass, UT_Vector3 &force, UT_Vector3 &torque) const override
#define SIM_NAME_POINTMASS
void buildGuideGeometrySubclass(const SIM_RootData &root, const SIM_Options &options, const GU_DetailHandle &gdh, UT_DMatrix4 *xform, const SIM_Time &t) const override
We override this method to create the attractor geometry.
SIM_ForceOrbit(const SIM_DataFactory *factory)
GLdouble t
Definition: glad.h:2397
GA_API const UT_StringHolder mass
GETSET_DATA_FUNCS_V3(SIM_NAME_POINTPOSITION, PointPosition)
Controls the position of the point we are orbiting.
SIM_API const UT_StringHolder force
fpreal64 fpreal
Definition: SYS_Types.h:277
SIM_API const UT_StringHolder position
#define SIM_NAME_POINTPOSITION