sam_mcelhinney
YaBB Newbies
Offline
Posts: 34
Re: classes question
Reply #4 - Oct 28th , 2008, 12:27pm
tab 2 (parent class) class Agent { int posA; int posB; float posX; float posY; float diam; int eye = 13; float head_turn = 0; float head_turn_previous = 0; float vector_1; float vector_2; float vector_3; float vector_4; float vector_speed; float left_rotate_vector; float right_rotate_vector; float rotate_vector; float rotate_vector_previous; Agent(int x, int y, float d){ posX = x; posY = y; diam = d; } void draw() { pushMatrix(); turn(); move(); translate(posA,posB); rotate(head_turn); ellipse(0,0,diam,diam); pushMatrix(); translate(eye,0); ellipse(0,0,diam/5,diam/5); rotate(-0.4*PI); pushMatrix(); for (int i = 0; i < depth_rays.length; i++) { depth_rays[i].draw(); depth_rays[i].detect(); rotate((0.8*PI)/(depth_rays.length - 1)); } popMatrix(); popMatrix(); popMatrix(); } Depth_ray [] depth_rays = {new Depth_ray(250,250,-2,150), new Depth_ray (250,250,-1,150), new Depth_ray(250,250,0,150), new Depth_ray(250,250,1,150), new Depth_ray(250,250,2,150)}; void turn() { degreeS = PI/180; vector_1 = (depth_rays[0].vector/depth_rays[0].ray_view); vector_2 = (depth_rays[1].vector/depth_rays[1].ray_view); vector_3 = (depth_rays[3].vector/depth_rays[3].ray_view); vector_4 = (depth_rays[4].vector/depth_rays[4].ray_view); left_rotate_vector = (((2*vector_1)+vector_2)/(vector_1+vector_2)); right_rotate_vector = (((2*vector_3)+vector_4)/(vector_3+vector_4)); rotate_vector = (right_rotate_vector - left_rotate_vector)*(36); // vector of rotation * angle between rays if (rotate_vector == rotate_vector_previous) { head_turn = head_turn; // number is in terms of PI bearing = bearing; // accumulative bearing is in terms of degrees } else { head_turn = head_turn+(rotate_vector*degreeS); // number is in terms of PI bearing = bearing+(rotate_vector); // accumulative bearing is in terms of degrees rotate_vector_previous = rotate_vector; } if (bearing > 359) { bearing = 0; head_turn = 0; } if (bearing < -359) { bearing = 0; head_turn = 0; } } void move() { vector_speed = (depth_rays[2].vector/depth_rays[2].ray_view); speed = 1*vector_speed; posX = posX+speed*(cos(bearing*degreeS)); posA = int (posX); posY = posY+speed*(sin(bearing*degreeS)); posB = int (posY); } }