本文整理汇总了C++中TwoDScene::setPosition方法的典型用法代码示例。如果您正苦于以下问题:C++ TwoDScene::setPosition方法的具体用法?C++ TwoDScene::setPosition怎么用?C++ TwoDScene::setPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TwoDScene
的用法示例。
在下文中一共展示了TwoDScene::setPosition方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: stepScene
bool ExplicitEuler::stepScene( TwoDScene& scene, scalar dt )
{
VectorXs& x = scene.getX();
VectorXs& v = scene.getV();
const VectorXs& m = scene.getM();
// if( scene.isFixed(i) ) // Determine if the ith particle is fixed
int num_particles = scene.getNumParticles();
VectorXs forces(num_particles * 2);
VectorXs dx(num_particles * 2);
VectorXs dv(num_particles * 2);
for (int i = 0; i < num_particles * 2; i++){
forces(i) = 0.0;
dx(i) = 0.0;
dv(i) = 0.0;
}
scene.accumulateGradU(forces, dx, dv);//, const VectorXs& dx, const VectorXs& dv )
for (int i = 0; i < num_particles; i++){
if (!scene.isFixed(i)){
int index = 2 * i; // even indeces of vector are x params and odd are y params
const Vector2s next_velocity(v(index) + dt*forces(index)/m(index),
v(index+1) + dt*forces(index+1)/m(index));
scene.setVelocity(i, next_velocity);
const Vector2s next_position(x(index) + dt*v(index),
x(index + 1) + dt*v(index+1));
scene.setPosition(i, next_position);
scalar kinetic_energy = 0;
text_file << step_count*dt << "\t" << scene.computeKineticEnergy() << endl;
}
}
step_count++;
return true;
}
示例2: loadParticles
void TwoDSceneXMLParser::loadParticles( rapidxml::xml_node<>* node, TwoDScene& twodscene )
{
assert( node != NULL );
// Count the number of particles
int numparticles = 0;
for( rapidxml::xml_node<>* nd = node->first_node("particle"); nd; nd = nd->next_sibling("particle") ) ++numparticles;
twodscene.resizeSystem(numparticles);
//std::cout << "Num particles " << numparticles << std::endl;
std::vector<std::string>& tags = twodscene.getParticleTags();
int particle = 0;
for( rapidxml::xml_node<>* nd = node->first_node("particle"); nd; nd = nd->next_sibling("particle") )
{
// Extract the particle's initial position
Vector3s pos;
if( nd->first_attribute("px") )
{
std::string attribute(nd->first_attribute("px")->value());
if( !stringutils::extractFromString(attribute,pos.x()) )
{
std::cerr << "\033[31;1mERROR IN XMLSCENEPARSER:\033[m Failed to parse value of px attribute for particle " << particle << ". Value must be numeric. Exiting." << std::endl;
exit(1);
}
}
else
{
std::cerr << "\033[31;1mERROR IN XMLSCENEPARSER:\033[m Failed to parse px attribute for particle " << particle << ". Exiting." << std::endl;
exit(1);
}
if( nd->first_attribute("py") )
{
std::string attribute(nd->first_attribute("py")->value());
if( !stringutils::extractFromString(attribute,pos.y()) )
{
std::cerr << "\033[31;1mERROR IN XMLSCENEPARSER:\033[m Failed to parse value of py attribute for particle " << particle << ". Value must be numeric. Exiting." << std::endl;
exit(1);
}
}
else
{
std::cerr << "\033[31;1mERROR IN XMLSCENEPARSER:\033[m Failed to parse py attribute for particle " << particle << ". Exiting." << std::endl;
exit(1);
}
if( nd->first_attribute("pz") )
{
std::string attribute(nd->first_attribute("pz")->value());
if( !stringutils::extractFromString(attribute,pos.z()) )
{
std::cerr << "\033[31;1mERROR IN XMLSCENEPARSER:\033[m Failed to parse value of pz attribute for particle " << particle << ". Value must be numeric. Exiting." << std::endl;
exit(1);
}
}
else
{
std::cerr << "\033[31;1mERROR IN XMLSCENEPARSER:\033[m Failed to parse pz attribute for particle " << particle << ". Exiting." << std::endl;
exit(1);
}
twodscene.setPosition( particle, pos );
// Extract the particle's initial velocity
Vector3s vel;
if( nd->first_attribute("vx") )
{
std::string attribute(nd->first_attribute("vx")->value());
if( !stringutils::extractFromString(attribute,vel.x()) )
{
std::cerr << "\033[31;1mERROR IN XMLSCENEPARSER:\033[m Failed to parse value of vx attribute for particle " << particle << ". Value must be numeric. Exiting." << std::endl;
exit(1);
}
}
else
{
std::cerr << "\033[31;1mERROR IN XMLSCENEPARSER:\033[m Failed to parse vx attribute for particle " << particle << ". Exiting." << std::endl;
exit(1);
}
if( nd->first_attribute("vy") )
{
std::string attribute(nd->first_attribute("vy")->value());
if( !stringutils::extractFromString(attribute,vel.y()) )
{
std::cerr << "\033[31;1mERROR IN XMLSCENEPARSER:\033[m Failed to parse value of vy attribute for particle " << particle << ". Value must be numeric. Exiting." << std::endl;
exit(1);
}
}
else
{
std::cerr << "\033[31;1mERROR IN XMLSCENEPARSER:\033[m Failed to parse vy attribute for particle " << particle << ". Exiting." << std::endl;
exit(1);
}
if( nd->first_attribute("vz") )
{
std::string attribute(nd->first_attribute("vz")->value());
//.........这里部分代码省略.........