HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SIM_ForceOrbit.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018
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  virtual ~SIM_ForceOrbit();
67 
68  /// Override this to return a SIM_GuideShared as the guide geometry looks
69  /// the same for all objects.
70  virtual SIM_Guide *createGuideObjectSubclass() const;
71 
72  /// We override this method to create the attractor geometry.
73  virtual void buildGuideGeometrySubclass(const SIM_RootData &root,
74  const SIM_Options &options,
75  const GU_DetailHandle &gdh,
76  UT_DMatrix4 *xform,
77  const SIM_Time &t) const;
78 
79  /// Calculates the force on a point. The force depends only on the
80  /// mass of the point.
81  virtual void getForceSubclass(const SIM_Object &object,
82  const UT_Vector3 &position,
83  const UT_Vector3 &velocity,
84  const UT_Vector3 &angvel,
85  const fpreal mass,
86  UT_Vector3 &force,
87  UT_Vector3 &torque) const;
88  /// Calculates the force on a surface. The force depends only
89  /// on the mass, so this function simply calls getForceSubclass(),
90  /// ignoring the circle parameters.
91  virtual void getForceOnCircleSubclass(const SIM_Object &object,
92  const UT_Vector3 &position,
93  const UT_Vector3 &normal,
94  const fpreal radius,
95  const UT_Vector3 &velocity,
96  const UT_Vector3 &angvel,
97  const fpreal mass,
98  UT_Vector3 &force,
99  UT_Vector3 &torque) const;
100  /// Calculates the force on a volume. The force depends only
101  /// on the mass, so this function simply calls getForceSubclass(),
102  /// ignoring the sphere parameters.
103  virtual void getForceOnSphereSubclass(const SIM_Object &object,
104  const UT_Vector3 &position,
105  const fpreal radius,
106  const UT_Vector3 &velocity,
107  const UT_Vector3 &angvel,
108  const fpreal mass,
109  UT_Vector3 &force,
110  UT_Vector3 &torque) const;
111 
112 private:
113  /// Get the SIM_DopDescription for creating an orbit force.
114  static const SIM_DopDescription *getForceOrbitDopDescription();
115 
116  /// This macro adds the standard getCastToType() method needed by
117  /// DECLARE_DATAFACTORY()
118  DECLARE_STANDARD_GETCASTTOTYPE();
119  /// This macro defines all the static functions needed to declare a
120  /// SIM_DataFactory for SIM_ForceOrbit.
121  DECLARE_DATAFACTORY(SIM_ForceOrbit,
122  SIM_Force,
123  "Orbit Force",
124  getForceOrbitDopDescription());
125 };
126 
127 } // End HDK_Sample namespace
128 
129 #endif
130 
GETSET_DATA_FUNCS_F(SIM_NAME_POINTMASS, PointMass)
Controls the mass of the point we are orbiting.
virtual 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
virtual SIM_Guide * createGuideObjectSubclass() const
#define SIM_NAME_POINTMASS
SIM_ForceOrbit(const SIM_DataFactory *factory)
virtual 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
GA_API const UT_StringHolder mass
double fpreal
Definition: SYS_Types.h:263
GETSET_DATA_FUNCS_V3(SIM_NAME_POINTPOSITION, PointPosition)
Controls the position of the point we are orbiting.
virtual void buildGuideGeometrySubclass(const SIM_RootData &root, const SIM_Options &options, const GU_DetailHandle &gdh, UT_DMatrix4 *xform, const SIM_Time &t) const
We override this method to create the attractor geometry.
#define SIM_NAME_POINTPOSITION
virtual 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