Пример #1
0
void clip_cs_menu() {
    cleardevice();
    outtext((char*)"Click and drag mouse to define rectangular clipping region");

    mouseInput(x1, y1, x2, y2);

    Point2D pMin(std::min(x1,x2), std::min(y1,y2)), pMax(std::max(x1,x2), std::max(y1,y2));
    std::vector<Point2D> rect;
    rect.push_back(pMin); rect.push_back(Point2D(pMin.x, pMax.y));
    rect.push_back(pMax); rect.push_back(Point2D(pMax.x, pMin.y));

    cleardevice();

    mypoly(rect);
    outtext((char*)"Click and drag mouse to make lines to be clipped, right click to EXIT");
    clearmouseclick(WM_RBUTTONDOWN);

    while(!ismouseclick(WM_RBUTTONDOWN)) {
        Point2D p1, p2;
        mouseLine(p1, p2);

        setcolor(RED);
        myline(p1, p2);

        setcolor(WHITE);
        clip_line_cs(pMin, pMax, p1, p2);
    }
}
Пример #2
0
//--------------------------------------------------------------------------- 
void Sky::makeBoundingBox()
{
   // This bounding box is less than the root container's bounding box, but
   //  greater than any "real" bounding box, ie the terrain.
   //
   Point3F pMin(-1e10f, -1e10f, -1e10f);
   Point3F pMax( 1e10f,  1e10f,  1e10f);
	setBoundingBox(Box3F(pMin, pMax));
}
Пример #3
0
void ShapeBezierSurface::computeBBox(SoAction*, SbBox3f& box, SbVec3f& /*center*/ )
{
	box.makeEmpty();
	for (int i = 0; i < m_surfacesVector.size(); i++)
	{
		BBox pBox =  m_surfacesVector[i]->GetComputeBBox();
		SbVec3f pMin( pBox.pMin[0], pBox.pMin[1], pBox.pMin[2] );
		box.extendBy( pMin );
		SbVec3f pMax( pBox.pMax[0], pBox.pMax[1], pBox.pMax[2] );
		box.extendBy( pMax );
	}
}
Пример #4
0
void PClock::tick()
{
    puint32 thisFrameTime = pTimeGetCurrentTimestamp();
    puint32 deltaTime = thisFrameTime - m_timestamp;
    deltaTime = deltaTime < 1? 1 : deltaTime; // at least 1 ms
    m_timestamp = thisFrameTime;
    
    if (!m_paused)
    {
    #if defined (P_WIN32) && defined (P_DEBUG)
        if (!isFpsControlEnabled() && deltaTime > P_MILLISECONDS_PER_FRAME)
        {
            // The application is in the debug mode and we are stepping through
            // the application, so the interval between two frames might be 
            // abnormally large. In this case, we need to trim the large delta
            // time to normal one for 
            deltaTime = P_MILLISECONDS_PER_FRAME;
        }
    #endif

        // We use the approximate average of last n frames to predicate the delta time
        // for next frame.
        // The larger n is, the faster animation will be after resume in a short while.
        const puint32 n = 4;
        pfloat32 elapsedNumFrames = (pfloat32)pMin(m_playedFrames, n - 1);
        m_systemDeltaTime = (m_systemDeltaTime * elapsedNumFrames + (pfloat32)deltaTime) / 
            (elapsedNumFrames + 1.0f);

        m_systemCurrentTime += m_systemDeltaTime;
        // The awake time is the real time invested in rendering and computation.
        pfloat32 awakeTime = m_systemDeltaTime - m_lastSleepingTime;
        
        if (isFpsControlEnabled() && awakeTime < m_minMSPerFrame)
        {
            // Note that the FPS control is upon the system frame/delta time
            // rather than the scaled one. The former is a measurement of frame
            // rate while the latter is that of the application/game speed.
            pfloat32 sleepingTime = m_minMSPerFrame - awakeTime;
            m_lastSleepingTime = sleepingTime;
            psleep(sleepingTime);
        }

        m_deltaTime = m_systemDeltaTime * m_scaling;

        m_currentTime += m_deltaTime;

        m_elapsedFrames++;
        m_playedFrames++;
    }
}
Пример #5
0
void Colony::distributeAntsByBlock()
{
    int nHorizontalBlocks = _environment->getWidth() / BLOCK_SIZE;
    int nVerticalBlocks   = _environment->getHeight() / BLOCK_SIZE;

    for (int hb = 0; hb < nHorizontalBlocks; ++hb)
    {
        for (int vb = 0; vb < nVerticalBlocks; ++vb)
        {
            Point pMin( hb * BLOCK_SIZE, vb * BLOCK_SIZE );
            Point pMax( pMin.x + BLOCK_SIZE - 1, pMin.y + BLOCK_SIZE - 1 );
            addAntInBlock( pMin, pMax );
        }
    }
}
Пример #6
0
void CPlanarGraph::GetGraphBoundingBox(v2f& posMin, v2f& posMax)
{
	v2f pMin(1e10);
	v2f pMax(-1e10);
	for ( int i=0; i<GetNumOfNodes(); i++ )
	{
		v2f pi = GetNode(i).GetPos();
		for ( int j=0; j<2; j++ )
		{
			pMin[j] = min(pMin[j], pi[j]);
			pMax[j] = max(pMax[j], pi[j]);
		}
	}
	posMin = pMin;
	posMax = pMax;
}
Пример #7
0
//-----------------------------------------------------------------------------
ImplicitMesh::ImplicitMesh(SimpleMesh * mesh) : mSourceMesh(mesh), mData(NULL)
{
  // Loop through all vertices in the mesh to determine the smallest
  // bounding box needed
  Vector3<float> pMin((std::numeric_limits<float>::max)(), (std::numeric_limits<float>::max)(), (std::numeric_limits<float>::max)());
  Vector3<float> pMax(-(std::numeric_limits<float>::max)(), -(std::numeric_limits<float>::max)(), -(std::numeric_limits<float>::max)());
  const std::vector<SimpleMesh::Vertex>& verts = mSourceMesh->GetVerts();
  for(unsigned int i=0; i < verts.size(); i++){
    const SimpleMesh::Vertex &v = verts.at(i);
    for (int j = 0; j < 3; j++) {
      if (pMin[j] > v.pos[j]) pMin[j] = v.pos[j];
      if (pMax[j] < v.pos[j]) pMax[j] = v.pos[j];
    }
  }

  // Pad with 0.1 to get around border issues
  Vector3<float> pad(0.1, 0.1, 0.1);
  pMin -= pad;
  pMax += pad;
  mBox = Bbox(pMin, pMax);
  std::cout << "Bounding box of implicit mesh: " << mBox << std::endl;
}
Пример #8
0
int Blockporter::DoExport(const TCHAR* name, ExpInterface* ei, Interface* i, BOOL supressPrompts, DWORD options)
{
	INode* root;
	//caption and message for MessagesBoxes
	TCHAR msg[MB_BUFFER_LENGTH];
	TCHAR cap[MB_BUFFER_LENGTH];

	//Get the root node
	root = i->GetRootNode();

	//the node of our object should be a groupnode, which contains every object
	//we want to export
	i->PushPrompt(_T("Searching for Group..."));
	bool found = false;
	for(int idx = 0; idx < root->NumberOfChildren(); idx++)
	{
		if(root->GetChildNode(idx)->IsGroupHead())
		{
			//we found our group
			//next step is to make the group node our new root, because every object
			//we want is part of this group

			found = true;
			root = root->GetChildNode(idx);
			break;
		}
	}

	if(!found)
	{
		MessageBox(nullptr, GetString(IDS_ERROR_NO_GROUP, msg), GetString(IDS_GENERAL_ERROR, cap), MB_OK | MB_ICONERROR);
		return 0;
	}

	//Now that we have the groupnode let's compare the fileversions
	if(!IsNewModelVersion(name, root->GetName()))
	{
		if(MessageBox(nullptr, GetString(IDS_VER_TO_LOW_MSG, msg), GetString(IDS_VER_TO_LOW_CAP, cap), MB_YESNO | MB_ICONEXCLAMATION) == IDNO)
			return 1;
	}

	i->PushPrompt(_T("Opening File"));
	Interface14* iface = GetCOREInterface14();
	UINT code = iface->DefaultTextSaveCodePage(true);
	MaxSDK::Util::Path storageNamePath(name);
	storageNamePath.SaveBaseFile();
	switch (code & MaxSDK::Util::MaxStringDataEncoding::MSDE_CP_MASK)
	{
	case CP_UTF8:
		mStream = _tfopen(name, _T("wt, ccs=UFT-8"));
		break;
	case MaxSDK::Util::MaxStringDataEncoding::MSDE_CP_UTF16:
		mStream = _tfopen(name, _T("wt, ccs=UTF-16BE"));
		break;
	default:
		mStream = _tfopen(name, _T("wt"));
	}
	if(!mStream)
		return 0;

	//now we have our file stream, so let's write the header
	i->PushPrompt(_T("Writing Header"));
	WriteHeader(root->GetName(), root->NumberOfChildren());

	//now that we have the header written, let's iterate through the objects in the
	//group and export the meshes and lights

	INode* child;
    Point3 pMin(0,0,0), pMax(0,0,0);

	for(int idx = 0; idx < root->NumberOfChildren(); idx++)
	{
		child = root->GetChildNode(idx);
		i->PushPrompt(_T("Processing Object %s", child->GetName()));
		if(child->IsGroupHead())
		{
			MessageBox(nullptr, GetString(IDS_ERROR_TO_MANY_GROUPS, msg), GetString(IDS_GENERAL_ERROR, cap), MB_OK | MB_ICONERROR);
			continue;
		}

		ObjectState os = child->EvalWorldState(0);

		//let's take a look at the SuperClassID of the object
		//so we find out if it's a mesh or a light
		if(!os.obj)
			continue; //somehow this node doesn't have an object

        Box3 boundBox;

		switch(os.obj->SuperClassID())
		{
		case GEOMOBJECT_CLASS_ID:
			_ftprintf(mStream, _T("<ObjectID=%i>\n"), idx);
			i->PushPrompt(_T("Writing MeshData for Object %s", child->GetName()));
			boundBox = WriteMeshData(child, idx);
            pMin.x = (boundBox.Min().x < pMin.x) ? boundBox.Min().x : pMin.x;
            pMin.y = (boundBox.Min().y < pMin.y) ? boundBox.Min().y : pMin.y;
            pMax.x = (boundBox.Max().x > pMax.x) ? boundBox.Max().x : pMax.x;
            pMax.y = (boundBox.Max().y > pMax.y) ? boundBox.Max().y : pMax.y;
			i->PushPrompt(_T("Writing MaterialData for Object %s", child->GetName()));
			WriteMaterialData(child);
			_ftprintf(mStream, _T("</Object>\n"));
			break;
		//case LIGHT_CLASS_ID:
		//	WriteLightData(child, idx);
		//	break;
		}
	}

    //Write the Bounding Box
    _ftprintf(mStream, _T("<BoundingBox>\n"));
    _ftprintf(mStream, _T("\t<Min=%f,%f>\n"), pMin.x, pMin.y);
    _ftprintf(mStream, _T("\t<Max=%f,%f>\n"), pMax.x, pMax.y);
    _ftprintf(mStream, _T("</BoundingBox>\n"));
	//we are done exporting, so close the stream
	i->PushPrompt(_T("Closing file..."));
	fclose(mStream);

	MessageBox(nullptr, GetString(IDS_FINISH_MSG, msg), GetString(IDS_FINISH_CAP, cap), MB_OK | MB_ICONINFORMATION);

	return 1;
}
Пример #9
0
dgMeshEffect * dgMeshEffect::CreateVoronoiConvexDecomposition (dgMemoryAllocator * const allocator, dgInt32 pointCount, dgInt32 pointStrideInBytes, const dgFloat32 * const pointCloud, dgInt32 materialId, const dgMatrix & textureProjectionMatrix)
{
   dgFloat32 normalAngleInRadians = 30.0f * 3.1416f / 180.0f;
   dgStack<dgBigVector> buffer (pointCount + 16);
   dgBigVector * const pool = &buffer[0];
   dgInt32 count = 0;
   dgFloat64 quantizeFactor = dgFloat64 (16.0f);
   dgFloat64 invQuantizeFactor = dgFloat64 (1.0f) / quantizeFactor;
   dgInt32 stride = pointStrideInBytes / sizeof (dgFloat32);
   dgBigVector pMin (dgFloat32 (1.0e10f), dgFloat32 (1.0e10f), dgFloat32 (1.0e10f), dgFloat32 (0.0f));
   dgBigVector pMax (dgFloat32 (-1.0e10f), dgFloat32 (-1.0e10f), dgFloat32 (-1.0e10f), dgFloat32 (0.0f));
   for (dgInt32 i = 0; i < pointCount; i ++)
   {
      dgFloat64 x = pointCloud[i * stride + 0];
      dgFloat64 y	= pointCloud[i * stride + 1];
      dgFloat64 z	= pointCloud[i * stride + 2];
      x = floor (x * quantizeFactor) * invQuantizeFactor;
      y = floor (y * quantizeFactor) * invQuantizeFactor;
      z = floor (z * quantizeFactor) * invQuantizeFactor;
      dgBigVector p (x, y, z, dgFloat64 (0.0f));
      pMin = dgBigVector (dgMin (x, pMin.m_x), dgMin (y, pMin.m_y), dgMin (z, pMin.m_z), dgFloat64 (0.0f));
      pMax = dgBigVector (dgMax (x, pMax.m_x), dgMax (y, pMax.m_y), dgMax (z, pMax.m_z), dgFloat64 (0.0f));
      pool[count] = p;
      count ++;
   }
   // add the bbox as a barrier
   pool[count + 0] = dgBigVector ( pMin.m_x, pMin.m_y, pMin.m_z, dgFloat64 (0.0f));
   pool[count + 1] = dgBigVector ( pMax.m_x, pMin.m_y, pMin.m_z, dgFloat64 (0.0f));
   pool[count + 2] = dgBigVector ( pMin.m_x, pMax.m_y, pMin.m_z, dgFloat64 (0.0f));
   pool[count + 3] = dgBigVector ( pMax.m_x, pMax.m_y, pMin.m_z, dgFloat64 (0.0f));
   pool[count + 4] = dgBigVector ( pMin.m_x, pMin.m_y, pMax.m_z, dgFloat64 (0.0f));
   pool[count + 5] = dgBigVector ( pMax.m_x, pMin.m_y, pMax.m_z, dgFloat64 (0.0f));
   pool[count + 6] = dgBigVector ( pMin.m_x, pMax.m_y, pMax.m_z, dgFloat64 (0.0f));
   pool[count + 7] = dgBigVector ( pMax.m_x, pMax.m_y, pMax.m_z, dgFloat64 (0.0f));
   count += 8;
   dgStack<dgInt32> indexList (count);
   count = dgVertexListToIndexList (&pool[0].m_x, sizeof (dgBigVector), 3, count, &indexList[0], dgFloat64 (5.0e-2f));
   dgAssert (count >= 8);
   dgFloat64 maxSize = dgMax (pMax.m_x - pMin.m_x, pMax.m_y - pMin.m_y, pMax.m_z - pMin.m_z);
   pMin -= dgBigVector (maxSize, maxSize, maxSize, dgFloat64 (0.0f));
   pMax += dgBigVector (maxSize, maxSize, maxSize, dgFloat64 (0.0f));
   // add the a guard zone, so that we do no have to clip
   dgInt32 guadVertexKey = count;
   pool[count + 0] = dgBigVector ( pMin.m_x, pMin.m_y, pMin.m_z, dgFloat64 (0.0f));
   pool[count + 1] = dgBigVector ( pMax.m_x, pMin.m_y, pMin.m_z, dgFloat64 (0.0f));
   pool[count + 2] = dgBigVector ( pMin.m_x, pMax.m_y, pMin.m_z, dgFloat64 (0.0f));
   pool[count + 3] = dgBigVector ( pMax.m_x, pMax.m_y, pMin.m_z, dgFloat64 (0.0f));
   pool[count + 4] = dgBigVector ( pMin.m_x, pMin.m_y, pMax.m_z, dgFloat64 (0.0f));
   pool[count + 5] = dgBigVector ( pMax.m_x, pMin.m_y, pMax.m_z, dgFloat64 (0.0f));
   pool[count + 6] = dgBigVector ( pMin.m_x, pMax.m_y, pMax.m_z, dgFloat64 (0.0f));
   pool[count + 7] = dgBigVector ( pMax.m_x, pMax.m_y, pMax.m_z, dgFloat64 (0.0f));
   count += 8;
   dgDelaunayTetrahedralization delaunayTetrahedras (allocator, &pool[0].m_x, count, sizeof (dgBigVector), dgFloat32 (0.0f));
   delaunayTetrahedras.RemoveUpperHull ();
   //	delaunayTetrahedras.Save("xxx0.txt");
   dgInt32 tetraCount = delaunayTetrahedras.GetCount();
   dgStack<dgBigVector> voronoiPoints (tetraCount + 32);
   dgStack<dgDelaunayTetrahedralization::dgListNode *> tetradrumNode (tetraCount);
   dgTree<dgList<dgInt32>, dgInt32> delanayNodes (allocator);
   dgInt32 index = 0;
   const dgHullVector * const delanayPoints = delaunayTetrahedras.GetHullVertexArray();
   for (dgDelaunayTetrahedralization::dgListNode * node = delaunayTetrahedras.GetFirst(); node; node = node->GetNext())
   {
      dgConvexHull4dTetraherum & tetra = node->GetInfo();
      voronoiPoints[index] = tetra.CircumSphereCenter (delanayPoints);
      tetradrumNode[index] = node;
      for (dgInt32 i = 0; i < 4; i ++)
      {
         dgTree<dgList<dgInt32>, dgInt32>::dgTreeNode * header = delanayNodes.Find (tetra.m_faces[0].m_index[i]);
         if (!header)
         {
            dgList<dgInt32> list (allocator);
            header = delanayNodes.Insert (list, tetra.m_faces[0].m_index[i]);
         }
         header->GetInfo().Append (index);
      }
      index ++;
   }
   dgMeshEffect * const voronoiPartition = new (allocator) dgMeshEffect (allocator);
   voronoiPartition->BeginPolygon();
   dgFloat64 layer = dgFloat64 (0.0f);
   dgTree<dgList<dgInt32>, dgInt32>::Iterator iter (delanayNodes);
   for (iter.Begin(); iter; iter ++)
   {
      dgTree<dgList<dgInt32>, dgInt32>::dgTreeNode * const nodeNode = iter.GetNode();
      const dgList<dgInt32> & list = nodeNode->GetInfo();
      dgInt32 key = nodeNode->GetKey();
      if (key < guadVertexKey)
      {
         dgBigVector pointArray[512];
         dgInt32 indexArray[512];
         dgInt32 count = 0;
         for (dgList<dgInt32>::dgListNode * ptr = list.GetFirst(); ptr; ptr = ptr->GetNext())
         {
            dgInt32 i = ptr->GetInfo();
            pointArray[count] = voronoiPoints[i];
            count ++;
            dgAssert (count < dgInt32 (sizeof (pointArray) / sizeof (pointArray[0])));
         }
         count = dgVertexListToIndexList (&pointArray[0].m_x, sizeof (dgBigVector), 3, count, &indexArray[0], dgFloat64 (1.0e-3f));
         if (count >= 4)
         {
            dgMeshEffect convexMesh (allocator, &pointArray[0].m_x, count, sizeof (dgBigVector), dgFloat64 (0.0f));
            if (convexMesh.GetCount())
            {
               convexMesh.CalculateNormals (normalAngleInRadians);
               convexMesh.UniformBoxMapping (materialId, textureProjectionMatrix);
               for (dgInt32 i = 0; i < convexMesh.m_pointCount; i ++)
                  convexMesh.m_points[i].m_w = layer;
               for (dgInt32 i = 0; i < convexMesh.m_atribCount; i ++)
                  convexMesh.m_attrib[i].m_vertex.m_w = layer;
               voronoiPartition->MergeFaces (&convexMesh);
               layer += dgFloat64 (1.0f);
            }
         }
      }
   }
   voronoiPartition->EndPolygon (dgFloat64 (1.0e-8f), false);
   //	voronoiPartition->SaveOFF("xxx0.off");
   //voronoiPartition->ConvertToPolygons();
   return voronoiPartition;
}
Пример #10
0
void PPropertyInt::operator=(pint32 value)
{
    m_value = pMin(m_range[1], pMax(value, m_range[0]));
}
Пример #11
0
/*
 * Break up commands into data that can be passed into the function
 * Parameters:
 * 	char* linePointer - Chooses which command function to call and passes tokens based on this string
 * 	struct annual_stats* dataStruct - Data from stdin
 */
void processCommands(char* linePointer, struct annual_stats* dataStruct)
{
	readLine(linePointer);
	int numOfCommands = atoi(linePointer);
	char delim[2] = " ";

	for (int i = 0; i < numOfCommands; i++)
	{
		readLine(linePointer);
		char* command = strtok(linePointer, delim);

		if(strcmp(command, "bsort") == 0)
		{
			char* temp = strtok(NULL, delim); //Either 2 for year '20xx' or r for 'range'
			if(temp[0] == '2')
			{
				int year = atoi(temp);
				char* field = strtok(NULL,delim);
				char* order = strtok(NULL,delim);

				struct package* package = orderPackage(year, year, field, dataStruct);
				bSortY(package, field, order);
			}
			else if(temp[0] == 'r')
			{
				int start = atoi(strtok(NULL,delim));
				int end = atoi(strtok(NULL,delim));
				char* field = strtok(NULL,delim);
				char* order = strtok(NULL,delim);

				struct package* package = orderPackage(start, end, field, dataStruct);
				bSortR(package, field, order, (end - start));
			}
			else
				printf("Error in calling sort function.\n");
		}
		else if (strcmp(command, "bfind") == 0)
		{
			int year = atoi(strtok(NULL,delim));;
			char* field = strtok(NULL,delim);
			char* item = strtok(NULL,delim);
			struct package* package = orderPackage(year, year, field, dataStruct);
			bFind(package, field, item);
		}
		else if(strcmp(command, "qsort") == 0)
		{
			char* temp = strtok(NULL, delim); //Either 2 for year '20xx' or r for 'range'
			if(temp[0] == '2')
			{
				int year = atoi(temp);
				char* field = strtok(NULL,delim);
				char* order = strtok(NULL,delim);

				struct package* package = orderPackage(year, year, field, dataStruct);
				qSortY(package, field, order);
			}
			else if(temp[0] == 'r')
			{
				int start = atoi(strtok(NULL,delim));
				int end = atoi(strtok(NULL,delim));
				char* field = strtok(NULL,delim);
				char* order = strtok(NULL,delim);

				struct package* package = orderPackage(start, end, field, dataStruct);
				qSortR(package, field, order, (end - start));
			}
			else
				printf("Error in calling sort function.\n");
		}
		else if (strcmp(command, "qfind") == 0)
		{
			int year = atoi(strtok(NULL,delim));;
			char* field = strtok(NULL,delim);
			char* item = strtok(NULL,delim);
			struct package* package = orderPackage(year, year, field, dataStruct);
			qFind(package, field, item);
		}
		else if (strcmp(command, "pmax") == 0)
		{
			int year = atoi(strtok(NULL,delim));;
			char* field = strtok(NULL,delim);
			struct package* package = orderPackage(year, year, field, dataStruct);
			pMax(package, field);
		}
		else if (strcmp(command, "pmin") == 0)
		{
			int year = atoi(strtok(NULL,delim));;
			char* field = strtok(NULL,delim);
			struct package* package = orderPackage(year, year, field, dataStruct);
			pMin(package, field);
		}
	}
}