disclosure of Invention
in view of the above, embodiments of the present application provide a method, an apparatus, a device, and a computer-readable storage medium for setting a sound source in a virtual environment, so as to solve technical defects in the prior art.
The embodiment of the application discloses a sound source setting method in a virtual environment, which comprises the following steps:
Acquiring a target environment boundary and a role position;
judging whether the role is in the target environment or not based on the target environment boundary and the role position;
if the role is in the target environment, setting position data which are the same as the role for a virtual sound source;
If the character is not in the target environment, calculating the distance between the character and the boundary of the target environment, and setting position data for the virtual sound source based on the calculated distance;
And setting a virtual sound source according to the position data of the virtual sound source.
Further, before the obtaining the target environment boundary and the role position, the method further includes:
establishing a target environment model;
The acquiring of the target environment boundary includes: and acquiring a target environment boundary according to the target environment model.
further, the acquiring the target environment boundary and the role position includes:
And acquiring the boundary of the target environment and the position of the role at regular time according to a preset time interval.
Further, the calculating a distance between the character and the boundary of the target environment and setting position data for the virtual sound source based on the calculated distance includes:
Calculating the shortest distance between the role and the boundary of the target environment;
obtaining a target position which is closest to the role on the boundary of the target environment based on the calculated shortest distance;
Setting the target position as position data of the analog sound source.
Further, the setting the target position as position data of the analog sound source includes:
in a case where the target position includes two or more positions, the same position data as any one of the target positions is set for the virtual sound source.
Further, the setting the target position as position data of the analog sound source includes:
Under the condition that the target position comprises two or more positions, converting the target environment boundary to obtain a conversion environment boundary;
and calculating the distance between the character and the boundary of the conversion environment, and setting position data for the virtual sound source based on the calculated distance.
Further, the calculating a distance between the character and the boundary of the conversion environment and setting position data for the virtual sound source based on the calculated distance includes:
calculating a shortest distance between the character and the transition environment boundary;
Based on the calculated shortest distance, obtaining a position which is closest to the role on the boundary of the conversion environment;
and setting the position closest to the character on the boundary of the conversion environment as the position data of the analog sound source.
The embodiment of the application discloses sound source setting device in virtual environment includes:
An acquisition module configured to acquire a target environment boundary and a role position;
A determining module configured to determine whether the character is in a target environment based on the target environment boundary and the character position;
if the role is in the target environment, setting position data which are the same as the role for a virtual sound source;
If the character is not in the target environment, calculating the distance between the character and the boundary of the target environment, and setting position data for the virtual sound source based on the calculated distance;
a setting module configured to set a virtual sound source according to the position data of the virtual sound source.
Optionally, the sound source setting apparatus in the virtual environment further includes:
an establishing module configured to establish a target environment model;
the acquisition module is specifically configured to: and acquiring a target environment boundary according to the target environment model.
Optionally, the obtaining module is further configured to:
And acquiring the boundary of the target environment and the position of the role at regular time according to a preset time interval.
Optionally, the computing module is further configured to:
calculating the shortest distance between the role and the boundary of the target environment;
obtaining a target position which is closest to the role on the boundary of the target environment based on the calculated shortest distance;
setting the target position as position data of the analog sound source.
optionally, the computing module is further configured to:
In a case where the target position includes two or more positions, the same position data as any one of the target positions is set for the virtual sound source.
optionally, the computing module is further configured to:
Under the condition that the target position comprises two or more positions, converting the target environment boundary to obtain a conversion environment boundary;
And calculating the distance between the character and the boundary of the conversion environment, and setting position data for the virtual sound source based on the calculated distance.
optionally, the computing module is further configured to:
Calculating a shortest distance between the character and the transition environment boundary;
Based on the calculated shortest distance, obtaining a position which is closest to the role on the boundary of the conversion environment;
And setting the position closest to the character on the boundary of the conversion environment as the position data of the analog sound source.
a computing device comprising a memory, a processor and computer instructions stored on the memory and executable on the processor, the processor when executing the instructions implementing the steps of a method of sound source setting in the virtual environment.
a computer readable storage medium storing computer instructions which, when executed by a processor, implement the steps of a method of setting a sound source in a virtual environment.
According to the sound source setting method, the sound source setting device, the sound source setting equipment and the computer readable storage medium in the virtual environment, the virtual sound sources in a single scene are combined into one virtual sound source, and the positions of the virtual sound sources change along with the change of the positions of the characters, so that the continuity of the sound of the virtual sound sources can be effectively improved, the consumption of system calculation is effectively reduced, and the game performance is greatly improved.
Detailed Description
in the following description, numerous specific details are set forth in order to provide a thorough understanding of the present application. This application is capable of implementation in many different ways than those herein set forth and of similar import by those skilled in the art without departing from the spirit of this application and is therefore not limited to the specific implementations disclosed below.
The terminology used in the description of the one or more embodiments is for the purpose of describing the particular embodiments only and is not intended to be limiting of the description of the one or more embodiments. As used in one or more embodiments of the present specification and the appended claims, the singular forms "a," "an," and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It should also be understood that the term "and/or" as used in one or more embodiments of the present specification refers to and encompasses any and all possible combinations of one or more of the associated listed items.
it will be understood that, although the terms first, second, etc. may be used herein in one or more embodiments to describe various information, these information should not be limited by these terms. These terms are only used to distinguish one type of information from another. For example, a first can also be referred to as a second and, similarly, a second can also be referred to as a first without departing from the scope of one or more embodiments of the present description. The word "if" as used herein may be interpreted as "at … …" or "when … …" or "in response to a determination", depending on the context.
in the present application, a method, an apparatus, a device and a storage medium for setting a sound source in a virtual environment are provided, and detailed descriptions are individually provided in the following embodiments.
fig. 1 is a block diagram illustrating a configuration of a computing device 100 according to an embodiment of the present specification. The components of the computing device 100 include, but are not limited to, memory 110 and processor 120. The processor 120 is coupled to the memory 110 via a bus 130 and a database 150 is used to store data.
computing device 100 also includes access device 140, access device 140 enabling computing device 100 to communicate via one or more networks 160. Examples of such networks include the Public Switched Telephone Network (PSTN), a Local Area Network (LAN), a Wide Area Network (WAN), a Personal Area Network (PAN), or a combination of communication networks such as the internet. Access device 140 may include one or more of any type of network interface (e.g., a Network Interface Card (NIC)) whether wired or wireless, such as an IEEE802.11 Wireless Local Area Network (WLAN) wireless interface, a worldwide interoperability for microwave access (Wi-MAX) interface, an ethernet interface, a Universal Serial Bus (USB) interface, a cellular network interface, a bluetooth interface, a Near Field Communication (NFC) interface, and so forth.
In one embodiment of the present description, the above-described components of computing device 100 and other components not shown in FIG. 1 may also be connected to each other, such as by a bus. It should be understood that the block diagram of the computing device architecture shown in FIG. 1 is for purposes of example only and is not limiting as to the scope of the description. Those skilled in the art may add or replace other components as desired.
Computing device 100 may be any type of stationary or mobile computing device, including a mobile computer or mobile computing device (e.g., tablet, personal digital assistant, laptop, notebook, netbook, etc.), a mobile phone (e.g., smartphone), a wearable computing device (e.g., smartwatch, smartglasses, etc.), or other type of mobile device, or a stationary computing device such as a desktop computer or PC. Computing device 100 may also be a mobile or stationary server.
wherein the processor 120 may perform the steps of the method shown in fig. 2.
As shown in fig. 2, fig. 2 is a schematic flowchart illustrating a sound source setting method in a virtual environment according to an embodiment of the present application, including steps S210 to S230.
Step S210: and acquiring the boundary of the target environment and the position of the role.
In an embodiment of the present application, the target environment may be various environments in a virtual scene of interest, such as a snow mountain, a lake, a sea, a street, an amusement park, and the like, which is not limited in this application. The method for determining the target environment may be various, and the method may be determined according to whether the distance between the role and the center of the environment area is greater than a preset threshold, where the environment area does not belong to the target environment when the distance between the role and the center of the environment area is greater than the preset threshold, and the environment area belongs to the target environment when the distance between the role and the center of the environment area is less than or equal to the preset threshold; when the character moves, the scene in the game interface is continuously changed along with the movement of the character, and the environment area presented in the game interface at the same time when the position of the character is obtained or in the same frame of picture can be used as the target environment, or the target environment can be determined by other methods.
The boundary is a landmark boundary for dividing the environment region, and may be an outer contour line of the environment region of various shapes. The target environment boundary may be an outer boundary of the virtual environment model of interest in connection with the character position. The position of the character can be the place and the direction of the character.
For example, suppose that three environment areas, namely a forest, a waterfall and a street, are set in a game, a character is located among the forest environment area, the waterfall environment area and the street environment area, and the distances between the character and the forest environment area, the waterfall environment area and the street environment area are equal to each other and are smaller than a preset threshold value, the forest environment, the waterfall environment and the street environment all belong to target environments, and the boundary of the forest environment area, the boundary of the waterfall environment area and the boundary of the street environment area all belong to target environment boundaries; under the condition that the role is located between the forest environment area and the waterfall environment area and the distance between the role and the street environment area is larger than a set threshold value, the street environment does not belong to a target environment, the boundary of the street environment area does not belong to the boundary of the target environment, under the condition that the role is located at an intermediate point between the forest environment area and the waterfall environment area, the forest environment and the waterfall environment both belong to the target environment, and the boundary of the forest environment area and the boundary of the waterfall environment area are both the boundaries of the target environment.
in practical application, the target environment boundary and the role position can be obtained at regular time according to a preset time interval.
The preset time interval may be determined according to actual requirements, for example, the target environment boundary and the role position (n is an integer greater than or equal to 1) may be obtained n times per second, or the target environment boundary and the role position (x is an integer greater than or equal to 1) may be obtained once per x frames.
Step S220: and judging whether the role is in the target environment or not based on the target environment boundary and the role position, if so, executing step S221, and if not, executing step S222.
step S221: and setting the same position data as the character for the virtual sound source. After the position data identical to the character is set for the virtual sound source, the process proceeds to step S230.
Step S222: and calculating the distance between the character and the boundary of the target environment, and setting position data for the virtual sound source based on the calculated distance. After the position data is set for the virtual sound source, the process proceeds to step S230.
For example, a coordinate system may be established based on the target environment, a central point in the target environment is used as a coordinate origin, a target environment boundary and a role position are represented in a coordinate form, a distance between the target environment boundary and the role position is calculated, if the distance between the target environment boundary and the role position is greater than a preset value, it is determined that the role is located outside the target environment, if the distance between the target environment boundary and the role position is less than the preset value, it is determined that the role is located in the target environment, and if the distance between the target environment boundary and the role position is equal to the preset value, it is determined that the role is located on the target environment boundary. In addition, whether the role is in the target environment can be judged by other methods, and the application does not limit the method.
if the character is in the target environment, setting position data which is the same as the position data of the character for the virtual sound source, and if the character moves in the target environment, moving the virtual sound source along with the movement of the character; if the character moves from the target environment to the outside of the target environment, the virtual sound source still moves along with the movement of the character when the character is still in the target environment, the distance between the character and the target environment is calculated after the character moves to the outside of the target environment, and position data is set for the virtual sound source based on the distance between the character and the target environment.
For example, the intersection point of the character position and the target environment boundary may be obtained by taking the character position as a starting point and making any ray intersecting the target environment boundary, the linear distance between the character position and the intersection point may be calculated, and the calculated linear distance may be used as the distance between the character and the target environment. In addition, the distance between the role and the target environment can be calculated by other methods, which is not limited in the present application.
Further, a shortest distance between the character and the target environment boundary is calculated.
and obtaining the target position which is closest to the role on the boundary of the target environment based on the calculated shortest distance.
Setting the target position as position data of the analog sound source.
The method for calculating the shortest distance between the character and the boundary of the target environment may be various, for example, several rays intersecting the boundary of the target environment may be made using the position of the character as a starting point, intersection points of several rays at the position of the character and the boundary of the target environment are generated, the linear distance between the position of the character and each intersection point is calculated, the calculated shortest distance is taken as the shortest distance between the character and the target environment, and the position of the point on the boundary of the target environment, which is the shortest distance from the character, is taken as the target position. In addition, the distance between the role and the target environment can be calculated by other methods, which is not limited in the present application.
The target position is a position of a point closest to the character on the boundary of the target environment, and the target position moves with the movement of the character and changes with the change of the position of the character.
in practical applications, in a case where the target position includes two or more positions, the same position data as any one of the target positions may be set for the virtual sound source.
specifically, if two or more points closest to the character exist on the boundary of the target environment and the distances between the two or more points and the character are equal, the positions of the two or more points closest to the character are all target positions, and since the distances between the character and the two or more target positions are equal, the same position data as the position of any one of the target positions can be set for the virtual sound source, in which case, the difference in the selection of the target positions does not affect the finally presented sound effect.
for example, assuming that the target environment boundary is a concave-shaped boundary, and the concave-shaped boundary has a hidden central line which can equally divide the concave-shaped boundary into two parts, when the character moves to the hidden central line in the concave region of the concave-shaped boundary, two or more points closest to the character exist on the target environment boundary, the positions of the two or more points closest to the character on the target environment are target positions, one of the target positions is arbitrarily selected, and position data which is the same as the position of the target position is set for the virtual sound source.
Step S230: and setting a virtual sound source according to the position data of the virtual sound source.
Specifically, the virtual sound source may be a timbre resource in a virtual game scene, and the type of the sound of the virtual sound source includes multiple types, such as wind sound, rain sound, thunder sound, and the like, or a mixed sound of wind sound, rain sound, and thunder sound, which may be determined according to the target environment and the game scene, which is not limited in this application.
for example, if the target environment is a lawn, the sound of the virtual sound source may include a worm sound, a joy sound, and the like, in the case where the specific game scene is a cool lawn, the sound of the virtual sound source may be a worm sound, and in the case where the specific game scene is a lawn suitable for stepping on green and picnics, the sound of the virtual sound source may be a mixed sound of the worm sound, the laughing sound, the joy sound, and the speech sound; if the target environment is an ocean, the virtual sound source may include wind sound, sea sound, and the like, and in the case that the specific game scene is an ocean in the world of clear sky, the sound of the virtual sound source may be the sea sound, ship whistle sound, and the like, or may be a mixed sound including the sea sound and the ship whistle sound, and in the case that the specific game scene is an ocean with lightning, the sound of the virtual sound source may include a mixed sound of thunder sound, wind sound, sea sound, and the like.
If the target environment is a train station, the sound of the virtual sound source may be speech sound, whistling sound, broadcast sound, and the like, and when the specific game scene is the train station where no train arrives, the sound of the virtual sound source may include vendor sound, crowd speech sound, and station broadcast sound, and the volume ratios of the vendor sound, the crowd speech sound, and the station broadcast sound in the sound of the virtual sound source may be determined according to actual requirements, if the volume ratio of the station broadcast sound in the sound of the virtual sound source is 40%, the volume ratios of the vendor sound and the crowd speech sound in the virtual sound source are both 30%, and the present application does not limit this.
The position data of the virtual sound source may include one or more, and the virtual sound source may also include one or more, which may be determined according to the specific situation, and the present application does not limit this.
The above embodiments will be further described with reference to specific examples.
For example, if an initial character position is obtained when a character enters a game scene, and the game interface further includes four environment areas, namely a creek environment area, a pasture environment area, a bamboo forest environment area and a flower field area, under the condition that the initial character position is the center of the game interface, the creek environment area, the pasture environment area, the bamboo forest environment area and the flower field environment area are all target environment areas, and the boundary of the creek environment area, the boundary of the pasture environment area, the boundary of the bamboo forest environment area and the boundary of the flower field environment area are all target environment boundaries.
assuming that a two-dimensional coordinate system is established by using an initial character position coordinate origin, each extracted target environment boundary and character positions of different frames are represented in a coordinate form, the target environment boundary and the character positions are acquired once per frame, assuming that the obtained character positions at the 10 th frame are (x10, y10) and (x10, y10) are located in the boundary of the pasture environment area, the position data of the virtual sound source at the 10 th frame is (x10, y10), and the virtual sound source plays the boeing sound and the eweing sound of the pasture environment area. Assuming that the acquired character position of the 12 th frame is (x12, y12) and (x12, y12) is still located within the boundary of the pasture environment area, the position data of the virtual sound source in the 12 th frame is updated to (x12, y12), and the virtual sound source still plays the boating and sheep howling in the pasture environment area.
Assuming that the character position acquired at the 15 th frame is (x15, y15), (x15, y15) is not in any target environment, the shortest distance between the character position (x15, y15) and each target environment is calculated respectively, and the distance between the character position (x15, y15) and the point a (xa, ya) on the boundary of the pasture environment area is obtained to be shortest, the position data set by the virtual sound source is updated to be (xa, ya), and the virtual sound source plays the bodes and bodes of the pasture environment area. Assuming that the character position acquired at the 18 th frame is (x18, y18), (x18, y18) is not in any target environment, respectively calculating the shortest distance between the character position (x18, y18) and each target environment to obtain the shortest distance between the character position (x18, y18) and the point b (xb, yb) on the boundary of the pasture environment area, updating the position data set by the virtual sound source to be (xb, yb), and the virtual sound source still plays the cattle and sheep sounds in the pasture environment area.
assuming that the character position acquired in the 22 nd frame is (x22, y22), (x22, y22) in none of the target environments, the shortest distance between the character position (x22, y22) and each of the target environments is calculated, and the distance between the character position (x22, y22) and the point c (xc, yc) and the point d (xd, yd) on the boundary of the brook environment area is obtained, and the distance between the character position (x22, y22) and the point c (xc, yc) and the distance between the character position (x22, y22) and the point d (xd, yd) are equal, the position data of the virtual sound source may be updated to (xc, yc) or (xd, yd), and the virtual sound source plays the sound of the brook environment area.
Assuming that the obtained angular positions of the 30 th frame are (x30, y30), (x30, y30) in none of the target environments, the shortest distance between the character positions (x30, y30) and each of the target environments is calculated, respectively, and the distance between the character positions (x30, y30) and the point e (xe, ye) on the boundary of the brook environment area and the point f (xf, yf) on the boundary of the flower field environment area is shortest, and the distance between the character positions (x30, y30) and the point e (xe, ye) on the boundary of the brook environment area and the distance between the character positions (x30, y30) and the point f (xf, yf) on the boundary of the flower field environment area are equal, the stream sound source is set at the point e (xe, ye) on the boundary of the brook environment area and the point f (xf, yf) on the boundary of the flower field environment area, respectively, and the virtual sound source area of the stream sound source area at the point e (ye) is played at the same time, the virtual sound source at point f (xf, yf) plays a bird song of the flower field environment area.
assuming that the character position acquired at the 36 th frame is (x36, y36), (x36, y36) in none of the target environments, the shortest distance between the character position (x36, y36) and each target environment is calculated, respectively, and the distance between the character position (x36, y36) and the point g (xg, yg), the point h (xh, yh) on the boundary of the bamboo forest environment area and the point i (xi, yi) on the boundary of the flower field environment area is shortest, and the distance between the character position (x36, y36) and the point g (xg, yg), the point h (xh, yh) on the boundary of the bamboo forest environment area and the distance between the character position (x36, y36) and the point i (xi, yi) on the boundary of the flower field environment area are equal, a virtual sound source area boundary (xi, xi) is set at the point g (xg, yg) or the point h, yh) on the boundary of the bamboo forest environment area, yi), two virtual sound sources are played simultaneously, the virtual sound source at the point g (xg, yg) or the point h (xh, yh) plays the wind sound of the bamboo forest environment area, and the virtual sound source at the point i (xi, yi) plays the bird song of the flower field environment area.
in the sound source setting method in a virtual environment according to an embodiment of the present application, when a character is located in a target environment area, a position of a virtual sound source is the same as a position of the character and moves along with movement of the character, and when the character is located outside the target environment, the position of the virtual sound source is a position of a point on a boundary of the target environment, the point being closest to the position of the character, and moves along with movement of the character, so that continuity and clarity of sound of the virtual sound source can be effectively ensured, and discontinuous or unclear sound of the virtual sound source caused by too far distance from the position of the virtual sound source due to movement of the character is avoided, thereby improving fineness and reality of the virtual sound source in a scene, and enhancing experience of a player.
as shown in fig. 3, fig. 3 is a schematic flowchart of a sound source setting method in a virtual environment according to an embodiment of the present application, including steps S310 to S340.
Step S310: and establishing a target environment model.
the target environment may be various environmental regions in the virtual scene of interest, such as a forest, a lake, a sea, a street, a market, a bar, and the like, which is not limited in this application. Various tools such as 3D max can be selected to build the target environment model, which is not limited in this application.
Step S320: and acquiring the boundary of the target environment and the position of the role according to the target environment model.
The method for obtaining the boundary of the target environment according to the target environment model may be various methods such as edge extraction, which is not limited in the present application.
step S330: and judging whether the role is in the target environment or not based on the target environment boundary and the role position. If so, step S331 is executed, and if not, step S332 is executed.
Step S331: and setting the same position data as the character for the virtual sound source. After the position data identical to the character is set for the virtual sound source, the process proceeds to step S340.
Step S332: and calculating the distance between the character and the boundary of the target environment, and setting position data for the virtual sound source based on the calculated distance. After the position data is set for the virtual sound source, step S340 is continuously performed.
Further, a shortest distance between the character and the target environment boundary is calculated.
And obtaining the target position which is closest to the role on the boundary of the target environment based on the calculated shortest distance.
setting the target position as position data of the analog sound source.
under the condition that the target position comprises two or more positions, the target environment boundary can be converted to obtain a conversion environment boundary; and calculating the distance between the character and the boundary of the conversion environment, and setting position data for the virtual sound source based on the calculated distance.
Specifically, if a ray passes through the target environment boundary of the target environment model and the target environment model to generate more than two intersection points, the target environment model is a concave model; if any ray passes through the target environment boundary of the target environment model and the target environment model to generate only two intersection points, the target environment model is a convex model.
In the case where the target position includes two or more positions, the target environment model is a concave model, and when the position data of the virtual sound source is determined, the uniquely obtained target position can be obtained by conversion between the concave model and the convex model. The target environment model can be converted into a convex model, the boundary of the target environment model after being converted into the convex model is extracted through methods such as edge extraction and the like, the boundary of the conversion environment is obtained, the distance between the role and the boundary of the conversion environment is calculated, and position data is set for the virtual sound source. The method for converting the female mold into the male mold is not limited in the present application. The method for calculating the distance between the role and the transition boundary may include various methods, and refer to step S220 described above, which is not described herein again.
Further, calculating a shortest distance between the character and the transition environment boundary; based on the calculated shortest distance, obtaining a position which is closest to the role on the boundary of the conversion environment; and setting the position closest to the character on the boundary of the conversion environment as the position data of the analog sound source.
The method for calculating the shortest distance between the role and the boundary of the transformation environment includes various methods, which can refer to the step S220, and is not described herein again.
For example, after the edge extraction is performed on the target environment model, an M-type target environment boundary with a closed bottom is obtained, when the character is within the boundary of the target environment, the position data which is the same as the position of the character is configured for the virtual sound source, in the case that the character is outside the boundary of the target environment, the shortest distance between the character and the boundary of the target environment is calculated, since, in the case of a transverse ray crossing the boundary of the object environment, there are more than two intersection points between the transverse ray and the boundary of the object environment, the target environment model is a concave model, the target environment model is converted to obtain a convex model, the converted target environment model is supposed to be subjected to edge extraction to obtain a conversion environment with a rectangular boundary, the shortest distance between the character and the rectangular conversion environment boundary is calculated, and position data which is not configured for the virtual sound source at the position on the conversion boundary closest to the character is obtained.
Step S340: and setting a virtual sound source according to the position data of the virtual sound source.
The position data of the virtual sound source may include one or more virtual sound sources, and the virtual sound source may also include one or more virtual sound sources, which may be determined according to specific situations, and refer to step S230 described above, which is not described herein again.
the above embodiments are further described below with reference to specific examples.
For example, if an initial character position is obtained when a character enters a game scene, and the game interface further includes two environment regions, namely a snack street and a bar, when the initial character position is the center of the game interface, the snack street environment region and the bar environment region are both target environment regions, and the boundary of the snack street environment region and the boundary of the bar environment region are both target environment boundaries.
a two-dimensional coordinate system is established by an initial role position coordinate origin, each extracted target environment boundary and the role positions with different frame numbers are expressed in a coordinate mode, and the target environment boundary and the role positions are acquired once per frame.
Assuming that the acquired character position in the 6 th frame is (x6, y6), (x6, y6) in none of the target environments, the shortest distance between the character position (x6, y6) and each target environment is calculated, respectively, the distance between the character position (x6, y6) and the point a (xa, ya) and the point b (xb, yb) on the bar environment area boundary is obtained as the shortest, and the distance between the character position (x6, y6) and the point a (xa, ya) and the distance between the character position (x6, y6) and the point b (xb, yb) are equal, the bar environment model is converted, the conversion model is obtained, the boundary of the conversion environment is obtained, the distance between the character position (x6, y6) and the boundary of the conversion environment is calculated, the shortest distance between the character position (x6, y6) and the point c, yc on the conversion environment boundary is obtained, the position data of the virtual sound source is set to the point c (xc, yc) and the virtual sound source plays the music sound of the bar environment area.
Assuming that the character position acquired at the 18 th frame is (x18, y18), (x18, y18) in none of the target environments, the shortest distance between the character position (x18, y18) and each target environment is calculated, respectively, and the distance between the character position (x18, y18) and the point d (xd, yd) and the point e (xe, ye) on the bar environment region boundary and the distance between the character position (x18, y18) and the point d (xd, yd), the distance between the point e (xe, ye) and the distance between the point q (xq, yq) are all equal, the bar environment model is converted to obtain a conversion model, the boundary of the conversion model is acquired to obtain a conversion environment boundary, the distance between the character position (x18, y18) and the conversion environment boundary are calculated, and the character position (x 18) is acquired, y18) and the point f (xf, yf) on the boundary of the conversion environment are the shortest, then virtual sound sources are respectively set at the point f (xf, yf) on the boundary of the conversion environment of the bar environment region and at the point q (xq, yq) on the boundary of the snack street environment region to play simultaneously, and the virtual sound source at the point f (xf, yf) on the boundary of the conversion environment of the bar environment region plays the music sound of the bar environment region, and the virtual sound source at the point q (xq, yq) on the boundary of the snack street environment region plays the call sound of the snack street environment region.
In the method for setting a sound source in a virtual environment, the target environment model and the target environment boundary are converted under the condition that two or more positions closest to the character exist on the target environment boundary, so that the only position closest to the character is determined to set the virtual sound source, the accuracy of the position of the virtual sound source can be effectively improved, the sound effect of the virtual sound source is effectively improved, and better experience is brought to a player.
As shown in fig. 4, fig. 4 is a schematic structural diagram illustrating an audio source setting apparatus in a virtual environment according to an embodiment of the present application.
an audio source setting apparatus in a virtual environment, comprising:
An obtaining module 410 configured to obtain the target environment boundary and the role position.
A determining module 420 configured to determine whether the character is in the target environment based on the target environment boundary and the character position.
and if the character is in the target environment, setting the same position data as the character for the virtual sound source.
and if the character is not in the target environment, calculating the distance between the character and the boundary of the target environment, and setting position data for the virtual sound source based on the calculated distance.
A setting module 430 configured to set a virtual sound source according to the position data of the virtual sound source.
Optionally, the sound source setting apparatus in the virtual environment further includes:
An establishing module configured to establish a target environment model.
the obtaining module 410 is specifically configured to: and acquiring a target environment boundary according to the target environment model.
And acquiring a target environment boundary according to the target environment model.
Optionally, the obtaining module 410 is further configured to:
And acquiring the boundary of the target environment and the position of the role at regular time according to a preset time interval.
Optionally, the computing module is further configured to:
Calculating the shortest distance between the character and the boundary of the target environment.
and obtaining the target position which is closest to the role on the boundary of the target environment based on the calculated shortest distance.
setting the target position as position data of the analog sound source.
Optionally, the computing module is further configured to:
In a case where the target position includes two or more positions, the same position data as any one of the target positions is set for the virtual sound source.
Optionally, the computing module is further configured to:
And under the condition that the target position comprises two or more positions, converting the target environment boundary to obtain a conversion environment boundary.
and calculating the distance between the character and the boundary of the conversion environment, and setting position data for the virtual sound source based on the calculated distance.
optionally, the computing module is further configured to:
calculating a shortest distance between the character and the transition environment boundary.
And obtaining the position which is closest to the role on the boundary of the conversion environment based on the calculated shortest distance.
And setting the position closest to the character on the boundary of the conversion environment as the position data of the analog sound source.
The sound source setting device in the virtual environment can effectively reduce consumption of virtual sound sources to system calculation and greatly improve game performance.
an embodiment of the present application further provides a computing device, including a memory, a processor, and computer instructions stored on the memory and executable on the processor, where the processor executes the instructions to implement the following steps:
and acquiring the boundary of the target environment and the position of the role.
And judging whether the role is in the target environment or not based on the target environment boundary and the role position.
And if the character is in the target environment, setting the same position data as the character for the virtual sound source.
And if the character is not in the target environment, calculating the distance between the character and the boundary of the target environment, and setting position data for the virtual sound source based on the calculated distance.
And setting a virtual sound source according to the position data of the virtual sound source.
an embodiment of the present application further provides a computer-readable storage medium, which stores computer instructions, and when the instructions are executed by a processor, the steps of the sound source setting method in the virtual environment are implemented.
The above is an illustrative scheme of a computer-readable storage medium of the present embodiment. It should be noted that the technical solution of the storage medium belongs to the same concept as the technical solution of the sound source setting method in the virtual environment, and details that are not described in detail in the technical solution of the storage medium can be referred to the description of the technical solution of the sound source setting method in the virtual environment.
The computer instructions comprise computer program code which may be in the form of source code, object code, an executable file or some intermediate form, or the like. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, usb disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM), electrical carrier wave signals, telecommunications signals, software distribution medium, and the like. It should be noted that the computer readable medium may contain content that is subject to appropriate increase or decrease as required by legislation and patent practice in jurisdictions, for example, in some jurisdictions, computer readable media does not include electrical carrier signals and telecommunications signals as is required by legislation and patent practice.
it should be noted that, for the sake of simplicity, the above-mentioned method embodiments are described as a series of acts or combinations, but those skilled in the art should understand that the present application is not limited by the described order of acts, as some steps may be performed in other orders or simultaneously according to the present application. Further, those skilled in the art should also appreciate that the embodiments described in the specification are preferred embodiments and that the acts and modules referred to are not necessarily required in this application.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and for parts that are not described in detail in a certain embodiment, reference may be made to related descriptions of other embodiments.
The preferred embodiments of the present application disclosed above are intended only to aid in the explanation of the application. Alternative embodiments are not exhaustive and do not limit the invention to the precise embodiments described. Obviously, many modifications and variations are possible in light of the above teaching. The embodiments were chosen and described in order to best explain the principles of the application and the practical application, to thereby enable others skilled in the art to best understand and utilize the application. The application is limited only by the claims and their full scope and equivalents.