コード例 #1
0
ファイル: puzzle.cpp プロジェクト: Templier/scummvm-test
void Puzzle::slidePiece(int x1, int y1, int x2, int y2) {
	int count;
	PointList slidePoints;
	slidePoints.resize(320);

	x1 += _pieceInfo[_puzzlePiece].offX;
	y1 += _pieceInfo[_puzzlePiece].offY;

	count = pathLine(slidePoints, 0, Point(x1, y1),
		 Point(x2 + _pieceInfo[_puzzlePiece].offX, y2 + _pieceInfo[_puzzlePiece].offY));

	if (count > 1) {
		int factor = count / 4;
		_sliding = true;

		if (!factor)
			factor++;

		for (int i = 1; i < count; i += factor) {
			_slidePointX = slidePoints[i].x;
			_slidePointY = slidePoints[i].y;
			_vm->_render->drawScene();
			_vm->_system->delayMillis(10);
		}
		_sliding = false;
	}

	_pieceInfo[_puzzlePiece].curX = x2;
	_pieceInfo[_puzzlePiece].curY = y2;
}
コード例 #2
0
int main()
{
	PointList points;

	// Generate points
	points.resize(sc_pointCount);
	for (unsigned int i = 0; i < points.size(); ++i) {
		points[i] = Point(
			rand()%(maxCoordinate*2) - maxCoordinate,
			rand()%(maxCoordinate*2) - maxCoordinate);
	}

	findClosestPoints(points, sc_numPointsToFind);

	// Print out results
	for (unsigned int i = 0; i < sc_numPointsToFind; ++i) {
		Point& point = points[i];
		std::cout << "(" << point.x << "," << point.y << ") ";
	}

	return 0;
}
コード例 #3
0
void MeshToNukeGeometryConverter::doConversion( const IECore::Object *from, GeometryList &to, int objIndex, const IECore::CompoundObject *operands ) const
{
	assert( from );
	const MeshPrimitive *mesh = static_cast<const MeshPrimitive *>( from );

	const std::vector<int> &vertPerFace = mesh->verticesPerFace()->readable();
	const std::vector<int> &vertIds = mesh->vertexIds()->readable();
	std::vector<int>::const_iterator ids = vertIds.begin();

	// create polygons
	for ( std::vector<int>::const_iterator vpf = vertPerFace.begin(); vpf != vertPerFace.end(); vpf++ )
	{
		Polygon *p = new Polygon( *vpf, true );
		for ( int v = 0; v < *vpf; v++, ids++ )
		{
			p->vertex(v) = *ids;
		}
		to.add_primitive( objIndex, p );
	}

	// get points
	// \todo: add parameters for standard prim vars
	const V3fVectorData *meshPoints = mesh->variableData< V3fVectorData >( "P", PrimitiveVariable::Vertex );
	if ( meshPoints )
	{
		unsigned numPoints = meshPoints->readable().size();
		PointList* points = to.writable_points( objIndex );
		points->resize( numPoints );
		std::transform( meshPoints->readable().begin(), meshPoints->readable().end(), points->begin(), IECore::convert< DD::Image::Vector3, Imath::V3f > );
	}

	// get normals
	const V3fVectorData *meshNormals = mesh->variableData< V3fVectorData >( "N", PrimitiveVariable::Vertex );
	if ( meshNormals )
	{
		Attribute* N = to.writable_attribute( objIndex, Group_Points, "N", NORMAL_ATTRIB);
		unsigned p = 0;
		for ( std::vector< Imath::V3f >::const_iterator nIt = meshNormals->readable().begin(); nIt < meshNormals->readable().end(); nIt++, p++)
		{
			N->normal(p) = IECore::convert< Vector3, Imath::V3f >( *nIt );
		}
	}

	// get uvs
	PrimitiveVariableMap::const_iterator uvIt = mesh->variables.find( "uv" );
	if( uvIt != mesh->variables.end() && uvIt->second.interpolation == PrimitiveVariable::FaceVarying && uvIt->second.data->typeId() == V2fVectorDataTypeId )
	{
		Attribute* uv = to.writable_attribute( objIndex, Group_Vertices, "uv", VECTOR4_ATTRIB );
		if( uvIt->second.indices )
		{
			const std::vector<Imath::V2f> &uvs = runTimeCast<V2fVectorData>( uvIt->second.data )->readable();
			const std::vector<int> &indices = uvIt->second.indices->readable();

			for( size_t i = 0; i < indices.size() ; ++i )
			{
				// as of Cortex 10, we take a UDIM centric approach
				// to UVs, which clashes with Nuke, so we must flip
				// the v values during conversion.
				uv->vector4( i ).set( uvs[indices[i]][0], 1.0 - uvs[indices[i]][1], 0.0f, 1.0f );
			}
		}
		else
		{
			const std::vector<Imath::V2f> &uvs = runTimeCast<V2fVectorData>( uvIt->second.data )->readable();

			for( size_t i = 0; i < uvs.size() ; ++i )
			{
				// as of Cortex 10, we take a UDIM centric approach
				// to UVs, which clashes with Nuke, so we must flip
				// the v values during conversion.
				uv->vector4( i ).set( uvs[i][0], 1.0 - uvs[i][1], 0.0f, 1.0f );
			}
		}
	}

	// get colours
	const Color3fVectorData *meshColours = mesh->variableData< Color3fVectorData >( "Cs", PrimitiveVariable::FaceVarying );
	if ( meshColours )
	{
		Attribute *Cf = to.writable_attribute( objIndex, Group_Vertices, "Cf", VECTOR4_ATTRIB );
		unsigned v = 0;
		for ( std::vector< Imath::Color3f >::const_iterator cIt = meshColours->readable().begin(); cIt < meshColours->readable().end(); cIt++, v++)
		{
			Cf->vector4( v ).set( (*cIt)[0], (*cIt)[1], (*cIt)[2], 1 );
		}
	}

	// \todo Implement custom prim vars...
}