⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cvinstnc.h

📁 Windows上的MUD客户端程序
💻 H
📖 第 1 页 / 共 3 页
字号:
/*----------------------------------------------------------------------------
                        _                              _ _       
        /\             | |                            | (_)      
       /  \   _ __   __| |_ __ ___  _ __ ___   ___  __| |_  __ _ 
      / /\ \ | '_ \ / _` | '__/ _ \| '_ ` _ \ / _ \/ _` | |/ _` |
     / ____ \| | | | (_| | | | (_) | | | | | |  __/ (_| | | (_| |
    /_/    \_\_| |_|\__,_|_|  \___/|_| |_| |_|\___|\__,_|_|\__,_|

    The contents of this file are subject to the Andromedia Public
	License Version 1.0 (the "License"); you may not use this file
	except in compliance with the License. You may obtain a copy of
	the License at http://www.andromedia.com/APL/

    Software distributed under the License is distributed on an
	"AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
	implied. See the License for the specific language governing
	rights and limitations under the License.

    The Original Code is Pueblo client code, released November 4, 1998.

    The Initial Developer of the Original Code is Andromedia Incorporated.
	Portions created by Andromedia are Copyright (C) 1998 Andromedia
	Incorporated.  All Rights Reserved.

	Andromedia Incorporated                         415.365.6700
	818 Mission Street - 2nd Floor                  415.365.6701 fax
	San Francisco, CA 94103

    Contributor(s):
	--------------------------------------------------------------------------
	   Chaco team:  Dan Greening, Glenn Crocker, Jim Doubek,
	                Coyote Lussier, Pritham Shetty.

					Wrote and designed original codebase.

------------------------------------------------------------------------------

	Declaration for the ChRenderContext and ChQvRenderData classes and derivations, 
	which are used to store renderer specific data for 3d graphics renderers for contexts
	and in QvNodes. 

----------------------------------------------------------------------------*/

// $Header: /home/cvs/chaco/modules/client/msw/ChGraphx/CvInstnc.h,v 2.30 1996/06/30 19:44:17 jimd Exp $
//
#if !defined( _CHINSTNC_H )
#define _CHINSTNC_H

#include "ChGrRend.h"

#include <ChGraphx.h>
#include "ChGrType.h"
#include "QvNodes.h"
#include "QvState.h"
#include "GxTrnsfm.h"

#if (defined(CH_USE_RLAB) || defined(CH_USE_D3D)) && defined(CH_IMMED_MODE)
#include <imode.h>
#endif

/*
	Classes defined elsewhere 
*/
class ChRenderContext;
class ChQvState;
class ChQvRenderData;
class ChQvRenderBaseData;
class ChQvTextureRenderData;
class ChQvBounds;
class ChQvBuildState;
class ChColorA;

/*
	Forward declarations of classes 
*/
class ChQvInstanceIterator;
class ChQvGroupInstance;
class ChBoundsIterator;
class ChQvInstance;
class ChQvTransformationInstance;
class ChDrawIterator;
class ChConstructionIterator;
class ChHittestIterator;
class ChCollisionIterator;

class ChPipeline	 
{
	public:
	ChPipeline() {};
	virtual ChPipeline::~ChPipeline() {};
	ChPipeline(GxTransform3Wf &model, GxTransform3Wf &world2Cam, GxTransform3Wf &cam2Clip, GxTransform3Wf &clip2Screen)
	{
		Set(model, world2Cam, cam2Clip, clip2Screen);
	}
	ChPipeline * Set(GxTransform3Wf &model, GxTransform3Wf &world2Cam, GxTransform3Wf &cam2Clip, GxTransform3Wf &clip2Screen);
	GxVec3f TransformToScreen(GxVec3f& pt);
 	GxVec3f TransformToPort(GxVec3f& pt, bool & boolClipped);

	protected:
		GxTransform3Wf	m_model;
		GxTransform3Wf	m_world2Cam;
		GxTransform3Wf	m_cam2Clip;
		GxTransform3Wf	m_model2Clip;
		GxTransform3Wf	m_clip2Screen;


};

/*----------------------------------------------------------------------------
	ChQvInstance class
----------------------------------------------------------------------------*/
class ChQvInstance
{
 	friend class ChQvInstanceIterator;
	// These should be unnecessary, but MSVC prevents accessing protected virtual
	// functions without them
	friend class ChQvGroupInstance;
	friend class ChQvLODInstance;
	friend class ChQvSeparatorInstance;
	friend class ChQvSwitchInstance;
	friend class ChQvWWWInlineInstance;
	friend class ChQvWWWAnchorInstance;

	public:
		enum nodeFamily	{ group, shape, property, camera, misc };	// ???
		//enum nodeType
	protected:

	public:
		ChQvInstance();
		virtual ~ChQvInstance();

		virtual bool Draw(ChRenderContext *pRC, ChDrawIterator *pIterator) {return true;};
		virtual bool Construct(ChRenderContext *pRC, ChConstructionIterator *pIterator) {return true;};
		virtual bool Hittest(ChRenderContext *pRC, ChHittestIterator *pIterator) {return true;};
		virtual bool CollisionTest(ChRenderContext *pRC, ChCollisionIterator *pIterator) {return true;};

		virtual bool GetBounds(ChQvBounds& bounds);
		ChRect GetBoundsExtent(ChRenderContext *pRC, ChQvBounds *pBounds = 0, bool *pboolClipped = 0, bool boolBeGenerous = true);
		bool IsBoundsDirty() { return m_boolBoundsDirty; };
										  

		virtual ChQvInstance* Attach(QvNode *pNode, ChQvBuildState *pState);
		virtual ChQvInstance* SetDirty(bool boolDirty = true)
			{ 
				m_boolBoundsDirty = m_boolRenderDirty = true;
				return this;
			};
		virtual ChQvInstance* SetTransformDirty(bool boolDirty = true) {return this;};

		ChQvGroupInstance *GetParent() { return m_pParent; };
		QvNode *GetNode() {return m_pNode;};
		ChQvInstance* SetTransform(ChQvTransformationInstance	*pTransform);
		virtual GxTransform3Wf&  GetTransform();
		virtual GxTransform3Wf  GetRendererTransform()
			{
				return GxTransform3Wf();
			}
		virtual ChQvTransformationInstance *GetTransformInstance() {return 0;};

		#if (defined(CH_USE_RLAB) || defined(CH_USE_D3D))
		virtual void Build(ChRenderContext *pRC) {};
		virtual  ChNrFrame GetFrame() {return (m_frame ? m_frame : GetParentFrame());};
		ChNrFrame GetParentFrame();
		virtual void CreateFrame();
		bool IsConstructed() {return m_boolConstructed;};
		virtual bool CanCollapse();
		virtual bool Collapse();
		virtual bool Reconstruct(ChRenderContext *pRC) { return false;};
		#endif
		inline ChRenderContext	*GetContext() {return m_pContext;};
		virtual bool SetTexture(ChQvTextureRenderData *pTextureData, ChNrMesh mesh = 0);

		void MarkForRemoval(bool boolDelete = true);
		inline bool IsMarkedForRemoval() {return m_boolDeleteMe;};
		ChQvInstance*  SetRenderData(ChQvRenderBaseData	*pRenderData)
			{
				m_pRenderData = pRenderData; 
				if(!pRenderData) m_pNode = 0;
				return this;
			};
		inline ChQvRenderBaseData* GetRenderData() {return m_pRenderData;};
		virtual string& GetRelativeURL();

		#if 1
		virtual void Use(bool boolChildren = true, chuint32 iBump = 1);
		virtual void Release(bool boolChildren = true, chuint32 iBump = 1);
		inline int GetUsage() { return m_iUsage; };
		#endif

		void InstallScripts();
		virtual void RemoveProperty(ChQvRenderBaseData *pData) {};
		ChRenderContext * GetRC() {return m_pContext;};

	protected:
		ChQvRenderBaseData	*m_pRenderData;
		QvNode 			*m_pNode;
		bool			m_boolBoundsDirty;
		bool			m_boolRenderDirty;
		ChQvBounds		*m_pBounds;
		#if (defined(CH_USE_RLAB) || defined(CH_USE_D3D))
		ChNrFrame 		m_frame;
		bool			m_boolConstructed;
		#endif
		ChRenderContext	*m_pContext;

		bool			m_boolDeleteMe;

		int				m_iUsage;

		// Traversal state

		// matrix
		ChQvTransformationInstance	*m_pTransform;		  // Model to world

		ChQvGroupInstance *m_pParent;

		virtual void Init(ChQvBuildState *pState);
		virtual void Term();
		virtual bool ComputeBounds();
		virtual int Iterate(ChQvInstanceIterator *pIterator);
		GxVec3f Transform(const GxVec3f& v);
		GxVec3f TransformWorldToModel(const GxVec3f& v);
		ChQvInstance * GetPipeline(ChRenderContext *pRC, ChPipeline &pipeline);
		ChQvInstance * SetParent(ChQvGroupInstance *pParent) {m_pParent = pParent; return this;};
};

class ChQvInstanceHasProps
{

	public:
		ChQvInstanceHasProps() {};
		virtual ~ChQvInstanceHasProps() {}


		inline QvMaterial 			*GetMaterial() { return m_pMaterial;};
		inline QvMaterialBinding 	*GetMaterialBinding() { return m_pMaterialBinding;};
		inline QvNormal 			*GetNormal() { return m_pNormal;};
		inline QvNormalBinding 		*GetNormalBinding() { return m_pNormalBinding;};
		inline QvCoordinate3 		*GetCoordinate3() { return m_pCoordinate3;};
		inline QvTexture2 			*GetTexture2() { return m_pTexture2;};
		inline QvTexture2Transform 	*GetTexture2Transform() { return m_pTexture2Transform;};
		inline QvTextureCoordinate2 *GetTextureCoordinate2() { return m_pTextureCoordinate2;};
		inline QvShapeHints 		*GetShapeHints() { return m_pShapeHints;};
		inline QvInfo 				*GetInfo() { return m_pInfo;};
		inline QvFontStyle 			*GetFontStyle() { return m_pFontStyle;};

		void RemoveProperty(ChQvRenderBaseData *pData);
		void RemoveProperty(ChQvRenderBaseData *pData, QvNode **pNode);

	protected:
		virtual void Init(ChQvBuildState *pState, ChQvInstance *pInstance);
		virtual void Term(ChQvInstance *pInstance);

		QvMaterial 				*m_pMaterial;
		QvMaterialBinding 		*m_pMaterialBinding;
		QvNormal 				*m_pNormal;
		QvNormalBinding 		*m_pNormalBinding;
		QvCoordinate3 			*m_pCoordinate3;
		QvTexture2 				*m_pTexture2;
		QvTexture2Transform 	*m_pTexture2Transform;
		QvTextureCoordinate2 	*m_pTextureCoordinate2;
		QvShapeHints 			*m_pShapeHints;
		QvInfo					*m_pInfo;
		QvFontStyle 			*m_pFontStyle;
};


class ChQvTransformationInstance:public ChQvInstance
{
	public:
		ChQvTransformationInstance();
		virtual ~ChQvTransformationInstance();
		virtual ChQvInstance* Attach(QvNode *pNode, ChQvBuildState *pState);
		virtual ChQvInstance* SetTransformDirty(bool boolDirty = true);
		ChQvTransformationInstance* SetTransform(const GxTransform3Wf& modelTransform);
		ChQvTransformationInstance* SetSelfTransform(const GxTransform3Wf& transform);
		virtual GxTransform3Wf&  GetTransform() { return m_ModelTransform;};
		ChQvTransformationInstance * AddDependent(ChQvInstance *pDependent);
		ChQvTransformationInstance * RemoveDependent(ChQvInstance *pDependent);

		ChQvTransformationInstance* Attach(QvNode *pNode, ChQvBuildState *pState, ChQvGroupInstance *pOwner);


	protected:

		ChPtrList<ChQvInstance>	m_dependents;
		GxTransform3Wf	m_ModelTransform;		  // Model to world
		GxTransform3Wf	m_SelfTransform;		  // Own matrix transform
		virtual void Init(ChQvBuildState *pState);
		ChQvTransformationInstance * m_pPredecessor;	// Who we depend on
};

typedef ChQvTransformationInstance ChQvTransformInstance;
typedef ChQvTransformationInstance ChQvRotationInstance;
typedef ChQvTransformationInstance ChQvScaleInstance;
typedef ChQvTransformationInstance ChQvTranslationInstance;
typedef ChQvTransformationInstance ChQvMatrixTransformInstance;


class ChQvGroupInstance:public ChQvInstance, public ChQvInstanceHasProps
{
	friend class ChQvInstanceIterator;

	public:
		ChQvGroupInstance();
		virtual ~ChQvGroupInstance();

		ChQvGroupInstance * Add(ChQvInstance *pChild);
		bool  Remove(ChQvInstance *pChild);
		#if (defined(CH_USE_RLAB) || defined(CH_USE_D3D))
		virtual void CreateFrame();
		virtual void Build(ChRenderContext *pRC);
		virtual bool Draw(ChRenderContext *pRC, ChDrawIterator *pIterator);
		virtual bool Construct(ChRenderContext *pRC, ChConstructionIterator *pIterator);
		#endif
		virtual ChQvGroupInstance *SetupTraversalState(ChQvState &state);
		void MarkChildForRemoval(QvNode *pNode);
		inline bool HasChildrenMarkedForRemoval() {return m_boolChildPendingRemoval;};
		void RemoveMarkedChildren();
		#if 1
		virtual void Use(bool boolChildren = true, chuint32 iBump = 1);
		virtual void Release(bool boolChildren = true, chuint32 iBump = 1);
		#endif
		ChQvInstance* GetChild( int iChild);
		virtual ChQvTransformationInstance *GetTransformInstance() {return &m_transformInstance;};
		virtual ChQvInstance* Attach(QvNode *pNode, ChQvBuildState *pState);
		virtual void RemoveProperty(ChQvRenderBaseData *pData)
			{
				ChQvInstanceHasProps::RemoveProperty(pData);
			};

	protected:
		virtual void Init(ChQvBuildState *pState);
		void RestoreProp(ChQvState &state, QvNode *pProp, QvState::StackIndex stackIndex);
		ChQvInstance * InstantiateChild(QvNode *pNewChild);


	protected:
		ChPtrList<ChQvInstance>	m_children;
		virtual bool Iterate(ChQvInstanceIterator *pIterator);

		bool m_boolChildPendingRemoval;
		ChQvTransformationInstance	m_transformInstance;
};

// Iterate over children
class ChQvInstanceIterator
{
	public:
		enum iterationType {inDrawScope, all};
		enum whenVisiting {beforeChildren, afterChildren, isLeaf};
	public:
		ChQvInstanceIterator(ChRenderContext * pContext);
		ChQvInstanceIterator(ChRenderContext * pContext, ChQvInstance *pRoot );

		virtual ~ChQvInstanceIterator();

		virtual void Attach( ChQvInstance *pInst );
		virtual bool Iterate();	   // Just those in draw scope; respects lods,etc.
		virtual bool IterateAll();  // Exhaustive iteration

		virtual int DoNode(ChQvInstance& inst) {return true;};
		iterationType GetIterationType() { return m_type;};
		whenVisiting GetVisitType() { return m_visitType; };
		ChQvInstanceIterator* SetVisitType(whenVisiting visitType) {m_visitType = visitType;return this; };
		ChRenderContext * GetRenderContext() {return m_pContext;};
		bool ShouldDoKids() { return m_boolDoKids; };
		void SetDoKids(bool boolDoEm = true) { m_boolDoKids = boolDoEm; };

   protected:
		iterationType m_type;
		ChQvInstance* m_pRoot;
		whenVisiting m_visitType;
   		ChRenderContext * m_pContext;
		bool		m_boolDoKids;

   private:
											/* Disable copy constructor and
												assignment operator */

      inline ChQvInstanceIterator( const ChQvInstanceIterator& ) {}
      inline ChQvInstanceIterator& operator=( const ChQvInstanceIterator& )
      			{
      				return *this;
      			}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -