void BinTree::sideways(Node* current, int level) const {
   if (current != NULL) {
      level++;
      sideways(current->right, level);
      for(int i = level; i >= 0; i--) {
          cout << "    ";
      }
      cout << *current->data << endl;
      sideways(current->left, level);
   }
}
Example #2
0
//---------------------------------------------------------------------------
// sideways
// Helper method for displaySideways. Rotates tree 90 degrees to the left.
void BinTree::sideways(Node* current, int level) const
{
	if (current != NULL)
    {
        level++;
		sideways(current->right, level);
		// indent for readability, 4 spaces per depth level
		for (int i = level; i >= 0; i--)
			cout << "    ";
		cout << *current->data << endl; // display information of object
		sideways(current->left, level);
	}
}
Example #3
0
void Balls::event() {
	beatcounter++;
	raincounter++;
	speed = (uint) (((double) speed / 255) * 20);
	if (speed <= 5) {
		speed = 5;
	}
	//cout << speed <<endl;
	switch (type) {
	case 0:
		rising();
		break;
	case 1:
		falling();
		break;
	case 2:
		expandimp();
		break;
	case 3:
		explodingDimmed();
		break;
	case 4:
		spring();
		break;
	case 5:
		raining();
		break;
	case 6:
		imploding();
		break;
	case 7:
		sideways();
		break;
	case 8:
		moon();
		break;
	case 9:
		mooning();
		break;
	}
}
Example #4
0
////////////////////////////////////////////////////////////////////////////////////////////////////
// displaySideways: displays the tree by traversing the tree recursively
// Pre Conditions: Tree is properly initialized
// Post Conditions: Displays a binary tree as though you are viewing it from the side
// hard coded displaying to standard output.
////////////////////////////////////////////////////////////////////////////////////////////////////
	void BinTree::displaySideways() const {
	   sideways(root, 0);
	}
Example #5
0
void vtFence3d::AddProfileConnectionMesh(const FLine3 &p3)
{
	uint i, j, npoints = p3.GetSize(), prof_points = m_Profile.GetSize();

	// Must have at least 2 points in the profile
	if (prof_points < 2)
		return;

	// Each segment of the profile becomes a long triangle strip.
	// If there are no shared vertices between segments, the number of
	//  vertices is, for a profile of N points and a line of P points:
	//   P * (N-1) * 2, for the sides
	//   N*2, for the end caps (or more if we have to tessellate)
	//
	int iEstimateVerts = npoints * (prof_points-1) * 2 + (prof_points * 2);
	vtMesh *pMesh = new vtMesh(osg::PrimitiveSet::TRIANGLE_STRIP,
		VT_TexCoords | VT_Normals, iEstimateVerts);

	vtMaterialDescriptor *desc = GetMatDescriptor(m_Params.m_ConnectMaterial);
	if (!desc)
	{
		VTLOG1("Warning: could not find material: ");
		VTLOG1(m_Params.m_ConnectMaterial);
		VTLOG1("\n");
		return;
	}
	FPoint2 uvscale = desc->GetUVScale();

	// determine side-pointing vector
	vtArray<float> ExtraElevation(npoints);
	FLine3 sideways(npoints);
	for (j = 0; j < npoints; j++)
	{
		// determine side-pointing vector
		if (j == 0)
			sideways[j] = SidewaysVector(p3[j], p3[j+1]);
		else if (j > 0 && j < npoints-1)
		{
			AngleSideVector(p3[j-1], p3[j], p3[j+1], sideways[j]);
			sideways[j] = -sideways[j];	// We want a vector pointing left, not right
		}
		else if (j == npoints-1)
			sideways[j] = SidewaysVector(p3[j-1], p3[j]);

		ExtraElevation[j] = 0.0f;
		if (m_Params.m_bConstantTop)
			ExtraElevation[j] = m_fMaxGroundY - p3[j].y;
	}

	float u;
	float v1, v2;
	for (i = 0; i < prof_points-1; i++)
	{
		float y1, y2;
		float z1, z2;
		FPoint3 pos, normal;

		// determine v texture coordinate
		float seg_length = m_Profile.SegmentLength(i);
		if (uvscale.y == -1)
		{
			v1 = 0.0f;
			v2 = 1.0f;
		}
		else
		{
			if (i == 0)
			{
				v1 = 0.0f;
				v2 = seg_length / uvscale.y;
			}
			else
			{
				v1 = v2;
				v2 += seg_length / uvscale.y;
			}
		}

		// determine Y and Z values
		y1 = m_Profile[i].y;
		y2 = m_Profile[i+1].y;
		z1 = m_Profile[i].x;
		z2 = m_Profile[i+1].x;

		u = 0.0f;
		int start = pMesh->NumVertices();
		for (j = 0; j < npoints; j++)
		{
			// determine vertex normal (for shading)
			float diffy = y2-y1;
			float diffz = z2-z1;
			float dy = -diffz;
			float dz = diffy;

			FPoint3 n1, n2;
			n1.Set(0, y1, 0);
			n1 += (sideways[j] * z1);
			n2.Set(0, y1 + dy, 0);
			n2 += (sideways[j] * (z1 + dz));

			normal = n2 - n1;
			normal.Normalize();

			// determine the two points of this segment edge, and add them
			pos = p3[j];
			pos.y += y2;
			pos.y += ExtraElevation[j];
			pos += (sideways[j] * z2);
			pMesh->AddVertexNUV(pos, normal, FPoint2(u, v2));

			pos = p3[j];
			pos.y += y1;
			pos.y += ExtraElevation[j];
			pos += (sideways[j] * z1);
			pMesh->AddVertexNUV(pos, normal, FPoint2(u, v1));

			if (j < npoints-1)
			{
				// increment u based on the length of each fence segment
				float length_meters = (p3[j+1] - p3[j]).Length();
				u += (length_meters / uvscale.x);
			}
		}
		pMesh->AddStrip2(npoints * 2, start);
	}

	// We must assume the profile is interpreted as a closed polygon, which
	//  may not be convex.  Hence it must be triangulated.
	FLine2 result;
	Triangulate_f::Process(m_Profile, result);
	uint tcount = result.GetSize()/3;

	int ind[3];
	int line_point;
	FPoint3 normal;

	// add cap at beginning
	line_point = 0;
	normal = p3[0] - p3[1];
	normal.Normalize();
	for (i=0; i<tcount; i++)
	{
		for (j = 0; j < 3; j++)
		{
			FPoint2 p2 = result[i*3+j];

			FPoint3 pos = p3[line_point];
			pos.y += p2.y;
			pos.y += ExtraElevation[line_point];
			pos += (sideways[line_point] * p2.x);

			FPoint2 uv = p2;
			if (uvscale.y != -1)
				uv.Div(uvscale);	// divide meters by [meters/uv] to get uv

			ind[j] = pMesh->AddVertexNUV(pos, normal, uv);
		}
		pMesh->AddTri(ind[0], ind[1], ind[2]);
	}

	// add cap at end
	line_point = npoints-1;
	normal = p3[npoints-1] - p3[npoints-2];
	normal.Normalize();
	for (i=0; i<tcount; i++)
	{
		for (j = 0; j < 3; j++)
		{
			FPoint2 p2 = result[i*3+j];

			FPoint3 pos = p3[line_point];
			pos.y += p2.y;
			pos.y += ExtraElevation[line_point];
			pos += (sideways[line_point] * p2.x);

			FPoint2 uv = p2;
			if (uvscale.y != -1)
				uv.Div(uvscale);	// divide meters by [meters/uv] to get uv

			ind[j] = pMesh->AddVertexNUV(pos, normal, uv);
		}
		pMesh->AddTri(ind[0], ind[2], ind[1]);
	}

	m_pFenceGeom->AddMesh(pMesh, GetMatIndex(desc));
}
Example #6
0
//------------------------------------------------------------------------------
// displaySideways
// Displays the tree sideways
// provided by Professor Zander
void Tree::displaySideways() const {
	sideways(_root, 0);
}