Tiberian Technologies Scripts Reference Revision: 9000
Loading...
Searching...
No Matches
FrustumClass.h
1/* Renegade Scripts.dll
2 Copyright 2013 Tiberian Technologies
3
4 This file is part of the Renegade scripts.dll
5 The Renegade scripts.dll is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2, or (at your option) any later
8 version. See the file COPYING for more details.
9 In addition, an exemption is given to allow Run Time Dynamic Linking of this code with any closed source module that does not contain code covered by this licence.
10 Only the source code to the module(s) containing the licenced code has to be released.
11*/
12#ifndef TT_INCLUDE_FRUSTUMCLASS_H
13#define TT_INCLUDE_FRUSTUMCLASS_H
14#include "Vector3.h"
15#include "plane.h"
16class FrustumClass
17{
18public:
19 void Init( const Matrix3D & camera,
20 const Vector2 & vpmin,
21 const Vector2 & vpmax,
22 float znear,
23 float zfar )
24 {
25 int i;
26 CameraTransform = camera;
27 if ((znear > 0.0f) && (zfar > 0.0f))
28 {
29 znear = -znear;
30 zfar = -zfar;
31 }
32 Corners[0].Set(vpmin.X, vpmax.Y, 1.0);
33 Corners[4] = Corners[0];
34 Corners[0] *= znear;
35 Corners[4] *= zfar;
36 Corners[1].Set(vpmax.X, vpmax.Y, 1.0);
37 Corners[5] = Corners[1];
38 Corners[1] *= znear;
39 Corners[5] *= zfar;
40 Corners[2].Set(vpmin.X, vpmin.Y, 1.0);
41 Corners[6] = Corners[2];
42 Corners[2] *= znear;
43 Corners[6] *= zfar;
44 Corners[3].Set(vpmax.X, vpmin.Y, 1.0);
45 Corners[7] = Corners[3];
46 Corners[3] *= znear;
47 Corners[7] *= zfar;
48 for (i = 0; i < 8; i++)
49 {
50 Matrix3D::Transform_Vector(CameraTransform, Corners[i], &(Corners[i]));
51 }
52 PlaneClass frustum_planes[6];
53 Planes[0].Set(Corners[0], Corners[3], Corners[1]);
54 Planes[1].Set(Corners[0], Corners[5], Corners[4]);
55 Planes[2].Set(Corners[0], Corners[6], Corners[2]);
56 Planes[3].Set(Corners[2], Corners[7], Corners[3]);
57 Planes[4].Set(Corners[1], Corners[7], Corners[5]);
58 Planes[5].Set(Corners[4], Corners[7], Corners[6]);
59 BoundMin = BoundMax = Corners[0];
60 for (i=1; i<8;i++)
61 {
62 if (Corners[i].X < BoundMin.X) BoundMin.X = Corners[i].X;
63 if (Corners[i].X > BoundMax.X) BoundMax.X = Corners[i].X;
64 if (Corners[i].Y < BoundMin.Y) BoundMin.Y = Corners[i].Y;
65 if (Corners[i].Y > BoundMax.Y) BoundMax.Y = Corners[i].Y;
66 if (Corners[i].Z < BoundMin.Z) BoundMin.Z = Corners[i].Z;
67 if (Corners[i].Z > BoundMax.Z) BoundMax.Z = Corners[i].Z;
68 }
69 }
70 const Vector3 & Get_Bound_Min(void) const { return BoundMin; }
71 const Vector3 & Get_Bound_Max(void) const { return BoundMax; }
72 Matrix3D CameraTransform; // 0000
73 PlaneClass Planes[6]; // 0030
74 Vector3 Corners[8]; // 0090
75 Vector3 BoundMin; // 00F0
76 Vector3 BoundMax; // 00FC
77}; // 0108
78
79#endif