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 /* ConeObstacle:
14  *  Encapsulates a cone in the game environment.
15  */
16 
17 #ifndef BZF_CONE_OBSTACLE_H
18 #define BZF_CONE_OBSTACLE_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 
28 class ConeObstacle : public Obstacle
29 {
30 public:
31 
32     enum
33     {
34         Edge,
35         Bottom,
36         StartFace,
37         EndFace,
38         MaterialCount
39     };
40 
41     ConeObstacle();
42     ConeObstacle(const MeshTransform& transform,
43                  const float* _pos, const float* _size,
44                  float _rotation, float _angle,
45                  const float _texsize[2], bool _useNormals,
46                  int _divisions, const BzMaterial* mats[MaterialCount],
47                  int physics, bool bounce, bool drive, bool shoot, bool ricochet);
48     ~ConeObstacle();
49 
50     Obstacle* copyWithTransform(const MeshTransform&) const;
51 
52     MeshObstacle* makeMesh();
53 
54     const char* getType() const;
55     static const char* getClassName(); // const
56     bool isValid() const;
57 
58     float intersect(const Ray&) const;
59     void getNormal(const float* p, float* n) const;
60     void get3DNormal(const float* p, float* n) const;
61 
62     bool inCylinder(const float* p, float radius, float height) const;
63     bool inBox(const float* p, float angle,
64                float halfWidth, float halfBreadth, float height) const;
65     bool inMovingBox(const float* oldP, float oldAngle,
66                      const float *newP, float newAngle,
67                      float halfWidth, float halfBreadth, float height) const;
68     bool isCrossing(const float* p, float angle,
69                     float halfWidth, float halfBreadth, float height,
70                     float* plane) const;
71 
72     bool getHitNormal(const float* pos1, float azimuth1,
73                       const float* pos2, float azimuth2,
74                       float halfWidth, float halfBreadth,
75                       float height, float* normal) const;
76 
77     int packSize() const;
78     void *pack(void*) const;
79     const void *unpack(const void*);
80 
81     void print(std::ostream& out, const std::string& indent) const;
82 
83 private:
84     void finalize();
85 
86 private:
87     static const char* typeName;
88 
89     MeshTransform transform;
90     int divisions;
91     float sweepAngle;
92     int phydrv;
93     bool smoothBounce;
94     bool useNormals;
95     float texsize[2];
96     const BzMaterial* materials[MaterialCount];
97 };
98 
99 
100 #endif // BZF_CONE_OBSTACLE_H
101 
102 // Local Variables: ***
103 // mode: C++ ***
104 // tab-width: 4 ***
105 // c-basic-offset: 4 ***
106 // indent-tabs-mode: nil ***
107 // End: ***
108 // ex: shiftwidth=4 tabstop=4
109