Ejemplo n.º 1
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.º 2
0
double ComputeCylinderRadius (const Point3d & p1, 
			      const Point3d & p2,
			      const Point3d & p3, 
			      const Point3d & p4)
{
  Vec3d v12(p1, p2);
  Vec3d v13(p1, p3);
  Vec3d v14(p1, p4);

  Vec3d n1 = Cross (v12, v13);
  Vec3d n2 = Cross (v14, v12);
		
  double n1l = n1.Length();
  double n2l = n2.Length();
  n1 /= n1l;
  n2 /= n2l;

  double v12len = v12.Length();
  double h1 = n1l / v12len;
  double h2 = n2l / v12len;
  
  /*
  (*testout) << "n1 = " << n1 << " n2 = " << n2 
	     << "h1 = " << h1 << " h2 = " << h2 << endl;
  */
  return ComputeCylinderRadius (n1, n2, h1, h2);
}
Ejemplo n.º 3
0
bool plTriUtils::IFastBarycentric(int iAx, const hsPoint3& p0, const hsPoint3& p1, const hsPoint3& p2, const hsPoint3&p, hsPoint3& out)
{
    if( --iAx < 0 )
        iAx = 2;
    int jAx = iAx - 1;
    if( jAx < 0 )
        jAx = 2;

    hsVector3 v02(&p0, &p2);
    hsVector3 v12(&p1, &p2);

    float totArea = v02[iAx] * v12[jAx] - v02[jAx] * v12[iAx];
    hsAssert(totArea != 0, "Should have already filtered degerate tris and degenerate projection");
    
    float invTotArea = 1.f / totArea;

    hsVector3 vp2(&p, &p2);

    float aArea = vp2[iAx] * v12[jAx] - vp2[jAx] * v12[iAx];

    float bArea = v02[iAx] * vp2[jAx] - v02[jAx] * vp2[iAx];

    out[0] = aArea * invTotArea;
    out[1] = bArea * invTotArea;
    out[2] = 1.f - out[0] - out[1];

    return true;
}
Ejemplo n.º 4
0
double  MQuadrangle::etaShapeMeasure()
{
  double AR = 1;//(minEdge()/maxEdge());

  SVector3 v01 (_v[1]->x()-_v[0]->x(),_v[1]->y()-_v[0]->y(),_v[1]->z()-_v[0]->z());
  SVector3 v12 (_v[2]->x()-_v[1]->x(),_v[2]->y()-_v[1]->y(),_v[2]->z()-_v[1]->z());
  SVector3 v23 (_v[3]->x()-_v[2]->x(),_v[3]->y()-_v[2]->y(),_v[3]->z()-_v[2]->z());
  SVector3 v30 (_v[0]->x()-_v[3]->x(),_v[0]->y()-_v[3]->y(),_v[0]->z()-_v[3]->z());

  SVector3 a = crossprod(v01,v12);
  SVector3 b = crossprod(v12,v23);
  SVector3 c = crossprod(v23,v30);
  SVector3 d = crossprod(v30,v01);

  double sign = 1.0;
  if (dot(a,b) < 0 || dot(a,c) < 0 || dot(a,d) < 0 )sign = -1;
  // FIXME ...
  //  if (a.z() > 0 || b.z() > 0 || c.z() > 0 || d.z() > 0) sign = -1;

  double a1 = 180 * angle3Vertices(_v[0], _v[1], _v[2]) / M_PI;
  double a2 = 180 * angle3Vertices(_v[1], _v[2], _v[3]) / M_PI;
  double a3 = 180 * angle3Vertices(_v[2], _v[3], _v[0]) / M_PI;
  double a4 = 180 * angle3Vertices(_v[3], _v[0], _v[1]) / M_PI;

  a1 = std::min(180.,a1);
  a2 = std::min(180.,a2);
  a3 = std::min(180.,a3);
  a4 = std::min(180.,a4);
  double angle = fabs(90. - a1);
  angle = std::max(fabs(90. - a2),angle);
  angle = std::max(fabs(90. - a3),angle);
  angle = std::max(fabs(90. - a4),angle);

  return sign*(1.-angle/90) * AR;
}
Ejemplo n.º 5
0
void Sphere::sub(int n, Point3 p1, Point3 p2, Point3 p3) {
    Vector3 pv1(p1.x,p1.y,p1.z);
    Vector3 pv2(p2.x,p2.y,p2.z);
    Vector3 pv3(p3.x,p3.y,p3.z);
    if (n == 1) {
        pv1.normalize();
        pv2.normalize();
        pv3.normalize();
		pv1 *= 0.5;
		pv2 *= 0.5;
		pv3 *= 0.5;
        p1.x = pv1.x; p1.y = pv1.y; p1.z = pv1.z;
        p2.x = pv2.x; p2.y = pv2.y; p2.z = pv2.z;
        p3.x = pv3.x; p3.y = pv3.y; p3.z = pv3.z;
        addTriangle(p1,p2,p3);
    } else {
        Vector3 av = pv1+pv2; 
        Vector3 bv = pv2+pv3; 
        Vector3 cv = pv3+pv1; 
    
        av.normalize();
        bv.normalize();
        cv.normalize();

        Point3 v12(av.x,av.y,av.z); 
        Point3 v23(bv.x,bv.y,bv.z); 
        Point3 v31(cv.x,cv.y,cv.z);

        sub(n-1,p1,v12,v31);
        sub(n-1,p2,v23,v12);
        sub(n-1,p3,v31,v23);
        sub(n-1,v12,v23,v31);
    }
}
Ejemplo n.º 6
0
void DragRect::TrackPoints12(const DPoint& pt1, const DPoint& pt2) {
    // width constant, height variable, theta variable
    Vec2d v12(pt1, pt2);
    DPoint pt0 = v12.flip90().unit().scale(v01_.mag()).add(pt1);
    pt0_ = pt0;
    v01_ = Vec2d(pt0, pt1);
    v02_ = Vec2d(pt0, pt2);
}
Ejemplo n.º 7
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.º 8
0
bool plTriUtils::FastBarycentric(const hsPoint3& p0, const hsPoint3& p1, const hsPoint3& p2, const hsPoint3&p, hsPoint3& out)
{
    hsVector3 v02(&p0, &p2);
    hsVector3 v12(&p1, &p2);
    int iAx = ISelectAxis(Cross(v12, v02));
    if( iAx < 0 )
        return false;
    return IFastBarycentric(iAx, p0, p1, p2, p, out);
}
Ejemplo n.º 9
0
bool plTriUtils::ProjectOntoPlaneAlongVector(const hsPoint3& p0, const hsPoint3& p1, const hsPoint3& p2, const hsVector3& vec, hsPoint3& p)
{
    hsVector3 v02(&p0, &p2);
    hsVector3 v12(&p1, &p2);

    hsVector3 norm = v12 % v02;
    float dist = norm.InnerProduct(p0 - p);

    return ProjectOntoPlaneAlongVector(norm, dist, vec, p);
}
Ejemplo n.º 10
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.º 11
0
int main() {

	Vector<int> v(15, 0);

	Vector<int> v2(17, 1);

	Vector<std::string> v3(1000000, "F**k");
	Vector<std::string>* v5 = new Vector<std::string>(100000, "Damn");

	assert(v[1] == 0);
	Vector<int> v12(15, 0);
	v = std::move(v2);
	assert(v.size() == 17);
	assert(v[0] == 1);
	assert(v3[0] == "F**k");
	Vector<int> v6;
	v6 = v2;
	v2 = v12;


	delete v5;
	std::cout << "Meeh" << std::endl;
	Vector<std::string> v40(100, "Damn");

	std::cout << "Moving" << std::endl;
	std::cout << "F**k" << std::endl;
	Vector<std::string> v41 = std::move(v40);
	std::cout << "Delete is the problem" << std::endl;

	auto begin = v41.begin();
	auto end = v41.end();
	while(begin != end) {
		std::cout << *begin << std::endl;
		++begin;
	}

	Vector<std::string> v42;

	for(int i = 0; i < 200; ++i) {
		std::cout << "Pushed back: " << i << std::endl;
		v42.push_back("Shiit");
	}

	v42.reset();


  
	return 0;
}
Ejemplo n.º 12
0
void Footprint::remove_colinear_edges(OGRLinearRing* ring)
{
	ring->closeRings();
	if(ring->getNumPoints()<4)
		return;
	
	std::vector<OGRPoint> pts1,pts2; //pts1 contains the original points while pts2 contains the results
	int flag =0; // to check if any vertex is removed
	
	int n=ring->getNumPoints();
	for(int i=0;i<n;i++)
	{
		OGRPoint pt;
		ring->getPoint(i,&pt);
		pts1.push_back(pt);
	}	

	pts2.push_back(pts1[0]);
	pts2.push_back(pts1[1]);									
	
	for(int i=2;i<n;i++)
	{																
		int j = pts2.size()-1;
	    OGRPoint* p1 = &pts2[j-1],*p2 = &pts2[j],*p3 = &pts1[i];
		OGRPoint v12(p2->getX()-p1->getX(),p2->getY()-p1->getY());
		OGRPoint v23(p3->getX()-p2->getX(),p3->getY()-p2->getY());

		double cos =( v12.getX() * v23.getX() + v12.getY() * v23.getY() )  / (p2->Distance(p1))*(p3->Distance(p2));

		if(cos==1)
		{
			pts2.pop_back();
			flag = 1;
		}
	
		pts2.push_back(*p3);					
	}

	if(flag)
	{
		ring->empty();
		ring = new OGRLinearRing();
		for(int i=0;i<pts2.size();i++)
			ring->addPoint(&pts2[i]);
	}

}
Ejemplo n.º 13
0
plTriUtils::Bary plTriUtils::ComputeBarycentric(const hsPoint3& p0, const hsPoint3& p1, const hsPoint3& p2, const hsPoint3&p, hsPoint3& out)
{
    hsVector3 v12(&p1, &p2);
    hsVector3 v02(&p0, &p2);
    hsVector3 norm = Cross(v12, v02);
    float invLenSq12 = norm.MagnitudeSquared();
    if( invLenSq12 < kAlmostZero )
        return kDegenerateTri; // degenerate triangle

    invLenSq12 = 1.f / invLenSq12;

    hsVector3 vp2(&p, &p2);
    hsVector3 v0 = Cross(v12, vp2);
    hsVector3 v1 = Cross(vp2, v02);

    return IComputeBarycentric(norm, invLenSq12, v0, v1, out);
}
Ejemplo n.º 14
0
		int Poly::getObtuseCorner() const {
			AVec2 v01(point[1]-point[0]),
				v02(point[2]-point[0]),
				v12(point[2]-point[1]);
			if(v01.dot(v02) < 0)
				return 0;

			v01 *= -1;
			if(v01.dot(v12) < 0)
				return 1;

			v12 *= -1;
			v02 *= -1;
			if(v02.dot(v12) < 0)
				return 2;
			return -1;
		}
Ejemplo n.º 15
0
bool plTriUtils::FastBarycentricProjection(const hsPoint3& p0, const hsPoint3& p1, const hsPoint3& p2, hsPoint3&p, hsPoint3& out)
{
    hsVector3 v02(&p0, &p2);
    hsVector3 v12(&p1, &p2);

    hsVector3 norm = Cross(v12, v02);
    float invLenSq12 = norm.MagnitudeSquared();
    if( invLenSq12 < kAlmostZero )
        return false; // degenerate triangle

    invLenSq12 = 1.f / invLenSq12;

    hsVector3 del(&p0, &p);
    float delDotNormOverLenSq = del.InnerProduct(norm) * invLenSq12;

    p += norm * delDotNormOverLenSq;

    int iAx = ISelectAxis(norm);
    hsAssert(iAx >= 0, "Should have already picked out degenerate tris");

    return IFastBarycentric(iAx, p0, p1, p2, p, out);
}
Ejemplo n.º 16
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.º 17
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);
}
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.º 19
0
void Scene::init(){
	primitives = new Primitive*[25];
	nrOfPrimitives = 0;
    
    //wall at0,0,1
    Vec3 v121( 0,0, 1 );
	primitives[nrOfPrimitives] = new PlanePrim( v121, -13.0f );
	primitives[nrOfPrimitives]->getMaterial()->setReflection( 1 );
	primitives[nrOfPrimitives]->getMaterial()->setDiffuse( 0.0f );
    primitives[nrOfPrimitives]->getMaterial()->setSpecular(1.0f);
    Color c121( 1,1,1 );
	primitives[nrOfPrimitives++]->getMaterial()->setColor(c121);
    
    
    //wall at 0 0 -1
    Vec3 v12( 0,0, -1 );
	primitives[nrOfPrimitives] = new PlanePrim( v12, 13.0f );
	primitives[nrOfPrimitives]->getMaterial()->setReflection( 1.0f );
	primitives[nrOfPrimitives]->getMaterial()->setDiffuse( 0.0f );
    primitives[nrOfPrimitives]->getMaterial()->setSpecular(1.0f);
    Color c12( 0.3f,0.3f,0.7f );
	primitives[nrOfPrimitives++]->getMaterial()->setColor(c12);
    //-
    
    //the ground
    Vec3 v1( 0,1, 0 );
	primitives[nrOfPrimitives] = new CheckerBoard( v1, 3.4f );
	primitives[nrOfPrimitives]->getMaterial()->setReflection( 0.7f );
	primitives[nrOfPrimitives]->getMaterial()->setDiffuse( 1.0f );
    primitives[nrOfPrimitives]->getMaterial()->setSpecular(0.0f);
    Color c1( 0.3f, 0.3f, 0.7f );
	primitives[nrOfPrimitives++]->getMaterial()->setColor(c1);
    //
    
    
    // 0 -1 0
    Vec3 v13( 0,-1, 0 );
	primitives[nrOfPrimitives] = new PlanePrim( v13, -3.4f );
	primitives[nrOfPrimitives]->getMaterial()->setReflection( 1 );
	primitives[nrOfPrimitives]->getMaterial()->setDiffuse( 1.0f );
    primitives[nrOfPrimitives]->getMaterial()->setSpecular(1.0f - primitives[nrOfPrimitives]->getMaterial()->getDiffuse());
    Color c13( 1,1,1 );
	primitives[nrOfPrimitives++]->getMaterial()->setColor(c13);
    //
    
	//middle sphere
    Vec3 v2( 0, 1, 8 );
	primitives[nrOfPrimitives] = new Sphere( v2, 1.0f );
	primitives[nrOfPrimitives]->getMaterial()->setReflection( 1 );
    primitives[nrOfPrimitives]->getMaterial()->setDiffuse( 0.2 );
    primitives[nrOfPrimitives]->getMaterial()->setSpecular(1.0f - primitives[nrOfPrimitives]->getMaterial()->getDiffuse());
    Color c2( 1,1,1);
	primitives[nrOfPrimitives++]->getMaterial()->setColor( c2 );
	//-
    
    //left sphere
    Vec3 v3( -5.5f, -0.5, 7 );
    Color c3( 0.7f, 0.7f, 0 );
	primitives[nrOfPrimitives] = new Sphere( v3, 2 );
	primitives[nrOfPrimitives]->getMaterial()->setReflection( 0.6f );
	primitives[nrOfPrimitives]->getMaterial()->setDiffuse( 0.9f );
    primitives[nrOfPrimitives]->getMaterial()->setSpecular(1.0f - primitives[nrOfPrimitives]->getMaterial()->getDiffuse());
	primitives[nrOfPrimitives++]->getMaterial()->setColor( c3 );
    //-
    
    //right sphere
    Vec3 v31( 5.5f, -0.5, 7 );
    Color c31( 0.7f, 0.0f, 0 );
	primitives[nrOfPrimitives] = new Sphere( v31, 2 );
	primitives[nrOfPrimitives]->getMaterial()->setReflection( 0.6f );
	primitives[nrOfPrimitives]->getMaterial()->setDiffuse( 0.9f );
    primitives[nrOfPrimitives]->getMaterial()->setSpecular(1.0f);
	primitives[nrOfPrimitives++]->getMaterial()->setColor( c31 );
    //-
    
    //a light
    Vec3 v4( 3, 2.5f, 3 );
    Color c4(0.7f,0.7f,0.7f);
	primitives[nrOfPrimitives] = new Sphere( v4, 0.5f );
	primitives[nrOfPrimitives]->isLight = true;
	primitives[nrOfPrimitives++]->getMaterial()->setColor( c4 );
	//--
    
    //another light
    Vec3 v5( 0, 5, 10 );
    Color c5( 0.6f, 0.6f, 0.8f );
	primitives[nrOfPrimitives] = new Sphere( v5, 0.5f );
	primitives[nrOfPrimitives]->isLight = true;
	primitives[nrOfPrimitives++]->getMaterial()->setColor( c5 );
	//--    
}
Ejemplo n.º 20
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();
}
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;
}