float Audio::distToListener(const cml::vector2f &pos) { sf::Vector3f lpos3 = sf::Listener::GetPosition(); cml::vector2f lpos(lpos3.x, lpos3.y); return cml::length(pos - lpos); }
unsigned long decode_forward_until(bwttext * t, unsigned long pos, unsigned char until, int inclusive, strbuf * sb) { character * ch; unsigned char c; unsigned long occ, p = pos; do { // read next char in the first column // or the given char at pos c = fpos_char(t, p); // output the char if (c != until || inclusive) strbuf_putchar(sb, c); // break the loop if it meets the char until if (c == until) return p; // map the fpos to lpos // the next char is at lpos in the first column // so p will still be an fpos - an fpos for the next char ch = t->char_hash[(unsigned int) c]; occ = p - ch->ss; p = lpos(t, c, occ); // no next char for the last position (t->end) } while (p != t->end); // TODO p==t->end ? return p; }
void MatConstIterator::seek(ptrdiff_t ofs, bool relative) { if( m->isContinuous() ) { ptr = (relative ? ptr : sliceStart) + ofs*elemSize; if( ptr < sliceStart ) ptr = sliceStart; else if( ptr > sliceEnd ) ptr = sliceEnd; return; } int d = m->dims; if( d == 2 ) { ptrdiff_t ofs0, y; if( relative ) { ofs0 = ptr - m->ptr(); y = ofs0/m->step[0]; ofs += y*m->cols + (ofs0 - y*m->step[0])/elemSize; } y = ofs/m->cols; int y1 = std::min(std::max((int)y, 0), m->rows-1); sliceStart = m->ptr(y1); sliceEnd = sliceStart + m->cols*elemSize; ptr = y < 0 ? sliceStart : y >= m->rows ? sliceEnd : sliceStart + (ofs - y*m->cols)*elemSize; return; } if( relative ) ofs += lpos(); if( ofs < 0 ) ofs = 0; int szi = m->size[d-1]; ptrdiff_t t = ofs/szi; int v = (int)(ofs - t*szi); ofs = t; ptr = m->ptr() + v*elemSize; sliceStart = m->ptr(); for( int i = d-2; i >= 0; i-- ) { szi = m->size[i]; t = ofs/szi; v = (int)(ofs - t*szi); ofs = t; sliceStart += v*m->step[i]; } sliceEnd = sliceStart + m->size[d-1]*elemSize; if( ofs > 0 ) ptr = sliceEnd; else ptr = sliceStart + (ptr - m->ptr()); }
int main(int argc, char* argv[]) { omp_set_nested(1); stepMode = true; GPUSystem = new System(1); GPUSystem->mTimeStep = .001; GPUSystem->mEndTime = 35; GPUSystem->mNumObjects = 1; GPUSystem->mIterations = 100; GPUSystem->mTolerance = 1e-5; GPUSystem->mOmegaContact = .9; GPUSystem->mOmegaBilateral = .2; GPUSystem->mUseOGL = 1; float mMu = .5; float mWallMu = .5; if (argc == 2) { numY = atoi(argv[1]); } else { cout << "ARGS: number of particle layers in y direction" << endl; exit(1); } float container_R = 10.0, container_T = .1; ChQuaternion<> quat(1, 0, 0, 0); ChVector<> lpos(0, 0, 0); CHBODYSHAREDPTR L = CHBODYSHAREDPTR(new CHBODY); CHBODYSHAREDPTR R = CHBODYSHAREDPTR(new CHBODY); CHBODYSHAREDPTR F = CHBODYSHAREDPTR(new CHBODY); CHBODYSHAREDPTR B = CHBODYSHAREDPTR(new CHBODY); CHBODYSHAREDPTR BTM = CHBODYSHAREDPTR(new CHBODY); CHBODYSHAREDPTR FREE = CHBODYSHAREDPTR(new CHBODY); ChQuaternion<> quat2(1, 0, 0, 0); quat2.Q_from_AngAxis(PI / 6.0, ChVector<> (1, 0, 0)); //GPUSystem->InitObject(L, 100000, ChVector<> (-container_R, 0, 0), quat, mWallMu, mWallMu, 0, true, true, -20, -20); //GPUSystem->InitObject(R, 100000, ChVector<> (container_R, 0, 0), quat, mWallMu, mWallMu, 0, true, true, -20, -20); //GPUSystem->InitObject(F, 100000, ChVector<> (0, 0, -container_R), quat, mWallMu, mWallMu, 0, true, true, -20, -20); //GPUSystem->InitObject(B, 100000, ChVector<> (0, 0, container_R), quat, mWallMu, mWallMu, 0, true, true, -20, -20); GPUSystem->InitObject(BTM, 1, ChVector<> (0, -container_R, 0), quat, mWallMu, mWallMu, 0, true, true, -1000, -20000); //GPUSystem->AddCollisionGeometry(L, BOX, ChVector<> (container_T, container_R, container_R), lpos, quat); //GPUSystem->AddCollisionGeometry(R, BOX, ChVector<> (container_T, container_R, container_R), lpos, quat); //GPUSystem->AddCollisionGeometry(F, BOX, ChVector<> (container_R, container_R, container_T), lpos, quat); //GPUSystem->AddCollisionGeometry(B, BOX, ChVector<> (container_R, container_R, container_T), lpos, quat); GPUSystem->AddCollisionGeometry(BTM, BOX, ChVector<> (container_R, container_T, container_R), lpos, quat); //GPUSystem->FinalizeObject(L); //GPUSystem->FinalizeObject(R); //GPUSystem->FinalizeObject(F); //GPUSystem->FinalizeObject(B); GPUSystem->FinalizeObject(BTM); ((ChLcpSolverGPU*) (GPUSystem->mSystem->GetLcpSolverSpeed()))->SetContactFactor(.6); GPUSystem->Setup(); SimulationLoop(argc, argv); return 0; }
void System::DoTimeStep() { if (mNumCurrentObjects < mNumObjects && mFrameNumber % 100 == 0) { float x = 1, y = numY, z = 1; float posX = 0, posY = -8, posZ = 0; srand(1); float mass = .01, mu = .5, rest = 0; ShapeType type = SPHERE; CHBODYSHAREDPTR mrigidBody; mNumCurrentObjects += x * y * z; int mobjNum = 0; for (int xx = 0; xx < x; xx++) { for (int yy = 0; yy < y; yy++) { for (int zz = 0; zz < z; zz++) { type = CYLINDER;//rand()%2;e float radius = .5;//(rand()%1000)/3000.0+.05; ChVector<> mParticlePos((xx - (x - 1) / 2.0) + posX, (yy) + posY, (zz - (z - 1) / 2.0) + posZ); //mParticlePos += ChVector<> (rand() % 1000 / 10000.0 - .05, rand() % 1000 / 10000.0 - .05, rand() % 1000 / 10000.0 - .05); ChQuaternion<> quat = ChQuaternion<> (1, 0, 0, 0);// (rand() % 1000 / 1000., rand() % 1000 / 1000., rand() % 1000 / 1000., rand() % 1000 / 1000.); ChVector<> dim; ChVector<> lpos(0, 0, 0); quat.Normalize(); mrigidBody = CHBODYSHAREDPTR(new CHBODY); InitObject(mrigidBody, mass, mParticlePos * 1.1, quat, mu, mu, rest, true, false, 0, 1); mrigidBody->SetPos_dt(ChVector<> (0, 0, 0)); switch (type) { case SPHERE: dim = ChVector<> (radius, 0, 0); case ELLIPSOID: dim = ChVector<> (radius * 1.3, radius, radius * 1.3); case BOX: dim = ChVector<> (radius, radius, radius); case CYLINDER: dim = ChVector<> (radius, radius*2, radius); } AddCollisionGeometry(mrigidBody, type, dim, lpos, quat); FinalizeObject(mrigidBody); mobjNum++; } } } } mFrameNumber++; mSystem->DoStepDynamics(mTimeStep); mCurrentTime += mTimeStep; GPUSystem->PrintStats(); }
void EventCanvas::viewMousePressEvent(QMouseEvent* event)/*{{{*/ { ///keyState = event->state(); _keyState = ((QInputEvent*) event)->modifiers(); _button = event->button(); //printf("viewMousePressEvent buttons:%x mods:%x button:%x\n", (int)event->buttons(), (int)keyState, event->button()); // special events if right button is clicked while operations // like moving or drawing lasso is performed. if (event->buttons() & Qt::RightButton & ~(event->button())) { //printf("viewMousePressEvent special buttons:%x mods:%x button:%x\n", (int)event->buttons(), (int)keyState, event->button()); switch (_drag) { case DRAG_LASSO: _drag = DRAG_OFF; redraw(); return; case DRAG_MOVE: _drag = DRAG_OFF; endMoveItems(_start, MOVE_MOVE, 0); return; default: break; } } // ignore event if (another) button is already active: if (event->buttons() & (Qt::LeftButton | Qt::RightButton | Qt::MidButton) & ~(event->button())) { //printf("viewMousePressEvent ignoring buttons:%x mods:%x button:%x\n", (int)event->buttons(), (int)keyState, event->button()); return; } bool shift = _keyState & Qt::ShiftModifier; bool alt = _keyState & Qt::AltModifier; bool ctrl = _keyState & Qt::ControlModifier; _start = event->pos(); //--------------------------------------------------- // set curItem to item mouse is pointing // (if any) //--------------------------------------------------- CItemList list = _items; if(multiPartSelectionAction && !multiPartSelectionAction->isChecked()) list = getItemlistForCurrentPart(); if (virt()) { _curItem = list.find(_start);//_items.find(_start); } else { _curItem = 0; //selectAtTick(_start.x()); iCItem ius; bool usfound = false; for (iCItem i = list.begin(); i != list.end(); ++i) { MidiTrack* mtrack = (MidiTrack*)i->second->part()->track(); int sy = _start.y(); int p = y2pitch(sy); if(editor->isGlobalEdit()) p += mtrack->getTransposition(); int p2 = pitch2y(p); QPoint lpos(_start.x(), p2); QRect box = i->second->bbox(); int x = rmapxDev(box.x()); int y = rmapyDev(box.y()); int w = rmapxDev(box.width()); int h = rmapyDev(box.height()); QRect r(x, y, w, h); r.translate(i->second->pos().x(), i->second->pos().y()); if(r.contains(lpos)) { if (i->second->isSelected()) { _curItem = i->second; break; } else if (!usfound) { ius = i; usfound = true; } } } if (!_curItem && usfound) _curItem = ius->second; } if(editor->isGlobalEdit() && _curItem) { populateMultiSelect(_curItem); } if (_curItem && (event->button() == Qt::MidButton)) { if (!_curItem->isSelected()) { selectItem(_curItem, true); updateSelection(); redraw(); } startDrag(_curItem, shift); } else if (event->button() == Qt::RightButton) { if (_curItem) { if (shift) { _drag = DRAG_RESIZE; setCursor(); int dx = _start.x() - _curItem->x(); _curItem->setWidth(dx); _start.setX(_curItem->x()); deselectAll(); selectItem(_curItem, true); updateSelection(); redraw(); } else { _itemPopupMenu = genItemPopup(_curItem); if (_itemPopupMenu) { QAction *act = _itemPopupMenu->exec(QCursor::pos()); if (act) itemPopup(_curItem, act->data().toInt(), _start); delete _itemPopupMenu; } } } else { _canvasPopupMenu = genCanvasPopup(true); if (_canvasPopupMenu) { QAction *act = _canvasPopupMenu->exec(QCursor::pos(), 0); if (act) { int actnum = act->data().toInt(); canvasPopup(actnum); if(actnum >= 20) //Nome of the tools have a higher number than 9 { editor->updateCanvas(); los->arranger->updateCanvas(); } } delete _canvasPopupMenu; } } } else if (event->button() == Qt::LeftButton) { switch (_tool) { case PointerTool: if (_curItem) { /*if (_curItem->part() != _curPart) { _curPart = _curItem->part(); _curPartId = _curPart->sn(); curPartChanged(); }*/ itemPressed(_curItem); if (shift) _drag = DRAG_COPY_START; else if (alt) { _drag = DRAG_CLONE_START; } else if (ctrl) { //Select all on the same pitch (e.g. same y-value) deselectAll(); //printf("Yes, ctrl and press\n"); for (iCItem i = _items.begin(); i != _items.end(); ++i) { if (i->second->y() == _curItem->y()) selectItem(i->second, true); } updateSelection(); redraw(); } else _drag = DRAG_MOVE_START; } else _drag = DRAG_LASSO_START; setCursor(); break; case RubberTool: deleteItem(_start); _drag = DRAG_DELETE; setCursor(); break; case PencilTool: if (_curItem) { _drag = DRAG_RESIZE; setCursor(); int dx = _start.x() - _curItem->x(); _curItem->setWidth(dx); _start.setX(_curItem->x()); } else { _drag = DRAG_NEW; setCursor(); _curItem = newItem(_start, event->modifiers()); if (_curItem) _items.add(_curItem); else { _drag = DRAG_OFF; setCursor(); } } deselectAll(); if (_curItem) { selectItem(_curItem, true); // Play the note itemPressed(_curItem); } updateSelection(); redraw(); break; default: break; } } mousePress(event); }/*}}}*/
int main(int argc, char* argv[]) { bool visualize = true; int threads = 8; int config = 0; real gravity = -9.81; //acceleration due to gravity real timestep = .01; //step size real time_to_run = 1; //length of simulation real current_time = 0; int num_steps = time_to_run / timestep; int max_iteration = 15; int tolerance = 0; //========================================================================================================= // Create system //========================================================================================================= ChSystemParallel * system_gpu = new ChSystemParallel; //========================================================================================================= // Populate the system with bodies/constraints/forces/etc. //========================================================================================================= ChVector<> lpos(0, 0, 0); ChQuaternion<> quat(1, 0, 0, 0); real container_width = 5; //width of area with particles real container_length = 25; //length of area that roller will go over real container_thickness = .25; //thickness of container walls real container_height = 2; //height of the outer walls real particle_radius = .58; // Create a material (will be used by both objects) ChSharedPtr<ChMaterialSurface> material; material = ChSharedPtr<ChMaterialSurface>(new ChMaterialSurface); material->SetFriction(0.4); // Create a ball ChSharedBodyPtr ball = ChSharedBodyPtr(new ChBody(new ChCollisionModelParallel)); InitObject(ball, 1, // mass ChVector<>(0, 10, 0), // position ChQuaternion<>(1, 0, 0, 0), // rotation material, // material true, // collide? false, // static? -15, -15); // collision family ball->SetPos_dt(ChVector<>(0,0,10)); AddCollisionGeometry(ball, SPHERE, particle_radius, lpos, quat); FinalizeObject(ball, (ChSystemParallel *) system_gpu); // Create a bin for the ball to fall into ChSharedBodyPtr bin = ChSharedBodyPtr(new ChBody(new ChCollisionModelParallel)); InitObject(bin, 1, // mass ChVector<>(0, 0, 0), // position ChQuaternion<>(1, 0, 0, 0), // rotation material, // material true, // collide? true, // static? -20, -20); // collision family AddCollisionGeometry(bin, BOX, ChVector<>(container_width, container_thickness, container_length), lpos, quat); AddCollisionGeometry(bin, BOX, Vector(container_thickness, container_height, container_length), Vector(-container_width + container_thickness, container_height, 0), quat); AddCollisionGeometry(bin, BOX, Vector(container_thickness, container_height, container_length), Vector(container_width - container_thickness, container_height, 0), quat); AddCollisionGeometry(bin, BOX, Vector(container_width, container_height, container_thickness), Vector(0, container_height, -container_length + container_thickness), quat); AddCollisionGeometry(bin, BOX, Vector(container_width, container_height, container_thickness), Vector(0, container_height, container_length - container_thickness), quat); FinalizeObject(bin, (ChSystemParallel *) system_gpu); //========================================================================================================= // Edit system settings //========================================================================================================= system_gpu->SetIntegrationType(ChSystem::INT_ANITESCU); system_gpu->SetParallelThreadNumber(threads); system_gpu->SetMaxiter(max_iteration); system_gpu->SetIterLCPmaxItersSpeed(max_iteration); system_gpu->SetTol(1e-3); system_gpu->SetTolSpeeds(1e-3); system_gpu->Set_G_acc(ChVector<>(0, gravity, 0)); system_gpu->SetStep(timestep); ((ChLcpSolverParallel *) (system_gpu->GetLcpSolverSpeed()))->SetMaxIteration(max_iteration); ((ChLcpSolverParallel *) (system_gpu->GetLcpSolverSpeed()))->SetTolerance(0); ((ChLcpSolverParallel *) (system_gpu->GetLcpSolverSpeed()))->SetCompliance(0, 0, 0); ((ChLcpSolverParallel *) (system_gpu->GetLcpSolverSpeed()))->SetContactRecoverySpeed(300); ((ChLcpSolverParallel *) (system_gpu->GetLcpSolverSpeed()))->SetSolverType(ACCELERATED_PROJECTED_GRADIENT_DESCENT); ((ChCollisionSystemParallel *) (system_gpu->GetCollisionSystem()))->SetCollisionEnvelope(particle_radius * .05); ((ChCollisionSystemParallel *) (system_gpu->GetCollisionSystem()))->setBinsPerAxis(R3(10, 10, 10)); ((ChCollisionSystemParallel *) (system_gpu->GetCollisionSystem()))->setBodyPerBin(100, 50); omp_set_num_threads(threads); //========================================================================================================= // Enter the time loop and render the simulation //========================================================================================================= if (visualize) { ChOpenGLManager * window_manager = new ChOpenGLManager(); ChOpenGL openGLView(window_manager, system_gpu, 800, 600, 0, 0, "Test_Solvers"); openGLView.render_camera->camera_pos = Vector(0, 5, -20); openGLView.render_camera->look_at = Vector(0, 0, 0); openGLView.SetCustomCallback(RunTimeStep); openGLView.StartSpinning(window_manager); window_manager->CallGlutMainLoop(); } return 0; }
int OneTimeSceneInit() { int ret; D3DXVECTOR3 campos = D3DXVECTOR3( -546.0f, 400.0f, -1845.0f ); ret = E3DSetCameraPos( campos ); if( ret ){ _ASSERT( 0 ); return 1; } D3DXVECTOR3 camtar = D3DXVECTOR3( 3.2733f, 450.0f, 70.6515f ); D3DXVECTOR3 camup = D3DXVECTOR3( 0.0f, 1.0f, 0.0f ); ret = E3DSetCameraTarget( camtar, camup ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DSetProjection( 1000.0f, 30000.0f, 60.0f ); if( ret ){ _ASSERT( 0 ); return 1; } char mqoname[MAX_PATH]; sprintf_s( mqoname, MAX_PATH, "%s\\hdrscene3.mqo", szMediaDir ); ret = E3DLoadMQOFileAsGround( mqoname, 10.0f, 0, BONETYPE_RDB2, &hsid0 ); if( ret ){ _ASSERT( 0 ); return 1; } //ピクセル単位のPhongライティングにする ret = E3DSetShaderType( hsid0, COL_PPHONG ); _ASSERT( !ret ); ret = E3DCreateLight( &lid1 ); if( ret ){ _ASSERT( 0 ); return 1; } D3DXVECTOR3 lpos( 1000.0f, 0.0f, 3500.0f ); E3DCOLOR4UC col= {255, 255, 255, 255 }; ret = E3DSetPointLight( lid1, lpos, 9000.0f, col ); if( ret ){ _ASSERT( 0 ); return 1; } //HDR用の強い光をセット E3DCOLOR4F diffuse = { 10.0f, 10.0f, 10.0f, 1.0f }; E3DCOLOR4F specular = { 0.2f, 0.2f, 0.2f, 1.0f }; ret = E3DSetHDRLightDiffuse( lid1, diffuse ); _ASSERT( !ret ); ret = E3DSetHDRLightSpecular( lid1, specular ); _ASSERT( !ret ); //トーンマップのテクスチャを作成 int toneok = 0; ret = E3DCreateToneMapTexture( 4, toneformat, &tonemapid, &toneok ); if( ret ){ _ASSERT( 0 ); return 1; } int okflag; SIZE orgsize = { 640 / 2, 480 }; SIZE small4 = { orgsize.cx / 4, orgsize.cy / 4 }; SIZE small8 = { orgsize.cx / 8, orgsize.cy / 8 }; ret = E3DCreateRenderTargetTexture( orgsize, hdrformat, &scid_org, &texid_org, &okflag ); if( ret || !okflag ){ _ASSERT( 0 ); return 1; } ret = E3DCreateRenderTargetTexture( small4, hdrformat, &scid_small, &texid_small, &okflag ); if( ret || !okflag ){ _ASSERT( 0 ); return 1; } ret = E3DCreateRenderTargetTexture( small4, D3DFMT_A8R8G8B8, &scid_bright, &texid_bright, &okflag ); if( ret || !okflag ){ _ASSERT( 0 ); return 1; } ret = E3DCreateRenderTargetTexture( small8, D3DFMT_A8R8G8B8, &scid_bloom0, &texid_bloom0, &okflag ); if( ret || !okflag ){ _ASSERT( 0 ); return 1; } ret = E3DCreateRenderTargetTexture( small8, D3DFMT_A8R8G8B8, &scid_bloom1, &texid_bloom1, &okflag ); if( ret || !okflag ){ _ASSERT( 0 ); return 1; } ret = E3DCreateRenderTargetTexture( small8, D3DFMT_A8R8G8B8, &scid_work, &texid_work, &okflag ); if( ret || !okflag ){ _ASSERT( 0 ); return 1; } ret = E3DCreateRenderTargetTexture( small8, D3DFMT_A8R8G8B8, &scid_bloom2, &texid_bloom2, &okflag ); if( ret || !okflag ){ _ASSERT( 0 ); return 1; } ret = E3DCreateRenderTargetTexture( orgsize, D3DFMT_A8R8G8B8, &scid_final, &texid_final, &okflag ); if( ret || !okflag ){ _ASSERT( 0 ); return 1; } char spname[MAX_PATH]; sprintf_s( spname, MAX_PATH, "%s\\dummy256.png", szMediaDir ); ret = E3DCreateSprite( spname, 0, 0, &spid1 ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DSetTextureToDispObj( -2, spid1, texid_org ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DGetSpriteSize( spid1, &spw1, &sph1 ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DCreateSprite( spname, 0, 0, &spid2 ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DSetTextureToDispObj( -2, spid2, texid_final ); if( ret ){ _ASSERT( 0 ); return 1; } ret = E3DGetSpriteSize( spid2, &spw2, &sph2 ); if( ret ){ _ASSERT( 0 ); return 1; } keydir = 0; middlegray = 0.1f; threshold = 9.5f; offset = 7.0f; return 0; }