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 /* PyramidBuilding:
14  *  Encapsulates a pyramid in the game environment.
15  */
16 
17 #ifndef BZF_PYRAMID_BUILDING_H
18 #define BZF_PYRAMID_BUILDING_H
19 
20 #include "common.h"
21 #include <string>
22 #include "Obstacle.h"
23 
24 class PyramidBuilding : public Obstacle
25 {
26 public:
27     PyramidBuilding();
28     PyramidBuilding(const float* pos, float rotation,
29                     float width, float breadth, float height, bool drive = false, bool shoot = false, bool ricochet = false);
30     ~PyramidBuilding();
31 
32     virtual Obstacle*   copyWithTransform(const MeshTransform&) const;
33 
34     const char*     getType() const;
35     static const char*  getClassName(); // const
36 
37     bool        isFlatTop() const;
38 
39     float       intersect(const Ray&) const;
40     void        getNormal(const float* p, float* n) const;
41     void        get3DNormal(const float* p, float* n) const;
42 
43     bool        inCylinder(const float* p, float radius, float height) const;
44     bool        inBox(const float* p, float angle,
45                       float halfWidth, float halfBreadth, float height) const;
46     bool        inMovingBox(const float* oldP, float oldAngle,
47                             const float *newP, float newAngle,
48                             float halfWidth, float halfBreadth, float height) const;
49     bool        isCrossing(const float* p, float angle,
50                            float halfWidth, float halfBreadth, float height,
51                            float* plane) const;
52 
53     bool        getHitNormal(
54         const float* pos1, float azimuth1,
55         const float* pos2, float azimuth2,
56         float halfWidth, float halfBreadth,
57         float height,
58         float* normal) const;
59 
60     void        getCorner(int index, float* pos) const;
61 
62     int packSize() const;
63     void *pack(void*) const;
64     const void *unpack(const void*);
65 
66     void print(std::ostream& out, const std::string& indent) const;
67     void printOBJ(std::ostream& out, const std::string& indent) const;
68 
69     std::string     userTextures[1];
70 
71 private:
72     void finalize();
73 
74     // compute minimum shrinking for height between z and z + height
75     float       shrinkFactor(float z, float height = 0.0) const;
76 
77 private:
78     static const char*  typeName;
79 };
80 
81 #endif // BZF_PYRAMID_BUILDING_H
82 
83 // Local Variables: ***
84 // mode: C++ ***
85 // tab-width: 4 ***
86 // c-basic-offset: 4 ***
87 // indent-tabs-mode: nil ***
88 // End: ***
89 // ex: shiftwidth=4 tabstop=4
90