示例#1
0
Signal ReadGraph(const QJsonObject& obj)
{
	Signal signal{};

	auto it = obj.find("name");
	if (it != obj.end())
	{
		const auto sigName = it->toString();
		signal.name = std::move(sigName);

		it = obj.find("color");
		if (it != obj.end())
			signal.graphic.color = it->toString();
		
		it = obj.find("visible");
		if (it != obj.end())
			signal.graphic.visible = it->toBool();
		
		it = obj.find("range");
		if (it != obj.end())
		{
			auto vec = ToVector(it->toArray());
			signal.graphic.rangeLower = vec.front();
			signal.graphic.rangeUpper = vec.back();
		}
		
		it = obj.find("values");
		if (it != obj.end() && it->isArray())
		{
			signal.y = ToVector(it->toArray());
		}
		
		it = obj.find("ticks");
		if (it != obj.end() && it->isArray())
		{
			signal.graphic.ticks = ToVector(it->toArray());
		}

		it = obj.find("tickLabels");
		if (it != obj.end() && it->isArray())
		{
			signal.graphic.tickLabels = ToStrVector(it->toArray());
		}
	}

	return signal;
}
示例#2
0
double RPCCamera::GetNadirAngle() const
{
   MyPoint3d camPnt; MyVector3d camVec;
   ToVector(100, 100, camVec, camPnt);
   MyVector3d vpnt = -camPnt;
   MyVectorNormalize(vpnt);
   return acos(MyVectorDot(vpnt, camVec));
}
示例#3
0
 void ConvertToVector(std::vector<T> &v){
     std::vector<std::string> tmp;
     ToVector(tmp);
     v.resize(tmp.size());
     typename std::vector<T>::iterator viter = v.begin();
     typename std::vector<std::string>::iterator iter;
     for(iter = tmp.begin(); iter!=tmp.end(); ++iter, ++viter)
         *viter = boost::lexical_cast<T, std::string>(*iter);
 }
示例#4
0
static void SumTest() {
	unsigned int number1[] = { 3, 5, 6 };
	unsigned int number2[] = { 7, 0, 4, 2, 1 };
	IntNode* n1 = CreateList(number1, ARRAY_SIZE(number1));
	IntNode* n2 = CreateList(number2, ARRAY_SIZE(number2));

	IntNode* sum = Sum(n1, n2);
	Asserts::IsTrue(sum != 0);
	
	unsigned int expectedData[] = { 0, 6, 0, 3, 1 };
	std::vector<unsigned int> actual = ToVector(sum);
	Asserts::AreEqual(expectedData, ARRAY_SIZE(expectedData), actual);
}
示例#5
0
void Delaunay3D::Event_SetScale(const EV::Arg<double>& event) {
    if(_simplices.empty()) return;

    std::cout << "Delaunay3D: scaling simplices ... ";
    for(unsigned j = 0; j < _simplices.size(); ++j) {
        Simplex& simplex = _simplices[j];

        leda::rational scale = 1 + 5 * event.value;
        leda::rat_vector center = scale * simplex.center;

        leda::nb::RatPolyMesh& graph = NB::GetGraph(_mesh);
        for(int i = 0; i < 4; ++i) {
            // NOTE: carrying out this addition with rat_vectors yields NaNs when converted to float.
            // i have absolutely NO IDEA why. maybe corrupted leda install?
            graph.set_position(simplex.verts[i], ToRatPoint(ToVector(simplex.localPos[i]) + ToVector(center)));
        }
    }
    std::cout << "DONE" << std::endl;
}
示例#6
0
文件: ray3.cpp 项目: NavQ/argos3
 bool CRay3::Intersects(const CPlane& c_plane,
                        CVector3& c_point) const {
    CVector3 cRayVec;
    Real fDen = c_plane.GetNormal().DotProduct(ToVector(cRayVec));
    if(Abs(fDen) > 0.0f) {
       /* There could be intersection */
       Real fTOnRay = -c_plane.GetNormal().DotProduct(m_cStart - c_plane.GetPosition()) / fDen;
       if(fTOnRay < 0.0f || fTOnRay > 1.0f) {
          /* Intersection point is beyond ray extrema */
          return false;
       }
       else {
          /* There is an intersection */
          GetPoint(c_point, fTOnRay);
          return true;
       }
    }
    else {
       /* No intersection */
       return false;
    }
 }
void GravityEntity::initializeEntity( const TiXmlElement *propertyElement /*= NULL */ )
{
	BaseClass::initializeEntity(propertyElement);

	sf::Vector2f finalGravity = thor::rotatedVector<float>(sf::Vector2f(0,GRAVITY_ACCELERATION), getRotation() );

	//HACKHACK!!
	if(std::abs(finalGravity.x) <= 5.0f)
	{
		finalGravity.x = 0.f;
	}

	if(std::abs(finalGravity.y) <= 5.0f)
	{
		finalGravity.y = 0.f;
	}

	if( finalGravity.x < 0.f )
	{
		m_gravityDirection = sb::PhysicsManager::Gravity_Right;
	}

	if( finalGravity.x > 0.f )
	{
		m_gravityDirection = sb::PhysicsManager::Gravity_Left;
	}

	if( finalGravity.y > 0.f )
	{
		m_gravityDirection = sb::PhysicsManager::Gravity_Up;
	}

	if( finalGravity.y < 0.f )
	{
		m_gravityDirection = sb::PhysicsManager::Gravity_Down;
	}


	const float GRAVITY_SIZE = 2.0f;

	{
		thor::ResourceKey<sf::Texture> key = thor::Resources::fromFile<sf::Texture>("Resource/Ogmo/Entities/Gravity.png");
		std::shared_ptr<sf::Texture> texture = sb::ResourceCache::getInstance()->acquire<sf::Texture>(key);
		m_gravitySprite.setTexture(*texture);
		m_gravitySprite.setOrigin(32,32);

		sb::GraphicsManager::getInstance()->addDrawable(m_gravitySprite,2);
	}

	{
		thor::ResourceKey<sf::SoundBuffer> key = thor::Resources::fromFile<sf::SoundBuffer>("Resource/Sounds/gravity.wav");
		std::shared_ptr<sf::SoundBuffer> buffer = sb::ResourceCache::getInstance()->acquire<sf::SoundBuffer>(key);
		m_gravitySound.setBuffer(*buffer);
		m_gravitySound.setVolume(50.f);
	}

	{
		b2BodyDef bodyDefinition;
		bodyDefinition.userData = (Entity*)this;
		bodyDefinition.position = ToVector(getPosition());
		bodyDefinition.angle = getRotation() * DEGTORAD * -1.f;
		bodyDefinition.type = b2_staticBody;

		b2Body* throwBody = sb::PhysicsManager::getInstance()->getPhysicsWorld()->CreateBody(&bodyDefinition);

		b2PolygonShape boxShape;
		boxShape.SetAsBox( 0.5f*GRAVITY_SIZE, 0.5f*GRAVITY_SIZE );

		b2FixtureDef fixtureDefinition;
		fixtureDefinition.shape = &boxShape;
		fixtureDefinition.density = 1.0f;
		fixtureDefinition.friction = 0.0f;
		fixtureDefinition.restitution = 0.5f;

		throwBody->CreateFixture(&fixtureDefinition);

		m_gravityBody.setBody(throwBody);

		sb::PhysicsManager::getInstance()->addSimulatable(&m_gravityBody);
	}
}
示例#8
0
int main() {

  //Test bin2Hex
  unsigned char ubin[] = {0xFF, 0xEE, 0x00, 0x55, 0x66};
  std::vector<std::remove_pointer<std::decay<decltype(ubin)>::type>::type> ubinVec;
  std::copy(ubin, ubin + 5, std::back_inserter(ubinVec));

  char* signedBin = reinterpret_cast<char*>(&ubin[0]);

  std::vector<std::remove_pointer<std::decay<decltype(signedBin)>::type>::type> signedbinVec;
  std::copy(signedBin, signedBin + 5, std::back_inserter(signedbinVec));
  PG(bin2hex(signedBin, 5));
  PG(bin2hex(ubin, 5));
  PG(ToVector(signedBin, 5));
  PG(ToVector(ubin, 5));
  PG(ubinVec);
  PG(signedbinVec);

#ifdef MOZ_XUL
  MOZ_LOG(0,0, ("some log\n"));
  NS_WARNING("only string\n");
  nsresult res = NS_OK;
  nsString foo = NS_LITERAL_STRING("nsString");
  nsCString bar = NS_LITERAL_CSTRING("nsCString");
  nsAutoString msg = NS_ConvertASCIItoUTF16("nsAutoString");
  nsAutoCString msg2("nsAutoCString");
#endif
  std::vector<int> vec;
  vec.push_back(1);
  vec.push_back(2);
  vec.push_back(3);

  std::vector<std::string> vecStr;
  vecStr.push_back("1");
  vecStr.push_back("2");
  vecStr.push_back("3");

  std::map<std::string, double> s2d;
  s2d["mozilla"] = 123.5566;
  s2d["gecko"] = 1234.0;

  std::unordered_map<std::string, std::string> s2s;
  s2s["mozilla"] = "mozilla";
  s2s["gecko"] = "gecko";
  float a = 55.66f;
  std::string b = "haha";
  double c = 42689.2;
  const char* d = "abc";
  bool e = true;
  MOZILLA f;
  f.Gecko();
  int32_t g = -123;
  int64_t h = -5566;
  uint32_t i = 123;
  uint64_t j = 1234;

#ifdef MOZ_XUL
  P(a, b, c, d, e, &f, g, h, i, j, foo, bar, msg, msg2, res);
#else
  P(a, b, c, d, e, &f, g, h, i, j, vec, vecStr, s2d, s2s);

#endif
  EZ_TAG = "123";
  PR(a, b, c, d, e, &f, g, h, i, j);
  PG(a, b, c, d, e, &f, g, h, i, j);
  PB(a, b, c, d, e, &f, g, h, i, j);
  PX0(EZ_RED);
  PX0(EZ_LIGHT_RED);
  PX0(EZ_GREEN);
  PX0(EZ_LIGHT_GREEN);
  PX0(EZ_BLUE);
  PX0(EZ_LIGHT_BLUE);
  PX0(EZ_DARY_GRAY);
  PX0(EZ_CYAN);
  PX0(EZ_LIGHT_CYAN);
  PX(EZ_LIGHT_CYAN, a, b, c, d, e, &f, g, h, i, j);
  PX0(EZ_PURPLE);
  PX0(EZ_LIGHT_PURPLE);
  PX0(EZ_BROWN);
  PX0(EZ_YELLOW);
  PX0(EZ_LIGHT_GRAY);
  PR0(); //Empty
  PG0();
  PB0();

  return 0;
}