Message 1 of 2
Trying to assign referenced control
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Why this does not work.
object does not move in viewport.
#include "MaxControls.h"
#include "maxscript/maxscript.h"
#define MaxControls_CLASS_ID Class_ID(0x8f48468f, 0x9b4b7159)
#define PBLOCK_REF 0
class MaxControls : public Control
{
public:
//From Animatable
Class_ID ClassID() { return MaxControls_CLASS_ID; }
SClass_ID SuperClassID() { return CTRL_MATRIX3_CLASS_ID; }
void GetClassName(TSTR& s) { s = GetString(IDS_CLASS_NAME); }
RefResult NotifyRefChanged(const Interval& changeInt, RefTargetHandle hTarget,
PartID& partID, RefMessage message, BOOL propagate);
int NumSubs();
TSTR SubAnimName(int i);
Animatable* SubAnim(int i);
// TODO: Maintain the number or references here
int NumRefs() { return eNumRefs; }
void DeleteThis() { delete this; }
void Copy(Control* pFrom);
void GetValue(TimeValue t, void *ptr, Interval &valid, GetSetMethod method);
void SetValue(TimeValue t, void *ptr, int commit, GetSetMethod method);
void CommitValue(TimeValue t) { mCtrl->CommitValue(t); }
void RestoreValue(TimeValue t) { mCtrl->RestoreValue(t); }
void SetReference(int i, ReferenceTarget* pTarget);
ReferenceTarget* GetReference(int i);
//Constructor/Destructor
MaxControls();
~MaxControls() { DeleteAllRefs(); };
private:
enum MyRefs {
eCtrlRef,
eNumRefs
};
Control* mCtrl;
};
MaxControls::MaxControls()
{
mCtrl = NULL;
ReplaceReference(eCtrlRef, NewDefaultPositionController());
}
RefResult MaxControls::NotifyRefChanged(const Interval& /*changeInt*/, RefTargetHandle /*hTarget*/, PartID& /*partID*/, RefMessage /*message*/, BOOL /*propagate*/)
{
return REF_DONTCARE;
}
int MaxControls::NumSubs()
{
return 1;
}
Animatable* MaxControls::SubAnim(int i) {
switch (i)
{
case eCtrlRef: return mCtrl;
}
return NULL;
}
void MaxControls::Copy(Control* pFrom)
{
}
void MaxControls::GetValue(TimeValue t, void *ptr, Interval &valid, GetSetMethod method)
{
//We read the values for our Position component from our referenced Point3 controllers
Point3 mat(0, 0, 0);
mCtrl->GetValue(t, &mat, valid, CTRL_RELATIVE);
if (method == CTRL_ABSOLUTE)
{
Point3* p3InVal = (Point3*)ptr;
*p3InVal = mat;
}
else // CTRL_RELATIVE
{
Matrix3* m3InVal = (Matrix3*)ptr;
m3InVal->PreTranslate(mat);
}
}
void MaxControls::SetValue(TimeValue t, void *ptr, int commit, GetSetMethod method)
{
// We set the requested values on our referenced Position controller.
// Max is trying to tell us what our value should be. In turn, we need
// to tell our subanim (our Position controllers) what their value should be.
Point3 *p3Val = (Point3*)ptr;
mCtrl->SetValue(t, &p3Val, commit, CTRL_RELATIVE);
}
TSTR MaxControls::SubAnimName(int i)
{
switch (i)
{
case eCtrlRef: return _T("Controls");
}
return _T("Unknown!");
}
void MaxControls::SetReference(int i, ReferenceTarget* pTarget)
{
switch (i)
{
case eCtrlRef: mCtrl = (Control*)pTarget; break;
}
}
ReferenceTarget* MaxControls::GetReference(int i)
{
switch (i)
{
case eCtrlRef: return mCtrl;
}
return NULL;
}
class MaxControlsClassDesc : public ClassDesc2
{
public:
int IsPublic() { return TRUE; }
void* Create(BOOL /*loading = FALSE*/) { return new MaxControls(); }
const TCHAR * ClassName() { return GetString(IDS_CLASS_NAME); }
SClass_ID SuperClassID() { return CTRL_MATRIX3_CLASS_ID; }
Class_ID ClassID() { return MaxControls_CLASS_ID; }
const TCHAR* Category() { return GetString(IDS_CATEGORY); }
};
ClassDesc2* GetMaxControlsDesc() {
static MaxControlsClassDesc MaxControlsDesc;
return &MaxControlsDesc;
}