mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-03 18:31:55 -04:00
add fill_ratio
This commit is contained in:
parent
fd8bc506d3
commit
9f57cfa1b2
@ -163,10 +163,22 @@ set_projector(const NodePath &projector) {
|
|||||||
// and vertical dimension of the projector,
|
// and vertical dimension of the projector,
|
||||||
// respectively; distance represents the approximate
|
// respectively; distance represents the approximate
|
||||||
// distance of the screen from the lens center.
|
// distance of the screen from the lens center.
|
||||||
|
//
|
||||||
|
// The fill_ratio parameter specifies the fraction of
|
||||||
|
// the image to cover. If it is 1.0, the entire image
|
||||||
|
// is shown full-size; if it is 0.9, 10% of the image
|
||||||
|
// around the edges is not part of the grid (and the
|
||||||
|
// grid is drawn smaller by the same 10%). This is
|
||||||
|
// intended to work around graphics drivers that tend to
|
||||||
|
// show dark edges or other unsatisfactory artifacts
|
||||||
|
// around the edges of textures: render the texture
|
||||||
|
// larger than necessary by a certain fraction, and make
|
||||||
|
// the screen smaller by the inverse fraction.
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
PT(GeomNode) ProjectionScreen::
|
PT(GeomNode) ProjectionScreen::
|
||||||
generate_screen(const NodePath &projector, const string &screen_name,
|
generate_screen(const NodePath &projector, const string &screen_name,
|
||||||
int num_x_verts, int num_y_verts, float distance) {
|
int num_x_verts, int num_y_verts, float distance,
|
||||||
|
float fill_ratio) {
|
||||||
nassertr(!projector.is_empty() &&
|
nassertr(!projector.is_empty() &&
|
||||||
projector.node()->is_of_type(LensNode::get_class_type()),
|
projector.node()->is_of_type(LensNode::get_class_type()),
|
||||||
NULL);
|
NULL);
|
||||||
@ -188,10 +200,15 @@ generate_screen(const NodePath &projector, const string &screen_name,
|
|||||||
coords.reserve(num_verts);
|
coords.reserve(num_verts);
|
||||||
float x_scale = 2.0f / (num_x_verts - 1);
|
float x_scale = 2.0f / (num_x_verts - 1);
|
||||||
float y_scale = 2.0f / (num_y_verts - 1);
|
float y_scale = 2.0f / (num_y_verts - 1);
|
||||||
|
|
||||||
for (int yi = 0; yi < num_y_verts; yi++) {
|
for (int yi = 0; yi < num_y_verts; yi++) {
|
||||||
for (int xi = 0; xi < num_x_verts; xi++) {
|
for (int xi = 0; xi < num_x_verts; xi++) {
|
||||||
LPoint2f film = LPoint2f((float)xi * x_scale - 1.0f,
|
LPoint2f film = LPoint2f((float)xi * x_scale - 1.0f,
|
||||||
(float)yi * y_scale - 1.0f);
|
(float)yi * y_scale - 1.0f);
|
||||||
|
|
||||||
|
// Reduce the image by the fill ratio.
|
||||||
|
film *= fill_ratio;
|
||||||
|
|
||||||
LPoint3f near_point, far_point;
|
LPoint3f near_point, far_point;
|
||||||
lens->extrude(film, near_point, far_point);
|
lens->extrude(film, near_point, far_point);
|
||||||
|
|
||||||
@ -264,14 +281,15 @@ generate_screen(const NodePath &projector, const string &screen_name,
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void ProjectionScreen::
|
void ProjectionScreen::
|
||||||
regenerate_screen(const NodePath &projector, const string &screen_name,
|
regenerate_screen(const NodePath &projector, const string &screen_name,
|
||||||
int num_x_verts, int num_y_verts, float distance) {
|
int num_x_verts, int num_y_verts, float distance,
|
||||||
|
float fill_ratio) {
|
||||||
// First, remove all existing children.
|
// First, remove all existing children.
|
||||||
remove_all_children();
|
remove_all_children();
|
||||||
|
|
||||||
// And attach a new child.
|
// And attach a new child.
|
||||||
PT(GeomNode) geom_node =
|
PT(GeomNode) geom_node =
|
||||||
generate_screen(projector, screen_name, num_x_verts, num_y_verts,
|
generate_screen(projector, screen_name, num_x_verts, num_y_verts,
|
||||||
distance);
|
distance, fill_ratio);
|
||||||
add_child(geom_node);
|
add_child(geom_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,9 +67,10 @@ PUBLISHED:
|
|||||||
PT(GeomNode) generate_screen(const NodePath &projector,
|
PT(GeomNode) generate_screen(const NodePath &projector,
|
||||||
const string &screen_name,
|
const string &screen_name,
|
||||||
int num_x_verts, int num_y_verts,
|
int num_x_verts, int num_y_verts,
|
||||||
float distance);
|
float distance, float fill_ratio);
|
||||||
void regenerate_screen(const NodePath &projector, const string &screen_name,
|
void regenerate_screen(const NodePath &projector, const string &screen_name,
|
||||||
int num_x_verts, int num_y_verts, float distance);
|
int num_x_verts, int num_y_verts, float distance,
|
||||||
|
float fill_ratio);
|
||||||
PT(PandaNode) make_flat_mesh(const NodePath &camera);
|
PT(PandaNode) make_flat_mesh(const NodePath &camera);
|
||||||
|
|
||||||
INLINE void set_invert_uvs(bool invert_uvs);
|
INLINE void set_invert_uvs(bool invert_uvs);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user