Polygonal adsorption method, device, computer readable storage medium and electronic device
Patent Information
- Application Number
- CN202310657787.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-05
- Publication Date
- 2026-10-20
- Estimated Expiration
- 2043-06-05
AI Technical Summary
相关技术采用的方法是通过分离轴定律计算出两个多边形之间的位置关系,再计算两个多边形吸附所需要的移动数值,整个过程较为复杂
[0009]在本发明至少部分实施例中,采用确定移动多边形上的第一顶点到固定多边形上的第一目标边的第一距离值,以及确定固定多边形上的第二顶点到移动多边形上的第二目标边的第二距离值,从而基于第一距离值和第二距离值确定移动多边形与固定多边形之间的位置关系,进一步基于位置关系控制移动多边形吸附至固定多边形的第一目标边。需要注意的是,根据移动多边形与固定多边形第一距离值及第二距离值确定移动多边形与固定多边形之间位置关系,再根据位置关系控制移动多边形吸附至固定多边形,可以使移动多边形能根据位置关系快速吸附至固定多边形,达到了降低多边形吸附的难度,提高了移动多边形吸附至固定多边形的吸附效率的目的,从而实现了移动多边形快速吸附至固定多边形的技术问题,进而解决了相关技术中多边形的吸附难度较大的技术问题。
Smart Images

Figure CN116630483B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of graphics processing, and more specifically, to a method, apparatus, computer-readable storage medium, and electronic device for adsorbing polygons. Background Technology
[0002] Currently, objects in games are mostly represented by polygonal images. When it's necessary to snap one polygon to the location of another polygon in space, the corresponding movement value needs to be obtained. The relevant technology uses the law of separation axes to calculate the positional relationship between the two polygons, and then calculates the movement value required for the two polygons to snap together. The whole process is quite complex.
[0003] There is currently no effective solution to the above problems. Summary of the Invention
[0004] At least some embodiments of the present invention provide a method, apparatus, computer-readable storage medium, and electronic device for adsorbing polygons, so as to at least solve the technical problem of the difficulty in adsorbing polygons in the related art.
[0005] According to one embodiment of the present invention, a method for snapping together a polygon is provided, comprising: determining a first distance value from a first vertex on a moving polygon to a first target edge on a fixed polygon, wherein the moving polygon represents a mapping of a moving object in a game scene on a preset plane, the fixed polygon represents a mapping of a fixed object in the game scene on the preset plane, and the first target edge represents the edge on the fixed polygon that is closest to the first vertex; determining a second distance value from a second vertex on the fixed polygon to a second target edge on the moving polygon, wherein the second target edge represents the edge on the moving polygon that is closest to the second vertex; determining a positional relationship between the moving polygon and the fixed polygon based on the first distance value and the second distance value; and controlling the moving polygon to snap together to the first target edge of the fixed polygon based on the positional relationship.
[0006] According to one embodiment of the present invention, a polygon adsorption device is also provided. The device includes: a first determining module, configured to determine a first distance value from a first vertex on a moving polygon to a first target edge on a fixed polygon, wherein the moving polygon represents a mapping of a moving object in a game scene on a preset plane, the fixed polygon represents a mapping of a fixed object in the game scene on the preset plane, and the first target edge represents the edge on the fixed polygon that is closest to the first vertex; a second determining module, configured to determine a second distance value from a second vertex on the fixed polygon to a second target edge on the moving polygon, wherein the second target edge represents the edge on the fixed polygon that is closest to the second vertex; a third determining module, configured to determine the positional relationship between the moving polygon and the fixed polygon based on the first distance value and the second distance value; and a control module, configured to control the moving polygon to adsorb onto the first target edge of the fixed polygon based on the positional relationship.
[0007] According to one embodiment of the present invention, a computer-readable storage medium is also provided, wherein a computer program is stored in the computer-readable storage medium, and the computer program is configured to execute the polygon adsorption method in the above embodiment when run by a processor.
[0008] According to one embodiment of the present invention, an electronic device is also provided, including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to perform the polygon adsorption method in the above embodiments.
[0009] In at least some embodiments of the present invention, a first distance value is determined from a first vertex on the moving polygon to a first target edge on the fixed polygon, and a second distance value is determined from a second vertex on the fixed polygon to a second target edge on the moving polygon. This determines the positional relationship between the moving polygon and the fixed polygon based on the first and second distance values, and further controls the moving polygon to snap to the first target edge of the fixed polygon based on this positional relationship. It should be noted that determining the positional relationship between the moving polygon and the fixed polygon based on the first and second distance values, and then controlling the moving polygon to snap to the fixed polygon based on this positional relationship, allows the moving polygon to quickly snap to the fixed polygon based on the positional relationship. This reduces the difficulty of snapping to the polygon and improves the snapping efficiency, thus solving the technical problem of rapid snapping of the moving polygon to the fixed polygon in related technologies. Attached Figure Description
[0010] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with their description, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings:
[0011] Figure 1 This is a hardware structure block diagram of a mobile terminal for a polygon adsorption method according to an embodiment of the present invention.
[0012] Figure 2 This is a flowchart of a polygon adsorption method according to one embodiment of the present invention;
[0013] Figure 3 This is a flowchart of an adsorption function algorithm according to one optional embodiment of the present invention;
[0014] Figure 4 This is a flowchart of a target distance value function algorithm according to one optional embodiment of the present invention;
[0015] Figure 5 This is a flowchart of a numerical computation function algorithm according to one optional embodiment of the present invention;
[0016] Figure 6 This is a schematic diagram of a transformation based on a preset axis of a moving polygon, according to one optional embodiment of the present invention.
[0017] Figure 7 This is a schematic diagram of a rotation with the first adsorption point as the axis of rotation according to one optional embodiment of the present invention;
[0018] Figure 8 This is a flowchart of a polygon adsorption method according to one optional embodiment of the present invention;
[0019] Figure 9 This is a schematic diagram of a polygon before adsorption according to one optional embodiment of the present invention;
[0020] Figure 10 This is a schematic diagram of a polygon after adsorption according to one optional embodiment of the present invention;
[0021] Figure 11 This is a schematic diagram of a polygonal adsorption device according to one embodiment of the present invention;
[0022] Figure 12 This is a schematic diagram of an electronic device according to one embodiment of the present invention. Detailed Implementation
[0023] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0024] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0025] According to one embodiment of the present invention, an embodiment of a polygon adsorption method is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be performed in a different order than that shown here.
[0026] This method embodiment can be executed on a mobile terminal, computer terminal, or similar computing device. Taking running on a mobile terminal as an example, the mobile terminal can be a smartphone (such as a tablet computer, PDA, mobile Internet Device (MID), PAD, game console, etc.). Figure 1 This is a hardware structure block diagram of a mobile terminal using a polygonal adsorption method according to an embodiment of the present invention. Figure 1 As shown, a mobile terminal may include one or more ( Figure 1Only one is shown in the diagram. A processor 102 (which may include, but is not limited to, a central processing unit (CPU), graphics processing unit (GPU), digital signal processing (DSP) chip, microprocessor (MCU), programmable logic device (FPGA), neural network processor (NPU), tensor processor (TPU), artificial intelligence (AI) type processor, etc.) and a memory 104 for storing data are also shown. Optionally, the mobile terminal may further include a transmission device 106 for communication functions, an input / output device 108, and a display device 110. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the mobile terminal described above. For example, the mobile terminal may also include components that are more... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0027] The memory 104 can be used to store computer programs, such as application software programs and modules, like the computer program corresponding to the polygon adsorption method in this embodiment of the invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, thereby realizing the aforementioned polygon adsorption method. The memory 104 may include high-speed random access memory and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the mobile terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0028] The transmission device 106 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the mobile terminal's communication provider. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 may be a Radio Frequency (RF) module used for wireless communication with the Internet.
[0029] The inputs in input / output device 108 can come from multiple human interface devices (HIDs). Examples include keyboards and mice, gamepads, and other dedicated game controllers (such as steering wheels, fishing rods, dance mats, and remote controls). Some HIDs, in addition to providing input functions, can also provide output functions, such as force feedback and vibration from gamepads, and audio output from controllers.
[0030] Display device 110 may be, for example, a head-up display (HUD), a touchscreen liquid crystal display (LCD), and a touch display (also referred to as a "touchscreen" or "touch display"). The LCD allows a user to interact with the user interface of the mobile terminal. In some embodiments, the mobile terminal has a graphical user interface (GUI), which allows the user to interact with the GUI by touching and / or gesturing on a touch-sensitive surface. Optional human-computer interaction functions include: creating web pages, drawing, word processing, creating electronic documents, playing games, video conferencing, instant messaging, sending and receiving emails, a call interface, playing digital video, playing digital music, and / or web browsing, etc. Executable instructions for performing the above human-computer interaction functions are configured / stored in one or more processor-executable computer program products or readable storage media.
[0031] In one embodiment of this disclosure, a polygon adsorption method can be run on a local terminal device or a server. When the polygon adsorption method is run on a server, the method can be implemented and executed based on a cloud interaction system, wherein the cloud interaction system includes a server and client devices.
[0032] In an optional implementation, various cloud applications, such as cloud gaming, can run under the cloud interaction system. Taking cloud gaming as an example, cloud gaming refers to a gaming method based on cloud computing. In the cloud gaming operating mode, the game program and the game screen presentation are separate. The storage and execution of the game are completed on the cloud gaming server. The client device is used for data reception, transmission, and game screen presentation. For example, the client device can be a display device with data transmission capabilities located close to the user, such as a mobile terminal, television, computer, or PDA; however, the information processing is performed by the cloud gaming server in the cloud. When playing the game, the player operates the client device to send operation commands to the cloud gaming server. The cloud gaming server runs the game according to the operation commands, encodes and compresses the game screen and other data, returns it to the client device via the network, and finally, the client device decodes and outputs the game screen.
[0033] In an optional implementation, taking a game as an example, the local terminal device stores the game program and is used to display the game screen. The local terminal device is used to interact with the player through a graphical user interface (GUI), i.e., conventionally by downloading, installing, and running the game program via an electronic device. The local terminal device can provide the GUI to the player in various ways, such as rendering it on the terminal's display screen or providing it to the player via holographic projection. For example, the local terminal device can include a display screen for displaying the GUI, which includes game screens, and a processor for running the game, generating the GUI, and controlling the display of the GUI on the display screen.
[0034] In one possible implementation, the present invention provides a polygon adsorption method that provides a graphical user interface through a terminal device, wherein the terminal device may be the aforementioned local terminal device or a client device in the aforementioned cloud interaction system. Figure 2 This is a flowchart of a polygon adsorption method according to one embodiment of the present invention. A graphical user interface is provided through a terminal device. The content displayed by the graphical user interface includes a touch area, such as... Figure 2 As shown, the method includes the following steps:
[0035] Step S202: Determine the first distance value from the first vertex on the moving polygon to the first target edge on the fixed polygon, wherein the moving polygon is used to represent the mapping graphic of the moving object in the game scene on the preset plane, the fixed polygon is used to represent the mapping graphic of the fixed object in the game scene on the preset plane, and the first target edge is used to represent the edge on the fixed polygon that is closest to the first vertex.
[0036] The aforementioned moving polygon can be a polygon image that needs to be moved, or a polygon that needs to snap to other polygons. The moving polygon can be any polygon image in the scene that needs to be moved, including but not limited to: characters and items. The fixed polygon can be a polygon whose position in the interface does not need to change, including but not limited to: characters and items.
[0037] The first vertex mentioned above can be a vertex on the moving polygon used to snap to the fixed polygon. The first target edge can be the edge on the fixed polygon with the shortest distance to the first vertex. The first distance value can be the distance between the first vertex on the moving polygon and the first target edge on the fixed polygon.
[0038] The game scene described above can be the game environment, buildings, or other scenes, including but not limited to: rooms and streets. The moving object can be a target that needs to be moved, or a target that needs to be snapped to other objects in the game. The preset plane can be a pre-defined graphical interface, or a pre-defined game interface where the moving object needs to be moved. The mapped graphic can be a polygon mapped onto the preset plane. The fixed object can be a target that does not need to be moved, or a target that is snapped to in the game interface.
[0039] In one alternative embodiment, a numerical calculation function algorithm is used to traverse each vertex of the moving polygon to determine the distance from each vertex of the moving polygon to the first target edge of the fixed polygon, thereby determining the first distance value from the first vertex of the moving polygon to the fixed polygon.
[0040] In another alternative embodiment, the moving polygon can be divided into multiple polygons, and an algorithm can be used to traverse all the vertices of the moving polygon. The coordinates of the vertices of the moving polygon and the expression of the first target edge can be obtained using a coordinate system. The distance from all vertices of the moving polygon to the first target edge can be calculated to obtain the first distance value.
[0041] In another optional embodiment, the edge of the fixed polygon closest to the moving polygon is determined as the first target edge. All vertices of the moving polygon are traversed, and the coordinates of the moving polygon vertices and the expression of the first target edge are obtained using a coordinate system. The coordinate system can be a coordinate system established with the image as the center point, and the expression can be an expression of the position of the first target edge in the coordinate system using x and y. Thus, the distance from all vertices of the moving polygon to the first target edge is calculated based on the coordinates of the moving polygon vertices and the expression of the first target edge, thereby obtaining the first distance value.
[0042] It should be noted that related technologies calculate non-intersecting polygons using the law of separating axes, and then calculate the movement parameters for these non-intersecting polygons. This results in the inability to calculate the movement parameters for intersecting polygons, and related technologies have difficulty obtaining the movement parameters for concave polygons. In contrast, this application uses an algorithm to traverse the moving polygons and obtain the corresponding data. Therefore, this application can obtain the movement parameters for both convex and concave polygons, and is not limited to the positional relationship between the two polygons. That is, it can also calculate the movement parameters between intersecting polygons.
[0043] Step S204: Determine the second distance value from the second vertex on the fixed polygon to the second target edge on the moving polygon, wherein the second target edge is used to represent the edge on the moving polygon that is closest to the second vertex.
[0044] The second vertex mentioned above can be a vertex on the fixed polygon. The second target edge can be the edge on the moving polygon that has the shortest distance to the second vertex. The second distance value can be the distance between the second vertex on the fixed polygon and the second target edge on the moving polygon.
[0045] In one optional embodiment, the edge of the moving polygon closest to the fixed polygon is determined as the second target edge. All vertices of the fixed polygon are traversed, and the coordinates of the vertices of the fixed polygon and the expression of the second target edge are obtained using the coordinate system. The distance from all vertices of the fixed polygon to the second target edge is calculated to obtain the second distance value.
[0046] In another alternative embodiment, the polygon can be divided into multiple polygons, all polygons can be traversed, non-intersecting polygons can be calculated using the law of separating axes, all vertices of the fixed polygons can be traversed, the coordinates of the vertices of the fixed polygons and the expression of the second target edge can be obtained using the coordinate system, and the distance from all vertices of the fixed polygons to the second target edge can be calculated to obtain the second distance value.
[0047] Step S206: Determine the positional relationship between the moving polygon and the fixed polygon based on the first distance value and the second distance value.
[0048] The aforementioned positional relationships can be between graphics or between moving and fixed polygons on the same interface.
[0049] In one optional embodiment, the current positions of the moving polygon and the fixed polygon are determined based on the obtained first and second distance values, and the positional relationship between the moving polygon and the fixed polygon is determined. If the distance from the first target edge of the fixed polygon to the nearest vertex of the moving polygon is greater than 0, and the distance from the second target edge of the moving polygon to the farthest vertex of the fixed polygon is less than 0, then the fixed polygon is determined to be inside the moving polygon. If the distance from the first target edge of the fixed polygon to the farthest vertex of the moving polygon is less than 0, and the distance from the second target edge of the moving polygon to the nearest vertex of the fixed polygon is greater than 0, then the moving polygon is determined to be inside the fixed polygon. If the distance from the first target edge of the fixed polygon to the nearest vertex of the moving polygon is greater than 0, and the distance from the second target edge of the moving polygon to the nearest vertex of the fixed polygon is greater than 0, then the moving polygon and the fixed polygon do not intersect.
[0050] Step S208: Based on the positional relationship, control the moving polygon to snap to the first target edge of the fixed polygon.
[0051] In one optional embodiment, the minimum distance between each vertex of the moving polygon and the fixed polygon and the first target edge or the second target edge is determined as the target distance value based on the positional relationship between the moving polygon and the fixed polygon.
[0052] In another optional embodiment, if the fixed polygon is inside the moving polygon, it is necessary to determine whether the distance of the first target edge from the nearest vertex on the moving polygon is less than the distance of the second target edge from the farthest vertex on the fixed polygon. If the distance of the first target edge from the nearest vertex on the moving polygon is less than the distance of the second target edge from the farthest vertex on the fixed polygon, the distance of the first target edge from the nearest vertex on the moving polygon is determined to be the target distance value; if the distance of the first target edge from the nearest vertex on the moving polygon is not less than the distance of the second target edge from the farthest vertex on the fixed polygon, the distance of the second target edge from the farthest vertex on the fixed polygon is determined to be the target distance value.
[0053] If the moving polygon is inside the fixed polygon, it is necessary to determine whether the distance from the farthest vertex of the first target edge to the moving polygon is less than the distance from the nearest vertex of the second target edge to the fixed polygon. If the distance from the farthest vertex of the first target edge to the moving polygon is less than the distance from the nearest vertex of the second target edge to the fixed polygon, then the distance from the farthest vertex of the first target edge to the moving polygon is determined to be the target distance value; if the distance from the farthest vertex of the first target edge to the moving polygon is not less than the distance from the nearest vertex of the second target edge to the fixed polygon, then the distance from the nearest vertex of the second target edge to the fixed polygon is determined to be the target distance value.
[0054] If the moving polygon is outside the fixed polygon, it is necessary to determine whether the distance from the first target edge to the nearest vertex on the moving polygon is less than the distance from the second target edge to the nearest vertex on the fixed polygon. If the distance from the first target edge to the nearest vertex on the moving polygon is less than the distance from the second target edge to the nearest vertex on the fixed polygon, then the distance from the first target edge to the nearest vertex on the moving polygon is determined to be the target distance value; if the distance from the first target edge to the nearest vertex on the moving polygon is not less than the distance from the second target edge to the nearest vertex on the fixed polygon, then the distance from the second target edge to the nearest vertex on the fixed polygon is determined to be the target distance value.
[0055] If the moving polygon intersects with the fixed polygon, the preset distance value is determined to be the target distance value.
[0056] Furthermore, the movement parameters required for the moving polygon to attach to the fixed polygon are determined based on the target distance value. These movement parameters include a rotation angle and a position vector. The rotation angle can be the angle at which the edge containing the first attachment point of the moving polygon is rotated to be parallel to the first target edge. The position vector can be the distance between the first attachment point and the second attachment point. One attachment method involves first rotating the edge containing the first attachment point of the moving polygon to be parallel to the first target edge of the fixed polygon based on the rotation angle, and then attaching the moving polygon to the fixed polygon based on the position vector. Specifically: the displacement vector from the preset axis of the moving polygon to the first attachment point is obtained; the moving polygon is rotated along the edge containing the first attachment point to be parallel to the first target edge based on the rotation angle, and the displacement vector after rotation is obtained to determine the coordinates of the first attachment point after rotation; the difference between the coordinates of the first and second attachment points is calculated to obtain the distance between the first and second attachment points; and the moving polygon is then controlled to attach to the first target edge of the fixed polygon based on the distance between the first and second attachment points. Another approach is to first snap the moving polygon to the fixed polygon based on the position vector, and then rotate the moving polygon along the first snap point to obtain the snapped image. Specifically, based on the first and second snap points of the moving and fixed polygons, first snap the first snap point to the second snap point so that the first snap point and the second snap point coincide. Then, rotate the moving polygon according to the rotation angle so that the edge where the first snap point is located snaps to the edge of the first target.
[0057] In at least some embodiments of the present invention, by determining a first distance value from a first vertex on the moving polygon to a first target edge on the fixed polygon, and a second distance value from a second vertex on the fixed polygon to a second target edge on the moving polygon, the positional relationship between the moving polygon and the fixed polygon is determined based on the first and second distance values. Furthermore, the moving polygon is controlled to snap to the first target edge of the fixed polygon based on this positional relationship. It should be noted that determining the positional relationship between the moving polygon and the fixed polygon based on the first and second distance values, and then controlling the moving polygon to snap to the fixed polygon based on this positional relationship, allows the moving polygon to quickly snap to the fixed polygon, reducing the difficulty of snapping and improving the snapping efficiency. This solves the technical problem of quickly snapping the moving polygon to the fixed polygon, thereby addressing the difficulty of snapping the moving polygon to the fixed polygon in game scenes and effectively improving the user's gaming experience.
[0058] It should be noted that, Figure 3 This is a flowchart of an adsorption function algorithm according to one optional embodiment of the present invention, such as... Figure 3As shown, the adsorption function algorithm can be used to traverse both the fixed and moving polygons. The adsorption function algorithm uses adsorption functions, including but not limited to: `get_global_absorb_trans_by_sdf` (Get_global_absorb_trans_by_sdf( ...
[0059] Optionally, the first distance value includes a first minimum distance value and a first maximum distance value, and the second distance value includes a second minimum distance value and a second maximum distance value. Determining the positional relationship between the moving polygon and the fixed polygon based on the first distance value and the second distance value includes: determining that the positional relationship is that the fixed polygon is contained inside the moving polygon when the first minimum distance value is greater than a preset value and the second maximum distance value is less than a preset value; determining that the positional relationship is that the moving polygon is contained inside the fixed polygon when the first maximum distance value is less than a preset value and the second minimum distance value is greater than a preset value; and determining that the positional relationship is that the moving polygon is outside the fixed polygon when the first minimum distance value is greater than a preset value and the second minimum distance value is greater than a preset value.
[0060] The first minimum distance value mentioned above can be the distance between the first target edge and the nearest vertex on the moving polygon. The first maximum distance value can be the distance between the first target edge and the farthest vertex on the moving polygon. The second minimum distance value can be the distance between the second target edge and the nearest vertex on the fixed polygon. The second maximum distance value can be the distance between the second target edge and the farthest vertex on the fixed polygon.
[0061] The aforementioned preset value can be data set in advance as needed, or it can be a value used to determine the positional relationship between the moving polygon and the fixed polygon. It can be 0, but is not limited to this.
[0062] In one optional embodiment, after obtaining the first distance value and the second distance value between the moving polygon and the fixed polygon, the positional relationship between the moving polygon and the fixed polygon can be determined based on the first distance value and the second distance value. Figure 4This is a flowchart of a target distance value function algorithm according to one optional embodiment of the present invention, such as... Figure 4 As shown, the target distance function first obtains the first minimum and first maximum distance values from each fixed polygon to the moving polygon, along with the corresponding position vector and rotation angle. Then, it obtains the second minimum and second maximum distance values from the moving polygon to the fixed polygon. When the first minimum distance is greater than 0 and the second maximum distance is less than 0, it indicates that the moving polygon covers the fixed polygon; when the first maximum distance is less than 0 and the second minimum distance is greater than 0, it indicates that the moving polygon is inside the fixed polygon; when the first minimum distance is greater than 0 and the second minimum distance is greater than 0, it indicates that the fixed polygon is outside the moving polygon. When two polygons intersect, snapping is not required; the function directly returns the zero distance, zero position vector, and zero rotation angle, among other movement parameters.
[0063] Optionally, controlling the moving polygon to snap to the first target edge of the fixed polygon based on the positional relationship includes: determining a target distance value from a first maximum distance value, a first minimum distance value, a second maximum distance value, a second minimum distance value, and a preset distance value based on the positional relationship; obtaining the movement parameter corresponding to the target distance value; and controlling the moving polygon to snap to the first target edge of the fixed polygon based on the movement parameter.
[0064] The aforementioned preset distance values can be distance values that are set in advance as needed, including but not limited to: zero distance, zero position vector, and zero rotation angle.
[0065] The target distance value mentioned above can be the shortest distance from the moving polygon to the fixed polygon. The movement parameters can be the movement data of the moving polygon to the fixed polygon, including but not limited to: displacement vector and rotation angle. The displacement vector can be the distance the moving polygon moves relative to the fixed polygon within a preset plane. The rotation angle can be the angle required for the second target edge of the moving polygon to rotate parallel to the first target edge of the fixed polygon.
[0066] In one alternative embodiment, Figure 5 This is a flowchart of a numerical computation function algorithm according to one optional embodiment of the present invention, such as... Figure 5As shown, the numerical calculation function algorithm takes a moving polygon and a fixed polygon as input. The numerical calculation function algorithm uses numerical calculation functions to calculate the first distance value and the second distance value between the moving polygon and the fixed polygon. The numerical calculation functions include, but are not limited to: get_polygon_min_max_trans(get_polygon_min_max_transform). The algorithm traverses all vertices of the moving polygon, calculates the first distance value and the second distance value of the directed distance from this vertex to the fixed polygon, as well as the first snap point, the second snap point, the first target edge and the second target edge. When the first minimum distance is greater than 0, the corresponding displacement vector and rotation angle are obtained; when the first maximum distance is less than 0, the corresponding displacement vector and rotation angle are obtained.
[0067] Furthermore, the first distance value, the second distance value, the displacement vector, and the rotation angle are returned to the target distance value function algorithm. The target distance value function algorithm then determines the positional relationship between the moving polygon and the fixed polygon based on the first and second distance values, and subsequently determines the target distance value at which the moving polygon snaps to the fixed polygon based on this positional relationship. Figure 4 This is a flowchart of a target distance value function algorithm according to one optional embodiment of the present invention, such as... Figure 4 As shown, the target distance function returns the corresponding data as the target distance value based on the positional relationship. Then, based on the target distance value, the corresponding position vector and rotation angle, and other movement parameters, are obtained. These movement parameters are then used to control the moving polygon to snap to the fixed polygon.
[0068] Optionally, determining the target distance value from the first maximum distance value, the first minimum distance value, the second maximum distance value, and the second minimum distance value based on the positional relationship includes: in response to the positional relationship that the fixed polygon is contained inside the moving polygon, determining whether the first minimum distance value is less than the second maximum distance value; in response to the first minimum distance value being less than the second maximum distance value, determining the first minimum distance value as the target distance value; and in response to the first minimum distance value being greater than or equal to the second maximum distance value, determining the second maximum distance value as the target distance value.
[0069] In one alternative embodiment, Figure 4 This is a flowchart of a target distance value function algorithm according to one optional embodiment of the present invention, such as... Figure 4 As shown, when the moving polygon covers the fixed polygon, further judgment is made. If the absolute value of the first minimum distance is less than the absolute value of the second maximum distance, the first minimum distance and the corresponding displacement vector, rotation angle and other parameters are returned; otherwise, the second maximum distance value and the corresponding displacement vector, rotation angle and other movement parameters are returned, and the returned parameters are determined to be the target distance value.
[0070] Optionally, determining the target distance value from the first maximum distance value, the first minimum distance value, the second maximum distance value, and the second minimum distance value based on the positional relationship includes: in response to the positional relationship that the moving polygon is contained inside the fixed polygon, determining whether the first maximum distance value is less than the second minimum distance value; in response to the first maximum distance value being less than the second minimum distance value, determining the first maximum distance value as the target distance value; and in response to the first maximum distance value being greater than or equal to the second minimum distance value, determining the second minimum distance value as the target distance value.
[0071] In one alternative embodiment, Figure 4 This is a flowchart of a target distance value function algorithm according to one optional embodiment of the present invention, such as... Figure 4 As shown, when the moving polygon is inside the fixed polygon, further judgment is made. If the absolute value of the first maximum distance is less than the absolute value of the second minimum distance, the first maximum distance value and the corresponding displacement vector, rotation angle and other parameters are returned. Otherwise, the second minimum distance value and the corresponding displacement vector, rotation angle and other movement parameters are returned. The returned parameters are determined to be the target distance value.
[0072] Optionally, determining the target distance value from the first maximum distance value, the first minimum distance value, the second maximum distance value, the second minimum distance value, and the preset distance value based on the positional relationship includes: in response to the positional relationship being that the moving polygon is outside the fixed polygon, determining whether the first minimum distance value is less than the second minimum distance value; in response to the first minimum distance value being less than the second minimum distance value, determining the first minimum distance value as the target distance value; and in response to the first minimum distance value being greater than or equal to the second minimum distance value, determining the second minimum distance value as the target distance value.
[0073] In one alternative embodiment, Figure 4 This is a flowchart of a target distance value function algorithm according to one optional embodiment of the present invention, such as... Figure 4 As shown, when the fixed polygon is outside the moving polygon, it is further determined that if the absolute value of the first minimum distance is less than the second minimum absolute value, the first minimum distance value and the corresponding displacement vector, rotation angle and other movement parameters are returned; otherwise, the second minimum distance value and the corresponding displacement vector, rotation angle and other movement parameters are returned, and the returned parameters are determined to be the target distance value.
[0074] Optionally, determining the target distance value from the first maximum distance value, the first minimum distance value, the second maximum distance value, the second minimum distance value, and the preset distance value based on the positional relationship includes: in response to the positional relationship being the intersection of the moving polygon and the fixed polygon, determining the preset distance value as the target distance value.
[0075] In one alternative embodiment, Figure 4This is a flowchart of a target distance value function algorithm according to one optional embodiment of the present invention, such as... Figure 4 As shown, when two polygons intersect, the movement parameters such as zero distance, zero position vector, and zero rotation angle are directly returned. If the movement parameters such as zero distance, zero position vector, and zero rotation angle are determined to be the target distance value, then there is no need to snap the moving polygon.
[0076] Optionally, the movement parameters include a rotation angle. Controlling the moving polygon to attach to the first target edge of the fixed polygon based on the movement parameters includes: determining a first vector from a preset axis of the coordinate system of the moving polygon to the first attachment point, where the first attachment point is the vertex among the first vertices that is closest to the fixed polygon; rotating the first vector using the rotation angle so that the edge where the attachment point is located is parallel to the first target edge, and obtaining the rotated first vector; determining the coordinates of the first attachment point based on the rotated first vector and the coordinates of the preset axis on a preset plane; performing a difference operation between the coordinates of the second attachment point and the coordinates of the first attachment point to obtain a second vector, where the second attachment point is the point on the first target edge that is closest to the first attachment point; and controlling the moving polygon to attach to the first target edge of the fixed polygon based on the second vector.
[0077] The coordinate system mentioned above can be a coordinate system established in a preset plane with the moving polygon as the center, or it can be a coordinate system with the vertex of the moving polygon that is closest to the first target edge of the fixed polygon as the center, and the coordinate axes are perpendicular to each other, used to mark the position of the moving polygon.
[0078] The preset axis can be the y-axis of the coordinate system pre-defined according to requirements, or it can be the first target edge. The preset axis here can be set according to actual needs.
[0079] The first snapping point can be a point on the fixed polygon that snaps to the moving polygon, or it can be the vertex among the first vertices that has the shortest distance to the fixed polygon. The first vector can be the distance between a preset axis and the first snapping point of the moving polygon. The second snapping point can be the point on the first target edge that has the shortest distance to the first snapping point. The second vector can be the distance between the second snapping point and the first snapping point.
[0080] In one alternative embodiment, Figure 6 This is a schematic diagram of a transformation based on a preset axis of a moving polygon, according to one optional embodiment of the present invention, as shown below. Figure 6As shown, the large square can be a fixed polygon, and the small square can be a moving polygon. Controlling the moving polygon to attach to the fixed polygon according to the moving parameters can be achieved by first determining the displacement vector between the preset axis of the coordinate system of the moving polygon and the first attachment point, and then rotating the moving polygon according to the rotation angle so that the first attachment point is parallel to the first target edge. Further, the displacement vector of the moving polygon after rotation is calculated by matrix multiplication, and the displacement coordinates after rotation are obtained by adding the displacement vector after rotation to the coordinates of the preset axis of the moving polygon. The difference between the displacement coordinates of the moving polygon and the first attachment point is calculated to obtain the moving displacement between the moving polygon and the fixed polygon, and thus controlling the moving polygon to attach to the first target edge of the fixed polygon.
[0081] Optionally, the movement parameters further include: a displacement vector, which controls the moving polygon to snap to the first target edge of the fixed polygon based on the movement parameters, including: controlling the first snap point to snap to the second snap point based on the displacement vector to obtain the snapped moving polygon; and rotating the snapped moving polygon based on the rotation angle so that the moving polygon snaps to the first target edge of the fixed polygon.
[0082] In one alternative embodiment, Figure 7 This is a schematic diagram of a rotation around a first adsorption point according to one optional embodiment of the present invention, as shown below. Figure 7 As shown, the first adsorption point is first adsorbed to the second adsorption point according to the displacement vector. Then, the moving polygon is rotated according to the rotation angle between the moving polygon and the fixed polygon, and finally the image of adsorption is obtained.
[0083] Figure 8 This is a flowchart of a polygonal adsorption method according to one optional embodiment of the present invention, such as... Figure 8 As shown, the snapping function is used to traverse all fixed and moving polygons. Further, a numerical calculation function is used to calculate the first distance value from each vertex of the moving polygon to the fixed polygon and the second distance value from each vertex of the fixed polygon to the moving polygon. The target distance function determines the positional relationship between the moving and fixed polygons based on the first and second distances, obtains the corresponding target distance value based on the positional relationship, and obtains the displacement vector and rotation angle corresponding to the target distance value from the moving polygon to the fixed polygon. Due to the difference between the game rotation axis and the calculation rotation axis, which can lead to differences in displacement vectors, the snapping function corrects these differences, obtaining the final displacement vector of the moving polygon snapping to the fixed polygon. Therefore, the moving polygon is snapped to the fixed polygon based on the displacement vector and rotation angle.
[0084] in addition, Figure 9 This is a schematic diagram of a polygon before adsorption according to one optional embodiment of the present invention, such as... Figure 9 As shown, the movable polygon is the hexagonal box in the image, and the fixed polygons are the piano and stool. The circle at the bottom represents the movement control keys, the lines represent the operation directions, the checkmark on the right is the confirmation key, and the crosshair is the cancellation key. Holding down the control keys and moving the hexagonal box along the operation directions will move the hexagonal box. The hexagonal shape mapped to the ground by the hexagonal box is difficult to align with the edges and vertices of the polygons mapped to the ground by the piano and stool, making it difficult to snap the hexagonal box to the correct position. In other words, the polygon mapped to the hexagonal box on the ground is difficult to snap to the edges of the polygons mapped to the ground by the piano and stool.
[0085] It should be noted that the polygons mapped onto the ground by the hexagonal box can accurately snap to the first target edge of the polygons mapped onto the ground by the piano and the stool, indicating that the hexagonal box is placed in the correct position.
[0086] Figure 10 This is a schematic diagram of a polygon after adsorption according to one optional embodiment of the present invention, such as... Figure 10 As shown, the moving polygon is the hexagonal box in the figure, and the fixed polygons are the piano and stool in the figure. The circle at the bottom is the movement control key, the lines are the operation directions, the checkmark on the right is the confirmation key, and the cross is the cancellation key. Using the polygon adsorption method of the embodiment of the present invention, the hexagonal box can be quickly adsorbed to the correct position. That is, the polygon of the hexagonal box mapped on the ground can be quickly adsorbed onto the first target edge of the polygon of the piano and stool mapped on the ground. The first target edge is the thickest line in the figure, which achieves the purpose of improving the adsorption efficiency of the moving polygon to the fixed polygon.
[0087] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of the present invention.
[0088] This embodiment also provides an apparatus for implementing the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the terms "unit" and "module" can refer to a combination of software and / or hardware that performs a predetermined function. Although the apparatus described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0089] Figure 11 This is a structural block diagram of a polygonal adsorption device according to one embodiment of the present invention. A graphical user interface is provided via a terminal device, and the content displayed in the graphical user interface includes a touch area. As shown in the figure, the device includes:
[0090] The first determining module 1102 is used to determine a first distance value from a first vertex on a moving polygon to a first target edge on a fixed polygon, wherein the moving polygon is used to represent the mapping graphic of a moving object in the game scene on a preset plane, the fixed polygon is used to represent the mapping graphic of a fixed object in the game scene on a preset plane, and the first target edge is used to represent the edge on the fixed polygon that is shortest to the first vertex.
[0091] The second determining module 1104 is used to determine a second distance value from the second vertex on the fixed polygon to the second target edge on the moving polygon, wherein the second target edge is used to represent the edge on the moving polygon that is closest to the second vertex.
[0092] The third determining module 1106 is used to determine the positional relationship between the moving polygon and the fixed polygon based on the first distance value and the second distance value.
[0093] Control module 1108 is used to control the moving polygon to snap to the first target edge of the fixed polygon based on the positional relationship.
[0094] Optionally, the third determining module 1106 includes: a first determining unit, configured to determine the positional relationship as the fixed polygon is contained inside the moving polygon in response to a first minimum distance value being greater than a preset value and a second maximum distance value being less than a preset value; a second determining unit, configured to determine the positional relationship as the moving polygon is contained inside the fixed polygon in response to a first maximum distance value being less than a preset value and a second minimum distance value being greater than a preset value; and a third determining unit, configured to determine the positional relationship as the moving polygon is outside the fixed polygon in response to a first minimum distance value being greater than a preset value and a second minimum distance value being greater than a preset value.
[0095] Optionally, the control module 1108 includes: a fourth determining unit, used to determine a target distance value from a first maximum distance value, a first minimum distance value, a second maximum distance value, a second minimum distance value, and a preset distance value based on positional relationships; an acquiring unit, used to acquire movement parameters corresponding to the target distance value; and a control unit, used to control the moving polygon to snap to the first target edge of the fixed polygon based on the movement parameters.
[0096] Optionally, the fourth determining unit includes: a first judging subunit, configured to determine whether a first minimum distance value is less than a second maximum distance value in response to the positional relationship being that the fixed polygon is contained inside the moving polygon; a first determining subunit, configured to determine that the first minimum distance value is a target distance value in response to the first minimum distance value being less than the second maximum distance value; and a second determining subunit, configured to determine that the second maximum distance value is a target distance value in response to the first minimum distance value being greater than or equal to the second maximum distance value.
[0097] Optionally, the fourth determining unit includes: a second determining subunit, configured to determine whether a first maximum distance value is less than a second minimum distance value in response to the positional relationship being that the moving polygon is contained within the fixed polygon; a third determining subunit, configured to determine that the first maximum distance value is a target distance value in response to the first maximum distance value being less than the second minimum distance value; and a fourth determining subunit, configured to determine that the second minimum distance value is a target distance value in response to the first maximum distance value being greater than or equal to the second minimum distance value.
[0098] Optionally, the fourth determining unit includes: a third determining subunit, configured to determine whether a first minimum distance value is less than a second minimum distance value in response to the positional relationship being that the moving polygon is outside the fixed polygon; a fifth determining subunit, configured to determine that the first minimum distance value is a target distance value in response to the first minimum distance value being less than the second minimum distance value; and a sixth determining subunit, configured to determine that the second minimum distance value is a target distance value in response to the first minimum distance value being greater than or equal to the second minimum distance value.
[0099] Optionally, the fourth determining unit includes: a seventh determining subunit, used to determine a preset distance value as a target distance value in response to the positional relationship being the intersection of a moving polygon and a fixed polygon.
[0100] Optionally, the control unit includes: an eighth determining subunit, configured to determine a first vector from a preset axis of the coordinate system of the moving polygon to a first adsorption point, wherein the first adsorption point is the first vertex that is closest to the fixed polygon; a first acquiring subunit, configured to rotate the first vector using a rotation angle so that the edge where the adsorption point is located is parallel to the first target edge, and acquire the rotated first vector; a ninth determining subunit, configured to determine the coordinates of the first adsorption point based on the rotated first vector and the coordinates of the preset axis on a preset plane; a second acquiring subunit, configured to perform a difference calculation on the coordinates of the second adsorption point and the coordinates of the first adsorption point to obtain a second vector, wherein the second adsorption point is the point on the first target edge that is closest to the first adsorption point; and a control subunit, configured to control the moving polygon to adsorb onto the first target edge of the fixed polygon based on the second vector.
[0101] Optionally, the control unit further includes: a third acquisition subunit, used to control the first adsorption point to adsorb to the second adsorption point based on the displacement vector, so as to obtain the adsorbed moving polygon; and a rotation subunit, used to rotate the adsorbed moving polygon based on the rotation angle, so that the moving polygon adsorbs to the first target edge of the fixed polygon.
[0102] It should be noted that the above-mentioned units and modules can be implemented by software or hardware. For the latter, they can be implemented in the following ways, but not limited to these: all the above-mentioned units and modules are located in the same processor; or, the above-mentioned units and modules are located in different processors in any combination.
[0103] From the above description of the embodiments, those skilled in the art will readily understand that the exemplary embodiments described herein can be implemented by software or by combining software with necessary hardware. Therefore, the technical solutions according to the embodiments of the present invention can be embodied in the form of a software product, which can be stored in a computer-readable storage medium (such as a CD-ROM, USB flash drive, portable hard drive, etc.) or on a network, including several instructions to cause a computing device (such as a personal computer, server, terminal device, or network device, etc.) to execute the method according to the embodiments of the present invention.
[0104] In exemplary embodiments of this application, a computer-readable storage medium stores a program product capable of implementing the methods described above in this embodiment. In some possible implementations, various aspects of the embodiments of the present invention can also be implemented as a program product comprising program code, which, when run on a terminal device, causes the terminal device to perform the steps described in the "Exemplary Methods" section of this embodiment according to various exemplary embodiments of the present invention.
[0105] According to embodiments of the present invention, a program product for implementing the above-described method may employ a portable compact disc read-only memory (CD-ROM) and include program code, and may run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited thereto. In the embodiments of the present invention, the computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in conjunction with an instruction execution system, apparatus, or device.
[0106] The aforementioned program product may take the form of any combination of one or more computer-readable media. Such computer-readable storage media may be, for example, but not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatuses, or devices, or any combination thereof. More specific examples (not exhaustive) of computer-readable storage media include: electrical connections having one or more wires, portable disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0107] It should be noted that the program code contained on the computer-readable storage medium can be transmitted using any suitable medium, including but not limited to wireless, wired, optical fiber, RF, etc., or any suitable combination thereof.
[0108] Embodiments of the present invention also provide an electronic device including a memory and a processor, the memory storing a computer program and the processor being configured to run the computer program to perform the steps in any of the above method embodiments.
[0109] In the electronic device of this embodiment, a technical solution for polygon snapping is provided. A first distance value is determined from a first vertex of the moving polygon to a first target edge of the fixed polygon, and a second distance value is determined from a second vertex of the fixed polygon to a second target edge of the moving polygon. Based on the first and second distance values, the positional relationship between the moving and fixed polygons is determined, and further, the moving polygon is controlled to snap to the first target edge of the fixed polygon based on this positional relationship. It is important to note that determining the positional relationship between the moving and fixed polygons based on the first and second distance values, and then controlling the moving polygon to snap to the fixed polygon based on this positional relationship, allows the moving polygon to snap to the fixed polygon quickly. This reduces the difficulty of snapping and improves the snapping efficiency, thus solving the technical problem of quickly snapping a moving polygon to a fixed polygon, and consequently addressing the difficulty of snapping a moving polygon to a fixed polygon in game scenes.
[0110] Figure 12 This is a schematic diagram of an electronic device according to an embodiment of the present invention. Figure 12 As shown, the electronic device 1200 is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of the present invention.
[0111] like Figure 12As shown, the electronic device 1200 is presented in the form of a general-purpose computing device. The components of the electronic device 1200 may include, but are not limited to: at least one processor 1210, at least one memory 1220, a bus 1230 connecting different system components (including memory 1220 and processor 1210), and a display 1240.
[0112] The memory 1220 stores program code that can be executed by the processor 1210, causing the processor 1210 to perform the steps described in the method section of the embodiments of this application according to various exemplary implementations of the present invention.
[0113] The memory 1220 may include a readable medium in the form of volatile memory cells, such as random access memory (RAM) 12201 and / or cache memory 12202, and may further include read-only memory (ROM) 12203, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory.
[0114] In some instances, memory 1220 may also include programs / utilities 12204 having a set (at least one) of program modules 12205, including but not limited to: an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. Memory 1220 may further include memory remotely located relative to processor 1210, which can be connected to electronic device 1200 via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0115] Bus 1230 can represent one or more of several types of bus structures, including a memory cell bus or memory cell controller, peripheral bus, graphics acceleration port, processor 1210, or a local bus using any of the various bus structures.
[0116] The display 1240 may be, for example, a touch screen liquid crystal display (LCD) that allows a user to interact with the user interface of the electronic device 1200.
[0117] Optionally, the electronic device 1200 can also communicate with one or more external devices 1200 (e.g., keyboard, pointing device, Bluetooth device, etc.), one or more devices that enable a user to interact with the electronic device 1200, and / or any device that enables the electronic device 1200 to communicate with one or more other computing devices (e.g., router, modem, etc.). This communication can be performed via the input / output (I / O) interface 1250. Furthermore, the electronic device 1200 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via the network adapter 1260. Figure 12 As shown, network adapter 1260 communicates with other modules of electronic device 1200 via bus 1230. It should be understood that, although... Figure 12 As not shown, other hardware and / or software modules may be used in conjunction with electronic device 1200, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.
[0118] The aforementioned electronic device 1200 may further include: a keyboard, a cursor control device (such as a mouse), an input / output interface (I / O interface), a network interface, a power supply, and / or a camera.
[0119] Those skilled in the art will understand that Figure 12 The structure shown is for illustrative purposes only and does not limit the structure of the electronic device described above. For example, the electronic device 1200 may also include components that are more... Figure 12 The more or fewer components shown, or having the same Figure 1 Different configurations are shown. The memory 1220 can be used to store computer programs and corresponding data, such as the computer program and corresponding data corresponding to the polygon adsorption method in this embodiment of the invention. The processor 1210 executes various functional applications and data processing by running the computer program stored in the memory 1220, thereby realizing the aforementioned polygon adsorption method.
[0120] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0121] In the above embodiments of the present invention, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0122] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units can be a logical functional division, and in actual implementation, there may be other division methods. For instance, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.
[0123] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0124] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0125] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0126] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A polygonal adsorption method, characterized in that, include: Determine a first distance value from a first vertex on a moving polygon to a first target edge on a fixed polygon, wherein the moving polygon represents a mapping of a moving object in the game scene on a preset plane, the fixed polygon represents a mapping of a fixed object in the game scene on the preset plane, and the first target edge represents the edge on the fixed polygon that is closest to the first vertex. Determine a second distance value from a second vertex on the fixed polygon to a second target edge on the moving polygon, wherein the second target edge represents the edge on the moving polygon that is closest to the second vertex; The positional relationship between the moving polygon and the fixed polygon is determined based on the first distance value and the second distance value; Based on the positional relationship, the moving polygon is controlled to snap to the first target edge of the fixed polygon.
2. The method according to claim 1, characterized in that, The first distance value includes: a first minimum distance value and a first maximum distance value; the second distance value includes: a second minimum distance value and a second maximum distance value; determining the positional relationship between the moving polygon and the fixed polygon based on the first distance value and the second distance value includes: In response to the first minimum distance value being greater than a preset value and the second maximum distance value being less than the preset value, the positional relationship is determined to be that the fixed polygon is contained within the moving polygon; In response to the first maximum distance value being less than the preset value and the second minimum distance value being greater than the preset value, the positional relationship is determined to be that the moving polygon is contained within the fixed polygon; In response to the first minimum distance value being greater than the preset value and the second minimum distance value being greater than the preset value, the positional relationship is determined to be that the moving polygon is outside the fixed polygon.
3. The method according to claim 2, characterized in that, Controlling the moving polygon to snap to the first target edge of the fixed polygon based on the positional relationship includes: The target distance value is determined from the first maximum distance value, the first minimum distance value, the second maximum distance value, the second minimum distance value, and the preset distance value based on the positional relationship. Obtain the movement parameters corresponding to the target distance value; Based on the movement parameters, the moving polygon is controlled to snap to the first target edge of the fixed polygon.
4. The method according to claim 3, characterized in that, Determining the target distance value from the first maximum distance value, the first minimum distance value, the second maximum distance value, and the second minimum distance value based on the positional relationship includes: In response to the positional relationship that the fixed polygon is contained within the moving polygon, it is determined whether the first minimum distance value is less than the second maximum distance value; In response to the first minimum distance value being less than the second maximum distance value, the first minimum distance value is determined to be the target distance value; In response to the first minimum distance value being greater than or equal to the second maximum distance value, the second maximum distance value is determined to be the target distance value.
5. The method according to claim 3, characterized in that, Determining the target distance value from the first maximum distance value, the first minimum distance value, the second maximum distance value, and the second minimum distance value based on the positional relationship includes: In response to the positional relationship that the moving polygon is contained within the fixed polygon, it is determined whether the first maximum distance value is less than the second minimum distance value; In response to the first maximum distance value being less than the second minimum distance value, the first maximum distance value is determined to be the target distance value; In response to the first maximum distance value being greater than or equal to the second minimum distance value, the second minimum distance value is determined to be the target distance value.
6. The method according to claim 3, characterized in that, Determining the target distance value from the first maximum distance value, the first minimum distance value, the second maximum distance value, the second minimum distance value, and the preset distance value based on the positional relationship includes: In response to the positional relationship that the moving polygon is outside the fixed polygon, it is determined whether the first minimum distance value is less than the second minimum distance value; In response to the first minimum distance value being less than the second minimum distance value, the first minimum distance value is determined to be the target distance value; In response to the first minimum distance value being greater than or equal to the second minimum distance value, the second minimum distance value is determined to be the target distance value.
7. The method according to claim 3, characterized in that, Determining the target distance value from the first maximum distance value, the first minimum distance value, the second maximum distance value, the second minimum distance value, and the preset distance value based on the positional relationship includes: In response to the positional relationship being that the moving polygon intersects with the fixed polygon, the preset distance value is determined to be the target distance value.
8. The method according to claim 3, characterized in that, The movement parameters include: rotation angle. Based on the movement parameters, controlling the moving polygon to snap to the first target edge of the fixed polygon includes: Determine a first vector from a preset axis of the coordinate system where the moving polygon is located to the first snap point, wherein the first snap point is the vertex among the first vertices that is closest to the fixed polygon; The first vector is rotated using a rotation angle so that the edge where the first adsorption point is located is parallel to the edge of the first target, and the rotated first vector is obtained. The coordinates of the first adsorption point are determined based on the first rotated vector and the coordinates of the preset axis on the preset plane. The second vector is obtained by performing a difference operation on the coordinates of the second adsorption point and the coordinates of the first adsorption point, wherein the second adsorption point is the point on the first target edge that is closest to the first adsorption point; Based on the second vector, the moving polygon is controlled to snap to the first target edge of the fixed polygon.
9. The method according to claim 8, characterized in that, The movement parameters further include: a displacement vector, which controls the moving polygon to snap to the first target edge of the fixed polygon based on the movement parameters, including: Based on the displacement vector, the first adsorption point is controlled to adsorb to the second adsorption point, resulting in a moving polygon after adsorption. The moving polygon after being attracted is rotated based on the rotation angle, so that the moving polygon is attracted to the first target edge of the fixed polygon.
10. A polygonal adsorption device, characterized in that, include: The first determining module is used to determine a first distance value from a first vertex on a moving polygon to a first target edge on a fixed polygon, wherein the moving polygon is used to represent a mapping graphic of a moving object in the game scene on a preset plane, the fixed polygon is used to represent a mapping graphic of a fixed object in the game scene on the preset plane, and the first target edge is used to represent the edge on the fixed polygon that is closest to the first vertex. The second determining module is used to determine a second distance value from a second vertex on the fixed polygon to a second target edge on the moving polygon, wherein the second target edge is used to represent the edge on the fixed polygon that is closest to the second vertex; The third determining module is used to determine the positional relationship between the moving polygon and the fixed polygon based on the first distance value and the second distance value; A control module is used to control the moving polygon to snap to the first target edge of the fixed polygon based on the positional relationship.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, wherein the computer program is configured to execute the polygon adsorption method according to any one of claims 1 to 9 when run by a processor.
12. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to run the computer program to perform the polygon adsorption method according to any one of claims 1 to 9.
Citation Information
Patent Citations
Map welting method, terminal device and storage medium
CN110704561A
Graph operation method and device, computer equipment and medium thereof
CN116107474A