Disclosure of Invention
In view of the foregoing deficiencies of the prior art, an object of the present invention is to provide a method and a system for locking display contents in a virtual reality mode, which aim to solve the problem that the existing virtual reality mode cannot lock specific display contents and is inconvenient for a user to view the specific display contents.
The technical scheme of the invention is as follows:
a method for locking display content in a virtual display mode comprises the following steps:
A. when the VR equipment worn by a user is detected to rotate, reading gyroscope data arranged in the VR equipment in real time;
B. calculating to obtain a scene rotation matrix and a matrix of the display content to be locked according to the gyroscope data;
C. and submitting the scene rotation matrix and the change matrix of the display content to be locked to OpenGL ES for rendering, and entering the rotated virtual reality scene.
Preferably, the method for locking display content in the virtual display mode, wherein the step a includes:
a0, initializing the OpenGL ES environment and the gyroscope.
Preferably, the method for locking display content in the virtual display mode, wherein the step B specifically includes:
b1, calculating according to the gyroscope data to obtain a VR equipment rotation matrix, a visual angle transformation matrix and a cutting matrix;
and B2, calculating to obtain a scene rotation matrix according to the VR equipment rotation matrix, the visual angle transformation matrix and the cutting matrix.
Preferably, the method for locking display content in the virtual display mode, wherein the step B further includes:
b3, initializing shaders of OpenGL ES, and reading the environment and the texture of the object.
Preferably, the method for locking display content in the virtual display mode, wherein the step C specifically includes:
c1, the environment renderer calls OpenGL ES to render the scene rotation matrix;
and C2, calling OpenGL ES by the object renderer to render the change matrix with the locked display content.
A system for locking display content in a virtual display mode, comprising:
the reading module is used for reading gyroscope data arranged in the VR equipment in real time when the VR equipment worn by a user is detected to rotate;
the calculation module is used for calculating to obtain a scene rotation matrix and a change matrix of the display content to be locked according to the gyroscope data;
and the rendering module is used for submitting the scene rotation matrix and the change matrix of the display content to be locked to OpenGL ES for rendering and entering the rotated virtual reality scene.
Preferably, the system for locking display content in the virtual display mode further comprises:
and the initialization module is used for initializing both the OpenGL ES environment and the gyroscope.
Preferably, the system for locking display content in the virtual display mode, wherein the computing module specifically includes:
the first calculation unit is used for calculating to obtain a VR equipment rotation matrix, a visual angle transformation matrix and a cutting matrix according to the gyroscope data;
and the second calculation unit is used for calculating a scene rotation matrix according to the VR equipment rotation matrix, the visual angle transformation matrix and the cutting matrix.
Preferably, the system for locking display content in the virtual display mode, wherein the computing module further comprises:
and the reading unit is used for carrying out initialization processing on the shader of the OpenGL ES and reading the environment and the texture of the object.
Preferably, the system for locking display content in the virtual display mode, wherein the rendering module specifically includes:
the environment renderer is used for calling OpenGL ES and rendering the scene rotation matrix;
and the object renderer is used for calling OpenGL ES and rendering the matrix with the locked display content.
Has the advantages that: the method and the system for locking the display content in the virtual reality mode realize the locking of the specific display content, when the VR equipment worn by the head of the user rotates, the scene part around the virtual reality still changes along with the head, and the specific display part does not leave the visual field of the user due to the rotation of the head, so that great convenience is brought to the user for watching the content of the specific display part through the locking mode.
Detailed Description
The present invention provides a method and system for locking display content in a virtual reality mode, and the following further describes the present invention in detail in order to make the purpose, technical scheme and effect of the present invention clearer and clearer. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
Referring to fig. 1, fig. 1 is a flowchart illustrating a method for locking display contents in a virtual reality mode according to a preferred embodiment of the present invention, as shown in the figure, the method includes the following steps:
s100, reading gyroscope data arranged in VR equipment in real time when the VR equipment worn by a user is detected to rotate;
s200, calculating according to the gyroscope data to obtain a scene rotation matrix and a matrix of display content to be locked;
and S300, submitting the scene rotation matrix and the change matrix of the display content to be locked to OpenGL ES for rendering, and entering the rotated virtual reality scene.
The invention realizes the locking of the specific display content in the virtual reality mode, namely, when the VR equipment worn by the head of the user rotates, the unlocked part of the virtual reality surrounding scene still changes along with the rotation of the head, but the specific display part does not leave the visual field of the user due to the rotation of the head, thereby bringing great convenience for the user to watch the content of the specific display part through the locking mode.
For example, when a user watches a 2D video by using a VR device, if a video display part is set at a middle fixed position of a virtual reality scene, if the video display part is locked, the video display part is always located at the middle fixed position of the virtual display scene no matter the VR device worn by the user rotates, and no corresponding position change is performed due to the rotation of the VR device worn by the user, so that the user can always see the video at the middle fixed position of the virtual display scene, thereby bringing great convenience to the user.
Further, in the present invention, the step S100 includes, before:
s10, initializing both an OpenGL ES environment and a gyroscope, specifically, initializing shaders of the OpenGL ES environment, and reading textures of the environment and an object; further, a sensor module is arranged in the VR equipment, and the gyroscope is initialized through the sensor module to prepare for reading gyroscope data.
Further, in the present invention, the step S100 specifically includes:
s110, calculating to obtain a VR equipment rotation matrix, a visual angle transformation matrix and a cutting matrix according to the gyroscope data;
specifically, in a virtual reality mode, a user can adjust the angle of watching a video by rotating VR equipment at the head, and a sensor module in the VR equipment is responsible for initializing a gyroscope, reading data of the gyroscope in real time and sending the data to a rendering module in the VR equipment;
specifically, the rendering module performs rendering through OpenGL ES, and virtual reality requires a user to see two similar pictures with slight viewing angle difference by the left and right eyes, so that a mobile phone screen needs to be divided into a left part and a right part for rendering respectively; the rendering module comprises two sub-modules which are an environment renderer and an object renderer respectively, and the two sub-modules calculate matrixes respectively according to data provided by the gyroscope; the environment renderer calculates a VR equipment rotation matrix, a visual angle transformation matrix and a cutting matrix according to gyroscope data; further, the object renderer calculates a matrix of the display content to be locked according to the fixed matrix.
And S120, calculating to obtain a scene rotation matrix according to the VR equipment rotation matrix, the visual angle transformation matrix and the cutting matrix.
Further, the environment renderer calculates a scene rotation matrix according to the VR device rotation matrix, the view transformation matrix and the clipping matrix.
Further, in the present invention, the step S300 specifically includes:
s310, the environment renderer calls OpenGL ES to render the scene rotation matrix;
and S320, the object renderer calls OpenGL ES to render the matrix of the display content to be locked.
Specifically, the environment renderer binds coordinates and textures in advance, and invokes OpenGL ES to render the scene rotation matrix to obtain a rotated virtual reality environment; and simultaneously, the object renderer calls OpenGL ES to render a matrix of the display content to be locked, and a display picture of the display content to be locked in the rotated virtual reality environment is obtained.
Based on the above method, the present invention further provides a system for locking display content in a virtual display mode, as shown in fig. 2, wherein the system comprises:
the reading module 100 is configured to read gyroscope data set in VR equipment in real time when it is detected that the VR equipment worn by a user rotates;
the calculation module 200 is configured to calculate a scene rotation matrix and a change matrix of the to-be-locked display content according to the gyroscope data;
the rendering module 300 is configured to submit the scene rotation matrix and the change matrix of the to-be-locked display content to OpenGL ES for rendering, and enter the rotated virtual reality scene.
Preferably, the system for locking display content in the virtual display mode further comprises:
and the initialization module is used for initializing both the OpenGL ES environment and the gyroscope.
Preferably, the system for locking display content in the virtual display mode, wherein the computing module specifically includes:
the first calculation unit is used for calculating to obtain a VR equipment rotation matrix, a visual angle transformation matrix and a cutting matrix according to the gyroscope data;
and the second calculation unit is used for calculating a scene rotation matrix according to the VR equipment rotation matrix, the visual angle transformation matrix and the cutting matrix.
Preferably, the system for locking display content in the virtual display mode, wherein the computing module further comprises:
and the reading unit is used for carrying out initialization processing on the shader of the OpenGL ES and reading the environment and the texture of the object.
Preferably, the system for locking display content in the virtual display mode, wherein the rendering module specifically includes:
the environment renderer is used for calling OpenGL ES and rendering the scene rotation matrix;
and the object renderer is used for calling OpenGL ES and rendering the matrix with the locked display content.
In summary, the method and the system for locking the display content in the virtual reality mode provided by the invention realize the locking of the specific display content, when the VR device worn on the head of the user rotates, the scene part around the virtual reality still changes along with the head, and the specific display part does not leave the visual field of the user due to the rotation of the head, so that great convenience is brought to the user for watching the content of the specific display part through the locking mode.
It is to be understood that the invention is not limited to the examples described above, but that modifications and variations may be effected thereto by those of ordinary skill in the art in light of the foregoing description, and that all such modifications and variations are intended to be within the scope of the invention as defined by the appended claims.