Exemplo n.º 1
0
// ==== fonctions pour charger la physique avant chaque début de level (tour + ennemis + bonus vies)
void loadPhysicsNormal(){
	initPhysics();
	// choisir aleatoirement quels etage ont une plateforme mobile et les initialiser (etage 0 a une plateforme obligatoirement)
	g_Plateforme[0] = NULL;
	initPlateform(0,((rand()/(double)RAND_MAX)*0.8f+4.2f),0);
	for(int i=1; i<nb_Etages; i++){
		g_Plateforme[i] = NULL;
		etageAvecPlateforme[i] = (int)(rand() % 2);//une chance sur 2 d'avoir une plateforme
		if(etageAvecPlateforme[i] ==0){
			float anglePlat =  ( rand()/(double)RAND_MAX ) * 0.8f + 4.2f;
			initPlateform(i,anglePlat,i);
		}
	}
	//remise à zero des ennemis
	for(int i=0; i<12; i++){
		for(int j=0; j<21; j++){
			g_Enemy[i][j] = NULL;
		}
	}
	createPhysicsOnMesh(nb_Etages);
	//creation des bonus vie
	for(int i=0; i<nb_BonusVie; i++){
		initObjets(tilesVies[i],etagesVies[i],i);
	}
	for(int i=nb_BonusVie; i<4; i++){
		g_ItemsState[i]=false;
	}
	//creation des ennemis
	for (int et=0; et<nb_Etages; et++){
		if(et==0 || et==3 || et==6 || et==9){
			for(int i=0; i<8; i++){
				if(tilesEnnemis[0][i]>0){
					// test pour ne pas mettre d'ennemi sur la plateforme mouvante
					if(!(etageAvecPlateforme[et] ==0 && (tilesEnnemis[0][i] == 10 |  tilesEnnemis[0][i] == 9))){
						initEnemy(tilesEnnemis[0][i],et);
						getInitialEnemiesPositions(g_Enemy[et][tilesEnnemis[0][i]],et,tilesEnnemis[0][i]);
						behaviors[et][tilesEnnemis[0][i]] = behaviorsEnnemis[0][i];
					}
				}
			}
		}else{
			int alea = (int)((rand() % (NUMBER_REPARTITIONS)));
			std::cerr<<"num alea = "<<alea<<std::endl;
			for(int i=0; i<8; i++){
				if(tilesEnnemis[0][i]>0){
					// test pour ne pas mettre d'ennemi sur la plateforme mouvante
					if(!(etageAvecPlateforme[et] ==0 && (tilesEnnemis[0][i] == 10 |  tilesEnnemis[0][i] == 9))){
						initEnemy(tilesEnnemis[alea][i],et);
						getInitialEnemiesPositions(g_Enemy[et][tilesEnnemis[alea][i]],et,tilesEnnemis[0][i]);
						behaviors[et][tilesEnnemis[0][i]] = behaviorsEnnemis[alea][i];
					}
				}
			}
		}
	}
	g_Enemy[0][1] = NULL;
	initPlayer(125*cos(4*M_PI/40),125*sin(4*M_PI/40),16);
	initAnimatedMesh();
	if(!menuDroite){beginTime = milliseconds();}
}
Exemplo n.º 2
0
bool Game::init(const mkString& cmd_line)
{
    rtti::TypeManager::getInstance().finishTypeRegistration();

    m_presetMgr = new rtti::PresetMgr;
    m_presetMgr->init();

    parseCmdLine(cmd_line);
    initRendering();
    initInput();
    initPhysics();

#ifdef ENABLE_BULLET_DEBUG_DRAW
    g_debugPhysicsDrawer = new BtOgre::DebugDrawer(m_ogreSceneMgr->getRootSceneNode(), m_physicsWorld);
    m_physicsWorld->setDebugDrawer(g_debugPhysicsDrawer);
#endif

    m_actorControllerFactory = new ActorControllerFactory;

    m_level = new Level();
    if (!m_level->load("data/levels/" + m_levelName + ".json"))
        return false;

    m_freelook = m_startWithFreelook;

	//Set Player conflict side to Neutral
	m_level->getPlayer()->setConflictSide(EConflictSide::Unknown);
    return true;
}
Exemplo n.º 3
0
// on "init" you need to initialize your instance
bool GameLayer::init()
{
	//////////////////////////////
	// 1. super init first
	if (!Layer::init())
	{
		return false;
	}

	Size visibleSize = Director::getInstance()->getVisibleSize();
	Vec2 origin = Director::getInstance()->getVisibleOrigin();

	initPhysics();
	

	//listen for touch, not multi touch app in this case.
	auto touchListener = EventListenerTouchOneByOne::create();
	touchListener->onTouchBegan = CC_CALLBACK_2(GameLayer::onTouchBegan, this);
	touchListener->onTouchMoved = CC_CALLBACK_2(GameLayer::onTouchMoved, this);
	touchListener->onTouchEnded = CC_CALLBACK_2(GameLayer::onTouchEnded, this);
	_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);

	//create main loop
	this->schedule(schedule_selector(GameLayer::update));

	return true;
}
Exemplo n.º 4
0
	void PhysicsObject::initPhysics(glm::vec3 position, btCollisionShape* shape, bool ground ){
		btDefaultMotionState* state =
			new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1),
			btVector3(position.x, position.y, position.z)));

		initPhysics(shape, state, ground);
	}
Exemplo n.º 5
0
bool HelloWorld::init()
{
if ( !Layer::init() )
    {
        return false;
    }
    
    initPhysics();
   
    this->schedule([this](float){
        for (b2Body* b = world->GetBodyList(); b; b = b->GetNext())
        {
            float timeStep = 0.03f;
            int32 velocityIterations = 8;
            int32 positionIterations = 1;
            
            world->Step(timeStep, velocityIterations, positionIterations);
            if (b->GetUserData() != nullptr) {
                Sprite* sprite = (Sprite*)b->GetUserData();
                sprite->setPosition( Vec2( b->GetPosition().x *
                                          PTM_RATIO, b->GetPosition().y * PTM_RATIO) );
                sprite->setRotation( -1 * CC_RADIANS_TO_DEGREES(b->GetAngle()) );
            }  
        }
        
    },0.0f,"Update");
    
    this->schedule([this](float){
        addOneSprite();
    },1.0f,"addSprite");
    return true;
}
Spacetime::Spacetime(void) 
{
	// Required physX runtime variable initializations
	gScene = NULL;
	gPhysics = NULL;
	gMaterial	= NULL;
	gFoundation = NULL;
	gDispatcher = NULL;
	gConnection	= NULL;
	deltaT = 1.0f / 600.0f;

	ANALYTIC = true;
	numTimeSteps = 10000;
	uThreshold = 10;

	initPhysics();

	state_0 = matrix<double>(DOF*joints.size()*2,1);
	state_d = matrix<double>(DOF*joints.size()*2,1);
		
	if (DOF == 1) {
		state_0(0,0) = -PxPi/4.0f;
		state_0(1,0) =  PxPi/4.0f;
		state_0(2,0) =  0.0f;
		state_0(3,0) =  0.0f;
		
		state_d(0,0) = 0.0f;
		state_d(1,0) = 0.0f;
		state_d(2,0) = 0.0f;
		state_d(3,0) = 0.0f;
	} 
	else if (DOF == 3) {
		state_0(0,0) = -PxPi/4.0f;
		state_0(1,0) =  0.0f;
		state_0(2,0) =  0.0f;
		state_0(3,0) =  PxPi/4.0f;
		state_0(4,0) =  0.0f;
		state_0(5,0) =  0.0f;
		state_0(6,0) =  0.0f;
		state_0(7,0) =  0.0f;
		state_0(8,0) =  0.0f;
		state_0(9,0) =  0.0f;
		state_0(10,0) = 0.0f;
		state_0(11,0) = 0.0f;

		state_d(0,0) = 0.0f;
		state_d(1,0) = 0.0f;
		state_d(2,0) = 0.0f;
		state_d(3,0) = 0.0f;
		state_d(4,0) = 0.0f;
		state_d(5,0) = 0.0f;
		state_d(6,0) = 0.0f;
		state_d(7,0) = 0.0f;
		state_d(8,0) = 0.0f;
		state_d(9,0) = 0.0f;
		state_d(10,0) = 0.0f;
		state_d(11,0) = 0.0f;
	}
}
Exemplo n.º 7
0
ChipmunkTestLayer::ChipmunkTestLayer()
{
#if CC_ENABLE_CHIPMUNK_INTEGRATION      
    // enable events

    auto touchListener = EventListenerTouchAllAtOnce::create();
    touchListener->onTouchesEnded = CC_CALLBACK_2(ChipmunkTestLayer::onTouchesEnded, this);
    _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);
    
    Device::setAccelerometerEnabled(true);
    auto accListener = EventListenerAcceleration::create(CC_CALLBACK_2(ChipmunkTestLayer::onAcceleration, this));
    _eventDispatcher->addEventListenerWithSceneGraphPriority(accListener, this);
    
    // title
    auto label = Label::createWithTTF("Multi touch the screen", "fonts/Marker Felt.ttf", 36.0f);
    label->setPosition(cocos2d::Point( VisibleRect::center().x, VisibleRect::top().y - 30));
    this->addChild(label, -1);

    // reset button
    createResetButton();

    // init physics
    initPhysics();

#if 1
    // Use batch node. Faster
    auto parent = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100);
    _spriteTexture = parent->getTexture();
#else
    // doesn't use batch node. Slower
    _spriteTexture = Director::getInstance()->getTextureCache()->addImage("Images/grossini_dance_atlas.png");
    auto parent = Node::create();
#endif
    addChild(parent, 0, kTagParentNode);

    addNewSpriteAtPosition(cocos2d::Point(200,200));

    // menu for debug layer
    MenuItemFont::setFontSize(18);
    auto item = MenuItemFont::create("Toggle debug", CC_CALLBACK_1(ChipmunkTestLayer::toggleDebugCallback, this));

    auto menu = Menu::create(item, NULL);
    this->addChild(menu);
    menu->setPosition(cocos2d::Point(VisibleRect::right().x-100, VisibleRect::top().y-60));

    scheduleUpdate();
#else
    auto label = Label::createWithTTF("Should define CC_ENABLE_CHIPMUNK_INTEGRATION=1\n to run this test case",
                                            "fonts/arial.ttf",
                                            18);
    auto size = Director::getInstance()->getWinSize();
    label->setPosition(Point(size.width/2, size.height/2));
    
    addChild(label);
    
#endif
    
}
Exemplo n.º 8
0
int _tmain(int argc, char** argv)
{

   glutInit(&argc, argv);
   glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
   glutInitWindowSize (1024, 768); 
   glutInitWindowPosition (0, 0);
   
   glutCreateWindow (argv[0]);
   //glutFullScreen();
   init ();
   initPhysics();
   glutDisplayFunc(display); 
   glutReshapeFunc(reshape);
   glutKeyboardFunc(keyboard);
   glutIdleFunc(OnIdle);
   glutMainLoop();

	
   /*
 
    for (int i=0 ; i<300 ; i++) {
            dynamicsWorld->stepSimulation(1/60.f,10);
 
            btTransform trans;
            fallRigidBody->getMotionState()->getWorldTransform(trans);
 
            std::cout << "sphere height: " << trans.getOrigin().getY() << std::endl;
    }
 
 */
   /*
    dynamicsWorld->removeRigidBody(fallRigidBody);
    delete fallRigidBody->getMotionState();
    delete fallRigidBody;
 
    dynamicsWorld->removeRigidBody(groundRigidBody);
    delete groundRigidBody->getMotionState();
    delete groundRigidBody;
 
 
    delete fallShape;
 
    delete groundShape;
 
 
    delete dynamicsWorld;
    delete solver;
    delete collisionConfiguration;
    delete dispatcher;
    delete broadphase;
	*/	
    return 0;

}
Exemplo n.º 9
0
Asteroid::Asteroid(int size, b2Vec2 location, b2World* pWorld)
:Object(pWorld)
{  
	mShouldDeleteBody = true;

	this->size = static_cast<Size>(size);
	health = (size + 1) * (size + 1);

	initPhysics(location);
	initSprite();
}
Exemplo n.º 10
0
bool GameMainLayer::init() {
    addNode2Scene();
    addGamePlayer2Scene();
    addMap();
    //createPhysicBorder();
    initPhysics();
    Director::getInstance()->getEventDispatcher()->addCustomEventListener(NOTIFY_PLAYER_JUMP_UP, std::bind(&GameMainLayer::jumpUpCallBack, this, std::placeholders::_1));
    addPhysicContactListener();
    scheduleUpdate();
    return true;
}
Exemplo n.º 11
0
void BlockBase::create(const cocos2d::Rect& rect) {
    mSprite = GameUtils::createRect(rect, getColor());
    
#if EDITOR_MODE
    initIDLabel();
#endif
    mRestoreSize = rect.size;
    mRestorePosition = getPosition();
    
    initShader();
    initPhysics();
}
Exemplo n.º 12
0
void PhysicsDemo::init()
{
	initSDL();
	initGL();
	initPhysics();

	m_camAng = lt::Vec3(20.0f, 0.0f, 0.0f);
	m_camZoom = -5.0;

	m_frameCount = 0;
	m_lastClock = SDL_GetTicks();
}
Exemplo n.º 13
0
ChipmunkTestLayer::ChipmunkTestLayer()
{
#if CC_ENABLE_CHIPMUNK_INTEGRATION      
    // enable events
    setTouchEnabled(true);
    setAccelerometerEnabled(true);

    // title
    auto label = LabelTTF::create("Multi touch the screen", "Marker Felt", 36);
    label->setPosition(Point( VisibleRect::center().x, VisibleRect::top().y - 30));
    this->addChild(label, -1);

    // reset button
    createResetButton();

    // init physics
    initPhysics();

#if 1
    // Use batch node. Faster
    auto parent = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100);
    _spriteTexture = parent->getTexture();
#else
    // doesn't use batch node. Slower
    _spriteTexture = TextureCache::getInstance()->addImage("Images/grossini_dance_atlas.png");
    auto parent = Node::create();
#endif
    addChild(parent, 0, kTagParentNode);

    addNewSpriteAtPosition(Point(200,200));

    // menu for debug layer
    MenuItemFont::setFontSize(18);
    auto item = MenuItemFont::create("Toggle debug", CC_CALLBACK_1(ChipmunkTestLayer::toggleDebugCallback, this));

    auto menu = Menu::create(item, NULL);
    this->addChild(menu);
    menu->setPosition(Point(VisibleRect::right().x-100, VisibleRect::top().y-60));

    scheduleUpdate();
#else
    auto label = LabelTTF::create("Should define CC_ENABLE_CHIPMUNK_INTEGRATION=1\n to run this test case",
                                            "Arial",
                                            18);
    auto size = Director::getInstance()->getWinSize();
    label->setPosition(Point(size.width/2, size.height/2));
    
    addChild(label);
    
#endif
    
}
Exemplo n.º 14
0
Game::Game()
{
    pWnd = new RenderWindow(VideoMode(800, 600), "Testing box2d");
	pWnd->setVisible(true);
	fps = 60;
	pWnd->setFramerateLimit(fps);
	frameTime = 1.0f / fps;

    setZoom();
	initPhysics();

	ragdoll = new Ragdoll(phyWorld, pWnd, 30, 10);
}
Exemplo n.º 15
0
Asteroid::Asteroid(int size, b2World* pWorld) :Object(pWorld) 
{ 
	mShouldDeleteBody = true;

	this->size = static_cast<Size>(size);
	health = (size + 1) * (size + 1);

	b2Vec2 position;
	int xRand = rand() % 2, yRand = rand() % 2;
	xRand == 0 ? position.x = static_cast<float>(rand() % 150 - 300) : position.x = static_cast<float>(SCREEN_WIDTH + (rand() % 150 + 150));
	yRand == 0 ? position.y = static_cast<float>(rand() % 150 - 300) : position.y = static_cast<float>(SCREEN_HEIGHT + (rand() % 150 + 150));
	initPhysics(position);
	initSprite(rand() % 3);
};
Exemplo n.º 16
0
void Asteroid::initAlreadyCreated(int size, b2Vec2 position, b2Vec2 velocity, float rotVel, float angle, int type)
{
	this->size = static_cast<Size>(size);
	health = (size + 1) * (size + 1);

	initPhysics(position);

	body->SetLinearVelocity(velocity);
	body->SetAngularVelocity(rotVel);
	body->SetTransform(position, angle);

	initSprite(type);

	mShouldDeleteBody = true;
}
Exemplo n.º 17
0
std::vector<double> BasicDemo::runSimulation(std::vector<double> prevState, std::vector<double> action){
  startPose_.setValue(prevState[0],1.0,prevState[1]);
  initPhysics();
  desiredPose_.setValue(action[0],1.0,action[1]);

  for(size_t i = 0; i<1000;i++){
    stepWorld();
  }

  std::vector<double> nextState;
  nextState.push_back(bravoBodyTrans_.getOrigin().getX());
  nextState.push_back(bravoBodyTrans_.getOrigin().getZ());

  return nextState;
}
Exemplo n.º 18
0
void Asteroid::init()
{
	mShouldDeleteBody = true;

	initSize();

	b2Vec2 position;
	//position.x = SCREEN_WIDTH / 2.0f;
	//position.y = SCREEN_HEIGHT / 2.0f;
	int xRand = rand() % 2, yRand = rand() % 2;
	xRand == 0 ? position.x = static_cast<float>(rand() % 150 - 300) : position.x = static_cast<float>(SCREEN_WIDTH + (rand() % 150 + 150));
	yRand == 0 ? position.y = static_cast<float>(rand() % 150 - 300) : position.y = static_cast<float>(SCREEN_HEIGHT + (rand() % 150 + 150));
	initPhysics(position);
	initSprite(rand() % 3);
}
Exemplo n.º 19
0
int main( int argc, char** argv )
{
  btDynamicsWorld* bw = initPhysics();
  osg::Group* root = new osg::Group;

  osg::ref_ptr< osgbInteraction::SaveRestoreHandler > srh = new osgbInteraction::SaveRestoreHandler;

  osg::Matrix m;

  m = osg::Matrix::rotate( .4, 0., 0., 1. ) * osg::Matrix::translate( 16., 0., 10. );
  btRigidBody *rb = createObject(root, m, srh.get());
  bw->addRigidBody(rb);
  
  m = osg::Matrix::rotate( osg::PI_2, 0, 1, 0 ) * osg::Matrix::translate( 0., 0., 10. );
  bw->addRigidBody(createWheel(root, m, srh.get()));

  m = osg::Matrix::rotate( 0, 0., 0., 1. ) * osg::Matrix::translate( -20., 0., 0. );
  bw->addRigidBody(createCow(root, m, srh.get()));

  root->addChild( osgbDynamics::generateGroundPlane( osg::Vec4( 0.f, 0.f, 1.f, 0.f ), bw ) );

  osgViewer::Viewer viewer;
  viewer.setUpViewInWindow( 30, 30, 768, 480, 1 );
  viewer.setSceneData( root );
  osgGA::TrackballManipulator* tb = new osgGA::TrackballManipulator;
  viewer.setCameraManipulator( tb );

  viewer.realize();
  srh->capture();

  viewer.addEventHandler(new myEventHandler(rb));
  viewer.addEventHandler( srh.get() );
  viewer.addEventHandler( new osgbInteraction::DragHandler(bw, viewer.getCamera() ) );

  double prevSimTime = 0.;
  while( !viewer.done() )
  {
    const double currSimTime = viewer.getFrameStamp()->getSimulationTime();
    bw->stepSimulation( currSimTime - prevSimTime );
    prevSimTime = currSimTime;
    viewer.frame();
  }

  return( 0 );
}
Exemplo n.º 20
0
void BlockBase::create(const cocos2d::Point& pt, const cocos2d::Size& size) {
    
    Rect r;
    r.origin = Point::ZERO;
    r.size = size;
    mSprite = GameUtils::createRect(r, getColor());
    
    setPosition(pt);
    
#if EDITOR_MODE
    initIDLabel();
#endif
    
    mRestoreSize = size;
    mRestorePosition = getPosition();
    
    initShader();
    initPhysics();
}
Spacetime::Spacetime(matrix<double> startPose, matrix<double> endPose, PxU32 numTimeSteps) 
{
	// Required physX runtime variable initializations
	gScene = NULL;
	gPhysics = NULL;
	gMaterial	= NULL;
	gFoundation = NULL;
	gDispatcher = NULL;
	gConnection	= NULL;
	deltaT = 1.0 / 600.0f;
	ANALYTIC = true;
	uThreshold = 0.00001;

	this->state_0 = startPose;
	this->state_d = endPose;
	this->numTimeSteps = numTimeSteps;
	
	initPhysics();
}
Exemplo n.º 22
0
void BlockBase::create(const cocos2d::Point& pt) {
    auto thick = 30;
    auto width = 200;
    Rect r;
    r.origin = Point::ZERO;
    r.size.width = width / 2;
    r.size.height = thick / 2;
    mSprite = GameUtils::createRect(r, getColor());
    mSprite->setPosition(pt);
    
#if EDITOR_MODE
    initIDLabel();
#endif
    
    mRestoreSize = r.size;
    mRestorePosition = getPosition();
    
    initShader();
    initPhysics();
}
Exemplo n.º 23
0
GameLayer::GameLayer() {
    
    
    _screenSize = CCDirector::sharedDirector()->getWinSize();
    _running = false;
    
    createScreen();
    
    std::string levelsFile = CCFileUtils::sharedFileUtils()->fullPathForFilename("levels.plist");
    _levels = CCArray::createWithContentsOfFileThreadSafe(levelsFile.c_str());
    _levels->retain();
    
    initPhysics();
    
    createPools();
    
    setTouchEnabled( true );
    setAccelerometerEnabled( true );
    
    
}
Exemplo n.º 24
0
void Planetoid :: initPlanetoid (const PhysicsObjectId& id,
                                 const Vector3& position,
                                 double radius,
                                 const DisplayList& display_list,
                                 double display_scale)
{
	assert(id != PhysicsObjectId::ID_NOTHING);
	assert(radius >= 0.0);
	assert(display_list.isReady());
	assert(display_scale >= 0.0);

	initPhysics(id,
	            position,
	            radius,
	            Vector3::ZERO,
	            display_list,
	            display_scale * radius);
	setOrientation(FORWARD_DEAFULT, UP_DEFAULT);

	m_owner               = PhysicsObjectId::FLEET_NATURE;
	m_is_actively_claimed = false;

	assert(invariant());
}
Exemplo n.º 25
0
void	BasicDemo::clientResetScene()
{
	exitPhysics();
	initPhysics();
}
Exemplo n.º 26
0
int main_phys_viewer( int argc, char** argv )
{
    osg::ArgumentParser arguments( &argc, argv );
    const bool debugDisplay( arguments.find( "--debug" ) > 0 );

    btDiscreteDynamicsWorld* bw = initPhysics();
    osg::Group* root = new osg::Group;

    osg::Group* launchHandlerAttachPoint = new osg::Group;
    root->addChild( launchHandlerAttachPoint );
    
    std::string         model_name = "eisk";
    
    auto obj = avCore::createObject(model_name, 10);
    osg::ref_ptr< osg::Node > rootModel( obj->getOrCreateNode() );
    if( !rootModel.valid() )
    {
        osg::notify( osg::FATAL ) << "mesh: Can't create mesh." << std::endl;
        return( 1 );
    }
    
    btCompoundShape*        cs_;
    bool loaded = phys::loadBulletFile(cfg().path.data + "/areas/" + model_name + "/" + model_name + ".bullet",  cs_);
    if(loaded)
    {
        const btTransform ct0 = cs_->getChildTransform(0);
        // cs.offset_ = from_bullet_vector3(ct0.getOrigin()); 
        cs_->setLocalScaling( btVector3(0.013,0.013,0.013));
        addRigidBody( bw, cs_ );
    }

    root->addChild( rootModel.get() );
    
    DynamicCharacterController* m_character = new DynamicCharacterController ();
    m_character->setup();
    bw->addAction(m_character);

#if 0
    // Add ground
    const osg::Vec4 plane( 0., 0., 1., -100. );
    root->addChild( osgbDynamics::generateGroundPlane( plane, bw ) );
#endif


    osgbCollision::GLDebugDrawer* dbgDraw( NULL );
    if( /*debugDisplay*/ true)
    {
        dbgDraw = new osgbCollision::GLDebugDrawer();
        dbgDraw->setDebugMode( ~btIDebugDraw::DBG_DrawText );
        bw->setDebugDrawer( dbgDraw );
        root->addChild( dbgDraw->getSceneGraph() );
    }

    osgViewer::Viewer viewer( arguments );
	viewer.apply(new osgViewer::SingleScreen(1));
    viewer.addEventHandler( new osgViewer::StatsHandler() );
    //viewer.setUpViewInWindow( 30, 30, 768, 480 );
    viewer.setSceneData( root );

    osgGA::TrackballManipulator* tb = new osgGA::TrackballManipulator;
    // tb->setHomePosition( osg::Vec3( 0., -16., 6. ), osg::Vec3( 0., 0., 5. ), osg::Vec3( 0., 0., 1. ) ); 
    viewer.setCameraManipulator( tb );
    viewer.getCamera()->setClearColor( osg::Vec4( .5, .5, .5, 1. ) );
    viewer.realize();


    double prevSimTime = 0.;
    while( !viewer.done() )
    {
        if( dbgDraw != NULL )
            dbgDraw->BeginDraw();

        const double currSimTime = viewer.getFrameStamp()->getSimulationTime();
        bw->stepSimulation( currSimTime - prevSimTime/*0.0*//*0.1*/ );
        prevSimTime = currSimTime;

        if( dbgDraw != NULL )
        {
            bw->debugDrawWorld();
            dbgDraw->EndDraw();
        }

        // worldInfo.m_sparsesdf.GarbageCollect();

        viewer.frame();
    }

    return( 0 );
}
Exemplo n.º 27
0
void Hinge2Vehicle::clientResetScene()
{
	exitPhysics();
	initPhysics();
}
void	Physics::clientResetScene(){
	exitPhysics();
	initPhysics();
}
Exemplo n.º 29
0
void BulletXmlImportDemo::clientResetScene()
{
	exitPhysics();
	initPhysics();
}
Exemplo n.º 30
0
int Menu(void)
{
	int r=0,key;
	const double angleInc = PI/180.;
	while(r!=eStart && r!= eStop)
	{
		FsPollDevice();
		key=FsInkey();
		switch(key)
		{
		case FSKEY_S:
			r=eStart;
			break;
		case FSKEY_ESC:
			r=eStop;
			break;
		case FSKEY_UP:
			iSpeed++;
			break;
		case FSKEY_DOWN:
			iSpeed = max(2., iSpeed-1);
			break;
		case FSKEY_LEFT:
			iAngle = max(0., iAngle-angleInc);
			break;
		case FSKEY_RIGHT:
			iAngle = min(90.0, iAngle+angleInc);
			break;
		}

		initPhysics(radius, iSpeed, iAngle);
		if (r == eStop)
			return r;
		int wid,hei;
		FsGetWindowSize(wid,hei);


		glViewport(0,0,wid,hei);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glOrtho(-0.5,(GLdouble)wid-0.5,(GLdouble)hei-0.5,-0.5,-1,1);

		glClearColor(0.0,0.0,0.0,0.0);
		glClear(GL_COLOR_BUFFER_BIT);
		glColor3ub(127,127,127);

		char sSpeed[128];
		sprintf(sSpeed, "Initial ball speed is %f m/s. Use Up/Down keys to change it!\n", iSpeed);
		char sAngle[128];
		sprintf(sAngle, "Initial horizon Angle is %f degrees. Use Left/Right keys to change it!\n", iAngle*180./PI);
		glColor3ub(255,255,255);
		glRasterPos2i(32,32);
		glCallLists(strlen(sSpeed),GL_UNSIGNED_BYTE,sSpeed);
		glRasterPos2i(32,64);
		glCallLists(strlen(sAngle),GL_UNSIGNED_BYTE,sAngle);
		const char *msg1="S.....Start Game";
		const char *msg2="ESC...Exit";
		glRasterPos2i(32,96);
		glCallLists(strlen(msg1),GL_UNSIGNED_BYTE,msg1);
		glRasterPos2i(32,128);
		glCallLists(strlen(msg2),GL_UNSIGNED_BYTE,msg2);

		FsSwapBuffers();
		FsSleep(10);
	}
	return r;
}