manipulators/maniparrow/ormaniparrow_manip.cxx

manipulators/maniparrow/ormaniparrow_manip.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 declarations
#include "ormaniparrow_manip.h"
// OpenGL
//--- Registration defines
#define ORMANIPARROW__CLASS ORMANIPARROW__CLASSNAME
#define ORMANIPARROW__LABEL "OR - Arrow"
#define ORMANIPARROW__DESC "OR - Arrow Manipulator Description"
//--- FiLMBOX implementation and registration
FBManipulatorImplementation ( ORMANIPARROW__CLASS );
FBRegisterManipulator ( ORMANIPARROW__CLASS,
ORMANIPARROW__LABEL,
ORMANIPARROW__DESC,
FB_DEFAULT_SDK_ICON ); // Icon filename (default=Open Reality icon)
/************************************************
* FiLMBOX Constructor.
************************************************/
bool ORManipArrow::FBCreate()
{
if( FBManipulator::FBCreate() )
{
// Properties
DefaultBehavior = true;
ViewerText = "Arrow Manipulator";
// Members
mTestState = 0;
mModel = NULL;
mRenderInModelSpace = true;
mActivated = false;
return true;
}
return false;
}
/************************************************
* FiLMBOX Destructor.
************************************************/
void ORManipArrow::FBDestroy()
{
FBManipulator::FBDestroy();
}
/************************************************
* FiLMBOX Draw.
************************************************/
void ORManipArrow::DrawArrow( FBVector3d lVector )
{
glLoadName(1);
glColor3f( 1.0, 1.0, 0.0 );
glBegin(GL_POLYGON);
glVertex3f( lVector[0], lVector[1]-1, lVector[2] );
glVertex3f( lVector[0]+50.0, lVector[1]-1, lVector[2] );
glVertex3f( lVector[0]+50.0, lVector[1]+1, lVector[2] );
glVertex3f( lVector[0], lVector[1]+1, lVector[2] );
glEnd();
glBegin(GL_POLYGON);
glVertex3f( lVector[0]+50.0, lVector[1]-5, lVector[2] );
glVertex3f( lVector[0]+60.0, lVector[1], lVector[2] );
glVertex3f( lVector[0]+50.0, lVector[1]+5, lVector[2] );
glEnd();
}
/************************************************
* Draw function for manipulator
************************************************/
void ORManipArrow::ViewExpose()
{
static int lValue = 0;
static int lStep = 1;
static bool lForward = true;
FBVector3d lVector;
FBModelList lList;
int lSelectedModels = lList.GetCount();
for(int i=0;i<lSelectedModels;i++)
{
if( lList[i]->Is(FBModel::TypeInfo) )
{
mModel = lList[i];
break;
}
else
{
mModel = NULL;
}
}
if( lSelectedModels == 0 )
{
mModel = NULL;
}
if( mModel != NULL )
{
mModel->GetVector(lVector);
mActivated = true;
if( mRenderInModelSpace )
{
FBModelRenderBegin( NULL );
}
DrawArrow( lVector );
glFlush();
if( mRenderInModelSpace )
{
FBModelRenderEnd();
}
}
}
/************************************************
* Deal with maniplator input.
************************************************/
bool ORManipArrow::ViewInput(int pMouseX, int pMouseY, FBInputType pAction, int pButtonKey, int pModifier)
{
static bool lMouseButtonPressed = false;
static bool lArrowSelected = false;
static int lPrevMouseX = 0;
FBVector3d lVector;
if( mActivated && Active )
{
switch( pAction )
{
{
// When a keyboard key is pressed.
}
break;
{
// When a keyboard key is released.
}
break;
{
// Mouse button double-clicked.
}
break;
{
if( mModel != NULL )
{
lMouseButtonPressed = true;
lArrowSelected = false;
// Mouse button clicked.
GLuint lSelectionBuf[64];
GLint lViewport[4];
FBCamera* lCamera = (FBCamera*)CurrentCamera;
glGetIntegerv(GL_VIEWPORT,lViewport);
glSelectBuffer(64, lSelectionBuf);
glRenderMode(GL_SELECT);
glInitNames();
glPushName( (GLuint)-1 );
glMatrixMode(GL_PROJECTION);
glPushMatrix();
{
glLoadIdentity();
// IMPORTANT: the picking transfo _PREMULTIPLIES_ the projection transfo...
gluPickMatrix(pMouseX, ((double)lCamera->WindowHeight) - pMouseY, 5.0, 5.0, lViewport);
FBMatrix lCameraProjMatrix;
lCamera->GetCameraMatrix( lCameraProjMatrix, kFBProjection );
glMultMatrixd( lCameraProjMatrix );
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
{
FBMatrix lCameraMVMatrix;
lCamera->GetCameraMatrix( lCameraMVMatrix, kFBModelView );
glLoadMatrixd( lCameraMVMatrix );
mModel->GetVector( lVector );
DrawArrow( lVector );
}
glPopMatrix();
}
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopName();
glFlush();
lArrowSelected = (glRenderMode(GL_RENDER)!=0);
}
}
break;
{
// Mouse button released.
lMouseButtonPressed = false;
}
break;
{
if( lMouseButtonPressed )
{
if( lArrowSelected )
{
if( mModel != NULL )
{
mModel->GetVector(lVector);
GLint lViewport[4];
glGetIntegerv(GL_VIEWPORT,lViewport);
if( pMouseX - lPrevMouseX > 0 )
{
lVector[0] += 3;
}
else if( pMouseX - lPrevMouseX < 0 )
{
lVector[0] -= 3;
}
mModel->SetVector(lVector);
}
}
}
// When there is mouse movement in the viewer window
}
break;
{
// Items are being dragged.
}
break;
{
// Items are being dropped.
}
break;
}
}
lPrevMouseX = pMouseX;
return true;
}