[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] libvob/include/vob/vobs Paper.hxx
From: |
Tuomas J. Lukka |
Subject: |
[Gzz-commits] libvob/include/vob/vobs Paper.hxx |
Date: |
Thu, 24 Apr 2003 13:49:53 -0400 |
CVSROOT: /cvsroot/libvob
Module name: libvob
Changes by: Tuomas J. Lukka <address@hidden> 03/04/24 13:49:53
Modified files:
include/vob/vobs: Paper.hxx
Log message:
EasyPaperQuad - easier parameters
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/libvob/libvob/include/vob/vobs/Paper.hxx.diff?tr1=1.5&tr2=1.6&r1=text&r2=text
Patches:
Index: libvob/include/vob/vobs/Paper.hxx
diff -u libvob/include/vob/vobs/Paper.hxx:1.5
libvob/include/vob/vobs/Paper.hxx:1.6
--- libvob/include/vob/vobs/Paper.hxx:1.5 Tue Apr 1 15:14:18 2003
+++ libvob/include/vob/vobs/Paper.hxx Thu Apr 24 13:49:53 2003
@@ -270,7 +270,6 @@
# coordinates.
*/
-
class PaperQuad {
public:
enum { NTrans = 2 };
@@ -492,6 +491,209 @@
VOB_DEFINED(PaperQuad);
+
+/**
+# there are three coordinate
+# systems here as well: the window cs, the object cs and the paper cs.
+# cs1 is object => window,
+# and cs2 is object => paper.
+* This version renders exactly the box of cs2
+*/
+
+class EasyPaperQuad {
+public:
+ enum { NTrans = 2 };
+
+ ::Vob::Paper::Paper *paper;
+ float dicefactor;
+ int flags;
+
+ template<class F> void params(F &f) {
+ f(paper, dicefactor, flags);
+ }
+
+ template<class T> void render(const T &coords1, const T &coords2) const {
+ const int flags = this->flags;
+
+ GLERR
+
+ Paper::LightParam lightParam;
+
+ // These are now irrelevant
+ lightParam.orig = ZPt(0,0,0);
+ lightParam.e0 = ZPt(1,0,0);
+ lightParam.e1 = ZPt(0,1,0);
+ lightParam.e2 = ZPt(0,0,1);
+
+ lightParam.Light = ZVec(-1,-1,1);
+ lightParam.Light_w = 0.0;
+
+ DBG(dbg_paperquad) << "EasyPaperquad: " <<
+ lightParam.orig << " " <<
+ lightParam.e0 << " " <<
+ lightParam.e1 << " " <<
+ lightParam.e2 << " " <<
+ "\\n"
+ ;
+ GLERR
+
+
+ int dice;
+ Pt box = coords2.getSqSize();
+
+ if(flags & PAPERQUAD_NONL_MAXLEN) {
+ Pt p1 = coords1.transform(Pt(0,0));
+ Pt p2 = coords1.transform(Pt(0,box.y));
+ Pt p3 = coords1.transform(Pt(box.x,0));
+ Pt p4 = coords1.transform(Pt(box.x,box.y));
+ float dist[4] = {
+ (p2-p1).length(),
+ (p3-p1).length(),
+ (p4-p2).length(),
+ (p4-p3).length()
+ };
+ float m = *std::max_element(dist, dist+4);
+
+ dice = (int)(m / dicefactor) + 2;
+ } else { // old way
+
+ ZPt ctr = .5 * box;
+ double len = box.length() / 2;
+ double nonl = coords1.nonlinearity(ctr, len);
+
+ dice = (int)(len * nonl * dicefactor) + 2;
+ }
+ DBG(dbg_paperquad) << "Dice: " << dice <<"\\n";
+ // Cap it at a ridiculous value
+ if( dice > 100) dice = 100;
+ if(dice < 2 ) dice = 2;
+
+ float *vertices = new float[dice * dice * 5];
+
+ int *indices = new int[(dice) * (2*dice)];
+
+ #define VERTICES3(x, y, z) vertices[((x)*dice + (y))*5 + (z)]
+ #define VERTICES2(x, y) vertices[((x)*dice + (y))*5]
+ #define INDICES2(x, y) indices[(x)*2*dice + (y)]
+ #define INDICES1(x) indices[(x)*2*dice]
+
+ int *indps[dice-1];
+ int counts[dice-1];
+ for(int ix = 0; ix<dice; ix++) {
+ if(ix < dice-1) {
+ counts[ix] = 2*dice;
+ indps[ix] = &INDICES1(ix);
+ }
+ for(int iy = 0; iy<dice; iy++) {
+ if(ix < dice-1) {
+ INDICES2(ix, 2*iy) = dice * ix + iy;
+ INDICES2(ix, 2*iy+1) = dice * (ix+1) + iy;
+ }
+ float x = ix / (dice - 1.0);
+ float y = iy / (dice - 1.0);
+ ZPt p(lerp(0., box.x, x), lerp(0., box.y, y), 0);
+ ZPt v = coords1.transform(p);
+ VERTICES3(ix, iy, 2) = v.x;
+ VERTICES3(ix, iy, 3) = v.y;
+ VERTICES3(ix, iy, 4) = v.z;
+ ZPt t;
+ t = coords2.transform(p);
+ VERTICES3(ix, iy, 0) = t.x;
+ VERTICES3(ix, iy, 1) = t.y;
+ DBG(dbg_paperquad) << " vert: " <<
+ ix << " " <<
+ iy << " : " <<
+ VERTICES3(ix, iy, 0) << " " <<
+ VERTICES3(ix, iy, 1) << " " <<
+ VERTICES3(ix, iy, 2) << " " <<
+ VERTICES3(ix, iy, 3) << " " <<
+ VERTICES3(ix, iy, 4) << " " <<
+ "\\n";
+ }
+ }
+
+ if(flags & PAPERQUAD_USE_VERTEX_PROGRAM) {
+ glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
+ glInterleavedArrays(GL_T2F_V3F, 5*sizeof(float), vertices);
+ glLockArraysEXT(0, dice*dice);
+
+ for(Paper::Paper::iterator it = paper->begin(); it !=
paper->end(); ++it) {
+
+ DBG(dbg_paperquad) << "Pass\\n";
+ GLERR
+ (*it).setUp_VP(&lightParam);
+
+ DBG(dbg_paperquad) << "Going to multidraw\\n";
+ GLERR
+ glMultiDrawElementsEXT(GL_QUAD_STRIP, counts,
+ GL_UNSIGNED_INT, (const GLvoid **)indps, dice-1);
+ DBG(dbg_paperquad) << "Teardown\\n";
+ GLERR
+ (*it).tearDown_VP();
+
+ GLERR
+ DBG(dbg_paperquad) << "Pass over\\n";
+
+ }
+ glUnlockArraysEXT();
+ glPopClientAttrib();
+ } else {
+ for(Paper::Paper::iterator it = paper->begin(); it !=
paper->end(); ++it) {
+
+ DBG(dbg_paperquad) << "Pass\\n";
+ GLERR
+ (*it).setUp_explicit(&lightParam);
+
+ DBG(dbg_paperquad) << "Going to set texcoords explicit\\n";
+ GLERR
+
+
+ for(int ix = 0; ix<dice-1; ix++) {
+ glBegin(GL_QUAD_STRIP);
+ for(int iy = 0; iy<dice; iy++) {
+
+ float tmp[4] = { VERTICES3(ix, iy, 0),
VERTICES3(ix, iy, 1), 0 ,1 };
+ DBG(dbg_paperquad) << "to texcoords\\n";
+ (*it).texcoords_explicit( tmp );
+ DBG(dbg_paperquad) << "to vertex\\n";
+ glVertex3fv( (&(VERTICES2(ix, iy))+2) );
+
+ float tmp2[4] = { VERTICES3(ix+1, iy, 0),
VERTICES3(ix+1, iy, 1), 0 ,1 };
+ DBG(dbg_paperquad) << "to texcoords\\n";
+ (*it).texcoords_explicit( tmp2 );
+ DBG(dbg_paperquad) << "to vertex\\n";
+ glVertex3fv( ((&VERTICES2(ix+1, iy))+2) );
+ }
+ DBG(dbg_paperquad) << "to end\\n";
+ glEnd();
+ }
+
+
+ DBG(dbg_paperquad) << "Teardown\\n";
+ GLERR
+ (*it).tearDown_explicit();
+
+ GLERR
+ DBG(dbg_paperquad) << "Pass over\\n";
+ }
+ }
+
+ DBG(dbg_paperquad) << "Passes over\\n";
+
+ GLERR
+
+ delete [] vertices;
+ delete [] indices;
+
+ }
+
+
+
+};
+
+
+VOB_DEFINED(EasyPaperQuad);
+
}
}