We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › (failed) rotate or camera at runtime
Page Index Toggle Pages: 1
(failed) rotate or camera at runtime (Read 792 times)
(failed) rotate or camera at runtime
Dec 25th, 2009, 9:17am
 
Hello,

I'm having a problem with this sketch. I'm using the draw function to put some matrices on display, but they are only drawn 3 times (one for each matrix) and then the conditional stops.

I would like to rotate freely around the displayed objects, but I can't. I've tried putting various rotateX/rotateY on draw(), and I've also played with putting a camera(), but not one responds in real-time, they only function on the 3 first iterations of the draw method.

Please, any advice on rotating the object (or camera) to see the dislay at various angles at runtime is appreciated!!!

Code:

import processing.opengl.*;
import de.cappelnord.ppm.*;

int dim;
int size = 24;

float drehI = 0.0;

PPMatrix m1;
PPMatrix m2;
PPMatrix m3;

PPMatrix[] history;

PPMatrixList list;
Iterator it;

boolean[][] mat1;
boolean[][] mat2;
boolean[][] mat3;

final static int NUM = 6;

float rotx = PI/4;
float roty = PI/4;

void mouseDragged() {
float rate = 0.01;
rotx += (pmouseY-mouseY) * rate;
roty += (mouseX-pmouseX) * rate;
}

void setup()
{
dim = PublicPixelMatrix.DIM;
size(1024, 576, OPENGL);
frameRate(25);
smooth();

mat1 = new boolean[dim][dim];
mat2 = new boolean[dim][dim];
mat3 = new boolean[dim][dim];

for(int i=0; i<dim; i++) {
for(int j=0; j<dim; j++) {
boolean bool = ((int)random(2)) == 1 ? true : false;
mat1[j][i] = bool;
}
}


arrayCopy(mat1, mat2);
arrayCopy(mat2, mat3);

m1 = new PPMatrix(1249422542, mat1);
m2 = new PPMatrix(1249422543, mat2);
m3 = new PPMatrix(1249422544, mat3);

list = new PPMatrixList();
list.add(m1);
list.add(m2);
list.add(m3);
//list = PublicPixelMatrix.readPPMatrixListFromURL("XXX");

it = list.iterator();

history = new PPMatrix[NUM];
}

void draw()
{
if(it.hasNext())
{
background(0);
noStroke();

PPMatrix matrix = (PPMatrix) it.next();

for(int i = history.length - 2; i >= 0; i--)
{
history[i+1] = history[i];
}
history[0] = matrix;

pushMatrix();
translate(width/2, height / 2 - ((dim * size) / 2));

drehI = drehI + 0.011;

rotateY( PI + (sin(drehI) * (PI/4)));
translate(-((dim * size) / 2),0);

for(int i = 0; i < history.length; i++)
{
if(history[i] != null)
{
pushMatrix();
translate(0,0,i*-80 );

float alpha = 255 - (((float) i / (float) history.length) * 220);

for(int y = 0; y < dim; y++)
{
for(int x = 0; x < dim; x++)
{
fill(0,history[i].get(x,y) ? 0 : 255,0, alpha);
rect(x * size, y * size, size , size);
}
}
popMatrix();
}
}
popMatrix();
fill(255);
}
///camera(rotx, 0., 0., 50.0, 50.0, 0.0, rotx, 1.0, 1.0);
}
Re: (failed) rotate or camera at runtime
Reply #1 - Dec 26th, 2009, 12:52pm
 
Try adding:
 if(it.hasNext())
 {
   ...
 }
 else
 {
   it = list.iterator();
 }
Re: (failed) rotate or camera at runtime
Reply #2 - Dec 26th, 2009, 1:37pm
 
Thank you very, very much JR for your help.

My problem is solved, and for future inquiries, I promise to be more empathic with any potential helpers.

Greetings,


-RT
Page Index Toggle Pages: 1