void CColorAnimImp::SetColorAtPos( const ColorAnimNode& color, int x, int y ) { // x info had been processed by OnCtrlLBtDown() ColorAnimNode tColor = color; tColor.a = calcAlpha(y); (new ColorEditCmd(this,m_fCurSelPos,tColor))->Execute(); }
bool CColorAnimImp::OnCtrlMouseMove( int x, int y ) { if ( CEventState::GetInst()->GetState(MGT_MOUSE_LBUTTON) != MGT_MOUSE_LBNDOWN ) return false; ColorAnimNode new_node = getColor(m_fCurSelPos); CCombinCmd* pCtrlMove = new CCombinCmd; m_bUpdateLock = true; CCmdMgr::GetInst()->UnDo(); m_bUpdateLock = false; if ( CEventState::GetInst()->GetState(MGI_KEY_CtrlKey) != MGT_KEY_DOWN ) { pCtrlMove->Push(new ColorDelCmd(this,m_fCurSelPos)); if ( m_fCurSelPos > m_fCtrlPointHalfSize && m_fCurSelPos < 1.0f - m_fCtrlPointHalfSize ) { m_fCurSelPos = float(x)/m_clientSize.width; } } if ( m_fCurSelPos <= m_fCtrlPointHalfSize ) m_fCurSelPos = 0.0f; if ( m_fCurSelPos >= 1.0f - m_fCtrlPointHalfSize ) m_fCurSelPos = 1.0f; new_node.a = calcAlpha(y); pCtrlMove->Push(new ColorInsCmd(this,m_fCurSelPos,new_node)); pCtrlMove->Execute(); return true; }
void HudGaugeRadarOrb::drawOutlinesHtl() { int i, last = NUM_ORB_RING_SLICES - 1; g3_start_instance_matrix(&vmd_zero_vector, &view_perturb, true); g3_start_instance_matrix(&vmd_zero_vector, &Player_obj->orient, true); gr_set_color(255, 255, 255); g3_render_sphere(&vmd_zero_vector, .05f); gr_set_line_width(2.0f); for (i = 0; i < NUM_ORB_RING_SLICES; i++) { gr_init_alphacolor(&Orb_color_orange, 192, 96, 32, calcAlpha(&orb_ring_xy[last])); gr_set_color_fast(&Orb_color_orange); //g3_draw_htl_line(&orb_ring_xy[last],&orb_ring_xy[i]); g3_render_line_3d(false, &orb_ring_xy[last],&orb_ring_xy[i]); gr_init_alphacolor(&Orb_color_teal, 48, 160, 96, calcAlpha(&orb_ring_xz[last])); gr_set_color_fast(&Orb_color_teal); //g3_draw_htl_line(&orb_ring_xz[last],&orb_ring_xz[i]); g3_render_line_3d(false, &orb_ring_xz[last],&orb_ring_xz[i]); gr_init_alphacolor(&Orb_color_purple, 112, 16, 192, calcAlpha(&orb_ring_yz[last])); gr_set_color_fast(&Orb_color_purple); //g3_draw_htl_line(&orb_ring_yz[last],&orb_ring_yz[i]); g3_render_line_3d(false, &orb_ring_yz[last],&orb_ring_yz[i]); last = i; } gr_set_line_width(1.0f); g3_done_instance(true); g3_done_instance(true); }
//following is at least half the algorithm //transforms each point locally //and computes numDist distances out to localLevel away void calcAppAniDel(double *vort, double *dist) { //big for loop. means do everything for every vector in vort. for (int x = 0; x < nx; x++) { for (int y = 0; y < ny; y++) { for (int z = 0; z < nz; z++) { //fprintf(stderr, "%d %d %d\n", x, y, z); //find transform based on this vector. double vX = GetArray(vort, x, y, z, 0); double vY = GetArray(vort, x, y, z, 1); double vZ = GetArray(vort, x, y, z, 2); double vNormSqr = vX*vX + vY*vY + vZ*vZ; //used alot double alpha = calcAlpha(sqrt(vNormSqr)); //used equally alot //fprintf(stderr, "%e %f\n", vNormSqr, alpha); //fprintf(stderr, "%f %f %f\n", vX, vY, vZ); double *metricTensor = calcMetricTensor(vX, vY, vZ, vNormSqr, alpha); //calc distance and save in each point for (int boxX = 0; boxX < numDist; boxX++) { for (int boxY = 0; boxY < numDist; boxY++) { for (int boxZ = 0; boxZ < numDist; boxZ++) { //gridDist is global variable that determines grid spacing //void SetDist(double *a, double v, int i, int j, int k, int l) is function to set each distance double thisDist = 0.0; if (!((0 == boxX - localLevel) && (0 == boxY - localLevel) && (0 == boxZ - localLevel))) { // we don't set the distance to this point, just to all surrounding. // treat current vector tail as origin, compute distances with metricTensor // and put total in thisDist //first compute the array representing the difference between this point and the one //the distance to which is being calculated double *point = (double *)malloc(3 * sizeof(double)); point[0] = (boxX - localLevel) * gridDist; point[1] = (boxY - localLevel) * gridDist; point[2] = (boxZ - localLevel) * gridDist; //fprintf(stderr, "%f %f %f \n", point[0], point[1], point[2]); //first step is metric (3x3) times the point (3x1) resulting in a 3x1 matrix double *firstStep = (double *)malloc(3 * sizeof(double)); firstStep[0] = point[0] * metricTensor[0] + point[1] * metricTensor[1] + point[2] * metricTensor[2]; firstStep[1] = point[0] * metricTensor[3] + point[1] * metricTensor[4] + point[2] * metricTensor[5]; firstStep[2] = point[0] * metricTensor[6] + point[1] * metricTensor[7] + point[2] * metricTensor[8]; //fprintf(stderr, "%f %f %f \n", firstStep[0], firstStep[1], firstStep[2]); //now take the point as a 1x3 matrix times this 3x1 resulting in a 1x1 (scalar) value. thisDist = firstStep[0] * point[0] + firstStep[1] * point[1] + firstStep[2] * point[2] ; if (thisDist < 0.0) { thisDist = sqrt(-thisDist); } else { thisDist = sqrt(thisDist); } //the following lines transforms the dist in L2-norm to L(infinity)-norm //this cheap trick is only going to work for localLevel == 1 //since in that case all 26 points have the same L(infinite)-distance double normalDist = sqrt( point[0] * point[0] + point[1] * point[1] + point[2] * point[2] ); double infDist = abs(boxX - localLevel); if (infDist < abs(boxY - localLevel)) { infDist = abs(boxY - localLevel); } if (infDist < abs(boxZ - localLevel)) { infDist = abs(boxZ - localLevel); } //fprintf(stderr, "%f\n", infDist); thisDist = infDist*thisDist/normalDist; //end L(infinity)-norm conversion free(firstStep); free(point); //fprintf(stderr, "%e \n", thisDist); } SetDist(dist, thisDist, x, y, z, (boxZ + numDist * (boxY + numDist * boxX)) ); } } } //that should be it for this step. free(metricTensor); } } } }
int main (int argc, char **argv) { //moveToX=atoi(argv[1]); //moveToY=atoi(argv[2]); long X =atol(argv[1]); long Y =atol(argv[2]); printf("X=%d\nY=%d\n",X,Y); //printf("X=%d\n",X); // wiringPI StepUp wiringPiSetup(); pinMode (STEP_RIGHT, OUTPUT); pinMode (DIR_RIGHT, OUTPUT); pinMode (STEP_LEFT, OUTPUT); pinMode (DIR_LEFT, OUTPUT); // Pos actual p float MLp; float MRp; float Xp; float Yp; float lpp= ((8*3.141592)/400); // lpp long per step = 0,06283184 // Punt Inicial X0,Y0,ML0,MR0 float ML0 = 220.0; float MR0 = 667.0; // Motors distance float Dm = 845.0; //Inicial point float alpha=calcAlpha(ML0, MR0, Dm); printf("alpha=%6.6f\n",alpha); float X0 = calcPx(ML0, alpha); float Y0 = calcPy(ML0, alpha); printf("X0=%6.6f\n",X0); printf("Y0=%6.6f\n",Y0); //final point X,Y // line equation float m = ((Y-Y0)/(X-X0)); float b = (Y-(m*X)); printf("m=%6.6f\n",m); printf("b=%6.6f\n",b); //XY repect Origin float fX=(float)X+X0; float fY=(float)Y+Y0; printf("fX=%6.6f\nfY=%6.6f\n",fX,fY); int inc_dir=0; if ( (fabs(X0-fX)) > (fabs(Y0-fY)) ){//dir Horizontal if (X0<fX) inc_dir=1; //line Horizontal Y0-fY=0 if (X0>fX) inc_dir=2; } else { //dir Vertical if (Y0<fY) inc_dir=3; if (Y0>fY) inc_dir=4; } printf("inc_dir=%i\n",inc_dir); float newX=X0; float newY=Y0; float newAlpha=alpha; while ( (fabs(newX-fX)>0.1) || (fabs(newY-fY)>0.1) ){ printf ("fabs newX-fX >0.1 %5.5f",fabs(newX-fX)); printf ("fabs newY-fY >0.1 %5.5f",fabs(newY-fY)); //Valor to find, aprox if (inc_dir==1){ newX+=0.02; newY=(m*newX)+b; } if (inc_dir==2){ newX-=0.02; newY=(m*newX)+b; } if (inc_dir==3){ newY+=0.02; newX=(newY-b)/m; } if (inc_dir==4){ newY-=0.02; newX=(newY-b)/m; } // in leght float newML= calcMLp(newX, newY); float newMR= calcMRp(newX, newY, Dm); //printf(" ML0====%5.5f MR0=====%5.5f\n",ML0,MR0); //printf("newML====%5.5f mewMR====%5.5f\n",newML,newMR); //printf("fabs(newML-(ML0+lpp)=%5.5f+ fabs(newMR-MR0)=%5.5f\n",fabs(newML-(ML0+lpp)), fabs(newMR-MR0)); float error_a = fabs(newML-(ML0+lpp)) + fabs(newMR-MR0); float error_b = fabs(newML-(ML0-lpp)) + fabs(newMR-MR0); float error_c = fabs(newML-(ML0)) + fabs(newMR-(MR0+lpp)); float error_d = fabs(newML-(ML0)) + fabs(newMR-(MR0-lpp)); //printf("error_a=%3.3f-error_b=%3.3f-error_c=%3.3f-error_d=%3.3f\n" // ,error_a,error_b,error_c,error_d); if ((error_a < error_b) && (error_a < error_c) && (error_a < error_d)){ //MakeStepLeft(1); printf("error_a\n"); ML0+=lpp; float newAlpha=calcAlpha(ML0,MR0,Dm); newX=calcPx(ML0, newAlpha); newY=calcPy(ML0, newAlpha); } if ((error_b < error_a) && (error_b < error_c) && (error_b < error_d)){ //MakeStepLeft(0); printf("error_b\n"); ML0-=lpp; float newAlpha=calcAlpha(ML0,MR0,Dm); newX=calcPx(ML0, newAlpha); newY=calcPy(ML0, newAlpha); } if ((error_c < error_a) && (error_c < error_b) && (error_c < error_d)){ //MakeStepRight(1); printf("error_c\n"); MR0+=lpp; float newAlpha=calcAlpha(ML0,MR0,Dm); newX=calcPx(ML0, newAlpha); newY=calcPy(ML0, newAlpha); } if ((error_d < error_a) && (error_d < error_b) && (error_d < error_c)){ //MakeStepRight(0); printf("error_d\n"); MR0-=lpp; float newAlpha=calcAlpha(ML0,MR0,Dm); newX=calcPx(ML0, newAlpha); newY=calcPy(ML0, newAlpha); } printf("ML0=%6.6f-MR0=%6.6f-Dm=%6.6f\n",ML0,MR0,Dm); printf("newAlpha=%6.6f ",newAlpha); printf("newX=%6.6f ",newX); printf("newY=%6.6f\n",newY); delay(1000); }//while return 0; }
void readBitmapFontVersion0(ImBuf * ibuf, unsigned char * rect, int step) { int glyphcount, bytes, i, index, linelength, ysize; unsigned char * buffer; bmFont * bmfont; linelength = ibuf->x * step; glyphcount = (rect[6 * step] << 8) | rect[7 * step]; bytes = ((glyphcount - 1) * sizeof(bmGlyph)) + sizeof(bmFont); ysize = (bytes + (ibuf->x - 1)) / ibuf->x; if (ysize < ibuf->y) { // we're first going to copy all data into a liniar buffer. // step can be 4 or 1 bytes, and the data is not sequential because // the bitmap was flipped vertically. buffer = (unsigned char*)MEM_mallocN(bytes, "readBitmapFontVersion0:buffer"); index = 0; for (i = 0; i < bytes; i++) { buffer[i] = rect[index]; index += step; if (index >= linelength) { // we've read one line, no skip to the line *before* that rect -= linelength; index -= linelength; } } // we're now going to endian convert the data bmfont = (bmFont*)MEM_mallocN(bytes, "readBitmapFontVersion0:bmfont"); index = 0; // first read the header bmfont->magic[0] = buffer[index++]; bmfont->magic[1] = buffer[index++]; bmfont->magic[2] = buffer[index++]; bmfont->magic[3] = buffer[index++]; bmfont->version = (buffer[index] << 8) | buffer[index + 1]; index += 2; bmfont->glyphcount = (buffer[index] << 8) | buffer[index + 1]; index += 2; bmfont->xsize = (buffer[index] << 8) | buffer[index + 1]; index += 2; bmfont->ysize = (buffer[index] << 8) | buffer[index + 1]; index += 2; for (i = 0; i < bmfont->glyphcount; i++) { bmfont->glyphs[i].unicode = (buffer[index] << 8) | buffer[index + 1]; index += 2; bmfont->glyphs[i].locx = (buffer[index] << 8) | buffer[index + 1]; index += 2; bmfont->glyphs[i].locy = (buffer[index] << 8) | buffer[index + 1]; index += 2; bmfont->glyphs[i].ofsx = buffer[index++]; bmfont->glyphs[i].ofsy = buffer[index++]; bmfont->glyphs[i].sizex = buffer[index++]; bmfont->glyphs[i].sizey = buffer[index++]; bmfont->glyphs[i].advance = buffer[index++]; bmfont->glyphs[i].reserved = buffer[index++]; /* MAART: if (G.f & G_DEBUG) { printfGlyph(&bmfont->glyphs[i]); } */ } MEM_freeN(buffer); /* MAART: if (G.f & G_DEBUG) { printf("Oldy = %d Newy = %d\n", ibuf->y, ibuf->y - ysize); printf("glyphcount = %d\n", glyphcount); printf("bytes = %d\n", bytes); } */ // we've read the data from the image. Now we're going // to crop the image vertically so only the bitmap data // remains visible ibuf->y -= ysize; ibuf->userdata = bmfont; ibuf->userflags |= IB_BITMAPFONT; if (ibuf->depth < 32) { // we're going to fake alpha here: calcAlpha(ibuf); } } else { /* MAART: printf("readBitmapFontVersion0: corrupted bitmapfont\n"); */ } }
void LC_MakerCamSVG::writeEllipse(RS_Ellipse* ellipse) { RS_Vector center = convertToSvg(ellipse->getCenter()); const RS_Vector centerTranslation=center - ellipse->getCenter(); double majorradius = ellipse->getMajorRadius(); double minorradius = ellipse->getMinorRadius(); if (convertEllipsesToBeziers) { std::string path = ""; if (ellipse->isArc()) { const int segments = 4; RS_DEBUG->print("RS_MakerCamSVG::writeEllipse: Writing ellipse arc approximated by 'path' with %d cubic bézier segments (as discussed in https://www.spaceroots.org/documents/ellipse/elliptical-arc.pdf) ...", segments); double x_axis_rotation = 2 * M_PI - ellipse->getAngle(); double start_angle = 2 * M_PI - ellipse->getAngle2(); double end_angle = 2 * M_PI - ellipse->getAngle1(); if (ellipse->isReversed()) { double temp_angle = start_angle; start_angle = end_angle; end_angle = temp_angle; } if (end_angle <= start_angle) { end_angle += 2 * M_PI; } double total_angle = end_angle - start_angle; double alpha = calcAlpha(total_angle / segments); RS_Vector start_point = centerTranslation + ellipse->getEllipsePoint(start_angle); path = svgPathMoveTo(start_point); for (int i = 1; i <= segments; i++) { double segment_start_angle = start_angle + ((i - 1) / (double)segments) * total_angle; double segment_end_angle = start_angle + (i / (double)segments) * total_angle; RS_Vector segment_start_point = centerTranslation + ellipse->getEllipsePoint(segment_start_angle); RS_Vector segment_end_point = centerTranslation + ellipse->getEllipsePoint(segment_end_angle); RS_Vector segment_control_point_1 = segment_start_point + calcEllipsePointDerivative(majorradius, minorradius, x_axis_rotation, segment_start_angle) * alpha; RS_Vector segment_control_point_2 = segment_end_point - calcEllipsePointDerivative(majorradius, minorradius, x_axis_rotation, segment_end_angle) * alpha; path += svgPathCurveTo(segment_end_point, segment_control_point_1, segment_control_point_2); } } else { RS_DEBUG->print("RS_MakerCamSVG::writeEllipse: Writing ellipse approximated by 'path' with 4 cubic bézier segments (as discussed in http://www.tinaja.com/glib/ellipse4.pdf) ..."); const double kappa = 0.551784; RS_Vector major {majorradius, 0.0}; RS_Vector minor {0.0, minorradius}; RS_Vector flip_y {1.0, -1.0}; major.rotate(ellipse->getAngle()); minor.rotate(ellipse->getAngle()); major.scale(flip_y); minor.scale(flip_y); RS_Vector offsetmajor {major * kappa}; RS_Vector offsetminor {minor * kappa}; path = svgPathMoveTo(center - major) + svgPathCurveTo((center - minor), (center - major - offsetminor), (center - minor - offsetmajor)) + svgPathCurveTo((center + major), (center - minor + offsetmajor), (center + major - offsetminor)) + svgPathCurveTo((center + minor), (center + major + offsetminor), (center + minor + offsetmajor)) + svgPathCurveTo((center - major), (center + minor - offsetmajor), (center - major + offsetminor)) + svgPathClose(); } xmlWriter->addElement("path", NAMESPACE_URI_SVG); xmlWriter->addAttribute("d", path); xmlWriter->closeElement(); } else { if (ellipse->isArc()) { RS_DEBUG->print("RS_MakerCamSVG::writeEllipse: Writing ellipse arc as 'path' with arc segments ..."); double x_axis_rotation = 180 - (RS_Math::rad2deg(ellipse->getAngle())); double startangle = RS_Math::rad2deg(ellipse->getAngle1()); double endangle = RS_Math::rad2deg(ellipse->getAngle2()); if (endangle <= startangle) { endangle += 360; } bool large_arc_flag = ((endangle - startangle) > 180); bool sweep_flag = false; if (ellipse->isReversed()) { large_arc_flag = !large_arc_flag; sweep_flag = !sweep_flag; } std::string path = svgPathMoveTo(convertToSvg(ellipse->getStartpoint())) + svgPathArc(convertToSvg(ellipse->getEndpoint()), majorradius, minorradius, x_axis_rotation, large_arc_flag, sweep_flag); xmlWriter->addElement("path", NAMESPACE_URI_SVG); xmlWriter->addAttribute("d", path); xmlWriter->closeElement(); } else { RS_DEBUG->print("RS_MakerCamSVG::writeEllipse: Writing full ellipse as 'ellipse' ..."); double angle = 180 - (RS_Math::rad2deg(ellipse->getAngle()) - 90); std::string transform = "translate(" + numXml(center.x) + ", " + numXml(center.y) + ") " + "rotate(" + numXml(angle) + ")"; xmlWriter->addElement("ellipse", NAMESPACE_URI_SVG); xmlWriter->addAttribute("rx", numXml(minorradius)); xmlWriter->addAttribute("ry", numXml(majorradius)); xmlWriter->addAttribute("transform", transform); xmlWriter->closeElement(); } } }