00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Side Effects Software Inc 00008 * 123 Front Street West, Suite 1401 00009 * Toronto, Ontario 00010 * Canada M5J 2M2 00011 * 416-504-9876 00012 */ 00013 00014 #ifndef __SIM_ConAnchorSpatial_h__ 00015 #define __SIM_ConAnchorSpatial_h__ 00016 00017 #include "SIM_API.h" 00018 #include "SIM_ConAnchor.h" 00019 #include <UT/UT_Quaternion.h> 00020 #include <UT/UT_Vector3.h> 00021 00022 // TODO: Read over this comment and make sure it all still makes sense: 00023 00024 /// Normally, constraints affect all three positional degrees of freedom 00025 /// of an object. Some constraints, however, can limit their action to 00026 /// only one or two degrees of freedom. For example, a hard constraint 00027 /// might only force geometry to follow the anchor in y, and leave the x 00028 /// and z DOFs unconstrained. In these situations, the constraint is 00029 /// completely independent of the unconstrained DOFs - movement of the 00030 /// geometry in unconstrained directions has no effect on the constraint 00031 /// (e.g., doesn't affect springs), and the constraint never has an effect 00032 /// in these DOFs (e.g., the constraint will never cause movement in x or z 00033 /// in the earlier example). 00034 class SIM_API SIM_ConAnchorSpatial : public SIM_ConAnchor 00035 { 00036 public: 00037 /// We categorize constraints by the shape created by sweeping a point 00038 /// through unconstrained space. The numerical representation 00039 /// is thus the number of degrees that have been constrained. 00040 /// "DOF" stands for "degrees of freedom". 00041 enum SIM_DOFType { 00042 DOF_SPACE = 0, /// Any point in space is valid. 00043 /// (i.e., constraint has no effect) 00044 DOF_PLANE = 1, /// Any point on a plane is valid. 00045 DOF_LINE = 2, /// Any point on a line is valid. 00046 DOF_POINT = 3 /// Only one point is valid 00047 /// (i.e., constraint prevents all movement) 00048 }; 00049 00050 GETSET_DATA_FUNCS_E(SIM_NAME_CONDOF, DOFTypeInput, SIM_DOFType); 00051 /// All constraints are represented by a vector which is interpreted 00052 /// differently depending on how many DOF will be constrained. 00053 /// This is troublesome as it only works in 3d. Ideally, we 00054 /// should specify two types of constraints: 00055 /// If P is the point to constrain, and R the rest point, and V 00056 /// the vector, we have: 00057 /// Normal constraint: 00058 /// dot(V, P) = dot(V, R) 00059 /// This removes one degree of freedom. Equivalent to PLANE. 00060 /// Vector constraint: 00061 /// P - R = s V, for some s 00062 /// This removes all but one degree of freedom. Equivalent to LINE. 00063 /// The result of this is always normalized. 00064 /// 00065 /// We can then define the UnconDOFFilter which, when applied to a velocity, 00066 /// will cause it to fulfill those conditions. We can then clamp 00067 /// a position P to a rest position R with the filter uF with: 00068 /// P' = (uF * (P - R)) + R 00069 /// (Note that we can also use the ConDOFFilter with the following 00070 /// equation: 00071 /// P' = (F * (R - P)) + P 00072 /// We present it with the unconstrained case to match the rotational 00073 /// case which is harder to rearrange) 00074 /// 00075 /// This vector is defined in simulation space, and may not be 00076 /// normalized. 00077 GETSET_DATA_FUNCS_V3(SIM_NAME_CONDIR, DOFVectorInput); 00078 00079 /// Overridable get/set for the DOF of the constraint 00080 SIM_DOFType getDOFType() const; 00081 void setDOFType(const SIM_DOFType type); 00082 const UT_Vector3 getDOFVector() const; 00083 void setDOFVector(const UT_Vector3 &vector); 00084 00085 /// Retrieve the world-space position to constrain to. 00086 UT_Vector3 getPosition(const SIM_Time &time) const; 00087 UT_Vector3 getVelocity(const SIM_Time &time) const; 00088 00089 /// Retrieve number of constrained degrees of freedom. 00090 int getNumConDOFs() const; 00091 /// Returns a matrix that, when multiplied by a vector, gives only the 00092 /// components of the vector that are constrained. 00093 void getConDOFFilter(UT_Matrix3 &result, 00094 const SIM_Time &time) const; 00095 00096 /// Opposite of getConDOFFilter(). 00097 /// getUnconDOFFilter() = identity - getConDOFFilter() 00098 void getUnconDOFFilter(UT_Matrix3 &result, 00099 const SIM_Time &time) const; 00100 00101 protected: 00102 explicit SIM_ConAnchorSpatial(const SIM_DataFactory *factory); 00103 virtual ~SIM_ConAnchorSpatial(); 00104 00105 virtual void buildAnchorGuideGeometrySubclass( 00106 const SIM_Options &options, 00107 const GU_DetailHandle &gdh, 00108 const SIM_Relationship &rel, 00109 const SIM_Time &t) const; 00110 00111 virtual UT_Vector3 getPositionSubclass(const SIM_Time &time) const = 0; 00112 virtual UT_Vector3 getVelocitySubclass(const SIM_Time &) const; 00113 00114 virtual SIM_DOFType getDOFTypeSubclass() const; 00115 virtual const UT_Vector3 getDOFVectorSubclass() const; 00116 00117 private: 00118 DECLARE_STANDARD_GETCASTTOTYPE(); 00119 DECLARE_CLASSNAME(SIM_ConAnchorSpatial, SIM_ConAnchor); 00120 }; 00121 00122 #endif
1.5.9