58 changed files with 1059 additions and 726 deletions
@ -1,323 +1,330 @@ |
|||||
#include "QuadSurface.h" |
#include "QuadSurface.h" |
||||
|
|
||||
namespace ofx { |
namespace ofx { |
||||
namespace piMapper { |
namespace piMapper { |
||||
|
|
||||
QuadSurface::QuadSurface(){ |
QuadSurface::QuadSurface(){ |
||||
_perspectiveWarping = false; |
_perspectiveWarping = false; |
||||
setup(); |
setup(); |
||||
} |
} |
||||
|
|
||||
QuadSurface::~QuadSurface(){ |
QuadSurface::~QuadSurface(){ |
||||
cout << "QuadSurface destructor." << endl; |
cout << "QuadSurface destructor." << endl; |
||||
} |
} |
||||
|
|
||||
void QuadSurface::setup(){ |
void QuadSurface::setup(){ |
||||
// Create 4 points for the 2 triangles
|
// Create 4 points for the 2 triangles
|
||||
ofVec2f p1 = ofVec2f(0, 0); |
Vec2 p1 = Vec2(0, 0); |
||||
ofVec2f p2 = ofVec2f(0, ofGetHeight()); |
Vec2 p2 = Vec2(0, ofGetHeight()); |
||||
ofVec2f p3 = ofVec2f(ofGetWidth(), ofGetHeight()); |
Vec2 p3 = Vec2(ofGetWidth(), ofGetHeight()); |
||||
ofVec2f p4 = ofVec2f(ofGetWidth(), 0); |
Vec2 p4 = Vec2(ofGetWidth(), 0); |
||||
|
|
||||
// Create 4 point for the texture coordinates
|
// Create 4 point for the texture coordinates
|
||||
ofVec2f t1 = ofVec2f(ofVec2f(0.0f, 0.0f)); |
Vec2 t1 = Vec2(Vec2(0.0f, 0.0f)); |
||||
ofVec2f t2 = ofVec2f(ofVec2f(1.0f, 0.0f)); |
Vec2 t2 = Vec2(Vec2(1.0f, 0.0f)); |
||||
ofVec2f t3 = ofVec2f(ofVec2f(1.0f, 1.0f)); |
Vec2 t3 = Vec2(Vec2(1.0f, 1.0f)); |
||||
ofVec2f t4 = ofVec2f(ofVec2f(0.0f, 1.0f)); |
Vec2 t4 = Vec2(Vec2(0.0f, 1.0f)); |
||||
|
|
||||
setup(p1, p2, p3, p4, t1, t2, t3, t4, source); |
setup(p1, p2, p3, p4, t1, t2, t3, t4, source); |
||||
} |
} |
||||
|
|
||||
void QuadSurface::setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f p4, |
void QuadSurface::setup(Vec2 p1, Vec2 p2, Vec2 p3, Vec2 p4, |
||||
ofVec2f t1, ofVec2f t2, ofVec2f t3, ofVec2f t4, |
Vec2 t1, Vec2 t2, Vec2 t3, Vec2 t4, |
||||
BaseSource * newSource){ |
BaseSource * newSource){ |
||||
// Assign texture
|
// Assign texture
|
||||
source = newSource; |
source = newSource; |
||||
|
|
||||
// Clear mesh
|
// Clear mesh
|
||||
mesh.clear(); |
mesh.clear(); |
||||
|
|
||||
// Create a surface with the points
|
// Create a surface with the points
|
||||
mesh.addVertex(p1); |
mesh.addVertex(p1.toOf()); |
||||
mesh.addVertex(p2); |
mesh.addVertex(p2.toOf()); |
||||
mesh.addVertex(p3); |
mesh.addVertex(p3.toOf()); |
||||
mesh.addVertex(p4); |
mesh.addVertex(p4.toOf()); |
||||
|
|
||||
// Add 2 triangles
|
// Add 2 triangles
|
||||
mesh.addTriangle(0, 2, 3); |
mesh.addTriangle(0, 2, 3); |
||||
mesh.addTriangle(0, 1, 2); |
mesh.addTriangle(0, 1, 2); |
||||
|
|
||||
// Add texture coordinates
|
// Add texture coordinates
|
||||
mesh.addTexCoord(t1); |
mesh.addTexCoord(t1.toOf()); |
||||
mesh.addTexCoord(t2); |
mesh.addTexCoord(t2.toOf()); |
||||
mesh.addTexCoord(t3); |
mesh.addTexCoord(t3.toOf()); |
||||
mesh.addTexCoord(t4); |
mesh.addTexCoord(t4.toOf()); |
||||
} |
} |
||||
|
|
||||
void QuadSurface::draw(){ |
void QuadSurface::draw(){ |
||||
if(source->getTexture() == 0){ |
if(source->getTexture() == 0){ |
||||
return; |
return; |
||||
} |
} |
||||
|
|
||||
if(!source->getTexture()->isAllocated()){ |
if(!source->getTexture()->isAllocated()){ |
||||
return; |
return; |
||||
} |
} |
||||
|
|
||||
if(_perspectiveWarping){ |
if(_perspectiveWarping){ |
||||
if(mesh.haveVertsChanged() || mesh.haveTexCoordsChanged()){ |
if(mesh.haveVertsChanged() || mesh.haveTexCoordsChanged()){ |
||||
calculateHomography(); |
calculateHomography(); |
||||
} |
} |
||||
|
|
||||
ofRectangle box = getMeshBoundingBox(); |
ofRectangle box = getMeshBoundingBox(); |
||||
ofMesh m = mesh; |
ofMesh m = mesh; |
||||
|
|
||||
m.setVertex(0, ofVec3f(0, 0, 0)); |
m.setVertex(0, ofVec3f(0, 0, 0)); |
||||
m.setVertex(1, ofVec3f(box.width, 0, 0)); |
m.setVertex(1, ofVec3f(box.width, 0, 0)); |
||||
m.setVertex(2, ofVec3f(box.width, box.height, 0)); |
m.setVertex(2, ofVec3f(box.width, box.height, 0)); |
||||
m.setVertex(3, ofVec3f(0, box.height, 0)); |
m.setVertex(3, ofVec3f(0, box.height, 0)); |
||||
|
|
||||
ofPushMatrix(); |
ofPushMatrix(); |
||||
if(true){ |
if(true){ |
||||
bool normalizedTexCoords = ofGetUsingNormalizedTexCoords(); |
bool normalizedTexCoords = ofGetUsingNormalizedTexCoords(); |
||||
ofEnableNormalizedTexCoords(); |
ofEnableNormalizedTexCoords(); |
||||
|
|
||||
glMultMatrixf(_matrix); |
glMultMatrixf(_matrix); |
||||
source->getTexture()->bind(); |
source->getTexture()->bind(); |
||||
m.draw(); |
m.draw(); |
||||
source->getTexture()->unbind(); |
source->getTexture()->unbind(); |
||||
|
|
||||
if(!normalizedTexCoords){ |
if(!normalizedTexCoords){ |
||||
ofDisableNormalizedTexCoords(); |
ofDisableNormalizedTexCoords(); |
||||
} |
} |
||||
} |
} |
||||
ofPopMatrix(); |
ofPopMatrix(); |
||||
}else{ |
}else{ |
||||
bool normalizedTexCoords = ofGetUsingNormalizedTexCoords(); |
bool normalizedTexCoords = ofGetUsingNormalizedTexCoords(); |
||||
ofEnableNormalizedTexCoords(); |
ofEnableNormalizedTexCoords(); |
||||
|
|
||||
ofPushStyle(); |
ofPushStyle(); |
||||
ofSetColor(255, 255, 255); |
ofSetColor(255, 255, 255); |
||||
|
|
||||
source->getTexture()->bind(); |
source->getTexture()->bind(); |
||||
mesh.draw(); |
mesh.draw(); |
||||
source->getTexture()->unbind(); |
source->getTexture()->unbind(); |
||||
|
|
||||
ofPopStyle(); |
ofPopStyle(); |
||||
|
|
||||
if(!normalizedTexCoords){ |
if(!normalizedTexCoords){ |
||||
ofDisableNormalizedTexCoords(); |
ofDisableNormalizedTexCoords(); |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
void QuadSurface::setVertex(int index, ofVec2f p){ |
void QuadSurface::setVertex(int index, Vec2 p){ |
||||
if(index > 3){ |
if(index > 3){ |
||||
ofLog() << "Vertex with this index does not exist: " << index << endl; |
ofLog() << "Vertex with this index does not exist: " << index << endl; |
||||
return; |
return; |
||||
} |
} |
||||
|
|
||||
mesh.setVertex(index, p); |
mesh.setVertex(index, p.toOf()); |
||||
ofVec3f v = mesh.getVertex(index); |
ofVec3f v = mesh.getVertex(index); |
||||
ofNotifyEvent(vertexChangedEvent, index, this); |
ofNotifyEvent(vertexChangedEvent, index, this); |
||||
} |
} |
||||
|
|
||||
void QuadSurface::setVertices(vector<ofVec2f> v){ |
void QuadSurface::setVertices(vector<Vec2> v){ |
||||
if(v.size() != 4){ |
if(v.size() != 4){ |
||||
throw runtime_error("Wrong number of vertices"); |
throw runtime_error("Wrong number of vertices"); |
||||
} |
} |
||||
|
|
||||
for(int i = 0; i < 4; ++i){ |
for(int i = 0; i < 4; ++i){ |
||||
mesh.setVertex(i, v[i]); |
mesh.setVertex(i, v[i].toOf()); |
||||
} |
} |
||||
|
|
||||
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); |
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); |
||||
} |
} |
||||
|
|
||||
void QuadSurface::setVertices(vector<ofVec3f> v){ |
void QuadSurface::setVertices(vector<ofVec3f> v){ |
||||
if(v.size() != 4){ |
if(v.size() != 4){ |
||||
throw runtime_error("Wrong number of vertices"); |
throw runtime_error("Wrong number of vertices"); |
||||
} |
} |
||||
|
|
||||
for(int i = 0; i < 4; ++i){ |
for(int i = 0; i < 4; ++i){ |
||||
mesh.setVertex(i, v[i]); |
mesh.setVertex(i, v[i]); |
||||
} |
} |
||||
|
|
||||
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); |
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); |
||||
} |
} |
||||
|
|
||||
void QuadSurface::setTexCoord(int index, ofVec2f t){ |
void QuadSurface::setTexCoord(int index, Vec2 t){ |
||||
if(index > 3){ |
if(index > 3){ |
||||
ofLog() << "Texture coordinate with this index does not exist: " << index |
ofLog() << "Texture coordinate with this index does not exist: " << index |
||||
<< endl; |
<< endl; |
||||
return; |
return; |
||||
} |
} |
||||
|
|
||||
mesh.setTexCoord(index, t); |
mesh.setTexCoord(index, t.toOf()); |
||||
} |
} |
||||
|
|
||||
void QuadSurface::setTexCoords(vector<ofVec2f> t){ |
void QuadSurface::setTexCoords(vector<Vec2> t){ |
||||
if(t.size() != 4){ |
if(t.size() != 4){ |
||||
throw runtime_error("Wrong number of vertices"); |
throw runtime_error("Wrong number of vertices"); |
||||
} |
} |
||||
for(int i = 0; i < 4; ++i){ |
for(int i = 0; i < 4; ++i){ |
||||
mesh.setTexCoord(i, t[i]); |
mesh.setTexCoord(i, t[i].toOf()); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
void QuadSurface::moveBy(ofVec2f v){ |
void QuadSurface::moveBy(Vec2 v){ |
||||
vector <ofVec3f> & vertices = getVertices(); |
vector <ofVec3f> & vertices = getVertices(); |
||||
|
|
||||
for(int i = 0; i < vertices.size(); i++){ |
for(int i = 0; i < vertices.size(); i++){ |
||||
vertices[i] += v; |
vertices[i] += v.toOf(); |
||||
} |
} |
||||
|
|
||||
setMoved(true); |
setMoved(true); |
||||
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); |
ofNotifyEvent(verticesChangedEvent, mesh.getVertices(), this); |
||||
} |
} |
||||
|
|
||||
int QuadSurface::getType(){ |
int QuadSurface::getType(){ |
||||
return SurfaceType::QUAD_SURFACE; |
return SurfaceType::QUAD_SURFACE; |
||||
} |
} |
||||
|
|
||||
bool QuadSurface::hitTest(ofVec2f p){ |
bool QuadSurface::hitTest(Vec2 p){ |
||||
// Construct ofPolyline from vertices
|
// Construct ofPolyline from vertices
|
||||
ofPolyline line = getHitArea(); |
ofPolyline line = getHitArea(); |
||||
|
|
||||
if(line.inside(p.x, p.y)){ |
if(line.inside(p.x, p.y)){ |
||||
return true; |
return true; |
||||
}else{ |
}else{ |
||||
return false; |
return false; |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
ofVec2f QuadSurface::getVertex(int index){ |
Vec2 QuadSurface::getVertex(int index){ |
||||
if(index > 3){ |
if(index > 3){ |
||||
ofLog() << "Vertex with this index does not exist: " << index << endl; |
ofLog() << "Vertex with this index does not exist: " << index << endl; |
||||
throw runtime_error("Vertex index out of bounds."); |
throw runtime_error("Vertex index out of bounds."); |
||||
} |
} |
||||
|
|
||||
ofVec3f vert = mesh.getVertex(index); |
ofVec3f vert = mesh.getVertex(index); |
||||
return ofVec2f(vert.x, vert.y); |
return Vec2(vert.x, vert.y); |
||||
} |
} |
||||
|
|
||||
ofVec2f QuadSurface::getTexCoord(int index){ |
Vec2 QuadSurface::getTexCoord(int index){ |
||||
if(index > 3){ |
if(index > 3){ |
||||
throw runtime_error("Texture coordinate index out of bounds."); |
throw runtime_error("Texture coordinate index out of bounds."); |
||||
} |
} |
||||
|
|
||||
return mesh.getTexCoord(index); |
return Vec2( |
||||
} |
mesh.getTexCoord(index).x, |
||||
|
mesh.getTexCoord(index).y); |
||||
ofPolyline QuadSurface::getHitArea(){ |
} |
||||
ofPolyline line; |
|
||||
line.addVertex(ofPoint(mesh.getVertex(0).x, mesh.getVertex(0).y)); |
ofPolyline QuadSurface::getHitArea(){ |
||||
line.addVertex(ofPoint(mesh.getVertex(1).x, mesh.getVertex(1).y)); |
ofPolyline line; |
||||
line.addVertex(ofPoint(mesh.getVertex(2).x, mesh.getVertex(2).y)); |
line.addVertex(ofPoint(mesh.getVertex(0).x, mesh.getVertex(0).y)); |
||||
line.addVertex(ofPoint(mesh.getVertex(3).x, mesh.getVertex(3).y)); |
line.addVertex(ofPoint(mesh.getVertex(1).x, mesh.getVertex(1).y)); |
||||
line.close(); |
line.addVertex(ofPoint(mesh.getVertex(2).x, mesh.getVertex(2).y)); |
||||
|
line.addVertex(ofPoint(mesh.getVertex(3).x, mesh.getVertex(3).y)); |
||||
return line; |
line.close(); |
||||
} |
|
||||
|
return line; |
||||
ofPolyline QuadSurface::getTextureHitArea(){ |
} |
||||
ofPolyline line; |
|
||||
vector <ofVec2f> & texCoords = mesh.getTexCoords(); |
ofPolyline QuadSurface::getTextureHitArea(){ |
||||
ofVec2f textureSize = ofVec2f(source->getTexture()->getWidth(), source->getTexture()->getHeight()); |
ofPolyline line; |
||||
for(int i = 0; i < texCoords.size(); i++){ |
Vec2 textureSize = |
||||
line.addVertex(ofPoint(texCoords[i] * textureSize)); |
Vec2(source->getTexture()->getWidth(), |
||||
} |
source->getTexture()->getHeight()); |
||||
line.close(); |
for(int i = 0; i < mesh.getTexCoords().size(); i++){ |
||||
|
line.addVertex(ofPoint(mesh.getTexCoords()[i] * textureSize.toOf())); |
||||
return line; |
} |
||||
} |
line.close(); |
||||
|
|
||||
vector <ofVec3f> & QuadSurface::getVertices(){ |
return line; |
||||
// return only joint vertices
|
} |
||||
return mesh.getVertices(); |
|
||||
} |
vector <ofVec3f> & QuadSurface::getVertices(){ |
||||
|
// return only joint vertices
|
||||
vector <ofVec2f> & QuadSurface::getTexCoords(){ |
return mesh.getVertices(); |
||||
return mesh.getTexCoords(); |
} |
||||
} |
|
||||
|
vector <Vec2> & QuadSurface::getTexCoords(){ |
||||
void QuadSurface::calculateHomography(){ |
_texCoords.clear(); |
||||
float src[4][2]; |
for(auto tc : mesh.getTexCoords()){ |
||||
float dst[4][2]; |
_texCoords.push_back(tc); |
||||
|
} |
||||
ofRectangle box = getMeshBoundingBox(); |
return _texCoords; |
||||
|
} |
||||
src[0][0] = 0; |
|
||||
src[0][1] = 0; |
void QuadSurface::calculateHomography(){ |
||||
src[1][0] = box.width; |
float src[4][2]; |
||||
src[1][1] = 0; |
float dst[4][2]; |
||||
src[2][0] = box.width; |
|
||||
src[2][1] = box.height; |
ofRectangle box = getMeshBoundingBox(); |
||||
src[3][0] = 0; |
|
||||
src[3][1] = box.height; |
src[0][0] = 0; |
||||
|
src[0][1] = 0; |
||||
ofVec3f p0 = mesh.getVertex(0); |
src[1][0] = box.width; |
||||
ofVec3f p1 = mesh.getVertex(1); |
src[1][1] = 0; |
||||
ofVec3f p2 = mesh.getVertex(2); |
src[2][0] = box.width; |
||||
ofVec3f p3 = mesh.getVertex(3); |
src[2][1] = box.height; |
||||
|
src[3][0] = 0; |
||||
dst[0][0] = p0.x; |
src[3][1] = box.height; |
||||
dst[0][1] = p0.y; |
|
||||
dst[1][0] = p1.x; |
ofVec3f p0 = mesh.getVertex(0); |
||||
dst[1][1] = p1.y; |
ofVec3f p1 = mesh.getVertex(1); |
||||
dst[2][0] = p2.x; |
ofVec3f p2 = mesh.getVertex(2); |
||||
dst[2][1] = p2.y; |
ofVec3f p3 = mesh.getVertex(3); |
||||
dst[3][0] = p3.x; |
|
||||
dst[3][1] = p3.y; |
dst[0][0] = p0.x; |
||||
|
dst[0][1] = p0.y; |
||||
HomographyHelper::findHomography(src, dst, _matrix); |
dst[1][0] = p1.x; |
||||
} |
dst[1][1] = p1.y; |
||||
|
dst[2][0] = p2.x; |
||||
void QuadSurface::setPerspectiveWarping(bool b){ |
dst[2][1] = p2.y; |
||||
_perspectiveWarping = b; |
dst[3][0] = p3.x; |
||||
} |
dst[3][1] = p3.y; |
||||
|
|
||||
bool QuadSurface::getPerspectiveWarping(){ |
HomographyHelper::findHomography(src, dst, _matrix); |
||||
return _perspectiveWarping; |
} |
||||
} |
|
||||
|
void QuadSurface::setPerspectiveWarping(bool b){ |
||||
ofRectangle QuadSurface::getMeshBoundingBox(){ |
_perspectiveWarping = b; |
||||
float minX = 10000.0f; |
} |
||||
float minY = 10000.0f; |
|
||||
float maxX = 0.0f; |
bool QuadSurface::getPerspectiveWarping(){ |
||||
float maxY = 0.0f; |
return _perspectiveWarping; |
||||
|
} |
||||
for(int i = 0; i < mesh.getVertices().size(); ++i){ |
|
||||
if(mesh.getVertices()[i].x < minX){ |
ofRectangle QuadSurface::getMeshBoundingBox(){ |
||||
minX = mesh.getVertices()[i].x; |
float minX = 10000.0f; |
||||
} |
float minY = 10000.0f; |
||||
|
float maxX = 0.0f; |
||||
if(mesh.getVertices()[i].y < minY){ |
float maxY = 0.0f; |
||||
minY = mesh.getVertices()[i].y; |
|
||||
} |
for(int i = 0; i < mesh.getVertices().size(); ++i){ |
||||
|
if(mesh.getVertices()[i].x < minX){ |
||||
if(mesh.getVertices()[i].x > maxX){ |
minX = mesh.getVertices()[i].x; |
||||
maxX = mesh.getVertices()[i].x; |
} |
||||
} |
|
||||
|
if(mesh.getVertices()[i].y < minY){ |
||||
if(mesh.getVertices()[i].y > maxY){ |
minY = mesh.getVertices()[i].y; |
||||
maxY = mesh.getVertices()[i].y; |
} |
||||
} |
|
||||
} |
if(mesh.getVertices()[i].x > maxX){ |
||||
|
maxX = mesh.getVertices()[i].x; |
||||
ofRectangle boundingBox = ofRectangle(ofPoint(minX, minY), ofPoint(maxX, maxY)); |
} |
||||
return boundingBox; |
|
||||
} |
if(mesh.getVertices()[i].y > maxY){ |
||||
|
maxY = mesh.getVertices()[i].y; |
||||
BaseSurface * QuadSurface::clone(){ |
} |
||||
QuadSurface * s = new QuadSurface(); |
} |
||||
s->setVertices(getVertices()); |
|
||||
s->setTexCoords(getTexCoords()); |
ofRectangle boundingBox = ofRectangle(ofPoint(minX, minY), ofPoint(maxX, maxY)); |
||||
s->setPerspectiveWarping(getPerspectiveWarping()); |
return boundingBox; |
||||
BaseSource * src = getSource(); |
} |
||||
src->referenceCount++; |
|
||||
s->setSource(src); |
BaseSurface * QuadSurface::clone(){ |
||||
return s; |
QuadSurface * s = new QuadSurface(); |
||||
} |
s->setVertices(getVertices()); |
||||
|
s->setTexCoords(getTexCoords()); |
||||
} // namespace piMapper
|
s->setPerspectiveWarping(getPerspectiveWarping()); |
||||
} // namespace ofx
|
BaseSource * src = getSource(); |
||||
|
src->referenceCount++; |
||||
|
s->setSource(src); |
||||
|
return s; |
||||
|
} |
||||
|
|
||||
|
} // namespace piMapper
|
||||
|
} // namespace ofx
|
||||
|
@ -1,55 +1,56 @@ |
|||||
#pragma once |
#pragma once |
||||
|
|
||||
#include "ofMain.h" |
#include "ofMain.h" |
||||
#include "BaseSurface.h" |
#include "BaseSurface.h" |
||||
#include "SurfaceType.h" |
#include "SurfaceType.h" |
||||
#include "HomographyHelper.h" |
#include "HomographyHelper.h" |
||||
|
#include "Vec2.h" |
||||
namespace ofx { |
|
||||
namespace piMapper { |
namespace ofx { |
||||
|
namespace piMapper { |
||||
class QuadSurface : public BaseSurface { |
|
||||
public: |
class QuadSurface : public BaseSurface { |
||||
QuadSurface(); |
public: |
||||
~QuadSurface(); |
QuadSurface(); |
||||
|
~QuadSurface(); |
||||
void setup(); |
|
||||
void setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f p4, ofVec2f t1, |
void setup(); |
||||
ofVec2f t2, ofVec2f t3, ofVec2f t4, BaseSource * newSource); |
void setup(Vec2 p1, Vec2 p2, Vec2 p3, Vec2 p4, Vec2 t1, |
||||
|
Vec2 t2, Vec2 t3, Vec2 t4, BaseSource * newSource); |
||||
void draw(); |
|
||||
|
void draw(); |
||||
void setVertex(int index, ofVec2f p); |
|
||||
void setVertices(vector<ofVec2f> v); |
void setVertex(int index, Vec2 p); |
||||
void setVertices(vector<ofVec3f> v); |
void setVertices(vector<Vec2> v); |
||||
|
void setVertices(vector<ofVec3f> v); |
||||
void setTexCoord(int index, ofVec2f t); |
|
||||
void setTexCoords(vector<ofVec2f> t); |
void setTexCoord(int index, Vec2 t); |
||||
|
void setTexCoords(vector<Vec2> t); |
||||
void moveBy(ofVec2f v); |
|
||||
|
void moveBy(Vec2 v); |
||||
int getType(); |
|
||||
bool hitTest(ofVec2f p); |
int getType(); |
||||
ofVec2f getVertex(int index); |
bool hitTest(Vec2 p); |
||||
ofVec2f getTexCoord(int index); |
Vec2 getVertex(int index); |
||||
ofPolyline getHitArea(); |
Vec2 getTexCoord(int index); |
||||
ofPolyline getTextureHitArea(); |
ofPolyline getHitArea(); |
||||
vector <ofVec3f> & getVertices(); |
ofPolyline getTextureHitArea(); |
||||
vector <ofVec2f> & getTexCoords(); |
vector <ofVec3f> & getVertices(); |
||||
|
vector <Vec2> & getTexCoords(); |
||||
void setPerspectiveWarping(bool b); |
|
||||
bool getPerspectiveWarping(); |
void setPerspectiveWarping(bool b); |
||||
|
bool getPerspectiveWarping(); |
||||
ofRectangle getMeshBoundingBox(); |
|
||||
|
ofRectangle getMeshBoundingBox(); |
||||
BaseSurface * clone(); |
|
||||
|
BaseSurface * clone(); |
||||
private: |
|
||||
void calculateHomography(); |
private: |
||||
|
void calculateHomography(); |
||||
float _matrix[16]; |
|
||||
bool _perspectiveWarping; |
float _matrix[16]; |
||||
}; |
bool _perspectiveWarping; |
||||
|
}; |
||||
} // namespace piMapper
|
|
||||
} // namespace ofx
|
} // namespace piMapper
|
||||
|
} // namespace ofx
|
||||
|
@ -0,0 +1,95 @@ |
|||||
|
#include "Vec2.h" |
||||
|
|
||||
|
namespace ofx { |
||||
|
namespace piMapper { |
||||
|
|
||||
|
Vec2::Vec2(){ |
||||
|
x = 0.0f; |
||||
|
y = 0.0f; |
||||
|
} |
||||
|
|
||||
|
Vec2::Vec2(float $x, float $y){ |
||||
|
x = $x; |
||||
|
y = $y; |
||||
|
} |
||||
|
|
||||
|
#if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9 |
||||
|
Vec2::Vec2(ofVec2f & src){ |
||||
|
x = src.x; |
||||
|
y = src.y; |
||||
|
} |
||||
|
|
||||
|
Vec2::Vec2(ofVec3f & src){ |
||||
|
x = src.x; |
||||
|
y = src.y; |
||||
|
} |
||||
|
|
||||
|
ofVec2f Vec2::toOf(){ |
||||
|
return ofVec2f(x, y); |
||||
|
} |
||||
|
|
||||
|
ofVec2f Vec2::toOf(Vec2 & src){ |
||||
|
return ofVec2f(src.x, src.y); |
||||
|
} |
||||
|
|
||||
|
vector<ofVec2f> Vec2::toOf(vector<Vec2> & src){ |
||||
|
vector<ofVec2f> dst; |
||||
|
for(auto v : src){ |
||||
|
dst.push_back(ofVec2f(v.x, v.y)); |
||||
|
} |
||||
|
return dst; |
||||
|
} |
||||
|
|
||||
|
float Vec2::distance(Vec2 & other){ |
||||
|
ofVec2f v1(x, y); |
||||
|
ofVec2f v2(other.x, other.y); |
||||
|
return v1.distance(v2); |
||||
|
} |
||||
|
#else |
||||
|
// TODO: The same for glm::vec2
|
||||
|
#endif |
||||
|
|
||||
|
void Vec2::operator=(const Vec2 & other){ |
||||
|
x = other.x; |
||||
|
y = other.y; |
||||
|
} |
||||
|
|
||||
|
void Vec2::operator=(const ofVec3f & other){ |
||||
|
x = other.x; |
||||
|
y = other.y; |
||||
|
} |
||||
|
|
||||
|
void Vec2::operator+=(Vec2 & other){ |
||||
|
x += other.x; |
||||
|
y += other.y; |
||||
|
} |
||||
|
|
||||
|
Vec2 Vec2::operator+(Vec2 & other){ |
||||
|
return Vec2(x + other.x, y + other.y); |
||||
|
} |
||||
|
|
||||
|
Vec2 Vec2::operator/(Vec2 & other){ |
||||
|
return Vec2(x / other.x, y / other.y); |
||||
|
} |
||||
|
|
||||
|
Vec2 Vec2::operator*(Vec2 & other){ |
||||
|
return Vec2(x * other.x, y * other.y); |
||||
|
} |
||||
|
|
||||
|
Vec2 Vec2::operator-(){ |
||||
|
return Vec2(-x, -y); |
||||
|
} |
||||
|
|
||||
|
Vec2 Vec2::operator-(Vec2 & other){ |
||||
|
return Vec2(x - other.x, y - other.y); |
||||
|
} |
||||
|
|
||||
|
bool Vec2::operator!=(Vec2 & other){ |
||||
|
if(x == other.x && y == other.y){ |
||||
|
return false; |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
} // namespace piMapper
|
||||
|
} // namespace ofx
|
@ -0,0 +1,49 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#include "ofMain.h" |
||||
|
|
||||
|
#if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9 |
||||
|
// ...
|
||||
|
#else |
||||
|
// TODO: include glm
|
||||
|
#endif |
||||
|
|
||||
|
namespace ofx { |
||||
|
namespace piMapper { |
||||
|
|
||||
|
//#if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9
|
||||
|
class Vec2{ |
||||
|
public: |
||||
|
Vec2(); |
||||
|
Vec2(float $x, float $y); |
||||
|
|
||||
|
#if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9 |
||||
|
Vec2(ofVec2f & src); |
||||
|
Vec2(ofVec3f & src); |
||||
|
ofVec2f toOf(); |
||||
|
static ofVec2f toOf(Vec2 & src); |
||||
|
static vector<ofVec2f> toOf(vector<Vec2> & src); |
||||
|
float distance(Vec2 & other); |
||||
|
#else |
||||
|
// TODO: The same for glm::vec2
|
||||
|
// static vector<glm::vec2> toOf(vector<Vec2> & src);
|
||||
|
#endif |
||||
|
|
||||
|
void operator=(const Vec2 & other); |
||||
|
void operator=(const ofVec3f & other); |
||||
|
void operator+=(Vec2 & other); |
||||
|
|
||||
|
Vec2 operator+(Vec2 & other); |
||||
|
Vec2 operator/(Vec2 & other); |
||||
|
Vec2 operator*(Vec2 & other); |
||||
|
Vec2 operator-(); |
||||
|
Vec2 operator-(Vec2 & other); |
||||
|
|
||||
|
bool operator!=(Vec2 & other); |
||||
|
|
||||
|
float x; |
||||
|
float y; |
||||
|
}; |
||||
|
|
||||
|
} // namespace piMapper
|
||||
|
} // namespace ofx
|
@ -0,0 +1,82 @@ |
|||||
|
#include "Vec3.h" |
||||
|
|
||||
|
namespace ofx { |
||||
|
namespace piMapper { |
||||
|
|
||||
|
Vec3::Vec3(){ |
||||
|
x = 0.0f; |
||||
|
y = 0.0f; |
||||
|
z = 0.0f; |
||||
|
} |
||||
|
|
||||
|
Vec3::Vec3(float $x, float $y, float $z){ |
||||
|
x = $x; |
||||
|
y = $y; |
||||
|
z = $z; |
||||
|
} |
||||
|
|
||||
|
#if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9 |
||||
|
Vec3::Vec3(ofVec3f & src){ |
||||
|
x = src.x; |
||||
|
y = src.y; |
||||
|
z = src.z; |
||||
|
} |
||||
|
|
||||
|
ofVec3f Vec3::toOf(){ |
||||
|
ofVec3f(x, y, z); |
||||
|
} |
||||
|
|
||||
|
ofVec3f toOf(Vec3 & src){ |
||||
|
return ofVec3f(src.x, src.y, src.z); |
||||
|
} |
||||
|
|
||||
|
vector<ofVec3f> toOf(vector<Vec3> & src){ |
||||
|
vector<ofVec3f> dst; |
||||
|
for(auto v : src){ |
||||
|
dst.push_back(ofVec3f(v.x, v.y, v.z)); |
||||
|
} |
||||
|
return dst; |
||||
|
} |
||||
|
#else |
||||
|
// TODO: The same for glm::vec2
|
||||
|
#endif |
||||
|
|
||||
|
void Vec3::operator=(const Vec3 & other){ |
||||
|
x = other.x; |
||||
|
y = other.y; |
||||
|
z = other.z; |
||||
|
} |
||||
|
|
||||
|
void Vec3::operator=(const ofVec3f & other){ |
||||
|
x = other.x; |
||||
|
y = other.y; |
||||
|
z = other.z; |
||||
|
} |
||||
|
|
||||
|
Vec3 Vec3::operator+(Vec3 & other){ |
||||
|
return Vec3( |
||||
|
x + other.x, |
||||
|
y + other.y, |
||||
|
z + other.z); |
||||
|
} |
||||
|
|
||||
|
Vec3 Vec3::operator-(){ |
||||
|
return Vec3(-x, -y, -z); |
||||
|
} |
||||
|
|
||||
|
Vec3 Vec3::operator-(Vec3 & other){ |
||||
|
return Vec3( |
||||
|
x - other.x, |
||||
|
y - other.y, |
||||
|
z - other.z); |
||||
|
} |
||||
|
|
||||
|
bool Vec3::operator!=(Vec3 & other){ |
||||
|
if(x == other.x && y == other.y && z == other.z){ |
||||
|
return false; |
||||
|
} |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
} // namespace piMapper
|
||||
|
} // namespace ofx
|
@ -0,0 +1,43 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
#if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9 |
||||
|
#include "ofMain.h" |
||||
|
#else |
||||
|
// TODO: include glm
|
||||
|
#endif |
||||
|
|
||||
|
namespace ofx { |
||||
|
namespace piMapper { |
||||
|
|
||||
|
class Vec3{ |
||||
|
public: |
||||
|
Vec3(); |
||||
|
Vec3(float $x, float $y, float $z); |
||||
|
|
||||
|
#if OF_VERSION_MAJOR == 0 && OF_VERSION_MINOR <= 9 |
||||
|
Vec3(ofVec3f & src); |
||||
|
ofVec3f toOf(); |
||||
|
static ofVec3f toOf(Vec3 & src); |
||||
|
static vector<ofVec3f> toOf(vector<Vec3> & src); |
||||
|
#else |
||||
|
// TODO: The same for glm::vec2
|
||||
|
// static vector<glm::vec2> toOf(vector<Vec2> & src);
|
||||
|
#endif |
||||
|
|
||||
|
void operator=(const Vec3 & other); |
||||
|
void operator=(const ofVec3f & other); |
||||
|
|
||||
|
Vec3 operator+(Vec3 & other); |
||||
|
|
||||
|
Vec3 operator-(); |
||||
|
Vec3 operator-(Vec3 & other); |
||||
|
|
||||
|
bool operator!=(Vec3 & other); |
||||
|
|
||||
|
float x; |
||||
|
float y; |
||||
|
float z; |
||||
|
}; |
||||
|
|
||||
|
} // namespace piMapper
|
||||
|
} // namespace ofx
|
Loading…
Reference in new issue