Normalize all the line endings
This commit is contained in:
parent
53cafa2f3b
commit
d6a65ff731
9494
data/g3d/test.g3dj
9494
data/g3d/test.g3dj
File diff suppressed because it is too large
Load Diff
@ -1,177 +1,177 @@
|
||||
{
|
||||
"version": [ 0, 1],
|
||||
"id": "",
|
||||
"meshes": [
|
||||
{
|
||||
"attributes": ["POSITION", "NORMAL", "TEXCOORD0"],
|
||||
"vertices": [
|
||||
-0.003717, -0.043092, 0.000001, 0.000000, -1.000000, 0.000000, 0.000000, 0.000000,
|
||||
-0.003717, -0.043092, -0.019798, 0.000000, -0.609973, -0.792383, 0.000000, 0.000000,
|
||||
0.013430, -0.043092, -0.009898, 0.686239, -0.609973, -0.396191, 0.000000, 0.000000,
|
||||
-0.003717, 0.527242, 0.000001, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000,
|
||||
0.013430, 0.527242, -0.009898, 0.686239, 0.609973, -0.396191, 0.000000, 0.000000,
|
||||
-0.003717, 0.527242, -0.019798, 0.000000, 0.609973, -0.792383, 0.000000, 0.000000,
|
||||
0.013430, -0.043092, 0.009901, 0.686239, -0.609973, 0.396191, 0.000000, 0.000000,
|
||||
0.013430, 0.527242, 0.009901, 0.686239, 0.609973, 0.396191, 0.000000, 0.000000,
|
||||
-0.003717, -0.043092, 0.019801, 0.000000, -0.609973, 0.792383, 0.000000, 0.000000,
|
||||
-0.003717, 0.527242, 0.019801, 0.000000, 0.609973, 0.792383, 0.000000, 0.000000,
|
||||
-0.020865, -0.043092, 0.009901, -0.686239, -0.609973, 0.396191, 0.000000, 0.000000,
|
||||
-0.020865, 0.527242, 0.009901, -0.686239, 0.609973, 0.396191, 0.000000, 0.000000,
|
||||
-0.020865, -0.043092, -0.009898, -0.686239, -0.609973, -0.396191, 0.000000, 0.000000,
|
||||
-0.020865, 0.527242, -0.009898, -0.686239, 0.609973, -0.396191, 0.000000, 0.000000,
|
||||
-0.000052, 1.708732, 0.000001, 0.000000, 1.000000, 0.000000, 0.627643, 0.963260,
|
||||
-0.056858, 1.692897, -0.056805, -0.359325, 0.861232, -0.359325, 0.811107, 0.943917,
|
||||
-0.080388, 1.692897, 0.000001, -0.508194, 0.861232, 0.000000, 0.930977, 0.971962,
|
||||
-0.112293, 1.619116, -0.112239, -0.584552, 0.562639, -0.584552, 0.871491, 0.884983,
|
||||
-0.158784, 1.619116, 0.000001, -0.826655, 0.562639, 0.000000, 1.012361, 0.910828,
|
||||
-0.176420, 1.422079, -0.176367, -0.675863, 0.293832, -0.675863, 0.903795, 0.728324,
|
||||
-0.249474, 1.422079, 0.000001, -0.955840, 0.293832, 0.000000, 1.035246, 0.751852,
|
||||
-0.210746, 1.159339, -0.210693, -0.704306, 0.088870, -0.704306, 0.922129, 0.451029,
|
||||
-0.298019, 1.159339, 0.000001, -0.996033, 0.088870, 0.000000, 1.045340, 0.473093,
|
||||
-0.210605, 0.903175, -0.210552, -0.705252, -0.072024, -0.705252, 0.936767, 0.254108,
|
||||
-0.297820, 0.903175, 0.000001, -0.997375, -0.072024, 0.000000, 1.052424, 0.274946,
|
||||
-0.180964, 0.617981, -0.180911, -0.685263, -0.246529, -0.685263, 0.956801, 0.142573,
|
||||
-0.255900, 0.617981, 0.000001, -0.969115, -0.246529, 0.000000, 1.061122, 0.161660,
|
||||
-0.116291, 0.378825, -0.116238, -0.610279, -0.505051, -0.610279, 0.991689, 0.079506,
|
||||
-0.164439, 0.378825, 0.000001, -0.863063, -0.505051, 0.000000, 1.074527, 0.095355,
|
||||
-0.059153, 0.290116, -0.059100, -0.407514, -0.817194, -0.407544, 1.038003, 0.052079,
|
||||
-0.083634, 0.290116, 0.000001, -0.576312, -0.817194, 0.000000, 1.090933, 0.063214,
|
||||
-0.083634, 0.290116, 0.000001, -0.576312, -0.817194, 0.000000, 0.090933, 0.063214,
|
||||
-0.059153, 0.290116, -0.059100, -0.407514, -0.817194, -0.407544, 0.038003, 0.052079,
|
||||
-0.000125, 0.265210, -0.000071, -0.000244, -0.999969, -0.000244, 0.127500, 0.036749,
|
||||
-0.000051, 0.290116, -0.083580, 0.000000, -0.817194, -0.576312, 0.994047, 0.033372,
|
||||
-0.000125, 0.265210, -0.000071, -0.000244, -0.999969, -0.000244, 1.127500, 0.036749,
|
||||
-0.000051, 0.378825, -0.164386, 0.000000, -0.505051, -0.863063, 0.893772, 0.053663,
|
||||
-0.000052, 0.617981, -0.255847, 0.000000, -0.246529, -0.969115, 0.836458, 0.114704,
|
||||
-0.000052, 0.903175, -0.297766, 0.000000, -0.072024, -0.997375, 0.812221, 0.226047,
|
||||
-0.000052, 1.159339, -0.297966, 0.000000, 0.088870, -0.996033, 0.797565, 0.423137,
|
||||
-0.000052, 1.422079, -0.249421, 0.000000, 0.293832, -0.955840, 0.781975, 0.700922,
|
||||
-0.000052, 1.619116, -0.158731, 0.000000, 0.562639, -0.826655, 0.759783, 0.858997,
|
||||
-0.000052, 1.692897, -0.080335, 0.000000, 0.861232, -0.508194, 0.728165, 0.921879,
|
||||
0.056754, 1.692897, -0.056805, 0.359325, 0.861232, -0.359325, 0.652361, 0.910987,
|
||||
0.112189, 1.619116, -0.112239, 0.584552, 0.562639, -0.584552, 0.659906, 0.845090,
|
||||
0.176316, 1.422079, -0.176367, 0.675863, 0.293832, -0.675863, 0.665734, 0.684958,
|
||||
0.210643, 1.159339, -0.210693, 0.704306, 0.088870, -0.704306, 0.670277, 0.405750,
|
||||
0.210502, 0.903175, -0.210552, 0.705252, -0.072024, -0.705252, 0.675032, 0.207335,
|
||||
0.180860, 0.617981, -0.180910, 0.685263, -0.246529, -0.685263, 0.684415, 0.093825,
|
||||
0.116188, 0.378825, -0.116237, 0.610279, -0.505051, -0.610279, 0.723612, 0.027920,
|
||||
0.059050, 0.290116, -0.059099, 0.407483, -0.817255, -0.407422, 1.018456, 0.011649,
|
||||
0.059050, 0.290116, -0.059099, 0.407483, -0.817255, -0.407422, 0.018456, 0.011649,
|
||||
0.083530, 0.290116, 0.000002, 0.576159, -0.817316, 0.000000, 0.267608, 0.018648,
|
||||
0.164335, 0.378825, 0.000002, 0.863063, -0.505051, 0.000000, 0.457225, 0.035136,
|
||||
0.255796, 0.617981, 0.000002, 0.969115, -0.246529, 0.000000, 0.515690, 0.098717,
|
||||
0.297716, 0.903175, 0.000002, 0.997375, -0.072024, 0.000000, 0.532803, 0.211513,
|
||||
0.297915, 1.159339, 0.000002, 0.996033, 0.088870, 0.000000, 0.541872, 0.409545,
|
||||
0.249370, 1.422079, 0.000002, 0.955840, 0.293832, 0.000000, 0.550746, 0.688375,
|
||||
0.158680, 1.619116, 0.000002, 0.826655, 0.562639, 0.000000, 0.562378, 0.848006,
|
||||
0.080284, 1.692897, 0.000001, 0.508194, 0.861232, 0.000000, 0.577714, 0.913236,
|
||||
0.056754, 1.692897, 0.056808, 0.359325, 0.861232, 0.359325, 0.500528, 0.928224,
|
||||
0.112188, 1.619116, 0.112242, 0.584552, 0.562670, 0.584552, 0.459880, 0.866817,
|
||||
0.176316, 1.422079, 0.176370, 0.675863, 0.293832, 0.675863, 0.433163, 0.709519,
|
||||
0.210642, 1.159339, 0.210696, 0.704306, 0.088870, 0.704306, 0.415507, 0.432148,
|
||||
0.210501, 0.903175, 0.210555, 0.705252, -0.072024, 0.705252, 0.399773, 0.235351,
|
||||
0.180860, 0.617981, 0.180914, 0.685263, -0.246529, 0.685263, 0.375517, 0.124299,
|
||||
0.116187, 0.378825, 0.116241, 0.610279, -0.505051, 0.610279, 0.325269, 0.063109,
|
||||
0.059049, 0.290116, 0.059103, 0.407361, -0.817347, 0.407392, 0.248452, 0.040330,
|
||||
-0.000053, 0.290116, 0.083583, 0.000000, -0.817316, 0.576159, 0.199939, 0.056802,
|
||||
-0.000053, 0.378825, 0.164389, 0.000000, -0.505051, 0.863063, 0.234895, 0.086200,
|
||||
-0.000053, 0.617981, 0.255850, 0.000000, -0.246529, 0.969115, 0.262269, 0.150492,
|
||||
-0.000052, 0.903175, 0.297769, 0.000000, -0.072024, 0.997375, 0.278892, 0.262611,
|
||||
-0.000052, 1.159339, 0.297968, 0.000000, 0.088870, 0.996033, 0.291619, 0.459894,
|
||||
-0.000052, 1.422079, 0.249424, 0.000000, 0.293832, 0.955840, 0.308400, 0.737559,
|
||||
-0.000052, 1.619116, 0.158734, 0.000000, 0.562670, 0.826655, 0.340691, 0.894603,
|
||||
-0.000052, 1.692897, 0.080338, 0.000000, 0.861232, 0.508194, 0.411564, 0.953109,
|
||||
-0.056858, 1.692897, 0.056808, -0.359325, 0.861232, 0.359325, 0.247502, 0.980115,
|
||||
-0.112293, 1.619116, 0.112242, -0.584552, 0.562670, 0.584552, 0.186319, 0.915857,
|
||||
-0.176420, 1.422079, 0.176369, -0.675863, 0.293832, 0.675863, 0.173739, 0.755927,
|
||||
-0.210747, 1.159339, 0.210696, -0.704306, 0.088870, 0.704306, 0.168491, 0.476740,
|
||||
-0.210606, 0.903175, 0.210555, -0.705252, -0.072024, 0.705252, 0.164886, 0.278291,
|
||||
-0.180964, 0.617981, 0.180913, -0.685263, -0.246529, 0.685263, 0.160531, 0.164632,
|
||||
-0.116292, 0.378825, 0.116240, -0.610279, -0.505051, 0.610279, 0.153922, 0.097744,
|
||||
-0.059154, 0.290116, 0.059102, -0.407453, -0.817255, 0.407483, 0.145909, 0.064880,
|
||||
-0.164439, 0.378825, 0.000001, -0.863063, -0.505051, 0.000000, 0.074527, 0.095355,
|
||||
-0.255900, 0.617981, 0.000001, -0.969115, -0.246529, 0.000000, 0.061122, 0.161660,
|
||||
-0.297820, 0.903175, 0.000001, -0.997375, -0.072024, 0.000000, 0.052424, 0.274946,
|
||||
-0.298019, 1.159339, 0.000001, -0.996033, 0.088870, 0.000000, 0.045340, 0.473093,
|
||||
-0.249474, 1.422079, 0.000001, -0.955840, 0.293832, 0.000000, 0.035246, 0.751852,
|
||||
-0.158784, 1.619116, 0.000001, -0.826655, 0.562639, 0.000000, 0.012361, 0.910828,
|
||||
-0.056858, 1.692897, 0.056808, -0.359325, 0.861232, 0.359325, 1.247502, 0.980115,
|
||||
-0.112293, 1.619116, 0.112242, -0.584552, 0.562670, 0.584552, 1.186319, 0.915857
|
||||
],
|
||||
"parts": [
|
||||
{
|
||||
"id": "mpart1",
|
||||
"type": "TRIANGLES",
|
||||
"indices": [
|
||||
0, 1, 2, 3, 4, 5, 0, 2, 6, 3, 7, 4,
|
||||
0, 6, 8, 3, 9, 7, 0, 8, 10, 3, 11, 9,
|
||||
0, 10, 12, 3, 13, 11, 12, 1, 0, 3, 5, 13,
|
||||
1, 5, 4, 1, 4, 2, 2, 4, 7, 2, 7, 6,
|
||||
6, 7, 9, 6, 9, 8, 8, 9, 11, 8, 11, 10,
|
||||
10, 11, 13, 10, 13, 12, 5, 1, 12, 5, 12, 13,
|
||||
14, 15, 16, 16, 15, 17, 16, 17, 18, 18, 17, 19,
|
||||
18, 19, 20, 20, 19, 21, 20, 21, 22, 22, 21, 23,
|
||||
22, 23, 24, 24, 23, 25, 24, 25, 26, 26, 25, 27,
|
||||
26, 27, 28, 28, 27, 29, 28, 29, 30, 31, 32, 33,
|
||||
29, 34, 35, 27, 36, 34, 27, 34, 29, 25, 37, 36,
|
||||
25, 36, 27, 23, 38, 37, 23, 37, 25, 21, 39, 38,
|
||||
21, 38, 23, 19, 40, 39, 19, 39, 21, 17, 41, 40,
|
||||
17, 40, 19, 15, 42, 41, 15, 41, 17, 15, 14, 42,
|
||||
42, 14, 43, 42, 43, 44, 42, 44, 41, 41, 44, 45,
|
||||
41, 45, 40, 40, 45, 46, 40, 46, 39, 39, 46, 47,
|
||||
39, 47, 38, 38, 47, 48, 38, 48, 37, 37, 48, 49,
|
||||
37, 49, 36, 36, 49, 50, 36, 50, 34, 34, 50, 35,
|
||||
51, 52, 33, 49, 53, 52, 49, 52, 50, 48, 54, 53,
|
||||
48, 53, 49, 47, 55, 54, 47, 54, 48, 46, 56, 55,
|
||||
46, 55, 47, 45, 57, 56, 45, 56, 46, 44, 58, 57,
|
||||
44, 57, 45, 43, 59, 58, 43, 58, 44, 43, 14, 59,
|
||||
59, 14, 60, 59, 60, 61, 59, 61, 58, 58, 61, 62,
|
||||
58, 62, 57, 57, 62, 63, 57, 63, 56, 56, 63, 64,
|
||||
56, 64, 55, 55, 64, 65, 55, 65, 54, 54, 65, 66,
|
||||
54, 66, 53, 53, 66, 67, 53, 67, 52, 52, 67, 33,
|
||||
67, 68, 33, 66, 69, 68, 66, 68, 67, 65, 70, 69,
|
||||
65, 69, 66, 64, 71, 70, 64, 70, 65, 63, 72, 71,
|
||||
63, 71, 64, 62, 73, 72, 62, 72, 63, 61, 74, 73,
|
||||
61, 73, 62, 60, 75, 74, 60, 74, 61, 60, 14, 75,
|
||||
75, 14, 76, 75, 76, 77, 75, 77, 74, 74, 77, 78,
|
||||
74, 78, 73, 73, 78, 79, 73, 79, 72, 72, 79, 80,
|
||||
72, 80, 71, 71, 80, 81, 71, 81, 70, 70, 81, 82,
|
||||
70, 82, 69, 69, 82, 83, 69, 83, 68, 68, 83, 33,
|
||||
83, 31, 33, 82, 84, 31, 82, 31, 83, 81, 85, 84,
|
||||
81, 84, 82, 80, 86, 85, 80, 85, 81, 79, 87, 86,
|
||||
79, 86, 80, 78, 88, 87, 78, 87, 79, 77, 89, 88,
|
||||
77, 88, 78, 90, 16, 18, 90, 18, 91, 90, 14, 16
|
||||
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"materials": [
|
||||
{
|
||||
"id": "_tree.png",
|
||||
"diffuse": [ 0.900000, 0.900000, 0.900000],
|
||||
"specular": [ 0.100000, 0.100000, 0.100000],
|
||||
"textures": [
|
||||
{
|
||||
"id": "_tree.png",
|
||||
"filename": "tree.png",
|
||||
"type": "DIFFUSE"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"nodes": [
|
||||
{
|
||||
"id": "treeA_root",
|
||||
"parts": [
|
||||
{
|
||||
"meshpartid": "mpart1",
|
||||
"materialid": "_tree.png",
|
||||
"uvMapping": [[ 0]]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"animations": []
|
||||
{
|
||||
"version": [ 0, 1],
|
||||
"id": "",
|
||||
"meshes": [
|
||||
{
|
||||
"attributes": ["POSITION", "NORMAL", "TEXCOORD0"],
|
||||
"vertices": [
|
||||
-0.003717, -0.043092, 0.000001, 0.000000, -1.000000, 0.000000, 0.000000, 0.000000,
|
||||
-0.003717, -0.043092, -0.019798, 0.000000, -0.609973, -0.792383, 0.000000, 0.000000,
|
||||
0.013430, -0.043092, -0.009898, 0.686239, -0.609973, -0.396191, 0.000000, 0.000000,
|
||||
-0.003717, 0.527242, 0.000001, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000,
|
||||
0.013430, 0.527242, -0.009898, 0.686239, 0.609973, -0.396191, 0.000000, 0.000000,
|
||||
-0.003717, 0.527242, -0.019798, 0.000000, 0.609973, -0.792383, 0.000000, 0.000000,
|
||||
0.013430, -0.043092, 0.009901, 0.686239, -0.609973, 0.396191, 0.000000, 0.000000,
|
||||
0.013430, 0.527242, 0.009901, 0.686239, 0.609973, 0.396191, 0.000000, 0.000000,
|
||||
-0.003717, -0.043092, 0.019801, 0.000000, -0.609973, 0.792383, 0.000000, 0.000000,
|
||||
-0.003717, 0.527242, 0.019801, 0.000000, 0.609973, 0.792383, 0.000000, 0.000000,
|
||||
-0.020865, -0.043092, 0.009901, -0.686239, -0.609973, 0.396191, 0.000000, 0.000000,
|
||||
-0.020865, 0.527242, 0.009901, -0.686239, 0.609973, 0.396191, 0.000000, 0.000000,
|
||||
-0.020865, -0.043092, -0.009898, -0.686239, -0.609973, -0.396191, 0.000000, 0.000000,
|
||||
-0.020865, 0.527242, -0.009898, -0.686239, 0.609973, -0.396191, 0.000000, 0.000000,
|
||||
-0.000052, 1.708732, 0.000001, 0.000000, 1.000000, 0.000000, 0.627643, 0.963260,
|
||||
-0.056858, 1.692897, -0.056805, -0.359325, 0.861232, -0.359325, 0.811107, 0.943917,
|
||||
-0.080388, 1.692897, 0.000001, -0.508194, 0.861232, 0.000000, 0.930977, 0.971962,
|
||||
-0.112293, 1.619116, -0.112239, -0.584552, 0.562639, -0.584552, 0.871491, 0.884983,
|
||||
-0.158784, 1.619116, 0.000001, -0.826655, 0.562639, 0.000000, 1.012361, 0.910828,
|
||||
-0.176420, 1.422079, -0.176367, -0.675863, 0.293832, -0.675863, 0.903795, 0.728324,
|
||||
-0.249474, 1.422079, 0.000001, -0.955840, 0.293832, 0.000000, 1.035246, 0.751852,
|
||||
-0.210746, 1.159339, -0.210693, -0.704306, 0.088870, -0.704306, 0.922129, 0.451029,
|
||||
-0.298019, 1.159339, 0.000001, -0.996033, 0.088870, 0.000000, 1.045340, 0.473093,
|
||||
-0.210605, 0.903175, -0.210552, -0.705252, -0.072024, -0.705252, 0.936767, 0.254108,
|
||||
-0.297820, 0.903175, 0.000001, -0.997375, -0.072024, 0.000000, 1.052424, 0.274946,
|
||||
-0.180964, 0.617981, -0.180911, -0.685263, -0.246529, -0.685263, 0.956801, 0.142573,
|
||||
-0.255900, 0.617981, 0.000001, -0.969115, -0.246529, 0.000000, 1.061122, 0.161660,
|
||||
-0.116291, 0.378825, -0.116238, -0.610279, -0.505051, -0.610279, 0.991689, 0.079506,
|
||||
-0.164439, 0.378825, 0.000001, -0.863063, -0.505051, 0.000000, 1.074527, 0.095355,
|
||||
-0.059153, 0.290116, -0.059100, -0.407514, -0.817194, -0.407544, 1.038003, 0.052079,
|
||||
-0.083634, 0.290116, 0.000001, -0.576312, -0.817194, 0.000000, 1.090933, 0.063214,
|
||||
-0.083634, 0.290116, 0.000001, -0.576312, -0.817194, 0.000000, 0.090933, 0.063214,
|
||||
-0.059153, 0.290116, -0.059100, -0.407514, -0.817194, -0.407544, 0.038003, 0.052079,
|
||||
-0.000125, 0.265210, -0.000071, -0.000244, -0.999969, -0.000244, 0.127500, 0.036749,
|
||||
-0.000051, 0.290116, -0.083580, 0.000000, -0.817194, -0.576312, 0.994047, 0.033372,
|
||||
-0.000125, 0.265210, -0.000071, -0.000244, -0.999969, -0.000244, 1.127500, 0.036749,
|
||||
-0.000051, 0.378825, -0.164386, 0.000000, -0.505051, -0.863063, 0.893772, 0.053663,
|
||||
-0.000052, 0.617981, -0.255847, 0.000000, -0.246529, -0.969115, 0.836458, 0.114704,
|
||||
-0.000052, 0.903175, -0.297766, 0.000000, -0.072024, -0.997375, 0.812221, 0.226047,
|
||||
-0.000052, 1.159339, -0.297966, 0.000000, 0.088870, -0.996033, 0.797565, 0.423137,
|
||||
-0.000052, 1.422079, -0.249421, 0.000000, 0.293832, -0.955840, 0.781975, 0.700922,
|
||||
-0.000052, 1.619116, -0.158731, 0.000000, 0.562639, -0.826655, 0.759783, 0.858997,
|
||||
-0.000052, 1.692897, -0.080335, 0.000000, 0.861232, -0.508194, 0.728165, 0.921879,
|
||||
0.056754, 1.692897, -0.056805, 0.359325, 0.861232, -0.359325, 0.652361, 0.910987,
|
||||
0.112189, 1.619116, -0.112239, 0.584552, 0.562639, -0.584552, 0.659906, 0.845090,
|
||||
0.176316, 1.422079, -0.176367, 0.675863, 0.293832, -0.675863, 0.665734, 0.684958,
|
||||
0.210643, 1.159339, -0.210693, 0.704306, 0.088870, -0.704306, 0.670277, 0.405750,
|
||||
0.210502, 0.903175, -0.210552, 0.705252, -0.072024, -0.705252, 0.675032, 0.207335,
|
||||
0.180860, 0.617981, -0.180910, 0.685263, -0.246529, -0.685263, 0.684415, 0.093825,
|
||||
0.116188, 0.378825, -0.116237, 0.610279, -0.505051, -0.610279, 0.723612, 0.027920,
|
||||
0.059050, 0.290116, -0.059099, 0.407483, -0.817255, -0.407422, 1.018456, 0.011649,
|
||||
0.059050, 0.290116, -0.059099, 0.407483, -0.817255, -0.407422, 0.018456, 0.011649,
|
||||
0.083530, 0.290116, 0.000002, 0.576159, -0.817316, 0.000000, 0.267608, 0.018648,
|
||||
0.164335, 0.378825, 0.000002, 0.863063, -0.505051, 0.000000, 0.457225, 0.035136,
|
||||
0.255796, 0.617981, 0.000002, 0.969115, -0.246529, 0.000000, 0.515690, 0.098717,
|
||||
0.297716, 0.903175, 0.000002, 0.997375, -0.072024, 0.000000, 0.532803, 0.211513,
|
||||
0.297915, 1.159339, 0.000002, 0.996033, 0.088870, 0.000000, 0.541872, 0.409545,
|
||||
0.249370, 1.422079, 0.000002, 0.955840, 0.293832, 0.000000, 0.550746, 0.688375,
|
||||
0.158680, 1.619116, 0.000002, 0.826655, 0.562639, 0.000000, 0.562378, 0.848006,
|
||||
0.080284, 1.692897, 0.000001, 0.508194, 0.861232, 0.000000, 0.577714, 0.913236,
|
||||
0.056754, 1.692897, 0.056808, 0.359325, 0.861232, 0.359325, 0.500528, 0.928224,
|
||||
0.112188, 1.619116, 0.112242, 0.584552, 0.562670, 0.584552, 0.459880, 0.866817,
|
||||
0.176316, 1.422079, 0.176370, 0.675863, 0.293832, 0.675863, 0.433163, 0.709519,
|
||||
0.210642, 1.159339, 0.210696, 0.704306, 0.088870, 0.704306, 0.415507, 0.432148,
|
||||
0.210501, 0.903175, 0.210555, 0.705252, -0.072024, 0.705252, 0.399773, 0.235351,
|
||||
0.180860, 0.617981, 0.180914, 0.685263, -0.246529, 0.685263, 0.375517, 0.124299,
|
||||
0.116187, 0.378825, 0.116241, 0.610279, -0.505051, 0.610279, 0.325269, 0.063109,
|
||||
0.059049, 0.290116, 0.059103, 0.407361, -0.817347, 0.407392, 0.248452, 0.040330,
|
||||
-0.000053, 0.290116, 0.083583, 0.000000, -0.817316, 0.576159, 0.199939, 0.056802,
|
||||
-0.000053, 0.378825, 0.164389, 0.000000, -0.505051, 0.863063, 0.234895, 0.086200,
|
||||
-0.000053, 0.617981, 0.255850, 0.000000, -0.246529, 0.969115, 0.262269, 0.150492,
|
||||
-0.000052, 0.903175, 0.297769, 0.000000, -0.072024, 0.997375, 0.278892, 0.262611,
|
||||
-0.000052, 1.159339, 0.297968, 0.000000, 0.088870, 0.996033, 0.291619, 0.459894,
|
||||
-0.000052, 1.422079, 0.249424, 0.000000, 0.293832, 0.955840, 0.308400, 0.737559,
|
||||
-0.000052, 1.619116, 0.158734, 0.000000, 0.562670, 0.826655, 0.340691, 0.894603,
|
||||
-0.000052, 1.692897, 0.080338, 0.000000, 0.861232, 0.508194, 0.411564, 0.953109,
|
||||
-0.056858, 1.692897, 0.056808, -0.359325, 0.861232, 0.359325, 0.247502, 0.980115,
|
||||
-0.112293, 1.619116, 0.112242, -0.584552, 0.562670, 0.584552, 0.186319, 0.915857,
|
||||
-0.176420, 1.422079, 0.176369, -0.675863, 0.293832, 0.675863, 0.173739, 0.755927,
|
||||
-0.210747, 1.159339, 0.210696, -0.704306, 0.088870, 0.704306, 0.168491, 0.476740,
|
||||
-0.210606, 0.903175, 0.210555, -0.705252, -0.072024, 0.705252, 0.164886, 0.278291,
|
||||
-0.180964, 0.617981, 0.180913, -0.685263, -0.246529, 0.685263, 0.160531, 0.164632,
|
||||
-0.116292, 0.378825, 0.116240, -0.610279, -0.505051, 0.610279, 0.153922, 0.097744,
|
||||
-0.059154, 0.290116, 0.059102, -0.407453, -0.817255, 0.407483, 0.145909, 0.064880,
|
||||
-0.164439, 0.378825, 0.000001, -0.863063, -0.505051, 0.000000, 0.074527, 0.095355,
|
||||
-0.255900, 0.617981, 0.000001, -0.969115, -0.246529, 0.000000, 0.061122, 0.161660,
|
||||
-0.297820, 0.903175, 0.000001, -0.997375, -0.072024, 0.000000, 0.052424, 0.274946,
|
||||
-0.298019, 1.159339, 0.000001, -0.996033, 0.088870, 0.000000, 0.045340, 0.473093,
|
||||
-0.249474, 1.422079, 0.000001, -0.955840, 0.293832, 0.000000, 0.035246, 0.751852,
|
||||
-0.158784, 1.619116, 0.000001, -0.826655, 0.562639, 0.000000, 0.012361, 0.910828,
|
||||
-0.056858, 1.692897, 0.056808, -0.359325, 0.861232, 0.359325, 1.247502, 0.980115,
|
||||
-0.112293, 1.619116, 0.112242, -0.584552, 0.562670, 0.584552, 1.186319, 0.915857
|
||||
],
|
||||
"parts": [
|
||||
{
|
||||
"id": "mpart1",
|
||||
"type": "TRIANGLES",
|
||||
"indices": [
|
||||
0, 1, 2, 3, 4, 5, 0, 2, 6, 3, 7, 4,
|
||||
0, 6, 8, 3, 9, 7, 0, 8, 10, 3, 11, 9,
|
||||
0, 10, 12, 3, 13, 11, 12, 1, 0, 3, 5, 13,
|
||||
1, 5, 4, 1, 4, 2, 2, 4, 7, 2, 7, 6,
|
||||
6, 7, 9, 6, 9, 8, 8, 9, 11, 8, 11, 10,
|
||||
10, 11, 13, 10, 13, 12, 5, 1, 12, 5, 12, 13,
|
||||
14, 15, 16, 16, 15, 17, 16, 17, 18, 18, 17, 19,
|
||||
18, 19, 20, 20, 19, 21, 20, 21, 22, 22, 21, 23,
|
||||
22, 23, 24, 24, 23, 25, 24, 25, 26, 26, 25, 27,
|
||||
26, 27, 28, 28, 27, 29, 28, 29, 30, 31, 32, 33,
|
||||
29, 34, 35, 27, 36, 34, 27, 34, 29, 25, 37, 36,
|
||||
25, 36, 27, 23, 38, 37, 23, 37, 25, 21, 39, 38,
|
||||
21, 38, 23, 19, 40, 39, 19, 39, 21, 17, 41, 40,
|
||||
17, 40, 19, 15, 42, 41, 15, 41, 17, 15, 14, 42,
|
||||
42, 14, 43, 42, 43, 44, 42, 44, 41, 41, 44, 45,
|
||||
41, 45, 40, 40, 45, 46, 40, 46, 39, 39, 46, 47,
|
||||
39, 47, 38, 38, 47, 48, 38, 48, 37, 37, 48, 49,
|
||||
37, 49, 36, 36, 49, 50, 36, 50, 34, 34, 50, 35,
|
||||
51, 52, 33, 49, 53, 52, 49, 52, 50, 48, 54, 53,
|
||||
48, 53, 49, 47, 55, 54, 47, 54, 48, 46, 56, 55,
|
||||
46, 55, 47, 45, 57, 56, 45, 56, 46, 44, 58, 57,
|
||||
44, 57, 45, 43, 59, 58, 43, 58, 44, 43, 14, 59,
|
||||
59, 14, 60, 59, 60, 61, 59, 61, 58, 58, 61, 62,
|
||||
58, 62, 57, 57, 62, 63, 57, 63, 56, 56, 63, 64,
|
||||
56, 64, 55, 55, 64, 65, 55, 65, 54, 54, 65, 66,
|
||||
54, 66, 53, 53, 66, 67, 53, 67, 52, 52, 67, 33,
|
||||
67, 68, 33, 66, 69, 68, 66, 68, 67, 65, 70, 69,
|
||||
65, 69, 66, 64, 71, 70, 64, 70, 65, 63, 72, 71,
|
||||
63, 71, 64, 62, 73, 72, 62, 72, 63, 61, 74, 73,
|
||||
61, 73, 62, 60, 75, 74, 60, 74, 61, 60, 14, 75,
|
||||
75, 14, 76, 75, 76, 77, 75, 77, 74, 74, 77, 78,
|
||||
74, 78, 73, 73, 78, 79, 73, 79, 72, 72, 79, 80,
|
||||
72, 80, 71, 71, 80, 81, 71, 81, 70, 70, 81, 82,
|
||||
70, 82, 69, 69, 82, 83, 69, 83, 68, 68, 83, 33,
|
||||
83, 31, 33, 82, 84, 31, 82, 31, 83, 81, 85, 84,
|
||||
81, 84, 82, 80, 86, 85, 80, 85, 81, 79, 87, 86,
|
||||
79, 86, 80, 78, 88, 87, 78, 87, 79, 77, 89, 88,
|
||||
77, 88, 78, 90, 16, 18, 90, 18, 91, 90, 14, 16
|
||||
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"materials": [
|
||||
{
|
||||
"id": "_tree.png",
|
||||
"diffuse": [ 0.900000, 0.900000, 0.900000],
|
||||
"specular": [ 0.100000, 0.100000, 0.100000],
|
||||
"textures": [
|
||||
{
|
||||
"id": "_tree.png",
|
||||
"filename": "tree.png",
|
||||
"type": "DIFFUSE"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"nodes": [
|
||||
{
|
||||
"id": "treeA_root",
|
||||
"parts": [
|
||||
{
|
||||
"meshpartid": "mpart1",
|
||||
"materialid": "_tree.png",
|
||||
"uvMapping": [[ 0]]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"animations": []
|
||||
}
|
180
gradlew.bat
vendored
180
gradlew.bat
vendored
@ -1,90 +1,90 @@
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windowz variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
if "%@eval[2+2]" == "4" goto 4NT_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
goto execute
|
||||
|
||||
:4NT_args
|
||||
@rem Get arguments from the 4NT Shell from JP Software
|
||||
set CMD_LINE_ARGS=%$
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windowz variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
if "%@eval[2+2]" == "4" goto 4NT_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
goto execute
|
||||
|
||||
:4NT_args
|
||||
@rem Get arguments from the 4NT Shell from JP Software
|
||||
set CMD_LINE_ARGS=%$
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
||||
|
@ -1,14 +1,14 @@
|
||||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := vtm-jni
|
||||
LOCAL_C_INCLUDES := . libtess2/Include
|
||||
|
||||
LOCAL_CFLAGS := $(LOCAL_C_INCLUDES:%=-I%) -O2 -Wall -D__ANDROID__ -Wall -std=c99 -O2 -ffast-math -DNDEBUG
|
||||
LOCAL_CPPFLAGS := $(LOCAL_C_INCLUDES:%=-I%) -O2 -Wall -D__ANDROID__ -Wall -std=c99 -O2 -ffast-math -DNDEBUG
|
||||
LOCAL_LDLIBS := -lm -llog
|
||||
LOCAL_ARM_MODE := arm
|
||||
|
||||
LOCAL_PATH:= $(call my-dir)
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := vtm-jni
|
||||
LOCAL_C_INCLUDES := . libtess2/Include
|
||||
|
||||
LOCAL_CFLAGS := $(LOCAL_C_INCLUDES:%=-I%) -O2 -Wall -D__ANDROID__ -Wall -std=c99 -O2 -ffast-math -DNDEBUG
|
||||
LOCAL_CPPFLAGS := $(LOCAL_C_INCLUDES:%=-I%) -O2 -Wall -D__ANDROID__ -Wall -std=c99 -O2 -ffast-math -DNDEBUG
|
||||
LOCAL_LDLIBS := -lm -llog
|
||||
LOCAL_ARM_MODE := arm
|
||||
|
||||
LOCAL_SRC_FILES := org.oscim.utils.TessJNI.cpp\
|
||||
libtess2/Source/sweep.c\
|
||||
libtess2/Source/priorityq.c\
|
||||
@ -18,5 +18,5 @@ LOCAL_SRC_FILES := org.oscim.utils.TessJNI.cpp\
|
||||
libtess2/Source/dict.c\
|
||||
libtess2/Source/mesh.c\
|
||||
gl/utils.c
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
@ -1,33 +1,33 @@
|
||||
<project name="android-natives" basedir="." default="postcompile">
|
||||
<property environment="env" />
|
||||
<!-- the suffix ndk-build executable -->
|
||||
<property name="ndkSuffix" value="" />
|
||||
|
||||
<target name="clean" depends="check-for-ndk" if="has-ndk-build">
|
||||
<exec executable="${env.NDK_HOME}/ndk-build${ndkSuffix}" failonerror="true">
|
||||
<arg value="clean"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="precompile" depends="check-for-ndk">
|
||||
|
||||
</target>
|
||||
|
||||
<target name="compile-natives" depends="precompile" if="has-ndk-build">
|
||||
<echo>ndk_home: ${env.NDK_HOME}</echo>
|
||||
<exec executable="${env.NDK_HOME}/ndk-build${ndkSuffix}" failonerror="true"/>
|
||||
</target>
|
||||
|
||||
<target name="postcompile" depends="compile-natives">
|
||||
|
||||
</target>
|
||||
|
||||
<target name="check-for-ndk">
|
||||
<condition property="ndk-build-found">
|
||||
<available file="ndk-build${ndkSuffix}" filepath="${env.NDK_HOME}"/>
|
||||
</condition>
|
||||
<condition property="has-ndk-build">
|
||||
<equals arg1="${ndk-build-found}" arg2="true"/>
|
||||
</condition>
|
||||
</target>
|
||||
</project>
|
||||
<project name="android-natives" basedir="." default="postcompile">
|
||||
<property environment="env" />
|
||||
<!-- the suffix ndk-build executable -->
|
||||
<property name="ndkSuffix" value="" />
|
||||
|
||||
<target name="clean" depends="check-for-ndk" if="has-ndk-build">
|
||||
<exec executable="${env.NDK_HOME}/ndk-build${ndkSuffix}" failonerror="true">
|
||||
<arg value="clean"/>
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="precompile" depends="check-for-ndk">
|
||||
|
||||
</target>
|
||||
|
||||
<target name="compile-natives" depends="precompile" if="has-ndk-build">
|
||||
<echo>ndk_home: ${env.NDK_HOME}</echo>
|
||||
<exec executable="${env.NDK_HOME}/ndk-build${ndkSuffix}" failonerror="true"/>
|
||||
</target>
|
||||
|
||||
<target name="postcompile" depends="compile-natives">
|
||||
|
||||
</target>
|
||||
|
||||
<target name="check-for-ndk">
|
||||
<condition property="ndk-build-found">
|
||||
<available file="ndk-build${ndkSuffix}" filepath="${env.NDK_HOME}"/>
|
||||
</condition>
|
||||
<condition property="has-ndk-build">
|
||||
<equals arg1="${ndk-build-found}" arg2="true"/>
|
||||
</condition>
|
||||
</target>
|
||||
</project>
|
||||
|
@ -1,24 +1,24 @@
|
||||
<project name="vtm-jni-Linux-64" basedir="." default="postcompile">
|
||||
<!-- include the environment -->
|
||||
<property environment="env"/>
|
||||
<!-- output directory for temporary object files -->
|
||||
<property name="buildDir" value="target/linux64" />
|
||||
<!-- output directory for the shared library -->
|
||||
<property name="libsDir" value="../libs/linux64" />
|
||||
<!-- the name of the shared library -->
|
||||
<property name="libName" value="libvtm-jni64.so"/>
|
||||
<!-- the jni header jniPlatform to use -->
|
||||
<property name="jniPlatform" value="linux"/>
|
||||
<!-- the compilerPrefix for the C & C++ compilers -->
|
||||
<property name="compilerPrefix" value=""/>
|
||||
<!-- the compilerSuffix for the C & C++ compilers -->
|
||||
<property name="compilerSuffix" value="" />
|
||||
|
||||
<!-- define gcc compiler, options and files to compile -->
|
||||
<property name="gcc" value="${compilerPrefix}gcc${compilerSuffix}"/>
|
||||
<property name="gcc-opts" value="-c -Wall -O2 -mfpmath=sse -msse -fmessage-length=0 -m64 -fPIC -Wall -std=c99 -O2 -ffast-math -DNDEBUG"/>
|
||||
<fileset id="gcc-files" dir="./">
|
||||
<exclude name="target/"/>
|
||||
<project name="vtm-jni-Linux-64" basedir="." default="postcompile">
|
||||
<!-- include the environment -->
|
||||
<property environment="env"/>
|
||||
<!-- output directory for temporary object files -->
|
||||
<property name="buildDir" value="target/linux64" />
|
||||
<!-- output directory for the shared library -->
|
||||
<property name="libsDir" value="../libs/linux64" />
|
||||
<!-- the name of the shared library -->
|
||||
<property name="libName" value="libvtm-jni64.so"/>
|
||||
<!-- the jni header jniPlatform to use -->
|
||||
<property name="jniPlatform" value="linux"/>
|
||||
<!-- the compilerPrefix for the C & C++ compilers -->
|
||||
<property name="compilerPrefix" value=""/>
|
||||
<!-- the compilerSuffix for the C & C++ compilers -->
|
||||
<property name="compilerSuffix" value="" />
|
||||
|
||||
<!-- define gcc compiler, options and files to compile -->
|
||||
<property name="gcc" value="${compilerPrefix}gcc${compilerSuffix}"/>
|
||||
<property name="gcc-opts" value="-c -Wall -O2 -mfpmath=sse -msse -fmessage-length=0 -m64 -fPIC -Wall -std=c99 -O2 -ffast-math -DNDEBUG"/>
|
||||
<fileset id="gcc-files" dir="./">
|
||||
<exclude name="target/"/>
|
||||
<include name="memcpy_wrap.c"/>
|
||||
<include name="gl/utils.c"/>
|
||||
<include name="libtess2/Source/bucketalloc.c"/>
|
||||
@ -28,126 +28,126 @@
|
||||
<include name="libtess2/Source/priorityq.c"/>
|
||||
<include name="libtess2/Source/sweep.c"/>
|
||||
<include name="libtess2/Source/tess.c"/>
|
||||
|
||||
|
||||
</fileset>
|
||||
|
||||
<!-- define g++ compiler, options and files to compile -->
|
||||
<property name="g++" value="${compilerPrefix}g++${compilerSuffix}"/>
|
||||
<property name="g++-opts" value="-c -Wall -O2 -mfpmath=sse -msse -fmessage-length=0 -m64 -fPIC -Wall -std=c99 -O2 -ffast-math -DNDEBUG"/>
|
||||
<fileset id="g++-files" dir="./">
|
||||
<exclude name="target/"/>
|
||||
|
||||
|
||||
</fileset>
|
||||
|
||||
<!-- define g++ compiler, options and files to compile -->
|
||||
<property name="g++" value="${compilerPrefix}g++${compilerSuffix}"/>
|
||||
<property name="g++-opts" value="-c -Wall -O2 -mfpmath=sse -msse -fmessage-length=0 -m64 -fPIC -Wall -std=c99 -O2 -ffast-math -DNDEBUG"/>
|
||||
<fileset id="g++-files" dir="./">
|
||||
<exclude name="target/"/>
|
||||
<include name="**/*.cpp"/>
|
||||
|
||||
|
||||
</fileset>
|
||||
|
||||
<!-- define linker and options -->
|
||||
<property name="linker" value="${compilerPrefix}g++${compilerSuffix}"/>
|
||||
<property name="linker-opts" value="-shared -m64 -Wl,-wrap,memcpy"/>
|
||||
<property name="libraries" value=""/>
|
||||
|
||||
<!-- cleans the build directory, removes all object files and shared libs -->
|
||||
<target name="clean">
|
||||
<delete includeemptydirs="true" quiet="true">
|
||||
<fileset dir="${buildDir}"/>
|
||||
<fileset dir="${libsDir}" includes="**/*" excludes="**/.svn"/>
|
||||
</delete>
|
||||
</target>
|
||||
|
||||
<target name="precompile">
|
||||
<condition property="compiler-found">
|
||||
<and>
|
||||
<or>
|
||||
<!-- Include both b/c Windows might be either -->
|
||||
<available file="${g++}" filepath="${env.PATH}"/>
|
||||
<available file="${g++}" filepath="${env.Path}"/>
|
||||
</or>
|
||||
<or>
|
||||
<!-- Include both b/c Windows might be either -->
|
||||
<available file="${gcc}" filepath="${env.PATH}"/>
|
||||
<available file="${gcc}" filepath="${env.Path}"/>
|
||||
</or>
|
||||
</and>
|
||||
</condition>
|
||||
<condition property="has-compiler">
|
||||
<equals arg1="${compiler-found}" arg2="true"/>
|
||||
</condition>
|
||||
|
||||
</target>
|
||||
|
||||
<target name="create-build-dir" depends="precompile" if="has-compiler">
|
||||
<!-- FIXME this is pretty nasty :/ -->
|
||||
<copy todir="${buildDir}">
|
||||
<fileset refid="g++-files"/>
|
||||
<fileset refid="gcc-files"/>
|
||||
</copy>
|
||||
<delete>
|
||||
<fileset dir="${buildDir}">
|
||||
<include name="*"/>
|
||||
<exclude name="*.o"/>
|
||||
</fileset>
|
||||
</delete>
|
||||
</target>
|
||||
|
||||
<!-- compiles all C and C++ files to object files in the build directory -->
|
||||
<target name="compile" depends="create-build-dir" if="has-compiler">
|
||||
<mkdir dir="${buildDir}"/>
|
||||
<apply failonerror="true" executable="${g++}" dest="${buildDir}" verbose="true">
|
||||
<arg line="${g++-opts}"/>
|
||||
<arg value="-Ijni-headers"/>
|
||||
<arg value="-Ijni-headers/${jniPlatform}"/>
|
||||
<arg value="-I."/>
|
||||
|
||||
|
||||
</fileset>
|
||||
|
||||
<!-- define linker and options -->
|
||||
<property name="linker" value="${compilerPrefix}g++${compilerSuffix}"/>
|
||||
<property name="linker-opts" value="-shared -m64 -Wl,-wrap,memcpy"/>
|
||||
<property name="libraries" value=""/>
|
||||
|
||||
<!-- cleans the build directory, removes all object files and shared libs -->
|
||||
<target name="clean">
|
||||
<delete includeemptydirs="true" quiet="true">
|
||||
<fileset dir="${buildDir}"/>
|
||||
<fileset dir="${libsDir}" includes="**/*" excludes="**/.svn"/>
|
||||
</delete>
|
||||
</target>
|
||||
|
||||
<target name="precompile">
|
||||
<condition property="compiler-found">
|
||||
<and>
|
||||
<or>
|
||||
<!-- Include both b/c Windows might be either -->
|
||||
<available file="${g++}" filepath="${env.PATH}"/>
|
||||
<available file="${g++}" filepath="${env.Path}"/>
|
||||
</or>
|
||||
<or>
|
||||
<!-- Include both b/c Windows might be either -->
|
||||
<available file="${gcc}" filepath="${env.PATH}"/>
|
||||
<available file="${gcc}" filepath="${env.Path}"/>
|
||||
</or>
|
||||
</and>
|
||||
</condition>
|
||||
<condition property="has-compiler">
|
||||
<equals arg1="${compiler-found}" arg2="true"/>
|
||||
</condition>
|
||||
|
||||
</target>
|
||||
|
||||
<target name="create-build-dir" depends="precompile" if="has-compiler">
|
||||
<!-- FIXME this is pretty nasty :/ -->
|
||||
<copy todir="${buildDir}">
|
||||
<fileset refid="g++-files"/>
|
||||
<fileset refid="gcc-files"/>
|
||||
</copy>
|
||||
<delete>
|
||||
<fileset dir="${buildDir}">
|
||||
<include name="*"/>
|
||||
<exclude name="*.o"/>
|
||||
</fileset>
|
||||
</delete>
|
||||
</target>
|
||||
|
||||
<!-- compiles all C and C++ files to object files in the build directory -->
|
||||
<target name="compile" depends="create-build-dir" if="has-compiler">
|
||||
<mkdir dir="${buildDir}"/>
|
||||
<apply failonerror="true" executable="${g++}" dest="${buildDir}" verbose="true">
|
||||
<arg line="${g++-opts}"/>
|
||||
<arg value="-Ijni-headers"/>
|
||||
<arg value="-Ijni-headers/${jniPlatform}"/>
|
||||
<arg value="-I."/>
|
||||
<arg value="-I."/>
|
||||
<arg value="-Ilibtess2/Include"/>
|
||||
|
||||
<srcfile/>
|
||||
<arg value="-o"/>
|
||||
<targetfile/>
|
||||
<fileset refid="g++-files"/>
|
||||
<compositemapper>
|
||||
<mapper type="glob" from="*.cpp" to="*.o"/>
|
||||
<mapper type="glob" from="*.mm" to="*.o"/>
|
||||
</compositemapper>
|
||||
</apply>
|
||||
<apply failonerror="true" executable="${gcc}" dest="${buildDir}" verbose="true">
|
||||
<arg line="${gcc-opts}"/>
|
||||
<arg value="-Ijni-headers"/>
|
||||
<arg value="-Ijni-headers/${jniPlatform}"/>
|
||||
<arg value="-I."/>
|
||||
|
||||
<srcfile/>
|
||||
<arg value="-o"/>
|
||||
<targetfile/>
|
||||
<fileset refid="g++-files"/>
|
||||
<compositemapper>
|
||||
<mapper type="glob" from="*.cpp" to="*.o"/>
|
||||
<mapper type="glob" from="*.mm" to="*.o"/>
|
||||
</compositemapper>
|
||||
</apply>
|
||||
<apply failonerror="true" executable="${gcc}" dest="${buildDir}" verbose="true">
|
||||
<arg line="${gcc-opts}"/>
|
||||
<arg value="-Ijni-headers"/>
|
||||
<arg value="-Ijni-headers/${jniPlatform}"/>
|
||||
<arg value="-I."/>
|
||||
<arg value="-I."/>
|
||||
<arg value="-Ilibtess2/Include"/>
|
||||
|
||||
<srcfile/>
|
||||
<arg value="-o"/>
|
||||
<targetfile/>
|
||||
<fileset refid="gcc-files"/>
|
||||
<compositemapper>
|
||||
|
||||
<srcfile/>
|
||||
<arg value="-o"/>
|
||||
<targetfile/>
|
||||
<fileset refid="gcc-files"/>
|
||||
<compositemapper>
|
||||
<mapper type="glob" from="*.c" to="*.o"/>
|
||||
<mapper type="glob" from="*.m" to="*.o"/>
|
||||
</compositemapper>
|
||||
</apply>
|
||||
</target>
|
||||
|
||||
<!-- links the shared library based on the previously compiled object files -->
|
||||
<target name="link" depends="compile" if="has-compiler">
|
||||
<fileset dir="${buildDir}" id="objFileSet">
|
||||
<patternset>
|
||||
<include name="**/*.o" />
|
||||
</patternset>
|
||||
</fileset>
|
||||
<pathconvert pathsep=" " property="objFiles" refid="objFileSet" />
|
||||
<mkdir dir="${libsDir}" />
|
||||
<exec executable="${linker}" failonerror="true" dir="${buildDir}">
|
||||
<arg line="${linker-opts}" />
|
||||
<arg value="-o" />
|
||||
<arg path="${libsDir}/${libName}" />
|
||||
<arg line="${objFiles}"/>
|
||||
<arg line="${libraries}" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="postcompile" depends="link">
|
||||
|
||||
</target>
|
||||
</project>
|
||||
<mapper type="glob" from="*.m" to="*.o"/>
|
||||
</compositemapper>
|
||||
</apply>
|
||||
</target>
|
||||
|
||||
<!-- links the shared library based on the previously compiled object files -->
|
||||
<target name="link" depends="compile" if="has-compiler">
|
||||
<fileset dir="${buildDir}" id="objFileSet">
|
||||
<patternset>
|
||||
<include name="**/*.o" />
|
||||
</patternset>
|
||||
</fileset>
|
||||
<pathconvert pathsep=" " property="objFiles" refid="objFileSet" />
|
||||
<mkdir dir="${libsDir}" />
|
||||
<exec executable="${linker}" failonerror="true" dir="${buildDir}">
|
||||
<arg line="${linker-opts}" />
|
||||
<arg value="-o" />
|
||||
<arg path="${libsDir}/${libName}" />
|
||||
<arg line="${objFiles}"/>
|
||||
<arg line="${libraries}" />
|
||||
</exec>
|
||||
</target>
|
||||
|
||||
<target name="postcompile" depends="link">
|
||||
|
||||
</target>
|
||||
</project>
|
||||
|
@ -1,73 +1,73 @@
|
||||
/*
|
||||
* Copyright 2014 Hannes Janetzek
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.android.test;
|
||||
|
||||
import static org.oscim.tiling.source.bitmap.DefaultSources.STAMEN_TONER;
|
||||
|
||||
import org.oscim.android.MapView;
|
||||
import org.oscim.layers.TileGridLayer;
|
||||
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
|
||||
import org.oscim.layers.tile.buildings.BuildingLayer;
|
||||
import org.oscim.layers.tile.vector.VectorTileLayer;
|
||||
import org.oscim.renderer.MapRenderer;
|
||||
import org.oscim.theme.IRenderTheme;
|
||||
import org.oscim.theme.ThemeLoader;
|
||||
import org.oscim.theme.VtmThemes;
|
||||
import org.oscim.tiling.TileSource;
|
||||
import org.oscim.tiling.source.geojson.HighroadJsonTileSource;
|
||||
import org.oscim.tiling.source.geojson.OsmBuildingJsonTileSource;
|
||||
import org.oscim.tiling.source.geojson.OsmLanduseJsonTileSource;
|
||||
import org.oscim.tiling.source.geojson.OsmWaterJsonTileSource;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
public class OsmJsonMapActivity extends MapActivity {
|
||||
|
||||
MapView mMapView;
|
||||
VectorTileLayer mBaseLayer;
|
||||
TileSource mTileSource;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mTileSource = new OsmWaterJsonTileSource();
|
||||
|
||||
mMap.setBaseMap(new BitmapTileLayer(mMap, STAMEN_TONER.build()));
|
||||
mMap.layers().add(new TileGridLayer(mMap));
|
||||
|
||||
IRenderTheme theme = ThemeLoader.load(VtmThemes.OSMARENDER);
|
||||
MapRenderer.setBackgroundColor(theme.getMapBackground());
|
||||
|
||||
VectorTileLayer l;
|
||||
l = new VectorTileLayer(mMap, new OsmLanduseJsonTileSource());
|
||||
l.setRenderTheme(theme);
|
||||
l.tileRenderer().setOverdrawColor(0);
|
||||
mMap.layers().add(l);
|
||||
|
||||
l = new VectorTileLayer(mMap, new HighroadJsonTileSource());
|
||||
l.setRenderTheme(theme);
|
||||
l.tileRenderer().setOverdrawColor(0);
|
||||
mMap.layers().add(l);
|
||||
|
||||
l = new VectorTileLayer(mMap, new OsmBuildingJsonTileSource());
|
||||
l.setRenderTheme(theme);
|
||||
l.tileRenderer().setOverdrawColor(0);
|
||||
mMap.layers().add(l);
|
||||
mMap.layers().add(new BuildingLayer(mMap, l));
|
||||
|
||||
mMap.setMapPosition(53.08, 8.83, Math.pow(2, 16));
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2014 Hannes Janetzek
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.android.test;
|
||||
|
||||
import static org.oscim.tiling.source.bitmap.DefaultSources.STAMEN_TONER;
|
||||
|
||||
import org.oscim.android.MapView;
|
||||
import org.oscim.layers.TileGridLayer;
|
||||
import org.oscim.layers.tile.bitmap.BitmapTileLayer;
|
||||
import org.oscim.layers.tile.buildings.BuildingLayer;
|
||||
import org.oscim.layers.tile.vector.VectorTileLayer;
|
||||
import org.oscim.renderer.MapRenderer;
|
||||
import org.oscim.theme.IRenderTheme;
|
||||
import org.oscim.theme.ThemeLoader;
|
||||
import org.oscim.theme.VtmThemes;
|
||||
import org.oscim.tiling.TileSource;
|
||||
import org.oscim.tiling.source.geojson.HighroadJsonTileSource;
|
||||
import org.oscim.tiling.source.geojson.OsmBuildingJsonTileSource;
|
||||
import org.oscim.tiling.source.geojson.OsmLanduseJsonTileSource;
|
||||
import org.oscim.tiling.source.geojson.OsmWaterJsonTileSource;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
||||
public class OsmJsonMapActivity extends MapActivity {
|
||||
|
||||
MapView mMapView;
|
||||
VectorTileLayer mBaseLayer;
|
||||
TileSource mTileSource;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mTileSource = new OsmWaterJsonTileSource();
|
||||
|
||||
mMap.setBaseMap(new BitmapTileLayer(mMap, STAMEN_TONER.build()));
|
||||
mMap.layers().add(new TileGridLayer(mMap));
|
||||
|
||||
IRenderTheme theme = ThemeLoader.load(VtmThemes.OSMARENDER);
|
||||
MapRenderer.setBackgroundColor(theme.getMapBackground());
|
||||
|
||||
VectorTileLayer l;
|
||||
l = new VectorTileLayer(mMap, new OsmLanduseJsonTileSource());
|
||||
l.setRenderTheme(theme);
|
||||
l.tileRenderer().setOverdrawColor(0);
|
||||
mMap.layers().add(l);
|
||||
|
||||
l = new VectorTileLayer(mMap, new HighroadJsonTileSource());
|
||||
l.setRenderTheme(theme);
|
||||
l.tileRenderer().setOverdrawColor(0);
|
||||
mMap.layers().add(l);
|
||||
|
||||
l = new VectorTileLayer(mMap, new OsmBuildingJsonTileSource());
|
||||
l.setRenderTheme(theme);
|
||||
l.tileRenderer().setOverdrawColor(0);
|
||||
mMap.layers().add(l);
|
||||
mMap.layers().add(new BuildingLayer(mMap, l));
|
||||
|
||||
mMap.setMapPosition(53.08, 8.83, Math.pow(2, 16));
|
||||
}
|
||||
}
|
||||
|
@ -1,32 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.oscim.gdx"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" >
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="10"
|
||||
android:targetSdkVersion="22" />
|
||||
|
||||
<application
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:allowBackup="true" >
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:screenOrientation="portrait"
|
||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.oscim.gdx"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0" >
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="10"
|
||||
android:targetSdkVersion="22" />
|
||||
|
||||
<application
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:allowBackup="true" >
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:screenOrientation="portrait"
|
||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
</LinearLayout>
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">VtmGdx</string>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">VtmGdx</string>
|
||||
</resources>
|
@ -1,90 +1,90 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.gdx;
|
||||
|
||||
import org.oscim.awt.AwtGraphics;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.tiling.TileSource;
|
||||
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
|
||||
import org.oscim.utils.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.badlogic.gdx.backends.jglfw.JglfwApplication;
|
||||
import com.badlogic.gdx.backends.jglfw.JglfwApplicationConfiguration;
|
||||
import com.badlogic.gdx.utils.SharedLibraryLoader;
|
||||
|
||||
public class GdxMapApp extends GdxMap {
|
||||
|
||||
public static final Logger log = LoggerFactory.getLogger(GdxMapApp.class);
|
||||
|
||||
public static void init() {
|
||||
// load native library
|
||||
new SharedLibraryLoader().load("vtm-jni");
|
||||
// init globals
|
||||
AwtGraphics.init();
|
||||
GdxAssets.init("assets/");
|
||||
GLAdapter.init(new GdxGL());
|
||||
GLAdapter.GDX_DESKTOP_QUIRKS = true;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Tile.SIZE = 360;
|
||||
init();
|
||||
new JglfwApplication(new GdxMapApp(), getConfig());
|
||||
}
|
||||
|
||||
public static void run(GdxMap map, JglfwApplicationConfiguration config, int tileSize) {
|
||||
Tile.SIZE = FastMath.clamp(tileSize, 128, 512);
|
||||
|
||||
new JglfwApplication(map, (config == null ? getConfig() : config));
|
||||
}
|
||||
|
||||
public static void run(JglfwApplicationConfiguration config, int tileSize, GdxMap map) {
|
||||
run(map, config, tileSize);
|
||||
}
|
||||
|
||||
static protected JglfwApplicationConfiguration getConfig() {
|
||||
JglfwApplicationConfiguration cfg = new JglfwApplicationConfiguration();
|
||||
cfg.title = "vtm-gdx";
|
||||
cfg.width = 800;
|
||||
cfg.height = 600;
|
||||
cfg.stencil = 8;
|
||||
//cfg.samples = 2;
|
||||
cfg.foregroundFPS = 30;
|
||||
cfg.backgroundFPS = 10;
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createLayers() {
|
||||
TileSource tileSource = new OSciMap4TileSource();
|
||||
|
||||
// TileSource tileSource = new MapFileTileSource();
|
||||
// tileSource.setOption("file", "/home/jeff/germany.map");
|
||||
|
||||
initDefaultLayers(tileSource, false, true, true);
|
||||
|
||||
//mMap.getLayers().add(new BitmapTileLayer(mMap, new ImagicoLandcover(), 20));
|
||||
//mMap.getLayers().add(new BitmapTileLayer(mMap, new OSMTileSource(), 20));
|
||||
//mMap.getLayers().add(new BitmapTileLayer(mMap, new ArcGISWorldShaded(), 20));
|
||||
|
||||
mMap.setMapPosition(0, 0, 1 << 2);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.gdx;
|
||||
|
||||
import org.oscim.awt.AwtGraphics;
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.tiling.TileSource;
|
||||
import org.oscim.tiling.source.oscimap4.OSciMap4TileSource;
|
||||
import org.oscim.utils.FastMath;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.badlogic.gdx.backends.jglfw.JglfwApplication;
|
||||
import com.badlogic.gdx.backends.jglfw.JglfwApplicationConfiguration;
|
||||
import com.badlogic.gdx.utils.SharedLibraryLoader;
|
||||
|
||||
public class GdxMapApp extends GdxMap {
|
||||
|
||||
public static final Logger log = LoggerFactory.getLogger(GdxMapApp.class);
|
||||
|
||||
public static void init() {
|
||||
// load native library
|
||||
new SharedLibraryLoader().load("vtm-jni");
|
||||
// init globals
|
||||
AwtGraphics.init();
|
||||
GdxAssets.init("assets/");
|
||||
GLAdapter.init(new GdxGL());
|
||||
GLAdapter.GDX_DESKTOP_QUIRKS = true;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Tile.SIZE = 360;
|
||||
init();
|
||||
new JglfwApplication(new GdxMapApp(), getConfig());
|
||||
}
|
||||
|
||||
public static void run(GdxMap map, JglfwApplicationConfiguration config, int tileSize) {
|
||||
Tile.SIZE = FastMath.clamp(tileSize, 128, 512);
|
||||
|
||||
new JglfwApplication(map, (config == null ? getConfig() : config));
|
||||
}
|
||||
|
||||
public static void run(JglfwApplicationConfiguration config, int tileSize, GdxMap map) {
|
||||
run(map, config, tileSize);
|
||||
}
|
||||
|
||||
static protected JglfwApplicationConfiguration getConfig() {
|
||||
JglfwApplicationConfiguration cfg = new JglfwApplicationConfiguration();
|
||||
cfg.title = "vtm-gdx";
|
||||
cfg.width = 800;
|
||||
cfg.height = 600;
|
||||
cfg.stencil = 8;
|
||||
//cfg.samples = 2;
|
||||
cfg.foregroundFPS = 30;
|
||||
cfg.backgroundFPS = 10;
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createLayers() {
|
||||
TileSource tileSource = new OSciMap4TileSource();
|
||||
|
||||
// TileSource tileSource = new MapFileTileSource();
|
||||
// tileSource.setOption("file", "/home/jeff/germany.map");
|
||||
|
||||
initDefaultLayers(tileSource, false, true, true);
|
||||
|
||||
//mMap.getLayers().add(new BitmapTileLayer(mMap, new ImagicoLandcover(), 20));
|
||||
//mMap.getLayers().add(new BitmapTileLayer(mMap, new OSMTileSource(), 20));
|
||||
//mMap.getLayers().add(new BitmapTileLayer(mMap, new ArcGISWorldShaded(), 20));
|
||||
|
||||
mMap.setMapPosition(0, 0, 1 << 2);
|
||||
}
|
||||
}
|
||||
|
@ -1,350 +1,350 @@
|
||||
/*
|
||||
* Copyright 2014 Hannes Janetzek
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.tiling.source.geojson;
|
||||
|
||||
import static com.fasterxml.jackson.core.JsonToken.END_ARRAY;
|
||||
import static com.fasterxml.jackson.core.JsonToken.END_OBJECT;
|
||||
import static com.fasterxml.jackson.core.JsonToken.FIELD_NAME;
|
||||
import static com.fasterxml.jackson.core.JsonToken.START_ARRAY;
|
||||
import static com.fasterxml.jackson.core.JsonToken.START_OBJECT;
|
||||
import static com.fasterxml.jackson.core.JsonToken.VALUE_NUMBER_FLOAT;
|
||||
import static com.fasterxml.jackson.core.JsonToken.VALUE_NUMBER_INT;
|
||||
import static com.fasterxml.jackson.core.JsonToken.VALUE_STRING;
|
||||
import static org.oscim.core.MercatorProjection.latitudeToY;
|
||||
import static org.oscim.core.MercatorProjection.longitudeToX;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import org.oscim.core.GeometryBuffer.GeometryType;
|
||||
import org.oscim.core.MapElement;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.tiling.ITileDataSink;
|
||||
import org.oscim.tiling.source.ITileDecoder;
|
||||
import org.oscim.utils.ArrayUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
public class GeoJsonTileDecoder implements ITileDecoder {
|
||||
static final Logger log = LoggerFactory.getLogger(GeoJsonTileDecoder.class);
|
||||
|
||||
private final MapElement mMapElement;
|
||||
private final GeoJsonTileSource mTileSource;
|
||||
private final LinkedHashMap<String, Object> mTagMap;
|
||||
private final JsonFactory mJsonFactory;
|
||||
|
||||
private final static char[] FIELD_FEATURES = "features".toCharArray();
|
||||
private final static char[] FIELD_GEOMETRY = "geometry".toCharArray();
|
||||
private final static char[] FIELD_PROPERTIES = "properties".toCharArray();
|
||||
private final static char[] FIELD_COORDINATES = "coordinates".toCharArray();
|
||||
private final static char[] FIELD_TYPE = "type".toCharArray();
|
||||
|
||||
private final static char[] LINETRING = "LineString".toCharArray();
|
||||
private final static char[] POLYGON = "Polygon".toCharArray();
|
||||
private final static char[] POINT = "Point".toCharArray();
|
||||
private final static char[] MULTI_LINESTRING = "MultiLineString".toCharArray();
|
||||
private final static char[] MULTI_POLYGON = "MultiPolygon".toCharArray();
|
||||
private final static char[] MULTI_POINT = "MultiPoint".toCharArray();
|
||||
|
||||
private ITileDataSink mTileDataSink;
|
||||
|
||||
private double mTileY, mTileX, mTileScale;
|
||||
|
||||
public GeoJsonTileDecoder(GeoJsonTileSource tileSource) {
|
||||
mTileSource = tileSource;
|
||||
mTagMap = new LinkedHashMap<String, Object>();
|
||||
mJsonFactory = new JsonFactory();
|
||||
|
||||
mMapElement = new MapElement();
|
||||
mMapElement.layer = 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean decode(Tile tile, ITileDataSink sink, InputStream is) throws IOException {
|
||||
mTileDataSink = sink;
|
||||
mTileScale = 1 << tile.zoomLevel;
|
||||
mTileX = tile.tileX / mTileScale;
|
||||
mTileY = tile.tileY / mTileScale;
|
||||
mTileScale *= Tile.SIZE;
|
||||
|
||||
JsonParser jp = mJsonFactory.createParser(new InputStreamReader(is));
|
||||
|
||||
for (JsonToken t; (t = jp.nextToken()) != null;) {
|
||||
if (t == FIELD_NAME) {
|
||||
if (match(jp, FIELD_FEATURES)) {
|
||||
if (jp.nextToken() != START_ARRAY)
|
||||
continue;
|
||||
|
||||
while ((t = jp.nextToken()) != null) {
|
||||
if (t == START_OBJECT)
|
||||
parseFeature(jp);
|
||||
|
||||
if (t == END_ARRAY)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void parseFeature(JsonParser jp)
|
||||
throws JsonParseException, IOException {
|
||||
|
||||
mMapElement.clear();
|
||||
mMapElement.tags.clear();
|
||||
mTagMap.clear();
|
||||
|
||||
for (JsonToken t; (t = jp.nextToken()) != null;) {
|
||||
if (t == FIELD_NAME) {
|
||||
if (match(jp, FIELD_GEOMETRY)) {
|
||||
if (jp.nextToken() == START_OBJECT)
|
||||
parseGeometry(jp);
|
||||
}
|
||||
|
||||
if (match(jp, FIELD_PROPERTIES)) {
|
||||
if (jp.nextToken() == START_OBJECT)
|
||||
parseProperties(jp);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (t == END_OBJECT)
|
||||
break;
|
||||
}
|
||||
|
||||
//add tag information
|
||||
mTileSource.decodeTags(mMapElement, mTagMap);
|
||||
if (mMapElement.tags.numTags == 0)
|
||||
return;
|
||||
|
||||
mTileSource.postGeomHook(mMapElement);
|
||||
|
||||
if (mMapElement.type == GeometryType.NONE)
|
||||
return;
|
||||
|
||||
//process this element
|
||||
mTileDataSink.process(mMapElement);
|
||||
}
|
||||
|
||||
private void parseProperties(JsonParser jp)
|
||||
throws JsonParseException, IOException {
|
||||
for (JsonToken t; (t = jp.nextToken()) != null;) {
|
||||
if (t == FIELD_NAME) {
|
||||
String text = jp.getCurrentName();
|
||||
|
||||
t = jp.nextToken();
|
||||
if (t == VALUE_STRING) {
|
||||
mTagMap.put(text, jp.getText());
|
||||
} else if (t == VALUE_NUMBER_INT) {
|
||||
mTagMap.put(text, jp.getNumberValue());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (t == END_OBJECT)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void parseGeometry(JsonParser jp)
|
||||
throws JsonParseException, IOException {
|
||||
|
||||
boolean multi = false;
|
||||
GeometryType type = GeometryType.NONE;
|
||||
|
||||
for (JsonToken t; (t = jp.nextToken()) != null;) {
|
||||
if (t == FIELD_NAME) {
|
||||
if (match(jp, FIELD_COORDINATES)) {
|
||||
if (jp.nextToken() != START_ARRAY)
|
||||
continue;
|
||||
if (multi) {
|
||||
parseMulti(jp, type);
|
||||
} else {
|
||||
if (type == GeometryType.POLY)
|
||||
parsePolygon(jp);
|
||||
|
||||
if (type == GeometryType.LINE)
|
||||
parseLineString(jp);
|
||||
|
||||
if (type == GeometryType.POINT)
|
||||
parseCoordinate(jp);
|
||||
|
||||
}
|
||||
} else if (match(jp, FIELD_TYPE)) {
|
||||
multi = false;
|
||||
|
||||
jp.nextToken();
|
||||
|
||||
if (match(jp, LINETRING))
|
||||
type = GeometryType.LINE;
|
||||
else if (match(jp, POLYGON))
|
||||
type = GeometryType.POLY;
|
||||
else if (match(jp, POINT))
|
||||
type = GeometryType.POINT;
|
||||
else if (match(jp, MULTI_LINESTRING)) {
|
||||
type = GeometryType.LINE;
|
||||
multi = true;
|
||||
}
|
||||
else if (match(jp, MULTI_POLYGON)) {
|
||||
type = GeometryType.POLY;
|
||||
multi = true;
|
||||
}
|
||||
else if (match(jp, MULTI_POINT)) {
|
||||
type = GeometryType.POINT;
|
||||
multi = true;
|
||||
}
|
||||
|
||||
if (type == GeometryType.POINT)
|
||||
mMapElement.startPoints();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (t == END_OBJECT)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void parseMulti(JsonParser jp, GeometryType type)
|
||||
throws JsonParseException, IOException {
|
||||
|
||||
for (JsonToken t; (t = jp.nextToken()) != null;) {
|
||||
if (t == END_ARRAY)
|
||||
break;
|
||||
|
||||
if (t == START_ARRAY) {
|
||||
if (type == GeometryType.POLY)
|
||||
parsePolygon(jp);
|
||||
|
||||
else if (type == GeometryType.LINE)
|
||||
parseLineString(jp);
|
||||
|
||||
else if (type == GeometryType.POINT)
|
||||
parseCoordinate(jp);;
|
||||
|
||||
} else {
|
||||
//....
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void parsePolygon(JsonParser jp)
|
||||
throws JsonParseException, IOException {
|
||||
int ring = 0;
|
||||
|
||||
for (JsonToken t; (t = jp.nextToken()) != null;) {
|
||||
if (t == START_ARRAY) {
|
||||
if (ring == 0)
|
||||
mMapElement.startPolygon();
|
||||
else
|
||||
mMapElement.startHole();
|
||||
|
||||
ring++;
|
||||
parseCoordSequence(jp);
|
||||
removeLastPoint();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (t == END_ARRAY)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void removeLastPoint() {
|
||||
mMapElement.pointPos -= 2;
|
||||
mMapElement.index[mMapElement.indexPos] -= 2;
|
||||
}
|
||||
|
||||
private void parseLineString(JsonParser jp)
|
||||
throws JsonParseException, IOException {
|
||||
mMapElement.startLine();
|
||||
parseCoordSequence(jp);
|
||||
}
|
||||
|
||||
private void parseCoordSequence(JsonParser jp)
|
||||
throws JsonParseException, IOException {
|
||||
|
||||
for (JsonToken t; (t = jp.nextToken()) != null;) {
|
||||
|
||||
if (t == START_ARRAY) {
|
||||
parseCoordinate(jp);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (t == END_ARRAY)
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void parseCoordinate(JsonParser jp)
|
||||
throws JsonParseException, IOException {
|
||||
int pos = 0;
|
||||
double x = 0, y = 0; //, z = 0;
|
||||
|
||||
for (JsonToken t; (t = jp.nextToken()) != null;) {
|
||||
if (t == VALUE_NUMBER_FLOAT || t == VALUE_NUMBER_INT) {
|
||||
|
||||
// avoid String allocation (by getDouble...)
|
||||
char[] val = jp.getTextCharacters();
|
||||
int offset = jp.getTextOffset();
|
||||
int length = jp.getTextLength();
|
||||
double c = ArrayUtils.parseNumber(val, offset, offset + length);
|
||||
|
||||
if (pos == 0)
|
||||
x = c;
|
||||
if (pos == 1)
|
||||
y = c;
|
||||
//if (pos == 2)
|
||||
//z = c;
|
||||
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (t == END_ARRAY)
|
||||
break;
|
||||
}
|
||||
|
||||
mMapElement.addPoint((float) ((longitudeToX(x) - mTileX) * mTileScale),
|
||||
(float) ((latitudeToY(y) - mTileY) * mTileScale));
|
||||
|
||||
}
|
||||
|
||||
private final static boolean match(JsonParser jp, char[] fieldName)
|
||||
throws JsonParseException, IOException {
|
||||
|
||||
int length = jp.getTextLength();
|
||||
if (length != fieldName.length)
|
||||
return false;
|
||||
|
||||
char[] val = jp.getTextCharacters();
|
||||
int offset = jp.getTextOffset();
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (fieldName[i] != val[i + offset])
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2014 Hannes Janetzek
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.tiling.source.geojson;
|
||||
|
||||
import static com.fasterxml.jackson.core.JsonToken.END_ARRAY;
|
||||
import static com.fasterxml.jackson.core.JsonToken.END_OBJECT;
|
||||
import static com.fasterxml.jackson.core.JsonToken.FIELD_NAME;
|
||||
import static com.fasterxml.jackson.core.JsonToken.START_ARRAY;
|
||||
import static com.fasterxml.jackson.core.JsonToken.START_OBJECT;
|
||||
import static com.fasterxml.jackson.core.JsonToken.VALUE_NUMBER_FLOAT;
|
||||
import static com.fasterxml.jackson.core.JsonToken.VALUE_NUMBER_INT;
|
||||
import static com.fasterxml.jackson.core.JsonToken.VALUE_STRING;
|
||||
import static org.oscim.core.MercatorProjection.latitudeToY;
|
||||
import static org.oscim.core.MercatorProjection.longitudeToX;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import org.oscim.core.GeometryBuffer.GeometryType;
|
||||
import org.oscim.core.MapElement;
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.tiling.ITileDataSink;
|
||||
import org.oscim.tiling.source.ITileDecoder;
|
||||
import org.oscim.utils.ArrayUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
public class GeoJsonTileDecoder implements ITileDecoder {
|
||||
static final Logger log = LoggerFactory.getLogger(GeoJsonTileDecoder.class);
|
||||
|
||||
private final MapElement mMapElement;
|
||||
private final GeoJsonTileSource mTileSource;
|
||||
private final LinkedHashMap<String, Object> mTagMap;
|
||||
private final JsonFactory mJsonFactory;
|
||||
|
||||
private final static char[] FIELD_FEATURES = "features".toCharArray();
|
||||
private final static char[] FIELD_GEOMETRY = "geometry".toCharArray();
|
||||
private final static char[] FIELD_PROPERTIES = "properties".toCharArray();
|
||||
private final static char[] FIELD_COORDINATES = "coordinates".toCharArray();
|
||||
private final static char[] FIELD_TYPE = "type".toCharArray();
|
||||
|
||||
private final static char[] LINETRING = "LineString".toCharArray();
|
||||
private final static char[] POLYGON = "Polygon".toCharArray();
|
||||
private final static char[] POINT = "Point".toCharArray();
|
||||
private final static char[] MULTI_LINESTRING = "MultiLineString".toCharArray();
|
||||
private final static char[] MULTI_POLYGON = "MultiPolygon".toCharArray();
|
||||
private final static char[] MULTI_POINT = "MultiPoint".toCharArray();
|
||||
|
||||
private ITileDataSink mTileDataSink;
|
||||
|
||||
private double mTileY, mTileX, mTileScale;
|
||||
|
||||
public GeoJsonTileDecoder(GeoJsonTileSource tileSource) {
|
||||
mTileSource = tileSource;
|
||||
mTagMap = new LinkedHashMap<String, Object>();
|
||||
mJsonFactory = new JsonFactory();
|
||||
|
||||
mMapElement = new MapElement();
|
||||
mMapElement.layer = 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean decode(Tile tile, ITileDataSink sink, InputStream is) throws IOException {
|
||||
mTileDataSink = sink;
|
||||
mTileScale = 1 << tile.zoomLevel;
|
||||
mTileX = tile.tileX / mTileScale;
|
||||
mTileY = tile.tileY / mTileScale;
|
||||
mTileScale *= Tile.SIZE;
|
||||
|
||||
JsonParser jp = mJsonFactory.createParser(new InputStreamReader(is));
|
||||
|
||||
for (JsonToken t; (t = jp.nextToken()) != null;) {
|
||||
if (t == FIELD_NAME) {
|
||||
if (match(jp, FIELD_FEATURES)) {
|
||||
if (jp.nextToken() != START_ARRAY)
|
||||
continue;
|
||||
|
||||
while ((t = jp.nextToken()) != null) {
|
||||
if (t == START_OBJECT)
|
||||
parseFeature(jp);
|
||||
|
||||
if (t == END_ARRAY)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void parseFeature(JsonParser jp)
|
||||
throws JsonParseException, IOException {
|
||||
|
||||
mMapElement.clear();
|
||||
mMapElement.tags.clear();
|
||||
mTagMap.clear();
|
||||
|
||||
for (JsonToken t; (t = jp.nextToken()) != null;) {
|
||||
if (t == FIELD_NAME) {
|
||||
if (match(jp, FIELD_GEOMETRY)) {
|
||||
if (jp.nextToken() == START_OBJECT)
|
||||
parseGeometry(jp);
|
||||
}
|
||||
|
||||
if (match(jp, FIELD_PROPERTIES)) {
|
||||
if (jp.nextToken() == START_OBJECT)
|
||||
parseProperties(jp);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (t == END_OBJECT)
|
||||
break;
|
||||
}
|
||||
|
||||
//add tag information
|
||||
mTileSource.decodeTags(mMapElement, mTagMap);
|
||||
if (mMapElement.tags.numTags == 0)
|
||||
return;
|
||||
|
||||
mTileSource.postGeomHook(mMapElement);
|
||||
|
||||
if (mMapElement.type == GeometryType.NONE)
|
||||
return;
|
||||
|
||||
//process this element
|
||||
mTileDataSink.process(mMapElement);
|
||||
}
|
||||
|
||||
private void parseProperties(JsonParser jp)
|
||||
throws JsonParseException, IOException {
|
||||
for (JsonToken t; (t = jp.nextToken()) != null;) {
|
||||
if (t == FIELD_NAME) {
|
||||
String text = jp.getCurrentName();
|
||||
|
||||
t = jp.nextToken();
|
||||
if (t == VALUE_STRING) {
|
||||
mTagMap.put(text, jp.getText());
|
||||
} else if (t == VALUE_NUMBER_INT) {
|
||||
mTagMap.put(text, jp.getNumberValue());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (t == END_OBJECT)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void parseGeometry(JsonParser jp)
|
||||
throws JsonParseException, IOException {
|
||||
|
||||
boolean multi = false;
|
||||
GeometryType type = GeometryType.NONE;
|
||||
|
||||
for (JsonToken t; (t = jp.nextToken()) != null;) {
|
||||
if (t == FIELD_NAME) {
|
||||
if (match(jp, FIELD_COORDINATES)) {
|
||||
if (jp.nextToken() != START_ARRAY)
|
||||
continue;
|
||||
if (multi) {
|
||||
parseMulti(jp, type);
|
||||
} else {
|
||||
if (type == GeometryType.POLY)
|
||||
parsePolygon(jp);
|
||||
|
||||
if (type == GeometryType.LINE)
|
||||
parseLineString(jp);
|
||||
|
||||
if (type == GeometryType.POINT)
|
||||
parseCoordinate(jp);
|
||||
|
||||
}
|
||||
} else if (match(jp, FIELD_TYPE)) {
|
||||
multi = false;
|
||||
|
||||
jp.nextToken();
|
||||
|
||||
if (match(jp, LINETRING))
|
||||
type = GeometryType.LINE;
|
||||
else if (match(jp, POLYGON))
|
||||
type = GeometryType.POLY;
|
||||
else if (match(jp, POINT))
|
||||
type = GeometryType.POINT;
|
||||
else if (match(jp, MULTI_LINESTRING)) {
|
||||
type = GeometryType.LINE;
|
||||
multi = true;
|
||||
}
|
||||
else if (match(jp, MULTI_POLYGON)) {
|
||||
type = GeometryType.POLY;
|
||||
multi = true;
|
||||
}
|
||||
else if (match(jp, MULTI_POINT)) {
|
||||
type = GeometryType.POINT;
|
||||
multi = true;
|
||||
}
|
||||
|
||||
if (type == GeometryType.POINT)
|
||||
mMapElement.startPoints();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (t == END_OBJECT)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void parseMulti(JsonParser jp, GeometryType type)
|
||||
throws JsonParseException, IOException {
|
||||
|
||||
for (JsonToken t; (t = jp.nextToken()) != null;) {
|
||||
if (t == END_ARRAY)
|
||||
break;
|
||||
|
||||
if (t == START_ARRAY) {
|
||||
if (type == GeometryType.POLY)
|
||||
parsePolygon(jp);
|
||||
|
||||
else if (type == GeometryType.LINE)
|
||||
parseLineString(jp);
|
||||
|
||||
else if (type == GeometryType.POINT)
|
||||
parseCoordinate(jp);;
|
||||
|
||||
} else {
|
||||
//....
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void parsePolygon(JsonParser jp)
|
||||
throws JsonParseException, IOException {
|
||||
int ring = 0;
|
||||
|
||||
for (JsonToken t; (t = jp.nextToken()) != null;) {
|
||||
if (t == START_ARRAY) {
|
||||
if (ring == 0)
|
||||
mMapElement.startPolygon();
|
||||
else
|
||||
mMapElement.startHole();
|
||||
|
||||
ring++;
|
||||
parseCoordSequence(jp);
|
||||
removeLastPoint();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (t == END_ARRAY)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void removeLastPoint() {
|
||||
mMapElement.pointPos -= 2;
|
||||
mMapElement.index[mMapElement.indexPos] -= 2;
|
||||
}
|
||||
|
||||
private void parseLineString(JsonParser jp)
|
||||
throws JsonParseException, IOException {
|
||||
mMapElement.startLine();
|
||||
parseCoordSequence(jp);
|
||||
}
|
||||
|
||||
private void parseCoordSequence(JsonParser jp)
|
||||
throws JsonParseException, IOException {
|
||||
|
||||
for (JsonToken t; (t = jp.nextToken()) != null;) {
|
||||
|
||||
if (t == START_ARRAY) {
|
||||
parseCoordinate(jp);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (t == END_ARRAY)
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void parseCoordinate(JsonParser jp)
|
||||
throws JsonParseException, IOException {
|
||||
int pos = 0;
|
||||
double x = 0, y = 0; //, z = 0;
|
||||
|
||||
for (JsonToken t; (t = jp.nextToken()) != null;) {
|
||||
if (t == VALUE_NUMBER_FLOAT || t == VALUE_NUMBER_INT) {
|
||||
|
||||
// avoid String allocation (by getDouble...)
|
||||
char[] val = jp.getTextCharacters();
|
||||
int offset = jp.getTextOffset();
|
||||
int length = jp.getTextLength();
|
||||
double c = ArrayUtils.parseNumber(val, offset, offset + length);
|
||||
|
||||
if (pos == 0)
|
||||
x = c;
|
||||
if (pos == 1)
|
||||
y = c;
|
||||
//if (pos == 2)
|
||||
//z = c;
|
||||
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (t == END_ARRAY)
|
||||
break;
|
||||
}
|
||||
|
||||
mMapElement.addPoint((float) ((longitudeToX(x) - mTileX) * mTileScale),
|
||||
(float) ((latitudeToY(y) - mTileY) * mTileScale));
|
||||
|
||||
}
|
||||
|
||||
private final static boolean match(JsonParser jp, char[] fieldName)
|
||||
throws JsonParseException, IOException {
|
||||
|
||||
int length = jp.getTextLength();
|
||||
if (length != fieldName.length)
|
||||
return false;
|
||||
|
||||
char[] val = jp.getTextCharacters();
|
||||
int offset = jp.getTextOffset();
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (fieldName[i] != val[i + offset])
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,71 +1,71 @@
|
||||
/*
|
||||
* Copyright 2014 Hannes Janetzek
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.tiling.source.geojson;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.oscim.core.MapElement;
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.tiling.ITileDataSource;
|
||||
import org.oscim.tiling.source.UrlTileDataSource;
|
||||
import org.oscim.tiling.source.UrlTileSource;
|
||||
|
||||
public abstract class GeoJsonTileSource extends UrlTileSource {
|
||||
|
||||
public GeoJsonTileSource(String url) {
|
||||
super(url, "/{Z}/{X}/{Y}.json");
|
||||
Map<String, String> opt = new HashMap<String, String>();
|
||||
opt.put("Accept-Encoding", "gzip");
|
||||
setHttpRequestHeaders(opt);
|
||||
}
|
||||
|
||||
public GeoJsonTileSource(String url, int zoomMin, int zoomMax) {
|
||||
super(url, "/{Z}/{X}/{Y}.json", zoomMin, zoomMax);
|
||||
Map<String, String> opt = new HashMap<String, String>();
|
||||
opt.put("Accept-Encoding", "gzip");
|
||||
setHttpRequestHeaders(opt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITileDataSource getDataSource() {
|
||||
|
||||
return new UrlTileDataSource(this, new GeoJsonTileDecoder(this), getHttpEngine());
|
||||
}
|
||||
|
||||
public Tag getFeatureTag() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** allow overriding tag handling */
|
||||
public abstract void decodeTags(MapElement mapElement, Map<String, Object> properties);
|
||||
|
||||
public Tag rewriteTag(String key, Object value) {
|
||||
|
||||
if (value == null)
|
||||
return null;
|
||||
|
||||
String val = (value instanceof String) ? (String) value : String.valueOf(value);
|
||||
|
||||
return new Tag(key, val);
|
||||
}
|
||||
|
||||
/** modify mapElement before process() */
|
||||
public void postGeomHook(MapElement mapElement) {
|
||||
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2014 Hannes Janetzek
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.tiling.source.geojson;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.oscim.core.MapElement;
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.tiling.ITileDataSource;
|
||||
import org.oscim.tiling.source.UrlTileDataSource;
|
||||
import org.oscim.tiling.source.UrlTileSource;
|
||||
|
||||
public abstract class GeoJsonTileSource extends UrlTileSource {
|
||||
|
||||
public GeoJsonTileSource(String url) {
|
||||
super(url, "/{Z}/{X}/{Y}.json");
|
||||
Map<String, String> opt = new HashMap<String, String>();
|
||||
opt.put("Accept-Encoding", "gzip");
|
||||
setHttpRequestHeaders(opt);
|
||||
}
|
||||
|
||||
public GeoJsonTileSource(String url, int zoomMin, int zoomMax) {
|
||||
super(url, "/{Z}/{X}/{Y}.json", zoomMin, zoomMax);
|
||||
Map<String, String> opt = new HashMap<String, String>();
|
||||
opt.put("Accept-Encoding", "gzip");
|
||||
setHttpRequestHeaders(opt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITileDataSource getDataSource() {
|
||||
|
||||
return new UrlTileDataSource(this, new GeoJsonTileDecoder(this), getHttpEngine());
|
||||
}
|
||||
|
||||
public Tag getFeatureTag() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** allow overriding tag handling */
|
||||
public abstract void decodeTags(MapElement mapElement, Map<String, Object> properties);
|
||||
|
||||
public Tag rewriteTag(String key, Object value) {
|
||||
|
||||
if (value == null)
|
||||
return null;
|
||||
|
||||
String val = (value instanceof String) ? (String) value : String.valueOf(value);
|
||||
|
||||
return new Tag(key, val);
|
||||
}
|
||||
|
||||
/** modify mapElement before process() */
|
||||
public void postGeomHook(MapElement mapElement) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,366 +1,366 @@
|
||||
package org.oscim.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Triangulates a polygon into triangles - duh. Doesn't handle
|
||||
* holes in polys
|
||||
*
|
||||
* @author Public Source from FlipCode
|
||||
*/
|
||||
public class Triangulator {
|
||||
/** The accepted error value */
|
||||
private static final float EPSILON = 0.0000000001f;
|
||||
/** The list of points to be triangulated */
|
||||
private final PointList poly = new PointList();
|
||||
/** The list of points describing the triangles */
|
||||
private final PointList tris = new PointList();
|
||||
/** True if we've tried to triangulate */
|
||||
private boolean tried;
|
||||
|
||||
/**
|
||||
* Create a new triangulator
|
||||
*/
|
||||
public Triangulator() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a point describing the polygon to be triangulated
|
||||
*
|
||||
* @param x The x coordinate of the point
|
||||
* @param y the y coordinate of the point
|
||||
*/
|
||||
public void addPolyPoint(float x, float y) {
|
||||
poly.add(new Point(x, y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cause the triangulator to split the polygon
|
||||
*
|
||||
* @return True if we managed the task
|
||||
*/
|
||||
public boolean triangulate() {
|
||||
tried = true;
|
||||
|
||||
boolean worked = process(poly, tris);
|
||||
return worked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a count of the number of triangles produced
|
||||
*
|
||||
* @return The number of triangles produced
|
||||
*/
|
||||
public int getTriangleCount() {
|
||||
if (!tried) {
|
||||
throw new RuntimeException("Call triangulate() before accessing triangles");
|
||||
}
|
||||
return tris.size() / 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a point on a specified generated triangle
|
||||
*
|
||||
* @param tri The index of the triangle to interegate
|
||||
* @param i The index of the point within the triangle to retrieve
|
||||
* (0 - 2)
|
||||
* @return The x,y coordinate pair for the point
|
||||
*/
|
||||
public float[] getTrianglePoint(int tri, int i) {
|
||||
if (!tried) {
|
||||
throw new RuntimeException("Call triangulate() before accessing triangles");
|
||||
}
|
||||
return tris.get((tri * 3) + i).toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the area of a polygon defined by the series of points
|
||||
* in the list
|
||||
*
|
||||
* @param contour The list of points defined the contour of the polygon
|
||||
* (Vector2f)
|
||||
* @return The area of the polygon defined
|
||||
*/
|
||||
private static float area(PointList contour) {
|
||||
int n = contour.size();
|
||||
|
||||
float A = 0.0f;
|
||||
|
||||
for (int p = n - 1, q = 0; q < n; p = q++) {
|
||||
Point contourP = contour.get(p);
|
||||
Point contourQ = contour.get(q);
|
||||
|
||||
A += contourP.getX() * contourQ.getY() - contourQ.getX()
|
||||
* contourP.getY();
|
||||
}
|
||||
return A * 0.5f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the point P is inside the triangle defined by
|
||||
* the points A,B,C
|
||||
*
|
||||
* @param Ax Point A x-coordinate
|
||||
* @param Ay Point A y-coordinate
|
||||
* @param Bx Point B x-coordinate
|
||||
* @param By Point B y-coordinate
|
||||
* @param Cx Point C x-coordinate
|
||||
* @param Cy Point C y-coordinate
|
||||
* @param Px Point P x-coordinate
|
||||
* @param Py Point P y-coordinate
|
||||
* @return True if the point specified is within the triangle
|
||||
*/
|
||||
private static boolean insideTriangle(float Ax, float Ay, float Bx,
|
||||
float By, float Cx, float Cy, float Px, float Py) {
|
||||
float ax, ay, bx, by, cx, cy, apx, apy, bpx, bpy, cpx, cpy;
|
||||
float cCROSSap, bCROSScp, aCROSSbp;
|
||||
|
||||
ax = Cx - Bx;
|
||||
ay = Cy - By;
|
||||
bx = Ax - Cx;
|
||||
by = Ay - Cy;
|
||||
cx = Bx - Ax;
|
||||
cy = By - Ay;
|
||||
apx = Px - Ax;
|
||||
apy = Py - Ay;
|
||||
bpx = Px - Bx;
|
||||
bpy = Py - By;
|
||||
cpx = Px - Cx;
|
||||
cpy = Py - Cy;
|
||||
|
||||
aCROSSbp = ax * bpy - ay * bpx;
|
||||
cCROSSap = cx * apy - cy * apx;
|
||||
bCROSScp = bx * cpy - by * cpx;
|
||||
|
||||
return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cut a the contour and add a triangle into V to describe the
|
||||
* location of the cut
|
||||
*
|
||||
* @param contour The list of points defining the polygon
|
||||
* @param u The index of the first point
|
||||
* @param v The index of the second point
|
||||
* @param w The index of the third point
|
||||
* @param n ?
|
||||
* @param V The array to populate with indicies of triangles
|
||||
* @return True if a triangle was found
|
||||
*/
|
||||
private static boolean snip(PointList contour, int u, int v, int w, int n,
|
||||
int[] V) {
|
||||
int p;
|
||||
float Ax, Ay, Bx, By, Cx, Cy, Px, Py;
|
||||
|
||||
Ax = contour.get(V[u]).getX();
|
||||
Ay = contour.get(V[u]).getY();
|
||||
|
||||
Bx = contour.get(V[v]).getX();
|
||||
By = contour.get(V[v]).getY();
|
||||
|
||||
Cx = contour.get(V[w]).getX();
|
||||
Cy = contour.get(V[w]).getY();
|
||||
|
||||
if (EPSILON > (((Bx - Ax) * (Cy - Ay)) - ((By - Ay) * (Cx - Ax)))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (p = 0; p < n; p++) {
|
||||
if ((p == u) || (p == v) || (p == w)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Px = contour.get(V[p]).getX();
|
||||
Py = contour.get(V[p]).getY();
|
||||
|
||||
if (insideTriangle(Ax, Ay, Bx, By, Cx, Cy, Px, Py)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a list of points defining a polygon
|
||||
*
|
||||
* @param contour The list of points describing the polygon
|
||||
* @param result The list of points describing the triangles. Groups
|
||||
* of 3 describe each triangle
|
||||
* @return True if we succeeded in completing triangulation
|
||||
*/
|
||||
private static boolean process(PointList contour, PointList result) {
|
||||
/* allocate and initialize list of Vertices in polygon */
|
||||
|
||||
int n = contour.size();
|
||||
if (n < 3)
|
||||
return false;
|
||||
|
||||
int[] V = new int[n];
|
||||
|
||||
/* we want a counter-clockwise polygon in V */
|
||||
|
||||
if (0.0f < area(contour)) {
|
||||
for (int v = 0; v < n; v++)
|
||||
V[v] = v;
|
||||
} else {
|
||||
for (int v = 0; v < n; v++)
|
||||
V[v] = (n - 1) - v;
|
||||
}
|
||||
|
||||
int nv = n;
|
||||
|
||||
/* remove nv-2 Vertices, creating 1 triangle every time */
|
||||
int count = 2 * nv; /* error detection */
|
||||
|
||||
//for (int m = 0, v = nv - 1; nv > 2;) {
|
||||
for (int v = nv - 1; nv > 2;) {
|
||||
/* if we loop, it is probably a non-simple polygon */
|
||||
if (0 >= (count--)) {
|
||||
//** Triangulate: ERROR - probable bad polygon!
|
||||
return false;
|
||||
}
|
||||
|
||||
/* three consecutive vertices in current polygon, <u,v,w> */
|
||||
int u = v;
|
||||
if (nv <= u)
|
||||
u = 0; /* previous */
|
||||
v = u + 1;
|
||||
if (nv <= v)
|
||||
v = 0; /* new v */
|
||||
int w = v + 1;
|
||||
if (nv <= w)
|
||||
w = 0; /* next */
|
||||
|
||||
if (snip(contour, u, v, w, nv, V)) {
|
||||
int a, b, c, s, t;
|
||||
|
||||
/* true names of the vertices */
|
||||
a = V[u];
|
||||
b = V[v];
|
||||
c = V[w];
|
||||
|
||||
/* output Triangle */
|
||||
result.add(contour.get(a));
|
||||
result.add(contour.get(b));
|
||||
result.add(contour.get(c));
|
||||
|
||||
//m++;
|
||||
|
||||
/* remove v from remaining polygon */
|
||||
for (s = v, t = v + 1; t < nv; s++, t++) {
|
||||
V[s] = V[t];
|
||||
}
|
||||
nv--;
|
||||
|
||||
/* resest error detection counter */
|
||||
count = 2 * nv;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* A single point handled by the triangulator
|
||||
*
|
||||
* @author Kevin Glass
|
||||
*/
|
||||
private class Point {
|
||||
/** The x coorindate of this point */
|
||||
private final float x;
|
||||
/** The y coorindate of this point */
|
||||
private final float y;
|
||||
|
||||
/**
|
||||
* Create a new point
|
||||
*
|
||||
* @param x The x coordindate of the point
|
||||
* @param y The y coordindate of the point
|
||||
*/
|
||||
public Point(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the x coordinate of the point
|
||||
*
|
||||
* @return The x coordinate of the point
|
||||
*/
|
||||
public float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the y coordinate of the point
|
||||
*
|
||||
* @return The y coordinate of the point
|
||||
*/
|
||||
public float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert this point into a float array
|
||||
*
|
||||
* @return The contents of this point as a float array
|
||||
*/
|
||||
public float[] toArray() {
|
||||
return new float[] { x, y };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of type <code>Point</code>
|
||||
*
|
||||
* @author Kevin Glass
|
||||
*/
|
||||
private class PointList {
|
||||
/** The list of points */
|
||||
private final ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
/**
|
||||
* Create a new empty list
|
||||
*/
|
||||
public PointList() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a point to the list
|
||||
*
|
||||
* @param point The point to add
|
||||
*/
|
||||
public void add(Point point) {
|
||||
points.add(point);
|
||||
}
|
||||
|
||||
///**
|
||||
// * Remove a point from the list
|
||||
// *
|
||||
// * @param point The point to remove
|
||||
// */
|
||||
//public void remove(Point point) {
|
||||
// points.remove(point);
|
||||
//}
|
||||
|
||||
/**
|
||||
* Get the size of the list
|
||||
*
|
||||
* @return The size of the list
|
||||
*/
|
||||
public int size() {
|
||||
return points.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a point a specific index in the list
|
||||
*
|
||||
* @param i The index of the point to retrieve
|
||||
* @return The point
|
||||
*/
|
||||
public Point get(int i) {
|
||||
return points.get(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
package org.oscim.utils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Triangulates a polygon into triangles - duh. Doesn't handle
|
||||
* holes in polys
|
||||
*
|
||||
* @author Public Source from FlipCode
|
||||
*/
|
||||
public class Triangulator {
|
||||
/** The accepted error value */
|
||||
private static final float EPSILON = 0.0000000001f;
|
||||
/** The list of points to be triangulated */
|
||||
private final PointList poly = new PointList();
|
||||
/** The list of points describing the triangles */
|
||||
private final PointList tris = new PointList();
|
||||
/** True if we've tried to triangulate */
|
||||
private boolean tried;
|
||||
|
||||
/**
|
||||
* Create a new triangulator
|
||||
*/
|
||||
public Triangulator() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a point describing the polygon to be triangulated
|
||||
*
|
||||
* @param x The x coordinate of the point
|
||||
* @param y the y coordinate of the point
|
||||
*/
|
||||
public void addPolyPoint(float x, float y) {
|
||||
poly.add(new Point(x, y));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cause the triangulator to split the polygon
|
||||
*
|
||||
* @return True if we managed the task
|
||||
*/
|
||||
public boolean triangulate() {
|
||||
tried = true;
|
||||
|
||||
boolean worked = process(poly, tris);
|
||||
return worked;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a count of the number of triangles produced
|
||||
*
|
||||
* @return The number of triangles produced
|
||||
*/
|
||||
public int getTriangleCount() {
|
||||
if (!tried) {
|
||||
throw new RuntimeException("Call triangulate() before accessing triangles");
|
||||
}
|
||||
return tris.size() / 3;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a point on a specified generated triangle
|
||||
*
|
||||
* @param tri The index of the triangle to interegate
|
||||
* @param i The index of the point within the triangle to retrieve
|
||||
* (0 - 2)
|
||||
* @return The x,y coordinate pair for the point
|
||||
*/
|
||||
public float[] getTrianglePoint(int tri, int i) {
|
||||
if (!tried) {
|
||||
throw new RuntimeException("Call triangulate() before accessing triangles");
|
||||
}
|
||||
return tris.get((tri * 3) + i).toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the area of a polygon defined by the series of points
|
||||
* in the list
|
||||
*
|
||||
* @param contour The list of points defined the contour of the polygon
|
||||
* (Vector2f)
|
||||
* @return The area of the polygon defined
|
||||
*/
|
||||
private static float area(PointList contour) {
|
||||
int n = contour.size();
|
||||
|
||||
float A = 0.0f;
|
||||
|
||||
for (int p = n - 1, q = 0; q < n; p = q++) {
|
||||
Point contourP = contour.get(p);
|
||||
Point contourQ = contour.get(q);
|
||||
|
||||
A += contourP.getX() * contourQ.getY() - contourQ.getX()
|
||||
* contourP.getY();
|
||||
}
|
||||
return A * 0.5f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the point P is inside the triangle defined by
|
||||
* the points A,B,C
|
||||
*
|
||||
* @param Ax Point A x-coordinate
|
||||
* @param Ay Point A y-coordinate
|
||||
* @param Bx Point B x-coordinate
|
||||
* @param By Point B y-coordinate
|
||||
* @param Cx Point C x-coordinate
|
||||
* @param Cy Point C y-coordinate
|
||||
* @param Px Point P x-coordinate
|
||||
* @param Py Point P y-coordinate
|
||||
* @return True if the point specified is within the triangle
|
||||
*/
|
||||
private static boolean insideTriangle(float Ax, float Ay, float Bx,
|
||||
float By, float Cx, float Cy, float Px, float Py) {
|
||||
float ax, ay, bx, by, cx, cy, apx, apy, bpx, bpy, cpx, cpy;
|
||||
float cCROSSap, bCROSScp, aCROSSbp;
|
||||
|
||||
ax = Cx - Bx;
|
||||
ay = Cy - By;
|
||||
bx = Ax - Cx;
|
||||
by = Ay - Cy;
|
||||
cx = Bx - Ax;
|
||||
cy = By - Ay;
|
||||
apx = Px - Ax;
|
||||
apy = Py - Ay;
|
||||
bpx = Px - Bx;
|
||||
bpy = Py - By;
|
||||
cpx = Px - Cx;
|
||||
cpy = Py - Cy;
|
||||
|
||||
aCROSSbp = ax * bpy - ay * bpx;
|
||||
cCROSSap = cx * apy - cy * apx;
|
||||
bCROSScp = bx * cpy - by * cpx;
|
||||
|
||||
return ((aCROSSbp >= 0.0f) && (bCROSScp >= 0.0f) && (cCROSSap >= 0.0f));
|
||||
}
|
||||
|
||||
/**
|
||||
* Cut a the contour and add a triangle into V to describe the
|
||||
* location of the cut
|
||||
*
|
||||
* @param contour The list of points defining the polygon
|
||||
* @param u The index of the first point
|
||||
* @param v The index of the second point
|
||||
* @param w The index of the third point
|
||||
* @param n ?
|
||||
* @param V The array to populate with indicies of triangles
|
||||
* @return True if a triangle was found
|
||||
*/
|
||||
private static boolean snip(PointList contour, int u, int v, int w, int n,
|
||||
int[] V) {
|
||||
int p;
|
||||
float Ax, Ay, Bx, By, Cx, Cy, Px, Py;
|
||||
|
||||
Ax = contour.get(V[u]).getX();
|
||||
Ay = contour.get(V[u]).getY();
|
||||
|
||||
Bx = contour.get(V[v]).getX();
|
||||
By = contour.get(V[v]).getY();
|
||||
|
||||
Cx = contour.get(V[w]).getX();
|
||||
Cy = contour.get(V[w]).getY();
|
||||
|
||||
if (EPSILON > (((Bx - Ax) * (Cy - Ay)) - ((By - Ay) * (Cx - Ax)))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (p = 0; p < n; p++) {
|
||||
if ((p == u) || (p == v) || (p == w)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Px = contour.get(V[p]).getX();
|
||||
Py = contour.get(V[p]).getY();
|
||||
|
||||
if (insideTriangle(Ax, Ay, Bx, By, Cx, Cy, Px, Py)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a list of points defining a polygon
|
||||
*
|
||||
* @param contour The list of points describing the polygon
|
||||
* @param result The list of points describing the triangles. Groups
|
||||
* of 3 describe each triangle
|
||||
* @return True if we succeeded in completing triangulation
|
||||
*/
|
||||
private static boolean process(PointList contour, PointList result) {
|
||||
/* allocate and initialize list of Vertices in polygon */
|
||||
|
||||
int n = contour.size();
|
||||
if (n < 3)
|
||||
return false;
|
||||
|
||||
int[] V = new int[n];
|
||||
|
||||
/* we want a counter-clockwise polygon in V */
|
||||
|
||||
if (0.0f < area(contour)) {
|
||||
for (int v = 0; v < n; v++)
|
||||
V[v] = v;
|
||||
} else {
|
||||
for (int v = 0; v < n; v++)
|
||||
V[v] = (n - 1) - v;
|
||||
}
|
||||
|
||||
int nv = n;
|
||||
|
||||
/* remove nv-2 Vertices, creating 1 triangle every time */
|
||||
int count = 2 * nv; /* error detection */
|
||||
|
||||
//for (int m = 0, v = nv - 1; nv > 2;) {
|
||||
for (int v = nv - 1; nv > 2;) {
|
||||
/* if we loop, it is probably a non-simple polygon */
|
||||
if (0 >= (count--)) {
|
||||
//** Triangulate: ERROR - probable bad polygon!
|
||||
return false;
|
||||
}
|
||||
|
||||
/* three consecutive vertices in current polygon, <u,v,w> */
|
||||
int u = v;
|
||||
if (nv <= u)
|
||||
u = 0; /* previous */
|
||||
v = u + 1;
|
||||
if (nv <= v)
|
||||
v = 0; /* new v */
|
||||
int w = v + 1;
|
||||
if (nv <= w)
|
||||
w = 0; /* next */
|
||||
|
||||
if (snip(contour, u, v, w, nv, V)) {
|
||||
int a, b, c, s, t;
|
||||
|
||||
/* true names of the vertices */
|
||||
a = V[u];
|
||||
b = V[v];
|
||||
c = V[w];
|
||||
|
||||
/* output Triangle */
|
||||
result.add(contour.get(a));
|
||||
result.add(contour.get(b));
|
||||
result.add(contour.get(c));
|
||||
|
||||
//m++;
|
||||
|
||||
/* remove v from remaining polygon */
|
||||
for (s = v, t = v + 1; t < nv; s++, t++) {
|
||||
V[s] = V[t];
|
||||
}
|
||||
nv--;
|
||||
|
||||
/* resest error detection counter */
|
||||
count = 2 * nv;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* A single point handled by the triangulator
|
||||
*
|
||||
* @author Kevin Glass
|
||||
*/
|
||||
private class Point {
|
||||
/** The x coorindate of this point */
|
||||
private final float x;
|
||||
/** The y coorindate of this point */
|
||||
private final float y;
|
||||
|
||||
/**
|
||||
* Create a new point
|
||||
*
|
||||
* @param x The x coordindate of the point
|
||||
* @param y The y coordindate of the point
|
||||
*/
|
||||
public Point(float x, float y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the x coordinate of the point
|
||||
*
|
||||
* @return The x coordinate of the point
|
||||
*/
|
||||
public float getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the y coordinate of the point
|
||||
*
|
||||
* @return The y coordinate of the point
|
||||
*/
|
||||
public float getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert this point into a float array
|
||||
*
|
||||
* @return The contents of this point as a float array
|
||||
*/
|
||||
public float[] toArray() {
|
||||
return new float[] { x, y };
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A list of type <code>Point</code>
|
||||
*
|
||||
* @author Kevin Glass
|
||||
*/
|
||||
private class PointList {
|
||||
/** The list of points */
|
||||
private final ArrayList<Point> points = new ArrayList<Point>();
|
||||
|
||||
/**
|
||||
* Create a new empty list
|
||||
*/
|
||||
public PointList() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a point to the list
|
||||
*
|
||||
* @param point The point to add
|
||||
*/
|
||||
public void add(Point point) {
|
||||
points.add(point);
|
||||
}
|
||||
|
||||
///**
|
||||
// * Remove a point from the list
|
||||
// *
|
||||
// * @param point The point to remove
|
||||
// */
|
||||
//public void remove(Point point) {
|
||||
// points.remove(point);
|
||||
//}
|
||||
|
||||
/**
|
||||
* Get the size of the list
|
||||
*
|
||||
* @return The size of the list
|
||||
*/
|
||||
public int size() {
|
||||
return points.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a point a specific index in the list
|
||||
*
|
||||
* @param i The index of the point to retrieve
|
||||
* @return The point
|
||||
*/
|
||||
public Point get(int i) {
|
||||
return points.get(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit trunk//EN" "http://google-web-toolkit.googlecode.com/svn/trunk/distro-source/core/src/gwt-module.dtd">
|
||||
<module>
|
||||
<source path="org/oscim" />
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit trunk//EN" "http://google-web-toolkit.googlecode.com/svn/trunk/distro-source/core/src/gwt-module.dtd">
|
||||
<module>
|
||||
<source path="org/oscim" />
|
||||
</module>
|
@ -1,214 +1,214 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.gdx;
|
||||
|
||||
import org.oscim.layers.TileGridLayer;
|
||||
import org.oscim.layers.tile.buildings.BuildingLayer;
|
||||
import org.oscim.layers.tile.vector.VectorTileLayer;
|
||||
import org.oscim.layers.tile.vector.labeling.LabelLayer;
|
||||
import org.oscim.map.Layers;
|
||||
import org.oscim.map.Map;
|
||||
import org.oscim.renderer.MapRenderer;
|
||||
import org.oscim.theme.VtmThemes;
|
||||
import org.oscim.tiling.TileSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.badlogic.gdx.Application;
|
||||
import com.badlogic.gdx.ApplicationListener;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.InputMultiplexer;
|
||||
import com.badlogic.gdx.utils.Timer;
|
||||
import com.badlogic.gdx.utils.Timer.Task;
|
||||
|
||||
public abstract class GdxMap implements ApplicationListener {
|
||||
final static Logger log = LoggerFactory.getLogger(GdxMap.class);
|
||||
|
||||
protected Map mMap;
|
||||
|
||||
VectorTileLayer mMapLayer;
|
||||
private MapRenderer mMapRenderer;
|
||||
|
||||
public GdxMap() {
|
||||
}
|
||||
|
||||
protected void initDefaultLayers(TileSource tileSource, boolean tileGrid, boolean labels,
|
||||
boolean buildings) {
|
||||
Layers layers = mMap.layers();
|
||||
|
||||
if (tileSource != null) {
|
||||
mMapLayer = mMap.setBaseMap(tileSource);
|
||||
mMap.setTheme(VtmThemes.DEFAULT);
|
||||
|
||||
if (buildings)
|
||||
layers.add(new BuildingLayer(mMap, mMapLayer));
|
||||
|
||||
if (labels)
|
||||
layers.add(new LabelLayer(mMap, mMapLayer));
|
||||
}
|
||||
|
||||
if (tileGrid)
|
||||
layers.add(new TileGridLayer(mMap));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
mMap = new MapAdapter();
|
||||
mMapRenderer = new MapRenderer(mMap);
|
||||
|
||||
Gdx.graphics.setContinuousRendering(false);
|
||||
Gdx.app.setLogLevel(Application.LOG_DEBUG);
|
||||
|
||||
int w = Gdx.graphics.getWidth();
|
||||
int h = Gdx.graphics.getHeight();
|
||||
|
||||
mMap.viewport().setScreenSize(w, h);
|
||||
mMapRenderer.onSurfaceCreated();
|
||||
mMapRenderer.onSurfaceChanged(w, h);
|
||||
|
||||
InputMultiplexer mux = new InputMultiplexer();
|
||||
mux.addProcessor(new InputHandler(this));
|
||||
//mux.addProcessor(new GestureDetector(20, 0.5f, 2, 0.05f,
|
||||
// new MapController(mMap)));
|
||||
mux.addProcessor(new MotionHandler(mMap));
|
||||
|
||||
Gdx.input.setInputProcessor(mux);
|
||||
|
||||
createLayers();
|
||||
}
|
||||
|
||||
protected void createLayers() {
|
||||
mMap.layers().add(new TileGridLayer(mMap));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
|
||||
}
|
||||
|
||||
/* private */boolean mRenderWait;
|
||||
/* private */boolean mRenderRequest;
|
||||
/* private */boolean mUpdateRequest;
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
if (!mRenderRequest)
|
||||
return;
|
||||
|
||||
mMapRenderer.onDrawFrame();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int w, int h) {
|
||||
mMap.viewport().setScreenSize(w, h);
|
||||
mMapRenderer.onSurfaceChanged(w, h);
|
||||
mMap.render();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume() {
|
||||
}
|
||||
|
||||
protected boolean onKeyDown(int keycode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Map getMap() {
|
||||
return mMap;
|
||||
}
|
||||
|
||||
class MapAdapter extends Map {
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return Gdx.graphics.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return Gdx.graphics.getHeight();
|
||||
}
|
||||
|
||||
private final Runnable mRedrawCb = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
prepareFrame();
|
||||
Gdx.graphics.requestRendering();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void updateMap(boolean forceRender) {
|
||||
synchronized (mRedrawCb) {
|
||||
if (!mRenderRequest) {
|
||||
mRenderRequest = true;
|
||||
Gdx.app.postRunnable(mRedrawCb);
|
||||
} else {
|
||||
mRenderWait = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
synchronized (mRedrawCb) {
|
||||
mRenderRequest = true;
|
||||
if (mClearMap)
|
||||
updateMap(false);
|
||||
else {
|
||||
Gdx.graphics.requestRendering();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean post(Runnable runnable) {
|
||||
Gdx.app.postRunnable(runnable);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean postDelayed(final Runnable action, long delay) {
|
||||
Timer.schedule(new Task() {
|
||||
@Override
|
||||
public void run() {
|
||||
action.run();
|
||||
}
|
||||
}, delay / 1000f);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beginFrame() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doneFrame(boolean animate) {
|
||||
synchronized (mRedrawCb) {
|
||||
mRenderRequest = false;
|
||||
if (animate || mRenderWait) {
|
||||
mRenderWait = false;
|
||||
updateMap(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.gdx;
|
||||
|
||||
import org.oscim.layers.TileGridLayer;
|
||||
import org.oscim.layers.tile.buildings.BuildingLayer;
|
||||
import org.oscim.layers.tile.vector.VectorTileLayer;
|
||||
import org.oscim.layers.tile.vector.labeling.LabelLayer;
|
||||
import org.oscim.map.Layers;
|
||||
import org.oscim.map.Map;
|
||||
import org.oscim.renderer.MapRenderer;
|
||||
import org.oscim.theme.VtmThemes;
|
||||
import org.oscim.tiling.TileSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.badlogic.gdx.Application;
|
||||
import com.badlogic.gdx.ApplicationListener;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.InputMultiplexer;
|
||||
import com.badlogic.gdx.utils.Timer;
|
||||
import com.badlogic.gdx.utils.Timer.Task;
|
||||
|
||||
public abstract class GdxMap implements ApplicationListener {
|
||||
final static Logger log = LoggerFactory.getLogger(GdxMap.class);
|
||||
|
||||
protected Map mMap;
|
||||
|
||||
VectorTileLayer mMapLayer;
|
||||
private MapRenderer mMapRenderer;
|
||||
|
||||
public GdxMap() {
|
||||
}
|
||||
|
||||
protected void initDefaultLayers(TileSource tileSource, boolean tileGrid, boolean labels,
|
||||
boolean buildings) {
|
||||
Layers layers = mMap.layers();
|
||||
|
||||
if (tileSource != null) {
|
||||
mMapLayer = mMap.setBaseMap(tileSource);
|
||||
mMap.setTheme(VtmThemes.DEFAULT);
|
||||
|
||||
if (buildings)
|
||||
layers.add(new BuildingLayer(mMap, mMapLayer));
|
||||
|
||||
if (labels)
|
||||
layers.add(new LabelLayer(mMap, mMapLayer));
|
||||
}
|
||||
|
||||
if (tileGrid)
|
||||
layers.add(new TileGridLayer(mMap));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
mMap = new MapAdapter();
|
||||
mMapRenderer = new MapRenderer(mMap);
|
||||
|
||||
Gdx.graphics.setContinuousRendering(false);
|
||||
Gdx.app.setLogLevel(Application.LOG_DEBUG);
|
||||
|
||||
int w = Gdx.graphics.getWidth();
|
||||
int h = Gdx.graphics.getHeight();
|
||||
|
||||
mMap.viewport().setScreenSize(w, h);
|
||||
mMapRenderer.onSurfaceCreated();
|
||||
mMapRenderer.onSurfaceChanged(w, h);
|
||||
|
||||
InputMultiplexer mux = new InputMultiplexer();
|
||||
mux.addProcessor(new InputHandler(this));
|
||||
//mux.addProcessor(new GestureDetector(20, 0.5f, 2, 0.05f,
|
||||
// new MapController(mMap)));
|
||||
mux.addProcessor(new MotionHandler(mMap));
|
||||
|
||||
Gdx.input.setInputProcessor(mux);
|
||||
|
||||
createLayers();
|
||||
}
|
||||
|
||||
protected void createLayers() {
|
||||
mMap.layers().add(new TileGridLayer(mMap));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
|
||||
}
|
||||
|
||||
/* private */boolean mRenderWait;
|
||||
/* private */boolean mRenderRequest;
|
||||
/* private */boolean mUpdateRequest;
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
if (!mRenderRequest)
|
||||
return;
|
||||
|
||||
mMapRenderer.onDrawFrame();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int w, int h) {
|
||||
mMap.viewport().setScreenSize(w, h);
|
||||
mMapRenderer.onSurfaceChanged(w, h);
|
||||
mMap.render();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pause() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resume() {
|
||||
}
|
||||
|
||||
protected boolean onKeyDown(int keycode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public Map getMap() {
|
||||
return mMap;
|
||||
}
|
||||
|
||||
class MapAdapter extends Map {
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return Gdx.graphics.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return Gdx.graphics.getHeight();
|
||||
}
|
||||
|
||||
private final Runnable mRedrawCb = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
prepareFrame();
|
||||
Gdx.graphics.requestRendering();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void updateMap(boolean forceRender) {
|
||||
synchronized (mRedrawCb) {
|
||||
if (!mRenderRequest) {
|
||||
mRenderRequest = true;
|
||||
Gdx.app.postRunnable(mRedrawCb);
|
||||
} else {
|
||||
mRenderWait = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render() {
|
||||
synchronized (mRedrawCb) {
|
||||
mRenderRequest = true;
|
||||
if (mClearMap)
|
||||
updateMap(false);
|
||||
else {
|
||||
Gdx.graphics.requestRendering();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean post(Runnable runnable) {
|
||||
Gdx.app.postRunnable(runnable);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean postDelayed(final Runnable action, long delay) {
|
||||
Timer.schedule(new Task() {
|
||||
@Override
|
||||
public void run() {
|
||||
action.run();
|
||||
}
|
||||
}, delay / 1000f);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beginFrame() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doneFrame(boolean animate) {
|
||||
synchronized (mRedrawCb) {
|
||||
mRenderRequest = false;
|
||||
if (animate || mRenderWait) {
|
||||
mRenderWait = false;
|
||||
updateMap(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,37 +1,37 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 Longri
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.ios;
|
||||
|
||||
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.gdx.GdxAssets;
|
||||
import org.oscim.gdx.GdxMap;
|
||||
import org.oscim.ios.backend.IosGL;
|
||||
import org.oscim.ios.backend.IosGraphics;
|
||||
|
||||
|
||||
public class IOSMapApp extends GdxMap {
|
||||
|
||||
public static void init() {
|
||||
|
||||
// init globals
|
||||
IosGraphics.init();
|
||||
GdxAssets.init("assets/");
|
||||
GLAdapter.init(new IosGL());
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 Longri
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.ios;
|
||||
|
||||
|
||||
import org.oscim.backend.GLAdapter;
|
||||
import org.oscim.gdx.GdxAssets;
|
||||
import org.oscim.gdx.GdxMap;
|
||||
import org.oscim.ios.backend.IosGL;
|
||||
import org.oscim.ios.backend.IosGraphics;
|
||||
|
||||
|
||||
public class IOSMapApp extends GdxMap {
|
||||
|
||||
public static void init() {
|
||||
|
||||
// init globals
|
||||
IosGraphics.init();
|
||||
GdxAssets.init("assets/");
|
||||
GLAdapter.init(new IosGL());
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,177 +1,177 @@
|
||||
{
|
||||
"version": [ 0, 1],
|
||||
"id": "",
|
||||
"meshes": [
|
||||
{
|
||||
"attributes": ["POSITION", "NORMAL", "TEXCOORD0"],
|
||||
"vertices": [
|
||||
-0.003717, -0.043092, 0.000001, 0.000000, -1.000000, 0.000000, 0.000000, 0.000000,
|
||||
-0.003717, -0.043092, -0.019798, 0.000000, -0.609973, -0.792383, 0.000000, 0.000000,
|
||||
0.013430, -0.043092, -0.009898, 0.686239, -0.609973, -0.396191, 0.000000, 0.000000,
|
||||
-0.003717, 0.527242, 0.000001, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000,
|
||||
0.013430, 0.527242, -0.009898, 0.686239, 0.609973, -0.396191, 0.000000, 0.000000,
|
||||
-0.003717, 0.527242, -0.019798, 0.000000, 0.609973, -0.792383, 0.000000, 0.000000,
|
||||
0.013430, -0.043092, 0.009901, 0.686239, -0.609973, 0.396191, 0.000000, 0.000000,
|
||||
0.013430, 0.527242, 0.009901, 0.686239, 0.609973, 0.396191, 0.000000, 0.000000,
|
||||
-0.003717, -0.043092, 0.019801, 0.000000, -0.609973, 0.792383, 0.000000, 0.000000,
|
||||
-0.003717, 0.527242, 0.019801, 0.000000, 0.609973, 0.792383, 0.000000, 0.000000,
|
||||
-0.020865, -0.043092, 0.009901, -0.686239, -0.609973, 0.396191, 0.000000, 0.000000,
|
||||
-0.020865, 0.527242, 0.009901, -0.686239, 0.609973, 0.396191, 0.000000, 0.000000,
|
||||
-0.020865, -0.043092, -0.009898, -0.686239, -0.609973, -0.396191, 0.000000, 0.000000,
|
||||
-0.020865, 0.527242, -0.009898, -0.686239, 0.609973, -0.396191, 0.000000, 0.000000,
|
||||
-0.000052, 1.708732, 0.000001, 0.000000, 1.000000, 0.000000, 0.627643, 0.963260,
|
||||
-0.056858, 1.692897, -0.056805, -0.359325, 0.861232, -0.359325, 0.811107, 0.943917,
|
||||
-0.080388, 1.692897, 0.000001, -0.508194, 0.861232, 0.000000, 0.930977, 0.971962,
|
||||
-0.112293, 1.619116, -0.112239, -0.584552, 0.562639, -0.584552, 0.871491, 0.884983,
|
||||
-0.158784, 1.619116, 0.000001, -0.826655, 0.562639, 0.000000, 1.012361, 0.910828,
|
||||
-0.176420, 1.422079, -0.176367, -0.675863, 0.293832, -0.675863, 0.903795, 0.728324,
|
||||
-0.249474, 1.422079, 0.000001, -0.955840, 0.293832, 0.000000, 1.035246, 0.751852,
|
||||
-0.210746, 1.159339, -0.210693, -0.704306, 0.088870, -0.704306, 0.922129, 0.451029,
|
||||
-0.298019, 1.159339, 0.000001, -0.996033, 0.088870, 0.000000, 1.045340, 0.473093,
|
||||
-0.210605, 0.903175, -0.210552, -0.705252, -0.072024, -0.705252, 0.936767, 0.254108,
|
||||
-0.297820, 0.903175, 0.000001, -0.997375, -0.072024, 0.000000, 1.052424, 0.274946,
|
||||
-0.180964, 0.617981, -0.180911, -0.685263, -0.246529, -0.685263, 0.956801, 0.142573,
|
||||
-0.255900, 0.617981, 0.000001, -0.969115, -0.246529, 0.000000, 1.061122, 0.161660,
|
||||
-0.116291, 0.378825, -0.116238, -0.610279, -0.505051, -0.610279, 0.991689, 0.079506,
|
||||
-0.164439, 0.378825, 0.000001, -0.863063, -0.505051, 0.000000, 1.074527, 0.095355,
|
||||
-0.059153, 0.290116, -0.059100, -0.407514, -0.817194, -0.407544, 1.038003, 0.052079,
|
||||
-0.083634, 0.290116, 0.000001, -0.576312, -0.817194, 0.000000, 1.090933, 0.063214,
|
||||
-0.083634, 0.290116, 0.000001, -0.576312, -0.817194, 0.000000, 0.090933, 0.063214,
|
||||
-0.059153, 0.290116, -0.059100, -0.407514, -0.817194, -0.407544, 0.038003, 0.052079,
|
||||
-0.000125, 0.265210, -0.000071, -0.000244, -0.999969, -0.000244, 0.127500, 0.036749,
|
||||
-0.000051, 0.290116, -0.083580, 0.000000, -0.817194, -0.576312, 0.994047, 0.033372,
|
||||
-0.000125, 0.265210, -0.000071, -0.000244, -0.999969, -0.000244, 1.127500, 0.036749,
|
||||
-0.000051, 0.378825, -0.164386, 0.000000, -0.505051, -0.863063, 0.893772, 0.053663,
|
||||
-0.000052, 0.617981, -0.255847, 0.000000, -0.246529, -0.969115, 0.836458, 0.114704,
|
||||
-0.000052, 0.903175, -0.297766, 0.000000, -0.072024, -0.997375, 0.812221, 0.226047,
|
||||
-0.000052, 1.159339, -0.297966, 0.000000, 0.088870, -0.996033, 0.797565, 0.423137,
|
||||
-0.000052, 1.422079, -0.249421, 0.000000, 0.293832, -0.955840, 0.781975, 0.700922,
|
||||
-0.000052, 1.619116, -0.158731, 0.000000, 0.562639, -0.826655, 0.759783, 0.858997,
|
||||
-0.000052, 1.692897, -0.080335, 0.000000, 0.861232, -0.508194, 0.728165, 0.921879,
|
||||
0.056754, 1.692897, -0.056805, 0.359325, 0.861232, -0.359325, 0.652361, 0.910987,
|
||||
0.112189, 1.619116, -0.112239, 0.584552, 0.562639, -0.584552, 0.659906, 0.845090,
|
||||
0.176316, 1.422079, -0.176367, 0.675863, 0.293832, -0.675863, 0.665734, 0.684958,
|
||||
0.210643, 1.159339, -0.210693, 0.704306, 0.088870, -0.704306, 0.670277, 0.405750,
|
||||
0.210502, 0.903175, -0.210552, 0.705252, -0.072024, -0.705252, 0.675032, 0.207335,
|
||||
0.180860, 0.617981, -0.180910, 0.685263, -0.246529, -0.685263, 0.684415, 0.093825,
|
||||
0.116188, 0.378825, -0.116237, 0.610279, -0.505051, -0.610279, 0.723612, 0.027920,
|
||||
0.059050, 0.290116, -0.059099, 0.407483, -0.817255, -0.407422, 1.018456, 0.011649,
|
||||
0.059050, 0.290116, -0.059099, 0.407483, -0.817255, -0.407422, 0.018456, 0.011649,
|
||||
0.083530, 0.290116, 0.000002, 0.576159, -0.817316, 0.000000, 0.267608, 0.018648,
|
||||
0.164335, 0.378825, 0.000002, 0.863063, -0.505051, 0.000000, 0.457225, 0.035136,
|
||||
0.255796, 0.617981, 0.000002, 0.969115, -0.246529, 0.000000, 0.515690, 0.098717,
|
||||
0.297716, 0.903175, 0.000002, 0.997375, -0.072024, 0.000000, 0.532803, 0.211513,
|
||||
0.297915, 1.159339, 0.000002, 0.996033, 0.088870, 0.000000, 0.541872, 0.409545,
|
||||
0.249370, 1.422079, 0.000002, 0.955840, 0.293832, 0.000000, 0.550746, 0.688375,
|
||||
0.158680, 1.619116, 0.000002, 0.826655, 0.562639, 0.000000, 0.562378, 0.848006,
|
||||
0.080284, 1.692897, 0.000001, 0.508194, 0.861232, 0.000000, 0.577714, 0.913236,
|
||||
0.056754, 1.692897, 0.056808, 0.359325, 0.861232, 0.359325, 0.500528, 0.928224,
|
||||
0.112188, 1.619116, 0.112242, 0.584552, 0.562670, 0.584552, 0.459880, 0.866817,
|
||||
0.176316, 1.422079, 0.176370, 0.675863, 0.293832, 0.675863, 0.433163, 0.709519,
|
||||
0.210642, 1.159339, 0.210696, 0.704306, 0.088870, 0.704306, 0.415507, 0.432148,
|
||||
0.210501, 0.903175, 0.210555, 0.705252, -0.072024, 0.705252, 0.399773, 0.235351,
|
||||
0.180860, 0.617981, 0.180914, 0.685263, -0.246529, 0.685263, 0.375517, 0.124299,
|
||||
0.116187, 0.378825, 0.116241, 0.610279, -0.505051, 0.610279, 0.325269, 0.063109,
|
||||
0.059049, 0.290116, 0.059103, 0.407361, -0.817347, 0.407392, 0.248452, 0.040330,
|
||||
-0.000053, 0.290116, 0.083583, 0.000000, -0.817316, 0.576159, 0.199939, 0.056802,
|
||||
-0.000053, 0.378825, 0.164389, 0.000000, -0.505051, 0.863063, 0.234895, 0.086200,
|
||||
-0.000053, 0.617981, 0.255850, 0.000000, -0.246529, 0.969115, 0.262269, 0.150492,
|
||||
-0.000052, 0.903175, 0.297769, 0.000000, -0.072024, 0.997375, 0.278892, 0.262611,
|
||||
-0.000052, 1.159339, 0.297968, 0.000000, 0.088870, 0.996033, 0.291619, 0.459894,
|
||||
-0.000052, 1.422079, 0.249424, 0.000000, 0.293832, 0.955840, 0.308400, 0.737559,
|
||||
-0.000052, 1.619116, 0.158734, 0.000000, 0.562670, 0.826655, 0.340691, 0.894603,
|
||||
-0.000052, 1.692897, 0.080338, 0.000000, 0.861232, 0.508194, 0.411564, 0.953109,
|
||||
-0.056858, 1.692897, 0.056808, -0.359325, 0.861232, 0.359325, 0.247502, 0.980115,
|
||||
-0.112293, 1.619116, 0.112242, -0.584552, 0.562670, 0.584552, 0.186319, 0.915857,
|
||||
-0.176420, 1.422079, 0.176369, -0.675863, 0.293832, 0.675863, 0.173739, 0.755927,
|
||||
-0.210747, 1.159339, 0.210696, -0.704306, 0.088870, 0.704306, 0.168491, 0.476740,
|
||||
-0.210606, 0.903175, 0.210555, -0.705252, -0.072024, 0.705252, 0.164886, 0.278291,
|
||||
-0.180964, 0.617981, 0.180913, -0.685263, -0.246529, 0.685263, 0.160531, 0.164632,
|
||||
-0.116292, 0.378825, 0.116240, -0.610279, -0.505051, 0.610279, 0.153922, 0.097744,
|
||||
-0.059154, 0.290116, 0.059102, -0.407453, -0.817255, 0.407483, 0.145909, 0.064880,
|
||||
-0.164439, 0.378825, 0.000001, -0.863063, -0.505051, 0.000000, 0.074527, 0.095355,
|
||||
-0.255900, 0.617981, 0.000001, -0.969115, -0.246529, 0.000000, 0.061122, 0.161660,
|
||||
-0.297820, 0.903175, 0.000001, -0.997375, -0.072024, 0.000000, 0.052424, 0.274946,
|
||||
-0.298019, 1.159339, 0.000001, -0.996033, 0.088870, 0.000000, 0.045340, 0.473093,
|
||||
-0.249474, 1.422079, 0.000001, -0.955840, 0.293832, 0.000000, 0.035246, 0.751852,
|
||||
-0.158784, 1.619116, 0.000001, -0.826655, 0.562639, 0.000000, 0.012361, 0.910828,
|
||||
-0.056858, 1.692897, 0.056808, -0.359325, 0.861232, 0.359325, 1.247502, 0.980115,
|
||||
-0.112293, 1.619116, 0.112242, -0.584552, 0.562670, 0.584552, 1.186319, 0.915857
|
||||
],
|
||||
"parts": [
|
||||
{
|
||||
"id": "mpart1",
|
||||
"type": "TRIANGLES",
|
||||
"indices": [
|
||||
0, 1, 2, 3, 4, 5, 0, 2, 6, 3, 7, 4,
|
||||
0, 6, 8, 3, 9, 7, 0, 8, 10, 3, 11, 9,
|
||||
0, 10, 12, 3, 13, 11, 12, 1, 0, 3, 5, 13,
|
||||
1, 5, 4, 1, 4, 2, 2, 4, 7, 2, 7, 6,
|
||||
6, 7, 9, 6, 9, 8, 8, 9, 11, 8, 11, 10,
|
||||
10, 11, 13, 10, 13, 12, 5, 1, 12, 5, 12, 13,
|
||||
14, 15, 16, 16, 15, 17, 16, 17, 18, 18, 17, 19,
|
||||
18, 19, 20, 20, 19, 21, 20, 21, 22, 22, 21, 23,
|
||||
22, 23, 24, 24, 23, 25, 24, 25, 26, 26, 25, 27,
|
||||
26, 27, 28, 28, 27, 29, 28, 29, 30, 31, 32, 33,
|
||||
29, 34, 35, 27, 36, 34, 27, 34, 29, 25, 37, 36,
|
||||
25, 36, 27, 23, 38, 37, 23, 37, 25, 21, 39, 38,
|
||||
21, 38, 23, 19, 40, 39, 19, 39, 21, 17, 41, 40,
|
||||
17, 40, 19, 15, 42, 41, 15, 41, 17, 15, 14, 42,
|
||||
42, 14, 43, 42, 43, 44, 42, 44, 41, 41, 44, 45,
|
||||
41, 45, 40, 40, 45, 46, 40, 46, 39, 39, 46, 47,
|
||||
39, 47, 38, 38, 47, 48, 38, 48, 37, 37, 48, 49,
|
||||
37, 49, 36, 36, 49, 50, 36, 50, 34, 34, 50, 35,
|
||||
51, 52, 33, 49, 53, 52, 49, 52, 50, 48, 54, 53,
|
||||
48, 53, 49, 47, 55, 54, 47, 54, 48, 46, 56, 55,
|
||||
46, 55, 47, 45, 57, 56, 45, 56, 46, 44, 58, 57,
|
||||
44, 57, 45, 43, 59, 58, 43, 58, 44, 43, 14, 59,
|
||||
59, 14, 60, 59, 60, 61, 59, 61, 58, 58, 61, 62,
|
||||
58, 62, 57, 57, 62, 63, 57, 63, 56, 56, 63, 64,
|
||||
56, 64, 55, 55, 64, 65, 55, 65, 54, 54, 65, 66,
|
||||
54, 66, 53, 53, 66, 67, 53, 67, 52, 52, 67, 33,
|
||||
67, 68, 33, 66, 69, 68, 66, 68, 67, 65, 70, 69,
|
||||
65, 69, 66, 64, 71, 70, 64, 70, 65, 63, 72, 71,
|
||||
63, 71, 64, 62, 73, 72, 62, 72, 63, 61, 74, 73,
|
||||
61, 73, 62, 60, 75, 74, 60, 74, 61, 60, 14, 75,
|
||||
75, 14, 76, 75, 76, 77, 75, 77, 74, 74, 77, 78,
|
||||
74, 78, 73, 73, 78, 79, 73, 79, 72, 72, 79, 80,
|
||||
72, 80, 71, 71, 80, 81, 71, 81, 70, 70, 81, 82,
|
||||
70, 82, 69, 69, 82, 83, 69, 83, 68, 68, 83, 33,
|
||||
83, 31, 33, 82, 84, 31, 82, 31, 83, 81, 85, 84,
|
||||
81, 84, 82, 80, 86, 85, 80, 85, 81, 79, 87, 86,
|
||||
79, 86, 80, 78, 88, 87, 78, 87, 79, 77, 89, 88,
|
||||
77, 88, 78, 90, 16, 18, 90, 18, 91, 90, 14, 16
|
||||
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"materials": [
|
||||
{
|
||||
"id": "_tree.png",
|
||||
"diffuse": [ 0.900000, 0.900000, 0.900000],
|
||||
"specular": [ 0.100000, 0.100000, 0.100000],
|
||||
"textures": [
|
||||
{
|
||||
"id": "_tree.png",
|
||||
"filename": "tree.png",
|
||||
"type": "DIFFUSE"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"nodes": [
|
||||
{
|
||||
"id": "treeA_root",
|
||||
"parts": [
|
||||
{
|
||||
"meshpartid": "mpart1",
|
||||
"materialid": "_tree.png",
|
||||
"uvMapping": [[ 0]]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"animations": []
|
||||
{
|
||||
"version": [ 0, 1],
|
||||
"id": "",
|
||||
"meshes": [
|
||||
{
|
||||
"attributes": ["POSITION", "NORMAL", "TEXCOORD0"],
|
||||
"vertices": [
|
||||
-0.003717, -0.043092, 0.000001, 0.000000, -1.000000, 0.000000, 0.000000, 0.000000,
|
||||
-0.003717, -0.043092, -0.019798, 0.000000, -0.609973, -0.792383, 0.000000, 0.000000,
|
||||
0.013430, -0.043092, -0.009898, 0.686239, -0.609973, -0.396191, 0.000000, 0.000000,
|
||||
-0.003717, 0.527242, 0.000001, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000,
|
||||
0.013430, 0.527242, -0.009898, 0.686239, 0.609973, -0.396191, 0.000000, 0.000000,
|
||||
-0.003717, 0.527242, -0.019798, 0.000000, 0.609973, -0.792383, 0.000000, 0.000000,
|
||||
0.013430, -0.043092, 0.009901, 0.686239, -0.609973, 0.396191, 0.000000, 0.000000,
|
||||
0.013430, 0.527242, 0.009901, 0.686239, 0.609973, 0.396191, 0.000000, 0.000000,
|
||||
-0.003717, -0.043092, 0.019801, 0.000000, -0.609973, 0.792383, 0.000000, 0.000000,
|
||||
-0.003717, 0.527242, 0.019801, 0.000000, 0.609973, 0.792383, 0.000000, 0.000000,
|
||||
-0.020865, -0.043092, 0.009901, -0.686239, -0.609973, 0.396191, 0.000000, 0.000000,
|
||||
-0.020865, 0.527242, 0.009901, -0.686239, 0.609973, 0.396191, 0.000000, 0.000000,
|
||||
-0.020865, -0.043092, -0.009898, -0.686239, -0.609973, -0.396191, 0.000000, 0.000000,
|
||||
-0.020865, 0.527242, -0.009898, -0.686239, 0.609973, -0.396191, 0.000000, 0.000000,
|
||||
-0.000052, 1.708732, 0.000001, 0.000000, 1.000000, 0.000000, 0.627643, 0.963260,
|
||||
-0.056858, 1.692897, -0.056805, -0.359325, 0.861232, -0.359325, 0.811107, 0.943917,
|
||||
-0.080388, 1.692897, 0.000001, -0.508194, 0.861232, 0.000000, 0.930977, 0.971962,
|
||||
-0.112293, 1.619116, -0.112239, -0.584552, 0.562639, -0.584552, 0.871491, 0.884983,
|
||||
-0.158784, 1.619116, 0.000001, -0.826655, 0.562639, 0.000000, 1.012361, 0.910828,
|
||||
-0.176420, 1.422079, -0.176367, -0.675863, 0.293832, -0.675863, 0.903795, 0.728324,
|
||||
-0.249474, 1.422079, 0.000001, -0.955840, 0.293832, 0.000000, 1.035246, 0.751852,
|
||||
-0.210746, 1.159339, -0.210693, -0.704306, 0.088870, -0.704306, 0.922129, 0.451029,
|
||||
-0.298019, 1.159339, 0.000001, -0.996033, 0.088870, 0.000000, 1.045340, 0.473093,
|
||||
-0.210605, 0.903175, -0.210552, -0.705252, -0.072024, -0.705252, 0.936767, 0.254108,
|
||||
-0.297820, 0.903175, 0.000001, -0.997375, -0.072024, 0.000000, 1.052424, 0.274946,
|
||||
-0.180964, 0.617981, -0.180911, -0.685263, -0.246529, -0.685263, 0.956801, 0.142573,
|
||||
-0.255900, 0.617981, 0.000001, -0.969115, -0.246529, 0.000000, 1.061122, 0.161660,
|
||||
-0.116291, 0.378825, -0.116238, -0.610279, -0.505051, -0.610279, 0.991689, 0.079506,
|
||||
-0.164439, 0.378825, 0.000001, -0.863063, -0.505051, 0.000000, 1.074527, 0.095355,
|
||||
-0.059153, 0.290116, -0.059100, -0.407514, -0.817194, -0.407544, 1.038003, 0.052079,
|
||||
-0.083634, 0.290116, 0.000001, -0.576312, -0.817194, 0.000000, 1.090933, 0.063214,
|
||||
-0.083634, 0.290116, 0.000001, -0.576312, -0.817194, 0.000000, 0.090933, 0.063214,
|
||||
-0.059153, 0.290116, -0.059100, -0.407514, -0.817194, -0.407544, 0.038003, 0.052079,
|
||||
-0.000125, 0.265210, -0.000071, -0.000244, -0.999969, -0.000244, 0.127500, 0.036749,
|
||||
-0.000051, 0.290116, -0.083580, 0.000000, -0.817194, -0.576312, 0.994047, 0.033372,
|
||||
-0.000125, 0.265210, -0.000071, -0.000244, -0.999969, -0.000244, 1.127500, 0.036749,
|
||||
-0.000051, 0.378825, -0.164386, 0.000000, -0.505051, -0.863063, 0.893772, 0.053663,
|
||||
-0.000052, 0.617981, -0.255847, 0.000000, -0.246529, -0.969115, 0.836458, 0.114704,
|
||||
-0.000052, 0.903175, -0.297766, 0.000000, -0.072024, -0.997375, 0.812221, 0.226047,
|
||||
-0.000052, 1.159339, -0.297966, 0.000000, 0.088870, -0.996033, 0.797565, 0.423137,
|
||||
-0.000052, 1.422079, -0.249421, 0.000000, 0.293832, -0.955840, 0.781975, 0.700922,
|
||||
-0.000052, 1.619116, -0.158731, 0.000000, 0.562639, -0.826655, 0.759783, 0.858997,
|
||||
-0.000052, 1.692897, -0.080335, 0.000000, 0.861232, -0.508194, 0.728165, 0.921879,
|
||||
0.056754, 1.692897, -0.056805, 0.359325, 0.861232, -0.359325, 0.652361, 0.910987,
|
||||
0.112189, 1.619116, -0.112239, 0.584552, 0.562639, -0.584552, 0.659906, 0.845090,
|
||||
0.176316, 1.422079, -0.176367, 0.675863, 0.293832, -0.675863, 0.665734, 0.684958,
|
||||
0.210643, 1.159339, -0.210693, 0.704306, 0.088870, -0.704306, 0.670277, 0.405750,
|
||||
0.210502, 0.903175, -0.210552, 0.705252, -0.072024, -0.705252, 0.675032, 0.207335,
|
||||
0.180860, 0.617981, -0.180910, 0.685263, -0.246529, -0.685263, 0.684415, 0.093825,
|
||||
0.116188, 0.378825, -0.116237, 0.610279, -0.505051, -0.610279, 0.723612, 0.027920,
|
||||
0.059050, 0.290116, -0.059099, 0.407483, -0.817255, -0.407422, 1.018456, 0.011649,
|
||||
0.059050, 0.290116, -0.059099, 0.407483, -0.817255, -0.407422, 0.018456, 0.011649,
|
||||
0.083530, 0.290116, 0.000002, 0.576159, -0.817316, 0.000000, 0.267608, 0.018648,
|
||||
0.164335, 0.378825, 0.000002, 0.863063, -0.505051, 0.000000, 0.457225, 0.035136,
|
||||
0.255796, 0.617981, 0.000002, 0.969115, -0.246529, 0.000000, 0.515690, 0.098717,
|
||||
0.297716, 0.903175, 0.000002, 0.997375, -0.072024, 0.000000, 0.532803, 0.211513,
|
||||
0.297915, 1.159339, 0.000002, 0.996033, 0.088870, 0.000000, 0.541872, 0.409545,
|
||||
0.249370, 1.422079, 0.000002, 0.955840, 0.293832, 0.000000, 0.550746, 0.688375,
|
||||
0.158680, 1.619116, 0.000002, 0.826655, 0.562639, 0.000000, 0.562378, 0.848006,
|
||||
0.080284, 1.692897, 0.000001, 0.508194, 0.861232, 0.000000, 0.577714, 0.913236,
|
||||
0.056754, 1.692897, 0.056808, 0.359325, 0.861232, 0.359325, 0.500528, 0.928224,
|
||||
0.112188, 1.619116, 0.112242, 0.584552, 0.562670, 0.584552, 0.459880, 0.866817,
|
||||
0.176316, 1.422079, 0.176370, 0.675863, 0.293832, 0.675863, 0.433163, 0.709519,
|
||||
0.210642, 1.159339, 0.210696, 0.704306, 0.088870, 0.704306, 0.415507, 0.432148,
|
||||
0.210501, 0.903175, 0.210555, 0.705252, -0.072024, 0.705252, 0.399773, 0.235351,
|
||||
0.180860, 0.617981, 0.180914, 0.685263, -0.246529, 0.685263, 0.375517, 0.124299,
|
||||
0.116187, 0.378825, 0.116241, 0.610279, -0.505051, 0.610279, 0.325269, 0.063109,
|
||||
0.059049, 0.290116, 0.059103, 0.407361, -0.817347, 0.407392, 0.248452, 0.040330,
|
||||
-0.000053, 0.290116, 0.083583, 0.000000, -0.817316, 0.576159, 0.199939, 0.056802,
|
||||
-0.000053, 0.378825, 0.164389, 0.000000, -0.505051, 0.863063, 0.234895, 0.086200,
|
||||
-0.000053, 0.617981, 0.255850, 0.000000, -0.246529, 0.969115, 0.262269, 0.150492,
|
||||
-0.000052, 0.903175, 0.297769, 0.000000, -0.072024, 0.997375, 0.278892, 0.262611,
|
||||
-0.000052, 1.159339, 0.297968, 0.000000, 0.088870, 0.996033, 0.291619, 0.459894,
|
||||
-0.000052, 1.422079, 0.249424, 0.000000, 0.293832, 0.955840, 0.308400, 0.737559,
|
||||
-0.000052, 1.619116, 0.158734, 0.000000, 0.562670, 0.826655, 0.340691, 0.894603,
|
||||
-0.000052, 1.692897, 0.080338, 0.000000, 0.861232, 0.508194, 0.411564, 0.953109,
|
||||
-0.056858, 1.692897, 0.056808, -0.359325, 0.861232, 0.359325, 0.247502, 0.980115,
|
||||
-0.112293, 1.619116, 0.112242, -0.584552, 0.562670, 0.584552, 0.186319, 0.915857,
|
||||
-0.176420, 1.422079, 0.176369, -0.675863, 0.293832, 0.675863, 0.173739, 0.755927,
|
||||
-0.210747, 1.159339, 0.210696, -0.704306, 0.088870, 0.704306, 0.168491, 0.476740,
|
||||
-0.210606, 0.903175, 0.210555, -0.705252, -0.072024, 0.705252, 0.164886, 0.278291,
|
||||
-0.180964, 0.617981, 0.180913, -0.685263, -0.246529, 0.685263, 0.160531, 0.164632,
|
||||
-0.116292, 0.378825, 0.116240, -0.610279, -0.505051, 0.610279, 0.153922, 0.097744,
|
||||
-0.059154, 0.290116, 0.059102, -0.407453, -0.817255, 0.407483, 0.145909, 0.064880,
|
||||
-0.164439, 0.378825, 0.000001, -0.863063, -0.505051, 0.000000, 0.074527, 0.095355,
|
||||
-0.255900, 0.617981, 0.000001, -0.969115, -0.246529, 0.000000, 0.061122, 0.161660,
|
||||
-0.297820, 0.903175, 0.000001, -0.997375, -0.072024, 0.000000, 0.052424, 0.274946,
|
||||
-0.298019, 1.159339, 0.000001, -0.996033, 0.088870, 0.000000, 0.045340, 0.473093,
|
||||
-0.249474, 1.422079, 0.000001, -0.955840, 0.293832, 0.000000, 0.035246, 0.751852,
|
||||
-0.158784, 1.619116, 0.000001, -0.826655, 0.562639, 0.000000, 0.012361, 0.910828,
|
||||
-0.056858, 1.692897, 0.056808, -0.359325, 0.861232, 0.359325, 1.247502, 0.980115,
|
||||
-0.112293, 1.619116, 0.112242, -0.584552, 0.562670, 0.584552, 1.186319, 0.915857
|
||||
],
|
||||
"parts": [
|
||||
{
|
||||
"id": "mpart1",
|
||||
"type": "TRIANGLES",
|
||||
"indices": [
|
||||
0, 1, 2, 3, 4, 5, 0, 2, 6, 3, 7, 4,
|
||||
0, 6, 8, 3, 9, 7, 0, 8, 10, 3, 11, 9,
|
||||
0, 10, 12, 3, 13, 11, 12, 1, 0, 3, 5, 13,
|
||||
1, 5, 4, 1, 4, 2, 2, 4, 7, 2, 7, 6,
|
||||
6, 7, 9, 6, 9, 8, 8, 9, 11, 8, 11, 10,
|
||||
10, 11, 13, 10, 13, 12, 5, 1, 12, 5, 12, 13,
|
||||
14, 15, 16, 16, 15, 17, 16, 17, 18, 18, 17, 19,
|
||||
18, 19, 20, 20, 19, 21, 20, 21, 22, 22, 21, 23,
|
||||
22, 23, 24, 24, 23, 25, 24, 25, 26, 26, 25, 27,
|
||||
26, 27, 28, 28, 27, 29, 28, 29, 30, 31, 32, 33,
|
||||
29, 34, 35, 27, 36, 34, 27, 34, 29, 25, 37, 36,
|
||||
25, 36, 27, 23, 38, 37, 23, 37, 25, 21, 39, 38,
|
||||
21, 38, 23, 19, 40, 39, 19, 39, 21, 17, 41, 40,
|
||||
17, 40, 19, 15, 42, 41, 15, 41, 17, 15, 14, 42,
|
||||
42, 14, 43, 42, 43, 44, 42, 44, 41, 41, 44, 45,
|
||||
41, 45, 40, 40, 45, 46, 40, 46, 39, 39, 46, 47,
|
||||
39, 47, 38, 38, 47, 48, 38, 48, 37, 37, 48, 49,
|
||||
37, 49, 36, 36, 49, 50, 36, 50, 34, 34, 50, 35,
|
||||
51, 52, 33, 49, 53, 52, 49, 52, 50, 48, 54, 53,
|
||||
48, 53, 49, 47, 55, 54, 47, 54, 48, 46, 56, 55,
|
||||
46, 55, 47, 45, 57, 56, 45, 56, 46, 44, 58, 57,
|
||||
44, 57, 45, 43, 59, 58, 43, 58, 44, 43, 14, 59,
|
||||
59, 14, 60, 59, 60, 61, 59, 61, 58, 58, 61, 62,
|
||||
58, 62, 57, 57, 62, 63, 57, 63, 56, 56, 63, 64,
|
||||
56, 64, 55, 55, 64, 65, 55, 65, 54, 54, 65, 66,
|
||||
54, 66, 53, 53, 66, 67, 53, 67, 52, 52, 67, 33,
|
||||
67, 68, 33, 66, 69, 68, 66, 68, 67, 65, 70, 69,
|
||||
65, 69, 66, 64, 71, 70, 64, 70, 65, 63, 72, 71,
|
||||
63, 71, 64, 62, 73, 72, 62, 72, 63, 61, 74, 73,
|
||||
61, 73, 62, 60, 75, 74, 60, 74, 61, 60, 14, 75,
|
||||
75, 14, 76, 75, 76, 77, 75, 77, 74, 74, 77, 78,
|
||||
74, 78, 73, 73, 78, 79, 73, 79, 72, 72, 79, 80,
|
||||
72, 80, 71, 71, 80, 81, 71, 81, 70, 70, 81, 82,
|
||||
70, 82, 69, 69, 82, 83, 69, 83, 68, 68, 83, 33,
|
||||
83, 31, 33, 82, 84, 31, 82, 31, 83, 81, 85, 84,
|
||||
81, 84, 82, 80, 86, 85, 80, 85, 81, 79, 87, 86,
|
||||
79, 86, 80, 78, 88, 87, 78, 87, 79, 77, 89, 88,
|
||||
77, 88, 78, 90, 16, 18, 90, 18, 91, 90, 14, 16
|
||||
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"materials": [
|
||||
{
|
||||
"id": "_tree.png",
|
||||
"diffuse": [ 0.900000, 0.900000, 0.900000],
|
||||
"specular": [ 0.100000, 0.100000, 0.100000],
|
||||
"textures": [
|
||||
{
|
||||
"id": "_tree.png",
|
||||
"filename": "tree.png",
|
||||
"type": "DIFFUSE"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"nodes": [
|
||||
{
|
||||
"id": "treeA_root",
|
||||
"parts": [
|
||||
{
|
||||
"meshpartid": "mpart1",
|
||||
"materialid": "_tree.png",
|
||||
"uvMapping": [[ 0]]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"animations": []
|
||||
}
|
@ -1,74 +1,74 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.web.client;
|
||||
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.gdx.client.MapConfig;
|
||||
|
||||
import com.badlogic.gdx.ApplicationListener;
|
||||
import com.badlogic.gdx.backends.gwt.GwtApplication;
|
||||
import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration;
|
||||
import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderCallback;
|
||||
import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderState;
|
||||
|
||||
public class GwtLauncher extends GwtApplication {
|
||||
|
||||
@Override
|
||||
public GwtApplicationConfiguration getConfig() {
|
||||
|
||||
GwtApplicationConfiguration cfg =
|
||||
new GwtApplicationConfiguration(getWindowWidth(),
|
||||
getWindowHeight());
|
||||
|
||||
cfg.canvasId = "map-canvas";
|
||||
cfg.stencil = true;
|
||||
cfg.fps = 120;
|
||||
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationListener getApplicationListener() {
|
||||
Tile.SIZE = MapConfig.get().getTileSize();
|
||||
|
||||
return new GwtMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreloaderCallback getPreloaderCallback() {
|
||||
return new PreloaderCallback() {
|
||||
|
||||
@Override
|
||||
public void update(PreloaderState state) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String file) {
|
||||
//log.debug("error loading " + file);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static native int getWindowWidth() /*-{
|
||||
return $wnd.innerWidth;
|
||||
}-*/;
|
||||
|
||||
private static native int getWindowHeight() /*-{
|
||||
return $wnd.innerHeight;
|
||||
}-*/;
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.web.client;
|
||||
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.gdx.client.MapConfig;
|
||||
|
||||
import com.badlogic.gdx.ApplicationListener;
|
||||
import com.badlogic.gdx.backends.gwt.GwtApplication;
|
||||
import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration;
|
||||
import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderCallback;
|
||||
import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderState;
|
||||
|
||||
public class GwtLauncher extends GwtApplication {
|
||||
|
||||
@Override
|
||||
public GwtApplicationConfiguration getConfig() {
|
||||
|
||||
GwtApplicationConfiguration cfg =
|
||||
new GwtApplicationConfiguration(getWindowWidth(),
|
||||
getWindowHeight());
|
||||
|
||||
cfg.canvasId = "map-canvas";
|
||||
cfg.stencil = true;
|
||||
cfg.fps = 120;
|
||||
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationListener getApplicationListener() {
|
||||
Tile.SIZE = MapConfig.get().getTileSize();
|
||||
|
||||
return new GwtMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreloaderCallback getPreloaderCallback() {
|
||||
return new PreloaderCallback() {
|
||||
|
||||
@Override
|
||||
public void update(PreloaderState state) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String file) {
|
||||
//log.debug("error loading " + file);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static native int getWindowWidth() /*-{
|
||||
return $wnd.innerWidth;
|
||||
}-*/;
|
||||
|
||||
private static native int getWindowHeight() /*-{
|
||||
return $wnd.innerHeight;
|
||||
}-*/;
|
||||
|
||||
}
|
||||
|
@ -1,75 +1,75 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>vtm-gdx</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
|
||||
<!-- pixel and dpi are way too simple concepts for web devs, lets have css-pixels!
|
||||
definition is limited only by your imagination! -->
|
||||
<!-- http://www.html5rocks.com/de/mobile/touch/ -->
|
||||
<!-- http://www.quirksmode.org/mobile/viewports.html -->
|
||||
<!-- http://www.quirksmode.org/blog/archives/2012/07/more_about_devi.html -->
|
||||
<!-- devicePixelRatio: http://coding.smashingmagazine.com/2012/08/20/towards-retina-web/ -->
|
||||
<meta name="viewport"
|
||||
content="width=device-width, initial-scale=1, user-scalable=no">
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="default.css">
|
||||
|
||||
<script type="text/javascript">
|
||||
var mapconfig = {
|
||||
tilesource : "oscimap4",
|
||||
tileurl : "http://opensciencemap.org/tiles/vtm",
|
||||
zoom : 2,
|
||||
latitude : 0.0,
|
||||
longitude : 0.0,
|
||||
tileSize : 400
|
||||
}
|
||||
//background : "naturalearth"
|
||||
</script>
|
||||
|
||||
</head>
|
||||
|
||||
<body oncontextmenu="return false;">
|
||||
<div id="credits">
|
||||
<a href="https://github.com/hjanetzek/vtm">Source</a> | map data © <a
|
||||
href="http://www.openstreemap.org">OpenStreetMap</a> contributors | <a
|
||||
href="http://www.opensciencemap.org">OpenScienceMap</a>
|
||||
</div>
|
||||
|
||||
<div id="canvas-area"
|
||||
style="position: fixed; left: 0px; top: 0px; width: 100%; height: 100%;">
|
||||
<canvas id="map-canvas"></canvas>
|
||||
</div>
|
||||
|
||||
<script type="text/Javascript">
|
||||
function canvasResize() {
|
||||
div = document.getElementById('canvas-area')
|
||||
canvas = document.getElementById('map-canvas')
|
||||
var w = div.scrollWidth;
|
||||
var h = div.scrollHeight;
|
||||
//console.log(div.clientHeight + " " + div.clientWidth)
|
||||
canvas.width = w;
|
||||
canvas.height = h;
|
||||
canvas.style.width = w + 'px';
|
||||
canvas.style.height = h + 'px';
|
||||
}
|
||||
canvasResize();
|
||||
window.addEventListener('resize', canvasResize, false);
|
||||
</script>
|
||||
<script type="text/javascript" src="VtmWebApp/js/_tessellate.js"></script>
|
||||
<script type="text/javascript" src="VtmWebApp/js/tessellate.js"></script>
|
||||
<script type="text/javascript" src="VtmWebApp/VtmWebApp.nocache.js"></script>
|
||||
|
||||
<div id="search">
|
||||
<table>
|
||||
<tr>
|
||||
<td id="nameFieldContainer">
|
||||
<td id="sendButtonContainer">
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" id="listContainer">
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>vtm-gdx</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
|
||||
<!-- pixel and dpi are way too simple concepts for web devs, lets have css-pixels!
|
||||
definition is limited only by your imagination! -->
|
||||
<!-- http://www.html5rocks.com/de/mobile/touch/ -->
|
||||
<!-- http://www.quirksmode.org/mobile/viewports.html -->
|
||||
<!-- http://www.quirksmode.org/blog/archives/2012/07/more_about_devi.html -->
|
||||
<!-- devicePixelRatio: http://coding.smashingmagazine.com/2012/08/20/towards-retina-web/ -->
|
||||
<meta name="viewport"
|
||||
content="width=device-width, initial-scale=1, user-scalable=no">
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="default.css">
|
||||
|
||||
<script type="text/javascript">
|
||||
var mapconfig = {
|
||||
tilesource : "oscimap4",
|
||||
tileurl : "http://opensciencemap.org/tiles/vtm",
|
||||
zoom : 2,
|
||||
latitude : 0.0,
|
||||
longitude : 0.0,
|
||||
tileSize : 400
|
||||
}
|
||||
//background : "naturalearth"
|
||||
</script>
|
||||
|
||||
</head>
|
||||
|
||||
<body oncontextmenu="return false;">
|
||||
<div id="credits">
|
||||
<a href="https://github.com/hjanetzek/vtm">Source</a> | map data © <a
|
||||
href="http://www.openstreemap.org">OpenStreetMap</a> contributors | <a
|
||||
href="http://www.opensciencemap.org">OpenScienceMap</a>
|
||||
</div>
|
||||
|
||||
<div id="canvas-area"
|
||||
style="position: fixed; left: 0px; top: 0px; width: 100%; height: 100%;">
|
||||
<canvas id="map-canvas"></canvas>
|
||||
</div>
|
||||
|
||||
<script type="text/Javascript">
|
||||
function canvasResize() {
|
||||
div = document.getElementById('canvas-area')
|
||||
canvas = document.getElementById('map-canvas')
|
||||
var w = div.scrollWidth;
|
||||
var h = div.scrollHeight;
|
||||
//console.log(div.clientHeight + " " + div.clientWidth)
|
||||
canvas.width = w;
|
||||
canvas.height = h;
|
||||
canvas.style.width = w + 'px';
|
||||
canvas.style.height = h + 'px';
|
||||
}
|
||||
canvasResize();
|
||||
window.addEventListener('resize', canvasResize, false);
|
||||
</script>
|
||||
<script type="text/javascript" src="VtmWebApp/js/_tessellate.js"></script>
|
||||
<script type="text/javascript" src="VtmWebApp/js/tessellate.js"></script>
|
||||
<script type="text/javascript" src="VtmWebApp/VtmWebApp.nocache.js"></script>
|
||||
|
||||
<div id="search">
|
||||
<table>
|
||||
<tr>
|
||||
<td id="nameFieldContainer">
|
||||
<td id="sendButtonContainer">
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" id="listContainer">
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,84 +1,84 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.web.client;
|
||||
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.gdx.client.MapConfig;
|
||||
import org.timepedia.exporter.client.ExporterUtil;
|
||||
|
||||
import com.badlogic.gdx.ApplicationListener;
|
||||
import com.badlogic.gdx.backends.gwt.GwtApplication;
|
||||
import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration;
|
||||
import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderCallback;
|
||||
import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderState;
|
||||
|
||||
public class GwtLauncher extends GwtApplication {
|
||||
|
||||
@Override
|
||||
public void onModuleLoad() {
|
||||
//GWT.create(GwtGdxMap.class);
|
||||
//JsOverlays.init();
|
||||
ExporterUtil.exportAll();
|
||||
|
||||
super.onModuleLoad();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GwtApplicationConfiguration getConfig() {
|
||||
|
||||
GwtApplicationConfiguration cfg =
|
||||
new GwtApplicationConfiguration(getWindowWidth(),
|
||||
getWindowHeight());
|
||||
|
||||
cfg.canvasId = "map-canvas";
|
||||
cfg.stencil = true;
|
||||
cfg.fps = 120;
|
||||
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationListener getApplicationListener() {
|
||||
Tile.SIZE = MapConfig.get().getTileSize();
|
||||
|
||||
return new GwtMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreloaderCallback getPreloaderCallback() {
|
||||
return new PreloaderCallback() {
|
||||
|
||||
@Override
|
||||
public void update(PreloaderState state) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String file) {
|
||||
//log.debug("error loading " + file);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static native int getWindowWidth() /*-{
|
||||
return $wnd.innerWidth;
|
||||
}-*/;
|
||||
|
||||
private static native int getWindowHeight() /*-{
|
||||
return $wnd.innerHeight;
|
||||
}-*/;
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.web.client;
|
||||
|
||||
import org.oscim.core.Tile;
|
||||
import org.oscim.gdx.client.MapConfig;
|
||||
import org.timepedia.exporter.client.ExporterUtil;
|
||||
|
||||
import com.badlogic.gdx.ApplicationListener;
|
||||
import com.badlogic.gdx.backends.gwt.GwtApplication;
|
||||
import com.badlogic.gdx.backends.gwt.GwtApplicationConfiguration;
|
||||
import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderCallback;
|
||||
import com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderState;
|
||||
|
||||
public class GwtLauncher extends GwtApplication {
|
||||
|
||||
@Override
|
||||
public void onModuleLoad() {
|
||||
//GWT.create(GwtGdxMap.class);
|
||||
//JsOverlays.init();
|
||||
ExporterUtil.exportAll();
|
||||
|
||||
super.onModuleLoad();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GwtApplicationConfiguration getConfig() {
|
||||
|
||||
GwtApplicationConfiguration cfg =
|
||||
new GwtApplicationConfiguration(getWindowWidth(),
|
||||
getWindowHeight());
|
||||
|
||||
cfg.canvasId = "map-canvas";
|
||||
cfg.stencil = true;
|
||||
cfg.fps = 120;
|
||||
|
||||
return cfg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationListener getApplicationListener() {
|
||||
Tile.SIZE = MapConfig.get().getTileSize();
|
||||
|
||||
return new GwtMap();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PreloaderCallback getPreloaderCallback() {
|
||||
return new PreloaderCallback() {
|
||||
|
||||
@Override
|
||||
public void update(PreloaderState state) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void error(String file) {
|
||||
//log.debug("error loading " + file);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private static native int getWindowWidth() /*-{
|
||||
return $wnd.innerWidth;
|
||||
}-*/;
|
||||
|
||||
private static native int getWindowHeight() /*-{
|
||||
return $wnd.innerHeight;
|
||||
}-*/;
|
||||
|
||||
}
|
||||
|
@ -1,33 +1,33 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>vtm-web-js</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
|
||||
<meta name="viewport"
|
||||
content="width=device-width, initial-scale=1, user-scalable=no">
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="default.css">
|
||||
</head>
|
||||
|
||||
<body oncontextmenu="return false;">
|
||||
<div id="canvas-area"
|
||||
style="position: fixed; left: 0px; top: 0px; width: 100%; height: 100%;">
|
||||
<canvas id="map-canvas">
|
||||
Your browser does not support the HTML5 canvas tag.
|
||||
</canvas>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="map.js"></script>
|
||||
|
||||
<script type="text/javascript" src="VtmWebApp/js/_tessellate.js"></script>
|
||||
<script type="text/javascript" src="VtmWebApp/js/tessellate.js"></script>
|
||||
<script type="text/javascript" src="VtmWebApp/VtmWebApp.nocache.js"></script>
|
||||
|
||||
<div id="credits">
|
||||
<a href="https://github.com/hjanetzek/vtm">Source</a> | map data © <a
|
||||
href="http://www.openstreemap.org">OpenStreetMap</a> contributors | <a
|
||||
href="http://www.opensciencemap.org">OpenScienceMap</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
<title>vtm-web-js</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
|
||||
<meta name="viewport"
|
||||
content="width=device-width, initial-scale=1, user-scalable=no">
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="default.css">
|
||||
</head>
|
||||
|
||||
<body oncontextmenu="return false;">
|
||||
<div id="canvas-area"
|
||||
style="position: fixed; left: 0px; top: 0px; width: 100%; height: 100%;">
|
||||
<canvas id="map-canvas">
|
||||
Your browser does not support the HTML5 canvas tag.
|
||||
</canvas>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript" src="map.js"></script>
|
||||
|
||||
<script type="text/javascript" src="VtmWebApp/js/_tessellate.js"></script>
|
||||
<script type="text/javascript" src="VtmWebApp/js/tessellate.js"></script>
|
||||
<script type="text/javascript" src="VtmWebApp/VtmWebApp.nocache.js"></script>
|
||||
|
||||
<div id="credits">
|
||||
<a href="https://github.com/hjanetzek/vtm">Source</a> | map data © <a
|
||||
href="http://www.openstreemap.org">OpenStreetMap</a> contributors | <a
|
||||
href="http://www.opensciencemap.org">OpenScienceMap</a>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,33 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.5.1//EN" "http://google-web-toolkit.googlecode.com/svn/tags/2.5.1/distro-source/core/src/gwt-module.dtd">
|
||||
<module rename-to='com.badlogic.gdx.backends.gwt'>
|
||||
<inherits name='com.google.gwt.user.User' />
|
||||
<!-- Inherit edited chrome theme ("gwt"-prefixed classes only) for a little bit of default styling in the text input dialogs -->
|
||||
<inherits name='com.badlogic.gdx.backends.gwt.theme.chrome.Chrome'/>
|
||||
<inherits name="com.google.gwt.http.HTTP"/>
|
||||
|
||||
<inherits name="com.badlogic.gdx" />
|
||||
<inherits name="com.google.gwt.webgl.WebGL" />
|
||||
<inherits name="com.badlogic.gwtref.GwtReflect"/>
|
||||
|
||||
<!-- <script src="soundmanager2-setup.js"/>
|
||||
<script src="soundmanager2-jsmin.js"/> -->
|
||||
|
||||
<!-- <public path="gwt/resources"/> -->
|
||||
<super-source path="gwt/emu" />
|
||||
<source path="gwt">
|
||||
<exclude name="**/emu/**" />
|
||||
<exclude name="**/theme/**" />
|
||||
<exclude name="**/PreloaderBundleGenerator.java"/>
|
||||
<exclude name="**/FileWrapper.java"/>
|
||||
<exclude name="**/emu/**" />
|
||||
</source>
|
||||
|
||||
<define-configuration-property name="gdx.assetpath" is-multi-valued="false"/>
|
||||
<define-configuration-property name="gdx.assetfilterclass" is-multi-valued="false"/>
|
||||
<define-configuration-property name="gdx.assetoutputpath" is-multi-valued="false"/>
|
||||
|
||||
<generate-with class="com.badlogic.gdx.backends.gwt.preloader.PreloaderBundleGenerator">
|
||||
<when-type-assignable class="com.badlogic.gdx.backends.gwt.preloader.PreloaderBundle"/>
|
||||
</generate-with>
|
||||
</module>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.5.1//EN" "http://google-web-toolkit.googlecode.com/svn/tags/2.5.1/distro-source/core/src/gwt-module.dtd">
|
||||
<module rename-to='com.badlogic.gdx.backends.gwt'>
|
||||
<inherits name='com.google.gwt.user.User' />
|
||||
<!-- Inherit edited chrome theme ("gwt"-prefixed classes only) for a little bit of default styling in the text input dialogs -->
|
||||
<inherits name='com.badlogic.gdx.backends.gwt.theme.chrome.Chrome'/>
|
||||
<inherits name="com.google.gwt.http.HTTP"/>
|
||||
|
||||
<inherits name="com.badlogic.gdx" />
|
||||
<inherits name="com.google.gwt.webgl.WebGL" />
|
||||
<inherits name="com.badlogic.gwtref.GwtReflect"/>
|
||||
|
||||
<!-- <script src="soundmanager2-setup.js"/>
|
||||
<script src="soundmanager2-jsmin.js"/> -->
|
||||
|
||||
<!-- <public path="gwt/resources"/> -->
|
||||
<super-source path="gwt/emu" />
|
||||
<source path="gwt">
|
||||
<exclude name="**/emu/**" />
|
||||
<exclude name="**/theme/**" />
|
||||
<exclude name="**/PreloaderBundleGenerator.java"/>
|
||||
<exclude name="**/FileWrapper.java"/>
|
||||
<exclude name="**/emu/**" />
|
||||
</source>
|
||||
|
||||
<define-configuration-property name="gdx.assetpath" is-multi-valued="false"/>
|
||||
<define-configuration-property name="gdx.assetfilterclass" is-multi-valued="false"/>
|
||||
<define-configuration-property name="gdx.assetoutputpath" is-multi-valued="false"/>
|
||||
|
||||
<generate-with class="com.badlogic.gdx.backends.gwt.preloader.PreloaderBundleGenerator">
|
||||
<when-type-assignable class="com.badlogic.gdx.backends.gwt.preloader.PreloaderBundle"/>
|
||||
</generate-with>
|
||||
</module>
|
||||
|
@ -1,342 +1,342 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011 See libgdx AUTHORS file.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
******************************************************************************/
|
||||
|
||||
package com.badlogic.gdx.backends.gwt;
|
||||
|
||||
import org.oscim.gdx.client.GdxGL;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Graphics;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.GL30;
|
||||
import com.badlogic.gdx.utils.GdxRuntimeException;
|
||||
import com.google.gwt.canvas.client.Canvas;
|
||||
import com.google.gwt.dom.client.CanvasElement;
|
||||
import com.google.gwt.dom.client.Document;
|
||||
import com.google.gwt.dom.client.Style.Unit;
|
||||
import com.google.gwt.user.client.ui.Panel;
|
||||
import com.google.gwt.webgl.client.WebGLContextAttributes;
|
||||
import com.google.gwt.webgl.client.WebGLRenderingContext;
|
||||
|
||||
public class GwtGraphics implements Graphics {
|
||||
static final Logger log = LoggerFactory.getLogger(GwtGraphics.class);
|
||||
|
||||
CanvasElement canvas;
|
||||
WebGLRenderingContext context;
|
||||
GL20 gl;
|
||||
String extensions;
|
||||
float fps = 0;
|
||||
long lastTimeStamp = System.currentTimeMillis();
|
||||
float deltaTime = 0;
|
||||
float time = 0;
|
||||
int frames;
|
||||
GwtApplicationConfiguration config;
|
||||
boolean inFullscreenMode = false;
|
||||
double pixelRatio;
|
||||
|
||||
public GwtGraphics(Panel root, final GwtApplicationConfiguration config) {
|
||||
this.pixelRatio = getDevicePixelRatioJSNI();
|
||||
|
||||
if (config.canvasId == null) {
|
||||
Canvas canvasWidget = Canvas.createIfSupported();
|
||||
if (canvasWidget == null)
|
||||
throw new GdxRuntimeException("Canvas not supported");
|
||||
canvas = canvasWidget.getCanvasElement();
|
||||
root.add(canvasWidget);
|
||||
} else {
|
||||
canvas = (CanvasElement) Document.get().getElementById(config.canvasId);
|
||||
|
||||
canvas.setWidth((int) (config.width * pixelRatio));
|
||||
canvas.setHeight((int) (config.height * pixelRatio));
|
||||
|
||||
canvas.getStyle().setWidth(config.width, Unit.PX);
|
||||
canvas.getStyle().setHeight(config.height, Unit.PX);
|
||||
}
|
||||
|
||||
this.config = config;
|
||||
|
||||
WebGLContextAttributes attributes = WebGLContextAttributes.create();
|
||||
attributes.setAntialias(config.antialiasing);
|
||||
attributes.setStencil(config.stencil);
|
||||
attributes.setAlpha(false);
|
||||
attributes.setPremultipliedAlpha(false);
|
||||
|
||||
context = WebGLRenderingContext.getContext(canvas, attributes);
|
||||
if (context == null)
|
||||
throw new GdxRuntimeException("Could not create Canvas for " + attributes);
|
||||
|
||||
context.viewport(0, 0, config.width, config.height);
|
||||
|
||||
// this actually *enables* the option to use std derivatives in shader..
|
||||
if (context.getExtension("OES_standard_derivatives") == null) {
|
||||
log.error("Missing gl extension for OES_standard_derivatives");
|
||||
}
|
||||
|
||||
if (context.getExtension("WEBKIT_WEBGL_depth_texture") == null) {
|
||||
log.error("Missing gl extension for WEBKIT_WEBGL_depth_texture");
|
||||
}
|
||||
|
||||
this.gl = config.useDebugGL ? new GwtGL20Debug(context) : new GdxGL(context);
|
||||
}
|
||||
|
||||
public static native double getDevicePixelRatioJSNI() /*-{
|
||||
return $wnd.devicePixelRatio || 1.0;
|
||||
}-*/;
|
||||
|
||||
public static native int getWindowWidthJSNI() /*-{
|
||||
return $wnd.innerWidth;
|
||||
}-*/;
|
||||
|
||||
public static native int getWindowHeightJSNI() /*-{
|
||||
return $wnd.innerHeight;
|
||||
}-*/;
|
||||
|
||||
public WebGLRenderingContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GL20 getGL20() {
|
||||
return gl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return canvas.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return canvas.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDeltaTime() {
|
||||
return deltaTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFramesPerSecond() {
|
||||
return (int) fps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphicsType getType() {
|
||||
return GraphicsType.WebGL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPpiX() {
|
||||
return 96;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPpiY() {
|
||||
return 96;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPpcX() {
|
||||
return 96 / 2.54f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPpcY() {
|
||||
return 96 / 2.54f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsDisplayModeChange() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DisplayMode[] getDisplayModes() {
|
||||
return new DisplayMode[] { new DisplayMode(getScreenWidthJSNI(), getScreenHeightJSNI(), 60,
|
||||
8) {
|
||||
} };
|
||||
}
|
||||
|
||||
private native int getScreenWidthJSNI() /*-{
|
||||
return $wnd.screen.width;
|
||||
}-*/;
|
||||
|
||||
private native int getScreenHeightJSNI() /*-{
|
||||
return $wnd.screen.height;
|
||||
}-*/;
|
||||
|
||||
private native boolean isFullscreenJSNI() /*-{
|
||||
if ("webkitIsFullScreen" in $doc) {
|
||||
return $doc.webkitIsFullScreen;
|
||||
}
|
||||
if ("mozFullScreen" in $doc) {
|
||||
return $doc.mozFullScreen;
|
||||
}
|
||||
return false
|
||||
}-*/;
|
||||
|
||||
private void fullscreenChanged() {
|
||||
if (!isFullscreen()) {
|
||||
canvas.setWidth(config.width);
|
||||
canvas.setHeight(config.height);
|
||||
}
|
||||
}
|
||||
|
||||
private native boolean setFullscreenJSNI(GwtGraphics graphics, CanvasElement element) /*-{
|
||||
if (element.webkitRequestFullScreen) {
|
||||
element.width = $wnd.screen.width;
|
||||
element.height = $wnd.screen.height;
|
||||
element.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
|
||||
$doc
|
||||
.addEventListener(
|
||||
"webkitfullscreenchange",
|
||||
function() {
|
||||
graphics.@com.badlogic.gdx.backends.gwt.GwtGraphics::fullscreenChanged()();
|
||||
}, false);
|
||||
return true;
|
||||
}
|
||||
if (element.mozRequestFullScreen) {
|
||||
element.width = $wnd.screen.width;
|
||||
element.height = $wnd.screen.height;
|
||||
element.mozRequestFullScreen();
|
||||
$doc
|
||||
.addEventListener(
|
||||
"mozfullscreenchange",
|
||||
function() {
|
||||
graphics.@com.badlogic.gdx.backends.gwt.GwtGraphics::fullscreenChanged()();
|
||||
}, false);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}-*/;
|
||||
|
||||
private native void exitFullscreen() /*-{
|
||||
if ($doc.webkitExitFullscreen)
|
||||
$doc.webkitExitFullscreen();
|
||||
if ($doc.mozExitFullscreen)
|
||||
$doc.mozExitFullscreen();
|
||||
}-*/;
|
||||
|
||||
@Override
|
||||
public DisplayMode getDesktopDisplayMode() {
|
||||
return new DisplayMode(getScreenWidthJSNI(), getScreenHeightJSNI(), 60, 8) {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setDisplayMode(DisplayMode displayMode) {
|
||||
if (displayMode.width != getScreenWidthJSNI()
|
||||
&& displayMode.height != getScreenHeightJSNI())
|
||||
return false;
|
||||
return setFullscreenJSNI(this, canvas);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setDisplayMode(int width, int height, boolean fullscreen) {
|
||||
if (fullscreen) {
|
||||
if (width != getScreenWidthJSNI() && height != getScreenHeightJSNI())
|
||||
return false;
|
||||
return setFullscreenJSNI(this, canvas);
|
||||
} else {
|
||||
if (isFullscreenJSNI())
|
||||
exitFullscreen();
|
||||
canvas.setWidth(width);
|
||||
canvas.setHeight(height);
|
||||
canvas.getStyle().setWidth(width, Unit.PX);
|
||||
canvas.getStyle().setHeight(height, Unit.PX);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferFormat getBufferFormat() {
|
||||
return new BufferFormat(8, 8, 8, 0, 16, config.stencil ? 8 : 0, 0, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsExtension(String extension) {
|
||||
if (extensions == null)
|
||||
extensions = Gdx.gl.glGetString(GL20.GL_EXTENSIONS);
|
||||
return extensions.contains(extension);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
long currTimeStamp = System.currentTimeMillis();
|
||||
deltaTime = (currTimeStamp - lastTimeStamp) / 1000.0f;
|
||||
lastTimeStamp = currTimeStamp;
|
||||
time += deltaTime;
|
||||
frames++;
|
||||
if (time > 1) {
|
||||
this.fps = frames;
|
||||
time = 0;
|
||||
frames = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(String title) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVSync(boolean vsync) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDensity() {
|
||||
return 96.0f / 160;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContinuousRendering(boolean isContinuous) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isContinuousRendering() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestRendering() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRawDeltaTime() {
|
||||
return getDeltaTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFullscreen() {
|
||||
return isFullscreenJSNI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGL30Available() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GL30 getGL30() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getFrameId() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Copyright 2011 See libgdx AUTHORS file.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
******************************************************************************/
|
||||
|
||||
package com.badlogic.gdx.backends.gwt;
|
||||
|
||||
import org.oscim.gdx.client.GdxGL;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Graphics;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.GL30;
|
||||
import com.badlogic.gdx.utils.GdxRuntimeException;
|
||||
import com.google.gwt.canvas.client.Canvas;
|
||||
import com.google.gwt.dom.client.CanvasElement;
|
||||
import com.google.gwt.dom.client.Document;
|
||||
import com.google.gwt.dom.client.Style.Unit;
|
||||
import com.google.gwt.user.client.ui.Panel;
|
||||
import com.google.gwt.webgl.client.WebGLContextAttributes;
|
||||
import com.google.gwt.webgl.client.WebGLRenderingContext;
|
||||
|
||||
public class GwtGraphics implements Graphics {
|
||||
static final Logger log = LoggerFactory.getLogger(GwtGraphics.class);
|
||||
|
||||
CanvasElement canvas;
|
||||
WebGLRenderingContext context;
|
||||
GL20 gl;
|
||||
String extensions;
|
||||
float fps = 0;
|
||||
long lastTimeStamp = System.currentTimeMillis();
|
||||
float deltaTime = 0;
|
||||
float time = 0;
|
||||
int frames;
|
||||
GwtApplicationConfiguration config;
|
||||
boolean inFullscreenMode = false;
|
||||
double pixelRatio;
|
||||
|
||||
public GwtGraphics(Panel root, final GwtApplicationConfiguration config) {
|
||||
this.pixelRatio = getDevicePixelRatioJSNI();
|
||||
|
||||
if (config.canvasId == null) {
|
||||
Canvas canvasWidget = Canvas.createIfSupported();
|
||||
if (canvasWidget == null)
|
||||
throw new GdxRuntimeException("Canvas not supported");
|
||||
canvas = canvasWidget.getCanvasElement();
|
||||
root.add(canvasWidget);
|
||||
} else {
|
||||
canvas = (CanvasElement) Document.get().getElementById(config.canvasId);
|
||||
|
||||
canvas.setWidth((int) (config.width * pixelRatio));
|
||||
canvas.setHeight((int) (config.height * pixelRatio));
|
||||
|
||||
canvas.getStyle().setWidth(config.width, Unit.PX);
|
||||
canvas.getStyle().setHeight(config.height, Unit.PX);
|
||||
}
|
||||
|
||||
this.config = config;
|
||||
|
||||
WebGLContextAttributes attributes = WebGLContextAttributes.create();
|
||||
attributes.setAntialias(config.antialiasing);
|
||||
attributes.setStencil(config.stencil);
|
||||
attributes.setAlpha(false);
|
||||
attributes.setPremultipliedAlpha(false);
|
||||
|
||||
context = WebGLRenderingContext.getContext(canvas, attributes);
|
||||
if (context == null)
|
||||
throw new GdxRuntimeException("Could not create Canvas for " + attributes);
|
||||
|
||||
context.viewport(0, 0, config.width, config.height);
|
||||
|
||||
// this actually *enables* the option to use std derivatives in shader..
|
||||
if (context.getExtension("OES_standard_derivatives") == null) {
|
||||
log.error("Missing gl extension for OES_standard_derivatives");
|
||||
}
|
||||
|
||||
if (context.getExtension("WEBKIT_WEBGL_depth_texture") == null) {
|
||||
log.error("Missing gl extension for WEBKIT_WEBGL_depth_texture");
|
||||
}
|
||||
|
||||
this.gl = config.useDebugGL ? new GwtGL20Debug(context) : new GdxGL(context);
|
||||
}
|
||||
|
||||
public static native double getDevicePixelRatioJSNI() /*-{
|
||||
return $wnd.devicePixelRatio || 1.0;
|
||||
}-*/;
|
||||
|
||||
public static native int getWindowWidthJSNI() /*-{
|
||||
return $wnd.innerWidth;
|
||||
}-*/;
|
||||
|
||||
public static native int getWindowHeightJSNI() /*-{
|
||||
return $wnd.innerHeight;
|
||||
}-*/;
|
||||
|
||||
public WebGLRenderingContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GL20 getGL20() {
|
||||
return gl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return canvas.getWidth();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return canvas.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDeltaTime() {
|
||||
return deltaTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFramesPerSecond() {
|
||||
return (int) fps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphicsType getType() {
|
||||
return GraphicsType.WebGL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPpiX() {
|
||||
return 96;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPpiY() {
|
||||
return 96;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPpcX() {
|
||||
return 96 / 2.54f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPpcY() {
|
||||
return 96 / 2.54f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsDisplayModeChange() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DisplayMode[] getDisplayModes() {
|
||||
return new DisplayMode[] { new DisplayMode(getScreenWidthJSNI(), getScreenHeightJSNI(), 60,
|
||||
8) {
|
||||
} };
|
||||
}
|
||||
|
||||
private native int getScreenWidthJSNI() /*-{
|
||||
return $wnd.screen.width;
|
||||
}-*/;
|
||||
|
||||
private native int getScreenHeightJSNI() /*-{
|
||||
return $wnd.screen.height;
|
||||
}-*/;
|
||||
|
||||
private native boolean isFullscreenJSNI() /*-{
|
||||
if ("webkitIsFullScreen" in $doc) {
|
||||
return $doc.webkitIsFullScreen;
|
||||
}
|
||||
if ("mozFullScreen" in $doc) {
|
||||
return $doc.mozFullScreen;
|
||||
}
|
||||
return false
|
||||
}-*/;
|
||||
|
||||
private void fullscreenChanged() {
|
||||
if (!isFullscreen()) {
|
||||
canvas.setWidth(config.width);
|
||||
canvas.setHeight(config.height);
|
||||
}
|
||||
}
|
||||
|
||||
private native boolean setFullscreenJSNI(GwtGraphics graphics, CanvasElement element) /*-{
|
||||
if (element.webkitRequestFullScreen) {
|
||||
element.width = $wnd.screen.width;
|
||||
element.height = $wnd.screen.height;
|
||||
element.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
|
||||
$doc
|
||||
.addEventListener(
|
||||
"webkitfullscreenchange",
|
||||
function() {
|
||||
graphics.@com.badlogic.gdx.backends.gwt.GwtGraphics::fullscreenChanged()();
|
||||
}, false);
|
||||
return true;
|
||||
}
|
||||
if (element.mozRequestFullScreen) {
|
||||
element.width = $wnd.screen.width;
|
||||
element.height = $wnd.screen.height;
|
||||
element.mozRequestFullScreen();
|
||||
$doc
|
||||
.addEventListener(
|
||||
"mozfullscreenchange",
|
||||
function() {
|
||||
graphics.@com.badlogic.gdx.backends.gwt.GwtGraphics::fullscreenChanged()();
|
||||
}, false);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}-*/;
|
||||
|
||||
private native void exitFullscreen() /*-{
|
||||
if ($doc.webkitExitFullscreen)
|
||||
$doc.webkitExitFullscreen();
|
||||
if ($doc.mozExitFullscreen)
|
||||
$doc.mozExitFullscreen();
|
||||
}-*/;
|
||||
|
||||
@Override
|
||||
public DisplayMode getDesktopDisplayMode() {
|
||||
return new DisplayMode(getScreenWidthJSNI(), getScreenHeightJSNI(), 60, 8) {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setDisplayMode(DisplayMode displayMode) {
|
||||
if (displayMode.width != getScreenWidthJSNI()
|
||||
&& displayMode.height != getScreenHeightJSNI())
|
||||
return false;
|
||||
return setFullscreenJSNI(this, canvas);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setDisplayMode(int width, int height, boolean fullscreen) {
|
||||
if (fullscreen) {
|
||||
if (width != getScreenWidthJSNI() && height != getScreenHeightJSNI())
|
||||
return false;
|
||||
return setFullscreenJSNI(this, canvas);
|
||||
} else {
|
||||
if (isFullscreenJSNI())
|
||||
exitFullscreen();
|
||||
canvas.setWidth(width);
|
||||
canvas.setHeight(height);
|
||||
canvas.getStyle().setWidth(width, Unit.PX);
|
||||
canvas.getStyle().setHeight(height, Unit.PX);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferFormat getBufferFormat() {
|
||||
return new BufferFormat(8, 8, 8, 0, 16, config.stencil ? 8 : 0, 0, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsExtension(String extension) {
|
||||
if (extensions == null)
|
||||
extensions = Gdx.gl.glGetString(GL20.GL_EXTENSIONS);
|
||||
return extensions.contains(extension);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
long currTimeStamp = System.currentTimeMillis();
|
||||
deltaTime = (currTimeStamp - lastTimeStamp) / 1000.0f;
|
||||
lastTimeStamp = currTimeStamp;
|
||||
time += deltaTime;
|
||||
frames++;
|
||||
if (time > 1) {
|
||||
this.fps = frames;
|
||||
time = 0;
|
||||
frames = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTitle(String title) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVSync(boolean vsync) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDensity() {
|
||||
return 96.0f / 160;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContinuousRendering(boolean isContinuous) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isContinuousRendering() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestRendering() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRawDeltaTime() {
|
||||
return getDeltaTime();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFullscreen() {
|
||||
return isFullscreenJSNI();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGL30Available() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GL30 getGL30() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getFrameId() {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,377 +1,377 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011 See libgdx AUTHORS file.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
******************************************************************************/
|
||||
|
||||
package com.badlogic.gdx.graphics;
|
||||
|
||||
import java.nio.Buffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.badlogic.gdx.backends.gwt.GwtFileHandle;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.utils.BufferUtils;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
import com.badlogic.gdx.utils.GdxRuntimeException;
|
||||
import com.google.gwt.canvas.client.Canvas;
|
||||
import com.google.gwt.canvas.dom.client.CanvasPixelArray;
|
||||
import com.google.gwt.canvas.dom.client.Context2d;
|
||||
import com.google.gwt.canvas.dom.client.Context2d.Composite;
|
||||
import com.google.gwt.dom.client.CanvasElement;
|
||||
import com.google.gwt.dom.client.ImageElement;
|
||||
|
||||
public class Pixmap implements Disposable {
|
||||
public static Map<Integer, Pixmap> pixmaps = new HashMap<Integer, Pixmap>();
|
||||
static int nextId = 0;
|
||||
|
||||
/** Different pixel formats.
|
||||
*
|
||||
* @author mzechner */
|
||||
public enum Format {
|
||||
Alpha, Intensity, LuminanceAlpha, RGB565, RGBA4444, RGB888, RGBA8888;
|
||||
}
|
||||
|
||||
/** Blending functions to be set with {@link Pixmap#setBlending}.
|
||||
* @author mzechner */
|
||||
public enum Blending {
|
||||
None, SourceOver
|
||||
}
|
||||
|
||||
/** Filters to be used with {@link Pixmap#drawPixmap(Pixmap, int, int, int, int, int, int, int, int)}.
|
||||
*
|
||||
* @author mzechner */
|
||||
public enum Filter {
|
||||
NearestNeighbour, BiLinear
|
||||
}
|
||||
|
||||
int width;
|
||||
int height;
|
||||
Format format;
|
||||
Canvas canvas;
|
||||
Context2d context;
|
||||
int id;
|
||||
IntBuffer buffer;
|
||||
int r = 255, g = 255, b = 255;
|
||||
float a;
|
||||
String color = make(r, g, b, a);
|
||||
static Blending blending;
|
||||
CanvasPixelArray pixels;
|
||||
|
||||
public Context2d getContext(){
|
||||
return context;
|
||||
}
|
||||
|
||||
public Pixmap (FileHandle file) {
|
||||
GwtFileHandle gwtFile = (GwtFileHandle)file;
|
||||
ImageElement img = gwtFile.preloader.images.get(file.path());
|
||||
if (img == null) throw new GdxRuntimeException("Couldn't load image '" + file.path() + "', file does not exist");
|
||||
create(img.getWidth(), img.getHeight(), Format.RGBA8888);
|
||||
context.setGlobalCompositeOperation(Composite.COPY);
|
||||
context.drawImage(img, 0, 0);
|
||||
context.setGlobalCompositeOperation(getComposite());
|
||||
}
|
||||
|
||||
private static Composite getComposite () {
|
||||
return blending == Blending.None ? Composite.COPY : Composite.SOURCE_OVER;
|
||||
}
|
||||
|
||||
public Pixmap (ImageElement img) {
|
||||
create(img.getWidth(), img.getHeight(), Format.RGBA8888);
|
||||
context.drawImage(img, 0, 0);
|
||||
}
|
||||
|
||||
public Pixmap (int width, int height, Format format) {
|
||||
create(width, height, format);
|
||||
}
|
||||
|
||||
private void create (int width, int height, Format format2) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.format = Format.RGBA8888;
|
||||
canvas = Canvas.createIfSupported();
|
||||
canvas.getCanvasElement().setWidth(width);
|
||||
canvas.getCanvasElement().setHeight(height);
|
||||
context = canvas.getContext2d();
|
||||
context.setGlobalCompositeOperation(getComposite());
|
||||
buffer = BufferUtils.newIntBuffer(1);
|
||||
id = nextId++;
|
||||
buffer.put(0, id);
|
||||
pixmaps.put(id, this);
|
||||
}
|
||||
|
||||
public static String make (int r2, int g2, int b2, float a2) {
|
||||
return "rgba(" + r2 + "," + g2 + "," + b2 + "," + a2 + ")";
|
||||
}
|
||||
|
||||
/** Sets the type of {@link Blending} to be used for all operations. Default is {@link Blending#SourceOver}.
|
||||
* @param blending the blending type */
|
||||
public static void setBlending (Blending blending) {
|
||||
Pixmap.blending = blending;
|
||||
Composite composite = getComposite();
|
||||
for (Pixmap pixmap : pixmaps.values()) {
|
||||
pixmap.context.setGlobalCompositeOperation(composite);
|
||||
}
|
||||
}
|
||||
|
||||
/** @return the currently set {@link Blending} */
|
||||
public static Blending getBlending () {
|
||||
return blending;
|
||||
}
|
||||
|
||||
/** Sets the type of interpolation {@link Filter} to be used in conjunction with
|
||||
* {@link Pixmap#drawPixmap(Pixmap, int, int, int, int, int, int, int, int)}.
|
||||
* @param filter the filter. */
|
||||
public static void setFilter (Filter filter) {
|
||||
}
|
||||
|
||||
public Format getFormat () {
|
||||
return format;
|
||||
}
|
||||
|
||||
public int getGLInternalFormat () {
|
||||
return GL20.GL_RGBA;
|
||||
}
|
||||
|
||||
public int getGLFormat () {
|
||||
return GL20.GL_RGBA;
|
||||
}
|
||||
|
||||
public int getGLType () {
|
||||
return GL20.GL_UNSIGNED_BYTE;
|
||||
}
|
||||
|
||||
public int getWidth () {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight () {
|
||||
return height;
|
||||
}
|
||||
|
||||
public Buffer getPixels () {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose () {
|
||||
pixmaps.remove(id);
|
||||
}
|
||||
|
||||
public CanvasElement getCanvasElement () {
|
||||
return canvas.getCanvasElement();
|
||||
}
|
||||
|
||||
/** Sets the color for the following drawing operations
|
||||
* @param color the color, encoded as RGBA8888 */
|
||||
public void setColor (int color) {
|
||||
r = (color >>> 24) & 0xff;
|
||||
g = (color >>> 16) & 0xff;
|
||||
b = (color >>> 8) & 0xff;
|
||||
a = (color & 0xff) / 255f;
|
||||
this.color = make(r, g, b, a);
|
||||
context.setFillStyle(this.color);
|
||||
context.setStrokeStyle(this.color);
|
||||
}
|
||||
|
||||
/** Sets the color for the following drawing operations.
|
||||
*
|
||||
* @param r The red component.
|
||||
* @param g The green component.
|
||||
* @param b The blue component.
|
||||
* @param a The alpha component. */
|
||||
public void setColor (float r, float g, float b, float a) {
|
||||
this.r = (int)(r * 255);
|
||||
this.g = (int)(g * 255);
|
||||
this.b = (int)(b * 255);
|
||||
this.a = a;
|
||||
color = make(this.r, this.g, this.b, this.a);
|
||||
context.setFillStyle(color);
|
||||
context.setStrokeStyle(this.color);
|
||||
}
|
||||
|
||||
/** Sets the color for the following drawing operations.
|
||||
* @param color The color. */
|
||||
public void setColor (Color color) {
|
||||
setColor(color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
/** Fills the complete bitmap with the currently set color. */
|
||||
public void fill () {
|
||||
context.fillRect(0, 0, getWidth(), getHeight());
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Sets the width in pixels of strokes.
|
||||
// *
|
||||
// * @param width The stroke width in pixels.
|
||||
// */
|
||||
// public void setStrokeWidth (int width);
|
||||
|
||||
/** Draws a line between the given coordinates using the currently set color.
|
||||
*
|
||||
* @param x The x-coodinate of the first point
|
||||
* @param y The y-coordinate of the first point
|
||||
* @param x2 The x-coordinate of the first point
|
||||
* @param y2 The y-coordinate of the first point */
|
||||
public void drawLine (int x, int y, int x2, int y2) {
|
||||
context.beginPath();
|
||||
context.moveTo(x, y);
|
||||
context.lineTo(x2, y2);
|
||||
context.stroke();
|
||||
context.closePath();
|
||||
}
|
||||
|
||||
/** Draws a rectangle outline starting at x, y extending by width to the right and by height downwards (y-axis points downwards)
|
||||
* using the current color.
|
||||
*
|
||||
* @param x The x coordinate
|
||||
* @param y The y coordinate
|
||||
* @param width The width in pixels
|
||||
* @param height The height in pixels */
|
||||
public void drawRectangle (int x, int y, int width, int height) {
|
||||
context.beginPath();
|
||||
context.rect(x, y, width, height);
|
||||
context.stroke();
|
||||
context.closePath();
|
||||
}
|
||||
|
||||
/** Draws an area form another Pixmap to this Pixmap.
|
||||
*
|
||||
* @param pixmap The other Pixmap
|
||||
* @param x The target x-coordinate (top left corner)
|
||||
* @param y The target y-coordinate (top left corner) */
|
||||
public void drawPixmap (Pixmap pixmap, int x, int y) {
|
||||
context.drawImage(pixmap.getCanvasElement(), x, y);
|
||||
}
|
||||
|
||||
/** Draws an area form another Pixmap to this Pixmap.
|
||||
*
|
||||
* @param pixmap The other Pixmap
|
||||
* @param x The target x-coordinate (top left corner)
|
||||
* @param y The target y-coordinate (top left corner)
|
||||
* @param srcx The source x-coordinate (top left corner)
|
||||
* @param srcy The source y-coordinate (top left corner);
|
||||
* @param srcWidth The width of the area form the other Pixmap in pixels
|
||||
* @param srcHeight The height of the area form the other Pixmap in pixles */
|
||||
public void drawPixmap (Pixmap pixmap, int x, int y, int srcx, int srcy, int srcWidth, int srcHeight) {
|
||||
context.drawImage(pixmap.getCanvasElement(), srcx, srcy, srcWidth, srcHeight, x, y, srcWidth, srcHeight);
|
||||
}
|
||||
|
||||
/** Draws an area form another Pixmap to this Pixmap. This will automatically scale and stretch the source image to the
|
||||
* specified target rectangle. Use {@link Pixmap#setFilter(Filter)} to specify the type of filtering to be used (nearest
|
||||
* neighbour or bilinear).
|
||||
*
|
||||
* @param pixmap The other Pixmap
|
||||
* @param srcx The source x-coordinate (top left corner)
|
||||
* @param srcy The source y-coordinate (top left corner);
|
||||
* @param srcWidth The width of the area form the other Pixmap in pixels
|
||||
* @param srcHeight The height of the area form the other Pixmap in pixles
|
||||
* @param dstx The target x-coordinate (top left corner)
|
||||
* @param dsty The target y-coordinate (top left corner)
|
||||
* @param dstWidth The target width
|
||||
* @param dstHeight the target height */
|
||||
public void drawPixmap (Pixmap pixmap, int srcx, int srcy, int srcWidth, int srcHeight, int dstx, int dsty, int dstWidth,
|
||||
int dstHeight) {
|
||||
context.drawImage(pixmap.getCanvasElement(), srcx, srcy, srcWidth, srcHeight, dstx, dsty, dstWidth, dstHeight);
|
||||
}
|
||||
|
||||
/** Fills a rectangle starting at x, y extending by width to the right and by height downwards (y-axis points downwards) using
|
||||
* the current color.
|
||||
*
|
||||
* @param x The x coordinate
|
||||
* @param y The y coordinate
|
||||
* @param width The width in pixels
|
||||
* @param height The height in pixels */
|
||||
public void fillRectangle (int x, int y, int width, int height) {
|
||||
context.fillRect(x, y, width, height);
|
||||
}
|
||||
|
||||
/** Draws a circle outline with the center at x,y and a radius using the current color and stroke width.
|
||||
*
|
||||
* @param x The x-coordinate of the center
|
||||
* @param y The y-coordinate of the center
|
||||
* @param radius The radius in pixels */
|
||||
public void drawCircle (int x, int y, int radius) {
|
||||
context.beginPath();
|
||||
context.arc(x, y, radius, 0, 2 * Math.PI, false);
|
||||
context.stroke();
|
||||
context.closePath();
|
||||
}
|
||||
|
||||
/** Fills a circle with the center at x,y and a radius using the current color.
|
||||
*
|
||||
* @param x The x-coordinate of the center
|
||||
* @param y The y-coordinate of the center
|
||||
* @param radius The radius in pixels */
|
||||
public void fillCircle (int x, int y, int radius) {
|
||||
context.beginPath();
|
||||
context.arc(x, y, radius, 0, 2 * Math.PI, false);
|
||||
context.fill();
|
||||
context.closePath();
|
||||
}
|
||||
|
||||
/** Fills a triangle with vertices at x1,y1 and x2,y2 and x3,y3 using the current color.
|
||||
*
|
||||
* @param x1 The x-coordinate of vertex 1
|
||||
* @param y1 The y-coordinate of vertex 1
|
||||
* @param x2 The x-coordinate of vertex 2
|
||||
* @param y2 The y-coordinate of vertex 2
|
||||
* @param x3 The x-coordinate of vertex 3
|
||||
* @param y3 The y-coordinate of vertex 3 */
|
||||
public void fillTriangle (int x1, int y1, int x2, int y2, int x3, int y3) {
|
||||
context.beginPath();
|
||||
context.moveTo(x1,y1);
|
||||
context.lineTo(x2,y2);
|
||||
context.lineTo(x3,y3);
|
||||
context.lineTo(x1,y1);
|
||||
context.fill();
|
||||
context.closePath();
|
||||
}
|
||||
|
||||
/** Returns the 32-bit RGBA8888 value of the pixel at x, y. For Alpha formats the RGB components will be one.
|
||||
*
|
||||
* @param x The x-coordinate
|
||||
* @param y The y-coordinate
|
||||
* @return The pixel color in RGBA8888 format. */
|
||||
public int getPixel (int x, int y) {
|
||||
if (pixels == null) pixels = context.getImageData(0, 0, width, height).getData();
|
||||
int i = x * 4 + y * width * 4;
|
||||
int r = pixels.get(i + 0) & 0xff;
|
||||
int g = pixels.get(i + 1) & 0xff;
|
||||
int b = pixels.get(i + 2) & 0xff;
|
||||
int a = pixels.get(i + 3) & 0xff;
|
||||
return (r << 24) | (g << 16) | (b << 8) | (a);
|
||||
}
|
||||
|
||||
/** Draws a pixel at the given location with the current color.
|
||||
*
|
||||
* @param x the x-coordinate
|
||||
* @param y the y-coordinate */
|
||||
public void drawPixel (int x, int y) {
|
||||
context.fillRect(x, y, 1, 1);
|
||||
}
|
||||
|
||||
/** Draws a pixel at the given location with the given color.
|
||||
*
|
||||
* @param x the x-coordinate
|
||||
* @param y the y-coordinate
|
||||
* @param color the color in RGBA8888 format. */
|
||||
public void drawPixel (int x, int y, int color) {
|
||||
setColor(color);
|
||||
drawPixel(x, y);
|
||||
}
|
||||
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Copyright 2011 See libgdx AUTHORS file.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
******************************************************************************/
|
||||
|
||||
package com.badlogic.gdx.graphics;
|
||||
|
||||
import java.nio.Buffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.badlogic.gdx.backends.gwt.GwtFileHandle;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.utils.BufferUtils;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
import com.badlogic.gdx.utils.GdxRuntimeException;
|
||||
import com.google.gwt.canvas.client.Canvas;
|
||||
import com.google.gwt.canvas.dom.client.CanvasPixelArray;
|
||||
import com.google.gwt.canvas.dom.client.Context2d;
|
||||
import com.google.gwt.canvas.dom.client.Context2d.Composite;
|
||||
import com.google.gwt.dom.client.CanvasElement;
|
||||
import com.google.gwt.dom.client.ImageElement;
|
||||
|
||||
public class Pixmap implements Disposable {
|
||||
public static Map<Integer, Pixmap> pixmaps = new HashMap<Integer, Pixmap>();
|
||||
static int nextId = 0;
|
||||
|
||||
/** Different pixel formats.
|
||||
*
|
||||
* @author mzechner */
|
||||
public enum Format {
|
||||
Alpha, Intensity, LuminanceAlpha, RGB565, RGBA4444, RGB888, RGBA8888;
|
||||
}
|
||||
|
||||
/** Blending functions to be set with {@link Pixmap#setBlending}.
|
||||
* @author mzechner */
|
||||
public enum Blending {
|
||||
None, SourceOver
|
||||
}
|
||||
|
||||
/** Filters to be used with {@link Pixmap#drawPixmap(Pixmap, int, int, int, int, int, int, int, int)}.
|
||||
*
|
||||
* @author mzechner */
|
||||
public enum Filter {
|
||||
NearestNeighbour, BiLinear
|
||||
}
|
||||
|
||||
int width;
|
||||
int height;
|
||||
Format format;
|
||||
Canvas canvas;
|
||||
Context2d context;
|
||||
int id;
|
||||
IntBuffer buffer;
|
||||
int r = 255, g = 255, b = 255;
|
||||
float a;
|
||||
String color = make(r, g, b, a);
|
||||
static Blending blending;
|
||||
CanvasPixelArray pixels;
|
||||
|
||||
public Context2d getContext(){
|
||||
return context;
|
||||
}
|
||||
|
||||
public Pixmap (FileHandle file) {
|
||||
GwtFileHandle gwtFile = (GwtFileHandle)file;
|
||||
ImageElement img = gwtFile.preloader.images.get(file.path());
|
||||
if (img == null) throw new GdxRuntimeException("Couldn't load image '" + file.path() + "', file does not exist");
|
||||
create(img.getWidth(), img.getHeight(), Format.RGBA8888);
|
||||
context.setGlobalCompositeOperation(Composite.COPY);
|
||||
context.drawImage(img, 0, 0);
|
||||
context.setGlobalCompositeOperation(getComposite());
|
||||
}
|
||||
|
||||
private static Composite getComposite () {
|
||||
return blending == Blending.None ? Composite.COPY : Composite.SOURCE_OVER;
|
||||
}
|
||||
|
||||
public Pixmap (ImageElement img) {
|
||||
create(img.getWidth(), img.getHeight(), Format.RGBA8888);
|
||||
context.drawImage(img, 0, 0);
|
||||
}
|
||||
|
||||
public Pixmap (int width, int height, Format format) {
|
||||
create(width, height, format);
|
||||
}
|
||||
|
||||
private void create (int width, int height, Format format2) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.format = Format.RGBA8888;
|
||||
canvas = Canvas.createIfSupported();
|
||||
canvas.getCanvasElement().setWidth(width);
|
||||
canvas.getCanvasElement().setHeight(height);
|
||||
context = canvas.getContext2d();
|
||||
context.setGlobalCompositeOperation(getComposite());
|
||||
buffer = BufferUtils.newIntBuffer(1);
|
||||
id = nextId++;
|
||||
buffer.put(0, id);
|
||||
pixmaps.put(id, this);
|
||||
}
|
||||
|
||||
public static String make (int r2, int g2, int b2, float a2) {
|
||||
return "rgba(" + r2 + "," + g2 + "," + b2 + "," + a2 + ")";
|
||||
}
|
||||
|
||||
/** Sets the type of {@link Blending} to be used for all operations. Default is {@link Blending#SourceOver}.
|
||||
* @param blending the blending type */
|
||||
public static void setBlending (Blending blending) {
|
||||
Pixmap.blending = blending;
|
||||
Composite composite = getComposite();
|
||||
for (Pixmap pixmap : pixmaps.values()) {
|
||||
pixmap.context.setGlobalCompositeOperation(composite);
|
||||
}
|
||||
}
|
||||
|
||||
/** @return the currently set {@link Blending} */
|
||||
public static Blending getBlending () {
|
||||
return blending;
|
||||
}
|
||||
|
||||
/** Sets the type of interpolation {@link Filter} to be used in conjunction with
|
||||
* {@link Pixmap#drawPixmap(Pixmap, int, int, int, int, int, int, int, int)}.
|
||||
* @param filter the filter. */
|
||||
public static void setFilter (Filter filter) {
|
||||
}
|
||||
|
||||
public Format getFormat () {
|
||||
return format;
|
||||
}
|
||||
|
||||
public int getGLInternalFormat () {
|
||||
return GL20.GL_RGBA;
|
||||
}
|
||||
|
||||
public int getGLFormat () {
|
||||
return GL20.GL_RGBA;
|
||||
}
|
||||
|
||||
public int getGLType () {
|
||||
return GL20.GL_UNSIGNED_BYTE;
|
||||
}
|
||||
|
||||
public int getWidth () {
|
||||
return width;
|
||||
}
|
||||
|
||||
public int getHeight () {
|
||||
return height;
|
||||
}
|
||||
|
||||
public Buffer getPixels () {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose () {
|
||||
pixmaps.remove(id);
|
||||
}
|
||||
|
||||
public CanvasElement getCanvasElement () {
|
||||
return canvas.getCanvasElement();
|
||||
}
|
||||
|
||||
/** Sets the color for the following drawing operations
|
||||
* @param color the color, encoded as RGBA8888 */
|
||||
public void setColor (int color) {
|
||||
r = (color >>> 24) & 0xff;
|
||||
g = (color >>> 16) & 0xff;
|
||||
b = (color >>> 8) & 0xff;
|
||||
a = (color & 0xff) / 255f;
|
||||
this.color = make(r, g, b, a);
|
||||
context.setFillStyle(this.color);
|
||||
context.setStrokeStyle(this.color);
|
||||
}
|
||||
|
||||
/** Sets the color for the following drawing operations.
|
||||
*
|
||||
* @param r The red component.
|
||||
* @param g The green component.
|
||||
* @param b The blue component.
|
||||
* @param a The alpha component. */
|
||||
public void setColor (float r, float g, float b, float a) {
|
||||
this.r = (int)(r * 255);
|
||||
this.g = (int)(g * 255);
|
||||
this.b = (int)(b * 255);
|
||||
this.a = a;
|
||||
color = make(this.r, this.g, this.b, this.a);
|
||||
context.setFillStyle(color);
|
||||
context.setStrokeStyle(this.color);
|
||||
}
|
||||
|
||||
/** Sets the color for the following drawing operations.
|
||||
* @param color The color. */
|
||||
public void setColor (Color color) {
|
||||
setColor(color.r, color.g, color.b, color.a);
|
||||
}
|
||||
|
||||
/** Fills the complete bitmap with the currently set color. */
|
||||
public void fill () {
|
||||
context.fillRect(0, 0, getWidth(), getHeight());
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Sets the width in pixels of strokes.
|
||||
// *
|
||||
// * @param width The stroke width in pixels.
|
||||
// */
|
||||
// public void setStrokeWidth (int width);
|
||||
|
||||
/** Draws a line between the given coordinates using the currently set color.
|
||||
*
|
||||
* @param x The x-coodinate of the first point
|
||||
* @param y The y-coordinate of the first point
|
||||
* @param x2 The x-coordinate of the first point
|
||||
* @param y2 The y-coordinate of the first point */
|
||||
public void drawLine (int x, int y, int x2, int y2) {
|
||||
context.beginPath();
|
||||
context.moveTo(x, y);
|
||||
context.lineTo(x2, y2);
|
||||
context.stroke();
|
||||
context.closePath();
|
||||
}
|
||||
|
||||
/** Draws a rectangle outline starting at x, y extending by width to the right and by height downwards (y-axis points downwards)
|
||||
* using the current color.
|
||||
*
|
||||
* @param x The x coordinate
|
||||
* @param y The y coordinate
|
||||
* @param width The width in pixels
|
||||
* @param height The height in pixels */
|
||||
public void drawRectangle (int x, int y, int width, int height) {
|
||||
context.beginPath();
|
||||
context.rect(x, y, width, height);
|
||||
context.stroke();
|
||||
context.closePath();
|
||||
}
|
||||
|
||||
/** Draws an area form another Pixmap to this Pixmap.
|
||||
*
|
||||
* @param pixmap The other Pixmap
|
||||
* @param x The target x-coordinate (top left corner)
|
||||
* @param y The target y-coordinate (top left corner) */
|
||||
public void drawPixmap (Pixmap pixmap, int x, int y) {
|
||||
context.drawImage(pixmap.getCanvasElement(), x, y);
|
||||
}
|
||||
|
||||
/** Draws an area form another Pixmap to this Pixmap.
|
||||
*
|
||||
* @param pixmap The other Pixmap
|
||||
* @param x The target x-coordinate (top left corner)
|
||||
* @param y The target y-coordinate (top left corner)
|
||||
* @param srcx The source x-coordinate (top left corner)
|
||||
* @param srcy The source y-coordinate (top left corner);
|
||||
* @param srcWidth The width of the area form the other Pixmap in pixels
|
||||
* @param srcHeight The height of the area form the other Pixmap in pixles */
|
||||
public void drawPixmap (Pixmap pixmap, int x, int y, int srcx, int srcy, int srcWidth, int srcHeight) {
|
||||
context.drawImage(pixmap.getCanvasElement(), srcx, srcy, srcWidth, srcHeight, x, y, srcWidth, srcHeight);
|
||||
}
|
||||
|
||||
/** Draws an area form another Pixmap to this Pixmap. This will automatically scale and stretch the source image to the
|
||||
* specified target rectangle. Use {@link Pixmap#setFilter(Filter)} to specify the type of filtering to be used (nearest
|
||||
* neighbour or bilinear).
|
||||
*
|
||||
* @param pixmap The other Pixmap
|
||||
* @param srcx The source x-coordinate (top left corner)
|
||||
* @param srcy The source y-coordinate (top left corner);
|
||||
* @param srcWidth The width of the area form the other Pixmap in pixels
|
||||
* @param srcHeight The height of the area form the other Pixmap in pixles
|
||||
* @param dstx The target x-coordinate (top left corner)
|
||||
* @param dsty The target y-coordinate (top left corner)
|
||||
* @param dstWidth The target width
|
||||
* @param dstHeight the target height */
|
||||
public void drawPixmap (Pixmap pixmap, int srcx, int srcy, int srcWidth, int srcHeight, int dstx, int dsty, int dstWidth,
|
||||
int dstHeight) {
|
||||
context.drawImage(pixmap.getCanvasElement(), srcx, srcy, srcWidth, srcHeight, dstx, dsty, dstWidth, dstHeight);
|
||||
}
|
||||
|
||||
/** Fills a rectangle starting at x, y extending by width to the right and by height downwards (y-axis points downwards) using
|
||||
* the current color.
|
||||
*
|
||||
* @param x The x coordinate
|
||||
* @param y The y coordinate
|
||||
* @param width The width in pixels
|
||||
* @param height The height in pixels */
|
||||
public void fillRectangle (int x, int y, int width, int height) {
|
||||
context.fillRect(x, y, width, height);
|
||||
}
|
||||
|
||||
/** Draws a circle outline with the center at x,y and a radius using the current color and stroke width.
|
||||
*
|
||||
* @param x The x-coordinate of the center
|
||||
* @param y The y-coordinate of the center
|
||||
* @param radius The radius in pixels */
|
||||
public void drawCircle (int x, int y, int radius) {
|
||||
context.beginPath();
|
||||
context.arc(x, y, radius, 0, 2 * Math.PI, false);
|
||||
context.stroke();
|
||||
context.closePath();
|
||||
}
|
||||
|
||||
/** Fills a circle with the center at x,y and a radius using the current color.
|
||||
*
|
||||
* @param x The x-coordinate of the center
|
||||
* @param y The y-coordinate of the center
|
||||
* @param radius The radius in pixels */
|
||||
public void fillCircle (int x, int y, int radius) {
|
||||
context.beginPath();
|
||||
context.arc(x, y, radius, 0, 2 * Math.PI, false);
|
||||
context.fill();
|
||||
context.closePath();
|
||||
}
|
||||
|
||||
/** Fills a triangle with vertices at x1,y1 and x2,y2 and x3,y3 using the current color.
|
||||
*
|
||||
* @param x1 The x-coordinate of vertex 1
|
||||
* @param y1 The y-coordinate of vertex 1
|
||||
* @param x2 The x-coordinate of vertex 2
|
||||
* @param y2 The y-coordinate of vertex 2
|
||||
* @param x3 The x-coordinate of vertex 3
|
||||
* @param y3 The y-coordinate of vertex 3 */
|
||||
public void fillTriangle (int x1, int y1, int x2, int y2, int x3, int y3) {
|
||||
context.beginPath();
|
||||
context.moveTo(x1,y1);
|
||||
context.lineTo(x2,y2);
|
||||
context.lineTo(x3,y3);
|
||||
context.lineTo(x1,y1);
|
||||
context.fill();
|
||||
context.closePath();
|
||||
}
|
||||
|
||||
/** Returns the 32-bit RGBA8888 value of the pixel at x, y. For Alpha formats the RGB components will be one.
|
||||
*
|
||||
* @param x The x-coordinate
|
||||
* @param y The y-coordinate
|
||||
* @return The pixel color in RGBA8888 format. */
|
||||
public int getPixel (int x, int y) {
|
||||
if (pixels == null) pixels = context.getImageData(0, 0, width, height).getData();
|
||||
int i = x * 4 + y * width * 4;
|
||||
int r = pixels.get(i + 0) & 0xff;
|
||||
int g = pixels.get(i + 1) & 0xff;
|
||||
int b = pixels.get(i + 2) & 0xff;
|
||||
int a = pixels.get(i + 3) & 0xff;
|
||||
return (r << 24) | (g << 16) | (b << 8) | (a);
|
||||
}
|
||||
|
||||
/** Draws a pixel at the given location with the current color.
|
||||
*
|
||||
* @param x the x-coordinate
|
||||
* @param y the y-coordinate */
|
||||
public void drawPixel (int x, int y) {
|
||||
context.fillRect(x, y, 1, 1);
|
||||
}
|
||||
|
||||
/** Draws a pixel at the given location with the given color.
|
||||
*
|
||||
* @param x the x-coordinate
|
||||
* @param y the y-coordinate
|
||||
* @param color the color in RGBA8888 format. */
|
||||
public void drawPixel (int x, int y, int color) {
|
||||
setColor(color);
|
||||
drawPixel(x, y);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,62 +1,62 @@
|
||||
/*
|
||||
* Copyright 2014 Hannes Janetzek
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.tiling.source.geojson;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.oscim.core.MapElement;
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.tiling.ITileDataSource;
|
||||
import org.oscim.tiling.source.JsonTileDataSource;
|
||||
import org.oscim.tiling.source.UrlTileSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public abstract class GeoJsonTileSource extends UrlTileSource {
|
||||
static final Logger log = LoggerFactory.getLogger(GeoJsonTileSource.class);
|
||||
|
||||
public GeoJsonTileSource(String url) {
|
||||
super(url, "/{Z}/{X}/{Y}.json");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITileDataSource getDataSource() {
|
||||
return new JsonTileDataSource(this);
|
||||
}
|
||||
|
||||
public Tag getFeatureTag() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** allow overriding tag handling */
|
||||
public abstract void decodeTags(MapElement mapElement, Map<String, Object> properties);
|
||||
|
||||
public Tag rewriteTag(String key, Object value) {
|
||||
|
||||
if (value == null)
|
||||
return null;
|
||||
|
||||
String val = (value instanceof String) ? (String) value : String.valueOf(value);
|
||||
|
||||
return new Tag(key, val);
|
||||
}
|
||||
|
||||
/** modify mapElement before process() */
|
||||
public void postGeomHook(MapElement mapElement) {
|
||||
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2014 Hannes Janetzek
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.tiling.source.geojson;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.oscim.core.MapElement;
|
||||
import org.oscim.core.Tag;
|
||||
import org.oscim.tiling.ITileDataSource;
|
||||
import org.oscim.tiling.source.JsonTileDataSource;
|
||||
import org.oscim.tiling.source.UrlTileSource;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public abstract class GeoJsonTileSource extends UrlTileSource {
|
||||
static final Logger log = LoggerFactory.getLogger(GeoJsonTileSource.class);
|
||||
|
||||
public GeoJsonTileSource(String url) {
|
||||
super(url, "/{Z}/{X}/{Y}.json");
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITileDataSource getDataSource() {
|
||||
return new JsonTileDataSource(this);
|
||||
}
|
||||
|
||||
public Tag getFeatureTag() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** allow overriding tag handling */
|
||||
public abstract void decodeTags(MapElement mapElement, Map<String, Object> properties);
|
||||
|
||||
public Tag rewriteTag(String key, Object value) {
|
||||
|
||||
if (value == null)
|
||||
return null;
|
||||
|
||||
String val = (value instanceof String) ? (String) value : String.valueOf(value);
|
||||
|
||||
return new Tag(key, val);
|
||||
}
|
||||
|
||||
/** modify mapElement before process() */
|
||||
public void postGeomHook(MapElement mapElement) {
|
||||
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,259 +1,259 @@
|
||||
/*
|
||||
* Copyright 2012 osmdroid authors: Nicolas Gramlich, Theodore Hong, Fred Eisele
|
||||
*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.layers.marker;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.oscim.core.Box;
|
||||
import org.oscim.core.Point;
|
||||
import org.oscim.event.Gesture;
|
||||
import org.oscim.event.GestureListener;
|
||||
import org.oscim.event.MotionEvent;
|
||||
import org.oscim.map.Map;
|
||||
import org.oscim.map.Viewport;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ItemizedLayer<Item extends MarkerItem> extends MarkerLayer<Item>
|
||||
implements GestureListener {
|
||||
|
||||
static final Logger log = LoggerFactory.getLogger(ItemizedLayer.class);
|
||||
|
||||
protected final List<Item> mItemList;
|
||||
protected final Point mTmpPoint = new Point();
|
||||
protected OnItemGestureListener<Item> mOnItemGestureListener;
|
||||
protected int mDrawnItemsLimit = Integer.MAX_VALUE;
|
||||
|
||||
public ItemizedLayer(Map map, MarkerSymbol defaulMarker) {
|
||||
this(map, new ArrayList<Item>(), defaulMarker, null);
|
||||
}
|
||||
|
||||
public ItemizedLayer(Map map, List<Item> list,
|
||||
MarkerSymbol defaultMarker,
|
||||
OnItemGestureListener<Item> listener) {
|
||||
|
||||
super(map, defaultMarker);
|
||||
|
||||
mItemList = list;
|
||||
mOnItemGestureListener = listener;
|
||||
populate();
|
||||
}
|
||||
|
||||
public void setOnItemGestureListener(OnItemGestureListener<Item> listener) {
|
||||
mOnItemGestureListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Item createItem(int index) {
|
||||
return mItemList.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return Math.min(mItemList.size(), mDrawnItemsLimit);
|
||||
}
|
||||
|
||||
public boolean addItem(Item item) {
|
||||
final boolean result = mItemList.add(item);
|
||||
populate();
|
||||
return result;
|
||||
}
|
||||
|
||||
public void addItem(int location, Item item) {
|
||||
mItemList.add(location, item);
|
||||
}
|
||||
|
||||
public boolean addItems(List<Item> items) {
|
||||
final boolean result = mItemList.addAll(items);
|
||||
populate();
|
||||
return result;
|
||||
}
|
||||
|
||||
public void removeAllItems() {
|
||||
removeAllItems(true);
|
||||
}
|
||||
|
||||
public void removeAllItems(boolean withPopulate) {
|
||||
mItemList.clear();
|
||||
if (withPopulate) {
|
||||
populate();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean removeItem(Item item) {
|
||||
final boolean result = mItemList.remove(item);
|
||||
populate();
|
||||
return result;
|
||||
}
|
||||
|
||||
public Item removeItem(int position) {
|
||||
final Item result = mItemList.remove(position);
|
||||
populate();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Each of these methods performs a item sensitive check. If the item is
|
||||
* located its corresponding method is called. The result of the call is
|
||||
* returned. Helper methods are provided so that child classes may more
|
||||
* easily override behavior without resorting to overriding the
|
||||
* ItemGestureListener methods.
|
||||
*/
|
||||
// @Override
|
||||
// public boolean onTap(MotionEvent event, MapPosition pos) {
|
||||
// return activateSelectedItems(event, mActiveItemSingleTap);
|
||||
// }
|
||||
|
||||
protected boolean onSingleTapUpHelper(int index, Item item) {
|
||||
return mOnItemGestureListener.onItemSingleTapUp(index, item);
|
||||
}
|
||||
|
||||
private final ActiveItem mActiveItemSingleTap = new ActiveItem() {
|
||||
@Override
|
||||
public boolean run(int index) {
|
||||
final ItemizedLayer<Item> that = ItemizedLayer.this;
|
||||
if (mOnItemGestureListener == null) {
|
||||
return false;
|
||||
}
|
||||
return onSingleTapUpHelper(index, that.mItemList.get(index));
|
||||
}
|
||||
};
|
||||
|
||||
protected boolean onLongPressHelper(int index, Item item) {
|
||||
return this.mOnItemGestureListener.onItemLongPress(index, item);
|
||||
}
|
||||
|
||||
private final ActiveItem mActiveItemLongPress = new ActiveItem() {
|
||||
@Override
|
||||
public boolean run(final int index) {
|
||||
final ItemizedLayer<Item> that = ItemizedLayer.this;
|
||||
if (that.mOnItemGestureListener == null) {
|
||||
return false;
|
||||
}
|
||||
return onLongPressHelper(index, that.mItemList.get(index));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* When a content sensitive action is performed the content item needs to be
|
||||
* identified. This method does that and then performs the assigned task on
|
||||
* that item.
|
||||
*
|
||||
* @return true if event is handled false otherwise
|
||||
*/
|
||||
protected boolean activateSelectedItems(MotionEvent event, ActiveItem task) {
|
||||
int size = mItemList.size();
|
||||
if (size == 0)
|
||||
return false;
|
||||
|
||||
int eventX = (int) event.getX() - mMap.getWidth() / 2;
|
||||
int eventY = (int) event.getY() - mMap.getHeight() / 2;
|
||||
Viewport mapPosition = mMap.viewport();
|
||||
|
||||
Box box = mapPosition.getBBox(null, 128);
|
||||
box.map2mercator();
|
||||
box.scale(1E6);
|
||||
|
||||
int nearest = -1;
|
||||
int inside = -1;
|
||||
double insideY = -Double.MAX_VALUE;
|
||||
|
||||
/* squared dist: 50*50 pixel ~ 2mm on 400dpi */
|
||||
double dist = 2500;
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
Item item = mItemList.get(i);
|
||||
|
||||
if (!box.contains(item.getPoint().longitudeE6,
|
||||
item.getPoint().latitudeE6))
|
||||
continue;
|
||||
|
||||
mapPosition.toScreenPoint(item.getPoint(), mTmpPoint);
|
||||
|
||||
float dx = (float) (mTmpPoint.x - eventX);
|
||||
float dy = (float) (mTmpPoint.y - eventY);
|
||||
|
||||
MarkerSymbol it = item.getMarker();
|
||||
if (it == null)
|
||||
it = mMarkerRenderer.mDefaultMarker;
|
||||
|
||||
if (it.isInside(dx, dy)) {
|
||||
if (mTmpPoint.y > insideY) {
|
||||
insideY = mTmpPoint.y;
|
||||
inside = i;
|
||||
}
|
||||
}
|
||||
if (inside >= 0)
|
||||
continue;
|
||||
|
||||
double d = dx * dx + dy * dy;
|
||||
if (d > dist)
|
||||
continue;
|
||||
|
||||
dist = d;
|
||||
nearest = i;
|
||||
}
|
||||
|
||||
if (inside >= 0)
|
||||
nearest = inside;
|
||||
|
||||
if (nearest >= 0 && task.run(nearest)) {
|
||||
mMarkerRenderer.update();
|
||||
mMap.render();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* When the item is touched one of these methods may be invoked depending on
|
||||
* the type of touch. Each of them returns true if the event was completely
|
||||
* handled.
|
||||
*/
|
||||
public static interface OnItemGestureListener<T> {
|
||||
public boolean onItemSingleTapUp(int index, T item);
|
||||
|
||||
public boolean onItemLongPress(int index, T item);
|
||||
}
|
||||
|
||||
public static interface ActiveItem {
|
||||
public boolean run(int aIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onGesture(Gesture g, MotionEvent e) {
|
||||
if (g instanceof Gesture.Tap)
|
||||
return activateSelectedItems(e, mActiveItemSingleTap);
|
||||
|
||||
if (g instanceof Gesture.LongPress)
|
||||
return activateSelectedItems(e, mActiveItemLongPress);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Item getByUid(Object uid) {
|
||||
for (Item it : mItemList)
|
||||
if (it.getUid() == uid)
|
||||
return it;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2012 osmdroid authors: Nicolas Gramlich, Theodore Hong, Fred Eisele
|
||||
*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 devemux86
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.oscim.layers.marker;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.oscim.core.Box;
|
||||
import org.oscim.core.Point;
|
||||
import org.oscim.event.Gesture;
|
||||
import org.oscim.event.GestureListener;
|
||||
import org.oscim.event.MotionEvent;
|
||||
import org.oscim.map.Map;
|
||||
import org.oscim.map.Viewport;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ItemizedLayer<Item extends MarkerItem> extends MarkerLayer<Item>
|
||||
implements GestureListener {
|
||||
|
||||
static final Logger log = LoggerFactory.getLogger(ItemizedLayer.class);
|
||||
|
||||
protected final List<Item> mItemList;
|
||||
protected final Point mTmpPoint = new Point();
|
||||
protected OnItemGestureListener<Item> mOnItemGestureListener;
|
||||
protected int mDrawnItemsLimit = Integer.MAX_VALUE;
|
||||
|
||||
public ItemizedLayer(Map map, MarkerSymbol defaulMarker) {
|
||||
this(map, new ArrayList<Item>(), defaulMarker, null);
|
||||
}
|
||||
|
||||
public ItemizedLayer(Map map, List<Item> list,
|
||||
MarkerSymbol defaultMarker,
|
||||
OnItemGestureListener<Item> listener) {
|
||||
|
||||
super(map, defaultMarker);
|
||||
|
||||
mItemList = list;
|
||||
mOnItemGestureListener = listener;
|
||||
populate();
|
||||
}
|
||||
|
||||
public void setOnItemGestureListener(OnItemGestureListener<Item> listener) {
|
||||
mOnItemGestureListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Item createItem(int index) {
|
||||
return mItemList.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return Math.min(mItemList.size(), mDrawnItemsLimit);
|
||||
}
|
||||
|
||||
public boolean addItem(Item item) {
|
||||
final boolean result = mItemList.add(item);
|
||||
populate();
|
||||
return result;
|
||||
}
|
||||
|
||||
public void addItem(int location, Item item) {
|
||||
mItemList.add(location, item);
|
||||
}
|
||||
|
||||
public boolean addItems(List<Item> items) {
|
||||
final boolean result = mItemList.addAll(items);
|
||||
populate();
|
||||
return result;
|
||||
}
|
||||
|
||||
public void removeAllItems() {
|
||||
removeAllItems(true);
|
||||
}
|
||||
|
||||
public void removeAllItems(boolean withPopulate) {
|
||||
mItemList.clear();
|
||||
if (withPopulate) {
|
||||
populate();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean removeItem(Item item) {
|
||||
final boolean result = mItemList.remove(item);
|
||||
populate();
|
||||
return result;
|
||||
}
|
||||
|
||||
public Item removeItem(int position) {
|
||||
final Item result = mItemList.remove(position);
|
||||
populate();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Each of these methods performs a item sensitive check. If the item is
|
||||
* located its corresponding method is called. The result of the call is
|
||||
* returned. Helper methods are provided so that child classes may more
|
||||
* easily override behavior without resorting to overriding the
|
||||
* ItemGestureListener methods.
|
||||
*/
|
||||
// @Override
|
||||
// public boolean onTap(MotionEvent event, MapPosition pos) {
|
||||
// return activateSelectedItems(event, mActiveItemSingleTap);
|
||||
// }
|
||||
|
||||
protected boolean onSingleTapUpHelper(int index, Item item) {
|
||||
return mOnItemGestureListener.onItemSingleTapUp(index, item);
|
||||
}
|
||||
|
||||
private final ActiveItem mActiveItemSingleTap = new ActiveItem() {
|
||||
@Override
|
||||
public boolean run(int index) {
|
||||
final ItemizedLayer<Item> that = ItemizedLayer.this;
|
||||
if (mOnItemGestureListener == null) {
|
||||
return false;
|
||||
}
|
||||
return onSingleTapUpHelper(index, that.mItemList.get(index));
|
||||
}
|
||||
};
|
||||
|
||||
protected boolean onLongPressHelper(int index, Item item) {
|
||||
return this.mOnItemGestureListener.onItemLongPress(index, item);
|
||||
}
|
||||
|
||||
private final ActiveItem mActiveItemLongPress = new ActiveItem() {
|
||||
@Override
|
||||
public boolean run(final int index) {
|
||||
final ItemizedLayer<Item> that = ItemizedLayer.this;
|
||||
if (that.mOnItemGestureListener == null) {
|
||||
return false;
|
||||
}
|
||||
return onLongPressHelper(index, that.mItemList.get(index));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* When a content sensitive action is performed the content item needs to be
|
||||
* identified. This method does that and then performs the assigned task on
|
||||
* that item.
|
||||
*
|
||||
* @return true if event is handled false otherwise
|
||||
*/
|
||||
protected boolean activateSelectedItems(MotionEvent event, ActiveItem task) {
|
||||
int size = mItemList.size();
|
||||
if (size == 0)
|
||||
return false;
|
||||
|
||||
int eventX = (int) event.getX() - mMap.getWidth() / 2;
|
||||
int eventY = (int) event.getY() - mMap.getHeight() / 2;
|
||||
Viewport mapPosition = mMap.viewport();
|
||||
|
||||
Box box = mapPosition.getBBox(null, 128);
|
||||
box.map2mercator();
|
||||
box.scale(1E6);
|
||||
|
||||
int nearest = -1;
|
||||
int inside = -1;
|
||||
double insideY = -Double.MAX_VALUE;
|
||||
|
||||
/* squared dist: 50*50 pixel ~ 2mm on 400dpi */
|
||||
double dist = 2500;
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
Item item = mItemList.get(i);
|
||||
|
||||
if (!box.contains(item.getPoint().longitudeE6,
|
||||
item.getPoint().latitudeE6))
|
||||
continue;
|
||||
|
||||
mapPosition.toScreenPoint(item.getPoint(), mTmpPoint);
|
||||
|
||||
float dx = (float) (mTmpPoint.x - eventX);
|
||||
float dy = (float) (mTmpPoint.y - eventY);
|
||||
|
||||
MarkerSymbol it = item.getMarker();
|
||||
if (it == null)
|
||||
it = mMarkerRenderer.mDefaultMarker;
|
||||
|
||||
if (it.isInside(dx, dy)) {
|
||||
if (mTmpPoint.y > insideY) {
|
||||
insideY = mTmpPoint.y;
|
||||
inside = i;
|
||||
}
|
||||
}
|
||||
if (inside >= 0)
|
||||
continue;
|
||||
|
||||
double d = dx * dx + dy * dy;
|
||||
if (d > dist)
|
||||
continue;
|
||||
|
||||
dist = d;
|
||||
nearest = i;
|
||||
}
|
||||
|
||||
if (inside >= 0)
|
||||
nearest = inside;
|
||||
|
||||
if (nearest >= 0 && task.run(nearest)) {
|
||||
mMarkerRenderer.update();
|
||||
mMap.render();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* When the item is touched one of these methods may be invoked depending on
|
||||
* the type of touch. Each of them returns true if the event was completely
|
||||
* handled.
|
||||
*/
|
||||
public static interface OnItemGestureListener<T> {
|
||||
public boolean onItemSingleTapUp(int index, T item);
|
||||
|
||||
public boolean onItemLongPress(int index, T item);
|
||||
}
|
||||
|
||||
public static interface ActiveItem {
|
||||
public boolean run(int aIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onGesture(Gesture g, MotionEvent e) {
|
||||
if (g instanceof Gesture.Tap)
|
||||
return activateSelectedItems(e, mActiveItemSingleTap);
|
||||
|
||||
if (g instanceof Gesture.LongPress)
|
||||
return activateSelectedItems(e, mActiveItemLongPress);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public Item getByUid(Object uid) {
|
||||
for (Item it : mItemList)
|
||||
if (it.getUid() == uid)
|
||||
return it;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -1,94 +1,94 @@
|
||||
/*
|
||||
* Copyright 2012 osmdroid authors:
|
||||
* Copyright 2012 Nicolas Gramlich
|
||||
* Copyright 2012 Theodore Hong
|
||||
* Copyright 2012 Fred Eisele
|
||||
*
|
||||
* Copyright 2014 Hannes Janetzek
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.oscim.layers.marker;
|
||||
|
||||
import org.oscim.core.GeoPoint;
|
||||
|
||||
/**
|
||||
* Immutable class describing a GeoPoint with a Title and a Description.
|
||||
*/
|
||||
public class MarkerItem {
|
||||
|
||||
public static final int ITEM_STATE_FOCUSED_MASK = 4;
|
||||
public static final int ITEM_STATE_PRESSED_MASK = 1;
|
||||
public static final int ITEM_STATE_SELECTED_MASK = 2;
|
||||
|
||||
/**
|
||||
* Indicates a hotspot for an area. This is where the origin (0,0) of a
|
||||
* point will be located relative to the area. In otherwords this acts as an
|
||||
* offset. NONE indicates that no adjustment should be made.
|
||||
*/
|
||||
public enum HotspotPlace {
|
||||
NONE, CENTER, BOTTOM_CENTER,
|
||||
TOP_CENTER, RIGHT_CENTER, LEFT_CENTER,
|
||||
UPPER_RIGHT_CORNER, LOWER_RIGHT_CORNER,
|
||||
UPPER_LEFT_CORNER, LOWER_LEFT_CORNER
|
||||
}
|
||||
|
||||
public final Object uid;
|
||||
public final String title;
|
||||
public final String description;
|
||||
public final GeoPoint geoPoint;
|
||||
protected MarkerSymbol mMarker;
|
||||
|
||||
/**
|
||||
* @param title
|
||||
* this should be <b>singleLine</b> (no <code>'\n'</code> )
|
||||
* @param description
|
||||
* a <b>multiLine</b> description ( <code>'\n'</code> possible)
|
||||
*/
|
||||
public MarkerItem(String title, String description, GeoPoint geoPoint) {
|
||||
this(null, title, description, geoPoint);
|
||||
}
|
||||
|
||||
public MarkerItem(Object uid, String title, String description, GeoPoint geoPoint) {
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
this.geoPoint = geoPoint;
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
public Object getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getSnippet() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public GeoPoint getPoint() {
|
||||
return geoPoint;
|
||||
}
|
||||
|
||||
public MarkerSymbol getMarker() {
|
||||
return mMarker;
|
||||
}
|
||||
|
||||
public void setMarker(MarkerSymbol marker) {
|
||||
mMarker = marker;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2012 osmdroid authors:
|
||||
* Copyright 2012 Nicolas Gramlich
|
||||
* Copyright 2012 Theodore Hong
|
||||
* Copyright 2012 Fred Eisele
|
||||
*
|
||||
* Copyright 2014 Hannes Janetzek
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.oscim.layers.marker;
|
||||
|
||||
import org.oscim.core.GeoPoint;
|
||||
|
||||
/**
|
||||
* Immutable class describing a GeoPoint with a Title and a Description.
|
||||
*/
|
||||
public class MarkerItem {
|
||||
|
||||
public static final int ITEM_STATE_FOCUSED_MASK = 4;
|
||||
public static final int ITEM_STATE_PRESSED_MASK = 1;
|
||||
public static final int ITEM_STATE_SELECTED_MASK = 2;
|
||||
|
||||
/**
|
||||
* Indicates a hotspot for an area. This is where the origin (0,0) of a
|
||||
* point will be located relative to the area. In otherwords this acts as an
|
||||
* offset. NONE indicates that no adjustment should be made.
|
||||
*/
|
||||
public enum HotspotPlace {
|
||||
NONE, CENTER, BOTTOM_CENTER,
|
||||
TOP_CENTER, RIGHT_CENTER, LEFT_CENTER,
|
||||
UPPER_RIGHT_CORNER, LOWER_RIGHT_CORNER,
|
||||
UPPER_LEFT_CORNER, LOWER_LEFT_CORNER
|
||||
}
|
||||
|
||||
public final Object uid;
|
||||
public final String title;
|
||||
public final String description;
|
||||
public final GeoPoint geoPoint;
|
||||
protected MarkerSymbol mMarker;
|
||||
|
||||
/**
|
||||
* @param title
|
||||
* this should be <b>singleLine</b> (no <code>'\n'</code> )
|
||||
* @param description
|
||||
* a <b>multiLine</b> description ( <code>'\n'</code> possible)
|
||||
*/
|
||||
public MarkerItem(String title, String description, GeoPoint geoPoint) {
|
||||
this(null, title, description, geoPoint);
|
||||
}
|
||||
|
||||
public MarkerItem(Object uid, String title, String description, GeoPoint geoPoint) {
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
this.geoPoint = geoPoint;
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
public Object getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public String getSnippet() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public GeoPoint getPoint() {
|
||||
return geoPoint;
|
||||
}
|
||||
|
||||
public MarkerSymbol getMarker() {
|
||||
return mMarker;
|
||||
}
|
||||
|
||||
public void setMarker(MarkerSymbol marker) {
|
||||
mMarker = marker;
|
||||
}
|
||||
}
|
||||
|
@ -1,115 +1,115 @@
|
||||
/*
|
||||
* Copyright 2012 osmdroid authors:
|
||||
* Copyright 2012 Nicolas Gramlich
|
||||
* Copyright 2012 Theodore Hong
|
||||
* Copyright 2012 Fred Eisele
|
||||
*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.oscim.layers.marker;
|
||||
|
||||
import org.oscim.core.Point;
|
||||
import org.oscim.layers.Layer;
|
||||
import org.oscim.map.Map;
|
||||
|
||||
/**
|
||||
* Draws a list of {@link MarkerItem} as markers to a map. The item with the
|
||||
* lowest index is drawn as last and therefore the 'topmost' marker. It also
|
||||
* gets checked for onTap first. This class is generic, because you then you get
|
||||
* your custom item-class passed back in onTap(). << TODO
|
||||
*/
|
||||
public abstract class MarkerLayer<Item extends MarkerItem> extends Layer {
|
||||
|
||||
protected final MarkerRenderer mMarkerRenderer;
|
||||
protected Item mFocusedItem;
|
||||
|
||||
/**
|
||||
* Method by which subclasses create the actual Items. This will only be
|
||||
* called from populate() we'll cache them for later use.
|
||||
*/
|
||||
protected abstract Item createItem(int i);
|
||||
|
||||
/**
|
||||
* The number of items in this overlay.
|
||||
*/
|
||||
public abstract int size();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public MarkerLayer(Map map, MarkerSymbol defaultSymbol) {
|
||||
super(map);
|
||||
|
||||
mMarkerRenderer = new MarkerRenderer((MarkerLayer<MarkerItem>) this, defaultSymbol);
|
||||
mRenderer = mMarkerRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to perform all processing on a new ItemizedOverlay.
|
||||
* Subclasses provide Items through the createItem(int) method. The subclass
|
||||
* should call this as soon as it has data, before anything else gets
|
||||
* called.
|
||||
*/
|
||||
protected final void populate() {
|
||||
mMarkerRenderer.populate(size());
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* If the given Item is found in the overlay, force it to be the current
|
||||
* focus-bearer. Any registered {link ItemizedLayer#OnFocusChangeListener}
|
||||
* will be notified. This does not move the map, so if the Item isn't
|
||||
* already centered, the user may get confused. If the Item is not found,
|
||||
* this is a no-op. You can also pass null to remove focus.
|
||||
*
|
||||
* @param item
|
||||
*/
|
||||
public void setFocus(Item item) {
|
||||
mFocusedItem = item;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the currently-focused item, or null if no item is currently
|
||||
* focused.
|
||||
*/
|
||||
public Item getFocus() {
|
||||
return mFocusedItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* Interface definition for overlays that contain items that can be snapped
|
||||
* to (for example, when the user invokes a zoom, this could be called
|
||||
* allowing the user to snap the zoom to an interesting point.)
|
||||
*/
|
||||
public interface Snappable {
|
||||
|
||||
/**
|
||||
* Checks to see if the given x and y are close enough to an item
|
||||
* resulting in snapping the current action (e.g. zoom) to the item.
|
||||
*
|
||||
* @param x
|
||||
* The x in screen coordinates.
|
||||
* @param y
|
||||
* The y in screen coordinates.
|
||||
* @param snapPoint
|
||||
* To be filled with the the interesting point (in screen
|
||||
* coordinates) that is closest to the given x and y. Can be
|
||||
* untouched if not snapping.
|
||||
* @return Whether or not to snap to the interesting point.
|
||||
*/
|
||||
boolean onSnapToItem(int x, int y, Point snapPoint);
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2012 osmdroid authors:
|
||||
* Copyright 2012 Nicolas Gramlich
|
||||
* Copyright 2012 Theodore Hong
|
||||
* Copyright 2012 Fred Eisele
|
||||
*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.oscim.layers.marker;
|
||||
|
||||
import org.oscim.core.Point;
|
||||
import org.oscim.layers.Layer;
|
||||
import org.oscim.map.Map;
|
||||
|
||||
/**
|
||||
* Draws a list of {@link MarkerItem} as markers to a map. The item with the
|
||||
* lowest index is drawn as last and therefore the 'topmost' marker. It also
|
||||
* gets checked for onTap first. This class is generic, because you then you get
|
||||
* your custom item-class passed back in onTap(). << TODO
|
||||
*/
|
||||
public abstract class MarkerLayer<Item extends MarkerItem> extends Layer {
|
||||
|
||||
protected final MarkerRenderer mMarkerRenderer;
|
||||
protected Item mFocusedItem;
|
||||
|
||||
/**
|
||||
* Method by which subclasses create the actual Items. This will only be
|
||||
* called from populate() we'll cache them for later use.
|
||||
*/
|
||||
protected abstract Item createItem(int i);
|
||||
|
||||
/**
|
||||
* The number of items in this overlay.
|
||||
*/
|
||||
public abstract int size();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public MarkerLayer(Map map, MarkerSymbol defaultSymbol) {
|
||||
super(map);
|
||||
|
||||
mMarkerRenderer = new MarkerRenderer((MarkerLayer<MarkerItem>) this, defaultSymbol);
|
||||
mRenderer = mMarkerRenderer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to perform all processing on a new ItemizedOverlay.
|
||||
* Subclasses provide Items through the createItem(int) method. The subclass
|
||||
* should call this as soon as it has data, before anything else gets
|
||||
* called.
|
||||
*/
|
||||
protected final void populate() {
|
||||
mMarkerRenderer.populate(size());
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* If the given Item is found in the overlay, force it to be the current
|
||||
* focus-bearer. Any registered {link ItemizedLayer#OnFocusChangeListener}
|
||||
* will be notified. This does not move the map, so if the Item isn't
|
||||
* already centered, the user may get confused. If the Item is not found,
|
||||
* this is a no-op. You can also pass null to remove focus.
|
||||
*
|
||||
* @param item
|
||||
*/
|
||||
public void setFocus(Item item) {
|
||||
mFocusedItem = item;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the currently-focused item, or null if no item is currently
|
||||
* focused.
|
||||
*/
|
||||
public Item getFocus() {
|
||||
return mFocusedItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* Interface definition for overlays that contain items that can be snapped
|
||||
* to (for example, when the user invokes a zoom, this could be called
|
||||
* allowing the user to snap the zoom to an interesting point.)
|
||||
*/
|
||||
public interface Snappable {
|
||||
|
||||
/**
|
||||
* Checks to see if the given x and y are close enough to an item
|
||||
* resulting in snapping the current action (e.g. zoom) to the item.
|
||||
*
|
||||
* @param x
|
||||
* The x in screen coordinates.
|
||||
* @param y
|
||||
* The y in screen coordinates.
|
||||
* @param snapPoint
|
||||
* To be filled with the the interesting point (in screen
|
||||
* coordinates) that is closest to the given x and y. Can be
|
||||
* untouched if not snapping.
|
||||
* @return Whether or not to snap to the interesting point.
|
||||
*/
|
||||
boolean onSnapToItem(int x, int y, Point snapPoint);
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,420 +1,420 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011 Mario Zechner <badlogicgames@gmail.com>
|
||||
* Copyright 2011 Nathan Sweet <nathan.sweet@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
******************************************************************************/
|
||||
|
||||
package org.oscim.utils.math;
|
||||
|
||||
|
||||
/**
|
||||
* Takes a linear value in the range of 0-1 and outputs a (usually) non-linear,
|
||||
* interpolated value.
|
||||
*/
|
||||
public abstract class Interpolation {
|
||||
/** @param a Alpha value between 0 and 1. */
|
||||
abstract public float apply(float a);
|
||||
|
||||
/** @param a Alpha value between 0 and 1. */
|
||||
public float apply(float start, float end, float a) {
|
||||
return start + (end - start) * apply(a);
|
||||
}
|
||||
|
||||
static public final Interpolation linear = new Interpolation() {
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return a;
|
||||
}
|
||||
};
|
||||
|
||||
static public final Interpolation fade = new Interpolation() {
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return MathUtils.clamp(a * a * a * (a * (a * 6 - 15) + 10), 0, 1);
|
||||
}
|
||||
};
|
||||
|
||||
static public final Pow pow2 = new Pow(2);
|
||||
static public final PowIn pow2In = new PowIn(2);
|
||||
static public final PowOut pow2Out = new PowOut(2);
|
||||
|
||||
static public final Pow pow3 = new Pow(3);
|
||||
static public final PowIn pow3In = new PowIn(3);
|
||||
static public final PowOut pow3Out = new PowOut(3);
|
||||
|
||||
static public final Pow pow4 = new Pow(4);
|
||||
static public final PowIn pow4In = new PowIn(4);
|
||||
static public final PowOut pow4Out = new PowOut(4);
|
||||
|
||||
static public final Pow pow5 = new Pow(5);
|
||||
static public final PowIn pow5In = new PowIn(5);
|
||||
static public final PowOut pow5Out = new PowOut(5);
|
||||
|
||||
static public final Interpolation sine = new Interpolation() {
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return (1 - MathUtils.cos(a * MathUtils.PI)) / 2;
|
||||
}
|
||||
};
|
||||
|
||||
static public final Interpolation sineIn = new Interpolation() {
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return 1 - MathUtils.cos(a * MathUtils.PI / 2);
|
||||
}
|
||||
};
|
||||
|
||||
static public final Interpolation sineOut = new Interpolation() {
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return MathUtils.sin(a * MathUtils.PI / 2);
|
||||
}
|
||||
};
|
||||
|
||||
static public final Interpolation exp10 = new Exp(2, 10);
|
||||
static public final Interpolation exp10In = new ExpIn(2, 10);
|
||||
static public final Interpolation exp10Out = new ExpOut(2, 10);
|
||||
|
||||
static public final Interpolation exp5 = new Exp(2, 5);
|
||||
static public final Interpolation exp5In = new ExpIn(2, 5);
|
||||
static public final Interpolation exp5Out = new ExpOut(2, 5);
|
||||
|
||||
static public final Interpolation circle = new Interpolation() {
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
if (a <= 0.5f) {
|
||||
a *= 2;
|
||||
return (1 - (float) Math.sqrt(1 - a * a)) / 2;
|
||||
}
|
||||
a--;
|
||||
a *= 2;
|
||||
return ((float) Math.sqrt(1 - a * a) + 1) / 2;
|
||||
}
|
||||
};
|
||||
|
||||
static public final Interpolation circleIn = new Interpolation() {
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return 1 - (float) Math.sqrt(1 - a * a);
|
||||
}
|
||||
};
|
||||
|
||||
static public final Interpolation circleOut = new Interpolation() {
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
a--;
|
||||
return (float) Math.sqrt(1 - a * a);
|
||||
}
|
||||
};
|
||||
|
||||
static public final Elastic elastic = new Elastic(2, 10);
|
||||
static public final Elastic elasticIn = new ElasticIn(2, 10);
|
||||
static public final Elastic elasticOut = new ElasticOut(2, 10);
|
||||
|
||||
static public final Interpolation swing = new Swing(1.5f);
|
||||
static public final Interpolation swingIn = new SwingIn(2f);
|
||||
static public final Interpolation swingOut = new SwingOut(2f);
|
||||
|
||||
static public final Interpolation bounce = new Bounce(4);
|
||||
static public final Interpolation bounceIn = new BounceIn(4);
|
||||
static public final Interpolation bounceOut = new BounceOut(4);
|
||||
|
||||
//
|
||||
|
||||
static public class Pow extends Interpolation {
|
||||
final int power;
|
||||
|
||||
public Pow(int power) {
|
||||
this.power = power;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
if (a <= 0.5f)
|
||||
return (float) Math.pow(a * 2, power) / 2;
|
||||
return (float) Math.pow((a - 1) * 2, power) / (power % 2 == 0 ? -2 : 2) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
static public class PowIn extends Pow {
|
||||
public PowIn(int power) {
|
||||
super(power);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return (float) Math.pow(a, power);
|
||||
}
|
||||
}
|
||||
|
||||
static public class PowOut extends Pow {
|
||||
public PowOut(int power) {
|
||||
super(power);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return (float) Math.pow(a - 1, power) * (power % 2 == 0 ? -1 : 1) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
static public class Exp extends Interpolation {
|
||||
final float value, power, min, scale;
|
||||
|
||||
public Exp(float value, float power) {
|
||||
this.value = value;
|
||||
this.power = power;
|
||||
min = (float) Math.pow(value, -power);
|
||||
scale = 1 / (1 - min);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
if (a <= 0.5f)
|
||||
return ((float) Math.pow(value, power * (a * 2 - 1)) - min) * scale / 2;
|
||||
return (2 - ((float) Math.pow(value, -power * (a * 2 - 1)) - min) * scale) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
static public class ExpIn extends Exp {
|
||||
public ExpIn(float value, float power) {
|
||||
super(value, power);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return ((float) Math.pow(value, power * (a - 1)) - min) * scale;
|
||||
}
|
||||
}
|
||||
|
||||
static public class ExpOut extends Exp {
|
||||
public ExpOut(float value, float power) {
|
||||
super(value, power);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return 1 - ((float) Math.pow(value, -power * a) - min) * scale;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
static public class Elastic extends Interpolation {
|
||||
final float value, power;
|
||||
|
||||
public Elastic(float value, float power) {
|
||||
this.value = value;
|
||||
this.power = power;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
if (a <= 0.5f) {
|
||||
a *= 2;
|
||||
return (float) Math.pow(value, power * (a - 1)) * MathUtils.sin(a * 20) * 1.0955f
|
||||
/ 2;
|
||||
}
|
||||
a = 1 - a;
|
||||
a *= 2;
|
||||
return 1 - (float) Math.pow(value, power * (a - 1)) * MathUtils.sin((a) * 20) * 1.0955f
|
||||
/ 2;
|
||||
}
|
||||
}
|
||||
|
||||
static public class ElasticIn extends Elastic {
|
||||
public ElasticIn(float value, float power) {
|
||||
super(value, power);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return (float) Math.pow(value, power * (a - 1)) * MathUtils.sin(a * 20) * 1.0955f;
|
||||
}
|
||||
}
|
||||
|
||||
static public class ElasticOut extends Elastic {
|
||||
public ElasticOut(float value, float power) {
|
||||
super(value, power);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
a = 1 - a;
|
||||
return (1 - (float) Math.pow(value, power * (a - 1)) * MathUtils.sin(a * 20) * 1.0955f);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
static public class Bounce extends BounceOut {
|
||||
public Bounce(float[] widths, float[] heights) {
|
||||
super(widths, heights);
|
||||
}
|
||||
|
||||
public Bounce(int bounces) {
|
||||
super(bounces);
|
||||
}
|
||||
|
||||
private float out(float a) {
|
||||
float test = a + widths[0] / 2;
|
||||
if (test < widths[0])
|
||||
return test / (widths[0] / 2) - 1;
|
||||
return super.apply(a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
if (a <= 0.5f)
|
||||
return (1 - out(1 - a * 2)) / 2;
|
||||
return out(a * 2 - 1) / 2 + 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
static public class BounceOut extends Interpolation {
|
||||
final float[] widths, heights;
|
||||
|
||||
public BounceOut(float[] widths, float[] heights) {
|
||||
if (widths.length != heights.length)
|
||||
throw new IllegalArgumentException("Must be the same number of widths and heights.");
|
||||
this.widths = widths;
|
||||
this.heights = heights;
|
||||
}
|
||||
|
||||
public BounceOut(int bounces) {
|
||||
if (bounces < 2 || bounces > 5)
|
||||
throw new IllegalArgumentException("bounces cannot be < 2 or > 5: " + bounces);
|
||||
widths = new float[bounces];
|
||||
heights = new float[bounces];
|
||||
heights[0] = 1;
|
||||
switch (bounces) {
|
||||
case 2:
|
||||
widths[0] = 0.6f;
|
||||
widths[1] = 0.4f;
|
||||
heights[1] = 0.33f;
|
||||
break;
|
||||
case 3:
|
||||
widths[0] = 0.4f;
|
||||
widths[1] = 0.4f;
|
||||
widths[2] = 0.2f;
|
||||
heights[1] = 0.33f;
|
||||
heights[2] = 0.1f;
|
||||
break;
|
||||
case 4:
|
||||
widths[0] = 0.34f;
|
||||
widths[1] = 0.34f;
|
||||
widths[2] = 0.2f;
|
||||
widths[3] = 0.15f;
|
||||
heights[1] = 0.26f;
|
||||
heights[2] = 0.11f;
|
||||
heights[3] = 0.03f;
|
||||
break;
|
||||
case 5:
|
||||
widths[0] = 0.3f;
|
||||
widths[1] = 0.3f;
|
||||
widths[2] = 0.2f;
|
||||
widths[3] = 0.1f;
|
||||
widths[4] = 0.1f;
|
||||
heights[1] = 0.45f;
|
||||
heights[2] = 0.3f;
|
||||
heights[3] = 0.15f;
|
||||
heights[4] = 0.06f;
|
||||
break;
|
||||
}
|
||||
widths[0] *= 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
a += widths[0] / 2;
|
||||
float width = 0, height = 0;
|
||||
for (int i = 0, n = widths.length; i < n; i++) {
|
||||
width = widths[i];
|
||||
if (a <= width) {
|
||||
height = heights[i];
|
||||
break;
|
||||
}
|
||||
a -= width;
|
||||
}
|
||||
a /= width;
|
||||
float z = 4 / width * height * a;
|
||||
return 1 - (z - z * a) * width;
|
||||
}
|
||||
}
|
||||
|
||||
static public class BounceIn extends BounceOut {
|
||||
public BounceIn(float[] widths, float[] heights) {
|
||||
super(widths, heights);
|
||||
}
|
||||
|
||||
public BounceIn(int bounces) {
|
||||
super(bounces);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return 1 - super.apply(1 - a);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
static public class Swing extends Interpolation {
|
||||
private final float scale;
|
||||
|
||||
public Swing(float scale) {
|
||||
this.scale = scale * 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
if (a <= 0.5f) {
|
||||
a *= 2;
|
||||
return a * a * ((scale + 1) * a - scale) / 2;
|
||||
}
|
||||
a--;
|
||||
a *= 2;
|
||||
return a * a * ((scale + 1) * a + scale) / 2 + 1;
|
||||
}
|
||||
}
|
||||
|
||||
static public class SwingOut extends Interpolation {
|
||||
private final float scale;
|
||||
|
||||
public SwingOut(float scale) {
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
a--;
|
||||
return a * a * ((scale + 1) * a + scale) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
static public class SwingIn extends Interpolation {
|
||||
private final float scale;
|
||||
|
||||
public SwingIn(float scale) {
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return a * a * ((scale + 1) * a - scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Copyright 2011 Mario Zechner <badlogicgames@gmail.com>
|
||||
* Copyright 2011 Nathan Sweet <nathan.sweet@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
******************************************************************************/
|
||||
|
||||
package org.oscim.utils.math;
|
||||
|
||||
|
||||
/**
|
||||
* Takes a linear value in the range of 0-1 and outputs a (usually) non-linear,
|
||||
* interpolated value.
|
||||
*/
|
||||
public abstract class Interpolation {
|
||||
/** @param a Alpha value between 0 and 1. */
|
||||
abstract public float apply(float a);
|
||||
|
||||
/** @param a Alpha value between 0 and 1. */
|
||||
public float apply(float start, float end, float a) {
|
||||
return start + (end - start) * apply(a);
|
||||
}
|
||||
|
||||
static public final Interpolation linear = new Interpolation() {
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return a;
|
||||
}
|
||||
};
|
||||
|
||||
static public final Interpolation fade = new Interpolation() {
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return MathUtils.clamp(a * a * a * (a * (a * 6 - 15) + 10), 0, 1);
|
||||
}
|
||||
};
|
||||
|
||||
static public final Pow pow2 = new Pow(2);
|
||||
static public final PowIn pow2In = new PowIn(2);
|
||||
static public final PowOut pow2Out = new PowOut(2);
|
||||
|
||||
static public final Pow pow3 = new Pow(3);
|
||||
static public final PowIn pow3In = new PowIn(3);
|
||||
static public final PowOut pow3Out = new PowOut(3);
|
||||
|
||||
static public final Pow pow4 = new Pow(4);
|
||||
static public final PowIn pow4In = new PowIn(4);
|
||||
static public final PowOut pow4Out = new PowOut(4);
|
||||
|
||||
static public final Pow pow5 = new Pow(5);
|
||||
static public final PowIn pow5In = new PowIn(5);
|
||||
static public final PowOut pow5Out = new PowOut(5);
|
||||
|
||||
static public final Interpolation sine = new Interpolation() {
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return (1 - MathUtils.cos(a * MathUtils.PI)) / 2;
|
||||
}
|
||||
};
|
||||
|
||||
static public final Interpolation sineIn = new Interpolation() {
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return 1 - MathUtils.cos(a * MathUtils.PI / 2);
|
||||
}
|
||||
};
|
||||
|
||||
static public final Interpolation sineOut = new Interpolation() {
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return MathUtils.sin(a * MathUtils.PI / 2);
|
||||
}
|
||||
};
|
||||
|
||||
static public final Interpolation exp10 = new Exp(2, 10);
|
||||
static public final Interpolation exp10In = new ExpIn(2, 10);
|
||||
static public final Interpolation exp10Out = new ExpOut(2, 10);
|
||||
|
||||
static public final Interpolation exp5 = new Exp(2, 5);
|
||||
static public final Interpolation exp5In = new ExpIn(2, 5);
|
||||
static public final Interpolation exp5Out = new ExpOut(2, 5);
|
||||
|
||||
static public final Interpolation circle = new Interpolation() {
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
if (a <= 0.5f) {
|
||||
a *= 2;
|
||||
return (1 - (float) Math.sqrt(1 - a * a)) / 2;
|
||||
}
|
||||
a--;
|
||||
a *= 2;
|
||||
return ((float) Math.sqrt(1 - a * a) + 1) / 2;
|
||||
}
|
||||
};
|
||||
|
||||
static public final Interpolation circleIn = new Interpolation() {
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return 1 - (float) Math.sqrt(1 - a * a);
|
||||
}
|
||||
};
|
||||
|
||||
static public final Interpolation circleOut = new Interpolation() {
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
a--;
|
||||
return (float) Math.sqrt(1 - a * a);
|
||||
}
|
||||
};
|
||||
|
||||
static public final Elastic elastic = new Elastic(2, 10);
|
||||
static public final Elastic elasticIn = new ElasticIn(2, 10);
|
||||
static public final Elastic elasticOut = new ElasticOut(2, 10);
|
||||
|
||||
static public final Interpolation swing = new Swing(1.5f);
|
||||
static public final Interpolation swingIn = new SwingIn(2f);
|
||||
static public final Interpolation swingOut = new SwingOut(2f);
|
||||
|
||||
static public final Interpolation bounce = new Bounce(4);
|
||||
static public final Interpolation bounceIn = new BounceIn(4);
|
||||
static public final Interpolation bounceOut = new BounceOut(4);
|
||||
|
||||
//
|
||||
|
||||
static public class Pow extends Interpolation {
|
||||
final int power;
|
||||
|
||||
public Pow(int power) {
|
||||
this.power = power;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
if (a <= 0.5f)
|
||||
return (float) Math.pow(a * 2, power) / 2;
|
||||
return (float) Math.pow((a - 1) * 2, power) / (power % 2 == 0 ? -2 : 2) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
static public class PowIn extends Pow {
|
||||
public PowIn(int power) {
|
||||
super(power);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return (float) Math.pow(a, power);
|
||||
}
|
||||
}
|
||||
|
||||
static public class PowOut extends Pow {
|
||||
public PowOut(int power) {
|
||||
super(power);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return (float) Math.pow(a - 1, power) * (power % 2 == 0 ? -1 : 1) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
static public class Exp extends Interpolation {
|
||||
final float value, power, min, scale;
|
||||
|
||||
public Exp(float value, float power) {
|
||||
this.value = value;
|
||||
this.power = power;
|
||||
min = (float) Math.pow(value, -power);
|
||||
scale = 1 / (1 - min);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
if (a <= 0.5f)
|
||||
return ((float) Math.pow(value, power * (a * 2 - 1)) - min) * scale / 2;
|
||||
return (2 - ((float) Math.pow(value, -power * (a * 2 - 1)) - min) * scale) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
static public class ExpIn extends Exp {
|
||||
public ExpIn(float value, float power) {
|
||||
super(value, power);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return ((float) Math.pow(value, power * (a - 1)) - min) * scale;
|
||||
}
|
||||
}
|
||||
|
||||
static public class ExpOut extends Exp {
|
||||
public ExpOut(float value, float power) {
|
||||
super(value, power);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return 1 - ((float) Math.pow(value, -power * a) - min) * scale;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
static public class Elastic extends Interpolation {
|
||||
final float value, power;
|
||||
|
||||
public Elastic(float value, float power) {
|
||||
this.value = value;
|
||||
this.power = power;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
if (a <= 0.5f) {
|
||||
a *= 2;
|
||||
return (float) Math.pow(value, power * (a - 1)) * MathUtils.sin(a * 20) * 1.0955f
|
||||
/ 2;
|
||||
}
|
||||
a = 1 - a;
|
||||
a *= 2;
|
||||
return 1 - (float) Math.pow(value, power * (a - 1)) * MathUtils.sin((a) * 20) * 1.0955f
|
||||
/ 2;
|
||||
}
|
||||
}
|
||||
|
||||
static public class ElasticIn extends Elastic {
|
||||
public ElasticIn(float value, float power) {
|
||||
super(value, power);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return (float) Math.pow(value, power * (a - 1)) * MathUtils.sin(a * 20) * 1.0955f;
|
||||
}
|
||||
}
|
||||
|
||||
static public class ElasticOut extends Elastic {
|
||||
public ElasticOut(float value, float power) {
|
||||
super(value, power);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
a = 1 - a;
|
||||
return (1 - (float) Math.pow(value, power * (a - 1)) * MathUtils.sin(a * 20) * 1.0955f);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
static public class Bounce extends BounceOut {
|
||||
public Bounce(float[] widths, float[] heights) {
|
||||
super(widths, heights);
|
||||
}
|
||||
|
||||
public Bounce(int bounces) {
|
||||
super(bounces);
|
||||
}
|
||||
|
||||
private float out(float a) {
|
||||
float test = a + widths[0] / 2;
|
||||
if (test < widths[0])
|
||||
return test / (widths[0] / 2) - 1;
|
||||
return super.apply(a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
if (a <= 0.5f)
|
||||
return (1 - out(1 - a * 2)) / 2;
|
||||
return out(a * 2 - 1) / 2 + 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
static public class BounceOut extends Interpolation {
|
||||
final float[] widths, heights;
|
||||
|
||||
public BounceOut(float[] widths, float[] heights) {
|
||||
if (widths.length != heights.length)
|
||||
throw new IllegalArgumentException("Must be the same number of widths and heights.");
|
||||
this.widths = widths;
|
||||
this.heights = heights;
|
||||
}
|
||||
|
||||
public BounceOut(int bounces) {
|
||||
if (bounces < 2 || bounces > 5)
|
||||
throw new IllegalArgumentException("bounces cannot be < 2 or > 5: " + bounces);
|
||||
widths = new float[bounces];
|
||||
heights = new float[bounces];
|
||||
heights[0] = 1;
|
||||
switch (bounces) {
|
||||
case 2:
|
||||
widths[0] = 0.6f;
|
||||
widths[1] = 0.4f;
|
||||
heights[1] = 0.33f;
|
||||
break;
|
||||
case 3:
|
||||
widths[0] = 0.4f;
|
||||
widths[1] = 0.4f;
|
||||
widths[2] = 0.2f;
|
||||
heights[1] = 0.33f;
|
||||
heights[2] = 0.1f;
|
||||
break;
|
||||
case 4:
|
||||
widths[0] = 0.34f;
|
||||
widths[1] = 0.34f;
|
||||
widths[2] = 0.2f;
|
||||
widths[3] = 0.15f;
|
||||
heights[1] = 0.26f;
|
||||
heights[2] = 0.11f;
|
||||
heights[3] = 0.03f;
|
||||
break;
|
||||
case 5:
|
||||
widths[0] = 0.3f;
|
||||
widths[1] = 0.3f;
|
||||
widths[2] = 0.2f;
|
||||
widths[3] = 0.1f;
|
||||
widths[4] = 0.1f;
|
||||
heights[1] = 0.45f;
|
||||
heights[2] = 0.3f;
|
||||
heights[3] = 0.15f;
|
||||
heights[4] = 0.06f;
|
||||
break;
|
||||
}
|
||||
widths[0] *= 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
a += widths[0] / 2;
|
||||
float width = 0, height = 0;
|
||||
for (int i = 0, n = widths.length; i < n; i++) {
|
||||
width = widths[i];
|
||||
if (a <= width) {
|
||||
height = heights[i];
|
||||
break;
|
||||
}
|
||||
a -= width;
|
||||
}
|
||||
a /= width;
|
||||
float z = 4 / width * height * a;
|
||||
return 1 - (z - z * a) * width;
|
||||
}
|
||||
}
|
||||
|
||||
static public class BounceIn extends BounceOut {
|
||||
public BounceIn(float[] widths, float[] heights) {
|
||||
super(widths, heights);
|
||||
}
|
||||
|
||||
public BounceIn(int bounces) {
|
||||
super(bounces);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return 1 - super.apply(1 - a);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
static public class Swing extends Interpolation {
|
||||
private final float scale;
|
||||
|
||||
public Swing(float scale) {
|
||||
this.scale = scale * 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
if (a <= 0.5f) {
|
||||
a *= 2;
|
||||
return a * a * ((scale + 1) * a - scale) / 2;
|
||||
}
|
||||
a--;
|
||||
a *= 2;
|
||||
return a * a * ((scale + 1) * a + scale) / 2 + 1;
|
||||
}
|
||||
}
|
||||
|
||||
static public class SwingOut extends Interpolation {
|
||||
private final float scale;
|
||||
|
||||
public SwingOut(float scale) {
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
a--;
|
||||
return a * a * ((scale + 1) * a + scale) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
static public class SwingIn extends Interpolation {
|
||||
private final float scale;
|
||||
|
||||
public SwingIn(float scale) {
|
||||
this.scale = scale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float apply(float a) {
|
||||
return a * a * ((scale + 1) * a - scale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,284 +1,284 @@
|
||||
/*******************************************************************************
|
||||
* Copyright 2011 Mario Zechner <badlogicgames@gmail.com>
|
||||
* Copyright 2011 Nathan Sweet <nathan.sweet@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
******************************************************************************/
|
||||
|
||||
package org.oscim.utils.math;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Utility and fast math functions.
|
||||
* <p>
|
||||
* Thanks to Riven on JavaGaming.org for the basis of sin/cos/atan2/floor/ceil.
|
||||
*
|
||||
* @author Nathan Sweet
|
||||
*/
|
||||
public class MathUtils {
|
||||
static public final float nanoToSec = 1 / 1000000000f;
|
||||
|
||||
static public final float PI = 3.1415927f;
|
||||
public static final float PI2 = PI * 2;
|
||||
|
||||
static private final int SIN_BITS = 13; // Adjust for accuracy.
|
||||
static private final int SIN_MASK = ~(-1 << SIN_BITS);
|
||||
static private final int SIN_COUNT = SIN_MASK + 1;
|
||||
|
||||
static private final float radFull = PI * 2;
|
||||
static private final float degFull = 360;
|
||||
static private final float radToIndex = SIN_COUNT / radFull;
|
||||
static private final float degToIndex = SIN_COUNT / degFull;
|
||||
|
||||
static public final float radiansToDegrees = 180f / PI;
|
||||
static public final float radDeg = radiansToDegrees;
|
||||
static public final float degreesToRadians = PI / 180;
|
||||
static public final float degRad = degreesToRadians;
|
||||
|
||||
static private class Sin {
|
||||
static final float[] table = new float[SIN_COUNT];
|
||||
static {
|
||||
for (int i = 0; i < SIN_COUNT; i++)
|
||||
table[i] = (float) Math.sin((i + 0.5f) / SIN_COUNT * radFull);
|
||||
for (int i = 0; i < 360; i += 90)
|
||||
table[(int) (i * degToIndex) & SIN_MASK] = (float) Math.sin(i * degreesToRadians);
|
||||
}
|
||||
}
|
||||
|
||||
static private class Cos {
|
||||
static final float[] table = new float[SIN_COUNT];
|
||||
static {
|
||||
for (int i = 0; i < SIN_COUNT; i++)
|
||||
table[i] = (float) Math.cos((i + 0.5f) / SIN_COUNT * radFull);
|
||||
for (int i = 0; i < 360; i += 90)
|
||||
table[(int) (i * degToIndex) & SIN_MASK] = (float) Math.cos(i * degreesToRadians);
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the sine in radians. */
|
||||
static public final float sin(float radians) {
|
||||
return Sin.table[(int) (radians * radToIndex) & SIN_MASK];
|
||||
}
|
||||
|
||||
/** Returns the cosine in radians. */
|
||||
static public final float cos(float radians) {
|
||||
return Cos.table[(int) (radians * radToIndex) & SIN_MASK];
|
||||
}
|
||||
|
||||
/** Returns the sine in radians. */
|
||||
static public final float sinDeg(float degrees) {
|
||||
return Sin.table[(int) (degrees * degToIndex) & SIN_MASK];
|
||||
}
|
||||
|
||||
/** Returns the cosine in radians. */
|
||||
static public final float cosDeg(float degrees) {
|
||||
return Cos.table[(int) (degrees * degToIndex) & SIN_MASK];
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
static private final int ATAN2_BITS = 7; // Adjust for accuracy.
|
||||
static private final int ATAN2_BITS2 = ATAN2_BITS << 1;
|
||||
static private final int ATAN2_MASK = ~(-1 << ATAN2_BITS2);
|
||||
static private final int ATAN2_COUNT = ATAN2_MASK + 1;
|
||||
static final int ATAN2_DIM = (int) Math.sqrt(ATAN2_COUNT);
|
||||
static private final float INV_ATAN2_DIM_MINUS_1 = 1.0f / (ATAN2_DIM - 1);
|
||||
|
||||
static private class Atan2 {
|
||||
static final float[] table = new float[ATAN2_COUNT];
|
||||
static {
|
||||
for (int i = 0; i < ATAN2_DIM; i++) {
|
||||
for (int j = 0; j < ATAN2_DIM; j++) {
|
||||
float x0 = (float) i / ATAN2_DIM;
|
||||
float y0 = (float) j / ATAN2_DIM;
|
||||
table[j * ATAN2_DIM + i] = (float) Math.atan2(y0, x0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns atan2 in radians from a lookup table. */
|
||||
static public final float atan2(float y, float x) {
|
||||
float add, mul;
|
||||
if (x < 0) {
|
||||
if (y < 0) {
|
||||
y = -y;
|
||||
mul = 1;
|
||||
} else
|
||||
mul = -1;
|
||||
x = -x;
|
||||
add = -PI;
|
||||
} else {
|
||||
if (y < 0) {
|
||||
y = -y;
|
||||
mul = -1;
|
||||
} else
|
||||
mul = 1;
|
||||
add = 0;
|
||||
}
|
||||
float invDiv = 1 / ((x < y ? y : x) * INV_ATAN2_DIM_MINUS_1);
|
||||
int xi = (int) (x * invDiv);
|
||||
int yi = (int) (y * invDiv);
|
||||
return (Atan2.table[yi * ATAN2_DIM + xi] + add) * mul;
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
static public Random random = new Random();
|
||||
|
||||
/**
|
||||
* Returns a random number between 0 (inclusive) and the specified value
|
||||
* (inclusive).
|
||||
*/
|
||||
static public final int random(int range) {
|
||||
return random.nextInt(range + 1);
|
||||
}
|
||||
|
||||
/** Returns a random number between start (inclusive) and end (inclusive). */
|
||||
static public final int random(int start, int end) {
|
||||
return start + random.nextInt(end - start + 1);
|
||||
}
|
||||
|
||||
/** Returns a random boolean value. */
|
||||
static public final boolean randomBoolean() {
|
||||
return random.nextBoolean();
|
||||
}
|
||||
|
||||
/** Returns random number between 0.0 (inclusive) and 1.0 (exclusive). */
|
||||
static public final float random() {
|
||||
return random.nextFloat();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random number between 0 (inclusive) and the specified value
|
||||
* (exclusive).
|
||||
*/
|
||||
static public final float random(float range) {
|
||||
return random.nextFloat() * range;
|
||||
}
|
||||
|
||||
/** Returns a random number between start (inclusive) and end (exclusive). */
|
||||
static public final float random(float start, float end) {
|
||||
return start + random.nextFloat() * (end - start);
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
/**
|
||||
* Returns the next power of two. Returns the specified value if the value
|
||||
* is already a power of two.
|
||||
*/
|
||||
static public int nextPowerOfTwo(int value) {
|
||||
if (value == 0)
|
||||
return 1;
|
||||
value--;
|
||||
value |= value >> 1;
|
||||
value |= value >> 2;
|
||||
value |= value >> 4;
|
||||
value |= value >> 8;
|
||||
value |= value >> 16;
|
||||
return value + 1;
|
||||
}
|
||||
|
||||
static public boolean isPowerOfTwo(int value) {
|
||||
return value != 0 && (value & value - 1) == 0;
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
static public int clamp(int value, int min, int max) {
|
||||
if (value < min)
|
||||
return min;
|
||||
if (value > max)
|
||||
return max;
|
||||
return value;
|
||||
}
|
||||
|
||||
static public short clamp(short value, short min, short max) {
|
||||
if (value < min)
|
||||
return min;
|
||||
if (value > max)
|
||||
return max;
|
||||
return value;
|
||||
}
|
||||
|
||||
static public float clamp(float value, float min, float max) {
|
||||
if (value < min)
|
||||
return min;
|
||||
if (value > max)
|
||||
return max;
|
||||
return value;
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
static private final int BIG_ENOUGH_INT = 16 * 1024;
|
||||
static private final double BIG_ENOUGH_FLOOR = BIG_ENOUGH_INT;
|
||||
static private final double CEIL = 0.9999999;
|
||||
static private final double BIG_ENOUGH_CEIL = Double.longBitsToDouble(Double.doubleToLongBits(BIG_ENOUGH_INT + 1) - 1);
|
||||
static private final double BIG_ENOUGH_ROUND = BIG_ENOUGH_INT + 0.5f;
|
||||
|
||||
/**
|
||||
* Returns the largest integer less than or equal to the specified float.
|
||||
* This method will only properly floor floats from
|
||||
* -(2^14) to (Float.MAX_VALUE - 2^14).
|
||||
*/
|
||||
static public int floor(float x) {
|
||||
return (int) (x + BIG_ENOUGH_FLOOR) - BIG_ENOUGH_INT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the largest integer less than or equal to the specified float.
|
||||
* This method will only properly floor floats that are
|
||||
* positive. Note this method simply casts the float to int.
|
||||
*/
|
||||
static public int floorPositive(float x) {
|
||||
return (int) x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smallest integer greater than or equal to the specified
|
||||
* float. This method will only properly ceil floats from
|
||||
* -(2^14) to (Float.MAX_VALUE - 2^14).
|
||||
*/
|
||||
static public int ceil(float x) {
|
||||
return (int) (x + BIG_ENOUGH_CEIL) - BIG_ENOUGH_INT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smallest integer greater than or equal to the specified
|
||||
* float. This method will only properly ceil floats that
|
||||
* are positive.
|
||||
*/
|
||||
static public int ceilPositive(float x) {
|
||||
return (int) (x + CEIL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the closest integer to the specified float. This method will only
|
||||
* properly round floats from -(2^14) to
|
||||
* (Float.MAX_VALUE - 2^14).
|
||||
*/
|
||||
static public int round(float x) {
|
||||
return (int) (x + BIG_ENOUGH_ROUND) - BIG_ENOUGH_INT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the closest integer to the specified float. This method will only
|
||||
* properly round floats that are positive.
|
||||
*/
|
||||
static public int roundPositive(float x) {
|
||||
return (int) (x + 0.5f);
|
||||
}
|
||||
}
|
||||
/*******************************************************************************
|
||||
* Copyright 2011 Mario Zechner <badlogicgames@gmail.com>
|
||||
* Copyright 2011 Nathan Sweet <nathan.sweet@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
******************************************************************************/
|
||||
|
||||
package org.oscim.utils.math;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* Utility and fast math functions.
|
||||
* <p>
|
||||
* Thanks to Riven on JavaGaming.org for the basis of sin/cos/atan2/floor/ceil.
|
||||
*
|
||||
* @author Nathan Sweet
|
||||
*/
|
||||
public class MathUtils {
|
||||
static public final float nanoToSec = 1 / 1000000000f;
|
||||
|
||||
static public final float PI = 3.1415927f;
|
||||
public static final float PI2 = PI * 2;
|
||||
|
||||
static private final int SIN_BITS = 13; // Adjust for accuracy.
|
||||
static private final int SIN_MASK = ~(-1 << SIN_BITS);
|
||||
static private final int SIN_COUNT = SIN_MASK + 1;
|
||||
|
||||
static private final float radFull = PI * 2;
|
||||
static private final float degFull = 360;
|
||||
static private final float radToIndex = SIN_COUNT / radFull;
|
||||
static private final float degToIndex = SIN_COUNT / degFull;
|
||||
|
||||
static public final float radiansToDegrees = 180f / PI;
|
||||
static public final float radDeg = radiansToDegrees;
|
||||
static public final float degreesToRadians = PI / 180;
|
||||
static public final float degRad = degreesToRadians;
|
||||
|
||||
static private class Sin {
|
||||
static final float[] table = new float[SIN_COUNT];
|
||||
static {
|
||||
for (int i = 0; i < SIN_COUNT; i++)
|
||||
table[i] = (float) Math.sin((i + 0.5f) / SIN_COUNT * radFull);
|
||||
for (int i = 0; i < 360; i += 90)
|
||||
table[(int) (i * degToIndex) & SIN_MASK] = (float) Math.sin(i * degreesToRadians);
|
||||
}
|
||||
}
|
||||
|
||||
static private class Cos {
|
||||
static final float[] table = new float[SIN_COUNT];
|
||||
static {
|
||||
for (int i = 0; i < SIN_COUNT; i++)
|
||||
table[i] = (float) Math.cos((i + 0.5f) / SIN_COUNT * radFull);
|
||||
for (int i = 0; i < 360; i += 90)
|
||||
table[(int) (i * degToIndex) & SIN_MASK] = (float) Math.cos(i * degreesToRadians);
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns the sine in radians. */
|
||||
static public final float sin(float radians) {
|
||||
return Sin.table[(int) (radians * radToIndex) & SIN_MASK];
|
||||
}
|
||||
|
||||
/** Returns the cosine in radians. */
|
||||
static public final float cos(float radians) {
|
||||
return Cos.table[(int) (radians * radToIndex) & SIN_MASK];
|
||||
}
|
||||
|
||||
/** Returns the sine in radians. */
|
||||
static public final float sinDeg(float degrees) {
|
||||
return Sin.table[(int) (degrees * degToIndex) & SIN_MASK];
|
||||
}
|
||||
|
||||
/** Returns the cosine in radians. */
|
||||
static public final float cosDeg(float degrees) {
|
||||
return Cos.table[(int) (degrees * degToIndex) & SIN_MASK];
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
static private final int ATAN2_BITS = 7; // Adjust for accuracy.
|
||||
static private final int ATAN2_BITS2 = ATAN2_BITS << 1;
|
||||
static private final int ATAN2_MASK = ~(-1 << ATAN2_BITS2);
|
||||
static private final int ATAN2_COUNT = ATAN2_MASK + 1;
|
||||
static final int ATAN2_DIM = (int) Math.sqrt(ATAN2_COUNT);
|
||||
static private final float INV_ATAN2_DIM_MINUS_1 = 1.0f / (ATAN2_DIM - 1);
|
||||
|
||||
static private class Atan2 {
|
||||
static final float[] table = new float[ATAN2_COUNT];
|
||||
static {
|
||||
for (int i = 0; i < ATAN2_DIM; i++) {
|
||||
for (int j = 0; j < ATAN2_DIM; j++) {
|
||||
float x0 = (float) i / ATAN2_DIM;
|
||||
float y0 = (float) j / ATAN2_DIM;
|
||||
table[j * ATAN2_DIM + i] = (float) Math.atan2(y0, x0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns atan2 in radians from a lookup table. */
|
||||
static public final float atan2(float y, float x) {
|
||||
float add, mul;
|
||||
if (x < 0) {
|
||||
if (y < 0) {
|
||||
y = -y;
|
||||
mul = 1;
|
||||
} else
|
||||
mul = -1;
|
||||
x = -x;
|
||||
add = -PI;
|
||||
} else {
|
||||
if (y < 0) {
|
||||
y = -y;
|
||||
mul = -1;
|
||||
} else
|
||||
mul = 1;
|
||||
add = 0;
|
||||
}
|
||||
float invDiv = 1 / ((x < y ? y : x) * INV_ATAN2_DIM_MINUS_1);
|
||||
int xi = (int) (x * invDiv);
|
||||
int yi = (int) (y * invDiv);
|
||||
return (Atan2.table[yi * ATAN2_DIM + xi] + add) * mul;
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
static public Random random = new Random();
|
||||
|
||||
/**
|
||||
* Returns a random number between 0 (inclusive) and the specified value
|
||||
* (inclusive).
|
||||
*/
|
||||
static public final int random(int range) {
|
||||
return random.nextInt(range + 1);
|
||||
}
|
||||
|
||||
/** Returns a random number between start (inclusive) and end (inclusive). */
|
||||
static public final int random(int start, int end) {
|
||||
return start + random.nextInt(end - start + 1);
|
||||
}
|
||||
|
||||
/** Returns a random boolean value. */
|
||||
static public final boolean randomBoolean() {
|
||||
return random.nextBoolean();
|
||||
}
|
||||
|
||||
/** Returns random number between 0.0 (inclusive) and 1.0 (exclusive). */
|
||||
static public final float random() {
|
||||
return random.nextFloat();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a random number between 0 (inclusive) and the specified value
|
||||
* (exclusive).
|
||||
*/
|
||||
static public final float random(float range) {
|
||||
return random.nextFloat() * range;
|
||||
}
|
||||
|
||||
/** Returns a random number between start (inclusive) and end (exclusive). */
|
||||
static public final float random(float start, float end) {
|
||||
return start + random.nextFloat() * (end - start);
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
/**
|
||||
* Returns the next power of two. Returns the specified value if the value
|
||||
* is already a power of two.
|
||||
*/
|
||||
static public int nextPowerOfTwo(int value) {
|
||||
if (value == 0)
|
||||
return 1;
|
||||
value--;
|
||||
value |= value >> 1;
|
||||
value |= value >> 2;
|
||||
value |= value >> 4;
|
||||
value |= value >> 8;
|
||||
value |= value >> 16;
|
||||
return value + 1;
|
||||
}
|
||||
|
||||
static public boolean isPowerOfTwo(int value) {
|
||||
return value != 0 && (value & value - 1) == 0;
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
static public int clamp(int value, int min, int max) {
|
||||
if (value < min)
|
||||
return min;
|
||||
if (value > max)
|
||||
return max;
|
||||
return value;
|
||||
}
|
||||
|
||||
static public short clamp(short value, short min, short max) {
|
||||
if (value < min)
|
||||
return min;
|
||||
if (value > max)
|
||||
return max;
|
||||
return value;
|
||||
}
|
||||
|
||||
static public float clamp(float value, float min, float max) {
|
||||
if (value < min)
|
||||
return min;
|
||||
if (value > max)
|
||||
return max;
|
||||
return value;
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
static private final int BIG_ENOUGH_INT = 16 * 1024;
|
||||
static private final double BIG_ENOUGH_FLOOR = BIG_ENOUGH_INT;
|
||||
static private final double CEIL = 0.9999999;
|
||||
static private final double BIG_ENOUGH_CEIL = Double.longBitsToDouble(Double.doubleToLongBits(BIG_ENOUGH_INT + 1) - 1);
|
||||
static private final double BIG_ENOUGH_ROUND = BIG_ENOUGH_INT + 0.5f;
|
||||
|
||||
/**
|
||||
* Returns the largest integer less than or equal to the specified float.
|
||||
* This method will only properly floor floats from
|
||||
* -(2^14) to (Float.MAX_VALUE - 2^14).
|
||||
*/
|
||||
static public int floor(float x) {
|
||||
return (int) (x + BIG_ENOUGH_FLOOR) - BIG_ENOUGH_INT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the largest integer less than or equal to the specified float.
|
||||
* This method will only properly floor floats that are
|
||||
* positive. Note this method simply casts the float to int.
|
||||
*/
|
||||
static public int floorPositive(float x) {
|
||||
return (int) x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smallest integer greater than or equal to the specified
|
||||
* float. This method will only properly ceil floats from
|
||||
* -(2^14) to (Float.MAX_VALUE - 2^14).
|
||||
*/
|
||||
static public int ceil(float x) {
|
||||
return (int) (x + BIG_ENOUGH_CEIL) - BIG_ENOUGH_INT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the smallest integer greater than or equal to the specified
|
||||
* float. This method will only properly ceil floats that
|
||||
* are positive.
|
||||
*/
|
||||
static public int ceilPositive(float x) {
|
||||
return (int) (x + CEIL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the closest integer to the specified float. This method will only
|
||||
* properly round floats from -(2^14) to
|
||||
* (Float.MAX_VALUE - 2^14).
|
||||
*/
|
||||
static public int round(float x) {
|
||||
return (int) (x + BIG_ENOUGH_ROUND) - BIG_ENOUGH_INT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the closest integer to the specified float. This method will only
|
||||
* properly round floats that are positive.
|
||||
*/
|
||||
static public int roundPositive(float x) {
|
||||
return (int) (x + 0.5f);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user