OpenSceneGraph FAQ "Turn"

Source: Internet
Author: User

1, a point on the back of the Earth, calculate its coordinates on the screen, can get it? Isn't it blocked?

A: Calculate the screen coordinates of a space point, using the Osgapex::getscreenposition function. When a space point is in the camera's viewport (regardless of whether it is obscured by another object), it can get its corresponding screen coordinates.

How to tell if a point is on the back of the Earth? You can think of the point at the back of the Earth by calculating the direction of the vertical ground at that point up, the angle to the camera direction, and if the angle is acute. Calculates the up direction of any point on the earth using Osgapex::computelocalupvector.

2. Can I play video in OSG?

A: You can use the QuickTime plugin or the FFmpeg plug-in to play video in OSG, the QuickTime plugin compilation requires the Quicktimesdk,ffmpeg plug-in compilation needs FFmpeg library (www.ffmpeg.org www.ffmpeg.com.cn http://ffmpeg.arrozcru.org/builds/). OSG's QuickTime plugin has stopped updating and is now pushing FFmpeg.

The FFmpeg plugin appears to have been available from version 2.9.

Video playback plug-in can be used to read video files such as AVI into the OSG texture, and to render the texture on the model, such as the realization of a stereoscopic billboard.

3. What is the reason why the illumination result is wrong after the model is scaled?

A: OpenGL's scaling matrix will transform the normal of the model at the same time, thus affecting the lighting effect, so the amplification may cause the model surface illumination is too strong, need to open gl_normalize.

Use of Stateset->setmode (Gl_normalize, Osg::stateattribute::on) in OSG;

4. How to open double-sided illumination in OSG

A: Render properties using Osg::lightmodel

5. Can I play GIF animation in OSG?

A: Yes, with the GIF plugin provided by OSG, you can read the animated GIF image and render it by setting it to a model texture. The object returned by reading the GIF image via the GIF plugin derives from Osg::imagestream, so you can control the animation playback using interfaces such as Paly.

The GIF plugin provides a lightweight, animated texture playback style, which is more suitable for simple applications than QuickTime and other video playback plugins.

In addition, OSG provides a osg::imagesequence class that can be read into multiple static images to form a sequence, and through the ImageStream interface functions to control the continuous playback of multiple pictures.

6, what is baking, how to achieve baking in OSG?

A: Baking, also known as texture baking, is to achieve the dynamic effect of model mapping by pre-rendering a scene to a specified texture per frame. such as the surface reflection, mirror, Countdown card on the beat of the text and other effects of the implementation, you can use texture baking technology.

It is very easy to achieve texture baking in osg, and the following steps are outlined:

Create a texture object, set the size of the texture, pixel format, and bind the texture object to the model;

Create a baking camera, specify the rendering order of Pre_render, specify the implementation as Frame_buffer_object, and bind the camera's color buffer to the texture object;

Add the camera's lower level to the scene you want to render to the texture;

Add the camera to the scene.

Refer to Examples\osgprerender or Demos\rtt for specific examples

7, why my OSG window to see the ball is flat?

Answer: This is because of the problem of setting the projection matrix, generally should be based on the actual aspect ratio of the viewport to set the projection matrix, such as the viewport width, height, respectively, width and height, set the camera projection matrix is camera-> Setprojectionmatrixasperspective (+, (double) width/height, 1.0f,10000.0f);

If the projection matrix is not set according to the actual viewport width, the effect of the picture being compressed or stretched will appear.

When the window size changes, the system automatically responds to wm_size messages through the Graphicscontext object, all cameras associated with that Graphicscontext object (by calling Osg::camera:: Setgraphicscontext the camera is associated with the Graphicscontext, the viewport and projection matrix are updated automatically, and the method of updating the projection matrix is to scale the projection matrix according to the change of the aspect ratio.

You can set a policy for the camera to reset the projection matrix when the window size changes, set to fixed without automatically resetting the projection matrix, and the default setting is horizontal. Osg::camera::setprojectionresizepolicy.

For HUD cameras, because of their use of orthogonal projection matrices, the projection matrix cannot be modified by the scaling above (the orthogonal projection matrix is not only related to the aspect ratio, but also to the width-height value). You can implement a Guieventhandler response Resize event yourself, resetting the viewport and projection matrix of the HUD camera based on the current main viewport width height.

8, what is Vbo, what is Displaylist?

A: Vbo and Displaylist are two of the technologies that OpenGL offers to improve rendering efficiency.

VBO (Vertex Buffer object)-vertex buffer objects, displaylist-display list.

When using VBO, if you modify the contents of the vertex array, you need to invoke the dirty () function of the vertex array to apply the modifications, and if you modify the contents of the vertex array, you need to call Dirtydisplaylist () to apply the modifications.

The display list is used by default in OSG instead of VBO.

9. When did the paging database thread, render thread, and filter thread in OSG exit?

A: The 1.osgviewer::viewer object is destructor-called stopthreading synchronously exits the render and filter threads, and calls the Databasepager::cancel to notify the paging database thread to exit.
2. When the WM_CLOSE message is received, the stopthreading is called to synchronize the render and filter threads.
3. You can manually invoke Stopthreading synchronization to exit the render and filter threads when needed.

10. What is the timing and sequence of OSG handling events?

A: OSG handles input events in the Viewer::eventtraversal function, Eventtraversal is called before the update traversal and render traversal of the frame loop.
The order of event processing in Eventtraversal is:
1. To traverse the scene tree for each event in this frame, call the event handling callback of node, drawable, Stateset object to handle the event.
2. Loop through the viewer's event handler (Guieventhandler) queue for each event in this frame, calling the event handler to handle the event.
3. For each event in this frame, call the viewer's camera operator (Cameramanipulator) to handle the event.

11. What is the function of switch node?

A: The switch node inherits from the group node, which corresponds to the Childlis has a boollist that holds a switch value for each child node, and when the child node switch is closed, the child node is guaranteed not to be accessed by accessors that are of the type active child node.
When the sub-node switch is off, the child nodes do not participate in the bounding box calculation.

12. What is the role of Nodemask and Traversalmask?

A: Nodemask (32-bit unsigned) is used as a property of the node class to limit whether a node can be accessed by a specified node accessor. The default value is 0xFFFFFFFF.
Traversalmask (and Overridemask) acts as a property of the node accessor, which is used to restrict which nodes the node accessor can access. The default value is 0xFFFFFFFF.
Whether a node can be accessed by accessors depends on: Traversalmask & (Overridemask | Nodemask)

13. What is the role of Osg::colormask?

A: Colormask encapsulates the function of the Glcolormask function to set the write mask for the color buffer, that is, whether the write operation is performed on R, G, B, and a bits.
You can use Colormask and set the write mask for Rgba to False when you only need to write depth buffers or template buffers, and not actually draw objects.

14, how to layout the screen elements (text, pictures, etc.)

A: Screen elements are typically rendered using the HUD (i.e. orthographic projection), where an orthographic projection camera can be defined in OSG, and the screen element is added as a child node to the HUD camera for rendering. The layout and scaling of elements are generally handled in two ways:
First, according to the actual size of the viewport layout, while tracking the size of the output window changes, and the actual size of the window to update the HUD camera projection matrix and viewport. This approach not only updates the camera's projection matrix and viewport dynamically, but also writes code to dynamically update the position and size of the screen element based on the viewport size change, such as updating the position by the specified alignment, and updating the size at the specified size scale. You can also update only the location not to update the size, so that the effect is that the size of the screen element does not scale with the window.
Second, according to the fixed size of the specified layout, while setting the HUD camera projection matrix for the same width and height of the fixed value, tracking Output window size changes, according to the actual size of the window to update the HUD camera viewport. In this way, you only need to write code to update the viewport of the camera, and the size and position of the screen elements are always calculated as the initial fixed viewport size and do not need to be adjusted with the window changes. The effect is that the size and layout of the screen elements and the window are scaled.

15. Similarities and differences between SetAttribute and Setattributeandmodes

A: SetAttribute is used to set the override mode for the rendering properties and properties, and the second parameter has a valid value of only the combination of override and protected, which does not affect the state of the property switch (setting on/off is not valid)!
Setattributeandmodes setting the render properties and overwrite modes also sets the switch for the property state.
The setattribute is used to set the rendering properties without changing the state, depending on the settings of the child nodes.

16. What are the optimization efficiency algorithms in OSG scene screening?
A: The main filtering methods used in OSG scene screening are: visual body screening, minimum pixel filtering and occlusion filtering. The visual body screening is the most basic and most commonly used screening method, its algorithm is: the use of the various faces of the visual body and the node bounding box intersection, if the node is outside a certain surface, then the node and its child nodes are rejected; If the node is completely within a polygon, Then all child nodes of the node do not need to be cross-checked with this face (the child node must also be completely within this plane) when the filter is calculated. In view of this filtering implementation, it is possible to use the tree structure scene graph to organize the scene nodes to improve the filtering efficiency.

17. I use OSG rendering in the static control of MFC, but I can't respond to mouse events.
A: This is entirely an issue with MFC controls, and to make the static control in the dialog box receive mouse messages, you need to set the notify of the static control property to True.


18, OSG rendering sort is done, what interfaces can be used to control the rendering order?
A: OSG generates a render tree of renderstage (root node), Renderbin (branch node), and Renderleaf (render leaf) by scene picking (cull), while generating a render state tree composed of stategraph, The final rendering operation is performed through the render tree, in the order of rendering:
Renderstage::d Raw
|
Renderstage::d rawprerenderstages
|
Renderstage::d rawinner-------------------------------------------renderbin::d Raw
| |
Renderstage::d rawpostrenderstages binnum Sub-bin less than 0 (in Binnum ascending order)
|
Render Yele (sorted) for this bin
|
Render leaves in all stategraph that are hung under this bin
|
Other sub-bin (press Binnum Ascending)
During the picking process, the Drawable object through the picking test is added to the render leaf list of the current Stategraph object, while Stategraph is referenced by the current Renderbin object, and the final rendering is Some of the rendered leaves are also found and rendered by the Stategraph object referenced by the Renderbin, and the other render leaves (the sorting mode of the renderbin corresponds to Front_to_back/back_to_front/traversal_ Order) is transferred to the Renderbin's rendered leaf list and then rendered.

We can control the rendering order of the corresponding nodes through Stateset's Binnum and binname settings.
1) binname for "Renderbin", "Statesortedbin" The default sort mode is Sort_by_state (currently implemented as not sorted)
The default ordering for "Depthsortedbin" for Binname is Sort_back_to_front (from far to near for alpha blending of semi-transparent objects)
The default sort of binname for "Traversalorderbin" is Traversal_order (that is, sorted by traversed order).
2) Binnum Small front rendering
3) Setnestrenderbins Sets whether Renderbin allows nesting, true that the newly renderbin is added as the child node of the current Renderbin, False the Renderbin is added as a child node of the Renderstage (root node).

19, OSG How to map the key combinations?
A: Because of the characteristics of the Win32 API, OSG had to convert the Ctrl+letter to {1,.., 26}, that is, CTRL + a Getkey () is 1, and CTRL + Z Getkey () for 26;shift+a~z is mapped to uppercase ' a ' ~ ' Z '.

20. Why does OSG automatically create a mipmap for my texture objects?
A: OSG automatically creates mipmap for non-mipmap mapped texture objects when texture filtering mode min_filter is set to one of the 4 mipmap-based types. The default value for Min_filter is linear_mipmap_linear, so the ability to automatically create MIPMAP is enabled if texture filtering is not explicitly set.

21, the role of texture::setunrefimagedataafterapply?
A: When this value is set to True, OSG automatically releases its reference to the image object after the texture object has been applied (apply) to reduce memory consumption.

22, the role of Osgdb::sharedstatemanager?
A: Sharedstatemanager is used to perform shared optimizations on stateset and texture objects in the system, that is, multiple texture objects of the same content in the system, preserving only one instance, and others using references to reduce memory consumption and increase rendering efficiency. Call the Osgdb::registry ()->getorcreatesharedstatemanager ()->share function for the newly loaded or created node object, using the method.

23. How to open the pre-compilation function of the paging database?
A: There are two things to do, 1) set OSG::D isplaysettings::instance ()->setcompilecontextshint (true), which enables the viewer to create a background GC for pre-compilation operations at realize ; 2) Call Osgdb::D Abasepager::setdoprecompile (true) to turn on the precompilation feature.

OpenSceneGraph FAQ "Turn"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.