TrinityCore
G3D::Cone Class Reference

`#include <Cone.h>`

## Public Member Functions

Cone (const Vector3 &tip, const Vector3 &direction, float angle)

Cone (const Vector3 &tip, const class Box &box)

virtual ~Cone ()

bool intersects (const class Sphere &s) const

bool contains (const class Vector3 &v) const

Vector3 randomDirectionInCone (Random &rng) const

## Static Public Member Functions

static float solidAngleFromHalfAngle (float halfAngle)

static double solidAngleFromHalfAngle (double halfAngle)

static float halfAngleFromSolidAngle (float solidAngle)

static double halfAngleFromSolidAngle (double solidAngle)

## Private Attributes

Vector3 tip

Vector3 direction

float angle

## Detailed Description

An infinite cone.

## Constructor & Destructor Documentation

 G3D::Cone::Cone ( const Vector3 & tip, const Vector3 & direction, float angle )
Parameters
 angle Angle from the center line to the edge, in radians
38  {
39  this->tip = tip;
40  this->direction = direction.direction();
41  this->angle = angle;
42
43  debugAssert(angle >= 0);
44  debugAssert(angle <= pi());
45 }
Vector3 direction
Definition: Cone.h:32
double pi()
Definition: g3dmath.h:147
Vector3 direction() const
Definition: Vector3.h:756
float angle
Definition: Cone.h:35
Vector3 tip
Definition: Cone.h:31
#define debugAssert(exp)
Definition: debugAssert.h:160

Here is the call graph for this function:

Here is the caller graph for this function:

 G3D::Cone::Cone ( const Vector3 & tip, const class Box & box )

Forms the smallest cone that contains the box. Undefined if the tip is inside or on the box.

 virtual G3D::Cone::~Cone ( )
inlinevirtual
50 {}

## Member Function Documentation

 bool G3D::Cone::contains ( const class Vector3 & v ) const

True if v is a point inside the cone.

124  {
125
126  Vector3 d = (v - tip).direction();
127
128  float x = d.dot(direction);
129
130  return (x > 0) && (x >= cosf(angle));
131 }
Vector3 direction
Definition: Cone.h:32
float angle
Definition: Cone.h:35
Vector3 tip
Definition: Cone.h:31
G3D::int16 x
Definition: Vector2int16.h:37

Here is the call graph for this function:

 float G3D::Cone::halfAngleFromSolidAngle ( float solidAngle )
static

Returns the half-angle (in radians) of a cone that subtends solidAngle (in steradians)

29  {
30  return acos((1.0f - (solidAngle / (2.0f * pif()))));
31 }
float acos(float fValue)
Definition: g3dmath.h:633
float pif()
Definition: g3dmath.h:151

Here is the call graph for this function:

 double G3D::Cone::halfAngleFromSolidAngle ( double solidAngle )
static
33  {
34  return aCos((1.0 - (solidAngle / (2.0 * pi()))));
35 }
double pi()
Definition: g3dmath.h:147
double aCos(double fValue)
Definition: g3dmath.h:622

Here is the call graph for this function:

 bool G3D::Cone::intersects ( const class Sphere & s ) const

Returns true if the cone touches, intersects, or contains b.

If c.intersects(s) and c.intersects(Sphere(s.center, s.radius * 2) then the sphere s is entirely within cone c.

108  {
109  // If the bounding sphere contains the tip, then
110  // they definitely touch.
111  if (b.contains(this->tip)) {
112  return true;
113  }
114
115  // Move the tip backwards, effectively making the cone bigger
116  // to account for the radius of the sphere.
117
118  Vector3 tip = this->tip - direction * b.radius / sinf(angle);
119
120  return Cone(tip, direction, angle).contains(b.center);
121 }
Vector3 direction
Definition: Cone.h:32
Cone(const Vector3 &tip, const Vector3 &direction, float angle)
Definition: Cone.cpp:38
float angle
Definition: Cone.h:35
Vector3 tip
Definition: Cone.h:31

Here is the call graph for this function:

 Vector3 G3D::Cone::randomDirectionInCone ( Random & rng ) const
47  {
48  const float cosThresh = cos(angle);
49
50  float cosAngle;
51  float normalizer;
52  Vector3 v;
53  do {
54  float vlenSquared;
55
56  // Sample uniformly on a sphere by rejection sampling and then normalizing
57  do {
58  v.x = rng.uniform(-1, 1);
59  v.y = rng.uniform(-1, 1);
60  v.z = rng.uniform(-1, 1);
61
62  // Sample uniformly on a cube
63  vlenSquared = v.squaredLength();
64  } while (vlenSquared > 1);
65
66
67  const float temp = v.dot(direction);
68
69  // Compute 1 / ||v||, but
70  // if the vector is in the wrong hemisphere, flip the sign
71  normalizer = rsqrt(vlenSquared) * sign(temp);
72
73  // Cosine of the angle between v and the light's negative-z axis
74  cosAngle = temp * normalizer;
75
76  } while (cosAngle < cosThresh);
77
78  // v was within the cone. Normalize it and maybe flip the hemisphere.
79  return v * normalizer;
80  }
Vector3 direction
Definition: Cone.h:32
float angle
Definition: Cone.h:35
double sign(double fValue)
Definition: g3dmath.h:669
double rsqrt(double x)
Definition: g3dmath.h:469

Here is the call graph for this function:

 float G3D::Cone::solidAngleFromHalfAngle ( float halfAngle )
static

Returns the solid angle (in steradians) subtended by a cone with half-angle halfAngle

21  {
22  return 2.0f * pif() * (1 - cosf(halfAngle));
23 }
float pif()
Definition: g3dmath.h:151

Here is the call graph for this function:

 double G3D::Cone::solidAngleFromHalfAngle ( double halfAngle )
static
25  {
26  return 2.0 * pi() * (1.0 - cos(halfAngle));
27 }
double pi()
Definition: g3dmath.h:147

Here is the call graph for this function:

## Member Data Documentation

 float G3D::Cone::angle
private

Angle from the center line to the edge.

 Vector3 G3D::Cone::direction
private
 Vector3 G3D::Cone::tip
private

The documentation for this class was generated from the following files: