/** * * Points are in world coordinates */ void Gouraud_Shading(face *f, object_copy *obj, vector<light> *lights, camera *camera, int xres, int yres, color **grid, float **depth_grid, MatrixXd *perspective, MatrixXd *inv_cam) { point *a = &(obj->points[f->vertices.index1-1]); color colora = lighting(a, &(obj->normals[f->normals.index1-1]), obj, lights, camera); point *b = &(obj->points[f->vertices.index2-1]); color colorb = lighting(b, &(obj->normals[f->normals.index2-1]), obj, lights, camera); point *c = &(obj->points[f->vertices.index3-1]); color colorc = lighting(c, &(obj->normals[f->normals.index3-1]), obj, lights, camera); point ndca = to_NDC(a, perspective, inv_cam); point ndcb = to_NDC(b, perspective, inv_cam); point ndcc = to_NDC(c, perspective, inv_cam); Vector3d va(ndca.x, ndca.y, ndca.z); Vector3d vb(ndcb.x, ndcb.y, ndcb.z); Vector3d vc(ndcc.x, ndcc.y, ndcc.z); Vector3d cross = (vc - vb).cross(va - vb); // ignore if pointing away from camera or if face is outside NDC box if (cross(2) >= 0 && is_in_box(&ndca) && is_in_box(&ndcb) && is_in_box(&ndcc)) raster_triangle(&ndca, &ndcb, &ndcc, colora, colorb, colorc, xres, yres, grid, depth_grid); }
int cbBarHintsPlugin::HitTestHints( cbBarInfo& info, const wxPoint& pos ) { wxPoint inPane = pos; mpPane->PaneToFrame( &inPane.x, &inPane.y ); wxRect& rect = info.mBoundsInParent; if ( info.IsFixed() ) return false; int boxOfs, grooveOfs, coord; GetHintsLayout( rect, info, boxOfs, grooveOfs, coord ); if ( mpPane->IsHorizontal() ) { if ( mCloseBoxOn ) { if ( is_in_box( wxPoint( rect.x + mHintGap + boxOfs, coord ), inPane ) ) return CLOSE_BOX_HITTED; coord += BTN_BOX_HEIGHT; } if ( mCollapseBoxOn ) { if ( mCloseBoxOn ) coord += BOX_T_BOX_GAP; if ( is_in_box( wxPoint( rect.x + mHintGap + boxOfs, coord ), inPane ) ) return COLLAPSE_BOX_HITTED; coord += BTN_BOX_HEIGHT; } } else { if ( mCloseBoxOn ) { coord -= BTN_BOX_WIDTH; if ( is_in_box( wxPoint( coord , rect.y + mHintGap + boxOfs ), inPane ) ) return CLOSE_BOX_HITTED; } if ( mCollapseBoxOn ) { if ( mCloseBoxOn ) coord -= BOX_T_BOX_GAP; coord -= BTN_BOX_WIDTH; if ( is_in_box( wxPoint( coord, rect.y + mHintGap + boxOfs ), inPane ) ) return COLLAPSE_BOX_HITTED; } } return false; }
/** * Also has depth buffering and ignores points where normals point away * * Points a, b, c are in NDC */ void raster_triangle_Phong(point *a, point *b, point *c, point *world_a, point *world_b, point *world_c, point *normal_a, point *normal_b, point *normal_c, object_copy *obj, vector<light> *lights, camera *CAM, int xres, int yres, color** grid, float** depth_grid, MatrixXd *perspective, MatrixXd *inv_cam) { point screen_a = NDC_to_screen(a, xres, yres); point screen_b = NDC_to_screen(b, xres, yres); point screen_c = NDC_to_screen(c, xres, yres); float x_min = min_x(&screen_a, &screen_b, &screen_c); float x_max = max_x(&screen_a, &screen_b, &screen_c); float y_min = min_y(&screen_a, &screen_b, &screen_c); float y_max = max_y(&screen_a, &screen_b, &screen_c); x_max = x_max > xres ? xres : x_max; y_max = y_max > yres ? yres : y_max; x_min = x_min < 0 ? 0 : x_min; y_min = y_min < 0 ? 0 : y_min; // TODO: compute colors by normals for (int x = x_min; x < x_max; x++) { for (int y = y_min; y < y_max; y++) { // get alpha/beta/gamma point curr_point = create_point(x, y, 0); float alpha = compute_alpha(&screen_a, &screen_b, &screen_c, &curr_point); float beta = compute_beta(&screen_a, &screen_b, &screen_c, &curr_point); float gamma = compute_gamma(&screen_a, &screen_b, &screen_c, &curr_point); curr_point.z = alpha * screen_a.z + beta * screen_b.z + gamma * screen_c.z; // compute interpolated point (in world view) and normal for the point point normal = (*normal_a) * alpha + (*normal_b) * beta + (*normal_c) * gamma; point coordinate = (*world_a) * alpha + (*world_b) * beta + (*world_c) * gamma; point ndc_coordinate = to_NDC(&coordinate, perspective, inv_cam); if (is_in_box(&ndc_coordinate) && valid_parameters(alpha, beta, gamma) && depth_grid[x][y] > curr_point.z) { color col = lighting(&coordinate, &normal, obj, lights, CAM); grid[x][y].r = col.r; grid[x][y].g = col.g; grid[x][y].b = col.b; depth_grid[x][y] = curr_point.z; } } } }