-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathellipsoid.cpp
More file actions
110 lines (92 loc) · 1.92 KB
/
Copy pathellipsoid.cpp
File metadata and controls
110 lines (92 loc) · 1.92 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright (c) 2000, 2001, 2002, 2003 by David Scherer and others.
// Copyright (c) 2003, 2004 by Jonathan Brandmeyer and others.
// See the file license.txt for complete license terms.
// See the file authors.txt for a complete list of contributors.
#include "ellipsoid.hpp"
namespace cvisual {
ellipsoid::ellipsoid()
: height(1.0), width(1.0)
{
}
void
ellipsoid::set_length( double l)
{
if (l < 0)
throw std::runtime_error( "length cannot be negative");
axis = axis.norm() * l;
}
double
ellipsoid::get_length()
{
return axis.mag();
}
void
ellipsoid::set_height( double h)
{
if (h < 0)
throw std::runtime_error( "height cannot be negative");
height = h;
}
double
ellipsoid::get_height()
{
return height;
}
void
ellipsoid::set_width( double w)
{
if (w < 0)
throw std::runtime_error( "width cannot be negative");
width = w;
}
double
ellipsoid::get_width()
{
return width;
}
vector
ellipsoid::get_size()
{
return vector(axis.mag(), height, width);
}
void
ellipsoid::set_size( const vector& s)
{
if (s.x < 0)
throw std::runtime_error( "length cannot be negative");
if (s.y < 0)
throw std::runtime_error( "height cannot be negative");
if (s.z < 0)
throw std::runtime_error( "width cannot be negative");
axis = axis.norm() * s.x;
height = s.y;
width = s.z;
}
vector
ellipsoid::get_scale()
{
return vector( axis.mag(), height, width)*0.5;
}
bool
ellipsoid::degenerate()
{
return !visible || height == 0.0 || width == 0.0 || axis.mag() == 0.0;
}
double
ellipsoid::get_max_dimension()
{
return 0.5*std::max(axis.mag(), std::max(width, height));
}
void
ellipsoid::grow_extent( extent& world)
{
if (degenerate())
return;
//world.add_sphere( pos, std::max( width, std::max( height, axis.mag())));
// TODO: not accurate (overestimates extent)
vector s = vector(axis.mag(),height,width)*0.5;
world.add_box( model_world_transform(1.0), -s, s );
world.add_body();
}
PRIMITIVE_TYPEINFO_IMPL(ellipsoid)
} // !namespace cvisual