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

📄 ch3dtrvs.cpp

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

    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.

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

	Implementation for the traversal of a VRML QV tree into Intel 3DR.

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

#include "grheader.h"


#include <ChCore.h>

#if !defined(CH_VRML_VIEWER) && !defined(CH_VRML_PLUGIN )
#include "ChGrMod.h"
#endif

#if defined( CH_ARCH_16 )
#include <QvElemnt.h> 
#else
#include <QvElement.h> 
#endif
#include <QvNodes.h>
#include <QvState.h>
#ifdef CH_MSW
#if defined( CH_ARCH_16 )
#include <UnknNode.h>
#else
#include <QvUnknownNode.h>
#endif
#include <windows.h>
#endif
#ifdef HUGE
#undef HUGE
#endif
#include <math.h>
#include <strstrea.h>
#include "ChMaze.h"
#include "ChMazDep.h"
#include "ChRender.h"
#include "ChSphere.h"
#include "CvType.h"

#include "CvBound.h"
#include "CvConvrt.h"
#include "CvMaterl.h"
#include "CvInstnc.h"
#include "CvTextur.h"
#include "CvQuery.h"
#include "CvTrnsfm.h"
#include "CvNormal.h"
#include "ChScriptData.h"

#include <QvChildList.h>

#define CH_WANT_TEXTURED_BACKGROUNDS	1

//////////////////////////////////////////////////////////////////////////////
//
// Traversal code for all nodes for Intel 3dr and Reality Lab. 
// The default method (in QvNode) does
// nothing. Because traverse() is defined in the header for ALL node
// classes, each one has an implementation here.
//
//////////////////////////////////////////////////////////////////////////////



// Standard invalidate for nodes - virtual 
void QvNode::Invalidate(ChRenderContext *pRC)
{
	pRC->SetDirty()->GetWnd()->InvalidateRect(0, 0);
}
    
#if defined( NO_TEMPLATES )    

#else
// Node editing functions

template <class aType>
void swap(aType& a, aType& b)
{
	aType tmp;
	tmp = a;
	a = b;
	b = tmp;
}     
#endif

#define DEFAULT_EDIT_NODE(className)	\
void									\
EditNode(className *a, className *b)      \
{									      \
}

void EditNode(QvPerspectiveCamera *pNode, QvPerspectiveCamera *src)
{
	pNode->position			= src->position;
	pNode->orientation		= src->orientation;
	pNode->focalDistance	= src->focalDistance;
	pNode->heightAngle		= src->heightAngle;

	if(pNode->GetRenderData()) pNode->GetRenderData()->SetDirty();
}

void EditNode(QvOrthographicCamera *pNode, QvOrthographicCamera *src)
{
	pNode->position			= src->position;
	pNode->orientation		= src->orientation;
	pNode->focalDistance	= src->focalDistance;
	pNode->height			= src->height;

	if(pNode->GetRenderData()) pNode->GetRenderData()->SetDirty();
}

class ChQvTransformEditIterator : public ChQvRenderBaseDataIterator
{
	public:
		ChQvTransformEditIterator(ChQvRenderBaseData &data, const GxTransform3Wf& transform); 
		virtual bool DoInstance(ChQvInstance &instance);
	protected:
		GxTransform3Wf m_mat;
};

ChQvTransformEditIterator::ChQvTransformEditIterator(ChQvRenderBaseData &data, const GxTransform3Wf& transform) :
	   ChQvRenderBaseDataIterator(data), m_mat(transform)
{
};

bool ChQvTransformEditIterator::DoInstance(ChQvInstance &instance)
{
	ChQvTransformationInstance *pInstance = (ChQvTransformationInstance *)&instance;
	pInstance->SetSelfTransform(m_mat);
	instance.SetTransformDirty();
	return true;
};

void EditNode(QvTransform *pNode, QvTransform *src)
{
	pNode->center= src->center;
	pNode->scaleOrientation= src->scaleOrientation;
	pNode->scaleFactor= src->scaleFactor;
	pNode->rotation= src->rotation;
	pNode->translation= src->translation;

	GxTransformF_t mat;
	GetTransform(pNode, mat);
	ChQvRenderBaseData * pData =  (ChQvRenderBaseData *)(pNode->GetRenderData());
	ChQvTransformEditIterator iterator(*pData, mat);
	iterator.Iterate();
}
void EditNode(QvRotation *pNode, QvRotation *src)
{
	pNode->rotation = src->rotation;

	GxTransformF_t mat;
	GetTransform(pNode, mat);
	ChQvRenderBaseData * pData =  (ChQvRenderBaseData *)(pNode->GetRenderData());
	ChQvTransformEditIterator iterator(*pData, mat);
	iterator.Iterate();
}
void EditNode(QvMatrixTransform *pNode, QvMatrixTransform *src)
{
	pNode->matrix = src->matrix;

	GxTransformF_t mat;
	GetTransform(pNode, mat);
	ChQvRenderBaseData * pData =  (ChQvRenderBaseData *)(pNode->GetRenderData());
	ChQvTransformEditIterator iterator(*pData, mat);
	iterator.Iterate();
}
void EditNode(QvTranslation *pNode, QvTranslation *src)
{
	pNode->translation = src->translation;

	GxTransformF_t mat;
	GetTransform(pNode, mat);
	ChQvRenderBaseData * pData =  (ChQvRenderBaseData *)(pNode->GetRenderData());
	ChQvTransformEditIterator iterator(*pData, mat);
	iterator.Iterate();
}
void EditNode(QvScale *pNode, QvScale *src)
{
	pNode->scaleFactor =  src->scaleFactor;

	GxTransformF_t mat;
	GetTransform(pNode, mat);
	ChQvRenderBaseData * pData =  (ChQvRenderBaseData *)(pNode->GetRenderData());
	ChQvTransformEditIterator iterator(*pData, mat);
	iterator.Iterate();
}    
void EditNode(QvSwitch *pNode, QvSwitch *src)
{
	pNode->whichChild =  src->whichChild;
}    

#if defined( NO_TEMPLATES )
bool DoNodeEditCommand(QvPerspectiveCamera *pNode, QvState *qstate)
{
	bool boolSubed = false;
	ChQvState * state = (ChQvState *)qstate;

	if(state->GetType() == ChQvState::editNode)
	{
		{
			if(	pNode->getName() == state->GetNode()->getName())
			{

				EditNode(pNode,(QvPerspectiveCamera*)(state->GetNode())); 
				// persp camera only
				state->SetCmdDone( true);
				boolSubed = true;
			}
		}
	}
	return boolSubed;		// we did not do substitiution
}   


bool DoNodeEditCommand(QvTransform *pNode, QvState *qstate)
{
	bool boolSubed = false;
	ChQvState * state = (ChQvState *)qstate;

	if(state->GetType() == ChQvState::editNode)
	{
		{
			if(	pNode->getName() == state->GetNode()->getName())
			{

				EditNode(pNode,(QvTransform*)(state->GetNode())); 
				// persp camera only
				state->SetCmdDone( true);
				boolSubed = true;
			}
		}
	}
	return boolSubed;		// we did not do substitiution
}    
bool DoNodeEditCommand(QvRotation *pNode, QvState *qstate)
{
	bool boolSubed = false;
	ChQvState * state = (ChQvState *)qstate;

	if(state->GetType() == ChQvState::editNode)
	{
		{
			if(	pNode->getName() == state->GetNode()->getName())
			{

				EditNode(pNode,(QvRotation*)(state->GetNode())); 
				// persp camera only
				state->SetCmdDone( true);
				boolSubed = true;
			}
		}
	}
	return boolSubed;		// we did not do substitiution
}    
bool DoNodeEditCommand(QvMatrixTransform *pNode, QvState *qstate)
{
	bool boolSubed = false;
	ChQvState * state = (ChQvState *)qstate;

	if(state->GetType() == ChQvState::editNode)
	{
		{
			if(	pNode->getName() == state->GetNode()->getName())
			{

				EditNode(pNode,(QvMatrixTransform*)(state->GetNode())); 
				// persp camera only
				state->SetCmdDone( true);
				boolSubed = true;
			}
		}
	}
	return boolSubed;		// we did not do substitiution
}    
bool DoNodeEditCommand(QvTranslation *pNode, QvState *qstate)
{
	bool boolSubed = false;
	ChQvState * state = (ChQvState *)qstate;

	if(state->GetType() == ChQvState::editNode)
	{
		{
			if(	pNode->getName() == state->GetNode()->getName())
			{

				EditNode(pNode,(QvTranslation*)(state->GetNode())); 
				// persp camera only
				state->SetCmdDone( true);
				boolSubed = true;
			}
		}
	}
	return boolSubed;		// we did not do substitiution
}    

bool DoNodeEditCommand(QvScale *pNode, QvState *qstate)
{
	bool boolSubed = false;
	ChQvState * state = (ChQvState *)qstate;

	if(state->GetType() == ChQvState::editNode)
	{
		{
			if(	pNode->getName() == state->GetNode()->getName())
			{

				EditNode(pNode,(QvScale*)(state->GetNode())); 
				// persp camera only
				state->SetCmdDone( true);
				boolSubed = true;
			}
		}
	}
	return boolSubed;		// we did not do substitiution
}    
 
#else
//
// Change a node to the one in the state command
template <class aType>
bool DoNodeEditCommand(aType *pNode, QvState *qstate)
{
	bool boolSubed = false;
	ChQvState * state = (ChQvState *)qstate;

	if(state->GetType() == ChQvState::editNode)
	{
		{
			if(	pNode->getName() == state->GetNode()->getName())
			{

				EditNode(pNode,(aType*)(state->GetNode())); 
				// persp camera only
				state->SetCmdDone( true);
				boolSubed = true;
			}
		}
	}
	return boolSubed;		// we did not do substitiution
}    
#endif

// Doesn't stop on the first find; Return LAST hit just like DEF works
bool QueryNode( QvNode * pNode, QvState *qvstate)
{
	bool boolIsQuery = false;
	
	ChQvState * qstate = (ChQvState *)qvstate;

	if(qstate->GetType() == ChQvState::queryNode)
	{
		ChQvQueryState * state = (ChQvQueryState *)qvstate;
		boolIsQuery = true;
		if(state->GetQuery()->GetType() == ChQvQuery::byClassName)
		{
			string strClass;
			pNode->GetType(strClass);
			if( strClass ==	state->GetQuery()->GetKey())
			{
				state->GetQuery()->SetResult(pNode);
				state->SetCmdDone( true);
			}
		}
		else
		{
			if(	pNode->getName() == state->GetQuery()->GetKeyNode()->getName())
			{
				state->GetQuery()->SetResult(pNode);
				state->SetCmdDone( true);
			}
		}
	}
	return boolIsQuery;		// we did not do substitiution
}

#define DEFAULT_QUERYNODE(pNode, state)	\
	if(QueryNode( pNode, state )) return;

// For debugging
static int indent = 0;
static void
announce(const char *className)
{
	char buf[500];
    for (int i = 0; i < indent; i++)  sprintf(buf+i,"\t"); 
    sprintf(buf+indent, "Traversing a %s\r\n", className);
	//OutputDebugString(buf);

⌨️ 快捷键说明

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