aboutsummaryrefslogtreecommitdiff
path: root/dep/g3dlite/G3D/Cylinder.h
blob: 85eba77b794c96d756a9c02f7588d4cf6721fe55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
 @file Cylinder.h
  
 @maintainer Morgan McGuire, http://graphics.cs.williams.edu
  
 @created 2003-02-07
 @edited  2005-09-26

 Copyright 2000-2005, Morgan McGuire.
 All rights reserved.
 */

#ifndef G3D_Cylinder_H
#define G3D_Cylinder_H

#include "G3D/platform.h"
#include "G3D/g3dmath.h"
#include "G3D/Vector3.h"

namespace G3D {

class Line;
class AABox;
/**
 Right cylinder
 */
class Cylinder {
private:
	Vector3			p1;
	Vector3			p2;

	float           mRadius;

public:

    /** Uninitialized */
    Cylinder();
    Cylinder(class BinaryInput& b);
	Cylinder(const Vector3& _p1, const Vector3& _p2, float _r);
	void serialize(class BinaryOutput& b) const;
	void deserialize(class BinaryInput& b);
	
	/** The line down the center of the Cylinder */
	Line axis() const;

    /** 
      A reference frame in which the center of mass is at the origin and
      the Y-axis is the cylinder's axis.  If the cylinder is transformed, this reference frame
      may freely rotate around its axis.*/
    void getReferenceFrame(class CoordinateFrame& cframe) const;

    /** Returns point 0 or 1 */
    inline const Vector3& point(int i) const {
        debugAssert(i >= 0 && i <= 1);
        return (i == 0) ? p1 : p2;
    }

    /**
     Returns true if the point is inside the Cylinder or on its surface.
     */
    bool contains(const Vector3& p) const;

    float area() const;

    float volume() const;

    float radius() const; 

    /** Center of mass */
    inline Vector3 center() const {
        return (p1 + p2) / 2.0f;
    }

    inline float height() const {
        return (p1 - p2).magnitude();
    }

    /**
     Get close axis aligned bounding box.
     With vertical world orientation, the top and bottom might not be very tight. */
    void getBounds(AABox& out) const;

    /** Random world space point with outward facing normal. */
    void getRandomSurfacePoint(Vector3& P, Vector3& N) const;

    /** Point selected uniformly at random over the volume. */
    Vector3 randomInteriorPoint() const;
};

} // namespace

#endif