]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/portals.qc
beginning of map-portals (an upcoming alternative to teleporters? maybe I will do...
[divverent/nexuiz.git] / data / qcsrc / server / portals.qc
1 vector fixedvectoangles(vector v)
2 {
3         vector a;
4         a = vectoangles(v);
5         a_x = -a_x;
6         return a;
7 }
8
9 vector Portal_Transform_Apply(vector transform, vector v)
10 {
11         makevectors(transform);
12         return v_forward * v_x
13              + v_right   * v_y
14                  + v_up      * v_z;
15 }
16
17 vector Portal_Transform_Invert(vector transform)
18 {
19         makevectors(transform);
20         // we want angles that turn v_forward into '1 0 0', v_right into '0 1 0' and v_up into '0 0 1'
21         // but these are orthogonal unit vectors!
22         // so to invert, we can simply vectoangles the TRANSPOSED matrix
23         // TODO is this always -transform?
24         return fixedvectoangles(
25                 '1 0 0' * v_forward_x + '0 1 0' * v_right_x + '0 0 1' * v_up_x,
26                 '1 0 0' * v_forward_y + '0 1 0' * v_right_y + '0 0 1' * v_up_y
27         );
28 }
29
30 vector Portal_Transform_Multiply(vector t1, vector t2)
31 {
32         vector vx, vy;
33         makevectors(t2); vx = v_forward; vy = v_right;
34         vx = Portal_Transform_Apply(t1, vx);
35         vy = Portal_Transform_Apply(t1, vy);
36         return fixedvectoangles(vx, vy);
37 }
38
39 vector Portal_Transform_Divide(vector to_transform, vector from_transform)
40 {
41         return Portal_Transform_Multiply(to_transform, Portal_Transform_Invert(from_transform));
42 }
43
44 void Portal_TeleportPlayer(entity teleporter, entity player)
45 {
46         vector to, transform;
47         to = teleporter.velocity;
48         transform = teleporter.mangle;
49         TeleportPlayer(teleporter, player, to, Portal_Transform_Multiply(transform, player.angles), Portal_Transform_Apply(transform, player.velocity));
50 }
51
52 float Portal_Fix(entity teleporter)
53 {
54         teleporter.mins = PL_MIN - '2 2 2';
55         teleporter.maxs = PL_MAX + '2 2 2';
56         return move_out_of_solid(teleporter);
57 }
58
59 void Portal_Connect(entity teleporter, entity destination)
60 {
61         teleporter.mangle = Portal_Transform_Divide(-(destination.angles), teleporter.angles);
62         teleporter.touch = Portal_Touch;
63         teleporter.cnt = 0;
64         destination.touch = SUB_Null;
65         destination.cnt = 1;
66 }
67
68 entity Portal_Spawn(entity own, vector org, vector ang)
69 {
70         entity portal;
71         portal = spawn();
72         portal.classname = "portal";
73         portal.owner = own;
74         portal.origin = org;
75         portal.angles = ang;
76         setmodel(portal, ...);
77 }