예제 #1
0
void Mouse( int button, int state, int x, int y )
{
  x /= 10.0f;
  y /= 10.0f;

  if(state == GLUT_DOWN)
    switch(button)
    {
    case GLUT_LEFT_BUTTON:
      {
        PolygonShape poly;
        uint32 count = (uint32)Random( 3, MaxPolyVertexCount );
        Vec2 *vertices = new Vec2[count];
        real e = Random( 5, 10 );
        for(uint32 i = 0; i < count; ++i)
          vertices[i].Set( Random( -e, e ), Random( -e, e ) );
        poly.Set( vertices, count );
        Body *b = scene.Add( &poly, x, y );
        b->SetOrient( Random( -PI, PI ) );
        b->restitution = 0.2f;
        b->dynamicFriction = 0.2f;
        b->staticFriction = 0.4f;
        delete [] vertices;
      }
      break;
    case GLUT_RIGHT_BUTTON:
      {
        Circle c( Random( 1.0f, 3.0f ) );
        Body *b = scene.Add( &c, x, y );
      }
      break;
    }
}
예제 #2
0
TEST(Moveable, applyForce) {
  Vector2d g = { 0.0, 0.0 };
  Vector2d initV = { 1.0, 1.0 };
  Vector2d initP = { 0.0, 0.0 };
  Vector2d force = { 4.0, 0.0 };
  World w(g);
  PolygonShape p;
  p.SetAsBox(2, 1);

  Moveable m(initV, initP);
  Entity e;

  m.init(w, p, e);

  auto actual = m.getVel();

  EXPECT_EQ(actual, initV);

  m.applyForce(force);
  w.Step(0.8, 8, 2);

  actual = m.getVel();

  // Note: 1.4 value found through trial.
  EXPECT_EQ(actual.x, 1.4f);
  EXPECT_EQ(actual.y, 1);
}
예제 #3
0
int main( void )
{
  glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE );
  glutInitWindowSize( 800, 600 );
  glutCreateWindow( "PhyEngine" );
  glutDisplayFunc( PhysicsLoop );
  glutKeyboardFunc( Keyboard );
  glutMouseFunc( Mouse );
  glutIdleFunc( PhysicsLoop );

  glMatrixMode( GL_PROJECTION );
  glPushMatrix( );
  glLoadIdentity( );
  gluOrtho2D( 0, 80, 60, 0 );
  glMatrixMode( GL_MODELVIEW );
  glPushMatrix( );
  glLoadIdentity( );

  Circle c( 5.0f );
  Body *b = scene.Add( &c, 40, 40 );
  b->SetStatic( );

  PolygonShape poly;
  poly.SetBox( 30.0f, 1.0f );
  b = scene.Add( &poly, 40, 55 );
  b->SetStatic( );
  b->SetOrient( 0 );

  srand( 1 );

  glutMainLoop( );

  return 0;
}
예제 #4
0
TEST(Moveable, getsetMass) {
  Moveable c;
  float expectedMass = 4.5;
  Vector2d expectedCenter = { 1, 1 };

  c.setMass(expectedMass,
      expectedCenter,
      0);

  auto actual = c.getMass();

  EXPECT_EQ(actual, expectedMass);

  Vector2d g = { 0.0, 0.0 };
  World w(g);
  PolygonShape p;
  p.SetAsBox(2, 1);
  Entity e;

  c.init(w, p, e);

  actual = c.getMass();

  EXPECT_EQ(actual, expectedMass);
}
예제 #5
0
TEST(Thrust, onAddEntity) {
  Vector2d g = { 0.0, 0.0 };
  Vector2d initP = { 0, 0 };
  Vector2d initV = { 0, 0 };
  Vector2d direction = { 1, 1 };
  float factor = 1000;
  EvUserMovement ev(direction);
  World w(g);
  PolygonShape p;
  p.SetAsBox(2, 1);

  Moveable cm(initP, initV);
  Thrustable ct(factor);
  Entity* e = new Entity();
  Thrust s;
  cm.init(w, p, *e);

  e->addComponent(&cm);
  e->addComponent(&ct);

  s.onAddEntity(*e);

  e->emit(EV_USER_MOVEMENT, &ev);
  w.Step(0.8, 8, 2);

  auto actual = cm.getVel();

  EXPECT_FLOAT_EQ(actual.x, 2.5);
  EXPECT_FLOAT_EQ(actual.y, 0.0);
}
예제 #6
0
void le::Body::CreatePolygonShape( Vector2f SizeBody, Vector2f Center, float Angle )
{
	if ( body != NULL )
	{
		PolygonShape* Shape = new PolygonShape( SizeBody, Center, Angle );
		Shape->SetPropirtes( fDensity, fRestitution, fFriction );
		Shape->SetFixture( body->CreateFixture( &Shape->GetFixtureDef() ) );
		body->GetFixtureList()->SetFilterData( *Filter );
		vShape.push_back( Shape );
	}
}
예제 #7
0
TEST(Moveable, init) {
  Vector2d g = { 0, 0 };
  World w(g);
  PolygonShape p;
  p.SetAsBox(2, 1);
  Moveable c;
  Entity e;

  c.init(w, p, e);

  auto actual = c.getBody();

  EXPECT_NE(actual, nullptr);
}
예제 #8
0
void le::Body::SetPropirtes( float Density, float Restitution, float Friction )
{
	for ( int i = 0; i < vShape.size(); i++)
	{
		PolygonShape* Shape = vShape[ i ];
		Shape->SetPropirtes( Density, Restitution, Friction );
	}

	for ( int i = 0; i < vCircle.size(); i++)
	{
		CircleShape* Circle = vCircle[ i ];
		Circle->SetPropirtes( Density, Restitution, Friction );
	}

	fDensity = Density;
	fRestitution = Restitution;
	fFriction = Friction;
}
예제 #9
0
	WSRockObject* WaterState::CreateRockObject(const Vector2f & pos)
	{
		WSRockObject* currentRock = new WSRockObject(m_world);

		Sprite* currentSprite = new Sprite();
		currentSprite->SetTexture(m_pRockTexture);
		currentSprite->SetColor(Vector4f(1.f, 1.f, 1.f, 1.f));
		currentSprite->SetLayer(0.f);
		currentSprite->SetShading(SpriteVertex::ALPHA_BLEND);
		currentSprite->m_position = pos;

		currentRock->SetSprite(currentSprite);

		PolygonShape* currentShape = new PolygonShape();

		ifstream f("assets/Sprites/Water/rocktexturepoints.txt");
		int count = 0;
		f >> count;
		Vector2f* vertices = new Vector2f[count];
		Vector2f offset;
		f >> offset.x >> offset.y;
		offset = -offset;

		for (int i = 0; i < count; ++ i)
		{
			Vector2f now;
			f >> now.x >> now.y;
			now += offset;
			vertices[i] = now;
		}

		currentShape->Set(vertices, count);

		currentRock->SetShape(currentShape, pos);

		delete currentShape;
		delete vertices;

		m_rockObjects.push_back(currentRock);

		return currentRock;

	}
예제 #10
0
void le::Body::SetSize( Vector2f SizeBody )
{
	for ( int i = 0; i < vShape.size(); i++ )
	{
		PolygonShape* Shape = vShape[ i ];
		body->DestroyFixture( &Shape->GetFixture() );
		Shape->SetSize( SizeBody );
		Shape->SetFixture( body->CreateFixture( &Shape->GetFixtureDef() ) );
	}

	for ( int i = 0; i < vCircle.size(); i++ )
	{
		CircleShape* Circle = vCircle[ i ];
		body->DestroyFixture( &Circle->GetFixture() );
		Circle->SetRadius( SizeBody.x/2 );
		Circle->SetFixture( body->CreateFixture( &Circle->GetFixtureDef() ) );
	}

	body->GetFixtureList()->SetFilterData( *Filter );
}
예제 #11
0
TEST(Moveable, getAngle) {
  Vector2d g = { 0.0, 0.0 };
  Vector2d vel = { 1, 1 };
  Vector2d initPos = { 1, 1 };
  float expectedAngle = 89.3;
  World w(g);
  PolygonShape p;
  p.SetAsBox(2, 1);
  Entity e;

  Moveable c = Moveable(vel, initPos, expectedAngle);

  auto actual = c.getAngle();
  EXPECT_EQ(actual, expectedAngle);

  c.init(w, p, e);

  actual = c.getAngle();
  EXPECT_EQ(actual, expectedAngle);
}
예제 #12
0
int w_PolygonShape_getPoints(lua_State *L)
{
	PolygonShape *t = luax_checkpolygonshape(L, 1);
	lua_remove(L, 1);
	return t->getPoints(L);
}
예제 #13
0
int w_PolygonShape_validate(lua_State *L)
{
	PolygonShape *t = luax_checkpolygonshape(L, 1);
	luax_pushboolean(L, t->validate());
	return 1;
}