Graph three-dimensional rotation and perspective method and system
By generating and combining miscut-perspective matrix, scaling matrix and inverse rotation matrix, the problem of high-cost 3D rendering in the embedded field is solved, and efficient 3D rotation and perspective rendering effects on 2D GPUs are achieved.
Patent Information
- Application Number
- CN202311823689.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-26
- Publication Date
- 2024-12-13
AI Technical Summary
In the prior art, three-dimensional rendering usually requires the support of 4x4 matrix, but this requires the support of 3D GPUs. 3D GPUs are relatively complex and expensive, and it is difficult to achieve efficient three-dimensional rendering in the embedded field.
By obtaining two-dimensional graphics, generating rotation matrix, plane rotation angle and three-dimensional rotation angle, calculating the wrong-cut-perspective matrix, scaling matrix and inverse rotation matrix, combining these matrices to generate a rotation perspective matrix, and rendering with a low-cost 2D GPU.
It realizes efficient 3D rotation and perspective rendering on low-cost GPUs, reducing hardware costs and improving rendering efficiency.
Smart Images

Figure CN119131315A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the display rendering field of embedded devices, and in particular to a three-dimensional graphic rotation and perspective method and system. Background Art
[0002] 3D rendering is an important technology in the field of computer graphics, used to create realistic 3D graphics or animations. It involves converting the mathematical representation of a 3D scene into a 2D graphic to be displayed on the screen or printed out.
[0003] GPUs play a vital role in 3D rendering. Their parallel computing capabilities, graphics pipelines, shader programs, and graphics APIs make them a key component for achieving high-performance, realistic, and interactive 3D rendering. Therefore, GPU technology has been evolving to meet the increasingly high demands of graphics rendering.
[0004] In 3D rendering, 3D transformation is usually achieved through matrix operations, where the rotation matrix is used to change the direction of a 3D object. 3D rendering usually uses a 4x4 matrix, but to support a 4x4 matrix, a 3D GPU is required, which is generally complex and expensive. For the embedded field, 3D rendering still requires a lot of computing resources, and often only a 2D GPU can be used for 2D rendering. Usually the 2D rendering matrix is a 3x3 matrix, but the 3x3 matrix and the corresponding points lack data in the Z-axis direction.
[0005] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present disclosure, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention
[0006] Therefore, the technical problem to be solved by the present invention is to overcome the problem that the prior art usually uses a 4x4 matrix for three-dimensional rendering. However, to support a 4x4 matrix, a 3D GPU is required, and a 3D GPU is generally complex and expensive. For the embedded field, three-dimensional rendering still requires a lot of computing resources, and often only a 2D GPU can be used for two-dimensional rendering. Usually, the two-dimensional rendering matrix is a 3x3 matrix, but the 3x3 matrix and the corresponding points lack data in the Z-axis direction.
[0007] In order to solve the above technical problems, the first aspect of the present invention provides a three-dimensional rotation and perspective method of a graphic, the method comprising:
[0008] Get a two-dimensional graphic;
[0009] Rotating the two-dimensional graphic to generate a rotation matrix, a plane rotation angle, and a three-dimensional rotation angle;
[0010] generating a shear-perspective matrix according to the three-dimensional rotation angle;
[0011] generating a scaling matrix according to the three-dimensional rotation angle;
[0012] Generate an inverse rotation matrix according to the plane rotation angle;
[0013] Generate a rotation perspective matrix according to the rotation matrix, the shear-perspective matrix, the scaling matrix and the inverse rotation matrix;
[0014] The GPU draws each point according to the rotation perspective matrix to generate a target three-dimensional graphic.
[0015] In one embodiment of the present invention, the two-dimensional graphic is rotated to generate a rotation matrix, a plane rotation angle, and a three-dimensional rotation angle:
[0016] Rotate the two-dimensional figure around the Y axis and the Z axis to generate a first angle;
[0017] Rotate the two-dimensional figure around the X-axis and the Z-axis to generate a second angle;
[0018] Generate the plane rotation angle and the three-dimensional rotation angle according to the first angle and the second angle;
[0019] The rotation matrix is generated according to the plane rotation angle.
[0020] In one embodiment of the present invention, the step of generating a scaling matrix according to the three-dimensional rotation angle comprises:
[0021] Calculating a scaling amount according to the three-dimensional rotation angle;
[0022] A scaling matrix is generated according to the scaling amount and the three-dimensional rotation angle.
[0023] In one embodiment of the present invention, the calculation formula of the scaling matrix is as follows:
[0024]
[0025] Where abs(cosθ) is the scaling amount.
[0026] In one embodiment of the present invention, the step of generating an inverse rotation matrix according to the plane rotation angle includes:
[0027] generating an inverse plane rotation angle according to the plane rotation angle;
[0028] Generates an inverse rotation matrix based on the inverse plane rotation angle.
[0029] In one embodiment of the present invention, the calculation formula of the plane rotation angle is as follows:
[0030] a=arctan(yRad / xRad)
[0031] Wherein, yRad is the first angle, and xRad is the second angle.
[0032] In one embodiment of the present invention, the calculation formula of the shear-perspective matrix is as follows:
[0033]
[0034] Where θ is the three-dimensional rotation angle.
[0035] The second aspect of the present invention provides a three-dimensional rotation and perspective system for graphics, which is applied to a method proposed in any one of the first aspects above, and the system comprises: a rotation module, a shear perspective module, a reverse scaling module, a reverse rotation module and a rotation perspective module;
[0036] The rotation module is configured to: obtain a two-dimensional graphic; rotate the two-dimensional graphic to generate a rotation matrix, a plane rotation angle, and a three-dimensional rotation angle;
[0037] The shear-perspective module is configured to: generate a shear-perspective matrix according to the three-dimensional rotation angle;
[0038] The inverse scaling module is configured to: generate a scaling matrix according to the three-dimensional rotation angle;
[0039] The inverse rotation module is configured to: generate an inverse rotation matrix according to the plane rotation angle
[0040] The rotation perspective module is configured to: generate a rotation perspective matrix according to the rotation matrix, the shear-perspective matrix, the scaling matrix and the inverse rotation matrix; and the GPU draws each point according to the rotation perspective matrix to generate a target three-dimensional graphic.
[0041] The third aspect of the present invention provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method described in the first aspect or any possible implementation of the first aspect is implemented.
[0042] A fourth aspect of the present invention provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in the first aspect or any possible implementation of the first aspect.
[0043] The above technical solution of the present invention has the following advantages compared with the prior art:
[0044] The three-dimensional rotation and perspective method and system of the present invention performs shearing and perspective on the rotated two-dimensional graphics through the shear-perspective matrix, and then performs reverse scaling and reverse rotation on the graphics, so as to achieve the purpose of low-cost GPU rendering with higher efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to make the contents of the present invention more clearly understood, the present invention is further described in detail below based on specific embodiments of the present invention in conjunction with the accompanying drawings.
[0046] Figure 1 It is a flow chart of a method and system for three-dimensional rotation and perspective of a graphic provided by the present invention;
[0047] Figure 2 It is a system architecture diagram of a three-dimensional graphic rotation and perspective method and system provided by the present invention. DETAILED DESCRIPTION
[0048] The present invention is further described below in conjunction with the accompanying drawings and specific embodiments so that those skilled in the art can better understand the present invention and implement it, but the embodiments are not intended to limit the present invention.
[0049] In addition, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various configurations. Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application.
[0050] Reference Figure 1 As shown, the present invention provides a three-dimensional rotation and perspective method for a graphic, the method comprising:
[0051] S100, obtaining a two-dimensional graphic;
[0052] In step S100, a two-dimensional graphic that needs to be rotated and perspective is obtained.
[0053] S200, rotating the two-dimensional graphic to generate a rotation matrix, a plane rotation angle, and a three-dimensional rotation angle;
[0054] In step S200, the two-dimensional graphic is rotated, and the steps of generating a rotated two-dimensional graphic include: rotating the two-dimensional graphic around the Y axis to the Z axis to generate a first angle; rotating the two-dimensional graphic around the X axis to the Z axis to generate a second angle; generating a plane rotation angle and a three-dimensional rotation angle according to the first angle and the second angle; generating the rotation matrix according to the plane rotation angle. The calculation formula of the plane rotation angle is as follows:
[0055] a = arctan(yRad / xRad) (1);
[0056] Wherein, yRad is the first angle, and xRad is the second angle.
[0057] In actual application scenarios, in GPUs, 3x3 matrices are typically used for 2D graphics transformations such as translation, rotation, scaling, and shearing, and these transformations typically only involve the first two rows. The values of the third row (0 0 1) are to ensure that no perspective effect is introduced, and perspective transformation is not required in 2D graphics rendering. Therefore, the GPU typically does not process the two components of the third row because their values are typically fixed in 2D graphics rendering. The GPU only focuses on the first two rows to perform various 2D graphics transformations. This helps to improve the performance and efficiency of graphics rendering. However, the GPU involved in this application will calculate the third row of the 3x3 matrix when encountering three-dimensional rendering.
[0058] The acquired two-dimensional figure is rotated. Since it needs to rotate around two axes, that is, around the X and Y axes respectively, specifically, the two-dimensional figure is rotated around the Y axis to the Z axis, and the angle between the two-dimensional figure and the Z axis after the rotation is the first angle yRad. The two-dimensional figure is rotated around the X axis to the Z axis, and the angle between the two-dimensional figure and the Z axis after the rotation is the second angle xRad, wherein the first angle yRad and the second angle xRad are normalized to between -π / 2 and π / 2. If the second angle xRad is not 0, the plane rotation angle a is calculated according to formula (1), otherwise the value of the plane rotation angle a is π / 2. The three-dimensional rotation angle θ is calculated according to formula (2).
[0059] θ=max(abs(xRad), abs(yRad)) (2);
[0060] Wherein, abs(xRad) is the scaling amount of the second angle, and abs(yRad) is the scaling amount of the first angle.
[0061] If xRad is less than 0, θ=-θ, and a rotation matrix is generated according to the plane rotation angle.
[0062]
[0063] The rotation matrix is shown in formula (3).
[0064] S300, generating a shear-perspective matrix according to the three-dimensional rotation angle;
[0065] In step S300, the calculation formula of the shear-perspective matrix is as follows:
[0066]
[0067] Where θ is the three-dimensional rotation angle.
[0068] In practical application scenarios, the shear-perspective matrix can be calculated according to the three-dimensional rotation angle using formula (4).
[0069] S400, generating a scaling matrix according to the three-dimensional rotation angle;
[0070] In step S400, the step of generating a scaling matrix according to the three-dimensional rotation angle includes: calculating a scaling amount according to the three-dimensional rotation angle; and generating a scaling matrix according to the scaling amount and the three-dimensional rotation angle.
[0071] In actual application scenarios, the scaling amount abs(cosθ) is calculated according to the obtained three-dimensional rotation angle θ, and the scaling matrix is calculated according to the scaling amount and the three-dimensional rotation angle. The scaling matrix is shown in formula (5):
[0072]
[0073] Where abs(cosθ) is the scaling amount.
[0074] S500: Generate an inverse rotation matrix according to the plane rotation angle.
[0075] In step S500, the step of generating an inverse rotation matrix according to the plane rotation angle includes: generating an inverse plane rotation angle according to the plane rotation angle; generating an inverse rotation matrix according to the inverse plane rotation angle.
[0076] In actual application scenarios, the inverse plane rotation angle -a is obtained according to the plane rotation angle a, and the inverse rotation matrix is generated according to the inverse plane rotation angle -a.
[0077]
[0078] The inverse rotation matrix is shown in formula (6).
[0079] S600: Generate a rotation perspective matrix according to the rotation matrix, the shear-perspective matrix, the scaling matrix and the inverse rotation matrix.
[0080] In practical application scenarios, the rotation perspective matrix can be generated according to the rotation matrix, the shear-perspective matrix, the scaling matrix and the inverse rotation matrix. The rotation perspective matrix is shown in formula (7):
[0081]
[0082] Among them, θ is the three-dimensional rotation angle, and abs(cosθ) is the scaling amount.
[0083] S700: GPU draws each point according to the rotation perspective matrix to generate a target three-dimensional graphic.
[0084] In actual application scenarios, the GPU uses a rotation perspective matrix for all points on a two-dimensional graphic to draw each point and ultimately obtain the target three-dimensional graphic.
[0085] Second, refer to Figure 2 As shown, the present application provides a three-dimensional graphic rotation and perspective system, the system comprising: a rotation module 100, a shear perspective module 200, a reverse scaling module 300, a reverse rotation module 400 and a rotation perspective module 500;
[0086] The rotation module 100 is configured to: obtain a two-dimensional graphic; rotate the two-dimensional graphic to generate a rotation matrix, a plane rotation angle, and a three-dimensional rotation angle;
[0087] The shear-perspective module 200 is configured to: generate a shear-perspective matrix according to the three-dimensional rotation angle;
[0088] The reverse scaling module 300 is configured to: generate a scaling matrix according to the three-dimensional rotation angle;
[0089] The inverse rotation module 400 is configured to: generate an inverse rotation matrix according to the plane rotation angle;
[0090] The rotation perspective module 500 is configured to: generate a rotation perspective matrix according to the rotation matrix, the shear-perspective matrix, the scaling matrix and the inverse rotation matrix; and the GPU draws each point according to the rotation perspective matrix to generate a target three-dimensional graphic.
[0091] The effects of the above-mentioned system when applying the above-mentioned method can be found in the description of the above-mentioned method embodiment, which will not be repeated here.
[0092] The third aspect of the present invention provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the method described in the first aspect or any possible implementation of the first aspect is implemented.
[0093] A fourth aspect of the present invention provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in the first aspect or any possible implementation of the first aspect.
[0094] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.
[0095] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0096] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0097] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0098] Obviously, the above embodiments are merely examples for clear explanation and are not intended to limit the implementation methods. For those skilled in the art, other different forms of changes or modifications can be made based on the above description. It is not necessary and impossible to list all the implementation methods here. The obvious changes or modifications derived from these are still within the protection scope of the invention.
Claims
1. A three-dimensional rotation and perspective method for a graphic, characterized in that: The method comprises: Get a two-dimensional graphic; Rotating the two-dimensional graphic to generate a rotation matrix, a plane rotation angle, and a three-dimensional rotation angle; generating a shear-perspective matrix according to the three-dimensional rotation angle; generating a scaling matrix according to the three-dimensional rotation angle; Generate an inverse rotation matrix according to the plane rotation angle; Generate a rotation perspective matrix according to the rotation matrix, the shear-perspective matrix, the scaling matrix and the inverse rotation matrix; The GPU draws each point according to the rotation perspective matrix to generate a target three-dimensional graphic.
2. A three-dimensional rotation and perspective method for graphics according to claim 1, characterized in that: The steps of rotating the two-dimensional graphic to generate a rotation matrix, a plane rotation angle and a three-dimensional rotation angle include: Rotate the two-dimensional figure around the Y axis and the Z axis to generate a first angle; Rotate the two-dimensional figure around the X-axis and the Z-axis to generate a second angle; Generate the plane rotation angle and the three-dimensional rotation angle according to the first angle and the second angle; The rotation matrix is generated according to the plane rotation angle.
3. A three-dimensional rotation and perspective method for graphics according to claim 1, characterized in that: The step of generating a scaling matrix according to the three-dimensional rotation angle comprises: Calculating a scaling amount according to the three-dimensional rotation angle; The scaling matrix is generated according to the scaling amount and the three-dimensional rotation angle.
4. A three-dimensional rotation and perspective method for graphics according to claim 1, characterized in that: The calculation formula of the scaling matrix is as follows: Where abs(cosθ) is the scaling amount.
5. A three-dimensional rotation and perspective method for graphics according to claim 1, characterized in that: The step of generating an inverse rotation matrix according to the plane rotation angle comprises: generating an inverse plane rotation angle according to the plane rotation angle; Generates an inverse rotation matrix based on the inverse plane rotation angle.
6. A three-dimensional rotation and perspective method of a graphic according to claim 2, characterized in that: The calculation formula of the plane rotation angle is as follows: a=arctan(yRad / xRad) Wherein, yRad is the first angle, and xRad is the second angle.
7. A method for three-dimensional rotation and perspective of a graphic according to claim 1, characterized in that: The calculation formula of the shear-perspective matrix is as follows: Where θ is the three-dimensional rotation angle.
8. A three-dimensional graphics rotation and perspective system, characterized in that: A three-dimensional rotation and perspective method for a graphic as described in any one of claims 1 to 7, the system comprising: a rotation module, a shear perspective module, a reverse scaling module, a reverse rotation module and a rotation perspective module; The rotation module is configured to: obtain a two-dimensional graphic; rotate the two-dimensional graphic to generate a rotation matrix, a plane rotation angle, and a three-dimensional rotation angle; The shear-perspective module is configured to: generate a shear-perspective matrix according to the three-dimensional rotation angle; The inverse scaling module is configured to: generate a scaling matrix according to the three-dimensional rotation angle; The inverse rotation module is configured to: generate an inverse rotation matrix according to the plane rotation angle; The rotation perspective module is configured to: generate a rotation perspective matrix according to the rotation matrix, the shear-perspective matrix, the scaling matrix and the inverse rotation matrix; and the GPU draws each point according to the rotation perspective matrix to generate a target three-dimensional graphic.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the steps of a three-dimensional rotation and perspective method of a graphic as described in any one of claims 1 to 7 are implemented.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of a three-dimensional rotation and perspective method of a graphic as described in any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Three-dimensional overturning interface switching method and device based on 2.5 D
CN120596174A
