#include "ormodel_template_model_display.h"
ORModelCustomDisplay::ORModelCustomDisplay(
const char* pName,
HIObject pObject )
: FBModel( pName, pObject )
, mPickedSubItem(-1)
{
}
bool ORModelCustomDisplay::FBCreate()
{
Scale.SetPropertyValue(100.0);
CreateGeometry();
return true;
}
void ORModelCustomDisplay::FBDestroy()
{
}
void ORModelCustomDisplay::CreateGeometry()
{
FBMesh* lMesh = new FBMesh("Model Custom");
this->Geometry = lMesh;
double lScale = Scale;
lMesh->GeometryBegin();
lMesh->VertexAdd( 0.0, 0.0, 0.0 );
lMesh->VertexAdd( lScale, lScale, lScale );
lMesh->VertexAdd( -lScale, -lScale, -lScale );
lMesh->GeometryEnd();
}
void ORModelCustomDisplay::CustomModelDisplay( FBCamera* pCamera,
FBModelShadingMode pShadingMode,
FBModelRenderPass pRenderPass,
float pPickingAreaWidth,
float pPickingAreaHeight)
{
FBMatrix MatrixView;
FBMatrix MatrixProjection;
FBViewingOptions* lViewingOptions = FBSystem::TheOne().Renderer->GetViewingOptions();
bool lIsSelectBufferPicking = lViewingOptions->IsInSelectionBufferPicking();
bool lIsColorBufferPicking = lViewingOptions->IsInColorBufferPicking();
SetAdditionalUniqueColorIDCount( lIsColorBufferPicking ? 2 : 0);
double lScale = Scale;
glPushAttrib(GL_COLOR_BUFFER_BIT | GL_POLYGON_BIT | GL_TRANSFORM_BIT | GL_LINE_BIT);
{
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
{
glTranslated(T[0],T[1],T[2]);
if (!lIsSelectBufferPicking && !lIsColorBufferPicking)
{
if ((bool)Selected)
{
if (mPickedSubItem == 0)
glColor3d(1.0,0.0,0.0);
else if (mPickedSubItem == 1)
glColor3d(0.0, 1.0, 0.0);
else
glColor3d(0.0, 0.0, 1.0);
}
else
{
glColor3d(1.0,1.0,1.0);
}
}
glLineWidth(3.0);
glBegin(GL_LINES);
glVertex3d(lScale,lScale,lScale);
glVertex3d(-lScale,lScale,lScale);
glEnd();
if (lIsColorBufferPicking)
glColor3dv(GetAdditionalUniqueColorID(0));
else if (lIsSelectBufferPicking)
glLoadName(1);
glBegin(GL_LINES);
glVertex3d(0,0,0);
glVertex3d(lScale,lScale,lScale);
glEnd();
if (lIsColorBufferPicking)
glColor3dv(GetAdditionalUniqueColorID(1));
else if (lIsSelectBufferPicking)
glLoadName(2);
glBegin(GL_LINES);
glVertex3d(0,0,0);
glVertex3d(-lScale,lScale,lScale);
glEnd();
}
glPopMatrix();
}
glPopAttrib();
}
bool ORModelCustomDisplay::CustomModelPicking(int pNbHits, unsigned int *pSelectBuffer, FBCamera* pCamera,
int pMouseX,int pMouseY,
FBMatrix* pGlobalInverseMatrix,
{
if( pNbHits <= 0)
return false;
mPickedSubItem = -1;
for (int Count=0; Count<pNbHits; Count++)
{
unsigned int NameCount = *pSelectBuffer++;
assert(NameCount == 1);
pSelectBuffer+=2;
unsigned int NameIndex = *pSelectBuffer++;
if(NameIndex==1)
{
mPickedSubItem = 0;
if(pOutPickedPoint)
{
}
}
else if(NameIndex==2)
{
mPickedSubItem = 1;
if(pOutPickedPoint)
{
*pOutPickedPoint =
FBTVector(-100,100,100,0);
}
}
}
FBTrace(
"Select %s SubItem[%d]", GetFullName(), mPickedSubItem);
return true;
}
{
pIntersectPos =
FBTVector(0, 2.0 * Scale / 3.0, 2.0 * Scale / 3.0);
return true;
}
bool ORModelCustomDisplay::PlugStateNotify(
FBConnectionAction pAction,FBPlug* pThis,
void* pData,
void* pDataOld,
int pDataSize)
{
if (FBSystem::TheOne().Renderer->IDBufferPicking)
{
switch(pAction)
{
{
FBPickInfosList* lPickInfoList = FBCreatePickInfosList();
if (FBSystem::TheOne().Renderer->GetLastPickInfoList(*lPickInfoList))
{
for (int lIndex = 0; lIndex < lPickInfoList->GetCount(); lIndex++)
{
FBPickInfos lPickInfo = lPickInfoList->GetAt(lIndex);
if (lPickInfo.mModel == this)
{
FBTrace(
"Select %s SubItem[%d]", GetFullName(), lPickInfo.mSubItemIndex);
mPickedSubItem = lPickInfo.mSubItemIndex;
}
}
}
}
break;
{
FBTrace(
"Unselect %s", GetFullName());
mPickedSubItem = -1;
}
break;
default:
break;
}
}
return ParentClass::PlugStateNotify(pAction, pThis, pData, pDataOld, pDataSize);
}
bool ORModelCustomDisplay::FbxStore(FBFbxObject* pFbxObject,
kFbxObjectStore pStoreWhat)
{
return true;
}
bool ORModelCustomDisplay::FbxRetrieve(FBFbxObject* pFbxObject,
kFbxObjectStore pStoreWhat)
{
return true;
}