/* get(u,i): returns the ith component of vector u */ func get { para u, i; return u[i]; }; /* add(u,v): returns the vector addition of vectors u and v */ func add { para u, v; return [u[1]+v[1], u[2]+v[2], u[3]+v[3]]; }; /* scale(s,v): returns the vector v multiplied by scalar s */ func scale { para s, v; return [v[1]*s, v[2]*s, v[3]*s]; }; /* unit(v): returns unit vector in direction of v */ func unit { para v; auto len; len = sqrt(float(v[1]*v[1] + v[2]*v[2] + v[3]*v[3])); if (len==0) return [@,@,@]; /* Stop divide by zero */ else return [(v[1]/len), (v[2]/len), (v[3]/len)]; }; /* dot(u,v): returns dot-product of vectors u and v */ func dot { para v; return (v[1]*u[1] + v[2]*u[2] + v[3]*u[3]); }; /* cross(u,v): returns cross-product of vectors u and v */ func cross { para u, v; return [(u[2]*v[3] - u[3]*v[2]), (u[3]*v[1] - u[1]*v[3]), (u[1]*v[2] - u[2]*v[1])]; }; /* JS-EDEN version */ func float { para x; return x; }; /* ## atan2 adapted from JavaScript in style of Matt Cranham - with conversion to degrees func atan2 { return ${{ Math.atan2(arguments[0])*180/Math.PI; }}$; }; */ ## to be consistent with EDEN conventions ... func atan2 { return ${{ Math.atan2(arguments[0], arguments[1]); }}$; }; func sin { return ${{ Math.sin(arguments[0]); }}$; }; func cos { return ${{ Math.cos(arguments[0]); }}$; }; /* Specification of view */ view_cen is [_x_pos,_y_pos,_z_pos]; view_norm is [-_x_dir, -_y_dir, -_z_dir]; view_theta is atan(_y_dir,_x_dir); view_up is [-_z_dir*cos(view_theta), -_z_dir*sin(view_theta), sqrt(_x_dir*_x_dir + _y_dir*_y_dir)]; eye_dist = 200; view_width = 200; view_height = 200; /* Calculate view plane x and z axis */ view_x is unit(cross(view_up,view_norm)); view_z is unit(view_norm); /* Definition of view: [Centre, View axis (x,y,z), Eye distance from plane] */ view is [view_cen, view_x, cross(view_z,view_x), view_z, eye_dist]; /* project(p,v): returns donald point of p projected into viewplane v */ func project { para p, v; auto pers, x, y, z; x = p[1] - v[1][1]; y = p[2] - v[1][2]; z = p[3] - v[1][3]; pers = 1 - (v[4][1]*x + v[4][2]*y + v[4][3]*z)/v[5]; if (pers <= 0) return [@, @]; /* At or behind eye */ else return [(v[2][1]*x + v[2][2]*y + v[2][3]*z)/pers, (v[3][1]*x + v[3][2]*y + v[3][3]*z)/pers]; };