[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] gzz ./TODO gfx/Makefile gfx/libcoords/Coords.hx...
From: |
Tuomas J. Lukka |
Subject: |
[Gzz-commits] gzz ./TODO gfx/Makefile gfx/libcoords/Coords.hx... |
Date: |
Tue, 22 Oct 2002 12:28:23 -0400 |
CVSROOT: /cvsroot/gzz
Module name: gzz
Changes by: Tuomas J. Lukka <address@hidden> 02/10/22 12:28:23
Modified files:
. : TODO
gfx : Makefile
gfx/libcoords : Coords.hxx
gfx/libfillet : Fillet.hxx
gfx/librenderables: Renderables.cxx Renderables.hxx
renderables.py
gfx/libutil : Vec23.hxx
Added files:
gfx/demo : sqfillet.py
gfx/libfillet : Fillet.cxx Makefile
Log message:
Almost working fillet implementation - see sqfillet demo
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/TODO.diff?tr1=1.315&tr2=1.316&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/Makefile.diff?tr1=1.15&tr2=1.16&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/demo/sqfillet.py?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libcoords/Coords.hxx.diff?tr1=1.16&tr2=1.17&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libfillet/Fillet.cxx?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libfillet/Makefile?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libfillet/Fillet.hxx.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/librenderables/Renderables.cxx.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/librenderables/Renderables.hxx.diff?tr1=1.20&tr2=1.21&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/librenderables/renderables.py.diff?tr1=1.110&tr2=1.111&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libutil/Vec23.hxx.diff?tr1=1.11&tr2=1.12&r1=text&r2=text
Patches:
Index: gzz/TODO
diff -u gzz/TODO:1.315 gzz/TODO:1.316
--- gzz/TODO:1.315 Mon Oct 21 11:34:41 2002
+++ gzz/TODO Tue Oct 22 12:28:22 2002
@@ -51,6 +51,11 @@
are affected by the cards for now.
Also, make it possible to trigger these tests by daytime
(e.g. after having changed something relevant)
+ - benchmarking framework: running benchmarks on different machines
+ and different VMs automatically as well, reporting
+ results graphically on web. Need to see when there
+ are important changes to speed, what caused them
+ etc.
- speed up tests: currently too much execfile().. could
pre-compile and exec compiled in the same globals().
tuukkah:
Index: gzz/gfx/Makefile
diff -u gzz/gfx/Makefile:1.15 gzz/gfx/Makefile:1.16
--- gzz/gfx/Makefile:1.15 Wed Oct 2 07:50:50 2002
+++ gzz/gfx/Makefile Tue Oct 22 12:28:22 2002
@@ -6,9 +6,9 @@
JAVAC=javac
JAVA=java
-SUBDIRS=libutil libtexture libmosaic libtext libpaper libcolor libcoords
librenderables libcallgl libglwrapper jni
+SUBDIRS=libutil libtexture libmosaic libtext libpaper libcolor libcoords
libfillet librenderables libcallgl libglwrapper jni
-JNIOBJS=jni/GzzGL-jni.o jni/paper-jni.o libcallgl/callgl.o libcolor/spaces.o
libmosaic/Mosaic.o libos/Os-GLX.o libpaper/Paper.o librenderables/Renderables.o
libtext/Text.o libtexture/Texture.o libtexture/Texture_pipetexture.o
libutil/buildmipmaps.o libutil/perlin.o libglwrapper/GL_wrapper.o
libcoords/Coords.o libutil/Debug.o
+JNIOBJS=jni/GzzGL-jni.o jni/paper-jni.o libcallgl/callgl.o libcolor/spaces.o
libmosaic/Mosaic.o libos/Os-GLX.o libpaper/Paper.o librenderables/Renderables.o
libtext/Text.o libtexture/Texture.o libtexture/Texture_pipetexture.o
libutil/buildmipmaps.o libutil/perlin.o libglwrapper/GL_wrapper.o
libcoords/Coords.o libfillet/Fillet.cxx libutil/Debug.o
include rules.mk
Index: gzz/gfx/libcoords/Coords.hxx
diff -u gzz/gfx/libcoords/Coords.hxx:1.16 gzz/gfx/libcoords/Coords.hxx:1.17
--- gzz/gfx/libcoords/Coords.hxx:1.16 Thu Oct 10 01:10:21 2002
+++ gzz/gfx/libcoords/Coords.hxx Tue Oct 22 12:28:22 2002
@@ -1,3 +1,6 @@
+#ifndef GZZ_COORDS_HXX
+#define GZZ_COORDS_HXX
+
#include <GL/gl.h>
/** Coordinate systems.
@@ -187,3 +190,5 @@
};
}
+
+#endif
Index: gzz/gfx/libfillet/Fillet.hxx
diff -u gzz/gfx/libfillet/Fillet.hxx:1.2 gzz/gfx/libfillet/Fillet.hxx:1.3
--- gzz/gfx/libfillet/Fillet.hxx:1.2 Mon Oct 21 07:02:55 2002
+++ gzz/gfx/libfillet/Fillet.hxx Tue Oct 22 12:28:22 2002
@@ -1,26 +1,150 @@
+#include <vector>
+#include <libutil/Debug.hxx>
+#include <libutil/Vec23.hxx>
#include <libcoords/Coords.hxx>
+#include <boost/lambda/bind.hpp>
/** Generic implementation of fillets.
*/
namespace Fillet {
+ using namespace Vec23;
+ using namespace boost::lambda;
+ using std::vector;
+
PREDBGVAR(dbg);
- struct Vertex {
- bool sharp;
- bool lineAfter;
- ZPt p;
+ /** Transform (currently only linear) an outline.
+ */
+ template<class In, class Out>
+ void transformOutline(const In &b, const In &e, Out o,
+ Coords::CoordSys &coords) {
+ transform(b, e, o,
+ bind(&Coords::CoordSys::transform,
+ &coords, _1));
+ }
+
+ /** An implementation of adjacent_find, which takes
+ * its predicate as a reference. This makes it easy
+ * to do something with the found pair.
+ */
+ template<class In, class Oper> In adjacent_find_operate(
+ In begin, In end, Oper &pred) {
+ if(begin == end) return end;
+ In cur = begin;
+ In next = begin;
+ while(++next != end) {
+ if(pred(*cur, *next)) return cur;
+ cur = next;
+ }
+ return end;
}
- /** A generic shape: polylines.
+ /** Cut an outline with a given cut function.
+ * The outline is simply a range of vertices.
+ * The Cut function, when given two vertices should
+ * see if it is the point to cut.
+ * The member cut should then store the new vertex.
+ * <p>
+ * The output iterator is filled with
+ * the cut point, all vertices of the input range
+ * and finally the cut point again.
*/
- class Shape {
- vector<Vertex> points;
+ template<class In, class Out, class Cut>
+ bool cutOutline(const In &b, const In &e,
+ Out o, Cut &c) {
+ In f = adjacent_find_operate(b, e, c);
+ if(f == e) {
+ In l = e;
+ l --;
+ if(!c(*l, *b)) return false;
+ *o++ = c.cut;
+ o = copy(b, e, o);
+ *o++ = c.cut;
+ return true;
+ }
+ *o++ = c.cut;
+ f++; // point to the middle of the two adjacent.
+ o = copy(f, e, o);
+ o = copy(b, f, o);
+ *o++ = c.cut;
+ return true;
+ }
+
+ inline bool between(float start, float end, float it) {
+ return (fabs(start-end) >= fabs(it-end)) &&
+ (fabs(start-end) >= fabs(it-start));
+ }
+
+ struct _Cutter {
+ HL iline;
+ Pt center;
+ Vec fromCenter;
+ ZPt cut;
+ _Cutter() { }
+ bool operator()(const ZPt &a, const ZPt &b) ;
+ };
+
+ struct FilletDistort {
+ ZPt center;
+ ZPt to;
+ float width;
+ float length;
+ Vec dir;
+ Vec norm;
+
+ FilletDistort(ZPt center, ZPt to, float width) :
+ center(center), to(to), width(width) {
+ dir = Vec(to-center).normalize();
+ norm = dir.cw90();
+ length = Vec(to-center).length();
+ }
+
+ ZPt operator() (ZPt p, bool& wasshifted) ;
+ };
+
+ template<class In, class Out, class Shift>
+ void shiftEdge(const In &b,
+ const In &e,
+ Out o,
+ Shift &d) {
+ In cur = b;
+ In prev = b;
+ bool prevshifted, curshifted;;
+ ZPt prevpt = d(*prev, prevshifted);
+ *o++ = prevpt;
+ while( (++cur) != e) {
+ ZPt curpt = d(*cur, curshifted);
+ if(curshifted || prevshifted) {
+ // Dice...
+ const int n = 30;
+ bool fooshifted;
+ for(int i=1; i<n; i++) {
+ *o++ = d(lerp(*prev, *cur, (float)i / n), fooshifted);
+ }
+ }
+ *o++ = curpt;
+ prev = cur;
+ prevpt = curpt;
+ prevshifted = curshifted;
+ }
+ }
+
+ template<class In, class Out>
+ bool blendEdge(const In &b,
+ const In &e,
+ Out o,
+ ZPt center, ZPt to, FilletDistort &d) {
+ _Cutter cut;
+ cut.iline = HPt(center).line(HPt(to));
+ cut.center = Pt(center);
+ cut.fromCenter = Vec(to - center);
+
+ vector<ZPt> tmp;
+ if(!cutOutline(b, e, back_inserter(tmp), cut))
+ return false;
+
+ shiftEdge(tmp.begin(), tmp.end(), o, d);
+ return true;
- public:
- /** Cut after the vertex i, by inserting two vertices
- * after it, without a line between them.
- */
- void cutAfter(int i, float end, float begin);
- // Shape transform(CoordSys *t, float dicefudge = 1);
}
}
Index: gzz/gfx/librenderables/Renderables.cxx
diff -u gzz/gfx/librenderables/Renderables.cxx:1.8
gzz/gfx/librenderables/Renderables.cxx:1.9
--- gzz/gfx/librenderables/Renderables.cxx:1.8 Sun Oct 6 13:37:46 2002
+++ gzz/gfx/librenderables/Renderables.cxx Tue Oct 22 12:28:22 2002
@@ -11,6 +11,12 @@
namespace Renderables {
+ const ZPt unitsquare[4] = {
+ ZPt( 0, 0, 0 ),
+ ZPt( 1, 0, 0 ),
+ ZPt( 1, 1, 0 ),
+ ZPt( 0, 1, 0 ),
+ };
DBGVAR(dbg, "Renderable.general");
DBGVAR(dbg_horiztext2, "Renderable.horiztext2");
Index: gzz/gfx/librenderables/Renderables.hxx
diff -u gzz/gfx/librenderables/Renderables.hxx:1.20
gzz/gfx/librenderables/Renderables.hxx:1.21
--- gzz/gfx/librenderables/Renderables.hxx:1.20 Mon Oct 7 04:07:51 2002
+++ gzz/gfx/librenderables/Renderables.hxx Tue Oct 22 12:28:22 2002
@@ -13,6 +13,7 @@
#include "libcolor/spaces.hxx"
#include "libtext/Text.hxx"
+#include "libfillet/Fillet.hxx"
#include "libcoords/Coords.hxx"
@@ -70,11 +71,22 @@
PREDBGVAR(dbg_horiztext2);
PREDBGVAR(dbg_irregularquad);
+ using namespace Vec23;
+
+ inline void glVertex(const ZVec &v) {
+ glVertex3f(v.x, v.y, v.z);
+ }
+
+
+ /** The points of the unit square,
+ * for use in e.g. transformOutline.
+ */
+ extern const ZPt unitsquare[4];
+
using Util::ObjectStorer;
typedef std::vector<unsigned short> unicodecharvector;
- using namespace Vec23;
typedef Mosaic::Rect TexRect;
Index: gzz/gfx/librenderables/renderables.py
diff -u gzz/gfx/librenderables/renderables.py:1.110
gzz/gfx/librenderables/renderables.py:1.111
--- gzz/gfx/librenderables/renderables.py:1.110 Tue Oct 22 09:23:17 2002
+++ gzz/gfx/librenderables/renderables.py Tue Oct 22 12:28:22 2002
@@ -103,6 +103,8 @@
""",
},
+
+
{
"Type": "1",
"Name" : "TextureMatrix",
@@ -287,6 +289,60 @@
glPopAttrib();
"""
},
+
+{
+ "Type": "2",
+ "Name": "SqFilletConnection",
+ "Data": "float width;",
+ "Params": "float width",
+ "ParamCode": "this->width = width;",
+ "RenderCode" : """
+ vector<ZPt> sq1;
+ vector<ZPt> sq2;
+ Fillet::transformOutline(
+ unitsquare + 0, unitsquare + 4,
+ back_inserter(sq1),
+ coords1);
+ Fillet::transformOutline(
+ unitsquare + 0, unitsquare + 4,
+ back_inserter(sq2),
+ coords2);
+ ZPt ctr1 = coords1.transform(ZPt(.5, .5, 0));
+ ZPt ctr2 = coords2.transform(ZPt(.5, .5, 0));
+ ZPt mid = 0.5*(ctr1 + ctr2);
+
+ Fillet::FilletDistort d1(ctr1, mid, width);
+ Fillet::FilletDistort d2(ctr2, mid, width);
+
+ vector<ZPt> o1;
+ if(!Fillet::blendEdge(sq1.begin(), sq1.end(),
+ back_inserter(o1), ctr1, mid, d1)) {
+ DBG(dbg) << "Blendedge failed! 1" <<ctr1<<" "<<mid<<"\\n";
+ return;
+ }
+
+ vector<ZPt> o2;
+ if(!Fillet::blendEdge(sq2.begin(), sq2.end(),
+ back_inserter(o2), ctr2, mid, d2)) {
+ DBG(dbg) << "Blendedge failed! 2" <<ctr2<<" "<<mid<<"\\n";
+ return;
+ }
+
+ glBegin(GL_LINE_STRIP);
+ for(unsigned i=0; i<o1.size(); i++)
+ glVertex(o1[i]);
+ glEnd();
+ GLERR
+
+ glBegin(GL_LINE_STRIP);
+ for(unsigned i=0; i<o2.size(); i++)
+ glVertex(o2[i]);
+ glEnd();
+ GLERR
+
+ """
+},
+
{
"Type": "2",
Index: gzz/gfx/libutil/Vec23.hxx
diff -u gzz/gfx/libutil/Vec23.hxx:1.11 gzz/gfx/libutil/Vec23.hxx:1.12
--- gzz/gfx/libutil/Vec23.hxx:1.11 Tue Oct 1 06:32:49 2002
+++ gzz/gfx/libutil/Vec23.hxx Tue Oct 22 12:28:23 2002
@@ -39,7 +39,8 @@
T x, y;
Vector() : x(0), y(0) { }
Vector(T x, T y) : x(x), y(y) { }
- Vector(Vector3<T> &v) : x(v.x), y(v.y) { }
+ template<class F>
+ Vector(const Vector3<F> &v) : x(v.x), y(v.y) { }
Vector operator*(const double &s) const { return Vector(s * x, s * y); }
template<class U>const Vector &operator*=(const U &s) { x *= s; y *= s;
return *this; }
Vector normalize() { return (1/length()) * *this ; }
@@ -70,8 +71,14 @@
Vector3(const Vector<T> &v, float z = 0) : x(v.x), y(v.y), z(z) { }
Vector3 operator*(const double &s) const { return Vector3(s * x, s * y,
s * z); } ;
- template<class U> const Vector3 &operator*=(const U &s) { x *= s; y *=
s; z *= s;
- return
*this; } ;
+ template<class U> const Vector3 &operator*=(const U &s) {
+ x *= s; y *= s; z *= s;
+ return *this;
+ } ;
+ template<class U> const Vector3 &operator/=(const U &s) {
+ x /= s; y /= s; z /= s;
+ return *this;
+ } ;
Vector3 normalize() const { return (1/length()) * *this ; }
Vector3<T> operator-() const { return Vector3<T>(-x, -y, -z); }
Vector3 operator+(const Vector3<T>&v) const { return Vector3(x+v.x,
y+v.y, z+v.z); }
@@ -130,6 +137,77 @@
template<class X, class Y> inline X lerp(X a, Y b, double fract) {
return a + fract * (b-a);
}
+
+
+
+ template<class T> void cross3(T x1, T y1, T z1, T x2, T y2, T z2, T &xr, T
&yr, T &zr) {
+ xr = y1 * z2 - y2 * z1;
+ yr = z1 * x2 - z2 * x1;
+ zr = x1 * y2 - x2 * y1;
+ }
+
+#define VEC23_EPS 0.000001
+
+ template<class T> class HLine2;
+
+ /** A homogeneous 2D point.
+ * Useful for computing: no fear of bad divisions!
+ */
+ template<class T> struct HPoint2 {
+ T x, y, w;
+ HPoint2() {}
+ HPoint2(T x, T y, T w) : x(x), y(y), w(w) { }
+ HPoint2(ZPt p) : x(p.x), y(p.y), w(1) { }
+
+ HLine2<T> line(HPoint2 p) {
+ T a, b, c;
+ cross3(x, y, w, p.x, p.y, p.w, a, b, c);
+ return HLine2<T>(a, b, c);
+ }
+
+ bool finite() {
+ T r = fabs(x) + fabs(y);
+ T i = fabs(w);
+ if(i < r * VEC23_EPS) return false;
+ return true;
+ }
+
+ operator Vector<T> () {
+ return Vector<T>(x/w, y/w);
+ }
+
+ };
+ template<class T> inline ostream& operator<<(ostream &o, const HPoint2<T>
&p) {
+ return o << "[2hv "<<p.x<<" "<<p.y<<" "<<p.w<<"]";
+ };
+
+ /** A homogeneous 2D line.
+ */
+ template<class T> struct HLine2 {
+ T a, b, c;
+ HLine2() {}
+ HLine2(T a, T b, T c) : a(a), b(b), c(c) { }
+
+ HPoint2<T> intersection(HLine2 l) {
+ T x, y, w;
+ cross3(a, b, c, l.a, l.b, l.c, x, y, w);
+ return HPoint2<T>(x, y, w);
+ }
+
+ bool finite() {
+ T r = fabs(a) + fabs(b);
+ T i = fabs(c);
+ if(r < i * VEC23_EPS) return false;
+ return true;
+ }
+
+ };
+ template<class T> inline ostream& operator<<(ostream &o, const HLine2<T>
&p) {
+ return o << "[2hl "<<p.a<<" "<<p.b<<" "<<p.c<<"]";
+ };
+
+ typedef HPoint2<float> HPt;
+ typedef HLine2<float> HL;
}
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gzz-commits] gzz ./TODO gfx/Makefile gfx/libcoords/Coords.hx...,
Tuomas J. Lukka <=