void Frustum<NumericT>::build_frustrum_from_matrix (const Matrix<4, 4, NumericT> & m) { // The constructor used for Plane will normalize its elements automatically // Left (m3 + m0) _planes[LEFT] = convert_plane_from_matrix_eqn(m.at(3, 0)+m.at(0, 0), m.at(3, 1)+m.at(0, 1), m.at(3, 2)+m.at(0, 2), (m.at(3, 3)+m.at(0, 3))); // Right (m3 - m0) _planes[RIGHT] = convert_plane_from_matrix_eqn(m.at(3, 0)-m.at(0, 0), m.at(3, 1)-m.at(0, 1), m.at(3, 2)-m.at(0, 2), (m.at(3, 3)-m.at(0, 3))); // Top (m3 - m1) _planes[TOP] = convert_plane_from_matrix_eqn(m.at(3, 0)-m.at(1, 0), m.at(3, 1)-m.at(1, 1), m.at(3, 2)-m.at(1, 2), (m.at(3, 3)-m.at(1, 3))); // Bottom (m3 + m1) _planes[BOTTOM] = convert_plane_from_matrix_eqn(m.at(3, 0)+m.at(1, 0), m.at(3, 1)+m.at(1, 1), m.at(3, 2)+m.at(1, 2), (m.at(3, 3)+m.at(1, 3))); // Near _planes[NEAR] = convert_plane_from_matrix_eqn(m.at(2, 0), m.at(2, 1), m.at(2, 2), m.at(2, 3)); // Far (m3 - m2) _planes[FAR] = convert_plane_from_matrix_eqn(m.at(3, 0)-m.at(2, 0), m.at(3, 1)-m.at(2, 1), m.at(3, 2)-m.at(2, 2), (m.at(3, 3)-m.at(2, 3))); // Calculate object-space points for box coordinates: AlignedBox<3, NumericT> clip_box(-1, 1); Vec3u k(2); auto inverse_view_matrix = inverse(m); for (std::size_t i = 0; i < 8; i += 1) { _corners[i] = inverse_view_matrix * clip_box.corner(k.distribute(i)); } _near_center = inverse_view_matrix * Vec3T(0, 0, 1); _far_center = inverse_view_matrix * Vec3T(0, 0, -1); }
source_t *nearest_source(node_t *tree, double x, double y) { source_t *nearest = NULL; double dist; box_t interest; dist = dblmin(tree->box.xmax - tree->box.xmin, tree->box.ymax - tree->box.ymin) / 100.0; interest.xmin = x - dist; interest.ymin = y - dist; interest.xmax = x + dist; interest.ymax = y + dist; clip_box(&interest, &tree->box); dist = dist * dist; if (debug) { printf("nearest_source: \n"); printf(" target (%0.2f, %0.2f)\n", x, y); printf(" interest (%0.4f, %0.4f) (%0.4f, %0.4f)\n", interest.xmin, interest.ymin, interest.xmax, interest.ymax); } nearer_source(tree, tree, x, y, &interest, &nearest, &dist); if (debug) printf("\n"); return nearest; }
void bridge_canvas_rep::my_typeset (int desired_status) { canvas_properties props= get_canvas_properties (env, st); SI delta= 0; string type= props->type; if (type != "plain") { SI hpad= props->hpadding; SI w = props->bar_width; SI pad = props->bar_padding; SI bor = props->border; if (ends (type, "w") || ends (type, "e")) delta= max (0, w + pad); delta += 2 * bor + 2 * hpad; } SI l= env->get_length (PAR_LEFT); SI r= env->get_length (PAR_RIGHT) + delta; with= tuple (PAR_LEFT, tree (TMLEN, as_string (0))) * tuple (PAR_RIGHT, tree (TMLEN, as_string (l + r))); box b = typeset_ornament (desired_status); SI x1, y1, x2, y2, scx, scy; get_canvas_horizontal (props, b->x1, b->x2, x1, x2, scx); get_canvas_vertical (props, b->y1, b->y2, y1, y2, scy); path dip= (type == "plain"? ip: decorate (ip)); box cb= clip_box (dip, b, x1, y1, x2, y2, props->xt, props->yt, scx, scy); if (type != "plain") cb= put_scroll_bars (props, cb, ip, b, scx, scy); insert_ornament (cb); //insert_ornament (remember_box (decorate (ip), cb)); }
/* Look for the nearest source to the target node -- Place that we're searching target -- source we're looking for interest -- the area of interest nearest -- the current nearest match dist -- distance to current nearest match */ static void nearer_source(node_t *tree, node_t *node, double tx, double ty, box_t *interest, source_t **nearest, double *dist) { source_t *s; double s_dist; if (debug) { printf("nearer_source: (%0.4f, %0.4f) (%0.4f, %0.4f)\n", node->box.xmin, node->box.ymin, node->box.xmax, node->box.ymax); } // Check if the node interesects with the area of interest if (intersecting(&node->box, interest)) { // If the node has no children run through the compares if (node->q1 == NULL) { if (debug) printf(" intersection with leaf\n"); for (s = (source_t *)node->contents.first; s != NULL; s = (source_t *)s->links.next) { s_dist = norm2(s->x, s->y, tx, ty); if (debug) printf(" comparing (%0.2f, %0.2f) dist %0.4f", s->x, s->y, s_dist); if (s_dist < *dist) { *nearest = s; *dist = s_dist; s_dist = sqrt(s_dist); // actual distance interest->xmin = tx - s_dist; interest->ymin = ty - s_dist; interest->xmax = tx + s_dist; interest->ymax = ty + s_dist; clip_box(interest, &tree->box); if (debug) { printf(" -- new nearest: dist %0.4f box (%0.4f, %0.4f) (%0.4f, %0.4f)", s_dist, interest->xmin, interest->ymin, interest->xmax, interest->ymax); } } if (debug) printf("\n"); } } else { if (debug) printf(" intersection, checking children\n"); // If the node has children, recurse through the // tree by calling nearer_source on each of the children nearer_source(tree, node->q1, tx, ty, interest, nearest, dist); nearer_source(tree, node->q2, tx, ty, interest, nearest, dist); nearer_source(tree, node->q3, tx, ty, interest, nearest, dist); nearer_source(tree, node->q4, tx, ty, interest, nearest, dist); } } else { if (debug) printf(" no intersection\n"); } }
void GrPatternFilledBox(int x1,int y1,int x2,int y2,GrPattern *p) { int width,height; clip_box(CURC,x1,y1,x2,y2); mouse_block(CURC,x1,y1,x2,y2); width = x2 - x1 + 1; height = y2 - y1 + 1; x1 += CURC->gc_xoffset; y1 += CURC->gc_yoffset; if(!p->gp_ispixmap) while(--height >= 0) _GrFillPattern(x1,y1++,width,p); else { void (*bltfun)(GrFrame*,int,int,GrFrame*,int,int,int,int,GrColor); int pwdt = p->gp_pxp_width; int phgt = p->gp_pxp_height; int xoff = x1 % pwdt; int ypos = y1; int yoff = ypos % phgt; if (CURC->gc_onscreen) bltfun = CURC->gc_driver->bltr2v; else bltfun = CURC->gc_driver->bitblt; while(height > 0) { int fillh = min(height,(phgt - yoff)); int linewdt = width; int xpos = x1; int xcuroff = xoff; while(linewdt > 0) { int fillw = min(linewdt,(pwdt - xcuroff)); (*bltfun)( &CURC->gc_frame,xpos,ypos, &p->gp_pxp_source,xcuroff,yoff,fillw,fillh, p->gp_pxp_oper ); linewdt -= fillw; xpos += fillw; xcuroff = 0; } height -= fillh; ypos += fillh; yoff = 0; } } mouse_unblock(); }