void DeferredLight::rebuildGeometry(float radius) { //Disable all 3 bits DISABLE_BIT(mPermutation, LightMaterialGenerator::MI_POINT); DISABLE_BIT(mPermutation, LightMaterialGenerator::MI_SPOTLIGHT); DISABLE_BIT(mPermutation, LightMaterialGenerator::MI_DIRECTIONAL); switch (mParentLight->getType()) { case Ogre::Light::LT_DIRECTIONAL: createRectangle2D(); ENABLE_BIT(mPermutation,LightMaterialGenerator::MI_DIRECTIONAL); break; case Ogre::Light::LT_POINT: /// XXX some more intelligent expression for rings and segments createSphere(radius, 10, 10); ENABLE_BIT(mPermutation,LightMaterialGenerator::MI_POINT); break; case Ogre::Light::LT_SPOTLIGHT: Ogre::Real height = mParentLight->getAttenuationRange(); Ogre::Radian coneRadiusAngle = mParentLight->getSpotlightOuterAngle() / 2; Ogre::Real rad = Ogre::Math::Tan(coneRadiusAngle) * height; createCone(rad, height, 20); ENABLE_BIT(mPermutation,LightMaterialGenerator::MI_SPOTLIGHT); break; } }
OpenGLWidget::OpenGLWidget(MainWindow* mainWindow) : QOpenGLWidget{mainWindow} , m_axisLegendScene{mainWindow->app()} , m_width{0} , m_height{0} , m_currentLocation{} , m_previousLocation{} { this->setFocusPolicy(Qt::StrongFocus); m_contextMenu = new QMenu(this); QMenu* createMenu = m_contextMenu->addMenu("Create"); createMenu->addAction(tr("Box"), this, SLOT(createBox())); createMenu->addAction(tr("Cylinder"), this, SLOT(createCylinder())); createMenu->addAction(tr("Cone"), this, SLOT(createCone())); createMenu->addAction(tr("Sphere"), this, SLOT(createSphere())); m_contextMenu->addAction(tr("Import Mesh"), this, SLOT(importMesh())); QSurfaceFormat format = this->format(); format.setVersion(kOpenGLMajorVersion, kOpenGLMinorVersion); format.setProfile(QSurfaceFormat::CoreProfile); format.setDepthBufferSize(32); format.setSwapBehavior(QSurfaceFormat::DoubleBuffer); LOG(INFO) << fmt::format("Setting format with OpenGL version {}.{}", kOpenGLMajorVersion, kOpenGLMinorVersion); this->setFormat(format); }
GLWidget::GLWidget(QWidget *parent) : QGLWidget(parent) { upSphereCone = downSphereCone = cylinderVertices = diskVertices = sphereVertices = coneVertices = 0; cylinderSize = diskSize = sphereVerticesSize = sphereConeSize = coneSize = 0; createSphere(1.0f, 10, 10); createCone(0.5f, 0.5f, 6); createDisk(0.5f, 6); createCylinder(0.9f, 0.1f, 0.0f, 50); program = new QOpenGLShaderProgram(this); setFormat(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer | QGL::SampleBuffers | QGL::NoDeprecatedFunctions)); modelView.setColumn(3, QVector4D(-0.5, -0.5, 0, 1)); }
void GLWidget::createAxis3D(int quality) { // middle point (sphere) createSphere(0.1f, quality, quality); axisSphereSize = sphereVerticesSize; axisSphereBuffer.create(); axisSphereBuffer.bind(); axisSphereBuffer.allocate(sphereVertices, axisSphereSize * sizeof(float)); axisBottomSphereSize = sphereConeSize; axisBottomSphereBuffer.create(); axisBottomSphereBuffer.bind(); axisBottomSphereBuffer.allocate(downSphereCone, axisBottomSphereSize * sizeof(float)); freeSphere(); //axis createCylinder(0.05f, 0.05f, 0.5f, quality); axisCylynderSize = cylinderSize; axisCylynderBuffer.create(); axisCylynderBuffer.bind(); axisCylynderBuffer.allocate(cylinderVertices, axisCylynderSize * sizeof(float)); freeCylinder(); createDisk(0.1f, quality); axisDiskSize = diskSize; axisDiskBuffer.create(); axisDiskBuffer.bind(); axisDiskBuffer.allocate(diskVertices, axisDiskSize * sizeof(float)); freeDisk(); createCone(0.1, 0.3, quality); axisConeSize = coneSize; axisConeBuffer.create(); axisConeBuffer.bind(); axisConeBuffer.allocate(coneVertices, axisConeSize * sizeof(float)); freeCone(); }
void DeferredLight::rebuildGeometry(Ogre::Real radius) { DISABLE_BIT(permutation, LightMaterialGenerator::MI_POINT); DISABLE_BIT(permutation, LightMaterialGenerator::MI_SPOTLIGHT); DISABLE_BIT(permutation, LightMaterialGenerator::MI_DIRECTIONAL); switch (parentLight->getType()) { case Ogre::Light::LT_DIRECTIONAL: createRectangle2D(); ENABLE_BIT(permutation,LightMaterialGenerator::MI_DIRECTIONAL); break; case Ogre::Light::LT_POINT: createSphere(radius, 10, 10); ENABLE_BIT(permutation,LightMaterialGenerator::MI_POINT); break; case Ogre::Light::LT_SPOTLIGHT: Ogre::Real height = parentLight->getAttenuationRange(); Ogre::Radian coneRadiusAngle = parentLight->getSpotlightOuterAngle() / 2; Ogre::Real rad = Ogre::Math::Tan(coneRadiusAngle) * height; createCone(rad, height, 20); ENABLE_BIT(permutation,LightMaterialGenerator::MI_SPOTLIGHT); break; } }
void GeomUtils::createCone(const Ogre::String& strName , float radius , float height, int nVerticesInBase) { MeshPtr pCone = MeshManager::getSingleton().createManual(strName, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); SubMesh *pConeVertex = pCone->createSubMesh(); pCone->sharedVertexData = new VertexData(); createCone(pCone->sharedVertexData, pConeVertex->indexData , radius , height , nVerticesInBase); // Generate face list pConeVertex->useSharedVertices = true; // the original code was missing this line: pCone->_setBounds( AxisAlignedBox( Vector3(-radius, 0, -radius), Vector3(radius, height, radius) ), false ); pCone->_setBoundingSphereRadius(Math::Sqrt(height*height + radius*radius)); // this line makes clear the mesh is loaded (avoids memory leaks) pCone->load(); }
void initializeDevices() { /////////////////////////INTERACTOR//////////////////////////// // Initialize Device Interactor to manage all trackers inputInteractor = vtkDeviceInteractor::New(); /////////////////////////CREATE TRACKER//////////////////////////// //Create connection to VRPN Tracker using vtkInteractionDevice.lib tracker1 = vtkVRPNTrackerCustomSensor::New(); tracker1->SetDeviceName(trackerAddress); tracker1->SetSensorIndex(sensorIndex);//TODO: Fix error handling tracker1->SetTracker2WorldTranslation(trackerOrigin[0],trackerOrigin[1],trackerOrigin[2]); double t2w1[3][3] = { 0, -1, 0, 0, 0, 1, -1, 0, 0 }; double t2wQuat1[4]; vtkMath::Matrix3x3ToQuaternion(t2w1, t2wQuat1); tracker1->SetTracker2WorldRotation(t2wQuat1); int trackerInitResult = tracker1->Initialize(); if (trackerInitResult == 0) { printf("Error initializing tracker "); } /////////////////////////CREATE TRACKER STYLE//////////////////////////// //Create device interactor style (defined in vtkInteractionDevice.lib) that determines how the device manipulates camera viewpoint trackerStyleCamera1 = vtkVRPNTrackerCustomSensorStyleCamera::New(); trackerStyleCamera1->SetTracker(tracker1); trackerStyleCamera1->SetRenderer(renwin->GetRenderers()->GetFirstRenderer()); //Create device interactor style (defined in vtkInteractionDevice.lib) that determines how the device manipulates camera viewpoint trackerStyleCamera2 = vtkVRPNTrackerCustomSensorStyleCamera::New(); trackerStyleCamera2->SetTracker(tracker1); trackerStyleCamera2->SetRenderer(/*datawin*/renwin->GetRenderers()->GetFirstRenderer()); /////////////////////////INTERACTOR//////////////////////////// //Register Tracker to Device Interactor inputInteractor->AddInteractionDevice(tracker1); inputInteractor->AddDeviceInteractorStyle(trackerStyleCamera1); inputInteractor->AddDeviceInteractorStyle(trackerStyleCamera2); if (USE_PHANTOM) { vtkVRPNPhantom* phantom1 = vtkVRPNPhantom::New(); phantom1->SetDeviceName("*****@*****.**"); phantom1->SetPhantom2WorldTranslation(0.000264,0.065412,0.0);//TODO: FIX phantom1->SetNumberOfButtons(2); phantom1->SetSensorIndex(sensorIndex); phantom1->Initialize(); createCone(false); /////////////////////////CREATE PHANTOM STYLE//////////////////////////// phantomStyleCamera1 = vtkVRPNPhantomStyleCamera::New(); /////////////////////////CONNECT TO SERVER CHANGE//////////////////////////// phantomStyleCamera1->SetActor(ConeActor); phantomStyleCamera1->SetConeSource(Cone); phantomStyleCamera1->SetPhantom(phantom1); phantomStyleCamera1->SetRenderer(/*datawin*/renwin->GetRenderers()->GetFirstRenderer()); /////////////////////////INTERACTOR//////////////////////////// //Register Phantom to Device Interactor inputInteractor->AddInteractionDevice(phantom1); inputInteractor->AddDeviceInteractorStyle(phantomStyleCamera1); } }
int main(int argc, char **argv) { // OSG init osgInit(argc,argv); { // Set up Window WindowEventProducerRecPtr TutorialWindow = createNativeWindow(); TutorialWindow->initWindow(); // Create the SimpleSceneManager helper SimpleSceneManager sceneManager; TutorialWindow->setDisplayCallback(boost::bind(display, &sceneManager)); TutorialWindow->setReshapeCallback(boost::bind(reshape, _1, &sceneManager)); // Tell the Manager what to manage sceneManager.setWindow(TutorialWindow); TutorialWindow->connectMousePressed(boost::bind(mousePressed, _1, &sceneManager)); TutorialWindow->connectMouseReleased(boost::bind(mouseReleased, _1, &sceneManager)); TutorialWindow->connectMouseDragged(boost::bind(mouseDragged, _1, &sceneManager)); TutorialWindow->connectMouseWheelMoved(boost::bind(mouseWheelMoved, _1, &sceneManager)); TutorialWindow->connectKeyTyped(boost::bind(keyPressed, _1)); // Make Main Scene Node NodeRecPtr Scene = makeCoredNode<Group>(); NodeRecPtr TorusNode = createTorus(); NodeRecPtr SphereNode = createSphere(); NodeRecPtr ConeNode = createCone(); NodeRecPtr BoxNode = createBox(); Scene->addChild(TorusNode); Scene->addChild(SphereNode); Scene->addChild(ConeNode); Scene->addChild(BoxNode); // Create the Graphics GraphicsRecPtr TutorialGraphics = Graphics2D::create(); // Initialize the LookAndFeelManager to enable default settings LookAndFeelManager::the()->getLookAndFeel()->init(); /****************************************************** Create a Background ******************************************************/ ColorLayerRecPtr GreyBackground = ColorLayer::create(); GreyBackground->setColor(Color4f(.93,.93,.93,1.0)); /****************************************************** Create some Borders ******************************************************/ LineBorderRecPtr PanelBorder = LineBorder::create(); EmptyBorderRecPtr Panel1Border = EmptyBorder::create(); EmptyBorderRecPtr Panel2Border = EmptyBorder::create(); EmptyBorderRecPtr emptyBorder = EmptyBorder::create(); PanelBorder->setColor(Color4f(0.0,0.0,0.0,1.0)); PanelBorder->setWidth(1); Panel1Border->setTopWidth(0); Panel1Border->setBottomWidth(6); Panel1Border->setLeftWidth(0); Panel1Border->setRightWidth(0); Panel2Border->setTopWidth(0); Panel2Border->setBottomWidth(0); Panel2Border->setLeftWidth(0); Panel2Border->setRightWidth(0); /****************************************************** Create some Labels and stuff to go with them ******************************************************/ LabelRecPtr LeftPanelLabel1 = Label::create(); UIFontRecPtr LeftPanelLabel1Font = UIFont::create(); LeftPanelLabel1Font->setSize(50); LeftPanelLabel1->setBorders(emptyBorder); LeftPanelLabel1->setBackgrounds(GreyBackground); LeftPanelLabel1->setFont(LeftPanelLabel1Font); LeftPanelLabel1->setText("OSG Gui"); LeftPanelLabel1->setPreferredSize(Vec2f(300, 100)); LeftPanelLabel1->setAlignment(Vec2f(0.0f, 0.5f)); /****************************************************** Create some Layouts ******************************************************/ BoxLayoutRecPtr MainInternalWindowLayout = BoxLayout::create(); FlowLayoutRecPtr LeftPanelLayout = FlowLayout::create(); BoxLayoutRecPtr RightPanelLayout = BoxLayout::create(); MainInternalWindowLayout->setOrientation(BoxLayout::HORIZONTAL_ORIENTATION); LeftPanelLayout->setOrientation(FlowLayout::HORIZONTAL_ORIENTATION); LeftPanelLayout->setMinorAxisAlignment(1.0f); RightPanelLayout->setOrientation(BoxLayout::VERTICAL_ORIENTATION); /****************************************************** Create MainFrame and Panels ******************************************************/ PanelRecPtr LeftPanel = Panel::createEmpty(); PanelRecPtr RightPanel = Panel::createEmpty(); // LeftPanel stuff LeftPanel->setPreferredSize(Vec2f(400, 500)); LeftPanel->pushToChildren(LeftPanelLabel1); PanelRecPtr LeftPanelButtonPanel = createLeftPanelButtonPanel(); LeftPanel->pushToChildren(LeftPanelButtonPanel); PanelRecPtr LeftPanelRadioTextPanel = createLeftPanelRadioTextPanel(); LeftPanel->pushToChildren(LeftPanelRadioTextPanel); LeftPanel->setLayout(LeftPanelLayout); LeftPanel->setBackgrounds(GreyBackground); LeftPanel->setBorders(Panel1Border); //RightPanel stuff RightPanel->setPreferredSize(Vec2f(200, 620)); PanelRecPtr RightPanelButtonPanel = createRightPanelButtonPanel(); RightPanel->pushToChildren(RightPanelButtonPanel); PanelRecPtr RightPanelCheckPanel = createRightPanelCheckPanel(TorusNode, SphereNode, ConeNode, BoxNode); RightPanel->pushToChildren(RightPanelCheckPanel); RightPanel->setLayout(RightPanelLayout); RightPanel->setBackgrounds(GreyBackground); RightPanel->setBorders(Panel2Border); // Create The Main InternalWindow InternalWindowRecPtr MainInternalWindow = InternalWindow::create(); MainInternalWindow->pushToChildren(LeftPanel); MainInternalWindow->pushToChildren(RightPanel); MainInternalWindow->setLayout(MainInternalWindowLayout); MainInternalWindow->setBackgrounds(GreyBackground); MainInternalWindow->setBorders(PanelBorder); MainInternalWindow->setAlignmentInDrawingSurface(Vec2f(0.5f,0.5f)); MainInternalWindow->setScalingInDrawingSurface(Vec2f(1.0f,1.0f)); MainInternalWindow->setDrawTitlebar(false); MainInternalWindow->setResizable(false); //MainInternalWindow->setOpacity(0.7f); // Create the Drawing Surface UIDrawingSurfaceRecPtr TutorialDrawingSurface = UIDrawingSurface::create(); TutorialDrawingSurface->setGraphics(TutorialGraphics); TutorialDrawingSurface->setEventProducer(TutorialWindow); TutorialDrawingSurface->openWindow(MainInternalWindow); // Make A 3D Rectangle to draw the UI on UIRectangleRecPtr UIRectCore = UIRectangle::create(); UIRectCore->setPoint(Pnt3f(-310.0,-310.0,370.0)); UIRectCore->setWidth(620); UIRectCore->setHeight(620); UIRectCore->setDrawingSurface(TutorialDrawingSurface); NodeRecPtr UIRectNode = Node::create(); UIRectNode->setCore(UIRectCore); // add the UIRect as a child Scene->addChild(UIRectNode); sceneManager.setRoot(Scene); // Show the whole Scene sceneManager.showAll(); //Create the Documentation Foreground and add it to the viewport SimpleScreenDoc TheSimpleScreenDoc(&sceneManager, TutorialWindow); //Open Window Vec2f WinSize(TutorialWindow->getDesktopSize() * 0.85f); Pnt2f WinPos((TutorialWindow->getDesktopSize() - WinSize) *0.5); TutorialWindow->openWindow(WinPos, WinSize, "21ExampleInterface"); //Enter main Loop TutorialWindow->mainLoop(); } osgExit(); return 0; }
iPhysicsCollision* iPhysics::createCone(float32 radius, float32 height, const iaMatrixf& offset) { return createCone(radius, height, offset, _shadowWorldID); }