-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathrectangular.cpp
More file actions
94 lines (79 loc) · 1.63 KB
/
Copy pathrectangular.cpp
File metadata and controls
94 lines (79 loc) · 1.63 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
#include "rectangular.hpp"
namespace cvisual {
rectangular::rectangular()
: width(1.0), height(1.0)
{
}
rectangular::rectangular( const rectangular& other)
: primitive( other), width( other.width), height( other.height)
{
}
rectangular::~rectangular()
{
}
void
rectangular::set_length( double l)
{
if (l < 0)
throw std::runtime_error( "length cannot be negative");
axis = axis.norm() * l;
}
double
rectangular::get_length()
{
return axis.mag();
}
void
rectangular::set_height( double h)
{
if (h < 0)
throw std::runtime_error( "height cannot be negative");
height = h;
}
double
rectangular::get_height()
{
return height;
}
void
rectangular::set_width( double w)
{
if (w < 0)
throw std::runtime_error( "width cannot be negative");
width = w;
}
double
rectangular::get_width()
{
return width;
}
vector
rectangular::get_size()
{
return vector(axis.mag(), height, width);
}
void
rectangular::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;
}
void
rectangular::apply_transform( const view& scene )
{
// OpenGL needs to invert the modelview matrix to generate the normal matrix,
// so try not to make it singular:
double min_scale = std::max( axis.mag(), std::max(height,width) ) * 1e-6;
vector size( std::max(min_scale,axis.mag()),
std::max(min_scale,height),
std::max(min_scale,width) );
model_world_transform( scene.gcf, size ).gl_mult();
}
} // !namespace cvisual