/* Perform one step of the solver */ void UpdateParticles( PARTICLE *p,int np, PARTICLEPHYS phys, PARTICLESPRING *s,int ns, double dt,int method, int gravity) { // printf("dt is (%lf)\n", dt); int i; PARTICLE *ptmp; PARTICLEDERIVATIVES *deriv; deriv = (PARTICLEDERIVATIVES *)malloc(np * sizeof(PARTICLEDERIVATIVES)); /* Midpoint */ CalculateForces(p,np,phys,s,ns, gravity); CalculateDerivatives(p,np,deriv); ptmp = (PARTICLE *)malloc(np * sizeof(PARTICLE)); for (i=0;i<np;i++) { ptmp[i] = p[i]; ptmp[i].p.x += deriv[i].dpdt.x * dt / 2; ptmp[i].p.y += deriv[i].dpdt.y * dt / 2; ptmp[i].p.z += deriv[i].dpdt.z * dt / 2; ptmp[i].p.x += deriv[i].dvdt.x * dt / 2; ptmp[i].p.y += deriv[i].dvdt.y * dt / 2; ptmp[i].p.z += deriv[i].dvdt.z * dt / 2; } CalculateForces(ptmp,np,phys,s,ns, gravity); CalculateDerivatives(ptmp,np,deriv); for (i=0;i<np;i++) { // printf("dt is (%lf)\n", dt); // printf("before p[%d].p.x = (%lf)\n", i, p[i].p.x); p[i].p.x += deriv[i].dpdt.x * dt; // printf("after p[%d].p.x = (%lf)\n", i, p[i].p.x); p[i].p.y += deriv[i].dpdt.y * dt; p[i].p.z += deriv[i].dpdt.z * dt; p[i].v.x += deriv[i].dvdt.x * dt; p[i].v.y += deriv[i].dvdt.y * dt; p[i].v.z += deriv[i].dvdt.z * dt; // printf("dt is (%lf)\n", dt); // printf("deriv[i].dvdt %d is at (%d, %d, %d) [%lf] \n", i, deriv[i].dvdt.x, deriv[i].dvdt.y, deriv[i].dvdt.z, dt); if(p[i].p.y < 0.0) { p[i].v.y = -p[i].v.y; } p[i].age += 1; // printf("particle %d is at (%lf, %lf, %lf)\n", i, p[i].p.x, p[i].p.y, p[i].p.z); } free(ptmp); free(deriv); }
void dgSolver::CalculateJointForces(const dgBodyCluster& cluster, dgBodyInfo* const bodyArray, dgJointInfo* const jointArray, dgFloat32 timestep) { m_cluster = &cluster; m_bodyArray = bodyArray; m_jointArray = jointArray; m_timestep = timestep; m_invTimestep = (timestep > dgFloat32(0.0f)) ? dgFloat32(1.0f) / timestep : dgFloat32(0.0f); m_invStepRK = dgFloat32 (0.25f); m_timestepRK = m_timestep * m_invStepRK; m_invTimestepRK = m_invTimestep * dgFloat32 (4.0f); m_threadCounts = m_world->GetThreadCount(); m_solverPasses = m_world->GetSolverIterations(); dgInt32 mask = -dgInt32(DG_SOA_WORD_GROUP_SIZE - 1); m_jointCount = ((m_cluster->m_jointCount + DG_SOA_WORD_GROUP_SIZE - 1) & mask) / DG_SOA_WORD_GROUP_SIZE; m_bodyProxyArray = dgAlloca(dgBodyProxy, cluster.m_bodyCount); m_bodyJacobiansPairs = dgAlloca(dgBodyJacobianPair, cluster.m_jointCount * 2); m_soaRowStart = dgAlloca(dgInt32, cluster.m_jointCount / DG_SOA_WORD_GROUP_SIZE + 1); InitWeights(); InitBodyArray(); InitJacobianMatrix(); CalculateForces(); }
void CFruchtermanReingold::calculate_coordinates() { CalculateForces(); for(int i = 0; i < vgc_nodes_num; ++i) { if(!vgc_graph->vertice_exists(i)) continue; QVector2D delta = vgc_vertices[i].v_force * NODE_MASS * TIME_DELTA * TIME_DELTA; vgc_vertices[i].v_coordinates += delta.toPoint() * std::min(delta.length(), (double)vgc_temperature) / delta.length(); } Cool(); }
void Entity::update() { if( Mode == EMM_CLIENT ) { if( time_for_next_update >= Game->getTimer()->getTimeMS() ) { Physics->getBody()->activate( true ); time_for_next_update = Game->getTimer()->getTimeMS() + MAX_SYNC_TIME; } } Network->update(); NetData* input = Network->getInStream(); do { if( input!= NULL ) { if( input->MsgType == ENMT_SYNC ) { Physics->getDrawMesh()->setPosition( irr::core::vector3df( input->Create.Position[0], input->Create.Position[1],input->Create.Position[2] ) ); Physics->getDrawMesh()->setRotation( irr::core::vector3df( input->Create.Rotation[0], input->Create.Position[1],input->Create.Position[2] ) ); Physics->getBody()->setLinearVelocity( irr::core::vector3df( input->Create.LinearVelocity[0], input->Create.LinearVelocity[1],input->Create.LinearVelocity[2] ) ); Physics->getBody()->setAngularVelocity( irr::core::vector3df( input->Create.AngularVelocity[0], input->Create.AngularVelocity[1],input->Create.AngularVelocity[2] ) ); } else if( input->MsgType == ENMT_INPUT ) { CalculateForces( input->Input ); u32 timems = Game->getTimer()->getTimeMS(); if( input->Input.Trigger && timems >= TimeForNextTrigger ) { // Bang! (create a bullet here. we don't have bullet data yet...) TimeForNextTrigger = timems + (timems - TimeForNextTrigger) + MIN_TRIGGER_TIME; } } if( input->MsgType != ENMT_DESTROY || (input->MsgType == ENMT_INPUT && input->Input.AXIS_Pitch == 0.0f && input->Input.AXIS_Roll == 0.0f && input->Input.AXIS_Yaw == 0.0f) ) { CalculateSlowDown(); } } input->drop(); Network->update(); } while( (input = Network->getInStream()) != NULL ); NetData* Update = NULL; if( Mode == EMM_SERVER ) { for( u32 i=0; i<Game->getEntityList().size(); i++ ) { if( Game->getEntityList()[i] != this ) Game->getEntityList()[i]->applyGravity( Physics->getDrawMesh()->getPosition(), Physics->getLocalData().Mass ); } Physics->update(); if( time_for_next_update <= Game->getTimer()->getTimeMS() ) { Physics->getBody()->activate( true ); time_for_next_update = Game->getTimer()->getTimeMS() + MAX_SYNC_TIME; Update = new NetData(); Update->grab(); Update->MessageStart = Message_Begin; Update->MsgTime = Game->getTimer()->getTimeMS(); Update->MsgType = ENMT_SYNC; Update->net_id = Network->getNetID(); Update->MessageEnd = Message_End; Update->Sync.Position[0] = Physics->getLocalData().Position[0]; Update->Sync.Rotation[0] = Physics->getLocalData().Rotation[0]; Update->Sync.LinearVelocity[0] = Physics->getLocalData().LinearVelocity[0]; Update->Sync.AngularVelocity[0] = Physics->getLocalData().AngularVelocity[0]; Update->Sync.Position[1] = Physics->getLocalData().Position[1]; Update->Sync.Rotation[1] = Physics->getLocalData().Rotation[1]; Update->Sync.LinearVelocity[1] = Physics->getLocalData().LinearVelocity[1]; Update->Sync.AngularVelocity[1] = Physics->getLocalData().AngularVelocity[1]; Update->Sync.Position[2] = Physics->getLocalData().Position[2]; Update->Sync.Rotation[2] = Physics->getLocalData().Rotation[2]; Update->Sync.LinearVelocity[2] = Physics->getLocalData().LinearVelocity[2]; Update->Sync.AngularVelocity[2] = Physics->getLocalData().AngularVelocity[2]; Network->sendData( Update ); Update->drop(); } } }