📄 cvselectors.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 ChQvInstance class for Intel 3DR.
----------------------------------------------------------------------------*/
// $Header: /home/cvs/chaco/modules/client/msw/ChGraphx/CvSelectors.cpp,v 2.6 1996/06/27 03:44:08 jimd Exp $
#include "grheader.h"
#include "CvInstnc.h"
#include <QvInfo.h>
#include <QvState.h>
#include "ChMaze.h"
#include "ChRenderData.h"
#include "ChMazDep.h"
#include "CvTrnsfm.h"
#include "CvNormal.h"
#include "CvBound.h"
#include "CvConvrt.h"
#include "CvHitTst.h"
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
ChQvLODInstance::ChQvLODInstance() : ChQvGroupInstance()
#if (defined(CH_USE_RLAB) || defined(CH_USE_D3D))
, m_pFrames(0)
, m_iCurrentChild(-1)
#endif
{
}
ChQvLODInstance::~ChQvLODInstance()
{
#if (defined(CH_USE_RLAB) || defined(CH_USE_D3D))
delete [] m_pFrames;
m_pFrames = 0;
if(!m_children.IsEmpty())
{
ChPosition pos = m_children.GetHeadPosition();
while(pos)
{
ChQvInstance *pChild = m_children.GetNext(pos);
ChNrFrame frame = pChild->GetFrame();
if (frame) ChNrObjectDestroy(frame);
}
}
#endif
}
#if (defined(CH_USE_RLAB) || defined(CH_USE_D3D))
// Callback to choose child while rendering
#if (defined(CH_USE_RLAB))
void LODFrameCallback(ChNrFrame frame, void * arg)
#else
void LODFrameCallback(ChNrFrame frame, void * arg, float delta)
#endif
{
ChQvLODInstance *pInst = (ChQvLODInstance *)arg;
pInst->PickAChild();
}
void ChQvLODInstance::PickAChild()
{
int iChild = LookupChild(m_pContext);
#if 1
if(iChild != m_iCurrentChild)
{
if(m_pFrames[iChild])
{
if(m_iCurrentChild >= 0)
{
ChNrFrameRemoveChild(m_frame, m_pFrames[m_iCurrentChild]);
}
ChNrFrameAddChild(m_frame, m_pFrames[iChild]);
m_iCurrentChild = iChild;
// Now get rid of unwanted stuff - very aggressive here!
//Purge(iChild, 100); // purge all but current and iChild
}
else
{
// Request the new one
// Instantiate the child, then spawn and start construction
QvNode *pChild = ((QvGroup*)GetNode())->getChild(iChild);
ChQvInstance * pChildInst = InstantiateChild(pChild);
// Add the child's new frame to our array, and remove it from us
m_pFrames[iChild] = pChildInst->GetFrame();
ChNrObjectReference(m_pFrames[iChild]);
ChNrFrameRemoveChild(m_frame, m_pFrames[iChild]);
// Spawn for new requests
ChQvSpawnState state((ChMazeWnd *)(GetContext()->GetWnd()), GetRelativeURL());
//((ChMazeWnd *)(GetContext()->GetWnd()))->GetCurrentURL());
pChild->traverse(&state);
// Now get rid of unwanted stuff
//Purge(iChild, 100); // purge all but current and iChild
}
}
#else
if(!m_children.IsEmpty())
{
if(iChild != m_iCurrentChild)
{
ChNrFrameRemoveChild(m_frame, m_pFrames[m_iCurrentChild]);
ChNrFrameAddChild(m_frame, m_pFrames[iChild]);
m_iCurrentChild = iChild;
}
}
#endif
};
#endif
int ChQvLODInstance::LookupChild(ChRenderContext * pContext)
{
QvLOD *lod = (QvLOD*)GetNode();
int iChild = -1;
// Transform camera from world coords
GxVec3f center, diff;
Qv2Gx(lod->center, center);
//center = Transform(center);
GxVec3f camera = pContext->GetCameraLoc();
camera = TransformWorldToModel(camera);
// compute distance from camera
diff = center;
diff -= camera;
float range = diff.magnitude();
range = pContext->GetAdjustedLODRange(range);
// Lookup in range array
int numKids = lod->getNumChildren();
if(numKids)
{
int numRanges = lod->range.num;
int i;
for( i = 0; i < numRanges; i++)
{
if(range < (lod->range.values[i]))
{
break;
}
}
iChild = min(i, (numKids - 1));
}
return iChild;
}
bool ChQvLODInstance::Purge(int iChildToKeep /* = -1 */, int iHowMuch /* = 100 */)
{
bool boolZapped = false;
#if (defined(CH_USE_RLAB) || defined(CH_USE_D3D))
// Throw away all the child instances except for the currently used
// and currently desired iChild; if iChild is -1, look it up
// It is intended that iHowMuch says how aggressive to be, but not used yet
if(iChildToKeep == -1)
{
iChildToKeep = LookupChild(m_pContext);
}
QvLOD *lod = (QvLOD*)GetNode();
int numKids = lod->getNumChildren();
for(int i = 0; i < numKids; i++)
{
if(i != iChildToKeep && i != m_iCurrentChild)
{
if(m_pFrames[i])
{
if(!m_children.IsEmpty())
{
ChPosition pos = m_children.GetHeadPosition();
while(pos)
{
ChPosition oldPos = pos;
ChQvInstance *pChild = m_children.GetNext(pos);
ChNrFrame frame = pChild->GetFrame();
if(frame == m_pFrames[i])
{
ChQvRenderBaseData * pData = (ChQvRenderBaseData *)pChild->GetNode()->GetRenderData();
m_pFrames[i] = 0;
ChNrObjectDestroy(frame);
#if 1
pChild->Release();
#endif
pData->PurgeQv();
//m_children.Remove(oldPos); this is done by deleting child
boolZapped = true;
break;
}
}
}
}
}
}
#endif
return boolZapped;
}
bool ChQvLODInstance::Iterate(ChQvInstanceIterator *pIterator)
{
if(pIterator->GetIterationType() == ChQvInstanceIterator::inDrawScope)
{
int iChild = LookupChild(pIterator->GetRenderContext());
pIterator->SetVisitType(ChQvInstanceIterator::beforeChildren);
pIterator->SetDoKids(true);
bool boolKeepGoing = pIterator->DoNode(*this);
if(pIterator->ShouldDoKids() && !m_children.IsEmpty() && boolKeepGoing)
{
ChPosition pos = m_children.FindIndex(iChild);
if(!pos)
{
pos = m_children.GetTailPosition();
}
if(pos)
{
pIterator->SetVisitType(ChQvInstanceIterator::isLeaf);
ChQvInstance *pChild = m_children.Get(pos);
boolKeepGoing = pChild->Iterate(pIterator);
}
}
pIterator->SetDoKids(true);
if(boolKeepGoing)
{
pIterator->SetVisitType(ChQvInstanceIterator::afterChildren);
boolKeepGoing = pIterator->DoNode(*this);
}
return boolKeepGoing;
}
else
{
return ChQvGroupInstance::Iterate(pIterator);
}
}
void ChQvLODInstance::SetUpKids(ChRenderContext* pContext)
{
#if (defined(CH_USE_RLAB) || defined(CH_USE_D3D))
QvLOD *pNode = (QvLOD *)GetNode();
int numKids = pNode->getNumChildren();
m_pFrames = new ChNrFrame[numKids];
for(int j = 0; j < numKids; j++) m_pFrames[j] = 0;
pContext->LockScene();
if(!m_children.IsEmpty())
{
int i = 0;
ChPosition pos = m_children.GetHeadPosition();
while(pos)
{
ChQvInstance *pChild = m_children.GetNext(pos);
m_pFrames[i] = pChild->GetFrame();
ChNrObjectReference(m_pFrames[i]);
if(pos) ChNrFrameRemoveChild(m_frame, m_pFrames[i]);
i++;
}
m_iCurrentChild = i - 1;
}
ChNrFrameAddCallback(m_frame, LODFrameCallback, this);
pContext->UnlockScene();
#endif
}
#if (defined(CH_USE_RLAB) || defined(CH_USE_D3D))
bool ChQvLODInstance::Construct(ChRenderContext *pRC, ChConstructionIterator *pIterator)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -