コード例 #1
0
ファイル: ObjectView.cpp プロジェクト: DonCN/haiku
void
ObjectView::MouseDown(BPoint point)
{
	GLObject* object = NULL;

	BMessage *msg = Window()->CurrentMessage();
	uint32 buttons = msg->FindInt32("buttons");
	object = reinterpret_cast<GLObject*>(fObjects.ItemAt(ObjectAtPoint(point)));

	if (object != NULL){
		if (buttons == B_PRIMARY_MOUSE_BUTTON || buttons == B_SECONDARY_MOUSE_BUTTON) {
			fTrackingInfo.pickedObject = object;
			fTrackingInfo.buttons = buttons;
			fTrackingInfo.isTracking = true;
			fTrackingInfo.lastX = point.x;
			fTrackingInfo.lastY = point.y;
			fTrackingInfo.lastDx = 0.0f;
			fTrackingInfo.lastDy = 0.0f;
			fTrackingInfo.pickedObject->Spin(0.0f, 0.0f);


			SetMouseEventMask(B_POINTER_EVENTS,
						B_LOCK_WINDOW_FOCUS | B_NO_POINTER_HISTORY);

			BCursor grabbingCursor(B_CURSOR_ID_GRABBING);
			SetViewCursor(&grabbingCursor);
		} else {
			ConvertToScreen(&point);
			object->MenuInvoked(point);
		}
	}
}
コード例 #2
0
ファイル: globject.cpp プロジェクト: Krutoy242/Game
bool GLObject::collision(GLObject & obj){
    float vx = obj.x()-x();
    float vy = obj.y()-y();
    if( object.model() ){
      //object.model()->cullInfo().radius();
      return ( vx*vx + vy*vy ) < viewSize()*obj.viewSize();
      } else
      return 0;
    }
コード例 #3
0
ファイル: globject.cpp プロジェクト: Krutoy242/Game
void GLObject::setMoveDisplace( GLObject & obj ){
    float vx = x()-obj.x(),
          vy = y()-obj.y();

//    bool nMove = 1;
//    UnitBehavior* u    = ((UnitBehavior*)getBehavior("unit")),
//                * uObj = ((UnitBehavior*)obj.getBehavior("unit"));
//    if( u && u->isMove() )
//      nMove = 0;

//    bool hashCmp = obj.getHashCode() > this->getHashCode();
//    if( u && uObj &&
//        u->sqrDistanceToTaget() < uObj->sqrDistanceToTaget() )
//      hashCmp = 0;

//    if( obj.getClass()->speed > 0 &&
//        ( hashCmp || nMove || u->getWarrior()->isAtack() ) )
//      setMoveDisplace(vx, vy);
    setMoveDisplace(vx, vy);
    }
コード例 #4
0
ファイル: bmpmap.cpp プロジェクト: Krutoy242/Game
void BmpMap::pixel(Game &game, int x, int y, const QColor& c){
    if( c==QColor(0, 0, 0) ){
      if( game.rand()%10==0 )
        game.add("grass")->setPosition(x, y, 0);
      } else
    if( c==QColor(0, 255, 0) ){
      game.add("tree0")->setPosition(x, y, 0);
      } else

    if( c.red()==0 && c.blue()==0 &&
        c.green() <= 127){
      for(int i=0; i<1; ++i){
        std::string name = "rock0";
        name.push_back('0'+rand()%5+1 );

        if( rand()%10==0 )
          game.add( name )->setPosition(x,
                                        y, 0);
        }
      } else

    if( c==QColor(128, 128, 128) ){
      int mx =  Map::coordX(x),
          my =  Map::coordX(y);
      game.map.setHeight( mx, my,
                          std::min(-4.0f, game.map.height(mx,my)));

      for(int i=-3; i<=3; ++i)
        for(int r=-3; r<=3; ++r){
          float w = std::max(1.0-sqrt(i*i+r*r)/3.0, 0.0);
          game.map.setHeight( mx+i, my+r,
                              std::min(-4.0f*w, game.map.height(mx+i,my+r)));
          game.map.excludeQuad(mx+i, my+r, 0);
          }

      } else

    if( c==QColor(255, 255, 0) ){
      game.add("gold")->setPosition(x, y, 0);
      } else

    if( c==QColor(255, 255, 255) ){
      if( game.playler(curPl).isActive() && curPl<9 ){
        GLObject *obj = game.add("castle");
        obj->setPosition(x, y, 0);
        obj->setPlayler( curPl );

        for(int i=0; i<6; ++i){
          GLObject *obj = game.add("worker");
          obj->setPosition(x+(i%3)*0.5, y+(i/3)*0.5, 0);
          obj->setPlayler( curPl );
          }
        }

      ++curPl;
      }

    }
コード例 #5
0
void WorldLoader::readString(std::string s){
    jsonRoot = parseJSON(s);
    JSONValue& jo = *jsonRoot;
    
    if (!serverMode){
        //Read and load the textures
        std::cout<<"Reading textures\n";
        std::vector<std::string> textures = jo["textures"].keys();
        
        for (std::vector<std::string>::iterator it=textures.begin(); it!=textures.end(); it++){
            //std::cout<<*it<<std::endl;
            tm.addTexture(*jo["textures"][*it],*it);
        }
    }
    //Read Projection details..
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(parseDouble(*jo["projection"]["fov"]),
                    parseDouble(*jo["projection"]["aspectRatio"]),
                    parseDouble(*jo["projection"]["near"]),
                    parseDouble(*jo["projection"]["far"])
    );

    //std::cout<<jo.stringise()<<std::endl;

    //load objects..
    int objectsCount = jo["objects"].length();
    //std::cout<<"Loading "<<objectsCount<<" objects."<<std::endl;
    for (int i=0; i<objectsCount; i++){
        GLObject* glo;
        if (*jo["objects"][i]["type"] == "cube"){
            glo = new GLCube();
            glo->setTextureManager(&tm);
            glo->setTexturePrefix(*jo["objects"][i]["texturePrefix"]);
            if (serverMode){
                jo["objects"][i].setMapValue("oid",parseJSON("\"" + getNewRandomOID() + "\""));
            }
            glo->setObjectID(*jo["objects"][i]["oid"]);
            
            
            //set up transformations..
            double position[3], rotation[3], size[3];
            std::istringstream  issp(*jo["objects"][i]["position"]),
                                isso(*jo["objects"][i]["orientation"]),
                                isss(*jo["objects"][i]["dimensions"]);
            
            issp>>position[0]>>position[1]>>position[2];
            isso>>rotation[0]>>rotation[1]>>rotation[2];
            isss>>size[0]>>size[1]>>size[2];
            glo->setPosition(position[0], position[1], position[2]);
            glo->setRotation(rotation[0], rotation[1], rotation[2]);
            glo->setSize(size[0], size[1], size[2]);
        }else{
コード例 #6
0
ファイル: ObjectView.cpp プロジェクト: DonCN/haiku
void
ObjectView::DrawFrame(bool noPause)
{
	LockGL();
	glClear(GL_COLOR_BUFFER_BIT | (fZbuf ? GL_DEPTH_BUFFER_BIT : 0));

	fObjListLock.Lock();
	for (int i = 0; i < fObjects.CountItems(); i++) {
	  GLObject *object = reinterpret_cast<GLObject*>(fObjects.ItemAt(i));
		if (object->Solidity() == 0)
			object->Draw(false, NULL);
	}
	EnforceState();
	for (int i = 0; i < fObjects.CountItems(); i++) {
		GLObject *object = reinterpret_cast<GLObject*>(fObjects.ItemAt(i));
		if (object->Solidity() != 0)
			object->Draw(false, NULL);
	}
	fObjListLock.Unlock();

	glDisable(GL_BLEND);
	glDepthMask(GL_TRUE);

	if (noPause) {
		uint64 now = system_time();
		float fps = 1.0 / ((now - fLastFrame) / 1000000.0);
		fLastFrame = now;
		int entry;
		if (fHistEntries < HISTSIZE) {
			entry = (fOldestEntry + fHistEntries) % HISTSIZE;
			fHistEntries++;
		} else {
			entry = fOldestEntry;
			fOldestEntry = (fOldestEntry + 1) % HISTSIZE;
		}

		fFpsHistory[entry] = fps;

		if (fHistEntries > 5) {
			fps = 0;
			for (int i = 0; i < fHistEntries; i++)
				fps += fFpsHistory[(fOldestEntry + i) % HISTSIZE];

			fps /= fHistEntries;

			if (fFps) {
				glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT);
				glPushMatrix();
				glLoadIdentity();
				glTranslatef(-0.9, -0.9, 0);
				glScalef(0.10, 0.10, 0.10);
				glDisable(GL_LIGHTING);
				glDisable(GL_DEPTH_TEST);
				glDisable(GL_BLEND);
				glColor3f(1.0, 1.0, 0);
				glMatrixMode(GL_PROJECTION);
				glPushMatrix();
				glLoadIdentity();
				glMatrixMode(GL_MODELVIEW);

				FPS::drawCounter(fps);

				glMatrixMode(GL_PROJECTION);
				glPopMatrix();
				glMatrixMode(GL_MODELVIEW);
				glPopMatrix();
				glPopAttrib();
			}
		}
	} else {
		fHistEntries = 0;
		fOldestEntry = 0;
	}
	SwapBuffers();
	UnlockGL();
}