1 /* bzflag
2  * Copyright (c) 1993-2021 Tim Riker
3  *
4  * This package is free software;  you can redistribute it and/or
5  * modify it under the terms of the license found in the file
6  * named COPYING that should have accompanied this file.
7  *
8  * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
9  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11  */
12 
13 /* TetraBuilding:
14  *  Encapsulates a tetrahederon in the game environment.
15  */
16 
17 #ifndef BZF_TETRA_BUILDING_H
18 #define BZF_TETRA_BUILDING_H
19 
20 #include "common.h"
21 #include <string>
22 #include "Obstacle.h"
23 #include "MeshObstacle.h"
24 #include "MeshTransform.h"
25 #include "BzMaterial.h"
26 
27 class TetraBuilding : public Obstacle
28 {
29 public:
30 
31     TetraBuilding();
32     TetraBuilding(const MeshTransform& transform,
33                   const float vertices[4][3], const float normals[4][3][3],
34                   const float texCoords[4][3][2], const bool useNormals[4],
35                   const bool useTexCoords[4], const BzMaterial* materials[4],
36                   bool drive = false, bool shoot = false, bool ricochet = false);
37     ~TetraBuilding();
38 
39     Obstacle* copyWithTransform(const MeshTransform&) const;
40 
41     MeshObstacle* makeMesh();
42 
43     void        finalize();
44 
45     const char*     getType() const;
46     static const char*  getClassName(); // const
47     bool        isValid() const;
48 
49     float       intersect(const Ray&) const;
50     void        getNormal(const float* p, float* n) const;
51     void        get3DNormal(const float* p, float* n) const;
52 
53     bool        inCylinder(const float* p, float radius, float height) const;
54     bool        inBox(const float* p, float angle,
55                       float halfWidth, float halfBreadth, float height) const;
56     bool        inMovingBox(const float* oldP, float oldAngle,
57                             const float *newP, float newAngle,
58                             float halfWidth, float halfBreadth, float height) const;
59     bool        isCrossing(const float* p, float angle,
60                            float halfWidth, float halfBreadth, float height,
61                            float* plane) const;
62 
63     bool        getHitNormal(
64         const float* pos1, float azimuth1,
65         const float* pos2, float azimuth2,
66         float halfWidth, float halfBreadth,
67         float height,
68         float* normal) const;
69 
70     void        getCorner(int index, float* pos) const;
71 
72     int packSize() const;
73     void *pack(void*) const;
74     const void *unpack(const void*);
75 
76     void print(std::ostream& out, const std::string& indent) const;
77 
78 private:
79     void checkVertexOrder();
80 
81 private:
82     static const char*  typeName;
83 
84     MeshTransform transform;
85     float vertices[4][3];
86     float normals[4][3][3];
87     float texcoords[4][3][2];
88     bool useNormals[4];
89     bool useTexcoords[4];
90     const BzMaterial* materials[4];
91 };
92 
93 
94 #endif // BZF_TETRA_BUILDING_H
95 
96 // Local Variables: ***
97 // mode: C++ ***
98 // tab-width: 4 ***
99 // c-basic-offset: 4 ***
100 // indent-tabs-mode: nil ***
101 // End: ***
102 // ex: shiftwidth=4 tabstop=4
103