/**********************************************************************
 *<
	FILE: cvObject.h

	DESCRIPTION:3d Studio plugin class for mw4 collision object data

	CREATED BY: jkyle

	HISTORY:7-22-1999 - Created

 *>	Copyright (c) 1997, All Rights Reserved.
 **********************************************************************/

#ifndef __CVOBJECT__H
#define __CVOBJECT__H

#ifdef STRICT							// Already defined by stdafx,
#undef STRICT							// so we avoid warning linking msg
#endif
#ifdef _MBCS							// The same as above
#undef _MBCS
#endif

#include "AnimationSuite.h"


#pragma pack(push,8)
#include "iparamm.h"

#define CV_MATERIAL 0
#define CV_SIZE 1

class ParamBlock;

struct CvStruct
{
	Stuff::OBB m_localSpaceVolume;
	Stuff::OBB m_worldSpaceVolume;
	BYTE	m_material;
};

class CvObject;

class CvObjectCreateCallBack: public CreateMouseCallBack 
{
	public:
		int proc( ViewExp *vpt,int msg, int point, int flags, IPoint2 m, Matrix3& mat );
		void SetObj(CvObject *obj) { m_ob = obj; }
    protected:
	    Point3 m_p0, m_p1;
	    CvObject *m_ob;
};


class CvObject : public HelperObject 
{
private:
//	void CalcLocalBoundBox(int,ViewExp *vpt,Box3& box);
//	void CalcOBBChildren(INode *);
	public:		
		static HWND m_hParams;
		static IObjParam *m_iObjParams;
		static IParamMap *m_pmapParam;

    protected:
		IParamBlock *m_pblock;
		BOOL m_suspendSnap;
		int m_extDispFlags;

    public:
		CvObject();
        ~CvObject() {};
		
		void BeginEditParams( IObjParam *ip, ULONG flags,Animatable *prev);
		void EndEditParams( IObjParam *ip, ULONG flags,Animatable *next);

        IParamArray *GetParamBlock() { return m_pblock; }
        ParamDimension *GetParameterDim(int pbIndex) { return stdNormalizedDim; }

		void InitNodeName(TSTR& s) { s = GetString(IDS_DB_CVOBJECT); }

		ObjectState Eval(TimeValue time);
		CreateMouseCallBack* GetCreateMouseCallBack();


		ObjectHandle ApplyTransform(Matrix3& matrix) {return this;}
		Interval ObjectValidity(TimeValue t) {return FOREVER;}
		int CanConvertToType(Class_ID obtype) {return FALSE;}
		Object* ConvertToType(TimeValue t, Class_ID obtype) {assert(0);return NULL;}		
		int DoOwnSelectHilite()	{ return 1; }


		int HitTest(TimeValue t, INode* inode, int type, int crossing, int flags, IPoint2 *p, ViewExp *vpt);
		void Snap(TimeValue t, INode* inode, SnapInfo *snap, IPoint2 *p, ViewExp *vpt);
		void SetExtendedDisplay(int flags);
		int Display(TimeValue t, INode* inode, ViewExp *vpt, int flags);
		void GetWorldBoundBox(TimeValue t, INode *mat, ViewExp *vpt, Box3& box );
		void GetLocalBoundBox(TimeValue t, INode *mat, ViewExp *vpt, Box3& box );

		static void DrawAxis(ViewExp *vpt, const Matrix3 &tm, float length, BOOL sel=FALSE, BOOL frozen=FALSE);
		static Box3 GetAxisBox(ViewExp *vpt, const Matrix3 &tm,Point3 box,int resetTM);
		static void DrawBox(GraphicsWindow *gw, Box3 &box);

		// Animatable methods
		void DeleteThis() { delete this; }
		Class_ID ClassID() { return CVOBJECT_CLASS_ID; }  
		void GetClassName(TSTR& s) { s = TSTR(GetString(IDS_DB_CV_HELPER)); }
		int IsKeyable(){ return 1;}

		// This method returns the number of sub-anims this plug-in
		// has.  Is has one, the parameter block.
		int NumSubs()  { return 1; }
		// This methods returns the ith sub-anim (parameter)
		Animatable* SubAnim(int i);
		// This method returns the name of the ith sub-anim.
		TSTR SubAnimName(int i);


	
		// From ref
		// reference the parameter block and the helper
		int NumRefs() { return 1;};
		// This method returns the ith reference.
		RefTargetHandle GetReference(int i);
		// This method sets the ith reference to the target passed.
		void SetReference(int i, RefTargetHandle rtarg);

		// This method recieves the change notification methods
		RefResult NotifyRefChanged(Interval, RefTargetHandle, PartID&, RefMessage);

		RefTargetHandle Clone(RemapDir& remap = NoRemap());
		IOResult Load(ILoad *iload);
		IOResult Save(ISave *isave);

        friend CvObjectCreateCallBack;

};

#pragma pack(pop)

#endif // __CVOBJECT__H
