Ejemplo n.º 1
0
void MainWindow::autoMeshInternal(TriangleListPtr trianglesFront, TriangleListPtr trianglesBack, struct predgparam3f_s *param, double targetRadius, int component, double minU, double maxU, double minV, double maxV, int maxSubdivisions, int subdivision)
{
    struct spin3f_s sp00, sp01, sp10, sp11;

    predgparam3f_eval(&sp00, param, minU, minV, component);
    predgparam3f_eval(&sp01, param, minU, maxV, component);
    predgparam3f_eval(&sp10, param, maxU, minV, component);
    predgparam3f_eval(&sp11, param, maxU, maxV, component);

    if (subdivision == maxSubdivisions || (projectedDistance(&sp00, &sp01) <= targetRadius && projectedDistance(&sp00, &sp10) <= targetRadius && projectedDistance(&sp00, &sp11) <= targetRadius &&
                                           projectedDistance(&sp01, &sp10) <= targetRadius && projectedDistance(&sp01, &sp11) <= targetRadius && projectedDistance(&sp10, &sp11) <= targetRadius))
    {
        QVector3D v00(sp00.s12 / (1 - sp00.s0), sp00.s23 / (1 - sp00.s0), sp00.s31 / (1 - sp00.s0));
        QVector3D v01(sp01.s12 / (1 - sp01.s0), sp01.s23 / (1 - sp01.s0), sp01.s31 / (1 - sp01.s0));
        QVector3D v10(sp10.s12 / (1 - sp10.s0), sp10.s23 / (1 - sp10.s0), sp10.s31 / (1 - sp10.s0));
        QVector3D v11(sp11.s12 / (1 - sp11.s0), sp11.s23 / (1 - sp11.s0), sp11.s31 / (1 - sp11.s0));

        trianglesFront->push_back(Triangle(v00, v01, v11));
        trianglesFront->push_back(Triangle(v00, v11, v10));

        trianglesBack->push_back(Triangle(v00, v11, v01));
        trianglesBack->push_back(Triangle(v00, v10, v11));
    }
    else
    {
        autoMeshInternal(trianglesFront, trianglesBack, param, targetRadius, component, minU, minU + 0.5 * (maxU - minU), minV, minV + 0.5 * (maxV - minV), maxSubdivisions, subdivision + 1);
        autoMeshInternal(trianglesFront, trianglesBack, param, targetRadius, component, minU, minU + 0.5 * (maxU - minU), minV + 0.5 * (maxV - minV), maxV, maxSubdivisions, subdivision + 1);
        autoMeshInternal(trianglesFront, trianglesBack, param, targetRadius, component, minU + 0.5 * (maxU - minU), maxU, minV, minV + 0.5 * (maxV - minV), maxSubdivisions, subdivision + 1);
        autoMeshInternal(trianglesFront, trianglesBack, param, targetRadius, component, minU + 0.5 * (maxU - minU), maxU, minV + 0.5 * (maxV - minV), maxV, maxSubdivisions, subdivision + 1);
    }
}
Ejemplo n.º 2
0
int main(){

	// Create the Views
	GLV glv;
	View v(Rect(100,100, 600,400));
	View v1(Rect(10,10, 300,200)), v2(Rect(v1.right()+10,10, 100,200));
	View v11(Rect(20,20, 80,100)), v12(Rect(80,80,100,80));

	// Create the tree hierarchy 
	glv << v;
	v << v1 << v2;
	v1 << v11 << v12;
	
	// Set properties of Views	
	View* views[] = {&v, &v1, &v2, &v11, &v12};
	for(int i=0; i<5; ++i){
		views[i]->addHandler(Event::MouseDrag, Behavior::mouseMove);
		//views[i]->enable(KeepWithinParent);
	}
	
	// Disable some of the default View properties
	v.disable(DrawBack);
	v2.disable(DrawBorder);
	v12.disable(FocusHighlight);
	
	// Set color styles
	glv.cloneStyle().colors().set(StyleColor::WhiteOnBlack);
	v1.colors().set(Color(0.2,0.4,1,0.8), 0.7);
			
	Window win(800,600, "Views", &glv);

	Application::run();
}
Ejemplo n.º 3
0
void Planet::drawAtmoCell(float r1, float r2, float a1, float a2, Color4F r1col, Color4F r2col)
{
    Vec2 v11(r1 * cosf(a1), r1 * sinf(a1));
    Vec2 v12(r1 * cosf(a2), r1 * sinf(a2));
    Vec2 v21(r2 * cosf(a1), r2 * sinf(a1));
    Vec2 v22(r2 * cosf(a2), r2 * sinf(a2));
    node()->drawTriangleGradient(v11, v21, v12, r1col, r2col, r1col);
    node()->drawTriangleGradient(v12, v21, v22, r1col, r2col, r2col);
}
Ejemplo n.º 4
0
void Planet::drawStratumCell(float a1, float a2, const Stratum& s1, const Stratum& s2)
{
    float r11 = _coreRadius + s1.alt1;
    float r12 = _coreRadius + s2.alt1;
    float r21 = _coreRadius + s1.alt2;
    float r22 = _coreRadius + s2.alt2;
    Vec2 v11(r11 * cosf(a1), r11 * sinf(a1));
    Vec2 v12(r12 * cosf(a2), r12 * sinf(a2));
    Vec2 v21(r21 * cosf(a1), r21 * sinf(a1));
    Vec2 v22(r22 * cosf(a2), r22 * sinf(a2));
    node()->drawTriangleGradient(v11, v21, v12, s1.col1, s2.col1, s1.col2);
    node()->drawTriangleGradient(v12, v21, v22, s1.col2, s2.col1, s2.col2);
}
Ejemplo n.º 5
0
void ValueTest::onEnter()
{
    UnitTestDemo::onEnter();

    Value v1;
    CCASSERT(v1.getType() == Value::Type::NONE, "");
    CCASSERT(v1.isNull(), "");

    Value v2(100);
    CCASSERT(v2.getType() == Value::Type::INTEGER, "");
    CCASSERT(!v2.isNull(), "");

    Value v3(101.4f);
    CCASSERT(v3.getType() == Value::Type::FLOAT, "");
    CCASSERT(!v3.isNull(), "");

    Value v4(106.1);
    CCASSERT(v4.getType() == Value::Type::DOUBLE, "");
    CCASSERT(!v4.isNull(), "");

    unsigned char byte = 50;
    Value v5(byte);
    CCASSERT(v5.getType() == Value::Type::BYTE, "");
    CCASSERT(!v5.isNull(), "");

    Value v6(true);
    CCASSERT(v6.getType() == Value::Type::BOOLEAN, "");
    CCASSERT(!v6.isNull(), "");

    Value v7("string");
    CCASSERT(v7.getType() == Value::Type::STRING, "");
    CCASSERT(!v7.isNull(), "");

    Value v8(std::string("string2"));
    CCASSERT(v8.getType() == Value::Type::STRING, "");
    CCASSERT(!v8.isNull(), "");

    auto createValueVector = [&]() {
        ValueVector ret;
        ret.push_back(v1);
        ret.push_back(v2);
        ret.push_back(v3);
        return ret;
    };


    Value v9(createValueVector());
    CCASSERT(v9.getType() == Value::Type::VECTOR, "");
    CCASSERT(!v9.isNull(), "");

    auto createValueMap = [&]() {
        ValueMap ret;
        ret["aaa"] = v1;
        ret["bbb"] = v2;
        ret["ccc"] = v3;
        return ret;
    };

    Value v10(createValueMap());
    CCASSERT(v10.getType() == Value::Type::MAP, "");
    CCASSERT(!v10.isNull(), "");

    auto createValueMapIntKey = [&]() {
        ValueMapIntKey ret;
        ret[111] = v1;
        ret[222] = v2;
        ret[333] = v3;
        return ret;
    };

    Value v11(createValueMapIntKey());
    CCASSERT(v11.getType() == Value::Type::INT_KEY_MAP, "");
    CCASSERT(!v11.isNull(), "");
}
int main(int argc, char *argv[])
{
  Pooma::initialize(argc,argv);
  Pooma::Tester tester(argc, argv);

  // --------------------------------------------------------------------------
  // 3D 
  // --------------------------------------------------------------------------
  Tensor<3,double,Full> t3f1(0.0, 3.0, 6.0, 1.0, 4.0, 7.0, 2.0, 5.0, 8.0);
  tester.out() << "t3f1: " << t3f1 << std::endl;
  Tensor<3,double,Full> t3f2 = -t3f1;
  tester.out() << "t3f2: " << t3f2 << std::endl;

  Tensor<3,double,Symmetric> t3s1(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);
  tester.out() << "t3s1: " << t3s1 << std::endl;
  Tensor<3,double,Symmetric> t3s2(-1.0, -2.0, -3.0, -4.0, -5.0, -6.0);
  tester.out() << "t3s2: " << t3s2 << std::endl;

  Tensor<3,double,Full> t3s1AsFull(1.0,2.0,4.0, 2.0,3.0,5.0, 4.0,5.0,6.0);
  tester.out() << "t3s1AsFull: " << t3s1AsFull << std::endl;
  Tensor<3,double,Full> t3s2AsFull = -t3s1AsFull;
  tester.out() << "t3s2AsFull: " << t3s2AsFull << std::endl;

  Tensor<3,double,Symmetric> t3s3(9.0, 9.0, 9.0, 9.0, 9.0, 9.0), 
    t3s4(9.0, 9.0, 9.0, 9.0, 9.0, 9.0);

  t3s3 = t3s1 + t3s2;
  tester.out() << "t3s3 = t3s1 + t3s2: " << t3s3 << std::endl;
  tester.check("t3s3", t3s3, Tensor<3,double,Symmetric>(0.0));
  tester.check("t3s3 against Full", 
               (t3s3 == Tensor<3,double,Symmetric>(0.0)));

  Tensor<3,double,Full> t3f3(99.9), t3f4(99.9), t3f5(99.9), t3f6(99.9);

  t3f3 = t3f1 + t3f2; // No need to check results here; done in TestTensors

  t3f4 = t3s1 + t3s2;
  tester.out() << "t3f4 = t3s1 + t3s2: " << t3f4 << std::endl;
  tester.check("t3f4", (t3f4 == t3s3));

  t3f5 = t3f1 + t3s2;
  tester.out() << "t3f5 = t3f1 + t3s2: " << t3f5 << std::endl;
  tester.check("t3f5", t3f5, t3f1 + t3s2AsFull);

  t3f6 = t3s2 + t3f1;
  tester.out() << "t3f6 = t3s2 + t3f1: " << t3f6 << std::endl;
  tester.check("t3f6", t3f6, t3f1 + t3s2AsFull);

  t3f6 -= t3f1;
  tester.out() << "t3f6 -= t3f1: " << t3f6 << std::endl;
  tester.check("t3f6", t3f6, t3s2AsFull);

  t3s4 = t3s3 - t3f1;
  tester.out() << "t3s4 = t3s3 - t3f1: " << t3s4 << std::endl;
  tester.check("t3s4", 
               (t3s4 == Tensor<3,double,Symmetric>(0,-3,-4,-6,-7,-8)));


  // Test Tensor dot Tensor:

  // Full:
  double sum = 0.0;
  int i, j, k;
  t3f3 = dot(t3f1, t3f2);
  for (i = 0; i < 3; ++i) {
    for (j = 0; j < 3; ++j) {
      for (k = 0; k < 3; ++k) {
        t3f3(i,k) -= t3f1(i,j)*t3f2(j,k);
      }
    }
  }
  t3f3 = t3f3*t3f3;
  for (i = 0; i < 3; ++i) {
    for (j = 0; j < 3; ++j) {
      sum += t3f3(i,j);
    }
  }
  tester.check("dot(t3f1, t3f2)", (sum == 0));
  
  // Symmetric:
  sum = 0.0;
  t3f3 = dot(t3s1, t3s2);
  for (i = 0; i < 3; ++i) {
    for (j = 0; j < 3; ++j) {
      for (k = 0; k < 3; ++k) {
        t3f3(i,k) -= t3s1(i,j)*t3s2(j,k);
      }
    }
  }
  t3f3 = t3f3*t3f3;
  for (i = 0; i < 3; ++i) {
    for (j = 0; j < 3; ++j) {
      sum += t3f3(i,j);
    }
  }
  tester.check("dot(t3s1, t3s2)", (sum == 0));

  // Test Tensor dot Vector, and vice-versa:

  // Full:
  // Vector dot Tensor
  Vector<3> v31(1.0, 2.0, 3.0);
  tester.out() << "v31: " << v31 << std::endl;
  Vector<3> v32(9.0);
  v32 = dot(v31, t3f2);
  tester.out() << "v32 = dot(v31, t3f2): " << v32 << std::endl;
  for (i = 0; i < 3; ++i) {
    for (j = 0; j < 3; ++j) {
      v32(j) -= v31(i)*t3f2(i,j);
    }
  }
  v32 = v32*v32;
  sum = 0.0;
  for (i = 0; i < 3; ++i) {
    sum += v32(i);
  }
  tester.check("dot(v31, t3f2)", (sum == 0));
  // Tensor dot Vector
  v32 = dot(t3f2, v31);
  tester.out() << "v32 = dot(t3f2, v31): " << v32 << std::endl;
  for (i = 0; i < 3; ++i) {
    for (j = 0; j < 3; ++j) {
      v32(i) -= t3f2(i,j)*v31(j);
    }
  }
  v32 = v32*v32;
  sum = 0.0;
  for (i = 0; i < 3; ++i) {
    sum += v32(i);
  }
  tester.check("dot(t3f2, v31)", (sum == 0));
  
  // Symmetric:
  // Vector dot Tensor
  v32 = dot(v31, t3s2);
  tester.out() << "v32 = dot(v31, t3s2): " << v32 << std::endl;
  for (i = 0; i < 3; ++i) {
    for (j = 0; j < 3; ++j) {
      v32(j) -= v31(i)*t3s2(i,j);
    }
  }
  v32 = v32*v32;
  sum = 0.0;
  for (i = 0; i < 3; ++i) {
    sum += v32(i);
  }
  tester.check("dot(v31, t3s2)", (sum == 0));
  // Tensor dot Vector
  v32 = dot(t3s2, v31);
  tester.out() << "v32 = dot(t3s2, v31): " << v32 << std::endl;
  for (i = 0; i < 3; ++i) {
    for (j = 0; j < 3; ++j) {
      v32(i) -= t3s2(i,j)*v31(j);
    }
  }
  v32 = v32*v32;
  sum = 0.0;
  for (i = 0; i < 3; ++i) {
    sum += v32(i);
  }
  tester.check("dot(t3s2, v31)", (sum == 0));


  // --------------------------------------------------------------------------
  // 2D 
  // --------------------------------------------------------------------------

  Tensor<2,double,Full> t2f1(0.0, 2.0, 1.0, 3.0);
  tester.out() << "t2f1: " << t2f1 << std::endl;
  Tensor<2,double,Full> t2f2 = -t2f1;
  tester.out() << "t2f2: " << t2f2 << std::endl;

  Tensor<2,double,Symmetric> t2s1(1.0, 2.0, 3.0);
  tester.out() << "t2s1: " << t2s1 << std::endl;
  Tensor<2,double,Symmetric> t2s2(-1.0, -2.0, -3.0);
  tester.out() << "t2s2: " << t2s2 << std::endl;

  Tensor<2,double,Full> t2s1AsFull(1.0,2.0, 2.0,3.0);
  tester.out() << "t2s1AsFull: " << t2s1AsFull << std::endl;
  Tensor<2,double,Full> t2s2AsFull = -t2s1AsFull;
  tester.out() << "t2s2AsFull: " << t2s2AsFull << std::endl;

  Tensor<2,double,Symmetric> t2s3(9.0, 9.0, 9.0), t2s4(9.0, 9.0, 9.0);

  t2s3 = t2s1 + t2s2;
  tester.out() << "t2s3 = t2s1 + t2s2: " << t2s3 << std::endl;
  tester.check("t2s3", t2s3, Tensor<2,double,Symmetric>(0.0));
  tester.check("t2s3 against Full", 
               (t2s3 == Tensor<2,double,Symmetric>(0.0)));

  Tensor<2,double,Full> t2f3(99.9), t2f4(99.9), t2f5(99.9), t2f6(99.9), 
    t2f7(99.9);

  t2f3 = t2f1 + t2f2;
  tester.out() << "t2f3 = t2f1 + t2f2: " << t2f3 << std::endl;
  tester.check("t2f3", t2f3, Tensor<2,double,Full>(0.0));

  t2f4 = t2s1 + t2s2;
  tester.out() << "t2f4 = t2s1 + t2s2: " << t2f4 << std::endl;
  tester.check("t2f4", (t2f4 == t2s3));

  t2f5 = t2f1 + t2s2;
  tester.out() << "t2f5 = t2f1 + t2s2: " << t2f5 << std::endl;
  tester.check("t2f5", t2f5, t2f1 + t2s2AsFull);

  t2f6 = t2s2 + t2f1;
  tester.out() << "t2f6 = t2s2 + t2f1: " << t2f6 << std::endl;
  tester.check("t2f6", t2f6, t2f1 + t2s2AsFull);

  t2f6 -= t2f1;
  tester.out() << "t2f6 -= t2f1: " << t2f6 << std::endl;
  tester.check("t2f6", t2f6, t2s2AsFull);

  t2s4 = t2s3 - t2f1;
  tester.out() << "t2s4 = t2s3 - t2f1: " << t2s4 << std::endl;
  tester.check("t2s4", 
               (t2s4 == Tensor<2,double,Symmetric>(-0, -2, -3)));


  // Test Tensor dot Tensor:

  // Full:
  sum = 0.0;
  t2f3 = dot(t2f1, t2f2);
  for (i = 0; i < 2; ++i) {
    for (j = 0; j < 2; ++j) {
      for (k = 0; k < 2; ++k) {
        t2f3(i,k) -= t2f1(i,j)*t2f2(j,k);
      }
    }
  }
  t2f3 = t2f3*t2f3;
  for (i = 0; i < 2; ++i) {
    for (j = 0; j < 2; ++j) {
      sum += t2f3(i,j);
    }
  }
  tester.check("dot(t2f1, t2f2)", (sum == 0));
  
  // Symmetric:
  sum = 0.0;
  t2f3 = dot(t2s1, t2s2);
  for (i = 0; i < 2; ++i) {
    for (j = 0; j < 2; ++j) {
      for (k = 0; k < 2; ++k) {
        t2f3(i,k) -= t2s1(i,j)*t2s2(j,k);
      }
    }
  }
  t2f3 = t2f3*t2f3;
  for (i = 0; i < 2; ++i) {
    for (j = 0; j < 2; ++j) {
      sum += t2f3(i,j);
    }
  }
  tester.check("dot(t2s1, t2s2)", (sum == 0));

  // Test Tensor dot Vector, and vice-versa:

  // Full:
  // Vector dot Tensor
  Vector<2> v21(1.0, 2.0);
  tester.out() << "v21: " << v21 << std::endl;
  Vector<2> v22(9.0);
  v22 = dot(v21, t2f2);
  tester.out() << "v22 = dot(v21, t2f2): " << v22 << std::endl;
  for (i = 0; i < 2; ++i) {
    for (j = 0; j < 2; ++j) {
      v22(j) -= v21(i)*t2f2(i,j);
    }
  }
  v22 = v22*v22;
  sum = 0.0;
  for (i = 0; i < 2; ++i) {
    sum += v22(i);
  }
  tester.check("dot(v21, t2f2)", (sum == 0));
  // Tensor dot Vector
  v22 = dot(t2f2, v21);
  tester.out() << "v22 = dot(t2f2, v21): " << v22 << std::endl;
  for (i = 0; i < 2; ++i) {
    for (j = 0; j < 2; ++j) {
      v22(i) -= t2f2(i,j)*v21(j);
    }
  }
  v22 = v22*v22;
  sum = 0.0;
  for (i = 0; i < 2; ++i) {
    sum += v22(i);
  }
  tester.check("dot(t2f2, v21)", (sum == 0));
  
  // Symmetric:
  // Vector dot Tensor
  v22 = dot(v21, t2s2);
  tester.out() << "v22 = dot(v21, t2s2): " << v22 << std::endl;
  for (i = 0; i < 2; ++i) {
    for (j = 0; j < 2; ++j) {
      v22(j) -= v21(i)*t2s2(i,j);
    }
  }
  v22 = v22*v22;
  sum = 0.0;
  for (i = 0; i < 2; ++i) {
    sum += v22(i);
  }
  tester.check("dot(v21, t2s2)", (sum == 0));
  // Tensor dot Vector
  v22 = dot(t2s2, v21);
  tester.out() << "v22 = dot(t2s2, v21): " << v22 << std::endl;
  for (i = 0; i < 2; ++i) {
    for (j = 0; j < 2; ++j) {
      v22(i) -= t2s2(i,j)*v21(j);
    }
  }
  v22 = v22*v22;
  sum = 0.0;
  for (i = 0; i < 2; ++i) {
    sum += v22(i);
  }
  tester.check("dot(t2s2, v21)", (sum == 0));


  // --------------------------------------------------------------------------
  // 1D 
  // --------------------------------------------------------------------------

  Tensor<1,double,Full> t1f1(1.0);
  tester.out() << "t1f1: " << t1f1 << std::endl;
  Tensor<1,double,Full> t1f2 = -t1f1;
  tester.out() << "t1f2: " << t1f2 << std::endl;

  Tensor<1,double,Symmetric> t1s1(1.0);
  tester.out() << "t1s1: " << t1s1 << std::endl;
  Tensor<1,double,Symmetric> t1s2(-1.0);
  tester.out() << "t1s2: " << t1s2 << std::endl;

  Tensor<1,double,Full> t1s1AsFull(1.0);
  tester.out() << "t1s1AsFull: " << t1s1AsFull << std::endl;
  Tensor<1,double,Full> t1s2AsFull = -t1s1AsFull;
  tester.out() << "t1s2AsFull: " << t1s2AsFull << std::endl;

  Tensor<1,double,Symmetric> t1s3(9.0), t1s4(9.0);

  t1s3 = t1s1 + t1s2;
  tester.out() << "t1s3 = t1s1 + t1s2: " << t1s3 << std::endl;
  tester.check("t1s3", t1s3, Tensor<1,double,Symmetric>(0.0));
  tester.check("t1s3 against Full", 
               (t1s3 == Tensor<1,double,Symmetric>(0.0)));

  Tensor<1,double,Full> t1f3(99.9), t1f4(99.9), t1f5(99.9), t1f6(99.9), 
    t1f7(99.9);

  t1f3 = t1f1 + t1f2;
  tester.out() << "t1f3 = t1f1 + t1f2: " << t1f3 << std::endl;
  tester.check("t1f3", t1f3, Tensor<1,double,Full>(0.0));

  t1f4 = t1s1 + t1s2;
  tester.out() << "t1f4 = t1s1 + t1s2: " << t1f4 << std::endl;
  tester.check("t1f4", (t1f4 == t1s3));

  t1f5 = t1f1 + t1s2;
  tester.out() << "t1f5 = t1f1 + t1s2: " << t1f5 << std::endl;
  tester.check("t1f5", t1f5, t1f1 + t1s2AsFull);

  t1f6 = t1s2 + t1f1;
  tester.out() << "t1f6 = t1s2 + t1f1: " << t1f6 << std::endl;
  tester.check("t1f6", t1f6, t1f1 + t1s2AsFull);

  t1f6 -= t1f1;
  tester.out() << "t1f6 -= t1f1: " << t1f6 << std::endl;
  tester.check("t1f6", t1f6, t1s2AsFull);

  t1s4 = t1s3 - t1f1;
  tester.out() << "t1s4 = t1s3 - t1f1: " << t1s4 << std::endl;
  tester.check("t1s4", 
               (t1s4 == Tensor<1,double,Symmetric>(-1)));


  // Test Tensor dot Tensor:

  // Full:
  sum = 0.0;
  t1f3 = dot(t1f1, t1f2);
  for (i = 0; i < 1; ++i) {
    for (j = 0; j < 1; ++j) {
      for (k = 0; k < 1; ++k) {
        t1f3(i,k) -= t1f1(i,j)*t1f2(j,k);
      }
    }
  }
  t1f3 = t1f3*t1f3;
  for (i = 0; i < 1; ++i) {
    for (j = 0; j < 1; ++j) {
      sum += t1f3(i,j);
    }
  }
  tester.check("dot(t1f1, t1f2)", (sum == 0));
  
  // Symmetric:
  sum = 0.0;
  t1f3 = dot(t1s1, t1s2);
  for (i = 0; i < 1; ++i) {
    for (j = 0; j < 1; ++j) {
      for (k = 0; k < 1; ++k) {
        t1f3(i,k) -= t1s1(i,j)*t1s2(j,k);
      }
    }
  }
  t1f3 = t1f3*t1f3;
  for (i = 0; i < 1; ++i) {
    for (j = 0; j < 1; ++j) {
      sum += t1f3(i,j);
    }
  }
  tester.check("dot(t1s1, t1s2)", (sum == 0));

  // Test Tensor dot Vector, and vice-versa:

  // Full:
  // Vector dot Tensor
  Vector<1> v11(1.0);
  tester.out() << "v11: " << v11 << std::endl;
  Vector<1> v12(9.0);
  v12 = dot(v11, t1f2);
  tester.out() << "v12 = dot(v11, t1f2): " << v12 << std::endl;
  for (i = 0; i < 1; ++i) {
    for (j = 0; j < 1; ++j) {
      v12(j) -= v11(i)*t1f2(i,j);
    }
  }
  v12 = v12*v12;
  sum = 0.0;
  for (i = 0; i < 1; ++i) {
    sum += v12(i);
  }
  tester.check("dot(v11, t1f2)", (sum == 0));
  // Tensor dot Vector
  v12 = dot(t1f2, v11);
  tester.out() << "v12 = dot(t1f2, v11): " << v12 << std::endl;
  for (i = 0; i < 1; ++i) {
    for (j = 0; j < 1; ++j) {
      v12(i) -= t1f2(i,j)*v11(j);
    }
  }
  v12 = v12*v12;
  sum = 0.0;
  for (i = 0; i < 1; ++i) {
    sum += v12(i);
  }
  tester.check("dot(t1f2, v11)", (sum == 0));
  
  // Symmetric:
  // Vector dot Tensor
  v12 = dot(v11, t1s2);
  tester.out() << "v12 = dot(v11, t1s2): " << v12 << std::endl;
  for (i = 0; i < 1; ++i) {
    for (j = 0; j < 1; ++j) {
      v12(j) -= v11(i)*t1s2(i,j);
    }
  }
  v12 = v12*v12;
  sum = 0.0;
  for (i = 0; i < 1; ++i) {
    sum += v12(i);
  }
  tester.check("dot(v11, t1s2)", (sum == 0));
  // Tensor dot Vector
  v12 = dot(t1s2, v11);
  tester.out() << "v12 = dot(t1s2, v11): " << v12 << std::endl;
  for (i = 0; i < 1; ++i) {
    for (j = 0; j < 1; ++j) {
      v12(i) -= t1s2(i,j)*v11(j);
    }
  }
  v12 = v12*v12;
  sum = 0.0;
  for (i = 0; i < 1; ++i) {
    sum += v12(i);
  }
  tester.check("dot(t1s2, v11)", (sum == 0));


  int ret = tester.results("TestSymmetricTensors");
  Pooma::finalize();
  return ret;
}
void test(const Cont &)
{
  // Testing if all types are provided.

  typename Cont::value_type              t0;
  typename Cont::reference               t1 = t0;      CGAL_USE(t1);
  typename Cont::const_reference         t2 = t0;      CGAL_USE(t2);
  typename Cont::pointer                 t3 = &t0;
  typename Cont::const_pointer           t4 = &t0;     CGAL_USE(t4);
  typename Cont::size_type               t5 = 0;       CGAL_USE(t5);
  typename Cont::difference_type         t6 = t3-t3;   CGAL_USE(t6);
  typename Cont::iterator                t7;           CGAL_USE(t7);
  typename Cont::const_iterator          t8;           CGAL_USE(t8);
  typename Cont::reverse_iterator        t9;           CGAL_USE(t9);
  typename Cont::const_reverse_iterator  t10;          CGAL_USE(t10);
  typename Cont::allocator_type          t15;

  std::cout << "Testing empty containers." << std::endl;

  Cont c0, c1;
  Cont c2(t15);
  Cont c3(c2);
  Cont c4;
  c4 = c2;

  typedef std::vector<typename Cont::value_type> Vect;
  Vect v0;
  const Cont c5(v0.begin(), v0.end());
  Cont c6(c5.begin(), c5.end());
  typename Cont::allocator_type Al;
  Cont c7(c0.begin(), c0.end(), Al);
  Cont c8;
  c8.insert(c0.rbegin(), c0.rend());

  // test conversion iterator-> const_iterator.
  typename Cont::const_iterator t16 = c5.begin();  CGAL_USE(t16);
  assert(t16 == c5.begin());

  assert(c0 == c1);
  assert(! (c0 < c1));

  assert(check_empty(c0));
  assert(check_empty(c1));
  assert(check_empty(c2));
  assert(check_empty(c3));
  assert(check_empty(c4));
  assert(check_empty(c5));
  assert(check_empty(c6));
  assert(check_empty(c7));
  assert(check_empty(c8));

  c1.swap(c0);

  assert(check_empty(c0));
  assert(check_empty(c1));

  c1.merge(c0);

  assert(check_empty(c0));
  assert(check_empty(c1));

  typename Cont::allocator_type  t20 = c0.get_allocator();

  std::cout << "Now filling some containers" << std::endl;

  Vect v1(10000);
  Cont c9(v1.begin(), v1.end());

  assert(c9.size() == v1.size());
  assert(c9.max_size() >= v1.size());
  assert(c9.capacity() >= c9.size());

  Cont c10 = c9;

  assert(c10 == c9);
  assert(c10.size() == v1.size());
  assert(c10.max_size() >= v1.size());
  assert(c10.capacity() >= c10.size());

  c9.clear();

  assert(check_empty(c9));
  assert(c9.capacity() >= c9.size());
  assert(c0 == c9);

  c9.merge(c10);
  c10.swap(c9);

  assert(check_empty(c9));
  assert(c9.capacity() >= c9.size());

  assert(c10.size() == v1.size());
  assert(c10.max_size() >= v1.size());
  assert(c10.capacity() >= c10.size());

  std::cout << "Testing insertion methods" << std::endl;

  c9.assign(c10.begin(), c10.end());

  assert(c9 == c10);

  c10.assign(c9.begin(), c9.end());

  assert(c9 == c10);

  c9.insert(c10.begin(), c10.end());

  assert(c9.size() == 2*v1.size());

  c9.clear();

  assert(c9 != c10);

  c9.insert(c10.begin(), c10.end());

  assert(c9.size() == v1.size());
  assert(c9 == c10);


  typename Cont::iterator it = c9.iterator_to(*c9.begin());
  assert(it == c9.begin());
  typename Cont::const_iterator cit = c9.iterator_to(const_cast<typename Cont::const_reference>(*c9.begin()));
  assert(cit == c9.begin());

  typename Cont::iterator s_it = Cont::s_iterator_to(*c9.begin());
  assert(s_it == c9.begin());
  typename Cont::const_iterator s_cit = Cont::s_iterator_to(const_cast<typename Cont::const_reference>(*c9.begin()));
  assert(s_cit == c9.begin());


  c10 = Cont();

  assert(check_empty(c10));

  for(typename Vect::const_iterator it = v1.begin(); it != v1.end(); ++it)
    c10.insert(*it);

  assert(c10.size() == v1.size());
  assert(c9 == c10);

  c9.erase(c9.begin());
  c9.erase(c9.begin());

  assert(c9.size() == v1.size() - 2);

  // test reserve
  /*Cont c11;
  c11.reserve(v1.size());
  for(typename Vect::const_iterator it = v1.begin(); it != v1.end(); ++it)
    c11.insert(*it);
  
  assert(c11.size() == v1.size());
  assert(c10 == c11);*/

  // owns() and owns_dereferencable().
  for(typename Cont::const_iterator it = c9.begin(), end = c9.end(); it != end; ++it) {
    assert(c9.owns(it));
    assert(c9.owns_dereferencable(it));
    assert(! c10.owns(it));
    assert(! c10.owns_dereferencable(it));
  }
  assert(c9.owns(c9.end()));
  assert(! c9.owns_dereferencable(c9.end()));


  c9.erase(c9.begin(), c9.end());

  assert(check_empty(c9));
  
  std::cout << "Testing parallel insertion" << std::endl;
  {
  Cont c11;
  Vect v11(1000000);
  std::vector<typename Cont::iterator> iterators(v11.size());
  tbb::parallel_for(
    tbb::blocked_range<size_t>( 0, v11.size() ),
    Insert_in_CCC_functor<Vect, Cont>(v11, c11, iterators)
  );
  assert(c11.size() == v11.size());
  
  std::cout << "Testing parallel erasure" << std::endl;
  tbb::parallel_for(
    tbb::blocked_range<size_t>( 0, v11.size() ),
    Erase_in_CCC_functor<Cont>(c11, iterators)
  );
  assert(c11.empty());
  }

  std::cout << "Testing parallel insertion AND erasure" << std::endl;
  {
  Cont c12;
  Vect v12(1000000);
  std::vector<tbb::atomic<bool> > free_elements(v12.size());
  for(typename std::vector<tbb::atomic<bool> >::iterator 
    it = free_elements.begin(), end = free_elements.end(); it != end; ++it) 
  {
    *it = true;
  }
    
  tbb::atomic<unsigned int> num_erasures; 
  num_erasures = 0;
  std::vector<typename Cont::iterator> iterators(v12.size());
  tbb::parallel_for(
    tbb::blocked_range<size_t>( 0, v12.size() ),
    Insert_and_erase_in_CCC_functor<Vect, Cont>(
      v12, c12, iterators, free_elements, num_erasures)
  );
  assert(c12.size() == v12.size() - num_erasures);
  }
}
Ejemplo n.º 8
0
void MainWindow::simpleMesh(TriangleListPtr trianglesFront, TriangleListPtr trianglesBack, struct predgparam3f_s *param, double radius)
{
    int number_of_components = predgparamtype3f_components(param->t);

    for (int c = 0; c < number_of_components; ++c)
    {
        for (double pu = 0; pu < 1 - radius; pu += radius) for (double pv = 0; pv < 1 - radius; pv += radius)
        {
            struct spin3f_s sp00, sp01, sp10, sp11;

            predgparam3f_eval(&sp00, param, pu, pv, c);
            predgparam3f_eval(&sp01, param, pu, pv + radius, c);
            predgparam3f_eval(&sp10, param, pu + radius, pv, c);
            predgparam3f_eval(&sp11, param, pu + radius, pv + radius, c);

            QVector3D v00(sp00.s12 / (1 - sp00.s0), sp00.s23 / (1 - sp00.s0), sp00.s31 / (1 - sp00.s0));
            QVector3D v01(sp01.s12 / (1 - sp01.s0), sp01.s23 / (1 - sp01.s0), sp01.s31 / (1 - sp01.s0));
            QVector3D v10(sp10.s12 / (1 - sp10.s0), sp10.s23 / (1 - sp10.s0), sp10.s31 / (1 - sp10.s0));
            QVector3D v11(sp11.s12 / (1 - sp11.s0), sp11.s23 / (1 - sp11.s0), sp11.s31 / (1 - sp11.s0));

            trianglesFront->push_back(Triangle(v00, v01, v11));
            trianglesFront->push_back(Triangle(v00, v11, v10));

            trianglesBack->push_back(Triangle(v00, v11, v01));
            trianglesBack->push_back(Triangle(v00, v10, v11));
        }

        // last u
        for (double pu = 0; pu < 1 - radius; pu += radius)
        {
            struct spin3f_s sp00, sp01, sp10, sp11;

            predgparam3f_eval(&sp00, param, pu, 1.0 - radius, c);
            predgparam3f_eval(&sp01, param, pu, 1.0, c);
            predgparam3f_eval(&sp10, param, pu + radius, 1.0 - radius, c);
            predgparam3f_eval(&sp11, param, pu + radius, 1.0, c);

            QVector3D v00(sp00.s12 / (1 - sp00.s0), sp00.s23 / (1 - sp00.s0), sp00.s31 / (1 - sp00.s0));
            QVector3D v01(sp01.s12 / (1 - sp01.s0), sp01.s23 / (1 - sp01.s0), sp01.s31 / (1 - sp01.s0));
            QVector3D v10(sp10.s12 / (1 - sp10.s0), sp10.s23 / (1 - sp10.s0), sp10.s31 / (1 - sp10.s0));
            QVector3D v11(sp11.s12 / (1 - sp11.s0), sp11.s23 / (1 - sp11.s0), sp11.s31 / (1 - sp11.s0));

            trianglesFront->push_back(Triangle(v00, v01, v11));
            trianglesFront->push_back(Triangle(v00, v11, v10));

            trianglesBack->push_back(Triangle(v00, v11, v01));
            trianglesBack->push_back(Triangle(v00, v10, v11));
        }

        // last v
        for (double pv = 0; pv < 1 - radius; pv += radius)
        {
            struct spin3f_s sp00, sp01, sp10, sp11;

            predgparam3f_eval(&sp00, param, 1.0 - radius, pv, c);
            predgparam3f_eval(&sp01, param, 1.0 - radius, pv + radius, c);
            predgparam3f_eval(&sp10, param, 1.0, pv, c);
            predgparam3f_eval(&sp11, param, 1.0, pv + radius, c);

            QVector3D v00(sp00.s12 / (1 - sp00.s0), sp00.s23 / (1 - sp00.s0), sp00.s31 / (1 - sp00.s0));
            QVector3D v01(sp01.s12 / (1 - sp01.s0), sp01.s23 / (1 - sp01.s0), sp01.s31 / (1 - sp01.s0));
            QVector3D v10(sp10.s12 / (1 - sp10.s0), sp10.s23 / (1 - sp10.s0), sp10.s31 / (1 - sp10.s0));
            QVector3D v11(sp11.s12 / (1 - sp11.s0), sp11.s23 / (1 - sp11.s0), sp11.s31 / (1 - sp11.s0));

            trianglesFront->push_back(Triangle(v00, v01, v11));
            trianglesFront->push_back(Triangle(v00, v11, v10));

            trianglesBack->push_back(Triangle(v00, v11, v01));
            trianglesBack->push_back(Triangle(v00, v10, v11));
        }

        // last uv
        {
            struct spin3f_s sp00, sp01, sp10, sp11;

            predgparam3f_eval(&sp00, param, 1.0 - radius, 1.0 - radius, c);
            predgparam3f_eval(&sp01, param, 1.0 - radius, 1.0, c);
            predgparam3f_eval(&sp10, param, 1.0, 1.0 - radius, c);
            predgparam3f_eval(&sp11, param, 1.0, 1.0, c);

            QVector3D v00(sp00.s12 / (1 - sp00.s0), sp00.s23 / (1 - sp00.s0), sp00.s31 / (1 - sp00.s0));
            QVector3D v01(sp01.s12 / (1 - sp01.s0), sp01.s23 / (1 - sp01.s0), sp01.s31 / (1 - sp01.s0));
            QVector3D v10(sp10.s12 / (1 - sp10.s0), sp10.s23 / (1 - sp10.s0), sp10.s31 / (1 - sp10.s0));
            QVector3D v11(sp11.s12 / (1 - sp11.s0), sp11.s23 / (1 - sp11.s0), sp11.s31 / (1 - sp11.s0));

            trianglesFront->push_back(Triangle(v00, v01, v11));
            trianglesFront->push_back(Triangle(v00, v11, v10));

            trianglesBack->push_back(Triangle(v00, v11, v01));
            trianglesBack->push_back(Triangle(v00, v10, v11));
        }
    }
}
Ejemplo n.º 9
0
static void VbTest()
{
#if !defined (ACE_WIN32)

  Vb v1;
  ACE_ASSERT(v1.valid() == 0);
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) VarBinad:v1(\"/\") [%s]\n",
    v1.to_string()));

  // purpose of this routine??
  set_exception_status( &v1, 10);

  Vb v2(v1);
  ACE_ASSERT(v2.valid() == 0);
  Oid o1("1.2.3"), o2;
  v2.set_oid(o1);
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) VarBinad:v2(\"1.2.3/\") [%s]\n",
    v2.to_string()));

  v2.get_oid(o2);
  ACE_ASSERT(o2 == o1);
  ACE_ASSERT(v2.valid() == 0);
  v2.set_null();
  ACE_ASSERT(v2.valid() == 0);
  v2.get_oid(o2);

  Vb v3;
  TimeTicks t(0), t1;
  v3.set_oid(o1);
  v3.set_value(t);
  ACE_ASSERT(v3.valid() == 1);
  v3.get_value(t1);
  ACE_ASSERT(t == t1);

  Vb v4;
  v4.set_oid(o1);
  v4.set_value(o1);
  ACE_ASSERT(v4.valid() == 1);
  v4.get_value(o2);
  ACE_ASSERT(o1 == o2);

  Vb v5;
  Counter32 c1(12), c2;
  v5.set_oid(o1);
  v5.set_value(c1);
  ACE_ASSERT(v5.valid() == 1);
  v5.get_value(c2);
  ACE_ASSERT(c1 == c2);

  Vb v6;
  Counter64 c3(12345678901234ULL), c4;
  v6.set_oid(o1);
  v6.set_value(c3);
  ACE_ASSERT(v6.valid() == 1);
  v6.get_value(c4);
  ACE_ASSERT(c3 == c4);

  Vb v7;
  Gauge32 g1(0123456), g2;
  v7.set_oid(o1);
  v7.set_value(g1);
  ACE_ASSERT(v7.valid() == 1);
  v7.get_value(g2);
  ACE_ASSERT(g1 == g2);

  Vb v8;
  SnmpInt32 i1(0123456), i2;
  v8.set_oid(o1);
  v8.set_value(i1);
  ACE_ASSERT(v8.valid() == 1);
  v8.get_value(i2);
  ACE_ASSERT(i1 == i2);

  Vb v9;
  SnmpUInt32 u1(0123456), u2;
  v9.set_oid(o1);
  v9.set_value(u1);
  ACE_ASSERT(v9.valid() == 1);
  v9.get_value(u2);
  ACE_ASSERT(u1 == u2);

  Vb v10;
  OctetStr s1(" abcdefghighlmnopqrstuvwxyz!@#$%^&*()"), s2;
  v10.set_oid(o1);
  v10.set_value(s1);
  ACE_ASSERT(v10.valid() == 1);
  v10.get_value(s2);
  ACE_ASSERT(s1 == s2);
  ACE_ASSERT(s1.length() == s2.length());

  // test assignment over all datatypes
  v10 = v5;
  ACE_ASSERT(v10 == v5);


  Vb v11(o1, s1, SNMP_CLASS_SUCCESS);
  ACE_ASSERT(v11.valid() == 1);
  v11.get_oid(o2);
  ACE_ASSERT(o1 == o2);
  v11.get_value(s2);
  ACE_ASSERT(s1 == s2);
#endif /*if ACE_WIN32*/
}
Ejemplo n.º 10
0
void CIcosahedron::init( float s  ){

	this->clearMesh();
	float p = ((1.0 + sqrt(5.0))/2.0)*s;

	TVector3 v0(s,0.0,p);
	this->iVertices.push_back(v0);
	TVector3 v1(-s,0.0,p);
	this->iVertices.push_back(v1);
	TVector3 v2(s,0.0,-p);
	this->iVertices.push_back(v2);
	TVector3 v3(-s,0.0,-p);
	this->iVertices.push_back(v3);
	TVector3 v4(0.0,p,s);
	this->iVertices.push_back(v4);
	TVector3 v5(0,-p,s);
	this->iVertices.push_back(v5);
	TVector3 v6(0,p,-s);
	this->iVertices.push_back(v6);
	TVector3 v7(0.0,-p,-s);
	this->iVertices.push_back(v7);
	TVector3 v8(p,s,0.0);
	this->iVertices.push_back(v8);
	TVector3 v9(-p,s,0.0);
	this->iVertices.push_back(v9);
	TVector3 v10(p,-s,0.0);
	this->iVertices.push_back(v10);
	TVector3 v11(-p,-s,0.0);
	this->iVertices.push_back(v11);


	TTriangle t0(0,4,1);
	this->iTriangles.push_back(t0);

	TTriangle t1(0,1,5);
	this->iTriangles.push_back(t1);

	TTriangle t2(0,5,10);
	this->iTriangles.push_back(t2);

	TTriangle t3(0,10,8);
	this->iTriangles.push_back(t3);

	TTriangle t4(0,8,4);
	this->iTriangles.push_back(t4);

	TTriangle t5(4,8,6);
	this->iTriangles.push_back(t5);

	TTriangle t6(4,6,9);
	this->iTriangles.push_back(t6);

	TTriangle t7(4,9,1);
	this->iTriangles.push_back(t7);

	TTriangle t8(1,9,11);
	this->iTriangles.push_back(t8);

	TTriangle t9(1,11,5);
	this->iTriangles.push_back(t9);

	TTriangle t10(2,7,3);
	this->iTriangles.push_back(t10);

	TTriangle t11(2,3,6);
	this->iTriangles.push_back(t11);

	TTriangle t12(2,6,8);
	this->iTriangles.push_back(t12);

	TTriangle t13(2,8,10);
	this->iTriangles.push_back(t13);

	TTriangle t14(2,10,7);
	this->iTriangles.push_back(t14);

	TTriangle t15(7,10,5);
	this->iTriangles.push_back(t15);

	TTriangle t16(7,5,11);
	this->iTriangles.push_back(t16);

	TTriangle t17(7,11,3);
	this->iTriangles.push_back(t17);

	TTriangle t18(3,11,9);
	this->iTriangles.push_back(t18);

	TTriangle t19(3,9,6);
	this->iTriangles.push_back(t19);
	}
Ejemplo n.º 11
0
void Hud::Draw (Zeni::Time::Second_Type elapsedTime)
{
	HeroComponent & hero = HeroComponent::GetInstance();

	double heroHealth = hero.GetHealth();
	double heroShields = hero.GetShields();
	double healthWidth = 200.0f;
	double healthHeight = 30.0f;

	Zeni::Point2f bgPosition1 (590.0f, 40.0f);
	Zeni::Point2f bgPosition2 (bgPosition1.x, bgPosition1.y + healthHeight);
	Zeni::Point2f bgPosition3 (bgPosition1.x + healthWidth, bgPosition1.y + healthHeight);
	Zeni::Point2f bgPosition4 (bgPosition1.x + healthWidth, bgPosition1.y);

	Zeni::Point2f healthPosition1 = bgPosition1;
	Zeni::Point2f healthPosition2 = bgPosition2;
	Zeni::Point2f healthPosition3 (bgPosition1.x + healthWidth * heroHealth / 1000.0f, bgPosition1.y + healthHeight);
	Zeni::Point2f healthPosition4 (bgPosition1.x + healthWidth * heroHealth / 1000.0f, bgPosition1.y);

	Zeni::Point2f shieldPosition1 = bgPosition1;
	Zeni::Point2f shieldPosition2 = bgPosition2;
	Zeni::Point2f shieldPosition3 (bgPosition1.x + healthWidth * heroShields / 100.0f, bgPosition1.y + healthHeight);
	Zeni::Point2f shieldPosition4 (bgPosition1.x + healthWidth * heroShields / 100.0f, bgPosition1.y);

	int score = hero.GetScore();

	std::stringstream ss4;
	ss4 << score;
	Zeni::get_Fonts()["score"].render_text (ss4.str(), Zeni::Point2f (20.0f, 550.0f), Zeni::get_Colors()["score"]);

	++frameCount;

	std::stringstream ss ("FPS: ");
	ss << fps;

	//Zeni::get_Fonts()["fps"].render_text (ss.str(), Zeni::Point2f(), Zeni::get_Colors()["fps"]);

	const std::vector<ProjectileFactory*>& heroWeapons = hero.GetWeapons();

	size_t numWeapons = heroWeapons.size();
	int selectedWeapon = hero.GetSelectedWeaponIndex();

	double corner = 800.0f - 30.0f * numWeapons;

	Zeni::Color enabled = Zeni::get_Colors()["weapon_enabled"];
	Zeni::Color disabled = Zeni::get_Colors()["weapon_disabled"];

	for (int i = 0; i < numWeapons; ++i)
	{
		Zeni::Vertex2f_Texture vertex1 (Zeni::Point2f(corner + 30.0f * i, 0.0f), Zeni::Point2f(0.0f, 0.0f));
		Zeni::Vertex2f_Texture vertex2 (Zeni::Point2f(corner + 30.0f * i, 30.0f), Zeni::Point2f(0.0f, 1.0f));
		Zeni::Vertex2f_Texture vertex3 (Zeni::Point2f(corner + 30.0f * (i + 1), 30.0f), Zeni::Point2f(1.0f, 1.0f));
		Zeni::Vertex2f_Texture vertex4 (Zeni::Point2f(corner + 30.0f * (i + 1), 0.0f), Zeni::Point2f(1.0f, 0.0f));
		Zeni::Quadrilateral<Zeni::Vertex2f_Texture> q (vertex1, vertex2, vertex3, vertex4);

		Zeni::Material backing(i == selectedWeapon ? "selected_weapon" : "weapon");

		q.lend_Material (&backing);

		Zeni::get_Video().render (q);
		
		double r = selectedWeapon == i ? weaponRotation : 0.0f;
		Zeni::render_image (
			heroWeapons[i]->GetTexture(),
			Zeni::Point2f(corner + 30 * i + 5.0f, 5.0f),
			Zeni::Point2f(corner + 30 * (i + 1.0f) - 5.0f, 25.0),
			r,
			1.0f,
			Zeni::Point2f(corner + 30 * i + 15.0f, 15.0f),
			false,
			heroWeapons[i]->IsReady() ? enabled : disabled);
	}

	int heroAmmo = heroWeapons[selectedWeapon]->GetAmmo();

	std::stringstream ss3;
	ss3 << heroAmmo;
	Zeni::get_Fonts()["ammo"].render_text (ss3.str(), Zeni::Point2f(corner - 5.0f, 0.0f), Zeni::get_Colors()["ammo"], Zeni::ZENI_RIGHT);

	Zeni::Vertex2f_Texture v9 (bgPosition1, Zeni::Point2f (0.0f, 0.0f));
	Zeni::Vertex2f_Texture v10 (bgPosition2, Zeni::Point2f (0.0f, 1.0f));
	Zeni::Vertex2f_Texture v11 (bgPosition3, Zeni::Point2f (1.0f, 1.0f));
	Zeni::Vertex2f_Texture v12 (bgPosition4, Zeni::Point2f (1.0f, 0.0f));

	Zeni::Quadrilateral<Zeni::Vertex2f_Texture> q3 (v9, v10, v11, v12);

	Zeni::Material healthbar1("healthbar1");

	q3.lend_Material (&healthbar1);

	Zeni::get_Video().render (q3);

	Zeni::Vertex2f_Texture v13 (healthPosition1, Zeni::Point2f (0.0f, 0.0f));
	Zeni::Vertex2f_Texture v14 (healthPosition2, Zeni::Point2f (0.0f, 1.0f));
	Zeni::Vertex2f_Texture v15 (healthPosition3, Zeni::Point2f (heroHealth / 1000.0f, 1.0f));
	Zeni::Vertex2f_Texture v16 (healthPosition4, Zeni::Point2f (heroHealth / 1000.0f, 0.0f));

	Zeni::Quadrilateral<Zeni::Vertex2f_Texture> q4 (v13, v14, v15, v16);

	Zeni::Material healthbar2("healthbar2");

	q4.lend_Material (&healthbar2);

	Zeni::get_Video().render (q4);

	Zeni::Vertex2f_Texture v17 (shieldPosition1, Zeni::Point2f (0.0f, 0.0f));
	Zeni::Vertex2f_Texture v18 (shieldPosition2, Zeni::Point2f (0.0f, 1.0f));
	Zeni::Vertex2f_Texture v19 (shieldPosition3, Zeni::Point2f (heroShields / 100.0f, 1.0f));
	Zeni::Vertex2f_Texture v20 (shieldPosition4, Zeni::Point2f (heroShields / 100.0f, 0.0f));

	Zeni::Quadrilateral<Zeni::Vertex2f_Texture> q5 (v17, v18, v19, v20);

	Zeni::Material healthbar3("healthbar3");

	q5.lend_Material (&healthbar3);

	Zeni::get_Video().render (q5);

	double timeRemaining = GameTimer::GetInstance().GetRemainingTime();

	Zeni::Color timerTextColor = timeRemaining < 10.0f ? Zeni::get_Colors()["low_time"] : Zeni::get_Colors()["time"];

	Zeni::render_image (
		"Timer",
		Zeni::Point2f (620.0f, 540.0f),
		Zeni::Point2f (670.0f, 590.0f),
		false,
		timerTextColor);

	std::stringstream ss2;
	int minutes = (int)timeRemaining / 60;
	ss2 << minutes << ":" << std::fixed << std::setprecision(2) << timeRemaining - minutes * 60;
	Zeni::get_Fonts()["time"].render_text (ss2.str(), Zeni::Point2f(680.0f, 550.0f), timerTextColor);
}
Ejemplo n.º 12
0
osg::Drawable *ReverseTileNode::createReverseTile(void) const {
    // Get the tile
    ReverseTile* tile = static_cast<ReverseTile*>(_lego);

    // Get tile color
    QColor color = tile->getColor();

    // Get integer sizes
    int width = tile->getWidth();
    int length = tile->getLength();
    int height = 3;

    // Get real position, according to tile size
    double mw = (-width)*Lego::length_unit/2;
    double pw = (width)*Lego::length_unit/2;
    double mwp = (-width+2)*Lego::length_unit/2;
    double ml = (-length)*Lego::length_unit/2;
    double pl = (length)*Lego::length_unit/2;
    double mh = (-height)*Lego::height_unit/2;
    double ph = (height)*Lego::height_unit/2;
    double phm = (height-1)*Lego::height_unit/2;

    // Create 14 vertices
    osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
    osg::Vec3 v0(mw, ml, mh);
    osg::Vec3 v1(mw, pl, mh);
    osg::Vec3 v2(mwp, pl, mh);
    osg::Vec3 v3(mwp, ml, mh);
    osg::Vec3 v4(pw, ml, phm);
    osg::Vec3 v5(pw, pl, phm);
    osg::Vec3 v6(pw, pl, ph);
    osg::Vec3 v7(pw, ml, ph);
    osg::Vec3 v8(mw, ml, ph);
    osg::Vec3 v9(mw, pl, ph);
    osg::Vec3 v10(mwp, ml, phm);
    osg::Vec3 v11(mwp, ml, ph);
    osg::Vec3 v12(mwp, pl, ph);
    osg::Vec3 v13(mwp, pl, phm);

    // Create 10 faces, 8 faces are quads splitted into two triangles
    // NB: Down face is transparent, we don't even create it

    // Front face t1
    vertices->push_back(v4);
    vertices->push_back(v5);
    vertices->push_back(v6);
    // Front face t2
    vertices->push_back(v4);
    vertices->push_back(v6);
    vertices->push_back(v7);

    // Back face t1
    vertices->push_back(v0);
    vertices->push_back(v1);
    vertices->push_back(v8);
    // Back face t2
    vertices->push_back(v1);
    vertices->push_back(v8);
    vertices->push_back(v9);

    // Top face t1
    vertices->push_back(v6);
    vertices->push_back(v7);
    vertices->push_back(v9);
    // Top face t2
    vertices->push_back(v7);
    vertices->push_back(v8);
    vertices->push_back(v9);

    // Slop face t1
    vertices->push_back(v2);
    vertices->push_back(v3);
    vertices->push_back(v5);
    // Slop face t2
    vertices->push_back(v3);
    vertices->push_back(v4);
    vertices->push_back(v5);

    // Right triangle face
    vertices->push_back(v2);
    vertices->push_back(v13);
    vertices->push_back(v5);

    // Right quad face t1
    vertices->push_back(v13);
    vertices->push_back(v12);
    vertices->push_back(v6);
    // Right quad face t2
    vertices->push_back(v13);
    vertices->push_back(v6);
    vertices->push_back(v5);

    // Right quad face down t1
    vertices->push_back(v1);
    vertices->push_back(v9);
    vertices->push_back(v12);
    // Right quad face down t2
    vertices->push_back(v1);
    vertices->push_back(v2);
    vertices->push_back(v12);

    // Left triangle face
    vertices->push_back(v3);
    vertices->push_back(v4);
    vertices->push_back(v10);

    // Left quad face t1
    vertices->push_back(v4);
    vertices->push_back(v10);
    vertices->push_back(v11);
    // Left quad face t2
    vertices->push_back(v4);
    vertices->push_back(v7);
    vertices->push_back(v11);

    // Left quad face down t1
    vertices->push_back(v0);
    vertices->push_back(v3);
    vertices->push_back(v8);
    // Left quad face down t2
    vertices->push_back(v3);
    vertices->push_back(v8);
    vertices->push_back(v11);

    // Create tile geometry
    osg::ref_ptr<osg::Geometry> tileGeometry = new osg::Geometry;

    // Match vertices
    tileGeometry->setVertexArray(vertices);

    // Add color (each rectangle has the same color except for the down one which is transparent)
    osg::Vec4 osgColor(static_cast<float>(color.red())/255.0, static_cast<float>(color.green())/255.0, static_cast<float>(color.blue())/255.0, 1.0);
    osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
    // Every face has the same color, so there is only one color
    colors->push_back(osgColor);

    // Match color
    tileGeometry->setColorArray(colors);
    tileGeometry->setColorBinding(osg::Geometry::BIND_OVERALL);

    // Create normals
    osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(0, 0, 1));
    normals->push_back(osg::Vec3(0, 0, 1));
    double w = pw - mwp;
    double h = phm - mh;
    double norm = std::sqrt(w*w + h*h);
    normals->push_back(osg::Vec3(h/norm, 0, -w/norm));
    normals->push_back(osg::Vec3(h/norm, 0, -w/norm));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));

    // Match normals
    tileGeometry->setNormalArray(normals);
    tileGeometry->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);

    // Define tile 18 GL_TRIANGLES with 20*3 vertices
    tileGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLES, 0, 18*3));

    // Return the tile whithout plot
    return tileGeometry.release();
}
Ejemplo n.º 13
0
osg::Drawable *ClampNode::createBrick(void) const {
    // Get the brick
    Clamp* clamp = static_cast<Clamp*>(_lego);
    
    // Get brick color
    QColor color = clamp->getColor();

    // Get clamp bounding box
    clamp->calculateBoundingBox();
    BoundingBox bb = clamp->getBoundingBox();
    // Get integer sizes
    int width = bb.getWidth();
    int length = bb.getLength();
    int height = bb.getHeight();

    // Get real position, according to tile size
    double mw = (-width)*Lego::length_unit/2;
    double mwpm = (-width)*Lego::length_unit/2+Lego::height_unit/2;
    double mwp = (-width)*Lego::length_unit/2+0.93*Lego::height_unit;
    double pw = (width)*Lego::length_unit/2;
    double pwm = (width)*Lego::length_unit/2-Lego::height_unit/2;
    double ml = (-length)*Lego::length_unit/2;
    double mlp = (-length+0.5)*Lego::length_unit/2;
    double pl = (length)*Lego::length_unit/2;
    double plm = (length-0.5)*Lego::length_unit/2;
    double mh = (-height)*Lego::height_unit/2;
    double mhp = (-height)*Lego::height_unit/2+2*Lego::plot_top_height;
    double mhpm = (-height)*Lego::height_unit/2+Lego::plot_top_height;
    double phm = (height)*Lego::height_unit/2-Lego::height_unit/2;
    double phmp = (height)*Lego::height_unit/2-0.5*Lego::height_unit/2;
    
    // Create 3 vertices
    osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
    osg::Vec3 v0(ml, mw, mh);
    osg::Vec3 v1(pl, mw, mh);
    osg::Vec3 v2(pl, pw, mh);
    osg::Vec3 v3(ml, pw, mh);
    osg::Vec3 v4(ml, pw, mhp);
    osg::Vec3 v5(pl, pw, mhp);
    osg::Vec3 v6(pl, mw, mhp);
    osg::Vec3 v7(ml, mw, mhp);
    osg::Vec3 v8(mlp, mw, mhp);
    osg::Vec3 v9(mlp, mw, phm);
    osg::Vec3 v10(ml, mw, phm);
    osg::Vec3 v11(ml, mwp, phmp);
    osg::Vec3 v12(mlp, mwp, phmp);
    osg::Vec3 v13(mlp, pw, mhp);
    osg::Vec3 v14(plm, mw, mhp);
    osg::Vec3 v15(plm, mw, phm);
    osg::Vec3 v16(pl, mw, phm);
    osg::Vec3 v17(pl, mwp, phmp);
    osg::Vec3 v18(plm, mwp, phmp);
    osg::Vec3 v19(plm, pw, mhp);
    osg::Vec3 v20(mlp, mwpm, mh);
    osg::Vec3 v21(plm, mwpm, mh);
    osg::Vec3 v22(plm, pwm, mh);
    osg::Vec3 v23(mlp, pwm, mh);
    osg::Vec3 v24(mlp, mwpm, mhpm);
    osg::Vec3 v25(plm, mwpm, mhpm);
    osg::Vec3 v26(plm, pwm, mhpm);
    osg::Vec3 v27(mlp, pwm, mhpm);
    
    // Create 1 faces, 0 faces are quads splitted into two triangles
    // NB: Down face is transparent, we don't even create it

    // Bottom
    vertices->push_back(v3);
    vertices->push_back(v2);
    vertices->push_back(v1);
    vertices->push_back(v0);
    // Bottom hole
    vertices->push_back(v20);
    vertices->push_back(v21);
    vertices->push_back(v22);
    vertices->push_back(v23);
    // Bottom far
    vertices->push_back(v24);
    vertices->push_back(v25);
    vertices->push_back(v26);
    vertices->push_back(v27);

    // Front face
    vertices->push_back(v2);
    vertices->push_back(v3);
    vertices->push_back(v4);
    vertices->push_back(v5);

    // Back face
    vertices->push_back(v0);
    vertices->push_back(v1);
    vertices->push_back(v6);
    vertices->push_back(v7);

    // Left bottom face
    vertices->push_back(v0);
    vertices->push_back(v3);
    vertices->push_back(v4);
    vertices->push_back(v7);

    // Right bottom face
    vertices->push_back(v1);
    vertices->push_back(v2);
    vertices->push_back(v5);
    vertices->push_back(v6);

    // Top face
    vertices->push_back(v4);
    vertices->push_back(v5);
    vertices->push_back(v6);
    vertices->push_back(v7);

    // Left part back
    vertices->push_back(v7);
    vertices->push_back(v8);
    vertices->push_back(v9);
    vertices->push_back(v10);

    // Left part left ext
    vertices->push_back(v4);
    vertices->push_back(v7);
    vertices->push_back(v10);
    vertices->push_back(v11);

    // Left part front
    vertices->push_back(v4);
    vertices->push_back(v11);
    vertices->push_back(v12);
    vertices->push_back(v13);

    // Left part left int
    vertices->push_back(v8);
    vertices->push_back(v9);
    vertices->push_back(v12);
    vertices->push_back(v13);

    // Right part back
    vertices->push_back(v6);
    vertices->push_back(v14);
    vertices->push_back(v15);
    vertices->push_back(v16);

    // Left part left ext
    vertices->push_back(v5);
    vertices->push_back(v6);
    vertices->push_back(v16);
    vertices->push_back(v17);

    // Left part front
    vertices->push_back(v5);
    vertices->push_back(v17);
    vertices->push_back(v18);
    vertices->push_back(v19);

    // Left part left int
    vertices->push_back(v14);
    vertices->push_back(v15);
    vertices->push_back(v18);
    vertices->push_back(v19);

    // Bottom front
    vertices->push_back(v20);
    vertices->push_back(v21);
    vertices->push_back(v25);
    vertices->push_back(v24);

    // Bottom right
    vertices->push_back(v21);
    vertices->push_back(v22);
    vertices->push_back(v26);
    vertices->push_back(v25);

    // Bottom back
    vertices->push_back(v22);
    vertices->push_back(v23);
    vertices->push_back(v27);
    vertices->push_back(v26);

    // Bottom left
    vertices->push_back(v23);
    vertices->push_back(v20);
    vertices->push_back(v24);
    vertices->push_back(v27);

    // Create tile geometry
    osg::ref_ptr<osg::Geometry> clampGeometry = new osg::Geometry;
    
    // Match vertices
    clampGeometry->setVertexArray(vertices);
    
    // Create colors
    osg::Vec4 osgColor(static_cast<float>(color.red())/255.0, static_cast<float>(color.green())/255.0, static_cast<float>(color.blue())/255.0, 1.0);
    osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
    // Every face has the same color, so there is only one color
    colors->push_back(osgColor);
    
    // Match color
    clampGeometry->setColorArray(colors);
    clampGeometry->setColorBinding(osg::Geometry::BIND_OVERALL);
    
    // Create normals
    osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
    normals->push_back(osg::Vec3(0, 0, -1));
    normals->push_back(osg::Vec3(0, 0, -1));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(0, 0, 1));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    double w = pw - mwp;
    double h = phmp - mhp;
    double norm = std::sqrt(w*w + h*h);
    normals->push_back(osg::Vec3(0, h/norm, w/norm));
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(1, 0, 0));
    normals->push_back(osg::Vec3(0, h/norm, w/norm));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(0, 1, 0));
    normals->push_back(osg::Vec3(-1, 0, 0));
    normals->push_back(osg::Vec3(0, -1, 0));
    normals->push_back(osg::Vec3(1, 0, 0));
    
    // Match normals
    clampGeometry->setNormalArray(normals);
    clampGeometry->setNormalBinding(osg::Geometry::BIND_PER_PRIMITIVE);

    // Define 1 GL_QUADS with 1*4 vertices, corresponding to bottom part
    clampGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0*4, 4));

    // Define 1 GL_QUADS with 1*4 vertices, corresponding to 1 hole in bottom part
    clampGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 1*4, 4));

    // Retesslate to create hole
    osgUtil::Tessellator tesslator;
    tesslator.setTessellationType(osgUtil::Tessellator::TESS_TYPE_GEOMETRY);
    tesslator.setWindingType(osgUtil::Tessellator::TESS_WINDING_ODD);
    tesslator.retessellatePolygons(*clampGeometry);

    // Create 17 GL_QUADS, i.e. 18*4 vertices
    clampGeometry->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 2*4, 18*4));

    // Return the tile whithout plot
    return clampGeometry.release();
}