Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Andrew Bauer
VTK
Commits
16acf7f3
Commit
16acf7f3
authored
Sep 09, 1994
by
Will Schroeder
Browse files
ENH: Added new Resetcamera(float bounds) method.
parent
cc2c7047
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/Renderer.hh
View file @
16acf7f3
...
...
@@ -106,6 +106,7 @@ public:
void
DoLights
();
void
DoActors
();
void
ResetCamera
();
void
ResetCamera
(
float
bounds
[
6
]);
void
SetRenderWindow
(
vlRenderWindow
*
);
vlRenderWindow
*
GetRenderWindow
()
{
return
RenderWindow
;};
...
...
src/Renderer.cc
View file @
16acf7f3
...
...
@@ -15,9 +15,10 @@ Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#include
<stdlib.h>
#include
<string.h>
#include
<math.h>
#include
"Renderer.hh"
#include
"RenderW.hh"
#include
"vlMath.hh"
// Description:
// Create object with black background, ambient light white, backlighting
...
...
@@ -141,20 +142,20 @@ void vlRenderer::DoActors()
}
// Description:
// Automatically set up the camera if no camera has been initially
// specified.
// Automatically set up the camera based on the visible actors.
// Camera will reposition itself to view the center point of the actors,
// and move along its initial view plane normal (i.e., vector defined from
// camera position to focal point).
void
vlRenderer
::
ResetCamera
()
{
vlActor
*
anActor
;
int
num
;
float
*
bounds
;
float
all_bounds
[
6
];
float
center
[
3
];
float
distance
;
float
width
;
float
allBounds
[
6
];
int
nothingVisible
=
1
;
all
_b
ounds
[
0
]
=
all
_b
ounds
[
2
]
=
all
_b
ounds
[
4
]
=
LARGE_FLOAT
;
all
_b
ounds
[
1
]
=
all
_b
ounds
[
3
]
=
all
_b
ounds
[
5
]
=
-
LARGE_FLOAT
;
all
B
ounds
[
0
]
=
all
B
ounds
[
2
]
=
all
B
ounds
[
4
]
=
LARGE_FLOAT
;
all
B
ounds
[
1
]
=
all
B
ounds
[
3
]
=
all
B
ounds
[
5
]
=
-
LARGE_FLOAT
;
// loop through actors
for
(
num
=
1
;
num
<=
this
->
Actors
.
GetNumberOfItems
();
num
++
)
...
...
@@ -164,35 +165,68 @@ void vlRenderer::ResetCamera()
// if it's invisible, we can skip the rest
if
(
anActor
->
GetVisibility
()
)
{
nothingVisible
=
0
;
bounds
=
anActor
->
GetBounds
();
if
(
bounds
[
0
]
<
all
_b
ounds
[
0
])
all
_b
ounds
[
0
]
=
bounds
[
0
];
if
(
bounds
[
1
]
>
all
_b
ounds
[
1
])
all
_b
ounds
[
1
]
=
bounds
[
1
];
if
(
bounds
[
2
]
<
all
_b
ounds
[
2
])
all
_b
ounds
[
2
]
=
bounds
[
2
];
if
(
bounds
[
3
]
>
all
_b
ounds
[
3
])
all
_b
ounds
[
3
]
=
bounds
[
3
];
if
(
bounds
[
4
]
<
all
_b
ounds
[
4
])
all
_b
ounds
[
4
]
=
bounds
[
4
];
if
(
bounds
[
5
]
>
all
_b
ounds
[
5
])
all
_b
ounds
[
5
]
=
bounds
[
5
];
if
(
bounds
[
0
]
<
all
B
ounds
[
0
])
all
B
ounds
[
0
]
=
bounds
[
0
];
if
(
bounds
[
1
]
>
all
B
ounds
[
1
])
all
B
ounds
[
1
]
=
bounds
[
1
];
if
(
bounds
[
2
]
<
all
B
ounds
[
2
])
all
B
ounds
[
2
]
=
bounds
[
2
];
if
(
bounds
[
3
]
>
all
B
ounds
[
3
])
all
B
ounds
[
3
]
=
bounds
[
3
];
if
(
bounds
[
4
]
<
all
B
ounds
[
4
])
all
B
ounds
[
4
]
=
bounds
[
4
];
if
(
bounds
[
5
]
>
all
B
ounds
[
5
])
all
B
ounds
[
5
]
=
bounds
[
5
];
}
}
// now we have the bounds for all actors
center
[
0
]
=
(
all_bounds
[
0
]
+
all_bounds
[
1
])
/
2.0
;
center
[
1
]
=
(
all_bounds
[
2
]
+
all_bounds
[
3
])
/
2.0
;
center
[
2
]
=
(
all_bounds
[
4
]
+
all_bounds
[
5
])
/
2.0
;
if
(
nothingVisible
)
{
vlErrorMacro
(
<<
"Can't reset camera if no actors are visible"
);
return
;
}
this
->
ResetCamera
(
allBounds
);
}
// Description:
// Automatically set up the camera based on a specified bounding box
// (xmin,xmax, ymin,ymax, zmin,zmax). Camera will reposition itself so
// that its focal point is the center of the bounding box, and adjust its
// distance and position to preserve its initial view plane normal
// (i.e., vector defined from camera position to focal point).
void
vlRenderer
::
ResetCamera
(
float
bounds
[
6
])
{
float
center
[
3
];
float
distance
;
float
width
;
vlMath
math
;
float
*
vpn
,
vn
[
3
];
if
(
this
->
ActiveCamera
!=
NULL
)
{
vpn
=
this
->
ActiveCamera
->
GetViewPlaneNormal
();
for
(
int
i
=
0
;
i
<
3
;
i
++
)
vn
[
i
]
=
vpn
[
i
];
}
else
{
vlErrorMacro
(
<<
"Trying to reset non-existant camera"
);
return
;
}
center
[
0
]
=
(
bounds
[
0
]
+
bounds
[
1
])
/
2.0
;
center
[
1
]
=
(
bounds
[
2
]
+
bounds
[
3
])
/
2.0
;
center
[
2
]
=
(
bounds
[
4
]
+
bounds
[
5
])
/
2.0
;
width
=
all_
bounds
[
3
]
-
all_
bounds
[
2
];
if
(
width
<
(
all_
bounds
[
1
]
-
all_
bounds
[
0
]))
width
=
bounds
[
3
]
-
bounds
[
2
];
if
(
width
<
(
bounds
[
1
]
-
bounds
[
0
]))
{
width
=
all_
bounds
[
1
]
-
all_
bounds
[
0
];
width
=
bounds
[
1
]
-
bounds
[
0
];
}
distance
=
0.8
*
width
/
tan
(
this
->
ActiveCamera
->
GetViewAngle
()
*
M_PI
/
360.0
);
distance
=
distance
+
(
all_
bounds
[
5
]
-
all_
bounds
[
4
])
/
2.0
;
distance
=
0.8
*
width
/
tan
(
this
->
ActiveCamera
->
GetViewAngle
()
*
math
.
Pi
()
/
360.0
);
distance
=
distance
+
(
bounds
[
5
]
-
bounds
[
4
])
/
2.0
;
// update the camera
this
->
ActiveCamera
->
SetFocalPoint
(
center
);
this
->
ActiveCamera
->
SetPosition
(
center
[
0
],
center
[
1
],
center
[
2
]
+
distance
);
this
->
ActiveCamera
->
SetView
Up
(
0
,
1
,
0
);
this
->
ActiveCamera
->
SetView
PlaneNormal
(
vn
);
this
->
ActiveCamera
->
SetClippingRange
(
distance
/
10.0
,
distance
*
5.0
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment