fix nearclip threshold
[divverent/nexuiz.git] / data / qcsrc / warpzonelib / client.qc
1 void WarpZone_Read(float isnew)
2 {
3         if not(self.enemy)
4         {
5                 self.enemy = spawn();
6                 self.enemy.classname = "warpzone_from";
7         }
8         self.classname = "trigger_warpzone";
9         self.origin_x = ReadCoord();
10         self.origin_y = ReadCoord();
11         self.origin_z = ReadCoord();
12         self.modelindex = ReadShort();
13         self.mins_x = ReadCoord();
14         self.mins_y = ReadCoord();
15         self.mins_z = ReadCoord();
16         self.maxs_x = ReadCoord();
17         self.maxs_y = ReadCoord();
18         self.maxs_z = ReadCoord();
19         self.enemy.oldorigin_x = ReadCoord();
20         self.enemy.oldorigin_y = ReadCoord();
21         self.enemy.oldorigin_z = ReadCoord();
22         self.enemy.avelocity_x = ReadCoord();
23         self.enemy.avelocity_y = ReadCoord();
24         self.enemy.avelocity_z = ReadCoord();
25         self.oldorigin_x = ReadCoord();
26         self.oldorigin_y = ReadCoord();
27         self.oldorigin_z = ReadCoord();
28         self.avelocity_x = ReadCoord();
29         self.avelocity_y = ReadCoord();
30         self.avelocity_z = ReadCoord();
31
32         // common stuff
33         WarpZone_SetUp(self, self.enemy.oldorigin, self.enemy.avelocity, self.oldorigin, self.avelocity);
34
35         // engine currently wants this
36         self.avelocity = AnglesTransform_TurnDirectionFR(self.avelocity);
37
38         self.flags = FL_CAMERA;
39         self.drawmask = MASK_NORMAL;
40
41         // link me
42         //setmodel(self, self.model);
43         setorigin(self, self.origin);
44         setsize(self, self.mins, self.maxs);
45 }
46
47 float warpzone_saved;
48 vector warpzone_saved_origin;
49 vector warpzone_saved_angles;
50 void WarpZone_FixView()
51 {
52         float pd;
53         entity e;
54         warpzone_saved = 0;
55         warpzone_saved_origin = warpzone_fixview_origin;
56         warpzone_saved_angles = warpzone_fixview_angles;
57
58         e = WarpZone_Find(warpzone_fixview_origin, warpzone_fixview_origin);
59         if(e)
60         {
61                 warpzone_saved = 1;
62                 warpzone_fixview_origin = WarpZone_TransformOrigin(e, warpzone_fixview_origin);
63                 warpzone_fixview_angles = WarpZone_TransformVAngles(e, warpzone_fixview_angles);
64         }
65
66         // if we are near any warpzone planes - MOVE AWAY (work around nearclip)
67         float nearclip = 2;
68         e = WarpZone_Find(warpzone_fixview_origin - '1 1 1' * nearclip, warpzone_fixview_origin + '1 1 1' * nearclip);
69         if(e)
70         {
71                 pd = WarpZone_PlaneDist(e, warpzone_fixview_origin);
72                 if(pd >= 0 && pd < nearclip)
73                 {
74                         warpzone_saved = 1;
75                         warpzone_fixview_origin = warpzone_fixview_origin + e.warpzone_forward * (nearclip - pd);
76                 }
77         }
78
79         if(warpzone_saved)
80         {
81                 R_SetView(VF_ORIGIN, warpzone_fixview_origin);
82                 R_SetView(VF_ANGLES, warpzone_fixview_angles);
83         }
84 }
85 void WarpZone_UnFixView()
86 {
87         if(warpzone_saved)
88         {
89                 warpzone_fixview_origin = warpzone_saved_origin;
90                 warpzone_fixview_angles = warpzone_saved_angles;
91                 R_SetView(VF_ORIGIN, warpzone_fixview_origin);
92                 R_SetView(VF_ANGLES, warpzone_fixview_angles);
93         }
94 }