[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] gzz/gfx demo/irregu4.py librenderables/renderab...
From: |
Janne V. Kujala |
Subject: |
[Gzz-commits] gzz/gfx demo/irregu4.py librenderables/renderab... |
Date: |
Wed, 11 Dec 2002 07:20:07 -0500 |
CVSROOT: /cvsroot/gzz
Module name: gzz
Changes by: Janne V. Kujala <address@hidden> 02/12/11 07:20:06
Modified files:
gfx/demo : irregu4.py
gfx/librenderables: renderables.py
gfx/libutil : Irregu.hxx effects.py
Log message:
cleanup
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/demo/irregu4.py.diff?tr1=1.42&tr2=1.43&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/librenderables/renderables.py.diff?tr1=1.160&tr2=1.161&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libutil/Irregu.hxx.diff?tr1=1.15&tr2=1.16&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gfx/libutil/effects.py.diff?tr1=1.24&tr2=1.25&r1=text&r2=text
Patches:
Index: gzz/gfx/demo/irregu4.py
diff -u gzz/gfx/demo/irregu4.py:1.42 gzz/gfx/demo/irregu4.py:1.43
--- gzz/gfx/demo/irregu4.py:1.42 Tue Dec 3 07:04:22 2002
+++ gzz/gfx/demo/irregu4.py Wed Dec 11 07:20:06 2002
@@ -87,8 +87,6 @@
Enable REGISTER_COMBINERS_NV
- CombinerParameterNV NUM_GENERAL_COMBINERS_NV 2
-
SPARE0 = TEX0 . COL0
SPARE0.alpha = TEX0.alpha * COL0.alpha + COL1.blue
Index: gzz/gfx/librenderables/renderables.py
diff -u gzz/gfx/librenderables/renderables.py:1.160
gzz/gfx/librenderables/renderables.py:1.161
--- gzz/gfx/librenderables/renderables.py:1.160 Sat Nov 30 14:40:42 2002
+++ gzz/gfx/librenderables/renderables.py Wed Dec 11 07:20:06 2002
@@ -1433,73 +1433,6 @@
# coords1: paper => window
# coords2: frame => paper (assumed to be affine)
#
-# texscale is paper-texture scaling
-# ripple_scale is the amplitude-period scale of the texture
-{
- "Type" : "2",
- "Name": "IrregularEllipse",
- "Data": """float texscale; float ripple_scale; int mode; CallGLCode setup;
- float dicefactor;""",
- "Params" : """
- float texscale, float ripple_scale, int mode, UTF8String setupcode,
- float dicefactor
- """,
- "ParamCode" : """
- this->texscale = texscale;
- this->ripple_scale = ripple_scale;
- this->mode = mode;
- setup = CallGLCode(setupcode.c_str());
- this->dicefactor = dicefactor;
- """,
- "RenderCode" : """
- DBG(dbg) << "IrregularEllipse\\n";
-
- // XXX: TODO: use coords1.nonlinearity()
- int n = (int)(36 * dicefactor);
- std::vector<ZPt> vert(n+1);
- std::vector<ZVec> norm(n+1);
-
- for (int i = 0; i <= n; i++) {
- float a = i * 2*M_PI / n;
- vert[i] = coords2.transform(ZPt(cos(a), sin(a), 0));
- }
-
- for (int i = 0; i <= n; i++) {
- ZVec v1 = (vert[(i+1) % n] - vert[i % n]).cw90().normalize();
- ZVec v2 = (vert[i % n] - vert[(i+n-1) % n]).cw90().normalize();
-
- norm[i] = (v1 + v2).normalize();
- norm[i] *= (ripple_scale * texscale) / v1.dot(norm[i]);
- }
-
- setup();
- float col[] = {1,1,1,1,0,0,0,0};
- if (!mode) glColor4f(0,0,0,1);
- Irregu::draw(coords1, vert, norm, texscale, 2.0, 128, 0,
- -.5, .5, 0, col, NULL, 3, 0,
- Irregu::SLICE_1D + Irregu::Y_SECCOLOR +
- mode * Irregu::DOTVEC_COLOR + Irregu::INTERP_DOTVEC);
-
- if (!mode) {
- glDisable(GL_TEXTURE_2D);
- glDisable(GL_REGISTER_COMBINERS_NV);
- float col[4];
- glGetFloatv(GL_CONSTANT_COLOR0_NV, col);
- glColor4fv(col);
- Irregu::fill(coords1, coords2.transform(ZPt(0,0,0)),
- vert, norm, -.5);
- }
-
- glPopAttrib();
-
- DBG(dbg) << "IrregularEllipse done\\n";
-
- """,
-} ,
-
-# coords1: paper => window
-# coords2: frame => paper (assumed to be affine)
-#
# shape: determines the frame shape; all shapes fit in [-1,1]^2
# setup: CallGL code that is run before calling Irregu::draw
# texscale, ..., flags: passed directly to Irregu::draw
@@ -1530,9 +1463,6 @@
}
return v;
}
- double power(double x, double y) {
- return x < 0 ? -pow(-x,y) : pow(x,y);
- }
""",
"ParamCode" : """
this->shape = shape;
@@ -1569,17 +1499,14 @@
n = 2 + shape;
default:
case 0:
- for (int i = 0; i < n; i++) {
- float a = i * 2*M_PI / n;
- vert[i] = coords2.transform(ZPt(cos(a), sin(a), 0));
- }
+ vert = Irregu::getEllipse(n, 2, 2);
break;
case 7: {
n = 4;
- vert[0] = coords2.transform(ZPt(+1, -1, 0));
- vert[1] = coords2.transform(ZPt(+1, +1, 0));
- vert[2] = coords2.transform(ZPt(-1, +1, 0));
- vert[3] = coords2.transform(ZPt(-1, -1, 0));
+ vert[0] = ZPt(+1, -1, 0);
+ vert[1] = ZPt(+1, +1, 0);
+ vert[2] = ZPt(-1, +1, 0);
+ vert[3] = ZPt(-1, -1, 0);
}
break;
case 8:
@@ -1588,30 +1515,16 @@
case 11: {
float xw = (coords2.transform(ZPt(1,0,0)) -
coords2.transform(ZPt(0,0,0))).length();
float yw = (coords2.transform(ZPt(0,1,0)) -
coords2.transform(ZPt(0,0,0))).length();
-
+
float pow = 2 + (shape - 8) * 3;
- float xpow = 2 / (pow * xw);
- float ypow = 2 / (pow * yw);
- for (int i = 0; i < n; i++) {
- float a = i * 2*M_PI / n;
- vert[i] = coords2.transform(ZPt(power(cos(a),xpow),
power(sin(a),ypow), 0));
- }
+ vert = Irregu::getEllipse(n, pow * xw, pow * yw);
}
break;
}
- vert[n] = vert[0];
vert.resize(n + 1);
-
- std::vector<ZVec> norm(n + 1);
-
- for (int i = 0; i <= n; i++) {
- ZVec v1 = (vert[(i+1) % n] - vert[i % n]).cw90().normalize();
- ZVec v2 = (vert[i % n] - vert[(i+n-1) % n]).cw90().normalize();
-
- norm[i] = (v1 + v2).normalize();
- norm[i] *= 1.0 / v1.dot(norm[i]);
- }
+ vert[n] = vert[0];
+ Irregu::transform(coords2, vert);
setup();
GLERR;
@@ -1672,6 +1585,7 @@
GLERR;
} else {
+ std::vector<ZVec> norm = Irregu::computeNorms(vert, n);
Irregu::draw(coords1, vert, norm, texscale,
linewidth, refsize, scale_pow,
border0, border1, texslicing,
Index: gzz/gfx/libutil/Irregu.hxx
diff -u gzz/gfx/libutil/Irregu.hxx:1.15 gzz/gfx/libutil/Irregu.hxx:1.16
--- gzz/gfx/libutil/Irregu.hxx:1.15 Sat Nov 30 14:40:42 2002
+++ gzz/gfx/libutil/Irregu.hxx Wed Dec 11 07:20:06 2002
@@ -74,6 +74,39 @@
return fabs(c.x * (b.y - a.y) + b.x * (a.y - c.y) + a.x * (c.y - b.y));
}
+
+ inline double power(double x, double y) {
+ return x < 0 ? -pow(-x,y) : pow(x,y);
+ }
+
+ inline vector<ZPt> getEllipse(int n, float pow0 = 2.0, float pow1 = 2.0) {
+ vector<ZPt> vert(n);
+ for (int i = 0; i < n; i++) {
+ float a = i * 2*M_PI / n;
+ vert[i] = ZPt(power(cos(a), 2 / pow0),
+ power(sin(a), 2 / pow1), 0);
+ }
+ return vert;
+ }
+
+ template <class Coords>
+ void transform(Coords &coords2, vector<ZPt> &pt) {
+ for (unsigned i = 0; i < pt.size(); i++)
+ pt[i] = coords2.transform(pt[i]);
+ }
+
+ inline vector<ZVec> computeNorms(vector<ZPt> &pt, unsigned n) {
+ vector<ZVec> norm(n + 1);
+ for (unsigned i = 0; i <= n; i++) {
+ ZVec v1 = (pt[(i+1) % n] - pt[i % n]).cw90().normalize();
+ ZVec v2 = (pt[i % n] - pt[(i+n-1) % n]).cw90().normalize();
+
+ norm[i] = (v1 + v2).normalize();
+ norm[i] *= 1.0 / v1.dot(norm[i]);
+ }
+ return norm;
+ }
+
/** Draws an irregular edge.
* The edge specified in paper coordinates.
*
Index: gzz/gfx/libutil/effects.py
diff -u gzz/gfx/libutil/effects.py:1.24 gzz/gfx/libutil/effects.py:1.25
--- gzz/gfx/libutil/effects.py:1.24 Mon Nov 4 05:38:55 2002
+++ gzz/gfx/libutil/effects.py Wed Dec 11 07:20:06 2002
@@ -4,14 +4,14 @@
import gzz
import java
import math
-from gfx.libutil.nvcode import combinercode
+from gfx.libutil.nvcode import parseCombiner
from gfx.libpaper.texcache import getCachedTexture
class IrreguFrame(IrregularFrame):
dicefactor = 0.8
tex = GL.createTexture()
- tex.shade(128, 128, 0, 4, "RGBA", "RGBA",
+ tex.shade(128, 128, 0, 1, "INTENSITY", "LUMINANCE",
"sawnoise", ["bias", "0.5",
"scale", "0.15", "freq", "1", "df", "2",
"scale2", "0.25", "freq2", "10", "df2", ".5"])
@@ -86,40 +86,19 @@
"color" : gzz.util.ColorUtil.colorGLString(color)}
def code2(color):
- return combinercode("""
+ return parseCombiner("""
PushAttrib ENABLE_BIT TEXTURE_BIT
-
CombinerParameterNV CONSTANT_COLOR0_NV %(color)s 1
-
+
Enable REGISTER_COMBINERS_NV
- CombinerParameterNV NUM_GENERAL_COMBINERS_NV 2
- # SPARE0 <- TEXTURE0 . COLOR
- CI0 RGB A TEXTURE0 UNSIGNED_IDENTITY_NV RGB
- CI0 RGB B PRIMARY_COLOR_NV UNSIGNED_IDENTITY_NV RGB
- CO0 RGB SPARE0_NV DISCARD_NV DISCARD_NV NONE NONE TRUE FALSE
FALSE
-
- # SPARE0.alpha <- TEXTURE0.alpha * COLOR.alpha + SEC_COLOR.b
- CI0 ALPHA A TEXTURE0 UNSIGNED_IDENTITY_NV ALPHA
- CI0 ALPHA B PRIMARY_COLOR_NV UNSIGNED_IDENTITY_NV ALPHA
- CI0 ALPHA C SECONDARY_COLOR_NV UNSIGNED_IDENTITY_NV BLUE
- CI0 ALPHA D ZERO UNSIGNED_INVERT_NV ALPHA
- CO0 ALPHA DISCARD_NV DISCARD_NV SPARE0_NV NONE NONE FALSE
FALSE FALSE
-
- # SPARE0.alpha <- SPARE0 + SPARE0.alpha
- CI1 ALPHA A SPARE0_NV UNSIGNED_IDENTITY_NV BLUE
- CI1 ALPHA B ZERO UNSIGNED_INVERT_NV ALPHA
- CI1 ALPHA C SPARE0_NV UNSIGNED_IDENTITY_NV ALPHA
- CI1 ALPHA D ZERO UNSIGNED_INVERT_NV ALPHA
- CO1 ALPHA DISCARD_NV DISCARD_NV SPARE0_NV NONE NONE FALSE
FALSE FALSE
-
- # color <- CONTANT_COLOR0
- # alpha <- SPARE0.alpha
- FCI A ZERO UNSIGNED_IDENTITY_NV RGB
- FCI B ZERO UNSIGNED_IDENTITY_NV RGB
- FCI C ZERO UNSIGNED_IDENTITY_NV RGB
- FCI D CONSTANT_COLOR0_NV UNSIGNED_IDENTITY_NV RGB
- FCI G SPARE0_NV UNSIGNED_IDENTITY_NV ALPHA
+ SPARE0 = TEX0 . COL0
+ SPARE0.alpha = TEX0.alpha * COL0.alpha + COL1.blue
+
+ SPARE0.alpha = SPARE0.blue + SPARE0.alpha
+
+ alpha = SPARE0.alpha
+ color = CONST0
BindTexture TEXTURE_2D %(tex)s
TexParameter TEXTURE_2D TEXTURE_MIN_FILTER LINEAR_MIPMAP_LINEAR
@@ -128,6 +107,8 @@
Enable ALPHA_TEST
AlphaFunc GEQUAL 1.0
+
+ Color 0 0 0 1
""") % {"tex" : self.tex2.getTexId(),
"color" : gzz.util.ColorUtil.colorGLString(color)}
@@ -146,10 +127,34 @@
if ratio < 3./4 or ratio > 4./3:
print "WARNING: anisotropy ratio", round(ratio,2), "is far
from one"
- self._content = GLRen.createIrregularEllipse(
- texscale, ripple_scale, 0, code2(contentColor), 1)
- self._frame = GLRen.createIrregularEllipse(
- texscale, ripple_scale, 1, code2(frameColor), 1)
+ # Irregu flags
+ Y_COLOR = 1;
+ Y_SECCOLOR = 2;
+ DOTVEC_COLOR = 4;
+ INTERP_DOTVEC = 8;
+ SLICE_1D = 16;
+ SLICE_2D = 32;
+ SHIFTS = 64;
+ INSIDE = 128;
+ SHIFTS8 = 256;
+
+ self._content = GLRen.createIrregularEdge(
+ 0, texscale, 2.0, 128, 0,
+ -.5 * ripple_scale * texscale,
+ .5 * ripple_scale * texscale,
+ 0, "1 1 1 1 0 0 0 0", "", 3, 0,
+ SLICE_1D + Y_SECCOLOR + INSIDE,
+ code2(contentColor),
+ 1.0)
+
+ self._frame = GLRen.createIrregularEdge(
+ 0, texscale, 2.0, 128, 0,
+ -.5 * ripple_scale * texscale,
+ .5 * ripple_scale * texscale,
+ 0, "1 1 1 1 0 0 0 0", "", 3, 0,
+ SLICE_1D + Y_SECCOLOR + DOTVEC_COLOR + INTERP_DOTVEC,
+ code2(frameColor),
+ 1.0)
def getContent(self): return self._content
def getFrame(self): return self._frame
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gzz-commits] gzz/gfx demo/irregu4.py librenderables/renderab...,
Janne V. Kujala <=