|
1 | 1 | /******************************************************************************* |
2 | 2 | * Copyright 2014 See AUTHORS file. |
3 | | - * |
| 3 | + * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
6 | 6 | * You may obtain a copy of the License at |
7 | | - * |
| 7 | + * |
8 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | | - * |
| 9 | + * |
10 | 10 | * Unless required by applicable law or agreed to in writing, software |
11 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
16 | 16 |
|
17 | 17 | package com.jzy.ai.fma.patterns; |
18 | 18 |
|
19 | | -import com.game.ai.fma.FormationPattern; |
20 | | -import com.game.ai.util.Location; |
21 | | -import com.game.engine.math.MathUtils; |
22 | | -import com.game.engine.math.Vector; |
| 19 | + |
| 20 | +import com.jzy.ai.fma.FormationPattern; |
| 21 | +import com.jzy.ai.util.Location; |
| 22 | +import com.jzy.javalib.base.util.MathUtil; |
| 23 | +import com.jzy.javalib.math.geometry.Vector; |
23 | 24 |
|
24 | 25 | /** |
25 | 26 | * 防御圈阵型<br> |
26 | 27 | * The defensive circle posts members around the circumference of a circle, so their backs are to the center of the circle. The |
27 | 28 | * circle can consist of any number of members. Although a huge number of members might look silly, this implementation doesn't |
28 | 29 | * put any fixed limit. |
29 | | - * |
| 30 | + * |
30 | 31 | * @param <T> Type of vector, either 2D or 3D, implementing the {@link Vector} interface |
31 | | - * |
32 | | - * @author davebaol */ |
| 32 | + * @author davebaol |
| 33 | + */ |
33 | 34 | public class DefensiveCircleFormationPattern<T extends Vector<T>> implements FormationPattern<T> { |
34 | | - /** The number of slots currently in the pattern. */ |
35 | | - int numberOfSlots; |
| 35 | + /** |
| 36 | + * The number of slots currently in the pattern. |
| 37 | + */ |
| 38 | + int numberOfSlots; |
36 | 39 |
|
37 | | - /** The radius of one member. This is needed to determine how close we can pack a given number of members around circle. */ |
38 | | - float memberRadius; |
| 40 | + /** |
| 41 | + * The radius of one member. This is needed to determine how close we can pack a given number of members around circle. |
| 42 | + */ |
| 43 | + float memberRadius; |
39 | 44 |
|
40 | | - /** Creates a {@code DefensiveCircleFormationPattern} |
41 | | - * @param memberRadius */ |
42 | | - public DefensiveCircleFormationPattern (float memberRadius) { |
43 | | - this.memberRadius = memberRadius; |
44 | | - } |
| 45 | + /** |
| 46 | + * Creates a {@code DefensiveCircleFormationPattern} |
| 47 | + * |
| 48 | + * @param memberRadius |
| 49 | + */ |
| 50 | + public DefensiveCircleFormationPattern(float memberRadius) { |
| 51 | + this.memberRadius = memberRadius; |
| 52 | + } |
45 | 53 |
|
46 | | - @Override |
47 | | - public void setNumberOfSlots (int numberOfSlots) { |
48 | | - this.numberOfSlots = numberOfSlots; |
49 | | - } |
| 54 | + @Override |
| 55 | + public void setNumberOfSlots(int numberOfSlots) { |
| 56 | + this.numberOfSlots = numberOfSlots; |
| 57 | + } |
50 | 58 |
|
51 | | - @Override |
52 | | - public Location<T> calculateSlotLocation (Location<T> outLocation, int slotNumber) { |
53 | | - if (numberOfSlots > 1) { |
54 | | - // Place the slot around the circle based on its slot number |
55 | | - float angleAroundCircle = (MathUtils.PI2 * slotNumber) / numberOfSlots; |
| 59 | + @Override |
| 60 | + public Location<T> calculateSlotLocation(Location<T> outLocation, int slotNumber) { |
| 61 | + if (numberOfSlots > 1) { |
| 62 | + // Place the slot around the circle based on its slot number |
| 63 | + float angleAroundCircle = (MathUtil.PI2 * slotNumber) / numberOfSlots; |
56 | 64 |
|
57 | | - // The radius depends on the radius of the member, |
58 | | - // and the number of members in the circle: |
59 | | - // we want there to be no gap between member's shoulders. |
60 | | - float radius = memberRadius / (float)Math.sin(Math.PI / numberOfSlots); |
| 65 | + // The radius depends on the radius of the member, |
| 66 | + // and the number of members in the circle: |
| 67 | + // we want there to be no gap between member's shoulders. |
| 68 | + float radius = memberRadius / (float) Math.sin(Math.PI / numberOfSlots); |
61 | 69 |
|
62 | | - // Fill location components based on the angle around circle. |
63 | | - outLocation.angleToVector(outLocation.getPosition(), angleAroundCircle).scl(radius); |
| 70 | + // Fill location components based on the angle around circle. |
| 71 | + outLocation.angleToVector(outLocation.getPosition(), angleAroundCircle).scl(radius); |
64 | 72 |
|
65 | | - // The members should be facing out |
66 | | - outLocation.setOrientation(angleAroundCircle); |
67 | | - } |
68 | | - else { |
69 | | - outLocation.getPosition().setZero(); |
70 | | - outLocation.setOrientation(MathUtils.PI2 * slotNumber); |
71 | | - } |
| 73 | + // The members should be facing out |
| 74 | + outLocation.setOrientation(angleAroundCircle); |
| 75 | + } else { |
| 76 | + outLocation.getPosition().setZero(); |
| 77 | + outLocation.setOrientation(MathUtil.PI2 * slotNumber); |
| 78 | + } |
72 | 79 |
|
73 | | - // Return the slot location |
74 | | - return outLocation; |
75 | | - } |
| 80 | + // Return the slot location |
| 81 | + return outLocation; |
| 82 | + } |
76 | 83 |
|
77 | | - @Override |
78 | | - public boolean supportsSlots (int slotCount) { |
79 | | - // In this case we support any number of slots. |
80 | | - return true; |
81 | | - } |
| 84 | + @Override |
| 85 | + public boolean supportsSlots(int slotCount) { |
| 86 | + // In this case we support any number of slots. |
| 87 | + return true; |
| 88 | + } |
82 | 89 |
|
83 | 90 | } |
0 commit comments