From a39577bf6661bcb962a7329abbebc66e501b1dac Mon Sep 17 00:00:00 2001 From: Pavel Govyadinov Date: Tue, 14 Apr 2015 14:02:46 -0500 Subject: [PATCH] Changes to the spider class: New method to remove redundant code --- gl/gl_spider.h | 56 ++++++++++++++------------------------------------------ 1 file changed, 14 insertions(+), 42 deletions(-) diff --git a/gl/gl_spider.h b/gl/gl_spider.h index 2847376..96a5c49 100644 --- a/gl/gl_spider.h +++ b/gl/gl_spider.h @@ -92,18 +92,7 @@ class gl_spider : public virtual gl_texture setPosition(0.0,0.0,0.0); setDirection(1.0,1.0,1.0); setMagnitude(0.1,0.1); - stim::vec Y(1.0,0.0,0.0); - if(cos(Y.dot(direction))< 0.087){ - Y[0] = 0.0; Y[1] = 1.0;} - /* - hor = stim::rect(position, direction, Y); - hor.scale(magnitude[0], magnitude[1]); - ver = stim::rect(position, direction, (Y.cross(direction)).norm()); - ver.scale(magnitude[0], magnitude[1]); - */ - hor = stim::rect(magnitude, position, direction, Y); - ver = stim::rect(magnitude, position, direction, - (Y.cross(direction)).norm()); + Update(); } gl_spider @@ -112,18 +101,7 @@ class gl_spider : public virtual gl_texture position = pos; direction = dir; magnitude = mag; - vec Y(1.0,0.0,0.0); - if(cos(Y.dot(direction))< 0.087){ - Y[0] = 0.0; Y[1] = 1.0;} - /* - hor = stim::rect(position, direction, Y); - hor.scale(magnitude[0], magnitude[1]); - ver = stim::rect(position, direction, (Y.cross(direction)).norm()); - ver.scale(magnitude[0], magnitude[1]); - */ - hor = stim::rect(magnitude, position, direction, Y); - ver = stim::rect(magnitude, position, direction, - (Y.cross(direction)).norm()); + Update(); } //temporary cost for convenience. gl_spider @@ -133,35 +111,35 @@ class gl_spider : public virtual gl_texture setPosition(pos_x, pos_y, pos_z); setDirection(dir_x, dir_y, dir_z); setMagnitude(mag_x, mag_y); + Update(); + } + + void + Update() + { vec Y(1.0,0.0,0.0); if(cos(Y.dot(direction))< 0.087){ Y[0] = 0.0; Y[1] = 1.0;} - /* - hor = stim::rect(position, direction, Y); - hor.scale(magnitude[0], magnitude[1]); - ver = stim::rect(position, direction, (Y.cross(direction)).norm()); - ver.scale(magnitude[0], magnitude[1]); - */ hor = stim::rect(magnitude, position, direction.norm(), ((Y.cross(direction)).cross(direction)).norm()); ver = stim::rect(magnitude, position, direction.norm(), hor.n()); } - + vec - getCurrentPosition() + getPosition() { return position; } vec - getCurrentDirection() + getDirection() { return direction; } vec - getCurrentMagnitude() + getMagnitude() { return magnitude; } @@ -212,14 +190,8 @@ class gl_spider : public virtual gl_texture { std::cout << position[0] << "," << position[1] << "," << position[1] << std::endl; - setPosition(direction*magnitude[1]+position); - vec Y(1.0,0.0,0.0); - if(cos(Y.dot(direction))< 0.087){ - Y[0] = 0.0; Y[1] = 1.0;} - hor = stim::rect(magnitude, position, direction.norm(), - ((Y.cross(direction)).cross(direction)).norm()); - ver = stim::rect(magnitude, position, direction.norm(), - hor.n()); + setPosition(direction*magnitude[1]/2+position); + Update(); std::cout << position[0] << "," << position[1] << "," << position[1] << std::endl; -- libgit2 0.21.4