manipulators/manipcamera/ormanipcamera_manip.cxx

manipulators/manipcamera/ormanipcamera_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 "ormanipcamera_manip.h"
#include <math.h>
//--- Registration define
#define ORMANIPCAMERA__CLASS ORMANIPCAMERA__CLASSNAME
#define ORMANIPCAMERA__LABEL "OR - Camera"
#define ORMANIPCAMERA__DESC "OR Camera Manipulator Description"
//--- FiLMBOX implementation and registration
FBManipulatorImplementation ( ORMANIPCAMERA__CLASS );
FBRegisterManipulator ( ORMANIPCAMERA__CLASS,
ORMANIPCAMERA__LABEL,
ORMANIPCAMERA__DESC,
FB_DEFAULT_SDK_ICON ); // Icon filename (default=Open Reality icon)
/************************************************
* FiLMBOX Constructor.
************************************************/
bool ORManipulatorCamera::FBCreate()
{
if( FBManipulator::FBCreate() )
{
FBVector3d lPos;
FBCamera* lCamera = NULL;
FBModel* lInterest = NULL;
// Assign default values.
mZoomingOut = false;
mTurningLeft = false;
mAnimatingAOV = false;
mRotating = false;
mStepAOV = 0.1;
mStepRotate = 0.1;
mModelRotate = NULL;
// Create camera & interest.
lCamera = new FBCamera ( "MyCamera" );
lInterest = new FBModelNull ( "MyInterest" );
lCamera->Show = true;
lInterest->Show = true;
lCamera->LookAt = lInterest;
// Set the new camera position
lPos[0] = 200.0;
lPos[1] = 150.0;
lPos[2] = 150.0;
lCamera->SetVector( lPos, kModelTranslation, true );
return true;
}
return false;
}
/************************************************
* FiLMBOX Destructor.
************************************************/
void ORManipulatorCamera::FBDestroy()
{
FBManipulator::FBDestroy();
}
/************************************************
* Draw function for the manipulator.
* In this function we are able to interact with the 3D
* viewer in FiLMBOX.
************************************************/
void ORManipulatorCamera::ViewExpose()
{
// Get the current camera.
FBCamera* lCamera = (FBCamera*) CurrentCamera;
FBTVector lRVS, lRVE;
FBTVector lTV, lUV;
FBVector3d lVector;
char lText[50];
char lText2[50];
// Display the current angle of view in the viewer.
sprintf(lText,"Angle of viewX: %lf",(double) lCamera->FieldOfViewX);
sprintf(lText2,"Angle of viewY: %lf",(double) lCamera->FieldOfViewY);
ViewerText = lText;
// If we're animating the AOV
if(mAnimatingAOV)
{
// Calculate the new angle of view.
lCamera->FieldOfView = lCamera->FieldOfView + (mZoomingOut?1:-1)*mStepAOV;
}
// If there is an object to rotate.
if(mRotating)
{
// Get the current model to rotate.
FBModel* lModel = mModelRotate;
// If there is no model, use the current camera.
if( ! lModel )
{
lModel = CurrentCamera;
}
// Get the local position.
lModel->GetVector( lVector, kModelTranslation, true );
// Up vector.
lUV.mValue[0] = 0.0;
lUV.mValue[1] = 1.0;
lUV.mValue[2] = 0.0;
// Use the X & Z coordinates to make a circle
lRVS.mValue[0] = lVector.mValue[0];
lRVS.mValue[1] = 0.0;
lRVS.mValue[2] = lVector.mValue[2];
// Calculate radius & tangeant lengths (isoceles triangle).
double lRLength = FBLength( lRVS );
double lTLength = lRLength * sin( mStepRotate/57.3 ) / sin( (180-mStepRotate) / (2*57.3) );
FBMult ( lTV, mTurningLeft ? lRVS:lUV, mTurningLeft ? lUV:lRVS );
FBMult ( lTV, lTV, 1/FBLength(lTV) );
FBMult ( lTV, lTV, lTLength );
FBAdd ( lRVE, lRVS, lTV );
FBMult ( lRVE, lRVE, 1/FBLength( lRVE ) );
FBMult ( lRVE, lRVE, lRLength );
// Copy the new values into the vector to affect the model with.
lVector.mValue[0] = lRVE.mValue[0];
lVector.mValue[1] = lVector.mValue[1]; // Keep the Y (height)
lVector.mValue[2] = lRVE.mValue[2];
// Affect the model's vector.
lModel->SetVector( lVector, kModelTranslation, true );
}
FBManipulator::ViewExpose();
}
/************************************************
* View and use the input from the user interacting
* with the 3D viewer.
************************************************/
bool ORManipulatorCamera::ViewInput(int pMouseX, int pMouseY, FBInputType pAction, int pButtonKey, int pModifier)
{
return FBManipulator::ViewInput(pMouseX, pMouseY, pAction, pButtonKey, pModifier);
}