View Javadoc

1   package cz.cuni.amis.pogamut.ut2004.utils;
2   
3   import javax.vecmath.Point3d;
4   import javax.vecmath.Vector3d;
5   
6   import cz.cuni.amis.pogamut.base3d.worldview.object.Velocity;
7   import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
8   import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.Jump;
9   
10  /**
11   * Class with utility methods for converting to Unreal units plus some handy constants.<p>
12   * Measures are in Unreal Engine native units called Unreal units (UU).
13   * @author ik
14   */
15  public class UnrealUtils {
16  
17  	public static final int iNT_NONE = Integer.MAX_VALUE;
18  	
19  	public static final long lONG_NONE = Long.MAX_VALUE;
20  	
21  	public static final float fLOAT_NONE = Float.MAX_VALUE;
22  	
23  	public static final double dOUBLE_NONE = Double.MAX_VALUE;
24  	
25  	public static final Integer INT_NONE = Integer.MAX_VALUE;
26  	
27  	public static final Long LONG_NONE = Long.MAX_VALUE;
28  	
29  	public static final Float FLOAT_NONE = Float.MAX_VALUE;
30  	
31  	public static final Double DOUBLE_NONE = Double.MAX_VALUE;
32  	
33  	public static final String STRING_NONE = "@@NONE@@";
34  	
35  	public static final Point3d POINT3D_NONE = new Point3d(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE);
36  	
37  	public static final Vector3d VECTOR3D_NONE = new Vector3d(Double.MAX_VALUE, Double.MAX_VALUE, Double.MAX_VALUE);
38  	
39      /**
40       * Radius in UU of the bounding cylinder used for collision detection.
41       */
42      public static final double CHARACTER_COLLISION_RADIUS = 25;
43      /**
44       * Height in UU of the bounding cylinder used for collision detection.
45       */
46      public static final double CHARACTER_COLLISION_HEIGHT = 44;
47      /**
48       * Height in UU of the bot when stading.
49       */
50      public static final double CHARACTER_HEIGHT_STANDING = 96;
51      /**
52       * Height in UU of the bot when crouching.
53       */
54      public static final double CHARACTER_HEIGHT_CROUCHING = 64;
55      /**
56       * Speed of the bot while running.
57       * TODO: fill after the reception of INIT message.
58       * @deprecated you should not use this as it is not reliable in multi-bot scenario
59       */
60      public static Velocity CHARACTER_RUN_SPEED;
61      /**
62       * Speed of the bot while walking.
63       * TODO: fill after the reception of INIT message.
64       * @deprecated you should not use this as it is not reliable in multi-bot scenario
65       */
66      public static Velocity CHARACTER_WALK_SPEED;
67      /**
68       * Center of gravity - distance from the floor in UU.
69       * TODO: estimate
70       */
71      public static final double BOT_CENTER_OF_GRAVITY_HEIGHT = 50;
72      /**
73       * NavPoint distance from the floor.
74       * TODO: estimate
75       */
76      public static final double NAV_POINT_HEIGHT = 10;
77  
78      public static final double FULL_ANGLE_IN_UNREAL_DEGREES = 65536;
79      
80      public static final double ONE_DEGREE_IN_UNREAL_DEGREES = ((double)FULL_ANGLE_IN_UNREAL_DEGREES) / ((double)360);
81      
82      public static final double ONE_RAD_IN_UNREAL_DEGREES = ((double)FULL_ANGLE_IN_UNREAL_DEGREES) / ((double)2*Math.PI);
83      
84      public static final double ONE_UNREAL_DEGREE_IN_DEGREES = ((double)360) / ((double)FULL_ANGLE_IN_UNREAL_DEGREES);
85      
86      public static final double ONE_UNREAD_DEGREE_IN_RAD = ((double)2*Math.PI) / ((double)FULL_ANGLE_IN_UNREAL_DEGREES);
87      
88      /**
89       * @deprecated use {@link UnrealUtils#ONE_UNREAD_DEGREE_IN_RAD}
90       */
91      public static final double UT_ANGLE_TO_RAD = 2*Math.PI / ((double)FULL_ANGLE_IN_UNREAL_DEGREES);
92  
93      /**
94       * @deprecated use {@link UnrealUtils#ONE_DEGREE_IN_UNREAL_DEGREES}
95       */
96      public static final double DEG_TO_UT_ANGLE = ((double)FULL_ANGLE_IN_UNREAL_DEGREES) / ((double)360);
97  
98      /**
99       * @deprecated 
100      */
101     public static final double UT_ANGLE_TO_DEG =  FULL_ANGLE_IN_UNREAL_DEGREES * 360;
102     
103     /**
104      * @deprecated use {@link UnrealUtils#ONE_RAD_IN_UNREAL_DEGREES}
105      */
106     public static final double RAD_TO_UT_ANGLE =  ((double)FULL_ANGLE_IN_UNREAL_DEGREES) / (2 * Math.PI);
107     
108     /**
109      * UT2004 time is running 110% of normal time. I.e., when 1 sec pass according to {@link System#currentTimeMillis()} than 1.1 secs pass according
110      * to UT2004.
111      */
112     public static final double UT2004_TIME_SPEED = 1.1;
113     
114     /**
115      * Force to be applied to {@link Jump#setForce(Double)} if full jump is needed.
116      * <p><p>
117      * Note that you actually do not need to set this value directly as GB2004 always assumes you want to do full jump. 
118      */
119     public static final int FULL_JUMP_FORCE = 340;
120     
121     /**
122      * Force to be applied to {@link Jump#setForce(Double)} if full double jump is needed.
123      * <p><p>
124      * Note that you actually do not need to set this value directly as GB2004 always assumes you want to do full double jump.
125      * We raised this value by 50 (was 705) in GameBots of Pogamut 3.3.1 because of problems of accessing spots 
126      * on the verge of reachability with double jump. 
127      */
128     public static final int FULL_DOUBLEJUMP_FORCE = 755;
129     
130     /**
131      * Delay to be made between two jumps in double jumping ({@link Jump#setDelay(Double)}) if full double jump is needed.
132      * <p><p>
133      * Note that you actually do not need to set this value directly as GB2004 always assumes you want to do full double jump.
134      * <p><p>
135      * In seconds. 
136      */
137     public static final double FULL_DOUBLEJUMP_DELAY = 0.39;
138     
139     /**
140      * Standard max. velocity of bots (it's actually almost 440 but it is better to have this number lower as you will check whether
141      * you're running at max speed with it...).
142      */
143     public static final double MAX_VELOCITY = 439.5;
144     
145     /**
146      * Converts angle in degrees (0-360) to Unreal units used for angles (0 - 65536).
147      * @param degrees Angle in degrees
148      * @return corresponding angle in Unreal units
149      */
150     public static int degreeToUnrealDegrees(double degrees) {
151         return (int)Math.round((degrees * (double)ONE_DEGREE_IN_UNREAL_DEGREES));
152     }
153 
154     /**
155      * Converts Unreal degrees (0-65536) to normal degrees (0 - 360).
156      * @param unrealDegrees
157      * @return
158      */
159     public static double unrealDegreeToDegree(int unrealDegrees) {
160         return ((double)unrealDegrees) * ((double)ONE_UNREAL_DEGREE_IN_DEGREES);
161     }
162 
163     /**
164      * Converts Unreal degrees (0-65536) to radians (0 - 2*PI)
165      * @param unrealDegrees
166      * @return
167      */
168     public static double unrealDegreeToRad(double unrealDegrees) {
169         return ((double)unrealDegrees) * ((double)ONE_UNREAD_DEGREE_IN_RAD);
170     }
171 
172     /**
173      * Tells whether UnrealId belongs to POGAMUT-CONTROLLED-BOT.
174      * @param botId
175      * @return
176      */
177     public static boolean isBotId(UnrealId id) {
178     	return id.getStringId().contains("RemoteBot");
179     }
180     
181 }