| 182 | } |
| 183 | |
| 184 | void demo2Create() { |
| 185 | defaultDrawOptions(); |
| 186 | |
| 187 | createJointAndBody(); |
| 188 | |
| 189 | mWindow->setTitle( "eepp - Physics - Pyramid Stack" ); |
| 190 | |
| 191 | Shape::resetShapeIdCounter(); |
| 192 | |
| 193 | mSpace = Physics::Space::New(); |
| 194 | mSpace->setGravity( cVectNew( 0, 100 ) ); |
| 195 | mSpace->setSleepTimeThreshold( 0.5f ); |
| 196 | |
| 197 | Body *body, *staticBody = mSpace->getStaticBody(); |
| 198 | Shape* shape; |
| 199 | |
| 200 | shape = mSpace->addShape( |
| 201 | ShapeSegment::New( staticBody, cVectNew( 0, mWindow->getHeight() ), |
| 202 | cVectNew( mWindow->getWidth(), mWindow->getHeight() ), 0.0f ) ); |
| 203 | shape->setE( 1.0f ); |
| 204 | shape->setU( 1.0f ); |
| 205 | shape->setLayers( NOT_GRABABLE_MASK ); |
| 206 | |
| 207 | shape = mSpace->addShape( |
| 208 | ShapeSegment::New( staticBody, cVectNew( mWindow->getWidth(), 0 ), |
| 209 | cVectNew( mWindow->getWidth(), mWindow->getHeight() ), 0.0f ) ); |
| 210 | shape->setE( 1.0f ); |
| 211 | shape->setU( 1.0f ); |
| 212 | shape->setLayers( NOT_GRABABLE_MASK ); |
| 213 | |
| 214 | shape = mSpace->addShape( ShapeSegment::New( staticBody, cVectNew( 0, 0 ), |
| 215 | cVectNew( 0, mWindow->getHeight() ), 0.0f ) ); |
| 216 | shape->setE( 1.0f ); |
| 217 | shape->setU( 1.0f ); |
| 218 | shape->setLayers( NOT_GRABABLE_MASK ); |
| 219 | |
| 220 | shape = mSpace->addShape( ShapeSegment::New( staticBody, cVectNew( 0, 0 ), |
| 221 | cVectNew( mWindow->getWidth(), 0 ), 0.0f ) ); |
| 222 | shape->setE( 1.0f ); |
| 223 | shape->setU( 1.0f ); |
| 224 | shape->setLayers( NOT_GRABABLE_MASK ); |
| 225 | |
| 226 | Float hw = mWindow->getWidth() / 2; |
| 227 | |
| 228 | for ( int i = 0; i < 14; i++ ) { |
| 229 | for ( int j = 0; j <= i; j++ ) { |
| 230 | body = mSpace->addBody( Body::New( 1.0f, Moment::forBox( 1.0f, 30.0f, 30.0f ) ) ); |
| 231 | body->setPos( cVectNew( hw + j * 32 - i * 16, 100 + i * 32 ) ); |
| 232 | |
| 233 | shape = mSpace->addShape( ShapePoly::New( body, 30.f, 30.f ) ); |
| 234 | shape->setE( 0.0f ); |
| 235 | shape->setU( 0.8f ); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | cpFloat radius = 15.0f; |
| 240 | |
| 241 | body = |