Пример #1
0
    void
    Object::applyDragForces(void)
    {
      double xf = m_linear_drag_coef[0] * m_linear_velocity[0];
      double yf = (m_linear_drag_coef[1] * m_linear_velocity[1] +
                   m_linear_drag_coef[6] * m_angular_velocity[2]);
      double zf = (m_linear_drag_coef[2] * m_linear_velocity[2] +
                   m_linear_drag_coef[7] * m_angular_velocity[1]);

      double pf = m_linear_drag_coef[3] * m_angular_velocity[0];
      double qf = (m_linear_drag_coef[4] * m_angular_velocity[1] +
                   m_linear_drag_coef[8] * m_linear_velocity[2]);
      double rf = (m_linear_drag_coef[5] * m_angular_velocity[2] +
                   m_linear_drag_coef[9] * m_linear_velocity[1]);

      addForces(xf, yf, zf, pf, qf, rf);

      xf = m_quad_drag_coef[0] * m_linear_velocity[0] * std::fabs(m_linear_velocity[0]);
      yf = (m_quad_drag_coef[1] * m_linear_velocity[1] * std::fabs(m_linear_velocity[1]) +
            m_quad_drag_coef[6] * m_angular_velocity[2] * std::fabs(m_angular_velocity[2]));
      zf = (m_quad_drag_coef[2] * m_linear_velocity[2] * std::fabs(m_linear_velocity[2]) +
            m_quad_drag_coef[7] * m_angular_velocity[1] * std::fabs(m_angular_velocity[1]));

      pf = m_quad_drag_coef[3] * m_angular_velocity[0] * std::fabs(m_angular_velocity[0]);
      qf = (m_quad_drag_coef[4] * m_angular_velocity[1] * std::fabs(m_angular_velocity[1]) +
            m_quad_drag_coef[8] * m_linear_velocity[2] * std::fabs(m_linear_velocity[2]));
      rf = (m_quad_drag_coef[5] * m_angular_velocity[2] * std::fabs(m_angular_velocity[2]) +
            m_quad_drag_coef[9] * m_linear_velocity[1] * std::fabs(m_linear_velocity[1]));

      addForces(xf, yf, zf, pf, qf, rf);
    }
Пример #2
0
void FluidSimulator::advectVelocity(){


	Cell ** updatedCells = new Cell*[simulationGrid->width];
	for (int i = 0; i < simulationGrid->width; i++){
		updatedCells[i] = new Cell[simulationGrid->height];
	}


	computeTimeStep();

	for (int i = 0; i < simulationGrid->width; i++){
		for (int j = 0; j < simulationGrid->height; j++){
			updatedCells[i][j] = advectCell(i, j);
		}
	}
	simulationGrid->cells = updatedCells;
	for (int i = 0; i < simulationGrid->width; i++){
		for (int j = 0; j < simulationGrid->height; j++){
			addForces(i, j);
		}
	}


	//std::cout << simulationGrid->getVelocityVector(4, 2);
}
Пример #3
0
//Default update for an Entity
void Entity::update(float deltaTime) {

	//Add force of gravity
	addForces({ 0.f, md_.mass * gravityScale_ });

	integrate(deltaTime);
}
Пример #4
0
void motion(int x, int y, int nx, int ny, float fx, float fy, int spy, int spx)
{
    if (clicked && nx < DIM-FR && nx > FR-1 && ny < DIM-FR && ny > FR-1)
    {
        addForces(dvfield, DIM, DIM, spx, spy, FORCE * DT * fx, FORCE * DT * fy, FR);
        lastx = x;
        lasty = y;
    }

    glutPostRedisplay();
}
Пример #5
0
void autoTest(char **argv)
{
    CFrameBufferObject *fbo = new CFrameBufferObject(wWidth, wHeight, 4, false, GL_TEXTURE_2D);
    g_CheckRender = new CheckFBO(wWidth, wHeight, 4, fbo);
    g_CheckRender->setPixelFormat(GL_RGBA);
    g_CheckRender->setExecPath(argv[0]);
    g_CheckRender->EnableQAReadback(true);

    fbo->bindRenderPath();

    reshape(wWidth, wHeight);

    for (int count=0; count<g_iFrameToCompare; count++)
    {
        simulateFluids();

        // add in a little force so the automated testing is interesing.
        if (ref_file)
        {
            int x = wWidth/(count+1);
            int y = wHeight/(count+1);
            float fx = (x / (float)wWidth);
            float fy = (y / (float)wHeight);
            int nx = (int)(fx * DIM);
            int ny = (int)(fy * DIM);

            int ddx = 35;
            int ddy = 35;
            fx = ddx / (float)wWidth;
            fy = ddy / (float)wHeight;
            int spy = ny-FR;
            int spx = nx-FR;

            addForces(dvfield, DIM, DIM, spx, spy, FORCE * DT * fx, FORCE * DT * fy, FR);
            lastx = x;
            lasty = y;
        }
    }

    display();

    fbo->unbindRenderPath();

    // compare to offical reference image, printing PASS or FAIL.
    printf("> (Frame %d) Readback BackBuffer\n", 100);
    g_CheckRender->readback(wWidth, wHeight);
    g_CheckRender->savePPM("fluidsGL.ppm", true, NULL);

    if (!g_CheckRender->PPMvsPPM("fluidsGL.ppm", ref_file, MAX_EPSILON_ERROR, 0.25f))
    {
        g_TotalErrors++;
    }
}
Пример #6
0
    void
    ASV::applyAsvActuation(void)
    {
      // Original parameters.
      double T2CLeft[] = {-0.7428, 1.6420, 4.0325, -0.769};
      double T2CRight[] = {-0.7428, 1.6420, 4.0325, -0.769};

      updateActuation(0);
      updateActuation(1);

      double Tl = m_actuation[0];
      double Tr = m_actuation[1];

      double turnLeft_i[4] = {m_asvm.turnLeft_k_2, m_asvm.turnLeft_k_1, Tl * std::fabs(Tl), Tl};
      double turnRight_i[4] = {m_asvm.turnRight_k_2, m_asvm.turnRight_k_1, Tr * std::fabs(Tr), Tr};

      double turnLeft = std::inner_product(turnLeft_i, turnLeft_i + 4, T2CLeft, 0.0);
      double turnRight = std::inner_product(turnRight_i, turnRight_i + 4, T2CRight, 0.0);

      double curL = 0.0;
      double curR = 0.0;

      if (m_asvm.turnLeft_k_1)
        curL = std::sqrt(std::fabs(m_asvm.turnLeft_k_1)) * (std::fabs(m_asvm.turnLeft_k_1) / m_asvm.turnLeft_k_1);

      if (m_asvm.turnRight_k_1)
        curR = std::sqrt(std::fabs(m_asvm.turnRight_k_1)) * (std::fabs(m_asvm.turnRight_k_1) / m_asvm.turnRight_k_1);

      double Xf = 25 * (curL + curR);
      double Nf = 0.00088667 * (curL - curR);

      addForces(Xf, 0, 0, 0, 0, Nf);

      // Set auxiliary memory.
      m_asvm.turnLeft_k_2 = m_asvm.turnLeft_k_1;
      m_asvm.turnLeft_k_1 = turnLeft;
      m_asvm.turnRight_k_2 = m_asvm.turnRight_k_1;
      m_asvm.turnRight_k_1 = turnRight;
    }
Пример #7
0
void motion(int x, int y)
{
    // Convert motion coordinates to domain
    float fx = (lastx / (float)wWidth);
    float fy = (lasty / (float)wHeight);
    int nx = (int)(fx * DIM);
    int ny = (int)(fy * DIM);

    if (clicked && nx < DIM-FR && nx > FR-1 && ny < DIM-FR && ny > FR-1)
    {
        int ddx = x - lastx;
        int ddy = y - lasty;
        fx = ddx / (float)wWidth;
        fy = ddy / (float)wHeight;
        int spy = ny-FR;
        int spx = nx-FR;
        addForces(dvfield, DIM, DIM, spx, spy, FORCE * DT * fx, FORCE * DT * fy, FR);
        lastx = x;
        lasty = y;
    }

    glutPostRedisplay();
}
Пример #8
0
void GLFluids::mouseMoveEvent(QMouseEvent *event)
{
    int x = event->x(); int y = event->y();

    // Convert motion coordinates to domain
    float fx = (lastx / (float)wWidth);
    float fy = (lasty / (float)wHeight);
    int nx = (int)(fx * DIM);
    int ny = (int)(fy * DIM);

    if (event->buttons() & Qt::LeftButton) {
        int ddx = x - lastx;
        int ddy = y - lasty;
        fx = ddx / (float)wWidth;
        fy = ddy / (float)wHeight;
        int spy = ny-FR;
        int spx = nx-FR;
        addForces(dvfield, DIM, DIM, spx, spy, FORCE * DT * fx, FORCE * DT * fy, FR);
    }

    lastx = x;
    lasty = y;
}