Esempio n. 1
0
void Mouth::commit() {
#ifdef DEBUG
	World::assertOnMainThread();
#endif
	if (committed_) {
		physBody_.b2Body_->DestroyFixture(
				&physBody_.b2Body_->GetFixtureList()[0]);
		physBody_.b2Body_->GetWorld()->DestroyJoint(pJoint);
		pJoint = nullptr;
	}

	bufferSize_ = size_ * BodyConst::MouthBufferDensity;

	// create fixture:
	b2PolygonShape shape;
	shape.SetAsBox(length_ * 0.5f, width_ * 0.5f); // our x and y mean length and width, so are reversed (because length is parallel to OX axis)
	b2FixtureDef fixDef;
	fixDef.density = BodyConst::MouthDensity;
	fixDef.friction = 0.2f;
	fixDef.restitution = 0.3f;
	fixDef.shape = &shape;

	physBody_.b2Body_->CreateFixture(&fixDef);

	b2WeldJointDef jdef;
	jdef.bodyA = parent_->getBody().b2Body_;
	jdef.bodyB = physBody_.b2Body_;
	glm::vec2 parentAnchor = parent_->getChildAttachmentPoint(attachmentDirectionParent_);
	jdef.localAnchorA = g2b(parentAnchor);
	glm::vec2 childAnchor = getChildAttachmentPoint(PI - localRotation_);
	jdef.localAnchorB = g2b(childAnchor);
	pJoint = (b2WeldJoint*) physBody_.b2Body_->GetWorld()->CreateJoint(&jdef);
}
Esempio n. 2
0
static void GB2Big(char *istr, char *ostr, int inlen)
{
  unsigned char s[2];

#ifdef DEBUG
  debug_message("translate GB to BIG5.\n");
#endif

  while(inlen >= 2)
  {
    s[0] = *istr++;
    s[1] = *istr++;

    if(is_GB1(s[0]) && is_GB2(s[1]))
    {
      g2b(s);
      *ostr++ = s[0];
      *ostr++ = s[1];
      inlen -= 2;
    }
    else
    {
      *ostr++ = s[0];
      istr--;
      inlen--;
    }
  }

  if(inlen > 0)
    *ostr++ = *istr;

  *ostr = '\0';
}
/*
  test of get_hash() : different objects, different hash
*/
void TestPosInTextRanges::test9b(void)
{
  PosInTextRanges g1a(QString("94-98+99-100+101-105+123-125"));
  PosInTextRanges g1b(QString("94-98+99-100+101-104+123-125"));
  QVERIFY( g1a.get_hash() != g1b.get_hash() );

  PosInTextRanges g2a(QString(""));
  PosInTextRanges g2b(QString("1-2"));
  QVERIFY( g2a.get_hash() != g2b.get_hash() );

  PosInTextRanges g3a(QString("1-2"));
  PosInTextRanges g3b(QString("1-3"));
  QVERIFY( g3a.get_hash() != g3b.get_hash() );
}
/*
  test of get_hash() : same objects, same hash
*/
void TestPosInTextRanges::test9a(void)
{
  PosInTextRanges g1a(QString("94-98+99-100+101-105+123-125"));
  PosInTextRanges g1b(QString("94-98+99-100+101-105+123-125"));
  QCOMPARE( g1a.get_hash() , g1b.get_hash() );

  PosInTextRanges g2a(QString(""));
  PosInTextRanges g2b(QString(""));
  QCOMPARE( g2a.get_hash() , g2b.get_hash() );

  PosInTextRanges g3a(QString("1-2"));
  PosInTextRanges g3b(QString("1-2"));
  QCOMPARE( g3a.get_hash() , g3b.get_hash() );
}
Esempio n. 5
0
int
main()
{
	unsigned char c[2], cc[2];
	int i;
	printf("//g2btab[c2-0x40][(c1-0x80)*2], g2btab[c2-0x40][(c1-0x80)*2+1]\n");
	printf("//c1: 0x80-0xff, c2: 0x40-0xfe\n");
	printf("static const char g2btab[192][256]={\n");
	for(c[1] = 0x40; /*c[1]<= 0xff &&*/c[1]; c[1]++) {
		printf("\t{");
		for(i=0, c[0]=0x80; /*c[0]<=0xff&&*/c[0]; c[0]++, i++) {
			cc[0]=c[0];
			cc[1]=c[1];
			g2b(cc);
			correctg2b(c, cc);
			if(cc[0]==GtoB_bad1&&cc[1]==GtoB_bad2){
				cc[0]=c[0];
				cc[1]=c[1];
				extrag2b(cc);
			}
			printf("%3d,%3d%s", (int)cc[0], (int)cc[1], c[0]==0xff?"":",");
			if(i%10==9) printf("\n\t ");
		}
		printf("}%s\n", c[1]==0xff?"":",");
	}
	printf("};\n");
	printf("//b2gtab[c2-0x40][(c1-0x80)*2], b2gtab[c2-0x40][(c1-0x80)*2+1]\n");
	printf("//c1: 0x80-0xff, c2: 0x40-0xfe\n");
	printf("static const char b2gtab[192][256]={\n");
	for(c[1] = 0x40; c[1]<= 0xff&&c[1]; c[1]++) {
		printf("\t{");
		for(i=0, c[0]=0x80; c[0]<=0xff&&c[0]; c[0]++, i++) {
			cc[0]=c[0];
			cc[1]=c[1];
			b2g(cc);
			correctg2b(c, cc);
			if(cc[0]==BtoG_bad1&&cc[1]==BtoG_bad2) {
				cc[0]=c[0];
				cc[1]=c[1];
				extrab2g(cc);
			}
			printf("%3d,%3d%s", (int)cc[0], (int)cc[1], c[0]==0xff?"":",");
                        if(i%10==9) printf("\n\t ");
		}
		printf("}%s\n", c[1]==0xff?"":",");
	}
	printf("};\n");
	return 0;
}