//=============================================================================
//
// Copyright 1998 by Captivation Digital Laboratories, Inc.
// All Rights Reserved.
//
//=============================================================================
//
//  CKMNode:  Captivation Kamui Model node.  This is the basic model type
//   for KRAD.
//   Derives from SceneNode.  See Scene3d.h.
//
//=============================================================================
//-----------------------------------------------------------------------------
// $Revision: 1 $
// $NoKeywords: $
//=============================================================================

#ifndef _CKMNODE_H_
#define _CKMNODE_H_

#include "krad.h"
#include "scene3d.h"
#include "kppverts.h"


///////////////
//
// KAnyVertexPtr - ptr to any kamui vertex
//
//////////////
typedef union
{
	KMVERTEX0      *mV0;
	KMVERTEX1      *mV1;
	KMVERTEX2      *mV2;
	KMVERTEX3      *mV3;
	KMVERTEX4      *mV4;
	KMVERTEX5      *mV5;
	KMVERTEX6      *mV6;
	KMVERTEX7      *mV7;
	KMVERTEX8      *mV8;
	KMVERTEX9      *mV9;
	KMVERTEX10     *mV10;
	KMVERTEX11     *mV11;
	KMVERTEX12     *mV12;
	KMVERTEX13     *mV13;
	KMVERTEX14     *mV14;
	KMVERTEX15     *mV15;
	KMVERTEX16     *mV16;
	KMVERTEX17     *mV17;
	void           *mVoid;      // kmSetVertex takes void pointer
	BYTE           *mByte;      // for copying lists
} KAnyVertexPtr;


//=============================================================================
//
//  KVertexContextGroup
//
//		This is a list of triangles and the vertex context with which
//  the list is associated.
//
//-----------------------------------------------------------------------------
// USAGE:
//
//
//-----------------------------------------------------------------------------
class  KVertexContextGroup
{
private:
	KVContext         mVertexContext;

	// these next 3 are parameters to the function kmSetVertex()..
public: // fix!! make private!!
	KAnyVertexPtr     mVertexArray;    // start of vertex array
	KMVERTEXTYPE      mType;           // type of vertex
	KMINT32           mStripSize;      // mNumVerts * size of 1 vertex

	const long       *mVertexIndexes;  // releates mVertexArray members to
	                                   //  their corresponding mesh verts

public:
	KVertexContextGroup();
	~KVertexContextGroup();

	inline void       mSetVertIndexes(const long *vertInds) { mVertexIndexes = vertInds; };
	inline KVContext &mGetVertexContext(void) { return mVertexContext; };
	void              mAllocateVerts(int num, KMVERTEXTYPE type);

	inline void       mSet(void) { mVertexContext.Set(); };
	inline void       mRegisterVerts(void) { KAMUI_TRY(KAMUI_SET_VERTEX(mVertexArray.mVoid, mType, mStripSize)); };

	void              mSetVertListEnd(long vNum) { mVertexArray.mV0[vNum].ParamControlWord = KM_VERTEXPARAM_ENDOFSTRIP; };

};

//=============================================================================
//============================================================================= CLASS SceneNode
//=============================================================================
//
//  KCKMNode is the general 3-d model SceneNode type.
//
//-----------------------------------------------------------------------------
// USAGE:
//
//
//-----------------------------------------------------------------------------

class KCKMNode : public SceneNode
{
protected:
	// array vertex context groups: (these contain the triangle strips which
	//  we draw and their corresponding vertex contexts..)
	long                 mNumVCGroups;
	KVertexContextGroup *mVCGroups;

	long                 mNumVerts;     // num elements in mMeshVerts
//	const vec3          *mSrcMeshVerts; // pointer to untransformed mesh verts
	vec3          *mSrcMeshVerts; // pointer to untransformed mesh verts
	KDynVertex          *mMeshVerts;    // pointer to transformed mesh verts

public:
	KCKMNode			(NODE_DELETE_STYLE ndel, SceneNode* parent);
	virtual ~KCKMNode();

	virtual void		EvaluateState					(void);
	virtual void		TransformAndRegisterTristrips	(mat4* m, NODE_LIST_BITS lbits);

};

#endif  // Headerfile Guard