Gun + the physics are on evil mode

This commit is contained in:
Halbear 2026-07-06 22:41:47 +01:00
parent 605c96362b
commit 8ab8c06f9c
23 changed files with 2248 additions and 899 deletions

File diff suppressed because it is too large Load diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View file

Binary file not shown.

View file

@ -0,0 +1,15 @@
{
"ID": "musket",
"Meshes": [
{
"ID": "cube_0",
"MaterialID": "musket-mat-1",
"OffsetVertex": 0,
"VertexSize": 25088,
"OffsetIndex": 0,
"IndexSize": 2880
}
],
"VertexPath": "resources/models/musket/musket.vtx",
"IndexPath": "resources/models/musket/musket.idx"
}

View file

@ -0,0 +1,4 @@
# Made in Blockbench 5.1.4
newmtl m_2fae0962-6878-9312-f690-fafaddc2a80c
map_Kd Musket.png
newmtl none

View file

@ -0,0 +1,923 @@
# Made in Blockbench 5.1.4
mtllib musket.mtl
o cube
v 0.046875 0.58203125 0.6875
v 0.046875 0.58203125 -0.75
v 0.046875 0.51953125 0.6875
v 0.046875 0.51953125 -0.75
v -0.046875 0.58203125 -0.75
v -0.046875 0.58203125 0.6875
v -0.046875 0.51953125 -0.75
v -0.046875 0.51953125 0.6875
vt 0.59375 0.953125
vt 0.5625 0.953125
vt 0.5625 0.9375
vt 0.59375 0.9375
vt 0.625 0.640625
vt 0.265625 0.640625
vt 0.265625 0.625
vt 0.625 0.625
vt 0.609375 0.671875
vt 0.578125 0.671875
vt 0.578125 0.65625
vt 0.609375 0.65625
vt 0.671875 0.921875
vt 0.3125 0.921875
vt 0.3125 0.90625
vt 0.671875 0.90625
vt 0 0.421875
vt 0.03125 0.421875
vt 0.03125 0.78125
vt 0 0.78125
vt 0.046875 0.78125
vt 0.078125 0.78125
vt 0.078125 0.421875
vt 0.046875 0.421875
vn 0 0 -1
vn 1 0 0
vn 0 0 1
vn -1 0 0
vn 0 1 0
vn 0 -1 0
usemtl m_2fae0962-6878-9312-f690-fafaddc2a80c
f 4/4/1 7/3/1 5/2/1 2/1/1
f 3/8/2 4/7/2 2/6/2 1/5/2
f 8/12/3 3/11/3 1/10/3 6/9/3
f 7/16/4 8/15/4 6/14/4 5/13/4
f 6/20/5 1/19/5 2/18/5 5/17/5
f 7/24/6 4/23/6 3/22/6 8/21/6
o cube
v 0.046812499999999924 0.625 0.8125
v 0.046812499999999924 0.625 0.6875
v 0.046812499999999924 0.5 0.8125
v 0.046812499999999924 0.5 0.6875
v -0.046812500000000035 0.625 0.6875
v -0.046812500000000035 0.625 0.8125
v -0.046812500000000035 0.5 0.6875
v -0.046812500000000035 0.5 0.8125
vt 0.609375 0.40625
vt 0.59375 0.40625
vt 0.59375 0.375
vt 0.609375 0.375
vt 0.5625 0.5
vt 0.53125 0.5
vt 0.53125 0.46875
vt 0.5625 0.46875
vt 0.625 1
vt 0.609375 1
vt 0.609375 0.96875
vt 0.625 0.96875
vt 0.53125 0.828125
vt 0.5 0.828125
vt 0.5 0.796875
vt 0.53125 0.796875
vt 0.1875 0.359375
vt 0.203125 0.359375
vt 0.203125 0.390625
vt 0.1875 0.390625
vt 0.609375 0.78125
vt 0.625 0.78125
vt 0.625 0.75
vt 0.609375 0.75
vn 0 0 -1
vn 1 0 0
vn 0 0 1
vn -1 0 0
vn 0 1 0
vn 0 -1 0
usemtl m_2fae0962-6878-9312-f690-fafaddc2a80c
f 12/28/7 15/27/7 13/26/7 10/25/7
f 11/32/8 12/31/8 10/30/8 9/29/8
f 16/36/9 11/35/9 9/34/9 14/33/9
f 15/40/10 16/39/10 14/38/10 13/37/10
f 14/44/11 9/43/11 10/42/11 13/41/11
f 15/48/12 12/47/12 11/46/12 16/45/12
o cube
v 0.046875 0.5293291419087276 1.0434698831278217
v 0.046875 0.625 0.8125
v 0.046875 0.29835925878090586 0.9477990250365492
v 0.046875 0.3940301168721783 0.7168291419087276
v -0.046875000000000444 0.625 0.8125
v -0.046875000000000444 0.5293291419087276 1.0434698831278217
v -0.046875000000000444 0.3940301168721783 0.7168291419087276
v -0.046875000000000444 0.29835925878090586 0.9477990250365492
vt 0.453125 1
vt 0.421875 1
vt 0.421875 0.9375
vt 0.453125 0.9375
vt 0.46875 0.71875
vt 0.40625 0.71875
vt 0.40625 0.65625
vt 0.46875 0.65625
vt 0.5 1
vt 0.46875 1
vt 0.46875 0.9375
vt 0.5 0.9375
vt 0.390625 0.609375
vt 0.328125 0.609375
vt 0.328125 0.546875
vt 0.390625 0.546875
vt 0.484375 0.65625
vt 0.515625 0.65625
vt 0.515625 0.71875
vt 0.484375 0.71875
vt 0.421875 0.515625
vt 0.453125 0.515625
vt 0.453125 0.453125
vt 0.421875 0.453125
vn 0 0.3826834323650897 -0.9238795325112867
vn 1 0 0
vn 0 -0.3826834323650897 0.9238795325112867
vn -1 0 0
vn 0 0.9238795325112867 0.3826834323650897
vn 0 -0.9238795325112867 -0.3826834323650897
usemtl m_2fae0962-6878-9312-f690-fafaddc2a80c
f 20/52/13 23/51/13 21/50/13 18/49/13
f 19/56/14 20/55/14 18/54/14 17/53/14
f 24/60/15 19/59/15 17/58/15 22/57/15
f 23/64/16 24/63/16 22/62/16 21/61/16
f 22/68/17 17/67/17 18/66/17 21/65/17
f 23/72/18 20/71/18 19/70/18 24/69/18
o cube
v 0.046812499999999924 0.5281249999999998 1.4195312500000001
v 0.046812499999999924 0.5281249999999998 1.0445312500000001
v 0.046812499999999924 0.27812500000000007 1.4195312500000001
v 0.046812499999999924 0.27812500000000007 1.0445312500000001
v -0.046812500000000035 0.5281249999999998 1.0445312500000001
v -0.046812500000000035 0.5281249999999998 1.4195312500000001
v -0.046812500000000035 0.27812500000000007 1.0445312500000001
v -0.046812500000000035 0.27812500000000007 1.4195312500000001
vt 0.203125 0.46875
vt 0.1875 0.46875
vt 0.1875 0.40625
vt 0.203125 0.40625
vt 0.25 0.640625
vt 0.15625 0.640625
vt 0.15625 0.578125
vt 0.25 0.578125
vt 0.234375 0.453125
vt 0.21875 0.453125
vt 0.21875 0.390625
vt 0.234375 0.390625
vt 0.40625 1
vt 0.3125 1
vt 0.3125 0.9375
vt 0.40625 0.9375
vt 0.515625 0.515625
vt 0.53125 0.515625
vt 0.53125 0.609375
vt 0.515625 0.609375
vt 0.15625 0.46875
vt 0.171875 0.46875
vt 0.171875 0.375
vt 0.15625 0.375
vn 0 0 -1
vn 1 0 0
vn 0 0 1
vn -1 0 0
vn 0 1 0
vn 0 -1 0
usemtl m_2fae0962-6878-9312-f690-fafaddc2a80c
f 28/76/19 31/75/19 29/74/19 26/73/19
f 27/80/20 28/79/20 26/78/20 25/77/20
f 32/84/21 27/83/21 25/82/21 30/81/21
f 31/88/22 32/87/22 30/86/22 29/85/22
f 30/92/23 25/91/23 26/90/23 29/89/23
f 31/96/24 28/95/24 27/94/24 32/93/24
o cube
v 0.04675000000000007 0.36148224834027304 1.447166045473688
v 0.04675000000000007 0.5289062499999998 1.0429687500000002
v 0.04675000000000007 0.1305123652124517 1.351495187382416
v 0.04675000000000007 0.2979363668721784 0.9472978919087279
v -0.046750000000000014 0.5289062499999998 1.0429687500000002
v -0.046750000000000014 0.36148224834027304 1.447166045473688
v -0.046750000000000014 0.2979363668721784 0.9472978919087279
v -0.046750000000000014 0.1305123652124517 1.351495187382416
vt 0.5625 0.609375
vt 0.546875 0.609375
vt 0.546875 0.546875
vt 0.5625 0.546875
vt 0.390625 0.71875
vt 0.28125 0.71875
vt 0.28125 0.65625
vt 0.390625 0.65625
vt 0.546875 0.453125
vt 0.53125 0.453125
vt 0.53125 0.390625
vt 0.546875 0.390625
vt 0.265625 0.71875
vt 0.15625 0.71875
vt 0.15625 0.65625
vt 0.265625 0.65625
vt 0.46875 0.390625
vt 0.484375 0.390625
vt 0.484375 0.5
vt 0.46875 0.5
vt 0.5 0.5
vt 0.515625 0.5
vt 0.515625 0.390625
vt 0.5 0.390625
vn 0 0.3826834323650897 -0.9238795325112867
vn 1 0 0
vn 0 -0.3826834323650897 0.9238795325112867
vn -1 0 0
vn 0 0.9238795325112867 0.3826834323650897
vn 0 -0.9238795325112867 -0.3826834323650897
usemtl m_2fae0962-6878-9312-f690-fafaddc2a80c
f 36/100/25 39/99/25 37/98/25 34/97/25
f 35/104/26 36/103/26 34/102/26 33/101/26
f 40/108/27 35/107/27 33/106/27 38/105/27
f 39/112/28 40/111/28 38/110/28 37/109/28
f 38/116/29 33/115/29 34/114/29 37/113/29
f 39/120/30 36/119/30 35/118/30 40/117/30
o cube
v 0.046875 0.5281312499999998 1.4765625
v 0.046875 0.5281312499999998 1.3515625
v 0.046875 0.130475 1.4765625
v 0.046875 0.130475 1.3515625
v -0.046875 0.5281312499999998 1.3515625
v -0.046875 0.5281312499999998 1.4765625
v -0.046875 0.130475 1.3515625
v -0.046875 0.130475 1.4765625
vt 0.25 0.5625
vt 0.21875 0.5625
vt 0.21875 0.46875
vt 0.25 0.46875
vt 0.40625 0.515625
vt 0.375 0.515625
vt 0.375 0.421875
vt 0.40625 0.421875
vt 0.5 0.609375
vt 0.46875 0.609375
vt 0.46875 0.515625
vt 0.5 0.515625
vt 0.359375 0.53125
vt 0.328125 0.53125
vt 0.328125 0.4375
vt 0.359375 0.4375
vt 0.546875 0.796875
vt 0.578125 0.796875
vt 0.578125 0.828125
vt 0.546875 0.828125
vt 0.5625 1
vt 0.59375 1
vt 0.59375 0.96875
vt 0.5625 0.96875
vn 0 0 -1
vn 1 0 0
vn 0 0 1
vn -1 0 0
vn 0 1 0
vn 0 -1 0
usemtl m_2fae0962-6878-9312-f690-fafaddc2a80c
f 44/124/31 47/123/31 45/122/31 42/121/31
f 43/128/32 44/127/32 42/126/32 41/125/32
f 48/132/33 43/131/33 41/130/33 46/129/33
f 47/136/34 48/135/34 46/134/34 45/133/34
f 46/140/35 41/139/35 42/138/35 45/137/35
f 47/144/36 44/143/36 43/142/36 48/141/36
o cube
v 0.04419417382415922 0.5754441738241592 0.75
v 0.04419417382415922 0.5754441738241592 -1.25
v 0 0.53125 0.75
v 0 0.53125 -1.25
v 6.938893903907228e-18 0.6196383476483185 -1.25
v 6.938893903907228e-18 0.6196383476483185 0.75
v -0.044194173824159216 0.5754441738241592 -1.25
v -0.044194173824159216 0.5754441738241592 0.75
vt 0.5625 0.53125
vt 0.546875 0.53125
vt 0.546875 0.515625
vt 0.5625 0.515625
vt 0.59375 0.75
vt 0.09375 0.75
vt 0.09375 0.734375
vt 0.59375 0.734375
vt 0.625 0.4375
vt 0.609375 0.4375
vt 0.609375 0.421875
vt 0.625 0.421875
vt 0.59375 0.78125
vt 0.09375 0.78125
vt 0.09375 0.765625
vt 0.59375 0.765625
vt 0.09375 0.21875
vt 0.109375 0.21875
vt 0.109375 0.71875
vt 0.09375 0.71875
vt 0.125 0.71875
vt 0.140625 0.71875
vt 0.140625 0.21875
vt 0.125 0.21875
vn 0 0 -1
vn 0.7071067811865475 -0.7071067811865476 0
vn 0 0 1
vn -0.7071067811865475 0.7071067811865476 0
vn 0.7071067811865476 0.7071067811865475 0
vn -0.7071067811865476 -0.7071067811865475 0
usemtl m_2fae0962-6878-9312-f690-fafaddc2a80c
f 52/148/37 55/147/37 53/146/37 50/145/37
f 51/152/38 52/151/38 50/150/38 49/149/38
f 56/156/39 51/155/39 49/154/39 54/153/39
f 55/160/40 56/159/40 54/158/40 53/157/40
f 54/164/41 49/163/41 50/162/41 53/161/41
f 55/168/42 52/167/42 51/166/42 56/165/42
o cube
v 0 0.53125 -0.3125
v 0 0.53125 -1.5
v 0 0.34375 -0.3125
v 0 0.34375 -1.5
v 0 0.53125 -1.5
v 0 0.53125 -0.3125
v 0 0.34375 -1.5
v 0 0.34375 -0.3125
vt 0.25 0.40625
vt 0.25 0.40625
vt 0.25 0.359375
vt 0.25 0.359375
vt 0.296875 0.9375
vt 0 0.9375
vt 0 0.890625
vt 0.296875 0.890625
vt 0.359375 0.375
vt 0.359375 0.375
vt 0.359375 0.328125
vt 0.359375 0.328125
vt 0.296875 1
vt 0 1
vt 0 0.953125
vt 0.296875 0.953125
vt 0.53125 0.078125
vt 0.53125 0.078125
vt 0.53125 0.375
vt 0.53125 0.375
vt 0.546875 0.375
vt 0.546875 0.375
vt 0.546875 0.078125
vt 0.546875 0.078125
vn 0 0 -1
vn 1 0 0
vn 0 0 1
vn -1 0 0
vn 0 1 0
vn 0 -1 0
usemtl m_2fae0962-6878-9312-f690-fafaddc2a80c
f 60/172/43 63/171/43 61/170/43 58/169/43
f 59/176/44 60/175/44 58/174/44 57/173/44
f 64/180/45 59/179/45 57/178/45 62/177/45
f 63/184/46 64/183/46 62/182/46 61/181/46
f 62/188/47 57/187/47 58/186/47 61/185/47
f 63/192/48 60/191/48 59/190/48 64/189/48
o cube
v 0.03125 0.69140625 -1.1875
v 0.03125 0.69140625 -1.1875
v 0.03125 0.56640625 -1.1875
v 0.03125 0.56640625 -1.1875
v -0.03125 0.69140625 -1.1875
v -0.03125 0.69140625 -1.1875
v -0.03125 0.56640625 -1.1875
v -0.03125 0.56640625 -1.1875
vt 0.609375 0.828125
vt 0.59375 0.828125
vt 0.59375 0.796875
vt 0.609375 0.796875
vt 0.078125 0.40625
vt 0.078125 0.40625
vt 0.078125 0.375
vt 0.078125 0.375
vt 0.578125 0.40625
vt 0.5625 0.40625
vt 0.5625 0.375
vt 0.578125 0.375
vt 0.25 0.453125
vt 0.25 0.453125
vt 0.25 0.421875
vt 0.25 0.421875
vt 0.3125 0.890625
vt 0.328125 0.890625
vt 0.328125 0.890625
vt 0.3125 0.890625
vt 0.34375 0.890625
vt 0.359375 0.890625
vt 0.359375 0.890625
vt 0.34375 0.890625
vn 0 0 -1
vn 1 0 0
vn 0 0 1
vn -1 0 0
vn 0 1 0
vn 0 -1 0
usemtl m_2fae0962-6878-9312-f690-fafaddc2a80c
f 68/196/49 71/195/49 69/194/49 66/193/49
f 67/200/50 68/199/50 66/198/50 65/197/50
f 72/204/51 67/203/51 65/202/51 70/201/51
f 71/208/52 72/207/52 70/206/52 69/205/52
f 70/212/53 65/211/53 66/210/53 69/209/53
f 71/216/54 68/215/54 67/214/54 72/213/54
o cube
v 0.08838834764831843 0.5625 -1.21875
v 0.08838834764831843 0.5625 -1.21875
v -6.938893903907228e-18 0.47411165235168157 -1.21875
v -6.938893903907228e-18 0.47411165235168157 -1.21875
v 6.938893903907228e-18 0.6508883476483185 -1.21875
v 6.938893903907228e-18 0.6508883476483185 -1.21875
v -0.08838834764831843 0.5625 -1.21875
v -0.08838834764831843 0.5625 -1.21875
vt 0.453125 0.4375
vt 0.421875 0.4375
vt 0.421875 0.40625
vt 0.453125 0.40625
vt 0 0.359375
vt 0 0.359375
vt 0 0.328125
vt 0 0.328125
vt 0.59375 0.453125
vt 0.5625 0.453125
vt 0.5625 0.421875
vt 0.59375 0.421875
vt 0.625 0.40625
vt 0.625 0.40625
vt 0.625 0.375
vt 0.625 0.375
vt 0.515625 0.9375
vt 0.546875 0.9375
vt 0.546875 0.9375
vt 0.515625 0.9375
vt 0.53125 0.65625
vt 0.5625 0.65625
vt 0.5625 0.65625
vt 0.53125 0.65625
vn 0 0 -1
vn 0.7071067811865475 -0.7071067811865476 0
vn 0 0 1
vn -0.7071067811865475 0.7071067811865476 0
vn 0.7071067811865476 0.7071067811865475 0
vn -0.7071067811865476 -0.7071067811865475 0
usemtl m_2fae0962-6878-9312-f690-fafaddc2a80c
f 76/220/55 79/219/55 77/218/55 74/217/55
f 75/224/56 76/223/56 74/222/56 73/221/56
f 80/228/57 75/227/57 73/226/57 78/225/57
f 79/232/58 80/231/58 78/230/58 77/229/58
f 78/236/59 73/235/59 74/234/59 77/233/59
f 79/240/60 76/239/60 75/238/60 80/237/60
o cube
v 0.08838834764831843 0.5625 -0.796875
v 0.08838834764831843 0.5625 -0.796875
v -6.938893903907228e-18 0.47411165235168157 -0.796875
v -6.938893903907228e-18 0.47411165235168157 -0.796875
v 6.938893903907228e-18 0.6508883476483185 -0.796875
v 6.938893903907228e-18 0.6508883476483185 -0.796875
v -0.08838834764831843 0.5625 -0.796875
v -0.08838834764831843 0.5625 -0.796875
vt 0.609375 0.71875
vt 0.578125 0.71875
vt 0.578125 0.6875
vt 0.609375 0.6875
vt 0.015625 0.359375
vt 0.015625 0.359375
vt 0.015625 0.328125
vt 0.015625 0.328125
vt 0.359375 0.421875
vt 0.328125 0.421875
vt 0.328125 0.390625
vt 0.359375 0.390625
vt 0.640625 1
vt 0.640625 1
vt 0.640625 0.96875
vt 0.640625 0.96875
vt 0.625 0.5
vt 0.65625 0.5
vt 0.65625 0.5
vt 0.625 0.5
vt 0.625 0.484375
vt 0.65625 0.484375
vt 0.65625 0.484375
vt 0.625 0.484375
vn 0 0 -1
vn 0.7071067811865475 -0.7071067811865476 0
vn 0 0 1
vn -0.7071067811865475 0.7071067811865476 0
vn 0.7071067811865476 0.7071067811865475 0
vn -0.7071067811865476 -0.7071067811865475 0
usemtl m_2fae0962-6878-9312-f690-fafaddc2a80c
f 84/244/61 87/243/61 85/242/61 82/241/61
f 83/248/62 84/247/62 82/246/62 81/245/62
f 88/252/63 83/251/63 81/250/63 86/249/63
f 87/256/64 88/255/64 86/254/64 85/253/64
f 86/260/65 81/259/65 82/258/65 85/257/65
f 87/264/66 84/263/66 83/262/66 88/261/66
o cube
v -8.326672684688674e-17 0.566069173824159 0.6875
v -8.326672684688674e-17 0.566069173824159 -0.75
v 0.04640388251536694 0.519665291308792 0.6875
v 0.04640388251536694 0.519665291308792 -0.75
v -0.04695630968816933 0.5191128641359898 -0.75
v -0.04695630968816933 0.5191128641359898 0.6875
v -0.0005524271728023084 0.4727089816206228 -0.75
v -0.0005524271728023084 0.4727089816206228 0.6875
vt 0.640625 0.5625
vt 0.625 0.5625
vt 0.625 0.546875
vt 0.640625 0.546875
vt 0.734375 0.859375
vt 0.375 0.859375
vt 0.375 0.84375
vt 0.734375 0.84375
vt 0.484375 0.375
vt 0.46875 0.375
vt 0.46875 0.359375
vt 0.484375 0.359375
vt 0.734375 0.890625
vt 0.375 0.890625
vt 0.375 0.875
vt 0.734375 0.875
vt 0.265625 0.25
vt 0.28125 0.25
vt 0.28125 0.609375
vt 0.265625 0.609375
vt 0.296875 0.609375
vt 0.3125 0.609375
vt 0.3125 0.25
vt 0.296875 0.25
vn 0 0 -1
vn 0.7071067811865475 0.7071067811865476 0
vn 0 0 1
vn -0.7071067811865475 -0.7071067811865476 0
vn -0.7071067811865476 0.7071067811865475 0
vn 0.7071067811865476 -0.7071067811865475 0
usemtl m_2fae0962-6878-9312-f690-fafaddc2a80c
f 92/268/67 95/267/67 93/266/67 90/265/67
f 91/272/68 92/271/68 90/270/68 89/269/68
f 96/276/69 91/275/69 89/274/69 94/273/69
f 95/280/70 96/279/70 94/278/70 93/277/70
f 94/284/71 89/283/71 90/282/71 93/281/71
f 95/288/72 92/287/72 91/286/72 96/285/72
o cube
v 0.04675000000000007 0.5095150584360891 0.7646645709543638
v 0.04675000000000007 0.5812682020045434 0.5914371586084975
v 0.04675000000000007 0.3940301168721783 0.7168291419087276
v 0.04675000000000007 0.4657832604406327 0.5436017295628613
v -0.046750000000000014 0.5812682020045434 0.5914371586084975
v -0.046750000000000014 0.5095150584360891 0.7646645709543638
v -0.046750000000000014 0.4657832604406327 0.5436017295628613
v -0.046750000000000014 0.3940301168721783 0.7168291419087276
vt 0.421875 0.390625
vt 0.40625 0.390625
vt 0.40625 0.359375
vt 0.421875 0.359375
vt 0.484375 0.828125
vt 0.4375 0.828125
vt 0.4375 0.796875
vt 0.484375 0.796875
vt 0.453125 0.390625
vt 0.4375 0.390625
vt 0.4375 0.359375
vt 0.453125 0.359375
vt 0.421875 0.828125
vt 0.375 0.828125
vt 0.375 0.796875
vt 0.421875 0.796875
vt 0.046875 0.359375
vt 0.0625 0.359375
vt 0.0625 0.40625
vt 0.046875 0.40625
vt 0.375 0.40625
vt 0.390625 0.40625
vt 0.390625 0.359375
vt 0.375 0.359375
vn 0 0.3826834323650897 -0.9238795325112867
vn 1 0 0
vn 0 -0.3826834323650897 0.9238795325112867
vn -1 0 0
vn 0 0.9238795325112867 0.3826834323650897
vn 0 -0.9238795325112867 -0.3826834323650897
usemtl m_2fae0962-6878-9312-f690-fafaddc2a80c
f 100/292/73 103/291/73 101/290/73 98/289/73
f 99/296/74 100/295/74 98/294/74 97/293/74
f 104/300/75 99/299/75 97/298/75 102/297/75
f 103/304/76 104/303/76 102/302/76 101/301/76
f 102/308/77 97/307/77 98/306/77 101/305/77
f 103/312/78 100/311/78 99/310/78 104/309/78
o cube
v 0.04675000000000007 0.523525731222588 0.5675194440856794
v 0.04675000000000007 0.576144703172788 0.44048600836537743
v 0.04675000000000007 0.4657832604406327 0.5436017295628613
v 0.04675000000000007 0.5184022323908325 0.41656829384255933
v -0.046750000000000014 0.576144703172788 0.44048600836537743
v -0.046750000000000014 0.523525731222588 0.5675194440856794
v -0.046750000000000014 0.5184022323908325 0.41656829384255933
v -0.046750000000000014 0.4657832604406327 0.5436017295628613
vt 0.640625 0.53125
vt 0.625 0.53125
vt 0.625 0.515625
vt 0.640625 0.515625
vt 0.640625 0.46875
vt 0.609375 0.46875
vt 0.609375 0.453125
vt 0.640625 0.453125
vt 0.515625 0.375
vt 0.5 0.375
vt 0.5 0.359375
vt 0.515625 0.359375
vt 0.640625 0.953125
vt 0.609375 0.953125
vt 0.609375 0.9375
vt 0.640625 0.9375
vt 0.625 0.796875
vt 0.640625 0.796875
vt 0.640625 0.828125
vt 0.625 0.828125
vt 0.21875 0.375
vt 0.234375 0.375
vt 0.234375 0.34375
vt 0.21875 0.34375
vn 0 0.3826834323650897 -0.9238795325112867
vn 1 0 0
vn 0 -0.3826834323650897 0.9238795325112867
vn -1 0 0
vn 0 0.9238795325112867 0.3826834323650897
vn 0 -0.9238795325112867 -0.3826834323650897
usemtl m_2fae0962-6878-9312-f690-fafaddc2a80c
f 108/316/79 111/315/79 109/314/79 106/313/79
f 107/320/80 108/319/80 106/318/80 105/317/80
f 112/324/81 107/323/81 105/322/81 110/321/81
f 111/328/82 112/327/82 110/326/82 109/325/82
f 110/332/83 105/331/83 106/330/83 109/329/83
f 111/336/84 108/335/84 107/334/84 112/333/84
o cube
v -0.046937500000000076 0.7982274123458662 0.6782468564315457
v -0.046937500000000076 0.75039198330023 0.5627619148676348
v -0.046937500000000076 0.625 0.75
v -0.046937500000000076 0.5771645709543638 0.6345150584360891
v -0.046937500000000076 0.75039198330023 0.5627619148676348
v -0.046937500000000076 0.7982274123458662 0.6782468564315457
v -0.046937500000000076 0.5771645709543638 0.6345150584360891
v -0.046937500000000076 0.625 0.75
vt 0.03125 0.359375
vt 0.03125 0.359375
vt 0.03125 0.3125
vt 0.03125 0.3125
vt 0.5625 0.71875
vt 0.53125 0.71875
vt 0.53125 0.671875
vt 0.5625 0.671875
vt 0.078125 0.359375
vt 0.078125 0.359375
vt 0.078125 0.3125
vt 0.078125 0.3125
vt 0.546875 1
vt 0.515625 1
vt 0.515625 0.953125
vt 0.546875 0.953125
vt 0.15625 0.328125
vt 0.15625 0.328125
vt 0.15625 0.359375
vt 0.15625 0.359375
vt 0.171875 0.359375
vt 0.171875 0.359375
vt 0.171875 0.328125
vt 0.171875 0.328125
vn 0 -0.3826834323650897 -0.9238795325112867
vn 1 0 0
vn 0 0.3826834323650897 0.9238795325112867
vn -1 0 0
vn 0 0.9238795325112867 -0.3826834323650897
vn 0 -0.9238795325112867 0.3826834323650897
usemtl m_2fae0962-6878-9312-f690-fafaddc2a80c
f 116/340/85 119/339/85 117/338/85 114/337/85
f 115/344/86 116/343/86 114/342/86 113/341/86
f 120/348/87 115/347/87 113/346/87 118/345/87
f 119/352/88 120/351/88 118/350/88 117/349/88
f 118/356/89 113/355/89 114/354/89 117/353/89
f 119/360/90 116/359/90 115/358/90 120/357/90
o cube
v -0.00006250000000007638 0.640625 0.875
v -0.00006250000000007638 0.640625 0.75
v -0.00006250000000007638 0.515625 0.875
v -0.00006250000000007638 0.515625 0.75
v -0.062437500000000035 0.640625 0.75
v -0.062437500000000035 0.640625 0.875
v -0.062437500000000035 0.515625 0.75
v -0.062437500000000035 0.515625 0.875
vt 0.640625 0.734375
vt 0.625 0.734375
vt 0.625 0.703125
vt 0.640625 0.703125
vt 0.609375 0.5625
vt 0.578125 0.5625
vt 0.578125 0.53125
vt 0.609375 0.53125
vt 0.640625 0.6875
vt 0.625 0.6875
vt 0.625 0.65625
vt 0.640625 0.65625
vt 0.609375 0.609375
vt 0.578125 0.609375
vt 0.578125 0.578125
vt 0.609375 0.578125
vt 0.328125 0.34375
vt 0.34375 0.34375
vt 0.34375 0.375
vt 0.328125 0.375
vt 0.625 0.609375
vt 0.640625 0.609375
vt 0.640625 0.578125
vt 0.625 0.578125
vn 0 0 -1
vn 1 0 0
vn 0 0 1
vn -1 0 0
vn 0 1 0
vn 0 -1 0
usemtl m_2fae0962-6878-9312-f690-fafaddc2a80c
f 124/364/91 127/363/91 125/362/91 122/361/91
f 123/368/92 124/367/92 122/366/92 121/365/92
f 128/372/93 123/371/93 121/370/93 126/369/93
f 127/376/94 128/375/94 126/374/94 125/373/94
f 126/380/95 121/379/95 122/378/95 125/377/95
f 127/384/96 124/383/96 123/382/96 128/381/96
o cube
v -0.031312500000000076 0.828125 0.9375
v -0.031312500000000076 0.828125 0.75
v -0.031312500000000076 0.515625 0.9375
v -0.031312500000000076 0.515625 0.75
v -0.031312500000000076 0.828125 0.75
v -0.031312500000000076 0.828125 0.9375
v -0.031312500000000076 0.515625 0.75
v -0.031312500000000076 0.515625 0.9375
vt 0.5625 0.359375
vt 0.5625 0.359375
vt 0.5625 0.28125
vt 0.5625 0.28125
vt 0.203125 0.5625
vt 0.15625 0.5625
vt 0.15625 0.484375
vt 0.203125 0.484375
vt 0.640625 0.4375
vt 0.640625 0.4375
vt 0.640625 0.359375
vt 0.640625 0.359375
vt 0.453125 0.609375
vt 0.40625 0.609375
vt 0.40625 0.53125
vt 0.453125 0.53125
vt 0.578125 0.3125
vt 0.578125 0.3125
vt 0.578125 0.359375
vt 0.578125 0.359375
vt 0.59375 0.359375
vt 0.59375 0.359375
vt 0.59375 0.3125
vt 0.59375 0.3125
vn 0 0 -1
vn 1 0 0
vn 0 0 1
vn -1 0 0
vn 0 1 0
vn 0 -1 0
usemtl m_2fae0962-6878-9312-f690-fafaddc2a80c
f 132/388/97 135/387/97 133/386/97 130/385/97
f 131/392/98 132/391/98 130/390/98 129/389/98
f 136/396/99 131/395/99 129/394/99 134/393/99
f 135/400/100 136/399/100 134/398/100 133/397/100
f 134/404/101 129/403/101 130/402/101 133/401/101
f 135/408/102 132/407/102 131/406/102 136/405/102
o cube
v -0.00006250000000007638 0.5 0.9375
v -0.00006250000000007638 0.5 0.25
v -0.00006250000000007638 0.1875 0.9375
v -0.00006250000000007638 0.1875 0.25
v -0.00006250000000007638 0.5 0.25
v -0.00006250000000007638 0.5 0.9375
v -0.00006250000000007638 0.1875 0.25
v -0.00006250000000007638 0.1875 0.9375
vt 0.609375 0.359375
vt 0.609375 0.359375
vt 0.609375 0.28125
vt 0.609375 0.28125
vt 0.359375 0.875
vt 0.1875 0.875
vt 0.1875 0.796875
vt 0.359375 0.796875
vt 0.625 0.359375
vt 0.625 0.359375
vt 0.625 0.28125
vt 0.625 0.28125
vt 0.171875 0.875
vt 0 0.875
vt 0 0.796875
vt 0.171875 0.796875
vt 0.046875 0.171875
vt 0.046875 0.171875
vt 0.046875 0.34375
vt 0.046875 0.34375
vt 0.0625 0.34375
vt 0.0625 0.34375
vt 0.0625 0.171875
vt 0.0625 0.171875
vn 0 0 -1
vn 1 0 0
vn 0 0 1
vn -1 0 0
vn 0 1 0
vn 0 -1 0
usemtl m_2fae0962-6878-9312-f690-fafaddc2a80c
f 140/412/103 143/411/103 141/410/103 138/409/103
f 139/416/104 140/415/104 138/414/104 137/413/104
f 144/420/105 139/419/105 137/418/105 142/417/105
f 143/424/106 144/423/106 142/422/106 141/421/106
f 142/428/107 137/427/107 138/426/107 141/425/107
f 143/432/108 140/431/108 139/430/108 144/429/108
o cube
v 0.08838834764831843 0.5 -0.546875
v 0.08838834764831843 0.5 -0.546875
v -6.938893903907228e-18 0.41161165235168157 -0.546875
v -6.938893903907228e-18 0.41161165235168157 -0.546875
v 6.938893903907228e-18 0.5883883476483185 -0.546875
v 6.938893903907228e-18 0.5883883476483185 -0.546875
v -0.08838834764831843 0.5 -0.546875
v -0.08838834764831843 0.5 -0.546875
vt 0.609375 0.515625
vt 0.578125 0.515625
vt 0.578125 0.484375
vt 0.609375 0.484375
vt 0.65625 1
vt 0.65625 1
vt 0.65625 0.96875
vt 0.65625 0.96875
vt 0.03125 0.40625
vt 0 0.40625
vt 0 0.375
vt 0.03125 0.375
vt 0.640625 0.78125
vt 0.640625 0.78125
vt 0.640625 0.75
vt 0.640625 0.75
vt 0.640625 0.640625
vt 0.671875 0.640625
vt 0.671875 0.640625
vt 0.640625 0.640625
vt 0.640625 0.625
vt 0.671875 0.625
vt 0.671875 0.625
vt 0.640625 0.625
vn 0 0 -1
vn 0.7071067811865475 -0.7071067811865476 0
vn 0 0 1
vn -0.7071067811865475 0.7071067811865476 0
vn 0.7071067811865476 0.7071067811865475 0
vn -0.7071067811865476 -0.7071067811865475 0
usemtl m_2fae0962-6878-9312-f690-fafaddc2a80c
f 148/436/109 151/435/109 149/434/109 146/433/109
f 147/440/110 148/439/110 146/438/110 145/437/110
f 152/444/111 147/443/111 145/442/111 150/441/111
f 151/448/112 152/447/112 150/446/112 149/445/112
f 150/452/113 145/451/113 146/450/113 149/449/113
f 151/456/114 148/455/114 147/454/114 152/453/114
o cube
v -8.326672684688674e-17 0.628569173824159 0.6875
v -8.326672684688674e-17 0.628569173824159 -0.75
v 0.04640388251536698 0.582165291308792 0.6875
v 0.04640388251536698 0.582165291308792 -0.75
v -0.04695630968816933 0.5816128641359898 -0.75
v -0.04695630968816933 0.5816128641359898 0.6875
v -0.0005524271728022702 0.5352089816206227 -0.75
v -0.0005524271728022702 0.5352089816206227 0.6875
vt 0.640625 0.5625
vt 0.625 0.5625
vt 0.625 0.546875
vt 0.640625 0.546875
vt 0.734375 0.875
vt 0.375 0.875
vt 0.375 0.859375
vt 0.734375 0.859375
vt 0.484375 0.375
vt 0.46875 0.375
vt 0.46875 0.359375
vt 0.484375 0.359375
vt 0.734375 0.890625
vt 0.375 0.890625
vt 0.375 0.875
vt 0.734375 0.875
vt 0.28125 0.25
vt 0.296875 0.25
vt 0.296875 0.609375
vt 0.28125 0.609375
vt 0.296875 0.609375
vt 0.3125 0.609375
vt 0.3125 0.25
vt 0.296875 0.25
vn 0 0 -1
vn 0.7071067811865475 0.7071067811865476 0
vn 0 0 1
vn -0.7071067811865475 -0.7071067811865476 0
vn -0.7071067811865476 0.7071067811865475 0
vn 0.7071067811865476 -0.7071067811865475 0
usemtl m_2fae0962-6878-9312-f690-fafaddc2a80c
f 156/460/115 159/459/115 157/458/115 154/457/115
f 155/464/116 156/463/116 154/462/116 153/461/116
f 160/468/117 155/467/117 153/466/117 158/465/117
f 159/472/118 160/471/118 158/470/118 157/469/118
f 158/476/119 153/475/119 154/474/119 157/473/119
f 159/480/120 156/479/120 155/478/120 160/477/120

Binary file not shown.

View file

@ -0,0 +1,44 @@
[
{
"ID": "musket-mat-0",
"TexturePath": "",
"NormalTexturePath": "",
"MetalRoughnessMap": "",
"DiffuseColour": {
"X": 0.6,
"Y": 0.6,
"Z": 0.6,
"W": 1.0
},
"Roughness": 0.0,
"Metallic": 0.0
},
{
"ID": "musket-mat-1",
"TexturePath": "resources\\models\\musket\\Musket.png",
"NormalTexturePath": "",
"MetalRoughnessMap": "",
"DiffuseColour": {
"X": 0.6,
"Y": 0.6,
"Z": 0.6,
"W": 1.0
},
"Roughness": 0.0,
"Metallic": 0.0
},
{
"ID": "musket-mat-2",
"TexturePath": "",
"NormalTexturePath": "",
"MetalRoughnessMap": "",
"DiffuseColour": {
"X": 0.6,
"Y": 0.6,
"Z": 0.6,
"W": 1.0
},
"Roughness": 0.0,
"Metallic": 0.0
}
]

View file

@ -7,6 +7,7 @@ import org.joml.Vector3f;
import java.util.List; import java.util.List;
public interface IPhysicsController { public interface IPhysicsController {
public boolean ApplyRotationalForce();
public String ID(); public String ID();
public String ActorID(); public String ActorID();
public String MeshID(); public String MeshID();

View file

@ -22,6 +22,7 @@ public class LegacyPhysicsController implements IPhysicsController {
Sensor Sensor
} }
public List<CollisionSensor> collisionSensors; public List<CollisionSensor> collisionSensors;
public Vector3f Velocities = new Vector3f(0,0,0); public Vector3f Velocities = new Vector3f(0,0,0);
public Vector3f WeightBalance = new Vector3f(0,0,0); public Vector3f WeightBalance = new Vector3f(0,0,0);
@ -93,6 +94,11 @@ public class LegacyPhysicsController implements IPhysicsController {
return this; return this;
} }
@Override
public boolean ApplyRotationalForce() {
return false;
}
@Override @Override
public String ID() { public String ID() {
return ""; return "";

View file

@ -2,6 +2,7 @@ package net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody;
import org.joml.Quaternionf; import org.joml.Quaternionf;
import org.joml.Vector3f; import org.joml.Vector3f;
import org.joml.primitives.AABBf;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -34,6 +35,17 @@ public class ConvexMesh {
return vertex; return vertex;
} }
public AABBf GetWorldAABB() {
float minX = Float.MAX_VALUE, minY = Float.MAX_VALUE, minZ = Float.MAX_VALUE;
float maxX = -Float.MAX_VALUE, maxY = -Float.MAX_VALUE, maxZ = -Float.MAX_VALUE;
for (int i = 0; i < LocalVertices.size(); i++) {
Vector3f w = WorldVertex(i);
minX = Math.min(minX, w.x); minY = Math.min(minY, w.y); minZ = Math.min(minZ, w.z);
maxX = Math.max(maxX, w.x); maxY = Math.max(maxY, w.y); maxZ = Math.max(maxZ, w.z);
}
return new AABBf(minX, minY, minZ, maxX, maxY, maxZ);
}
public Vector3f WorldFaceNormal(Face f) { public Vector3f WorldFaceNormal(Face f) {
Vector3f normal = new Vector3f(f.LocalNormal); Vector3f normal = new Vector3f(f.LocalNormal);
Orientation.transform(normal); Orientation.transform(normal);

View file

@ -1,6 +1,7 @@
package net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody; package net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody;
import net.halbear.Terrain4J.EngineCore.Logic.Physics.IPhysicsController; import net.halbear.Terrain4J.EngineCore.Logic.Physics.IPhysicsController;
import net.halbear.Terrain4J.EngineCore.Logic.Physics.LegacyPhysicsController;
import org.joml.Matrix3f; import org.joml.Matrix3f;
import org.joml.Quaternionf; import org.joml.Quaternionf;
import org.joml.Vector3f; import org.joml.Vector3f;
@ -21,6 +22,8 @@ public class RigidBody {
public AABBf BoundingBox; public AABBf BoundingBox;
public boolean OnGround = false;
public Vector3f LastPosition = new Vector3f();
public final Vector3f Position; public final Vector3f Position;
public final Quaternionf Rotation; public final Quaternionf Rotation;
public Vector3f WeightBalance = new Vector3f(0,0,0); public Vector3f WeightBalance = new Vector3f(0,0,0);
@ -44,6 +47,14 @@ public class RigidBody {
public float Friction = 0.5f; public float Friction = 0.5f;
public boolean IsStatic = false; public boolean IsStatic = false;
public boolean RotationLocked = false;
public boolean UsesFrictionResolution = true;
public final Vector3f PreviousPosition = new Vector3f();
public boolean Grounded = false;
public String PhysicsControllerID = "NULL"; public String PhysicsControllerID = "NULL";
public final String RigidBodyID; public final String RigidBodyID;
@ -57,6 +68,13 @@ public class RigidBody {
SetMass(MassKG); SetMass(MassKG);
} }
public RigidBody LockRotation(){
RotationLocked = true;
InverseInertiaLocal.zero();
InverseInertiaWorld.zero();
return this;
}
public void SetMass(float mass) { public void SetMass(float mass) {
this.MassKG = mass; this.MassKG = mass;
if (mass <= 0f) { if (mass <= 0f) {
@ -70,7 +88,7 @@ public class RigidBody {
} }
public void SetRigidBoxInertia(float x, float y, float z){ public void SetRigidBoxInertia(float x, float y, float z){
if(IsStatic) return; if(IsStatic || RotationLocked) return;
float width = 2 * x, height = 2 * y, depth = 2 * z; float width = 2 * x, height = 2 * y, depth = 2 * z;
float ix = (MassKG/12.0f) * (height * height + depth * depth); float ix = (MassKG/12.0f) * (height * height + depth * depth);
float iy = (MassKG/12.0f) * (width * width + depth * depth); float iy = (MassKG/12.0f) * (width * width + depth * depth);
@ -83,7 +101,7 @@ public class RigidBody {
} }
public void UpdateInertiaWorld(){ public void UpdateInertiaWorld(){
if(IsStatic) { if(IsStatic || RotationLocked) {
InverseInertiaWorld.zero(); InverseInertiaWorld.zero();
return; return;
} }
@ -115,8 +133,11 @@ public class RigidBody {
private final Vector3f GravityToAdd = new Vector3f(); private final Vector3f GravityToAdd = new Vector3f();
private final Vector3f VelocityToAdd = new Vector3f(); private final Vector3f VelocityToAdd = new Vector3f();
public void Integrate(float DeltaTime, Vector3f Gravity){ public void Integrate(float DeltaTime, Vector3f Gravity){
PreviousPosition.set(Position);
if(IsStatic) return; if(IsStatic) return;
LinearVelocity.add(GravityToAdd.set(Gravity).mul(DeltaTime)); if(!Grounded) {
LinearVelocity.add(GravityToAdd.set(Gravity).mul(DeltaTime));
}
Position.add(VelocityToAdd.set(LinearVelocity).mul(DeltaTime)); Position.add(VelocityToAdd.set(LinearVelocity).mul(DeltaTime));
Quaternionf Spin = new Quaternionf( Quaternionf Spin = new Quaternionf(

View file

@ -5,8 +5,11 @@ import org.joml.Vector3f;
//Resolves the Separating Axis Theorem Test into reaction forces in impulses and position correction //Resolves the Separating Axis Theorem Test into reaction forces in impulses and position correction
public class RigidCollision { public class RigidCollision {
private static final float CORRECTION_THRESHOLD = 0.9f; //how much it gets corrected positionally per physics step private static final float CORRECTION_THRESHOLD = 1.0f;
private static final float SLOP = 0.001f; // amount of overlap can happen before collision gets corrected private static final float SLOP = 0.00f;
private static final float GROUNDED_DOT_THRESHOLD = 0.7f;
private static final Vector3f WorldUp = new Vector3f(0, 1, 0);
public synchronized static void ResolveCollision(RigidBody body1, RigidBody body2, SeparatingAxisTheoremTester.CollisionResult collisionResult){ public synchronized static void ResolveCollision(RigidBody body1, RigidBody body2, SeparatingAxisTheoremTester.CollisionResult collisionResult){
Vector3f Normal = collisionResult.Normal; Vector3f Normal = collisionResult.Normal;
@ -15,6 +18,9 @@ public class RigidCollision {
} }
CorrectPositioning(body1,body2,Normal,collisionResult.Penetration); CorrectPositioning(body1,body2,Normal,collisionResult.Penetration);
if(Normal.dot(WorldUp) > GROUNDED_DOT_THRESHOLD && !body2.IsStatic) body2.Grounded = true;
if(-Normal.dot(WorldUp) > GROUNDED_DOT_THRESHOLD && !body1.IsStatic) body1.Grounded = true;
} }
private static final Vector3f Dist1 = new Vector3f(); private static final Vector3f Dist1 = new Vector3f();
@ -24,7 +30,6 @@ public class RigidCollision {
private static final Vector3f RelativeVelocity = new Vector3f(); private static final Vector3f RelativeVelocity = new Vector3f();
private synchronized static void ResolveContact(RigidBody body1, RigidBody body2, Vector3f normal, SeparatingAxisTheoremTester.Contact contact){ private synchronized static void ResolveContact(RigidBody body1, RigidBody body2, Vector3f normal, SeparatingAxisTheoremTester.Contact contact){
Vector3f Point = contact.Point; Vector3f Point = contact.Point;
Dist1.set(Point).sub(body1.Position); Dist1.set(Point).sub(body1.Position);
Dist2.set(Point).sub(body2.Position); Dist2.set(Point).sub(body2.Position);
@ -43,8 +48,8 @@ public class RigidCollision {
float j = -(1 + Restitution) * VelocityAlongNormal / InverseMassSum; float j = -(1 + Restitution) * VelocityAlongNormal / InverseMassSum;
Impulse.set(normal).mul(j); Impulse.set(normal).mul(j);
body1.LinearVelocity.mul(-1,body1.LinearVelocity.y < 0 ? 1 : -1,-1).mul(body1.Bounciness,body1.LinearVelocity.y < 0 ? 1 : body1.Bounciness,body1.Bounciness); // body1.LinearVelocity.mul(-1,body1.LinearVelocity.y < 0 ? 1 : -1,-1).mul(body1.Bounciness,body1.LinearVelocity.y < 0 ? 1 : body1.Bounciness,body1.Bounciness);
body2.LinearVelocity.mul(-1,body2.LinearVelocity.y < 0 ? 1 : -1,-1).mul(body2.Bounciness,body2.LinearVelocity.y < 0 ? 1 : body2.Bounciness,body2.Bounciness); // body2.LinearVelocity.mul(-1,body2.LinearVelocity.y < 0 ? 1 : -1,-1).mul(body2.Bounciness,body2.LinearVelocity.y < 0 ? 1 : body2.Bounciness,body2.Bounciness);
body1.ApplyImpulse(NegatedImpulse.set(Impulse).negate(), Point); body1.ApplyImpulse(NegatedImpulse.set(Impulse).negate(), Point);

View file

@ -23,6 +23,7 @@ public class RigidPhysicsController implements IPhysicsController {
return RigidControllerRegister.get(ID); return RigidControllerRegister.get(ID);
} }
public final List<String> Collisions = new ArrayList<>(); public final List<String> Collisions = new ArrayList<>();
public boolean ApplyRotation = true;
public static RigidBody Ground = new RigidBody("FLOOR",ConvexMesh.Box(100,100f,100),0); public static RigidBody Ground = new RigidBody("FLOOR",ConvexMesh.Box(100,100f,100),0);
public static RigidBody Wall = new RigidBody("WALL",ConvexMesh.Box(100,100f,10),0); public static RigidBody Wall = new RigidBody("WALL",ConvexMesh.Box(100,100f,10),0);
@ -78,6 +79,11 @@ public class RigidPhysicsController implements IPhysicsController {
return this; return this;
} }
@Override
public boolean ApplyRotationalForce() {
return ApplyRotation;
}
@Override @Override
public String ID() { public String ID() {
return ControllerID; return ControllerID;
@ -103,7 +109,7 @@ public class RigidPhysicsController implements IPhysicsController {
rigidBody.Integrate(DeltaTime, new Vector3f(0,-1.8f,0)); rigidBody.Integrate(DeltaTime, new Vector3f(0,-1.8f,0));
if(Actor.Actors.get(ActorID) != null) { if(Actor.Actors.get(ActorID) != null) {
Actor.Actors.get(ActorID).SetPosition(new Vector3f(rigidBody.Position)); Actor.Actors.get(ActorID).SetPosition(new Vector3f(rigidBody.Position));
Actor.Actors.get(ActorID).SetRotation(rigidBody.Rotation); if(ApplyRotation) Actor.Actors.get(ActorID).SetRotation(rigidBody.Rotation);
} }
} }
/* /*

View file

@ -115,6 +115,7 @@ public class SeparatingAxisTheoremTester {
//Face collision/clipping //Face collision/clipping
ConvexMesh ReferenceMesh = BestFaceOwner; ConvexMesh ReferenceMesh = BestFaceOwner;
if(ReferenceMesh == null) return null;
ConvexMesh IncidentMesh = (ReferenceMesh == Mesh1) ? Mesh2 : Mesh1; ConvexMesh IncidentMesh = (ReferenceMesh == Mesh1) ? Mesh2 : Mesh1;
ConvexMesh.Face ReferenceFace = BestFace; ConvexMesh.Face ReferenceFace = BestFace;
Vector3f ReferenceFaceNormalWorld = ReferenceMesh.WorldFaceNormal(ReferenceFace); Vector3f ReferenceFaceNormalWorld = ReferenceMesh.WorldFaceNormal(ReferenceFace);

View file

@ -0,0 +1,45 @@
package net.halbear.Terrain4J.EngineCore.Logic.Physics;
import org.joml.primitives.AABBf;
import java.util.*;
public class SpatialHashGrid {
public static float CellSize = 3f;
private static final Map<Long, List<String>> Cells = new HashMap<>();
public static void Clear() {
Cells.clear();
}
public static void Insert(String bodyID, AABBf worldBounds) {
int minX = (int) Math.floor(worldBounds.minX / CellSize);
int minY = (int) Math.floor(worldBounds.minY / CellSize);
int minZ = (int) Math.floor(worldBounds.minZ / CellSize);
int maxX = (int) Math.floor(worldBounds.maxX / CellSize);
int maxY = (int) Math.floor(worldBounds.maxY / CellSize);
int maxZ = (int) Math.floor(worldBounds.maxZ / CellSize);
for (int x = minX; x <= maxX; x++) {
for (int y = minY; y <= maxY; y++) {
for (int z = minZ; z <= maxZ; z++) {
long key = HashCell(x, y, z);
Cells.computeIfAbsent(key, k -> new ArrayList<>()).add(bodyID);
}
}
}
}
private static long HashCell(int x, int y, int z) {
long xi = ((long) x) & 0x1FFFFFL;
long yi = ((long) y) & 0x1FFFFFL;
long zi = ((long) z) & 0x1FFFFFL;
return (xi << 42) | (yi << 21) | zi;
}
public static Collection<List<String>> Buckets() {
return Cells.values();
}
}

View file

@ -1,15 +1,17 @@
package net.halbear.Terrain4J.EngineCore.Logic.Physics; package net.halbear.Terrain4J.EngineCore.Logic.Physics;
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig; import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.ConvexMesh;
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.RigidBody; import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.RigidBody;
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.RigidCollision; import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.RigidCollision;
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.SeparatingAxisTheoremTester; import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.SeparatingAxisTheoremTester;
import net.halbear.Terrain4J.EngineCore.Threads.PhysicsThread; import net.halbear.Terrain4J.EngineCore.Threads.PhysicsThread;
import org.joml.Vector2f;
import org.joml.Vector3f;
import org.joml.primitives.AABBf;
import org.joml.primitives.Intersectionf;
import java.util.ArrayList; import java.util.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class WorldPhysicsManager { public class WorldPhysicsManager {
public static float GravityMS = 9.8f; public static float GravityMS = 9.8f;
@ -75,6 +77,8 @@ public class WorldPhysicsManager {
for (int i = 0; i < ActiveControllers.size(); i++) { for (int i = 0; i < ActiveControllers.size(); i++) {
PhysicsObjects.get(ActiveControllers.get(i)).PhysicsTick(FixedTimeStep, TargetFrameTime); PhysicsObjects.get(ActiveControllers.get(i)).PhysicsTick(FixedTimeStep, TargetFrameTime);
} }
SweepForTunneling();
ResetGroundedFlags();
ResolveAllCollisions(); ResolveAllCollisions();
Accumulator -= FixedTimeStep; Accumulator -= FixedTimeStep;
stepsRun++; stepsRun++;
@ -86,20 +90,61 @@ public class WorldPhysicsManager {
} }
private static void ResolveAllCollisions() { private static void ResolveAllCollisions() {
List<String> ids = RigidBody.RigidBodies; List<String> ids = RigidBody.RigidBodies;
for (int i = 0; i < ids.size(); i++) {
RigidBody a = RigidBody.RigidBodyRegister.get(ids.get(i));
if (a == null) continue;
for (int j = i + 1; j < ids.size(); j++) {
RigidBody b = RigidBody.RigidBodyRegister.get(ids.get(j));
if (b == null) continue;
if (a.IsStatic && b.IsStatic) continue;
SeparatingAxisTheoremTester.CollisionResult result = SeparatingAxisTheoremTester.TestCollision(a.shape, b.shape); List<RigidBody> dynamicBodies = new ArrayList<>();
if (result != null) { List<RigidBody> staticBodies = new ArrayList<>();
RigidCollision.ResolveCollision(a, b, result); Map<String, AABBf> worldBounds = new HashMap<>();
SpatialHashGrid.Clear();
for (int i = 0; i < ids.size(); i++) {
RigidBody body = RigidBody.RigidBodyRegister.get(ids.get(i));
if (body == null) continue;
AABBf bounds = body.shape.GetWorldAABB();
worldBounds.put(body.RigidBodyID, bounds);
if (body.IsStatic) {
staticBodies.add(body);
} else {
dynamicBodies.add(body);
SpatialHashGrid.Insert(body.RigidBodyID, bounds);
}
}
Set<String> testedPairs = new HashSet<>();
for (List<String> bucket : SpatialHashGrid.Buckets()) {
int size = bucket.size();
for (int i = 0; i < size; i++) {
RigidBody a = RigidBody.RigidBodyRegister.get(bucket.get(i));
if (a == null) continue;
for (int j = i + 1; j < size; j++) {
RigidBody b = RigidBody.RigidBodyRegister.get(bucket.get(j));
if (b == null || a == b) continue;
TryResolve(a, b, worldBounds, testedPairs);
} }
} }
} }
for (RigidBody dyn : dynamicBodies) {
for (RigidBody stat : staticBodies) {
TryResolve(dyn, stat, worldBounds, testedPairs);
}
}
}
private static void TryResolve(RigidBody a, RigidBody b, Map<String, AABBf> worldBounds, Set<String> testedPairs) {
String key = a.RigidBodyID.compareTo(b.RigidBodyID) < 0
? a.RigidBodyID + "|" + b.RigidBodyID
: b.RigidBodyID + "|" + a.RigidBodyID;
if (!testedPairs.add(key)) return;
if (!worldBounds.get(a.RigidBodyID).intersectsAABB(worldBounds.get(b.RigidBodyID))) return;
SeparatingAxisTheoremTester.CollisionResult result = SeparatingAxisTheoremTester.TestCollision(a.shape, b.shape);
if (result != null) {
RigidCollision.ResolveCollision(a, b, result);
}
} }
public static void PhysicsTick2(float DeltaTime, float TargetFrameTime){ public static void PhysicsTick2(float DeltaTime, float TargetFrameTime){
@ -109,6 +154,8 @@ public class WorldPhysicsManager {
for (int i = 0; i < ActiveControllers.size(); i++) { for (int i = 0; i < ActiveControllers.size(); i++) {
PhysicsObjects.get(ActiveControllers.get(i)).PhysicsTick(DeltaTime, TargetFrameTime); PhysicsObjects.get(ActiveControllers.get(i)).PhysicsTick(DeltaTime, TargetFrameTime);
} }
SweepForTunneling();
ResetGroundedFlags();
ResolveAllCollisions(); ResolveAllCollisions();
for (int i = 0; i < ActiveControllers.size(); i++) { for (int i = 0; i < ActiveControllers.size(); i++) {
PhysicsObjects.get(ActiveControllers.get(i)).Collisions().clear(); PhysicsObjects.get(ActiveControllers.get(i)).Collisions().clear();
@ -130,4 +177,67 @@ public class WorldPhysicsManager {
} }
} }
private static void ResetGroundedFlags() {
List<String> ids = RigidBody.RigidBodies;
for (int i = 0; i < ids.size(); i++) {
RigidBody body = RigidBody.RigidBodyRegister.get(ids.get(i));
if (body != null) body.Grounded = false;
}
}
public static float MinSweepDistanceFactor = 0.5f;
public static float SweepMarginFactor = 0.5f;
private static void SweepForTunneling() {
List<String> ids = RigidBody.RigidBodies;
for (int i = 0; i < ids.size(); i++) {
RigidBody body = RigidBody.RigidBodyRegister.get(ids.get(i));
if (body == null || body.IsStatic) continue;
Vector3f from = body.PreviousPosition;
Vector3f to = body.Position;
float movedDistanceSq = from.distanceSquared(to);
if (movedDistanceSq < 1e-8f) continue;
float radius = BoundingRadius(body.shape);
float minSweepDistSq = (radius * radius) * (MinSweepDistanceFactor * MinSweepDistanceFactor);
if (movedDistanceSq < minSweepDistSq) continue; // moved a normal, slow amount - discrete SAT already handles this fine
float margin = radius * SweepMarginFactor;
Float earliestT = null;
for (int j = 0; j < ids.size(); j++) {
if (i == j) continue;
RigidBody other = RigidBody.RigidBodyRegister.get(ids.get(j));
if (other == null) continue;
Float t = RaySweepAABB(from, to, other.shape.GetWorldAABB(), margin);
if (t != null && (earliestT == null || t < earliestT)) {
earliestT = t;
}
}
if (earliestT != null) {
Vector3f safePosition = new Vector3f(from).lerp(to, Math.max(0f, earliestT - 0.01f));
body.Position.set(safePosition);
}
}
}
private static Float RaySweepAABB(Vector3f from, Vector3f to, AABBf bounds, float margin) {
Vector3f dir = new Vector3f(to).sub(from);
Vector3f min = new Vector3f(bounds.minX - margin, bounds.minY - margin, bounds.minZ - margin);
Vector3f max = new Vector3f(bounds.maxX + margin, bounds.maxY + margin, bounds.maxZ + margin);
Vector2f result = new Vector2f();
boolean hit = Intersectionf.intersectRayAab(from, dir, min, max, result);
if (!hit) return null;
if (result.x < 0f || result.x > 1f) return null;
return result.x;
}
private static float BoundingRadius(ConvexMesh shape) {
Vector3f half = new Vector3f(shape.TopRightForward).sub(shape.BottomLeftBack).mul(0.5f);
return half.length();
}
} }

View file

@ -45,7 +45,7 @@ import static org.lwjgl.glfw.GLFW.*;
public class GameCore implements GameLogic { public class GameCore implements GameLogic {
private static final float MOUSE_SENSITIVITY = 0.1f; private static final float MOUSE_SENSITIVITY = 0.1f;
private static final float MOVEMENT_SPEED = 0.025f; private static final float MOVEMENT_SPEED = 0.01f;
public static boolean LoadingLevel = false; public static boolean LoadingLevel = false;
public List<Actor> CubeActors = new ArrayList<>(); public List<Actor> CubeActors = new ArrayList<>();
@ -67,6 +67,7 @@ public class GameCore implements GameLogic {
public List<IMoveableActorComponent> ActorEditorComponents = new ArrayList<>(); public List<IMoveableActorComponent> ActorEditorComponents = new ArrayList<>();
private Gimbal gimbal; private Gimbal gimbal;
private Vector2f DeltaPos = new Vector2f(0,0); private Vector2f DeltaPos = new Vector2f(0,0);
private String PlayerActorID = "NULL";
public Vector2f GetDeltaPos(){return DeltaPos;} public Vector2f GetDeltaPos(){return DeltaPos;}
@Override @Override
@ -101,6 +102,17 @@ public class GameCore implements GameLogic {
CollisionMesh mesh = new CollisionMesh("Super Collision Mesh","NULL"); CollisionMesh mesh = new CollisionMesh("Super Collision Mesh","NULL");
mesh.AddNewCollisionPoly(new Vector3f(-100,-5,100),new Vector3f(-100,-5.5f,-100),new Vector3f(100,-6,-100)); mesh.AddNewCollisionPoly(new Vector3f(-100,-5,100),new Vector3f(-100,-5.5f,-100),new Vector3f(100,-6,-100));
mesh.AddNewCollisionPoly(new Vector3f(100,-5.5f,100),new Vector3f(100,-6,-100),new Vector3f(-100,-5,100)); mesh.AddNewCollisionPoly(new Vector3f(100,-5.5f,100),new Vector3f(100,-6,-100),new Vector3f(-100,-5,100));
ModelData MusketData = ModelLoader.LoadModel("resources/models/musket/musket.json");
List<MaterialData> MusketMat = ModelLoader.LoadMaterials("resources/models/musket/musket_mat.json");
var Musket = new PlayerActor("DebugCamera","Player", MusketData.ID(), new Vector3f(0,5f,-5f)).SetCameraOffset(new Vector3f(0,1.0f,0));
Musket.SetPositionOffset(new Vector3f(0.5f,1.0f,-1.25f));
Musket.SetRotation(0,(float)Math.toRadians(180),0);
Musket.CreatePhysicsController( ConvexMesh.Box(0.5f,0.75f,0.5f),200f);
PlayerActorID = "Player";
RigidPhysicsController physicsController = (RigidPhysicsController) Musket.GetPhysicsController();
RigidBody.RigidBodyRegister.get(physicsController.RigidBodyID).LockRotation();
try { try {
Melona.GenerateCollisionMesh(MelonaData); Melona.GenerateCollisionMesh(MelonaData);
Melona.SetPhysicsType(Actor.PhysicsControllerType.T4JLegacyCollision); Melona.SetPhysicsType(Actor.PhysicsControllerType.T4JLegacyCollision);
@ -110,12 +122,15 @@ public class GameCore implements GameLogic {
} }
mesh.RegisterMesh(); mesh.RegisterMesh();
scene.AddActor(Melona); scene.AddActor(Melona);
scene.AddActor(Musket);
ActorEditorComponents.add(new EditorActorComponent(Melona,new Vector3f(0,0f,-5f),new Vector3f(1.0f,1.8f,1.0f))); ActorEditorComponents.add(new EditorActorComponent(Melona,new Vector3f(0,0f,-5f),new Vector3f(1.0f,1.8f,1.0f)));
CubeActors.forEach(scene::AddActor); CubeActors.forEach(scene::AddActor);
List<MaterialData> materials = new ArrayList<>(); List<MaterialData> materials = new ArrayList<>();
materials.addAll(MelonaDataMat); materials.addAll(MelonaDataMat);
materials.addAll(MusketMat);
models.add(MelonaData); models.add(MelonaData);
models.add(MusketData);
Camera camera = scene.GetCamera(); Camera camera = scene.GetCamera();
camera.SetPosition(0,0,0); camera.SetPosition(0,0,0);
camera.SetRotation(0,0,0); camera.SetRotation(0,0,0);
@ -170,7 +185,7 @@ public class GameCore implements GameLogic {
Melona.CreatePhysicsController( ConvexMesh.Box(0.5f,0.5f,0.5f),20); Melona.CreatePhysicsController( ConvexMesh.Box(0.5f,0.5f,0.5f),20);
RigidPhysicsController physicsController = (RigidPhysicsController) Melona.GetPhysicsController(); RigidPhysicsController physicsController = (RigidPhysicsController) Melona.GetPhysicsController();
RigidBody.RigidBodyRegister.get(physicsController.RigidBodyID).LinearVelocity.set(0,0,-20f -(40f * (float)Math.random())); //RigidBody.RigidBodyRegister.get(physicsController.RigidBodyID).LinearVelocity.set(0,0,-20f -(40f * (float)Math.random()));
scene.AddActor(Melona); scene.AddActor(Melona);
} }
@ -224,6 +239,10 @@ public class GameCore implements GameLogic {
@Override @Override
public void RenderThreadInput(EngineInstance engineInstance, long FrameDiffNanoSeconds) { public void RenderThreadInput(EngineInstance engineInstance, long FrameDiffNanoSeconds) {
Actor player = Actor.Actors.get(PlayerActorID);
if(player != null){
player.TickUpdate();
}
engineInstance.scene().CameraTick(FrameDiffNanoSeconds); engineInstance.scene().CameraTick(FrameDiffNanoSeconds);
if(ChangeGraphicsSettings){ if(ChangeGraphicsSettings){
if(NextAAMode != -1){ if(NextAAMode != -1){
@ -248,6 +267,8 @@ public class GameCore implements GameLogic {
KeyboardInput input = window.getKeyboardInput(); KeyboardInput input = window.getKeyboardInput();
float MovementDist = (float)(FrameDiffNanoSeconds / 1000000L) * MOVEMENT_SPEED; float MovementDist = (float)(FrameDiffNanoSeconds / 1000000L) * MOVEMENT_SPEED;
Camera camera = scene.GetCamera(); Camera camera = scene.GetCamera();
PlayerActor playerActor = (PlayerActor) Actor.Actors.get(PlayerActorID);
if(playerActor!= null)camera = Camera.GetCamera(playerActor.AttachedCameraID);
if(input.keyPressed(GLFW_KEY_ENTER)) { if(input.keyPressed(GLFW_KEY_ENTER)) {
SpawnNewActor(engineInstance, new Vector3f( (float)(5 * Math.random()),20 + (float)(10 * Math.random()), (float)(5 * Math.random())),new Vector3f(-1f + (float)(2 * Math.random()),-1f + (float)(2 * Math.random()),-1f + (float)(2 * Math.random())),new Vector3f((float)Math.random(),(float)Math.random(),(float)Math.random())); SpawnNewActor(engineInstance, new Vector3f( (float)(5 * Math.random()),20 + (float)(10 * Math.random()), (float)(5 * Math.random())),new Vector3f(-1f + (float)(2 * Math.random()),-1f + (float)(2 * Math.random()),-1f + (float)(2 * Math.random())),new Vector3f((float)Math.random(),(float)Math.random(),(float)Math.random()));
} }
@ -269,22 +290,30 @@ public class GameCore implements GameLogic {
EngineConfig.getInstance().SetRenderCollisionMesh(!EngineConfig.getInstance().RenderCollisionMeshes()); EngineConfig.getInstance().SetRenderCollisionMesh(!EngineConfig.getInstance().RenderCollisionMeshes());
} }
if(input.keyPressed(GLFW_KEY_W)){ if(input.keyPressed(GLFW_KEY_W)){
camera.MoveForward(MovementDist); if(playerActor == null)camera.MoveForward(MovementDist);
else playerActor.Move(new Vector3f(MovementDist* (float)Math.sin((camera.GetRotation().y)),0,-MovementDist* (float)Math.cos((camera.GetRotation().y))));
} }
if(input.keyPressed(GLFW_KEY_S)){ if(input.keyPressed(GLFW_KEY_S)){
camera.MoveBackward(MovementDist); if(playerActor == null)camera.MoveBackward(MovementDist);
else playerActor.Move(new Vector3f(-MovementDist* (float)Math.sin((camera.GetRotation().y)),0,MovementDist * (float)Math.cos((camera.GetRotation().y))));
} }
if(input.keyPressed(GLFW_KEY_A)){ if(input.keyPressed(GLFW_KEY_A)){
camera.MoveLeft(MovementDist); if(playerActor == null) camera.MoveLeft(MovementDist);
else playerActor.Move(new Vector3f(-MovementDist * (float)Math.cos((camera.GetRotation().y)),0,-MovementDist * (float)Math.sin((camera.GetRotation().y))));
} }
if(input.keyPressed(GLFW_KEY_D)){ if(input.keyPressed(GLFW_KEY_D)){
camera.MoveRight(MovementDist); if(playerActor == null)camera.MoveRight(MovementDist);
else playerActor.Move(new Vector3f(MovementDist * (float)Math.cos((camera.GetRotation().y)),0,MovementDist * (float)Math.sin((camera.GetRotation().y))));
} }
if(input.keyPressed(GLFW_KEY_SPACE)){ if(input.keyPressed(GLFW_KEY_SPACE)){
camera.MoveUp(MovementDist); if(playerActor == null)camera.MoveUp(MovementDist);
}
if(input.keySinglePress(GLFW_KEY_SPACE)){
// camera.MoveUp(MovementDist);
if(playerActor != null)playerActor.Move(new Vector3f(0,5f,0));
} }
if(input.keyPressed(GLFW_KEY_LEFT_SHIFT)){ if(input.keyPressed(GLFW_KEY_LEFT_SHIFT)){
camera.MoveDown(MovementDist); if(playerActor == null)camera.MoveDown(MovementDist);
} }
if(input.keyPressed(GLFW_KEY_LEFT_CONTROL)){ if(input.keyPressed(GLFW_KEY_LEFT_CONTROL)){
camera.Sprint(true); camera.Sprint(true);
@ -340,7 +369,7 @@ public class GameCore implements GameLogic {
if(PrimaryRuntime.GetFastThread().Ticks(20)==0){ if(PrimaryRuntime.GetFastThread().Ticks(20)==0){
//CollisionManager.UpdateCollisionChunks(); //CollisionManager.UpdateCollisionChunks();
} }
WorldPhysicsManager.SteppedPhysicsTick2(DeltaTime, PhysicsFramerate); WorldPhysicsManager.PhysicsTick2(DeltaTime, PhysicsFramerate);
} }
@Override @Override

View file

@ -29,6 +29,7 @@ public class Actor{
private final String ModelID; private final String ModelID;
private final Matrix4f ModelMatrix; private final Matrix4f ModelMatrix;
private final Vector3f Position; private final Vector3f Position;
private final Vector3f PositionOffset;
private final Quaternionf Rotation; private final Quaternionf Rotation;
private CollisionMesh collisionMesh; private CollisionMesh collisionMesh;
private Vector3f Scale; private Vector3f Scale;
@ -51,6 +52,7 @@ public class Actor{
ActorNames.add(ID); ActorNames.add(ID);
this.ModelID = ModelID; this.ModelID = ModelID;
this.Position = Position; this.Position = Position;
this.PositionOffset = new Vector3f();
TemporaryVector = new Vector3f(); TemporaryVector = new Vector3f();
PivotOffset = new Vector3f(); PivotOffset = new Vector3f();
AdditionalPivotOffset = new Vector3f(); AdditionalPivotOffset = new Vector3f();
@ -61,6 +63,20 @@ public class Actor{
Actors.put(ID,this); Actors.put(ID,this);
} }
public Vector3f GetPositionOffset(){
return PositionOffset;
}
public Actor SetPositionOffset(Vector3f PositionOffset){
this.PositionOffset.set(PositionOffset);
return this;
}
public Actor SetPositionOffset(float x, float y, float z){
this.PositionOffset.set(x,y,z);
return this;
}
public Vector3f GetAditionalPivotOffset(){return AdditionalPivotOffset;} public Vector3f GetAditionalPivotOffset(){return AdditionalPivotOffset;}
public Actor SetAditionalPivotOffset(Vector3f offset){ public Actor SetAditionalPivotOffset(Vector3f offset){
@ -75,6 +91,10 @@ public class Actor{
return this; return this;
} }
public void TickUpdate() {
}
public IPhysicsController GetPhysicsController(){return physicsController;} public IPhysicsController GetPhysicsController(){return physicsController;}
public Actor CreatePhysicsController(ConvexMesh mesh, float Mass){ public Actor CreatePhysicsController(ConvexMesh mesh, float Mass){
@ -106,6 +126,13 @@ public class Actor{
UpdateModelMatrix(); UpdateModelMatrix();
return this; return this;
} }
public Actor SetRotMatrix(Vector3f rot){
Rotation.set(0,0,0,1.0f);
SetRotation(rot);
return this;
}
public Actor SetRotation(Vector3f rot){ public Actor SetRotation(Vector3f rot){
Rotation.rotateX(rot.x); Rotation.rotateX(rot.x);
Rotation.rotateY(rot.y); Rotation.rotateY(rot.y);
@ -146,7 +173,8 @@ public class Actor{
public void UpdateModelMatrix(){ public void UpdateModelMatrix(){
ModelMatrix.translateLocal(TemporaryVector.set(PivotOffset).add(AdditionalPivotOffset)); ModelMatrix.translateLocal(TemporaryVector.set(PivotOffset).add(AdditionalPivotOffset));
ModelMatrix.translationRotateScale(Position, Rotation, Scale); ModelMatrix.translationRotateScale(new Vector3f(Position), Rotation, Scale);
ModelMatrix.translate(PositionOffset);
ModelMatrix.translateLocal(TemporaryVector.negate()); ModelMatrix.translateLocal(TemporaryVector.negate());
} }

View file

@ -4,7 +4,12 @@ import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
import org.joml.Matrix4f; import org.joml.Matrix4f;
import org.joml.Vector3f; import org.joml.Vector3f;
import java.util.HashMap;
import java.util.Map;
public class Camera { public class Camera {
public static final Map<String, Camera> CameraRegistry = new HashMap<>();
private final Vector3f Direction; private final Vector3f Direction;
private final Vector3f Position; private final Vector3f Position;
private final Vector3f Right; private final Vector3f Right;
@ -13,12 +18,13 @@ public class Camera {
private final Matrix4f ViewMatrix; private final Matrix4f ViewMatrix;
private float FOV = (float) (60 * EngineConfig.DegToRad); private float FOV = (float) (60 * EngineConfig.DegToRad);
private boolean Sprint; private boolean Sprint;
private final String ID;
public Vector3f GetDirection(){ public Vector3f GetDirection(){
return Direction; return Direction;
} }
public Camera CloneCamera(){ public Camera CloneCamera(String CameraName){
Camera NewCam = new Camera(); Camera NewCam = new Camera(CameraName);
NewCam.SetPosition(Position.x, Position.y, Position.z); NewCam.SetPosition(Position.x, Position.y, Position.z);
NewCam.SetRotation(Rotation.x, Rotation.y, Rotation.z); NewCam.SetRotation(Rotation.x, Rotation.y, Rotation.z);
NewCam.Right.set(new Vector3f(Right)); NewCam.Right.set(new Vector3f(Right));
@ -29,13 +35,23 @@ public class Camera {
return NewCam; return NewCam;
} }
public Camera(){ public static Camera GetCamera(String CameraID){
return CameraRegistry.get(CameraID);
}
public String GetID(){
return ID;
}
public Camera(String CameraName){
Direction = new Vector3f(); Direction = new Vector3f();
Position = new Vector3f(); Position = new Vector3f();
Right = new Vector3f(); Right = new Vector3f();
Rotation = new Vector3f(); Rotation = new Vector3f();
Up = new Vector3f(); Up = new Vector3f();
ViewMatrix = new Matrix4f(); ViewMatrix = new Matrix4f();
ID = CameraName;
CameraRegistry.put(CameraName,this);
} }
public Camera SetFOVrad(float FOVradians){ public Camera SetFOVrad(float FOVradians){

View file

@ -0,0 +1,70 @@
package net.halbear.Terrain4J.EngineCore.Main.Scene;
import net.halbear.Terrain4J.EngineCore.Logic.EngineConfig;
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.ConvexMesh;
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.RigidBody;
import net.halbear.Terrain4J.EngineCore.Logic.Physics.RigidBody.RigidPhysicsController;
import org.joml.Quaternionf;
import org.joml.Vector3f;
import org.tinylog.Logger;
public class PlayerActor extends Actor{
public String AttachedCameraID;
public final Vector3f CameraOffset = new Vector3f(0,0,0);
Camera PlayerCam;
public PlayerActor(String AttachedCameraID, String ID, String ModelID, Vector3f Position) {
this.AttachedCameraID = AttachedCameraID;
PlayerCam = Camera.CameraRegistry.get(AttachedCameraID);
super(ID, ModelID, Position);
}
@Override
public Actor CreatePhysicsController(ConvexMesh mesh, float Mass){
super.CreatePhysicsController(mesh,Mass);
RigidPhysicsController controller = (RigidPhysicsController)GetPhysicsController();
controller.ApplyRotation = false;
return this;
}
public PlayerActor SetCameraOffset(Vector3f Offset){
CameraOffset.set(Offset);
return this;
}
@Override
public void TickUpdate(){
Vector3f Rotation = PlayerCam.GetRotation();
Vector3f Position = new Vector3f(GetPosition());
GetRotation().identity().rotateYXZ(-Rotation.y, -Rotation.x, Rotation.z);
UpdateModelMatrix();
if(Position == null || CameraOffset == null) return;
Position.add(CameraOffset);
PlayerCam.SetPosition(Position.x, Position.y, Position.z);
}
public void Move(Vector3f Velocity){
if(PhysicsType == PhysicsControllerType.RigidBodySeparatingAxisTheory) {
RigidPhysicsController physicsController = (RigidPhysicsController) GetPhysicsController();
RigidBody.RigidBodyRegister.get(physicsController.RigidBodyID).LinearVelocity.add(Velocity);
}
}
/* @Override
public void UpdateModelMatrix(){
if(PlayerCam != null){
Vector3f Rotation = PlayerCam.GetRotation();
Vector3f Position = new Vector3f(GetPosition());
SetRotMatrix(new Vector3f(Rotation.x,Rotation.y,Rotation.z));
super.UpdateModelMatrix();
if(Position == null || CameraOffset == null) return;
Position.add(CameraOffset);
PlayerCam.SetPosition(Position.x, Position.y, Position.z);
} else{
super.UpdateModelMatrix();
}
}*/
}

View file

@ -81,7 +81,7 @@ public class Scene implements IScene {
ActiveActors = new ArrayList<>(); ActiveActors = new ArrayList<>();
CameraFrames = new HashMap<>(); CameraFrames = new HashMap<>();
var EngConfig = EngineConfig.getInstance(); var EngConfig = EngineConfig.getInstance();
camera = new Camera(); camera = new Camera("DebugCamera");
LastCameraFrame = new CameraFrame(camera.GetPosition(),camera.GetRotation(),camera.GetFOV(), "NO_FRAME"); LastCameraFrame = new CameraFrame(camera.GetPosition(),camera.GetRotation(),camera.GetFOV(), "NO_FRAME");
Projection = new Project3D(camera.GetFOV(),EngConfig.GetZNearPlane(), EngConfig.GetZFarPlane(), Projection = new Project3D(camera.GetFOV(),EngConfig.GetZNearPlane(), EngConfig.GetZFarPlane(),
window.getWidth(), window.getHeight()); window.getWidth(), window.getHeight());