本文整理汇总了C++中TrackedButtonInteractionEvent类的典型用法代码示例。如果您正苦于以下问题:C++ TrackedButtonInteractionEvent类的具体用法?C++ TrackedButtonInteractionEvent怎么用?C++ TrackedButtonInteractionEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TrackedButtonInteractionEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processEvent
bool MicrobeBarGraphObject::processEvent(InteractionEvent * ie)
{
if(ie->asTrackedButtonEvent() && ie->asTrackedButtonEvent()->getButton() == 0 && (ie->getInteraction() == BUTTON_DOWN || ie->getInteraction() == BUTTON_DOUBLE_CLICK))
{
TrackedButtonInteractionEvent * tie = (TrackedButtonInteractionEvent*)ie;
GraphLayoutObject * layout = dynamic_cast<GraphLayoutObject*>(_parent);
if(!layout)
{
return false;
}
std::string selectedGroup;
std::vector<std::string> selectedKeys;
osg::Vec3 start, end(0,1000,0);
start = start * tie->getTransform() * getWorldToObjectMatrix();
end = end * tie->getTransform() * getWorldToObjectMatrix();
osg::Vec3 planePoint;
osg::Vec3 planeNormal(0,-1,0);
osg::Vec3 intersect;
float w;
bool clickUsed = false;
bool selectValid = false;
if(linePlaneIntersectionRef(start,end,planePoint,planeNormal,intersect,w))
{
if(_graph->processClick(intersect,selectedKeys,selectValid))
{
clickUsed = true;
}
}
if(selectValid && _microbeCount)
{
if(selectedKeys.size())
{
for(int i = 0; i < _microbeCount; ++i)
{
if(!strcmp(selectedKeys[0].c_str(),_microbeList[i].species))
{
selectedGroup = _microbeList[i].phylum;
break;
}
}
}
layout->selectMicrobes(selectedGroup,selectedKeys);
}
if(clickUsed)
{
return true;
}
}
return TiledWallSceneObject::processEvent(ie);
}
示例2: eventCallback
bool GraphKeyObject::eventCallback(InteractionEvent * ie)
{
TrackedButtonInteractionEvent * tie = ie->asTrackedButtonEvent();
if(tie)
{
if(tie->getButton() == 0 && (tie->getInteraction() == BUTTON_DOWN || tie->getInteraction() == BUTTON_DOUBLE_CLICK))
{
osg::Vec3 point1, point2(0,1000.0,0);
point1 = point1 * tie->getTransform() * getWorldToObjectMatrix();
point2 = point2 * tie->getTransform() * getWorldToObjectMatrix();
osg::Vec3 planePoint, planeNormal(0,-1,0), intersect;
float w;
if(linePlaneIntersectionRef(point1,point2,planePoint,planeNormal,intersect,w))
{
for(int i = 0; i < _rangeList.size(); ++i)
{
if(intersect.x() >= _rangeList[i].first && intersect.x() <= _rangeList[i].second)
{
std::string group = _labels[i];
std::vector<std::string> emptyList;
GraphLayoutObject * layout = dynamic_cast<GraphLayoutObject*>(_parent);
if(layout)
{
layout->selectPatients(group,emptyList);
}
return true;
}
}
}
}
}
return false;
}
示例3: switch
bool WaterMaze::processEvent(InteractionEvent * event)
{
KeyboardInteractionEvent * kie = event->asKeyboardEvent();
if (kie)
{
if (kie->getInteraction() == KEY_UP)
{
switch(kie->getKey())
{
case 'n':
//next paradigm
changeParadigm(1);
break;
case 'b':
changeParadigm(-1);
break;
case 'f':
//next trial
changeTrial(1);
break;
case 'a':
//override trial limit add trial
addTrial();
break;
case 's':
// start/abort trail and reset position
startStop();
break;
case 'l':
//load geometry
load();
break;
case 'i':
/* info */
cout << endl << endl;
//running state of application
cout << "Current Running State: " << _state << endl;
//Paradigm ID
cout << "Current Paradigm: " << _paradigms[_currentParadigm]->getID() << endl;
//trials ran
cout << "Trial: " << _paradigms[_currentParadigm]->getTrialNumber() << endl;
//android controller data
if(ComController::instance()->isMaster())
cout << "# of Connected Devices: " << _controller->getNumControllers() << endl;
//volume
cout << "Master Volume: " << _masterVolume << endl;
break;
case 'h':
//help menu
std::cout << "Welcome to WaterMaze!\n" <<
"l - load geometry\n" <<
"n - proceed to next paradigm\n" <<
"s - start/stop trial\n" <<
"f - proceed to next trial\n" <<
"a - override trial limit/add trial\n" <<
"i - info\n" <<
"h - help menu" << std::endl;
break;
case osgGA::GUIEventAdapter::KeySymbol::KEY_Up:
//raise master volume
cout << "Raising Volume" << endl;
_masterVolume = min(1.0, _masterVolume + 0.1);
for(int i = 0; i < _paradigms.size(); ++i)
{
_paradigms[i]->setVolume(_masterVolume);
}
break;
case osgGA::GUIEventAdapter::KeySymbol::KEY_Down:
//lower master volume
cout << "Lowering Volume" << endl;
_masterVolume = max(0.0, _masterVolume - 0.1);
for(int i = 0; i < _paradigms.size(); ++i)
{
_paradigms[i]->setVolume(_masterVolume);
}
break;
}
}
}
TrackedButtonInteractionEvent * tie = event->asTrackedButtonEvent();
if (tie)
{
if(tie->getHand() == 0 && tie->getButton() == 0)
{
if (tie->getInteraction() == BUTTON_DOWN && !_runningTrial)
{
return true;
}
else if (tie->getInteraction() == BUTTON_DRAG && !_runningTrial)
{
return true;
}
else if (tie->getInteraction() == BUTTON_UP)
{
return false;
}
return false;
}
}
//.........这里部分代码省略.........
示例4: processEvent
bool BubbleMenu::processEvent(InteractionEvent * event)
{
if(!_myMenu || !event->asTrackedButtonEvent())
{
return false;
}
TrackedButtonInteractionEvent * tie = event->asTrackedButtonEvent();
if(!_menuActive && !_showFavMenu)
{
if(_trigger == DOUBLECLICK)
{
if(event->getInteraction() == BUTTON_DOUBLE_CLICK)
{
if(tie->getButton() == _secondaryButton)
{
SceneManager::instance()->getMenuRoot()->addChild(_menuRoot);
if (!_showFavMenu)
{
SceneManager::instance()->getMenuRoot()->addChild(_favMenuRoot);
}
osg::Vec3 menuPoint = osg::Vec3(0, _distance, 0);
osg::Vec3 menuStartPos = osg::Vec3(0, _distance, _height);
menuPoint = menuStartPos;
if(event->asMouseEvent())
{
osg::Vec3 menuOffset = osg::Vec3(
_widthMap[_myMenu] / 2.0,0,0);
osg::Matrix m;
m.makeTranslate(menuPoint);
m.makeTranslate(menuStartPos);
_menuRoot->setMatrix(m);
}
else
{
osg::Vec3 viewerPoint =
TrackingManager::instance()->getHeadMat(0).getTrans();
osg::Vec3 viewerDir = viewerPoint - menuPoint;
viewerDir.z() = 0.0;
osg::Vec3 menuOffset = osg::Vec3(
_widthMap[_myMenu] * _scale / 2.0,0,0);
_menuRoot->setMatrix(osg::Matrix::translate(menuPoint));
}
_menuActive = true;
SceneManager::instance()->closeOpenObjectMenu();
return true;
}
}
}
else if(_trigger == UPCLICK)
{
return false;
}
}
else if (!_menuActive && _showFavMenu)
{
if(_trigger == DOUBLECLICK)
{
if(event->getInteraction() == BUTTON_DOUBLE_CLICK)
{
if(tie->getButton() == _secondaryButton)
{
SceneManager::instance()->getMenuRoot()->addChild(_menuRoot);
if (!_showFavMenu)
{
SceneManager::instance()->getMenuRoot()->addChild(_favMenuRoot);
}
osg::Vec3 menuPoint = osg::Vec3(0, _distance, 0);
osg::Vec3 menuStartPos = osg::Vec3(0, _distance, _height);
menuPoint = menuStartPos;
if(event->asMouseEvent())
{
osg::Vec3 menuOffset = osg::Vec3(
_widthMap[_myMenu] / 2.0,0,0);
osg::Matrix m;
m.makeTranslate(menuPoint);
m.makeTranslate(menuStartPos);
_menuRoot->setMatrix(m);
}
else
{
osg::Vec3 viewerPoint =
TrackingManager::instance()->getHeadMat(0).getTrans();
osg::Vec3 viewerDir = viewerPoint - menuPoint;
viewerDir.z() = 0.0;
//.........这里部分代码省略.........
示例5: processEvent
bool Sketch::processEvent(InteractionEvent * event)
{
TrackedButtonInteractionEvent * tie = event->asTrackedButtonEvent();
if(!tie)
{
return false;
}
if(tie->getHand() == 0 && tie->getButton() == 0)
{
if(_csCB->getValue())
{
if(_colorSelector->buttonEvent(tie->getInteraction(),
tie->getTransform()))
{
_color = _colorSelector->getColor();
if(_activeObject)
{
_activeObject->setColor(_color);
}
return true;
}
}
osg::Vec3 point(0,Sketch::instance()->getPointerDistance(),0);
point = point * TrackingManager::instance()->getHandMat(0);
osg::Vec3 distance;
if (!_freezeCB->getValue())
{
point = point * PluginHelper::getWorldToObjectTransform();
}
else
{
}
if (_snapToGridCB->getValue())
{
for (int i = 0; i < 3; ++i)
{
int diff = (int)floor(point[i]) % _gridSize;
point[i] -= diff;
}
distance = point - _lastPoint;
distance[0] = (int)distance[0];
distance[1] = (int)distance[1];
distance[2] = (int)distance[2];
}
else
{
distance = point - _lastPoint;
}
_lastPoint = point;
if (_mode == MOVE)
{
if (tie->getInteraction() == BUTTON_DOWN)
{
bool inSphere = false;
for (int i = 0; i < _shapeList.size(); ++i)
{
if (_shapeList[i]->containsPoint(_lastPoint))
{
_movingList.push_back(_shapeList[i]->getPat());
_movingLayout = false;
inSphere = true;
}
}
for (int i = 0; i < _layoutList.size(); ++i)
{
if (_layoutList[i]->shape->containsPoint(_lastPoint))
{
if (!inSphere)
{
_movingLayout = true;
_movingList.push_back(_layoutList[i]->getPat());
for (int j = 0; j < _layoutList[i]->children.size(); ++j)
{
_movingList.push_back(_layoutList[i]->children[j]);
}
}
}
}
return !_movingList.empty();
}
else if (tie->getInteraction() == BUTTON_DRAG)
{
for (int i = 0; i < _movingList.size(); ++i)
{
// remove child shapes that are dragged out of layouts
if (!_movingLayout)
{
//.........这里部分代码省略.........
示例6: processEvent
bool SceneObject::processEvent(InteractionEvent * ie)
{
TrackedButtonInteractionEvent * tie = ie->asTrackedButtonEvent();
if(tie)
{
if(_eventActive && _activeHand != tie->getHand())
{
return false;
}
if(_movable && tie->getButton() == _moveButton)
{
if(tie->getInteraction() == BUTTON_DOWN)
{
_lastHandInv = osg::Matrix::inverse(tie->getTransform());
_lastHandMat = tie->getTransform();
_lastobj2world = getObjectToWorldMatrix();
_eventActive = true;
_moving = true;
_activeHand = tie->getHand();
return true;
}
else if(_moving
&& (tie->getInteraction() == BUTTON_DRAG
|| tie->getInteraction() == BUTTON_UP))
{
processMove(tie->getTransform());
if(tie->getInteraction() == BUTTON_UP)
{
_eventActive = false;
_moving = false;
_activeHand = -2;
}
return true;
}
}
if(_contextMenu && tie->getButton() == _menuButton)
{
if(tie->getInteraction() == BUTTON_DOWN)
{
if(!_myMenu->isVisible())
{
_myMenu->setVisible(true);
osg::Vec3 start(0,0,0), end(0,1000,0);
start = start * tie->getTransform();
end = end * tie->getTransform();
osg::Vec3 p1, p2;
bool n1, n2;
float dist = 0;
if(intersects(start,end,p1,n1,p2,n2))
{
float d1 = (p1 - start).length();
if(n1)
{
d1 = -d1;
}
float d2 = (p2 - start).length();
if(n2)
{
d2 = -d2;
}
if(n1)
{
dist = d2;
}
else if(n2)
{
dist = d1;
}
else
{
if(d1 < d2)
{
dist = d1;
}
else
{
dist = d2;
}
}
}
dist = std::min(dist,
SceneManager::instance()->_menuMaxDistance);
dist = std::max(dist,
SceneManager::instance()->_menuMinDistance);
osg::Vec3 menuPoint(0,dist,0);
menuPoint = menuPoint * tie->getTransform();
osg::Vec3 viewerPoint =
TrackingManager::instance()->getHeadMat(0).getTrans();
osg::Vec3 viewerDir = viewerPoint - menuPoint;
viewerDir.z() = 0.0;
//.........这里部分代码省略.........
示例7: processEvent
bool Sketch::processEvent(InteractionEvent * event)
{
TrackedButtonInteractionEvent * tie = event->asTrackedButtonEvent();
if(!tie)
{
return false;
}
if(tie->getHand() == 0 && tie->getButton() == 0)
{
if(_csCB->getValue())
{
if(_colorSelector->buttonEvent(tie->getInteraction(), tie->getTransform()))
{
_color = _colorSelector->getColor();
if(_activeObject)
{
_activeObject->setColor(_color);
}
return true;
}
}
if(_activeObject)
{
bool ret = _activeObject->buttonEvent(tie->getInteraction(), tie->getTransform());
if(_activeObject->isDone())
{
finishGeometry();
createGeometry();
}
return ret;
}
}
/*if(hand == 0 && button == 0 && type == BUTTON_DOWN && _mode >= 0)
{
//std::cerr << "Start drawing." << std::endl;
if(_mode == RIBBON)
{
_verts = new Vec3Array(0);
_colors = new Vec4Array(1);
_normals = new Vec3Array(0);
_primitive = new DrawArrays(PrimitiveSet::TRIANGLE_STRIP, 0, 0);
_currentGeometry = new osg::Geometry();
(*_colors)[0] = _color;
_currentGeometry->setVertexArray(_verts);
_currentGeometry->setColorArray(_colors);
_currentGeometry->setNormalArray(_normals);
_currentGeometry->setNormalBinding(Geometry::BIND_PER_VERTEX);
_currentGeometry->setColorBinding(Geometry::BIND_OVERALL);
_currentGeometry->setUseDisplayList(false);
//_currentGeometry->setUseVertexBufferObjects(true);
_currentGeometry->addPrimitiveSet(_primitive);
_sketchGeode->addDrawable(_currentGeometry);
MyComputeBounds * mcb = new MyComputeBounds();
_currentBound = &mcb->_bound;
_currentGeometry->setComputeBoundingBoxCallback(mcb);
osg::Vec3 point(-50.0 * _sizeRV->getValue(), _pointerDistance, 0);
point = point * mat * PluginHelper::getWorldToObjectTransform();
_verts->push_back(point);
_normals->push_back(osg::Vec3(0,0,1));
_currentBound->expandBy(point);
point = osg::Vec3(50.0 * _sizeRV->getValue(), _pointerDistance, 0);
point = point * mat * PluginHelper::getWorldToObjectTransform();
_verts->push_back(point);
_normals->push_back(osg::Vec3(0,0,1));
_currentBound->expandBy(point);
_lastTransform = mat * PluginHelper::getWorldToObjectTransform();
_count = 2;
_primitive->setCount(_count);
_currentGeometry->dirtyBound();
_drawing = true;
}
else if(_mode == LINE)
{
if(_lt == LINE_NONE)
{
//std::cerr << "LINE_NONE" << std::endl;
return false;
}
if(!_drawing)
{
//std::cerr << "Starting Line." << std::endl;
_verts = new Vec3Array(0);
_colors = new Vec4Array(1);
_primitive = new DrawArrays(PrimitiveSet::LINE_STRIP, 0, 0);
//.........这里部分代码省略.........
示例8: processEvent
bool FPTiledWallSceneObject::processEvent(InteractionEvent * ie)
{
if(!_tiledWallMovement)
{
return SceneObject::processEvent(ie);
}
TrackedButtonInteractionEvent * tie = ie->asTrackedButtonEvent();
if(tie)
{
if(_eventActive && _activeHand != tie->getHand())
{
return false;
}
if(_movable && tie->getButton() == _moveButton)
{
//sort of a hack, need to find a better way to disable navigation for this object type
if(getNavigationOn())
{
setNavigationOn(false);
}
if(tie->getInteraction() == BUTTON_DOWN || (_moving
&& (tie->getInteraction() == BUTTON_DRAG
|| tie->getInteraction() == BUTTON_UP)))
{
if(tie->getInteraction() == BUTTON_DOWN)
{
osg::Vec3 lineP1,lineP2(0,1000.0,0),planePoint,planeNormal(0,-1,0);
float w;
lineP1 = lineP1 * tie->getTransform() * getWorldToObjectMatrix();
lineP2 = lineP2 * tie->getTransform() * getWorldToObjectMatrix();
linePlaneIntersectionRef(lineP1,lineP2,planePoint,planeNormal,_movePoint,w);
_eventActive = true;
_moving = true;
_activeHand = tie->getHand();
return true;
}
if(!_moving)
{
return false;
}
// top level
if(!_parent)
{
osg::Vec3 wallPoint;
if(SceneManager::instance()->getPointOnTiledWall(tie->getTransform(),wallPoint))
{
osg::Vec3 soPoint = _movePoint * getObjectToWorldMatrix();
osg::Matrix m;
m.makeTranslate(wallPoint - soPoint);
setTransform(getTransform() * m);
}
}
else
{
osg::Vec3 lineP1,lineP2(0,1000.0,0),planePoint,planeNormal(0,-1,0),intersect;
float w;
lineP1 = lineP1 * tie->getTransform() * _parent->getWorldToObjectMatrix();
lineP2 = lineP2 * tie->getTransform() * _parent->getWorldToObjectMatrix();
if(linePlaneIntersectionRef(lineP1,lineP2,planePoint,planeNormal,intersect,w))
{
osg::Vec3 soPoint = _movePoint * getTransform();
osg::Matrix m;
m.makeTranslate(intersect - soPoint);
setTransform(getTransform() * m);
}
}
if(tie->getInteraction() == BUTTON_UP)
{
_eventActive = false;
_moving = false;
_activeHand = -2;
}
return true;
}
}
}
return SceneObject::processEvent(ie);
}
示例9: getHandButtonMask
void TrackingManager::generateButtonEvents()
{
int numEvents;
TrackedButtonInteractionEvent * events = NULL;
if(ComController::instance()->isMaster())
{
std::vector<TrackedButtonInteractionEvent*> eventList;
for(int j = 0; j < _numHands; j++)
{
unsigned int bit = 1;
unsigned int newMask = getHandButtonMask(j);
//std::cerr << "ButtonMask: " << newMask << std::endl;
for(int i = 0; i < _genHandDefaultButtonEvents[j].size(); i++)
{
if(!_genHandDefaultButtonEvents[j][i])
{
bit = bit << 1;
continue;
}
//std::cerr << "last mask " << _lastButtonMask << " new mask " << newMask << " bit: " << bit << " " << (newMask & bit) << " " << (_lastButtonMask & bit) << std::endl;
if(((_lastHandButtonMask[j] & bit) != (newMask & bit))
|| ((_lastHandButtonMask[j] & bit) && (newMask & bit)))
{
//std::cerr << "last mask " << _lastButtonMask << " new mask " << newMask << std::endl;
TrackedButtonInteractionEvent * buttonEvent =
new TrackedButtonInteractionEvent();
if((_lastHandButtonMask[j] & bit) && (newMask & bit))
{
buttonEvent->setInteraction(BUTTON_DRAG);
}
else if(_lastHandButtonMask[j] & bit)
{
buttonEvent->setInteraction(BUTTON_UP);
}
else
{
buttonEvent->setInteraction(BUTTON_DOWN);
}
buttonEvent->setButton(i);
// set current pointer info
buttonEvent->setTransform(_handMatList[j]);
buttonEvent->setHand(j);
eventList.push_back(buttonEvent);
}
bit = bit << 1;
}
_lastHandButtonMask[j] = newMask;
}
numEvents = eventList.size();
ComController::instance()->sendSlaves(&numEvents,sizeof(int));
if(numEvents)
{
events = new TrackedButtonInteractionEvent[numEvents];
for(int i = 0; i < numEvents; i++)
{
events[i] = *eventList[i];
delete eventList[i];
}
ComController::instance()->sendSlaves(events,
numEvents * sizeof(TrackedButtonInteractionEvent));
}
}
else
{
ComController::instance()->readMaster(&numEvents,sizeof(int));
if(numEvents)
{
events = new TrackedButtonInteractionEvent[numEvents];
ComController::instance()->readMaster(events,
numEvents * sizeof(TrackedButtonInteractionEvent));
}
}
TrackedButtonInteractionEvent * ie;
for(int i = 0; i < numEvents; i++)
{
ie = new TrackedButtonInteractionEvent();
*ie = events[i];
InteractionManager::instance()->addEvent(ie);
}
if(events)
{
delete[] events;
}
}
示例10: clear
//.........这里部分代码省略.........
if (_runningTrial)
{
std::cout << "Stopping trial." << std::endl;
_runningTrial = false;
_resetTime = true;
}
else
{
std::cout << "Starting trial." << std::endl;
_runningTrial = true;
}
}
else if (kie->getInteraction() == KEY_UP && kie->getKey() == 'l')
{
std::cout << "Loading geometry." << std::endl;
load(_trials[_currentTrial].width, _trials[_currentTrial].height);
}
else if (kie->getInteraction() == KEY_UP && kie->getKey() == 'h')
{
std::cout << "Welcome to WaterMaze!\n" <<
"l - load geometry\n" <<
"n - next trial\n" <<
"r - repeat trial\n" <<
"b - back to previous trial\n" <<
"p - play/pause\n" <<
"h - help\n" <<
"1-9 - reset position" << std::endl;
}
else if (kie->getInteraction() == KEY_UP && kie->getKey() == '1')
{
if (_runningTrial)
{
return true;
}
osg::Matrixd mat;
mat = _tilePositions[0]->getMatrix();
PluginHelper::setObjectMatrix(mat);
}
else if (kie->getInteraction() == KEY_UP && kie->getKey() == '2')
{
if (_runningTrial)
{
return true;
}
osg::Matrixd mat;
mat = _tilePositions[1]->getMatrix();
PluginHelper::setObjectMatrix(mat);
}
else if (kie->getInteraction() == KEY_UP && kie->getKey() == '3')
{
if (_runningTrial)
{
return true;
}
osg::Matrixd mat;
mat = _tilePositions[2]->getMatrix();
PluginHelper::setObjectMatrix(mat);
}
else if (kie->getInteraction() == KEY_UP && kie->getKey() == '4')
{
if (_runningTrial)
{
return true;
}
osg::Matrixd mat;
mat = _tilePositions[3]->getMatrix();
PluginHelper::setObjectMatrix(mat);
}
}
TrackedButtonInteractionEvent * tie = event->asTrackedButtonEvent();
if (tie)
{
return false;
if(tie->getHand() == 0 && tie->getButton() == 0)
{
if (tie->getInteraction() == BUTTON_DOWN)
{
return true;
}
else if (tie->getInteraction() == BUTTON_DRAG)
{
return true;
}
else if (tie->getInteraction() == BUTTON_UP)
{
return true;
}
return true;
}
}
return true;
}
示例11: if
void BoardMenuListGeometry::processEvent(InteractionEvent * event)
{
if(event->getInteraction() == BUTTON_UP)
{
_geodeSelected->removeDrawables(0,_geodeSelected->getNumDrawables());
_geodeSelected->addDrawable(_valuesSelected[_listItem->getFocus()]);
_clicked = false;
_listItem->setDirty(true);
}
if(event->asMouseEvent())
{
MouseInteractionEvent * mie = event->asMouseEvent();
if(event->getInteraction() == BUTTON_DOWN
|| event->getInteraction() == BUTTON_DOUBLE_CLICK)
{
int y = mie->getY();
_lastMouseY = y;
_clicked = true;
_listItem->setDirty(true);
return;
}
if(event->getInteraction() == BUTTON_DRAG
|| event->getInteraction() == BUTTON_UP)
{
int y = mie->getY();
float pixelRange = 400;
bool valueUpdated = false;
int valueMax = _listItem->getListSize();
int index = _listItem->getIndex();
if(y != _lastMouseY)
{
int change = (int)((y - _lastMouseY)
* _listItem->getSensitivity() / pixelRange);
if(change)
{
index -= change;
if(index > valueMax)
index = valueMax;
else if(index < 0)
index = 0;
_listItem->setIndex(index);
valueUpdated = true;
}
}
if(valueUpdated)
{
if(_listItem->getCallback())
{
_listItem->getCallback()->menuCallback(_item);
}
_lastMouseY = y;
}
return;
}
}
else if(event->asTrackedButtonEvent())
{
TrackedButtonInteractionEvent * tie = event->asTrackedButtonEvent();
if(event->getInteraction() == BUTTON_DOWN
|| event->getInteraction() == BUTTON_DOUBLE_CLICK)
{
_point = tie->getTransform().getTrans();
_lastDistance = 0.0;
_clicked = true;
_listItem->setDirty(true);
return;
}
if(event->getInteraction() == BUTTON_DRAG
|| event->getInteraction() == BUTTON_UP)
{
MenuList * _listItem = (MenuList*)_item;
osg::Vec3 vec = tie->getTransform().getTrans();
;
vec = vec - _point;
float newDistance = vec.z();
float range = 400;
bool valueUpdated = false;
int valueMax = _listItem->getListSize();
int index = _listItem->getIndex();
if(newDistance != _lastDistance)
{
int change = (int)((newDistance - _lastDistance)
* _listItem->getSensitivity() / range);
if(change)
{
index -= change;
if(index > valueMax)
//.........这里部分代码省略.........
示例12: processEvent
bool BoardPopupMenu::processEvent(InteractionEvent * event)
{
if(!_menuActive || !_myMenu || !event->asTrackedButtonEvent())
{
return false;
}
TrackedButtonInteractionEvent * tie = event->asTrackedButtonEvent();
if(_clickActive)
{
if(tie->getHand() == _activeHand)
{
if(tie->getInteraction() == BUTTON_DRAG
|| tie->getInteraction() == BUTTON_UP)
{
if(tie->getButton() == _primaryButton)
{
BoardMenuSubMenuGeometry * smg =
dynamic_cast<BoardMenuSubMenuGeometry *>(_activeItem);
if(smg && smg->isMenuHead())
{
updateMovement(tie);
}
_activeItem->processEvent(event);
if(tie->getInteraction() == BUTTON_UP)
{
_clickActive = false;
}
return true;
}
}
}
return false;
}
else if(tie->getHand() == _activeHand && tie->getButton() == _primaryButton)
{
if(tie->getInteraction() == BUTTON_DOWN
|| tie->getInteraction() == BUTTON_DOUBLE_CLICK)
{
if(_activeItem)
{
BoardMenuSubMenuGeometry * smg =
dynamic_cast<BoardMenuSubMenuGeometry *>(_activeItem);
if(smg && smg->isMenuHead())
{
osg::Vec3 ray;
ray = _currentPoint[tie->getHand()]
- tie->getTransform().getTrans();
if(!tie->asPointerEvent())
{
_moveDistance = ray.length();
}
else
{
_moveDistance = ray.y();
}
_menuPoint = _currentPoint[tie->getHand()]
* osg::Matrix::inverse(_menuRoot->getMatrix());
updateMovement(tie);
}
else if(smg && !smg->isMenuHead())
{
if(smg->isMenuOpen())
{
closeMenu((SubMenu*)smg->getMenuItem());
}
else
{
openMenu(smg);
}
}
_clickActive = true;
_activeItem->processEvent(event);
return true;
}
return false;
}
}
return false;
}
示例13: if
//.........这里部分代码省略.........
for(int i = 0; i < _handButtonList.size(); i++)
{
std::cerr << "Button: " << i << " hand: " << _handButtonList[i].first << " handButton: " << _handButtonList[i].second << " valid: " << _handValidList[i] << std::endl;
}
}
}
_handListInit = true;
}
osg::Matrix m = InteractionManager::instance()->getMouseMat();
osg::Vec3 pos = m.getTrans();
osg::Quat rot = m.getRotate();
_mouseBody.x = pos.x();
_mouseBody.y = pos.y();
_mouseBody.z = pos.z();
_mouseBody.qx = rot.x();
_mouseBody.qy = rot.y();
_mouseBody.qz = rot.z();
_mouseBody.qw = rot.w();
_mouseButtonMask = InteractionManager::instance()->getMouseButtonMask();
int mouseWheel = InteractionManager::instance()->getMouseWheel();
if(mouseWheel > 0)
{
_mouseValuator = 1.0;
}
else if(mouseWheel < 0)
{
_mouseValuator = -1.0;
}
else
{
_mouseValuator = 0.0;
}
if(!_handButtonList.size())
{
return;
}
std::queue<InteractionEvent *,std::list<InteractionEvent *> > tempQueue;
//std::cerr << "Mouse queue size: " << InteractionManager::instance()->_mouseQueue.size() << std::endl;
while(InteractionManager::instance()->_mouseQueue.size())
{
MouseInteractionEvent * mie = dynamic_cast<MouseInteractionEvent*>(InteractionManager::instance()->_mouseQueue.front());
if(!mie)
{
tempQueue.push(InteractionManager::instance()->_mouseQueue.front());
InteractionManager::instance()->_mouseQueue.pop();
continue;
}
InteractionManager::instance()->_mouseQueue.pop();
if(mie->getButton() < 0 || mie->getButton() >= _handButtonList.size() || !_handValidList[mie->getButton()])
{
tempQueue.push(mie);
continue;
}
InteractionEvent * event;
if(TrackingManager::instance()->getHandTrackerType(_handButtonList[mie->getButton()].first) == TrackerBase::MOUSE)
{
mie->setHand(_handButtonList[mie->getButton()].first);
mie->setButton(_handButtonList[mie->getButton()].second);
event = mie;
}
else
{
TrackedButtonInteractionEvent * tie = new TrackedButtonInteractionEvent;
tie->setInteraction(mie->getInteraction());
tie->setHand(_handButtonList[mie->getButton()].first);
tie->setButton(_handButtonList[mie->getButton()].second);
int hsystem, hindex;
TrackingManager::instance()->getHandAddress(_handButtonList[mie->getButton()].first,hsystem,hindex);
if(TrackingManager::instance()->getTrackingSystem(hsystem))
{
TrackerBase::TrackedBody * body = TrackingManager::instance()->getTrackingSystem(hsystem)->getBody(hindex);
tie->setTransform(TrackingManager::instance()->getHandTransformFromTrackedBody(_handButtonList[mie->getButton()].first,body));
}
delete mie;
event = tie;
}
eventMap[event->getEventType()].push_back(event);
}
// put unusable events back in the mouse interaction queue so they will be cleaned up later
while(tempQueue.size())
{
InteractionManager::instance()->_mouseQueue.push(tempQueue.front());
tempQueue.pop();
}
}
示例14: log
//.........这里部分代码省略.........
float change = (x - _lastMouseX) * (max - min) / pixelRange;
float newValue;
if(mrv->getIsLog())
{
newValue = pow(mrv->getLogBase(),current + change);
newValue = std::min(newValue,mrv->getMax());
}
else
{
newValue = std::min(mrv->getValue() + change,
mrv->getMax());
}
mrv->setValue(newValue);
valueUpdated = true;
}
}
if(valueUpdated)
{
if(mrv->getCallback())
{
mrv->getCallback()->menuCallback(_item);
}
}
_lastMouseY = y;
_lastMouseX = x;
return;
}
}
else if(event->asTrackedButtonEvent())
{
TrackedButtonInteractionEvent * tie = event->asTrackedButtonEvent();
if(event->getInteraction() == BUTTON_DOWN
|| event->getInteraction() == BUTTON_DOUBLE_CLICK)
{
_point = tie->getTransform().getTrans();
osg::Vec3 forward = osg::Vec3(0,1.0,0) * tie->getTransform();
forward = forward - _point;
_normal = forward ^ osg::Vec3(0,0,1.0);
_normal.normalize();
_lastDistance = 0.0;
return;
}
if(event->getInteraction() == BUTTON_DRAG
|| event->getInteraction() == BUTTON_UP)
{
MenuRangeValueCompact * mrv = (MenuRangeValueCompact*)_item;
float min, max, current;
if(mrv->getIsLog())
{
min = log(mrv->getMin()) / log(mrv->getLogBase());
max = log(mrv->getMax()) / log(mrv->getLogBase());
current = log(mrv->getValue()) / log(mrv->getLogBase());
}
else
{
min = mrv->getMin();
max = mrv->getMax();
current = mrv->getValue();
}
osg::Vec3 vec = tie->getTransform().getTrans();
示例15: TrackedButtonInteractionEvent
void TrackingManager::generateThreadButtonEvents()
{
TrackedButtonInteractionEvent * buttonEvent;
for(int j = 0; j < _numHands; j++)
{
unsigned int bit = 1;
unsigned int newMask = _threadHandButtonMasks[j];
//std::cerr << "ButtonMask: " << newMask << std::endl;
for(int i = 0; i < _genHandDefaultButtonEvents[j].size(); i++)
{
if(!_genHandDefaultButtonEvents[j][i])
{
bit = bit << 1;
continue;
}
//std::cerr << "last mask " << _lastButtonMask << " new mask " << newMask << " bit: " << bit << " " << (newMask & bit) << " " << (_lastButtonMask & bit) << std::endl;
if((_threadLastHandButtonMask[j] & bit) != (newMask & bit))
{
buttonEvent = new TrackedButtonInteractionEvent();
//std::cerr << "last mask " << _lastButtonMask << " new mask " << newMask << std::endl;
if(_threadLastHandButtonMask[j] & bit)
{
buttonEvent->setInteraction(BUTTON_UP);
}
else
{
buttonEvent->setInteraction(BUTTON_DOWN);
}
buttonEvent->setButton(i);
// set current pointer info
if(getIsHandThreaded(j))
{
buttonEvent->setTransform(_threadHandMatList[j]);
}
else
{
buttonEvent->setTransform(_handMatList[j]);
}
buttonEvent->setHand(j);
//_threadEvents.push((InteractionEvent*)buttonEvent);
genComTrackEvents->processEvent(buttonEvent);
}
else if((_threadLastHandButtonMask[j] & bit) && (newMask & bit))
{
buttonEvent = new TrackedButtonInteractionEvent();
buttonEvent->setInteraction(BUTTON_DRAG);
buttonEvent->setButton(i);
// set current pointer info
if(getIsHandThreaded(j))
{
buttonEvent->setTransform(_threadHandMatList[j]);
}
else
{
buttonEvent->setTransform(_handMatList[j]);
}
buttonEvent->setHand(j);
//_threadEvents.push((InteractionEvent*)buttonEvent);
genComTrackEvents->processEvent(buttonEvent);
}
bit = bit << 1;
}
_threadLastHandButtonMask[j] = newMask;
}
}