Exemplo n.º 1
0
void RigidBodyApplication::drawDebug()
{
    if (!renderDebugInfo) return;

    // Recalculate the contacts, so they are current (in case we're
    // paused, for example).
    generateContacts();

    // Render the contacts, if required
    glBegin(GL_LINES);
    for (unsigned i = 0; i < cData.contactCount; i++)
    {
        // Interbody contacts are in green, floor contacts are red.
        if (contacts[i].body[1]) {
            glColor3f(0,1,0);
        } else {
            glColor3f(1,0,0);
        }

        mechaEngine::Vector3 vec = contacts[i].contactPoint;
        glVertex3f(vec.x, vec.y, vec.z);

        vec += contacts[i].contactNormal;
        glVertex3f(vec.x, vec.y, vec.z);
    }

    glEnd();
}
Exemplo n.º 2
0
void RigidBodyApplication::update()
{
    // Find the duration of the last frame in seconds
    float duration = (float)TimingData::get().lastFrameDuration * 0.001f;
    if (duration <= 0.0f) return;
    else if (duration > 0.05f) duration = 0.05f;

    // Exit immediately if we aren't running the simulation
    if (pauseSimulation)
    {
        Application::update();
        return;
    }
    else if (autoPauseSimulation)
    {
        pauseSimulation = true;
        autoPauseSimulation = false;
    }

    // Update the objects
    updateObjects(duration);

    // Perform the contact generation
    generateContacts();

    // Resolve detected contacts
    resolver.resolveContacts(
        cData.contactArray,
        cData.contactCount,
        duration
        );

    Application::update();
}
Exemplo n.º 3
0
void jfBigBallisticSimulation_x86::run()
{
    while(m_EventHandler->handleEvents())
    {
        m_CurrentShotType = m_EventHandler->getCurrentShotType();
        m_EventHandler->handleKeyEvents();
        m_LastFrameDuration = m_Timer->getTicks();
        m_Timer->start();
        jfReal timeStep = ((jfReal)m_LastFrameDuration)/1000.0;
        if((m_EventHandler->getMouseEvent().getStatus() == EVENT_MOUSELEFT))
        {
            if(!m_MousePressedLast)
            {
                m_MousePressedLast = true;
                fire();
            }
        }
        else
        {
            m_MousePressedLast = false;
        }

		updateObjects(timeStep);

		generateContacts();

        vector<jfContact*> contacts;
        m_CollisionData->getContacts(&contacts);
        m_ContactResolver->resolveContacts(contacts,
                                            timeStep);
        m_3DGraphicsHandler->draw();

        drawDebug();
    }
}
Exemplo n.º 4
0
void jfBigBallisticSimulation_x86::drawDebug()
{
    if (!m_RenderDebugInfo)
    {
        return;
    }

    // Recalculate the contacts, so they are current (in case we're
    // paused, for example).
    generateContacts();
    vector<jfContact*> contacts;
    m_CollisionData->getContacts(&contacts);
    m_3DGraphicsHandler->drawDebug(contacts);
}
Exemplo n.º 5
0
void jfBoxesAndBallsSimulation_x86::run()
{
    while (m_EventHandler->handleEvents()) {
        m_EventHandler->handleKeyEvents();
        m_EventHandler->handleMouseEvents();

        m_LastFrameDuration = m_Timer->getTicks();
        m_Timer->start();
        //jfReal timeStep = ((jfReal)m_LastFrameDuration)/1000.0;

        jfReal timeStep = 0.01; // Fix it so both x86 and x86 versions will have around same amounts of work to do on each frame.

        if ((m_EventHandler->getMouseEvent().getStatus() == EVENT_MOUSELEFT)) {
            if (!m_MousePressedLast) {
                m_MousePressedLast = true;
                fire();
            }
        } else {
            m_MousePressedLast = false;
        }

        // start timer
        //        gettimeofday(&t1, NULL);

        updateObjects(timeStep);
/*
        // stop timer
        gettimeofday(&t2, NULL);
        m_ElapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0;      // sec to ms
        m_ElapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0;   // us to ms
        char buf[255];
        sprintf(buf, "%d\n", m_ElapsedTime);
        logToFile(buf, "CollisionDetectionTimes.dat");
        //gettimeofday(&t1, NULL);
*/
#ifdef PERF_TIMING
        m_PerformanceTimer->start();
#endif
        generateContacts();
#ifdef PERF_TIMING
        m_PerformanceTimer->stop();
        m_ElapsedTime = m_PerformanceTimer->getElapsedTime();
        char buf[255];
        sprintf(buf, "%lf\n", m_ElapsedTime);
        logToFile(buf, timingFilename);
#endif

        vector<jfContact*> contacts; // = m_CollisionData->getContacts();
        m_CollisionData->getContacts(&contacts);
        //cout <<"contacts.size() is : " <<contacts.size()<<endl;
        m_ContactResolver->resolveContacts(contacts,
            timeStep);

        /*m_ContactResolver->resolveContacts(m_CollisionData->getContactArray(),
                                            m_CollisionData->getContactCount(),
                                            timeStep);
                                            */
        m_3DGraphicsHandler->draw();

        //drawDebug();
    }
}