📄 control.h
字号:
//
// The 'val' pointer used with SetValue will point to a
// SetMorphTargetPacket data structure. This has a pointer to
// an object (entire pipeline) and the name of the target.
// A pointer to one of these is passed to SetValue
class SetMorphTargetPacket {
public:
Matrix3 tm;
Object *obj;
TSTR name;
BOOL forceCreate; // Make sure the key is created even if it is at frame 0
SetMorphTargetPacket(Object *o,TSTR n,Matrix3 &m,BOOL fc=FALSE) {obj = o;name = n;tm = m;forceCreate=fc;}
SetMorphTargetPacket(Object *o,TSTR n,BOOL fc=FALSE) {obj = o;name = n;tm = Matrix3(1);forceCreate=fc;}
};
class MorphControl : public Control {
public:
// Access the object pipelines of the controller's targets. Note
// that these are pointers to the pipelines, not the result of
// evaluating the pipelines.
virtual int NumMorphTargs() {return 0;}
virtual Object *GetMorphTarg(int i) {return NULL;}
virtual void DeleteMorphTarg(int i) {}
virtual void GetMorphTargName(int i,TSTR &name) {name.printf(_T("Target #%d"),i);}
virtual void SetMorphTargName(int i,TSTR name) {}
virtual Matrix3 GetMorphTargTM(int i) {return Matrix3(1);}
// Checks an object to see if it is an acceptable target.
virtual BOOL ValidTarget(TimeValue t,Object *obj) {return FALSE;}
// When a REFMSG_SELECT_BRANCH message is received the morph controller should
// mark the target indicated and be prepared to return its ID from this method.
virtual int GetFlaggedTarget() {return -1;}
// Should call these methods on targets
virtual BOOL HasUVW() { return 1; }
virtual void SetGenUVW(BOOL sw) { }
};
//-------------------------------------------------------------
// Control base class for Master Controllers
//
class MasterPointControl : public Control {
public:
// Set the number of sub-controllers
virtual void SetNumSubControllers(int num, BOOL keep=FALSE) {}
// Return the number of sub-controllers
virtual int GetNumSubControllers() { return 0; }
// Delete all the sub-controllers that are set to TRUE in the BitArray
virtual void DeleteControlSet (BitArray set) {}
// Add a new sub-controller
virtual int AddSubController(Control* ctrl) { return 0; }
// Return i'th of sub-controller
virtual Control* GetSubController(int i) { return NULL; }
// Set the i'th sub-controller
virtual void SetSubController(int i, Control* ctrl) {}
};
//----------------------------------------------------------------//
//
// Some stuff to help with ORTs - these could actually be Interval methods
inline TimeValue CycleTime(Interval i,TimeValue t)
{
int res, dur = i.Duration()-1;
if (dur<=0) return t;
res = (t-i.Start())%dur;
if (t<i.Start()) {
return i.End()+res;
} else {
return i.Start()+res;
}
}
inline int NumCycles(Interval i,TimeValue t)
{
int dur = i.Duration()-1;
if (dur<=0) return 1;
if (t<i.Start()) {
return (abs(t-i.Start())/dur)+1;
} else
if (t>i.End()) {
return (abs(t-i.End())/dur)+1;
} else {
return 0;
}
}
// Types that use this template must support:
// T + T, T - T, T * float, T + float
template <class T> T
LinearExtrapolate(TimeValue t0, TimeValue t1, T &val0, T &val1, T &endVal)
{
return (T)(endVal + (val1-val0) * float(t1-t0));
}
template <class T> T
RepeatExtrapolate(Interval range, TimeValue t,
T &startVal, T &endVal, T &cycleVal)
{
int cycles = NumCycles(range,t);
T delta;
if (t<range.Start()) {
delta = startVal - endVal;
} else {
delta = endVal - startVal;
}
return (T)(cycleVal + delta * float(cycles));
}
template <class T> T
IdentityExtrapolate(TimeValue endPoint, TimeValue t, T &endVal )
{
return (T)(endVal + float(t-endPoint));
}
CoreExport Quat LinearExtrapolate(TimeValue t0, TimeValue t1, Quat &val0, Quat &val1, Quat &endVal);
CoreExport Quat RepeatExtrapolate(Interval range, TimeValue t,
Quat &startVal, Quat &endVal, Quat &cycleVal);
CoreExport Quat IdentityExtrapolate(TimeValue endPoint, TimeValue t, Quat &endVal );
CoreExport ScaleValue LinearExtrapolate(TimeValue t0, TimeValue t1, ScaleValue &val0, ScaleValue &val1, ScaleValue &endVal);
CoreExport ScaleValue RepeatExtrapolate(Interval range, TimeValue t, ScaleValue &startVal, ScaleValue &endVal, ScaleValue &cycleVal);
CoreExport ScaleValue IdentityExtrapolate(TimeValue endPoint, TimeValue t, ScaleValue &endVal);
template <class T> T
LinearInterpolate(const T &v0,const T &v1,float u)
{
return (T)((1.0f-u)*v0 + u*v1);
}
inline Quat
LinearInterpolate(const Quat &v0,const Quat &v1,float u)
{
return Slerp(v0,v1,u);
}
inline ScaleValue
LinearInterpolate(const ScaleValue &v0,const ScaleValue &v1,float u)
{
ScaleValue res;
res.s = ((float)1.0-u)*v0.s + u*v1.s;
res.q = Slerp(v0.q,v1.q,u);
return res;
}
inline Interval TestInterval(Interval iv, DWORD flags)
{
TimeValue start = iv.Start();
TimeValue end = iv.End();
if (!(flags&TIME_INCLEFT)) {
start++;
}
if (!(flags&TIME_INCRIGHT)) {
end--;
}
if (end<start) {
iv.SetEmpty();
} else {
iv.Set(start,end);
}
return iv;
}
inline Quat ScaleQuat(Quat q, float s)
{
float angle;
Point3 axis;
AngAxisFromQ(q,&angle,axis);
return QFromAngAxis(angle*s,axis);
}
//-------------------------------------------------------------------
// A place to store values during Hold/Restore periods
//
//********************************************************
// TempStore: This is a temporary implementation:
// It uses a linear search-
// A hash-coded dictionary would be faster.
// (if there are ever a lot of entries)
//********************************************************
struct Slot {
void *key;
void *pdata;
int nbytes;
Slot *next;
public:
Slot() { pdata = NULL; }
~Slot() {
if (pdata) free(pdata);
pdata = NULL;
}
};
class TempStore {
Slot *slotList;
Slot* Find(int n, void *data, void *ptr);
public:
TempStore() { slotList = NULL; }
~TempStore() { ClearAll(); }
CoreExport void ClearAll(); // empty out the store
CoreExport void PutBytes(int n, void *data, void *ptr);
CoreExport void GetBytes(int n, void *data, void *ptr);
CoreExport void Clear(void *ptr); // Remove single entry
void PutFloat(float f, void *ptr) {
PutBytes(sizeof(float),(void *)&f,ptr);
}
CoreExport void PutInt(int i, void *ptr) {
PutBytes(sizeof(int),(void *)&i,ptr);
}
CoreExport void GetFloat(float *f, void *ptr) {
GetBytes(sizeof(float),(void *)f,ptr);
}
CoreExport void GetInt(int *i, void *ptr) {
GetBytes(sizeof(int),(void *)i,ptr);
}
CoreExport void PutPoint3(Point3 f, void *ptr) {
PutBytes(sizeof(Point3),(void *)&f,ptr);
}
CoreExport void GetPoint3(Point3 *f, void *ptr) {
GetBytes(sizeof(Point3),(void *)f,ptr);
}
CoreExport void PutQuat( Quat f, void *ptr) {
PutBytes(sizeof(Quat),(void *)&f,ptr);
}
CoreExport void GetQuat( Quat *f, void *ptr) {
GetBytes(sizeof(Quat),(void *)f,ptr);
}
CoreExport void PutScaleValue( ScaleValue f, void *ptr) {
PutBytes(sizeof(ScaleValue),(void *)&f,ptr);
}
CoreExport void GetScaleValue( ScaleValue *f, void *ptr) {
GetBytes(sizeof(ScaleValue),(void *)f,ptr);
}
};
extern CoreExport TempStore tmpStore; // this should be in the scene data struct.
CoreExport int Animating(); // is the animate switch on??
CoreExport void AnimateOn(); // turn animate on
CoreExport void AnimateOff(); // turn animate off
CoreExport void SuspendAnimate(); // suspend animation (uses stack)
CoreExport void ResumeAnimate(); // resume animation ( " )
CoreExport TimeValue GetAnimStart();
CoreExport TimeValue GetAnimEnd();
CoreExport void SetAnimStart(TimeValue s);
CoreExport void SetAnimEnd(TimeValue e);
CoreExport Control *NewDefaultFloatController();
CoreExport Control *NewDefaultPoint3Controller();
CoreExport Control *NewDefaultMatrix3Controller();
CoreExport Control *NewDefaultPositionController();
CoreExport Control *NewDefaultRotationController();
CoreExport Control *NewDefaultScaleController();
CoreExport Control *NewDefaultBoolController();
CoreExport Control *NewDefaultColorController();
CoreExport Control *NewDefaultMasterPointController();
CoreExport Control* CreateInterpFloat();
CoreExport Control* CreateInterpPosition();
CoreExport Control* CreateInterpPoint3();
CoreExport Control* CreateInterpRotation();
CoreExport Control* CreateInterpScale();
CoreExport Control* CreatePRSControl();
CoreExport Control* CreateLookatControl();
CoreExport Control* CreateMasterPointControl();
CoreExport void SetDefaultController(SClass_ID sid, ClassDesc *desc);
CoreExport ClassDesc *GetDefaultController(SClass_ID sid);
CoreExport void SetDefaultColorController(ClassDesc *desc);
CoreExport void SetDefaultBoolController(ClassDesc *desc);
#endif //__CONTROL__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -