chrismale
YaBB Newbies
Offline
Posts: 6
Re: opengl-mode so ... slow - how come?
Reply #2 - Mar 12th , 2006, 4:47pm
thanks a lot for the quick answer, mr. f! here's a bit of just-for-speed-testing-purposes-code i manufactured, here it slows down with more than 30000 for totalVertices: import damkjer.ocd.*; import processing.opengl.*; //initialize with settings: int totalVertices = 3000; int totverts = totalVertices/3; float camrot = -TWO_PI/200; int maxVal = 15000; float camDist = maxVal*2; color vertCol = color(100,50,50,255); boolean lighting = true; //initializing: Camera cam; int[][][] verts; void setup() { size(1000, 600, OPENGL); framerate(25); verts = new int[totverts][3][3]; for(int i=0; i<totverts; i++) { for(int u=0; u < 3; u++) { verts[i][u][0] = int(-maxVal/2 + random(maxVal)); verts[i][u][1] = int(-maxVal/2 + random(maxVal)); verts[i][u][2] = int(-maxVal/2 + random(maxVal)); } } cam = new Camera(this, camDist); } void draw() { background(0); fill(vertCol); strokeWeight(2); stroke(50,50,50); noStroke(); if(lighting) { lights(); } for(int i=0; i<totverts; i++) { beginShape(TRIANGLES); vertex(verts[i][0][0], verts[i][0][1], verts[i][0][2]); vertex(verts[i][1][0], verts[i][1][1], verts[i][1][2]); vertex(verts[i][2][0], verts[i][2][1], verts[i][2][2]); endShape(); } cam.circle(camrot); cam.feed(); } // Vec3D - simple 3D vector class // processing.unlekker.net class Vec3D { float x,y,z; Vec3D(float _x,float _y,float _z) { x=_x; y=_y; z=_z; } Vec3D(Vec3D v) { x=v.x; y=v.y; z=v.z; } void set(float _x,float _y,float _z) { x=_x; y=_y; z=_z; } void set(Vec3D v) { x=v.x; y=v.y; z=v.z; } void add(float _x,float _y,float _z) { x+=_x; y+=_y; z+=_z; } void add(Vec3D v) { x+=v.x; y+=v.y; z+=v.z; } void sub(float _x,float _y,float _z) { x-=_x; y-=_y; z-=_z; } void sub(Vec3D v) { x-=v.x; y-=v.y; z-=v.z; } void mult(float m) { x*=m; y*=m; z*=m; } void div(float m) { x/=m; y/=m; z/=m; } float length() { return sqrt(x*x+y*y+z*z); } void normalise() { float l=length(); if(l!=0) { x/=l; y/=l; z/=l; } } void rotateX(float val) { // Floats are not precise enough, so doubles are used for the calculations double cosval=Math.cos(val); double sinval=Math.sin(val); double tmp1=y*cosval - z*sinval; double tmp2=y*sinval + z*cosval; y=(float)tmp1; z=(float)tmp2; } void rotateY(float val) { // Floats are not precise enough, so doubles are used for the calculations double cosval=Math.cos(val); double sinval=Math.sin(val); double tmp1=x*cosval - z*sinval; double tmp2=x*sinval + z*cosval; x=(float)tmp1; z=(float)tmp2; } void rotateZ(float val) { // Floats are not precise enough, so doubles are used for the calculations double cosval=Math.cos(val); double sinval=Math.sin(val); double tmp1=x*cosval - y*sinval; double tmp2=x*sinval + y*cosval; x=(float)tmp1; y=(float)tmp2; } }