/** * Check whether the location is inside the box. * * @pre Location must be defined. * @pre Box must be defined. */ bool contains(const osmium::Location& location) const noexcept { assert(bottom_left()); assert(top_right()); assert(location); return location.x() >= bottom_left().x() && location.y() >= bottom_left().y() && location.x() <= top_right().x() && location.y() <= top_right().y(); }
bool MapReader::GetRoadsInBounds(IPosition::GPS top_left, IPosition::GPS bottom_right, std::vector<std::string> & street_names) { IPosition::GPS bottom_left(bottom_right.lat, top_left.lon, 0.0); IPosition::GPS top_right(top_left.lat, bottom_right.lon, 0.0); for (unsigned i = 0; i < ways.size(); i++) { const Way & way = ways[i]; IPosition::GPS way_lower_left, way_upper_right; GetWayBounds(way, way_lower_left, way_upper_right); bool left_in_bounds = way_lower_left.lon > bottom_left.lon && way_lower_left.lon < top_right.lon; bool right_in_bounds = way_upper_right.lon > bottom_left.lon && way_upper_right.lon < top_right.lon; bool top_in_bounds = way_upper_right.lat > bottom_left.lat && way_upper_right.lat < top_right.lat; bool bottom_in_bounds = way_lower_left.lat > bottom_left.lat && way_lower_left.lat < top_right.lat; if ((left_in_bounds && (top_in_bounds || bottom_in_bounds)) || (right_in_bounds && (top_in_bounds || bottom_in_bounds))) { if (std::find(street_names.begin(), street_names.end(), way.name) == street_names.end()) { street_names.push_back(way.name); } } } return true; }
void top_right(node * root) { cout << root->data << " "; if (root->right != NULL) { top_right(root->right); } }
worksheet::const_iterator worksheet::cbegin() const { auto dimensions = calculate_dimension(); cell_reference top_right(dimensions.get_bottom_right().get_column_index(), dimensions.get_top_left().get_row()); range_reference row_range(dimensions.get_top_left(), top_right); return const_iterator(*this, row_range, major_order::row); }
void top_view(node * root) { if (root->left != NULL) { top_left(root->left); } cout << root->data << " "; if (root->right != NULL) { top_right(root->right); } }
bool aabr_smallest_subaabr_containing_line (aabr const& r, move2 const& line, aabr& res__aabr) { real2 p1,p2; real unused, thouShaltNotPass; if( line_intersection(r, line, p1, unused, p2, thouShaltNotPass) ) { real2 bottom_left( MIN(p1.x,p2.x), MIN(p1.y,p2.y)); real2 top_right( MAX(p1.x,p2.x), MAX(p1.y,p2.y)); res__aabr = aabr( bottom_left, top_right - bottom_left ); return true; } else return false; }
// Return the bounding boxes of columns at the given y-range void ColPartitionSet::GetColumnBoxes(int y_bottom, int y_top, ColSegment_LIST *segments) { ColPartition_IT it(&parts_); ColSegment_IT col_it(segments); col_it.move_to_last(); for (it.mark_cycle_pt(); !it.cycled_list(); it.forward()) { ColPartition* part = it.data(); ICOORD bot_left(part->LeftAtY(y_top), y_bottom); ICOORD top_right(part->RightAtY(y_bottom), y_top); ColSegment *col_seg = new ColSegment(); col_seg->InsertBox(TBOX(bot_left, top_right)); col_it.add_after_then_move(col_seg); } }
//------------------------------------------------------------------------------ void QLabel::CalculateSize( void) { CCPoint bottom_left( 0.0f, 0.0f); CCSize content_size = m_CCFontNode->getContentSize(); CCPoint top_right( content_size.width, content_size.height); CCAffineTransform to_parent = CCAffineTransformConcat(m_CCFontNode->nodeToParentTransform(), m_CCNode->nodeToParentTransform()); bottom_left = CCPointApplyAffineTransform( bottom_left, to_parent); top_right = CCPointApplyAffineTransform( top_right, to_parent); xText = bottom_left.x; yText = bottom_left.y; wText = top_right.x - bottom_left.x; hText = top_right.y - bottom_left.y; }
int ccc_win_main() { Point top_left(1, 3); Point top_right(1, 4); Point bottom_left(2, 3); Line horizontal(top_left, top_right); Line vertical(top_left, bottom_left); cwin << horizontal << vertical; horizontal.move(1, 0); vertical.move(0, 1); cwin << horizontal << vertical; return 0; }
OrientedBoxInterface::OrientedBoxInterface(const InputParameters & parameters) : _center(parameters.get<Point>("center")) { const std::string & name = parameters.get<std::string>("_object_name"); // Define the bounding box Real xmax = 0.5 * parameters.get<Real>("width"); Real ymax = 0.5 * parameters.get<Real>("length"); Real zmax = 0.5 * parameters.get<Real>("height"); Point bottom_left(-xmax, -ymax, -zmax); Point top_right(xmax, ymax, zmax); _bounding_box = new MeshTools::BoundingBox(bottom_left, top_right); /* * now create the rotation matrix that rotates the oriented * box's width direction to "x", its length direction to "y" * and its height direction to "z" */ RealVectorValue w = parameters.get<RealVectorValue>("width_direction"); RealVectorValue l = parameters.get<RealVectorValue>("length_direction"); /* * Normalize the width and length directions in readiness for * insertion into the rotation matrix */ Real len = w.norm(); if (len == 0.0) mooseError("Length of width_direction vector is zero in " << name); w /= len; len = l.norm(); if (len == 0.0) mooseError("Length of length_direction vector is zero in " << name); l /= len; if (w*l > 1E-10) mooseError("width_direction and length_direction are not perpendicular in " << name); // The rotation matrix! _rot_matrix = new RealTensorValue(w, l, w.cross(l)); }
// Returns a bounding box of the outline contained within the // given horizontal range. TBOX BLOBNBOX::BoundsWithinLimits(int left, int right) { FCOORD no_rotation(1.0f, 0.0f); float top = box.top(); float bottom = box.bottom(); if (cblob_ptr != NULL) { find_cblob_limits(cblob_ptr, static_cast<float>(left), static_cast<float>(right), no_rotation, bottom, top); } if (top < bottom) { top = box.top(); bottom = box.bottom(); } FCOORD bot_left(left, bottom); FCOORD top_right(right, top); TBOX shrunken_box(bot_left); TBOX shrunken_box2(top_right); shrunken_box += shrunken_box2; return shrunken_box; }
void TrajectoryCosts::CalculateLateralAndLongitudinalCosts(vector<TrajectoryCost>& trajectoryCosts, const vector<vector<vector<WayPoint> > >& rollOuts, const vector<vector<WayPoint> >& totalPaths, const WayPoint& currState, const vector<WayPoint>& contourPoints, const PlanningParams& params, const CAR_BASIC_INFO& carInfo, const VehicleState& vehicleState) { double critical_lateral_distance = carInfo.width/2.0 + params.horizontalSafetyDistancel; double critical_long_front_distance = carInfo.wheel_base/2.0 + carInfo.length/2.0 + params.verticalSafetyDistance; double critical_long_back_distance = carInfo.length/2.0 + params.verticalSafetyDistance - carInfo.wheel_base/2.0; int iCostIndex = 0; PlannerHNS::Mat3 rotationMat(-currState.pos.a); PlannerHNS::Mat3 translationMat(-currState.pos.x, -currState.pos.y); PlannerHNS::Mat3 invRotationMat(currState.pos.a-M_PI_2); PlannerHNS::Mat3 invTranslationMat(currState.pos.x, currState.pos.y); double corner_slide_distance = critical_lateral_distance/2.0; double ratio_to_angle = corner_slide_distance/carInfo.max_steer_angle; double slide_distance = vehicleState.steer * ratio_to_angle; GPSPoint bottom_left(-critical_lateral_distance ,-critical_long_back_distance, currState.pos.z, 0); GPSPoint bottom_right(critical_lateral_distance, -critical_long_back_distance, currState.pos.z, 0); GPSPoint top_right_car(critical_lateral_distance, carInfo.wheel_base/3.0 + carInfo.length/3.0, currState.pos.z, 0); GPSPoint top_left_car(-critical_lateral_distance, carInfo.wheel_base/3.0 + carInfo.length/3.0, currState.pos.z, 0); GPSPoint top_right(critical_lateral_distance - slide_distance, critical_long_front_distance, currState.pos.z, 0); GPSPoint top_left(-critical_lateral_distance - slide_distance , critical_long_front_distance, currState.pos.z, 0); bottom_left = invRotationMat*bottom_left; bottom_left = invTranslationMat*bottom_left; top_right = invRotationMat*top_right; top_right = invTranslationMat*top_right; bottom_right = invRotationMat*bottom_right; bottom_right = invTranslationMat*bottom_right; top_left = invRotationMat*top_left; top_left = invTranslationMat*top_left; top_right_car = invRotationMat*top_right_car; top_right_car = invTranslationMat*top_right_car; top_left_car = invRotationMat*top_left_car; top_left_car = invTranslationMat*top_left_car; // m_SafetyBox.clear(); // m_SafetyBox.push_back(bottom_left); // m_SafetyBox.push_back(bottom_right); // m_SafetyBox.push_back(top_right); // m_SafetyBox.push_back(top_left); m_SafetyBorder.points.clear(); m_SafetyBorder.points.push_back(bottom_left) ; m_SafetyBorder.points.push_back(bottom_right) ; m_SafetyBorder.points.push_back(top_right_car) ; m_SafetyBorder.points.push_back(top_right) ; m_SafetyBorder.points.push_back(top_left) ; m_SafetyBorder.points.push_back(top_left_car) ; for(unsigned int il=0; il < rollOuts.size(); il++) { if(rollOuts.at(il).size() > 0 && rollOuts.at(il).at(0).size()>0) { RelativeInfo car_info; PlanningHelpers::GetRelativeInfo(totalPaths.at(il), currState, car_info); for(unsigned int it=0; it< rollOuts.at(il).size(); it++) { for(unsigned int icon = 0; icon < contourPoints.size(); icon++) { RelativeInfo obj_info; PlanningHelpers::GetRelativeInfo(totalPaths.at(il), contourPoints.at(icon), obj_info); double longitudinalDist = PlanningHelpers::GetExactDistanceOnTrajectory(totalPaths.at(il), car_info, obj_info); if(obj_info.iFront == 0 && longitudinalDist > 0) longitudinalDist = -longitudinalDist; double close_in_percentage = 1; // close_in_percentage = ((longitudinalDist- critical_long_front_distance)/params.rollInMargin)*4.0; // // if(close_in_percentage <= 0 || close_in_percentage > 1) close_in_percentage = 1; double distance_from_center = trajectoryCosts.at(iCostIndex).distance_from_center; if(close_in_percentage < 1) distance_from_center = distance_from_center - distance_from_center * (1.0-close_in_percentage); double lateralDist = fabs(obj_info.perp_distance - distance_from_center); if(longitudinalDist < -carInfo.length || lateralDist > 6) { continue; } longitudinalDist = longitudinalDist - critical_long_front_distance; if(m_SafetyBorder.PointInsidePolygon(m_SafetyBorder, contourPoints.at(icon).pos) == true) trajectoryCosts.at(iCostIndex).bBlocked = true; if(lateralDist <= critical_lateral_distance && longitudinalDist >= -carInfo.length/1.5 && longitudinalDist < params.minFollowingDistance) trajectoryCosts.at(iCostIndex).bBlocked = true; trajectoryCosts.at(iCostIndex).lateral_cost += 1.0/lateralDist; trajectoryCosts.at(iCostIndex).longitudinal_cost += 1.0/fabs(longitudinalDist); if(longitudinalDist >= -critical_long_front_distance && longitudinalDist < trajectoryCosts.at(iCostIndex).closest_obj_distance) { trajectoryCosts.at(iCostIndex).closest_obj_distance = longitudinalDist; trajectoryCosts.at(iCostIndex).closest_obj_velocity = contourPoints.at(icon).v; } } iCostIndex++; } } } }
osg::Node* createWrapWall(osg::BoundingBox& bb,const std::string& filename) { osg::Group* group = new osg::Group; // left hand side of bounding box. osg::Vec3 top_left(bb.xMax(),bb.yMax(),bb.zMax()); osg::Vec3 bottom_left(bb.xMax(),bb.yMax(),bb.zMin()); osg::Vec3 bottom_right(bb.xMax(),bb.yMin(),bb.zMin()); osg::Vec3 top_right(bb.xMax(),bb.yMin(),bb.zMax()); osg::Vec3 center(bb.xMax(),(bb.yMin()+bb.yMax())*0.5f,(bb.zMin()+bb.zMax())*0.5f); float height = bb.zMax()-bb.zMin(); // create the geometry for the wall. osg::Geometry* geom = new osg::Geometry; osg::Vec3Array* vertices = new osg::Vec3Array(4); (*vertices)[0] = top_left; (*vertices)[1] = bottom_left; (*vertices)[2] = bottom_right; (*vertices)[3] = top_right; geom->setVertexArray(vertices); osg::Vec2Array* texcoords = new osg::Vec2Array(4); (*texcoords)[0].set(-1.0f,2.0f); (*texcoords)[1].set(-1.0f,-1.0f); (*texcoords)[2].set(2.0f,-1.0f); (*texcoords)[3].set(2.0f,2.0f); geom->setTexCoordArray(0,texcoords); osg::Vec3Array* normals = new osg::Vec3Array(1); (*normals)[0].set(-1.0f,0.0f,0.0f); geom->setNormalArray(normals, osg::Array::BIND_OVERALL); osg::Vec4Array* colors = new osg::Vec4Array(1); (*colors)[0].set(1.0f,1.0f,1.0f,1.0f); geom->setColorArray(colors, osg::Array::BIND_OVERALL); geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4)); osg::Geode* geom_geode = new osg::Geode; geom_geode->addDrawable(geom); group->addChild(geom_geode); // set up the texture state. osg::Texture2D* texture = new osg::Texture2D; texture->setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state. texture->setBorderColor(osg::Vec4(1.0f,1.0f,1.0f,0.5f)); // only used when wrap is set to CLAMP_TO_BORDER texture->setImage(osgDB::readRefImageFile(filename)); osg::StateSet* stateset = geom->getOrCreateStateSet(); stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); stateset->setMode(GL_BLEND,osg::StateAttribute::ON); stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); // create the text label. osgText::Text* text = new osgText::Text; text->setDataVariance(osg::Object::DYNAMIC); text->setFont("fonts/arial.ttf"); text->setPosition(center); text->setCharacterSize(height*0.03f); text->setAlignment(osgText::Text::CENTER_CENTER); text->setAxisAlignment(osgText::Text::YZ_PLANE); osg::Geode* text_geode = new osg::Geode; text_geode->addDrawable(text); osg::StateSet* text_stateset = text_geode->getOrCreateStateSet(); text_stateset->setAttributeAndModes(new osg::PolygonOffset(-1.0f,-1.0f),osg::StateAttribute::ON); group->addChild(text_geode); // set the update callback to cycle through the various min and mag filter modes. group->setUpdateCallback(new WrapCallback(texture,text)); return group; }
JNIEXPORT void JNICALL Java_org_openscenegraph_osg_core_Geode_nativeGetTextureRectangle2( JNIEnv *env, jclass, jlong cptr, jlong imagecptr, jfloat width, jfloat height) { osg::Geode *geode = reinterpret_cast<osg::Geode *>(cptr); osg::Image *image = reinterpret_cast<osg::Image *>(imagecptr); osg::BoundingBox bb(0.0f,0.0f,0.0f,width,height,0.0f); osg::Vec3 top_left(bb.xMin(),bb.yMax(),bb.zMax()); osg::Vec3 bottom_left(bb.xMin(),bb.yMin(),bb.zMax()); osg::Vec3 bottom_right(bb.xMax(),bb.yMin(),bb.zMax()); osg::Vec3 top_right(bb.xMax(),bb.yMax(),bb.zMax()); // create geometry osg::Geometry* geom = new osg::Geometry; osg::Vec3Array* vertices = new osg::Vec3Array(6); (*vertices)[0] = top_left; (*vertices)[1] = bottom_left; (*vertices)[2] = bottom_right; (*vertices)[3] = bottom_right; (*vertices)[4] = top_right; (*vertices)[5] = top_left; geom->setVertexArray(vertices); osg::Vec2Array* texcoords = new osg::Vec2Array(6); (*texcoords)[0].set(0.0f, 0.0f); (*texcoords)[1].set(0.0f, 1.0f); (*texcoords)[2].set(1.0f, 1.0f); (*texcoords)[3].set(1.0f, 1.0f); (*texcoords)[4].set(1.0f, 0.0f); (*texcoords)[5].set(0.0f, 0.0f); geom->setTexCoordArray(0,texcoords); osg::Vec3Array* normals = new osg::Vec3Array(1); (*normals)[0].set(0.0f,-1.0f,0.0f); geom->setNormalArray(normals); geom->setNormalBinding(osg::Geometry::BIND_OVERALL); osg::Vec4Array* colors = new osg::Vec4Array(1); (*colors)[0].set(1.0f,1.0f,1.0f,1.0f); geom->setColorArray(colors); geom->setColorBinding(osg::Geometry::BIND_OVERALL); geom->addPrimitiveSet(new osg::DrawArrays(GL_TRIANGLES, 0, 6)); // disable display list so our modified tex coordinates show up geom->setUseDisplayList(false); // setup texture osg::Texture2D* texture = new osg::Texture2D(image); texture->setDataVariance(osg::Object::DYNAMIC); /*/////////////////////kookmin start/////////////////////*/ // setup state osg::StateSet* state = geom->getOrCreateStateSet(); state->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); state->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); /*/////////////////////kookmin start/////////////////////*/ // turn off lighting state->setMode(GL_LIGHTING, osg::StateAttribute::OFF); texture->ref(); //image->ref(); geom->ref(); geode->addDrawable(geom); }
void MyRendererTFEditor_TFE::paintEvent( QPaintEvent * ) { QPainter painter( this ); painter.setRenderHint( QPainter::Antialiasing, false ); int s_w = this->size().width(); int s_h = this->size().height(); std::vector < TFEMarker > mrks; // remove isomarker for convienence TFEMarkers tfe_markers = m_tfe_markers; for( int i = 0 ; i < tfe_markers.markers.size() ; ) if( tfe_markers.markers.at( i ).b_iso ) tfe_markers.delMarker( i ); else i++; mrks = tfe_markers.markers; // paint tranfer function indirectly via tf markers for( int i = 0 ; i < mrks.size() - 1 ; i++ ) { QPoint bottom_left( rescale( m_display_min, m_display_max, mrks.at( i ).x, 0.0, 1.0 ) * s_w, s_h ); QPoint top_left( rescale( m_display_min, m_display_max, mrks.at( i ).x, 0.0, 1.0 ) * s_w, ( 1 - mrks.at( i ).color_right.alphaF() ) * s_h ); QPoint bottom_right( rescale( m_display_min, m_display_max, mrks.at( i+1 ).x, 0.0, 1.0 ) * s_w, s_h ); QPoint top_right( rescale( m_display_min, m_display_max, mrks.at( i+1 ).x, 0.0, 1.0 ) * s_w, ( 1 - mrks.at( i+1 ).color_left.alphaF() ) * s_h ); QPoint points[] = { top_right, bottom_right, bottom_left, top_left }; QLinearGradient gradient( bottom_left, bottom_right ); gradient.setColorAt( 0, mrks.at( i ).color_right ); gradient.setColorAt( 1, mrks.at( i+1 ).color_left ); painter.setPen( Qt::transparent ); painter.setBrush( gradient ); painter.drawPolygon( points, 4 ); } // paint histogram //for( int i = 0 ; i < TF_SIZE ; i++ ) //{ // int x_rescaled = int(rescale( 0, s_w - 1, i, m_display_min * ( TF_SIZE - 1 ), m_display_max * ( TF_SIZE - 1 ) )); // // // paint histogram // painter.setPen( QColor( 185, 185, 185, 75 ) ); // painter.drawLine( QLineF( i, // s_h, // i, // s_h - m_histogram[x_rescaled] * s_h ) ); //} painter.setRenderHint( QPainter::Antialiasing, true ); mrks = m_tfe_markers.markers; // paint markers for( int i = 1 ; i < mrks.size() - 1 ; i++ ) { float rect_center_x = ( rescale( m_display_min, m_display_max, mrks.at(i).x, 0.0, 1.0 ) * s_w ); float rect_center_y; QColor color_marker; int size_mark = 3; // paint vertical lines for iso marker if( mrks.at( i ).b_iso ) { painter.setRenderHint( QPainter::Antialiasing, false ); painter.setPen( QColor( 0, 0, 0, 50 ) ); painter.drawLine( QLineF( rect_center_x - 1, s_h, rect_center_x - 1, 0 ) ); painter.drawLine( QLineF( rect_center_x + 1, s_h, rect_center_x + 1, 0 ) ); painter.setPen( mrks.at( i ).color_left ); painter.drawLine( QLineF( rect_center_x, s_h, rect_center_x, 0 ) ); painter.setRenderHint( QPainter::Antialiasing, true ); } // draw markers rect_center_y = ( s_h - mrks.at(i).color_left.alpha() * s_h / 255.0 ); color_marker = mrks.at(i).color_left; color_marker.setAlpha( 255 ); if( mrks.at(i).color_left == mrks.at(i).color_right ) { painter.setPen( Qt::black ); painter.setBrush( Qt::NoBrush ); painter.drawEllipse( QRectF( rect_center_x - size_mark - 1, rect_center_y - size_mark - 1, 2*size_mark + 3 , 2*size_mark + 3 ) ); painter.setPen( color_marker ); painter.setBrush( QBrush( color_marker ) ); painter.drawEllipse( QRectF( rect_center_x - size_mark, rect_center_y - size_mark, 2*size_mark + 1 , 2*size_mark + 1 ) ); } else { painter.setPen( Qt::black ); painter.setBrush( Qt::NoBrush ); painter.drawEllipse( QRectF( rect_center_x - size_mark - 1, rect_center_y - size_mark - 1, 2*size_mark + 3 , 2*size_mark + 3 ) ); painter.setPen( color_marker ); painter.setBrush( QBrush( color_marker ) ); painter.drawEllipse( QRectF( rect_center_x - size_mark, rect_center_y - size_mark, 2*size_mark + 1 , 2*size_mark + 1 ) ); rect_center_y = ( s_h - mrks.at(i).color_right.alpha() * s_h / 255.0 ); color_marker = mrks.at(i).color_right; color_marker.setAlpha( 255 ); painter.setPen( Qt::black ); painter.setBrush( Qt::NoBrush ); painter.drawEllipse( QRectF( rect_center_x - size_mark - 1, rect_center_y - size_mark - 1, 2*size_mark + 3 , 2*size_mark + 3 ) ); painter.setPen( color_marker ); painter.setBrush( QBrush( color_marker ) ); painter.drawEllipse( QRectF( rect_center_x - size_mark, rect_center_y - size_mark, 2*size_mark + 1 , 2*size_mark + 1 ) ); } } // draw white circle around selected marker if( m_tfe_marker_selected != 0 ) { float rect_center_x = rescale( m_display_min, m_display_max, mrks.at(m_tfe_marker_selected).x, 0.0, 1.0 ) * s_w; float rect_center_y; int size_mark = 5; painter.setPen( QColor( 0, 0, 0, 50 ) ); painter.setBrush( Qt::NoBrush ); rect_center_y = s_h - mrks.at(m_tfe_marker_selected).color_left.alpha() * s_h / 255.0; if( mrks.at( m_tfe_marker_selected ).color_left == mrks.at( m_tfe_marker_selected ).color_right ) painter.drawEllipse( QRectF( rect_center_x - size_mark, rect_center_y - size_mark, 2*size_mark + 1 , 2*size_mark + 1 ) ); else { painter.drawEllipse( QRectF( rect_center_x - size_mark, rect_center_y - size_mark, 2*size_mark + 1 , 2*size_mark + 1 ) ); rect_center_y = s_h - mrks.at(m_tfe_marker_selected).color_right.alpha() * s_h / 255.0; painter.drawEllipse( QRectF( rect_center_x - size_mark, rect_center_y - size_mark, 2*size_mark + 1 , 2*size_mark + 1 ) ); } } // draw translucent white divisions int count_divisions; count_divisions = 20; for( int i = 1; i < count_divisions; i++ ) { float tenth = s_w / float( count_divisions ); painter.setPen( QColor( 255, 255, 255, 65 ) ); painter.drawLine( QLineF( tenth * i, 0, tenth * i, s_h ) ); painter.drawText( QPoint( tenth* i + 4, s_h - 3 ), tr( "%1" ).arg( m_display_min + ( m_display_max - m_display_min ) * i / count_divisions, 0, 'f', 2 ) ); } count_divisions = 5; for( int i = 1; i < count_divisions; i++ ) { float fourth = s_h / float( count_divisions ); painter.setPen( QColor( 255, 255, 255, 65 ) ); painter.drawLine( QLineF( 0, fourth * i, s_w, fourth * i ) ); } // paint black rectangular border painter.setRenderHint( QPainter::Antialiasing, false ); painter.setPen( QColor( 0, 0, 0, 50 ) ); painter.setBrush( Qt::NoBrush ); painter.drawRect( 0, 0, s_w - 1, s_h - 1 ); }
//------------------------------------------------------------------------------ void Background2D::OnResize() { calculateScreenScale(); for( unsigned int i = 0; i < m_Tiles.size(); ++i ) { Tile &tile( m_Tiles[ i ] ); Ogre::Vector2 top_left ( tile.x, -tile.y ); Ogre::Vector2 top_right( tile.x + tile.width, top_left.y ); Ogre::Vector2 bottom_right( top_right.x, -( tile.y + tile.height ) ); Ogre::Vector2 bottom_left( top_left.x, bottom_right.y ); virtualScreenToWorldSpace( top_left ); virtualScreenToWorldSpace( top_right ); virtualScreenToWorldSpace( bottom_right ); virtualScreenToWorldSpace( bottom_left ); float new_x1 = top_left.x; float new_y1 = top_left.y; float new_x2 = top_right.x; float new_y2 = top_right.y; float new_x3 = bottom_right.x; float new_y3 = bottom_right.y; float new_x4 = bottom_left.x; float new_y4 = bottom_left.y; Ogre::HardwareVertexBufferSharedPtr vertex_buffer; if( m_Tiles[ i ].blending == QGears::B_ALPHA ) { vertex_buffer = m_AlphaVertexBuffer; } else if( m_Tiles[ i ].blending == QGears::B_ADD ) { vertex_buffer = m_AddVertexBuffer; } float* writeIterator = ( float* )vertex_buffer->lock( Ogre::HardwareBuffer::HBL_NORMAL ); writeIterator += m_Tiles[ i ].start_vertex_index * TILE_VERTEX_INDEX_SIZE; *writeIterator++ = new_x1; *writeIterator++ = new_y1; writeIterator += 7; *writeIterator++ = new_x2; *writeIterator++ = new_y2; writeIterator += 7; *writeIterator++ = new_x3; *writeIterator++ = new_y3; writeIterator += 7; ///* *writeIterator++ = new_x1; *writeIterator++ = new_y1; writeIterator += 7; *writeIterator++ = new_x3; *writeIterator++ = new_y3; writeIterator += 7; //*/ *writeIterator++ = new_x4; *writeIterator++ = new_y4; vertex_buffer->unlock(); } applyScroll(); }
//------------------------------------------------------------------------------ void Background2D::AddTile( const int x, const int y, const int width, const int height, const float depth, const float u1, const float v1, const float u2, const float v2, const Blending blending ) { Ogre::RenderOperation render_op; Ogre::HardwareVertexBufferSharedPtr vertex_buffer; unsigned int max_vertex_count; if( blending == QGears::B_ALPHA ) { render_op = m_AlphaRenderOp; vertex_buffer = m_AlphaVertexBuffer; max_vertex_count = m_AlphaMaxVertexCount; } else if( blending == QGears::B_ADD ) { render_op = m_AddRenderOp; vertex_buffer = m_AddVertexBuffer; max_vertex_count = m_AddMaxVertexCount; } else { LOG_ERROR( "Unknown blending type." ); return; } if( render_op.vertexData->vertexCount + TILE_VERTEX_COUNT > max_vertex_count ) { LOG_ERROR( "Max number of tiles reached. Can't create more than " + Ogre::StringConverter::toString( max_vertex_count / TILE_VERTEX_COUNT ) + " tiles." ); return; } Tile tile; tile.x = x; tile.y = y; tile.width = width; tile.height = height; tile.start_vertex_index = render_op.vertexData->vertexCount; tile.blending = blending; size_t index( m_Tiles.size() ); m_Tiles.push_back( tile ); Ogre::Vector2 top_left ( x, -y ); Ogre::Vector2 top_right( x + width, top_left.y ); Ogre::Vector2 bottom_right( top_right.x, -( y + height ) ); Ogre::Vector2 bottom_left( top_left.x, bottom_right.y ); virtualScreenToWorldSpace( top_left ); virtualScreenToWorldSpace( top_right ); virtualScreenToWorldSpace( bottom_right ); virtualScreenToWorldSpace( bottom_left ); float new_x1 = top_left.x; float new_y1 = top_left.y; float new_x2 = top_right.x; float new_y2 = top_right.y; float new_x3 = bottom_right.x; float new_y3 = bottom_right.y; float new_x4 = bottom_left.x; float new_y4 = bottom_left.y; float* writeIterator = ( float* )vertex_buffer->lock( Ogre::HardwareBuffer::HBL_NORMAL ); writeIterator += render_op.vertexData->vertexCount * TILE_VERTEX_INDEX_SIZE; *writeIterator++ = new_x1; *writeIterator++ = new_y1; *writeIterator++ = depth; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = u1; *writeIterator++ = v1; *writeIterator++ = new_x2; *writeIterator++ = new_y2; *writeIterator++ = depth; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = u2; *writeIterator++ = v1; *writeIterator++ = new_x3; *writeIterator++ = new_y3; *writeIterator++ = depth; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = u2; *writeIterator++ = v2; *writeIterator++ = new_x1; *writeIterator++ = new_y1; *writeIterator++ = depth; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = u1; *writeIterator++ = v1; *writeIterator++ = new_x3; *writeIterator++ = new_y3; *writeIterator++ = depth; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = u2; *writeIterator++ = v2; *writeIterator++ = new_x4; *writeIterator++ = new_y4; *writeIterator++ = depth; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = 1; *writeIterator++ = u1; *writeIterator++ = v2; render_op.vertexData->vertexCount += TILE_VERTEX_COUNT; vertex_buffer->unlock(); }
vertex_list3 sprite::map() const { auto r = bounding_box(); return vertex_list3{{ r.top_left().to_vector3(), r.top_right().to_vector3(), r.bottom_right().to_vector3(), r.bottom_left().to_vector3() }}; }
virtual ng::vertex_list3 map() const { auto r = bounding_box(); return ng::vertex_list3{ r.top_left().to_vector3(), r.top_right().to_vector3(), r.bottom_right().to_vector3(), r.bottom_left().to_vector3() }; }
osg::Node* createRectangle(osg::BoundingBox& bb, const std::string& filename) { osg::Vec3 top_left(bb.xMin(),bb.yMax(),bb.zMax()); osg::Vec3 bottom_left(bb.xMin(),bb.yMax(),bb.zMin()); osg::Vec3 bottom_right(bb.xMax(),bb.yMax(),bb.zMin()); osg::Vec3 top_right(bb.xMax(),bb.yMax(),bb.zMax()); // create geometry osg::Geometry* geom = new osg::Geometry; osg::Vec3Array* vertices = new osg::Vec3Array(4); (*vertices)[0] = top_left; (*vertices)[1] = bottom_left; (*vertices)[2] = bottom_right; (*vertices)[3] = top_right; geom->setVertexArray(vertices); osg::Vec2Array* texcoords = new osg::Vec2Array(4); (*texcoords)[0].set(0.0f, 0.0f); (*texcoords)[1].set(1.0f, 0.0f); (*texcoords)[2].set(1.0f, 1.0f); (*texcoords)[3].set(0.0f, 1.0f); geom->setTexCoordArray(0,texcoords); osg::Vec3Array* normals = new osg::Vec3Array(1); (*normals)[0].set(0.0f,-1.0f,0.0f); geom->setNormalArray(normals, osg::Array::BIND_OVERALL); osg::Vec4Array* colors = new osg::Vec4Array(1); (*colors)[0].set(1.0f,1.0f,1.0f,1.0f); geom->setColorArray(colors, osg::Array::BIND_OVERALL); geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, 4)); // disable display list so our modified tex coordinates show up geom->setUseDisplayList(false); // load image osg::ref_ptr<osg::Image> img = osgDB::readRefImageFile(filename); // setup texture osg::TextureRectangle* texture = new osg::TextureRectangle(img); osg::TexMat* texmat = new osg::TexMat; texmat->setScaleByTextureRectangleSize(true); // setup state osg::StateSet* state = geom->getOrCreateStateSet(); state->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); state->setTextureAttributeAndModes(0, texmat, osg::StateAttribute::ON); // turn off lighting state->setMode(GL_LIGHTING, osg::StateAttribute::OFF); // install 'update' callback osg::Geode* geode = new osg::Geode; geode->addDrawable(geom); geode->setUpdateCallback(new TexturePanCallback(texmat)); return geode; }
/** * Bounds are valid, ie. defined and inside usual bounds * (-180<=lon<=180, -90<=lat<=90). */ constexpr bool valid() const noexcept { return bottom_left().valid() && top_right().valid(); }
osg::Node* createSubloadWall(osg::BoundingBox& bb) { osg::Group* group = new osg::Group; // left hand side of bounding box. osg::Vec3 top_left(bb.xMin(),bb.yMax(),bb.zMax()); osg::Vec3 bottom_left(bb.xMin(),bb.yMax(),bb.zMin()); osg::Vec3 bottom_right(bb.xMax(),bb.yMax(),bb.zMin()); osg::Vec3 top_right(bb.xMax(),bb.yMax(),bb.zMax()); osg::Vec3 center((bb.xMax()+bb.xMin())*0.5f,bb.yMax(),(bb.zMin()+bb.zMax())*0.5f); float height = bb.zMax()-bb.zMin(); // create the geometry for the wall. osg::Geometry* geom = new osg::Geometry; osg::Vec3Array* vertices = new osg::Vec3Array(4); (*vertices)[0] = top_left; (*vertices)[1] = bottom_left; (*vertices)[2] = bottom_right; (*vertices)[3] = top_right; geom->setVertexArray(vertices); osg::Vec2Array* texcoords = new osg::Vec2Array(4); (*texcoords)[0].set(0.0f,1.0f); (*texcoords)[1].set(0.0f,0.0f); (*texcoords)[2].set(1.0f,0.0f); (*texcoords)[3].set(1.0f,1.0f); geom->setTexCoordArray(0,texcoords); osg::Vec3Array* normals = new osg::Vec3Array(1); (*normals)[0].set(0.0f,-1.0f,0.0f); geom->setNormalArray(normals); geom->setNormalBinding(osg::Geometry::BIND_OVERALL); osg::Vec4Array* colors = new osg::Vec4Array(1); (*colors)[0].set(1.0f,1.0f,1.0f,1.0f); geom->setColorArray(colors); geom->setColorBinding(osg::Geometry::BIND_OVERALL); geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4)); osg::Geode* geom_geode = new osg::Geode; geom_geode->addDrawable(geom); group->addChild(geom_geode); // set up the texture state. osg::Texture2D* texture = new osg::Texture2D; texture->setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state. texture->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR); texture->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR); osg::StateSet* stateset = geom->getOrCreateStateSet(); stateset->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON); // create the text label. osgText::Text* text = new osgText::Text; text->setDataVariance(osg::Object::DYNAMIC); text->setFont("fonts/arial.ttf"); text->setPosition(center); text->setCharacterSize(height*0.03f); text->setAlignment(osgText::Text::CENTER_CENTER); text->setAxisAlignment(osgText::Text::XZ_PLANE); osg::Geode* text_geode = new osg::Geode; text_geode->addDrawable(text); osg::StateSet* text_stateset = text_geode->getOrCreateStateSet(); text_stateset->setAttributeAndModes(new osg::PolygonOffset(-1.0f,-1.0f),osg::StateAttribute::ON); group->addChild(text_geode); // set the update callback to cycle through the various min and mag filter modes. group->setUpdateCallback(new ImageUpdateCallback(texture,text)); return group; }
osg::Node* createTestTexture2D(osg::Node* node, const std::string& filename) { osg::BoundingBox bb; osg::ref_ptr<osg::ComputeBoundsVisitor> boundsVistor = new osg::ComputeBoundsVisitor(); boundsVistor->reset(); node->accept(*boundsVistor.get()); bb = boundsVistor->getBoundingBox(); osg::Group* group = new osg::Group; // left hand side of bounding box. osg::Vec3 top_left(bb.xMin(), bb.yMin(), bb.zMax()); osg::Vec3 bottom_left(bb.xMin(), bb.yMin(), bb.zMin()); osg::Vec3 bottom_right(bb.xMin(), bb.yMax(), bb.zMin()); osg::Vec3 top_right(bb.xMin(), bb.yMax(), bb.zMax()); osg::Vec3 center(bb.xMin(), (bb.yMin() + bb.yMax())*0.5f, (bb.zMin() + bb.zMax())*0.5f); float height = bb.zMax() - bb.zMin(); // create the geometry for the wall. osg::Geometry* geom = new osg::Geometry; osg::Vec3Array* vertices = new osg::Vec3Array(4); (*vertices)[0] = top_left; (*vertices)[1] = bottom_left; (*vertices)[2] = bottom_right; (*vertices)[3] = top_right; geom->setVertexArray(vertices); osg::Vec2Array* texcoords = new osg::Vec2Array(4); (*texcoords)[0].set(0.0f, 1.0f); (*texcoords)[1].set(0.0f, 0.0f); (*texcoords)[2].set(1.0f, 0.0f); (*texcoords)[3].set(1.0f, 1.0f); geom->setTexCoordArray(0, texcoords); osg::Vec3Array* normals = new osg::Vec3Array(1); (*normals)[0].set(1.0f, 0.0f, 0.0f); geom->setNormalArray(normals, osg::Array::BIND_OVERALL); osg::Vec4Array* colors = new osg::Vec4Array(1); (*colors)[0].set(1.0f, 1.0f, 1.0f, 1.0f); geom->setColorArray(colors, osg::Array::BIND_OVERALL); geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, 4)); osg::Geode* geom_geode = new osg::Geode; geom_geode->addDrawable(geom); group->addChild(geom_geode); // set up the texture state. osg::Texture2D* texture = new osg::Texture2D; texture->setDataVariance(osg::Object::DYNAMIC); // protect from being optimized away as static state. osg::notify(osg::FATAL) << filename << std::endl; osg::Image* image = g_SystemContext._resourceLoader->getImageByFileName(filename); if (image == NULL) { osg::notify(osg::FATAL) << filename << "--load faile!!!" << std::endl; } else texture->setImage(0, image); osg::StateSet* stateset = geom->getOrCreateStateSet(); stateset->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON); osg::notify(osg::FATAL) << "33333" << std::endl; // create the text label. osgText::Text* text = new osgText::Text; text->setDataVariance(osg::Object::DYNAMIC); text->setFont("fonts/arial.ttf"); text->setPosition(center); text->setCharacterSize(height*0.03f); text->setAlignment(osgText::Text::CENTER_CENTER); text->setAxisAlignment(osgText::Text::YZ_PLANE); osg::Geode* text_geode = new osg::Geode; text_geode->addDrawable(text); osg::StateSet* text_stateset = text_geode->getOrCreateStateSet(); text_stateset->setAttributeAndModes(new osg::PolygonOffset(-1.0f, -1.0f), osg::StateAttribute::ON); group->addChild(text_geode); // set the update callback to cycle through the various min and mag filter modes. //group->setUpdateCallback(new FilterCallback(texture,text)); return group; }