/// @copydoc Entity::Attach() void Camera::Attach() { Base::Attach(); // Update the scene view associated with this camera. if( IsValid( m_sceneViewId ) ) { World* pWorld = GetWorld(); HELIUM_ASSERT( pWorld ); GraphicsScene* pScene = pWorld->GetGraphicsScene(); if( pScene ) { GraphicsSceneView* pSceneView = pScene->GetSceneView( m_sceneViewId ); if( pSceneView ) { Simd::Matrix44 rotationMatrix( Simd::Matrix44::INIT_ROTATION, GetRotation() ); pSceneView->SetView( GetPosition(), Vector4ToVector3( rotationMatrix.GetRow( 2 ) ), Vector4ToVector3( rotationMatrix.GetRow( 1 ) ) ); pSceneView->SetHorizontalFov( m_fov ); } } } }
void Viewport::OnResize() { const uint32_t width = (m_Size.x > 0) ? m_Size.x : 64; const uint32_t height = (m_Size.y > 0) ? m_Size.y : 64; const float32_t aspectRatio = static_cast< float32_t >( width ) / static_cast< float32_t >( height ); if (m_World) { Renderer* pRenderer = Renderer::GetStaticInstance(); Renderer::ContextInitParameters ctxParams; ctxParams.pWindow = m_Window; ctxParams.displayWidth = width; ctxParams.displayHeight = height; ctxParams.bFullscreen = false; ctxParams.bVsync = false; RRenderContextPtr renderCtx = pRenderer->CreateSubContext( ctxParams ); GraphicsScene* pGraphicsScene = GetGraphicsScene(); GraphicsSceneView* pSceneView = pGraphicsScene->GetSceneView( m_SceneViewId ); pSceneView->SetRenderContext( renderCtx ); pSceneView->SetDepthStencilSurface( RenderResourceManager::GetStaticInstance().GetDepthStencilSurface() ); pSceneView->SetAspectRatio( aspectRatio ); pSceneView->SetViewport( 0, 0, width, height ); pSceneView->SetClearColor( Helium::Color( 0x00505050 ) ); } }
void GraphicsScene::UpdateCallback( void *param, u32 begin, u32 end ) { // ASSERT ( dynamic_cast<GraphicsScene*>(param)); GraphicsScene* pThis = static_cast<GraphicsScene*>(param); pThis->ProcessRange( begin, end ); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); //connect signals of GUI elements with slots of this class connectSignalSlots(); //hide advanced settings and connect signals/slots to show them hideAdvancedSettings(); //initialize graphicsview GraphicsScene *scene = new GraphicsScene(); ui->graphicsView->setScene(scene); scene->setBackgroundBrush(QBrush(Qt::darkGray)); ui->graphicsView->setDragMode(QGraphicsView::ScrollHandDrag); scene->addText("Start by dragging images here."); ui->graphicsView->setRenderHints(QPainter::HighQualityAntialiasing | QPainter::SmoothPixmapTransform); ui->graphicsView->setAcceptDrops(true); //initialize QImage objects to store the calculated maps input = QImage(); channelIntensity = QImage(); normalmap = QImage(); specmap = QImage(); displacementmap = QImage(); ssaomap = QImage(); //initialize calctimes lastCalctime_normal = 0; lastCalctime_specular = 0; lastCalctime_displace = 0; lastCalctime_ssao = 0; //initialize stopQueue flag stopQueue = false; //show default status message ui->statusBar->showMessage("Drag images into the empty preview window to load them."); //hide queue progressbar ui->progressBar_Queue->hide(); //if the program was opened via "open with" by the OS, extract the image paths from the arguments //(args[0] is the name of the application) QStringList args = QCoreApplication::arguments(); if(args.size() > 1) { QList<QUrl> imageUrls; for(int i = 1; i < args.size(); i++) { imageUrls.append(QUrl::fromLocalFile(args[i])); } loadMultipleDropped(imageUrls); } }
GraphicsObject::GraphicsObject(GraphicsScene & scene, const Vector3 & position) : m_position(position), m_scene_node(nullptr) { Ogre::Entity * ogre_head = scene.scene_manager().createEntity("Head", "ogrehead.mesh"); m_scene_node = scene.scene_manager().getRootSceneNode()->createChildSceneNode(); m_scene_node->attachObject(ogre_head); m_scene_node->setPosition(Ogre::Vector3(m_position.x(), m_position.z(), m_position.y())); }
/*! * \brief Takes care of resizing upon mouse release event. * * This method takes care of creating the necessary undo commands * upon mouse release event. In this way, when resizing this item * (painting) the undo commands are passed to the undostack making * them available should an undo/redo command be issued. */ void Painting::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { GraphicsItem::mouseReleaseEvent(event); if(m_activeHandle != Caneda::NoHandle && m_paintingRect != m_store) { ChangePaintingRectCmd *cmd = new ChangePaintingRectCmd(this, storedPaintingRect(), m_paintingRect); GraphicsScene *scene = qobject_cast<GraphicsScene*>(this->scene()); scene->undoStack()->push(cmd); } m_activeHandle = Caneda::NoHandle; }
void Viewport::UnbindFromWorld() { // Release the old scene view if we have one. if ( m_World && IsValid(m_SceneViewId) ) { GraphicsScene* pGraphicsScene = GetGraphicsScene(); pGraphicsScene->ReleaseSceneView( m_SceneViewId ); } m_World.Release(); m_SceneViewId = Invalid<uint32_t>(); }
void GraphicsLinesForCurve::updateAfterCommand (GraphicsScene &scene, const PointStyle &pointStyle, const Point &point) { LOG4CPP_DEBUG_S ((*mainCat)) << "GraphicsLinesForCurve::updateAfterCommand" << " curve=" << m_curveName.toLatin1().data() << " pointCount=" << m_graphicsPoints.count(); GraphicsPoint *graphicsPoint = 0; if (m_graphicsPoints.contains (point.ordinal())) { graphicsPoint = m_graphicsPoints [point.ordinal()]; // Due to ordinal renumbering, the coordinates may belong to some other point so we override // them for consistent ordinal-position mapping. Updating the identifier also was added for // better logging (i.e. consistency between Document and GraphicsScene dumps), but happened // to fix a bug with the wrong set of points getting deleted from Cut and Delete graphicsPoint->setPos (point.posScreen()); graphicsPoint->setData (DATA_KEY_IDENTIFIER, point.identifier()); } else { // Point does not exist in scene so create it graphicsPoint = scene.createPoint (point.identifier (), pointStyle, point.posScreen()); m_graphicsPoints [point.ordinal ()] = graphicsPoint; } // Mark point as wanted ENGAUGE_CHECK_PTR (graphicsPoint); graphicsPoint->setWanted (); }
void SI_Symbol::removeFromSchematic(GraphicsScene& scene) throw (Exception) { mComponentInstance->unregisterSymbol(*this); scene.removeItem(*mGraphicsItem); foreach (SI_SymbolPin* pin, mPins) pin->removeFromSchematic(scene); }
void SI_Symbol::addToSchematic(GraphicsScene& scene) throw (Exception) { mGenCompInstance->registerSymbol(*this); scene.addItem(*mGraphicsItem); foreach (SI_SymbolPin* pin, mPins) pin->addToSchematic(scene); }
void SI_SymbolPin::removeFromSchematic(GraphicsScene& scene) noexcept { Q_ASSERT(mAddedToSchematic == true); Q_ASSERT(mRegisteredNetPoint == nullptr); mComponentSignalInstance->unregisterSymbolPin(*this); scene.removeItem(*mGraphicsItem); mAddedToSchematic = false; updateErcMessages(); }
void Viewport::BindToWorld( World* newWorld ) { if (newWorld && newWorld != m_World) { GraphicsScene* pGraphicsScene; // Release the old scene view if we have one. if ( m_World && IsValid(m_SceneViewId) ) { pGraphicsScene = GetGraphicsScene(); pGraphicsScene->ReleaseSceneView( m_SceneViewId ); } // Set up the new scene view. m_World = newWorld; pGraphicsScene = GetGraphicsScene(); m_SceneViewId = pGraphicsScene->AllocateSceneView(); OnResize(); } }
/// @copydoc Entity::Attach() void MeshComponent::Attach(GraphicsScene *pGrahpicsScene, TransformComponent *pTransformComponent) { if (!pTransformComponent) { return; } HELIUM_ASSERT( pGrahpicsScene ); HELIUM_ASSERT( IsInvalid( m_graphicsSceneObjectId ) ); Mesh* pMesh = m_Mesh; if( pMesh && pMesh->GetVertexBuffer() && pMesh->GetIndexBuffer() ) { size_t meshSectionCount = pMesh->GetSectionCount(); if( meshSectionCount != 0 ) { GraphicsScene* pGraphicsScene = pGrahpicsScene; HELIUM_ASSERT( pGraphicsScene ); m_graphicsSceneObjectId = pGraphicsScene->AllocateSceneObject(); HELIUM_ASSERT( IsValid( m_graphicsSceneObjectId ) ); m_graphicsSceneObjectSubMeshDataIds.Reserve( meshSectionCount ); m_graphicsSceneObjectSubMeshDataIds.Resize( meshSectionCount ); for( size_t meshSectionIndex = 0; meshSectionIndex < meshSectionCount; ++meshSectionIndex ) { size_t subMeshId = pGraphicsScene->AllocateSceneObjectSubMeshData( m_graphicsSceneObjectId ); HELIUM_ASSERT( IsValid( subMeshId ) ); m_graphicsSceneObjectSubMeshDataIds[ meshSectionIndex ] = subMeshId; } SetNeedsGraphicsSceneObjectUpdate(pTransformComponent); } } }
void GraphicsLinesForCurves::addRemoveCurves (GraphicsScene &scene, const QStringList &curveNames) { LOG4CPP_INFO_S ((*mainCat)) << "GraphicsLinesForCurves::addRemoveCurves" << " curveCount=" << m_graphicsLinesForCurve.count(); // Add new curves QStringList::const_iterator itrC; for (itrC = curveNames.begin (); itrC != curveNames.end (); itrC++) { QString curveName = *itrC; if (!m_graphicsLinesForCurve.contains (curveName)) { GraphicsLinesForCurve *item = new GraphicsLinesForCurve(curveName); scene.addItem (item); m_graphicsLinesForCurve [curveName] = item; } } // Remove expired curves GraphicsLinesContainer::const_iterator itrG, itrGNext; for (itrG = m_graphicsLinesForCurve.begin (); itrG != m_graphicsLinesForCurve.end (); itrG = itrGNext) { const QString curveName = itrG.key (); GraphicsLinesForCurve *graphicsLines = itrG.value(); itrGNext = itrG; itrGNext++; if (!curveNames.contains (curveName)) { delete graphicsLines; m_graphicsLinesForCurve.remove (curveName); } } }
void MainWindow::doActionLoad(){ GraphicsScene* scene = dynamic_cast<GraphicsScene*>(graphicsSheet->scene()); scene->loadFromFile("sample.drw"); }
void MainWindow::doActionSave(){ GraphicsScene* scene = dynamic_cast<GraphicsScene*>(graphicsSheet->scene()); scene->saveToFile("sample.drw"); }
void Viewport::Draw() { SCENE_GRAPH_RENDER_SCOPE_TIMER( ("") ); uint64_t start = Helium::TimerGetClock(); if (!m_World) { return; } Camera& camera = m_Cameras[m_CameraMode]; GraphicsScene* pGraphicsScene = GetGraphicsScene(); GraphicsSceneView* pSceneView = pGraphicsScene->GetSceneView( m_SceneViewId ); BufferedDrawer* pDrawer = pGraphicsScene->GetSceneViewBufferedDrawer( m_SceneViewId ); DrawArgs args; { SCENE_GRAPH_RENDER_SCOPE_TIMER( ("Setup Viewport and Projection") ); Vector3 pos; camera.GetPosition( pos ); const Matrix4& invView = camera.GetInverseView(); pSceneView->SetView( Simd::Vector3( &pos.x ), -Simd::Vector3( &invView.z.x ), Simd::Vector3( &invView.y.x ) ); pSceneView->SetHorizontalFov( Camera::FieldOfView * static_cast< float32_t >(HELIUM_RAD_TO_DEG) ); } if (m_GridVisible) { m_GlobalPrimitives[GlobalPrimitives::StandardGrid]->Draw( pDrawer, &args ); } #ifdef VIEWPORT_REFACTOR // this seems like a bad place to do this if (m_Tool) { SCENE_GRAPH_RENDER_SCOPE_TIMER( ("Tool Evaluate") ); m_Tool->Evaluate(); } { SCENE_GRAPH_RENDER_SCOPE_TIMER( ("Clear and Reset Scene") ); device->BeginScene(); device->SetRenderTarget( 0, m_DeviceManager.GetBackBuffer() ); device->SetDepthStencilSurface( m_DeviceManager.GetDepthBuffer() ); device->Clear(NULL, NULL, D3DCLEAR_TARGET | D3DCLEAR_STENCIL | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(255, 80, 80, 80), 1.0f, 0); device->SetTransform(D3DTS_WORLD, (D3DMATRIX*)&Matrix4::Identity); m_ResourceTracker->ResetState(); } { SCENE_GRAPH_RENDER_SCOPE_TIMER( ("Setup Viewport and Projection") ); device->SetTransform(D3DTS_PROJECTION, (D3DMATRIX*)&m_Cameras[m_CameraMode].SetProjection(m_Size.x, m_Size.y)); device->SetTransform(D3DTS_VIEW, (D3DMATRIX*)&m_Cameras[m_CameraMode].GetViewport()); } { SCENE_GRAPH_RENDER_SCOPE_TIMER( ("Setup RenderState (culling, lighting, and fill") ); device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); if (m_Cameras[m_CameraMode].IsBackFaceCulling()) { device->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); } else { device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); } device->SetRenderState(D3DRS_LIGHTING, TRUE); device->SetRenderState(D3DRS_COLORVERTEX, FALSE); device->SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL); device->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL); device->SetRenderState(D3DRS_SPECULARMATERIALSOURCE, D3DMCS_MATERIAL); device->SetRenderState(D3DRS_ZENABLE, TRUE); device->SetRenderState(D3DRS_NORMALIZENORMALS, TRUE); device->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); device->SetPixelShader( NULL ); device->SetVertexShader( NULL ); D3DLIGHT9 light; ZeroMemory(&light, sizeof(light)); D3DCOLORVALUE ambient; D3DCOLORVALUE diffuse; D3DCOLORVALUE specular; if ( m_Cameras[m_CameraMode].GetShadingMode() == ShadingMode::Wireframe ) { ambient = SceneGraph::Color::DIMGRAY; diffuse = SceneGraph::Color::BLACK; specular = SceneGraph::Color::BLACK; } else { ambient = SceneGraph::Color::DIMGRAY; diffuse = SceneGraph::Color::SILVER; specular = SceneGraph::Color::SILVER; } Vector3 dir; m_Cameras[m_CameraMode].GetDirection(dir); // setup light light.Type = D3DLIGHT_DIRECTIONAL; light.Ambient = ambient; light.Diffuse = diffuse; light.Specular = specular; // set light into runtime light.Direction = *(D3DVECTOR*)&dir; device->SetLight(0, &light); device->LightEnable(0, true); // light from the back dir *= -1.0f; // set light into runtime light.Direction = *(D3DVECTOR*)&dir; device->SetLight(1, &light); device->LightEnable(1, true); } { SCENE_GRAPH_RENDER_SCOPE_TIMER( ("PreRender") ); device->SetTransform(D3DTS_WORLD, (D3DMATRIX*)&Matrix4::Identity); if (m_GridVisible) { m_GlobalPrimitives[GlobalPrimitives::StandardGrid]->Draw( &args ); } } { SCENE_GRAPH_RENDER_SCOPE_TIMER( ("Render") ); { SCENE_GRAPH_RENDER_SCOPE_TIMER( ("Render Setup") ); m_RenderVisitor.Reset( &args, this ); } { SCENE_GRAPH_RENDER_SCOPE_TIMER( ("Render Walk") ); m_Render.Raise( &m_RenderVisitor ); } if (m_Tool) { SCENE_GRAPH_RENDER_SCOPE_TIMER( ("Render Tool") ); m_Tool->Draw( &args ); } { SCENE_GRAPH_RENDER_SCOPE_TIMER( ("Render Draw") ); m_RenderVisitor.Draw(); } args.m_EntryCount = m_RenderVisitor.GetSize(); } { SCENE_GRAPH_RENDER_SCOPE_TIMER( ("PostRender") ); device->SetTransform(D3DTS_WORLD, (D3DMATRIX*)&Matrix4::Identity); device->Clear(NULL, NULL, D3DCLEAR_ZBUFFER, 0, 1.0f, 0); if (m_AxesVisible) { static_cast<SceneGraph::PrimitiveAxes*>(m_GlobalPrimitives[GlobalPrimitives::ViewportAxes])->DrawViewport( &args, &m_Cameras[m_CameraMode] ); } if (m_Tool) { m_Tool->Draw( &args ); } if ( m_Focused ) { unsigned w = 3; unsigned x = m_Size.x; unsigned y = m_Size.y; uint32_t color = D3DCOLOR_ARGB(255, 200, 200, 200); std::vector< TransformedColored > vertices; // <-- // | \ ^ // v \ | // --> // top vertices.push_back(TransformedColored ((float)0, (float)0, 1.0f, color)); vertices.push_back(TransformedColored ((float)0, (float)w, 1.0f, color)); vertices.push_back(TransformedColored ((float)x, (float)w, 1.0f, color)); vertices.push_back(TransformedColored ((float)x, (float)0, 1.0f, color)); vertices.push_back(TransformedColored ((float)0, (float)0, 1.0f, color)); // bottom vertices.push_back(TransformedColored ((float)0, (float)y-w, 1.0f, color)); vertices.push_back(TransformedColored ((float)0, (float)y, 1.0f, color)); vertices.push_back(TransformedColored ((float)x, (float)y, 1.0f, color)); vertices.push_back(TransformedColored ((float)x, (float)y-w, 1.0f, color)); vertices.push_back(TransformedColored ((float)0, (float)y-w, 1.0f, color)); // left vertices.push_back(TransformedColored ((float)0, (float)0, 1.0f, color)); vertices.push_back(TransformedColored ((float)0, (float)y, 1.0f, color)); vertices.push_back(TransformedColored ((float)w, (float)y, 1.0f, color)); vertices.push_back(TransformedColored ((float)w, (float)0, 1.0f, color)); vertices.push_back(TransformedColored ((float)0, (float)0, 1.0f, color)); // right vertices.push_back(TransformedColored ((float)x-w, (float)0, 1.0f, color)); vertices.push_back(TransformedColored ((float)x-w, (float)y, 1.0f, color)); vertices.push_back(TransformedColored ((float)x, (float)y, 1.0f, color)); vertices.push_back(TransformedColored ((float)x, (float)0, 1.0f, color)); vertices.push_back(TransformedColored ((float)x-w, (float)0, 1.0f, color)); device->SetRenderState(D3DRS_ZENABLE, FALSE); device->SetFVF(ElementFormats[ElementTypes::TransformedColored]); device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, &vertices.front(), sizeof(TransformedColored)); device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, &(vertices[5]), sizeof(TransformedColored)); device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, &(vertices[10]), sizeof(TransformedColored)); device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, &(vertices[15]), sizeof(TransformedColored)); device->SetRenderState(D3DRS_ZENABLE, TRUE); m_ResourceTracker->ResetState(); } if (m_DragMode == DragModes::Select) { m_SelectionFrame->Draw( &args ); } } { SCENE_GRAPH_RENDER_SCOPE_TIMER( ("Process Statistics") ); m_Statistics->m_FrameNumber++; m_Statistics->m_FrameCount++; m_Statistics->m_RenderTime += Helium::CyclesToMillis( Helium::TimerGetClock() - start ); m_Statistics->m_RenderWalkTime += args.m_WalkTime; m_Statistics->m_RenderSortTime += args.m_SortTime; m_Statistics->m_RenderCompareTime += args.m_CompareTime; m_Statistics->m_RenderDrawTime += args.m_DrawTime; m_Statistics->m_EntryCount += args.m_EntryCount; m_Statistics->m_TriangleCount += args.m_TriangleCount; m_Statistics->m_LineCount += args.m_LineCount; m_Statistics->Update(); if (m_StatisticsVisible) { m_Statistics->Draw(&args); } } { SCENE_GRAPH_RENDER_SCOPE_TIMER( ("End Scene") ); device->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); device->SetRenderState( D3DRS_ZWRITEENABLE, TRUE ); device->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE ); device->EndScene(); } { SCENE_GRAPH_RENDER_SCOPE_TIMER( ("Display") ); if ( m_DeviceManager.Display( m_Window ) == D3DERR_DEVICELOST ) { m_DeviceManager.SetDeviceLost(); } } #endif }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), selectInteractor(0), newLineItemInteractor(0), newRectItemInteractor(0), newTextItemInteractor(0) { setObjectName(QStringLiteral("MainWindow")); resize(1024, 768); graphicsSheet = new GraphicsSheet(this); QGraphicsDropShadowEffect* shadow = new QGraphicsDropShadowEffect(graphicsSheet); shadow->setBlurRadius(20); shadow->setColor(QColor(0xa0, 0xa0, 0xa0)); graphicsSheet->setGraphicsEffect(shadow); graphicsSheet->setScaleBackground(QColor(0xFF, 0xFF, 0xF8)); QLayout* layout = new ScrollAreaLayout(); layout->addWidget(graphicsSheet); QWidget *centralwidget = new QWidget(this); centralwidget->setLayout(layout); setCentralWidget(centralwidget); /*****************************************************************************/ menubar = new QMenuBar(this); menubar->setObjectName(QStringLiteral("menubar")); menubar->setGeometry(QRect(0, 0, 401, 21)); setMenuBar(menubar); statusbar = new QStatusBar(this); statusbar->setObjectName(QStringLiteral("statusbar")); setStatusBar(statusbar); toolBar = new QToolBar(this); toolBar->setObjectName(QStringLiteral("toolBar")); addToolBar(Qt::TopToolBarArea, toolBar); /*****************************************************************************/ /* Initialize zoom, scale, and paper formats */ graphicsSheet->addScale("1:10", 0.1); graphicsSheet->addScale("1:5", 0.2); graphicsSheet->addScale("1:2", 0.5); graphicsSheet->addScale("1:1", 1.0); graphicsSheet->addScale("2:1", 2.0); graphicsSheet->addScale("5:1", 5.0); graphicsSheet->addScale("10:1", 10.0); LabelledComboBox* scaleWidget = new LabelledComboBox(toolBar, "Scale: "); scaleWidget->getComboBox()->addItems(graphicsSheet->getScaleNames()); toolBar->addWidget(scaleWidget); QObject::connect(scaleWidget->getComboBox(), SIGNAL(currentIndexChanged(int)), graphicsSheet, SLOT(setScale(int))); graphicsSheet->addZoom("50%", 0.5); graphicsSheet->addZoom("75%", 0.75); graphicsSheet->addZoom("100%", 1.0); graphicsSheet->addZoom("125%", 1.25); graphicsSheet->addZoom("150%", 1.5); graphicsSheet->addZoom("200%", 2.0); LabelledComboBox* zoomWidget = new LabelledComboBox(toolBar, "Zoom: "); zoomWidget->getComboBox()->addItems(graphicsSheet->getZoomNames()); toolBar->addWidget(zoomWidget); QObject::connect(zoomWidget->getComboBox(), SIGNAL(currentIndexChanged(int)), graphicsSheet, SLOT(setZoom(int))); graphicsSheet->setUnit("mm"); graphicsSheet->addSize("DIN A3", QSizeF(297.0, 420.0)); graphicsSheet->addSize("DIN A4", QSizeF(210.0, 297.0)); graphicsSheet->addSize("Letter", QSizeF(215.9, 279.4)); graphicsSheet->addSize("DIN A5", QSizeF(148.0, 210.0)); LabelledComboBox* sizeWidget = new LabelledComboBox(toolBar, "Sheet Size: "); sizeWidget->getComboBox()->addItems(graphicsSheet->getSizeNames()); toolBar->addWidget(sizeWidget); QObject::connect(sizeWidget->getComboBox(), SIGNAL(currentIndexChanged(int)), graphicsSheet, SLOT(setSize(int))); QCheckBox* checkbox = new QCheckBox("Landscape", toolBar); toolBar->addWidget(checkbox); QObject::connect(checkbox, SIGNAL(stateChanged(int)), graphicsSheet, SLOT(setDirection(int))); QIcon icon; icon.addFile(QStringLiteral(":/Icons/file-load.png"), QSize(), QIcon::Normal, QIcon::Off); actionLoad = new QAction(icon, "Load drawing ...", this); toolBar->addAction(actionLoad); QObject::connect(actionLoad, SIGNAL(triggered()), this, SLOT(doActionLoad())); QIcon icon2; icon2.addFile(QStringLiteral(":/Icons/file-save.png"), QSize(), QIcon::Normal, QIcon::Off); actionSave = new QAction(icon2, "Save drawing", this); toolBar->addAction(actionSave); QObject::connect(actionSave, SIGNAL(triggered()), this, SLOT(doActionSave())); QIcon icon3; icon3.addFile(QStringLiteral(":/Icons/file-save-as.png"), QSize(), QIcon::Normal, QIcon::Off); actionSaveAs = new QAction(icon3, "Save drawing as ...", this); toolBar->addAction(actionSaveAs); QObject::connect(actionSaveAs, SIGNAL(triggered()), this, SLOT(doActionSaveAs())); QIcon icon4; icon4.addFile(QStringLiteral(":/Icons/object-select.png"), QSize(), QIcon::Normal, QIcon::Off); actionSelect = new QAction(icon4, "Edit object", this); actionSelect->setCheckable(true); toolBar->addAction(actionSelect); QObject::connect(actionSelect, SIGNAL(triggered()), this, SLOT(doActionSelect())); QIcon icon5; icon5.addFile(QStringLiteral(":/Icons/object-newline.png"), QSize(), QIcon::Normal, QIcon::Off); actionNewLineItem = new QAction(icon5, "New line", this); actionNewLineItem->setCheckable(true); toolBar->addAction(actionNewLineItem); QObject::connect(actionNewLineItem, SIGNAL(triggered()), this, SLOT(doActionNewLineItem())); QIcon icon6; icon6.addFile(QStringLiteral(":/Icons/object-newrect.png"), QSize(), QIcon::Normal, QIcon::Off); actionNewRectItem = new QAction(icon6, "New rectangle", this); actionNewRectItem->setCheckable(true); toolBar->addAction(actionNewRectItem); QObject::connect(actionNewRectItem, SIGNAL(triggered()), this, SLOT(doActionNewRectItem())); QIcon icon7; icon7.addFile(QStringLiteral(":/Icons/object-newtext.png"), QSize(), QIcon::Normal, QIcon::Off); actionNewTextItem = new QAction(icon7, "New text rectangle", this); actionNewTextItem->setCheckable(true); toolBar->addAction(actionNewTextItem); QObject::connect(actionNewTextItem, SIGNAL(triggered()), this, SLOT(doActionNewTextItem())); QIcon icon8; icon8.addFile(QStringLiteral(":/Icons/object-newcircle.png"), QSize(), QIcon::Normal, QIcon::Off); actionNewCircleItem = new QAction(icon8, "New circle", this); actionNewCircleItem->setCheckable(true); toolBar->addAction(actionNewCircleItem); QObject::connect(actionNewCircleItem, SIGNAL(triggered()), this, SLOT(doActionNewCircleItem())); QIcon icon9; icon9.addFile(QStringLiteral(":/Icons/object-newellipse.png"), QSize(), QIcon::Normal, QIcon::Off); actionNewEllipseItem = new QAction(icon9, "New ellipse", this); actionNewEllipseItem->setCheckable(true); toolBar->addAction(actionNewEllipseItem); QObject::connect(actionNewEllipseItem, SIGNAL(triggered()), this, SLOT(doActionNewEllipseItem())); QIcon icon10; icon10.addFile(QStringLiteral(":/Icons/object-newbezier.png"), QSize(), QIcon::Normal, QIcon::Off); actionNewBezierItem = new QAction(icon10, "New bezier curve", this); actionNewBezierItem->setCheckable(true); toolBar->addAction(actionNewBezierItem); QObject::connect(actionNewBezierItem, SIGNAL(triggered()), this, SLOT(doActionNewBezierItem())); QIcon icon11; icon11.addFile(QStringLiteral(":/Icons/object-delete.png"), QSize(), QIcon::Normal, QIcon::Off); actionDeleteItem = new QAction(icon11, "Delete selected objects", this); toolBar->addAction(actionDeleteItem); QObject::connect(actionDeleteItem, SIGNAL(triggered()), graphicsSheet, SLOT(deleteSelectedItems())); QIcon icon12; icon12.addFile(QStringLiteral(":/Icons/edit-redo.png"), QSize(), QIcon::Normal, QIcon::Off); actionRedo = new QAction(icon12, "Redo last undone action", this); toolBar->addAction(actionRedo); QObject::connect(actionRedo, SIGNAL(triggered()), this, SLOT(doActionRedo())); QIcon icon13; icon13.addFile(QStringLiteral(":/Icons/edit-undo.png"), QSize(), QIcon::Normal, QIcon::Off); actionUndo = new QAction(icon13, "Undo last action", this); toolBar->addAction(actionUndo); QObject::connect(actionUndo, SIGNAL(triggered()), this, SLOT(doActionUndo())); QActionGroup* actionGroup = new QActionGroup(this); actionGroup->addAction(actionSelect); actionGroup->addAction(actionNewLineItem); actionGroup->addAction(actionNewRectItem); actionGroup->addAction(actionNewTextItem); actionGroup->addAction(actionNewCircleItem); actionGroup->addAction(actionNewEllipseItem); actionGroup->addAction(actionNewBezierItem); actionSelect->setChecked(true); #if 0 QAction* actionInfo = new QAction("Info", this); toolBar->addAction(actionInfo); QObject::connect(actionInfo, SIGNAL(triggered(bool)), this, SLOT(printInfo())); QAction* actionRotate = new QAction("Rotate", this); toolBar->addAction(actionRotate); QObject::connect(actionRotate, SIGNAL(triggered(bool)), this, SLOT(rotateItem())); QAction* actionResize = new QAction("ResizeHandle", this); toolBar->addAction(actionResize); QObject::connect(actionResize, SIGNAL(triggered(bool)), this, SLOT(resizeItem())); #endif zoomWidget->getComboBox()->setCurrentIndex(2); sizeWidget->getComboBox()->setCurrentIndex(3); scaleWidget->getComboBox()->setCurrentIndex(2); checkbox->setChecked(true); /*****************************************************************************/ GraphicsScene* scene = dynamic_cast<GraphicsScene*>(graphicsSheet->scene()); QObject::connect(scene, SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); scene->loadFromFile("sample.drw"); selectInteractor = new EditItemInteractor(); // TODO: get all registered items from the factory! #if 0 newLineItemInteractor = new NewItemInteractor(LineItem::create, 1); // LineItem::P2Handle); QObject::connect(newLineItemInteractor, SIGNAL(editDone()), this, SLOT(toggleActionSelect())); newRectItemInteractor = new NewItemInteractor(RectItem::create, 1); // RectItem::BottomRightHandle); QObject::connect(newRectItemInteractor, SIGNAL(editDone()), this, SLOT(toggleActionSelect())); newTextItemInteractor = new NewItemInteractor(TextItem::create, 1); // TextItem::BottomRightHandle); QObject::connect(newTextItemInteractor, SIGNAL(editDone()), this, SLOT(toggleActionSelect())); newCircleItemInteractor = new NewItemInteractor(CircleItem::create, 1); // CircleItem::RadHandle); QObject::connect(newCircleItemInteractor, SIGNAL(editDone()), this, SLOT(toggleActionSelect())); newEllipseItemInteractor = new NewItemInteractor(EllipseItem::create, 1); // EllipseItem::BottomRightHandle); QObject::connect(newEllipseItemInteractor, SIGNAL(editDone()), this, SLOT(toggleActionSelect())); newBezierItemInteractor = new NewItemInteractor(BezierItem::create, 1); // BezierItem::P2Handle); QObject::connect(newBezierItemInteractor, SIGNAL(editDone()), this, SLOT(toggleActionSelect())); #endif graphicsSheet->setInteractor(selectInteractor); graphicsSheet->setSnapper(new EdgeSnapper(new GridSnapper())); propertyEditor = new ObjectController(); QDockWidget* propertiesDock = new QDockWidget(this); propertiesDock->setObjectName(QStringLiteral("propertiesDock")); propertiesDock->setFeatures(QDockWidget::DockWidgetFloatable|QDockWidget::DockWidgetMovable); propertiesDock->setWindowTitle("Item properties"); propertiesDock->setWidget(propertyEditor); addDockWidget(static_cast<Qt::DockWidgetArea>(2), propertiesDock); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), lastCalctime_normal(0), lastCalctime_specular(0), lastCalctime_displace(0), lastCalctime_ssao(0), stopQueue(false) { ui->setupUi(this); supportedImageformats << "*.png" << "*.jpg" << "*.jpeg" << "*.tiff" << "*.tif" << "*.ppm" << "*.bmp" << "*.xpm" << "*.tga" << "*.gif"; //connect signals of GUI elements with slots of this class connectSignalSlots(); //hide advanced settings and connect signals/slots to show them hideAdvancedSettings(); //initialize graphicsview GraphicsScene *scene = new GraphicsScene(); ui->graphicsView->setScene(scene); ui->graphicsView->setDragMode(QGraphicsView::ScrollHandDrag); scene->addText("Start by dragging images here."); ui->graphicsView->setRenderHints(QPainter::HighQualityAntialiasing | QPainter::SmoothPixmapTransform); ui->graphicsView->setAcceptDrops(true); //show default status message ui->statusBar->showMessage("Drag images into the empty preview window to load them."); //hide queue progressbar ui->progressBar_Queue->hide(); // SSAO map generator is not ready yet, remove it from the UI ui->tabWidget->removeTab(4); //default UI colors useCustomUiColors = false; uiColorMainDefault = QColor("#444"); uiColorTextDefault = QColor("#eee"); uiColorGraphicsViewDefault = QColor(Qt::darkGray); uiColorMain = uiColorMainDefault; uiColorText = uiColorTextDefault; uiColorGraphicsView = uiColorGraphicsViewDefault; //read last window position and color settings from registry readSettings(); //set UI colors setUiColors(); //if the program was opened via "open with" by the OS, //extract the image paths from the arguments QStringList args = QCoreApplication::arguments(); if(args.size() > 1) { QList<QUrl> imageUrls; for(int i = 1; i < args.size(); i++) { imageUrls.append(QUrl::fromLocalFile(args[i])); } loadMultipleDropped(imageUrls); } }
Widget::Widget(QWidget *parent) : QWidget(parent) { QHBoxLayout * hbox = new QHBoxLayout; QGraphicsView * view = new QGraphicsView; GraphicsScene * scene = new GraphicsScene; QPolygonF polygon; qreal side = 20; qreal dx = qSqrt(3)/2 * side; polygon // standing on a point << QPointF(dx, -side/2) << QPointF(0, -side) << QPointF(-dx, -side/2) << QPointF(-dx, side/2) << QPointF(0, side) << QPointF(dx, side/2); // Sitting flat // << QPointF(-side/2, dx) // << QPointF(-side, 0) // << QPointF(-side/2, -dx) // << QPointF(side/2, -dx) // << QPointF(side, 0) // << QPointF(side/2, dx); int h = 9; int w = 17; int mid_h = h/2; int mid_w = w/2; for(int r = 0; r < h; r++) { for(int c = 0; c < w; c++) { if(qAbs(mid_h - r) + qAbs(mid_w - c) > 8 || (r % 2 != c % 2)) { // don't add a hexagon, it isn't on the board! } else { BoardHexagon * hexagon = new BoardHexagon(0); hexagon->setPolygon(polygon); scene->addItem(hexagon); hexagon->setPos(dx * c, side * 1.5 * r); hexagon->setToolTip(QString::number(r) + "," + QString::number(c)); } } } QGraphicsEllipseItem * ellipse = scene->addEllipse(-20, -20, 20, 20,QPen(), QBrush(QColor(Qt::green))); this->makeDraggable(ellipse); view->setRenderHint(QPainter::Antialiasing); view->setScene(scene); view->setMouseTracking(true); hbox->addWidget(view); this->setLayout(hbox); this->resize(600, 400); }
void Viewport::Draw() { HELIUM_EDITOR_SCENE_RENDER_SCOPE_TIMER( "" ); uint64_t start = Timer::GetTickCount(); if (!m_World) { return; } Camera& camera = m_Cameras[m_CameraMode]; GraphicsScene* pGraphicsScene = GetGraphicsScene(); GraphicsSceneView* pSceneView = pGraphicsScene->GetSceneView( m_SceneViewId ); BufferedDrawer* pDrawer = pGraphicsScene->GetSceneViewBufferedDrawer( m_SceneViewId ); { HELIUM_EDITOR_SCENE_RENDER_SCOPE_TIMER( "Setup Viewport and Projection" ); pSceneView->SetViewAndProjectionMatrices( Simd::Matrix44( const_cast<Matrix4&>( camera.GetView() ).GetArray1d() ), Simd::Matrix44( const_cast<Matrix4&>( camera.GetProjection() ).GetArray1d() ) ); } pGraphicsScene->SetActiveSceneView( m_SceneViewId ); pGraphicsScene->Update( m_World.Get() ); pGraphicsScene->SetActiveSceneView( Invalid< uint32_t >() ); if (m_GridVisible) { m_GlobalPrimitives[GlobalPrimitives::StandardGrid]->Draw( pDrawer ); } // this seems like a bad place to do this if (m_Tool) { HELIUM_EDITOR_SCENE_RENDER_SCOPE_TIMER( "Tool Evaluate" ); m_Tool->Evaluate(); } { HELIUM_EDITOR_SCENE_RENDER_SCOPE_TIMER( "PreRender" ); if (m_GridVisible) { m_GlobalPrimitives[GlobalPrimitives::StandardGrid]->Draw( pDrawer ); } } { HELIUM_EDITOR_SCENE_RENDER_SCOPE_TIMER( "Render" ); { HELIUM_EDITOR_SCENE_RENDER_SCOPE_TIMER( "Render Setup" ); m_RenderVisitor.Reset( this, pDrawer ); } { HELIUM_EDITOR_SCENE_RENDER_SCOPE_TIMER( "Render Walk" ); m_Render.Raise( &m_RenderVisitor ); } if (m_Tool) { HELIUM_EDITOR_SCENE_RENDER_SCOPE_TIMER( "Render Tool" ); m_Tool->Draw( pDrawer ); } } { HELIUM_EDITOR_SCENE_RENDER_SCOPE_TIMER( "PostRender" ); //device->Clear(NULL, NULL, D3DCLEAR_ZBUFFER, 0, 1.0f, 0); if (m_AxesVisible) { static_cast<Editor::PrimitiveAxes*>(m_GlobalPrimitives[GlobalPrimitives::ViewportAxes])->DrawViewport( pDrawer, &m_Cameras[m_CameraMode] ); } if (m_Tool) { m_Tool->Draw( pDrawer ); } #if VIEWPORT_REFACTOR if ( m_Focused ) { unsigned w = 3; unsigned x = m_Size.x; unsigned y = m_Size.y; uint32_t color = D3DCOLOR_ARGB(255, 200, 200, 200); std::vector< TransformedColored > vertices; // <-- // | \ ^ // v \ | // --> // top vertices.push_back(TransformedColored ((float)0, (float)0, 1.0f, color)); vertices.push_back(TransformedColored ((float)0, (float)w, 1.0f, color)); vertices.push_back(TransformedColored ((float)x, (float)w, 1.0f, color)); vertices.push_back(TransformedColored ((float)x, (float)0, 1.0f, color)); vertices.push_back(TransformedColored ((float)0, (float)0, 1.0f, color)); // bottom vertices.push_back(TransformedColored ((float)0, (float)y-w, 1.0f, color)); vertices.push_back(TransformedColored ((float)0, (float)y, 1.0f, color)); vertices.push_back(TransformedColored ((float)x, (float)y, 1.0f, color)); vertices.push_back(TransformedColored ((float)x, (float)y-w, 1.0f, color)); vertices.push_back(TransformedColored ((float)0, (float)y-w, 1.0f, color)); // left vertices.push_back(TransformedColored ((float)0, (float)0, 1.0f, color)); vertices.push_back(TransformedColored ((float)0, (float)y, 1.0f, color)); vertices.push_back(TransformedColored ((float)w, (float)y, 1.0f, color)); vertices.push_back(TransformedColored ((float)w, (float)0, 1.0f, color)); vertices.push_back(TransformedColored ((float)0, (float)0, 1.0f, color)); // right vertices.push_back(TransformedColored ((float)x-w, (float)0, 1.0f, color)); vertices.push_back(TransformedColored ((float)x-w, (float)y, 1.0f, color)); vertices.push_back(TransformedColored ((float)x, (float)y, 1.0f, color)); vertices.push_back(TransformedColored ((float)x, (float)0, 1.0f, color)); vertices.push_back(TransformedColored ((float)x-w, (float)0, 1.0f, color)); device->SetRenderState(D3DRS_ZENABLE, FALSE); device->SetFVF(ElementFormats[ElementTypes::TransformedColored]); device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, &vertices.front(), sizeof(TransformedColored)); device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, &(vertices[5]), sizeof(TransformedColored)); device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, &(vertices[10]), sizeof(TransformedColored)); device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, &(vertices[15]), sizeof(TransformedColored)); device->SetRenderState(D3DRS_ZENABLE, TRUE); } if (m_DragMode == DragModes::Select) { m_SelectionFrame->Draw( &args ); } #endif } }
Camera::Camera(const GraphicsScene& scene): scene_(scene), resolution_(scene.areaSize()) { }
int APIENTRY _tWinMain( HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR /*lpCmdLine*/, int nCmdShow ) { ForceLoadComponentsDll(); #if HELIUM_TOOLS ForceLoadEditorSupportDll(); #endif HELIUM_TRACE_SET_LEVEL( TraceLevels::Debug ); Timer::StaticInitialize(); #if !HELIUM_RELEASE && !HELIUM_PROFILE Helium::InitializeSymbols(); #endif AsyncLoader::GetStaticInstance().Initialize(); FilePath baseDirectory; if ( !FileLocations::GetBaseDirectory( baseDirectory ) ) { HELIUM_TRACE( TraceLevels::Error, TXT( "Could not get base directory." ) ); return -1; } HELIUM_VERIFY( CacheManager::InitializeStaticInstance( baseDirectory ) ); Helium::Bullet::Initialize(); int resultCode = -1; { Reflect::Initialize(); Helium::Components::Initialize(); Helium::TaskScheduler::CalculateSchedule(); #if HELIUM_TOOLS #endif InitEngineJobsDefaultHeap(); InitGraphicsJobsDefaultHeap(); InitTestJobsDefaultHeap(); #if HELIUM_TOOLS //HELIUM_VERIFY( LooseAssetLoader::InitializeStaticInstance() ); HELIUM_VERIFY( LooseAssetLoader::InitializeStaticInstance() ); AssetPreprocessor* pAssetPreprocessor = AssetPreprocessor::CreateStaticInstance(); HELIUM_ASSERT( pAssetPreprocessor ); PlatformPreprocessor* pPlatformPreprocessor = new PcPreprocessor; HELIUM_ASSERT( pPlatformPreprocessor ); pAssetPreprocessor->SetPlatformPreprocessor( Cache::PLATFORM_PC, pPlatformPreprocessor ); #else HELIUM_VERIFY( CacheAssetLoader::InitializeStaticInstance() ); #endif #if !GTEST AssetLoader* gAssetLoader = NULL; #endif gAssetLoader = AssetLoader::GetStaticInstance(); HELIUM_ASSERT( gAssetLoader ); Config& rConfig = Config::GetStaticInstance(); rConfig.BeginLoad(); while( !rConfig.TryFinishLoad() ) { gAssetLoader->Tick(); } #if HELIUM_TOOLS ConfigPc::SaveUserConfig(); #endif uint32_t displayWidth; uint32_t displayHeight; //bool bFullscreen; bool bVsync; { StrongPtr< GraphicsConfig > spGraphicsConfig( rConfig.GetConfigObject< GraphicsConfig >( Name( TXT( "GraphicsConfig" ) ) ) ); HELIUM_ASSERT( spGraphicsConfig ); displayWidth = spGraphicsConfig->GetWidth(); displayHeight = spGraphicsConfig->GetHeight(); //bFullscreen = spGraphicsConfig->GetFullscreen(); bVsync = spGraphicsConfig->GetVsync(); } WNDCLASSEXW windowClass; windowClass.cbSize = sizeof( windowClass ); windowClass.style = 0; windowClass.lpfnWndProc = WindowProc; windowClass.cbClsExtra = 0; windowClass.cbWndExtra = 0; windowClass.hInstance = hInstance; windowClass.hIcon = NULL; windowClass.hCursor = NULL; windowClass.hbrBackground = NULL; windowClass.lpszMenuName = NULL; windowClass.lpszClassName = L"HeliumTestAppClass"; windowClass.hIconSm = NULL; HELIUM_VERIFY( RegisterClassEx( &windowClass ) ); WindowData windowData; windowData.hMainWnd = NULL; windowData.hSubWnd = NULL; windowData.bProcessMessages = true; windowData.bShutdownRendering = false; windowData.resultCode = 0; DWORD dwStyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU; RECT windowRect; windowRect.left = 0; windowRect.top = 0; windowRect.right = static_cast< LONG >( displayWidth ); windowRect.bottom = static_cast< LONG >( displayHeight ); HELIUM_VERIFY( AdjustWindowRect( &windowRect, dwStyle, FALSE ) ); HWND hMainWnd = ::CreateWindowW( L"HeliumTestAppClass", L"Helium TestApp", dwStyle, CW_USEDEFAULT, CW_USEDEFAULT, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top, NULL, NULL, hInstance, NULL ); HELIUM_ASSERT( hMainWnd ); windowRect.left = 0; windowRect.top = 0; windowRect.right = static_cast< LONG >( displayWidth ); windowRect.bottom = static_cast< LONG >( displayHeight ); HELIUM_VERIFY( AdjustWindowRect( &windowRect, dwStyle, FALSE ) ); #if MULTI_WINDOW HWND hSubWnd = ::CreateWindowW( L"HeliumTestAppClass", L"Helium TestApp (second view)", dwStyle, CW_USEDEFAULT, CW_USEDEFAULT, windowRect.right - windowRect.left, windowRect.bottom - windowRect.top, NULL, NULL, hInstance, NULL ); HELIUM_ASSERT( hSubWnd ); #endif windowData.hMainWnd = hMainWnd; SetWindowLongPtr( hMainWnd, GWLP_USERDATA, reinterpret_cast< LONG_PTR >( &windowData ) ); ShowWindow( hMainWnd, nCmdShow ); UpdateWindow( hMainWnd ); #if MULTI_WINDOW windowData.hSubWnd = hSubWnd; SetWindowLongPtr( hSubWnd, GWLP_USERDATA, reinterpret_cast< LONG_PTR >( &windowData ) ); ShowWindow( hSubWnd, nCmdShow ); UpdateWindow( hSubWnd ); #endif HELIUM_VERIFY( D3D9Renderer::CreateStaticInstance() ); Renderer* pRenderer = Renderer::GetStaticInstance(); HELIUM_ASSERT( pRenderer ); pRenderer->Initialize(); Renderer::ContextInitParameters contextInitParams; contextInitParams.pWindow = hMainWnd; contextInitParams.displayWidth = displayWidth; contextInitParams.displayHeight = displayHeight; contextInitParams.bVsync = bVsync; HELIUM_VERIFY( pRenderer->CreateMainContext( contextInitParams ) ); #if MULTI_WINDOW contextInitParams.pWindow = hSubWnd; RRenderContextPtr spSubRenderContext = pRenderer->CreateSubContext( contextInitParams ); HELIUM_ASSERT( spSubRenderContext ); #endif Input::Initialize(&hMainWnd, false); { AssetPath prePassShaderPath; HELIUM_VERIFY( prePassShaderPath.Set( HELIUM_PACKAGE_PATH_CHAR_STRING TXT( "Shaders" ) HELIUM_OBJECT_PATH_CHAR_STRING TXT( "PrePass.hlsl" ) ) ); AssetPtr spPrePassShader; HELIUM_VERIFY( AssetLoader::GetStaticInstance()->LoadObject( prePassShaderPath, spPrePassShader ) ); HELIUM_ASSERT( spPrePassShader.Get() ); } RenderResourceManager& rRenderResourceManager = RenderResourceManager::GetStaticInstance(); rRenderResourceManager.Initialize(); rRenderResourceManager.UpdateMaxViewportSize( displayWidth, displayHeight ); //// Create a scene definition SceneDefinitionPtr spSceneDefinition; gAssetLoader->LoadObject( AssetPath( TXT( "/ExampleGames/Empty/Scenes/TestScene:SceneDefinition" ) ), spSceneDefinition ); EntityDefinitionPtr spEntityDefinition; gAssetLoader->LoadObject( AssetPath( TXT( "/ExampleGames/Empty/Scenes/TestScene:TestBull_Entity" ) ), spEntityDefinition ); DynamicDrawer& rDynamicDrawer = DynamicDrawer::GetStaticInstance(); HELIUM_VERIFY( rDynamicDrawer.Initialize() ); RRenderContextPtr spMainRenderContext = pRenderer->GetMainContext(); HELIUM_ASSERT( spMainRenderContext ); WorldManager& rWorldManager = WorldManager::GetStaticInstance(); HELIUM_VERIFY( rWorldManager.Initialize() ); // Create a world WorldPtr spWorld( rWorldManager.CreateWorld( spSceneDefinition ) ); HELIUM_ASSERT( spWorld ); HELIUM_TRACE( TraceLevels::Info, TXT( "Created world \"%s\".\n" ), *spSceneDefinition->GetPath().ToString() ); //Slice *pRootSlice = spWorld->GetRootSlice(); //Entity *pEntity = pRootSlice->CreateEntity(spEntityDefinition); GraphicsScene* pGraphicsScene = spWorld->GetComponents().GetFirst<GraphicsManagerComponent>()->GetGraphicsScene(); HELIUM_ASSERT( pGraphicsScene ); GraphicsSceneView* pMainSceneView = NULL; if( pGraphicsScene ) { uint32_t mainSceneViewId = pGraphicsScene->AllocateSceneView(); if( IsValid( mainSceneViewId ) ) { float32_t aspectRatio = static_cast< float32_t >( displayWidth ) / static_cast< float32_t >( displayHeight ); RSurface* pDepthStencilSurface = rRenderResourceManager.GetDepthStencilSurface(); HELIUM_ASSERT( pDepthStencilSurface ); pMainSceneView = pGraphicsScene->GetSceneView( mainSceneViewId ); HELIUM_ASSERT( pMainSceneView ); pMainSceneView->SetRenderContext( spMainRenderContext ); pMainSceneView->SetDepthStencilSurface( pDepthStencilSurface ); pMainSceneView->SetAspectRatio( aspectRatio ); pMainSceneView->SetViewport( 0, 0, displayWidth, displayHeight ); pMainSceneView->SetClearColor( Color( 0x00202020 ) ); //spMainCamera->SetSceneViewId( mainSceneViewId ); #if MULTI_WINDOW uint32_t subSceneViewId = pGraphicsScene->AllocateSceneView(); if( IsValid( subSceneViewId ) ) { GraphicsSceneView* pSubSceneView = pGraphicsScene->GetSceneView( subSceneViewId ); HELIUM_ASSERT( pSubSceneView ); pSubSceneView->SetRenderContext( spSubRenderContext ); pSubSceneView->SetDepthStencilSurface( pDepthStencilSurface ); pSubSceneView->SetAspectRatio( aspectRatio ); pSubSceneView->SetViewport( 0, 0, displayWidth, displayHeight ); pSubSceneView->SetClearColor( Color( 0x00202020 ) ); //spSubCamera->SetSceneViewId( subSceneViewId ); } #endif } #if !HELIUM_RELEASE && !HELIUM_PROFILE BufferedDrawer& rSceneDrawer = pGraphicsScene->GetSceneBufferedDrawer(); rSceneDrawer.DrawScreenText( 20, 20, String( TXT( "CACHING" ) ), Color( 0xff00ff00 ), RenderResourceManager::DEBUG_FONT_SIZE_LARGE ); rSceneDrawer.DrawScreenText( 21, 20, String( TXT( "CACHING" ) ), Color( 0xff00ff00 ), RenderResourceManager::DEBUG_FONT_SIZE_LARGE ); //rSceneDrawer.Draw //Helium::DynamicDrawer &drawer = DynamicDrawer::GetStaticInstance(); //drawer. #endif } rWorldManager.Update(); float time = 0.0f; #if MULTI_WINDOW spSubRenderContext.Release(); #endif spMainRenderContext.Release(); Helium::StrongPtr<Helium::Texture2d> texture; gAssetLoader->LoadObject( AssetPath( TXT( "/Textures:Triangle.png" ) ), texture); Helium::RTexture2d *rTexture2d = texture->GetRenderResource2d(); while( windowData.bProcessMessages ) { #if GRAPHICS_SCENE_BUFFERED_DRAWER BufferedDrawer& rSceneDrawer = pGraphicsScene->GetSceneBufferedDrawer(); rSceneDrawer.DrawScreenText( 20, 20, String( TXT( "RUNNING" ) ), Color( 0xffffffff ), RenderResourceManager::DEBUG_FONT_SIZE_LARGE ); rSceneDrawer.DrawScreenText( 21, 20, String( TXT( "RUNNING" ) ), Color( 0xffffffff ), RenderResourceManager::DEBUG_FONT_SIZE_LARGE ); time += 0.01f; DynamicArray<SimpleVertex> verticesU; verticesU.New( -100.0f, -100.0f, 750.0f ); verticesU.New( 100.0f, -100.0f, 750.0f ); verticesU.New( 100.0f, 100.0f, 750.0f ); verticesU.New( -100.0f, 100.0f, 750.0f ); rSceneDrawer.DrawLineList( verticesU.GetData(), static_cast<uint32_t>( verticesU.GetSize() ) ); DynamicArray<SimpleTexturedVertex> verticesT; verticesT.New( Simd::Vector3( -100.0f, 100.0f, 750.0f ), Simd::Vector2( 0.0f, 0.0f ) ); verticesT.New( Simd::Vector3( 100.0f, 100.0f, 750.0f ), Simd::Vector2( 1.0f, 0.0f ) ); verticesT.New( Simd::Vector3( -100.0f, -100.0f, 750.0f ), Simd::Vector2( 0.0f, 1.0f ) ); verticesT.New( Simd::Vector3( 100.0f, -100.0f, 750.0f ), Simd::Vector2( 1.0f, 1.0f ) ); //rSceneDrawer.DrawTextured( // RENDERER_PRIMITIVE_TYPE_TRIANGLE_STRIP, // verticesT.GetData(), // verticesT.GetSize(), // NULL, // 2, // rTexture2d, Helium::Color(1.0f, 1.0f, 1.0f, 1.0f), Helium::RenderResourceManager::RASTERIZER_STATE_DEFAULT, Helium::RenderResourceManager::DEPTH_STENCIL_STATE_NONE); //rSceneDrawer.DrawTexturedQuad(rTexture2d); Helium::Simd::Matrix44 transform = Helium::Simd::Matrix44::IDENTITY; Simd::Vector3 location(0.0f, 400.0f, 0.0f); Simd::Quat rotation(Helium::Simd::Vector3::BasisZ, time); Simd::Vector3 scale(1000.0f, 1000.0f, 1000.0f); transform.SetRotationTranslationScaling(rotation, location, scale); rSceneDrawer.DrawTexturedQuad(rTexture2d, transform, Simd::Vector2(0.0f, 0.0f), Simd::Vector2(0.5f, 0.5f)); #endif //Helium::Simd::Vector3 up = Simd::Vector3::BasisY; ////Helium::Simd::Vector3 eye(5000.0f * sin(time), 0.0f, 5000.0f * cos(time)); //Helium::Simd::Vector3 eye(0.0f, 0.0f, -1000.0f); //Helium::Simd::Vector3 forward = Simd::Vector3::Zero - eye; //forward.Normalize(); ////pMainSceneView->SetClearColor( Color( 0xffffffff ) ); //pMainSceneView->SetView(eye, forward, up); if (Input::IsKeyDown(Input::KeyCodes::KC_A)) { HELIUM_TRACE( TraceLevels::Info, TXT( "A is down" ) ); } if (Input::IsKeyDown(Input::KeyCodes::KC_ESCAPE)) { HELIUM_TRACE( TraceLevels::Info, TXT( "Exiting" ) ); break; } MSG message; if( PeekMessage( &message, NULL, 0, 0, PM_REMOVE ) ) { TranslateMessage( &message ); DispatchMessage( &message ); if( windowData.bShutdownRendering ) { if( spWorld ) { spWorld->Shutdown(); } spWorld.Release(); WorldManager::DestroyStaticInstance(); spSceneDefinition.Release(); spEntityDefinition.Release(); DynamicDrawer::DestroyStaticInstance(); RenderResourceManager::DestroyStaticInstance(); Renderer::DestroyStaticInstance(); break; } if( message.message == WM_QUIT ) { windowData.bProcessMessages = false; windowData.resultCode = static_cast< int >( message.wParam ); resultCode = static_cast< int >( message.wParam ); break; } } rWorldManager.Update(); #if GRAPHICS_SCENE_BUFFERED_DRAWER if( pGraphicsScene ) { BufferedDrawer& rSceneDrawer = pGraphicsScene->GetSceneBufferedDrawer(); rSceneDrawer.DrawScreenText( 20, 20, String( TXT( "Debug text test!" ) ), Color( 0xffffffff ) ); } #endif } if( spWorld ) { spWorld->Shutdown(); } spWorld.Release(); } WorldManager::DestroyStaticInstance(); DynamicDrawer::DestroyStaticInstance(); RenderResourceManager::DestroyStaticInstance(); Helium::Input::Cleanup(); Renderer::DestroyStaticInstance(); JobManager::DestroyStaticInstance(); Config::DestroyStaticInstance(); #if HELIUM_TOOLS AssetPreprocessor::DestroyStaticInstance(); #endif AssetLoader::DestroyStaticInstance(); CacheManager::DestroyStaticInstance(); Helium::Components::Cleanup(); Reflect::Cleanup(); AssetType::Shutdown(); Asset::Shutdown(); Reflect::ObjectRefCountSupport::Shutdown(); Helium::Bullet::Cleanup(); AssetPath::Shutdown(); Name::Shutdown(); FileLocations::Shutdown(); ThreadLocalStackAllocator::ReleaseMemoryHeap(); #if HELIUM_ENABLE_MEMORY_TRACKING DynamicMemoryHeap::LogMemoryStats(); ThreadLocalStackAllocator::ReleaseMemoryHeap(); #endif return resultCode; }