void x34() { takes_S( 1 ); takes_S( v ); takes_S( r ); takes_S( cr ); takes_S( f() ); takes_S( fc() ); takes_S( fr() ); takes_S( frc() ); takes_S( S(1) ); takes_S( (v.*mp)() ); takes_S( (pf)() ); takes_cS( 1 ); takes_cS( v ); takes_cS( r ); takes_cS( cr ); takes_cS( f() ); takes_cS( fc() ); takes_cS( fr() ); takes_cS( frc() ); takes_cS( S(1) ); takes_cS( (v.*mp)() ); takes_cS( (pf)() ); }
void VirusBase::elasticEdges( Particle2D &pt, float $elastic, float $buffer, float $friction ) { ofxVec2f frc(0, 0); ofxVec2f totVel = pt.vel + vel; // since it is added when it is past wall (elastic) adds way too much rotation, // may work with stiff walls ? // //ofxVec2f tanVec = pt.loc.getPerpendicular(); //tanVec.normalize(); //tanVec *= angVel; //totVel += tanVec; if (loc.x + pt.loc.x > ofGetWidth() + $buffer ) { frc.x = -$elastic; frc.y = -totVel.y * ($elastic * $friction ); } if (loc.x + pt.loc.x < -$buffer) { frc.x += $elastic; frc.y = -totVel.y * ($elastic * $friction ); } if (loc.y + pt.loc.y > ofGetHeight() + $buffer) { frc.x = -totVel.x * ($elastic * $friction); frc.y += -$elastic; } if (loc.y + pt.loc.y < -$buffer) { frc.x = -totVel.x * ($elastic * $friction); frc.y += $elastic; } //pt.addForce( frc ); addForceBodyPoint(pt, frc, 1.4f); }
//------------------------------------------------------------ // friction is the amount of traction that the particle induces, i.e. higher traction will imitate a sticky surface // void VirusBase::bounceOffEdges(Particle2D &pt, float $damping, float $wallPadding, float $friction) { ofxVec2f frc(0, 0); ofxVec2f totVel = pt.vel + vel; // since it is added when it is past wall (elastic) adds way too much rotation, // may work with stiff walls ? // //ofxVec2f tanVec = pt.loc.getPerpendicular(); //tanVec.normalize(); //tanVec *= angVel * 2.5f; //totVel += tanVec; // what are the walls float minx = $wallPadding; float miny = $wallPadding; float maxx = ofGetWidth() - $wallPadding; float maxy = ofGetHeight() - $wallPadding; bool bDidICollide; if (loc.x + pt.loc.x > maxx){ pt.loc.x = maxx - loc.x; // move to the edge, (important!) pt.vel.x *= -1; frc.y = -totVel.y * $friction; bDidICollide = true; } else if (loc.x + pt.loc.x < minx){ pt.loc.x = minx - loc.x; // move to the edge, (important!) pt.vel.x *= -1; frc.y = -totVel.y * $friction; bDidICollide = true; } if (loc.y + pt.loc.y > maxy){ pt.loc.y = maxy - loc.y; // move to the edge, (important!) pt.vel.y *= -1; frc.x = -totVel.x * $friction; bDidICollide = true; } else if (loc.y + pt.loc.y < miny){ pt.loc.y = miny - loc.y; // move to the edge, (important!) pt.vel.y *= -1; frc.x = -totVel.x * $friction; bDidICollide = true; } if (bDidICollide == true) { pt.vel *= $damping; } addForceBodyPoint(pt, frc, 1.4f); }
void iMinimapView::Compose(HDC hdc) { iRect clRect = iWMetrics::GetClRect(m_hWnd); m_outBuff.m_Dib.Fill(cColorBlack); if (m_pMap) { iRect frc(Screen2Map(m_frameLT, m_pMap->GetWidth()), Screen2Map(m_frameRB, m_pMap->GetWidth())); if (m_dibMap.GetWidth() > clRect.w || m_dibMap.GetHeight() > clRect.h){ uint32 factor = iMAX<uint32>(m_dibMap.GetWidth()/clRect.w, m_dibMap.GetHeight()/clRect.h )+1; iDib ndib(iSize(m_dibMap.GetWidth()/factor,m_dibMap.GetHeight()/factor)); iDibTransformer::Stretch(m_dibMap, ndib, iDibTransformer::Pyramidal); iPoint offset(clRect.w/2 - ndib.GetSize().w/2, clRect.h/2 - ndib.GetSize().h/2); ndib.CopyToDibXY(&m_outBuff.m_Dib, offset, BLEND_ALPHABLEND); frc.x /= factor; frc.y /= factor; frc.w /= factor; frc.h /= factor; frc.Move(offset.x, offset.y); } else { uint32 factor = iMIN<uint32>(clRect.w / m_dibMap.GetWidth(), clRect.h / m_dibMap.GetHeight()); if (factor > 1) { iDib ndib(m_dibMap); iDibTransformer::MultiplySize(ndib, factor); iPoint offset(clRect.w/2 - ndib.GetSize().w/2, clRect.h/2 - ndib.GetSize().h/2); ndib.CopyToDibXY(&m_outBuff.m_Dib, offset, BLEND_ALPHABLEND); frc.x *= factor; frc.y *= factor; frc.w *= factor; frc.h *= factor; frc.Move(offset.x, offset.y); } else { iPoint offset(clRect.w/2 - m_dibMap.GetSize().w/2, clRect.h/2 - m_dibMap.GetSize().h/2); m_dibMap.CopyToDibXY(&m_outBuff.m_Dib, offset, BLEND_ALPHABLEND); frc.Move(offset.x, offset.y); } } iDibPrimitives::DrawFrame(m_outBuff.m_Dib, frc, iColor(255,255,0,255), BLEND_SRCCOPY); } ::BitBlt(hdc,0,0, clRect.w,clRect.h,m_outBuff,0,0,SRCCOPY); }
//------------------------------------------------------------ void ttRopeJoint::swing(){ float maxInput; float maxOutput; if(ropeBasic->num_char == 0){ maxInput = 90; maxOutput = 50; }else if(ropeBasic->num_char == 1){ maxInput = -90; maxOutput = -50; } if (ropeBasic->bFixedMove) { ofPoint frc(0,0); if (control->bSwingLeft) { frc.x = ofMap(control->diff.x, 0, maxInput, 0, maxOutput,true); endRect.setVelocity(frc.x, 0); control->bSwingLeft = false; } if (control->bSwingRight) { frc.x = ofMap(control->diff.x, 0, -maxInput, 0, maxOutput,true); endRect.setVelocity(-frc.x, 0); control->bSwingRight = false; } float diffX = endRect.getPosition().x - startPos.x; float diffY = endRect.getPosition().y - startPos.y; float angleTo = atan2(diffY, diffX); endRect.setAngle(PI/2 + angleTo); } }
Fraction operator *(const Fraction& lhs, const Fraction& rhs) { Fraction frc(lhs.num(), lhs.den()); return frc *= rhs; }
void iMinimapView::ScrollMap(iPoint pos) { pos.x -= 20; pos.y -= 25; SCROLLINFO si; iRect clRect = iWMetrics::GetClRect(this->m_hWnd); //this->ClientToScreen( int left; int width; int top = 0; int height = 100; left = 24; width = 128; top = -8; height = 128; iRect frc(Screen2Map(m_frameLT, m_pMap->GetWidth()), Screen2Map(m_frameRB, m_pMap->GetWidth())); if (m_dibMap.GetWidth() > clRect.w || m_dibMap.GetHeight() > clRect.h){ uint32 factor = iMAX<uint32>(m_dibMap.GetWidth()/clRect.w, m_dibMap.GetHeight()/clRect.h )+1; iDib ndib(iSize(m_dibMap.GetWidth()/factor,m_dibMap.GetHeight()/factor)); iPoint offset(clRect.w/2 - ndib.GetSize().w/2, clRect.h/2 - ndib.GetSize().h/2); frc.x /= factor; frc.y /= factor; frc.w /= factor; frc.h /= factor; frc.Move(offset.x, offset.y); } else { uint32 factor = iMIN<uint32>(clRect.w / m_dibMap.GetWidth(), clRect.h / m_dibMap.GetHeight()); if (factor > 1) { iDib ndib(m_dibMap); iDibTransformer::MultiplySize(ndib, factor); iPoint offset(clRect.w/2 - ndib.GetSize().w/2, clRect.h/2 - ndib.GetSize().h/2); ndib.CopyToDibXY(&m_outBuff.m_Dib, offset, BLEND_ALPHABLEND); frc.x *= factor; frc.y *= factor; frc.w *= factor; frc.h *= factor; frc.Move(offset.x, offset.y); } else { iPoint offset(clRect.w/2 - m_dibMap.GetSize().w/2, clRect.h/2 - m_dibMap.GetSize().h/2); frc.Move(offset.x, offset.y); } } pos.x -= frc.w / 2; pos.y -= frc.h / 2; double hrz = 0, vrt = 0; if(pos.x <= left) hrz = 0.0; else if((unsigned)(pos.x) >= left + width) hrz = 1.0; else hrz = (double)(pos.x - left) / (double)width; if(pos.y <= top) vrt = 0.0; else if((unsigned)(pos.y) >= top + height) vrt = 1.0; else vrt = (double)(pos.y - top) / (double)height; if(pos.y < 0) vrt = 0.0; si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_RANGE; m_pMainView->GetScrollInfo(SB_HORZ, &si); m_pMainView->SendMessage(WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, (int)((double)si.nMax * hrz))); si.cbSize = sizeof(SCROLLINFO); si.fMask = SIF_RANGE; m_pMainView->GetScrollInfo(SB_VERT, &si); m_pMainView->SendMessage(WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION, si.nMax * vrt)); }
//-------------------------------------------------------------- void ofApp::keyPressed(int key){ switch (key) { case ' ':{ // add one sphere shared_ptr< ofxBulletSphere > ss( new ofxBulletSphere() ); ss->create( world.world, camera.getPosition()+100.0f*camera.getLookAtDir(), 0.05, 30.0); ss->add(); ofVec3f frc(camera.getLookAtDir()); frc.normalize(); ss->applyCentralForce(frc*1000); spheres.push_back( ss ); } break; case '0': // sakura enableDrawAssimpModelWireFrame = false; changeAssimpModel(0); break; case '1': // bitcoin & dgcoin enableDrawAssimpModelWireFrame = false; changeAssimpModel(1); break; case '2': // dna enableDrawAssimpModelWireFrame = false; changeAssimpModel(2); break; case '3': // maple enableDrawAssimpModelWireFrame = false; changeAssimpModel(3); break; case 'f': ofToggleFullscreen(); break; case 'h': // show/hide gui panel showPanel = !showPanel; // show/hide mouse cursor showPanel ? ofShowCursor() : ofHideCursor(); break; case 'm':{ // add model ofxBulletAssimpShape *bulletCustomShape; bulletCustomShape = new ofxBulletAssimpShape; ofQuaternion startRot = ofQuaternion(1., 0., 0., PI); bulletCustomShape->init((btCompoundShape*)assimpModelBulletShapes[0]->getCollisionShape(), assimpModelBulletShapes[0]->getCentroid()); bulletCustomShape->create(world.world, modelStartPosition, startRot, modelMass); bulletCustomShape->add(); ofVec3f frc(camera.getLookAtDir()); frc.normalize(); bulletCustomShape->applyCentralForce(frc*0.005); assimpModelBulletShapes.push_back(bulletCustomShape); } break; case 'w':{ ofVec3f wind(0, 0, 0.01); for (int i = 0; i < assimpModelBulletShapes.size(); i++) { assimpModelBulletShapes[i]->applyCentralForce(wind); } } break; default: break; } }
//-------------------------------------------------------------- void ofApp::update(){ // timer update timer.update(); // dmx if (enableDmx) { for (int i = 0; i < DMX_CHANNEL_NUMBER; i++) { dmxChannels[i].set(tween.update()); dmx.setLevel(i+1, dmxChannels[i]);// be careful, dmx channel starts from 1, not 0. } dmx.update(); if ((int)ofGetElapsedTimef() % DMX_TIMER_PER_SECONDS == 0){ // FIXME: hard code and use same tween to each dmx channel for (int i = 0; i < DMX_CHANNEL_NUMBER; i++) { doEase(dmxChannels[i], 10000, 0); } } } // kinect kinect.update(); if( kinect.isFrameNew() ){ if (showPanel) { texDepth.loadData(kinect.getDepthPixels()); texRGB.loadData(kinect.getRgbPixels()); } rawDepthPixels = kinect.getRawDepthPixels(); // bullet if (kinectBulletShape == NULL ) { updateKinectMesh(); setupWhenKinectIsReady(); }else if(enableScanPeople) { // scanning people feature if (!diffDepthTexture.isAllocated()) { diffDepthTexture.allocate(rawDepthPixels.getWidth(), rawDepthPixels.getHeight(), GL_RGB);// color texture diffDepthTexturePixels = new unsigned char[rawDepthPixels.getWidth()*rawDepthPixels.getHeight()*3]; } diffDepthPixels = rawDepthPixels; // copy float * diffDepthPixelsPointer = diffDepthPixels.getPixels(); modelStartPositions.clear(); for (int x = 0; x < rawDepthPixels.getWidth(); x++) { for (int y = 0; y < rawDepthPixels.getHeight(); y++) { diffDepthPixelsPointer[rawDepthPixels.getWidth()*y+x] = savedReferenceDepthPixels[rawDepthPixels.getWidth()*y+x]-rawDepthPixels[rawDepthPixels.getWidth()*y+x]; if (/* savedReferenceDepthPixels[rawDepthPixels.getWidth()*y+x] > kinect.minDistance && savedReferenceDepthPixels[rawDepthPixels.getWidth()*y+x] < kinect.maxDistance && */ rawDepthPixels[rawDepthPixels.getWidth()*y+x] > kinect.minDistance && rawDepthPixels[rawDepthPixels.getWidth()*y+x] < kinect.maxDistance) { if (diffDepthPixelsPointer[rawDepthPixels.getWidth()*y+x] > 0) { // calculate probability float probability = diffDepthPixelsPointer[rawDepthPixels.getWidth()*y+x] / probabilityFactor; // judge add or not bool judgeAdd = (ofRandomuf() < probability); if (judgeAdd) { modelStartPositions.push_back(ofVec3f(x, y, modelStartPosition->z)); } // set diffDepthTexturePixels with red color if (showPanel) { diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+0] = ofMap(diffDepthPixelsPointer[rawDepthPixels.getWidth()*y+x], 0, kinect.maxDistance-kinect.minDistance, 0, 255, true) ; // r diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+1] = 0; // g diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+2] = 0; // b } }else{ // set diffDepthTexturePixels with blue color if (showPanel) { diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+0] = 0; // r diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+1] = 0; // g diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+2] = ofMap(-1*diffDepthPixelsPointer[rawDepthPixels.getWidth()*y+x], 0, kinect.maxDistance-kinect.minDistance, 0, 255, true); // b } } }else{ // black if (showPanel) { diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+0] = 0; // r diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+1] = 0; // g diffDepthTexturePixels[(rawDepthPixels.getWidth()*y+x)*3+2] = 0; // b } } } } // grayscale diff texture // diffDepthTexture.loadData(diffDepthPixels); // draw RGB diff texture if (showPanel) { diffDepthTexture.loadData(diffDepthTexturePixels, rawDepthPixels.getWidth(), rawDepthPixels.getHeight(), GL_RGB); } }else{ updateKinectMesh(); } } // bullet if (!stopUpdatingKinectBullet && !enableScanPeople) { if (kinectHeight != 0 && kinectBulletShape != NULL) { kinectBulletShape->remove(); kinectBulletShape->create( world.world, kinectMesh, ofVec3f(0,0,0), 0.f, ofVec3f(0, 0, 0), ofVec3f(kinectWidth, kinectHeight, kinect.maxDistance.getMax()) ); kinectBulletShape->add(); kinectBulletShape->enableKinematic(); kinectBulletShape->setActivationState( DISABLE_DEACTIVATION ); } } // model if (enableAddModel) { // add model in modelStartPosition ofxBulletAssimpShape *bulletCustomShape; bulletCustomShape = new ofxBulletAssimpShape(currentModelSetId, rand()%(int)modelSetVector[currentModelSetId].size()); ofQuaternion startRot = ofQuaternion(1., 0., 0., PI); int modelId = modelSetVector[bulletCustomShape->getSetId()][bulletCustomShape->getIndex()]; bulletCustomShape->init((btCompoundShape*)referenceAssimpModelBulletShapes[modelId]->getCollisionShape(), referenceAssimpModelBulletShapes[modelId]->getCentroid()); bulletCustomShape->create(world.world, modelStartPosition, startRot, modelMass); bulletCustomShape->add(); ofVec3f frc(camera.getLookAtDir()); frc.normalize(); bulletCustomShape->applyCentralForce(frc*0.005); assimpModelBulletShapes.push_back(bulletCustomShape); } if (enableAddModelRandom && timer.getName() != "interval") { // add model in random x, random y and modelStartPosition.z ofxBulletAssimpShape *bulletCustomShape; bulletCustomShape = new ofxBulletAssimpShape(currentModelSetId, rand()%(int)modelSetVector[currentModelSetId].size()); ofQuaternion startRot = ofQuaternion(ofRandom(0, 1), ofRandom(0, 1), ofRandom(0, 1), ofRandom(-1*PI, PI)); int modelId = modelSetVector[bulletCustomShape->getSetId()][bulletCustomShape->getIndex()]; bulletCustomShape->init((btCompoundShape*)referenceAssimpModelBulletShapes[modelId]->getCollisionShape(), referenceAssimpModelBulletShapes[modelId]->getCentroid()); // random square // ofVec3f instantModelStartPosition(ofRandom(0, w), ofRandom(0, h), modelStartPosition->z); // random circle float instantRadius = ofRandom(0, 500); // float instantRadius = (ofRandom(-500, 500)+ofRandom(-500, 500)+ofRandom(-500, 500)+ofRandom(-500, 500)+ofRandom(-500, 500))/5.0; float instantTheta = ofRandom(-PI, PI); ofVec3f instantModelStartPosition(kinectWidth/2.0+instantRadius*cos(instantTheta), kinectHeight/2.0+instantRadius*sin(instantTheta), modelStartPosition->z); bulletCustomShape->create(world.world, instantModelStartPosition, startRot, modelMass); bulletCustomShape->add(); ofVec3f frc(camera.getLookAtDir()); frc.normalize(); bulletCustomShape->applyCentralForce(frc*ofRandom(-0.01, 0.01)); ofVec3f instantTorque(ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005)); bulletCustomShape->applyTorque(instantTorque); assimpModelBulletShapes.push_back(bulletCustomShape); } if (enableScanPeople) { // add models in modelStartPositioins // ofLogNotice("modelStartPositions"+ofToString(modelStartPositions.size())); for (int i = 0; i < modelStartPositions.size(); i++) { // add model in random x, random y and modelStartPosition.z ofxBulletAssimpShape *bulletCustomShape; bulletCustomShape = new ofxBulletAssimpShape(currentModelSetId, rand()%(int)modelSetVector[currentModelSetId].size()); ofQuaternion startRot = ofQuaternion(ofRandom(0, 1), ofRandom(0, 1), ofRandom(0, 1), ofRandom(-1*PI, PI)); int modelId = modelSetVector[currentModelSetId][rand()%(int)modelSetVector[currentModelSetId].size()]; bulletCustomShape->init((btCompoundShape*)referenceAssimpModelBulletShapes[modelId]->getCollisionShape(), referenceAssimpModelBulletShapes[modelId]->getCentroid()); bulletCustomShape->create(world.world, modelStartPositions[i], startRot, modelMass); bulletCustomShape->add(); ofVec3f frc(camera.getLookAtDir()); frc.normalize(); bulletCustomShape->applyCentralForce(frc*ofRandom(-0.01, 0.01)); ofVec3f instantTorque; switch (currentModelSetId) { case 0: instantTorque.set(ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005)); break; case 1: instantTorque.set(ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005)); break; case 2: instantTorque.set(ofRandom(-0.0001, 0.0001), ofRandom(-0.0001, 0.0001), ofRandom(-0.0001, 0.0001)); break; case 3: instantTorque.set(ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005)); break; case 4: instantTorque.set(ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005), ofRandom(-0.005, 0.005)); break; default: break; } bulletCustomShape->applyTorque(instantTorque); assimpModelBulletShapes.push_back(bulletCustomShape); } } // world world.setGravity(worldGravity); world.update(ofGetLastFrameTime()*2, 20); ofRectangle kinectRange(0, 0, kinectWidth, kinectHeight); for( int i = 0; i < assimpModelBulletShapes.size(); i++ ) { // erase model which is in out range(z < 0) if(assimpModelBulletShapes[i]->getPosition().z < 0) { assimpModelBulletShapes[i]->remove(); assimpModelBulletShapes.erase(assimpModelBulletShapes.begin() + i); // erase only one bullet shape // break; }else if(kinectIsReady && kinectRange.inside(assimpModelBulletShapes[i]->getPosition().x, assimpModelBulletShapes[i]->getPosition().y)){ // apply force to bullet shape inside the float instantKinectDepth = rawDepthPixels[(int)assimpModelBulletShapes[i]->getPosition().x + (int)assimpModelBulletShapes[i]->getPosition().y*kinectWidth]; if (instantKinectDepth > kinect.minDistance && instantKinectDepth < kinect.maxDistance && assimpModelBulletShapes[i]->getPosition().z > instantKinectDepth) { // add force to the model which is above the kinect mesh if (ofGetMousePressed()) { ofVec3f wind(0, 0, 0.001); // FIXME: hard code assimpModelBulletShapes[i]->applyCentralForce(wind); } } } } // camera if (enableMouseInput) { camera.enableMouseInput(); }else{ camera.disableMouseInput(); camera.setupPerspective(false, cameraFov, cameraNearDist, cameraFarDist, ofVec2f(0.0f, 0.0f)); camera.setPosition(cameraPosition); camera.lookAt(ofVec3f(cameraLookAt), ofVec3f(0, -1, 0)); } // camera target debugSphereCameraTarget.setPosition(cameraLookAt); // light light.setPosition(lightPosition); light.setSpecularColor(lightSpecularColor); light.setDiffuseColor(lightDissuseColor); light.setAmbientColor(lightAmbientColor); light.setAttenuation(lightAttenuation->x, lightAttenuation->y, lightAttenuation->z); // material material.setSpecularColor(materialSpecularColor); material.setDiffuseColor(materialDiffuseColor); material.setAmbientColor(materialAmbientColor); material.setEmissiveColor(materialEmissiveColor); material.setShininess(materialShininess); }
S const &cr = v; S f(); S const fc(); S &fr(); S const &frc(); S (S::*mp)(); S (*pf)(); S &x10 = 1; S &x11 = v; S &x12 = r; S &x13 = cr; S &x14 = f(); S &x15 = fc(); S &x16 = fr(); S &x17 = frc(); S &x18 = S(1); S &x19 = (v.*mp)(); S &x1a = (pf)(); S const &x20 = 1; S const &x21 = v; S const &x22 = r; S const &x23 = cr; S const &x24 = f(); S const &x25 = fc(); S const &x26 = fr(); S const &x27 = frc(); S const &x28 = S(1); S const &x29 = (v.*mp)(); S const &x2a = (pf)();