Browse Source

Add `setVertices` and `setTexCoords` methods

This is to be able to pass vectors of values to the surfaces instead values one by one

diff --git a/src/Surfaces/BaseSurface.h b/src/Surfaces/BaseSurface.h
index 19d090b..e524872 100644
--- a/src/Surfaces/BaseSurface.h
+++ b/src/Surfaces/BaseSurface.h
@@ -16,8 +16,13 @@ class BaseSurface {
 		~BaseSurface();
 		virtual void setup(){}
 		virtual void draw(){}
+
 		virtual void setVertex(int index, ofVec2f p){}
+		virtual void setVertices(vector<ofVec2f> v){}
+
 		virtual void setTexCoord(int index, ofVec2f t){}
+		virtual void setTexCoords(vector<ofVec2f> t){}
+
 		virtual void moveBy(ofVec2f v){}
 		virtual int getType(){}
 		virtual bool hitTest(ofVec2f p){}
diff --git a/src/Surfaces/QuadSurface.cpp b/src/Surfaces/QuadSurface.cpp
index 34055e7..3a9089b 100644
--- a/src/Surfaces/QuadSurface.cpp
+++ b/src/Surfaces/QuadSurface.cpp
@@ -103,6 +103,16 @@ void QuadSurface::setVertex(int index, ofVec2f p){
 	calculate4dTextureCoords();
 }

+void QuadSurface::setVertices(vector<ofVec2f> v){
+	if(v.size() != 4){
+		throw runtime_error("Wrong number of vertices");
+	}
+	for(int i = 0; i < 4; ++i){
+		mesh.setVertex(i, v[i]);
+	}
+	calculate4dTextureCoords();
+}
+
 void QuadSurface::setTexCoord(int index, ofVec2f t){
 	if(index > 3){
 		ofLog() << "Texture coordinate with this index does not exist: " << index
@@ -114,6 +124,16 @@ void QuadSurface::setTexCoord(int index, ofVec2f t){
 	calculate4dTextureCoords();
 }

+void QuadSurface::setTexCoords(vector<ofVec2f> t){
+	if(t.size() != 4){
+		throw runtime_error("Wrong number of vertices");
+	}
+	for(int i = 0; i < 4; ++i){
+		mesh.setTexCoord(i, t[i]);
+	}
+	calculate4dTextureCoords();
+}
+
 void QuadSurface::moveBy(ofVec2f v){
 	vector <ofVec3f> & vertices = getVertices();
 	for(int i = 0; i < vertices.size(); i++){
diff --git a/src/Surfaces/QuadSurface.h b/src/Surfaces/QuadSurface.h
index b53ac95..07777d4 100644
--- a/src/Surfaces/QuadSurface.h
+++ b/src/Surfaces/QuadSurface.h
@@ -18,8 +18,13 @@ class QuadSurface : public BaseSurface {
 				   ofVec2f t2, ofVec2f t3, ofVec2f t4, BaseSource * newSource);

 		void draw();
+
 		void setVertex(int index, ofVec2f p);
+		void setVertices(vector<ofVec2f> v);
+
 		void setTexCoord(int index, ofVec2f t);
+		void setTexCoords(vector<ofVec2f> t);
+
 		void moveBy(ofVec2f v);

 		int getType();
diff --git a/src/Surfaces/TriangleSurface.cpp b/src/Surfaces/TriangleSurface.cpp
index 8937948..27e3951 100644
--- a/src/Surfaces/TriangleSurface.cpp
+++ b/src/Surfaces/TriangleSurface.cpp
@@ -62,6 +62,15 @@ void TriangleSurface::setVertex(int index, ofVec2f p){
 	mesh.setVertex(index, p);
 }

+void TriangleSurface::setVertices(vector<ofVec2f> v){
+	if(v.size() != 3){
+		throw runtime_error("Wrong number of vertices");
+	}
+	for(int i = 0; i < 3; ++i){
+		mesh.setVertex(i, v[i]);
+	}
+}
+
 void TriangleSurface::setTexCoord(int index, ofVec2f t){
 	if(index > 2){
 		ofLog() << "Texture coordinate with this index does not exist: " << index
@@ -72,6 +81,15 @@ void TriangleSurface::setTexCoord(int index, ofVec2f t){
 	mesh.setTexCoord(index, t);
 }

+void TriangleSurface::setTexCoords(vector<ofVec2f> t){
+	if(t.size() != 3){
+		throw runtime_error("Wrong number of texture coordinates");
+	}
+	for(int i = 0; i < 3; ++i){
+		mesh.setTexCoord(i, t[i]);
+	}
+}
+
 void TriangleSurface::moveBy(ofVec2f v){
 	vector <ofVec3f> & vertices = getVertices();
 	for(int i = 0; i < vertices.size(); i++){
diff --git a/src/Surfaces/TriangleSurface.h b/src/Surfaces/TriangleSurface.h
index 9edfcf4..c3d9317 100644
--- a/src/Surfaces/TriangleSurface.h
+++ b/src/Surfaces/TriangleSurface.h
@@ -16,8 +16,13 @@ class TriangleSurface : public BaseSurface {
 		void setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f t1, ofVec2f t2,
 				   ofVec2f t3, BaseSource * newSource);
 		void draw();
+
 		void setVertex(int index, ofVec2f p);
+		void setVertices(vector<ofVec2f> v);
+
 		void setTexCoord(int index, ofVec2f t);
+		void setTexCoords(vector<ofVec2f> t);
+
 		void moveBy(ofVec2f v);

 		int getType();
master
Krisjanis Rijnieks 10 years ago
parent
commit
965eb57d14
  1. 5
      src/Surfaces/BaseSurface.h
  2. 20
      src/Surfaces/QuadSurface.cpp
  3. 5
      src/Surfaces/QuadSurface.h
  4. 18
      src/Surfaces/TriangleSurface.cpp
  5. 5
      src/Surfaces/TriangleSurface.h

5
src/Surfaces/BaseSurface.h

@ -16,8 +16,13 @@ class BaseSurface {
~BaseSurface();
virtual void setup(){}
virtual void draw(){}
virtual void setVertex(int index, ofVec2f p){}
virtual void setVertices(vector<ofVec2f> v){}
virtual void setTexCoord(int index, ofVec2f t){}
virtual void setTexCoords(vector<ofVec2f> t){}
virtual void moveBy(ofVec2f v){}
virtual int getType(){}
virtual bool hitTest(ofVec2f p){}

20
src/Surfaces/QuadSurface.cpp

@ -103,6 +103,16 @@ void QuadSurface::setVertex(int index, ofVec2f p){
calculate4dTextureCoords();
}
void QuadSurface::setVertices(vector<ofVec2f> v){
if(v.size() != 4){
throw runtime_error("Wrong number of vertices");
}
for(int i = 0; i < 4; ++i){
mesh.setVertex(i, v[i]);
}
calculate4dTextureCoords();
}
void QuadSurface::setTexCoord(int index, ofVec2f t){
if(index > 3){
ofLog() << "Texture coordinate with this index does not exist: " << index
@ -114,6 +124,16 @@ void QuadSurface::setTexCoord(int index, ofVec2f t){
calculate4dTextureCoords();
}
void QuadSurface::setTexCoords(vector<ofVec2f> t){
if(t.size() != 4){
throw runtime_error("Wrong number of vertices");
}
for(int i = 0; i < 4; ++i){
mesh.setTexCoord(i, t[i]);
}
calculate4dTextureCoords();
}
void QuadSurface::moveBy(ofVec2f v){
vector <ofVec3f> & vertices = getVertices();
for(int i = 0; i < vertices.size(); i++){

5
src/Surfaces/QuadSurface.h

@ -18,8 +18,13 @@ class QuadSurface : public BaseSurface {
ofVec2f t2, ofVec2f t3, ofVec2f t4, BaseSource * newSource);
void draw();
void setVertex(int index, ofVec2f p);
void setVertices(vector<ofVec2f> v);
void setTexCoord(int index, ofVec2f t);
void setTexCoords(vector<ofVec2f> t);
void moveBy(ofVec2f v);
int getType();

18
src/Surfaces/TriangleSurface.cpp

@ -62,6 +62,15 @@ void TriangleSurface::setVertex(int index, ofVec2f p){
mesh.setVertex(index, p);
}
void TriangleSurface::setVertices(vector<ofVec2f> v){
if(v.size() != 3){
throw runtime_error("Wrong number of vertices");
}
for(int i = 0; i < 3; ++i){
mesh.setVertex(i, v[i]);
}
}
void TriangleSurface::setTexCoord(int index, ofVec2f t){
if(index > 2){
ofLog() << "Texture coordinate with this index does not exist: " << index
@ -72,6 +81,15 @@ void TriangleSurface::setTexCoord(int index, ofVec2f t){
mesh.setTexCoord(index, t);
}
void TriangleSurface::setTexCoords(vector<ofVec2f> t){
if(t.size() != 3){
throw runtime_error("Wrong number of texture coordinates");
}
for(int i = 0; i < 3; ++i){
mesh.setTexCoord(i, t[i]);
}
}
void TriangleSurface::moveBy(ofVec2f v){
vector <ofVec3f> & vertices = getVertices();
for(int i = 0; i < vertices.size(); i++){

5
src/Surfaces/TriangleSurface.h

@ -16,8 +16,13 @@ class TriangleSurface : public BaseSurface {
void setup(ofVec2f p1, ofVec2f p2, ofVec2f p3, ofVec2f t1, ofVec2f t2,
ofVec2f t3, BaseSource * newSource);
void draw();
void setVertex(int index, ofVec2f p);
void setVertices(vector<ofVec2f> v);
void setTexCoord(int index, ofVec2f t);
void setTexCoords(vector<ofVec2f> t);
void moveBy(ofVec2f v);
int getType();

Loading…
Cancel
Save