WhirlyGlobe
1.1
A 3D interactive globe toolkit for ios
|
00001 /* 00002 * WhirlyVector.h 00003 * WhirlyGlobeLib 00004 * 00005 * Created by Steve Gifford on 1/18/11. 00006 * Copyright 2011 mousebird consulting 00007 * 00008 * Licensed under the Apache License, Version 2.0 (the "License"); 00009 * you may not use this file except in compliance with the License. 00010 * You may obtain a copy of the License at 00011 * http://www.apache.org/licenses/LICENSE-2.0 00012 * 00013 * Unless required by applicable law or agreed to in writing, software 00014 * distributed under the License is distributed on an "AS IS" BASIS, 00015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00016 * See the License for the specific language governing permissions and 00017 * limitations under the License. 00018 * 00019 */ 00020 00021 // Note: This works around a problem in compilation for the iphone 00022 #define EIGEN_DONT_VECTORIZE 1 00023 // #define EIGEN_DISABLE_UNALIGNED_ARRAY_ASSERT 1 00024 00025 #import <Eigen/Eigen> 00026 #import <vector> 00027 00028 typedef Eigen::Vector3f Point3f; 00029 typedef Eigen::Vector2f Point2f; 00030 00031 namespace WhirlyGlobe 00032 { 00033 00035 class TexCoord : public Eigen::Vector2f 00036 { 00037 public: 00038 TexCoord() { } 00039 TexCoord(float u,float v) : Eigen::Vector2f(u,v) { } 00040 float u() const { return x(); } 00041 float &u() { return x(); } 00042 float v() const { return y(); } 00043 float &v() { return y(); } 00044 }; 00045 00047 class GeoCoord : public Eigen::Vector2f 00048 { 00049 public: 00050 GeoCoord() { } 00051 GeoCoord(float lon,float lat) : Eigen::Vector2f(lon,lat) { } 00053 float lon() const { return x(); } 00054 float &lon() { return x(); } 00056 float lat() const { return y(); } 00057 float &lat() { return y(); } 00058 GeoCoord operator + (const GeoCoord &that) { return GeoCoord(x()+that.x(),y()+that.y()); } 00059 00062 static GeoCoord CoordFromDegrees(float lon,float lat); 00063 }; 00064 00066 class RGBAColor 00067 { 00068 public: 00069 RGBAColor() { } 00070 RGBAColor(unsigned char r,unsigned char g,unsigned char b,unsigned char a) : r(r), g(g), b(b), a(a) { } 00071 RGBAColor(unsigned char r,unsigned char g,unsigned char b) : r(r), g(g), b(b), a(255) { } 00072 00073 bool operator == (RGBAColor &that) const { return (r == that.r && g == that.g && b == that.b && a == that.a); } 00074 00075 unsigned char r,g,b,a; 00076 }; 00077 00080 class Mbr 00081 { 00082 public: 00084 Mbr() : pt_ll(0.f,0.f), pt_ur(-1.f,-1.f) { } 00086 Mbr(Point2f ll,Point2f ur) : pt_ll(ll), pt_ur(ur) { } 00088 Mbr(const std::vector<Point2f> &pts); 00089 00091 const Point2f &ll() const { return pt_ll; } 00092 Point2f &ll() { return pt_ll; } 00094 const Point2f &ur() const { return pt_ur; } 00095 Point2f &ur() { return pt_ur; } 00096 00098 bool valid() const { return pt_ur.x() >= pt_ll.x(); } 00099 00101 float area() const; 00102 00104 void addPoint(Point2f pt); 00105 00107 bool overlaps(const Mbr &that) const; 00108 00110 bool inside(Point2f pt) const { return ((pt_ll.x() < pt.x()) && (pt_ll.y() < pt.y()) && (pt.x() < pt_ur.x()) && (pt.y() < pt_ur.y())); } 00111 00112 protected: 00113 Point2f pt_ll,pt_ur; 00114 }; 00115 00119 class GeoMbr 00120 { 00121 public: 00123 GeoMbr() : pt_ll(-1000,-1000), pt_ur(-1000,-1000) { } 00125 GeoMbr(GeoCoord ll,GeoCoord ur) : pt_ll(ll), pt_ur(ur) { } 00127 GeoMbr(const std::vector<GeoCoord> &coords); 00129 GeoMbr(const std::vector<Point2f> &pts); 00130 00132 void reset() { pt_ll = GeoCoord(-1000,-1000); pt_ur = GeoCoord(-1000,-1000); } 00133 00135 const GeoCoord &ll() const { return pt_ll; } 00136 GeoCoord &ll() { return pt_ll; } 00138 const GeoCoord &ur() const { return pt_ur; } 00139 GeoCoord &ur() { return pt_ur; } 00141 GeoCoord lr() const { return GeoCoord(pt_ur.x(),pt_ll.y()); } 00143 GeoCoord ul() const { return GeoCoord(pt_ll.x(),pt_ur.y()); } 00144 00146 GeoCoord mid() const { return GeoCoord((pt_ll.x()+pt_ur.x())/2,(pt_ll.y()+pt_ur.y())/2); } 00147 00149 bool valid() { return (pt_ll.x() != -1000); } 00150 00153 float area() const; 00154 00156 void addGeoCoord(GeoCoord coord); 00157 00159 void addGeoCoords(const std::vector<GeoCoord> &coords); 00161 void addGeoCoords(const std::vector<Point2f> &coords); 00162 00165 bool overlaps(const GeoMbr &that) const; 00166 00168 bool inside(GeoCoord coord) const; 00169 00170 protected: 00172 void splitIntoMbrs(std::vector<Mbr> &mbrs) const; 00173 00174 GeoCoord pt_ll,pt_ur; 00175 }; 00176 00179 Eigen::Quaternionf QuatFromTwoVectors(const Point3f &a,const Point3f &b); 00180 00181 }