bool CreateBrushTool::handleStartPlaneDrag(InputState& inputState, Planef& plane, Vec3f& initialPoint) { assert(m_brush == NULL); Model::EditStateManager& editStateManager = document().editStateManager(); if (inputState.mouseButtons() != MouseButtons::MBLeft || inputState.modifierKeys() != ModifierKeys::MKNone || editStateManager.selectionMode() != Model::EditStateManager::SMNone) return false; Model::FaceHit* hit = static_cast<Model::FaceHit*>(inputState.pickResult().first(Model::HitType::FaceHit, true, m_filter)); if (hit != NULL) { initialPoint = hit->hitPoint(); } else { Renderer::Camera& camera = view().camera(); initialPoint = camera.defaultPoint(inputState.pickRay().direction); } plane = Planef(Vec3f::PosZ, initialPoint); m_initialPoint = initialPoint; updateBounds(m_initialPoint); Preferences::PreferenceManager& prefs = Preferences::PreferenceManager::preferences(); Renderer::TextureRendererManager& textureRendererManager = document().sharedResources().textureRendererManager(); m_brushFigure = new Renderer::BrushFigure(textureRendererManager); m_brushFigure->setFaceColor(prefs.getColor(Preferences::FaceColor)); m_brushFigure->setEdgeColor(prefs.getColor(Preferences::SelectedEdgeColor)); m_brushFigure->setOccludedEdgeColor(prefs.getColor(Preferences::OccludedSelectedEdgeColor)); m_brushFigure->setEdgeMode(Renderer::BrushFigure::EMRenderOccluded); m_brush = new Model::Brush(document().map().worldBounds(), document().map().forceIntegerFacePoints(), m_bounds, document().mruTexture()); m_brushFigure->setBrush(*m_brush); return true; }
void CreateEntityTool::updateEntityPosition(InputState& inputState) { assert(m_entity != NULL); Utility::Grid& grid = document().grid(); Model::FaceHit* hit = static_cast<Model::FaceHit*>(inputState.pickResult().first(Model::HitType::FaceHit, true, view().filter())); Vec3f delta; if (hit == NULL) { Vec3f newPosition = inputState.camera().defaultPoint(inputState.pickRay().direction); const Vec3f& center = m_entity->bounds().center(); delta = grid.moveDeltaForEntity(center, document().map().worldBounds(), newPosition - center); } else { Model::Face& face = hit->face(); delta = grid.moveDeltaForEntity(face, m_entity->bounds(), document().map().worldBounds(), inputState.pickRay(), hit->hitPoint()); } if (delta.null()) return; m_entity->setProperty(Model::Entity::OriginKey, m_entity->origin() + delta, true); m_entityFigure->invalidate(); }