Exemplo n.º 1
0
void NP_World::update(float deltaTime)
{
    for (size_t i = 0; i < m_objects.size(); ++i)
        m_objects[i]->update(deltaTime);

    //TODO:
    // FOR EACH STEP DO THESE THINGS: 
    //Generate collision info
    contacts.clear();
    for (size_t i = 0; i < m_objects.size(); ++i)
    {
        NP_Body* A = m_objects[i]->getBody();        

        for (size_t j = 0; j < m_objects.size(); ++j)
        {
            NP_Body* B = m_objects[j]->getBody();

            if (A->inverseMass == 0 && B->inverseMass == 0)
                continue;
            NP_CollisionInfo cI(A, B);
            updateOrientation(m_objects[i]);
            updateOrientation(m_objects[j]);
            cI.Solve(); //Do collision check
            if (cI.contact_count)
                contacts.emplace_back(cI);            
        }
    }
   
    // Integrate forces
    // - Go through objects - calc forces (calc acceleration)
    for (size_t i = 0; i < m_objects.size(); ++i)
        integrateForces(m_objects[i], deltaTime);

    // Init collision
    //for (size_t i = 0; i < contacts.size(); ++i)
    //{
    //    contacts[i].Initialize();
    //}

    //Solve collisions - apply impulse
    for (size_t i = 0; i < contacts.size(); ++i)
    {
        contacts[i].ApplyImpulse();
    }

    // Integrate velocities
    for (size_t i = 0; i < m_objects.size(); ++i)
        integrateVelocity(m_objects[i], deltaTime);

    for (size_t i = 0; i < m_objects.size(); ++i)
    {
        m_objects[i]->getBody()->m_force = glm::vec2(0, 0);
        m_objects[i]->getBody()->m_torque = 0;
    }

}
Exemplo n.º 2
0
// perform Guass-Jordanian elimination:  The matrix will become
// it's inverse
void	XSQUARE_MATRIX::Inverse_GJ(void)
{
	if (m_lpdValues)
	{
		XSQUARE_MATRIX	cI(m_uiN);
		cI.Identity();
		// allocate work space
		double	dScalar;

		// Using row reduction, reduce the source matrix to the identity, 
		// and the identity will become A^{-1}
		for (unsigned int uiRow = 0; uiRow < m_uiN; uiRow++)
		{
			if (m_lpdValues[uiRow * m_uiN + uiRow] == 0.0)
			{
				for (unsigned int uiRowInner = uiRow + 1; 
						uiRowInner < m_uiN; 
						uiRowInner++)
				{
					if (m_lpdValues[uiRowInner * m_uiN + uiRow] != 0.0)
					{
						Swap_Rows(uiRow,uiRowInner);
						cI.Swap_Rows(uiRow,uiRowInner);
					}
				}
			}
			dScalar = 1.0 / m_lpdValues[uiRow * m_uiN + uiRow];
			Scale_Row(uiRow,dScalar);
			cI.Scale_Row(uiRow,dScalar);

			for (unsigned int uiRowInner = 0; 
					uiRowInner < m_uiN; 
					uiRowInner++)
			{
				double	dRow_Scalar = 
							-m_lpdValues[uiRowInner * m_uiN + uiRow];
				if (uiRowInner != uiRow)
				{
					cI.Add_Rows(uiRowInner,uiRow,dRow_Scalar,false);
					Add_Rows(uiRowInner,uiRow,dRow_Scalar,true);
				}
			}
		}
		// copy result into current matrix
		*this = cI;
	}
}
Exemplo n.º 3
0
int main(int argc, char *argv[], char *envp[]) 
{
	int RValue = false;
	int CaptureModeHex = 0;
	int NewChar=0;
	int nResult = 0;
    int arraySize = 2000;

    srand(time(NULL));

    printf ("main - start\n");
    //CFucntInt *_my_int = new CFucntInt(arraySize);

    //Run(memory_leack_test);
    //memory_leack_test();

    Funct<int> cI(25);
	Funct<double> cD(3.12);
	cout << "cI " << cI.GetValue() << endl;
	cout << "cD " << cD.GetValue() << endl;
    cout << "cI " << endl;

    video_buffer screen;
    screen.makeFrame();
    
    //int a = game();

    int *p;
    int i = 10;

    p = &i;
    cout << "Address of i: " << p << "\n";
    cout << "Value of i: " << *p << "\n";


    //my_smart_pointer<video_buffer> pMyVideoBuffer (new video_buffer());    
    //pMyVideoBuffer->makeFrame();
    
    _CrtDumpMemoryLeaks();

//*************MAIN LOOP*****************//
cout << "\n$ > Press Any Key to exit." << std::endl;
do 
{
    //This is simple Windows way:
    Sleep(55);
    // active_matrix->run_matrix();
   
   //nResult = produceRND();   
   //printf ("1-Time: %ld. RND: %d\n", _time->Get1msTimeMS(), nResult);
   
   //nResult = produceRND();   
   //printf ("2-Time: %ld. RND: %d\n", _time->Get1msTimeMS(), nResult);

   // control of endless loop (may be also in monitor.cpp)
    if (_kbhit())  // has anything been pressed from keyboard ?
    {
        NewChar=(unsigned char)_getch();
        RValue = true;
        if ((NewChar & 0xff) == 24)  // CTRL-X   pressed
        {
            RValue = true; // END mark
        }     
        if (NewChar == 'd')  // pressed
        {
            if (1 == CaptureModeHex) 
                CaptureModeHex = 1;
		    else
                CaptureModeHex = 0;
        }
    }
} while (!RValue);  
printf ("Application complete.\n");
return 0;
}