miscellaneous/marker_template/ormarker_template_custom.cxx

miscellaneous/marker_template/ormarker_template_custom.cxx
/***************************************************************************************
Autodesk(R) Open Reality(R) Samples
(C) 2009 Autodesk, Inc. and/or its licensors
All rights reserved.
AUTODESK SOFTWARE LICENSE AGREEMENT
Autodesk, Inc. licenses this Software to you only upon the condition that
you accept all of the terms contained in the Software License Agreement ("Agreement")
that is embedded in or that is delivered with this Software. By selecting
the "I ACCEPT" button at the end of the Agreement or by copying, installing,
uploading, accessing or using all or any portion of the Software you agree
to enter into the Agreement. A contract is then formed between Autodesk and
either you personally, if you acquire the Software for yourself, or the company
or other legal entity for which you are acquiring the software.
AUTODESK, INC., MAKES NO WARRANTY, EITHER EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
PURPOSE REGARDING THESE MATERIALS, AND MAKES SUCH MATERIALS AVAILABLE SOLELY ON AN
"AS-IS" BASIS.
IN NO EVENT SHALL AUTODESK, INC., BE LIABLE TO ANYONE FOR SPECIAL, COLLATERAL,
INCIDENTAL, OR CONSEQUENTIAL DAMAGES IN CONNECTION WITH OR ARISING OUT OF PURCHASE
OR USE OF THESE MATERIALS. THE SOLE AND EXCLUSIVE LIABILITY TO AUTODESK, INC.,
REGARDLESS OF THE FORM OF ACTION, SHALL NOT EXCEED THE PURCHASE PRICE OF THE
MATERIALS DESCRIBED HEREIN.
Autodesk, Inc., reserves the right to revise and improve its products as it sees fit.
Autodesk and Open Reality are registered trademarks or trademarks of Autodesk, Inc.,
in the U.S.A. and/or other countries. All other brand names, product names, or
trademarks belong to their respective holders.
GOVERNMENT USE
Use, duplication, or disclosure by the U.S. Government is subject to restrictions as
set forth in FAR 12.212 (Commercial Computer Software-Restricted Rights) and
DFAR 227.7202 (Rights in Technical Data and Computer Software), as applicable.
Manufacturer is Autodesk, Inc., 10 Duke Street, Montreal, Quebec, Canada, H3C 2L7.
***************************************************************************************/
//--- Class declaration
#include "ormarker_template_custom.h"
FBClassImplementation( ORMarkerCustom );
FBStorableCustomModelImplementation( ORMarkerCustom, ORMARKERCUSTOM__DESCSTR );
/************************************************
* Constructor.
************************************************/
ORMarkerCustom::ORMarkerCustom( const char* pName, HIObject pObject )
: FBModelMarker( pName, pObject )
{
}
/************************************************
* FiLMBOX Constructor.
************************************************/
bool ORMarkerCustom::FBCreate()
{
ShadingMode = kFBModelShadingTexture;
Size = 50.0;
Length = 1.0;
Show = true;
mPickedSubItem = -1;
return true;
}
/************************************************
* FiLMBOX Destructor.
************************************************/
void ORMarkerCustom::FBDestroy()
{
ParentClass::FBDestroy();
}
void ORMarkerCustom::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();
// Request / Release additional uniquecolorId resources.
SetAdditionalUniqueColorIDCount( lIsColorBufferPicking ? 2 : 0);
double lScale = 100;
glPushAttrib(GL_COLOR_BUFFER_BIT | GL_POLYGON_BIT | GL_TRANSFORM_BIT | GL_LINE_BIT); //Push Current GL states.
{
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
{
FBVector3d T = Translation;
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);
// Draw with Model's Unique ColorID (or selection name (-1) set by Mobu Internally).
glBegin(GL_LINES);
glVertex3d(lScale,lScale,lScale);
glVertex3d(-lScale,lScale,lScale);
glEnd();
if (lIsColorBufferPicking)
// Draw with subitem additional ColorID
glColor3dv(GetAdditionalUniqueColorID(0));
else if (lIsSelectBufferPicking)
// Draw with subitem selection name 1;
glLoadName(1);
glBegin(GL_LINES);
glVertex3d(0,0,0);
glVertex3d(lScale,lScale,lScale);
glEnd();
if (lIsColorBufferPicking)
// Draw with subitem additional ColorID
glColor3dv(GetAdditionalUniqueColorID(1));
else if (lIsSelectBufferPicking)
// Draw with subitem selection name 2;
glLoadName(2);
glBegin(GL_LINES);
glVertex3d(0,0,0);
glVertex3d(-lScale,lScale,lScale);
glEnd();
}
glPopMatrix();
}
glPopAttrib();
}
bool ORMarkerCustom::CustomModelPicking( int pNbHits, unsigned int *pSelectBuffer, FBCamera* pCamera,
int pMouseX,int pMouseY,
FBTVector* localRaySrc, FBTVector* localRayDir,
FBTVector* pWorldRaySrc, FBTVector* pWorldRayDir,
FBMatrix* pGlobalInverseMatrix,
FBTVector* pOutPickedPoint)
{
// no hits
if( pNbHits <= 0)
return false;
mPickedSubItem = -1;
for (int Count=0; Count<pNbHits; Count++)
{
/* Each hit record contains the following information stored as unsigned ints:
* - Number of names in the name stack for this hit record
* - Minimum depth value of primitives (range 0 to 2^32-1)
* - Maximum depth value of primitives (range 0 to 2^32-1)
* - Name stack contents (one name for each unsigned int).
* see http://www.opengl.org/archives/resources/faq/technical/selection.htm
*/
unsigned int NameCount = *pSelectBuffer++;
assert(NameCount == 1);
// Skip two items (Min & Max Depth)
pSelectBuffer+=2;
// Fetch the first name from stack.
unsigned int NameIndex = *pSelectBuffer++;
if(NameIndex==1)
{
mPickedSubItem = 0;
if(pOutPickedPoint)
{
*pOutPickedPoint = FBTVector(100,100,100,0);
}
}
else if(NameIndex==2)
{
mPickedSubItem = 1;
if(pOutPickedPoint)
{
*pOutPickedPoint = FBTVector(-100,100,100,0);
}
}
}
FBTrace("Select %s SubItem[%d]", GetFullName(), mPickedSubItem);
return true;
}
bool ORMarkerCustom::PlugStateNotify(FBConnectionAction pAction,FBPlug* pThis,void* pData/*=NULL*/,void* pDataOld/*=NULL*/,int pDataSize/*=0*/)
{
if (FBSystem::TheOne().Renderer->IDBufferPicking)
{
switch(pAction)
{
case kFBSelect:
{
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;
}
}
// Important, continue forward notification to parent class.
return ParentClass::PlugStateNotify(pAction, pThis, pData, pDataOld, pDataSize);
}
bool ORMarkerCustom::FbxStore(FBFbxObject* pFbxObject, kFbxObjectStore pStoreWhat)
{
return true;
}
bool ORMarkerCustom::FbxRetrieve(FBFbxObject* pFbxObject, kFbxObjectStore pStoreWhat)
{
return true;
}