mirror of
https://github.com/processing/processing4.git
synced 2026-04-19 18:59:18 +02:00
Updated opengl examples
This commit is contained in:
@@ -21,7 +21,6 @@ class Particle {
|
||||
part.vertex(-partSize/2, +partSize/2, 0, sprite.height);
|
||||
part.end();
|
||||
|
||||
// Getting original location doesn't work (somehwo
|
||||
rebirth(width/2,height/2);
|
||||
lifespan = random(255);
|
||||
}
|
||||
@@ -53,9 +52,7 @@ class Particle {
|
||||
lifespan = lifespan - 1;
|
||||
velocity.add(gravity);
|
||||
|
||||
// Tint not working
|
||||
part.tint(255,lifespan);
|
||||
part.translate(velocity.x, velocity.y);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Ariel and V3ga's arcball class with a couple tiny mods by Robert Hodgin
|
||||
|
||||
class Arcball{
|
||||
class Arcball {
|
||||
float center_x, center_y, radius;
|
||||
Vec3 v_down, v_drag;
|
||||
Quat q_now, q_down, q_drag;
|
||||
@@ -22,7 +22,7 @@ class Arcball{
|
||||
q_drag = new Quat();
|
||||
|
||||
axisSet = new Vec3[] {new Vec3(1.0f, 0.0f, 0.0f), new Vec3(0.0f, 1.0f, 0.0f), new Vec3(0.0f, 0.0f, 1.0f)};
|
||||
axis = -1; // no constraints...
|
||||
axis = -1; // no constraints...
|
||||
}
|
||||
|
||||
void mousePressed(){
|
||||
@@ -37,7 +37,6 @@ class Arcball{
|
||||
}
|
||||
|
||||
void run(){
|
||||
|
||||
q_now = Quat.mul(q_drag, q_down);
|
||||
applyQuat2Matrix(q_now);
|
||||
|
||||
|
||||
@@ -59,11 +59,9 @@ final float[][] DTVectorTable = {
|
||||
abstract class Curve3D {
|
||||
abstract void feval(float t, PVector p);
|
||||
abstract void deval(float t, PVector d);
|
||||
|
||||
abstract float fevalX(float t);
|
||||
abstract float fevalY(float t);
|
||||
abstract float fevalZ(float t);
|
||||
|
||||
abstract float devalX(float t);
|
||||
abstract float devalY(float t);
|
||||
abstract float devalZ(float t);
|
||||
@@ -74,15 +72,18 @@ abstract class Spline extends Curve3D {
|
||||
int factorial(int n) {
|
||||
return n <= 0 ? 1 : n * factorial(n - 1);
|
||||
}
|
||||
|
||||
// Gives n!/(i!(n-i)!).
|
||||
int binomialCoef(int i, int n) {
|
||||
if ((i <= MAX_BEZIER_ORDER) &&(n <= MAX_BEZIER_ORDER)) return BinomialCoefTable[i][n - 1];
|
||||
else return int(factorial(n) /(factorial(i) * factorial(n - i)));
|
||||
if ((i <= MAX_BEZIER_ORDER) && (n <= MAX_BEZIER_ORDER)) return BinomialCoefTable[i][n - 1];
|
||||
else return int(factorial(n) / (factorial(i) * factorial(n - i)));
|
||||
}
|
||||
|
||||
// Evaluates the Berstein polinomial(i, n) at u.
|
||||
float bersteinPol(int i, int n, float u) {
|
||||
return binomialCoef(i, n) * pow(u, i) * pow(1 - u, n - i);
|
||||
}
|
||||
|
||||
// The derivative of the Berstein polinomial.
|
||||
float dbersteinPol(int i, int n, float u) {
|
||||
float s1, s2;
|
||||
@@ -95,9 +96,23 @@ abstract class Spline extends Curve3D {
|
||||
}
|
||||
|
||||
class BSpline extends Spline {
|
||||
// Control points.
|
||||
float[][] bsplineCPoints;
|
||||
|
||||
// Parameters.
|
||||
boolean lookup;
|
||||
|
||||
// Auxiliary arrays used in the calculations.
|
||||
float[][] M3;
|
||||
float[] TVector, DTVector;
|
||||
|
||||
// Point and tangent vectors.
|
||||
float[] pt, tg;
|
||||
|
||||
BSpline() {
|
||||
initParameters(true);
|
||||
}
|
||||
|
||||
BSpline(boolean t) {
|
||||
initParameters(t);
|
||||
}
|
||||
@@ -112,6 +127,7 @@ class BSpline extends Spline {
|
||||
tg = new float[3];
|
||||
lookup = t;
|
||||
}
|
||||
|
||||
// Sets n-th control point.
|
||||
void setCPoint(int n, PVector P) {
|
||||
bsplineCPoints[n][0] = P.x;
|
||||
@@ -142,7 +158,6 @@ class BSpline extends Spline {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Updates the temporal matrix used in order 3 calculations.
|
||||
void updateMatrix3() {
|
||||
float s;
|
||||
@@ -160,6 +175,7 @@ class BSpline extends Spline {
|
||||
evalPoint(t);
|
||||
p.set(pt);
|
||||
}
|
||||
|
||||
void deval(float t, PVector d) {
|
||||
evalTangent(t);
|
||||
d.set(tg);
|
||||
@@ -169,10 +185,12 @@ class BSpline extends Spline {
|
||||
evalPoint(t);
|
||||
return pt[0];
|
||||
}
|
||||
|
||||
float fevalY(float t) {
|
||||
evalPoint(t);
|
||||
return pt[1];
|
||||
}
|
||||
|
||||
float fevalZ(float t) {
|
||||
evalPoint(t);
|
||||
return pt[2];
|
||||
@@ -182,10 +200,12 @@ class BSpline extends Spline {
|
||||
evalTangent(t);
|
||||
return tg[0];
|
||||
}
|
||||
|
||||
float devalY(float t) {
|
||||
evalTangent(t);
|
||||
return tg[1];
|
||||
}
|
||||
|
||||
float devalZ(float t) {
|
||||
evalTangent(t);
|
||||
return tg[2];
|
||||
@@ -284,18 +304,4 @@ class BSpline extends Spline {
|
||||
tg[j] = s;
|
||||
}
|
||||
}
|
||||
|
||||
// Control points.
|
||||
float[][] bsplineCPoints;
|
||||
|
||||
// Parameters.
|
||||
boolean lookup;
|
||||
|
||||
// Auxiliary arrays used in the calculations.
|
||||
float[][] M3;
|
||||
float[] TVector, DTVector;
|
||||
|
||||
// Point and tangent vectors.
|
||||
float[] pt, tg;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,11 +11,15 @@ int LHANDED = -1;
|
||||
int RHANDED = 1;
|
||||
|
||||
void createRibbonModel(ArrayList residues, PShape model, ArrayList trj) {
|
||||
ArrayList vertices;
|
||||
ArrayList normals;
|
||||
vertices = new ArrayList();
|
||||
normals = new ArrayList();
|
||||
// For line ribbons
|
||||
ArrayList vertices0 = new ArrayList();
|
||||
ArrayList vertices1 = new ArrayList();
|
||||
ArrayList vertices2 = new ArrayList();
|
||||
|
||||
// For flat ribbons
|
||||
ArrayList vertices = new ArrayList();
|
||||
ArrayList normals = new ArrayList();
|
||||
|
||||
if (ribbonDetail == 1) uspacing = 10;
|
||||
else if (ribbonDetail == 2) uspacing = 5;
|
||||
else if (ribbonDetail == 3) uspacing = 2;
|
||||
@@ -35,16 +39,42 @@ void createRibbonModel(ArrayList residues, PShape model, ArrayList trj) {
|
||||
constructControlPoints(residues, i, ss[i], handness[i]);
|
||||
|
||||
if (renderMode == 0) {
|
||||
generateSpline(0, vertices);
|
||||
generateSpline(1, vertices);
|
||||
generateSpline(2, vertices);
|
||||
generateSpline(0, vertices0);
|
||||
generateSpline(1, vertices1);
|
||||
generateSpline(2, vertices2);
|
||||
}
|
||||
else generateFlatRibbon(vertices, normals);
|
||||
else {
|
||||
generateFlatRibbon(vertices, normals);
|
||||
}
|
||||
}
|
||||
|
||||
if (renderMode == 0) {
|
||||
// not implemented
|
||||
model = createShape();
|
||||
model.stroke(ribbonColor);
|
||||
model.noFill();
|
||||
model.beginContour();
|
||||
for (int i = 0; i < vertices0.size(); i++) {
|
||||
PVector posVec = (PVector)vertices0.get(i);
|
||||
model.vertex(posVec.x, posVec.y, posVec.z);
|
||||
}
|
||||
model.endContour();
|
||||
model.beginContour();
|
||||
for (int i = 0; i < vertices1.size(); i++) {
|
||||
PVector posVec = (PVector)vertices1.get(i);
|
||||
model.vertex(posVec.x, posVec.y, posVec.z);
|
||||
}
|
||||
model.endContour();
|
||||
model.beginContour();
|
||||
for (int i = 0; i < vertices2.size(); i++) {
|
||||
PVector posVec = (PVector)vertices2.get(i);
|
||||
model.vertex(posVec.x, posVec.y, posVec.z);
|
||||
}
|
||||
model.endContour();
|
||||
model.end(OPEN);
|
||||
} else {
|
||||
// The ribbon construction is fairly inneficient here, since
|
||||
// it could use triangle strips instead to avoid duplicating
|
||||
// shared vertices...
|
||||
model = createShape(TRIANGLES);
|
||||
model.noStroke();
|
||||
model.fill(ribbonColor);
|
||||
@@ -56,11 +86,15 @@ void createRibbonModel(ArrayList residues, PShape model, ArrayList trj) {
|
||||
}
|
||||
model.end();
|
||||
}
|
||||
//model.setColor(ribbonColor);
|
||||
|
||||
trj.add(model);
|
||||
|
||||
println("Adding new model with " + vertices.size() + " vertices.");
|
||||
if (renderMode == 0) {
|
||||
int totCount = vertices0.size() + vertices1.size() + vertices2.size();
|
||||
println("Adding new model with " + totCount + " vertices.");
|
||||
} else {
|
||||
println("Adding new model with " + vertices.size() + " vertices.");
|
||||
}
|
||||
}
|
||||
|
||||
float calculateGyrRadius(ArrayList atoms) {
|
||||
@@ -201,23 +235,21 @@ void generateSpline(int n, ArrayList vertices) {
|
||||
float u;
|
||||
PVector v0, v1;
|
||||
|
||||
v0 = new PVector();
|
||||
v1 = new PVector();
|
||||
|
||||
if (n == 0) splineSide1.feval(0, v1);
|
||||
else if (n == 1) splineCenter.feval(0, v1);
|
||||
else splineSide2.feval(0, v1);
|
||||
vertices.add(new PVector(v1.x, v1.y, v1.z));
|
||||
|
||||
for (ui = 1; ui <= 10; ui ++) {
|
||||
if (ui % uspacing == 0) {
|
||||
u = 0.1 * ui;
|
||||
v0.set(v1);
|
||||
|
||||
if (n == 0) splineSide1.feval(u, v1);
|
||||
else if (n == 1) splineCenter.feval(u, v1);
|
||||
else splineSide2.feval(u, v1);
|
||||
|
||||
vertices.add(new PVector(v0.x, v0.y, v0.z));
|
||||
vertices.add(new PVector(v1.x, v1.y, v1.z));
|
||||
}
|
||||
}
|
||||
@@ -461,4 +493,3 @@ void constructControlPoints(ArrayList residues, int res, int ss, int handness) {
|
||||
PVector linearComb(float scalar0, PVector vector0, float scalar1, PVector vector1) {
|
||||
return PVector.add(PVector.mult(vector0, scalar0), PVector.mult(vector1, scalar1));
|
||||
}
|
||||
|
||||
|
||||
@@ -103,19 +103,13 @@ void readPDB(String filename) {
|
||||
}
|
||||
|
||||
// Centering models at (0, 0, 0).
|
||||
// float dx = -0.5f * (xmin + xmax);
|
||||
// float dy = -0.5f * (ymin + ymax);
|
||||
// float dz = -0.5f * (zmin + zmax);
|
||||
// for (int n = 0; n < models.size(); n++) {
|
||||
// model = (PShape3D)models.get(n);
|
||||
// model.loadVertices();
|
||||
// for (int i = 0; i < model.getVertexCount(); i++) {
|
||||
// model.vertices[3 * i + 0] += dx;
|
||||
// model.vertices[3 * i + 1] += dy;
|
||||
// model.vertices[3 * i + 2] += dz;
|
||||
// }
|
||||
// model.updateVertices();
|
||||
// }
|
||||
float dx = -0.5f * (xmin + xmax);
|
||||
float dy = -0.5f * (ymin + ymax);
|
||||
float dz = -0.5f * (zmin + zmax);
|
||||
for (int n = 0; n < models.size(); n++) {
|
||||
model = (PShape) models.get(n);
|
||||
model.translate(dx, dy, dz);
|
||||
}
|
||||
|
||||
println("Loaded PDB file with " + models.size() + " models.");
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
// the structure using a ribbon representation.
|
||||
|
||||
String pdbFile = "4HHB.pdb"; // PDB file to read
|
||||
//String pdbFile = "2POR.pdb";
|
||||
//String pdbFile = "1CBS.pdb";
|
||||
//String pdbFile = "2POR.pdb";
|
||||
|
||||
// Some parameters to control the visual appearance:
|
||||
float scaleFactor = 5; // Size factor
|
||||
@@ -29,12 +29,10 @@ void setup() {
|
||||
}
|
||||
|
||||
void draw() {
|
||||
background(0);
|
||||
background(0);
|
||||
|
||||
lights();
|
||||
|
||||
if (renderMode == 1) {
|
||||
lights();
|
||||
}
|
||||
|
||||
translate(width/2, height/2, 200);
|
||||
arcball.run();
|
||||
|
||||
@@ -50,5 +48,3 @@ void mousePressed(){
|
||||
void mouseDragged(){
|
||||
arcball.mouseDragged();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -84,11 +84,11 @@ PVector evalPoint(float u, float v) {
|
||||
float z = c * sin(1.5 * t);
|
||||
|
||||
PVector dv = new PVector();
|
||||
dv.x = -1.5f * b * sin(1.5f * t) * cos(t) -
|
||||
(a + b * cos(1.5f * t)) * sin(t);
|
||||
dv.y = -1.5f * b * sin(1.5f * t) * sin(t) +
|
||||
(a + b * cos(1.5f * t)) * cos(t);
|
||||
dv.z = 1.5f * c * cos(1.5f * t);
|
||||
dv.x = -1.5 * b * sin(1.5 * t) * cos(t) -
|
||||
(a + b * cos(1.5 * t)) * sin(t);
|
||||
dv.y = -1.5 * b * sin(1.5 * t) * sin(t) +
|
||||
(a + b * cos(1.5 * t)) * cos(t);
|
||||
dv.z = 1.5 * c * cos(1.5 * t);
|
||||
|
||||
PVector q = dv;
|
||||
q.normalize();
|
||||
|
||||
@@ -16,7 +16,7 @@ void setup() {
|
||||
pg.beginDraw();
|
||||
pg.background(0, 0);
|
||||
pg.noStroke();
|
||||
pg.fill(255, 0, 0, 75);
|
||||
pg.fill(255, 0, 0, 200);
|
||||
pg.endDraw();
|
||||
|
||||
// Saving trefoil surface into a PShape3D object
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// Status: Fixed
|
||||
|
||||
/**
|
||||
* Move Eye.
|
||||
* by Simon Greenwold.
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// Status: Fixed
|
||||
|
||||
/**
|
||||
* Ortho vs Perspective.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// ISSUES: shapes containing curve vertices don't render properly
|
||||
|
||||
/**
|
||||
* Run-Amuck
|
||||
* By Ira Greenberg <br />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Blending, by Andres Colubri
|
||||
// Images can be blended using one of the 10 blending modes
|
||||
// available in OPENGL2.
|
||||
// available in P3D.
|
||||
// Images by Kevin Bjorke.
|
||||
|
||||
PImage pic1, pic2;
|
||||
|
||||
@@ -15,7 +15,7 @@ void setup()
|
||||
{
|
||||
size(640, 360, P3D);
|
||||
tex = loadImage("berlin-1.jpg");
|
||||
textureMode(NORMALIZED);
|
||||
textureMode(NORMAL);
|
||||
fill(255);
|
||||
stroke(color(44,48,32));
|
||||
}
|
||||
|
||||
@@ -33,6 +33,9 @@ void setup() {
|
||||
ln = new Line(words[i], 0, i * 70);
|
||||
lns[i] = ln;
|
||||
}
|
||||
|
||||
// To avoid letter occluding each other on the edges
|
||||
hint(DISABLE_DEPTH_TEST);
|
||||
}
|
||||
|
||||
void draw() {
|
||||
|
||||
Reference in New Issue
Block a user