hi, its not homework its because im using the class glmodel from glgraphics library and i cannot use stuff like rotate in that class. Im still having some problems, when i apply too much rotation it get distortion.
Any idea of why is this?
here is the code
Code:
import geomerative.*;
import javax.media.opengl.GL;
import processing.opengl.*;
import codeanticode.glgraphics.*;
GLCamera cam;
GLModel model;
float[] coords;
float[] colors;
float[] x;
float[] y;
float[] dx;
float[] dy;
float[] direccion;
float[] delta_x;
float[] delta_y;
float velocidad = 3;
//float direccion = random(TWO_PI);
int numPoints = 1154;
float distance = 4200;
//***********<geomerative>****************
RFont f;
RShape grp;
RPoint[] points;
RCommand curva = new RCommand(20 , 0, -400, -200, 200, -200, 0, -100);
RCommand curva_two = new RCommand(0 , -100, -400, -200, 200, -200, 0, -300);
RCommand[] piezas = new RCommand[5];
RCommand[] piezas_two = new RCommand[5];
int augment = 0;
float move_x ;
float move_y ;
int switcher = 0;
float mueve_letra_x = 48;
float mueve_letra_y = 38;
// mueve_letra_x es 48
// mueve_letra_y es 38;
//**********</geomerative>****************
void setup()
{
size(640, 480, GLConstants.GLGRAPHICS);
RG.init(this);
grp = RG.getText("a abc d a a a a a a a a ", "matteo.ttf", 12, CENTER);
points = grp.getPoints();
print(points);
cam = new GLCamera(this, 0, 0, distance, 0, 0, 0);
model = new GLModel(this, numPoints, POINTS, GLModel.DYNAMIC);
model.initColors();
x = new float[numPoints];
y = new float[numPoints];
dx = new float[numPoints];
dy = new float[numPoints];
delta_x = new float[numPoints];
delta_y = new float[numPoints];
direccion = new float[numPoints];
coords = new float[4 * numPoints];
colors = new float[4 * numPoints];
for (int i = 0; i < numPoints; i++)
{
x[i] = random(642);
y[i] = random(482);
dx[i] = random(642);
dy[i] = random(482);
direccion[i] = int(random(TWO_PI));
for (int j = 0; j < 3; j++) coords[4 * i + j] = 11 * random(-1, 1);
for (int j = 0; j < 3; j++) colors[4 * i + j ]= 0;
colors[4 * i + 3] = 0.5;
}
model.updateVertices(coords);
model.updateColors(colors);
}
void draw()
{
GLGraphics renderer = (GLGraphics)g;
GL gl = renderer.beginGL();
RG.setPolygonizer(RG.UNIFORMSTEP);
RG.setPolygonizerStep(4);
points = grp.getPoints();
augment = augment + 1;
piezas = curva.split(map(augment, 0, width, 0, 1));
piezas_two = curva_two.split(map(augment, 0, width, 0, 1));
if (switcher == 0 ) {
mueve_letra_x = piezas[0].endPoint.x;
mueve_letra_y = piezas[0].endPoint.y;
}
else if (switcher ==1) {
mueve_letra_x = piezas_two[0].endPoint.x;
mueve_letra_y = piezas_two[0].endPoint.y;
}
if (piezas[0].endPoint.x == 0 ) {
switcher = 1;
augment = 0;
}
noFill();
stroke(0,50);
curva.draw();
curva_two.draw();
stroke(255, 0, 0, 255);
ellipse(move_x , move_y, 10, 10);
stroke(0, 255, 0, 255);
piezas[1].draw();
piezas_two[1].draw();
//*******************</geomerative>*************
for (int i = 0; i < numPoints; i++){
float d = dist(x[i] , y[i] , points[i].x , points[i].y );
// float d = dist(x[i] , y[i] , points[i/52].x * -1 , points[i/52].y * -1);
if (mousePressed == true) {
delta_x[i] = 253 * (points[i].x + 239 - x[i] ) / d ;
delta_y[i] = 253 * (points[i].y + 288 - y[i] ) / d ;
}
else {
delta_x[i] = 0;
delta_y[i] = 0;
}
float radianes = radians(40);
direccion[i] = direccion[i] + random ( - radianes , radianes);
////////////////////////////////////////////////////////
dx[i] = velocidad * cos(direccion[i]);
dy[i] = velocidad * sin(direccion[i]);
x[i] = x[i] + dx[i]/6 + delta_x[i]/1 /1 ;
y[i] = y[i] + dy[i]/6 + delta_y[i]/1 / 1 ;
coords[4 * i ] = x[i]/6.5 - mueve_letra_x/5 - 64;
coords[4 * i + 1 ] = y[i]/6.5 * -1 + mueve_letra_y/5 + 64;
// Xrotated = X * COS(angle) - Y * SIN(angle)
//Yrotated = X * SIN(angle) + Y * COS(angle)
coords[4 * i ] = coords[4 * i ] * cos(mouseX * 0.003) - coords[4 * i + 1 ] * sin(mouseX * 0.003);
coords[4 * i + 1 ] = coords[4 * i] * sin(mouseX * 0.003) + coords[4 * i + 1 ] * cos(mouseX * 0.003);
}
model.updateVertices(coords);
cam.feed();
cam.clear(255, 255 , 255);
gl.glPointSize(1);
//gl.glLineWidth(8);
model.render();
cam.done();
renderer.endGL();
// println(frameRate);
}