00001 /* 00002 * Copyright (c) 2012 00003 * Side Effects Software Inc. All rights reserved. 00004 * 00005 * Redistribution and use of Houdini Development Kit samples in source and 00006 * binary forms, with or without modification, are permitted provided that the 00007 * following conditions are met: 00008 * 1. Redistributions of source code must retain the above copyright notice, 00009 * this list of conditions and the following disclaimer. 00010 * 2. The name of Side Effects Software may not be used to endorse or 00011 * promote products derived from this software without specific prior 00012 * written permission. 00013 * 00014 * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS 00015 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00016 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00017 * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, 00018 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 00019 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 00020 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00021 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00022 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 00023 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00024 * 00025 *---------------------------------------------------------------------------- 00026 */ 00027 00028 /// @file SIM_ForceOrbit.h 00029 /// This example creates a custom force DOP. 00030 /// 00031 /// This class will add a new DOP node called Orbit Force. This node will 00032 /// attach a SIM_ForceOrbit instance on DOP objects. Solvers will discover 00033 /// this instance when iterating over the applied forces and can call one of 00034 /// getForce*() methods to find out the applied force and torque values. 00035 /// Houdini will also use the createGuideObject() method to display guide 00036 /// geometry. 00037 00038 #ifndef __SIM_ForceOrbit_h__ 00039 #define __SIM_ForceOrbit_h__ 00040 00041 #include <SIM/SIM_Force.h> 00042 #include <SIM/SIM_OptionsUser.h> 00043 00044 #define SIM_NAME_POINTMASS "pointmass" 00045 #define SIM_NAME_POINTPOSITION "pointposition" 00046 00047 namespace HDK_Sample { 00048 00049 /// This is an implementation of the SIM_Force interface. This 00050 /// implementation returns a force value that is proportional to the 00051 /// square of the distance from a point in space (as if there were an 00052 /// infinitely small massive body at that location). 00053 class SIM_ForceOrbit : public SIM_Force, 00054 public SIM_OptionsUser 00055 { 00056 public: 00057 /// Controls the position of the point we are orbiting. 00058 GETSET_DATA_FUNCS_V3(SIM_NAME_POINTPOSITION, PointPosition); 00059 /// Controls the mass of the point we are orbiting. 00060 GETSET_DATA_FUNCS_F(SIM_NAME_POINTMASS, PointMass); 00061 00062 protected: 00063 /// Declare a protected constructor to ensure the data factory is used to 00064 /// create new instances of SIM_ForceOrbit. 00065 explicit SIM_ForceOrbit(const SIM_DataFactory *factory); 00066 virtual ~SIM_ForceOrbit(); 00067 00068 /// Override this to return a SIM_GuideShared as the guide geometry looks 00069 /// the same for all objects. 00070 virtual SIM_Guide *createGuideObjectSubclass() const; 00071 00072 /// We override this method to create the attractor geometry. 00073 virtual void buildGuideGeometrySubclass(const SIM_RootData &root, 00074 const SIM_Options &options, 00075 const GU_DetailHandle &gdh, 00076 UT_DMatrix4 *xform, 00077 const SIM_Time &t) const; 00078 00079 /// Calculates the force on a point. The force depends only on the 00080 /// mass of the point. 00081 virtual void getForceSubclass(const SIM_Object &object, 00082 const UT_Vector3 &position, 00083 const UT_Vector3 &velocity, 00084 const UT_Vector3 &angvel, 00085 const fpreal mass, 00086 UT_Vector3 &force, 00087 UT_Vector3 &torque) const; 00088 /// Calculates the force on a surface. The force depends only 00089 /// on the mass, so this function simply calls getForceSubclass(), 00090 /// ignoring the circle parameters. 00091 virtual void getForceOnCircleSubclass(const SIM_Object &object, 00092 const UT_Vector3 &position, 00093 const UT_Vector3 &normal, 00094 const fpreal radius, 00095 const UT_Vector3 &velocity, 00096 const UT_Vector3 &angvel, 00097 const fpreal mass, 00098 UT_Vector3 &force, 00099 UT_Vector3 &torque) const; 00100 /// Calculates the force on a volume. The force depends only 00101 /// on the mass, so this function simply calls getForceSubclass(), 00102 /// ignoring the sphere parameters. 00103 virtual void getForceOnSphereSubclass(const SIM_Object &object, 00104 const UT_Vector3 &position, 00105 const fpreal radius, 00106 const UT_Vector3 &velocity, 00107 const UT_Vector3 &angvel, 00108 const fpreal mass, 00109 UT_Vector3 &force, 00110 UT_Vector3 &torque) const; 00111 00112 private: 00113 /// Get the SIM_DopDescription for creating an orbit force. 00114 static const SIM_DopDescription *getForceOrbitDopDescription(); 00115 00116 /// This macro adds the standard getCastToType() method needed by 00117 /// DECLARE_DATAFACTORY() 00118 DECLARE_STANDARD_GETCASTTOTYPE(); 00119 /// This macro defines all the static functions needed to declare a 00120 /// SIM_DataFactory for SIM_ForceOrbit. 00121 DECLARE_DATAFACTORY(SIM_ForceOrbit, 00122 SIM_Force, 00123 "Orbit Force", 00124 getForceOrbitDopDescription()); 00125 }; 00126 00127 } // End HDK_Sample namespace 00128 00129 #endif 00130
1.5.9