Esempio n. 1
0
void MemExploreApp::update()
{
  Vec2f center = getWindowCenter();

  mCameraArcball.resetQuat();
  mCameraArcball.mouseDown(center);
  mCameraArcball.mouseDrag(getWindowSize() - mMousePos);
  mCamera.setOrientation(mCameraArcball.getQuat() * mCamera.getOrientation());

  // Reset mouse position to center of screen
  if(mIsFullscreen) {
    Vec2f center = getWindowCenter();
    CGSetLocalEventsSuppressionInterval(0.0);
    CGWarpMouseCursorPosition(CGPointMake(center.x, center.y));
    mMousePos = center;
  }

  float speed = 0.01f;
  Vec3f camX = mCamera.getOrientation() * Vec3f::xAxis() * speed;
  Vec3f camY = mCamera.getOrientation() * Vec3f::yAxis() * speed;
  Vec3f camZ = mCamera.getOrientation() * Vec3f::zAxis() * speed;
  
  if(mKeysDown.count('w')) mCameraAcc -= camZ;
  if(mKeysDown.count('a')) mCameraAcc -= camX;
  if(mKeysDown.count('s')) mCameraAcc += camZ;
  if(mKeysDown.count('d')) mCameraAcc += camX;
  if(mKeysDown.count('q')) mCameraAcc += camY;
  if(mKeysDown.count('e')) mCameraAcc -= camY;

  mCameraVel += mCameraAcc;
  mCamera.setEyePoint(mCamera.getEyePoint() + mCameraVel);
  mCameraVel *= 0.975f;
  mCameraAcc *= 0.8f;
}
Esempio n. 2
0
bool valid(tr1::unordered_set<string> const& st, sbmt::fat_syntax_rule const& r)
{
    vector<string> v; keys(*r.lhs_root(),v);
    BOOST_FOREACH(string const& vv, v) {
        if (st.find(vv) == st.end()) return false;
    }
    return true;
}
Esempio n. 3
0
void MemExploreApp::keyDown(KeyEvent e)
{
  if(e.getCode() == 27) { // Esc
    mIsFullscreen = false;
    setFullScreen(mIsFullscreen);
  }
  else if(e.getChar() == 'f') {
    mIsFullscreen = true;
    setFullScreen(mIsFullscreen);
  }
  else if(e.getChar() == ' ') {
    delete mDataPointer;
    mDataPointer = new uint8_t;
  }
  else {
    mKeysDown.insert(e.getChar());
  }
}
Esempio n. 4
0
void insert(tr1::unordered_set<string>& st, sbmt::fat_syntax_rule const& r)
{
    vector<string> v; keys(*r.lhs_root(),v);
    st.insert(v.begin(),v.end());
}
Esempio n. 5
0
void read(char* fname,tr1::unordered_set<string>& st)
{
    ifstream fs(fname);
    return st.insert(istream_iterator<string>(fs),istream_iterator<string>());
}
    bool wordSegmentation(string s, tr1::unordered_set<string> &dict) {
        // write your code here
        if (s.size() == 0)
        {
        	return true;
        }
    	vector<bool> res;

    	res.push_back(true);

    	int maxWordLen = 0;
    	for (tr1::unordered_set<string>::iterator i = dict.begin();
    		 i != dict.end(); i++)
    	{
    		int curSize = (*i).size();
    		if (curSize > maxWordLen)
    		{
    			maxWordLen = curSize;
    		}
    	}

    	//cout << "maxWordLen is " << maxWordLen << endl;

    	for (int i = 0; i < s.size(); i++)
    	{
    		bool seged = false;
    		for (int j = (i - maxWordLen > 0) ? (i - maxWordLen) : 0; j <= i; j++)
    		{
    			string subs = s.substr(j, i - j + 1);
    			tr1::unordered_set<string>::const_iterator got = dict.find(subs);
    			if (got != dict.end())
    			{
		    		if (res[j])
		    		{
		    			seged = true;
			    		break;
			    	}
		    	}
	    	}
	    	if (seged)
	    	{
	    		res.push_back(true);
	    	}
	    	else
	    	{
	    		res.push_back(false);
	    	}
    	}

  //   	int lastSegedPos = -1;
		// for(int i = 0; i < s.size(); i++)
		// {
		// 	string subs = s.substr(lastSegedPos + 1, i - lastSegedPos);
		// 	cout << "current i is " << i << endl;
		// 	cout << "subs is " << subs << endl;
		// 	tr1::unordered_set<string>::const_iterator got = dict.find(subs);
		// 	if (got != dict.end())
		// 	{
		// 		cout << "lastSegedPos changed from " << lastSegedPos << " to " << i << endl;
		// 		res.push_back(true);
		// 		lastSegedPos = i;
		// 	}
		// 	else
		// 	{
		// 		res.push_back(false);
		// 	}
		// }  

    	// for (int i = 0; i < s.size(); i++)
    	// {
    	// 	bool seged = false;
    	// 	for (int j = 0; j <= i; j++)
    	// 	{
    	// 		string subs = s.substr(j, i - j + 1);
    	// 		tr1::unordered_set<string>::const_iterator got = dict.find(subs);
    	// 		if (got != dict.end())
    	// 		{
		   //  		if (res[j])
		   //  		{
		   //  			seged = true;
			  //   		break;
			  //   	}
		   //  	}
	    // 	}
	    // 	if (seged)
	    // 	{
	    // 		res.push_back(true);
	    // 	}
	    // 	else
	    // 	{
	    // 		res.push_back(false);
	    // 	}
    	// }

    	return res[s.size()];
    }
Esempio n. 7
0
void MemExploreApp::keyUp(KeyEvent e)
{
  mKeysDown.erase(e.getChar());
}