JNIEXPORT void JNICALL Java_com_mousebird_maply_QuadImageOfflineLayer_geoBoundsForTileNative (JNIEnv *env, jobject obj, jint x, jint y, jint level, jobject llObj, jobject urObj) { try { QuadImageOfflineLayerAdapter *adapter = QILAdapterClassInfo::getClassInfo()->getObject(env,obj); Point2d *ll = Point2dClassInfo::getClassInfo()->getObject(env,llObj); Point2d *ur = Point2dClassInfo::getClassInfo()->getObject(env,urObj); if (!adapter || !ll || !ur) return; Mbr mbr = adapter->control->getQuadtree()->generateMbrForNode(WhirlyKit::Quadtree::Identifier(x,y,level)); GeoMbr geoMbr; CoordSystem *wkCoordSys = adapter->control->getCoordSys(); geoMbr.addGeoCoord(wkCoordSys->localToGeographic(Point3f(mbr.ll().x(),mbr.ll().y(),0.0))); geoMbr.addGeoCoord(wkCoordSys->localToGeographic(Point3f(mbr.ur().x(),mbr.ll().y(),0.0))); geoMbr.addGeoCoord(wkCoordSys->localToGeographic(Point3f(mbr.ur().x(),mbr.ur().y(),0.0))); geoMbr.addGeoCoord(wkCoordSys->localToGeographic(Point3f(mbr.ll().x(),mbr.ur().y(),0.0))); ll->x() = geoMbr.ll().x(); ll->y() = geoMbr.ll().y(); ur->x() = geoMbr.ur().x(); ur->y() = geoMbr.ur().y(); } catch (...) { __android_log_print(ANDROID_LOG_VERBOSE, "Maply", "Crash in QuadPagingLayer::geoBoundsForTileNative()"); } }
inline double crossProduct2d(const Point2d& p0, const Point2d& p1, const Point2d& p2) { double a1 = p1.x() - p0.x(); double a2 = p1.y() - p0.y(); double b1 = p2.x() - p0.x(); double b2 = p2.y() - p0.y(); return a1 * b2 - a2 * b1; }
void View::calcFrustumWidth(unsigned int frameWidth,unsigned int frameHeight,Point2d &ll,Point2d &ur,double & near,double &far) { ll.x() = -imagePlaneSize; ur.x() = imagePlaneSize; double ratio = ((double)frameHeight / (double)frameWidth); ll.y() = -imagePlaneSize * ratio; ur.y() = imagePlaneSize * ratio ; near = nearPlane; far = farPlane; }
void HeightMapLoaderConstant::Get(const Point2d & pos, const size_t sz, HeightMap & hm) const { if (pos.x() >= totalSize_ || pos.y() >= totalSize_) { throw std::runtime_error("Out of constant loader range"); } const float value = sz == 1 ? pointValue_ : patchValue_; const float increment = (pos.y() * totalSize_ + pos.x()) * increment_; HeightMap::Container v(sz * sz, value + increment); hm.Swap(v); }
//------------------------------------------------------------------------------ void Viewer::drawSceneForPicking() { //dessine le dashboard { treeD::ScreenSpaceProjection ssp( Vector2d(width(), height()) ); Camera cam = getCamera(); glDisable( GL_LIGHTING ); for( int i = 0; i < mMainDialog.getNumberOfParticuleSystems(); ++i ) { QColor c = idToColor( i ); glColor4ub( c.red(), c.green(), c.blue(), c.alpha() ); glPushMatrix(); Vector2i s = mSpriteCatalog.getSprite("crosshair").getFrameSize(); Point2d p = cam.worldToSreen( mMainDialog.getParticuleSystem(i).getPosition() ); glTranslated( p.x(), p.y(), 0.0); glScaled( s.x(), s.y(), 0 ); drawRectangle( Point2d(-0.5), Vector2d(1.0) ); glPopMatrix(); } // glPushMatrix(); // glTranslated( 10, 10, 0 ); // mSpriteCatalog.getSprite( "minus" ).draw(); // glPopMatrix(); glEnable( GL_LIGHTING ); } }
//------------------------------------------------------------------------------ void Viewer::draw() { for( int i = 0; i < mMainDialog.getNumberOfParticuleSystems(); ++i ) { mMainDialog.getParticuleSystem(i).draw(); } //dessine le dashboard { treeD::ScreenSpaceProjection ssp( Vector2d(width(), height()) ); Camera cam = getCamera(); glDisable( GL_LIGHTING ); glColor4ub( 255, 255, 255, 255 ); for( int i = 0; i < mMainDialog.getNumberOfParticuleSystems(); ++i ) { if( mMainDialog.mSelectionId == i ) { glColor4ub( 0, 255, 0, 255 ); } glPushMatrix(); Point2d p = cam.worldToSreen( mMainDialog.getParticuleSystem(i).getPosition() ); glTranslated( p.x(), p.y(), 0.0); mSpriteCatalog.getSprite( "crosshair" ).draw(); glPopMatrix(); } glColor4ub( 255, 255, 255, 255 ); glPushMatrix(); glTranslated( 10, 10, 0 ); mSpriteCatalog.getSprite( "minus" ).draw(); glPopMatrix(); glEnable( GL_LIGHTING ); } }
void File::write_point(const Point2d &p, FILE *pFile) { double x = p.x(); double y = p.y(); fwrite(&x, sizeof(double), 1, pFile); fwrite(&y, sizeof(double), 1, pFile); }
ModelData WindowRenderer::RenderRectangleWindow(const Size2d & size, const TextureId id) { using namespace boost::assign; ModelData md; md.textureId = id; md.type = ModelData::Mode::Triangle; md.points.reserve(4); md.indexes.reserve(6); md.textures.reserve(4); const Point2d p = Point2d::Cast(size); md.points += Point3d(0.0f, 0.0f, 0.0f), Point3d(0.0f, p.y(), 0.0f), Point3d(p.x(), p.y(), 0.0f), Point3d(p.x(), 0.0f, 0.0f); md.indexes += 0, 2, 1, 0, 3, 2; md.textures += Point2d(0, 1), Point2d(0, 0), Point2d(1, 0), Point2d(1, 1); return md; }
bool Circle::is_inside(Point2d const& p) const { /*override*/ if(sqrt(pow(p.x()-m_mid_.x(),2)+pow(p.y()-m_mid_.y(),2))<=m_radius_) { return true; } else { return false; } }
Point2d ScreenSizeManipulator::ConvertToOgl(const Point2d & p) const { assert(screenSize_ != Size2d()); const float x = (2 * p.x() - screenSize_.x()) / screenSize_.x(); const float y = (2 * p.y() - screenSize_.y()) / screenSize_.y(); return Point2d(x, y); }
// Note: we do not use glColor because glColor is clamped to [0,1] // and converted to an int ! void GimRasterizer::vertex(const Point2d& uv, const Point3d& xyz) { float w = static_cast<float>(target_->width()) ; // float s = (float(w) / (float(w) + 1.0)) ; float s = ((float(w) - 0.99) / float(w)) ; glTexCoord3d(xyz.x(), xyz.y(), xyz.z()) ; // TODO: setup viewing matrix instead ... float u = s * 2.0 * (uv.x() - 0.5) ; float v = s * 2.0 * (uv.y() - 0.5) ; glVertex2d(u,v) ; }
HeightMap::Value HeightMapExtended::At(const Point2d & p) const { if (p.x() >= extendedSz_ || p.y() >= extendedSz_) { const std::string err = (boost::format("Requested value out of range. Sz = %f x = %f y = %f") % extendedSz_ % p.x() % p.y()).str(); throw std::range_error(err); } if (extendedSz_ == GetSize()) { return HeightMap::At(p); } const float factor = static_cast<float>(extendedSz_) / GetSize(); const float xScaled = p.x() / factor; const float yScaled = p.y() / factor; const float xUp = ::ceil(xScaled); const float xDown = ::floor(xScaled); const float yUp = ::ceil(yScaled); const float yDown = ::floor(yScaled); const Value v1U = HeightMap::At(Point2d(xUp, yDown)); const Value v2U = HeightMap::At(Point2d(xUp, yUp)); const Value v1 = Interpolate(v1U, v2U, yDown, yUp, yScaled); const Value v1D = HeightMap::At(Point2d(xDown, yDown)); const Value v2D = HeightMap::At(Point2d(xDown, yUp)); const Value v2 = Interpolate(v1D, v2D, yDown, yUp, yScaled); const Value v = Interpolate(v1, v2, xDown, xUp, xScaled); return v; }
void TerrainRangeArc::ProcessRange(const Point2d & vec, const Angle a, const int y, const AxisPairType & pt, const Point2d & c) { const IntersectionType & r = GetIntersection(vec, a, y, pt); for (const AxisPairType & apt : r) { const TerrainRange::Range range( utils::FloatFloorToInt(y + c.y()), utils::FloatFloorToInt(apt.first + c.x()), utils::FloatCeilToInt(apt.second + c.x()) ); PutRange(range); } }
void analytical_derivative2(const Camera& camera_, const Point3d& point_, const Point2d& obs, TooN::Matrix<2,12,double>& j) { typedef T Scalar; const std::array<T,9> c = { T(camera_[0],0),T(camera_[1],1),T(camera_[2],2), T(camera_[3],3),T(camera_[4],4),T(camera_[5],5), T(camera_[6],6),T(camera_[7],7),T(camera_[8],8)}; const std::array<T,3> pt = {T(point_[0],9),T(point_[1],10),T(point_[2],11)}; std::array<T,2> p; const T theta2 = c[0]*c[0] + c[1]*c[1] + c[2]*c[2]; if (theta2 > Scalar(std::numeric_limits<double>::epsilon())) { const T theta = sqrt(theta2), costheta = cos(theta), sintheta = sin(theta), theta_inverse = 1.0 / theta, w[3] = { c[0] * theta_inverse, c[1] * theta_inverse, c[2] * theta_inverse }, tmp = (w[0] * pt[0] + w[1] * pt[1] + w[2] * pt[2]) * (Scalar(1.0) - costheta), p2 = pt[2] * costheta + (w[0] * pt[1] - w[1] * pt[0]) * sintheta + w[2] * tmp + c[5]; p[0] = - (pt[0] * costheta + (w[1] * pt[2] - w[2] * pt[1]) * sintheta + w[0] * tmp + c[3]) / p2; p[1] = - (pt[1] * costheta + (w[2] * pt[0] - w[0] * pt[2]) * sintheta + w[1] * tmp + c[4]) / p2; } else { const T p2 = pt[2] + c[0] * pt[1] - c[1] * pt[0] + c[5]; p[0] = - (pt[0] + c[1] * pt[2] - c[2] * pt[1] + c[3]) / p2; p[1] = - (pt[1] + c[2] * pt[0] - c[0] * pt[2] + c[4]) / p2; } const T r2 = p[0]*p[0] + p[1]*p[1], fx = c[6] * (Scalar(1.0) + r2 * (c[7] + c[8] * r2)); const typename T::Array jacobx = (fx * p[0] - Scalar(obs.x())).infinite(), jacoby = (fx * p[1] - Scalar(obs.y())).infinite(); for(int i = 0 ; i < 12 ; ++i) { j(0,i) = jacobx[i]; j(1,i) = jacoby[i]; } }
JNIEXPORT void JNICALL Java_com_mousebird_maply_Point2d_setValue (JNIEnv *env, jobject obj, jdouble x, jdouble y) { try { Point2dClassInfo *classInfo = Point2dClassInfo::getClassInfo(); Point2d *pt = classInfo->getObject(env,obj); if (!pt) return; pt->x() = x; pt->y() = y; } catch (...) { __android_log_print(ANDROID_LOG_VERBOSE, "Maply", "Crash in Point2d::setValue()"); } }
JNIEXPORT jdouble JNICALL Java_com_mousebird_maply_Point2d_getX (JNIEnv *env, jobject obj) { try { Point2dClassInfo *classInfo = Point2dClassInfo::getClassInfo(); Point2d *pt = classInfo->getObject(env,obj); if (!pt) return 0.0; return pt->x(); } catch (...) { __android_log_print(ANDROID_LOG_VERBOSE, "Maply", "Crash in Point2d::getX()"); } return 0.0; }
JNIEXPORT void JNICALL Java_com_mousebird_maply_Billboard_addPoly (JNIEnv *env, jobject obj, jobject pointsArray, jobject texCoordsArray, jfloatArray colorArray, jobject vertexArray, jlong texID) { try { BillboardClassInfo *classInfo = BillboardClassInfo::getClassInfo(); Billboard *inst = classInfo->getObject(env, obj); if (!inst) return; jclass iterClass = env->FindClass("java/util/Iterator"); jmethodID hasNext = env->GetMethodID(iterClass,"hasNext","()Z"); jmethodID next = env->GetMethodID(iterClass,"next","()Ljava/lang/Object;"); Point2dClassInfo *ptClassInfo = Point2dClassInfo::getClassInfo(); //Create new SingleBillboardPoly SingleBillboardPoly *poly = new SingleBillboardPoly(); //Add Points jclass listClass = env->GetObjectClass(pointsArray); jmethodID literMethod = env->GetMethodID(listClass,"iterator","()Ljava/util/Iterator;"); jobject liter = env->CallObjectMethod(pointsArray,literMethod); while (env->CallBooleanMethod(liter, hasNext)) { jobject javaVecObj = env->CallObjectMethod(liter, next); Point2d *newPt = ptClassInfo->getObject(env,javaVecObj); poly->pts.push_back(*newPt); env->DeleteLocalRef(javaVecObj); } env->DeleteLocalRef(liter); //Add texCoord listClass = env->GetObjectClass(texCoordsArray); literMethod = env->GetMethodID(listClass,"iterator","()Ljava/util/Iterator;"); liter = env->CallObjectMethod(texCoordsArray,literMethod); while (env->CallBooleanMethod(liter, hasNext)) { jobject javaVecObj = env->CallObjectMethod(liter, next); Point2d *newPt = ptClassInfo->getObject(env,javaVecObj); TexCoord newTexCoord(newPt->x(), newPt->y()); poly->texCoords.push_back(newTexCoord); env->DeleteLocalRef(javaVecObj); } env->DeleteLocalRef(liter); //Add Vertex Attribute listClass = env->GetObjectClass(vertexArray); literMethod = env->GetMethodID(listClass,"iterator","()Ljava/util/Iterator;"); liter = env->CallObjectMethod(vertexArray,literMethod); SingleVertexAttributeClassInfo *vertexClassInfo = SingleVertexAttributeClassInfo::getClassInfo(); while (env->CallBooleanMethod(liter, hasNext)) { jobject javaVecObj = env->CallObjectMethod(liter, next); SingleVertexAttribute *newVertex = vertexClassInfo->getObject(env,javaVecObj); poly->vertexAttrs.insert(*newVertex); env->DeleteLocalRef(javaVecObj); } env->DeleteLocalRef(liter); //Delete objects env->DeleteLocalRef(iterClass); env->DeleteLocalRef(listClass); //Color jsize len = 0; jfloat *colors; if (colorArray != NULL) { colors = env->GetFloatArrayElements(colorArray, 0); len = env->GetArrayLength(colorArray); } RGBAColor color; if (len < 4) color = RGBAColor(0,0,0,0); else { jfloat *colors = env->GetFloatArrayElements(colorArray, 0); color = RGBAColor(colors[0]*255.0,colors[1]*255.0,colors[2]*255.0,colors[3]*255.0); } poly->color = color; poly->texId = texID; //Add Poly inst->polys.push_back(*poly); } catch (...) { __android_log_print(ANDROID_LOG_VERBOSE, "Maply", "Crash in Billboard::addPoly()"); } }
void GimRasterizer::set_pixel(const Point2d& uv, const Point3d& p) { int x = int(uv.x() * (target_->width() - 1)) ; int y = int(uv.y() * (target_->height() - 1)) ; set_pixel(x,y,p) ; }
Point2d add_noise(Point2d in, double sigma) { Point2d out (in.x()+sigma*snrv(), in.y()+sigma*snrv()); return out; }
/// Bounding box used to calculate quad tree nodes. In local coordinate system. virtual Mbr getTotalExtents() { Mbr mbr(Point2f(ll.x(),ll.y()),Point2f(ur.x(),ur.y())); return mbr; }
void Point2d::rotate(Point2d const& Zentrum, double const r){ //Rotation um ein beliebiges Zentrum double x = x_; double y = y_; x_ = Zentrum.x() + (x-Zentrum.x()) * cos(-r) - (y-Zentrum.y()) * sin(-r); y_ = Zentrum.y() + (x-Zentrum.x()) * sin(-r) + (y-Zentrum.y()) * cos(-r); }