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; } }
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; }