interpik.h

Go to the documentation of this file.
00001 //**************************************************************************/
00002 // Copyright (c) 1998-2006 Autodesk, Inc.
00003 // All rights reserved.
00004 // 
00005 // These coded instructions, statements, and computer programs contain
00006 // unpublished proprietary information written by Autodesk, Inc., and are
00007 // protected by Federal copyright law. They may not be disclosed to third
00008 // parties or copied or duplicated in any form, in whole or in part, without
00009 // the prior written consent of Autodesk, Inc.
00010 //**************************************************************************/
00011 // FILE:        interpik.h
00012 // DESCRIPTION: Implements IK related methods for interp controllers
00013 // AUTHOR:      Rolf Berteig
00014 // HISTORY:     created 6/19/95
00015 //**************************************************************************/
00016 
00017 #pragma once
00018 #include "maxheap.h"
00019 #include "hold.h"
00020 #include "control.h"
00021 
00022 // forward declarations
00023 class Control;
00024 class ISpinnerControl;
00025 class IKEnumCallback;
00026 class IKDeriv;
00027 class IKClipObject;
00028 class InitJointData;
00029 class InitJointData2;
00030 
00031 #define PROPID_INTERPUI     (PROPID_USER+1)
00032 #define PROPID_JOINTPARAMS  (PROPID_USER+2)
00033 #define PROPID_KEYINFO      (PROPID_USER+3)
00034 
00035 // Flags for JointParams
00036 #define JNT_XACTIVE     (1<<0)
00037 #define JNT_YACTIVE     (1<<1)
00038 #define JNT_ZACTIVE     (1<<2)
00039 #define JNT_XLIMITED    (1<<3)
00040 #define JNT_YLIMITED    (1<<4)
00041 #define JNT_ZLIMITED    (1<<5)
00042 #define JNT_XEASE       (1<<6)
00043 #define JNT_YEASE       (1<<7)
00044 #define JNT_ZEASE       (1<<8)
00045 #define JNT_XSPRING     (1<<9)
00046 #define JNT_YSPRING     (1<<10)
00047 #define JNT_ZSPRING     (1<<11)
00048 
00049 #define JNT_PARAMS2     (1<<12) // If this bit is set, the structure is a JointParams2
00050 #define JNT_PARAMS_EULER (1<<13) // If this bit is set, the structure is a JointParamsEuler
00051 
00052 #define JP_HELD         (1<<27)
00053 #define JNT_LIMITEXACT  (1<<28)
00054 #define JNT_ROLLOPEN    (1<<29)
00055 #define JNT_ROT         (1<<30) 
00056 #define JNT_POS         (1<<31)
00057 
00058 class JointParams2;
00059 
00073 class InterpCtrlUI : public AnimProperty {
00074     public:
00075         HWND hParams;
00076         IObjParam *ip;
00077         Control *cont;
00078         
00081         InterpCtrlUI(HWND h,IObjParam *i,Control *c) 
00082             {hParams=h;ip=i;cont=c;}
00083         
00085         ~InterpCtrlUI() {}
00088         DWORD ID() {return PROPID_INTERPUI;}        
00089     };
00090 
00091 class InterpKeyInfo : public AnimProperty {
00092     public:
00093         DWORD ID() {return PROPID_KEYINFO;}
00094         virtual ~InterpKeyInfo() {}
00095     };
00096 
00097 
00098 // IK Joint parameters
00140 class JointParams : public AnimProperty {
00141     public:
00142         float *min, *max;
00143         float *damping;
00144         float *spring;
00145         float *stens;
00146         float scale;
00147         DWORD flags;
00148         int dofs;
00149 
00152         CoreExport JointParams(DWORD type=JNT_POS,int dofs=3,float s=1.0f);
00155         CoreExport JointParams(const JointParams &j);
00157         CoreExport ~JointParams();
00160         DWORD ID() {return PROPID_JOINTPARAMS;}
00161 
00163         CoreExport JointParams&  operator=(JointParams& j);
00164 
00165         // Returns TRUE if the curent state is the default.
00169         CoreExport BOOL IsDefault();
00170         
00181         CoreExport IOResult Save(ISave *isave);
00192         CoreExport IOResult Load(ILoad *iload);
00193 
00194         // Applies contraints to the given delta based on parameters and the current value v.
00212         CoreExport float ConstrainInc(int index,float v,float delta);       
00213         
00214         // Access bits
00224         BOOL Active(int i) {return (flags&(JNT_XACTIVE<<i))?TRUE:FALSE;}
00234         BOOL Limited(int i) {return (flags&(JNT_XLIMITED<<i))?TRUE:FALSE;}
00245         BOOL Ease(int i) {return (flags&(JNT_XEASE<<i))?TRUE:FALSE;}
00246         BOOL Spring(int i) {return (flags&(JNT_XSPRING<<i))?TRUE:FALSE;}
00251         DWORD Type() {return flags & (JNT_POS|JNT_ROT);}
00254         BOOL RollupOpen() {return (flags&JNT_ROLLOPEN)?TRUE:FALSE;}
00265         void SetActive(int i,BOOL s) {if (s) flags|=(JNT_XACTIVE<<i); else flags&=~(JNT_XACTIVE<<i);}
00276         void SetLimited(int i,BOOL s) {if (s) flags|=(JNT_XLIMITED<<i); else flags&=~(JNT_XLIMITED<<i);}
00287         void SetEase(int i,BOOL s) {if (s) flags|=(JNT_XEASE<<i); else flags&=~(JNT_XEASE<<i);}
00288         void SetSpring(int i,BOOL s) {if (s) flags|=(JNT_XSPRING<<i); else flags&=~(JNT_XSPRING<<i);}
00296         void SetType(DWORD type) {flags&=~(JNT_POS|JNT_ROT);flags|=type;}
00302         void SetRollOpen(BOOL open) {if (open) flags|=JNT_ROLLOPEN; else flags&= ~JNT_ROLLOPEN;}
00303 
00304         // This is the interactive adjustment of limits
00320         CoreExport virtual void SpinnerChange(InterpCtrlUI *ui,WORD id,ISpinnerControl* spin,BOOL interactive);
00321 
00322         // These methods manage the joint parameters dialog.
00325         CoreExport void InitDialog(InterpCtrlUI *ui);
00328         CoreExport void EndDialog(InterpCtrlUI *ui,BOOL dontDel=FALSE);     
00331         CoreExport void SpinnerDown(InterpCtrlUI *ui,WORD id,ISpinnerControl *spin);
00334         CoreExport void SpinnerUp(InterpCtrlUI *ui,WORD id,ISpinnerControl *spin,BOOL accept);
00337         CoreExport void Command(InterpCtrlUI *ui,WORD notify, WORD id, HWND hCtrl);
00340         CoreExport void EnableDisable(InterpCtrlUI *ui);
00341 
00342         CoreExport void MirrorConstraints(int axis);
00343 
00344         // RB 8/25/2000: Added this method to support JointParams2
00345         JointParams2 *GetJointParams2Interface() {if (flags & JNT_PARAMS2) return (JointParams2*)this; else return NULL;}
00346     };
00347 
00361 class JointParams2 : public JointParams {
00362     public:
00363         float *preferredAngle;
00364 
00375         CoreExport JointParams2(DWORD type=JNT_POS,int dofs=3,float s=1.0f);
00378         CoreExport JointParams2(const JointParams2 &j);
00381         CoreExport JointParams2(const JointParams  &j);
00383         CoreExport ~JointParams2();
00384     };
00385 
00386 
00387 
00388 class JPLimitsRestore : public RestoreObj {
00389     public:
00390         JointParams *jp;
00391         float umin[6], umax[6], uspring[6];
00392         float rmin[6], rmax[6], rspring[6];
00393         
00394         JPLimitsRestore(JointParams *j) {
00395             jp = j;
00396             for (int i=0; i<jp->dofs; i++) {
00397                 umin[i]    = jp->min[i];
00398                 umax[i]    = jp->max[i];
00399                 uspring[i] = jp->spring[i];
00400                 }
00401             }
00402         void Restore(int isUndo) {
00403             if (isUndo) {
00404                 for (int i=0; i<jp->dofs; i++) {
00405                     rmin[i]    = jp->min[i];
00406                     rmax[i]    = jp->max[i];
00407                     rspring[i] = jp->spring[i];
00408                     }
00409                 }
00410             for (int i=0; i<jp->dofs; i++) {
00411                 jp->min[i]    = umin[i];
00412                 jp->max[i]    = umax[i];
00413                 jp->spring[i] = uspring[i];
00414                 }           
00415             }
00416         void Redo() {
00417             for (int i=0; i<jp->dofs; i++) {
00418                 jp->min[i]    = rmin[i];
00419                 jp->max[i]    = rmax[i];
00420                 jp->spring[i] = rspring[i];
00421                 }           
00422             }
00423         void EndHold() {
00424             jp->flags &= ~JP_HELD;
00425             }
00426     };
00427 
00428 
00429 // Just holds a couple of pointers.
00440 class JointDlgData: public MaxHeapOperators {
00441     public:
00442         InterpCtrlUI *ui;
00443         JointParams *jp;    
00446         JointDlgData(InterpCtrlUI *ui,JointParams *jp) {this->ui=ui;this->jp=jp;}
00447     };
00448 
00449 // A window proc for handling joint parameters.
00450 CoreExport INT_PTR CALLBACK JointParamDlgProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam);
00451 
00452 
00453 // Handles the IK functions for all types of point3 and quat key frame controllers.
00454 void QuatEnumIKParams(Control *cont,IKEnumCallback &callback);
00455 BOOL QuatCompDeriv(Control *cont,TimeValue t,Matrix3& ptm,IKDeriv& derivs,DWORD flags);
00456 float QuatIncIKParam(Control *cont,TimeValue t,int index,float delta);
00457 CoreExport void QuatBeginIKParams(Control *cont,IObjParam *ip, ULONG flags,Animatable *prev);
00458 void Point3EnumIKParams(Control *cont,IKEnumCallback &callback);
00459 BOOL Point3CompDeriv(Control *cont,TimeValue t,Matrix3& ptm,IKDeriv& derivs,DWORD flags);
00460 float Point3IncIKParam(Control *cont,TimeValue t,int index,float delta);
00461 CoreExport void Point3BeginIKParams(Control *cont,IObjParam *ip, ULONG flags,Animatable *prev);
00462 
00463 CoreExport BOOL CanCopyIKParams(Control *cont,int which);
00464 CoreExport IKClipObject* CopyIKParams(Control *cont,int which);
00465 CoreExport BOOL CanPasteIKParams(Control *cont,IKClipObject *co,int which);
00466 CoreExport void PasteIKParams(Control *cont,IKClipObject *co,int which);
00467 
00468 CoreExport void InitIKJointsPos(Control *cont,InitJointData *posData);
00469 CoreExport void InitIKJointsRot(Control *cont,InitJointData *rotData);
00470 CoreExport BOOL GetIKJointsPos(Control *cont,InitJointData *posData);
00471 CoreExport BOOL GetIKJointsRot(Control *cont,InitJointData *rotData);
00472 
00473 CoreExport void InitIKJointsPos(Control *cont,InitJointData2 *posData);
00474 CoreExport void InitIKJointsRot(Control *cont,InitJointData2 *rotData);
00475 CoreExport BOOL GetIKJointsPos(Control *cont,InitJointData2 *posData);
00476 CoreExport BOOL GetIKJointsRot(Control *cont,InitJointData2 *rotData);
00477 
00478 CoreExport void QuatMirrorIKConstraints(Control *cont,int axis,int which);
00479 
00480 class StdIKClipObject : public IKClipObject {
00481     public:
00482         JointParams *jp;
00483         SClass_ID sid;
00484         Class_ID cid;
00485         
00486         StdIKClipObject(SClass_ID s,Class_ID c,JointParams *j) 
00487             {sid=s;cid=c;jp=j;}
00488         CoreExport ~StdIKClipObject();
00489         SClass_ID   SuperClassID() {return sid;}
00490         Class_ID    ClassID() {return cid;}     
00491         CoreExport void DeleteThis();
00492     };
00493 
00494 
00495 #define SPRINGTENS_UI   (50.0f)
00496 #define DEF_SPRINGTENS  (0.02f)
00497 
00498