#include "ormanip_association_manip.h"
#define ORMANIPASSOCIATION__CLASS ORMANIPASSOCIATION__CLASSNAME
#define ORMANIPASSOCIATION__DESC "OR - Manipulator Association Description"
ORMANIPASSOCIATION__LABEL,
ORMANIPASSOCIATION__DESC,
bool ORManip_Association::FBCreate()
{
if( FBManipulator::FBCreate() )
{
DefaultBehavior = true;
ViewerText = "Association Manipulator";
mRenderInModelSpace = true;
mActivated = false;
((FBScene*)FBSystem().Scene)->OnChange.Add (
this, (
FBCallback) &ORManip_Association::EventSceneChange );
return true;
}
return false;
}
void ORManip_Association::FBDestroy()
{
((FBScene*)FBSystem().Scene)->OnChange.Remove (
this, (
FBCallback) &ORManip_Association::EventSceneChange );
FBManipulator::FBDestroy();
}
void ORManip_Association::EventSceneChange(
HISender pSender,
HKEvent pEvent )
{
FBEventSceneChange lEvent( pEvent );
switch( lEvent.Type )
{
{
FBComponent* lChildComp = (FBComponent*)lEvent.ChildComponent;
if (mModel == lChildComp)
{
Active = false;
AlwaysActive = false;
DefaultBehavior = true;
}
}
break;
}
}
void ORManip_Association::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();
}
void ORManip_Association::SetModel(FBComponent* pFBModel)
{
if( pFBModel->Is(FBModel::TypeInfo) )
{
mModel = (FBModel*)pFBModel;
}
}
void ORManip_Association::ViewExpose()
{
static int lValue = 0;
static int lStep = 1;
static bool lForward = true;
{
mModel->GetVector(lVector);
mActivated = true;
if( mRenderInModelSpace )
{
FBModelRenderBegin(
NULL );
}
DrawArrow( lVector );
glFlush();
if( mRenderInModelSpace )
{
FBModelRenderEnd();
}
}
}
bool ORManip_Association::ViewInput(
int pMouseX,
int pMouseY,
FBInputType pAction,
int pButtonKey,
int pModifier)
{
static bool lMouseButtonPressed = false;
static bool lArrowSelected = false;
static int lPrevMouseX = 0;
if( mActivated )
{
switch( pAction )
{
{
}
break;
{
}
break;
{
}
break;
{
{
lMouseButtonPressed = true;
lArrowSelected = false;
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();
gluPickMatrix(pMouseX, ((double)lCamera->WindowHeight) - pMouseY, 5.0, 5.0, lViewport);
FBMatrix lMatrix;
glMultMatrixd( lMatrix );
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
{
glLoadMatrixd( lMatrix );
mModel->GetVector( lVector );
DrawArrow( lVector );
}
glPopMatrix();
}
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopName();
glFlush();
lArrowSelected = (glRenderMode(GL_RENDER)!=0);
}
}
break;
{
lMouseButtonPressed = false;
}
break;
{
if( lMouseButtonPressed )
{
if( lArrowSelected )
{
{
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);
}
}
}
}
break;
{
}
break;
{
}
break;
}
}
lPrevMouseX = pMouseX;
return true;
}