/*询问*/
	inline void query() {/*这是题目特定函数*/
		int l , r;
		scanf("%d%d",&l,&r);
		RotateTo(l-1 , 0);
		RotateTo(r+1 , root);
		printf("%lld\n",sum[keyTree]);
	}
	/*更新*/
	inline void update( ) {/*这是题目特定函数*/
		int l , r , c;
		scanf("%d%d%d",&l,&r,&c);
		RotateTo(l-1,0);
		RotateTo(r+1,root);
		add[ keyTree ] += c;
		sum[ keyTree ] += (long long)c * sz[ keyTree ];
	}
Beispiel #3
0
	ll query(int l, int r) {
		if( l>r ) swap(l, r);
		RotateTo(l-1, null);
		RotateTo(r+1, root);
		TNode<T> *now = root->rc->lc;
		now->up();
		return now->sum + now->inc*now->sz;
	}
void CComputerBauer::HandleGolfer(const float elapsed)
{
	CChicken* c=(CChicken*)SearchNextChicken();
	if (c==NULL)return;

	// um 0.07 RAD weiter nach links drehen um noch richtig zu zielen
	float w=GetWinkel(ang.y,c->pos)-0.07f;
	float entf=Magnitude(pos-c->pos);

	if (abs(w)>0.025f)w=RotateTo(w,elapsed*((entf<13.0f)?2.25f:1.0f));

	if (entf>1.5f)speed.z=4.4f;
	else speed.z=0.0f;

	if ((w<0.1f)&&(entf<2.0f))
	{	// Zuschlagen
		ang.x=-0.2f;

		CGolfer* g=(CGolfer*)object;
		if (g->Schlag())
		{
			g->SendNotify(3);
		}
	}
}
void CComputerBauer::HandleGartenkralle(const float elapsed)
{
	CChicken* c=(CChicken*)SearchNextChicken();
	if (c==NULL)return;

	// um 0.07 RAD weiter nach links drehen um noch richtig zu zielen
	float w=GetWinkel(ang.y,c->pos)-0.07f;
	float entf=Magnitude(pos-c->pos);

	if (abs(w)>0.02f)w=RotateTo(w,elapsed*((entf<13.0f)?2.25f:1.0f));

	if (entf>1.3f)speed.z=4.0f;
	else speed.z=0.0f;

	if ((w<0.1f)&&(entf<1.8f))
	{	// Zustechen
		ang.x=-0.45f;

		CGartenkralle* g=(CGartenkralle*)object;
		if (g->Stoss())
		{
			g->SendNotify(2);
			g->EndStoss();
		}
	}
}
void CComputerBauer::HandlePlasmaCannon(const float elapsed)
{
	CPlasmaCannon* p=(CPlasmaCannon*)object;
	if (p->munition<1.0f)
	{	// Weglegen, wenn keine Munni mehr
		p->Throw();
		p->SendNotify(2);
		object=NULL;

//		RotateTo(D3DVECTOR(0,0,0),elapsed);
		return;
	}

	CChicken* c=(CChicken*)SearchNextChicken();
	if (c==NULL)return;

	// um 0.07 RAD weiter nach links drehen um noch richtig zu zielen
	float w=GetWinkel(ang.y,c->pos)-0.07f;
	float entf=Magnitude(pos-c->pos);

	if (abs(w)>0.02f)w=RotateTo(w,elapsed*((entf<13.0f)?1.85f:0.9f));

	if (entf<2.5f)speed.z=-2.5f;
		else if (entf>5.0f)speed.z=3.3f;
		else speed.z=0.0f;

	if ((w<0.1f)&&(p->CanShoot())&&(entf<17.0f))
	{	// Schießen
		float sx=sqrtf(sqr(pos.x-c->pos.x)+sqr(pos.z-c->pos.z));
		// 0.65 weiter oben ansetzen, bei Plasmakanone
		float sy=pos.y+0.65f-c->pos.y;
		float alpha=0.0f;
		float bestdistance=4.0f;

		float aktalpha=-0.7f;
		do
		{
			float y=GetSchussY(sx,aktalpha);

			if (abs(y-sy)<bestdistance)
			{
				bestdistance=abs(y-sy);
				alpha=aktalpha;
			}

			aktalpha+=0.05f;
		}while (aktalpha<g_PI*0.5f);

		if (bestdistance<4.0f)
		{
			ang.x=-alpha;

			if (p->Shoot())p->SendNotify(1);
		}else ang.x=0.0f;
	}
}
Beispiel #7
0
GameObject::GameObject(void) : tPosition(GameObject::WORLD),
	tObject(GameObject::SPRITE),
	velocity(0,0,0),
	worldMatrix(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),
	lookDirection(1,0,0),
	mMeshOirentation(1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1),
	duration(1.f),
	parent(NULL)
{
	myVertex.AnimationProgress = 0;
	myVertex.AnimationSize = 1;
	myVertex.TextureIndex = 0;
	myVertex.Opacity = 1;
	SetColor(D3DXCOLOR(0,0,0,0));
	RotateTo(0,0,0);
	TranslateTo(0,0,0);
	ScaleTo(0.f);
}
const BOOLEAN CComputerBauer::SearchWeapon(const float elapsed)
{
	// Nächste Waffe in der Umgebung suchen
	ang.x=0.0f;
	CWeapon* found=NULL;
	float entf=150.0f;

	CObject* o=chain->GetFirst();
	while (o)
	{
		switch(GetType(o->id))
		{
		case IDDrescher:
		case IDPlasmaCannon:
		case IDGartenkralle:
		case IDGolfer:
			{
				CWeapon *w=(CWeapon*)o;
				if ((w->parent==NULL)&&(Magnitude(w->pos-pos)<entf))
				{
					if ((o->IsType(IDPlasmaCannon))&&(((CPlasmaCannon*)w)->munition<3))goto dochnicht;
					if ((o->IsType(IDGartenkralle))&&(((CGartenkralle*)w)->werfer!=NULL))goto dochnicht;
					
					found=w;
					entf=Magnitude(w->pos-pos);

				}
			}
			break;
		}
dochnicht:
		o=o->next;
	}
	if (found!=NULL)
	{
		float w=RotateTo(found->pos,elapsed);
		if (w<0.3f)speed.z=5.0f;else speed.z=1.5f;
		return TRUE;
	}else{
		// Keine brauchbare Waffe gefunden -> Dumm rumlaufen?
		speed=D3DVECTOR(0,0,0);
		return FALSE;
	}
}
Beispiel #9
0
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);
}
Beispiel #10
0
	GameObject::GameObject(int textureIndex, float scale, float posX, float posY, float posZ, float dur, PositionType tPos) :
//	myMesh(NULL),
	//position(&v.Position),
	//color(&v.Color),
	tObject(SPRITE),
	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)
{
	myVertex.TextureIndex = textureIndex;
	myVertex.AnimationSize = 0;
	myVertex.AnimationProgress = 0;
	myVertex.Opacity = 1.f;
	SetColor(D3DXCOLOR(0,0,0,0));
	ScaleTo(scale);
	TranslateTo(posX,posY,posZ);
	RotateTo(0,0,0);
}
void WorldPhysics::AI() {
  if (tmp_wait>0) {tmp_wait--;return;}
  if (bulldozer_state==8) speed=0;
  
  const dReal* BPosition=bulldozer->getPosition();
//  const dReal* BRotation=bulldozer->getRotation();
  dReal minDistance=150; //~100 * sqrt(2)

  Item* tmp;
  int currentItemN=-1;
  if (items.size()==0) return;
  for (int i=0;i<items.size();i++) {
    const dReal* ItemPosition=items[i]->getPosition();
    if (ItemPosition[2]<0) items[i]->state=2;
    if (items[i]->state==2) continue;
    if (items[i]->state==1) {currentItemN=i;break;}
    if (items[i]->state==0) {
      dReal tmpmin=sqrt((ItemPosition[0]-BPosition[0])*
            (ItemPosition[0]-BPosition[0]) + 
            (ItemPosition[1]-BPosition[1])*
            (ItemPosition[1]-BPosition[1]));
      if (tmpmin<minDistance) {
        minDistance=tmpmin;
        currentItemN=i;
      }
    }
  }
  if (currentItemN==-1) {
    //bulldozer_state=0;
    generateItems();
    return;
  }
  /*
  for (int i=0;i<items.size();i++) {
    const dReal* tmp_pos=items[i]->getPosition();
    if (tmp_pos[2]<0) items[i]->state=2;

    if (items[i]->state==1) {
      currentItemN=i;
      break;
    }
    if (items[i]->state==2) currentItemN++;
  }
  if (currentItemN>=items.size()) return;
  */
  tmp=items[currentItemN];
  const dReal* ItemPosition=tmp->getPosition();
  switch (tmp->state) {
    case 0: { // Выбрали нужный кубик
      tmp->state=1;
      bulldozer_state=1; // Поворот до кубика
    } break;
    case 1: {  // Надо к нему подъехать
    switch (bulldozer_state) {
        
        case 1:{
          speed=0;
          if (RotateTo(ItemPosition[0]-BPosition[0],ItemPosition[1]-BPosition[1])) bulldozer_state=2;
        } break;
        
        case 2: {
          if (RotateTo(ItemPosition[0]-BPosition[0],ItemPosition[1]-BPosition[1])) {
            speed=3;
            if (((ItemPosition[0]-BPosition[0])*
              (ItemPosition[0]-BPosition[0]) + 
              (ItemPosition[1]-BPosition[1])*
              (ItemPosition[1]-BPosition[1]))<50) {
              speed=0;
              bulldozer_state=3;
              }
                
          } else {
            speed=0;
            bulldozer_state=1;
          }
        } break;
        case 3: {
          cheat_joint=dJointCreateSlider(world,0);
          dJointAttach(cheat_joint,bulldozer->body,tmp->body);
          dJointSetSliderAxis(cheat_joint,0,0,1);
          //dJointSetSliderParam (cheat_joint, dParamCFM, 0.5);
          bulldozer_state=4;
        }break;
        case 4: {
          if (RotateTo(100-BPosition[0],0-BPosition[1])) bulldozer_state=5;
        }break;
        case 5: {
          if (RotateTo(100-BPosition[0],0-BPosition[1])) {
            speed=3;
            if (sqrt((100-BPosition[0])*
                  (100-BPosition[0]) + 
                  (0-BPosition[1])*
                  (0-BPosition[1]))<(sqrt(2)*25+LENGTH/2+RADIUS)) {
              speed=0;
              bulldozer_state=6;
                  }
                
          } else {
            speed=0;
            bulldozer_state=4;
          }
        } break;
        
      case 6: {
        dJointDestroy(cheat_joint);
        dBodyAddForce(tmp->body,100-BPosition[0],0-BPosition[1], 5);
        bulldozer_state=7;
      } break;
      case 7: {
        speed=-10;
        tmp_wait=70;
        bulldozer_state=8;
      } break;
      case 8: {
        speed=0;
        tmp->state=2;
      } break;
        
      
      
      
      }
    } break;
  }
  
}
Beispiel #12
0
	void update(int l, int r, T val) {
		RotateTo(l-1, null);
		RotateTo(r+1, root);
		root->rc->lc->inc += val;
		root->rc->lc->up();
	}
Beispiel #13
0
void StaticObject::Rotate(float deg, glm::vec3 axis)
{
    //this->toWorld = glm::rotate(glm::mat4(1.0f), glm::radians(deg), axis) * this->toWorld;
    //this->normalMatrix = glm::mat3(glm::transpose(glm::inverse(toWorld)));
    RotateTo(glm::mat3(glm::rotate(toWorld, glm::radians(deg), axis)));
}
Beispiel #14
0
void Property::Rotate(float degree)
{
	RotateTo(rotation + degree);
}
		//----------------------------------------------------------------
		/// Rotate To
		///
		/// Rotate about the given axis to the given angle 
		///
		/// @param X-axis Component
		/// @param Y-axis Component
		/// @param Z-axis Component
		/// @param Angle in radians
		//----------------------------------------------------------------
		void Transform::RotateTo(f32 inXAxis, f32 inYAxis, f32 inZAxis, f32 infAngleRads)
		{
			RotateTo(Vector3(inXAxis,inYAxis,inZAxis),infAngleRads);
		}