control.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. /**********************************************************************
  2. *<
  3. FILE: control.h
  4. DESCRIPTION: Control definitions
  5. CREATED BY: Dan Silva and Rolf Berteig
  6. HISTORY: created 9 September 1994
  7. *> Copyright (c) 1994, All Rights Reserved.
  8. **********************************************************************/
  9. #ifndef __CONTROL__
  10. #define __CONTROL__
  11. #include "plugapi.h"
  12. extern CoreExport void ApplyScaling(Matrix3 &m, const ScaleValue &v);
  13. extern CoreExport void InitControlLists();
  14. class ScaleValue;
  15. class ViewExp;
  16. class INode;
  17. class XFormModes;
  18. class INodeTab;
  19. CoreExport ScaleValue operator+(const ScaleValue& s0, const ScaleValue& s1);
  20. CoreExport ScaleValue operator-(const ScaleValue& s0, const ScaleValue& s1);
  21. CoreExport ScaleValue operator*(const ScaleValue& s, float f);
  22. CoreExport ScaleValue operator*(float f, const ScaleValue& s);
  23. CoreExport ScaleValue operator+(const ScaleValue& s, float f);
  24. CoreExport ScaleValue operator+(float f, const ScaleValue& s);
  25. class ScaleValue {
  26. public:
  27. Point3 s;
  28. Quat q;
  29. ScaleValue() {}
  30. ScaleValue(const Point3& as) { s = as; q = IdentQuat(); }
  31. ScaleValue(const Point3& as, const Quat& aq) {s = as; q = aq;}
  32. ScaleValue& operator+=(const ScaleValue& s) {(*this)=(*this)+s;return (*this);}
  33. ScaleValue& operator*=(const float s) {(*this)=(*this)*s;return (*this);}
  34. ScaleValue& operator=(const ScaleValue &v) {s=v.s;q=v.q;return (*this);}
  35. float& operator[](int el) {return s[el];}
  36. };
  37. // Types of ORTs
  38. #define ORT_BEFORE 1
  39. #define ORT_AFTER 2
  40. // ORTs
  41. #define ORT_CONSTANT 1
  42. #define ORT_CYCLE 2
  43. #define ORT_LOOP 3 // This is cycle with continuity.
  44. #define ORT_OSCILLATE 4
  45. #define ORT_LINEAR 5
  46. #define ORT_IDENTITY 6
  47. #define ORT_RELATIVE_REPEAT 7
  48. /*---------------------------------------------------------------------*/
  49. // A list of ease curves.
  50. class EaseCurveList : public ReferenceTarget {
  51. friend class AddEaseRestore;
  52. friend class DeleteEaseRestore;
  53. private:
  54. Tab<Control*> eases;
  55. public:
  56. EaseCurveList() {OpenTreeEntry(1);}
  57. CoreExport ~EaseCurveList();
  58. CoreExport TimeValue ApplyEase(TimeValue t,Interval &valid);
  59. CoreExport void AppendEaseCurve(Control *cont);
  60. CoreExport void DeleteEaseCurve(int i);
  61. CoreExport void DisableEaseCurve(int i);
  62. CoreExport void EnableEaseCurve(int i);
  63. CoreExport BOOL IsEaseEnabled(int i);
  64. int NumEaseCurves() {return eases.Count();}
  65. // Animatable
  66. void GetClassName(TSTR& s) { s= TSTR(_T("EaseCurve")); }
  67. Class_ID ClassID() { return Class_ID(EASE_LIST_CLASS_ID,0); }
  68. SClass_ID SuperClassID() { return EASE_LIST_CLASS_ID; }
  69. CoreExport int NumSubs();
  70. CoreExport Animatable* SubAnim(int i);
  71. CoreExport TSTR SubAnimName(int i);
  72. BOOL BypassTreeView() { return TRUE; }
  73. void DeleteThis() { delete this; }
  74. ParamDimension* GetParamDimension(int i) {return stdTimeDim;}
  75. CoreExport BOOL AssignController(Animatable *control,int subAnim);
  76. CoreExport void* GetInterface(ULONG id);
  77. CoreExport IOResult Save(ISave *isave);
  78. CoreExport IOResult Load(ILoad *iload);
  79. // Reference
  80. CoreExport int NumRefs();
  81. CoreExport RefTargetHandle GetReference(int i);
  82. CoreExport void SetReference(int i, RefTargetHandle rtarg);
  83. CoreExport RefTargetHandle Clone(RemapDir &remap = NoRemap());
  84. CoreExport RefResult NotifyRefChanged(Interval changeInt, RefTargetHandle hTarget,
  85. PartID& partID, RefMessage message);
  86. };
  87. class EaseCurveAnimProp : public AnimProperty {
  88. public:
  89. EaseCurveList *el;
  90. EaseCurveAnimProp() { el=NULL; }
  91. DWORD ID() {return PROPID_EASELIST;}
  92. };
  93. #define GetEaseListInterface(anim) ((EaseCurveList*)anim->GetInterface(I_EASELIST))
  94. /*---------------------------------------------------------------------*/
  95. // A list of multiplier curves.
  96. class MultCurveList : public ReferenceTarget {
  97. friend class AddMultRestore;
  98. friend class DeleteMultRestore;
  99. private:
  100. Tab<Control*> mults;
  101. public:
  102. MultCurveList() {OpenTreeEntry(1);}
  103. CoreExport ~MultCurveList();
  104. CoreExport float GetMultVal(TimeValue t,Interval &valid);
  105. CoreExport void AppendMultCurve(Control *cont);
  106. CoreExport void DeleteMultCurve(int i);
  107. CoreExport void DisableMultCurve(int i);
  108. CoreExport void EnableMultCurve(int i);
  109. CoreExport BOOL IsMultEnabled(int i);
  110. int NumMultCurves() {return mults.Count();}
  111. // Animatable
  112. void GetClassName(TSTR& s) { s= TSTR(_T("MultCurve")); }
  113. Class_ID ClassID() { return Class_ID(MULT_LIST_CLASS_ID,0); }
  114. SClass_ID SuperClassID() { return MULT_LIST_CLASS_ID; }
  115. CoreExport int NumSubs();
  116. CoreExport Animatable* SubAnim(int i);
  117. CoreExport TSTR SubAnimName(int i);
  118. BOOL BypassTreeView() { return TRUE; }
  119. void DeleteThis() { delete this; }
  120. ParamDimension* GetParamDimension(int i) {return stdNormalizedDim;}
  121. CoreExport BOOL AssignController(Animatable *control,int subAnim);
  122. CoreExport void* GetInterface(ULONG id);
  123. CoreExport IOResult Save(ISave *isave);
  124. CoreExport IOResult Load(ILoad *iload);
  125. // Reference
  126. CoreExport int NumRefs();
  127. CoreExport RefTargetHandle GetReference(int i);
  128. CoreExport void SetReference(int i, RefTargetHandle rtarg);
  129. CoreExport RefTargetHandle Clone(RemapDir &remap = NoRemap());
  130. CoreExport RefResult NotifyRefChanged(Interval changeInt, RefTargetHandle hTarget,
  131. PartID& partID, RefMessage message);
  132. };
  133. class MultCurveAnimProp : public AnimProperty {
  134. public:
  135. MultCurveList *ml;
  136. MultCurveAnimProp() { ml=NULL; }
  137. DWORD ID() {return PROPID_MULTLIST;}
  138. };
  139. #define GetMultListInterface(anim) ((MultCurveList*)anim->GetInterface(I_MULTLIST))
  140. /*---------------------------------------------------------------------*/
  141. //
  142. // For hit testing controller apparatus
  143. //
  144. class CtrlHitRecord {
  145. friend class CtrlHitLog;
  146. CtrlHitRecord *next;
  147. public:
  148. INode *nodeRef;
  149. DWORD distance;
  150. ulong hitInfo;
  151. DWORD infoExtra;
  152. CtrlHitRecord() {next=NULL; distance=0; hitInfo=0; nodeRef=NULL;}
  153. CtrlHitRecord(CtrlHitRecord *nxt,INode *nr, DWORD d, ulong inf, DWORD extra) {
  154. next=nxt;nodeRef=nr;distance=d;hitInfo=inf;infoExtra=extra;}
  155. CtrlHitRecord *Next() {return next;}
  156. };
  157. class CtrlHitLog {
  158. CtrlHitRecord *first;
  159. public:
  160. CtrlHitLog() { first = NULL; }
  161. ~CtrlHitLog() { Clear(); }
  162. CoreExport void Clear();
  163. CtrlHitRecord* First() { return first; }
  164. CoreExport CtrlHitRecord* ClosestHit();
  165. void LogHit(INode *nr,DWORD dist,ulong info,DWORD infoExtra)
  166. {first = new CtrlHitRecord(first,nr,dist,info,infoExtra);}
  167. };
  168. // For enumerating IK paramaters
  169. class IKEnumCallback {
  170. public:
  171. virtual void proc(Control *c, int index)=0;
  172. };
  173. class IKDeriv {
  174. public:
  175. virtual int NumEndEffectors()=0;
  176. virtual Point3 EndEffectorPos(int index)=0;
  177. virtual void DP(Point3 dp,int index)=0;
  178. virtual void DR(Point3 dr,int index)=0;
  179. virtual void NextDOF()=0;
  180. };
  181. // Flags passed to CompDerivs
  182. #define POSITION_DERIV (1<<0)
  183. #define ROTATION_DERIV (1<<1)
  184. // This class is used to store IK parameters that have been
  185. // copied to a clipboard.
  186. class IKClipObject {
  187. public:
  188. // Identifies the creator of the clip object
  189. virtual SClass_ID SuperClassID()=0;
  190. virtual Class_ID ClassID()=0;
  191. virtual void DeleteThis()=0;
  192. };
  193. // Values for 'which' pasted to Copy/PasteIKParams
  194. #define COPYPASTE_IKPOS 1
  195. #define COPYPASTE_IKROT 2
  196. // Passed to InitIKJoints() which is called when importing
  197. // R4 3DS files that have IK joint data.
  198. class InitJointData {
  199. public:
  200. BOOL active[3];
  201. BOOL limit[3];
  202. BOOL ease[3];
  203. Point3 min, max, damping;
  204. };
  205. // These two ways values can be retreived or set.
  206. // For get:
  207. // RELATIVE = Apply
  208. // ABSOLUTE = Just get the value
  209. // For set:
  210. // RELATIVE = Add the value to the existing value (i.e Move/Rotate/Scale)
  211. // ABSOLUTE = Just set the value
  212. enum GetSetMethod {CTRL_RELATIVE,CTRL_ABSOLUTE};
  213. // Control class provides default implementations for load and save which save the ORT type in these chunks:
  214. #define CONTROLBASE_CHUNK 0x8499
  215. #define INORT_CHUNK 0x3000
  216. #define OUTORT_CHUNK 0x3001
  217. #define CONT_DISABLED_CHUNK 0x3002
  218. // Inheritance flags.
  219. #define INHERIT_POS_X (1<<0)
  220. #define INHERIT_POS_Y (1<<1)
  221. #define INHERIT_POS_Z (1<<2)
  222. #define INHERIT_ROT_X (1<<3)
  223. #define INHERIT_ROT_Y (1<<4)
  224. #define INHERIT_ROT_Z (1<<5)
  225. #define INHERIT_SCL_X (1<<6)
  226. #define INHERIT_SCL_Y (1<<7)
  227. #define INHERIT_SCL_Z (1<<8)
  228. #define INHERIT_ALL 511
  229. class Control : public ReferenceTarget {
  230. public:
  231. Control() {SetORT(ORT_CONSTANT,ORT_BEFORE);SetORT(ORT_CONSTANT,ORT_AFTER);};
  232. virtual ~Control() {};
  233. virtual void Copy(Control *from)=0;
  234. virtual void CommitValue(TimeValue t) {}
  235. virtual void RestoreValue(TimeValue t) {}
  236. virtual INode* GetTarget() { return NULL; }
  237. virtual RefResult SetTarget(INode *targ) {return REF_SUCCEED;}
  238. // Implemented by transform controllers that have position controller
  239. // that can be edited in the trajectory branch
  240. virtual Control *GetPositionController() {return NULL;}
  241. virtual Control *GetRotationController() {return NULL;}
  242. virtual Control *GetScaleController() {return NULL;}
  243. virtual BOOL SetPositionController(Control *c) {return FALSE;}
  244. virtual BOOL SetRotationController(Control *c) {return FALSE;}
  245. virtual BOOL SetScaleController(Control *c) {return FALSE;}
  246. // Implemented by look at controllers that have a float valued roll
  247. // controller so that the roll can be edited via the transform type-in
  248. virtual Control *GetRollController() {return NULL;}
  249. virtual BOOL SetRollController(Control *c) {return FALSE;}
  250. // Implemented by any Point3 controller that wishes to indicate that it is intended
  251. // to control floating point RGB color values
  252. virtual BOOL IsColorController() {return FALSE;}
  253. // Implemented by TM controllers that support
  254. // filtering out inheritance
  255. virtual DWORD GetInheritanceFlags() {return INHERIT_ALL;}
  256. virtual BOOL SetInheritanceFlags(DWORD f,BOOL keepPos) {return FALSE;} // return TRUE if TM controller supports inheritance
  257. virtual BOOL IsLeaf() {return TRUE;}
  258. virtual int IsKeyable() {return 1;}
  259. // If a controller does not want to allow another controller
  260. // to be assigned on top of it, it can return FALSE to this method.
  261. virtual BOOL IsReplaceable() {return TRUE;}
  262. // This is called on TM, pos, rot, and scale controllers when their
  263. // input matrix is about to change. If they return FALSE, the node will
  264. // call SetValue() to make the necessary adjustments.
  265. virtual BOOL ChangeParents(TimeValue t,const Matrix3& oldP,const Matrix3& newP,const Matrix3& tm) {return FALSE;}
  266. // val points to an instance of a data type that corresponds with the controller
  267. // type. float for float controllers, etc.
  268. // Note that for SetValue on Rotation controllers, if the SetValue is
  269. // relative, val points to an AngAxis while if it is absolute it points
  270. // to a Quat.
  271. virtual void GetValue(TimeValue t, void *val, Interval &valid, GetSetMethod method=CTRL_ABSOLUTE)=0;
  272. virtual void SetValue(TimeValue t, void *val, int commit=1, GetSetMethod method=CTRL_ABSOLUTE)=0;
  273. // Transform controllers that do not inherit their parent's transform
  274. // should override this method. Returning FALSE will cause SetValue
  275. // to be called even in the case when the parent is also being transformed.
  276. virtual BOOL InheritsParentTransform() { return TRUE; }
  277. virtual int GetORT(int type) {return (aflag>>(type==ORT_BEFORE?A_ORT_BEFORESHIFT:A_ORT_AFTERSHIFT))&A_ORT_MASK;}
  278. CoreExport virtual void SetORT(int ort,int type);
  279. // Sets the enabled/disabled state for ORTs
  280. CoreExport virtual void EnableORTs(BOOL enable);
  281. // Default implementations of load and save handle loading and saving of out of range type.
  282. // Call these from derived class load and save.
  283. // NOTE: Must call these before any of the derived class chunks are loaded or saved.
  284. CoreExport IOResult Save(ISave *isave);
  285. CoreExport IOResult Load(ILoad *iload);
  286. // For IK
  287. // Note: IK params must be given in the order they are applied to
  288. // the parent matrix. When derivatives are computed for a parameter
  289. // that parameter will apply itself to the parent matrix so the next
  290. // parameter has the appropriate reference frame. If a controller isn't
  291. // participating in IK then it should return FALSE and the client (usually PRS)
  292. // will apply the controller's value to the parent TM.
  293. virtual void EnumIKParams(IKEnumCallback &callback) {}
  294. virtual BOOL CompDeriv(TimeValue t,Matrix3& ptm,IKDeriv& derivs,DWORD flags) {return FALSE;}
  295. virtual float IncIKParam(TimeValue t,int index,float delta) {return 0.0f;}
  296. virtual void ClearIKParam(Interval iv,int index) {return;}
  297. virtual BOOL CanCopyIKParams(int which) {return FALSE;}
  298. virtual IKClipObject *CopyIKParams(int which) {return NULL;}
  299. virtual BOOL CanPasteIKParams(IKClipObject *co,int which) {return FALSE;}
  300. virtual void PasteIKParams(IKClipObject *co,int which) {}
  301. virtual void InitIKJoints(InitJointData *posData,InitJointData *rotData) {}
  302. // Ease curves
  303. virtual BOOL CanApplyEaseMultCurves() {return TRUE;}
  304. CoreExport TimeValue ApplyEase(TimeValue t,Interval &valid);
  305. CoreExport void AppendEaseCurve(Control *cont);
  306. CoreExport void DeleteEaseCurve(int i);
  307. CoreExport int NumEaseCurves();
  308. // Multiplier curves
  309. CoreExport float GetMultVal(TimeValue t,Interval &valid);
  310. CoreExport void AppendMultCurve(Control *cont);
  311. CoreExport void DeleteMultCurve(int i);
  312. CoreExport int NumMultCurves();
  313. // These are implemented to handle ease curves. If a controller
  314. // is a leaf controller, then it MUST NOT BY DEFINITION have any
  315. // sub controllers or references. If it is a leaf controller, then
  316. // these are implemented to handle the ease curve list.
  317. // If it is NOT a leaf controller, then these can be overridden.
  318. CoreExport int NumRefs();
  319. CoreExport RefTargetHandle GetReference(int i);
  320. CoreExport void SetReference(int i, RefTargetHandle rtarg);
  321. CoreExport int NumSubs();
  322. CoreExport Animatable* SubAnim(int i);
  323. CoreExport TSTR SubAnimName(int i);
  324. // Default implementations of some Animatable methods
  325. CoreExport void* GetInterface(ULONG id);
  326. CoreExport int PaintFCurves(
  327. ParamDimensionBase *dim,
  328. HDC hdc,
  329. Rect& rcGraph,
  330. Rect& rcPaint,
  331. float tzoom,
  332. int tscroll,
  333. float vzoom,
  334. int vscroll,
  335. DWORD flags );
  336. CoreExport int GetFCurveExtents(
  337. ParamDimensionBase *dim,
  338. float &min, float &max, DWORD flags);
  339. //-------------------------------------------------------
  340. // Controllers that wish to have an apparatus available in
  341. // the scene will implement these methods:
  342. // NOTE: Most of these methods are duplicated in BaseObject or Object
  343. // (see object.h for descriptions).
  344. virtual int Display(TimeValue t, INode* inode, ViewExp *vpt, int flags) { return 0; };
  345. virtual int HitTest(TimeValue t, INode* inode, int type, int crossing, int flags, IPoint2 *p, ViewExp *vpt) { return 0; }
  346. virtual void GetWorldBoundBox(TimeValue t,INode* inode, ViewExp *vpt, Box3& box) {}
  347. virtual void ActivateSubobjSel(int level, XFormModes& modes ) {}
  348. virtual void SelectSubComponent(CtrlHitRecord *hitRec, BOOL selected, BOOL all, BOOL invert=FALSE) {}
  349. virtual void ClearSelection(int selLevel) {}
  350. virtual int SubObjectIndex(CtrlHitRecord *hitRec) {return 0;}
  351. virtual void GetSubObjectCenters(SubObjAxisCallback *cb,TimeValue t,INode *node) {}
  352. virtual void GetSubObjectTMs(SubObjAxisCallback *cb,TimeValue t,INode *node) {}
  353. // Modify sub object apparatuses
  354. virtual void SubMove( TimeValue t, Matrix3& partm, Matrix3& tmAxis, Point3& val, BOOL localOrigin=FALSE ){}
  355. virtual void SubRotate( TimeValue t, Matrix3& partm, Matrix3& tmAxis, Quat& val, BOOL localOrigin=FALSE ){}
  356. virtual void SubScale( TimeValue t, Matrix3& partm, Matrix3& tmAxis, Point3& val, BOOL localOrigin=FALSE ){}
  357. virtual void MouseCycleCompleted(TimeValue t) {}
  358. };
  359. // Any controller that does not evaluate itself as a function of it's
  360. // input can subclass off this class.
  361. // GetValueLocalTime() will never ask the controller to apply the value,
  362. // it will always ask for it absolute.
  363. class StdControl : public Control {
  364. public:
  365. virtual void GetValueLocalTime(TimeValue t, void *val, Interval &valid, GetSetMethod method=CTRL_ABSOLUTE)=0;
  366. virtual void SetValueLocalTime(TimeValue t, void *val, int commit=1, GetSetMethod method=CTRL_ABSOLUTE)=0;
  367. CoreExport void GetValue(TimeValue t, void *val, Interval &valid, GetSetMethod method=CTRL_ABSOLUTE);
  368. CoreExport void SetValue(TimeValue t, void *val, int commit=1, GetSetMethod method=CTRL_ABSOLUTE);
  369. virtual void Extrapolate(Interval range,TimeValue t,void *val,Interval &valid,int type)=0;
  370. virtual void *CreateTempValue()=0;
  371. virtual void DeleteTempValue(void *val)=0;
  372. virtual void ApplyValue(void *val, void *delta)=0;
  373. virtual void MultiplyValue(void *val, float m)=0;
  374. };
  375. // Each super class of controller may have a specific packet defined that
  376. // the 'val' pointer will point to instead of a literal value.
  377. // In reality, probably only the Transform controller will do this.
  378. enum SetXFormCommand { XFORM_MOVE, XFORM_ROTATE, XFORM_SCALE, XFORM_SET };
  379. class SetXFormPacket {
  380. public:
  381. SetXFormCommand command;
  382. Matrix3 tmParent;
  383. Matrix3 tmAxis; // if command is XFORM_SET, this will contain the new value for the XFORM.
  384. Point3 p;
  385. Quat q;
  386. AngAxis aa;
  387. BOOL localOrigin;
  388. // XFORM_SET
  389. SetXFormPacket(const Matrix3& mat,const Matrix3& par=Matrix3(1))
  390. {command=XFORM_SET,tmParent=par,tmAxis=mat;}
  391. // XFORM_MOVE
  392. SetXFormPacket(Point3 pt, const Matrix3& par=Matrix3(1),
  393. const Matrix3& a=Matrix3(1))
  394. {command=XFORM_MOVE;tmParent=par;tmAxis=a;p=pt;localOrigin=FALSE;}
  395. // XFORM_ROTATE
  396. SetXFormPacket(Quat qt, BOOL l, const Matrix3& par=Matrix3(1),
  397. const Matrix3& a=Matrix3(1))
  398. {command=XFORM_ROTATE;tmParent=par;tmAxis=a;q=qt;aa=AngAxis(q);localOrigin=l;}
  399. SetXFormPacket(AngAxis aA, BOOL l, const Matrix3& par=Matrix3(1),
  400. const Matrix3& a=Matrix3(1))
  401. {command=XFORM_ROTATE;tmParent=par;tmAxis=a;q=Quat(aA);aa=aA;localOrigin=l;}
  402. // XFORM_SCALE
  403. SetXFormPacket(Point3 pt, BOOL l, const Matrix3& par=Matrix3(1),
  404. const Matrix3& a=Matrix3(1))
  405. {command=XFORM_SCALE;tmParent=par;tmAxis=a;p=pt;localOrigin=l;}
  406. // Just in case you want to do it by hand...
  407. SetXFormPacket() {};
  408. };
  409. // This is a special control base class for controllers that control
  410. // morphing of geomoetry.
  411. //
  412. // The 'val' pointer used with GetValue will point to an object state.
  413. // This would be the result of evaluating a combination of targets and
  414. // producing a new object that is some combination of the targets.
  415. //
  416. // The 'val' pointer used with SetValue will point to a
  417. // SetMorphTargetPacket data structure. This has a pointer to
  418. // an object (entire pipeline) and the name of the target.
  419. // A pointer to one of these is passed to SetValue
  420. class SetMorphTargetPacket {
  421. public:
  422. Matrix3 tm;
  423. Object *obj;
  424. TSTR name;
  425. BOOL forceCreate; // Make sure the key is created even if it is at frame 0
  426. SetMorphTargetPacket(Object *o,TSTR n,Matrix3 &m,BOOL fc=FALSE) {obj = o;name = n;tm = m;forceCreate=fc;}
  427. SetMorphTargetPacket(Object *o,TSTR n,BOOL fc=FALSE) {obj = o;name = n;tm = Matrix3(1);forceCreate=fc;}
  428. };
  429. class MorphControl : public Control {
  430. public:
  431. // Access the object pipelines of the controller's targets. Note
  432. // that these are pointers to the pipelines, not the result of
  433. // evaluating the pipelines.
  434. virtual int NumMorphTargs() {return 0;}
  435. virtual Object *GetMorphTarg(int i) {return NULL;}
  436. virtual void GetMorphTargName(int i,TSTR &name) {name.printf(_T("Target #%d"),i);}
  437. virtual Matrix3 GetMorphTargTM(int i) {return Matrix3(1);}
  438. // Checks an object to see if it is an acceptable target.
  439. virtual BOOL ValidTarget(TimeValue t,Object *obj) {return FALSE;}
  440. };
  441. //----------------------------------------------------------------//
  442. //
  443. // Some stuff to help with ORTs - these could actually be Interval methods
  444. inline TimeValue CycleTime(Interval i,TimeValue t)
  445. {
  446. int res, dur = i.Duration()-1;
  447. if (dur<=0) return t;
  448. res = (t-i.Start())%dur;
  449. if (res<0) {
  450. return i.End()+res;
  451. } else {
  452. return i.Start()+res;
  453. }
  454. }
  455. inline int NumCycles(Interval i,TimeValue t)
  456. {
  457. int dur = i.Duration()-1;
  458. if (dur<=0) return 1;
  459. if (t<i.Start()) {
  460. return (abs(t-i.Start())/dur)+1;
  461. } else
  462. if (t>i.End()) {
  463. return (abs(t-i.End())/dur)+1;
  464. } else {
  465. return 0;
  466. }
  467. }
  468. // Types that use this template must support:
  469. // T + T, T - T, T * float, T + float
  470. template <class T> T
  471. LinearExtrapolate(TimeValue t0, TimeValue t1, T &val0, T &val1, T &endVal)
  472. {
  473. return (T)(endVal + (val1-val0) * float(t1-t0));
  474. }
  475. template <class T> T
  476. RepeatExtrapolate(Interval range, TimeValue t,
  477. T &startVal, T &endVal, T &cycleVal)
  478. {
  479. int cycles = NumCycles(range,t);
  480. T delta;
  481. if (t<range.Start()) {
  482. delta = startVal - endVal;
  483. } else {
  484. delta = endVal - startVal;
  485. }
  486. return (T)(cycleVal + delta * float(cycles));
  487. }
  488. template <class T> T
  489. IdentityExtrapolate(TimeValue endPoint, TimeValue t, T &endVal )
  490. {
  491. return (T)(endVal + float(t-endPoint));
  492. }
  493. CoreExport Quat LinearExtrapolate(TimeValue t0, TimeValue t1, Quat &val0, Quat &val1, Quat &endVal);
  494. CoreExport Quat RepeatExtrapolate(Interval range, TimeValue t,
  495. Quat &startVal, Quat &endVal, Quat &cycleVal);
  496. CoreExport Quat IdentityExtrapolate(TimeValue endPoint, TimeValue t, Quat &endVal );
  497. template <class T> T
  498. LinearInterpolate(const T &v0,const T &v1,float u)
  499. {
  500. return (T)((1.0f-u)*v0 + u*v1);
  501. }
  502. inline Quat
  503. LinearInterpolate(const Quat &v0,const Quat &v1,float u)
  504. {
  505. return Slerp(v0,v1,u);
  506. }
  507. inline ScaleValue
  508. LinearInterpolate(const ScaleValue &v0,const ScaleValue &v1,float u)
  509. {
  510. ScaleValue res;
  511. res.s = ((float)1.0-u)*v0.s + u*v1.s;
  512. res.q = Slerp(v0.q,v1.q,u);
  513. return res;
  514. }
  515. inline Interval TestInterval(Interval iv, DWORD flags)
  516. {
  517. TimeValue start = iv.Start();
  518. TimeValue end = iv.End();
  519. if (!(flags&TIME_INCLEFT)) {
  520. start++;
  521. }
  522. if (!(flags&TIME_INCRIGHT)) {
  523. end--;
  524. }
  525. if (end<start) {
  526. iv.SetEmpty();
  527. } else {
  528. iv.Set(start,end);
  529. }
  530. return iv;
  531. }
  532. inline Quat ScaleQuat(Quat q, float s)
  533. {
  534. float angle;
  535. Point3 axis;
  536. AngAxisFromQ(q,&angle,axis);
  537. return QFromAngAxis(angle*s,axis);
  538. }
  539. //-------------------------------------------------------------------
  540. // A place to store values during Hold/Restore periods
  541. //
  542. //********************************************************
  543. // TempStore: This is a temporary implementation:
  544. // It uses a linear search-
  545. // A hash-coded dictionary would be faster.
  546. // (if there are ever a lot of entries)
  547. //********************************************************
  548. struct Slot {
  549. void *key;
  550. void *pdata;
  551. int nbytes;
  552. Slot *next;
  553. public:
  554. Slot() { pdata = NULL; }
  555. ~Slot() {
  556. if (pdata) free(pdata);
  557. pdata = NULL;
  558. }
  559. };
  560. class TempStore {
  561. Slot *slotList;
  562. Slot* Find(int n, void *data, void *ptr);
  563. public:
  564. TempStore() { slotList = NULL; }
  565. ~TempStore() { ClearAll(); }
  566. CoreExport void ClearAll(); // empty out the store
  567. CoreExport void PutBytes(int n, void *data, void *ptr);
  568. CoreExport void GetBytes(int n, void *data, void *ptr);
  569. CoreExport void Clear(void *ptr); // Remove single entry
  570. void PutFloat(float f, void *ptr) {
  571. PutBytes(sizeof(float),(void *)&f,ptr);
  572. }
  573. CoreExport void PutInt(int i, void *ptr) {
  574. PutBytes(sizeof(int),(void *)&i,ptr);
  575. }
  576. CoreExport void GetFloat(float *f, void *ptr) {
  577. GetBytes(sizeof(float),(void *)f,ptr);
  578. }
  579. CoreExport void GetInt(int *i, void *ptr) {
  580. GetBytes(sizeof(int),(void *)i,ptr);
  581. }
  582. CoreExport void PutPoint3(Point3 f, void *ptr) {
  583. PutBytes(sizeof(Point3),(void *)&f,ptr);
  584. }
  585. CoreExport void GetPoint3(Point3 *f, void *ptr) {
  586. GetBytes(sizeof(Point3),(void *)f,ptr);
  587. }
  588. CoreExport void PutQuat( Quat f, void *ptr) {
  589. PutBytes(sizeof(Quat),(void *)&f,ptr);
  590. }
  591. CoreExport void GetQuat( Quat *f, void *ptr) {
  592. GetBytes(sizeof(Quat),(void *)f,ptr);
  593. }
  594. CoreExport void PutScaleValue( ScaleValue f, void *ptr) {
  595. PutBytes(sizeof(ScaleValue),(void *)&f,ptr);
  596. }
  597. CoreExport void GetScaleValue( ScaleValue *f, void *ptr) {
  598. GetBytes(sizeof(ScaleValue),(void *)f,ptr);
  599. }
  600. };
  601. extern CoreExport TempStore tmpStore; // this should be in the scene data struct.
  602. CoreExport int Animating(); // is the animate switch on??
  603. CoreExport void AnimateOn(); // turn animate on
  604. CoreExport void AnimateOff(); // turn animate off
  605. CoreExport void SuspendAnimate(); // suspend animation (uses stack)
  606. CoreExport void ResumeAnimate(); // resume animation ( " )
  607. CoreExport TimeValue GetAnimStart();
  608. CoreExport TimeValue GetAnimEnd();
  609. CoreExport void SetAnimStart(TimeValue s);
  610. CoreExport void SetAnimEnd(TimeValue e);
  611. CoreExport Control *NewDefaultFloatController();
  612. CoreExport Control *NewDefaultPoint3Controller();
  613. CoreExport Control *NewDefaultMatrix3Controller();
  614. CoreExport Control *NewDefaultPositionController();
  615. CoreExport Control *NewDefaultRotationController();
  616. CoreExport Control *NewDefaultScaleController();
  617. CoreExport Control *NewDefaultBoolController();
  618. CoreExport Control *NewDefaultColorController();
  619. CoreExport void SetDefaultController(SClass_ID sid, ClassDesc *desc);
  620. CoreExport ClassDesc *GetDefaultController(SClass_ID sid);
  621. CoreExport void SetDefaultColorController(ClassDesc *desc);
  622. CoreExport void SetDefaultBoolController(ClassDesc *desc);
  623. #endif //__CONTROL__