📄 chrenderdata.cpp
字号:
/*----------------------------------------------------------------------------
_ _ _
/\ | | | (_)
/ \ _ __ __| |_ __ ___ _ __ ___ ___ __| |_ __ _
/ /\ \ | '_ \ / _` | '__/ _ \| '_ ` _ \ / _ \/ _` | |/ _` |
/ ____ \| | | | (_| | | | (_) | | | | | | __/ (_| | | (_| |
/_/ \_\_| |_|\__,_|_| \___/|_| |_| |_|\___|\__,_|_|\__,_|
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 ChRenderContext class for Intel 3DR.
----------------------------------------------------------------------------*/
// $Header: /home/cvs/chaco/modules/client/msw/ChGraphx/ChRenderData.cpp,v 2.30 1996/08/22 22:45:14 jimd Exp $
#include "grheader.h"
#include <QvInfo.h>
#include <QvState.h>
#include "ChMaze.h"
#include "ChRenderData.h"
#include "ChScriptData.h"
#include "ChMazDep.h"
#include "CvConvrt.h"
#include "CvTrnsfm.h"
#include "CvNormal.h"
#include "CvInstnc.h"
#include "CvType.h"
#include "CvHitTst.h"
#include "ChSphere.h"
#include "ChRLImg.h"
#include <ChSFImage.h>
#include "ChQvPars.h"
#include <ChCore.h>
#include <ChUtil.h>
#include <QvChildList.h>
// Statics
// Be sure to Term all these classes in ChQvRenderBaseData::Term()
ChQvRenderBaseData::ChVrmlDispatcher *ChQvTransformationRenderData::m_pDispatcher = 0;
ChQvRenderBaseData::ChVrmlDispatcher *ChQvGroupRenderData::m_pDispatcher = 0;
ChQvRenderBaseData::ChVrmlDispatcher *ChQvSwitchRenderData::m_pDispatcher = 0;
ChQvRenderBaseData::ChVrmlDispatcher *ChQvSpinGroupRenderData::m_pDispatcher = 0;
ChQvRenderBaseData::ChVrmlDispatcher *ChQvPCameraRenderData::m_pDispatcher = 0;
// Base Render Data
ChQvRenderBaseData::~ChQvRenderBaseData()
{
while(!m_instances.IsEmpty())
{
ChQvInstance *pInstance = m_instances.RemoveHead();
pInstance->SetRenderData(0);
}
// Also need to get rid of dependents!!!!!!!!
while(!m_dependents.IsEmpty())
{
ChQvInstance *pInstance = m_dependents.RemoveHead();
pInstance->RemoveProperty(this);
}
};
ChQvRenderBaseData *ChQvRenderBaseData::Attach(QvNode *pNode)
{
m_pNode = pNode;
return this;
}
ChQvRenderBaseData *ChQvRenderBaseData::Add(ChQvInstance *pInstance)
{
m_instances.AddTail(pInstance);
return this;
}
ChQvRenderBaseData *ChQvRenderBaseData::Remove(ChQvInstance *pInstance)
{
if(m_instances.IsEmpty()) return this;
ChPosition pos = m_instances.Find(pInstance);
if(pos)
{
m_instances.Remove(pos);
}
return (this);
}
ChQvRenderBaseData *ChQvRenderBaseData::AddDependent(ChQvInstance *pInstance)
{
m_dependents.AddTail(pInstance);
return this;
}
bool ChQvRenderBaseData::RemoveDependent(ChQvInstance *pInstance)
{
if(m_dependents.IsEmpty()) return false;
ChPosition pos = m_dependents.Find(pInstance);
if(pos)
{
m_dependents.Remove(pos);
}
return (pos != 0);
}
bool ChQvRenderBaseData::DispatchEvent(ChRenderContext *pRC, ChApplet * pApplet, ChIVrmlEvent *pEvent)
{
#if defined(CH_VRML_EVENTS)
ChVrmlDispatcher *pDisp = GetDispatcher();
if(pDisp)
{
ChEventDispatch *pDispDesc = pDisp->Find(pEvent->GetName());
if(pDispDesc)
{
return ((this->*(pDispDesc->m_handler))(pRC, pApplet, pEvent));
}
}
// Not handled yet, so we'll try routing directly to the field
QvField *fld = 0;
LPCTSTR strEvent = pEvent->GetName();
if(QvRoute::findConnection(GetNode(), strEvent, fld, true))
{
// Need some serious type checking here TODO !!!!!!!!!!!!
if(fld->getType() == pEvent->GetFieldType())
{
if(pEvent->IsMultiple() && pEvent->GetCount())
{
((QvMField*)fld)->setValues(pEvent->GetBytes(), 0, pEvent->GetCount());
}
else
{
((QvSField*)fld)->setValue(pEvent->GetBytes());
SetDirty(true);
}
}
else
{
// Post an error!! TODO!!!!
string * pMsg = new string( "Error : Attempt to attach - field type mismatch" );
// The merssage string is deleted by the message handler
((ChMazeWnd*)pRC->GetWnd())->PostMessage( WM_VRML_MAZE_ERROR,
CH_MAZE_ROUTE_ERROR_FIELD_MISMATCH,
(LPARAM)pMsg );
}
}
else
{
string * pMsg = new string( "Error : Invalid event name" );
// The merssage string is deleted by the message handler
((ChMazeWnd*)pRC->GetWnd())->PostMessage( WM_VRML_MAZE_ERROR,
CH_MAZE_ROUTE_ERROR_EVENT_NOTFOUND,
(LPARAM)pMsg );
}
#endif
return false;
};
void ChQvRenderBaseData::PurgeQv()
{
QvNode* pNode = m_pNode;
ChQvPurgeState state(0);
pNode->traverse(&state);
}
int ChQvRenderBaseData::GetInstanceCount()
{
return m_instances.GetCount();
}
ChQvRenderBaseData *ChQvRenderBaseData::Add(ChQvScriptRenderData *pScript)
{
ASSERT(pScript);
if(m_scripts.IsEmpty() || !(m_scripts.Find(pScript)))
{ // No Dupes!
m_scripts.AddTail(pScript);
// Now add our instances to the script
if (!m_instances.IsEmpty())
{
ChPosition pos = m_instances.GetHeadPosition();
while(pos)
{
ChQvInstance *pInst = m_instances.GetNext(pos);
if(pInst) pScript->AddInstance(pInst);
}
}
}
return this;
}
ChQvRenderBaseData *ChQvRenderBaseData::Remove(ChQvScriptRenderData *pScript)
{
if(m_scripts.IsEmpty()) return this;
ChPosition pos = m_scripts.Find(pScript);
if(pos)
{
m_scripts.Remove(pos);
}
return (this);
}
#if 0
class MyBaseDirtyIterator : public ChQvRenderBaseDataIterator
{
public:
MyBaseDirtyIterator( const ChQvRenderBaseData& rbd ) : ChQvRenderBaseDataIterator(rbd) {};
virtual int DoInstance(ChQvInstance& inst)
{
inst.SetDirty(true);
return true;
};
protected:
private:
/* Disable copy constructor and
assignment operator */
inline MyBaseDirtyIterator( const MyTransformDirtyIterator& ) {}
inline MyBaseDirtyIterator& operator=( const MyTransformDirtyIterator& )
{
return *this;
}
};
#endif
void ChQvRenderBaseData::SetDirty(bool boolDirty)
{
ChQvRenderData::SetDirty(boolDirty);
// nada for now, use the iterator later when we handle things other than transforms
}
/* Standard ABC Instance Iterator for base data */
ChQvRenderBaseDataIterator::ChQvRenderBaseDataIterator()
{
}
ChQvRenderBaseDataIterator::ChQvRenderBaseDataIterator( const ChQvRenderBaseData& rbd )
{
Attach((ChQvRenderBaseData&)rbd);
}
ChQvRenderBaseDataIterator::~ChQvRenderBaseDataIterator()
{
}
void ChQvRenderBaseDataIterator::Attach( ChQvRenderBaseData& rbd )
{
m_pData = &rbd;
}
int ChQvRenderBaseDataIterator::Iterate()
{
bool boolKeepGoing = true;
if (!m_pData->m_instances.IsEmpty())
{
ChPosition pos = m_pData->m_instances.GetHeadPosition();
while(pos && boolKeepGoing)
{
ChQvInstance *pInst = m_pData->m_instances.GetNext(pos);
boolKeepGoing = DoInstance(*pInst);
}
}
return boolKeepGoing;
}
int ChQvRenderBaseDataIterator::IterateDependents()
{
bool boolKeepGoing = true;
if (!m_pData->m_dependents.IsEmpty())
{
ChPosition pos = m_pData->m_dependents.GetHeadPosition();
while(pos && boolKeepGoing)
{
ChQvInstance *pInst = m_pData->m_dependents.GetNext(pos);
boolKeepGoing = DoInstance(*pInst);
}
}
return boolKeepGoing;
}
int ChQvRenderBaseDataIterator::IterateScripts()
{
bool boolKeepGoing = true;
if (!m_pData->m_scripts.IsEmpty())
{
ChPosition pos = m_pData->m_scripts.GetHeadPosition();
while(pos && boolKeepGoing)
{
ChQvScriptRenderData *pScript = m_pData->m_scripts.GetNext(pos);
boolKeepGoing = DoScript(*pScript);
}
}
return boolKeepGoing;
}
void ChQvRenderBaseData::Term()
{
ChQvTransformationRenderData::Term();
ChQvGroupRenderData::Term();
ChQvSwitchRenderData::Term();
ChQvSpinGroupRenderData::Term();
ChQvPCameraRenderData::Term();
}
/* Types of render data */
ChQvTransformationRenderData::ChQvTransformationRenderData(QvNode* pNode) :
ChQvRenderBaseData(pNode)
{
#if defined(CH_VRML_EVENTS)
if(!m_pDispatcher)
{
m_pDispatcher = new ChVrmlDispatcher;
Init();
}
#endif
};
void ChQvTransformationRenderData::Init()
{
ChQvRenderBaseData::Init();
#if defined(CH_VRML_EVENTS)
AddVrmlDispatcher("set_rotation", SFRotation, OnSetRotation);
AddVrmlDispatcher("set_translation", SFVec3f, OnSetTranslation);
AddVrmlDispatcher("set_scaleFactor", SFVec3f, OnSetScaleFactor);
AddVrmlDispatcher("set_scaleOrientation", SFRotation, OnSetScaleOrientation);
AddVrmlDispatcher("set_center", SFVec3f, OnSetCenter);
#endif
};
ChQvTransformationRenderData::~ChQvTransformationRenderData()
{
// delete instances - not stored in the instance tree, so we do it here
while(!m_instances.IsEmpty())
{
ChQvInstance *pInstance = m_instances.RemoveHead();
if(pInstance) pInstance->Release();
}
}
void ChQvTransformationRenderData::Term()
{
#if defined(CH_VRML_EVENTS)
delete m_pDispatcher;
m_pDispatcher = 0;
#endif
}
#if (defined(CH_USE_RLAB) || defined(CH_USE_D3D))
#if 1 || defined(CH_VRML_EVENTS)
class MyTransformDirtyIterator: public ChQvRenderBaseDataIterator
{
public:
MyTransformDirtyIterator( const ChQvTransformationRenderData& rbd ) : ChQvRenderBaseDataIterator(rbd) {};
virtual int DoInstance(ChQvInstance& inst)
{
GxTransformF_t mat;
// Needs to get fixed for other transform types
string strType;
switch(inst.GetNode()->GetType(strType))
{
case typeQvRotation:
{
GetTransform((QvRotation*)(inst.GetNode()), mat);
break;
}
case typeQvTransform:
{
GetTransform((QvTransform*)(inst.GetNode()), mat);
break;
}
case typeQvScale:
{
GetTransform((QvScale*)(inst.GetNode()), mat);
break;
}
case typeQvTranslation:
{
GetTransform((QvTranslation*)(inst.GetNode()), mat);
break;
}
case typeQvMatrixTransform:
{
GetTransform((QvMatrixTransform*)(inst.GetNode()), mat);
break;
}
}
ChQvTransformInstance *pInst = (ChQvTransformInstance *)&inst;
pInst->SetSelfTransform(mat);
inst.SetTransformDirty(true);
return true;
};
protected:
private:
/* Disable copy constructor and
assignment operator */
inline MyTransformDirtyIterator( const MyTransformDirtyIterator& ) {}
inline MyTransformDirtyIterator& operator=( const MyTransformDirtyIterator& )
{
return *this;
}
};
#endif
#endif
void ChQvTransformationRenderData::SetDirty(bool boolDirty)
{
#if (defined(CH_USE_RLAB) || defined(CH_USE_D3D))
#if 1 || defined(CH_VRML_EVENTS)
m_boolDirty = boolDirty;
if(boolDirty)
{
MyTransformDirtyIterator iterator(*this);
iterator.Iterate();
}
m_boolDirty = false;
#endif
#endif
}
bool ChQvTransformationRenderData::OnSetRotation(ChRenderContext *pRC, ChApplet * pApplet, ChIVrmlEvent *pEventList)
{
bool boolSuccess = false;
#if defined(CH_VRML_EVENTS)
// Apply based on transform type - eventually this gets merged into
// the containing separator in 2.0 - if we were going to keep this node,
// we'd split out the classes, but for now just hack it
string strType;
float axis[3];
float angle;
ChRotationEvent *pEvent = (ChRotationEvent *)pEventList;
pEvent->GetValue(axis, angle);
QvSFRotation *pRotation = 0;
if(m_pNode->GetType(strType) == typeQvRotation)
{
QvRotation *pNode = (QvRotation *)m_pNode;
pRotation = &(pNode->rotation);
boolSuccess = true;
}
else if(m_pNode->GetType(strType) == typeQvTransform)
{
QvTransform *pNode = (QvTransform *)m_pNode;
pRotation = &(pNode->rotation);
boolSuccess = true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -