//--------------------------------------------- void EntRainDrop::Render() { if( IsInGame() ) { DrawFunction::Gotoxy( NUMBER_OF_SPACES + GetPositionInWorld(), GROUND_HEIGHT - m_timeOfLive ); DrawFunction::PrintSimbolInWorld( SYMBOL_RAIN ); } }
//--------------------------------------------- void EntHero::Render() { if( IsInGame() && m_alive ) { DrawFunction::Gotoxy( NUMBER_OF_SPACES + GetPositionInWorld(), GROUND_HEIGHT ); DrawFunction::PrintSimbolInWorld( SYMBOL_HERO ); } }
//--------------------------------------------- void EntHero::Update() { switch( m_direction ) { case RightDirection: if( GetPositionInWorld() < WORLD_WIDTH - 1 ) { MoveRight(); } break; case LeftDirection: if( GetPositionInWorld() > 0 ) { MoveLeft(); } break; default: break; } }
//--------------------------------------------- void EntBullet::Update() { if( GetPositionInWorld() < 1 || GetPositionInWorld() > WORLD_WIDTH - 1 ) { SetIsInGame( false ); } else { switch( m_direction ) { case RightDirection: MoveRight(); break; case LeftDirection: MoveLeft(); break; default: break; } } }
// The state machine is wired up with this Paint method. We wrote a few helper // functions at the top of this files to keep this method clear and easy to // read. void ExampleImageInteractor::Paint(mitk::StateMachineAction*, mitk::InteractionEvent* event) { try { auto renderer = event->GetSender(); auto image = GetImage(this->GetDataNode()); auto timeStep = renderer->GetTimeStep(); auto geometry = GetGeometry(image, timeStep); // This method is wired up to mouse events. Thus, we can safely assume // that the following cast will succeed and we have access to the mouse // position and the first intersection point of a ray originating at the // mouse position and shot into the scene. Convenient, isn't it? :-) auto positionEvent = dynamic_cast<mitk::InteractionPositionEvent*>(event); auto position = positionEvent->GetPositionInWorld(); if (!geometry->IsInside(position)) return; // Nothing to paint, as we're not inside the image bounds. // Okay, we're safe. Convert the mouse position to the index of the pixel // we're pointing at. itk::Index<3> index; geometry->WorldToIndex<3>(position, index); // We don't need to paint over and over again while moving the mouse // pointer inside the same pixel. That's especially relevant when operating // on zoomed images. if (index != m_LastPixelIndex) { // And finally... ::Paint(image, index, timeStep); // Nearly done. We request the renderer to update the render window in // order to see the result immediately. Actually, we should update all // of the render windows by caling RequestUpdateAll() instead, as the // painted pixels are possibly visible in other render windows, too. // However, we decided to prefer performance here. mitk::RenderingManager::GetInstance()->RequestUpdate(positionEvent->GetSender()->GetRenderWindow()); MITK_INFO << index[0] << " " << index[1] << " " << index[2]; m_LastPixelIndex = index; } } catch (...) { return; } }
//--------------------------------------------- void EntBullet::Render() { if( IsInGame() ) { DrawFunction::Gotoxy( NUMBER_OF_SPACES + GetPositionInWorld(), GROUND_HEIGHT ); if( m_direction == RightDirection ) { DrawFunction::PrintSimbolInWorld( SYMBOL_BULLET_RIGHT ); } else if( LeftDirection ) { DrawFunction::PrintSimbolInWorld( SYMBOL_BULLET_LEFT ); } } }
std::string mitk::EventFactory::EventToXML(mitk::InteractionEvent *event) { InternalEvent* ie = dynamic_cast<InternalEvent*> (event); if (ie != NULL) return ""; std::string eventClass = event->GetNameOfClass(); std::string eventXML = "<" + InteractionEventConst::xmlTagEventVariant() + " " + InteractionEventConst::xmlParameterEventClass() + "=\""; std::transform(eventClass.cbegin(), eventClass.cend(), eventClass.begin(), ::toupper); eventXML += eventClass + "\" >\n"; // here follow event specific attributes if (eventClass == "MOUSEPRESSEVENT" || eventClass == "MOUSERELEASEEVENT" || eventClass == "MOUSEDOUBLECLICKEVENT" || eventClass == "MOUSEMOVEEVENT" || eventClass == "MOUSEWHEELEVENT") { if (!(eventClass == "MOUSEMOVEEVENT") && !(eventClass == "MOUSEWHEELEVENT")) { // EventButton eventXML += " <" + InteractionEventConst::xmlTagAttribute() +" " + InteractionEventConst::xmlParameterName() + "=\"" + InteractionEventConst::xmlEventPropertyEventButton() + "\" "; eventXML += InteractionEventConst::xmlParameterValue() + "=\""; eventXML += GetEventButton(event); eventXML += "\"/>\n"; } // ButtonState if (GetButtonState(event) != "") { eventXML += " <" + InteractionEventConst::xmlTagAttribute() +" " + InteractionEventConst::xmlParameterName() + "=\"" + InteractionEventConst::xmlEventPropertyButtonState() + "\" "; eventXML += InteractionEventConst::xmlParameterValue() + "=\""; eventXML += GetButtonState(event); eventXML += "\"/>\n"; } // Modifiers if (GetModifierState(event) != "") { eventXML += " <" + InteractionEventConst::xmlTagAttribute() +" " + InteractionEventConst::xmlParameterName() + "=\"" + InteractionEventConst::xmlEventPropertyModifier() + "\" "; eventXML += InteractionEventConst::xmlParameterValue() + "=\""; eventXML += GetModifierState(event); eventXML += "\"/>\n"; } // Position on Screen eventXML += " <" + InteractionEventConst::xmlTagAttribute() +" " + InteractionEventConst::xmlParameterName() + "=\"" + InteractionEventConst::xmlEventPropertyPositionOnScreen() + "\" "; eventXML += InteractionEventConst::xmlParameterValue() + "=\""; eventXML += GetPositionOnScreen(event); eventXML += "\"/>\n"; // Position in World eventXML += " <" + InteractionEventConst::xmlTagAttribute() +" " + InteractionEventConst::xmlParameterName() + "=\"" + InteractionEventConst::xmlEventPropertyPositionInWorld() + "\" "; eventXML += InteractionEventConst::xmlParameterValue() + "=\""; eventXML += GetPositionInWorld(event); eventXML += "\"/>\n"; } else if (eventClass == "INTERACTIONKEYEVENT") { mitk::InteractionKeyEvent* ke = dynamic_cast<mitk::InteractionKeyEvent*>(event); // key eventXML += " <" + InteractionEventConst::xmlTagAttribute() +" " + InteractionEventConst::xmlParameterName() + "=\"" + InteractionEventConst::xmlEventPropertyKey() + "\" "; eventXML += InteractionEventConst::xmlParameterValue() + "=\""; eventXML += ke->GetKey(); eventXML += "\"/>\n"; } else { MITK_WARN << "Event not recognized, discarding event of type " << event->GetNameOfClass(); } if (eventClass == "MOUSEWHEELEVENT") { MouseWheelEvent* we = dynamic_cast<MouseWheelEvent*> (event); int delta = we->GetWheelDelta(); std::stringstream ss; ss << delta; eventXML += " <" + InteractionEventConst::xmlTagAttribute() +" " + InteractionEventConst::xmlParameterName() + "=\"" + InteractionEventConst::xmlEventPropertyWheelDelta() + "\" "; eventXML += InteractionEventConst::xmlParameterValue() + "=\""; eventXML += ss.str(); eventXML += "\"/>\n"; eventXML += " <" + InteractionEventConst::xmlTagAttribute() +" " + InteractionEventConst::xmlParameterName() + "=\"" + InteractionEventConst::xmlEventPropertyScrollDirection() + "\" "; eventXML += InteractionEventConst::xmlParameterValue() + "=\""; eventXML += delta < 0 ? "DOWN" : "UP"; eventXML += "\"/>\n"; } // Renderer name eventXML += " <" + InteractionEventConst::xmlTagAttribute() +" " + InteractionEventConst::xmlParameterName() + "=\"" + InteractionEventConst::xmlEventPropertyRendererName() + "\" "; eventXML += InteractionEventConst::xmlParameterValue() + "=\""; eventXML += event->GetSender()->GetName(); eventXML += "\"/>\n"; // closing tag: eventXML += "</" + InteractionEventConst::xmlTagEventVariant() + ">"; return eventXML; }
bool mitk::GizmoInteractor::HasPickedHandle(const InteractionEvent* interactionEvent) { auto positionEvent = dynamic_cast<const InteractionPositionEvent*>(interactionEvent); if(positionEvent == NULL) { return false; } DataNode::Pointer gizmoNode = this->GetDataNode(); if (m_Gizmo.IsNull()) { return false; } if (m_ManipulatedObjectGeometry.IsNull()) { return false; } if (interactionEvent->GetSender()->GetRenderWindow()->GetNeverRendered()) { return false; } if (interactionEvent->GetSender()->GetMapperID() == BaseRenderer::Standard2D) { m_PickedHandle = PickFrom2D(positionEvent); } else { m_PickedHandle = PickFrom3D(positionEvent); } if (m_PickedHandle != Gizmo::NoHandle) { // if something relevant was picked, we calculate a number of // important points and axes for the upcoming geometry manipulations // note initial state m_InitialClickPosition2D = positionEvent->GetPointerPositionOnScreen(); m_InitialClickPosition3D = positionEvent->GetPositionInWorld(); auto renderer = positionEvent->GetSender()->GetVtkRenderer(); renderer->SetWorldPoint(m_InitialClickPosition3D[0], m_InitialClickPosition3D[1], m_InitialClickPosition3D[2], 0); renderer->WorldToDisplay(); m_InitialClickPosition2DZ = renderer->GetDisplayPoint()[2]; m_InitialGizmoCenter3D = m_Gizmo->GetCenter(); positionEvent->GetSender()->WorldToDisplay( m_InitialGizmoCenter3D, m_InitialGizmoCenter2D ); m_InitialManipulatedObjectGeometry = m_ManipulatedObjectGeometry->Clone(); switch (m_PickedHandle) { case Gizmo::MoveAlongAxisX: case Gizmo::RotateAroundAxisX: case Gizmo::ScaleX: m_AxisOfMovement = m_InitialManipulatedObjectGeometry->GetAxisVector(0); break; case Gizmo::MoveAlongAxisY: case Gizmo::RotateAroundAxisY: case Gizmo::ScaleY: m_AxisOfMovement = m_InitialManipulatedObjectGeometry->GetAxisVector(1); break; case Gizmo::MoveAlongAxisZ: case Gizmo::RotateAroundAxisZ: case Gizmo::ScaleZ: m_AxisOfMovement = m_InitialManipulatedObjectGeometry->GetAxisVector(2); break; default: break; } m_AxisOfMovement.Normalize(); m_AxisOfRotation = m_AxisOfMovement; // for translation: test whether the user clicked into the "object's real" axis direction // or into the other one Vector3D intendedAxis = m_InitialClickPosition3D - m_InitialGizmoCenter3D; if ( intendedAxis * m_AxisOfMovement < 0 ) { m_AxisOfMovement *= -1.0; } // for rotation: test whether the axis of rotation is more looking in the direction // of the camera or in the opposite vtkCamera* camera = renderer->GetActiveCamera(); vtkVector3d cameraDirection( camera->GetDirectionOfProjection() ); double angle_rad = vtkMath::AngleBetweenVectors( cameraDirection.GetData(), m_AxisOfRotation.GetDataPointer() ); if ( angle_rad < vtkMath::Pi() / 2.0 ) { m_AxisOfRotation *= -1.0; } return true; } else { return false; } }