A method, apparatus and electronic device for controlling a virtual camera in a virtual scene
By constructing a target range for the virtual camera and objects, and adjusting the camera position to avoid obstacles, the problem of obstacles obstructing the virtual camera's image path is solved, thus improving the user experience.
Patent Information
- Application Number
- CN202310791839.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-29
- Publication Date
- 2026-08-25
- Estimated Expiration
- 2043-06-29
AI Technical Summary
When a virtual camera captures images of virtual objects, obstacles obstructing the path can degrade the user experience. Existing technologies can create a sense of abrupt change by making obstacles semi-transparent or transparent.
Construct the target range for the virtual camera and virtual objects, and adjust the distance between the virtual camera and the objects to avoid obstacles and prevent them from entering the image acquisition path.
To improve the user experience and avoid the abrupt disappearance of obstacles, the camera position is adjusted in time to avoid obstacles by predicting their approach to the path.
Smart Images

Figure CN116764208B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of game technology, and in particular to a method, device, and electronic device for controlling a virtual camera in a virtual scene. Background Technology
[0002] As users' entertainment needs expand, various online games are gradually coming into view, such as combat games and treasure hunting games.
[0003] In the game, players can choose a character to represent them. A virtual camera can be positioned behind this character at a preset distance, with a fixed camera angle. This virtual camera, while maintaining the same camera angle and distance, follows the character's movement and captures images of the character within the game scene. Therefore, the various images seen by the player are the images of the character captured by the virtual camera, and the character is present in every frame.
[0004] As the game character moves, there may be situations where the character enters buildings in the game scene or goes around obstacles in the game scene. In these situations, obstacles may appear between the virtual camera and the game character, and these obstacles may block the virtual camera's image capture path for the game character, causing the virtual camera to be unable to capture the image of the game character.
[0005] In related technologies, when an obstacle is detected in the path of a virtual camera capturing the image of a game character, the obstacle can be processed to be semi-transparent or completely transparent. In this way, although an obstacle still exists in the path of the virtual camera capturing the image of the game character, the virtual camera can still capture the game character through the obstacle.
[0006] However, in the aforementioned technologies, treating obstacles as semi-transparent or completely transparent can give users a sudden feeling of the obstacles disappearing abruptly, thus affecting the user's gaming experience. Summary of the Invention
[0007] The purpose of this application is to provide a method, device, and electronic device for controlling a virtual camera in a virtual scene, so as to avoid obstacles obstructing the virtual camera's image acquisition path for virtual objects and improve user experience. The specific technical solution is as follows:
[0008] In a first aspect, embodiments of this application provide a method for controlling a virtual camera in a virtual scene, applied to an electronic device. The electronic device provides a user interface to a user, and the virtual scene includes a virtual object controlled by the electronic device and a virtual camera that captures images of the virtual object. The content displayed on the user interface includes the content captured by the virtual camera in the virtual scene. The method includes:
[0009] In response to an operation command sent by the user for the virtual object, the system controls the virtual object to move within the virtual scene and controls the virtual camera to follow the virtual object's movement; wherein, the virtual scene is a three-dimensional scene;
[0010] Based on the acquisition distance of the virtual camera when acquiring images of the virtual object, and the current positions of the virtual camera and the virtual object in the virtual scene, a target range including the virtual camera and the virtual object is constructed; wherein, the target range moves with the virtual camera and the virtual object;
[0011] For each frame captured by the virtual camera, if an obstacle is detected in the virtual scene at the time the virtual camera captures that frame, and the detection distance between the obstacle and the target area is not greater than a preset distance, then within a numerical range with a preset initial distance as the maximum value and a calibration distance as the minimum value, the target distance between the virtual camera and the virtual object is determined when the detection distance is greater than the preset distance; wherein, the calibration distance is the distance between the virtual object and a calibration point, and the calibration point is: a point on the line connecting the virtual camera and the virtual object, excluding the points where the virtual camera and the virtual object are located;
[0012] Control the virtual camera to move to a position on the line connecting the virtual camera and the virtual object, at a distance equal to the target distance from the virtual object.
[0013] Optionally, in one specific implementation, the method further includes:
[0014] When the virtual camera is detected to have completed its movement, the virtual camera is controlled to capture an image of the virtual object, thus obtaining the next frame of the virtual object.
[0015] Optionally, in one specific implementation, the calibration distance is:
[0016] The preset minimum distance between the virtual camera and the virtual object; or, the distance between the center of the virtual sphere and the virtual object when, during the movement of a virtual sphere with the current position of the virtual object as its center and a calibrated radius as its radius, the virtual sphere reaches a position where the obstacle has not entered the interior of the virtual sphere and the obstacle and the virtual sphere have only one intersection point.
[0017] Optionally, in one specific implementation, determining the target distance between the virtual camera and the virtual object within a numerical range with a preset initial distance as the maximum value and a calibration distance as the minimum value, when the detection distance is greater than the preset distance, includes:
[0018] The maximum value of the numerical range is determined as the current maximum value, and the minimum value of the numerical range is determined as the current minimum value;
[0019] Calculate the average of the current maximum value and the current minimum value, and use it as the current intermediate value;
[0020] The current target range is determined when the acquisition distance between the virtual camera and the virtual object is the current median value, and it is determined whether the detection distance between the obstacle and the current target range is greater than the preset distance;
[0021] If not, then the current intermediate value is determined as the current maximum value, and the step of calculating the average of the current maximum value and the current minimum value is returned;
[0022] If so, the current intermediate value is determined as the target distance between the virtual camera and the virtual object.
[0023] Optionally, in one specific implementation, before determining the current intermediate value as the target distance between the virtual camera and the virtual object, the method further includes:
[0024] Determine whether the difference between the current maximum value and the current intermediate value is less than a preset threshold;
[0025] If so, the current intermediate value is determined as the target distance between the virtual camera and the virtual object;
[0026] Otherwise, the current intermediate value is determined as the current minimum value, and the step of calculating the average of the current maximum value and the current minimum value is returned.
[0027] Optionally, in one specific implementation, the method further includes:
[0028] After the virtual camera completes its movement, if the detection distance between the obstacle and the target area is greater than the preset distance, the virtual camera is controlled to move along the straight line between the virtual camera and the virtual object until the distance between the virtual camera and the virtual object is restored to the preset initial distance.
[0029] Optionally, in one specific implementation, the step of constructing a target range including the virtual camera and the virtual object based on the acquisition distance of the virtual camera when acquiring images of the virtual object, and the current positions of the virtual camera and the virtual object in the virtual scene, includes:
[0030] Construct a cone with the current position of the virtual camera in the virtual scene as its vertex, the acquisition distance of the virtual camera in acquiring images of the virtual object as its height, and the current position of the virtual object in the virtual scene as its center and a preset radius as its base, as the target range including the virtual camera and the virtual object.
[0031] Secondly, embodiments of this application provide a control device for a virtual camera in a virtual scene, applied to an electronic device. The electronic device provides a user interface to a user, and the virtual scene includes virtual objects controlled by the electronic device and a virtual camera that captures images of the virtual objects. The content displayed on the user interface includes the content captured by the virtual camera in the virtual scene. The device includes:
[0032] The instruction response module is used to respond to the operation instructions sent by the user for the virtual object, control the virtual object to move in the virtual scene, and control the virtual camera to follow the virtual object; wherein, the virtual scene is a three-dimensional scene;
[0033] The range construction module is used to construct a target range including the virtual camera and the virtual object based on the acquisition distance of the virtual camera when acquiring images of the virtual object, and the current positions of the virtual camera and the virtual object in the virtual scene; wherein, the target range moves with the virtual camera and the virtual object;
[0034] The distance determination module is used to determine the target distance between the virtual camera and the virtual object for each frame captured by the virtual camera. If an obstacle with a detection distance of no more than a preset distance is detected in the virtual scene when the virtual camera captures that frame, the target distance between the virtual camera and the virtual object is determined within a numerical range with a preset initial distance as the maximum value and a calibration distance as the minimum value. The calibration distance is the distance between the virtual object and a calibration point, which is a point on the line connecting the virtual camera and the virtual object, excluding the points where the virtual camera and the virtual object are located.
[0035] A control movement module is used to control the virtual camera to move to a position on the line connecting the virtual camera and the virtual object, where the distance between the virtual camera and the virtual object is the target distance.
[0036] Optionally, in one specific implementation, the apparatus further includes:
[0037] The control acquisition module is used to control the virtual camera to acquire images of the virtual object when the virtual camera completes its movement, so as to obtain the next frame of the virtual object.
[0038] Optionally, in one specific implementation, the calibration distance is:
[0039] The preset minimum distance between the virtual camera and the virtual object; or, the distance between the center of the virtual sphere and the virtual object when, during the movement of a virtual sphere with the current position of the virtual object as its center and a calibrated radius as its radius, the virtual sphere reaches a position where the obstacle has not entered the interior of the virtual sphere and the obstacle and the virtual sphere have only one intersection point.
[0040] Optionally, in one specific implementation, the distance determination module includes:
[0041] The first determining submodule is used to determine the maximum value of the numerical range as the current maximum value, and to determine the minimum value of the numerical range as the current minimum value;
[0042] The calculation submodule is used to calculate the average of the current maximum value and the current minimum value as the current intermediate value;
[0043] The second determining submodule is used to determine the current target range when the acquisition distance between the virtual camera and the virtual object is the current intermediate value, and to determine whether the detection distance between the obstacle and the current target range is greater than the preset distance; if not, the third determining submodule is triggered; if yes, the fourth determining submodule is triggered.
[0044] The third determining submodule is used to determine the current intermediate value as the current maximum value and return the step of calculating the average of the current maximum value and the current minimum value;
[0045] The fourth determining submodule is used to determine the current intermediate value as the target distance between the virtual camera and the virtual object.
[0046] Optionally, in one specific implementation, the apparatus further includes:
[0047] The judgment module is used to determine whether the difference between the current maximum value and the current intermediate value is less than a preset threshold before determining the current intermediate value as the target distance between the virtual camera and the virtual object; if so, the fourth determination submodule is triggered; otherwise, the fifth determination submodule is triggered.
[0048] The fifth determining submodule is used to determine the current intermediate value as the current minimum value and return the step of calculating the average of the current maximum value and the current minimum value.
[0049] Optionally, in one specific implementation, the apparatus further includes:
[0050] The distance recovery module is used to control the virtual camera to move along the straight line between the virtual camera and the virtual object after the virtual camera has moved, if the detected distance between the obstacle and the target range is greater than the preset distance, until the distance between the virtual camera and the virtual object is restored to the preset initial distance.
[0051] Optionally, in one specific implementation, the range construction module is specifically used for:
[0052] Construct a cone with the current position of the virtual camera in the virtual scene as its vertex, the acquisition distance of the virtual camera in acquiring images of the virtual object as its height, and the current position of the virtual object in the virtual scene as its center and a preset radius as its base, as the target range including the virtual camera and the virtual object.
[0053] Thirdly, embodiments of this application provide an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;
[0054] Memory, used to store computer programs;
[0055] When a processor executes a program stored in memory, it implements the steps of any of the above method embodiments.
[0056] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of any of the above method embodiments.
[0057] Fifthly, embodiments of this application also provide a computer program product containing instructions that, when run on a computer, cause the computer to execute any of the virtual camera control methods described above.
[0058] Beneficial effects of the embodiments in this application:
[0059] As can be seen from the above, the solution provided in the embodiments of this application, when applied to an electronic device, allows the electronic device to provide a user interface, and the content displayed on the user interface is about a virtual scene. The virtual scene is a three-dimensional scene, and it may include virtual objects controlled by the electronic device and a virtual camera that captures images of the virtual objects. Therefore, the content displayed on the user interface may include the content captured by the virtual camera in the virtual scene.
[0060] In response to user-sent operation commands for virtual objects, the system controls the movement of virtual objects within a virtual scene and controls the virtual camera to follow the movement of virtual objects. Furthermore, based on the acquisition distance of the virtual camera when capturing images of virtual objects and the current positions of the virtual camera and virtual objects within the virtual scene, a target range including the virtual camera and virtual objects can be constructed. The target range follows the movement of the virtual camera and virtual objects.
[0061] For each frame captured by the virtual camera, if an obstacle is detected in the virtual scene at a detection distance no greater than a preset distance from the target area when the virtual camera captures that frame, the target distance between the virtual camera and the virtual object can be determined within a numerical range with the preset initial distance as the maximum value and the calibration distance as the minimum value, when the detection distance is greater than the preset distance. The calibration distance is the distance between the virtual object and a calibration point, which is a point on the line connecting the virtual camera and the virtual object, excluding the points where the virtual camera and the virtual object are located. Then, the virtual camera can be moved to a position on the line connecting the virtual camera and the virtual object where the distance between the camera and the virtual object is the target distance.
[0062] Based on this, the solution provided in this application can predetermine a target range based on the acquisition distance between the virtual camera and the virtual object, as well as their current positions in the virtual scene. Thus, when the virtual camera is capturing frames, if an obstacle exists in the virtual scene whose detection distance from the target range is no greater than a preset distance, it can be considered that the obstacle is close to the virtual camera's image capture path for the virtual object and may obstruct that path. Furthermore, by controlling the virtual camera to move along the line connecting the virtual camera and the virtual object, the acquisition distance between them can be shortened, achieving obstacle avoidance. Compared to related technologies, since the obstacle can be avoided before it enters the virtual camera's image capture path for the virtual object, there is no need to process the obstacle as semi-transparent or completely transparent. This avoids the sudden disappearance of obstacles for the user, thus improving the user experience.
[0063] Of course, implementing any product or method of this application does not necessarily require achieving all of the advantages described above at the same time. Attached Figure Description
[0064] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other embodiments can be obtained based on these drawings.
[0065] Figure 1 A flowchart illustrating a method for controlling a virtual camera in a virtual scene according to an embodiment of this application;
[0066] Figures 2(a)-2(d) These are schematic diagrams of images of virtual objects captured by the virtual camera provided in the embodiments of this application;
[0067] Figures 3(a)-3(b) These are schematic diagrams illustrating the target range provided in the embodiments of this application;
[0068] Figures 4(a)-4(c) These are schematic diagrams illustrating the detection distance between obstacles and target areas provided in embodiments of this application;
[0069] Figure 5 Another flowchart illustrating the control method of a virtual camera in a virtual scene provided in the embodiments of this application;
[0070] Figures 6(a)-6(d) These are schematic diagrams illustrating specific examples of determining target distance provided in the embodiments of this application;
[0071] Figure 7 This is a flowchart illustrating yet another method for controlling a virtual camera in a virtual scene, as provided in an embodiment of this application.
[0072] Figure 8 This is a schematic diagram of the structure of a control device for a virtual camera in a virtual scene, provided in an embodiment of this application.
[0073] Figure 9 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0074] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art based on this application are within the scope of protection of this application.
[0075] In related technologies, when an obstacle is detected in the path of the virtual camera's view of the game character, the obstacle can be made semi-transparent or completely transparent. This way, although an obstacle still exists in the path, the virtual camera can still capture the game character through it. However, in these technologies, making obstacles semi-transparent or completely transparent can create a sudden, abrupt feeling of the obstacle disappearing, thus negatively impacting the user's gaming experience.
[0076] To address the aforementioned technical problems, this application provides a method for controlling a virtual camera in a virtual scene.
[0077] This method is applicable to various application scenarios that require controlling a virtual camera in a virtual scene to track and capture images of virtual objects. For example, in combat games, it involves controlling a virtual camera in a 3D virtual scene to track and capture images of the target game character in the 3D virtual scene.
[0078] Furthermore, this method can be applied to various electronic devices capable of data processing, such as mobile phones, tablets, and laptops, and these electronic devices can run various applications that require controlling a virtual camera to track and capture various images of virtual objects.
[0079] Therefore, the embodiments of this application do not specifically limit the application scenarios and execution entities of the method.
[0080] This application provides a method for controlling a virtual camera in a virtual scene. The method is applied to an electronic device that provides a user interface. The virtual scene includes virtual objects controlled by the electronic device and a virtual camera that captures images of the virtual objects. The content displayed on the user interface includes the content captured by the virtual camera in the virtual scene. Specifically, the method includes the following steps:
[0081] In response to an operation command sent by the user for the virtual object, the system controls the virtual object to move within the virtual scene and controls the virtual camera to follow the virtual object's movement; wherein, the virtual scene is a three-dimensional scene;
[0082] Based on the acquisition distance of the virtual camera when acquiring images of the virtual object, and the current positions of the virtual camera and the virtual object in the virtual scene, a target range including the virtual camera and the virtual object is constructed; wherein, the target range moves with the virtual camera and the virtual object;
[0083] For each frame captured by the virtual camera, if an obstacle is detected in the virtual scene at the time the virtual camera captures that frame, and the detection distance between the obstacle and the target area is not greater than a preset distance, then within a numerical range with a preset initial distance as the maximum value and a calibration distance as the minimum value, the target distance between the virtual camera and the virtual object is determined when the detection distance is greater than the preset distance; wherein, the calibration distance is the distance between the virtual object and a calibration point, and the calibration point is: a point on the line connecting the virtual camera and the virtual object, excluding the points where the virtual camera and the virtual object are located;
[0084] Control the virtual camera to move to a position on the line connecting the virtual camera and the virtual object, at a distance equal to the target distance from the virtual object.
[0085] As can be seen from the above, the solution provided in the embodiments of this application, when applied to an electronic device, allows the electronic device to provide a user interface, and the content displayed on the user interface is about a virtual scene. The virtual scene is a three-dimensional scene, and it may include virtual objects controlled by the electronic device and a virtual camera that captures images of the virtual objects. Therefore, the content displayed on the user interface may include the content captured by the virtual camera in the virtual scene.
[0086] In response to user-sent operation commands for virtual objects, the system controls the movement of virtual objects within a virtual scene and controls the virtual camera to follow the movement of virtual objects. Furthermore, based on the acquisition distance of the virtual camera when capturing images of virtual objects and the current positions of the virtual camera and virtual objects within the virtual scene, a target range including the virtual camera and virtual objects can be constructed. The target range follows the movement of the virtual camera and virtual objects.
[0087] For each frame captured by the virtual camera, if an obstacle is detected in the virtual scene at a detection distance no greater than a preset distance from the target area when the virtual camera captures that frame, the target distance between the virtual camera and the virtual object can be determined within a numerical range with the preset initial distance as the maximum value and the calibration distance as the minimum value, when the detection distance is greater than the preset distance. The calibration distance is the distance between the virtual object and a calibration point, which is a point on the line connecting the virtual camera and the virtual object, excluding the points where the virtual camera and the virtual object are located. Then, the virtual camera can be moved to a position on the line connecting the virtual camera and the virtual object where the distance between the camera and the virtual object is the target distance.
[0088] Based on this, the solution provided in this application can predetermine a target range based on the acquisition distance between the virtual camera and the virtual object, as well as their current positions in the virtual scene. Thus, when the virtual camera is capturing frames, if an obstacle exists in the virtual scene whose detection distance from the target range is no greater than a preset distance, it can be considered that the obstacle is close to the virtual camera's image capture path for the virtual object and may obstruct that path. Furthermore, by controlling the virtual camera to move along the line connecting the virtual camera and the virtual object, the acquisition distance between them can be shortened, achieving obstacle avoidance. Compared to related technologies, since the obstacle can be avoided before it enters the virtual camera's image capture path for the virtual object, there is no need to process the obstacle as semi-transparent or completely transparent. This avoids the sudden disappearance of obstacles for the user, thus improving the user experience.
[0089] The following, with reference to the accompanying drawings, provides a detailed description of a method for controlling a virtual camera in a virtual scene according to an embodiment of this application.
[0090] Figure 1 This is a flowchart illustrating a method for controlling a virtual camera in a virtual scene, provided as an embodiment of this application. This method can be applied to an electronic device, which can provide a user interface. The virtual scene may include a virtual object controlled by the electronic device and a virtual camera that acquires images of the virtual object. The content displayed on the user interface may include the content acquired by the virtual camera in the virtual scene. Figure 1 As shown, the method may include the following steps S101-S104.
[0091] S101: In response to user-sent operation commands for virtual objects, control the virtual objects to move in the virtual scene and control the virtual camera to follow the virtual objects.
[0092] The virtual scene is a three-dimensional scene;
[0093] Taking game applications as an example, when a user wants to experience a specific game, they can install the game's application on an electronic device that provides a user interface. Then, they can launch the game. When the electronic device detects this user interaction, it can display the game's interface on its user screen.
[0094] The content displayed on the user interface may include images of the virtual scene of the target game, and the virtual scene may be a three-dimensional scene.
[0095] After launching the target game application, users can select the virtual object they want to control from among the various virtual objects available in the target game, and then control the selected virtual object through an electronic device.
[0096] The aforementioned virtual object can be a virtual object in the target game, such as a virtual character or virtual animal in the target game; or it can be a group of multiple virtual objects in the target game, such as a legion; all of these are reasonable and are not specifically limited in this application embodiment.
[0097] For example, a user can select a game character to represent themselves in a target game, and then control that game character to move around in the game scene via an electronic device.
[0098] Furthermore, in order to help users understand the location of the virtual object in the virtual scene, and to show the user the operation results when the user operates the virtual object through an electronic device, a virtual camera can be set up to capture images of the virtual object.
[0099] Thus, the virtual scene can include a virtual object controlled by an electronic device and a virtual camera that captures images of the virtual object. Furthermore, the content displayed on the user interface of the electronic device can include the content captured by the virtual camera in the virtual scene.
[0100] When the virtual camera captures images of virtual objects, both the acquisition orientation and the acquisition distance between the camera and the virtual object can be adjusted.
[0101] However, in order to ensure that the frames of images of virtual objects captured by the virtual camera can be seamlessly connected and to avoid rapid changes in the capture position that would affect the user experience, the virtual camera that captures images is usually set at a certain position of the virtual object, such as behind, to the left, or to the right, to capture images of the virtual object.
[0102] For example, as shown in Figure 2(a), a virtual camera for capturing images of a virtual object 210 can be set directly behind the virtual object 210, and the virtual camera can be controlled to always remain directly behind the virtual object 210 to capture images of the virtual object 210.
[0103] Furthermore, the proportion of the virtual object in the frame captured by the virtual camera varies depending on the distance between the virtual camera and the virtual object. Therefore, in order to maintain a relatively fixed proportion of the virtual object in each frame captured by the virtual camera and avoid user discomfort caused by the constantly changing proportion of the virtual object in each frame, the virtual camera is typically controlled to capture images of the virtual object at a fixed acquisition distance.
[0104] Furthermore, in order to achieve the preset game effect, a preset initial distance can be set. Then, the virtual camera can be controlled to capture images of the virtual object at the preset initial distance. In this way, each frame captured by the virtual camera can achieve the preset game effect, thereby improving the user experience.
[0105] The aforementioned preset initial distance can be set according to the game parameters and the desired game effect, such as 3 meters, 5 meters, etc.; these are all reasonable and are not specifically limited in this embodiment.
[0106] For example, in a 3D (3D) game, if the target character is 1.8 meters tall, the preset initial distance can be set to 5 meters. This allows the virtual camera to be positioned 5 meters behind the target character to capture images of the virtual object.
[0107] When a user wants to control the movement of a selected virtual object within a virtual scene, they can send operation commands on the user interface of the electronic device to instruct the user to control the movement of the virtual object.
[0108] Optionally, users can use the mouse to select virtual objects and send operation commands to the electronic device for the virtual objects.
[0109] Optionally, users can send operation commands to virtual objects displayed on the user interface of the touch electronic device.
[0110] Optionally, users can send operation commands to virtual objects by selecting control options related to virtual objects on the electronic device.
[0111] In this way, when the electronic device detects the operation command sent by the user for the virtual object, it can respond to the operation command, control the virtual object to move in the virtual scene, and control the virtual camera that is capturing images of the virtual object to follow the movement of the virtual object.
[0112] This allows the virtual camera and the virtual object to move with the same motion parameters, that is, to move at the same speed and in the same direction. This enables the virtual camera to track and capture images of the virtual object, allowing users to see the virtual object moving in the virtual scene.
[0113] However, during the process of controlling the virtual camera to follow a virtual object's movement within the virtual scene, obstacles may appear in the path of the virtual camera's image capture of the virtual object. These obstacles could include other user-controlled virtual objects or various props within the virtual scene. In such cases, the obstacle would occlude the virtual object, thus affecting the virtual camera's ability to capture images of it.
[0114] For example, as shown in Figure 2(b), after the virtual object 210 enters a building in the virtual scene, the building wall 220 may enter the image acquisition path of the virtual camera for the virtual object 210, thereby obscuring the virtual object 210 and preventing the virtual camera from capturing the image of the virtual object 210.
[0115] In related technologies, as shown in Figure 2(c), the building wall 220 can be processed into a semi-transparent or completely transparent state. In this way, although the building wall 220 still exists in the image acquisition path of the virtual camera for the virtual object 210, the virtual camera can capture the image of the virtual object 210 through the building wall 220. The area enclosed by the dotted line in the figure is the building wall 220 that has been processed into a semi-transparent state.
[0116] However, in related technologies, methods that process obstacles already appearing in the image capture path of a virtual camera targeting a virtual object as transparent or semi-transparent can create a sudden, abrupt feeling for the user, negatively impacting the user experience. Therefore, to avoid this, the virtual camera control method in a virtual scene provided in this application embodiment can construct a target range including the virtual camera and the virtual object, and utilize this target range to avoid obstacles in the virtual scene from entering the image capture path of the virtual camera targeting the virtual object.
[0117] S102: Based on the acquisition distance of the virtual camera when acquiring images of virtual objects, and the current positions of the virtual camera and virtual objects in the virtual scene, construct a target range including the virtual camera and virtual objects;
[0118] The target area moves along with the virtual camera and virtual objects;
[0119] After setting up a virtual camera to capture images of the virtual object, a target range including the virtual camera and the virtual object can be constructed based on the acquisition distance of the virtual camera, the current position of the virtual camera in the virtual scene, and the current position of the virtual object in the virtual scene.
[0120] The target range can change depending on any one of the following: the acquisition distance of the virtual camera capturing images of the virtual object, the current position of the virtual camera in the virtual scene, and the current position of the virtual object in the virtual scene. Furthermore, the acquisition distance, the current position of the virtual camera in the virtual scene, and the current position of the virtual object in the virtual scene can change as the virtual camera and the virtual object move; therefore, the target range can move with the virtual camera and the virtual object.
[0121] The shape of the aforementioned target area can be set according to the game parameters and the desired game effect. For example, a cuboid, cylinder, hemisphere, etc. are all reasonable and are not specifically limited in this embodiment.
[0122] Furthermore, the aforementioned target range may include the boundary lines constituting the range and the areas enclosed by the boundary lines. For example, when the aforementioned target range is a cone including a virtual camera and a virtual object, as shown in FIG3(a), the aforementioned target range may include the base surface, the side surface of the cone, and the area enclosed by the base surface and the side surface of the cone.
[0123] Optionally, in one specific implementation, step S102 above may include the following step 11:
[0124] Step 11: Construct a cone with the current position of the virtual camera in the virtual scene as the vertex, the acquisition distance of the virtual camera to acquire images of the virtual object as the height, and the current position of the virtual object in the virtual scene as the center of the base circle with a preset radius, as the target range including the virtual camera and the virtual object.
[0125] In this specific implementation, a cone can be constructed with the current position of the virtual camera in the virtual scene as the vertex, the acquisition distance of the virtual camera to acquire images of the virtual object as the height, the current position of the virtual object in the virtual scene as the center of the base circle and the base radius as the preset radius, and the constructed cone is used as the target range including the virtual camera and the virtual object.
[0126] The aforementioned preset radius can be set according to the game parameters and the desired game effect, such as 1 meter, 1.4 meters, etc., which are all reasonable and are not specifically limited in this application embodiment.
[0127] For example, as shown in Figure 3(a), a cone can be constructed with the current position of the virtual camera 320 in the virtual scene as the vertex, the current position of the virtual object 310 in the virtual scene as the center of the base circle, a preset radius as the radius of the base circle, and the acquisition distance 340 of the virtual camera 320 acquiring images of the virtual object 310 as the height, thereby obtaining the target range 330 including the virtual camera and the virtual object.
[0128] Optionally, as shown in Figure 3(b), a cuboid is constructed with the plane where the virtual camera 320 is currently located in the virtual scene as the left surface, the plane where the virtual object 310 is currently located in the virtual scene as the right surface corresponding to the left surface, the acquisition distance 340 of the virtual camera 320 acquiring the image of the virtual object 310 as the length, and a preset height and a preset width as the width, thereby obtaining the target range 330 including the virtual camera and the virtual object.
[0129] It should be noted that the aforementioned target range is fictitious information used to control the virtual camera and is not displayed in the frames captured by the virtual camera. In other words, the user cannot directly view the target range from the user interface of the electronic device.
[0130] S103: For each frame captured by the virtual camera, if an obstacle is detected in the virtual scene at the time the virtual camera captures the frame and the detection distance between the obstacle and the target range is not greater than a preset distance, then within the range of values with the preset initial distance as the maximum value and the calibration distance as the minimum value, the target distance between the virtual camera and the virtual object is determined when the detection distance is greater than the preset distance.
[0131] The calibration distance is the distance between the virtual object and the calibration point. The calibration point is a point on the line connecting the virtual camera and the virtual object, excluding the points where the virtual camera and the virtual object are located.
[0132] To control the virtual camera using the aforementioned target range and prevent obstacles in the virtual scene from entering the camera's image capture path for the virtual object, a preset distance can be set. Furthermore, when the distance between the obstacle and the target range is no greater than the preset distance, the obstacle is more likely to obstruct the camera's image capture path when the virtual camera captures the next frame of the virtual object; conversely, when the distance between the obstacle and the target range is greater than the preset distance, the obstacle is less likely to obstruct the camera's image capture path when the virtual camera captures the next frame of the virtual object.
[0133] The aforementioned preset distance can be set according to the game parameters and the desired game effect, such as 0 meters, 1 meter, 5 meters, etc., which are all reasonable and are not specifically limited in this application embodiment.
[0134] Based on this, after constructing the target range including the virtual camera and virtual objects, for each frame captured by the virtual camera, the detection distance between each obstacle in the virtual scene and the target range can be determined when the virtual camera captures that frame. It can also detect whether there are obstacles in the virtual scene whose detection distance from the target range is not greater than the preset distance when the virtual camera captures that frame.
[0135] Furthermore, if an obstacle is detected in the virtual scene at a detection distance no greater than the preset distance from the target area when the virtual camera captures the frame, the virtual camera can be controlled to move towards the virtual object to prevent the obstacle from obstructing the virtual camera's image capture path for the virtual object when the virtual camera captures the next frame about the virtual object.
[0136] In this way, by controlling the virtual camera to move toward the virtual object, the distance between the virtual camera and the virtual object can be shortened, so that the virtual camera moves between the virtual object and the aforementioned obstacle, or so that the target range including the virtual camera and the virtual object obtained after the virtual camera moves is far away from the aforementioned obstacle, thereby achieving the purpose of changing the detection distance between the target range and the obstacle, so that the detection distance is greater than the preset distance.
[0137] Conversely, if it is detected that there are no obstacles in the virtual scene whose detection distance from the target range is no greater than the preset distance when the virtual camera captures the frame, then the possibility that the obstacles in the virtual scene will block the virtual camera's image capture path for the virtual object is small. Therefore, there is no need to adjust the capture distance between the virtual camera and the virtual object for the time being.
[0138] Among them, whether the detection distance between the obstacle and the target area is greater than the above-mentioned preset distance can be called collision detection, and whether the detection distance between the obstacle and the target area is not greater than the above-mentioned preset distance can be called collision between the obstacle and the target area.
[0139] For example, with a preset distance of 0 meters, as shown in Figure 4(a), if obstacle 410 enters the target range 420, the detection distance between obstacle 410 and the target range 420 is no greater than the preset distance. Therefore, when the virtual camera 430 captures the next frame of the virtual object 440, obstacle 410 may obstruct the image capture path of the virtual camera 430 for the virtual object 440. As shown in Figure 4(b), if there is an intersection between obstacle 410 and the edge of the target range 420, then the detection distance between obstacle 410 and the target range 420 can be considered to be... If the detection distance is 0 meters, then the detection distance is no greater than the aforementioned preset distance. Therefore, when the virtual camera 430 captures the next frame of the virtual object 440, the obstacle 410 may obstruct the image capture path of the virtual camera 430 for the virtual object 440. As shown in Figure 4(c), if the detection distance between the obstacle 410 and the target area 420 is 3 meters, which is greater than the aforementioned preset distance, then the possibility that the obstacle 410 will obstruct the image capture path of the virtual camera 430 for the virtual object 440 when the virtual camera 430 captures the next frame of the virtual object 440 is relatively small.
[0140] Before adjusting the acquisition distance between the virtual camera and the virtual object, the target distance between the virtual camera and the virtual object can be determined first when the detection distance between the obstacle and the target area is greater than the preset distance mentioned above.
[0141] When the virtual camera captures this frame, the detection distance between the target area constructed based on the acquisition distance between the virtual camera and the virtual object and the obstacle is no greater than a preset distance. That is, at the current acquisition distance, the obstacle may obstruct the virtual camera's image capture path for the virtual object. Therefore, to avoid the obstacle, the acquisition distance between the virtual camera and the virtual object can be shortened so that the detection distance between the new target area formed by the virtual camera and the virtual object and the obstacle is greater than the aforementioned preset distance. This ensures that when the virtual camera captures an image of the virtual object, the obstacle cannot obstruct the virtual camera's image capture path for the virtual object.
[0142] Therefore, in order to avoid the aforementioned obstacles, when the virtual camera is capturing the next frame of the virtual object, the target distance between the virtual camera and the virtual object should be less than the acquisition distance between the virtual camera and the virtual object when the virtual camera is capturing the frame.
[0143] Therefore, for each frame captured by the virtual camera, if an obstacle is detected in the virtual scene at a detection distance not greater than a preset distance from the target area when the virtual camera captures that frame, the target distance between the virtual camera and the virtual object can be determined within a numerical range with the preset initial distance as the maximum value and the calibration distance as the minimum value, when the detection distance is greater than the preset distance.
[0144] The aforementioned calibration distance is the distance between the virtual object and the calibration point, and the aforementioned calibration point is: a point on the line connecting the virtual camera and the virtual object, excluding the points where the virtual camera and the virtual object are located.
[0145] As mentioned earlier, to achieve the desired game effect, the acquisition distance between the virtual camera and the virtual object is usually set to a preset initial distance. However, when the virtual camera is capturing a frame, if there are obstacles in the virtual scene whose detection distance from the target area is no greater than the preset distance, and if the acquisition distance between the virtual camera and the virtual object is no less than the preset initial distance when the virtual camera captures the next frame about the virtual object, then it is impossible to bypass the obstacle. In other words, the obstacle may obstruct the virtual camera's image acquisition path for the virtual object.
[0146] Therefore, to avoid the aforementioned obstacles, the virtual camera can be controlled to move towards the virtual object along the line connecting the virtual camera and the virtual object, thereby shortening the distance between them. In this way, when the virtual camera captures the next frame of the virtual object, the capture distance between the virtual camera and the virtual object will be less than the preset initial distance.
[0147] Because, as the virtual camera moves towards the virtual object along the aforementioned line, it can stop at a point on the line between the virtual camera and the virtual object, other than the point where the virtual camera and the virtual object are located, the detection distance between the newly constructed target area including the virtual camera and the virtual object and the obstacle is greater than the aforementioned preset distance. Therefore, this point can be used as a calibration point, and the distance between this calibration point and the virtual object can be used as the calibration distance.
[0148] Furthermore, in order to determine the target distance between the virtual camera and the virtual object when the detection distance between the target range and the obstacle is greater than the preset distance, a numerical range can be constructed with the preset initial distance as the maximum value and the calibration distance as the minimum value. Then, within the above numerical range, the target distance is determined.
[0149] Optionally, the preset initial distance can be reduced by a preset step size to obtain a new current maximum value. Then, a new target range is constructed when the distance between the virtual camera and the virtual object is the current maximum value, and it is determined whether the detection distance between the obstacle and the new target range is not greater than a preset distance. If so, the new current maximum value is reduced by the preset step size, and the process returns to the step of determining the current target range when the distance between the virtual camera and the virtual object is the current maximum value. Otherwise, the new current maximum value is determined as the target distance between the virtual camera and the virtual object when the detection distance between the target range and the obstacle is greater than the preset distance.
[0150] The preset step size can be set according to actual needs, such as 0.2 meters, 1 meter, etc., which are all reasonable and are not specifically limited in this application embodiment.
[0151] Optionally, a preset initial distance can be used as the current maximum value and a calibrated distance as the current minimum value. Then, the current median value between the current maximum and minimum values is calculated. This median value is then used as the target distance. It is then determined whether the current detected distance between the constructed target range and the obstacle is greater than a preset distance. If the current detected distance is greater than the preset distance, this median value can be used as the new current minimum value, and the median value between it and the current maximum value is calculated. If the current detected distance is not greater than the preset distance, this median value can be used as the new current maximum value, and the median value between it and the current minimum value is calculated. In this way, by updating the current maximum and minimum values and repeatedly calculating the median value between them, the range of values for the target distance is gradually narrowed, and the target distance is finally determined.
[0152] For clarity, the calibration distance involved in step S103 above, as well as the specific implementation method for determining the target distance, will be explained below.
[0153] S104: Control the virtual camera to move to the line connecting the virtual camera and the virtual object, at a distance equal to the target distance from the virtual object.
[0154] After determining the target distance, a position can be determined on the line connecting the virtual camera and the virtual object, at which distance from the virtual object is the target distance. The virtual camera can then be controlled to move along the line connecting the virtual camera and the virtual object to that position.
[0155] Since the virtual camera moves along the line connecting the virtual camera and the virtual object, and the distance between the virtual camera and the virtual object is reduced, the effect of controlling the movement of the virtual camera is that the virtual camera moves a certain distance closer to the current position of the virtual object along the line connecting the virtual camera and the virtual object.
[0156] In this way, after the virtual camera finishes moving, the new target range formed by the virtual camera and the virtual object, and the detection distance between the virtual camera and the obstacle will be greater than the preset distance mentioned above, thus achieving the purpose of avoiding the obstacle.
[0157] Alternatively, in one specific implementation, such as Figure 5 As shown in the embodiment of this application, a virtual camera control method further includes the following step S105:
[0158] S105: When the virtual camera completes its movement, control the virtual camera to capture an image of the virtual object and obtain the next frame of the virtual object.
[0159] In this specific implementation, when the virtual camera completes its movement, it can be controlled to capture images of virtual objects in the virtual scene, thereby obtaining the next frame of the virtual object.
[0160] When the virtual camera finishes moving, the virtual scene in which the virtual object is currently located may be the same as or different from the virtual scene in which the virtual object was located when the virtual camera captured the previous frame.
[0161] In one scenario, the virtual object may not move while the virtual camera is being moved. As a result, the virtual scene in which the virtual object is currently located is the same as the virtual scene in which the virtual object was located when the virtual camera captured the previous frame. Therefore, the virtual camera can be controlled to capture images of the virtual object in the virtual scene.
[0162] In another scenario, while controlling the movement of the virtual camera, the virtual object moves to a new virtual scene. The virtual camera must also move along with the virtual object. Therefore, when the virtual camera completes its movement, the virtual scene in which the virtual object and the virtual camera are currently located is different from the virtual scene in which the virtual object was located when the virtual camera captured the previous frame. This allows the virtual camera to capture images of the virtual object in the new virtual scene.
[0163] For example, as shown in Figure 2(b), after the virtual camera captures a frame of the virtual object 210, it detects that a building wall 220 in the virtual scene where the virtual object 210 is located obstructs the virtual camera's image capture path for the virtual object 210. Therefore, the target distance between the virtual camera and the virtual object 210 can be determined. Then, the virtual camera is controlled to move forward along the line connecting the virtual camera and the virtual object 210 until it reaches a position where the distance between the virtual camera and the virtual object 210 is the target distance. After the virtual camera movement is detected, it can capture an image of the virtual object 210 in the current virtual scene, thus obtaining the image of the virtual object 210 as shown in Figure 2(d). Since there is no obstruction from the semi-transparent building wall 220, the image shown in Figure 2(d) is clearer than the image of the virtual object 210 shown in Figure 2(c).
[0164] As can be seen from the above, by applying the solution provided in this application, a target range can be pre-determined based on the acquisition distance between the virtual camera and the virtual object, as well as the current positions of the virtual camera and the virtual object in the virtual scene. Thus, when the virtual camera is capturing frames, if there is an obstacle in the virtual scene whose detection distance from the target range is no greater than a preset distance, it can be considered that the obstacle is close to the virtual camera's image acquisition path for the virtual object and may obstruct that path. Furthermore, by controlling the virtual camera to move along the line connecting the virtual camera and the virtual object, the acquisition distance between the virtual camera and the virtual object can be shortened, achieving the purpose of avoiding obstacles. Compared with related technologies, since the obstacle can be avoided before it enters the virtual camera's image acquisition path for the virtual object, there is no need to process the obstacle as semi-transparent or completely transparent. This avoids the sudden disappearance of obstacles for the user, thereby improving the user experience.
[0165] Below, in step S103 above, for each frame captured by the virtual camera, if an obstacle is detected in the virtual scene at a detection distance not greater than a preset distance from the target area when the virtual camera captures that frame, the target distance between the virtual camera and the virtual object is determined within a numerical range with the preset initial distance as the maximum value and the calibration distance as the minimum value, the calibration distance involved, and the specific implementation method for determining the above target distance will be explained.
[0166] When the distance between the virtual camera and the virtual object is too close, the frames captured by the virtual camera may only include partial features of the virtual object. For example, when the capture distance between the virtual camera and the virtual object is 0, the virtual camera might be positioned close to a certain area on the back of the virtual object. In this case, the virtual camera can only capture that area, thus affecting the imaging quality. Therefore, to ensure the imaging quality of each frame captured by the virtual camera, a preset minimum distance can be set between the virtual camera and the virtual object.
[0167] Based on this, in one optional implementation, the aforementioned calibration distance is a preset minimum distance between the virtual camera and the virtual object.
[0168] In this specific implementation, a preset minimum distance can be used as the aforementioned calibration distance. Furthermore, a numerical range can be constructed using the aforementioned preset initial distance as the maximum value and the aforementioned preset minimum distance as the minimum value. Then, within this numerical range, the target distance between the virtual camera and the virtual object can be determined when the detection distance is greater than the preset distance.
[0169] Optionally, in one specific implementation, the aforementioned calibration distance is the distance between the center of the virtual sphere and the virtual object when the virtual sphere, with the current position of the virtual object as its center and the calibration radius as its radius, moves along the connecting line from the current position of the virtual object to a position where the obstacle does not enter the interior of the virtual sphere and the obstacle and the virtual sphere have only one intersection point.
[0170] In this specific implementation, a virtual sphere can be constructed with the current position of the virtual object as its center and the calibrated radius as its radius.
[0171] Then, the virtual sphere can be controlled to move from the current position of the virtual object to the current position of the virtual camera along the line connecting the virtual camera and the virtual object.
[0172] During the process of controlling the movement of the virtual sphere, if the virtual sphere moves to a position where the obstacle has not entered the interior of the virtual sphere and the obstacle and the virtual sphere have only one intersection point, the center of the virtual sphere can be used as the calibration point, and the distance between the center of the virtual sphere and the virtual object can be used as the calibration distance.
[0173] In other words, a virtual sphere can be constructed, and the center of this virtual sphere can be used as the location of the virtual camera when capturing the next frame of the virtual object. Thus, when the center of the virtual sphere is the current location of the virtual object, the virtual camera coincides with the virtual object, preventing obstacles from entering the virtual camera's image capture path.
[0174] The process of controlling the virtual sphere to move along the line connecting the virtual camera and the virtual object towards the current position of the virtual camera is the process of controlling the virtual camera to gradually move away from the virtual object.
[0175] As the virtual sphere moves, it gradually approaches the obstacle. When it reaches a position where the obstacle has not yet entered the virtual sphere and there is only one intersection point between them, the obstacle will not enter the virtual sphere. Therefore, the obstacle will not obstruct the image capture path of the virtual camera capturing images of the virtual object. Furthermore, since the virtual camera is located at the center of the virtual sphere, the distance between the obstacle and the virtual sphere is the calibration radius. This allows the virtual sphere to be controlled to stop moving, and the location of its center can be determined as the calibration point.
[0176] In other words, since the obstacle and the virtual sphere only have one intersection point, it can be assumed that the obstacle has not yet entered the interior of the virtual sphere, and the center of the virtual sphere has not collided with the obstacle. Therefore, when the virtual camera is located at the calibration point where the center of the virtual sphere is located, the target distance between the virtual camera and the virtual object is the calibration distance between the calibration point and the virtual object. At this time, the detection distance between the obstacle and the new target range determined based on the calibration distance is greater than a preset distance. Furthermore, when the target distance between the virtual camera and the virtual object is less than the calibration distance, the detection distance between the obstacle and the new target range is also greater than the preset distance. That is, when the target distance is not greater than the calibration distance between the center of the virtual sphere and the virtual object, the detection distance between the obstacle and the new target range determined based on the target distance is greater than the preset distance.
[0177] Based on this, the above-mentioned preset initial distance can be used as the maximum distance, and the above-mentioned calibration distance can be used as the minimum distance to construct a numerical range. Within this numerical range, the target distance between the virtual camera and the virtual object is determined when the detection distance between the target range and the obstacle is greater than the distance.
[0178] Of course, the above-mentioned calibration distance can also be the distance between other points on the line connecting the virtual camera and the virtual object and the virtual object, which will not be listed here.
[0179] Optionally, in one specific implementation, step S103 above, determining the target distance between the virtual camera and the virtual object when the detection distance is greater than the preset distance within a numerical range with the preset initial distance as the maximum value and the calibration distance as the minimum value, may include the following steps 21-25:
[0180] Step 21: Determine the maximum value in the range as the current maximum value, and determine the minimum value in the range as the current minimum value;
[0181] Step 22: Calculate the average of the current maximum and minimum values, and use it as the current median value;
[0182] Step 23: Determine the current target range when the acquisition distance between the virtual camera and the virtual object is the current median value, and determine whether the detection distance between the obstacle and the current target range is greater than the preset distance; if not, proceed to step 24; otherwise, proceed to step 25.
[0183] Step 24: Determine the current intermediate value as the current maximum value, and return to the step of calculating the average of the current maximum value and the current minimum value;
[0184] Step 25: Determine the current intermediate value as the target distance between the virtual camera and the virtual object.
[0185] In this specific implementation, after determining the above numerical range, the maximum value of the above numerical range can be determined as the current maximum value, and the minimum value of the numerical range can be determined as the current minimum value. Then, the average value of the above current maximum value and the above current minimum value can be calculated, and the average value can be used as the current intermediate value.
[0186] Next, the aforementioned current intermediate value can be determined as the acquisition distance between the virtual camera and the virtual object, and the current target range can be determined when the acquisition distance between the virtual camera and the virtual object is this current intermediate value. Then, it is determined whether the detection distance between the obstacle and the current target range is greater than a preset distance.
[0187] If the detection distance between the obstacle and the current target range is not greater than the preset distance, then when the distance between the virtual camera and the virtual object is the aforementioned current intermediate value, the obstacle can still block the virtual camera's image acquisition path for the virtual object. Therefore, it is still necessary to shorten the acquisition distance between the virtual camera and the virtual object. Consequently, the current intermediate value can be determined as the current maximum value, and the process returns to the step of calculating the average of the current maximum value and the current minimum value. The average of the current maximum value and the current minimum value is calculated again, and the obtained average value is determined as the current intermediate value. After that, the current target range when the distance between the virtual camera and the virtual object is the current intermediate value can be determined again, and it is determined whether the detection distance between the obstacle and the current target range is greater than the preset distance.
[0188] If the detection distance between the obstacle and the current target area is greater than the preset distance, then when the distance between the virtual camera and the virtual object is the aforementioned current intermediate value, the obstacle will not block the virtual camera's image acquisition path for the virtual object. Therefore, the current intermediate value can be determined as the target distance between the virtual camera and the virtual object.
[0189] The method described above, which determines the target distance by setting the current maximum and minimum values, updating the current maximum and minimum values, and repeatedly calculating the median value between the current maximum and minimum values, can be called the binary search method.
[0190] When the aforementioned calibration distance is the preset minimum distance between the virtual camera and the virtual object, the preset initial distance can be set as the current maximum value, and the preset minimum distance can be set as the current minimum value. After that, the target distance between the virtual camera and the virtual object can be calculated.
[0191] For example, with a preset initial distance of 210 meters and a preset minimum distance of 10 meters, the preset initial distance is determined as the current maximum value, and the preset minimum distance is determined as the current minimum value. The average of the current maximum and minimum values is calculated to obtain the current median value of 110. Then, the current target range is determined when the acquisition distance between the virtual camera and the virtual object is 110 meters, and it is determined whether the detection distance between the obstacle and the current target range is greater than the preset distance. If it is greater, 110 meters can be used as the target distance; if it is not greater, 110 can be used as the current maximum value, the preset minimum distance is determined as the current minimum value, and the average of the current maximum and minimum values is calculated to obtain the current median value of 60. Then, the current target range is determined when the acquisition distance between the virtual camera and the virtual object is 60 meters, and it is again determined whether the detection distance between the obstacle and the current target range is greater than the preset distance.
[0192] If the aforementioned calibration distance is the distance between the center of the virtual sphere and the virtual object when the virtual sphere, with the current position of the virtual object as its center and the calibration radius as its radius, moves along the connecting line from the current position of the virtual object to the position where the obstacle does not enter the interior of the virtual sphere and the obstacle and the virtual sphere have only one intersection, then the preset initial distance can be determined as the current maximum value, and the calibration distance between the center of the virtual sphere and the virtual object can be determined as the current minimum value. After that, the target distance between the virtual camera and the virtual object can be calculated.
[0193] For example, when the preset initial distance is 100 meters, and the virtual sphere reaches the obstacle without entering its interior, and the obstacle and the virtual sphere only have one intersection point, the calibrated distance between the center of the virtual sphere and the virtual object is 20 meters. The preset initial distance is then determined as the current maximum value, and the calibrated distance is determined as the current minimum value. The average of the current maximum and minimum values is calculated to obtain the current median value of 60. Next, the current target range is determined when the acquisition distance between the virtual camera and the virtual object is 60 meters, and it is determined whether the detection distance between the obstacle and the current target range is greater than the preset distance. If it is greater, 60 meters can be used as the target distance; if not, the current median value can be used as the current maximum value, and the calibrated distance as the current minimum value. The average of the current maximum and minimum values is calculated to obtain the current median value of 40. Then, the current target range is determined when the acquisition distance between the virtual camera and the virtual object is 40 meters, and it is again determined whether the detection distance between the obstacle and the current target range is greater than the preset distance.
[0194] In this way, by updating the current maximum and minimum values, and by repeatedly calculating the intermediate value between the current maximum and minimum values, the range of values for the target distance is gradually narrowed, and the target distance is finally determined.
[0195] Typically, based on the imaging principle of objects appearing larger when closer and smaller when farther away, as a virtual camera moves closer to a virtual object, the proportion of the virtual object in each frame increases. To bypass these obstacles, when controlling the virtual camera to zoom in along the line connecting the camera and the virtual object, if the distance between the camera and the virtual object changes too drastically between adjacent frames, the proportion of the virtual object in those frames will differ significantly. This could create a sudden, abrupt change in the user's perception of the virtual object's proximity, negatively impacting the user experience. Therefore, to avoid this situation, it is desirable that the difference between the determined target distance and the preset initial distance be relatively small.
[0196] Optionally, in one specific implementation, the virtual camera control method provided in this application embodiment may include the following steps 21-27:
[0197] Step 21: Determine the maximum value in the range as the current maximum value, and determine the minimum value in the range as the current minimum value;
[0198] Step 22: Calculate the average of the current maximum and minimum values, and use it as the current median value;
[0199] Step 23: Determine the current target range when the acquisition distance between the virtual camera and the virtual object is the current median value, and determine whether the detection distance between the obstacle and the current target range is greater than the preset distance; if not, proceed to step 24; otherwise, proceed to step 26.
[0200] Step 24: Determine the current intermediate value as the current maximum value, and return to the step of calculating the average of the current maximum value and the current minimum value;
[0201] Step 26: Determine whether the difference between the current maximum value and the current median value is less than the preset threshold; if yes, proceed to step 25; otherwise, proceed to step 27.
[0202] Step 27: Determine the current median value as the current minimum value, and return to the step of calculating the average of the current maximum value and the current minimum value;
[0203] Step 25: Determine the current intermediate value as the target distance between the virtual camera and the virtual object when the virtual camera captures the next frame of the virtual object.
[0204] In this specific implementation method, the specific implementation methods of steps 21-24 above have been explained in detail above, and will not be repeated here. The specific implementation methods of steps 25-27 are explained below.
[0205] A preset threshold can be set. When the current target range, where the acquisition distance between the virtual camera and the virtual object is the current median value, is greater than the preset distance when the detection distance between the target range and the obstacle is greater than the preset distance, it can be determined whether the difference between the current maximum value and the current median value is less than the preset threshold. If the difference is less than the preset threshold, the current median value can be determined as the target distance between the virtual camera and the virtual object. If the difference is not less than the preset threshold, the target distance can be determined between the current maximum value and the current median value, i.e., the current median value can be determined as the current minimum value, and the process returns to step 22 to recalculate the average of the current maximum value and the current minimum value.
[0206] The aforementioned preset threshold can be set according to the game parameters and the desired game effect, such as 0.1 meters, 0.5 meters, etc., which are all reasonable and are not specifically limited in this application embodiment.
[0207] For example, with a preset initial distance of 210 meters, a calibration distance of 10 meters, and a preset threshold of 20, the current intermediate value 110 is calculated. Since the detection distance between the current target range and the obstacle is greater than the preset distance when the acquisition distance between the virtual camera and the virtual object is determined to be 110 meters, it can be further determined whether the difference between the current maximum value 210 and the current intermediate value 110 is less than the preset threshold. Since the difference 100 between the current maximum value 210 and the current intermediate value 110 is greater than the preset threshold 20, this current intermediate value can be used as the current minimum value, and the current intermediate value 160 between the current maximum value 210 and the current minimum value 110 can be calculated.
[0208] If the detection distance between the current target range and the obstacle is greater than the preset distance when the acquisition distance between the virtual camera and the virtual object is 160 meters, it can be determined whether the difference between the current intermediate value 160 and the current maximum value 210 is less than the preset threshold. Since the difference between the current maximum value 210 and the current intermediate value 160 is 50, which is greater than the preset threshold 20, the current intermediate value can be taken as the current minimum value, and the current intermediate value 185 between the current maximum value 210 and the current minimum value 160 can be calculated.
[0209] Since the detection distance between the current target range and the obstacle is greater than the preset distance when the distance between the virtual camera and the virtual object is determined to be 185 meters, it can be determined whether the difference between the current intermediate value 185 and the current maximum value 210 is less than the preset threshold. Since the difference 25 between the current maximum value 210 and the current intermediate value 185 is greater than the preset threshold 20, the current intermediate value 185 can be taken as the current minimum value, and the current intermediate value 197.5 between the current maximum value 210 and the current minimum value 185 can be calculated.
[0210] When the acquisition distance between the virtual camera and the virtual object is 197.5 meters, the detection distance between the current target range and the obstacle is greater than the preset distance. It can be determined whether the difference between the current intermediate value 197.5 and the current maximum value 210 is less than the preset threshold. Since the difference between the current maximum value 210 and the current intermediate value 197.5 is 12.5, which is less than the preset threshold 20, the current intermediate value 197.5 can be determined as the target distance.
[0211] In this way, by continuously updating the current maximum and minimum values, repeatedly calculating the current intermediate value, and determining whether the difference between the current intermediate value and the current maximum value meets a preset threshold, the difference between the determined target distance and the aforementioned preset initial distance can be gradually reduced. Thus, when the virtual camera is moved to a position where the distance between it and the virtual object is the target distance, the distance moved is relatively small. This avoids the user experiencing abrupt changes in the proportion of the virtual object in adjacent frames due to excessive virtual camera zooming in, thereby improving the user experience.
[0212] To facilitate understanding of steps 21-27 above, the following will be combined with... Figures 6(a)-6(d) Please provide an explanation.
[0213] As shown in Figure 6(a), in a specific instance, step S103 above may include the following steps S601-S608:
[0214] S601: Collision between an obstacle and a cone was detected;
[0215] S602: Set the preset initial distance to the current maximum value and the calibration distance to the current minimum value;
[0216] S603: Calculate the average of the current maximum and the current minimum values, and use it as the current median value;
[0217] S604: Determine the current cone when the acquisition distance between the virtual camera and the virtual object is the current median value, and determine whether the obstacle collides with the current cone; if yes, proceed to step S605; otherwise, proceed to step S606.
[0218] S605: Determine the current intermediate value as the current maximum value and return to step S603;
[0219] S606: Determine whether the difference between the current maximum value and the current median value is less than a preset threshold; if yes, proceed to step S607; otherwise, proceed to step S608.
[0220] S607: Determine the current intermediate value as the target distance between the virtual camera and the virtual object;
[0221] S608: The current intermediate value is determined to be the current minimum value, and the process returns to step S603.
[0222] When the acquisition distance between the virtual camera and the virtual object is a preset initial distance, a cone is constructed with the current position of the virtual camera in the virtual scene as the vertex, the acquisition distance of the virtual camera to acquire images of the virtual object as the height, the current position of the virtual object in the virtual scene as the center of the base circle, and a preset radius as the base radius.
[0223] When the virtual camera captures each frame, as shown in Figure 6(b), if an obstacle 620 collides with the cone 630 in the virtual scene where the virtual object 610 is located when the frame is captured, the preset initial distance can be determined as the current maximum value, the calibration distance can be determined as the current minimum value, and the average of the current maximum value and the current minimum value can be calculated as the current intermediate value.
[0224] Next, determine the current cone when the acquisition distance between the virtual camera and the virtual object is the current intermediate value, and determine whether the obstacle collides with the current cone. If, as shown in Figure 6(c), the obstacle 620 collides with the current cone 640, then determine the current intermediate value as the current maximum value, and calculate the average of the current maximum value and the current minimum value again to obtain the current intermediate value. Then, determine the current cone when the acquisition distance between the virtual camera and the virtual object is the current intermediate value again, and then determine whether the obstacle collides with the current cone.
[0225] If, as shown in Figure 6(d), the obstacle 620 does not collide with the current cone 640, then it is determined whether the difference between the current maximum value and the current intermediate value is less than a preset threshold. If the difference between the current maximum value and the current intermediate value is less than the preset threshold, then the current intermediate value is determined as the target distance between the virtual camera and the virtual object. If the difference between the current maximum value and the current intermediate value is not less than the preset threshold, then the current intermediate value is determined as the current minimum value, and the average of the current maximum value and the current minimum value is calculated again to obtain the current intermediate value. Then, the current cone is determined again when the acquisition distance between the virtual camera and the virtual object is the current intermediate value. After that, it is determined whether the obstacle collides with the current cone.
[0226] Since the aforementioned preset initial distance is a distance that can achieve a better gaming effect, in order to improve the user experience, after bypassing the aforementioned obstacles, the acquisition distance between the virtual camera and the virtual object can be restored to the aforementioned preset initial distance.
[0227] Alternatively, in one specific implementation, such as Figure 7 As shown in the embodiment of this application, a method for controlling a virtual camera in a virtual scene may further include the following step S106:
[0228] S106: After the virtual camera has moved, if the detection distance between the obstacle and the target area is not greater than the preset distance, control the virtual camera to move along the straight line between the virtual camera and the virtual object until the distance between the virtual camera and the virtual object is restored to the preset initial distance.
[0229] In this specific implementation, after the virtual camera completes its movement, the preset initial distance can be used as the acquisition distance between the virtual camera and the virtual object. The detection distance between the obstacle and the target area is then checked to see if it is greater than the preset distance. Furthermore, if the detection distance between the obstacle and the target area is detected to be greater than the preset distance, the virtual camera can be controlled to move along the straight line between the virtual camera and the virtual object until the distance between the virtual camera and the virtual object returns to the preset initial distance.
[0230] Optionally, when an obstacle is detected behind the virtual camera and the distance between the obstacle and the virtual camera is not less than the aforementioned preset initial distance, the virtual camera can be controlled to move along the straight line between the virtual camera and the virtual object until the distance between the virtual camera and the virtual object is restored to the preset initial distance.
[0231] Based on the same inventive concept, and corresponding to the embodiments provided in this application Figure 1 The present invention provides a method for controlling a virtual camera in a virtual scene, and also provides a control device for a virtual camera in a virtual scene.
[0232] Figure 8 This is a schematic diagram of a control device for a virtual camera in a virtual scene, provided as an embodiment of this application. The device is applied to an electronic device that provides a user interface. The virtual scene includes virtual objects controlled by the electronic device and a virtual camera that captures images of the virtual objects. The content displayed on the user interface includes the content captured by the virtual camera in the virtual scene. Figure 8 As shown in the embodiment of this application, a control device for a virtual camera in a virtual scene may include the following modules:
[0233] The instruction response module 810 is used to respond to the operation instruction sent by the user for the virtual object, control the virtual object to move in the virtual scene, and control the virtual camera to follow the virtual object; wherein, the virtual scene is a three-dimensional scene;
[0234] The range construction module 820 is used to construct a target range including the virtual camera and the virtual object based on the acquisition distance of the virtual camera when acquiring images of the virtual object, and the current position of the virtual camera and the virtual object in the virtual scene; wherein, the target range moves with the virtual camera and the virtual object;
[0235] The distance determination module 830 is used to determine, for each frame captured by the virtual camera, if an obstacle is detected in the virtual scene at the time the virtual camera captures that frame, and the detection distance between the obstacle and the target range is not greater than a preset distance, then within a numerical range with a preset initial distance as the maximum value and a calibration distance as the minimum value, the target distance between the virtual camera and the virtual object when the detection distance is greater than the preset distance; wherein, the calibration distance is the distance between the virtual object and a calibration point, and the calibration point is: a point on the line connecting the virtual camera and the virtual object, excluding the point where the virtual camera and the virtual object are located;
[0236] The control movement module 840 is used to control the virtual camera to move to a position on the line connecting the virtual camera and the virtual object, with the distance between the camera and the virtual object being the target distance.
[0237] As can be seen from the above, by applying the solution provided in this application, a target range can be pre-determined based on the acquisition distance between the virtual camera and the virtual object, as well as the current positions of the virtual camera and the virtual object in the virtual scene. Thus, when the virtual camera is capturing frames, if there is an obstacle in the virtual scene whose detection distance from the target range is no greater than a preset distance, it can be considered that the obstacle is close to the virtual camera's image acquisition path for the virtual object and may obstruct that path. Furthermore, by controlling the virtual camera to move along the line connecting the virtual camera and the virtual object, the acquisition distance between the virtual camera and the virtual object can be shortened, achieving the purpose of avoiding obstacles. Compared with related technologies, since the obstacle can be avoided before it enters the virtual camera's image acquisition path for the virtual object, there is no need to process the obstacle as semi-transparent or completely transparent. This avoids the sudden disappearance of obstacles for the user, thereby improving the user experience.
[0238] Optionally, in one specific implementation, the apparatus further includes:
[0239] The control acquisition module is used to control the virtual camera to acquire images of the virtual object when the virtual camera completes its movement, so as to obtain the next frame of the virtual object.
[0240] Optionally, in one specific implementation, the calibration distance is:
[0241] The preset minimum distance between the virtual camera and the virtual object; or, the distance between the center of the virtual sphere and the virtual object when, during the movement of a virtual sphere with the current position of the virtual object as its center and a calibrated radius as its radius, the virtual sphere reaches a position where the obstacle has not entered the interior of the virtual sphere and the obstacle and the virtual sphere have only one intersection point.
[0242] Optionally, in one specific implementation, the distance determination module 830 includes:
[0243] The first determining submodule is used to determine the maximum value of the numerical range as the current maximum value, and to determine the minimum value of the numerical range as the current minimum value;
[0244] The calculation submodule is used to calculate the average of the current maximum value and the current minimum value as the current intermediate value;
[0245] The second determining submodule is used to determine the current target range when the acquisition distance between the virtual camera and the virtual object is the current intermediate value, and to determine whether the detection distance between the obstacle and the current target range is greater than the preset distance; if not, the third determining submodule is triggered; if yes, the fourth determining submodule is triggered.
[0246] The third determining submodule is used to determine the current intermediate value as the current maximum value and return the step of calculating the average of the current maximum value and the current minimum value;
[0247] The fourth determining submodule is used to determine the current intermediate value as the target distance between the virtual camera and the virtual object.
[0248] Optionally, in one specific implementation, the apparatus further includes:
[0249] The judgment module is used to determine whether the difference between the current maximum value and the current intermediate value is less than a preset threshold before determining the current intermediate value as the target distance between the virtual camera and the virtual object; if so, the fourth determination submodule is triggered; otherwise, the fifth determination submodule is triggered.
[0250] The fifth determining submodule is used to determine the current intermediate value as the current minimum value and return the step of calculating the average of the current maximum value and the current minimum value.
[0251] Optionally, in one specific implementation, the apparatus further includes:
[0252] The distance recovery module is used to control the virtual camera to move along the straight line between the virtual camera and the virtual object after the virtual camera has moved, if the detected distance between the obstacle and the target range is greater than the preset distance, until the distance between the virtual camera and the virtual object is restored to the preset initial distance.
[0253] Optionally, in one specific implementation, the range construction module 820 is specifically used for:
[0254] Construct a cone with the current position of the virtual camera in the virtual scene as its vertex, the acquisition distance of the virtual camera in acquiring images of the virtual object as its height, and the current position of the virtual object in the virtual scene as its center and a preset radius as its base, as the target range including the virtual camera and the virtual object.
[0255] This application also provides an electronic device, such as... Figure 9 As shown, it includes a processor 901, a communication interface 902, a memory 903, and a communication bus 904, wherein the processor 901, the communication interface 902, and the memory 903 communicate with each other through the communication bus 904.
[0256] Memory 903 is used to store computer programs;
[0257] When the processor 901 executes the program stored in the memory 903, it implements the steps of the virtual camera control method in any of the virtual scenes provided in the embodiments of this application.
[0258] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.
[0259] The communication interface is used for communication between the aforementioned electronic devices and other devices.
[0260] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0261] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0262] In another embodiment provided in this application, a computer-readable storage medium is also provided, which stores a computer program that, when executed by a processor, implements the steps of the control method for a virtual camera in any of the above-described virtual scenes.
[0263] In another embodiment provided in this application, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute the control method of a virtual camera in any of the virtual scenes described in the above embodiments.
[0264] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk (SSD)).
[0265] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0266] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the device embodiments, electronic device embodiments, computer-readable storage medium embodiments, and computer program product embodiments are basically similar to the method embodiments, so the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0267] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application are included within the scope of protection of this application.
Claims
1. A method for controlling a virtual camera in a virtual scene, characterized in that, Applied to an electronic device, the electronic device provides a user interface to a user, and the virtual scene includes virtual objects controlled by the electronic device and a virtual camera for capturing images of the virtual objects; The content displayed on the user interface includes the content captured by the virtual camera in the virtual scene; the method includes: In response to an operation command sent by the user for the virtual object, the system controls the virtual object to move within the virtual scene and controls the virtual camera to follow the virtual object's movement; wherein, the virtual scene is a three-dimensional scene; Based on the acquisition distance of the virtual camera when acquiring images of the virtual object, and the current positions of the virtual camera and the virtual object in the virtual scene, a target range including the virtual camera and the virtual object is constructed; wherein, the target range moves with the virtual camera and the virtual object; For each frame captured by the virtual camera, if an obstacle is detected in the virtual scene at a detection distance not greater than a preset distance from the target area when the virtual camera captures that frame, then within a numerical range with a preset initial distance as the maximum value and a calibration distance as the minimum value, the target distance between the virtual camera and the virtual object is determined when the detection distance is greater than the preset distance; wherein, the calibration distance is the distance between the virtual object and a calibration point, and the calibration point is: a point on the line connecting the virtual camera and the virtual object, excluding the points where the virtual camera and the virtual object are located; the preset distance is used to determine the possibility that the obstacle will obstruct the virtual camera's image capture path for the virtual object when the virtual camera captures the next frame about the virtual object; The virtual camera is controlled to move to a position on the line connecting the virtual camera and the virtual object, at a distance equal to the target distance from the virtual object, so as to prevent the obstacle from obstructing the virtual camera's image capture path for the virtual object when the virtual camera captures the next frame of the virtual object.
2. The method according to claim 1, characterized in that, The method further includes: When the virtual camera is detected to have completed its movement, the virtual camera is controlled to capture an image of the virtual object, thus obtaining the next frame of the virtual object.
3. The method according to claim 1, characterized in that, The calibration distance is: The preset minimum distance between the virtual camera and the virtual object; or, In a virtual sphere with the current position of the virtual object as its center and a calibrated radius as its radius, as it moves along the connecting line starting from the current position of the virtual object, the distance between the center of the virtual sphere and the virtual object is when the obstacle is reached but not inside the virtual sphere, and the obstacle and the virtual sphere have only one intersection point.
4. The method according to claim 3, characterized in that, The step of determining the target distance between the virtual camera and the virtual object within a numerical range with a preset initial distance as the maximum value and a calibration distance as the minimum value, when the detection distance is greater than the preset distance, includes: The maximum value of the numerical range is determined as the current maximum value, and the minimum value of the numerical range is determined as the current minimum value; Calculate the average of the current maximum value and the current minimum value, and use it as the current intermediate value; The current target range is determined when the acquisition distance between the virtual camera and the virtual object is the current median value, and it is determined whether the detection distance between the obstacle and the current target range is greater than the preset distance; If not, then the current intermediate value is determined as the current maximum value, and the step of calculating the average of the current maximum value and the current minimum value is returned; If so, the current intermediate value is determined as the target distance between the virtual camera and the virtual object.
5. The method according to claim 4, characterized in that, Before determining the current intermediate value as the target distance between the virtual camera and the virtual object, the method further includes: Determine whether the difference between the current maximum value and the current intermediate value is less than a preset threshold; If so, the current intermediate value is determined as the target distance between the virtual camera and the virtual object; Otherwise, the current intermediate value is determined as the current minimum value, and the step of calculating the average of the current maximum value and the current minimum value is returned.
6. The method according to claim 1, characterized in that, The method further includes: After the virtual camera completes its movement, if the detection distance between the obstacle and the target area is greater than the preset distance, the virtual camera is controlled to move along the straight line between the virtual camera and the virtual object until the distance between the virtual camera and the virtual object is restored to the preset initial distance.
7. The method according to any one of claims 1-6, characterized in that, The acquisition distance for image acquisition of the virtual object based on the virtual camera, and the current positions of the virtual camera and the virtual object in the virtual scene, are used to construct a target range including the virtual camera and the virtual object, including: Construct a cone with the current position of the virtual camera in the virtual scene as its vertex, the acquisition distance of the virtual camera in acquiring images of the virtual object as its height, and the current position of the virtual object in the virtual scene as its center and a preset radius as its base, as the target range including the virtual camera and the virtual object.
8. A control device for a virtual camera in a virtual scene, characterized in that, Applied to an electronic device, the electronic device provides a user interface to a user, and the virtual scene includes virtual objects controlled by the electronic device and a virtual camera for capturing images of the virtual objects; The user interface displays content including content captured by the virtual camera in the virtual scene; the device includes: The instruction response module is used to respond to the operation instructions sent by the user for the virtual object, control the virtual object to move in the virtual scene, and control the virtual camera to follow the virtual object; wherein, the virtual scene is a three-dimensional scene; The range construction module is used to construct a target range including the virtual camera and the virtual object based on the acquisition distance of the virtual camera when acquiring images of the virtual object, and the current positions of the virtual camera and the virtual object in the virtual scene; wherein, the target range moves with the virtual camera and the virtual object; A distance determination module is used to determine, for each frame captured by the virtual camera, if an obstacle is detected in the virtual scene at a detection distance not greater than a preset distance from the target area when the virtual camera captures that frame, then within a numerical range with a preset initial distance as the maximum value and a calibration distance as the minimum value, the target distance between the virtual camera and the virtual object when the detection distance is greater than the preset distance; wherein, the calibration distance is the distance between the virtual object and a calibration point, and the calibration point is: a point on the line connecting the virtual camera and the virtual object, excluding the points where the virtual camera and the virtual object are located; the preset distance is used to determine the possibility that the obstacle will obstruct the virtual camera's image capture path for the virtual object when the virtual camera captures the next frame about the virtual object; A control movement module is used to control the virtual camera to move to a position on the line connecting the virtual camera and the virtual object, at a distance equal to the target distance from the virtual object, so as to prevent the obstacle from obstructing the virtual camera's image acquisition path for the virtual object when the virtual camera is capturing the next frame of the image about the virtual object.
9. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, when executing a program stored in memory, implements the steps of the method described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the method described in any one of claims 1-7.
Citation Information
Patent Citations
Virtual camera control method and system, storage medium and terminal equipment
CN112156467A
Image generating apparatus, method of generating image, program, and recording medium
US20090058856A1