├── COPYING
├── GlTron
├── .gitignore
├── AndroidManifest.xml
├── lint.xml
├── proguard.cfg
├── project.properties
├── res
│ ├── drawable-hdpi
│ │ ├── gltron_bitmap.png
│ │ ├── gltron_floor.png
│ │ ├── gltron_impact.png
│ │ ├── gltron_trail.png
│ │ ├── gltron_traildecal.png
│ │ ├── gltron_wall_1.png
│ │ ├── gltron_wall_2.png
│ │ ├── gltron_wall_3.png
│ │ ├── gltron_wall_4.png
│ │ ├── icon.png
│ │ ├── skybox0.png
│ │ ├── skybox1.png
│ │ ├── skybox2.png
│ │ ├── skybox3.png
│ │ ├── skybox4.png
│ │ ├── skybox5.png
│ │ ├── xenotron0.png
│ │ └── xenotron1.png
│ ├── drawable-ldpi
│ │ └── icon.png
│ ├── drawable-mdpi
│ │ └── icon.png
│ ├── layout
│ │ ├── main.xml
│ │ └── preferences.xml
│ ├── raw
│ │ ├── game_crash.ogg
│ │ ├── game_engine.ogg
│ │ ├── game_recognizer.ogg
│ │ ├── lightcycle.mtl
│ │ ├── lightcyclehigh.obj
│ │ ├── recognizer.mtl
│ │ ├── recognizerhigh.obj
│ │ └── song_revenge_of_cats.ogg
│ └── values
│ │ ├── array.xml
│ │ └── strings.xml
└── src
│ └── com
│ └── glTron
│ ├── Game
│ ├── Camera.java
│ ├── ComputerAI.java
│ ├── GLTronGame.java
│ ├── Player.java
│ ├── Recognizer.java
│ └── UserPrefs.java
│ ├── OpenGLRenderer.java
│ ├── OpenGLView.java
│ ├── Preferences.java
│ ├── Sound
│ └── SoundManager.java
│ ├── Video
│ ├── Explosion.java
│ ├── Font.java
│ ├── GLTexture.java
│ ├── GraphicUtils.java
│ ├── HUD.java
│ ├── Lighting.java
│ ├── Material.java
│ ├── Model.java
│ ├── Segment.java
│ ├── TrailMesh.java
│ ├── Trails_Renderer.java
│ ├── Vec.java
│ ├── Video.java
│ └── WorldGraphics.java
│ └── glTron.java
├── README
└── RELEASE_NOTES.txt
/GlTron/.gitignore:
--------------------------------------------------------------------------------
1 | local.properties
2 | bin/
3 | gen/
4 | libs/
5 | obj/
6 | .classpath
7 | .project
8 | .settings/
9 |
--------------------------------------------------------------------------------
/GlTron/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/GlTron/lint.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/GlTron/proguard.cfg:
--------------------------------------------------------------------------------
1 | -optimizationpasses 5
2 | -dontusemixedcaseclassnames
3 | -dontskipnonpubliclibraryclasses
4 | -dontpreverify
5 | -verbose
6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
7 |
8 | -keep public class * extends android.app.Activity
9 | -keep public class * extends android.app.Application
10 | -keep public class * extends android.app.Service
11 | -keep public class * extends android.content.BroadcastReceiver
12 | -keep public class * extends android.content.ContentProvider
13 | -keep public class * extends android.app.backup.BackupAgentHelper
14 | -keep public class * extends android.preference.Preference
15 | -keep public class com.android.vending.licensing.ILicensingService
16 |
17 | -keepclasseswithmembernames class * {
18 | native ;
19 | }
20 |
21 | -keepclasseswithmembernames class * {
22 | public (android.content.Context, android.util.AttributeSet);
23 | }
24 |
25 | -keepclasseswithmembernames class * {
26 | public (android.content.Context, android.util.AttributeSet, int);
27 | }
28 |
29 | -keepclassmembers enum * {
30 | public static **[] values();
31 | public static ** valueOf(java.lang.String);
32 | }
33 |
34 | -keep class * implements android.os.Parcelable {
35 | public static final android.os.Parcelable$Creator *;
36 | }
37 |
--------------------------------------------------------------------------------
/GlTron/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system use,
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 |
10 | # Project target.
11 | target=android-8
12 |
--------------------------------------------------------------------------------
/GlTron/res/drawable-hdpi/gltron_bitmap.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chluverman/android-gltron/69c8a230d0190a4978827b85ebaa04a04c70890e/GlTron/res/drawable-hdpi/gltron_bitmap.png
--------------------------------------------------------------------------------
/GlTron/res/drawable-hdpi/gltron_floor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chluverman/android-gltron/69c8a230d0190a4978827b85ebaa04a04c70890e/GlTron/res/drawable-hdpi/gltron_floor.png
--------------------------------------------------------------------------------
/GlTron/res/drawable-hdpi/gltron_impact.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chluverman/android-gltron/69c8a230d0190a4978827b85ebaa04a04c70890e/GlTron/res/drawable-hdpi/gltron_impact.png
--------------------------------------------------------------------------------
/GlTron/res/drawable-hdpi/gltron_trail.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chluverman/android-gltron/69c8a230d0190a4978827b85ebaa04a04c70890e/GlTron/res/drawable-hdpi/gltron_trail.png
--------------------------------------------------------------------------------
/GlTron/res/drawable-hdpi/gltron_traildecal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chluverman/android-gltron/69c8a230d0190a4978827b85ebaa04a04c70890e/GlTron/res/drawable-hdpi/gltron_traildecal.png
--------------------------------------------------------------------------------
/GlTron/res/drawable-hdpi/gltron_wall_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chluverman/android-gltron/69c8a230d0190a4978827b85ebaa04a04c70890e/GlTron/res/drawable-hdpi/gltron_wall_1.png
--------------------------------------------------------------------------------
/GlTron/res/drawable-hdpi/gltron_wall_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chluverman/android-gltron/69c8a230d0190a4978827b85ebaa04a04c70890e/GlTron/res/drawable-hdpi/gltron_wall_2.png
--------------------------------------------------------------------------------
/GlTron/res/drawable-hdpi/gltron_wall_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chluverman/android-gltron/69c8a230d0190a4978827b85ebaa04a04c70890e/GlTron/res/drawable-hdpi/gltron_wall_3.png
--------------------------------------------------------------------------------
/GlTron/res/drawable-hdpi/gltron_wall_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chluverman/android-gltron/69c8a230d0190a4978827b85ebaa04a04c70890e/GlTron/res/drawable-hdpi/gltron_wall_4.png
--------------------------------------------------------------------------------
/GlTron/res/drawable-hdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chluverman/android-gltron/69c8a230d0190a4978827b85ebaa04a04c70890e/GlTron/res/drawable-hdpi/icon.png
--------------------------------------------------------------------------------
/GlTron/res/drawable-hdpi/skybox0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chluverman/android-gltron/69c8a230d0190a4978827b85ebaa04a04c70890e/GlTron/res/drawable-hdpi/skybox0.png
--------------------------------------------------------------------------------
/GlTron/res/drawable-hdpi/skybox1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chluverman/android-gltron/69c8a230d0190a4978827b85ebaa04a04c70890e/GlTron/res/drawable-hdpi/skybox1.png
--------------------------------------------------------------------------------
/GlTron/res/drawable-hdpi/skybox2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chluverman/android-gltron/69c8a230d0190a4978827b85ebaa04a04c70890e/GlTron/res/drawable-hdpi/skybox2.png
--------------------------------------------------------------------------------
/GlTron/res/drawable-hdpi/skybox3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chluverman/android-gltron/69c8a230d0190a4978827b85ebaa04a04c70890e/GlTron/res/drawable-hdpi/skybox3.png
--------------------------------------------------------------------------------
/GlTron/res/drawable-hdpi/skybox4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chluverman/android-gltron/69c8a230d0190a4978827b85ebaa04a04c70890e/GlTron/res/drawable-hdpi/skybox4.png
--------------------------------------------------------------------------------
/GlTron/res/drawable-hdpi/skybox5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chluverman/android-gltron/69c8a230d0190a4978827b85ebaa04a04c70890e/GlTron/res/drawable-hdpi/skybox5.png
--------------------------------------------------------------------------------
/GlTron/res/drawable-hdpi/xenotron0.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chluverman/android-gltron/69c8a230d0190a4978827b85ebaa04a04c70890e/GlTron/res/drawable-hdpi/xenotron0.png
--------------------------------------------------------------------------------
/GlTron/res/drawable-hdpi/xenotron1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chluverman/android-gltron/69c8a230d0190a4978827b85ebaa04a04c70890e/GlTron/res/drawable-hdpi/xenotron1.png
--------------------------------------------------------------------------------
/GlTron/res/drawable-ldpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chluverman/android-gltron/69c8a230d0190a4978827b85ebaa04a04c70890e/GlTron/res/drawable-ldpi/icon.png
--------------------------------------------------------------------------------
/GlTron/res/drawable-mdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chluverman/android-gltron/69c8a230d0190a4978827b85ebaa04a04c70890e/GlTron/res/drawable-mdpi/icon.png
--------------------------------------------------------------------------------
/GlTron/res/layout/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
12 |
--------------------------------------------------------------------------------
/GlTron/res/layout/preferences.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
9 |
10 |
16 |
17 |
18 |
19 |
22 |
23 |
27 |
28 |
32 |
33 |
34 |
35 |
36 |
37 |
40 |
41 |
42 |
46 |
47 |
53 |
54 |
55 |
58 |
59 |
65 |
66 |
67 |
73 |
74 |
80 |
81 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/GlTron/res/raw/game_crash.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chluverman/android-gltron/69c8a230d0190a4978827b85ebaa04a04c70890e/GlTron/res/raw/game_crash.ogg
--------------------------------------------------------------------------------
/GlTron/res/raw/game_engine.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chluverman/android-gltron/69c8a230d0190a4978827b85ebaa04a04c70890e/GlTron/res/raw/game_engine.ogg
--------------------------------------------------------------------------------
/GlTron/res/raw/game_recognizer.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chluverman/android-gltron/69c8a230d0190a4978827b85ebaa04a04c70890e/GlTron/res/raw/game_recognizer.ogg
--------------------------------------------------------------------------------
/GlTron/res/raw/lightcycle.mtl:
--------------------------------------------------------------------------------
1 | newmtl Hull
2 | Ka 0.0813 0.0813 0.0813
3 | Kd 0.7813 0.7813 0.7813
4 | Ks 0.6813 0.6813 0.6813
5 | Ns 5.0000
6 | Ni 1.0000
7 | illum 2
8 |
9 | newmtl Window
10 | Ka 0.0000 0.0000 0.0000
11 | Kd 0.0000 0.0000 0.0000
12 | Ks 1.0 1.0 1.0
13 | Ns 30.0000
14 | Ni 1.0000
15 | illum 2
16 |
17 | newmtl Rim
18 | Ka 0.0000 0.0000 0.0000
19 | Kd 0.0000 0.0000 0.0000
20 | Ks 0.0 0.0 0.0
21 | Ns 0.0000
22 | Ni 1.0000
23 | illum 2
24 |
25 | newmtl Spoke
26 | Ka 0.0 0.0 0.0
27 | Kd 0.0 0.0 0.0
28 | Ks 0.0 0.0 0.0
29 | Ns 30.0
30 | Ni 1.0
31 | illum 20
32 |
33 | newmtl Chassis
34 | Ka 0.2000 0.2000 0.2000
35 | Kd 0.5000 0.5000 0.5000
36 | Ks 0.3000 0.3000 0.3000
37 | Ns 3.0000
38 | Ni 1.0000
39 | illum 2
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/GlTron/res/raw/recognizer.mtl:
--------------------------------------------------------------------------------
1 | #
2 | # Wavefront material file
3 | # Converted by 3D Exploration 1.3.00 BETA
4 | # XDimension Software
5 | # http://www.xdsoft.com/explorer/
6 | #
7 | newmtl Hull
8 | Ka 0.2 0.290196 0.215686
9 | Kd 0.14902 0.458824 0.164706
10 | Ks 0.898039 0.898039 0.898039
11 | illum 0
12 |
--------------------------------------------------------------------------------
/GlTron/res/raw/recognizerhigh.obj:
--------------------------------------------------------------------------------
1 | #
2 | # Wavefront OBJ file
3 | # Converted by the 3D Exploration 1.7
4 | # XDimension Software, LLC
5 | # http://www.xdsoft.com/explorer/
6 | #
7 | # object Middle Bar
8 | mtllib recognizer.mtl
9 | g Middle_Bar
10 | v -140.483 5 32.6104
11 | v 139.517 5 32.6104
12 | v -140.483 5 42.6104
13 | v 139.517 5 42.6104
14 | v -140.483 -52.488 32.6104
15 | v 139.517 -52.488 32.6104
16 | v -140.483 -55 42.6104
17 | v 139.517 -55 42.6104
18 | # 8 verticies
19 | vn 0 1 9.53674e-08
20 | vn 0 -0.969869 -0.243628
21 | vn 0 0 -1
22 | vn 1 0 0
23 | vn 0 -6.35783e-08 1
24 | vn -1 0 0
25 | # 6 normals
26 | usemtl Hull
27 | f 1//1 3//1 4//1
28 | f 4//1 2//1 1//1
29 | f 5//2 6//2 8//2
30 | f 8//2 7//2 5//2
31 | f 1//3 2//3 6//3
32 | f 6//3 5//3 1//3
33 | f 2//4 4//4 8//4
34 | f 8//4 6//4 2//4
35 | f 4//5 3//5 7//5
36 | f 7//5 8//5 4//5
37 | f 3//6 1//6 5//6
38 | f 5//6 7//6 3//6
39 | # object Shoulder01
40 | g Shoulder01
41 | v -150.491 5 90.6522
42 | v -10.4913 5 90.6522
43 | v -150.491 5 100.652
44 | v -10.4913 5 100.652
45 | v -150.491 -55 90.6522
46 | v -10.4913 -55 90.6522
47 | v -150.491 -55 100.652
48 | v -10.4913 -55 100.652
49 | # 8 verticies
50 | vn 0 1 9.53674e-08
51 | vn 0 -1 0
52 | vn 0 1.27157e-07 -1
53 | vn 1 0 0
54 | vn 0 -1.27157e-07 1
55 | vn -1 0 0
56 | # 6 normals
57 | f 9//7 11//7 12//7
58 | f 12//7 10//7 9//7
59 | f 13//8 14//8 16//8
60 | f 16//8 15//8 13//8
61 | f 9//9 10//9 14//9
62 | f 14//9 13//9 9//9
63 | f 10//10 12//10 16//10
64 | f 16//10 14//10 10//10
65 | f 12//11 11//11 15//11
66 | f 15//11 16//11 12//11
67 | f 11//12 9//12 13//12
68 | f 13//12 15//12 11//12
69 | # object Shoulder02
70 | g Shoulder02
71 | v 9.56645 5 90.6522
72 | v 149.566 5 90.6522
73 | v 9.56645 5 100.652
74 | v 149.566 5 100.652
75 | v 9.56645 -55 90.6522
76 | v 149.566 -55 90.6522
77 | v 9.56645 -55 100.652
78 | v 149.566 -55 100.652
79 | # 8 verticies
80 | vn 0 1 9.53674e-08
81 | vn 0 -1 0
82 | vn 0 1.27157e-07 -1
83 | vn 1 0 0
84 | vn 0 -1.27157e-07 1
85 | vn -1 0 0
86 | # 6 normals
87 | f 17//13 19//13 20//13
88 | f 20//13 18//13 17//13
89 | f 21//14 22//14 24//14
90 | f 24//14 23//14 21//14
91 | f 17//15 18//15 22//15
92 | f 22//15 21//15 17//15
93 | f 18//16 20//16 24//16
94 | f 24//16 22//16 18//16
95 | f 20//17 19//17 23//17
96 | f 23//17 24//17 20//17
97 | f 19//18 17//18 21//18
98 | f 21//18 23//18 19//18
99 | # object Chest01
100 | g Chest01
101 | v -27.9831 3.17897 67.8053
102 | v 27.0169 3.17897 67.8053
103 | v -39.7688 3.17897 88.366
104 | v 38.8026 3.17897 88.366
105 | v -27.9831 -52.2233 67.8052
106 | v 27.0169 -52.2233 67.8052
107 | v -39.7688 -50.0614 88.366
108 | v 38.8026 -50.0614 88.366
109 | # 8 verticies
110 | vn 0 1 -3.47874e-08
111 | vn 0 -0.994518 0.10457
112 | vn 0 1.37709e-07 -1
113 | vn 0.867575 1.32036e-07 -0.497307
114 | vn 0.867575 1.95589e-07 -0.497306
115 | vn 0.867575 6.84837e-08 -0.497307
116 | vn 0 -1.43301e-07 1
117 | vn -0.867575 7.7119e-09 -0.497306
118 | vn -0.867575 6.84837e-08 -0.497307
119 | vn -0.867575 -5.30599e-08 -0.497306
120 | # 10 normals
121 | f 25//19 27//19 28//19
122 | f 28//19 26//19 25//19
123 | f 29//20 30//20 32//20
124 | f 32//20 31//20 29//20
125 | f 25//21 26//21 30//21
126 | f 30//21 29//21 25//21
127 | f 26//22 28//23 32//22
128 | f 32//22 30//24 26//22
129 | f 28//25 27//25 31//25
130 | f 31//25 32//25 28//25
131 | f 27//26 25//27 29//26
132 | f 29//26 31//28 27//26
133 | # object LegA01
134 | g LegA01
135 | v -138.604 -2.5 44.6729
136 | v -111.604 -2.5 44.6729
137 | v -138.604 -2.5 89.0729
138 | v -111.604 -2.5 89.0729
139 | v -138.604 -47.5 44.6729
140 | v -111.604 -47.5 44.6729
141 | v -138.604 -47.5 89.0729
142 | v -111.604 -47.5 89.0729
143 | # 8 verticies
144 | vn 0 1 4.29583e-08
145 | vn 0 -1 8.59166e-08
146 | vn 0 8.4771e-08 -1
147 | vn 1 0 0
148 | vn 0 -1.69542e-07 1
149 | vn -1 0 0
150 | # 6 normals
151 | f 33//29 35//29 36//29
152 | f 36//29 34//29 33//29
153 | f 37//30 38//30 40//30
154 | f 40//30 39//30 37//30
155 | f 33//31 34//31 38//31
156 | f 38//31 37//31 33//31
157 | f 34//32 36//32 40//32
158 | f 40//32 38//32 34//32
159 | f 36//33 35//33 39//33
160 | f 39//33 40//33 36//33
161 | f 35//34 33//34 37//34
162 | f 37//34 39//34 35//34
163 | # object LegB01
164 | g LegB01
165 | v 110.638 -2.5 44.6729
166 | v 137.638 -2.5 44.6729
167 | v 110.638 -2.5 89.0729
168 | v 137.638 -2.5 89.0729
169 | v 110.638 -47.5 44.6729
170 | v 137.638 -47.5 44.6729
171 | v 110.638 -47.5 89.0729
172 | v 137.638 -47.5 89.0729
173 | # 8 verticies
174 | vn 0 1 4.29583e-08
175 | vn 0 -1 8.59166e-08
176 | vn 0 8.4771e-08 -1
177 | vn 1 0 0
178 | vn 0 -1.69542e-07 1
179 | vn -1 0 0
180 | # 6 normals
181 | f 41//35 43//35 44//35
182 | f 44//35 42//35 41//35
183 | f 45//36 46//36 48//36
184 | f 48//36 47//36 45//36
185 | f 41//37 42//37 46//37
186 | f 46//37 45//37 41//37
187 | f 42//38 44//38 48//38
188 | f 48//38 46//38 42//38
189 | f 44//39 43//39 47//39
190 | f 47//39 48//39 44//39
191 | f 43//40 41//40 45//40
192 | f 45//40 47//40 43//40
193 | # object Bar02
194 | g Bar02
195 | v 79.3256 -7.83574e-06 63.0187
196 | v 106.326 -7.83574e-06 63.0187
197 | v 79.3256 -7.42305e-06 73.0187
198 | v 106.326 -7.42305e-06 73.0187
199 | v 79.3256 -50 63.0187
200 | v 106.326 -50 63.0187
201 | v 79.3256 -50 73.0187
202 | v 106.326 -50 73.0187
203 | # 8 verticies
204 | vn 0 1 -4.12693e-08
205 | vn 0 -1 3.8147e-07
206 | vn 0 7.62939e-08 -1
207 | vn 1 0 0
208 | vn 0 0 1
209 | vn -1 0 0
210 | # 6 normals
211 | f 49//41 51//41 52//41
212 | f 52//41 50//41 49//41
213 | f 53//42 54//42 56//42
214 | f 56//42 55//42 53//42
215 | f 49//43 50//43 54//43
216 | f 54//43 53//43 49//43
217 | f 50//44 52//44 56//44
218 | f 56//44 54//44 50//44
219 | f 52//45 51//45 55//45
220 | f 55//45 56//45 52//45
221 | f 51//46 49//46 53//46
222 | f 53//46 55//46 51//46
223 | # object Bar01
224 | g Bar01
225 | v -107.292 -7.83574e-06 63.0187
226 | v -80.2918 -7.83574e-06 63.0187
227 | v -107.292 -7.42305e-06 73.0187
228 | v -80.2918 -7.42305e-06 73.0187
229 | v -107.292 -50 63.0187
230 | v -80.2918 -50 63.0187
231 | v -107.292 -50 73.0187
232 | v -80.2918 -50 73.0187
233 | # 8 verticies
234 | vn 0 1 -4.12693e-08
235 | vn 0 -1 3.8147e-07
236 | vn 0 7.62939e-08 -1
237 | vn 1 0 0
238 | vn 0 0 1
239 | vn -1 0 0
240 | # 6 normals
241 | f 57//47 59//47 60//47
242 | f 60//47 58//47 57//47
243 | f 61//48 62//48 64//48
244 | f 64//48 63//48 61//48
245 | f 57//49 58//49 62//49
246 | f 62//49 61//49 57//49
247 | f 58//50 60//50 64//50
248 | f 64//50 62//50 58//50
249 | f 60//51 59//51 63//51
250 | f 63//51 64//51 60//51
251 | f 59//52 57//52 61//52
252 | f 61//52 63//52 59//52
253 | # object LegA02
254 | g LegA02
255 | v -138.604 -2.5 -108.936
256 | v -75.413 -2.5 -108.936
257 | v -138.604 -2.5 -90.182
258 | v -111.604 -2.5 -90.182
259 | v -138.604 -2.5 31.0636
260 | v -111.604 -2.5 31.0636
261 | v -138.604 -47.5 -108.936
262 | v -75.413 -47.5 -108.936
263 | v -138.604 -47.5 -90.182
264 | v -111.604 -47.5 -90.182
265 | v -138.604 -47.5 31.0636
266 | v -111.604 -47.5 31.0636
267 | # 12 verticies
268 | vn 0 1 1.52553e-07
269 | vn 0 1 6.52712e-08
270 | vn 0 1 1.08912e-07
271 | vn 0 1 2.16305e-08
272 | vn 0 -1 2.03404e-07
273 | vn 0 -1 1.25115e-07
274 | vn 0 -1 4.68262e-08
275 | vn 0 -1 -3.14625e-08
276 | vn 0 0 -1
277 | vn 0.460093 0 0.887871
278 | vn 1 0 0
279 | vn 0 -4.23855e-08 1
280 | vn -1 0 0
281 | # 13 normals
282 | f 65//53 67//54 68//55
283 | f 68//55 66//53 65//53
284 | f 67//54 69//56 70//56
285 | f 70//56 68//55 67//54
286 | f 71//57 72//57 74//58
287 | f 74//58 73//59 71//57
288 | f 73//59 74//58 76//60
289 | f 76//60 75//60 73//59
290 | f 65//61 66//61 72//61
291 | f 72//61 71//61 65//61
292 | f 66//62 68//62 74//62
293 | f 74//62 72//62 66//62
294 | f 68//63 70//63 76//63
295 | f 76//63 74//63 68//63
296 | f 70//64 69//64 75//64
297 | f 75//64 76//64 70//64
298 | f 69//65 67//65 73//65
299 | f 73//65 75//65 69//65
300 | f 67//65 65//65 71//65
301 | f 71//65 73//65 67//65
302 | # object Lower Midd
303 | g Lower_Midd
304 | v -31.9831 2.44438 23.265
305 | v 31.0169 2.44438 23.265
306 | v -37.9831 2.44438 30.6854
307 | v 37.0169 2.44438 30.6854
308 | v -31.9831 -49.7811 23.2649
309 | v 31.0169 -49.7811 23.2649
310 | v -37.9831 -52.4122 30.6854
311 | v 37.0169 -52.4122 30.6854
312 | # 8 verticies
313 | vn 0 1 0
314 | vn 0 -0.942507 -0.334187
315 | vn 0 3.65214e-08 -1
316 | vn 0.777605 3.33431e-08 -0.628754
317 | vn 0.777605 4.37232e-08 -0.628754
318 | vn 0.777604 2.2963e-08 -0.628754
319 | vn 0 -6.95395e-08 1
320 | vn -0.777605 3.33431e-08 -0.628754
321 | vn -0.777605 2.2963e-08 -0.628754
322 | vn -0.777604 4.37232e-08 -0.628754
323 | # 10 normals
324 | f 77//66 79//66 80//66
325 | f 80//66 78//66 77//66
326 | f 81//67 82//67 84//67
327 | f 84//67 83//67 81//67
328 | f 77//68 78//68 82//68
329 | f 82//68 81//68 77//68
330 | f 78//69 80//70 84//69
331 | f 84//69 82//71 78//69
332 | f 80//72 79//72 83//72
333 | f 83//72 84//72 80//72
334 | f 79//73 77//74 81//73
335 | f 81//73 83//75 79//73
336 | # object Head
337 | g Head
338 | v -26.0768 4.99999 104.591
339 | v 25.1107 4.99999 104.591
340 | v -20.8268 0.818023 119.111
341 | v 19.8607 0.818023 119.111
342 | v -26.0768 -55 104.591
343 | v 25.1107 -55 104.591
344 | v -20.8268 -44.5524 119.111
345 | v 19.8607 -44.5524 119.111
346 | # 8 verticies
347 | vn 0 0.960938 0.276762
348 | vn 0 -0.811715 0.584054
349 | vn 0 0 -1
350 | vn 0.940417 -1.97673e-08 0.340025
351 | vn 0.940417 -3.95346e-08 0.340025
352 | vn 0.940417 0 0.340025
353 | vn 0 0 1
354 | vn -0.940417 1.97673e-08 0.340025
355 | vn -0.940417 0 0.340025
356 | vn -0.940417 3.95346e-08 0.340025
357 | # 10 normals
358 | f 85//76 87//76 88//76
359 | f 88//76 86//76 85//76
360 | f 89//77 90//77 92//77
361 | f 92//77 91//77 89//77
362 | f 85//78 86//78 90//78
363 | f 90//78 89//78 85//78
364 | f 86//79 88//80 92//79
365 | f 92//79 90//81 86//79
366 | f 88//82 87//82 91//82
367 | f 91//82 92//82 88//82
368 | f 87//83 85//84 89//83
369 | f 89//83 91//85 87//83
370 | # object Chest02
371 | g Chest02
372 | v 9.50792 3.17897 66.114
373 | v 9.50792 3.17897 52.5693
374 | v 65.8137 3.17897 52.5693
375 | v 81.2614 3.17896 88.9498
376 | v 42.0824 3.17896 88.9498
377 | v 29.1534 3.17897 66.114
378 | v 9.50793 -52.4011 66.114
379 | v 9.50793 -53.8253 52.5693
380 | v 65.8137 -53.8253 52.5693
381 | v 81.2614 -50 88.9498
382 | v 42.0825 -50 88.9498
383 | v 29.1534 -52.4011 66.114
384 | # 12 verticies
385 | vn -1 -1.69442e-07 9.0208e-09
386 | vn -1 -1.67299e-07 5.88969e-15
387 | vn -1 -1.71586e-07 1.80416e-08
388 | vn 0 0 -1
389 | vn 0.920458 1.32055e-07 -0.390841
390 | vn 0.920458 2.6411e-07 -0.390841
391 | vn 0.920458 0 -0.390841
392 | vn 0 0 1
393 | vn -0.870205 -1.87175e-07 0.49269
394 | vn -0.870205 -1.87083e-07 0.49269
395 | vn -0.870205 -1.87268e-07 0.49269
396 | vn 0 -1.37268e-07 1
397 | vn 2.37897e-08 1 7.8056e-08
398 | vn 3.56845e-08 1 1.34686e-07
399 | vn 0 1 1.11409e-07
400 | vn 2.37897e-08 1 2.91848e-08
401 | vn 0 1 -3.52046e-08
402 | vn 6.79452e-08 -0.994518 0.10457
403 | vn 0 -0.994518 0.10457
404 | vn 1.01918e-07 -0.994518 0.10457
405 | vn 6.79452e-08 -0.994518 0.10457
406 | vn 0 -0.994518 0.10457
407 | # 22 normals
408 | f 93//86 94//87 100//86
409 | f 93//86 100//86 99//88
410 | f 94//89 95//89 101//89
411 | f 94//89 101//89 100//89
412 | f 95//90 96//91 102//90
413 | f 95//90 102//90 101//92
414 | f 96//93 97//93 103//93
415 | f 96//93 103//93 102//93
416 | f 97//94 98//95 104//94
417 | f 97//94 104//94 103//96
418 | f 98//97 93//97 99//97
419 | f 98//97 99//97 104//97
420 | f 95//98 97//99 96//100
421 | f 95//98 98//101 97//99
422 | f 94//102 98//101 95//98
423 | f 94//102 93//102 98//101
424 | f 101//103 102//104 103//105
425 | f 101//103 103//105 104//106
426 | f 100//107 101//103 104//106
427 | f 100//107 104//106 99//107
428 | # object Upper Midd
429 | g Upper_Midd
430 | v -61.7065 3.17897 44.7497
431 | v 60.7403 3.17897 44.7497
432 | v -64.9831 3.17897 50.8321
433 | v 64.0169 3.17897 50.8321
434 | v -61.7065 -54.6475 44.7497
435 | v 60.7403 -54.6475 44.7497
436 | v -64.9831 -54.008 50.8321
437 | v 64.0169 -54.008 50.8321
438 | # 8 verticies
439 | vn 0 1 0
440 | vn 0 -0.994518 0.104569
441 | vn 0 0 -1
442 | vn 0.880381 1.58182e-08 -0.474268
443 | vn 0.880381 3.16364e-08 -0.474268
444 | vn 0.88038 0 -0.474268
445 | vn 0 -6.67058e-08 1
446 | vn -0.880381 1.58182e-08 -0.474268
447 | vn -0.880381 0 -0.474268
448 | vn -0.88038 3.16364e-08 -0.474268
449 | # 10 normals
450 | f 105//108 107//108 108//108
451 | f 108//108 106//108 105//108
452 | f 109//109 110//109 112//109
453 | f 112//109 111//109 109//109
454 | f 105//110 106//110 110//110
455 | f 110//110 109//110 105//110
456 | f 106//111 108//112 112//111
457 | f 112//111 110//113 106//111
458 | f 108//114 107//114 111//114
459 | f 111//114 112//114 108//114
460 | f 107//115 105//116 109//115
461 | f 109//115 111//117 107//115
462 | # object Head01
463 | g Head01
464 | v 19.2607 2.00002 118.603
465 | v -20.2269 2.00001 118.603
466 | v -11.1143 -6.31388 145.091
467 | v 10.1482 -6.31388 145.091
468 | v 15.3119 -46.6 114.103
469 | v -16.2781 -46.6 114.103
470 | v -16.2781 -3.39998 114.103
471 | v 15.3119 -3.39998 114.103
472 | v -20.2268 -52 118.603
473 | v -11.1143 -26.7259 145.091
474 | v -10.0512 -27.0406 149.972
475 | v 9.08504 -27.0406 149.972
476 | v 9.08503 -8.66976 149.972
477 | v -10.0512 -8.66976 149.972
478 | v 10.1482 -26.7259 145.091
479 | v 19.2607 -52 118.603
480 | v 12.2744 -30.1023 147.813
481 | v -13.2406 -30.1024 147.813
482 | v -13.2406 -5.60795 147.813
483 | v 12.2744 -5.60794 147.813
484 | v 12.1079 -42.3555 128.711
485 | v 9.58973 -32.7047 138.825
486 | v 9.93852 -34.8278 136.6
487 | v -13.0741 -42.3555 128.711
488 | v -10.5559 -32.7047 138.825
489 | v -13.0551 -42.2632 128.807
490 | v -13.0741 -42.4313 128.711
491 | v 12.1079 -42.4313 128.711
492 | v 9.58974 -37.1741 137.868
493 | v -10.5559 -37.1741 137.868
494 | # 30 verticies
495 | vn -1.71999e-07 0.954108 0.299464
496 | vn -1.72822e-07 0.954108 0.299464
497 | vn -1.7868e-07 0.992766 0.120065
498 | vn -1.81468e-07 0.997549 -0.0699663
499 | vn -1.20756e-07 8.83031e-08 -1
500 | vn -2.41513e-07 -4.26527e-14 -1
501 | vn -3.19895e-14 1.76606e-07 -1
502 | vn -0.945609 -1.78141e-07 0.325306
503 | vn -0.945609 -1.7672e-07 0.325306
504 | vn -0.945609 -1.79561e-07 0.325306
505 | vn -0.293234 -5.13759e-08 0.956041
506 | vn 0.293234 6.089e-08 0.956041
507 | vn 0.293234 5.32787e-08 0.956041
508 | vn -0.293234 -4.56675e-08 0.956041
509 | vn 0.945609 1.4888e-07 0.325306
510 | vn 0.945609 1.2104e-07 0.325306
511 | vn 0.945609 1.7672e-07 0.325306
512 | vn 4.63837e-08 -0.640184 -0.768222
513 | vn 1.2369e-07 -0.640183 -0.768222
514 | vn -3.09227e-08 -0.640184 -0.768222
515 | vn -1.1596e-07 0.640185 -0.768221
516 | vn -0.751644 -7.2877e-08 -0.659569
517 | vn -0.751645 -1.3009e-08 -0.659568
518 | vn -0.751644 -1.32745e-07 -0.659569
519 | vn 0.751645 2.37581e-07 -0.659568
520 | vn 0.751645 2.25932e-07 -0.659568
521 | vn 0.751644 2.49229e-07 -0.659568
522 | vn 7.50588e-08 -0.627548 -0.778578
523 | vn 5.62941e-08 -0.627548 -0.778578
524 | vn 9.38235e-08 -0.627548 -0.778578
525 | vn -1.7728e-07 0.967966 -0.251083
526 | vn -1.80898e-07 0.967966 -0.251083
527 | vn -0.788013 -1.50336e-07 -0.615659
528 | vn -0.788013 -1.47268e-07 -0.615659
529 | vn -0.788013 -1.53404e-07 -0.615659
530 | vn 0.788013 1.34995e-07 -0.615659
531 | vn 0.788013 1.47268e-07 -0.615659
532 | vn 0.788013 1.22723e-07 -0.615659
533 | vn 1.00538e-07 -0.576393 0.817173
534 | vn 8.61753e-08 -0.576393 0.817173
535 | vn 1.149e-07 -0.576393 0.817173
536 | vn 0.560687 1.01873e-07 0.828028
537 | vn 0.560687 8.73199e-08 0.828028
538 | vn -1.11309e-07 0.576391 0.817174
539 | vn -1.07719e-07 0.576391 0.817174
540 | vn -1.149e-07 0.576391 0.817174
541 | vn -0.560687 -9.8235e-08 0.828028
542 | vn -0.560687 -1.0915e-07 0.828028
543 | vn 6.22973e-08 -0.723497 0.690327
544 | vn -1.17426e-06 -0.723497 0.690327
545 | vn -7.03585e-07 -0.723497 0.690327
546 | vn 1.95224e-07 -0.723497 0.690327
547 | vn -8.38773e-05 -0.723492 0.690332
548 | vn -3.04282e-07 -0.540835 0.841129
549 | vn -2.37337e-06 -0.723497 0.690327
550 | vn -0.000140798 -0.723489 0.690336
551 | vn 1.07309e-06 -0.574707 0.818359
552 | vn -0.000209962 -0.723485 0.69034
553 | vn 6.56878e-08 -0.867253 0.497868
554 | vn 1.31376e-07 -0.867253 0.497868
555 | vn 0 -0.867253 0.497868
556 | vn 0 0 -1
557 | vn 0.964211 0 0.265138
558 | vn 0.964211 3.06608e-07 0.265138
559 | vn 0.970348 -0.0137885 0.241319
560 | vn 0.980307 -0.0413331 0.193105
561 | vn 0.97313 -0.0206848 0.229327
562 | vn 0 -0.209306 0.97785
563 | vn 1.98166e-08 -0.209306 0.97785
564 | vn -0.952257 -0.0639002 0.298534
565 | vn -0.952254 -0.0639105 0.298543
566 | vn -0.963611 -0.0426831 0.263879
567 | vn -0.968654 -0.0320246 0.246339
568 | vn -0.981172 0 0.193138
569 | # 74 normals
570 | f 113//118 114//119 115//120
571 | f 115//120 116//121 113//118
572 | f 117//122 118//123 119//122
573 | f 119//122 120//124 117//122
574 | f 121//125 122//126 115//125
575 | f 115//125 114//127 121//125
576 | f 123//128 124//129 125//130
577 | f 125//130 126//131 123//128
578 | f 127//132 128//133 113//132
579 | f 113//132 116//134 127//132
580 | f 128//135 121//136 118//135
581 | f 118//135 117//137 128//135
582 | f 114//138 113//138 120//138
583 | f 120//138 119//138 114//138
584 | f 121//139 114//140 119//139
585 | f 119//139 118//141 121//139
586 | f 113//142 128//143 117//142
587 | f 117//142 120//144 113//142
588 | f 122//145 127//146 129//145
589 | f 129//145 130//147 122//145
590 | f 116//121 115//120 131//148
591 | f 131//148 132//149 116//121
592 | f 115//150 122//151 130//150
593 | f 130//150 131//152 115//150
594 | f 127//153 116//154 132//153
595 | f 132//153 129//155 127//153
596 | f 130//156 129//157 124//156
597 | f 124//156 123//158 130//156
598 | f 129//159 132//160 125//130
599 | f 125//130 124//129 129//159
600 | f 132//161 131//162 126//161
601 | f 126//161 125//163 132//161
602 | f 131//164 130//165 123//128
603 | f 123//128 126//131 131//164
604 | f 128//166 127//167 133//168
605 | f 128//166 133//168 121//169
606 | f 127//167 122//170 134//171
607 | f 135//172 127//167 134//171
608 | f 127//167 135//172 133//168
609 | f 122//170 121//169 136//173
610 | f 136//173 121//169 133//168
611 | f 134//171 122//170 137//174
612 | f 122//170 136//173 138//175
613 | f 137//174 122//170 138//175
614 | f 139//176 140//177 141//176
615 | f 141//176 142//178 139//176
616 | f 133//179 140//179 139//179
617 | f 140//180 133//181 141//182
618 | f 134//183 141//182 135//184
619 | f 141//185 134//171 142//186
620 | f 133//181 135//184 141//182
621 | f 133//179 139//179 136//179
622 | f 137//174 142//186 134//171
623 | f 142//187 137//188 139//189
624 | f 139//189 138//190 136//191
625 | f 138//190 139//189 137//188
626 | # object Head02
627 | g Head02
628 | v -81.7331 4.99999 104.591
629 | v -26.4755 4.99999 104.591
630 | v -13.6081 -6.46815 144.624
631 | v -11.9564 -6.46815 144.624
632 | v -81.7331 -55 104.591
633 | v -26.4755 -55 104.591
634 | v -13.6081 -26.6205 144.624
635 | v -11.9564 -26.6205 144.624
636 | # 8 verticies
637 | vn 0 0.961333 0.27539
638 | vn 0 -0.815805 0.578326
639 | vn 0 0 -1
640 | vn 0.940083 0 -0.340947
641 | vn 0 0 1
642 | vn -0.348607 0 0.937269
643 | vn -0.174303 0 0.984692
644 | vn -0.506639 0 0.862158
645 | # 8 normals
646 | f 143//192 145//192 146//192
647 | f 146//192 144//192 143//192
648 | f 147//193 148//193 150//193
649 | f 150//193 149//193 147//193
650 | f 143//194 144//194 148//194
651 | f 148//194 147//194 143//194
652 | f 144//195 146//195 150//195
653 | f 150//195 148//195 144//195
654 | f 146//196 145//197 149//198
655 | f 149//198 150//196 146//196
656 | f 145//197 143//199 147//199
657 | f 147//199 149//198 145//197
658 | # object Chest03
659 | g Chest03
660 | v -66.7799 3.17895 52.5693
661 | v -10.4741 3.17895 52.5693
662 | v -10.4741 3.17895 66.114
663 | v -30.1196 3.17895 66.114
664 | v -43.0486 3.17895 88.9498
665 | v -82.2276 3.17895 88.9498
666 | v -66.7799 -53.7851 52.5693
667 | v -10.4741 -53.7851 52.5693
668 | v -10.4741 -52.3759 66.114
669 | v -30.1196 -52.3759 66.114
670 | v -43.0486 -50 88.9498
671 | v -82.2276 -50 88.9498
672 | # 12 verticies
673 | vn 0 1.33934e-07 -1
674 | vn 1 0 0
675 | vn 0 -1.37331e-07 1
676 | vn 0.870206 -3.38307e-08 0.492689
677 | vn 0.870205 0 0.492689
678 | vn 0.870206 -6.76614e-08 0.492689
679 | vn 0 0 1
680 | vn -0.920459 2.61733e-08 -0.39084
681 | vn -0.920459 5.23466e-08 -0.39084
682 | vn -0.920459 0 -0.39084
683 | vn -1.00186e-09 1 3.99743e-08
684 | vn -6.6791e-10 1 3.83844e-08
685 | vn 0 1 3.93208e-08
686 | vn -6.6791e-10 1 3.70123e-08
687 | vn 0 1 3.52045e-08
688 | vn -5.11222e-08 -0.994631 0.103482
689 | vn 0 -0.994631 0.103482
690 | vn -3.40815e-08 -0.994631 0.103482
691 | vn -3.40815e-08 -0.994631 0.103482
692 | vn 0 -0.994631 0.103482
693 | # 20 normals
694 | f 151//200 152//200 158//200
695 | f 151//200 158//200 157//200
696 | f 152//201 153//201 159//201
697 | f 152//201 159//201 158//201
698 | f 153//202 154//202 160//202
699 | f 153//202 160//202 159//202
700 | f 154//203 155//204 161//203
701 | f 154//203 161//203 160//205
702 | f 155//206 156//206 162//206
703 | f 155//206 162//206 161//206
704 | f 156//207 151//208 157//207
705 | f 156//207 157//207 162//209
706 | f 155//210 151//211 156//212
707 | f 154//213 151//211 155//210
708 | f 154//213 152//214 151//211
709 | f 153//214 152//214 154//213
710 | f 161//215 162//216 157//217
711 | f 160//218 161//215 157//217
712 | f 160//218 157//217 158//219
713 | f 159//219 160//218 158//219
714 | # object LegB02
715 | g LegB02
716 | v 137.638 -47.5 -108.936
717 | v 74.4468 -47.5 -108.936
718 | v 137.638 -47.5 -90.182
719 | v 110.638 -47.5 -90.182
720 | v 137.638 -47.5 31.0636
721 | v 110.638 -47.5 31.0636
722 | v 137.638 -2.49998 -108.936
723 | v 74.4468 -2.49999 -108.936
724 | v 137.638 -2.49997 -90.182
725 | v 110.638 -2.49998 -90.182
726 | v 137.638 -2.49998 31.0636
727 | v 110.638 -2.49998 31.0636
728 | # 12 verticies
729 | vn 1.61194e-07 -1 2.86615e-08
730 | vn 1.8838e-07 -1 -1.04875e-08
731 | vn 1.54557e-07 -1 8.62018e-09
732 | vn 1.81102e-07 -1 5.73231e-08
733 | vn 2.8257e-07 -1 0
734 | vn 2.11928e-07 -1 -1.57313e-08
735 | vn -1.85156e-07 1 -1.77574e-07
736 | vn -1.84875e-07 1 -1.77169e-07
737 | vn -1.85249e-07 1 -1.09206e-07
738 | vn -1.85437e-07 1 -4.09729e-08
739 | vn -1.85437e-07 1 2.75297e-08
740 | vn -1.85437e-07 1 2.75297e-08
741 | vn -1.20735e-07 -1.02348e-14 -1
742 | vn -1.20735e-07 -2.04696e-14 -1
743 | vn -1.20735e-07 0 -1
744 | vn -0.460093 -1.53271e-07 0.887871
745 | vn -0.460093 -2.28537e-07 0.887871
746 | vn -0.460093 -7.80051e-08 0.887871
747 | vn -1 -2.54313e-07 3.14625e-08
748 | vn -1 -3.39084e-07 6.29251e-08
749 | vn -1 -1.69542e-07 -4.66745e-15
750 | vn 0 0 1
751 | vn 1 0 0
752 | # 23 normals
753 | f 163//220 165//221 166//222
754 | f 166//222 164//223 163//220
755 | f 165//221 167//224 168//225
756 | f 168//225 166//222 165//221
757 | f 169//226 170//227 172//228
758 | f 172//228 171//229 169//226
759 | f 171//229 172//228 174//230
760 | f 174//230 173//231 171//229
761 | f 163//232 164//233 170//232
762 | f 170//232 169//234 163//232
763 | f 164//235 166//236 172//235
764 | f 172//235 170//237 164//235
765 | f 166//238 168//239 174//238
766 | f 174//238 172//240 166//238
767 | f 168//241 167//241 173//241
768 | f 173//241 174//241 168//241
769 | f 167//242 165//242 171//242
770 | f 171//242 173//242 167//242
771 | f 165//242 163//242 169//242
772 | f 169//242 171//242 165//242
773 | # object Head04
774 | g Head04
775 | v 80.7669 -55 104.591
776 | v 25.5093 -55 104.591
777 | v 12.6419 -26.6205 144.624
778 | v 10.9902 -26.6205 144.624
779 | v 80.7669 5.00002 104.591
780 | v 25.5093 5.00001 104.591
781 | v 12.6419 -6.46814 144.624
782 | v 10.9902 -6.46814 144.624
783 | # 8 verticies
784 | vn 8.44784e-08 -0.815806 0.578326
785 | vn 0 -0.815806 0.578326
786 | vn 1.68957e-07 -0.815805 0.578326
787 | vn -6.80931e-08 0.961333 0.27539
788 | vn -1.36186e-07 0.961333 0.27539
789 | vn 0 0.961332 0.27539
790 | vn -6.90348e-08 -6.35783e-08 -1
791 | vn 0 0 -1
792 | vn -1.3807e-07 -1.27157e-07 -1
793 | vn -0.940083 -1.78629e-07 -0.340947
794 | vn -0.940083 -1.77951e-07 -0.340947
795 | vn -0.940083 -1.79307e-07 -0.340947
796 | vn 0 0 1
797 | vn 0.348607 1.15039e-07 0.937269
798 | vn 0.174303 3.29944e-08 0.984692
799 | vn 0.506639 2.38474e-07 0.862158
800 | vn 0.506639 1.67189e-07 0.862158
801 | # 17 normals
802 | f 175//243 177//244 178//243
803 | f 178//243 176//245 175//243
804 | f 179//246 180//247 182//246
805 | f 182//246 181//248 179//246
806 | f 175//249 176//250 180//249
807 | f 180//249 179//251 175//249
808 | f 176//252 178//253 182//252
809 | f 182//252 180//254 176//252
810 | f 178//255 177//256 181//257
811 | f 181//257 182//255 178//255
812 | f 177//256 175//258 179//259
813 | f 179//259 181//257 177//256
814 |
--------------------------------------------------------------------------------
/GlTron/res/raw/song_revenge_of_cats.ogg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Chluverman/android-gltron/69c8a230d0190a4978827b85ebaa04a04c70890e/GlTron/res/raw/song_revenge_of_cats.ogg
--------------------------------------------------------------------------------
/GlTron/res/values/array.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | - Blue Bike
4 | - Yellow Bike
5 | - Red Bike
6 | - Grey Bike
7 | - Green Bike
8 | - Purple Bike
9 |
10 |
11 | - 0
12 | - 1
13 | - 2
14 | - 3
15 | - 4
16 | - 5
17 |
18 |
19 | - Normal
20 | - Far
21 | - Close
22 | - Birds-eye
23 |
24 |
25 | - 1
26 | - 2
27 | - 3
28 | - 4
29 |
30 |
31 | - 0
32 | - 1
33 | - 2
34 |
35 |
36 | - Small
37 | - Medium
38 | - Large
39 |
40 |
41 | - 6 Players
42 | - 5 Players
43 | - 4 Players (Default)
44 | - 3 Players
45 | - 2 Players
46 |
47 |
48 | - 6
49 | - 5
50 | - 4
51 | - 3
52 | - 2
53 |
54 |
55 | - Slow
56 | - Normal
57 | - Fast
58 | - Extreme
59 |
60 |
61 | - 0
62 | - 1
63 | - 2
64 | - 3
65 |
66 |
--------------------------------------------------------------------------------
/GlTron/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Hello World, glTron!
4 | GL TRON
5 | Preferences
6 |
7 |
--------------------------------------------------------------------------------
/GlTron/src/com/glTron/Game/Camera.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Iain Churcher
3 | *
4 | * Based on GLtron by Andreas Umbach (www.gltron.org)
5 | *
6 | * This file is part of GL TRON.
7 | *
8 | * GL TRON is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * GL TRON is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with GL TRON. If not, see .
20 | *
21 | */
22 |
23 | package com.glTron.Game;
24 |
25 | import java.nio.FloatBuffer;
26 |
27 | import javax.microedition.khronos.opengles.GL10;
28 |
29 | import com.glTron.Video.GraphicUtils;
30 | import com.glTron.Video.Vec;
31 |
32 | public class Camera {
33 |
34 | CamType _cameraType;
35 | int _interpolated_cam;
36 | int _interpolated_target;
37 | int _coupled;
38 | int _freedom[] = new int[3];
39 | int _type;
40 |
41 | Player _PlayerData;
42 | Vec _target = new Vec();
43 | Vec _cam = new Vec();
44 | float _movement[] = new float[4]; // indices CAM_R, CAM_CHI, CAM_PHI, CAM_PHI_OFFSET
45 |
46 | private static final float CAM_CIRCLE_DIST = 17.0f;
47 | private static final float CAM_FOLLOW_DIST = 18.0f;
48 | private static final float CAM_FOLLOW_FAR_DIST = 30.0f;
49 | private static final float CAM_FOLLOW_CLOSE_DIST = 0.0f;
50 | private static final float CAM_FOLLOW_BIRD_DIST = 200.0f;
51 |
52 | private static final float CAM_CIRCLE_Z = 8.0f;
53 | private static final float CAM_COCKPIT_Z = 4.0f;
54 |
55 | //private static final float CAM_SPEED = 0.000349f;
56 | private static final float CAM_SPEED = 0.000698f;
57 |
58 | private static final int CAM_R = 0;
59 | private static final int CAM_CHI = 1;
60 | private static final int CAM_PHI = 2;
61 | private static final int CAM_PHI_OFFSET = 3;
62 |
63 | private static final int CAM_FREE_R = 0;
64 | private static final int CAM_FREE_PHI = 1;
65 | private static final int CAM_FREE_CHI = 2;
66 |
67 | private static final float CLAMP_R_MIN = 6.0f;
68 | private static final float CLAMP_R_MAX = 45.0f;
69 | private static final float CLAMP_CHI_MIN = (((float)Math.PI) / 8.0f);
70 | private static final float CLAMP_CHI_MAX = (3.0f * (float)Math.PI / 8.0f);
71 |
72 | private static final float B_HEIGHT = 0.0f;
73 |
74 | private static final float cam_defaults[][] = {
75 | { CAM_CIRCLE_DIST, (float)Math.PI / 3.0f, 0.0f }, // circle
76 | { CAM_FOLLOW_DIST, (float)Math.PI / 4.0f, (float)Math.PI / 72.0f }, // follow
77 | { CAM_FOLLOW_FAR_DIST, (float)Math.PI / 4.0f, (float)Math.PI / 72.0f }, // follow far
78 | { CAM_FOLLOW_CLOSE_DIST, (float)Math.PI / 4.0f, (float)Math.PI / 72.0f }, // follow close
79 | { CAM_FOLLOW_BIRD_DIST, (float)Math.PI / 4.0f, (float)Math.PI / 72.0f }, // birds-eye view
80 | { CAM_COCKPIT_Z, (float)Math.PI / 8.0f, 0.0f }, // cockpit
81 | { CAM_CIRCLE_DIST, (float)Math.PI / 3.0f, 0.0f } // free
82 | };
83 |
84 | private static final float camAngles[] = {
85 | (float)Math.PI / 2.0f, 0.0f,
86 | 3.0f * (float)Math.PI / 2.0f, (float)Math.PI,
87 | 2.0f * (float)Math.PI
88 | };
89 |
90 | public enum CamType {
91 | E_CAM_TYPE_CIRCLING,
92 | E_CAM_TYPE_FOLLOW,
93 | E_CAM_TYPE_FOLLOW_FAR,
94 | E_CAM_TYPE_FOLLOW_CLOSE,
95 | E_CAM_TYPE_BIRD,
96 | E_CAM_TYPE_COCKPIT,
97 | E_CAM_TYPE_MOUSE
98 | }
99 |
100 | public Camera(Player PlayerData, CamType camtype)
101 | {
102 | _cameraType = camtype;
103 | _PlayerData = PlayerData;
104 |
105 | switch(camtype) {
106 | case E_CAM_TYPE_CIRCLING:
107 | initCircleCamera();
108 | break;
109 | case E_CAM_TYPE_FOLLOW:
110 | case E_CAM_TYPE_FOLLOW_FAR:
111 | case E_CAM_TYPE_FOLLOW_CLOSE:
112 | case E_CAM_TYPE_BIRD:
113 | initFollowCamera(camtype);
114 | break;
115 | case E_CAM_TYPE_COCKPIT:
116 | break;
117 | case E_CAM_TYPE_MOUSE:
118 | break;
119 | }
120 |
121 | _target.v[0] = PlayerData.getXpos();
122 | _target.v[1] = PlayerData.getYpos();
123 | _target.v[2] = 0.0f;
124 |
125 | _cam.v[0] = PlayerData.getXpos() + CAM_CIRCLE_DIST;
126 | _cam.v[1] = PlayerData.getYpos();
127 | _cam.v[2] = CAM_CIRCLE_Z;
128 |
129 | }
130 |
131 | public void updateType(CamType camtype)
132 | {
133 | _cameraType = camtype;
134 | _movement[CAM_R] = cam_defaults[camtype.ordinal()][CAM_R];
135 | }
136 |
137 | private void initCircleCamera()
138 | {
139 | _movement[CAM_R] = cam_defaults[0][CAM_R];
140 | _movement[CAM_CHI] = cam_defaults[0][CAM_CHI];
141 | _movement[CAM_PHI] = cam_defaults[0][CAM_PHI];
142 | _movement[CAM_PHI_OFFSET] = 0.0f;
143 |
144 | _interpolated_cam = 0;
145 | _interpolated_target = 0;
146 | _coupled = 0;
147 | _freedom[CAM_FREE_R] = 1;
148 | _freedom[CAM_FREE_PHI] = 0;
149 | _freedom[CAM_FREE_CHI] = 1;
150 | }
151 |
152 | private void initFollowCamera(CamType type)
153 | {
154 | _movement[CAM_R] = cam_defaults[type.ordinal()][CAM_R];
155 | _movement[CAM_CHI] = cam_defaults[type.ordinal()][CAM_CHI];
156 | _movement[CAM_PHI] = cam_defaults[type.ordinal()][CAM_PHI];
157 | _movement[CAM_PHI_OFFSET] = 0.0f;
158 |
159 | _interpolated_cam = 1;
160 | _interpolated_target = 0;
161 | _coupled = 1;
162 | _freedom[CAM_FREE_R] = 1;
163 | _freedom[CAM_FREE_PHI] = 1;
164 | _freedom[CAM_FREE_CHI] = 1;
165 | }
166 |
167 | private void clampCam()
168 | {
169 | if(_freedom[CAM_FREE_R] == 1) {
170 | if(_movement[CAM_R] < CLAMP_R_MIN) {
171 | _movement[CAM_R] = CLAMP_R_MIN;
172 | }
173 | if(_movement[CAM_R] > CLAMP_R_MAX) {
174 | _movement[CAM_R] = CLAMP_R_MAX;
175 | }
176 | }
177 |
178 | if(_freedom[CAM_FREE_CHI] == 1) {
179 | if(_movement[CAM_CHI] < CLAMP_CHI_MIN) {
180 | _movement[CAM_CHI] = CLAMP_CHI_MIN;
181 | }
182 | if(_movement[CAM_CHI] > CLAMP_CHI_MAX) {
183 | _movement[CAM_CHI] = CLAMP_CHI_MAX;
184 | }
185 | }
186 | }
187 |
188 | private void playerCamera(Player PlayerData, long CurrentTime, long dt)
189 | {
190 | float phi,chi,r,x,y;
191 | float dest[] = new float[3];
192 | float tdest[] = new float[3];
193 | long time;
194 | int dir;
195 | int ldir;
196 |
197 | clampCam();
198 |
199 | phi = _movement[CAM_PHI] + _movement[CAM_PHI_OFFSET];
200 | chi = _movement[CAM_CHI];
201 | r = _movement[CAM_R];
202 |
203 | if(_coupled == 1)
204 | {
205 | // do turn stuff here
206 | time = CurrentTime - PlayerData.TurnTime;
207 | if(time < PlayerData.TURN_LENGTH)
208 | {
209 | dir = PlayerData.getDirection();
210 | ldir = PlayerData.getLastDirection();
211 | if(dir == 1 && ldir == 2)
212 | {
213 | dir = 4;
214 | }
215 | if(dir == 2 && ldir == 1)
216 | {
217 | ldir = 4;
218 | }
219 | phi += ((PlayerData.TURN_LENGTH - time) * camAngles[ldir] +
220 | time * camAngles[dir]) / PlayerData.TURN_LENGTH;
221 | }
222 | else
223 | {
224 | phi += camAngles[PlayerData.getDirection()];
225 | }
226 | }
227 |
228 | x = PlayerData.getXpos();
229 | y = PlayerData.getYpos();
230 |
231 | // position the camera
232 | dest[0] = x + r * (float)Math.cos(phi) * (float)Math.sin(chi);
233 | dest[1] = y + r * (float)Math.sin(phi) * (float)Math.sin(chi);
234 | dest[2] = r * (float)Math.cos(chi);
235 |
236 | switch(_cameraType)
237 | {
238 | case E_CAM_TYPE_CIRCLING:
239 | _movement[CAM_PHI] += CAM_SPEED * dt;
240 | tdest[0] = x;
241 | tdest[1] = y;
242 | tdest[2] = B_HEIGHT;
243 | break;
244 |
245 | case E_CAM_TYPE_FOLLOW:
246 | case E_CAM_TYPE_FOLLOW_FAR:
247 | case E_CAM_TYPE_FOLLOW_CLOSE:
248 | case E_CAM_TYPE_BIRD:
249 | tdest[0] = x;
250 | tdest[1] = y;
251 | tdest[2] = B_HEIGHT;
252 | break;
253 | }
254 |
255 | _cam.v[0] = dest[0];
256 | _cam.v[1] = dest[1];
257 | _cam.v[2] = dest[2];
258 |
259 | _target.v[0] = tdest[0];
260 | _target.v[1] = tdest[1];
261 | _target.v[2] = tdest[2];
262 |
263 | }
264 |
265 | public FloatBuffer ReturnCamBuffer()
266 | {
267 | return GraphicUtils.ConvToFloatBuffer(_cam.v);
268 | }
269 |
270 | public void doCameraMovement(Player PlayerData, long CurrentTime, long dt)
271 | {
272 | playerCamera(PlayerData,CurrentTime,dt);
273 | }
274 |
275 | public void doLookAt(GL10 gl)
276 | {
277 | float m[] = new float[16];
278 | Vec Up = new Vec(0.0f, 0.0f, 1.0f);
279 | Vec x,y,z;
280 |
281 | z = _cam.Sub(_target);
282 | z.Normalise();
283 | x = Up.Cross(z);
284 | y = z.Cross(x);
285 | x.Normalise();
286 | y.Normalise();
287 |
288 | m[0*4+0] = x.v[0];
289 | m[1*4+0] = x.v[1];
290 | m[2*4+0] = x.v[2];
291 | m[3*4+0] = 0.0f;
292 |
293 | m[0*4+1] = y.v[0];
294 | m[1*4+1] = y.v[1];
295 | m[2*4+1] = y.v[2];
296 | m[3*4+1] = 0.0f;
297 |
298 | m[0*4+2] = z.v[0];
299 | m[1*4+2] = z.v[1];
300 | m[2*4+2] = z.v[2];
301 | m[3*4+2] = 0.0f;
302 |
303 | m[0*4+3] = 0.0f;
304 | m[1*4+3] = 0.0f;
305 | m[2*4+3] = 0.0f;
306 | m[3*4+3] = 1.0f;
307 |
308 | FloatBuffer M = GraphicUtils.ConvToFloatBuffer(m);
309 | gl.glMultMatrixf(M);
310 |
311 | // Translate Eye to origin
312 | gl.glTranslatef(-_cam.v[0], -_cam.v[1], -_cam.v[2]);
313 | }
314 |
315 | }
316 |
--------------------------------------------------------------------------------
/GlTron/src/com/glTron/Game/ComputerAI.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Iain Churcher
3 | *
4 | * Based on GLtron by Andreas Umbach (www.gltron.org)
5 | *
6 | * This file is part of GL TRON.
7 | *
8 | * GL TRON is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * GL TRON is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with GL TRON. If not, see .
20 | *
21 | */
22 |
23 | package com.glTron.Game;
24 |
25 | import com.glTron.Video.Segment;
26 | import com.glTron.Video.Vec;
27 |
28 | public class ComputerAI {
29 |
30 | private static final int E_FRONT = 0;
31 | private static final int E_LEFT = 1;
32 | private static final int E_RIGHT = 2;
33 | private static final int E_BACKLEFT = 3;
34 | private static final int E_MAX = 4;
35 |
36 | private static float front, left, right, backleft;
37 |
38 | private static float distance;
39 |
40 | private static final float FLT_MAX = 10000.0f;
41 |
42 | private static final int TURN_TIME_LEVEL = 1;
43 | private static final int MIN_TURN_TIME[] = { 600, 400, 200, 100 };
44 | private static final float MAX_SEG_LENGTH[] = { 0.6f, 0.3f, 0.3f, 0.3f };
45 | private static final float CRITICAL[] = { 0.2f, 0.08037f, 0.08037f, 0.0837f };
46 | private static final int SPIRAL[] = { 10, 10, 10, 10 };
47 | private static final int RL_DELTA[] = { 0, 10, 20, 30 };
48 |
49 | private static Segment Walls[];
50 | private static Player Players[];
51 |
52 | private static long Current;
53 | private static float GridSize;
54 |
55 | private static int tdiff[] = {0,0,0,0,0,0};
56 | private static long aiTime[] = { 0,0,0,0,0,0};
57 |
58 | private static float SAVE_T_DIFF = 0.500f;
59 | private static float HOPELESS_T = 0.80f;
60 |
61 |
62 | private static int agressive_action[][] = {
63 | { 2, 0, 2, 2 },
64 | { 0, 1, 1, 2 },
65 | { 0, 1, 1, 2 },
66 | { 0, 1, 1, 2 },
67 | { 0, 2, 2, 1 },
68 | { 0, 2, 2, 1 },
69 | { 0, 2, 2, 1 },
70 | { 1, 1, 1, 0 }
71 | };
72 |
73 | private static int evasive_action[][] = {
74 | { 1, 1, 2, 2 },
75 | { 1, 1, 2, 0 },
76 | { 1, 1, 2, 0 },
77 | { 1, 1, 2, 0 },
78 | { 2, 0, 1, 1 },
79 | { 2, 0, 1, 1 },
80 | { 2, 0, 1, 1 },
81 | { 2, 2, 1, 1 }
82 | };
83 |
84 |
85 | public static void initAI(Segment walls[], Player players[], float gSize)
86 | {
87 | Walls = walls;
88 | Players = players;
89 | GridSize = gSize;
90 | }
91 |
92 | public static void updateTime(long dt, long current)
93 | {
94 | // Dt = dt;
95 | Current = current;
96 | }
97 |
98 | public static void doComputer( int player, int target)
99 | {
100 | int closestOpp;
101 |
102 | // avoid short turns
103 | if((Current - aiTime[player]) < MIN_TURN_TIME[TURN_TIME_LEVEL])
104 | return;
105 |
106 | calculateDistances(player);
107 | closestOpp = getClosestOpponent(player);
108 |
109 | if(closestOpp == -1 ||
110 | distance > 48.0f ||
111 | front < distance)
112 | {
113 | doComputerSimple(player,target);
114 | }
115 | else
116 | {
117 | doComputerActive(player,target);
118 | }
119 |
120 | }
121 |
122 | private static void doComputerActive(int plyr, int target)
123 | {
124 | int location = -1;
125 | Segment player = new Segment();
126 | Segment opponent = new Segment();
127 | float t_player, t_opponent;
128 |
129 | player.vStart.v[0] = Players[plyr].getXpos();
130 | player.vStart.v[1] = Players[plyr].getYpos();
131 |
132 | opponent.vStart.v[0] = Players[target].getXpos();
133 | opponent.vStart.v[1] = Players[target].getYpos();
134 |
135 | player.vDirection.v[0] =
136 | Players[plyr].DIRS_X[Players[plyr].getDirection()] *
137 | Players[plyr].getSpeed();
138 | player.vDirection.v[1] =
139 | Players[plyr].DIRS_Y[Players[plyr].getDirection()] *
140 | Players[plyr].getSpeed();
141 |
142 | opponent.vDirection.v[0] =
143 | Players[target].DIRS_X[Players[target].getDirection()] *
144 | Players[target].getSpeed();
145 |
146 | opponent.vDirection.v[1] =
147 | Players[target].DIRS_Y[Players[target].getDirection()] *
148 | Players[target].getSpeed();
149 |
150 | // Compute sector
151 | Vec diff = player.vStart.Sub(opponent.vStart);
152 | Vec v1 = new Vec(diff.v[0],diff.v[1],0.0f);
153 | Vec v2 = new Vec(opponent.vDirection.v[0],opponent.vDirection.v[1],0.0f);
154 |
155 | v1.Normalise();
156 | v2.Normalise();
157 |
158 | Vec v3 = v1.Cross(v2);
159 | v3.Normalise();
160 |
161 | float cosphi,phi;
162 |
163 | cosphi = v1.Dot(v2);
164 |
165 | if(cosphi < -1)
166 | cosphi = -1;
167 | else if(cosphi > 1)
168 | cosphi = 1;
169 |
170 | phi = (float)Math.acos(cosphi);
171 |
172 | Vec up = new Vec(0.0f,0.0f, 1.0f);
173 | if(v3.Dot(up) > 0.0f)
174 | {
175 | phi = 2.0f * (float)Math.PI - phi;
176 | }
177 |
178 | int i;
179 |
180 | for(i=0; i < 8; i++)
181 | {
182 | phi -= (float)Math.PI / 4.0f;
183 | if(phi < 0.0f)
184 | {
185 | location = i;
186 | break;
187 | }
188 | }
189 |
190 | // Compute intersection
191 | Segment seg1 = new Segment();
192 | Segment seg2 = new Segment();
193 |
194 | seg1.vStart.Copy(opponent.vStart);
195 | seg1.vDirection.Copy(opponent.vDirection);
196 | seg2.vStart.Copy(player.vStart);
197 |
198 | seg2.vDirection = opponent.vDirection.Orthogonal();
199 | seg2.vDirection.Normalise();
200 |
201 | seg2.vDirection.Scale(player.vDirection.Length2());
202 |
203 | seg1.Intersect(seg2);
204 |
205 | t_opponent = seg1.t1;
206 | t_player = seg1.t2;
207 |
208 | if(t_player < 0)
209 | t_player *= -1;
210 |
211 | switch(location)
212 | {
213 | case 0: case 7:
214 | case 1: case 6:
215 | if(t_player < t_opponent)
216 | {
217 | // boost stuff
218 | //if(t_player - t_opponent < SAVE_T_DIFF)
219 | ai_aggressive(plyr,target,location);
220 | }
221 | else
222 | {
223 | if(t_opponent < HOPELESS_T)
224 | {
225 | ai_evasive(plyr,target,location);
226 | }
227 | else if(t_opponent - t_player < SAVE_T_DIFF)
228 | {
229 | // boost
230 | ai_aggressive(plyr,target,location);
231 | }
232 | else
233 | {
234 | ai_evasive(plyr,target,location);
235 | }
236 | }
237 | break;
238 | case 2: case 4:
239 | case 3: case 5:
240 | doComputerSimple(plyr,target);
241 | break;
242 | }
243 |
244 | }
245 |
246 | private static void doComputerSimple(int player, int target)
247 | {
248 | int level = 3;
249 | Segment trail = Players[player].getTrail(Players[player].getTrailOffset());
250 |
251 | // First check if we are in danger or should turn...
252 | if(front > CRITICAL[level] * GridSize && trail.Length() < MAX_SEG_LENGTH[level] * GridSize)
253 | return;
254 |
255 | // Decide where to turn
256 | if(front > right && front > left)
257 | return; // no way out
258 |
259 | if( left > RL_DELTA[level] &&
260 | Math.abs(right - left) < RL_DELTA[level] &&
261 | backleft > left && tdiff[player] < SPIRAL[level])
262 | {
263 | Players[player].doTurn(Players[player].TURN_LEFT, Current);
264 | tdiff[player]++;
265 | }
266 | else if(right > left && tdiff[player] > -SPIRAL[level])
267 | {
268 | Players[player].doTurn(Players[player].TURN_RIGHT, Current);
269 | tdiff[player]--;
270 | }
271 | else if( right < left && tdiff[player] < SPIRAL[level])
272 | {
273 | Players[player].doTurn(Players[player].TURN_LEFT, Current);
274 | tdiff[player]++;
275 | }
276 | else
277 | {
278 | if(tdiff[player] > 0)
279 | {
280 | Players[player].doTurn(Players[player].TURN_RIGHT, Current);
281 | tdiff[player]--;
282 | }
283 | else
284 | {
285 | Players[player].doTurn(Players[player].TURN_LEFT, Current);
286 | tdiff[player]++;
287 | }
288 | }
289 | aiTime[player] = Current;
290 | }
291 |
292 | private static int getClosestOpponent( int player)
293 | {
294 | Vec v_player = new Vec(Players[player].getXpos(), Players[player].getYpos(), 0.0f);
295 | Vec v_opponent;
296 | Vec diff;
297 | int i;
298 | int retVal = -1;
299 | float d;
300 |
301 | distance = FLT_MAX;
302 |
303 | for(i = 0; i < GLTronGame.mCurrentPlayers; i++)
304 | {
305 | if(i == player)
306 | continue;
307 |
308 | if(Players[i].getSpeed() > 0)
309 | {
310 | v_opponent = new Vec(Players[i].getXpos(),Players[i].getYpos(),0.0f);
311 | diff = v_player.Sub(v_opponent);
312 | d = Math.abs(diff.v[0]) + Math.abs(diff.v[1]);
313 | if(d < distance)
314 | {
315 | distance = d;
316 | retVal = i;
317 | }
318 |
319 | }
320 | }
321 | return retVal;
322 |
323 | }
324 |
325 | private static void calculateDistances( int player)
326 | {
327 | int i,j;
328 | int currDir = Players[player].getDirection();
329 | int dirLeft = (currDir + 3) % 4;
330 | int dirRight = (currDir + 1) % 4;
331 | float t1,t2;
332 | Segment segments[] = new Segment[E_MAX];
333 | Segment wall[];
334 | Vec v;
335 | Vec vPos = new Vec(Players[player].getXpos(),Players[player].getYpos(), 0.0f);
336 |
337 | for(i = 0; i< E_MAX; i++ )
338 | {
339 | segments[i] = new Segment();
340 | segments[i].vStart.Copy(vPos);
341 | }
342 |
343 | segments[E_FRONT].vDirection.v[0] = Players[player].DIRS_X[currDir];
344 | segments[E_FRONT].vDirection.v[1] = Players[player].DIRS_Y[currDir];
345 | segments[E_LEFT].vDirection.v[0] = Players[player].DIRS_X[dirLeft];
346 | segments[E_LEFT].vDirection.v[1] = Players[player].DIRS_Y[dirLeft];
347 | segments[E_RIGHT].vDirection.v[0] = Players[player].DIRS_X[dirRight];
348 | segments[E_RIGHT].vDirection.v[1] = Players[player].DIRS_Y[dirRight];
349 | segments[E_BACKLEFT].vDirection.v[0] =
350 | Players[player].DIRS_X[dirLeft] - Players[player].DIRS_X[currDir];
351 | segments[E_BACKLEFT].vDirection.v[1] =
352 | Players[player].DIRS_Y[dirLeft] - Players[player].DIRS_Y[currDir];
353 |
354 | segments[E_BACKLEFT].vDirection.Normalise2();
355 |
356 | front = FLT_MAX;
357 | left = FLT_MAX;
358 | right = FLT_MAX;
359 | backleft = FLT_MAX;
360 |
361 | for(i=0; i < GLTronGame.mCurrentPlayers; i++)
362 | {
363 | wall = Players[i].getTrails();
364 |
365 | if(Players[i].getTrailHeight() < Players[i].TRAIL_HEIGHT)
366 | continue;
367 |
368 | for(j=0; j < Players[i].getTrailOffset() + 1; j++)
369 | {
370 | if(i == player && j == Players[i].getTrailOffset())
371 | break;
372 |
373 | v = segments[E_FRONT].Intersect(wall[j]);
374 | t1 = segments[E_FRONT].t1;
375 | t2 = segments[E_FRONT].t2;
376 | if( (v != null) && t1 > 0.0f && t1 < front && t2 >= 0.0f && t2 <= 1.0f)
377 | front = t1;
378 |
379 | v = segments[E_LEFT].Intersect(wall[j]);
380 | t1 = segments[E_LEFT].t1;
381 | t2 = segments[E_LEFT].t2;
382 | if( (v != null) && t1 > 0.0f && t1 < left && t2 >= 0.0f && t2 <= 1.0f)
383 | left = t1;
384 |
385 | v = segments[E_RIGHT].Intersect(wall[j]);
386 | t1 = segments[E_RIGHT].t1;
387 | t2 = segments[E_RIGHT].t2;
388 | if( (v != null) && t1 > 0.0f && t1 < right && t2 >= 0.0f && t2 <= 1.0f)
389 | right = t1;
390 |
391 | v = segments[E_BACKLEFT].Intersect(wall[j]);
392 | t1 = segments[E_BACKLEFT].t1;
393 | t2 = segments[E_BACKLEFT].t2;
394 | if( (v != null) && t1 > 0.0f && t1 < backleft && t2 >= 0.0f && t2 <= 1.0f)
395 | backleft = t1;
396 |
397 | }
398 | }
399 |
400 | for(i=0; i < 4; i++)
401 | {
402 | v = segments[E_FRONT].Intersect(Walls[i]);
403 | t1 = segments[E_FRONT].t1;
404 | t2 = segments[E_FRONT].t2;
405 | if( (v != null) && t1 > 0.0f && t1 < front && t2 >= 0.0f && t2 <= 1.0f)
406 | front = t1;
407 |
408 | v = segments[E_LEFT].Intersect(Walls[i]);
409 | t1 = segments[E_LEFT].t1;
410 | t2 = segments[E_LEFT].t2;
411 | if( (v != null) && t1 > 0.0f && t1 < left && t2 >= 0.0f && t2 <= 1.0f)
412 | left = t1;
413 |
414 | v = segments[E_RIGHT].Intersect(Walls[i]);
415 | t1 = segments[E_RIGHT].t1;
416 | t2 = segments[E_RIGHT].t2;
417 | if( (v != null) && t1 > 0.0f && t1 < right && t2 >= 0.0f && t2 <= 1.0f)
418 | right = t1;
419 |
420 | v = segments[E_BACKLEFT].Intersect(Walls[i]);
421 | t1 = segments[E_BACKLEFT].t1;
422 | t2 = segments[E_BACKLEFT].t2;
423 | if( (v != null) && t1 > 0.0f && t1 < backleft && t2 >= 0.0f && t2 <= 1.0f)
424 | backleft = t1;
425 | }
426 |
427 | // leave out debug segments??
428 |
429 | }
430 |
431 | private static void ai_action(int action, int player)
432 | {
433 | float save_distance =
434 | (MIN_TURN_TIME[TURN_TIME_LEVEL] * Players[player].getSpeed() / 1000.0f) + 20.0f;
435 |
436 | switch(action)
437 | {
438 | case 0: break;
439 | case 1:
440 | // Turn left
441 | if(left > save_distance)
442 | {
443 | Players[player].doTurn(Players[player].TURN_LEFT, Current);
444 | tdiff[player]++;
445 | aiTime[player] = Current;
446 | }
447 | break;
448 | case 2:
449 | // Turn right
450 | if(right > save_distance)
451 | {
452 | Players[player].doTurn(Players[player].TURN_RIGHT, Current);
453 | tdiff[player]--;
454 | aiTime[player] = Current;
455 | }
456 | break;
457 | }
458 | }
459 |
460 | private static void ai_aggressive(int player, int target, int location)
461 | {
462 | int dirdiff = (
463 | 4 + Players[player].getDirection() -
464 | Players[target].getDirection()) % 4;
465 |
466 | ai_action(agressive_action[location][dirdiff],player);
467 | }
468 |
469 | private static void ai_evasive(int player, int target, int location)
470 | {
471 | int dirdiff = (
472 | 4 + Players[player].getDirection() -
473 | Players[target].getDirection()) % 4;
474 |
475 | ai_action(evasive_action[location][dirdiff],player);
476 | }
477 | }
478 |
--------------------------------------------------------------------------------
/GlTron/src/com/glTron/Game/GLTronGame.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Iain Churcher
3 | *
4 | * Based on GLtron by Andreas Umbach (www.gltron.org)
5 | *
6 | * This file is part of GL TRON.
7 | *
8 | * GL TRON is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * GL TRON is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with GL TRON. If not, see .
20 | *
21 | */
22 |
23 | package com.glTron.Game;
24 |
25 | import java.nio.FloatBuffer;
26 |
27 | import javax.microedition.khronos.opengles.GL10;
28 |
29 | import android.content.Context;
30 | import android.os.Handler;
31 | import android.os.SystemClock;
32 |
33 | import com.glTron.R;
34 | import com.glTron.Game.Camera.CamType;
35 | import com.glTron.Sound.SoundManager;
36 | import com.glTron.Video.*;
37 | import com.glTron.Video.Lighting.LightType;
38 |
39 |
40 | public class GLTronGame {
41 |
42 | // Define Time data
43 | public long TimeLastFrame;
44 | public long TimeCurrent;
45 | public long TimeDt;
46 |
47 | // Define arena setting
48 | private static float mCurrentGridSize;
49 |
50 | public static final int MAX_PLAYERS = 6;
51 | public static final int OWN_PLAYER = 0;
52 | public static int mCurrentPlayers = 0;
53 |
54 | // Define game textures
55 | private GLTexture ExplodeTex;
56 | private GLTexture SplashScreen;
57 |
58 | private Model LightBike;
59 | private Model RecognizerModel;
60 | private Video Visual;
61 | private WorldGraphics World;
62 | private Lighting Lights = new Lighting();
63 |
64 | private Player Players[] = new Player[MAX_PLAYERS];
65 |
66 | private Recognizer mRecognizer;
67 |
68 | // Camera data
69 | private Camera Cam;
70 |
71 | Trails_Renderer TrailRenderer;
72 |
73 | // input processing FIXME make enum type instead of bunch of flags
74 | boolean boProcessInput = false;
75 | boolean boProcessReset = false;
76 | int inputDirection;
77 |
78 | boolean boInitialState = true;
79 | private boolean boLoading = true;
80 |
81 | // sound index
82 | public static int CRASH_SOUND = 1;
83 | public static int ENGINE_SOUND = 2;
84 | public static int MUSIC_SOUND = 3;
85 | public static int RECOGNIZER_SOUND = 4;
86 |
87 | float mEngineSoundModifier = 1.0f;
88 | long mEngineStartTime = 0;
89 |
90 | // Font
91 | HUD tronHUD;
92 |
93 | // Ads
94 | Handler _handler;
95 |
96 | Context mContext;
97 | GL10 gl;
98 |
99 | public Segment Walls[] = {
100 | new Segment(),
101 | new Segment(),
102 | new Segment(),
103 | new Segment()
104 | };
105 |
106 | private int aiCount = 1;
107 |
108 | // Preferences
109 | public static UserPrefs mPrefs;
110 |
111 | public GLTronGame()
112 | {
113 | initWalls();
114 | }
115 |
116 | public void initialiseGame()
117 | {
118 | int player;
119 |
120 | // Load sounds
121 | SoundManager.getInstance();
122 | SoundManager.initSounds(mContext);
123 | SoundManager.addSound(ENGINE_SOUND, R.raw.game_engine);
124 | SoundManager.addSound(CRASH_SOUND, R.raw.game_crash);
125 | SoundManager.addSound(RECOGNIZER_SOUND, R.raw.game_recognizer);
126 | SoundManager.addMusic(R.raw.song_revenge_of_cats);
127 |
128 | // Load HUD
129 | tronHUD = new HUD(gl,mContext);
130 |
131 | //Load preferences
132 | mPrefs = new UserPrefs(mContext);
133 | mCurrentPlayers = mPrefs.NumberOfPlayers();
134 | mCurrentGridSize = mPrefs.GridSize();
135 |
136 | initWalls();
137 |
138 | // Load Models
139 | LightBike = new Model(mContext,R.raw.lightcyclehigh);
140 | RecognizerModel = new Model(mContext,R.raw.recognizerhigh);
141 | World = new WorldGraphics(gl, mContext, mCurrentGridSize);
142 | TrailRenderer = new Trails_Renderer(gl,mContext);
143 |
144 | for(player = 0; player < mCurrentPlayers; player++)
145 | {
146 | Players[player] = new Player(player, mCurrentGridSize, LightBike, tronHUD);
147 | }
148 |
149 | mRecognizer = new Recognizer(mCurrentGridSize);
150 |
151 | Cam = new Camera(Players[OWN_PLAYER], CamType.E_CAM_TYPE_CIRCLING);
152 | ExplodeTex = new GLTexture(gl,mContext, R.drawable.gltron_impact);
153 |
154 | ComputerAI.initAI(Walls,Players,mCurrentGridSize);
155 |
156 | // Setup perspective
157 | gl.glMatrixMode(GL10.GL_MODELVIEW);
158 | Visual.doPerspective(gl, mCurrentGridSize);
159 | gl.glMatrixMode(GL10.GL_MODELVIEW);
160 |
161 | // Initialise sounds
162 | if(mPrefs.PlayMusic())
163 | SoundManager.playMusic(true);
164 | if(mPrefs.PlaySFX())
165 | SoundManager.playSoundLoop(RECOGNIZER_SOUND, 1.0f);
166 |
167 | ResetTime();
168 |
169 | boLoading = false;
170 | }
171 |
172 | public void setUI_Handler(Handler handler)
173 | {
174 | _handler = handler;
175 | }
176 |
177 | // hooks for android pausing thread
178 | public void pauseGame()
179 | {
180 | SoundManager.getInstance();
181 | SoundManager.globalPauseSound();
182 | }
183 |
184 | // hooks for android resuming thread
185 | public void resumeGame()
186 | {
187 | SoundManager.getInstance();
188 | SoundManager.globalResumeSound();
189 |
190 | if(mPrefs != null)
191 | {
192 | mPrefs.ReloadPrefs();
193 |
194 | SoundManager.stopSound(RECOGNIZER_SOUND);
195 |
196 | // Update options
197 | if(!boInitialState)
198 | {
199 | Cam.updateType(mPrefs.CameraType());
200 | if(mPrefs.PlaySFX() && mPrefs.DrawRecognizer())
201 | SoundManager.playSoundLoop(RECOGNIZER_SOUND, 1.0f);
202 | }
203 | else
204 | {
205 | boProcessReset = true;
206 | }
207 |
208 | if(mPrefs.PlayMusic())
209 | SoundManager.playMusic(true);
210 | else
211 | SoundManager.stopMusic();
212 |
213 | SoundManager.stopSound(ENGINE_SOUND);
214 | if(mPrefs.PlaySFX()) {
215 | SoundManager.playSoundLoop(ENGINE_SOUND,mEngineSoundModifier);
216 | }
217 | else
218 | SoundManager.stopSound(ENGINE_SOUND);
219 |
220 |
221 | ResetTime();
222 | }
223 | }
224 |
225 | public void drawSplash(Context ctx, GL10 gl1)
226 | {
227 | float verts[] = {
228 | -1.0f, 1.0f, 0.0f,
229 | 1.0f, 1.0f, 0.0f,
230 | -1.0f, -1.0f,0.0f,
231 | 1.0f, -1.0f, 0.0f
232 | };
233 |
234 | float texture[] = {
235 | 0.0f, 1.0f,
236 | 1.0f, 1.0f,
237 | 0.0f, 0.0f,
238 | 1.0f, 0.0f
239 | };
240 |
241 | gl = gl1;
242 | mContext = ctx;
243 |
244 | FloatBuffer vertfb = GraphicUtils.ConvToFloatBuffer(verts);
245 | FloatBuffer texfb = GraphicUtils.ConvToFloatBuffer(texture);
246 |
247 | gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
248 | gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
249 |
250 | gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
251 | gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
252 |
253 | gl.glLoadIdentity();
254 |
255 | gl.glEnable(GL10.GL_TEXTURE_2D);
256 | if(SplashScreen == null)
257 | SplashScreen = new GLTexture(gl,mContext,R.drawable.gltron_bitmap);
258 |
259 | gl.glBindTexture(GL10.GL_TEXTURE_2D, SplashScreen.getTextureID());
260 |
261 | gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertfb);
262 | gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texfb);
263 | gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
264 |
265 | gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
266 | gl.glDisableClientState(GL10.GL_NORMAL_ARRAY);
267 | gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
268 |
269 | }
270 |
271 | public void updateScreenSize(int width, int height)
272 | {
273 | if(Visual == null)
274 | {
275 | Visual = new Video(width, height);
276 | }
277 | else
278 | {
279 | Visual.SetWidthHeight(width, height);
280 | }
281 |
282 |
283 | }
284 |
285 | public void addTouchEvent(float x, float y)
286 | {
287 | if(boLoading)
288 | return;
289 |
290 | if(Players[OWN_PLAYER].getSpeed() > 0.0f)
291 | {
292 | if(boInitialState)
293 | {
294 | // Change the camera and start movement.
295 | Cam = new Camera(Players[OWN_PLAYER], mPrefs.CameraType());
296 | SoundManager.stopMusic();
297 |
298 | if(mPrefs.PlayMusic())
299 | SoundManager.playMusic(true);
300 |
301 | if(mPrefs.PlaySFX() && mPrefs.DrawRecognizer())
302 | SoundManager.playSoundLoop(RECOGNIZER_SOUND, 1.0f);
303 |
304 | tronHUD.displayInstr(false);
305 | boInitialState = false;
306 | }
307 | else
308 | {
309 | if(x <= (Visual.GetWidth() / 2))
310 | {
311 | inputDirection = Players[OWN_PLAYER].TURN_LEFT;
312 | }
313 | else
314 | {
315 | inputDirection = Players[OWN_PLAYER].TURN_RIGHT;
316 | }
317 | boProcessInput = true;
318 | }
319 | }
320 | else
321 | {
322 | // Restart the player only once trail is 0
323 | if(Players[OWN_PLAYER].getTrailHeight() <= 0.0f)
324 | {
325 | boProcessReset = true;
326 | }
327 | }
328 | }
329 |
330 | public void RunGame()
331 | {
332 | int plyr;
333 |
334 | UpdateTime();
335 | ComputerAI.updateTime(TimeDt, TimeCurrent);
336 |
337 | if(boProcessInput)
338 | {
339 | Players[OWN_PLAYER].doTurn(inputDirection, TimeCurrent);
340 | mEngineSoundModifier = 1.3f;
341 | boProcessInput = false;
342 | }
343 |
344 | if(boProcessReset)
345 | {
346 | // refresh preferences
347 | mPrefs.ReloadPrefs();
348 | mCurrentPlayers = mPrefs.NumberOfPlayers();
349 |
350 | if(mPrefs.GridSize() != mCurrentGridSize)
351 | {
352 | mCurrentGridSize = mPrefs.GridSize();
353 |
354 | // re-init the world
355 | initWalls();
356 |
357 | World = new WorldGraphics(gl, mContext, mCurrentGridSize);
358 |
359 | ComputerAI.initAI(Walls,Players,mCurrentGridSize);
360 |
361 | // Setup perspective
362 | gl.glMatrixMode(GL10.GL_MODELVIEW);
363 | Visual.doPerspective(gl, mCurrentGridSize);
364 | gl.glMatrixMode(GL10.GL_MODELVIEW);
365 | }
366 |
367 | for(plyr = 0; plyr < mPrefs.NumberOfPlayers(); plyr++)
368 | {
369 | Players[plyr] = new Player(plyr, mCurrentGridSize, LightBike, tronHUD);
370 | Players[plyr].setSpeed(mPrefs.Speed());
371 | }
372 |
373 | mRecognizer = new Recognizer(mCurrentGridSize);
374 |
375 | tronHUD.resetConsole();
376 | Cam = new Camera(Players[OWN_PLAYER], CamType.E_CAM_TYPE_CIRCLING);
377 |
378 | SoundManager.stopSound(ENGINE_SOUND); // ensure sound is stopped before playing again.
379 | SoundManager.stopSound(RECOGNIZER_SOUND);
380 |
381 | tronHUD.displayInstr(true);
382 |
383 | if(mPrefs.PlaySFX())
384 | SoundManager.playSoundLoop(ENGINE_SOUND, 1.0f);
385 |
386 | boInitialState = true;
387 | boProcessReset = false;
388 | }
389 |
390 | // round robin AI to speed up frame time
391 | if(Players[aiCount].getTrailHeight() == Players[aiCount].TRAIL_HEIGHT)
392 | {
393 | ComputerAI.doComputer(aiCount, OWN_PLAYER);
394 | }
395 |
396 | // Manage sounds
397 | if(Players[OWN_PLAYER].getSpeed() == 0.0f)
398 | {
399 | SoundManager.stopSound(ENGINE_SOUND);
400 | mEngineStartTime = 0;
401 | mEngineSoundModifier = 1.0f;
402 | }
403 | else if(!boInitialState)
404 | {
405 | if(mPrefs.PlaySFX())
406 | {
407 | if(mEngineSoundModifier < 1.5f)
408 | {
409 | if(mEngineStartTime != 0)
410 | {
411 | if((TimeCurrent + 1000) > mEngineStartTime)
412 | {
413 | mEngineSoundModifier += 0.01f;
414 | SoundManager.changeRate(ENGINE_SOUND, mEngineSoundModifier);
415 | }
416 | }
417 | }
418 | }
419 | }
420 |
421 | mEngineStartTime = TimeCurrent;
422 |
423 | aiCount++;
424 |
425 | if(aiCount > (mCurrentPlayers - 1))
426 | aiCount = 1;
427 |
428 | RenderGame();
429 | }
430 |
431 | // DT smoothing experiment
432 | private final int MAX_SAMPLES = 20;
433 | private long DtHist[] = new long[MAX_SAMPLES];
434 | private int DtHead = 0;
435 | private int DtElements = 0;
436 |
437 | private void ResetTime()
438 | {
439 | TimeLastFrame = SystemClock.uptimeMillis();
440 | TimeCurrent = TimeLastFrame;
441 | TimeDt = 0;
442 | DtHead = 0;
443 | DtElements = 0;
444 | }
445 |
446 | private void UpdateTime()
447 | {
448 | long RealDt;
449 | int i;
450 |
451 | TimeLastFrame = TimeCurrent;
452 | TimeCurrent = SystemClock.uptimeMillis();
453 | RealDt = TimeCurrent - TimeLastFrame;
454 | // TimeDt = RealDt;
455 |
456 | DtHist[DtHead] = RealDt;
457 |
458 | DtHead++;
459 |
460 | if(DtHead >= MAX_SAMPLES)
461 | {
462 | DtHead = 0;
463 | }
464 |
465 | if(DtElements == MAX_SAMPLES)
466 | {
467 | // Average the last MAX_SAMPLE DT's
468 | TimeDt = 0;
469 | for(i = 0; i < MAX_SAMPLES; i++)
470 | {
471 | TimeDt += DtHist[i];
472 | }
473 | TimeDt /= MAX_SAMPLES;
474 | }
475 | else
476 | {
477 | TimeDt = RealDt;
478 | DtElements++;
479 | }
480 | }
481 |
482 | private void initWalls()
483 | {
484 | float raw[][] = {
485 | {0.0f, 0.0f, 1.0f, 0.0f },
486 | { 1.0f, 0.0f, 0.0f, 1.0f },
487 | { 1.0f, 1.0f, -1.0f, 0.0f },
488 | { 0.0f, 1.0f, 0.0f, -1.0f }
489 | };
490 |
491 | float width = mCurrentGridSize;
492 | float height = mCurrentGridSize;
493 |
494 | int j;
495 |
496 | for(j = 0; j < 4; j++)
497 | {
498 | Walls[j].vStart.v[0] = raw[j][0] * width;
499 | Walls[j].vStart.v[1] = raw[j][1] * height;
500 | Walls[j].vDirection.v[0] = raw[j][2] * width;
501 | Walls[j].vDirection.v[1] = raw[j][3] * height;
502 | }
503 | }
504 |
505 |
506 | private void RenderGame()
507 | {
508 | int player;
509 | boolean boOwnPlayerActive = true;
510 | boolean boOtherPlayersActive = false;
511 | boolean boCheckWinner = false;
512 |
513 | if(!boInitialState)
514 | {
515 | for(player = 0; player < mCurrentPlayers; player++)
516 | {
517 | Players[player].doMovement(TimeDt,TimeCurrent,Walls,Players);
518 | //check win lose should be in game logic not render - FIXME
519 | if(player == OWN_PLAYER)
520 | {
521 | if(Players[player].getSpeed() == 0.0f)
522 | boOwnPlayerActive = false;
523 | }
524 | else
525 | {
526 | if(Players[player].getSpeed() > 0.0f)
527 | boOtherPlayersActive = true;
528 | }
529 |
530 | boCheckWinner = true;
531 |
532 | }
533 |
534 | if(mPrefs.DrawRecognizer())
535 | mRecognizer.doMovement(TimeDt);
536 |
537 | }
538 |
539 | Cam.doCameraMovement(Players[OWN_PLAYER],TimeCurrent, TimeDt);
540 |
541 | gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
542 |
543 | // Load identity
544 | gl.glMatrixMode(GL10.GL_PROJECTION);
545 | gl.glLoadIdentity();
546 | Visual.doPerspective(gl, mCurrentGridSize);
547 | gl.glMatrixMode(GL10.GL_MODELVIEW);
548 | gl.glLoadIdentity();
549 | gl.glLightfv(GL10.GL_LIGHT1, GL10.GL_POSITION, Cam.ReturnCamBuffer());
550 |
551 | gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT | GL10.GL_STENCIL_BUFFER_BIT);
552 | gl.glEnable(GL10.GL_BLEND);
553 |
554 | Cam.doLookAt(gl);
555 |
556 | gl.glDisable(GL10.GL_LIGHTING);
557 | gl.glDisable(GL10.GL_BLEND);
558 | gl.glDepthMask(false);
559 | gl.glDisable(GL10.GL_DEPTH_TEST);
560 |
561 | World.drawSkyBox(gl);
562 | World.drawFloorTextured(gl);
563 |
564 | gl.glDepthMask(true);
565 | gl.glEnable(GL10.GL_DEPTH_TEST);
566 |
567 | if(mPrefs.DrawRecognizer())
568 | mRecognizer.draw(gl, RecognizerModel);
569 |
570 | World.drawWalls(gl);
571 |
572 | Lights.setupLights(gl, LightType.E_WORLD_LIGHTS);
573 |
574 | for(player = 0; player < mCurrentPlayers; player++)
575 | {
576 | if(player == 0 || Players[player].isVisible(Cam))
577 | Players[player].drawCycle(gl, TimeCurrent, TimeDt, Lights, ExplodeTex);
578 |
579 | Players[player].drawTrails(TrailRenderer,Cam);
580 | }
581 |
582 | if(boCheckWinner)
583 | {
584 | if(!boOwnPlayerActive && boOtherPlayersActive)
585 | {
586 | tronHUD.displayLose();
587 | }
588 | else if(boOwnPlayerActive && !boOtherPlayersActive)
589 | {
590 | tronHUD.displayWin();
591 | Players[OWN_PLAYER].setSpeed(0.0f);
592 | }
593 | }
594 |
595 | tronHUD.draw(Visual,TimeDt,Players[OWN_PLAYER].getScore());
596 | }
597 |
598 | }
599 |
--------------------------------------------------------------------------------
/GlTron/src/com/glTron/Game/Player.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Iain Churcher
3 | *
4 | * Based on GLtron by Andreas Umbach (www.gltron.org)
5 | *
6 | * This file is part of GL TRON.
7 | *
8 | * GL TRON is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * GL TRON is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with GL TRON. If not, see .
20 | *
21 | */
22 |
23 | package com.glTron.Game;
24 |
25 | import java.util.Random;
26 |
27 | import javax.microedition.khronos.opengles.GL10;
28 |
29 | import android.util.Log;
30 |
31 | import com.glTron.Sound.SoundManager;
32 | import com.glTron.Video.*;
33 |
34 | public class Player {
35 |
36 |
37 | private Model Cycle;
38 | private int Player_num;
39 | private int Direction;
40 | private int LastDirection;
41 | private Explosion Explode;
42 |
43 | private int Score;
44 |
45 | GLTexture _ExplodeTex;
46 |
47 | private Segment[] Trails = new Segment[1000] ;
48 |
49 | private HUD tronHUD; // Allow messages to be added to console
50 |
51 |
52 | private int trailOffset;
53 | private float trailHeight;
54 |
55 | private float Speed;
56 | public long TurnTime;
57 | public final float DIRS_X[] = {0.0f, -1.0f, 0.0f, 1.0f};
58 | public final float DIRS_Y[] = {-1.0f, 0.0f, 1.0f, 0.0f};
59 | private final float SPEED_OZ_FREQ = 1200.0f;
60 | private final float SPEED_OZ_FACTOR = 0.09f;
61 |
62 | private final float dirangles[] = { 0.0f, -90.0f, -180.0f, 90.0f, 180.0f, -270.0f };
63 | public final int TURN_LEFT = 3;
64 | public final int TURN_RIGHT = 1;
65 | public final int TURN_LENGTH = 200;
66 | public final float TRAIL_HEIGHT = 3.5f;
67 | private final float EXP_RADIUS_MAX = 30.0f;
68 | private final float EXP_RADIUS_DELTA = 0.01f;
69 |
70 | private TrailMesh Trailmesh;
71 |
72 | private float exp_radius;
73 |
74 | private final float START_POS[][] = {
75 | { 0.5f, 0.25f},
76 | {0.75f, 0.5f},
77 | {0.5f, 0.4f},
78 | {0.25f, 0.5f},
79 | {0.25f, 0.25f},
80 | {0.65f, 0.35f}
81 | };
82 |
83 | private final float ColourDiffuse[][] = {
84 | { 0.0f, 0.1f, 0.900f, 1.000f}, // Blue
85 | { 1.00f, 0.550f, 0.140f, 1.000f}, // Yellow
86 | { 0.750f, 0.020f, 0.020f, 1.000f}, // Red
87 | { 0.800f, 0.800f, 0.800f, 1.000f}, // Grey
88 | { 0.120f, 0.750f, 0.0f, 1.000f}, // Green
89 | { 0.750f, 0.0f, 0.35f, 1.000f} // Purple
90 | };
91 |
92 | private final float ColourSpecular[][] = {
93 | { 0.0f, 0.1f, 0.900f, 1.000f}, // Blue
94 | {0.500f, 0.500f, 0.000f, 1.000f}, // Yellow
95 | {0.750f, 0.020f, 0.020f, 1.000f}, // Red
96 | {1.00f, 1.00f, 1.00f, 1.000f}, // Grey
97 | {0.050f, 0.500f, 0.00f, 1.00f}, // Green
98 | {0.500f, 0.000f, 0.500f, 1.00f}, // Purple
99 | };
100 |
101 | private final float ColourAlpha[][] = {
102 | {0.0f, 0.1f, 0.900f, 0.600f}, // Blue
103 | {1.000f, 0.850f, 0.140f, 0.600f}, // Yellow
104 | {0.750f, 0.020f, 0.020f, 0.600f}, // Red
105 | {0.700f, 0.700f, 0.700f, 0.600f}, // Grey
106 | {0.120f, 0.700f, 0.000f, 0.600f}, // Green
107 | {0.720f, 0.000f, 0.300f, 0.600f} // Purple
108 | };
109 |
110 | private static boolean ColourTaken[] = {false,false,false,false,false,false};
111 | private int mPlayerColourIndex;
112 |
113 | // private final int MAX_LOD_LEVEL = 3;
114 | private final int LOD_DIST[][] = {
115 | { 1000, 1000, 1000 },
116 | {100, 200, 400},
117 | {30,100,200},
118 | {10,30,150}
119 | };
120 |
121 | public Player(int player_number, float gridSize, Model mesh, HUD hud)
122 | {
123 | int colour = 0;
124 | boolean done = false;
125 |
126 | Random rand = new Random();
127 | Direction = rand.nextInt(3); // accepts values 0..3;
128 | LastDirection = Direction;
129 |
130 | Trails[0] = new Segment();
131 | trailOffset = 0;
132 | Trails[trailOffset].vStart.v[0] = START_POS[player_number][0] * gridSize;
133 | Trails[trailOffset].vStart.v[1] = START_POS[player_number][1] * gridSize;
134 | Trails[trailOffset].vDirection.v[0] = 0.0f;
135 | Trails[trailOffset].vDirection.v[1] = 0.0f;
136 |
137 | trailHeight = TRAIL_HEIGHT;
138 |
139 | tronHUD = hud;
140 |
141 | Speed = 10.0f;
142 | exp_radius = 0.0f;
143 |
144 | Cycle = mesh;
145 | Player_num = player_number;
146 | Score = 0;
147 |
148 | // Select Colour
149 | if(player_number == GLTronGame.OWN_PLAYER)
150 | {
151 | // Re-init the colour taken array - must now create players sequentially for this to work
152 | for(colour = 0; colour < GLTronGame.MAX_PLAYERS; colour++)
153 | {
154 | ColourTaken[colour] = false;
155 | }
156 |
157 | ColourTaken[GLTronGame.mPrefs.PlayerColourIndex()] = true;
158 | mPlayerColourIndex = GLTronGame.mPrefs.PlayerColourIndex();
159 | }
160 | else
161 | {
162 | while(!done)
163 | {
164 | if(!ColourTaken[colour])
165 | {
166 | ColourTaken[colour] = true;
167 | mPlayerColourIndex = colour;
168 | done = true;
169 | }
170 | colour++;
171 | }
172 | }
173 |
174 | }
175 |
176 |
177 | public void doTurn(int direction, long current_time)
178 | {
179 | float x = getXpos();
180 | float y = getYpos();
181 |
182 | trailOffset++;
183 | Trails[trailOffset] = new Segment();
184 | Trails[trailOffset].vStart.v[0] = x;
185 | Trails[trailOffset].vStart.v[1] = y;
186 | Trails[trailOffset].vDirection.v[0] = 0.0f;
187 | Trails[trailOffset].vDirection.v[1] = 0.0f;
188 |
189 | LastDirection = Direction;
190 | Direction = (Direction + direction) % 4;
191 | TurnTime = current_time;
192 | }
193 |
194 |
195 | public void doMovement(long dt, long current_time, Segment walls[], Player plyers[])
196 | {
197 | float fs;
198 | float t;
199 |
200 | if(Speed > 0.0f) // Player is still alive
201 | {
202 | fs = (float) (1.0f - SPEED_OZ_FACTOR + SPEED_OZ_FACTOR *
203 | Math.cos(0.0f * (float)Math.PI / 4.0f +
204 | (current_time % SPEED_OZ_FREQ) *
205 | 2.0f * Math.PI / SPEED_OZ_FREQ));
206 |
207 | t = dt / 100.0f * Speed * fs;
208 |
209 | Trails[trailOffset].vDirection.v[0] += t * DIRS_X[Direction];
210 | Trails[trailOffset].vDirection.v[1] += t * DIRS_Y[Direction];
211 |
212 | doCrashTestWalls(walls);
213 | doCrashTestPlayer(plyers);
214 |
215 | }
216 | else
217 | {
218 | if(trailHeight > 0.0f)
219 | {
220 | trailHeight -= (dt * TRAIL_HEIGHT) / 1000.0f;
221 | }
222 | if(exp_radius < EXP_RADIUS_MAX)
223 | {
224 | exp_radius += (dt * EXP_RADIUS_DELTA);
225 | }
226 | }
227 | }
228 |
229 | public void drawCycle(GL10 gl, long curr_time, long time_dt, Lighting Lights, GLTexture ExplodeTex)
230 | {
231 | gl.glPushMatrix();
232 | gl.glTranslatef(getXpos(), getYpos(), 0.0f);
233 |
234 | doCycleRotation(gl,curr_time);
235 |
236 | //Lights.setupLights(gl, LightType.E_CYCLE_LIGHTS);
237 |
238 | gl.glEnable(GL10.GL_LIGHTING);
239 | gl.glEnable(GL10.GL_DEPTH_TEST);
240 | gl.glDepthMask(true);
241 | if(exp_radius == 0.0f)
242 | {
243 | gl.glEnable(GL10.GL_NORMALIZE);
244 | gl.glTranslatef(0.0f, 0.0f, Cycle.GetBBoxSize().v[2] / 2.0f);
245 | gl.glEnable(GL10.GL_CULL_FACE);
246 | //gl.glTranslatef((GridSize/2.0f), (GridSize/2.0f), 0.0f);
247 | //gl.glTranslatef(_Player._PlayerXpos, _Player._PlayerYpos, 0.0f);
248 | Cycle.Draw(gl,ColourSpecular[Player_num],ColourDiffuse[mPlayerColourIndex]);
249 | gl.glDisable(GL10.GL_CULL_FACE);
250 | }
251 | else if(exp_radius < EXP_RADIUS_MAX)
252 | {
253 | // Draw Crash if crashed..
254 | if(getExplode() != null)
255 | {
256 | if(getExplode().runExplode())
257 | {
258 | gl.glEnable(GL10.GL_BLEND);
259 |
260 | Explode.Draw(gl, time_dt, ExplodeTex);
261 |
262 | gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
263 | gl.glTranslatef(0.0f, 0.0f, Cycle.GetBBoxSize().v[2] / 2.0f);
264 | //LightBike.Explode(gl, _Player.getExplode().getRadius());
265 | }
266 | }
267 | }
268 |
269 | gl.glDisable(GL10.GL_BLEND);
270 | gl.glDisable(GL10.GL_LIGHTING);
271 | gl.glPopMatrix();
272 |
273 | }
274 |
275 | public void doCrashTestWalls(Segment Walls[])
276 | {
277 | Segment Current = Trails[trailOffset];
278 | Vec V;
279 |
280 | for(int j=0; j < 4; j++)
281 | {
282 | V = Current.Intersect(Walls[j]);
283 |
284 | if(V != null)
285 | {
286 | if(Current.t1 >= 0.0f && Current.t1 < 1.0f && Current.t2 >= 0.0f && Current.t2 < 1.0f)
287 | {
288 | StringBuilder sb1 = new StringBuilder();
289 |
290 | Current.vDirection.v[0] = V.v[0] - Current.vStart.v[0];
291 | Current.vDirection.v[1] = V.v[1] - Current.vStart.v[1];
292 | Speed = 0.0f;
293 | Explode = new Explosion(0.0f);
294 |
295 | sb1.append("Player ");
296 | sb1.append(Player_num);
297 | sb1.append(" CRASH wall!");
298 | tronHUD.addLineToConsole(sb1.toString());
299 |
300 | if(GLTronGame.mPrefs.PlaySFX())
301 | SoundManager.playSound(GLTronGame.CRASH_SOUND, 1.0f);
302 |
303 | Log.e("GLTRON", "Wall CRASH");
304 | break;
305 | }
306 | }
307 | }
308 |
309 | }
310 |
311 | public void doCrashTestPlayer(Player players[])
312 | {
313 | int j,k;
314 | Segment Current = Trails[trailOffset];
315 | Segment Wall;
316 | Vec V;
317 |
318 | for(j = 0; j < GLTronGame.mCurrentPlayers; j++)
319 | {
320 |
321 | if(players[j].getTrailHeight() < TRAIL_HEIGHT)
322 | continue;
323 |
324 | for(k =0; k < players[j].getTrailOffset() + 1; k++)
325 | {
326 | if(players[j] == this && k >= trailOffset - 1)
327 | break;
328 |
329 | Wall = players[j].getTrail(k);
330 |
331 | V = Current.Intersect(Wall);
332 |
333 | if(V != null)
334 | {
335 | if(Current.t1 >= 0.0f && Current.t1 < 1.0f && Current.t2 >= 0.0f && Current.t2 < 1.0f)
336 | {
337 | StringBuilder sb1 = new StringBuilder();
338 |
339 | Current.vDirection.v[0] = V.v[0] - Current.vStart.v[0];
340 | Current.vDirection.v[1] = V.v[1] - Current.vStart.v[1];
341 | Speed = 0.0f;
342 | Explode = new Explosion(0.0f);
343 |
344 | sb1.append("Player ");
345 | sb1.append(Player_num);
346 | sb1.append(" CRASH trail!");
347 | tronHUD.addLineToConsole(sb1.toString());
348 |
349 | players[j].addScore(10);
350 |
351 | if(GLTronGame.mPrefs.PlaySFX())
352 | SoundManager.playSound(GLTronGame.CRASH_SOUND, 1.0f);
353 |
354 | Log.e("GLTRON", "Wall CRASH");
355 | break;
356 | }
357 | }
358 | }
359 | }
360 | }
361 |
362 | private void doCycleRotation(GL10 gl, long CurrentTime)
363 | {
364 | long time = CurrentTime - TurnTime;
365 | float dirAngle;
366 | float axis = 1.0f;
367 | float Angle;
368 |
369 | dirAngle = getDirAngle(time);
370 |
371 | gl.glRotatef(dirAngle, 0.0f, 0.0f, 1.0f);
372 |
373 | if((time < TURN_LENGTH) && (LastDirection != Direction))
374 | {
375 | if( (Direction < LastDirection) && (LastDirection != 3))
376 | {
377 | axis = -1.0f;
378 | }
379 | else if( ((LastDirection == 3) && (Direction == 2)) ||
380 | ((LastDirection == 0) && (Direction == 3)) )
381 | {
382 | axis = -1.0f;
383 | }
384 | Angle = (float)Math.sin((Math.PI * time / TURN_LENGTH)) * 25.0f;
385 | gl.glRotatef(Angle, 0.0f, (axis * -1.0f), 0.0f);
386 | }
387 | }
388 |
389 | public void drawTrails(Trails_Renderer render, Camera cam)
390 | {
391 | if(trailHeight > 0.0f)
392 | {
393 | Trailmesh = new TrailMesh(this);
394 | render.Render(Trailmesh);
395 | Trailmesh = null;
396 | render.drawTrailLines(Trails,trailOffset,trailHeight,cam);
397 | }
398 | }
399 |
400 | public boolean isVisible(Camera cam)
401 | {
402 | Vec v1;
403 | Vec v2;
404 | Vec tmp = new Vec(getXpos(),getYpos(),0.0f);
405 | int lod_level = 2;
406 | float d,s;
407 | int i;
408 | int LC_LOD = 3;
409 | float fov = 120;
410 |
411 | boolean retValue;
412 |
413 | v1 = cam._target.Sub(cam._cam);
414 | v1.Normalise();
415 |
416 | v2 = cam._cam.Sub(tmp);
417 |
418 | d = v2.Length();
419 |
420 | for(i=0;i= LOD_DIST[lod_level][i]; i++);
421 |
422 | if(i >= LC_LOD)
423 | {
424 | retValue = false;
425 | }
426 | else
427 | {
428 | v2 = tmp.Sub(cam._cam);
429 | v2.Normalise();
430 |
431 | s = v1.Dot(v2);
432 | d = (float)Math.cos((fov/2) * 2 * Math.PI / 360.0f);
433 |
434 | if(s < d - (Cycle.GetBBoxRadius() * 2.0f))
435 | {
436 | retValue = false;
437 | }
438 | else
439 | {
440 | retValue = true;
441 | }
442 |
443 | }
444 |
445 | return retValue;
446 | }
447 |
448 | private float getDirAngle(long time)
449 | {
450 | int last_dir;
451 | float dir_angle;
452 |
453 | if(time < TURN_LENGTH)
454 | {
455 | last_dir = LastDirection;
456 | if(Direction == 3 && last_dir ==2)
457 | {
458 | last_dir = 4;
459 | }
460 | if(Direction == 2 && last_dir == 3)
461 | {
462 | last_dir = 5;
463 | }
464 | dir_angle = ((TURN_LENGTH - time) * dirangles[last_dir] +
465 | time * dirangles[Direction]) / TURN_LENGTH;
466 | }
467 | else
468 | {
469 | dir_angle = dirangles[Direction];
470 | }
471 | return dir_angle;
472 | }
473 |
474 | public Explosion getExplode()
475 | {
476 | return Explode;
477 | }
478 |
479 | public Segment getTrail(int offset)
480 | {
481 | return Trails[offset];
482 | }
483 |
484 | public Segment[] getTrails()
485 | {
486 | return Trails;
487 | }
488 |
489 | public float getTrailHeight()
490 | {
491 | return trailHeight;
492 | }
493 |
494 | public int getTrailOffset()
495 | {
496 | return trailOffset;
497 | }
498 |
499 | public void setExplodeTex(GLTexture tex)
500 | {
501 | _ExplodeTex = tex;
502 | }
503 |
504 | public float getXpos()
505 | {
506 | return Trails[trailOffset].vStart.v[0] + Trails[trailOffset].vDirection.v[0];
507 | }
508 |
509 | public float getYpos()
510 | {
511 | return Trails[trailOffset].vStart.v[1] + Trails[trailOffset].vDirection.v[1];
512 | }
513 |
514 | public int getDirection()
515 | {
516 | return Direction;
517 | }
518 |
519 | public int getLastDirection()
520 | {
521 | return LastDirection;
522 | }
523 |
524 | public float getSpeed()
525 | {
526 | return Speed;
527 | }
528 |
529 | public void setSpeed(float sp)
530 | {
531 | Speed = sp;
532 | }
533 |
534 | public float[] getColorAlpha()
535 | {
536 | return ColourAlpha[mPlayerColourIndex];
537 | }
538 |
539 | public float[] getColorDiffuse()
540 | {
541 | return ColourDiffuse[mPlayerColourIndex];
542 | }
543 |
544 | public void addScore(int val)
545 | {
546 | if(Speed > 0.0f)
547 | Score += val;
548 | }
549 |
550 | public int getScore()
551 | {
552 | return Score;
553 | }
554 |
555 | }
556 |
--------------------------------------------------------------------------------
/GlTron/src/com/glTron/Game/Recognizer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Iain Churcher
3 | *
4 | * Based on GLtron by Andreas Umbach (www.gltron.org)
5 | *
6 | * This file is part of GL TRON.
7 | *
8 | * GL TRON is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * GL TRON is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with GL TRON. If not, see .
20 | *
21 | */
22 | package com.glTron.Game;
23 |
24 | import java.nio.FloatBuffer;
25 |
26 | import javax.microedition.khronos.opengles.GL10;
27 |
28 | import android.util.FloatMath;
29 |
30 | import com.glTron.Video.GraphicUtils;
31 | import com.glTron.Video.Model;
32 | import com.glTron.Video.Vec;
33 |
34 | public class Recognizer {
35 |
36 | /*
37 | * Private items
38 | */
39 | private float mAlpha;
40 | private float mGridSize;
41 | private FloatBuffer mColour;
42 | private FloatBuffer mShadow;
43 |
44 | /*
45 | * Constants
46 | */
47 | private final float xv[] = {0.5f, 0.3245f, 0.6f, 0.5f, 0.68f, -0.3f};
48 | private final float yv[] = {0.8f, 1.0f, 0.0f, 0.2f, 0.2f, 0.0f};
49 | //private final float colour[] = {0.05f, 0.14f, 0.05f, 0.50f};
50 | private final float colour[] = {0.6f, 0.16f, 0.2f, 0.50f};
51 |
52 | private final float ShadowMatrix[] = {
53 | 4.0f, 0.0f, 0.0f, 0.0f,
54 | 0.0f, 4.0f, 0.0f, 0.0f,
55 | -2.0f, -2.0f, 0.0f, 0.0f,
56 | 0.0f, 0.0f, 0.0f, 4.0f
57 | };
58 |
59 | private final float scaleFactor = 0.25f;
60 | private final float HEIGHT = 40.0f;
61 |
62 | public Recognizer(float gridSize)
63 | {
64 | mAlpha = 0.0f;
65 | mGridSize = gridSize;
66 | mColour = GraphicUtils.ConvToFloatBuffer(colour);
67 | mShadow = GraphicUtils.ConvToFloatBuffer(ShadowMatrix);
68 | }
69 |
70 | public void doMovement(long dt)
71 | {
72 | mAlpha += dt / 2000.0f;
73 | }
74 |
75 | public void reset()
76 | {
77 | mAlpha = 0.0f;
78 | }
79 |
80 | public void draw(GL10 gl, Model mesh)
81 | {
82 | Vec p,v;
83 | float dirx;
84 |
85 | gl.glPushMatrix();
86 |
87 | p = getPosition(mesh);
88 | v = getVelocity();
89 |
90 | dirx = getAngle(v);
91 |
92 | gl.glTranslatef(p.v[0], p.v[1], HEIGHT);
93 | gl.glRotatef(dirx, 0.0f, 0.0f, 1.0f);
94 |
95 | gl.glScalef(scaleFactor, scaleFactor, scaleFactor);
96 |
97 | gl.glDisable(GL10.GL_LIGHT0);
98 | gl.glDisable(GL10.GL_LIGHT1);
99 | gl.glLightfv(GL10.GL_LIGHT2, GL10.GL_SPECULAR, mColour);
100 | gl.glEnable(GL10.GL_LIGHT2);
101 |
102 | gl.glDisable(GL10.GL_BLEND);
103 | gl.glEnable(GL10.GL_CULL_FACE);
104 |
105 | gl.glEnable(GL10.GL_LIGHTING);
106 |
107 | gl.glEnable(GL10.GL_POLYGON_OFFSET_FILL);
108 | gl.glPolygonOffset(1.0f, 1.0f);
109 |
110 | gl.glEnable(GL10.GL_NORMALIZE);
111 | gl.glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
112 |
113 | mesh.Draw(gl);
114 |
115 | gl.glDisable(GL10.GL_POLYGON_OFFSET_FILL);
116 | gl.glDisable(GL10.GL_LIGHT2);
117 | gl.glEnable(GL10.GL_LIGHT1);
118 | gl.glDisable(GL10.GL_LIGHTING);
119 |
120 | // TODO:
121 | // Original glTron used to render another model in wireframe mode over the existing recognizer
122 | // OpenGL ES does not support this wireframe rendering mode. Need to come up with a replacement
123 |
124 | gl.glDisable(GL10.GL_CULL_FACE);
125 |
126 | gl.glPopMatrix();
127 |
128 | // Draw the shadow
129 | gl.glEnable(GL10.GL_STENCIL_TEST);
130 | gl.glStencilOp(GL10.GL_REPLACE, GL10.GL_REPLACE, GL10.GL_REPLACE);
131 | gl.glStencilFunc(GL10.GL_GREATER, 1, 1);
132 | gl.glEnable(GL10.GL_BLEND);
133 | gl.glColor4f(0.0f,0.0f,0.0f,0.8f);
134 | gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
135 |
136 | gl.glPushMatrix();
137 | gl.glMultMatrixf(mShadow);
138 | gl.glTranslatef(p.v[0], p.v[1], HEIGHT);
139 | gl.glRotatef(dirx, 0.0f, 0.0f, 1.0f);
140 | gl.glScalef(scaleFactor,scaleFactor,scaleFactor);
141 | gl.glEnable(GL10.GL_NORMALIZE);
142 | mesh.Draw(gl);
143 | gl.glDisable(GL10.GL_STENCIL_TEST);
144 | gl.glDisable(GL10.GL_BLEND);
145 | gl.glDisable(GL10.GL_CULL_FACE);
146 | gl.glPopMatrix();
147 |
148 | }
149 |
150 | /*
151 | * Private methods
152 | */
153 | private float getAngle(Vec velocity)
154 | {
155 | float dxval = velocity.v[0];
156 | float dyval = velocity.v[0];
157 |
158 | float phi = (float)Math.acos(dxval / FloatMath.sqrt(dxval * dxval + dyval * dyval));
159 |
160 | if(dyval < 0.0f)
161 | phi = (float)(2.0f * Math.PI - phi);
162 |
163 | return (float)((phi + Math.PI / 2.0f) * 180.0f / Math.PI);
164 | }
165 |
166 | private Vec getPosition(Model mesh)
167 | {
168 | float x,y;
169 | float max = mesh.GetBBoxSize().v[0] * scaleFactor;
170 | float boundary = mGridSize - max;
171 | Vec pos;
172 |
173 | x = (max + (getx() + 1.0f) * boundary) / 2.0f;
174 | y = (max + (gety() + 1.0f) * boundary) / 2.0f;
175 |
176 | pos = new Vec(x,y,0.0f);
177 |
178 | return pos;
179 | }
180 |
181 | private Vec getVelocity()
182 | {
183 | Vec vel = new Vec(getdx() * mGridSize / 100.0f, getdy() * mGridSize / 100.0f,0.0f);
184 | return vel;
185 | }
186 |
187 | private float getx()
188 | {
189 | return (xv[0] * FloatMath.sin(xv[1] * mAlpha + xv[2]) - xv[3] * FloatMath.sin(xv[4] * mAlpha + xv[5]));
190 | }
191 |
192 | private float gety()
193 | {
194 | return (yv[0] * FloatMath.cos(yv[1] * mAlpha + yv[2] - yv[3] * FloatMath.sin(yv[4] * mAlpha + yv[5])));
195 | }
196 |
197 | private float getdx()
198 | {
199 | return (xv[1] * xv[0] * FloatMath.cos(xv[1] * mAlpha + xv[2]) - xv[4] * xv[3] * FloatMath.cos(xv[4] * mAlpha + xv[5]));
200 | }
201 |
202 | private float getdy()
203 | {
204 | return -(yv[1] * yv[0] * FloatMath.sin(yv[1] * mAlpha + yv[2]) - yv[4] * yv[3] * FloatMath.sin(yv[4] * mAlpha + yv[5]));
205 | }
206 |
207 | }
208 |
--------------------------------------------------------------------------------
/GlTron/src/com/glTron/Game/UserPrefs.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Iain Churcher
3 | *
4 | * Based on GLtron by Andreas Umbach (www.gltron.org)
5 | *
6 | * Preferences implementation based on work by Noah NZM TECH
7 | *
8 | * This file is part of GL TRON.
9 | *
10 | * GL TRON is free software: you can redistribute it and/or modify
11 | * it under the terms of the GNU General Public License as published by
12 | * the Free Software Foundation, either version 3 of the License, or
13 | * (at your option) any later version.
14 | *
15 | * GL TRON is distributed in the hope that it will be useful,
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | * GNU General Public License for more details.
19 | *
20 | * You should have received a copy of the GNU General Public License
21 | * along with GL TRON. If not, see .
22 | *
23 | */
24 |
25 | package com.glTron.Game;
26 |
27 | import android.content.Context;
28 | import android.content.SharedPreferences;
29 | import android.preference.PreferenceManager;
30 | import com.glTron.Game.Camera;
31 |
32 | public class UserPrefs {
33 |
34 | // Pref defaults
35 | private final int C_PREF_FOLLOW_CAM = 1;
36 | private final int C_PREF_FOLLOW_CAM_FAR = 2;
37 | private final int C_PREF_FOLLOW_CAM_CLOSE = 3;
38 | private final int C_PREF_BIRD_CAM = 4;
39 |
40 | private final String C_DEFAULT_CAM_TYPE = "1";
41 |
42 | private static final float C_GRID_SIZES[] = {360.0f, 720.0f, 1440.0f};
43 |
44 | private static final float C_SPEED[] = {5.0f, 10.0f, 15.0f, 20.0f};
45 |
46 | private Context mContext;
47 | private Camera.CamType mCameraType;
48 |
49 | private boolean mMusic;
50 | private boolean mSFX;
51 |
52 | private boolean mFPS;
53 | private boolean mDrawRecog;
54 |
55 | private int mNumOfPlayers;
56 | private float mGridSize;
57 | private float mSpeed;
58 | private int mPlayerColourIndex;
59 |
60 | public UserPrefs(Context ctx)
61 | {
62 | mContext = ctx;
63 | ReloadPrefs();
64 | }
65 |
66 | public void ReloadPrefs()
67 | {
68 | int cameraType;
69 | int gridIndex;
70 | int speedIndex;
71 |
72 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
73 | cameraType = Integer.valueOf(prefs.getString("cameraPref",C_DEFAULT_CAM_TYPE));
74 |
75 | switch(cameraType)
76 | {
77 | case C_PREF_FOLLOW_CAM:
78 | mCameraType = Camera.CamType.E_CAM_TYPE_FOLLOW;
79 | break;
80 | case C_PREF_FOLLOW_CAM_FAR:
81 | mCameraType = Camera.CamType.E_CAM_TYPE_FOLLOW_FAR;
82 | break;
83 | case C_PREF_FOLLOW_CAM_CLOSE:
84 | mCameraType = Camera.CamType.E_CAM_TYPE_FOLLOW_CLOSE;
85 | break;
86 | case C_PREF_BIRD_CAM:
87 | mCameraType = Camera.CamType.E_CAM_TYPE_BIRD;
88 | break;
89 | default:
90 | mCameraType = Camera.CamType.E_CAM_TYPE_FOLLOW;
91 | break;
92 | }
93 |
94 | mMusic = prefs.getBoolean("musicOption", true);
95 | mSFX = prefs.getBoolean("sfxOption", true);
96 | mFPS = prefs.getBoolean("fpsOption", false);
97 | mNumOfPlayers = Integer.valueOf(prefs.getString("playerNumber", "4"));
98 | gridIndex = Integer.valueOf(prefs.getString("arenaSize", "1"));
99 | mGridSize = C_GRID_SIZES[gridIndex];
100 | speedIndex = Integer.valueOf(prefs.getString("gameSpeed", "1"));
101 | mSpeed = C_SPEED[speedIndex];
102 | mPlayerColourIndex = Integer.valueOf(prefs.getString("playerBike","0"));
103 | mDrawRecog = prefs.getBoolean("drawRecog", true);
104 | }
105 |
106 | public Camera.CamType CameraType()
107 | {
108 |
109 | return mCameraType;
110 | }
111 |
112 | public boolean PlayMusic()
113 | {
114 | return mMusic;
115 | }
116 |
117 | public boolean PlaySFX()
118 | {
119 | return mSFX;
120 | }
121 |
122 | public boolean DrawFPS()
123 | {
124 | return mFPS;
125 | }
126 |
127 | public int NumberOfPlayers()
128 | {
129 | return mNumOfPlayers;
130 | }
131 |
132 | public float GridSize()
133 | {
134 | return mGridSize;
135 | }
136 |
137 | public float Speed()
138 | {
139 | return mSpeed;
140 | }
141 |
142 | public int PlayerColourIndex()
143 | {
144 | return mPlayerColourIndex;
145 | }
146 |
147 | public boolean DrawRecognizer()
148 | {
149 | return mDrawRecog;
150 | }
151 | }
152 |
--------------------------------------------------------------------------------
/GlTron/src/com/glTron/OpenGLRenderer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Iain Churcher
3 | *
4 | * Based on GLtron by Andreas Umbach (www.gltron.org)
5 | *
6 | * This file is part of GL TRON.
7 | *
8 | * GL TRON is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * GL TRON is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with GL TRON. If not, see .
20 | *
21 | */
22 |
23 |
24 | package com.glTron;
25 |
26 | import javax.microedition.khronos.egl.EGLConfig;
27 | import javax.microedition.khronos.opengles.GL10;
28 |
29 | import android.content.Context;
30 | import android.opengl.GLSurfaceView;
31 | import android.os.Handler;
32 | import android.util.Log;
33 |
34 | import com.glTron.Game.GLTronGame;
35 |
36 | public class OpenGLRenderer implements GLSurfaceView.Renderer {
37 |
38 | GLTronGame Game = new GLTronGame();
39 |
40 | Context mContext;
41 |
42 | String Debug;
43 | StringBuffer sb = new StringBuffer(40);
44 |
45 | private int frameCount = 0;
46 |
47 | public OpenGLRenderer(Context context, int win_width, int win_height)
48 | {
49 | mContext = context;
50 | Log.e("GLTRON", "Renderer Constructor: Create Video Object");
51 | Debug = sb.append("Screen size = ").append(win_width).append(",").append(win_height).toString();
52 | Log.e("GLTRON", Debug);
53 | Game.updateScreenSize(win_width, win_height);
54 | }
55 |
56 | public void setUI_Handler(Handler handler)
57 | {
58 | Game.setUI_Handler(handler);
59 | }
60 |
61 | public void onTouch(float x, float y)
62 | {
63 | Game.addTouchEvent(x, y);
64 | }
65 |
66 | public void onPause()
67 | {
68 | Game.pauseGame();
69 | }
70 |
71 | public void onResume()
72 | {
73 | Game.resumeGame();
74 | }
75 |
76 | public void onSurfaceCreated(GL10 gl, EGLConfig config) {
77 |
78 | Log.e("GLTRON", "Renderer: Surface Created Do perspective");
79 |
80 | //Game.initialiseGame(mContext, gl);
81 | Game.drawSplash(mContext, gl);
82 | }
83 |
84 |
85 | @Override
86 | public void onSurfaceChanged(GL10 gl, int w, int h) {
87 | Log.e("GLTRON", "Renderer: Surface changed");
88 | sb=null;
89 | sb = new StringBuffer(40);
90 | Debug = sb.append("Screen size = ").append(w).append(",").append(h).toString();
91 | Log.e("GLTRON", Debug);
92 | Game.updateScreenSize(w, h);
93 | }
94 |
95 | @Override
96 | public void onDrawFrame(GL10 gl) {
97 |
98 | if(frameCount == 1)
99 | {
100 | Game.initialiseGame();
101 | }
102 | else if(frameCount > 1)
103 | {
104 | Game.RunGame();
105 | }
106 |
107 | frameCount++;
108 |
109 | }
110 |
111 |
112 | }
113 |
--------------------------------------------------------------------------------
/GlTron/src/com/glTron/OpenGLView.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Iain Churcher
3 | *
4 | * Based on GLtron by Andreas Umbach (www.gltron.org)
5 | *
6 | * This file is part of GL TRON.
7 | *
8 | * GL TRON is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * GL TRON is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with GL TRON. If not, see .
20 | *
21 | */
22 |
23 | package com.glTron;
24 |
25 | import android.content.Context;
26 | import android.opengl.GLSurfaceView;
27 | import android.os.Handler;
28 | import android.view.MotionEvent;
29 |
30 | public class OpenGLView extends GLSurfaceView {
31 |
32 | private OpenGLRenderer _renderer;
33 |
34 | private float _x = 0;
35 | private float _y = 0;
36 |
37 | public OpenGLView(Context context,int width, int height) {
38 | super(context);
39 | _renderer = new OpenGLRenderer(context, width, height);
40 | setRenderer(_renderer);
41 | }
42 |
43 | public void setUI_Handler(Handler handler)
44 | {
45 | _renderer.setUI_Handler(handler);
46 | }
47 |
48 | public void onPause()
49 | {
50 | _renderer.onPause();
51 | }
52 |
53 | public void onResume()
54 | {
55 | _renderer.onResume();
56 | }
57 |
58 | public boolean onTouchEvent(final MotionEvent event) {
59 |
60 | if(event.getAction() == MotionEvent.ACTION_DOWN) {
61 | _x = event.getX();
62 | _y = event.getY();
63 | _renderer.onTouch(_x, _y);
64 |
65 | }
66 |
67 | return true;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/GlTron/src/com/glTron/Preferences.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Iain Churcher
3 | * Copyright © 2012 Noah NZM Tech
4 | *
5 | * Based on GLtron by Andreas Umbach (www.gltron.org)
6 | *
7 | * This file is part of GL TRON.
8 | *
9 | * GL TRON is free software: you can redistribute it and/or modify
10 | * it under the terms of the GNU General Public License as published by
11 | * the Free Software Foundation, either version 3 of the License, or
12 | * (at your option) any later version.
13 | *
14 | * GL TRON is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU General Public License
20 | * along with GL TRON. If not, see .
21 | *
22 | */
23 | package com.glTron;
24 |
25 | import android.os.Bundle;
26 | import android.preference.PreferenceActivity;
27 |
28 | public class Preferences extends PreferenceActivity {
29 | @Override
30 | protected void onCreate(Bundle savedInstanceState) {
31 | // TODO Auto-generated method stub
32 | super.onCreate(savedInstanceState);
33 | addPreferencesFromResource(R.layout.preferences);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/GlTron/src/com/glTron/Sound/SoundManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Iain Churcher
3 | *
4 | * Based on GLtron by Andreas Umbach (www.gltron.org)
5 | *
6 | * This file is part of GL TRON.
7 | *
8 | * GL TRON is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * GL TRON is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with GL TRON. If not, see .
20 | *
21 | */
22 |
23 | package com.glTron.Sound;
24 |
25 | import java.io.IOException;
26 | import java.util.HashMap;
27 |
28 | import android.content.Context;
29 | import android.media.AudioManager;
30 | import android.media.MediaPlayer;
31 | import android.media.SoundPool;
32 |
33 | public class SoundManager {
34 |
35 | // music
36 | private static MediaPlayer mPlayer;
37 |
38 | // sound effects
39 | private static SoundManager _instance;
40 | private static SoundPool mSoundPool;
41 | private static HashMap mSoundPoolMap;
42 | private static AudioManager mAudioManager;
43 | private static Context mContext;
44 |
45 | private static final int MAX_SOUNDS = 10;
46 |
47 | private static int MAX_INDEX = 10;
48 |
49 | private static int mIndexToStream[] = new int[MAX_INDEX];
50 |
51 |
52 | private SoundManager()
53 | {
54 | }
55 |
56 | /*
57 | * Requests the instance if the sound manager and creates it
58 | * if it does not exist
59 | */
60 | static synchronized public SoundManager getInstance()
61 | {
62 | if(_instance == null)
63 | _instance = new SoundManager();
64 | return _instance;
65 | }
66 |
67 | public static void initSounds(Context theContext)
68 | {
69 | mContext = theContext;
70 | mSoundPool = new SoundPool(MAX_SOUNDS,AudioManager.STREAM_MUSIC, 0);
71 | mSoundPoolMap = new HashMap();
72 | mAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
73 | }
74 |
75 | public static void addSound(int Index, int SoundID)
76 | {
77 | mSoundPoolMap.put(Index, mSoundPool.load(mContext, SoundID, 1));
78 | }
79 |
80 | public static void addMusic(int MusicID)
81 | {
82 | // limited to one music stream FIXME
83 | mPlayer = MediaPlayer.create(mContext, MusicID);
84 | }
85 |
86 | public static void playMusic(boolean boLoop)
87 | {
88 | if(mPlayer != null)
89 | {
90 | float streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
91 | streamVolume /= mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
92 |
93 | mPlayer.setLooping(boLoop);
94 | mPlayer.setVolume(streamVolume, streamVolume);
95 | mPlayer.start();
96 | }
97 | }
98 |
99 | public static void stopMusic()
100 | {
101 | if(mPlayer != null)
102 | {
103 | if(mPlayer.isPlaying())
104 | {
105 | mPlayer.stop();
106 | try
107 | {
108 | mPlayer.prepare();
109 | mPlayer.seekTo(0);
110 | }
111 | catch (IOException e)
112 | {
113 | // do nothing here FIXME
114 | }
115 | }
116 | }
117 | }
118 |
119 | public static void playSound(int index, float speed)
120 | {
121 | float streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
122 | streamVolume /= mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
123 | streamVolume *= 0.5;
124 | mIndexToStream[index] = mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, 0, speed);
125 | }
126 |
127 | public static void playSoundLoop(int index, float speed)
128 | {
129 | float streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
130 | streamVolume /= mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
131 | streamVolume *= 0.5;
132 | mIndexToStream[index] = mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, -1, speed);
133 | }
134 |
135 | public static void stopSound(int index)
136 | {
137 | //mSoundPool.stop(mSoundPoolMap.get(index));
138 | mSoundPool.stop(mIndexToStream[index]);
139 | }
140 |
141 | public static void changeRate(int index, float rate)
142 | {
143 | //mSoundPool.setRate(mSoundPoolMap.get(index), rate);
144 | mSoundPool.setRate(mIndexToStream[index], rate);
145 | }
146 |
147 | public static void globalPauseSound()
148 | {
149 | if(mSoundPool != null)
150 | mSoundPool.autoPause();
151 |
152 | if(mPlayer != null && mPlayer.isPlaying())
153 | mPlayer.pause();
154 | }
155 |
156 | public static void globalResumeSound()
157 | {
158 | if(mSoundPool != null)
159 | mSoundPool.autoResume();
160 |
161 | if(mPlayer != null)
162 | mPlayer.start();
163 | }
164 |
165 | public static void cleanup()
166 | {
167 | mSoundPool.release();
168 | mSoundPool = null;
169 | mSoundPoolMap.clear();
170 | mAudioManager.unloadSoundEffects();
171 | _instance = null;
172 | }
173 |
174 | }
175 |
--------------------------------------------------------------------------------
/GlTron/src/com/glTron/Video/Explosion.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Iain Churcher
3 | *
4 | * Based on GLtron by Andreas Umbach (www.gltron.org)
5 | *
6 | * This file is part of GL TRON.
7 | *
8 | * GL TRON is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * GL TRON is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with GL TRON. If not, see .
20 | *
21 | */
22 |
23 | package com.glTron.Video;
24 |
25 | import java.nio.FloatBuffer;
26 |
27 | import javax.microedition.khronos.opengles.GL10;
28 |
29 | public class Explosion {
30 |
31 | private float Radius;
32 |
33 | private final float IMPACT_RADIUS_DELTA = 0.025f;
34 | private final float IMPACT_MAX_RADIUS = 25.0f;
35 |
36 | // Shockwave behaviour constants
37 | private final float SHOCKWAVE_MIN_RADIUS = 0.0f;
38 | private final float SHOCKWAVE_MAX_RADIUS = 45.0f;
39 | private final float SHOCKWAVE_WIDTH = 0.2f;
40 | private final float SHOCKWAVE_SPACING = 6.0f;
41 | private final float SHOCKWAVE_SPEED = 1.2f; // relative to impact radius delta
42 | private final int SHOCKWAVE_SEGMENTS = 25;
43 | private final int NUM_SHOCKWAVES = 3;
44 |
45 | // Glow contants
46 | private final float GLOW_START_OPACITY = 1.2f;
47 | private final float GLOW_INTENSITY = 1.0f;
48 |
49 | // Spire contants
50 | private final float SPIRE_WIDTH = 0.40f;
51 | private final int NUM_SPIRES = 21;
52 |
53 | private GLTexture ExplodeTex;
54 |
55 | public Explosion(float radius)
56 | {
57 | Radius = radius;
58 | }
59 |
60 | public float getRadius()
61 | {
62 | return Radius;
63 | }
64 |
65 | public boolean runExplode()
66 | {
67 | boolean retVal = true;
68 | if(Radius > IMPACT_MAX_RADIUS)
69 | {
70 | retVal = false;
71 | }
72 | return retVal;
73 | }
74 |
75 | public void Draw(GL10 gl, long GameDeltaTime, GLTexture tex)
76 | {
77 | gl.glDisable(GL10.GL_LIGHTING);
78 | gl.glPushMatrix();
79 | gl.glRotatef(90,90,0,1);
80 | gl.glTranslatef(0.0f, -0.5f, -0.5f);
81 | gl.glColor4f(0.68f, 0.0f, 0.0f, 1.0f);
82 |
83 | ExplodeTex = tex;
84 |
85 | drawShockwaves(gl);
86 |
87 | if(Radius < IMPACT_MAX_RADIUS)
88 | {
89 | drawImpactGlow(gl);
90 | drawSpires(gl);
91 | }
92 |
93 | Radius += (GameDeltaTime * IMPACT_RADIUS_DELTA);
94 |
95 | gl.glPopMatrix();
96 | gl.glEnable(GL10.GL_LIGHTING);
97 |
98 | }
99 |
100 | private void drawSpires(GL10 gl)
101 | {
102 | int i;
103 |
104 | Vec zunit = new Vec(0.0f, 0.0f, 1.0f);
105 | Vec right,left;
106 |
107 | Vec vectors[] = {
108 | new Vec(1.00f, 0.20f, 0.00f),
109 | new Vec(0.80f, 0.25f, 0.00f),
110 | new Vec(0.90f, 0.50f, 0.00f),
111 | new Vec(0.70f, 0.50f, 0.00f),
112 | new Vec(0.52f, 0.45f, 0.00f),
113 | new Vec(0.65f, 0.75f, 0.00f),
114 | new Vec(0.42f, 0.68f, 0.00f),
115 | new Vec(0.40f, 1.02f, 0.00f),
116 | new Vec(0.20f, 0.90f, 0.00f),
117 | new Vec(0.08f, 0.65f, 0.00f),
118 | new Vec(0.00f, 1.00f, 0.00f),
119 | new Vec(-0.08f, 0.65f, 0.00f),
120 | new Vec(-0.20f, 0.90f, 0.00f),
121 | new Vec(-0.40f, 1.02f, 0.00f),
122 | new Vec(-0.42f, 0.68f, 0.00f),
123 | new Vec(-0.65f, 0.75f, 0.00f),
124 | new Vec(-0.52f, 0.45f, 0.00f),
125 | new Vec(-0.70f, 0.50f, 0.00f),
126 | new Vec(-0.90f, 0.50f, 0.00f),
127 | new Vec(-0.80f, 0.30f, 0.00f),
128 | new Vec(-1.00f, 0.20f, 0.00f)
129 | };
130 |
131 | float TriList[] = new float[3*3];
132 | FloatBuffer SpireBuffer;
133 |
134 |
135 | gl.glColor4f(1.0f, 1.0f, 1.0f, 0.0f);
136 | gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
137 | gl.glBlendFunc(GL10.GL_ONE, GL10.GL_ONE);
138 |
139 | for(i=0; i < NUM_SPIRES; i++)
140 | {
141 | right = vectors[i].Cross(zunit);
142 | right.Normalise();
143 | right.Mul(SPIRE_WIDTH);
144 |
145 | left = zunit.Cross(vectors[i]);
146 | left.Normalise();
147 | left.Mul(SPIRE_WIDTH);
148 |
149 | TriList[0] = right.v[0];
150 | TriList[1] = right.v[1];
151 | TriList[2] = right.v[2];
152 | TriList[3] = (Radius * vectors[i].v[0]);
153 | TriList[4] = (Radius * vectors[i].v[1]);
154 | TriList[5] = 0.0f;
155 | TriList[6] = left.v[0];
156 | TriList[7] = left.v[1];
157 | TriList[8] = left.v[2];
158 |
159 | SpireBuffer = GraphicUtils.ConvToFloatBuffer(TriList);
160 | gl.glVertexPointer(3, GL10.GL_FLOAT, 0, SpireBuffer);
161 | gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 3);
162 | }
163 |
164 | gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
165 |
166 | }
167 |
168 | private void drawImpactGlow(GL10 gl)
169 | {
170 | float opacity;
171 | float ImpactVertex[] = {
172 | -1.0f, -1.0f, 0.0f,
173 | 1.0f, -1.0f, 0.0f,
174 | 1.0f, 1.0f, 0.0f,
175 | 1.0f, 1.0f, 0.0f,
176 | -1.0f, 1.0f, 0.0f,
177 | -1.0f, -1.0f,0.0f
178 | };
179 | float TexVertex[] = {
180 | 0.0f, 0.0f,
181 | 1.0f, 0.0f,
182 | 1.0f,1.0f,
183 | 1.0f,1.0f,
184 | 0.0f, 1.0f,
185 | 0.0f, 0.0f
186 | };
187 | FloatBuffer ImpactBuffer;
188 | FloatBuffer TexBuffer;
189 |
190 | opacity = GLOW_START_OPACITY - (Radius / IMPACT_MAX_RADIUS);
191 |
192 | gl.glPushMatrix();
193 | gl.glScalef(Radius, Radius, 1.0f);
194 | gl.glBindTexture(GL10.GL_TEXTURE_2D, ExplodeTex.getTextureID());
195 | gl.glEnable(GL10.GL_TEXTURE_2D);
196 |
197 | gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
198 | gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
199 |
200 | gl.glColor4f(GLOW_INTENSITY, GLOW_INTENSITY, GLOW_INTENSITY, opacity);
201 | gl.glDepthMask(false);
202 |
203 | ImpactBuffer = GraphicUtils.ConvToFloatBuffer(ImpactVertex);
204 | gl.glVertexPointer(3, GL10.GL_FLOAT, 0, ImpactBuffer);
205 | TexBuffer = GraphicUtils.ConvToFloatBuffer(TexVertex);
206 | gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, TexBuffer);
207 |
208 | //gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
209 | gl.glDrawArrays(GL10.GL_TRIANGLES ,0, 6);
210 |
211 | gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
212 | gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
213 | gl.glDepthMask(true);
214 | gl.glDisable(GL10.GL_TEXTURE_2D);
215 | gl.glPopMatrix();
216 | }
217 |
218 | private void drawShockwaves(GL10 gl)
219 | {
220 | int waves;
221 | float radius = (Radius * SHOCKWAVE_SPEED);
222 |
223 | gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
224 |
225 | for(waves=0; waves SHOCKWAVE_MIN_RADIUS && radius < SHOCKWAVE_MAX_RADIUS)
228 | {
229 | drawWave(gl,radius);
230 | }
231 | radius -= SHOCKWAVE_SPACING;
232 | }
233 | }
234 |
235 | private void drawWave(GL10 gl,float adj_radius)
236 | {
237 | int i,j,vertex;
238 | double angle;
239 | double delta_radius = SHOCKWAVE_WIDTH / SHOCKWAVE_SEGMENTS;
240 | double delta_angle = (180.0 / SHOCKWAVE_SEGMENTS) * (Math.PI / 180);
241 | double start_angle = (270.0 * (Math.PI / 180));
242 | int NumberOfIndices = (2*(SHOCKWAVE_SEGMENTS + 1));
243 |
244 | float WaveVertex[] = new float[(3*(2*(SHOCKWAVE_SEGMENTS + 1)))];
245 | FloatBuffer WaveBuffer;
246 |
247 | gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
248 |
249 | for(i=0; i < SHOCKWAVE_SEGMENTS; i++)
250 | {
251 | angle = start_angle;
252 | vertex = 0;
253 | for(j=0; j <= SHOCKWAVE_SEGMENTS; j++)
254 | {
255 | WaveVertex[vertex] = (float)((adj_radius + delta_radius) * Math.sin(angle));
256 | vertex++;
257 | WaveVertex[vertex] = (float)((adj_radius + delta_radius) * Math.cos(angle));
258 | vertex++;
259 | WaveVertex[vertex] = 0.0f;
260 | vertex++;
261 |
262 | WaveVertex[vertex] = (float)(adj_radius * Math.sin(angle));
263 | vertex++;
264 | WaveVertex[vertex] = (float)(adj_radius * Math.cos(angle));
265 | vertex++;
266 | WaveVertex[vertex] = 0.0f;
267 | vertex++;
268 |
269 | angle += delta_angle;
270 | }
271 |
272 | WaveBuffer = GraphicUtils.ConvToFloatBuffer(WaveVertex);
273 | gl.glVertexPointer(3, GL10.GL_FLOAT, 0, WaveBuffer);
274 | gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, NumberOfIndices);
275 | adj_radius += delta_radius;
276 | }
277 |
278 | gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
279 | }
280 | }
281 |
--------------------------------------------------------------------------------
/GlTron/src/com/glTron/Video/Font.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Iain Churcher
3 | *
4 | * Based on GLtron by Andreas Umbach (www.gltron.org)
5 | *
6 | * This file is part of GL TRON.
7 | *
8 | * GL TRON is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * GL TRON is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with GL TRON. If not, see .
20 | *
21 | */
22 |
23 | package com.glTron.Video;
24 |
25 | import java.nio.FloatBuffer;
26 |
27 | import javax.microedition.khronos.opengles.GL10;
28 |
29 | import android.content.Context;
30 |
31 | public class Font {
32 |
33 | //private int _nTextures;
34 | public int _texwidth;
35 | public int _width;
36 | public int _lower;
37 | public int _upper;
38 |
39 | private GL10 gl;
40 |
41 | // Hard code to only 2 textures as thats
42 | // what both fonts use in the default art pack
43 | private GLTexture Tex1;
44 | private GLTexture Tex2;
45 |
46 | public Font(GL10 gl1, Context context, int tex1, int tex2)
47 | {
48 | gl = gl1;
49 | Tex1 = new GLTexture(gl,context,tex1,GL10.GL_CLAMP_TO_EDGE,GL10.GL_CLAMP_TO_EDGE,false);
50 | Tex2 = new GLTexture(gl,context,tex2,GL10.GL_CLAMP_TO_EDGE,GL10.GL_CLAMP_TO_EDGE,false);
51 | //_nTextures = 2;
52 | }
53 |
54 | public void drawText(int x, int y, int size, String text)
55 | {
56 | gl.glEnable(GL10.GL_BLEND);
57 | gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
58 | gl.glEnable(GL10.GL_TEXTURE_2D);
59 |
60 | gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
61 | gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
62 |
63 | gl.glPushMatrix();
64 | gl.glTranslatef(x, y, 0);
65 | gl.glScalef(size, size, size);
66 |
67 | renderString(text);
68 |
69 | gl.glPopMatrix();
70 | gl.glDisable(GL10.GL_TEXTURE_2D);
71 | gl.glDisable(GL10.GL_BLEND);
72 | }
73 |
74 | private void renderString(String str)
75 | {
76 | int w = _texwidth / _width;
77 | float cw = (float)_width / (float)_texwidth;
78 | float cx,cy;
79 | int i, index;
80 | int tex;
81 | int bound = -1;
82 |
83 | float vertex[] = new float[6 * 2];
84 | float textre[] = new float[6 * 2];
85 | FloatBuffer vertexBuff;
86 | FloatBuffer texBuff;
87 |
88 | // skip color bit is it used?
89 |
90 | for(i = 0; i < str.length(); i++)
91 | {
92 | index = str.charAt(i) - _lower + 1;
93 |
94 | if(index >= _upper)
95 | return; // index out of bounds
96 |
97 | tex = index / (w * w);
98 |
99 | // Bind texture
100 | if(tex != bound)
101 | {
102 | if(tex == 0)
103 | gl.glBindTexture(GL10.GL_TEXTURE_2D, Tex1.getTextureID());
104 | else
105 | gl.glBindTexture(GL10.GL_TEXTURE_2D, Tex2.getTextureID());
106 |
107 | gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_MODULATE);
108 | bound = tex;
109 | }
110 |
111 | // find texture coordinates
112 | index = index % (w * w);
113 | cx = (float)(index % w) / (float)w;
114 | cy = (float)(index / w) / (float)w;
115 |
116 | // draw character
117 | textre[0] = cx;
118 | textre[1] = 1.0f-cy-cw;
119 | vertex[0] = (float)i;
120 | vertex[1] = 0.0f;
121 |
122 | textre[2] = cx+cw;
123 | textre[3] = 1.0f-cy-cw;
124 | vertex[2] = i + 1.0f;
125 | vertex[3] = 0.0f;
126 |
127 | textre[4] = cx + cw;
128 | textre[5] = 1.0f - cy;
129 | vertex[4] = i + 1.0f;
130 | vertex[5] = 1.0f;
131 |
132 | textre[6] = cx + cw;
133 | textre[7] = 1.0f - cy;
134 | vertex[6] = i + 1.0f;
135 | vertex[7] = 1.0f;
136 |
137 | textre[8] = cx;
138 | textre[9] = 1.0f - cy;
139 | vertex[8] = i;
140 | vertex[9] = 1.0f;
141 |
142 | textre[10] = cx;
143 | textre[11] = 1.0f - cy - cw;
144 | vertex[10] = i;
145 | vertex[11] = 0.0f;
146 |
147 | vertexBuff = GraphicUtils.ConvToFloatBuffer(vertex);
148 | texBuff = GraphicUtils.ConvToFloatBuffer(textre);
149 |
150 | gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertexBuff);
151 | gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texBuff);
152 | gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 6);
153 |
154 | }
155 | }
156 | }
157 |
--------------------------------------------------------------------------------
/GlTron/src/com/glTron/Video/GLTexture.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Iain Churcher
3 | *
4 | * Based on GLtron by Andreas Umbach (www.gltron.org)
5 | *
6 | * This file is part of GL TRON.
7 | *
8 | * GL TRON is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * GL TRON is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with GL TRON. If not, see .
20 | *
21 | */
22 |
23 | package com.glTron.Video;
24 |
25 | import javax.microedition.khronos.opengles.GL10;
26 |
27 | import android.content.Context;
28 | import android.graphics.Bitmap;
29 | import android.graphics.BitmapFactory;
30 | import android.graphics.Matrix;
31 | import android.opengl.GLUtils;
32 |
33 | public class GLTexture {
34 |
35 | int _texID[];
36 | boolean boGenMipMap = true;
37 |
38 | int WrapS;
39 | int WrapT;
40 |
41 | public int DebugType;
42 |
43 | public GLTexture(GL10 gl, Context context, int resource)
44 | {
45 | WrapS = GL10.GL_REPEAT;
46 | WrapT = GL10.GL_REPEAT;
47 | _texID = new int[1];
48 | loadTexture(gl,context,resource);
49 | }
50 |
51 | public GLTexture(GL10 gl, Context context, int resource, int wrap_s, int wrap_t)
52 | {
53 | WrapS = wrap_s;
54 | WrapT = wrap_t;
55 | _texID = new int[1];
56 | loadTexture(gl,context,resource);
57 | }
58 |
59 | public GLTexture(GL10 gl, Context context, int resource, int wrap_s, int wrap_t, boolean mipMap)
60 | {
61 | WrapS = wrap_s;
62 | WrapT = wrap_t;
63 | boGenMipMap = mipMap;
64 | _texID = new int[1];
65 | loadTexture(gl,context,resource);
66 | }
67 |
68 | // Will load a texture out of a drawable resource file, and return an OpenGL texture ID:
69 | private void loadTexture(GL10 gl, Context context, int resource) {
70 |
71 | // In which ID will we be storing this texture?
72 | gl.glGenTextures(1, _texID, 0);
73 |
74 | // We need to flip the textures vertically:
75 | Matrix flip = new Matrix();
76 | flip.postScale(1f, -1f);
77 |
78 | // This will tell the BitmapFactory to not scale based on the device's pixel density:
79 | // (Thanks to Matthew Marshall for this bit)
80 | BitmapFactory.Options opts = new BitmapFactory.Options();
81 | opts.inScaled = false;
82 |
83 | // Load up, and flip the texture:
84 | Bitmap temp = BitmapFactory.decodeResource(context.getResources(), resource, opts);
85 | Bitmap bmp = Bitmap.createBitmap(temp, 0, 0, temp.getWidth(), temp.getHeight(), flip, true);
86 | temp.recycle();
87 |
88 | gl.glBindTexture(GL10.GL_TEXTURE_2D, _texID[0]);
89 |
90 | // Set all of our texture parameters:
91 | if(boGenMipMap)
92 | {
93 | gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR_MIPMAP_NEAREST);
94 | gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR_MIPMAP_NEAREST);
95 | }
96 | else
97 | {
98 | gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
99 | gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
100 | }
101 | gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, WrapS);
102 | gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, WrapT);
103 |
104 | DebugType = GLUtils.getInternalFormat(bmp);
105 |
106 | // Generate, and load up all of the mipmaps:
107 | if(boGenMipMap)
108 | {
109 | for(int level=0, height = bmp.getHeight(), width = bmp.getWidth(); true; level++) {
110 | // Push the bitmap onto the GPU:
111 | GLUtils.texImage2D(GL10.GL_TEXTURE_2D, level, bmp, 0);
112 |
113 | // We need to stop when the texture is 1x1:
114 | if(height==1 && width==1) break;
115 |
116 | // Resize, and let's go again:
117 | width >>= 1; height >>= 1;
118 | if(width<1) width = 1;
119 | if(height<1) height = 1;
120 |
121 | Bitmap bmp2 = Bitmap.createScaledBitmap(bmp, width, height, true);
122 | bmp.recycle();
123 | bmp = bmp2;
124 | }
125 | }
126 | else
127 | {
128 | GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bmp, 0);
129 | }
130 |
131 | bmp.recycle();
132 |
133 | }
134 |
135 | public int getTextureID()
136 | {
137 | return _texID[0];
138 | }
139 |
140 | }
141 |
--------------------------------------------------------------------------------
/GlTron/src/com/glTron/Video/GraphicUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Iain Churcher
3 | *
4 | * Based on GLtron by Andreas Umbach (www.gltron.org)
5 | *
6 | * This file is part of GL TRON.
7 | *
8 | * GL TRON is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * GL TRON is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with GL TRON. If not, see .
20 | *
21 | */
22 |
23 | package com.glTron.Video;
24 |
25 | import java.nio.ByteBuffer;
26 | import java.nio.ByteOrder;
27 | import java.nio.FloatBuffer;
28 | import java.nio.ShortBuffer;
29 |
30 | public class GraphicUtils {
31 |
32 | public class vec2 {
33 | public float v[] = new float[2];
34 | }
35 |
36 | public class vec3 {
37 | public float v[] = new float[3];
38 | }
39 |
40 | public class vec4 {
41 | public float v[] = new float[4];
42 | }
43 |
44 |
45 | public static vec2 vec2Add(vec2 Result, vec2 v1, vec2 v2)
46 | {
47 | Result.v[0] = v1.v[0] + v2.v[0];
48 | Result.v[1] = v1.v[1] + v2.v[1];
49 |
50 | return Result;
51 | }
52 |
53 | public static FloatBuffer ConvToFloatBuffer(float buf[])
54 | {
55 | FloatBuffer ReturnBuffer;
56 |
57 | ByteBuffer vbb = ByteBuffer.allocateDirect(buf.length * 4);
58 | vbb.order(ByteOrder.nativeOrder());
59 | ReturnBuffer = vbb.asFloatBuffer();
60 | ReturnBuffer.put(buf);
61 | ReturnBuffer.position(0);
62 |
63 | return ReturnBuffer;
64 | }
65 |
66 | public static ByteBuffer ConvToByteBuffer(byte buf[])
67 | {
68 | ByteBuffer ReturnBuffer = ByteBuffer.allocateDirect(buf.length);
69 |
70 | ReturnBuffer.order(ByteOrder.nativeOrder());
71 | ReturnBuffer.put(buf);
72 | ReturnBuffer.position(0);
73 |
74 | return ReturnBuffer;
75 | }
76 |
77 | public static ShortBuffer ConvToShortBuffer(short buf[])
78 | {
79 | ShortBuffer ReturnBuffer = ShortBuffer.allocate(buf.length);
80 | ReturnBuffer.put(buf);
81 | ReturnBuffer.position(0);
82 | return ReturnBuffer;
83 | }
84 |
85 | }
86 |
--------------------------------------------------------------------------------
/GlTron/src/com/glTron/Video/HUD.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Iain Churcher
3 | *
4 | * Based on GLtron by Andreas Umbach (www.gltron.org)
5 | *
6 | * This file is part of GL TRON.
7 | *
8 | * GL TRON is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * GL TRON is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with GL TRON. If not, see .
20 | *
21 | */
22 |
23 | package com.glTron.Video;
24 |
25 | import javax.microedition.khronos.opengles.GL10;
26 |
27 | import android.content.Context;
28 |
29 | import com.glTron.R;
30 | import com.glTron.Game.GLTronGame;
31 |
32 | public class HUD {
33 |
34 | private Font xenoTron;
35 | private GL10 gl;
36 |
37 | // fps members
38 | private final int FPS_HSIZE = 20;
39 | private int fps_h[] = new int[FPS_HSIZE];
40 | private int pos = -FPS_HSIZE;
41 | private int fps_min = 0;
42 | private int fps_avg = 0;
43 |
44 | // console members
45 | private final int CONSOLE_DEPTH = 100;
46 | private String consoleBuff[] = new String[CONSOLE_DEPTH];
47 | private int position;
48 | private int offset;
49 |
50 | // win lose
51 | private boolean dispWinner = false;
52 | private boolean dispLoser = false;
53 | private boolean dispInst = true;
54 |
55 | public HUD(GL10 gl1, Context ctx)
56 | {
57 | gl = gl1;
58 | // Load font
59 | xenoTron = new Font(gl,ctx,R.drawable.xenotron0, R.drawable.xenotron1);
60 | // Hard code these values for now allow loadable fonts later...
61 | xenoTron._texwidth = 256;
62 | xenoTron._width = 32;
63 | xenoTron._lower = 32;
64 | xenoTron._upper = 126;
65 |
66 | resetConsole();
67 |
68 | }
69 |
70 | public void draw(Video Visual, long dt, int plyrScore)
71 | {
72 | // Draw fps
73 | gl.glDisable(GL10.GL_DEPTH_TEST);
74 | Visual.rasonly(gl);
75 |
76 | if(GLTronGame.mPrefs.DrawFPS())
77 | drawFPS(Visual,dt);
78 |
79 | drawConsole(Visual);
80 | drawWinLose(Visual);
81 | drawScore(plyrScore);
82 | drawInstructions(Visual);
83 | }
84 |
85 | public void resetConsole()
86 | {
87 | int i;
88 |
89 | position = 0;
90 | offset = 0;
91 |
92 | for(i = 0; i < CONSOLE_DEPTH; i++)
93 | {
94 | consoleBuff[i] = null;
95 | }
96 |
97 | dispWinner = false;
98 | dispLoser = false;
99 | }
100 |
101 | public void displayWin()
102 | {
103 | if(dispLoser != true)
104 | dispWinner = true;
105 | }
106 |
107 | public void displayLose()
108 | {
109 | if(dispWinner != true)
110 | dispLoser = true;
111 | }
112 |
113 | public void displayInstr(Boolean value)
114 | {
115 | dispInst = value;
116 | }
117 |
118 |
119 | public void addLineToConsole(String str)
120 | {
121 | int i,x = 0;
122 |
123 | consoleBuff[position] = str;
124 | position++;
125 |
126 | if(position >= (CONSOLE_DEPTH - 1))
127 | {
128 | // shuffle data up the array
129 | for(i=0;i Visual._vp_w / 2 - 25)
211 | size--;
212 |
213 | gl.glColor4f(1.0f, 0.4f, 0.2f, 1.0f);
214 | xenoTron.drawText(25, Visual.GetHeight() - 20 * (i + 1), size, consoleBuff[index]);
215 | }
216 | }
217 | }
218 |
219 | private void drawFPS(Video Visual, long dt)
220 | {
221 | int diff;
222 | StringBuilder sb = new StringBuilder();
223 |
224 | diff = (dt > 0) ? (int)dt : 1;
225 |
226 | if(pos < 0)
227 | {
228 | fps_avg = 1000 / diff;
229 | fps_min = 1000 / diff;
230 | fps_h[pos + FPS_HSIZE] = 1000 / diff;
231 | pos++;
232 | }
233 | else
234 | {
235 | fps_h[pos] = 1000 / diff;
236 | pos = (pos + 1) % FPS_HSIZE;
237 |
238 | if(pos % 10 == 0)
239 | {
240 | int i;
241 | int sum = 0;
242 | int min = 1000;
243 |
244 | for(i=0;i.
20 | *
21 | */
22 |
23 | package com.glTron.Video;
24 |
25 | import java.nio.FloatBuffer;
26 |
27 | import javax.microedition.khronos.opengles.GL10;
28 |
29 | public class Lighting {
30 |
31 | FloatBuffer white_fb;
32 | FloatBuffer gray66_fb;
33 | FloatBuffer gray10_fb;
34 | FloatBuffer black_fb;
35 | FloatBuffer posWorld0_fb;
36 | FloatBuffer posWorld1_fb;
37 | FloatBuffer posCycles_fb;
38 |
39 | private static final float white[] = { 1.0f, 1.0f, 1.0f, 1.0f };
40 | private static final float gray66[] = { 0.66f, 0.66f, 0.66f, 1.0f };
41 | private static final float gray10[] = { 0.1f, 0.1f, 0.1f, 1.0f };
42 | private static final float black[] = { 0.0f, 0.0f, 0.0f, 1.0f };
43 |
44 | private static final float posWorld0[] = {1.0f, 0.8f, 0.0f, 0.0f};
45 | private static final float posWorld1[] = {-1.0f, -0.8f, 0.0f, 0.0f};
46 | private static final float posCycles[] = {0.0f, 0.0f, 0.0f, 1.0f};
47 |
48 | public enum LightType {
49 | E_WORLD_LIGHTS,
50 | E_CYCLE_LIGHTS,
51 | E_RECOGNISER_LIGHTS
52 | }
53 |
54 | public Lighting()
55 | {
56 | white_fb = GraphicUtils.ConvToFloatBuffer(white);
57 | gray66_fb = GraphicUtils.ConvToFloatBuffer(gray66);
58 | gray10_fb = GraphicUtils.ConvToFloatBuffer(gray10);
59 | black_fb = GraphicUtils.ConvToFloatBuffer(black);
60 | posWorld0_fb = GraphicUtils.ConvToFloatBuffer(posWorld0);
61 | posWorld1_fb = GraphicUtils.ConvToFloatBuffer(posWorld1);
62 | posCycles_fb = GraphicUtils.ConvToFloatBuffer(posCycles);
63 |
64 | }
65 |
66 | public void setupLights(GL10 gl, LightType lightType)
67 | {
68 | // Turn off global ambient lighting
69 | gl.glLightModelfv(GL10.GL_LIGHT_MODEL_AMBIENT, black_fb);
70 | gl.glLightModelf(GL10.GL_LIGHT_MODEL_TWO_SIDE, 1.0f);
71 |
72 | if(lightType == LightType.E_WORLD_LIGHTS) {
73 | gl.glEnable(GL10.GL_LIGHTING);
74 | gl.glMatrixMode(GL10.GL_MODELVIEW);
75 | gl.glPushMatrix();
76 |
77 | gl.glEnable(GL10.GL_LIGHT0);
78 | gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, posWorld0_fb);
79 | gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, gray10_fb);
80 | gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_SPECULAR, white_fb);
81 | gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, white_fb);
82 |
83 | gl.glEnable(GL10.GL_LIGHT1);
84 | gl.glLightfv(GL10.GL_LIGHT1, GL10.GL_POSITION, posWorld1_fb);
85 | gl.glLightfv(GL10.GL_LIGHT1, GL10.GL_AMBIENT, black_fb);
86 | gl.glLightfv(GL10.GL_LIGHT1, GL10.GL_SPECULAR, gray66_fb);
87 | gl.glLightfv(GL10.GL_LIGHT1, GL10.GL_DIFFUSE, gray66_fb);
88 | gl.glPopMatrix();
89 |
90 | } else {
91 | gl.glEnable(GL10.GL_LIGHTING);
92 | gl.glEnable(GL10.GL_LIGHT0);
93 |
94 | gl.glMatrixMode(GL10.GL_MODELVIEW);
95 | gl.glPushMatrix();
96 | gl.glLoadIdentity();
97 |
98 | gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_POSITION, posCycles_fb);
99 | gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_AMBIENT, gray10_fb);
100 | gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_SPECULAR, white_fb);
101 | gl.glLightfv(GL10.GL_LIGHT0, GL10.GL_DIFFUSE, white_fb);
102 |
103 | gl.glDisable(GL10.GL_LIGHT1);
104 |
105 | gl.glPopMatrix();
106 | }
107 |
108 | }
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/GlTron/src/com/glTron/Video/Material.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Iain Churcher
3 | *
4 | * Based on GLtron by Andreas Umbach (www.gltron.org)
5 | *
6 | * This file is part of GL TRON.
7 | *
8 | * GL TRON is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * GL TRON is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with GL TRON. If not, see .
20 | *
21 | */
22 |
23 | package com.glTron.Video;
24 |
25 | import java.io.BufferedReader;
26 | import java.io.IOException;
27 | import java.io.InputStream;
28 | import java.io.InputStreamReader;
29 | import java.nio.ByteBuffer;
30 | import java.nio.ByteOrder;
31 | import java.nio.FloatBuffer;
32 | import java.util.ArrayList;
33 |
34 | import android.content.Context;
35 | import android.util.Log;
36 |
37 | public class Material {
38 |
39 | // members
40 | ArrayList materials = new ArrayList();
41 |
42 | String Debug;
43 | StringBuffer sb = new StringBuffer(40);
44 |
45 | public enum ColourType {
46 | E_AMBIENT,
47 | E_DIFFUSE,
48 | E_SPECULAR
49 | }
50 |
51 | private class MaterialData {
52 | //members
53 | public float[] ambient = { 0.2f, 0.2f, 0.2f, 1.0f };
54 | public float[] diffuse = { 1.0f, 1.0f, 0.0f, 1.0f };
55 | public float[] specular = { 1.0f, 1.0f, 1.0f, 1.0f };
56 | public float shininess = 2.0f;
57 | public String name;
58 | //public String map_diffuse;
59 | }
60 |
61 | Material(Context ctx, int resId) {
62 | Debug = sb.append("Start Add Material, ").append(resId).toString();
63 | Log.e("GLTRON",Debug);
64 | AddMaterial(ctx,resId);
65 | }
66 |
67 | public void AddMaterial(Context ctx, int resId) {
68 | // Load the file and save the resources
69 | String buf;
70 | String[] temp;
71 | int iMaterial;
72 | MaterialData mData;
73 |
74 | InputStream inputStream = ctx.getResources().openRawResource(resId);
75 | InputStreamReader inputreader = new InputStreamReader(inputStream);
76 | BufferedReader buffreader = new BufferedReader(inputreader);
77 |
78 | iMaterial = -1;
79 |
80 | try
81 | {
82 | while((buf = buffreader.readLine()) != null) {
83 | if(buf != null && (buf.length() > 1)) {
84 | temp = buf.split(" ");
85 | switch(buf.charAt(0)) {
86 | case '#':
87 | break;
88 | case 'n':
89 | iMaterial++;
90 | materials.add(new MaterialData());
91 | mData = materials.get(iMaterial);
92 | mData.name = temp[1];
93 | break;
94 | default:
95 | mData = materials.get(iMaterial);
96 | if(temp[0].contains("Ka")) {
97 | mData.ambient[0] = Float.valueOf(temp[1].trim()).floatValue();
98 | mData.ambient[1] = Float.valueOf(temp[2].trim()).floatValue();
99 | mData.ambient[2] = Float.valueOf(temp[3].trim()).floatValue();
100 | } else if(temp[0].contains("Kd")) {
101 | mData.diffuse[0] = Float.valueOf(temp[1].trim()).floatValue();
102 | mData.diffuse[1] = Float.valueOf(temp[2].trim()).floatValue();
103 | mData.diffuse[2] = Float.valueOf(temp[3].trim()).floatValue();
104 | } else if(temp[0].contains("Ks")) {
105 | mData.specular[0] = Float.valueOf(temp[1].trim()).floatValue();
106 | mData.specular[1] = Float.valueOf(temp[2].trim()).floatValue();
107 | mData.specular[2] = Float.valueOf(temp[3].trim()).floatValue();
108 | } else if(temp[0].contains("Ns")) {
109 | mData.shininess = Float.valueOf(temp[1].trim()).floatValue();
110 | }
111 | break;
112 | }
113 | }
114 | }
115 | }
116 | catch (IOException e)
117 | {
118 | Log.e("GLTRON","Materail Read File Exception");
119 | }
120 | }
121 |
122 |
123 | public int GetIndex(String sname)
124 | {
125 | int retindex = -1;
126 | MaterialData[] mData = new MaterialData[materials.size()];
127 | mData = (MaterialData[])materials.toArray(mData);
128 | int numOfElements = mData.length;
129 |
130 | for(int x=0; x < numOfElements; x++) {
131 | if(mData[x].name.equals(sname)) {
132 | retindex = x;
133 | }
134 | }
135 |
136 | return retindex;
137 | }
138 |
139 | public int GetNumber()
140 | {
141 | MaterialData[] mData = new MaterialData[materials.size()];
142 | mData = (MaterialData[])materials.toArray(mData);
143 | return mData.length;
144 | }
145 |
146 | public FloatBuffer GetAmbient(int mindex)
147 | {
148 | FloatBuffer Ambient;
149 | MaterialData mData = (MaterialData)(materials.get(mindex));
150 | ByteBuffer bb = ByteBuffer.allocateDirect(4 * 4);
151 | bb.order(ByteOrder.nativeOrder());
152 | Ambient = bb.asFloatBuffer();
153 | Ambient.put(mData.ambient);
154 | Ambient.position(0);
155 |
156 | return Ambient;
157 | }
158 |
159 | public FloatBuffer GetDiffuse(int mindex)
160 | {
161 | FloatBuffer Diffuse;
162 | MaterialData mData = (MaterialData)(materials.get(mindex));
163 | ByteBuffer bb = ByteBuffer.allocateDirect(4 * 4);
164 | bb.order(ByteOrder.nativeOrder());
165 | Diffuse = bb.asFloatBuffer();
166 | Diffuse.put(mData.diffuse);
167 | Diffuse.position(0);
168 |
169 | return Diffuse;
170 | }
171 |
172 | public FloatBuffer GetSpecular(int mindex)
173 | {
174 | FloatBuffer Specular;
175 | MaterialData mData = (MaterialData)(materials.get(mindex));
176 | ByteBuffer bb = ByteBuffer.allocateDirect(4 * 4);
177 | bb.order(ByteOrder.nativeOrder());
178 | Specular = bb.asFloatBuffer();
179 | Specular.put(mData.specular);
180 | Specular.position(0);
181 |
182 | return Specular;
183 | }
184 |
185 | public float GetShininess(int mindex)
186 | {
187 | MaterialData mData = (materials.get(mindex));
188 | return mData.shininess;
189 | }
190 |
191 | public void SetMaterialColour(String name, ColourType Element, float[] colour)
192 | {
193 | for(int i=0;i.
20 | *
21 | */
22 |
23 | package com.glTron.Video;
24 |
25 | import java.io.BufferedReader;
26 | import java.io.IOException;
27 | import java.io.InputStream;
28 | import java.io.InputStreamReader;
29 | import java.nio.ByteBuffer;
30 | import java.nio.ByteOrder;
31 | import java.nio.FloatBuffer;
32 | import java.nio.ShortBuffer;
33 | import java.util.ArrayList;
34 |
35 | import javax.microedition.khronos.opengles.GL10;
36 |
37 | import android.content.Context;
38 | import android.util.Log;
39 |
40 | import com.glTron.Video.Material.ColourType;
41 |
42 | public class Model {
43 |
44 | // member vars
45 | private Material mMaterials;
46 | private int MaterialsCount[];
47 | private float rawVertex[];
48 | private FloatBuffer mVertexBuffer;
49 | private FloatBuffer mNormalBuffer;
50 | private ShortBuffer mIndicesBuffer[];
51 | private int mNumOfVertices;
52 | private Vec mBBoxMin;
53 | private Vec mBBoxSize;
54 | private float mBBoxfRadius;
55 |
56 | String Debug;
57 | StringBuffer sb = new StringBuffer(40);
58 |
59 | private class face {
60 | int vertex[] = new int[3];
61 | int normal[] = new int[3];
62 | int material;
63 | }
64 |
65 | private class vec3 {
66 | float v[] = {0.0f, 0.0f, 0.0f};
67 | }
68 |
69 | public Model(Context ctx, int resId)
70 | {
71 | readMesh(ctx,resId);
72 | }
73 |
74 | private void readMesh(Context ctx, int resId)
75 | {
76 | String buf;
77 | String[] temp;
78 | String[] temp2;
79 | String restemp;
80 | int resourceId;
81 | int faceIndex = -1;
82 | ArrayList mVertices = new ArrayList();
83 | ArrayList mNormals = new ArrayList();
84 | ArrayList mFaces = new ArrayList();
85 | int numOfVertices = 0;
86 | int numOfNormals = 0;
87 | int numOfFaces = -1;
88 | vec3 Vertex;
89 | face currFace;
90 | face faceArray[];
91 |
92 | Log.e("GLTRON","Start Read Mesh");
93 |
94 | InputStream inputStream = ctx.getResources().openRawResource(resId);
95 | InputStreamReader inputreader = new InputStreamReader(inputStream);
96 | BufferedReader buffreader = new BufferedReader(inputreader);
97 |
98 | try
99 | {
100 | while((buf = buffreader.readLine()) != null) {
101 |
102 | if(buf != null && (buf.length() > 1)) {
103 | temp = buf.split(" ");
104 | switch(buf.charAt(0)) {
105 | case 'm':
106 | //obtain the resource id
107 | restemp = temp[1].substring(0, (temp[1].length()-4));
108 | resourceId = ctx.getResources().getIdentifier(restemp.trim(), "raw", ctx.getPackageName());
109 | if(mMaterials == null) {
110 | mMaterials = new Material(ctx,resourceId);
111 | } else {
112 | mMaterials.AddMaterial(ctx,resourceId);
113 | }
114 | break;
115 | case 'u':
116 | //search all materials for mesh for name
117 | int result;
118 | result = mMaterials.GetIndex(temp[1]);
119 | if(result > -1) {
120 | faceIndex = result;
121 | }
122 | break;
123 | case 'v':
124 | // populate vertex, normal and texture coords
125 | switch(buf.charAt(1)) {
126 | case ' ':
127 | mVertices.add(new vec3());
128 | Vertex = (vec3)mVertices.get(numOfVertices);
129 | Vertex.v[0] = Float.valueOf(temp[1].trim()).floatValue();
130 | Vertex.v[1] = Float.valueOf(temp[2].trim()).floatValue();
131 | Vertex.v[2] = Float.valueOf(temp[3].trim()).floatValue();
132 | numOfVertices++;
133 | break;
134 | case 'n':
135 | mNormals.add(new vec3());
136 | Vertex = (vec3)mNormals.get(numOfNormals);
137 | Vertex.v[0] = Float.valueOf(temp[1].trim()).floatValue();
138 | Vertex.v[1] = Float.valueOf(temp[2].trim()).floatValue();
139 | Vertex.v[2] = Float.valueOf(temp[3].trim()).floatValue();
140 | numOfNormals++;
141 | break;
142 | case 't':
143 | // ignore textures
144 | break;
145 | }
146 | break;
147 | case 'f':
148 | // Load face data
149 | numOfFaces++;
150 | mFaces.add(new face());
151 | currFace = (face)mFaces.get(numOfFaces);
152 | temp2 = temp[1].split("//");
153 | currFace.vertex[0] = Integer.parseInt(temp2[0].trim());
154 | currFace.normal[0] = Integer.parseInt(temp2[1].trim());
155 | temp2 = temp[2].split("//");
156 | currFace.vertex[1] = Integer.parseInt(temp2[0].trim());
157 | currFace.normal[1] = Integer.parseInt(temp2[1].trim());
158 | temp2 = temp[3].split("//");
159 | currFace.vertex[2] = Integer.parseInt(temp2[0].trim());
160 | currFace.normal[2] = Integer.parseInt(temp2[1].trim());
161 | currFace.material = faceIndex;
162 | break;
163 | }
164 | }
165 | }
166 | }
167 | catch (IOException e)
168 | {
169 | Log.e("GLTRON","Mesh file access error");
170 | }
171 |
172 | faceArray = new face[mFaces.size()];
173 | faceArray = (face[])mFaces.toArray(faceArray);
174 | int nVertices = 0;
175 |
176 | // Create an array of the size of the total number of materials
177 | int numOfMaterials = mMaterials.GetNumber();
178 | MaterialsCount = new int[numOfMaterials];
179 |
180 | for(int x=0; x Indices = new ArrayList();
253 | short tempIndices[];
254 |
255 | for(int i=0;i 0) {
302 |
303 | gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, mMaterials.GetAmbient(i));
304 | gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, mMaterials.GetDiffuse(i));
305 | gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_SPECULAR, mMaterials.GetSpecular(i));
306 | gl.glMaterialf(GL10.GL_FRONT_AND_BACK, GL10.GL_SHININESS, mMaterials.GetShininess(i));
307 |
308 | gl.glDrawElements(GL10.GL_TRIANGLES, mIndicesBuffer[i].capacity(),
309 | GL10.GL_UNSIGNED_SHORT, mIndicesBuffer[i]);
310 | }
311 | }
312 |
313 | }
314 |
315 | public void Explode(GL10 gl, float radius)
316 | {
317 | int i,j,k;
318 |
319 | float normal[] = new float[3];
320 | float vertex[] = new float[3];
321 | FloatBuffer Normals;
322 | FloatBuffer Vertex;
323 | short indices;
324 |
325 | final int EXP_VECTORS = 10;
326 |
327 | float vectors[][] = {
328 | { 0.03f, -0.06f, -0.07f },
329 | { 0.04f, 0.08f, -0.03f },
330 | { 0.10f, -0.04f, -0.07f },
331 | { 0.06f, -0.09f, -0.10f },
332 | { -0.03f, -0.05f, 0.02f },
333 | { 0.07f, 0.08f, -0.00f },
334 | { 0.01f, -0.04f, 0.10f },
335 | { -0.01f, -0.07f, 0.09f },
336 | { 0.01f, -0.01f, -0.09f },
337 | { -0.04f, 0.04f, 0.02f }
338 | };
339 |
340 | gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
341 | gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);
342 |
343 | for(i = 0; i < mMaterials.GetNumber(); i++)
344 | {
345 | gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, mMaterials.GetAmbient(i));
346 | gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, mMaterials.GetDiffuse(i));
347 | gl.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_SPECULAR, mMaterials.GetSpecular(i));
348 | gl.glMaterialf(GL10.GL_FRONT_AND_BACK, GL10.GL_SHININESS, mMaterials.GetShininess(i));
349 |
350 | for(j=0; j < (mIndicesBuffer[i].capacity() / 3); j++)
351 | {
352 | indices = mIndicesBuffer[i].get(3 * j);
353 |
354 | normal[0] = mNormalBuffer.get(3 * indices);
355 | normal[1] = mNormalBuffer.get((3 * indices) + 1);
356 | normal[2] = mNormalBuffer.get((3 * indices) + 2);
357 |
358 | gl.glPushMatrix();
359 | gl.glTranslatef(
360 | radius * (normal[0] + vectors[j % EXP_VECTORS][0]),
361 | radius * (normal[1] + vectors[j % EXP_VECTORS][1]),
362 | Math.abs(radius * (normal[2] + vectors[j % EXP_VECTORS][2])) );
363 |
364 | for(k=0; k < 3; k++)
365 | {
366 | indices = mIndicesBuffer[i].get(3 * j + k);
367 |
368 | normal[0] = mNormalBuffer.get(3 * indices);
369 | normal[1] = mNormalBuffer.get((3 * indices) + 1);
370 | normal[2] = mNormalBuffer.get((3 * indices) + 2);
371 |
372 | Normals = GraphicUtils.ConvToFloatBuffer(normal);
373 |
374 | vertex[0] = rawVertex[3 * indices];
375 | vertex[1] = rawVertex[(3 * indices) + 1];
376 | vertex[2] = rawVertex[(3 * indices) + 2];
377 |
378 | Vertex = GraphicUtils.ConvToFloatBuffer(vertex);
379 |
380 | gl.glVertexPointer(3, GL10.GL_FLOAT, 0, Vertex);
381 | gl.glNormalPointer(GL10.GL_FLOAT, 0, Normals);
382 | gl.glDrawArrays(GL10.GL_TRIANGLES, 0, 3);
383 | }
384 | gl.glPopMatrix();
385 | }
386 | }
387 | }
388 |
389 | private void computeBBox()
390 | {
391 | int i, j;
392 | Vec vMin = new Vec(rawVertex[0],rawVertex[1],rawVertex[2]);
393 | Vec vMax = new Vec(rawVertex[0],rawVertex[1],rawVertex[2]);
394 | Vec vSize = new Vec();
395 |
396 | for(i=0; i rawVertex[3 * i + j]) {
399 | vMin.v[j] = rawVertex[3 * i + j];
400 | }
401 | if(vMax.v[j] < rawVertex[3 * i + j]) {
402 | vMax.v[j] = rawVertex[3 * i + j];
403 | }
404 | }
405 | }
406 |
407 | vSize = vMax.Sub(vMin);
408 | mBBoxMin = vMin;
409 | mBBoxSize = vSize;
410 | mBBoxfRadius = vSize.Length() / 10.0f;
411 |
412 | }
413 |
414 | public Vec GetBBoxSize()
415 | {
416 | return mBBoxSize;
417 | }
418 |
419 | public Vec GetBBoxMin()
420 | {
421 | return mBBoxMin;
422 | }
423 |
424 | public float GetBBoxRadius()
425 | {
426 | return mBBoxfRadius;
427 | }
428 | }
429 |
--------------------------------------------------------------------------------
/GlTron/src/com/glTron/Video/Segment.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Iain Churcher
3 | *
4 | * Based on GLtron by Andreas Umbach (www.gltron.org)
5 | *
6 | * This file is part of GL TRON.
7 | *
8 | * GL TRON is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * GL TRON is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with GL TRON. If not, see .
20 | *
21 | */
22 |
23 | package com.glTron.Video;
24 |
25 | public class Segment {
26 | public Vec vStart = new Vec();
27 | public Vec vDirection = new Vec();
28 |
29 | public float t1;
30 | public float t2;
31 |
32 | private boolean findT_Result = false;
33 |
34 | private float findT(Segment S, Vec V)
35 | {
36 | float t = 0.0f;
37 | float epsilon = 0.001f;
38 |
39 | findT_Result = false;
40 |
41 | if(Math.abs(S.vDirection.v[0]) > Math.abs(S.vDirection.v[1])) {
42 |
43 | t = (V.v[0] - S.vStart.v[0]) / S.vDirection.v[0];
44 |
45 | if(Math.abs(V.v[1] - (S.vStart.v[1] + t * S.vDirection.v[1])) > epsilon) {
46 | findT_Result = true;
47 | }
48 |
49 | } else {
50 |
51 | t = (V.v[1] - S.vStart.v[1]) / S.vDirection.v[1];
52 |
53 | if(Math.abs(V.v[0] - (S.vStart.v[0] + t * S.vDirection.v[0])) > epsilon) {
54 | findT_Result = true;
55 | }
56 |
57 | }
58 |
59 | return t;
60 | }
61 |
62 | private Vec IntersectParallel(Segment S2)
63 | {
64 | Vec ReturnResult = new Vec();
65 | Vec V = new Vec();
66 | float t;
67 |
68 | // If the lines dont overlap return NULL
69 | // else find t2 for t1 = 0
70 | // if t2 in [0,1] return t2, t1 = 0
71 | // else find t1 for t2 ==0 and t2 == 1
72 | // if t1 < 0 return NULL (no intersection)
73 | // else return the smaller t1 and the corresponding t2
74 |
75 | // if the lines dont overlap return NULL
76 | // else find t2 for t1 == 0
77 |
78 | V.Copy(vStart);
79 | t2 = findT(S2, V);
80 | if(findT_Result) {
81 | // vector is not collinear
82 | return null;
83 | }
84 |
85 | // if t2 in [0,1] return t2, t1 = 0
86 | if(t2 >= 0.0f && t2 <= 1.0f) {
87 | ReturnResult.Copy(vStart);
88 | t1 = 0;
89 | return ReturnResult;
90 | }
91 |
92 | // else find t1 for t2 == 0 and t2 == 1
93 | V.Copy(S2.vStart);
94 | t1 = findT(this, V);
95 | if(findT_Result) {
96 | return null;
97 | }
98 |
99 | // if t1 < 0 return NULL (no intersection)
100 | if(t1 < 0.0f) {
101 | return null;
102 | }
103 |
104 | V = S2.vStart.Add(S2.vDirection);
105 |
106 | t = findT(this,V);
107 | if(findT_Result) {
108 | return null;
109 | }
110 |
111 | if(t1 > 1.0f && t > 1.0f) {
112 | return null;
113 | }
114 |
115 | if(t < t1) {
116 | t1 = t;
117 | t2 = 1.0f;
118 | ReturnResult.Copy(V);
119 | } else {
120 | t2 = 0.0f;
121 | ReturnResult.Copy(S2.vStart);
122 | }
123 |
124 | return ReturnResult;
125 | }
126 |
127 | private Vec IntersectNonParallel(Segment S2)
128 | {
129 | Vec ReturnResult = new Vec();
130 | Vec v1 = new Vec();
131 | Vec v2 = new Vec();
132 | Vec tmp1 = new Vec();
133 | Vec tmp2 = new Vec();
134 | Vec vIntersection = new Vec();
135 |
136 | // compute the homogenous line coordinates
137 | tmp1.v[0] = vStart.v[0];
138 | tmp1.v[1] = vStart.v[1];
139 | tmp1.v[2] = 1.0f;
140 |
141 | tmp2.v[0] = vStart.v[0] + vDirection.v[0];
142 | tmp2.v[1] = vStart.v[1] + vDirection.v[1];
143 | tmp2.v[2] = 1.0f;
144 |
145 | v1 = tmp1.Cross(tmp2);
146 |
147 | tmp1.v[0] = S2.vStart.v[0];
148 | tmp1.v[1] = S2.vStart.v[1];
149 | tmp1.v[2] = 1.0f;
150 |
151 | tmp2.v[0] = S2.vStart.v[0] + S2.vDirection.v[0];
152 | tmp2.v[1] = S2.vStart.v[1] + S2.vDirection.v[1];
153 | tmp2.v[2] = 1.0f;
154 |
155 | v2 = tmp1.Cross(tmp2);
156 |
157 | // compute the intersection in homogenous coordinates and project back to 2d
158 | vIntersection = v1.Cross(v2);
159 | ReturnResult.v[0] = vIntersection.v[0] / vIntersection.v[2];
160 | ReturnResult.v[1] = vIntersection.v[1] / vIntersection.v[2];
161 |
162 | // compute t1, t2
163 | if(Math.abs(vDirection.v[0]) > Math.abs(vDirection.v[1])) {
164 | t1 = (ReturnResult.v[0] - vStart.v[0]) / vDirection.v[0];
165 | } else {
166 | t1 = (ReturnResult.v[1] - vStart.v[1]) / vDirection.v[1];
167 | }
168 |
169 | if(Math.abs(S2.vDirection.v[0]) > Math.abs(S2.vDirection.v[1])) {
170 | t2 = (ReturnResult.v[0] - S2.vStart.v[0]) / S2.vDirection.v[0];
171 | } else {
172 | t2 = (ReturnResult.v[1] - S2.vStart.v[1]) / S2.vDirection.v[1];
173 | }
174 |
175 | return ReturnResult;
176 | }
177 |
178 | public Vec Intersect(Segment S2)
179 | {
180 | Vec ReturnResult; // = new Vec();
181 |
182 | if(Math.abs(vDirection.Dot(S2.vDirection.Orthogonal())) < 0.1) {
183 | // Vector lines are parallel
184 | ReturnResult = IntersectParallel(S2);
185 | if(ReturnResult == null) {
186 | t1 = 0.0f;
187 | t2 = 0.0f;
188 | }
189 | } else {
190 | // Non parallel
191 | ReturnResult = IntersectNonParallel(S2);
192 | }
193 |
194 | return ReturnResult;
195 | }
196 |
197 | public float Length()
198 | {
199 | return vDirection.Length();
200 | }
201 |
202 | }
203 |
--------------------------------------------------------------------------------
/GlTron/src/com/glTron/Video/TrailMesh.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Iain Churcher
3 | *
4 | * Based on GLtron by Andreas Umbach (www.gltron.org)
5 | *
6 | * This file is part of GL TRON.
7 | *
8 | * GL TRON is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * GL TRON is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with GL TRON. If not, see .
20 | *
21 | */
22 |
23 | package com.glTron.Video;
24 |
25 | import com.glTron.Game.Player;
26 |
27 | public class TrailMesh {
28 |
29 | float Vertices[];
30 | float Normals[];
31 | float TexCoords[];
32 | short Indices[];
33 | byte Colors[];
34 | int iSize;
35 | int iUsed;
36 | int piOffset;
37 | int pvOffset;
38 |
39 | Player playerData;
40 |
41 | private enum MeshColourType {
42 | E_COLOUR_TRAIL,
43 | E_COLOUR_BRIGHT,
44 | E_COLOUR_CYCLE
45 | }
46 |
47 | private final float DECAL_WIDTH = 20.0f;
48 |
49 | private Vec normals[] = {
50 | new Vec(1.0f, 0.0f, 0.0f),
51 | new Vec(-1.0f, 0.0f, 0.0f),
52 | new Vec(0.0f, 1.0f, 0.0f),
53 | new Vec(0.0f,-1.0f,0.0f)
54 | };
55 |
56 | private final float DIRS_X[] = {0.0f, -1.0f, 0.0f, 1.0f};
57 | private final float DIRS_Y[] = {-1.0f, 0.0f, 1.0f, 0.0f};
58 |
59 | private final float BOW_LENGTH = 6.0f;
60 | private final float BOW_DIST2 = 0.85f;
61 | private final float BOW_DIST3 = 2.0f;
62 | private final float BOW_DIST1 = 0.4f;
63 | private final float dists[] = { BOW_DIST2, BOW_DIST3, BOW_DIST1, 0.0f };
64 |
65 | String Debug;
66 | StringBuffer sb = new StringBuffer(40);
67 |
68 | public TrailMesh(Player player)
69 | {
70 | int TrailOffset = player.getTrailOffset();
71 |
72 | playerData = player;
73 |
74 | int vmeshSize = ((TrailOffset * 4) + 8) + ((10 * 2) + 2);
75 | int imeshSize = ((TrailOffset * 6) + (2 * 6)) + ((10*6) + 6);
76 |
77 | Vertices = new float[3 * vmeshSize];
78 | Normals = new float[3 * vmeshSize];
79 | TexCoords = new float[2 * vmeshSize];
80 | Indices = new short[imeshSize];
81 | Colors = new byte[4 * vmeshSize];
82 |
83 | trailGeometry();
84 | bowGeometry();
85 | }
86 |
87 | private void bowGeometry()
88 | {
89 | Segment s = new Segment();
90 | int bdist = 2;
91 | int i;
92 | float trail_height = playerData.getTrailHeight();
93 | float t, fTop, fFloor;
94 | int iOffset = piOffset;
95 |
96 | s.vStart.v[0] = getSegmentEndX(0) ;
97 | s.vStart.v[1] = getSegmentEndY(0) ;
98 | s.vDirection.v[0] = getSegmentEndX(bdist) - s.vStart.v[0];
99 | s.vDirection.v[1] = getSegmentEndY(bdist) - s.vStart.v[1];
100 |
101 | for(i = 0; i < 10; i++)
102 | {
103 | t = i * 1.0f / 10.0f;
104 | fTop =(float) Math.sqrt(1.0f - t * t);
105 | fFloor = (t < 0.6f) ? 0.0f : 0.5f * (t - 0.6f);
106 |
107 | if(fTop < 0.3f) fTop = 0.3f;
108 |
109 | storeVertex(pvOffset,s,t,(fFloor * trail_height), (fTop * trail_height), DECAL_WIDTH, 0.0f);
110 | storeColor(pvOffset, MeshColourType.E_COLOUR_BRIGHT);
111 | pvOffset += 2;
112 |
113 | if(i > 0)
114 | {
115 | storeIndices(iOffset,pvOffset - 4);
116 | iOffset += 6;
117 | }
118 |
119 | }
120 | storeVertex(pvOffset,s,1.0f,(0.2f * trail_height),( 0.3f * trail_height),DECAL_WIDTH,0.0f);
121 | storeColor(pvOffset,MeshColourType.E_COLOUR_CYCLE);
122 | pvOffset += 2;
123 | storeIndices(iOffset,pvOffset - 4);
124 | iUsed += iOffset - piOffset;
125 | piOffset = iOffset;
126 | }
127 |
128 | private void trailGeometry()
129 | {
130 | int i;
131 | int curVertex = 0;
132 | int curIndex = 0;
133 | int TrailOffset = playerData.getTrailOffset();
134 | Segment segs[] = playerData.getTrails();
135 | float trail_height = playerData.getTrailHeight();
136 | float fTotalLength = 0.0f;
137 | float fsegLength;
138 | Segment s = new Segment();
139 |
140 | for(i=0; i < TrailOffset; i++)
141 | {
142 | fsegLength = segs[i].Length();
143 | if(i ==0 || cmpdir(segs[i-1],segs[i]) )
144 | {
145 | storeVertex(curVertex,segs[i],0.0f,0.0f,trail_height,fsegLength,fTotalLength);
146 | storeColor(curVertex,MeshColourType.E_COLOUR_TRAIL);
147 | curVertex += 2;
148 | }
149 |
150 | storeVertex(curVertex,segs[i],1.0f,0.0f,trail_height,fsegLength,fTotalLength);
151 | storeColor(curVertex, MeshColourType.E_COLOUR_TRAIL);
152 | curVertex += 2;
153 |
154 | storeIndices(curIndex, curVertex - 4);
155 | curIndex += 6;
156 |
157 | fTotalLength += fsegLength;
158 | }
159 |
160 | s.vStart.v[0] = segs[TrailOffset].vStart.v[0];
161 | s.vStart.v[1] = segs[TrailOffset].vStart.v[1];
162 | s.vDirection.v[0] = getSegmentEndX(1) - s.vStart.v[0];
163 | s.vDirection.v[1] = getSegmentEndY(1) - s.vStart.v[1];
164 |
165 | fsegLength = s.Length();
166 |
167 | storeVertex(curVertex,s,0.0f,0.0f,trail_height,fsegLength,fTotalLength);
168 | storeColor(curVertex, MeshColourType.E_COLOUR_TRAIL);
169 | curVertex += 2;
170 |
171 | storeVertex(curVertex,s,1.0f,0.0f,trail_height,fsegLength,fTotalLength);
172 | storeColor(curVertex,MeshColourType.E_COLOUR_TRAIL );
173 | curVertex += 2;
174 |
175 | storeIndices(curIndex,curVertex - 4);
176 | curIndex += 6;
177 |
178 | fTotalLength += fsegLength;
179 |
180 | s.vStart.v[0] += s.vDirection.v[0];
181 | s.vStart.v[1] += s.vDirection.v[1];
182 | s.vDirection.v[0] = getSegmentEndX(0) - s.vStart.v[0];
183 | s.vDirection.v[1] = getSegmentEndY(0) - s.vStart.v[1];
184 | fsegLength = s.Length();
185 |
186 | storeVertex(curVertex,s,0.0f,0.0f,trail_height,fsegLength,fTotalLength);
187 | storeColor(curVertex, MeshColourType.E_COLOUR_TRAIL);
188 | curVertex += 2;
189 |
190 | storeVertex(curVertex,s,1.0f,0.0f,trail_height,fsegLength,fTotalLength);
191 | storeColor(curVertex, MeshColourType.E_COLOUR_BRIGHT);
192 | curVertex += 2;
193 |
194 | storeIndices(curIndex,curVertex - 4);
195 | curIndex += 6;
196 |
197 | iUsed = curIndex;
198 | piOffset = curIndex;
199 | pvOffset = curVertex;
200 |
201 | }
202 |
203 | private void storeColor(int offset, MeshColourType colourType)
204 | {
205 | int colOffset = offset * 4;
206 | float White[] = {1.0f,1.0f,1.0f,1.0f};
207 | float color[] = {0.0f, 0.0f, 0.0f, 0.0f};
208 |
209 | switch(colourType)
210 | {
211 | case E_COLOUR_TRAIL:
212 | color = playerData.getColorAlpha();
213 | break;
214 | case E_COLOUR_BRIGHT:
215 | color = White;
216 | break;
217 | case E_COLOUR_CYCLE:
218 | color = playerData.getColorDiffuse();
219 | break;
220 | }
221 |
222 | Colors[colOffset++] = (byte)(color[0] * 255.0f);
223 | Colors[colOffset++] = (byte)(color[1] * 255.0f);
224 | Colors[colOffset++] =(byte)( color[2] * 255.0f);
225 | Colors[colOffset++] = (byte)(color[3] * 255.0f);
226 |
227 |
228 | Colors[colOffset++] = (byte)(color[0] * 255.0f);
229 | Colors[colOffset++] = (byte)(color[1] * 255.0f);
230 | Colors[colOffset++] =(byte)( color[2] * 255.0f);
231 | Colors[colOffset++] = (byte)(color[3] * 255.0f);
232 |
233 | }
234 |
235 | private float getSegmentEndY( int dist)
236 | {
237 | float tlength,blength;
238 | float retVal;
239 | int dir = playerData.getDirection();
240 | int TrailOffset = playerData.getTrailOffset();
241 | Segment segs[] = playerData.getTrails();
242 |
243 | if(DIRS_Y[dir] == 0)
244 | {
245 | retVal = segs[TrailOffset].vStart.v[1] + segs[TrailOffset].vDirection.v[1];
246 | }
247 | else
248 | {
249 | tlength = segs[TrailOffset].Length();
250 | blength = (tlength < 2 * BOW_LENGTH) ? tlength / 2 : BOW_LENGTH;
251 |
252 | retVal = (segs[TrailOffset].vStart.v[1] + segs[TrailOffset].vDirection.v[1] -
253 | dists[dist] * blength * DIRS_Y[dir]);
254 | }
255 |
256 | return retVal;
257 | }
258 |
259 | private float getSegmentEndX(int dist)
260 | {
261 | float tlength, blength;
262 | float retVal;
263 | int dir = playerData.getDirection();
264 | int TrailOffset = playerData.getTrailOffset();
265 | Segment segs[] = playerData.getTrails();
266 |
267 | if(DIRS_X[dir] == 0)
268 | {
269 | retVal = segs[TrailOffset].vStart.v[0] + segs[TrailOffset].vDirection.v[0];
270 | }
271 | else
272 | {
273 | tlength = segs[TrailOffset].Length();
274 | blength = (tlength < 2 * BOW_LENGTH) ? tlength /2 : BOW_LENGTH;
275 |
276 | retVal = (segs[TrailOffset].vStart.v[0] + segs[TrailOffset].vDirection.v[0] -
277 | dists[dist] * blength * DIRS_X[dir]);
278 | }
279 | return retVal;
280 | }
281 |
282 | private boolean cmpdir(Segment s1, Segment s2)
283 | {
284 | boolean returnval = true;
285 | if( (s1.vDirection.v[0] == 0.0f && s2.vDirection.v[0] == 0.0f) ||
286 | (s1.vDirection.v[1] == 0.0f && s2.vDirection.v[1] == 0.0f) )
287 | {
288 | returnval = false;
289 | }
290 | return returnval;
291 | }
292 |
293 | private void storeIndices(int indexOffset, int vertexOffset)
294 | {
295 | short ppBase[][] = {
296 | { 0, 2, 1, 2, 3, 1 },
297 | { 0, 1, 2, 1, 3, 2}
298 | };
299 | int i;
300 | int winding = 0;
301 |
302 | if(Vertices[vertexOffset * 3] == Vertices[(vertexOffset + 2) * 3])
303 | {
304 |
305 | winding = (Vertices[(vertexOffset * 3) + 1] <= Vertices[((vertexOffset + 2) * 3) + 1]) ? 0 : 1;
306 | }
307 | else
308 | {
309 | winding = (Vertices[vertexOffset * 3] < Vertices[(vertexOffset + 2) * 3]) ? 1 : 0;;
310 | }
311 |
312 | for(i = 0; i < 6; i++)
313 | Indices[indexOffset + i] =(short)(ppBase[winding][i] + vertexOffset);
314 | }
315 |
316 | private void storeVertex(
317 | int offset, Segment s, float t, float fFloor, float fTop,
318 | float fSegLength, float fTotalLength)
319 | {
320 |
321 | Vec v;
322 | int texOffset = 2 * offset;
323 |
324 | int iNormal;
325 | float fUStart;
326 |
327 | if(s.vDirection.v[0] == 0.0f)
328 | iNormal = 0;
329 | else
330 | iNormal = 2;
331 |
332 | fUStart = (fTotalLength / DECAL_WIDTH) - (float)Math.floor(fTotalLength / DECAL_WIDTH);
333 |
334 | v = new Vec(
335 | (s.vStart.v[0] + t * s.vDirection.v[0]),
336 | ( s.vStart.v[1] + t * s.vDirection.v[1]),
337 | fFloor);
338 |
339 | // sb=null;
340 | // sb = new StringBuffer(40);
341 | // Debug = sb.append("Offset = ").append(offset).append("/").append(vmeshSize).toString();
342 | // Log.e("GLTRON", Debug);
343 |
344 | TexCoords[texOffset] = fUStart + t * fSegLength / DECAL_WIDTH;
345 | TexCoords[texOffset + 1] = 0.0f;
346 |
347 | Vertices[offset * 3] = v.v[0];
348 | Vertices[(offset * 3) + 1] = v.v[1];
349 | Vertices[(offset * 3) + 2] = v.v[2];
350 |
351 | Normals[offset * 3] = normals[iNormal].v[0];
352 | Normals[(offset * 3) + 1] = normals[iNormal].v[1];
353 | Normals[(offset * 3) + 2] = normals[iNormal].v[2];
354 |
355 | texOffset += 2;
356 | v.v[2] = fTop;
357 | TexCoords[texOffset] = fUStart + t * fSegLength / DECAL_WIDTH;
358 | TexCoords[texOffset + 1] = 1.0f;
359 | Vertices[(offset + 1) * 3] = v.v[0];
360 | Vertices[((offset + 1) * 3) + 1] = v.v[1];
361 | Vertices[((offset + 1) * 3) + 2] = v.v[2];
362 |
363 | Normals[(offset + 1) * 3] = normals[iNormal].v[0];
364 | Normals[((offset + 1) *3) + 1] = normals[iNormal].v[1];
365 | Normals[((offset + 1) *3) + 2] = normals[iNormal].v[2];
366 | }
367 |
368 | }
369 |
--------------------------------------------------------------------------------
/GlTron/src/com/glTron/Video/Trails_Renderer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Iain Churcher
3 | *
4 | * Based on GLtron by Andreas Umbach (www.gltron.org)
5 | *
6 | * This file is part of GL TRON.
7 | *
8 | * GL TRON is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * GL TRON is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with GL TRON. If not, see .
20 | *
21 | */
22 |
23 | package com.glTron.Video;
24 |
25 | import java.nio.ByteBuffer;
26 | import java.nio.FloatBuffer;
27 | import java.nio.ShortBuffer;
28 |
29 | import javax.microedition.khronos.opengles.GL10;
30 |
31 | import com.glTron.R;
32 | import com.glTron.Game.*;
33 |
34 | import android.content.Context;
35 |
36 | public class Trails_Renderer {
37 |
38 | GLTexture Trails;
39 | GL10 gl;
40 |
41 | private final float LX = 2.0f;
42 | private final float LY = 2.0f;
43 |
44 | private final float shadow_matrix[] =
45 | {
46 | LX * LY, 0.0f, 0.0f, 0.0f,
47 | 0.0f, LX * LY, 0.0f, 0.0f,
48 | -LY, -LX, 0.0f, 0.0f,
49 | 0.0f, 0.0f, 0.0f, LX * LY
50 | };
51 |
52 | FloatBuffer shadowFb;
53 |
54 | public Trails_Renderer(GL10 gl_in, Context context)
55 | {
56 | gl = gl_in;
57 | Trails = new GLTexture(gl,context,R.drawable.gltron_traildecal,GL10.GL_REPEAT, GL10.GL_CLAMP_TO_EDGE);
58 | shadowFb = GraphicUtils.ConvToFloatBuffer(shadow_matrix);
59 | }
60 |
61 | public void Render(TrailMesh mesh)
62 | {
63 | int i;
64 |
65 | FloatBuffer vertexFb = GraphicUtils.ConvToFloatBuffer(mesh.Vertices);
66 | FloatBuffer normalFb = GraphicUtils.ConvToFloatBuffer(mesh.Normals);
67 | FloatBuffer texFb = GraphicUtils.ConvToFloatBuffer(mesh.TexCoords);
68 | ShortBuffer indBb = GraphicUtils.ConvToShortBuffer(mesh.Indices);
69 | ByteBuffer colorFb = GraphicUtils.ConvToByteBuffer(mesh.Colors);
70 |
71 | statesNormal();
72 |
73 | for(i = 0; i < 2; i++) // change to 2 to draw shadows
74 | {
75 | if( i == 0)
76 | statesNormal();
77 | else
78 | statesShadow();
79 |
80 | gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texFb);
81 | gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexFb);
82 | gl.glNormalPointer(GL10.GL_FLOAT, 0, normalFb);
83 | gl.glColorPointer(4, GL10.GL_UNSIGNED_BYTE, 0, colorFb);
84 |
85 | gl.glDrawElements(GL10.GL_TRIANGLES, mesh.iUsed, GL10.GL_UNSIGNED_SHORT, indBb);
86 |
87 | gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
88 | gl.glDisableClientState(GL10.GL_NORMAL_ARRAY);
89 | gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
90 | gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
91 |
92 | statesRestore();
93 | }
94 |
95 | gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_REPLACE);
96 |
97 | }
98 |
99 | private void statesShadow()
100 | {
101 | // gl.glDisable(GL10.GL_CULL_FACE);
102 | // gl.glDisable(GL10.GL_TEXTURE_2D);
103 | // gl.glDisable(GL10.GL_LIGHTING);
104 |
105 | gl.glEnable(GL10.GL_STENCIL_TEST);
106 | gl.glStencilOp(GL10.GL_REPLACE, GL10.GL_REPLACE, GL10.GL_REPLACE);
107 | gl.glStencilFunc(GL10.GL_GREATER, 1, 1);
108 | // gl.glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
109 | gl.glEnable(GL10.GL_BLEND);
110 | gl.glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
111 | gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
112 |
113 | gl.glPushMatrix();
114 | gl.glMultMatrixf(shadowFb);
115 |
116 | gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
117 | gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);
118 | gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
119 | gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
120 |
121 | gl.glDisable(GL10.GL_CULL_FACE);
122 | gl.glDisable(GL10.GL_TEXTURE_2D);
123 | gl.glDisable(GL10.GL_LIGHTING);
124 | }
125 |
126 | private void statesRestore()
127 | {
128 | gl.glDisable(GL10.GL_COLOR_MATERIAL);
129 | gl.glCullFace(GL10.GL_BACK);
130 | gl.glDisable(GL10.GL_CULL_FACE);
131 | gl.glDisable(GL10.GL_TEXTURE_2D);
132 | gl.glDisable(GL10.GL_BLEND);
133 | gl.glEnable(GL10.GL_LIGHTING);
134 | //gl.glPolygonMode(GL10.GL_FRONT_AND_BACK, GL10.GL_FILL);
135 | gl.glDisable(GL10.GL_POLYGON_OFFSET_FILL);
136 | gl.glDisable(GL10.GL_STENCIL_TEST);
137 | gl.glPopMatrix();
138 | }
139 | private void statesNormal()
140 | {
141 | gl.glEnable(GL10.GL_POLYGON_OFFSET_FILL);
142 | gl.glPolygonOffset(1,1);
143 | gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
144 | gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);
145 | gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
146 | //gl.glFrontFace(GL10.GL_CCW);
147 | gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
148 |
149 | gl.glDisable(GL10.GL_CULL_FACE);
150 | gl.glShadeModel(GL10.GL_SMOOTH);
151 | gl.glEnable(GL10.GL_TEXTURE_2D);
152 |
153 | gl.glBindTexture(GL10.GL_TEXTURE_2D, Trails.getTextureID());
154 |
155 | gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_DECAL);
156 |
157 | float black[] = { 0.0f, 0.0f, 0.0f, 1.0f};
158 | FloatBuffer fBlack = GraphicUtils.ConvToFloatBuffer(black);
159 |
160 | gl.glMaterialfv(GL10.GL_FRONT_AND_BACK,GL10. GL_SPECULAR, fBlack);
161 |
162 | gl.glEnable(GL10.GL_COLOR_MATERIAL);
163 |
164 | gl.glEnable(GL10.GL_BLEND);
165 | gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
166 |
167 | }
168 |
169 | FloatBuffer trailtopfb;
170 | static final float trail_top[] = {
171 | 1.0f, 1.0f, 1.0f, .7f,
172 | 1.0f, 1.0f, 1.0f, .7f,
173 | 1.0f, 1.0f, 1.0f, .7f};
174 |
175 | public void drawTrailLines(Segment segs[],int trail_offset, float trail_height, Camera cam)
176 | {
177 |
178 | int segOffset;
179 |
180 | if(trailtopfb == null)
181 | trailtopfb = GraphicUtils.ConvToFloatBuffer(trail_top);
182 |
183 | gl.glEnable(GL10.GL_LINE_SMOOTH);
184 | gl.glEnable(GL10.GL_BLEND);
185 | gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
186 | gl.glDisable(GL10.GL_LIGHTING);
187 |
188 | gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
189 | gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
190 |
191 | gl.glColorPointer(4, GL10.GL_FLOAT, 0, trailtopfb);
192 |
193 | for(segOffset = 0; segOffset <= trail_offset; segOffset++)
194 | {
195 | // Dont change alpha based on dist yet
196 | gl.glColorPointer(4, GL10.GL_FLOAT, 0, trailtopfb);
197 | gl.glColor4f(1.0f, 1.0f, 1.0f, 0.4f);
198 |
199 | float tempvertex[] =
200 | {
201 | segs[segOffset].vStart.v[0],
202 | segs[segOffset].vStart.v[1],
203 | trail_height,
204 |
205 | segs[segOffset].vStart.v[0] + segs[segOffset].vDirection.v[0],
206 | segs[segOffset].vStart.v[1] + segs[segOffset].vDirection.v[1],
207 | trail_height
208 | };
209 |
210 | FloatBuffer fb = GraphicUtils.ConvToFloatBuffer(tempvertex);
211 |
212 | gl.glVertexPointer(3, GL10.GL_FLOAT, 0, fb);
213 | gl.glDrawArrays(GL10.GL_LINES, 0, 2);
214 | }
215 |
216 | // TODO: Draw the final segment
217 | // gl.glColorPointer(4, GL10.GL_FLOAT, 0, trailtopfb);
218 | //
219 | // float tempvertex[] =
220 | // {
221 | // segs[trail_offset].vStart.v[0],
222 | // segs[trail_offset].vStart.v[1],
223 | // trail_height
224 | // };
225 |
226 | // gl.glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
227 |
228 | gl.glDisable(GL10.GL_BLEND);
229 | gl.glDisable(GL10.GL_LINE_SMOOTH);
230 | gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
231 | }
232 |
233 | }
234 |
--------------------------------------------------------------------------------
/GlTron/src/com/glTron/Video/Vec.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Iain Churcher
3 | *
4 | * Based on GLtron by Andreas Umbach (www.gltron.org)
5 | *
6 | * This file is part of GL TRON.
7 | *
8 | * GL TRON is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * GL TRON is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with GL TRON. If not, see .
20 | *
21 | */
22 |
23 | package com.glTron.Video;
24 |
25 | public class Vec {
26 |
27 | public float v[] = new float[3];
28 |
29 | public Vec()
30 | {
31 | v[0] = 0.0f;
32 | v[1] = 0.0f;
33 | v[2] = 0.0f;
34 | }
35 |
36 | public Vec(float x, float y, float z)
37 | {
38 | v[0] = x;
39 | v[1] = y;
40 | v[2] = z;
41 | }
42 |
43 | public void Copy(Vec V1)
44 | {
45 | v[0] = V1.v[0];
46 | v[1] = V1.v[1];
47 | v[2] = V1.v[2];
48 | }
49 |
50 | public Vec Add(Vec V1)
51 | {
52 | Vec ReturnResult = new Vec();
53 |
54 | ReturnResult.v[0] = v[0] + V1.v[0];
55 | ReturnResult.v[1] = v[1] + V1.v[1];
56 | ReturnResult.v[2] = v[2] + V1.v[2];
57 |
58 | return ReturnResult;
59 | }
60 |
61 | public Vec Sub(Vec V1)
62 | {
63 | Vec ReturnResult = new Vec();
64 |
65 | ReturnResult.v[0] = v[0] - V1.v[0];
66 | ReturnResult.v[1] = v[1] - V1.v[1];
67 | ReturnResult.v[2] = v[2] - V1.v[2];
68 |
69 | return ReturnResult;
70 | }
71 |
72 | public void Mul(float Mul)
73 | {
74 | v[0] *= Mul;
75 | v[1] *= Mul;
76 | v[2] *= Mul;
77 | }
78 |
79 | public void Scale(float fScale)
80 | {
81 | v[0] *= fScale;
82 | v[1] *= fScale;
83 | v[2] *= fScale;
84 | }
85 |
86 | public Vec Cross(Vec V1)
87 | {
88 | Vec ReturnResult = new Vec();
89 |
90 | ReturnResult.v[0] = v[1] * V1.v[2] - v[2] * V1.v[1];
91 | ReturnResult.v[1] = v[2] * V1.v[0] - v[0] * V1.v[2];
92 | ReturnResult.v[2] = v[0] * V1.v[1] - v[1] * V1.v[0];
93 |
94 | return ReturnResult;
95 | }
96 |
97 | public float Dot(Vec V1)
98 | {
99 | return (v[0] * V1.v[0] + v[1] * V1.v[1] + v[2] * V1.v[2]);
100 | }
101 |
102 | public float Length()
103 | {
104 | return (float) (Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]));
105 | }
106 |
107 | public float Length2()
108 | {
109 | return (float) (Math.sqrt(v[0] * v[0] + v[1] * v[1]));
110 | }
111 |
112 | public void Normalise()
113 | {
114 | float d = Length();
115 |
116 | if(d != 0) {
117 | v[0] /= d;
118 | v[1] /= d;
119 | v[2] /= d;
120 | }
121 | }
122 |
123 | public void Normalise2()
124 | {
125 | float d = Length2();
126 |
127 | if(d != 0)
128 | {
129 | v[0] /= d;
130 | v[1] /= d;
131 | }
132 | }
133 |
134 | public Vec Orthogonal()
135 | {
136 | Vec ReturnResult = new Vec();
137 |
138 | ReturnResult.v[0] = v[1];
139 | ReturnResult.v[1] = -v[0];
140 |
141 | return ReturnResult;
142 | }
143 |
144 | }
145 |
--------------------------------------------------------------------------------
/GlTron/src/com/glTron/Video/Video.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Iain Churcher
3 | *
4 | * Based on GLtron by Andreas Umbach (www.gltron.org)
5 | *
6 | * This file is part of GL TRON.
7 | *
8 | * GL TRON is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * GL TRON is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with GL TRON. If not, see .
20 | *
21 | */
22 |
23 | package com.glTron.Video;
24 |
25 | import javax.microedition.khronos.opengles.GL10;
26 |
27 | public class Video {
28 |
29 | float _height, _width;
30 | int _vp_x, _vp_y;
31 | int _vp_h, _vp_w;
32 |
33 | int _onScreen;
34 |
35 | public Video(int width, int height)
36 | {
37 | SetWidthHeight(width,height);
38 | _vp_x = 0;
39 | _vp_y = 0;
40 | _vp_w = Float.floatToIntBits(_width);
41 | _vp_h = Float.floatToIntBits(_height);
42 | }
43 |
44 | public void SetWidthHeight(int width, int height)
45 | {
46 | _height = Float.intBitsToFloat(height);
47 | _width = Float.intBitsToFloat(width);
48 | }
49 |
50 | public void rasonly(GL10 gl)
51 | {
52 | gl.glMatrixMode(GL10.GL_PROJECTION);
53 | gl.glLoadIdentity();
54 | gl.glOrthof(0.0f, (float)_vp_w, 0.0f, (float)_vp_h, 0.0f, 1.0f);
55 | gl.glMatrixMode(GL10.GL_MODELVIEW);
56 | gl.glLoadIdentity();
57 | gl.glViewport(0, 0, _vp_w, _vp_h);
58 | }
59 |
60 | public void doPerspective(GL10 gl, float GridSize)
61 | {
62 | int w,h;
63 |
64 | // gl.glMatrixMode(GL10.GL_PROJECTION);
65 | // float size = .01f * (float) Math.tan(Math.toRadians(45.0) / 2);
66 | // float ratio = _width / _height;
67 | // // perspective:
68 | // gl.glFrustumf(-size, size, -size / ratio, size / ratio, 0.01f, 100.0f);
69 | // w = Float.floatToIntBits(_width);
70 | // h = Float.floatToIntBits(_height);
71 | // gl.glViewport(0, 0, w, h);
72 |
73 | float top;
74 | float left;
75 | float ratio = _width / _height;
76 | //float znear = 0.5f;
77 | float znear = 1.0f;
78 | float zfar = (float)(GridSize * 6.5f);
79 | //float fov = 120.0f;
80 | float fov = 105.0f;
81 |
82 | gl.glMatrixMode(GL10.GL_PROJECTION);
83 | gl.glLoadIdentity();
84 | top = (float)Math.tan(fov * Math.PI / 360.0f) * (float)znear;
85 | left = (float)(((float)-top)*((float)ratio));
86 | gl.glFrustumf(left, -left, -top, top, znear, zfar);
87 |
88 | w = Float.floatToIntBits(_width);
89 | h = Float.floatToIntBits(_height);
90 | gl.glViewport(0, 0, w, h);
91 |
92 |
93 | }
94 |
95 | public int GetWidth()
96 | {
97 | return Float.floatToIntBits(_width);
98 | }
99 |
100 | public int GetHeight()
101 | {
102 | return Float.floatToIntBits(_height);
103 | }
104 |
105 | }
106 |
--------------------------------------------------------------------------------
/GlTron/src/com/glTron/Video/WorldGraphics.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Iain Churcher
3 | *
4 | * Based on GLtron by Andreas Umbach (www.gltron.org)
5 | *
6 | * This file is part of GL TRON.
7 | *
8 | * GL TRON is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * GL TRON is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with GL TRON. If not, see .
20 | *
21 | */
22 |
23 | package com.glTron.Video;
24 |
25 | import java.nio.ByteBuffer;
26 | import java.nio.FloatBuffer;
27 |
28 | import javax.microedition.khronos.opengles.GL10;
29 |
30 | import android.content.Context;
31 |
32 | import com.glTron.R;
33 |
34 | public class WorldGraphics {
35 |
36 | float _grid_size;
37 | FloatBuffer _WallVertexBuffer[] = new FloatBuffer[4];
38 | ByteBuffer _IndicesBuffer;
39 | FloatBuffer _TexBuffer;
40 | FloatBuffer _FloorTexBuffer;
41 | FloatBuffer _SkyBoxVertexBuffers[] = new FloatBuffer[6];
42 | int _NumOfIndices;
43 |
44 | // Textures
45 | GLTexture _SkyBoxTextures[];
46 | GLTexture _Walls[];
47 | GLTexture _Floor;
48 |
49 | public WorldGraphics(GL10 gl, Context context, float grid_size)
50 | {
51 | // Save Grid Size
52 | _grid_size = grid_size;
53 |
54 | initWalls();
55 | initSkyBox();
56 | loadTextures(gl,context);
57 |
58 | // Setup standard square index and tex buffers
59 | // Define indices and tex coords
60 | float t = grid_size / 240.0f;
61 | byte indices[] = {0,1,3, 0,3,2};
62 | //float texCoords[] = {0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f};
63 | float texCoords[] = {t, 1.0f, 0.0f, 1.0f, t, 0.0f, 0.0f, 0.0f};
64 |
65 | float l = grid_size / 4;
66 | t = l / 12;
67 | float florTexCoords [] = {0.0f, 0.0f, t,0.0f, 0.0f,t, t,t};
68 |
69 | _FloorTexBuffer = GraphicUtils.ConvToFloatBuffer(florTexCoords);
70 | _TexBuffer = GraphicUtils.ConvToFloatBuffer(texCoords);
71 | _IndicesBuffer = GraphicUtils.ConvToByteBuffer(indices);
72 | _NumOfIndices = indices.length;
73 |
74 | }
75 |
76 | private void loadTextures(GL10 gl, Context context)
77 | {
78 | GLTexture skyBoxTextures[] = {
79 | new GLTexture(gl,context, R.drawable.skybox0),
80 | new GLTexture(gl,context, R.drawable.skybox1),
81 | new GLTexture(gl,context, R.drawable.skybox2),
82 | new GLTexture(gl,context, R.drawable.skybox3),
83 | new GLTexture(gl,context, R.drawable.skybox4),
84 | new GLTexture(gl,context, R.drawable.skybox5) };
85 |
86 | _SkyBoxTextures = skyBoxTextures;
87 |
88 | GLTexture Walltex[] = {
89 | new GLTexture(gl,context,R.drawable.gltron_wall_1),
90 | new GLTexture(gl,context,R.drawable.gltron_wall_2),
91 | new GLTexture(gl,context,R.drawable.gltron_wall_3),
92 | new GLTexture(gl,context,R.drawable.gltron_wall_4) };
93 |
94 | _Walls = Walltex;
95 |
96 | _Floor = new GLTexture(gl,context,R.drawable.gltron_floor);
97 | }
98 |
99 | private void initSkyBox()
100 | {
101 | float d = (float)_grid_size * 3;
102 |
103 | float sides[][] = {
104 | { d, d, -d, d, -d, -d, d, -d, d, d, d, d }, /* front */
105 | { d, d, d, -d, d, d, -d, -d, d, d, -d, d }, /* top */
106 | { -d, d, -d, d, d, -d, d, d, d, -d, d, d }, /* left */
107 | { d, -d, -d, -d, -d, -d, -d, -d, d, d, -d, d }, /* right */
108 | { -d, d, -d, -d, -d, -d, d, -d, -d, d, d, -d }, /* bottom */
109 | { -d, -d, -d, -d, d, -d, -d, d, d, -d, -d, d } };/* back */
110 |
111 | for(int i=0; i<6; i++)
112 | {
113 | _SkyBoxVertexBuffers[i] = GraphicUtils.ConvToFloatBuffer(sides[i]);
114 | }
115 | }
116 |
117 | private void initWalls()
118 | {
119 | // Setup Wall buffers
120 | //float t = _grid_size / 240.0f;
121 | float h = 48.0f; // Wall height
122 |
123 | float WallVertices[][] =
124 | {
125 | { // Wall 1
126 | 0.0f, 0.0f, h,
127 | _grid_size, 0.0f, h,
128 | 0.0f, 0.0f, 0.0f,
129 | _grid_size, 0.0f, 0.0f
130 | },
131 | { // Wall 2
132 | _grid_size, 0.0f, h,
133 | _grid_size, _grid_size, h,
134 | _grid_size, 0.0f, 0.0f,
135 | _grid_size, _grid_size, 0.0f
136 | },
137 | { // Wall 3
138 | _grid_size, _grid_size, h,
139 | 0.0f, _grid_size, h,
140 | _grid_size, _grid_size, 0.0f,
141 | 0.0f, _grid_size, 0.0f
142 | },
143 | { // Wall 4
144 | 0.0f, _grid_size, h,
145 | 0.0f, 0.0f, h,
146 | 0.0f, _grid_size, 0.0f,
147 | 0.0f, 0.0f, 0.0f
148 | }
149 | };
150 |
151 | _WallVertexBuffer[0] = GraphicUtils.ConvToFloatBuffer(WallVertices[0]);
152 | _WallVertexBuffer[1] = GraphicUtils.ConvToFloatBuffer(WallVertices[1]);
153 | _WallVertexBuffer[2] = GraphicUtils.ConvToFloatBuffer(WallVertices[2]);
154 | _WallVertexBuffer[3] = GraphicUtils.ConvToFloatBuffer(WallVertices[3]);
155 |
156 | }
157 |
158 | public void drawWalls(GL10 gl)
159 | {
160 |
161 | gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
162 | gl.glEnable(GL10.GL_CULL_FACE);
163 | gl.glEnable(GL10.GL_TEXTURE_2D);
164 | gl.glEnable(GL10.GL_BLEND);
165 |
166 | for(int Walls=0; Walls<4; Walls++) {
167 |
168 | gl.glBindTexture(GL10.GL_TEXTURE_2D, _Walls[Walls].getTextureID());
169 | gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
170 | gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
171 | gl.glVertexPointer(3, GL10.GL_FLOAT, 0, _WallVertexBuffer[Walls]);
172 | gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, _TexBuffer);
173 | //Draw the vertices as triangles, based on the Index Buffer information
174 | gl.glDrawElements(GL10.GL_TRIANGLES, _NumOfIndices, GL10.GL_UNSIGNED_BYTE, _IndicesBuffer);
175 | //Disable the client state before leaving
176 | gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
177 | gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
178 | }
179 |
180 | gl.glDisable(GL10.GL_CULL_FACE);
181 | gl.glDisable(GL10.GL_TEXTURE_2D);
182 | gl.glDisable(GL10.GL_BLEND);
183 |
184 | }
185 |
186 | public void drawFloorTextured(GL10 gl)
187 | {
188 | int i,j,l;
189 |
190 | gl.glEnable(GL10.GL_BLEND);
191 | gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
192 | gl.glEnable(GL10.GL_TEXTURE_2D);
193 | gl.glBindTexture(GL10.GL_TEXTURE_2D, _Floor.getTextureID());
194 |
195 | gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
196 |
197 | l = (int)(_grid_size / 4);
198 |
199 | for(i = 0; i < (int)_grid_size; i += l) {
200 | for(j = 0; j < (int)_grid_size; j += l) {
201 | float rawVertices[] = new float[4 * 3];
202 |
203 | rawVertices[0] = (float)i;
204 | rawVertices[1] = (float)j;
205 | rawVertices[2] = 0.0f;
206 |
207 | rawVertices[3] = (float)(i + l);
208 | rawVertices[4] = (float)j;
209 | rawVertices[5] = 0.0f;
210 |
211 | rawVertices[6] = (float)i;
212 | rawVertices[7] = (float)(j + l);
213 | rawVertices[8] = 0.0f;
214 |
215 | rawVertices[9] = (float)(i + l);
216 | rawVertices[10] = (float)(j + l);
217 | rawVertices[11] = 0.0f;
218 |
219 | FloatBuffer VertexBuffer = GraphicUtils.ConvToFloatBuffer(rawVertices);
220 |
221 | gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
222 | gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
223 | //gl.glFrontFace(GL10.GL_CCW);
224 |
225 | gl.glVertexPointer(3, GL10.GL_FLOAT, 0, VertexBuffer);
226 | gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, _FloorTexBuffer);
227 |
228 | //Draw the vertices as triangles, based on the Index Buffer information
229 | gl.glDrawElements(GL10.GL_TRIANGLES, _NumOfIndices, GL10.GL_UNSIGNED_BYTE, _IndicesBuffer);
230 |
231 | //Disable the client state before leaving
232 | gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
233 | gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
234 | }
235 | }
236 | }
237 |
238 | public void drawSkyBox(GL10 gl)
239 | {
240 | gl.glEnable(GL10.GL_TEXTURE_2D);
241 | gl.glDepthMask(false);
242 | gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
243 |
244 | for(int i=0; i<6; i++)
245 | {
246 | gl.glBindTexture(GL10.GL_TEXTURE_2D, _SkyBoxTextures[i].getTextureID());
247 |
248 | gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
249 | gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
250 | //gl.glFrontFace(GL10.GL_CCW);
251 |
252 | gl.glVertexPointer(3, GL10.GL_FLOAT, 0, _SkyBoxVertexBuffers[i]);
253 | gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, _TexBuffer);
254 |
255 | gl.glDrawElements(GL10.GL_TRIANGLES, _NumOfIndices, GL10.GL_UNSIGNED_BYTE, _IndicesBuffer);
256 |
257 | gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
258 | gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
259 |
260 | }
261 | gl.glDisable(GL10.GL_TEXTURE_2D);
262 | gl.glDepthMask(true);
263 |
264 | }
265 |
266 |
267 | }
268 |
--------------------------------------------------------------------------------
/GlTron/src/com/glTron/glTron.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright © 2012 Iain Churcher
3 | *
4 | * Based on GLtron by Andreas Umbach (www.gltron.org)
5 | *
6 | * This file is part of GL TRON.
7 | *
8 | * GL TRON is free software: you can redistribute it and/or modify
9 | * it under the terms of the GNU General Public License as published by
10 | * the Free Software Foundation, either version 3 of the License, or
11 | * (at your option) any later version.
12 | *
13 | * GL TRON is distributed in the hope that it will be useful,
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | * GNU General Public License for more details.
17 | *
18 | * You should have received a copy of the GNU General Public License
19 | * along with GL TRON. If not, see .
20 | *
21 | */
22 |
23 | package com.glTron;
24 |
25 | import android.app.Activity;
26 | import android.content.Intent;
27 | import android.os.Bundle;
28 | import android.view.Display;
29 | import android.view.KeyEvent;
30 | import android.view.Window;
31 | import android.view.WindowManager;
32 |
33 | public class glTron extends Activity {
34 | /** Called when the activity is first created. */
35 | private OpenGLView _View;
36 |
37 | private Boolean _FocusChangeFalseSeen = false;
38 | private Boolean _Resume = false;
39 |
40 | @Override
41 | public void onCreate(Bundle savedInstanceState) {
42 |
43 | WindowManager w = getWindowManager();
44 | Display d = w.getDefaultDisplay();
45 | int width = d.getWidth();
46 | int height = d.getHeight();
47 |
48 | super.onCreate(savedInstanceState);
49 |
50 | this.requestWindowFeature(Window.FEATURE_NO_TITLE);
51 | getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
52 | WindowManager.LayoutParams.FLAG_FULLSCREEN);
53 |
54 | _View = new OpenGLView(this, width, height);
55 | setContentView(_View);
56 |
57 | }
58 |
59 |
60 | @Override
61 | public void onPause() {
62 | _View.onPause();
63 | super.onPause();
64 | }
65 |
66 | @Override
67 | public void onResume() {
68 | if(!_FocusChangeFalseSeen)
69 | {
70 | _View.onResume();
71 | }
72 | _Resume = true;
73 | super.onResume();
74 | }
75 |
76 | @Override
77 | public void onWindowFocusChanged(boolean focus) {
78 | if(focus)
79 | {
80 | if(_Resume)
81 | {
82 | _View.onResume();
83 | }
84 |
85 | _Resume = false;
86 | _FocusChangeFalseSeen = false;
87 | }
88 | else
89 | {
90 | _FocusChangeFalseSeen = true;
91 | }
92 | }
93 |
94 | //open menu when key pressed
95 | public boolean onKeyUp(int keyCode, KeyEvent event) {
96 | if (keyCode == KeyEvent.KEYCODE_MENU) {
97 | this.startActivity(new Intent(this, Preferences.class));
98 | }
99 | return super.onKeyUp(keyCode, event);
100 | }
101 | }
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | Android Port of glTRON -
2 |
3 | INTRODUCTION
4 | ============
5 | This project was undertaken by myself (Iain Churcher) to learn both android and openGL ES programming.
6 |
7 | The code in this project was based on glTron version 0.7 by Andreas Umbach and can be found at the following website:
8 |
9 | www.gltron.org
10 |
11 | The code created is Java port of the original 'C' code, there is no Android NDK calls thus should be fully portable to all current and future Android platforms.
12 |
13 | This is not a faithful port and I have taken 'creative' license with numerous concepts.
14 |
15 | I am fairly new to Java coming from a C background and as such please forgive my messy inefficient code.
16 |
17 | I hope that this helps other people with learning to program android opengl games and that they have as much fun as I have had making this.
18 |
19 | I can be contacted via GitHub (Chluverman)... or via iain.linux.coding@gmail.com
20 |
21 | LICENSE
22 | =======
23 |
24 | As this code was derived from a GPL project all code thus provided remains under the GPLv3 and can be found on github under the android-gltron repository.
25 |
26 | See COPYING file for license info
27 |
28 | Note that the GPL means you have to contribute changes back to the community!
29 |
30 | TO DO LIST
31 | ==========
32 |
33 | As this was a learning experiance this is not a faitful port missing features are as follows:
34 |
35 | 1) Recogniser not implemented.
36 | 2) Bike shadows not implemented
37 | 3) Bike glow not implemented
38 | 4) Bike model explosion (attempted this but was far to slow on my phone)
39 | 5) Speed Boost..
40 | 6) 2d Map
41 | 7) Multiplayer (alas i only have one android device)
42 | 8) Loadable artpacks (fixed to the default)
43 | 9) Any user settings.. (e.g. fixed to HARD AI) (Now done in 1.1)
44 | 10) 3D sound (only your own bike makes engine noise and no sounds are directional)
45 |
46 | Probably a few other things ive missed.
47 |
48 | I have no immediate plans to continue working this code but if enough people request features than I shall endevour to find some more time.
49 |
50 | DEVICES TESTED ON
51 | =================
52 |
53 | Developed on a Nexus S running Ice Cream Sandwich
54 |
55 | Tested on:
56 | Samsung Tab 10.1
57 | Sony Erricson Xperia
58 |
--------------------------------------------------------------------------------
/RELEASE_NOTES.txt:
--------------------------------------------------------------------------------
1 | RELEASE NOTES:
2 |
3 | June 2012 - 1.1.2 - Remove AdMob
4 | 1) Remove AdMob including related permissions to comply fully with the GPL
5 | 2) Updated license info to GPLv3
6 | 3) Added .gitignore file to no longer configure auto generated files
7 | 4) Added installLocation in manifest to allow moving to external storage
8 |
9 | June 2012 - 1.1.1 - Bug fixes
10 | 1) Fix birds eye camera view (was defaulting to Normal when selected)
11 | 2) Fix back key to exit game (broken after last update)
12 |
13 | June 2012 - 1.1 - User preferences added
14 |
15 | Added user specified options:-
16 | 1) Bike Colour select from 6 colours
17 | 2) Toggle Music / SFX on/off
18 | 3) Toggle FPS counter
19 | 4) Change Camera mode
20 | 5) Select number of players between 2 and 6
21 | 6) Select Arena Size (Small, Medium, Large)
22 | 7) Select Game Speed (Slow, Normal, Fast, Extreme)
23 |
24 | Note: Increasing the Arena size and adding players reduces performance.
25 |
26 | Thanks to Noah from NVM Tech for inspiration and code contributions.
27 |
28 |
29 | Feb 2012 - 1.0 - Initial version
30 |
--------------------------------------------------------------------------------