COpenGL::SetSelectProcedure![]()
void SetSelectProcedure( void (*SelectProcedure)( void* ), void* hData );
Parameters
| SelectProcedure | Specifies callback procedure which COpenGL object is using for object selection. This is usually the same procedure used for scene rendering or wrapper around such procedure. |
| hData | Specifies the content of selection procedure callback. ClassGL will call the selection callback procedure with hData pointer as its parameter. The hData parameter usually specifies pointer to the class wrapping the COpenGL object. |
Remarks
Provided callback procedure is usually the same method which application uses for scene rendering. The COpenGL object first switch OpenGL render mode to GL_SELECT and then calls the callback SelectProcedure with provided hData. Within the selection procedure the application should call glLoadName for each object available for selection and then draw these objects. Therefore the selection mechanism is exactly the same which OpenGL provides.
This method is available from ClassGL version 3.0
Example
int COpenGLView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
// initialize OpenGL context
m_OpenGL.OnCreate( ( LPARAM )m_hWnd );
// set selection methods callbacks
m_OpenGL.SetSelectProcedure( CLASSGL_SELECTPROC SelectProc, this );
m_OpenGL.SetSelectObjectCallback( CLASSGL_SELECTOBJECTPROC SelectObjectProc, this );
m_OpenGL.SetOnChangeCallback( CLASSGL_ONCHANGEPROC OnChangeProc, this );
// indicate success
return 0;
}
/* static */ void COpenGLView::SelectProc( COpenGLView* Me )
{
Me->DrawScene( true );
}
/* static */ void COpenGLView::SelectObjectProc( COpenGLView* Me, int ObjectId )
{
Me->SelectObject( ObjectId );
}
/* static */ void COpenGLView::OnChangeProc( COpenGLView* Me, SObjectInfo* Object )
{
Me->OnChange( Object );
}
void COpenGLView::DrawScene( bool SelectObject )
{
COglSampleDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// go through array of objects and draw them one by one
for ( int i = 0; i < pDoc->m_Objects.GetSize(); i++ )
{
// get the object
CMyObject* Object =
(
CMyObject* )pDoc->m_Objects.GetAt( i ); //
save
current "world view"
matrix glPushMatrix();
//
apply object info to display object on proper
position/rotation
m_OpenGL.ApplyObjectInfo(& Object->m_ObjectInfo );
//
if this is a "select object" call, load the object
identifier
if( SelectObject )
glLoadName(
Object->m_ObjectInfo.ObjectId ); // draw the object Object->Draw(); // restore the
"world
view"matrix glPopMatrix(); }
}
void COglSampleView::SelectObject( int ObjectId )
{
COglSampleDoc* pDoc =
GetDocument(); ASSERT_VALID(pDoc); // go through the listof objects and
compare
one object id after
another for ( int i=
0; i < pDoc->m_MyObjects.GetSize(); i++ )
{ CMyObject* MyObject=
( CMyObject*) pDoc->m_MyObjects.GetAt(
i ); if (
ObjectId=
=
MyObject->m_ObjectInfo.ObjectId ) { // setreference to object
position
info m_OpenGL. < STRONG>
SetManipulatedObject < /STRONG>
( &My->m_ObjectInfo );
return;
}
}
// call base class to unselect previously selected object
m_OpenGL.SetManipulatedObject( NULL );
m_OpenGL.UnsetFitSelectedInfo();
}
void CoglSampleView::OnChange( SObjectInfo* Object )
{
COglSampleDoc* pDoc =
GetDocument();
ASSERT_VALID(pDoc);PDoc->SetModifiedFlag( TRUE );
}
See Also
SetSelectObjectCallback, SetManipulatedObject
![]()
| © 2001 Solid Graphics, All rights reserved. |
| To view this site, we require use of either Netscape Navigator 4.0 or higher or Internet Explorer 4.0 or higher. |