/** * Calculate the end of the directonal marker line. * * This is done by calculating the scale we need to multiply the directional marker by to * reach each of the three sides of the bounding box, then take the smallest of these, * because that is the side it will intersect. Finally, multiply by an overall scale factor. */ CC3Vector CC3DirectionMarkerNode::calculateLineEnd() { CC3Box pbb = getParentBoundingBox(); CC3Vector md = getMarkerDirection(); CC3Vector pbbDirScale = cc3v(calcScale( md.x, pbb.minimum.x, pbb.maximum.x ), calcScale( md.y, pbb.minimum.y, pbb.maximum.y ), calcScale( md.z, pbb.minimum.z, pbb.maximum.z )); //CC3_PUSH_NOSHADOW GLfloat dirScale = MIN(pbbDirScale.x, MIN(pbbDirScale.y, pbbDirScale.z)); dirScale = dirScale * getDirectionMarkerScale(); //CC3_POP_NOSHADOW // Ensure that the direction marker has the minimum length specified by directionMarkerMinimumLength if (directionMarkerMinimumLength) { GLfloat gblUniScale = getGlobalScale().length() / CC3Vector::kCC3VectorUnitCubeLength; GLfloat minScale = directionMarkerMinimumLength / gblUniScale; dirScale = MAX(dirScale, minScale); } CC3Vector lineEnd = md.scaleUniform( dirScale ); //LogTrace(@"%@ calculated line end %@ from pbb scale %@ and dir scale %.3f and min global length: %.3f", self, // NSStringFromCC3Vector(lineEnd), NSStringFromCC3Vector(pbbDirScale), dirScale, directionMarkerMinimumLength); return lineEnd; }
void PolynomialSurface::prepareEquationsAndDataPoints( GrayImage const& image, BinaryImage const& mask, std::vector<double>& equations, std::vector<double>& data_points) const { int const width = image.width(); int const height = image.height(); double const xscale = calcScale(width); double const yscale = calcScale(height); uint8_t const* image_line = image.data(); int const image_bpl = image.stride(); uint32_t const* mask_line = mask.data(); int const mask_wpl = mask.wordsPerLine(); int const last_word_idx = (width - 1) >> 5; int const last_word_mask = ~uint32_t(0) << (31 - ((width - 1) & 31)); for (int y = 0; y < height; ++y) { double const y_adjusted = y * yscale; int idx = 0; // Full words. for (; idx < last_word_idx; ++idx) { processMaskWord( image_line, mask_line[idx], idx, y, y_adjusted, xscale, equations, data_points ); } // Last word. processMaskWord( image_line, mask_line[idx] & last_word_mask, idx, y, y_adjusted, xscale, equations, data_points ); image_line += image_bpl; mask_line += mask_wpl; } }
// generate and save a bitmap for use by ATLC int EdgeCoupledEmbeddedMicrostrip2B1AWindow::drawBitmap() { if(!validateParams()) return -1; double boardHeight = params["H1"]->value() + params["H2"]->value() + params["H3"]->value() + params["T1"]->value() * 2; double tlineWidth = fmax(params["W1"]->value(), params["W2"]->value()) + params["S1"]->value(); calcScale(boardHeight, tlineWidth); int substrate1HeightPix = scale_factor * params["H1"]->value(); int substrate2HeightPix = scale_factor * params["H2"]->value(); int substrate3HeightPix = scale_factor * params["H3"]->value(); int traceThicknessPix = scale_factor * params["T1"]->value(); int traceSeparationPix = scale_factor * params["S1"]->value(); int lowerTraceWidthPix = scale_factor * params["W1"]->value(); int upperTraceWidthPix = scale_factor * params["W2"]->value(); // create the BMP that ATLC will use MakeBitmap bmp(width, height); // bottom copper (arbitrary thickness) bmp.drawRect(0, 0, width, traceThicknessPix, COLOR_COPPER_GND); // laminate bmp.drawRect(0, traceThicknessPix, width, substrate1HeightPix, COLOR_LAM1); bmp.drawRect(0, traceThicknessPix+substrate1HeightPix, width, substrate2HeightPix, COLOR_LAM2); bmp.drawRect(0, traceThicknessPix+substrate1HeightPix+substrate2HeightPix, width, substrate3HeightPix, COLOR_LAM3); // microstrip copper above second laminate bmp.drawTrapezoid( (width - 2*lowerTraceWidthPix - traceSeparationPix)/2, traceThicknessPix+substrate1HeightPix+substrate2HeightPix, lowerTraceWidthPix, upperTraceWidthPix, traceThicknessPix, COLOR_COPPER_POS); bmp.drawTrapezoid( (width - 2*lowerTraceWidthPix - traceSeparationPix)/2 + traceSeparationPix + lowerTraceWidthPix, traceThicknessPix+substrate1HeightPix+substrate2HeightPix, lowerTraceWidthPix, upperTraceWidthPix, traceThicknessPix, COLOR_COPPER_NEG); // draw enclosing boundary bmp.drawRectOutline(0, 0, width-1, height-1, 1, COLOR_COPPER_GND); // save bitmap file atlc->setEr(COLOR_LAM1, params["Er1"]->value()); atlc->setEr(COLOR_LAM2, params["Er2"]->value()); atlc->setEr(COLOR_LAM3, params["Er3"]->value()); bmp.save(atlc->simBitmap()); return 0; }
void GameObject::ScaleTo(float s) { float deltaScale = s/GetScale(); if(tObject == MESH){ myMesh.Scale.x = s; myMesh.Scale.y = s; myMesh.Scale.z = s; } else { myVertex.Radius = s; } calcScale(); for(auto it = children.begin(); it != children.end(); it++) (*it)->ScaleTo((*it)->GetScale()*deltaScale); }
void PolynomialSurface::prepareEquationsAndDataPoints( GrayImage const& image, std::vector<double>& equations, std::vector<double>& data_points) const { int const width = image.width(); int const height = image.height(); uint8_t const* line = image.data(); int const bpl = image.stride(); // Pretend that both x and y positions of pixels // lie in range of [0, 1]. double const xscale = calcScale(width); double const yscale = calcScale(height); for (int y = 0; y < height; ++y, line += bpl) { double const y_adjusted = yscale * y; for (int x = 0; x < width; ++x) { double const x_adjusted = xscale * x; data_points.push_back((1.0 / 255.0) * line[x]); double pow1 = 1.0; for (int i = 0; i <= m_vertDegree; ++i) { double pow2 = pow1; for (int j = 0; j <= m_horDegree; ++j) { equations.push_back(pow2); pow2 *= x_adjusted; } pow1 *= y_adjusted; } } } }
float CameraTool::find_view ( const SGR::vec3f& minvec, const SGR::vec3f& maxvec, float percentOfView ) { // translate SGR::vec3f center = ( minvec + maxvec ) / 2.0f; // scale float s = calcScale ( minvec, maxvec ); if ( s != 0 ) { _currentScale = percentOfView / s; camera_reset ( _pview->camid() ); camera_translate ( _pview->camid(), center.x(), center.y(), center.z() ); camera_scale ( _pview->camid(), _currentScale ); _currentTranslate.xyz ( center.x(), center.y(), center.z() ); } return _currentScale; }
void MeshOpt::runOptim(alglib::real_1d_array &x, const alglib::real_1d_array &initGradObj, int itMax) { static const double EPSG = 0.; static const double EPSF = 0.; static const double EPSX = 0.; _iter = 0; alglib::real_1d_array scale; calcScale(scale); int iterationscount = 0, nfev = 0, terminationtype = -1; alglib::mincgstate state; alglib::mincgreport rep; try { mincgcreate(x, state); mincgsetscale(state,scale); mincgsetprecscale(state); mincgsetcond(state, EPSG, EPSF, EPSX, itMax); mincgsetxrep(state, true); alglib::mincgoptimize(state, evalObjGradFunc, printProgressFunc, this); mincgresults(state, x, rep); } catch(alglib::ap_error &e) { Msg::Error("%s", e.msg.c_str()); } iterationscount = rep.iterationscount; nfev = rep.nfev; terminationtype = rep.terminationtype; if (_verbose > 2) { Msg::Info("Optimization finalized after %d iterations (%d function evaluations),", iterationscount, nfev); switch(int(terminationtype)) { case 1: Msg::Info("because relative function improvement is no more than EpsF"); break; case 2: Msg::Info("because relative step is no more than EpsX"); break; case 4: Msg::Info("because gradient norm is no more than EpsG"); break; case 5: Msg::Info("because the maximum number of steps was taken"); break; default: Msg::Info("with code %d", int(terminationtype)); break; } } }
GameObject::GameObject(Mesh* m, float& posX, float& posY, float& posZ, float& scale, float& rotX, float& rotY, float& rotZ, float dur,PositionType tPos) : //position(NULL), //color(&myMesh.Color), tObject(MESH), tPosition(tPos), velocity(0,0,0), lookDirection(1,0,0), mMeshOirentation(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1), duration(dur), parent(NULL) { myMesh.MeshToRender = m; myMesh.Position = D3DXVECTOR3(posX, posY, posZ);; //position = &myMesh.Position; myMesh.Color = D3DXCOLOR(0,0,0,0); //color = &myMesh.Color; myMesh.Scale = D3DXVECTOR3(scale, scale, scale); calcScale(); calcTranslation(); RotateTo(rotX, rotY, rotZ); }
void CameraTool::setCameraConstraint ( int nodeid, float percentOfView ) { float minarr[3], maxarr[3]; get_bbox ( nodeid, minarr, maxarr ); SGR::vec3f minvec(minarr), maxvec(maxarr); SGR::vec3f sz = (maxvec - minvec) / percentOfView; SGR::vec3f center = ( minvec + maxvec ) / 2.0f; QSize wndsize ( _pview->getWidth(), _pview->getHeight() ); if ( wndsize.width() > wndsize.height() ) sz.x ( (wndsize.width() / wndsize.height()) * sz.y () ); else sz.y ( (wndsize.height() / wndsize.width()) * sz.x () ); _minTranslate = center - (sz / 2.0f); _maxTranslate = center + (sz / 2.0f); _minScale = calcScale ( _minTranslate, _maxTranslate ); _maxScale = 1; _isInConstraintMode = true; }
void Slideshow::jumpSlide(int skip) { const int count = m_selection.count()>1 ? m_selection.count() : m_model->rowCount(QModelIndex()); m_pos = (m_pos + skip) % count; if(m_pos < 0) m_pos = count - m_pos; m_timertext->hide(); qDebug() << "next slide" << m_pos << "of" << count; QRectF view = m_scene->sceneRect(); int realpos; if(m_selection.count()>1) realpos = m_selection.at(m_pos); else realpos = m_pos; const Picture *pic = m_model->pictureAt(realpos); QGraphicsPixmapItem *newpic = new QGraphicsPixmapItem(pic->fullpath(m_gallery)); QRectF bounds = newpic->boundingRect(); newpic->setTransformOriginPoint(bounds.width()/2, bounds.height()/2); newpic->setPos(-bounds.width()/2.0, -bounds.height()/2.0); newpic->setRotation(pic->rotation()); // Scale image to fit screen, taking the rotation in account QRectF truebounds = newpic->mapRectToScene(bounds); qreal scale = calcScale(truebounds.size(), view.size()); newpic->setScale(scale); delete m_picture; m_picture = newpic; m_scene->addItem(m_picture); }
void M_scquantizer::generateCycle() { int l1, l3, quant, transpose; unsigned int l2; float lutquant = 0.0; if (base != lastbase) { calcScale(); } inData = port_M_in->getinputdata (); triggerData = port_M_trigger->getinputdata (); transposeData = port_M_transpose->getinputdata (); if (triggerData == synthdata->zeroModuleData) { for (l1 = 0; l1 < synthdata->poly; l1++) { quant = 1; for (l2 = 0; l2 < 128; l2++) { if (scale_notes[quant] > 4.0 + inData[l1][l2]) { lutquant = scale_notes[quant-1]; break; } else { quant++; } } for (l2 = 0; l2 < synthdata->cyclesize; l2++) { if (scale_notes[quant] > 4.0 + inData[l1][l2]) { lutquant = scale_notes[quant-1]; } if (qsig[l1] != lutquant) { qsig[l1] = lutquant; data[1][l1][l2] = 1.0; trigCount[l1] = 512; } else { if (trigCount[l1] > 0) { data[1][l1][l2] = 1; trigCount[l1]--; } else { data[1][l1][l2] = 0; } } transpose = (int)(transposeData[l1][l2] * 12.0); data[0][l1][l2] = (float)qsig[l1] - 4.0 + (float)(transpose + base) / 12.0; } } } else { for (l1 = 0; l1 < synthdata->poly; l1++) { for (l2 = 0; l2 < synthdata->cyclesize; l2++) { if (!trigger[l1] && (triggerData[l1][l2] > 0.5)) { trigger[l1] = true; quant = 1; for (l3 = 0; l3 < 128; l3++) { if (scale_notes[quant] > 4.0 + inData[l1][l2]) { break; } else { quant++; } } qsig[l1] = scale_notes[quant-1]; data[1][l1][l2] = 1.0; trigCount[l1] = 512; } else { if (trigger[l1] && (triggerData[l1][l2] < 0.5)) { trigger[l1] = false; } } if (trigCount[l1] > 0) { data[1][l1][l2] = 1; trigCount[l1]--; } else { data[1][l1][l2] = 0; } transpose = (int)(transposeData[l1][l2] * 12.0); data[0][l1][l2] = (float)qsig[l1] - 4.0 + (float)(transpose + base) / 12.0; } } } }
float SampleEditorControl::calcScale() { return calcScale(getVisibleLength()); }
void OptHOM::OptimPass(alglib::real_1d_array &x, int itMax) { static const double EPSG = 0.; static const double EPSF = 0.; static const double EPSX = 0.; static int OPTMETHOD = 1; Msg::Info("--- Optimization pass with initial jac. range (%g, %g), jacBar = %g", minJac, maxJac, jacBar); iter = 0; alglib::real_1d_array scale; calcScale(scale); int iterationscount = 0, nfev = 0, terminationtype = -1; if (OPTMETHOD == 1) { alglib::mincgstate state; alglib::mincgreport rep; try{ mincgcreate(x, state); mincgsetscale(state,scale); mincgsetprecscale(state); mincgsetcond(state, EPSG, EPSF, EPSX, itMax); mincgsetxrep(state, true); alglib::mincgoptimize(state, evalObjGradFunc, printProgressFunc, this); mincgresults(state, x, rep); } catch(alglib::ap_error e){ Msg::Error("%s", e.msg.c_str()); } iterationscount = rep.iterationscount; nfev = rep.nfev; terminationtype = rep.terminationtype; } else { alglib::minlbfgsstate state; alglib::minlbfgsreport rep; try{ minlbfgscreate(3, x, state); minlbfgssetscale(state,scale); minlbfgssetprecscale(state); minlbfgssetcond(state, EPSG, EPSF, EPSX, itMax); minlbfgssetxrep(state, true); alglib::minlbfgsoptimize(state, evalObjGradFunc, printProgressFunc, this); minlbfgsresults(state, x, rep); } catch(alglib::ap_error e){ Msg::Error("%s", e.msg.c_str()); } iterationscount = rep.iterationscount; nfev = rep.nfev; terminationtype = rep.terminationtype; } Msg::Info("Optimization finalized after %d iterations (%d function evaluations),", iterationscount, nfev); switch(int(terminationtype)) { case 1: Msg::Info("because relative function improvement is no more than EpsF"); break; case 2: Msg::Info("because relative step is no more than EpsX"); break; case 4: Msg::Info("because gradient norm is no more than EpsG"); break; case 5: Msg::Info("because the maximum number of steps was taken"); break; default: Msg::Info("with code %d", int(terminationtype)); break; } }
void Jumper::AirplaneJump::update(float dt) { updateAnimation( dt ); bool useWingsuit = database::Suit::getRecord( _jumper->getVirtues()->equipment.suit.id )->wingsuit; float phaseTime = useWingsuit ? trackInvSpeed * ( FRAMETIME(2113) - FRAMETIME(2104) ) : trackInvSpeed * ( FRAMETIME(1673) - FRAMETIME(1669) ); if( _actionTime > _blendTime + phaseTime ) { if( _phActor->isSleeping() ) { // place jumper to airplane exit Matrix4f clumpLTM = _clump->getFrame()->getLTM(); Vector3f clumpScale = calcScale( clumpLTM ); Matrix4f exitLTM = _jumper->getAirplaneExit()->getLTM(); orthoNormalize( exitLTM ); exitLTM[0][0] *= clumpScale[0], exitLTM[0][1] *= clumpScale[0], exitLTM[0][2] *= clumpScale[0]; exitLTM[1][0] *= clumpScale[1], exitLTM[1][1] *= clumpScale[1], exitLTM[1][2] *= clumpScale[1]; exitLTM[2][0] *= clumpScale[2], exitLTM[2][1] *= clumpScale[2], exitLTM[2][2] *= clumpScale[2]; _clump->getFrame()->setMatrix( exitLTM ); _clump->getFrame()->getLTM(); Matrix4f sampleLTM = Jumper::getCollisionFF( _clump )->getFrame()->getLTM(); _phActor->setGlobalPose( wrap( sampleLTM ) ); _phActor->wakeUp(); NxVec3 velH = wrap( _clump->getFrame()->getAt() ); velH.normalize(); velH *= 3.0f; NxVec3 velV = wrap( _clump->getFrame()->getUp() ); velV.normalize(); velV *= 0.25f; NxVec3 velA = wrap( _jumper->getAirplane()->getVel() ); _phActor->setLinearVelocity( velH + velV + velA ); _jumper->initOverburdenCalculator( velH + velV + velA ); // modified exits (only fixed wing, not heli) bool helicopter = strcmp(_jumper->getAirplane()->getDesc()->templateClump->getName(), "Helicopter01") == 0; if (!helicopter) { if (_jumper->getSpinalCord()->left) { _phActor->addLocalTorque(NxVec3(0,5700.0f,0)); //_phActor->setAngularDamping(2.0f); } else if (_jumper->getSpinalCord()->right) { _phActor->addLocalTorque(NxVec3(0,-5700.0f,0)); //_phActor->setAngularDamping(2.0f); } if (_jumper->getSpinalCord()->up) { // headdown exit _phActor->addLocalTorque(NxVec3(5700.0f,0,0)); } else if (_jumper->getSpinalCord()->down) { // sitfly exit _phActor->addLocalTorque(NxVec3(-8700.0f,0,0)); _phActor->addLocalForce(NxVec3(0,0,10000.0f)); } _phActor->setAngularDamping(2.0f); } } else { if (_jumper->getSpinalCord()->left) { _phActor->addLocalTorque(NxVec3(0,2000.0f*dt,0)); } else if (_jumper->getSpinalCord()->right) { _phActor->addLocalTorque(NxVec3(0,-2000.0f*dt,0)); } _clump->getFrame()->setMatrix( _matrixConversion->convert( wrap( _phActor->getGlobalPose() ) ) ); } } else { // place jumper to airplane exit Matrix4f clumpLTM = _clump->getFrame()->getLTM(); Vector3f clumpScale = calcScale( clumpLTM ); Matrix4f exitLTM = _jumper->getAirplaneExit()->getLTM(); Vector3f pos = _jumper->getAirplaneExit()->getPos(); getCore()->logMessage("exit pos: %2.2f %2.2f %2.2f", pos[0], pos[1], pos[2]); orthoNormalize( exitLTM ); exitLTM[0][0] *= clumpScale[0], exitLTM[0][1] *= clumpScale[0], exitLTM[0][2] *= clumpScale[0]; exitLTM[1][0] *= clumpScale[1], exitLTM[1][1] *= clumpScale[1], exitLTM[1][2] *= clumpScale[1]; exitLTM[2][0] *= clumpScale[2], exitLTM[2][1] *= clumpScale[2], exitLTM[2][2] *= clumpScale[2]; _clump->getFrame()->setMatrix( exitLTM ); } if( _clump->getAnimationController()->isEndOfAnimation( 0 )) // || (_jumper->getSpinalCord()->modifier && _jumper->isPlayer() && _actionTime > _blendTime + phaseTime )) { _endOfAction = true; } }