| 127 | static int bodyCount = 0; |
| 128 | |
| 129 | void demo1Create() { |
| 130 | defaultDrawOptions(); |
| 131 | |
| 132 | createJointAndBody(); |
| 133 | |
| 134 | mWindow->setTitle( "eepp - Physics - Logo Smash" ); |
| 135 | |
| 136 | mSpace = Physics::Space::New(); |
| 137 | mSpace->setIterations( 1 ); |
| 138 | |
| 139 | // The space will contain a very large number of similarly sized objects. |
| 140 | // This is the perfect candidate for using the spatial hash. |
| 141 | // Generally you will never need to do this. |
| 142 | mSpace->useSpatialHash( 2.0, 10000 ); |
| 143 | |
| 144 | bodyCount = 0; |
| 145 | |
| 146 | Body* body; |
| 147 | Shape* shape; |
| 148 | |
| 149 | Float pX = mWindow->getWidth() / 2 - ( image_width * 4 ) / 2; |
| 150 | Float pY = mWindow->getHeight() / 2 - ( image_height * 4 ) / 2; |
| 151 | |
| 152 | for ( int y = 0; y < image_height; y++ ) { |
| 153 | for ( int x = 0; x < image_width; x++ ) { |
| 154 | if ( !get_pixel( x, y ) ) |
| 155 | continue; |
| 156 | |
| 157 | shape = make_ball( pX + x * 4, pY + y * 4 ); |
| 158 | |
| 159 | mSpace->addBody( shape->getBody() ); |
| 160 | mSpace->addShape( shape ); |
| 161 | |
| 162 | bodyCount++; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | body = mSpace->addBody( Body::New( INFINITY, INFINITY ) ); |
| 167 | body->setPos( cVectNew( 0, mWindow->getHeight() / 2 + 16 ) ); |
| 168 | body->setVel( cVectNew( 400, 0 ) ); |
| 169 | |
| 170 | shape = mSpace->addShape( ShapeCircle::New( body, 8.0f, cVectZero ) ); |
| 171 | shape->setElasticity( 0.0 ); |
| 172 | shape->setFriction( 0.0 ); |
| 173 | shape->setLayers( NOT_GRABABLE_MASK ); |
| 174 | |
| 175 | bodyCount++; |
| 176 | } |
| 177 | |
| 178 | void demo1Update() {} |
| 179 | |