@quake2ts/shared 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/index.global.js +2 -0
- package/dist/browser/index.global.js.map +1 -0
- package/dist/cjs/index.cjs +6569 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/index.js +6200 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/audio/constants.d.ts +24 -0
- package/dist/types/audio/constants.d.ts.map +1 -0
- package/dist/types/bsp/collision.d.ts +201 -0
- package/dist/types/bsp/collision.d.ts.map +1 -0
- package/dist/types/bsp/contents.d.ts +72 -0
- package/dist/types/bsp/contents.d.ts.map +1 -0
- package/dist/types/bsp/spatial.d.ts +13 -0
- package/dist/types/bsp/spatial.d.ts.map +1 -0
- package/dist/types/index.d.ts +38 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/inventory-helpers.d.ts +19 -0
- package/dist/types/inventory-helpers.d.ts.map +1 -0
- package/dist/types/io/binaryStream.d.ts +38 -0
- package/dist/types/io/binaryStream.d.ts.map +1 -0
- package/dist/types/io/binaryWriter.d.ts +26 -0
- package/dist/types/io/binaryWriter.d.ts.map +1 -0
- package/dist/types/io/index.d.ts +4 -0
- package/dist/types/io/index.d.ts.map +1 -0
- package/dist/types/io/messageBuilder.d.ts +21 -0
- package/dist/types/io/messageBuilder.d.ts.map +1 -0
- package/dist/types/items/ammo.d.ts +40 -0
- package/dist/types/items/ammo.d.ts.map +1 -0
- package/dist/types/items/index.d.ts +8 -0
- package/dist/types/items/index.d.ts.map +1 -0
- package/dist/types/items/powerups.d.ts +31 -0
- package/dist/types/items/powerups.d.ts.map +1 -0
- package/dist/types/items/weaponInfo.d.ts +5 -0
- package/dist/types/items/weaponInfo.d.ts.map +1 -0
- package/dist/types/items/weapons.d.ts +27 -0
- package/dist/types/items/weapons.d.ts.map +1 -0
- package/dist/types/math/angles.d.ts +19 -0
- package/dist/types/math/angles.d.ts.map +1 -0
- package/dist/types/math/anorms.d.ts +2 -0
- package/dist/types/math/anorms.d.ts.map +1 -0
- package/dist/types/math/color.d.ts +12 -0
- package/dist/types/math/color.d.ts.map +1 -0
- package/dist/types/math/mat4.d.ts +7 -0
- package/dist/types/math/mat4.d.ts.map +1 -0
- package/dist/types/math/random.d.ts +60 -0
- package/dist/types/math/random.d.ts.map +1 -0
- package/dist/types/math/vec3.d.ts +79 -0
- package/dist/types/math/vec3.d.ts.map +1 -0
- package/dist/types/net/driver.d.ts +10 -0
- package/dist/types/net/driver.d.ts.map +1 -0
- package/dist/types/net/index.d.ts +3 -0
- package/dist/types/net/index.d.ts.map +1 -0
- package/dist/types/net/netchan.d.ts +85 -0
- package/dist/types/net/netchan.d.ts.map +1 -0
- package/dist/types/pmove/apply.d.ts +5 -0
- package/dist/types/pmove/apply.d.ts.map +1 -0
- package/dist/types/pmove/categorize.d.ts +36 -0
- package/dist/types/pmove/categorize.d.ts.map +1 -0
- package/dist/types/pmove/config.d.ts +5 -0
- package/dist/types/pmove/config.d.ts.map +1 -0
- package/dist/types/pmove/constants.d.ts +76 -0
- package/dist/types/pmove/constants.d.ts.map +1 -0
- package/dist/types/pmove/currents.d.ts +58 -0
- package/dist/types/pmove/currents.d.ts.map +1 -0
- package/dist/types/pmove/dimensions.d.ts +14 -0
- package/dist/types/pmove/dimensions.d.ts.map +1 -0
- package/dist/types/pmove/duck.d.ts +39 -0
- package/dist/types/pmove/duck.d.ts.map +1 -0
- package/dist/types/pmove/fly.d.ts +34 -0
- package/dist/types/pmove/fly.d.ts.map +1 -0
- package/dist/types/pmove/index.d.ts +18 -0
- package/dist/types/pmove/index.d.ts.map +1 -0
- package/dist/types/pmove/jump.d.ts +28 -0
- package/dist/types/pmove/jump.d.ts.map +1 -0
- package/dist/types/pmove/move.d.ts +78 -0
- package/dist/types/pmove/move.d.ts.map +1 -0
- package/dist/types/pmove/pmove.d.ts +40 -0
- package/dist/types/pmove/pmove.d.ts.map +1 -0
- package/dist/types/pmove/slide.d.ts +63 -0
- package/dist/types/pmove/slide.d.ts.map +1 -0
- package/dist/types/pmove/snap.d.ts +40 -0
- package/dist/types/pmove/snap.d.ts.map +1 -0
- package/dist/types/pmove/special.d.ts +39 -0
- package/dist/types/pmove/special.d.ts.map +1 -0
- package/dist/types/pmove/stuck.d.ts +21 -0
- package/dist/types/pmove/stuck.d.ts.map +1 -0
- package/dist/types/pmove/types.d.ts +72 -0
- package/dist/types/pmove/types.d.ts.map +1 -0
- package/dist/types/pmove/view.d.ts +19 -0
- package/dist/types/pmove/view.d.ts.map +1 -0
- package/dist/types/pmove/water.d.ts +21 -0
- package/dist/types/pmove/water.d.ts.map +1 -0
- package/dist/types/protocol/bitpack.d.ts +17 -0
- package/dist/types/protocol/bitpack.d.ts.map +1 -0
- package/dist/types/protocol/configstrings.d.ts +73 -0
- package/dist/types/protocol/configstrings.d.ts.map +1 -0
- package/dist/types/protocol/constants.d.ts +36 -0
- package/dist/types/protocol/constants.d.ts.map +1 -0
- package/dist/types/protocol/contracts.d.ts +17 -0
- package/dist/types/protocol/contracts.d.ts.map +1 -0
- package/dist/types/protocol/crc.d.ts +5 -0
- package/dist/types/protocol/crc.d.ts.map +1 -0
- package/dist/types/protocol/cvar.d.ts +15 -0
- package/dist/types/protocol/cvar.d.ts.map +1 -0
- package/dist/types/protocol/effects.d.ts +33 -0
- package/dist/types/protocol/effects.d.ts.map +1 -0
- package/dist/types/protocol/entity.d.ts +46 -0
- package/dist/types/protocol/entity.d.ts.map +1 -0
- package/dist/types/protocol/entityEvent.d.ts +13 -0
- package/dist/types/protocol/entityEvent.d.ts.map +1 -0
- package/dist/types/protocol/entityState.d.ts +26 -0
- package/dist/types/protocol/entityState.d.ts.map +1 -0
- package/dist/types/protocol/index.d.ts +19 -0
- package/dist/types/protocol/index.d.ts.map +1 -0
- package/dist/types/protocol/layout.d.ts +9 -0
- package/dist/types/protocol/layout.d.ts.map +1 -0
- package/dist/types/protocol/ops.d.ts +44 -0
- package/dist/types/protocol/ops.d.ts.map +1 -0
- package/dist/types/protocol/player-state.d.ts +40 -0
- package/dist/types/protocol/player-state.d.ts.map +1 -0
- package/dist/types/protocol/player.d.ts +28 -0
- package/dist/types/protocol/player.d.ts.map +1 -0
- package/dist/types/protocol/renderFx.d.ts +23 -0
- package/dist/types/protocol/renderFx.d.ts.map +1 -0
- package/dist/types/protocol/stats.d.ts +61 -0
- package/dist/types/protocol/stats.d.ts.map +1 -0
- package/dist/types/protocol/tempEntity.d.ts +67 -0
- package/dist/types/protocol/tempEntity.d.ts.map +1 -0
- package/dist/types/protocol/usercmd.d.ts +33 -0
- package/dist/types/protocol/usercmd.d.ts.map +1 -0
- package/dist/types/protocol/writeUserCmd.d.ts +4 -0
- package/dist/types/protocol/writeUserCmd.d.ts.map +1 -0
- package/dist/types/replay/index.d.ts +3 -0
- package/dist/types/replay/index.d.ts.map +1 -0
- package/dist/types/replay/io.d.ts +7 -0
- package/dist/types/replay/io.d.ts.map +1 -0
- package/dist/types/replay/schema.d.ts +41 -0
- package/dist/types/replay/schema.d.ts.map +1 -0
- package/dist/types/testing.d.ts +6 -0
- package/dist/types/testing.d.ts.map +1 -0
- package/package.json +43 -0
- package/src/audio/constants.ts +35 -0
- package/src/bsp/collision.ts +1075 -0
- package/src/bsp/contents.ts +108 -0
- package/src/bsp/spatial.ts +116 -0
- package/src/index.ts +37 -0
- package/src/inventory-helpers.ts +81 -0
- package/src/io/binaryStream.ts +159 -0
- package/src/io/binaryWriter.ts +146 -0
- package/src/io/index.ts +3 -0
- package/src/io/messageBuilder.ts +117 -0
- package/src/items/ammo.ts +47 -0
- package/src/items/index.ts +8 -0
- package/src/items/powerups.ts +32 -0
- package/src/items/weaponInfo.ts +45 -0
- package/src/items/weapons.ts +28 -0
- package/src/math/angles.ts +135 -0
- package/src/math/anorms.ts +165 -0
- package/src/math/color.ts +42 -0
- package/src/math/mat4.ts +58 -0
- package/src/math/random.ts +182 -0
- package/src/math/vec3.ts +379 -0
- package/src/net/driver.ts +9 -0
- package/src/net/index.ts +2 -0
- package/src/net/netchan.ts +451 -0
- package/src/pmove/apply.ts +151 -0
- package/src/pmove/categorize.ts +162 -0
- package/src/pmove/config.ts +5 -0
- package/src/pmove/constants.ts +94 -0
- package/src/pmove/currents.ts +287 -0
- package/src/pmove/dimensions.ts +40 -0
- package/src/pmove/duck.ts +154 -0
- package/src/pmove/fly.ts +197 -0
- package/src/pmove/index.ts +18 -0
- package/src/pmove/jump.ts +92 -0
- package/src/pmove/move.ts +527 -0
- package/src/pmove/pmove.ts +446 -0
- package/src/pmove/slide.ts +267 -0
- package/src/pmove/snap.ts +89 -0
- package/src/pmove/special.ts +207 -0
- package/src/pmove/stuck.ts +258 -0
- package/src/pmove/types.ts +82 -0
- package/src/pmove/view.ts +57 -0
- package/src/pmove/water.ts +56 -0
- package/src/protocol/bitpack.ts +139 -0
- package/src/protocol/configstrings.ts +104 -0
- package/src/protocol/constants.ts +40 -0
- package/src/protocol/contracts.ts +149 -0
- package/src/protocol/crc.ts +32 -0
- package/src/protocol/cvar.ts +15 -0
- package/src/protocol/effects.ts +33 -0
- package/src/protocol/entity.ts +304 -0
- package/src/protocol/entityEvent.ts +14 -0
- package/src/protocol/entityState.ts +28 -0
- package/src/protocol/index.ts +19 -0
- package/src/protocol/layout.ts +9 -0
- package/src/protocol/ops.ts +49 -0
- package/src/protocol/player-state.ts +51 -0
- package/src/protocol/player.ts +165 -0
- package/src/protocol/renderFx.ts +22 -0
- package/src/protocol/stats.ts +161 -0
- package/src/protocol/tempEntity.ts +69 -0
- package/src/protocol/usercmd.ts +63 -0
- package/src/protocol/writeUserCmd.ts +30 -0
- package/src/replay/index.ts +2 -0
- package/src/replay/io.ts +37 -0
- package/src/replay/schema.ts +42 -0
- package/src/testing.ts +200 -0
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { ANORMS } from '../math/anorms.js';
|
|
2
|
+
|
|
3
|
+
export class NetworkMessageBuilder {
|
|
4
|
+
private buffer: Uint8Array;
|
|
5
|
+
private view: DataView;
|
|
6
|
+
private offset: number;
|
|
7
|
+
|
|
8
|
+
constructor(initialSize: number = 1024) {
|
|
9
|
+
this.buffer = new Uint8Array(initialSize);
|
|
10
|
+
this.view = new DataView(this.buffer.buffer);
|
|
11
|
+
this.offset = 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
private ensureCapacity(needed: number): void {
|
|
15
|
+
if (this.offset + needed > this.buffer.length) {
|
|
16
|
+
const newSize = Math.max(this.buffer.length * 2, this.offset + needed);
|
|
17
|
+
const newBuffer = new Uint8Array(newSize);
|
|
18
|
+
newBuffer.set(this.buffer);
|
|
19
|
+
this.buffer = newBuffer;
|
|
20
|
+
this.view = new DataView(this.buffer.buffer);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public getData(): Uint8Array {
|
|
25
|
+
return this.buffer.slice(0, this.offset);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public writeByte(value: number): void {
|
|
29
|
+
this.ensureCapacity(1);
|
|
30
|
+
this.view.setUint8(this.offset, value);
|
|
31
|
+
this.offset += 1;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public writeChar(value: number): void {
|
|
35
|
+
this.ensureCapacity(1);
|
|
36
|
+
this.view.setInt8(this.offset, value);
|
|
37
|
+
this.offset += 1;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public writeShort(value: number): void {
|
|
41
|
+
this.ensureCapacity(2);
|
|
42
|
+
this.view.setInt16(this.offset, value, true);
|
|
43
|
+
this.offset += 2;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public writeUShort(value: number): void {
|
|
47
|
+
this.ensureCapacity(2);
|
|
48
|
+
this.view.setUint16(this.offset, value, true);
|
|
49
|
+
this.offset += 2;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public writeLong(value: number): void {
|
|
53
|
+
this.ensureCapacity(4);
|
|
54
|
+
this.view.setInt32(this.offset, value, true);
|
|
55
|
+
this.offset += 4;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public writeFloat(value: number): void {
|
|
59
|
+
this.ensureCapacity(4);
|
|
60
|
+
this.view.setFloat32(this.offset, value, true);
|
|
61
|
+
this.offset += 4;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public writeString(value: string): void {
|
|
65
|
+
const len = value.length + 1; // +1 for null terminator
|
|
66
|
+
this.ensureCapacity(len);
|
|
67
|
+
for (let i = 0; i < value.length; i++) {
|
|
68
|
+
this.view.setUint8(this.offset + i, value.charCodeAt(i));
|
|
69
|
+
}
|
|
70
|
+
this.view.setUint8(this.offset + value.length, 0);
|
|
71
|
+
this.offset += len;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public writeData(data: Uint8Array): void {
|
|
75
|
+
this.ensureCapacity(data.length);
|
|
76
|
+
this.buffer.set(data, this.offset);
|
|
77
|
+
this.offset += data.length;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public writeCoord(value: number): void {
|
|
81
|
+
this.writeShort(Math.round(value * 8.0));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public writeAngle(value: number): void {
|
|
85
|
+
this.writeByte(Math.round(value * 256.0 / 360.0) & 255);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public writeAngle16(value: number): void {
|
|
89
|
+
this.writeShort(Math.round(value * 65536.0 / 360.0));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
public writeDir(x: number, y: number, z: number): void {
|
|
93
|
+
// Find closest normal from ANORMS
|
|
94
|
+
// Simple brute force or use lookup if needed.
|
|
95
|
+
// For now, let's just use 0 if implementation is complex to find best match.
|
|
96
|
+
// Or unimplemented for now?
|
|
97
|
+
// "WriteDir" in Q2 usually means writing a byte index into ANORMS.
|
|
98
|
+
|
|
99
|
+
let best = 0;
|
|
100
|
+
let bestDot = -999999;
|
|
101
|
+
|
|
102
|
+
const len = Math.sqrt(x*x + y*y + z*z);
|
|
103
|
+
if (len > 0) {
|
|
104
|
+
x /= len; y /= len; z /= len;
|
|
105
|
+
|
|
106
|
+
for (let i=0; i<162; i++) {
|
|
107
|
+
const dot = x*ANORMS[i][0] + y*ANORMS[i][1] + z*ANORMS[i][2];
|
|
108
|
+
if (dot > bestDot) {
|
|
109
|
+
bestDot = dot;
|
|
110
|
+
best = i;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
this.writeByte(best);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ammo type identifiers shared across game and cgame.
|
|
3
|
+
* Reference: rerelease/g_items.cpp, game/src/inventory/ammo.ts
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export enum AmmoType {
|
|
7
|
+
Bullets = 0,
|
|
8
|
+
Shells,
|
|
9
|
+
Rockets,
|
|
10
|
+
Grenades,
|
|
11
|
+
Cells,
|
|
12
|
+
Slugs,
|
|
13
|
+
// RAFAEL
|
|
14
|
+
MagSlugs,
|
|
15
|
+
Trap,
|
|
16
|
+
// RAFAEL
|
|
17
|
+
// ROGUE
|
|
18
|
+
Flechettes,
|
|
19
|
+
Tesla,
|
|
20
|
+
Disruptor, // Was missing or named differently?
|
|
21
|
+
Prox,
|
|
22
|
+
// ROGUE
|
|
23
|
+
// Custom or Extras?
|
|
24
|
+
Nuke,
|
|
25
|
+
Rounds,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const AMMO_TYPE_COUNT = Object.keys(AmmoType).length / 2;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Item classnames for ammo pickups.
|
|
32
|
+
* Used for spawning and identifying ammo items.
|
|
33
|
+
*/
|
|
34
|
+
export enum AmmoItemId {
|
|
35
|
+
Shells = 'ammo_shells',
|
|
36
|
+
Bullets = 'ammo_bullets',
|
|
37
|
+
Rockets = 'ammo_rockets',
|
|
38
|
+
Grenades = 'ammo_grenades',
|
|
39
|
+
Cells = 'ammo_cells',
|
|
40
|
+
Slugs = 'ammo_slugs',
|
|
41
|
+
MagSlugs = 'ammo_magslug',
|
|
42
|
+
Flechettes = 'ammo_flechettes',
|
|
43
|
+
Disruptor = 'ammo_disruptor',
|
|
44
|
+
Tesla = 'ammo_tesla',
|
|
45
|
+
Trap = 'ammo_trap',
|
|
46
|
+
Prox = 'ammo_prox',
|
|
47
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Powerup identifiers shared across game and cgame.
|
|
3
|
+
* Reference: rerelease/g_items.cpp, game/src/inventory/playerInventory.ts
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export enum PowerupId {
|
|
7
|
+
QuadDamage = 'quad',
|
|
8
|
+
Invulnerability = 'invulnerability',
|
|
9
|
+
EnviroSuit = 'enviro_suit',
|
|
10
|
+
Rebreather = 'rebreather',
|
|
11
|
+
Silencer = 'silencer',
|
|
12
|
+
// New additions for demo playback and extended support
|
|
13
|
+
PowerScreen = 'power_screen',
|
|
14
|
+
PowerShield = 'power_shield',
|
|
15
|
+
QuadFire = 'quad_fire',
|
|
16
|
+
Invisibility = 'invisibility',
|
|
17
|
+
Bandolier = 'bandolier',
|
|
18
|
+
AmmoPack = 'ammo_pack',
|
|
19
|
+
IRGoggles = 'ir_goggles',
|
|
20
|
+
DoubleDamage = 'double_damage',
|
|
21
|
+
SphereVengeance = 'sphere_vengeance',
|
|
22
|
+
SphereHunter = 'sphere_hunter',
|
|
23
|
+
SphereDefender = 'sphere_defender',
|
|
24
|
+
Doppelganger = 'doppelganger',
|
|
25
|
+
TagToken = 'tag_token',
|
|
26
|
+
TechResistance = 'tech_resistance',
|
|
27
|
+
TechStrength = 'tech_strength',
|
|
28
|
+
TechHaste = 'tech_haste',
|
|
29
|
+
TechRegeneration = 'tech_regeneration',
|
|
30
|
+
Flashlight = 'flashlight',
|
|
31
|
+
Compass = 'compass',
|
|
32
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { WeaponId } from './weapons.js';
|
|
2
|
+
import { AmmoType } from './ammo.js';
|
|
3
|
+
|
|
4
|
+
// Order matches Q2 original weapon wheel index order for bitmask generation
|
|
5
|
+
// Used by both Game (for STAT_WEAPONS_OWNED calculation) and CGame (for weapon wheel UI)
|
|
6
|
+
export const WEAPON_WHEEL_ORDER: WeaponId[] = [
|
|
7
|
+
WeaponId.Blaster,
|
|
8
|
+
WeaponId.Shotgun,
|
|
9
|
+
WeaponId.SuperShotgun,
|
|
10
|
+
WeaponId.Machinegun,
|
|
11
|
+
WeaponId.Chaingun,
|
|
12
|
+
WeaponId.GrenadeLauncher,
|
|
13
|
+
WeaponId.RocketLauncher,
|
|
14
|
+
WeaponId.HandGrenade,
|
|
15
|
+
WeaponId.HyperBlaster,
|
|
16
|
+
WeaponId.Railgun,
|
|
17
|
+
WeaponId.BFG10K
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
// Mapping of weapon to its ammo type
|
|
21
|
+
// Used by CGame to lookup ammo counts for weapon wheel
|
|
22
|
+
export const WEAPON_AMMO_MAP: Record<WeaponId, AmmoType | null> = {
|
|
23
|
+
[WeaponId.Blaster]: null,
|
|
24
|
+
[WeaponId.Shotgun]: AmmoType.Shells,
|
|
25
|
+
[WeaponId.SuperShotgun]: AmmoType.Shells,
|
|
26
|
+
[WeaponId.Machinegun]: AmmoType.Bullets,
|
|
27
|
+
[WeaponId.Chaingun]: AmmoType.Bullets,
|
|
28
|
+
[WeaponId.HandGrenade]: AmmoType.Grenades,
|
|
29
|
+
[WeaponId.GrenadeLauncher]: AmmoType.Grenades,
|
|
30
|
+
[WeaponId.RocketLauncher]: AmmoType.Rockets,
|
|
31
|
+
[WeaponId.HyperBlaster]: AmmoType.Cells,
|
|
32
|
+
[WeaponId.Railgun]: AmmoType.Slugs,
|
|
33
|
+
[WeaponId.BFG10K]: AmmoType.Cells,
|
|
34
|
+
|
|
35
|
+
// Extensions / Rogue / Xatrix
|
|
36
|
+
[WeaponId.Grapple]: null,
|
|
37
|
+
[WeaponId.ChainFist]: null,
|
|
38
|
+
[WeaponId.EtfRifle]: AmmoType.Flechettes,
|
|
39
|
+
[WeaponId.ProxLauncher]: AmmoType.Prox,
|
|
40
|
+
[WeaponId.IonRipper]: AmmoType.Cells,
|
|
41
|
+
[WeaponId.PlasmaBeam]: AmmoType.Cells,
|
|
42
|
+
[WeaponId.Phalanx]: AmmoType.MagSlugs,
|
|
43
|
+
[WeaponId.Disruptor]: AmmoType.Disruptor,
|
|
44
|
+
[WeaponId.Trap]: AmmoType.Trap,
|
|
45
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Weapon identifiers shared across game and cgame.
|
|
3
|
+
* Reference: rerelease/g_items.cpp, game/src/inventory/playerInventory.ts
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export enum WeaponId {
|
|
7
|
+
Blaster = 'blaster',
|
|
8
|
+
Shotgun = 'shotgun',
|
|
9
|
+
SuperShotgun = 'supershotgun', // Matched to assets (w_supershotgun, weapon_supershotgun)
|
|
10
|
+
Machinegun = 'machinegun',
|
|
11
|
+
Chaingun = 'chaingun',
|
|
12
|
+
HandGrenade = 'grenades', // Matched to assets (w_grenades, weapon_grenades)
|
|
13
|
+
GrenadeLauncher = 'grenadelauncher', // Matched to assets (w_grenadelauncher)
|
|
14
|
+
RocketLauncher = 'rocketlauncher', // Matched to assets (w_rocketlauncher)
|
|
15
|
+
HyperBlaster = 'hyperblaster',
|
|
16
|
+
Railgun = 'railgun',
|
|
17
|
+
BFG10K = 'bfg10k',
|
|
18
|
+
// New additions for demo playback and extended support
|
|
19
|
+
Grapple = 'grapple',
|
|
20
|
+
ChainFist = 'chainfist',
|
|
21
|
+
EtfRifle = 'etf_rifle', // Confirm asset?
|
|
22
|
+
ProxLauncher = 'prox_launcher', // Confirm asset?
|
|
23
|
+
IonRipper = 'ionripper',
|
|
24
|
+
PlasmaBeam = 'plasmabeam',
|
|
25
|
+
Phalanx = 'phalanx',
|
|
26
|
+
Disruptor = 'disruptor',
|
|
27
|
+
Trap = 'trap',
|
|
28
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { Vec3 } from './vec3.js';
|
|
2
|
+
|
|
3
|
+
export const PITCH = 0;
|
|
4
|
+
export const YAW = 1;
|
|
5
|
+
export const ROLL = 2;
|
|
6
|
+
|
|
7
|
+
const DEG2RAD_FACTOR = Math.PI / 180;
|
|
8
|
+
const RAD2DEG_FACTOR = 180 / Math.PI;
|
|
9
|
+
|
|
10
|
+
// Export constants for direct use in matrix operations
|
|
11
|
+
export const DEG2RAD = DEG2RAD_FACTOR;
|
|
12
|
+
export const RAD2DEG = RAD2DEG_FACTOR;
|
|
13
|
+
|
|
14
|
+
function axisComponent(vec: Vec3, axis: number): number {
|
|
15
|
+
switch (axis) {
|
|
16
|
+
case PITCH:
|
|
17
|
+
return vec.x;
|
|
18
|
+
case YAW:
|
|
19
|
+
return vec.y;
|
|
20
|
+
case ROLL:
|
|
21
|
+
default:
|
|
22
|
+
return vec.z;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface AngleVectorsResult {
|
|
27
|
+
readonly forward: Vec3;
|
|
28
|
+
readonly right: Vec3;
|
|
29
|
+
readonly up: Vec3;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function degToRad(degrees: number): number {
|
|
33
|
+
return degrees * DEG2RAD_FACTOR;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function radToDeg(radians: number): number {
|
|
37
|
+
return radians * RAD2DEG_FACTOR;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function lerpAngle(from: number, to: number, frac: number): number {
|
|
41
|
+
let target = to;
|
|
42
|
+
|
|
43
|
+
if (target - from > 180) {
|
|
44
|
+
target -= 360;
|
|
45
|
+
} else if (target - from < -180) {
|
|
46
|
+
target += 360;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return from + frac * (target - from);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function angleMod(angle: number): number {
|
|
53
|
+
const value = angle % 360;
|
|
54
|
+
return value < 0 ? 360 + value : value;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function angleVectors(angles: Vec3): AngleVectorsResult {
|
|
58
|
+
const yaw = degToRad(axisComponent(angles, YAW));
|
|
59
|
+
const pitch = degToRad(axisComponent(angles, PITCH));
|
|
60
|
+
const roll = degToRad(axisComponent(angles, ROLL));
|
|
61
|
+
|
|
62
|
+
const sy = Math.sin(yaw);
|
|
63
|
+
const cy = Math.cos(yaw);
|
|
64
|
+
const sp = Math.sin(pitch);
|
|
65
|
+
const cp = Math.cos(pitch);
|
|
66
|
+
const sr = Math.sin(roll);
|
|
67
|
+
const cr = Math.cos(roll);
|
|
68
|
+
|
|
69
|
+
const forward: Vec3 = {
|
|
70
|
+
x: cp * cy,
|
|
71
|
+
y: cp * sy,
|
|
72
|
+
z: -sp,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const right: Vec3 = {
|
|
76
|
+
x: -sr * sp * cy - cr * -sy,
|
|
77
|
+
y: -sr * sp * sy - cr * cy,
|
|
78
|
+
z: -sr * cp,
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const up: Vec3 = {
|
|
82
|
+
x: cr * sp * cy - sr * -sy,
|
|
83
|
+
y: cr * sp * sy - sr * cy,
|
|
84
|
+
z: cr * cp,
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
return { forward, right, up };
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function vectorToYaw(vec: Vec3): number {
|
|
91
|
+
const pitch = axisComponent(vec, PITCH);
|
|
92
|
+
const yawAxis = axisComponent(vec, YAW);
|
|
93
|
+
|
|
94
|
+
if (pitch === 0) {
|
|
95
|
+
if (yawAxis === 0) {
|
|
96
|
+
return 0;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return yawAxis > 0 ? 90 : 270;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const yaw = radToDeg(Math.atan2(yawAxis, pitch));
|
|
103
|
+
return yaw < 0 ? yaw + 360 : yaw;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function vectorToAngles(vec: Vec3): Vec3 {
|
|
107
|
+
const x = vec.x;
|
|
108
|
+
const y = vec.y;
|
|
109
|
+
const z = vec.z;
|
|
110
|
+
|
|
111
|
+
if (y === 0 && x === 0) {
|
|
112
|
+
return { x: z > 0 ? -90 : -270, y: 0, z: 0 };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
let yaw: number;
|
|
116
|
+
if (x) {
|
|
117
|
+
yaw = radToDeg(Math.atan2(y, x));
|
|
118
|
+
} else if (y > 0) {
|
|
119
|
+
yaw = 90;
|
|
120
|
+
} else {
|
|
121
|
+
yaw = 270;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (yaw < 0) {
|
|
125
|
+
yaw += 360;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const forward = Math.sqrt(x * x + y * y);
|
|
129
|
+
let pitch = radToDeg(Math.atan2(z, forward));
|
|
130
|
+
if (pitch < 0) {
|
|
131
|
+
pitch += 360;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return { x: -pitch, y: yaw, z: 0 };
|
|
135
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
// Extracted from full/client/anorms.h
|
|
2
|
+
export const ANORMS: [number, number, number][] = [
|
|
3
|
+
[-0.525731, 0.000000, 0.850651],
|
|
4
|
+
[-0.442863, 0.238856, 0.864188],
|
|
5
|
+
[-0.295242, 0.000000, 0.955423],
|
|
6
|
+
[-0.309017, 0.500000, 0.809017],
|
|
7
|
+
[-0.162460, 0.262866, 0.951056],
|
|
8
|
+
[0.000000, 0.000000, 1.000000],
|
|
9
|
+
[0.000000, 0.850651, 0.525731],
|
|
10
|
+
[-0.147621, 0.716567, 0.681718],
|
|
11
|
+
[0.147621, 0.716567, 0.681718],
|
|
12
|
+
[0.000000, 0.525731, 0.850651],
|
|
13
|
+
[0.309017, 0.500000, 0.809017],
|
|
14
|
+
[0.525731, 0.000000, 0.850651],
|
|
15
|
+
[0.295242, 0.000000, 0.955423],
|
|
16
|
+
[0.442863, 0.238856, 0.864188],
|
|
17
|
+
[0.162460, 0.262866, 0.951056],
|
|
18
|
+
[-0.681718, 0.147621, 0.716567],
|
|
19
|
+
[-0.809017, 0.309017, 0.500000],
|
|
20
|
+
[-0.587785, 0.425325, 0.688191],
|
|
21
|
+
[-0.850651, 0.525731, 0.000000],
|
|
22
|
+
[-0.864188, 0.442863, 0.238856],
|
|
23
|
+
[-0.716567, 0.681718, 0.147621],
|
|
24
|
+
[-0.688191, 0.587785, 0.425325],
|
|
25
|
+
[-0.500000, 0.809017, 0.309017],
|
|
26
|
+
[-0.238856, 0.864188, 0.442863],
|
|
27
|
+
[-0.425325, 0.688191, 0.587785],
|
|
28
|
+
[-0.716567, 0.681718, -0.147621],
|
|
29
|
+
[-0.500000, 0.809017, -0.309017],
|
|
30
|
+
[-0.525731, 0.850651, 0.000000],
|
|
31
|
+
[0.000000, 0.850651, -0.525731],
|
|
32
|
+
[-0.238856, 0.864188, -0.442863],
|
|
33
|
+
[0.000000, 0.955423, -0.295242],
|
|
34
|
+
[-0.262866, 0.951056, -0.162460],
|
|
35
|
+
[0.000000, 1.000000, 0.000000],
|
|
36
|
+
[0.000000, 0.955423, 0.295242],
|
|
37
|
+
[-0.262866, 0.951056, 0.162460],
|
|
38
|
+
[0.238856, 0.864188, 0.442863],
|
|
39
|
+
[0.262866, 0.951056, 0.162460],
|
|
40
|
+
[0.500000, 0.809017, 0.309017],
|
|
41
|
+
[0.238856, 0.864188, -0.442863],
|
|
42
|
+
[0.262866, 0.951056, -0.162460],
|
|
43
|
+
[0.500000, 0.809017, -0.309017],
|
|
44
|
+
[0.850651, 0.525731, 0.000000],
|
|
45
|
+
[0.716567, 0.681718, 0.147621],
|
|
46
|
+
[0.716567, 0.681718, -0.147621],
|
|
47
|
+
[0.525731, 0.850651, 0.000000],
|
|
48
|
+
[0.425325, 0.688191, 0.587785],
|
|
49
|
+
[0.864188, 0.442863, 0.238856],
|
|
50
|
+
[0.688191, 0.587785, 0.425325],
|
|
51
|
+
[0.809017, 0.309017, 0.500000],
|
|
52
|
+
[0.681718, 0.147621, 0.716567],
|
|
53
|
+
[0.587785, 0.425325, 0.688191],
|
|
54
|
+
[0.955423, 0.295242, 0.000000],
|
|
55
|
+
[1.000000, 0.000000, 0.000000],
|
|
56
|
+
[0.951056, 0.162460, 0.262866],
|
|
57
|
+
[0.850651, -0.525731, 0.000000],
|
|
58
|
+
[0.955423, -0.295242, 0.000000],
|
|
59
|
+
[0.864188, -0.442863, 0.238856],
|
|
60
|
+
[0.951056, -0.162460, 0.262866],
|
|
61
|
+
[0.809017, -0.309017, 0.500000],
|
|
62
|
+
[0.681718, -0.147621, 0.716567],
|
|
63
|
+
[0.850651, 0.000000, 0.525731],
|
|
64
|
+
[0.864188, 0.442863, -0.238856],
|
|
65
|
+
[0.809017, 0.309017, -0.500000],
|
|
66
|
+
[0.951056, 0.162460, -0.262866],
|
|
67
|
+
[0.525731, 0.000000, -0.850651],
|
|
68
|
+
[0.681718, 0.147621, -0.716567],
|
|
69
|
+
[0.681718, -0.147621, -0.716567],
|
|
70
|
+
[0.850651, 0.000000, -0.525731],
|
|
71
|
+
[0.809017, -0.309017, -0.500000],
|
|
72
|
+
[0.864188, -0.442863, -0.238856],
|
|
73
|
+
[0.951056, -0.162460, -0.262866],
|
|
74
|
+
[0.147621, 0.716567, -0.681718],
|
|
75
|
+
[0.309017, 0.500000, -0.809017],
|
|
76
|
+
[0.425325, 0.688191, -0.587785],
|
|
77
|
+
[0.442863, 0.238856, -0.864188],
|
|
78
|
+
[0.587785, 0.425325, -0.688191],
|
|
79
|
+
[0.688191, 0.587785, -0.425325],
|
|
80
|
+
[-0.147621, 0.716567, -0.681718],
|
|
81
|
+
[-0.309017, 0.500000, -0.809017],
|
|
82
|
+
[0.000000, 0.525731, -0.850651],
|
|
83
|
+
[-0.525731, 0.000000, -0.850651],
|
|
84
|
+
[-0.442863, 0.238856, -0.864188],
|
|
85
|
+
[-0.295242, 0.000000, -0.955423],
|
|
86
|
+
[-0.162460, 0.262866, -0.951056],
|
|
87
|
+
[0.000000, 0.000000, -1.000000],
|
|
88
|
+
[0.295242, 0.000000, -0.955423],
|
|
89
|
+
[0.162460, 0.262866, -0.951056],
|
|
90
|
+
[-0.442863, -0.238856, -0.864188],
|
|
91
|
+
[-0.309017, -0.500000, -0.809017],
|
|
92
|
+
[-0.162460, -0.262866, -0.951056],
|
|
93
|
+
[0.000000, -0.850651, -0.525731],
|
|
94
|
+
[-0.147621, -0.716567, -0.681718],
|
|
95
|
+
[0.147621, -0.716567, -0.681718],
|
|
96
|
+
[0.000000, -0.525731, -0.850651],
|
|
97
|
+
[0.309017, -0.500000, -0.809017],
|
|
98
|
+
[0.442863, -0.238856, -0.864188],
|
|
99
|
+
[0.162460, -0.262866, -0.951056],
|
|
100
|
+
[0.238856, -0.864188, -0.442863],
|
|
101
|
+
[0.500000, -0.809017, -0.309017],
|
|
102
|
+
[0.425325, -0.688191, -0.587785],
|
|
103
|
+
[0.716567, -0.681718, -0.147621],
|
|
104
|
+
[0.688191, -0.587785, -0.425325],
|
|
105
|
+
[0.587785, -0.425325, -0.688191],
|
|
106
|
+
[0.000000, -0.955423, -0.295242],
|
|
107
|
+
[0.000000, -1.000000, 0.000000],
|
|
108
|
+
[0.262866, -0.951056, -0.162460],
|
|
109
|
+
[0.000000, -0.850651, 0.525731],
|
|
110
|
+
[0.000000, -0.955423, 0.295242],
|
|
111
|
+
[0.238856, -0.864188, 0.442863],
|
|
112
|
+
[0.262866, -0.951056, 0.162460],
|
|
113
|
+
[0.500000, -0.809017, 0.309017],
|
|
114
|
+
[0.716567, -0.681718, 0.147621],
|
|
115
|
+
[0.525731, -0.850651, 0.000000],
|
|
116
|
+
[-0.238856, -0.864188, -0.442863],
|
|
117
|
+
[-0.500000, -0.809017, -0.309017],
|
|
118
|
+
[-0.262866, -0.951056, -0.162460],
|
|
119
|
+
[-0.850651, -0.525731, 0.000000],
|
|
120
|
+
[-0.716567, -0.681718, -0.147621],
|
|
121
|
+
[-0.716567, -0.681718, 0.147621],
|
|
122
|
+
[-0.525731, -0.850651, 0.000000],
|
|
123
|
+
[-0.500000, -0.809017, 0.309017],
|
|
124
|
+
[-0.238856, -0.864188, 0.442863],
|
|
125
|
+
[-0.262866, -0.951056, 0.162460],
|
|
126
|
+
[-0.864188, -0.442863, 0.238856],
|
|
127
|
+
[-0.809017, -0.309017, 0.500000],
|
|
128
|
+
[-0.688191, -0.587785, 0.425325],
|
|
129
|
+
[-0.681718, -0.147621, 0.716567],
|
|
130
|
+
[-0.442863, -0.238856, 0.864188],
|
|
131
|
+
[-0.587785, -0.425325, 0.688191],
|
|
132
|
+
[-0.309017, -0.500000, 0.809017],
|
|
133
|
+
[-0.147621, -0.716567, 0.681718],
|
|
134
|
+
[-0.425325, -0.688191, 0.587785],
|
|
135
|
+
[-0.162460, -0.262866, 0.951056],
|
|
136
|
+
[0.442863, -0.238856, 0.864188],
|
|
137
|
+
[0.162460, -0.262866, 0.951056],
|
|
138
|
+
[0.309017, -0.500000, 0.809017],
|
|
139
|
+
[0.147621, -0.716567, 0.681718],
|
|
140
|
+
[0.000000, -0.525731, 0.850651],
|
|
141
|
+
[0.425325, -0.688191, 0.587785],
|
|
142
|
+
[0.587785, -0.425325, 0.688191],
|
|
143
|
+
[0.688191, -0.587785, 0.425325],
|
|
144
|
+
[-0.955423, 0.295242, 0.000000],
|
|
145
|
+
[-0.951056, 0.162460, 0.262866],
|
|
146
|
+
[-1.000000, 0.000000, 0.000000],
|
|
147
|
+
[-0.850651, 0.000000, 0.525731],
|
|
148
|
+
[-0.955423, -0.295242, 0.000000],
|
|
149
|
+
[-0.951056, -0.162460, 0.262866],
|
|
150
|
+
[-0.864188, 0.442863, -0.238856],
|
|
151
|
+
[-0.951056, 0.162460, -0.262866],
|
|
152
|
+
[-0.809017, 0.309017, -0.500000],
|
|
153
|
+
[-0.864188, -0.442863, -0.238856],
|
|
154
|
+
[-0.951056, -0.162460, -0.262866],
|
|
155
|
+
[-0.809017, -0.309017, -0.500000],
|
|
156
|
+
[-0.681718, 0.147621, -0.716567],
|
|
157
|
+
[-0.681718, -0.147621, -0.716567],
|
|
158
|
+
[-0.850651, 0.000000, -0.525731],
|
|
159
|
+
[-0.688191, 0.587785, -0.425325],
|
|
160
|
+
[-0.587785, 0.425325, -0.688191],
|
|
161
|
+
[-0.425325, 0.688191, -0.587785],
|
|
162
|
+
[-0.425325, -0.688191, -0.587785],
|
|
163
|
+
[-0.587785, -0.425325, -0.688191],
|
|
164
|
+
[-0.688191, -0.587785, -0.425325]
|
|
165
|
+
];
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export type Color4 = [number, number, number, number];
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* TypeScript port of G_AddBlend from rerelease q_std.h.
|
|
5
|
+
*
|
|
6
|
+
* Given an incoming RGBA color and an existing blend color, computes the new
|
|
7
|
+
* blended color where alpha is accumulated and RGB is mixed proportionally
|
|
8
|
+
* to the previous vs. new alpha contribution.
|
|
9
|
+
*
|
|
10
|
+
* This function is pure and does not mutate its inputs.
|
|
11
|
+
*/
|
|
12
|
+
export function addBlendColor(
|
|
13
|
+
r: number,
|
|
14
|
+
g: number,
|
|
15
|
+
b: number,
|
|
16
|
+
a: number,
|
|
17
|
+
current: Color4,
|
|
18
|
+
): Color4 {
|
|
19
|
+
if (a <= 0) {
|
|
20
|
+
return current;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const oldR = current[0];
|
|
24
|
+
const oldG = current[1];
|
|
25
|
+
const oldB = current[2];
|
|
26
|
+
const oldA = current[3];
|
|
27
|
+
|
|
28
|
+
const a2 = oldA + (1 - oldA) * a;
|
|
29
|
+
|
|
30
|
+
if (a2 <= 0) {
|
|
31
|
+
return [0, 0, 0, 0];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const a3 = oldA / a2;
|
|
35
|
+
|
|
36
|
+
const newR = oldR * a3 + r * (1 - a3);
|
|
37
|
+
const newG = oldG * a3 + g * (1 - a3);
|
|
38
|
+
const newB = oldB * a3 + b * (1 - a3);
|
|
39
|
+
|
|
40
|
+
return [newR, newG, newB, a2];
|
|
41
|
+
}
|
|
42
|
+
|
package/src/math/mat4.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Vec3 } from './vec3.js';
|
|
2
|
+
|
|
3
|
+
export type Mat4 = Float32Array;
|
|
4
|
+
|
|
5
|
+
export function createMat4Identity(): Mat4 {
|
|
6
|
+
return new Float32Array([
|
|
7
|
+
1, 0, 0, 0,
|
|
8
|
+
0, 1, 0, 0,
|
|
9
|
+
0, 0, 1, 0,
|
|
10
|
+
0, 0, 0, 1,
|
|
11
|
+
]);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function multiplyMat4(a: Float32Array, b: Float32Array): Mat4 {
|
|
15
|
+
const out = new Float32Array(16);
|
|
16
|
+
for (let row = 0; row < 4; row += 1) {
|
|
17
|
+
for (let col = 0; col < 4; col += 1) {
|
|
18
|
+
out[col * 4 + row] =
|
|
19
|
+
a[0 * 4 + row] * b[col * 4 + 0] +
|
|
20
|
+
a[1 * 4 + row] * b[col * 4 + 1] +
|
|
21
|
+
a[2 * 4 + row] * b[col * 4 + 2] +
|
|
22
|
+
a[3 * 4 + row] * b[col * 4 + 3];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function transformPointMat4(mat: Float32Array, point: Vec3): Vec3 {
|
|
29
|
+
const x = point.x;
|
|
30
|
+
const y = point.y;
|
|
31
|
+
const z = point.z;
|
|
32
|
+
return {
|
|
33
|
+
x: mat[0] * x + mat[4] * y + mat[8] * z + mat[12],
|
|
34
|
+
y: mat[1] * x + mat[5] * y + mat[9] * z + mat[13],
|
|
35
|
+
z: mat[2] * x + mat[6] * y + mat[10] * z + mat[14],
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function mat4FromBasis(origin: Vec3, axis: readonly [Vec3, Vec3, Vec3]): Mat4 {
|
|
40
|
+
const out = createMat4Identity();
|
|
41
|
+
out[0] = axis[0].x;
|
|
42
|
+
out[1] = axis[0].y;
|
|
43
|
+
out[2] = axis[0].z;
|
|
44
|
+
|
|
45
|
+
out[4] = axis[1].x;
|
|
46
|
+
out[5] = axis[1].y;
|
|
47
|
+
out[6] = axis[1].z;
|
|
48
|
+
|
|
49
|
+
out[8] = axis[2].x;
|
|
50
|
+
out[9] = axis[2].y;
|
|
51
|
+
out[10] = axis[2].z;
|
|
52
|
+
|
|
53
|
+
out[12] = origin.x;
|
|
54
|
+
out[13] = origin.y;
|
|
55
|
+
out[14] = origin.z;
|
|
56
|
+
|
|
57
|
+
return out;
|
|
58
|
+
}
|