vrj::PfBasicSimulator Class Reference

Interface for objects that wish to perform simulator function with an OpenGL application. More...

#include <vrj/Draw/Pf/PfBasicSimulator.h>

Inheritance diagram for vrj::PfBasicSimulator:

Inheritance graph
[legend]
Collaboration diagram for vrj::PfBasicSimulator:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 PfBasicSimulator ()
virtual ~PfBasicSimulator ()
virtual bool config (jccl::ConfigElementPtr element)
 Configure the basic simulator config.
virtual void initialize (SimViewport *simVp)
virtual void setKeyboardMouse (gadget::KeyboardMouseInterface kmInterface)
 Sets the keyboard/mouse device the simulator can use to get input from the user.
const gmtl::Matrix44f & getCameraPos ()
const gmtl::Matrix44f & getHeadPos ()
const gmtl::Matrix44f & getWandPos ()
virtual void updateProjectionData (const float positionScale, Projection *leftProj, Projection *rightProj)
 Called as part of the viewports updateProjection call.
void updateInternalData (float positionScale)
 Update internal simulator data.
virtual void updateSimulatorSceneGraph ()
 Draws this sim device using the given information about the Window it will be drawing into.
bool configPerformerAPI (jccl::ConfigElementPtr element)
void initSimulatorGraph ()

Static Public Member Functions

static std::string getElementType ()

Protected Attributes

SimViewportmSimViewport
gadget::PositionInterface mCamera
 Proxy interfaces to devices needed.
gadget::PositionInterface mWand
gmtl::Matrix44f mCameraPos
 The data about the position of all this stuff.
gmtl::Matrix44f mHeadPos
gmtl::Matrix44f mWandPos
pfScene * mRootWithSim
 The root with the simulator group & the sceneRoot.
Drawing attributes
bool mDrawProjections
 Should we draw projections.
gmtl::Vec3f mSurfaceColor
 Color to draw surfaces.
Simulator stuff
pfGroup * mSimTree
 The simulator scene graph.
pfDCS * mHeadDCS
 The DCS above the head.
pfDCS * mWandDCS
 The DCS above the wand.
std::string mHeadModel
 The head model file path.
std::string mWandModel
 The wand model file path.

Detailed Description

Interface for objects that wish to perform simulator function with an OpenGL application.

Definition at line 56 of file PfBasicSimulator.h.


Constructor & Destructor Documentation

vrj::PfBasicSimulator::PfBasicSimulator (  ) 

Definition at line 76 of file PfBasicSimulator.cpp.

00076                                    : mRootWithSim(NULL),
00077    mSimTree(NULL), mHeadDCS(NULL), mWandDCS(NULL)
00078 {
00079    //setDrawWandFunctor(new GlDrawConeWandFunctor());
00080    //setDrawWandFunctor(new GlDrawRightAngleWandFunctor());
00081 }

virtual vrj::PfBasicSimulator::~PfBasicSimulator (  )  [inline, virtual]

Definition at line 61 of file PfBasicSimulator.h.

00061 {}


Member Function Documentation

bool vrj::PfBasicSimulator::config ( jccl::ConfigElementPtr  element  )  [virtual]

Configure the basic simulator config.

Precondition:
element is a valid configuration element.
Postcondition:
It should be configured

Implements vrj::DrawSimInterface.

Definition at line 88 of file PfBasicSimulator.cpp.

References configPerformerAPI(), mCamera, mDrawProjections, mSurfaceColor, and mWand.

00089 {
00090    vprASSERT(element.get() != NULL);
00091    vprASSERT(element->getID() == std::string("default_simulator"));
00092 
00093    std::string camera_proxy_str = element->getProperty<std::string>("camera_pos");
00094    std::string wand_proxy_str = element->getProperty<std::string>("wand_pos");
00095 
00096    mCamera.init(camera_proxy_str);
00097    mWand.init(wand_proxy_str);      // Configure the wand to use
00098 
00099    if(!mCamera.isConnected())
00100    {
00101       vprDEBUG(vprDBG_ERROR, vprDBG_CRITICAL_LVL)
00102          << clrOutNORM(clrRED,"ERROR:")
00103          << "PfBasicSimulator:: Fatal Error: Camera not found named: "
00104          << camera_proxy_str.c_str() << vprDEBUG_FLUSH;
00105       vprASSERT(false);
00106    }
00107 
00108    // Get drawing parameters
00109    mDrawProjections = element->getProperty<bool>("draw_projections");
00110    mSurfaceColor[0] = element->getProperty<float>("surface_color", 0);
00111    mSurfaceColor[1] = element->getProperty<float>("surface_color", 1);
00112    mSurfaceColor[2] = element->getProperty<float>("surface_color", 2);
00113 
00114    configPerformerAPI(element);
00115 
00116    return true;
00117 }

static std::string vrj::PfBasicSimulator::getElementType (  )  [inline, static]

Definition at line 71 of file PfBasicSimulator.h.

00072    {
00073       return std::string("default_simulator");
00074    }

virtual void vrj::PfBasicSimulator::initialize ( SimViewport simVp  )  [inline, virtual]

Implements vrj::DrawSimInterface.

Definition at line 76 of file PfBasicSimulator.h.

References mSimViewport.

00077    {
00078       mSimViewport = simVp;
00079    }

void vrj::PfBasicSimulator::setKeyboardMouse ( gadget::KeyboardMouseInterface  kmInterface  )  [virtual]

Sets the keyboard/mouse device the simulator can use to get input from the user.

Implements vrj::PfSimInterface.

Definition at line 123 of file PfBasicSimulator.cpp.

00124 {
00125    boost::ignore_unused_variable_warning(kmInterface);
00126 }

const gmtl::Matrix44f& vrj::PfBasicSimulator::getCameraPos (  )  [inline]

Definition at line 88 of file PfBasicSimulator.h.

References mCameraPos.

Referenced by updateProjectionData().

00089    {
00090       return mCameraPos;
00091    }

const gmtl::Matrix44f& vrj::PfBasicSimulator::getHeadPos (  )  [inline]

Definition at line 93 of file PfBasicSimulator.h.

References mHeadPos.

Referenced by updateSimulatorSceneGraph().

00094    {
00095       return mHeadPos;
00096    }

const gmtl::Matrix44f& vrj::PfBasicSimulator::getWandPos (  )  [inline]

Definition at line 98 of file PfBasicSimulator.h.

References mWandPos.

Referenced by updateSimulatorSceneGraph().

00099    {
00100       return mWandPos;
00101    }

void vrj::PfBasicSimulator::updateProjectionData ( const float  positionScale,
Projection leftProj,
Projection rightProj 
) [virtual]

Called as part of the viewports updateProjection call.

Reimplemented from vrj::DrawSimInterface.

Definition at line 129 of file PfBasicSimulator.cpp.

References vrj::Projection::calcViewMatrix(), getCameraPos(), vrj::User::getInterocularDistance(), vrj::Viewport::getUser(), mSimViewport, and updateInternalData().

00131 {
00132    updateInternalData(positionScale);
00133 
00134    gmtl::Matrix44f camera_pos = getCameraPos();
00135    gmtl::Vec3f camera_trans = gmtl::makeTrans<gmtl::Vec3f>(camera_pos);
00136 
00137    gmtl::Matrix44f left_eye_pos, right_eye_pos;     // NOTE: Eye coord system is -z forward, x-right, y-up
00138 
00139    // -- Calculate camera (eye) Positions -- //
00140    vprDEBUG(vprDBG_ALL, vprDBG_HEX_LVL)
00141       << "[vrj::PfBasicSimulator::updateProjectionData()] Getting cam position"
00142       << std::endl << vprDEBUG_FLUSH;
00143    vprDEBUG(vprDBG_ALL, vprDBG_HEX_LVL)
00144       << "CamPos:" << camera_trans << std::endl << vprDEBUG_FLUSH;
00145 
00146    // Compute location of left and right eyes
00147    float interocular_dist = mSimViewport->getUser()->getInterocularDistance();
00148    interocular_dist *= positionScale;               // Scale into correct units
00149    float eye_offset = interocular_dist / 2.0f;      // Distance to move eye
00150 
00151    left_eye_pos = camera_pos * gmtl::makeTrans<gmtl::Matrix44f>( gmtl::Vec3f(-eye_offset, 0.0f, 0.0f) );
00152    right_eye_pos = camera_pos * gmtl::makeTrans<gmtl::Matrix44f>( gmtl::Vec3f(eye_offset, 0.0f, 0.0f) );
00153 
00154    leftProj->calcViewMatrix(left_eye_pos, positionScale);
00155    rightProj->calcViewMatrix(right_eye_pos, positionScale);
00156 }

void vrj::PfBasicSimulator::updateInternalData ( float  positionScale  ) 

Update internal simulator data.

Definition at line 159 of file PfBasicSimulator.cpp.

References vrj::User::getHeadPosProxy(), vrj::Viewport::getUser(), mCamera, mCameraPos, mHeadPos, mSimViewport, mWand, and mWandPos.

Referenced by updateProjectionData().

00160 {
00161    mHeadPos = mSimViewport->getUser()->getHeadPosProxy()->getData(positionScale);
00162    mWandPos = mWand->getData(positionScale);
00163 
00164    mCameraPos = mCamera->getData(positionScale);
00165    gmtl::invert(mCameraPos);
00166 }

void vrj::PfBasicSimulator::updateSimulatorSceneGraph (  )  [virtual]

Draws this sim device using the given information about the Window it will be drawing into.

Implements vrj::PfSimInterface.

Definition at line 266 of file PfBasicSimulator.cpp.

References getHeadPos(), vrj::GetPfMatrix(), getWandPos(), mHeadDCS, and mWandDCS.

00267 {
00268       gmtl::Matrix44f vj_head_mat = getHeadPos();          // Get Juggler matrices
00269       gmtl::Matrix44f vj_wand_mat = getWandPos();
00270       pfMatrix head_mat = GetPfMatrix(vj_head_mat);    // Convert to Performer
00271       pfMatrix wand_mat = GetPfMatrix(vj_wand_mat);
00272       mHeadDCS->setMat(head_mat);                        // Set the DCS nodes
00273       mWandDCS->setMat(wand_mat);
00274 }

bool vrj::PfBasicSimulator::configPerformerAPI ( jccl::ConfigElementPtr  element  ) 

Definition at line 171 of file PfBasicSimulator.cpp.

References initSimulatorGraph(), mHeadModel, mRootWithSim, mWandModel, and vrjDBG_DRAW_MGR().

Referenced by config().

00172 {
00173    //vprASSERT(Element->getID() == std::string("apiPerformer"));
00174 
00175    vprDEBUG(vrjDBG_DRAW_MGR,vprDBG_CONFIG_LVL) << "PfBasicSimulator::configPerformerAPI:"
00176                                             << " Configuring Performer\n" << vprDEBUG_FLUSH;
00177 
00178    // --- Get simulator model info --- //
00179    std::string head_file = element->getProperty<std::string>("head_model");
00180    std::string wand_file = element->getProperty<std::string>("wand_model");
00181    if(head_file.empty())
00182    {
00183       vprDEBUG(vprDBG_ALL,vprDBG_CONFIG_LVL)
00184          << "WARNING: PfBasicSimulator::config: simHeadModel not set."
00185          << std::endl << vprDEBUG_FLUSH;
00186    }
00187    if(wand_file.empty())
00188    {
00189       vprDEBUG(vprDBG_ALL,vprDBG_CONFIG_LVL)
00190          << "WARNING: PfBasicSimulator::config: simWandModel not set."
00191          << std::endl << vprDEBUG_FLUSH;
00192    }
00193 
00194    mHeadModel = vpr::replaceEnvVars(head_file);
00195    mWandModel = vpr::replaceEnvVars(wand_file);
00196 
00197    vprDEBUG(vrjDBG_DRAW_MGR,vprDBG_CONFIG_LVL)
00198       << "Head Model: " << mHeadModel.c_str() << std::endl
00199       << "Wand Model: " << mWandModel.c_str() << std::endl << vprDEBUG_FLUSH;
00200 
00201    mRootWithSim = PfDrawManager::instance()->getRootWithSim();
00202    if (NULL != mRootWithSim)
00203    {
00204       initSimulatorGraph();
00205       return true;
00206    }
00207    return false;
00208 }

void vrj::PfBasicSimulator::initSimulatorGraph (  ) 

Definition at line 210 of file PfBasicSimulator.cpp.

References mHeadDCS, mHeadModel, mRootWithSim, mSimTree, mWandDCS, mWandModel, and vrjDBG_DRAW_MGR().

Referenced by configPerformerAPI().

00211 {
00212    pfNode* head_node(NULL);
00213    pfNode* wand_node(NULL);
00214 
00215    if(!mHeadModel.empty())
00216    {
00217       head_node = pfdLoadFile(mHeadModel.c_str());     // Load head model
00218       vprDEBUG(vrjDBG_DRAW_MGR,vprDBG_CONFIG_LVL)
00219          << "[vrj::PfBasicSimulator::initSimulatorGraph()] Loaded head model: "
00220          << mHeadModel.c_str() << std::endl << vprDEBUG_FLUSH;
00221    }
00222    else
00223    {
00224       vprDEBUG(vrjDBG_DRAW_MGR,vprDBG_CONFIG_LVL)
00225          << "[vrj::PfBasicSimulator::initSimulatorGraph()] "
00226          << "No wand head specified.\n" << vprDEBUG_FLUSH;
00227    }
00228 
00229    if(!mWandModel.empty())
00230    {
00231       wand_node = pfdLoadFile(mWandModel.c_str());     // Load wand model
00232       vprDEBUG(vrjDBG_DRAW_MGR,vprDBG_CONFIG_LVL)
00233          << "[vrj::PfBasicSImulator::initSimulatorGraph()] "
00234          << "Loaded wand model: " << mWandModel << std::endl << vprDEBUG_FLUSH;
00235    }
00236    else
00237    {
00238       vprDEBUG(vrjDBG_DRAW_MGR,vprDBG_CONFIG_LVL)
00239          << "[vrj::PfDrawManager::initSimulatorGraph()] "
00240          << "No wand model specified.\n" << vprDEBUG_FLUSH;
00241    }
00242 
00243    mSimTree = new pfGroup;
00244 
00245    //mRootWithSim = new pfScene;
00246 
00247    mHeadDCS = new pfDCS;
00248    mWandDCS = new pfDCS;
00249    mSimTree->addChild(mHeadDCS);
00250    mSimTree->addChild(mWandDCS);
00251    if(NULL != head_node)
00252    {
00253       mHeadDCS->addChild(head_node);
00254    }
00255    if(NULL != wand_node)
00256    {
00257       mWandDCS->addChild(wand_node);
00258    }
00259 
00260    if((head_node != NULL) && (wand_node != NULL))
00261    {
00262       mRootWithSim->addChild(mSimTree);      // Put sim stuff in the graph
00263    }
00264 }


Member Data Documentation

SimViewport* vrj::PfBasicSimulator::mSimViewport [protected]

Definition at line 127 of file PfBasicSimulator.h.

Referenced by initialize(), updateInternalData(), and updateProjectionData().

bool vrj::PfBasicSimulator::mDrawProjections [protected]

Should we draw projections.

Definition at line 131 of file PfBasicSimulator.h.

Referenced by config().

gmtl::Vec3f vrj::PfBasicSimulator::mSurfaceColor [protected]

Color to draw surfaces.

Definition at line 132 of file PfBasicSimulator.h.

Referenced by config().

gadget::PositionInterface vrj::PfBasicSimulator::mCamera [protected]

Proxy interfaces to devices needed.

Definition at line 135 of file PfBasicSimulator.h.

Referenced by config(), and updateInternalData().

gadget::PositionInterface vrj::PfBasicSimulator::mWand [protected]

Definition at line 136 of file PfBasicSimulator.h.

Referenced by config(), and updateInternalData().

gmtl::Matrix44f vrj::PfBasicSimulator::mCameraPos [protected]

The data about the position of all this stuff.

Definition at line 138 of file PfBasicSimulator.h.

Referenced by getCameraPos(), and updateInternalData().

gmtl::Matrix44f vrj::PfBasicSimulator::mHeadPos [protected]

Definition at line 139 of file PfBasicSimulator.h.

Referenced by getHeadPos(), and updateInternalData().

gmtl::Matrix44f vrj::PfBasicSimulator::mWandPos [protected]

Definition at line 140 of file PfBasicSimulator.h.

Referenced by getWandPos(), and updateInternalData().

pfScene* vrj::PfBasicSimulator::mRootWithSim [protected]

The root with the simulator group & the sceneRoot.

Definition at line 142 of file PfBasicSimulator.h.

Referenced by configPerformerAPI(), and initSimulatorGraph().

pfGroup* vrj::PfBasicSimulator::mSimTree [protected]

The simulator scene graph.

Definition at line 146 of file PfBasicSimulator.h.

Referenced by initSimulatorGraph().

pfDCS* vrj::PfBasicSimulator::mHeadDCS [protected]

The DCS above the head.

Definition at line 147 of file PfBasicSimulator.h.

Referenced by initSimulatorGraph(), and updateSimulatorSceneGraph().

pfDCS* vrj::PfBasicSimulator::mWandDCS [protected]

The DCS above the wand.

Definition at line 148 of file PfBasicSimulator.h.

Referenced by initSimulatorGraph(), and updateSimulatorSceneGraph().

std::string vrj::PfBasicSimulator::mHeadModel [protected]

The head model file path.

Definition at line 149 of file PfBasicSimulator.h.

Referenced by configPerformerAPI(), and initSimulatorGraph().

std::string vrj::PfBasicSimulator::mWandModel [protected]

The wand model file path.

Definition at line 150 of file PfBasicSimulator.h.

Referenced by configPerformerAPI(), and initSimulatorGraph().


The documentation for this class was generated from the following files:
Generated on Thu Jan 4 10:58:26 2007 for VR Juggler by  doxygen 1.5.1