Beispiel #1
0
void keyboard(unsigned char key, int x_pos, int y_pos)
{
    btRigidBody* tempRB = objectsDataList.getRigidBody(3);
    // Handle keyboard input
    if(key == 27)//ESC
    {
        exit(0);
    }
    switch (key)
    {
        case 'a':
        tempRB->applyForce(btVector3( 10, 0.f, 0.f ), btVector3(0.0f,0.0f,0.0f));
        //Move cylinder X
        break;
        case 'd':
        tempRB->applyForce(btVector3( -10, 0.f, 0.f ), btVector3(0.0f,0.0f,0.0f));
        //Move cylinder -X
        break;
        case 'w':
        tempRB->applyForce(btVector3( 0.0f, 0.f, 10.0f ), btVector3(0.0f,0.0f,0.0f));
        //Move cylinder -Z
        break;
        case 's':
        tempRB->applyForce(btVector3( 0.0, 0.f, -10.0f ), btVector3(0.0f,0.0f,0.0f));
        //Move cylinder Z
        break;
    }
} 
Beispiel #2
0
void handleSpecialKeypress(int key, int x, int y) 
{
    btRigidBody* tempRB = objectsDataList.getRigidBody(2);

    switch (key) 
    {
    case GLUT_KEY_LEFT:
            tempRB->applyCentralImpulse( btVector3( 2, 0.f, 0.f ) );
        //Move circle X 
        break;  

    case GLUT_KEY_RIGHT:
            tempRB->applyCentralImpulse( btVector3( -2, 0.f, 0.f ) );
        //Move circle -X
        break;

    case GLUT_KEY_UP:
            tempRB->applyCentralImpulse( btVector3( 0, 0.f, 2.f ) );
        //Move circle -Z
        break;

    case GLUT_KEY_DOWN:
            tempRB->applyCentralImpulse( btVector3( 0, 0.f, -2.f ) );
        //Move circle Z
        break;
    
    }
}
Beispiel #3
0
void resetGame()
{
    float dt;
    start = std::chrono::high_resolution_clock::now(); 
    scoreOne = 1000;
    
    cout << "globalObjCount" << globalObjCount << endl;
// reset items
    for (int index = 0; index < globalObjCount; index++)
        {

        // if on the puck
        if ( index != 0 )
            {
            btVector3 startPos;

            if (objectsDataList.getRigidBody(index) && objectsDataList.getRigidBody(index)->getMotionState())
                {
	               
                     btTransform puckTrans;
		             puckTrans.setIdentity();

                     if ( index == 1 )
                        {
                         startPos = btVector3(-5.0f, -3.0f, -5.0f);
                        }
                     
	                 puckTrans.setOrigin(startPos);
		             btDefaultMotionState* puckMotionState = new btDefaultMotionState(puckTrans);
		             objectsDataList.getRigidBody(index)->setMotionState(puckMotionState);
                     objectsDataList.getRigidBody(index)->setLinearVelocity(btVector3(0.0f, 0.0f, 0.0f));
                     objectsDataList.getRigidBody(index)->setAngularVelocity(btVector3(0,0,0));
                }
            }
        }
    dt = getDT();
    dynamicsWorld->stepSimulation(dt, 10.0f);
}
Beispiel #4
0
///////////////////////////////////////
// human interaction functions below //   
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv///
void movePlayerOnePad (int x, int y) 
{
    btRigidBody* tempRB = objectsDataList.getRigidBody(1);
    btVector3 tempVec3; 
    tempVec3 = tempRB->getLinearVelocity();
    int xValue = 0;
    int yValue = 0;
    int zValue = 0;

   int topFourth = h / 4;
   int bottomFourth = topFourth * 3;

   int leftFourth = w / 4;
   int rightFourth = leftFourth * 3;

   if ( x < leftFourth )
        {
            xValue += 5;
            xValue = xValue + tempVec3.getX();
            if(xValue > 15)
                xValue = 15;
        }
    
    if ( x > rightFourth )
        {
            xValue -= 5;
            xValue = xValue + tempVec3.getX();
            if(xValue < -15)
                xValue = -15;
        }            

   if ( y < topFourth )
        {
            zValue += 5;
            zValue = zValue + tempVec3.getZ();
            if(zValue > 15)
                zValue = 15;
        }

    if ( y > bottomFourth )
        {
            zValue -= 5;
            zValue = zValue + tempVec3.getZ();
            if(zValue < -15)
                zValue = -15;
        }


    tempRB->setLinearVelocity(btVector3(xValue, yValue , zValue));
}
Beispiel #5
0
void myMouse(int button, int state, int x, int y)
{ 
    if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
    {
        cout << "Left Button Pressed" << endl;
        

        btRigidBody* tempRB = objectsDataList.getRigidBody(1);
        btVector3 tempVec3;
        int xValue = 0;
        int yValue = 0;
        int zValue = 0;

        int topFourth = h / 4;
        int bottomFourth = topFourth * 3;

        int leftFourth = w / 4;
        int rightFourth = leftFourth * 3;

        // move up
        if ( y < topFourth )
        {
        zValue += 15;
        }
        // move down
        if ( y > bottomFourth )
        {
        zValue -= 15;
        }
        // move left
        if ( x < leftFourth )
        {
        xValue += 15;
        }
        // move rith
        if ( x > rightFourth )
        {
        xValue -= 15;
        }

        tempVec3 = tempRB->getLinearVelocity();
        tempRB->setLinearVelocity(btVector3(xValue + tempVec3.getX(), yValue + tempVec3.getY(), zValue + tempVec3.getZ()));
        
    } 
}